1 // Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_DIGEST_INTERNAL_H
16 #define OPENSSL_HEADER_CRYPTO_FIPSMODULE_DIGEST_INTERNAL_H
17 
18 #include <openssl/base.h>
19 
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 
25 // env_md_st is typoed ("evp" -> "env"), but the typo comes from OpenSSL and
26 // some consumers forward-declare these structures so we're leaving it alone.
27 struct env_md_st {
28   // type contains a NID identifing the digest function. (For example,
29   // NID_md5.)
30   int type;
31 
32   // md_size contains the size, in bytes, of the resulting digest.
33   unsigned md_size;
34 
35   // flags contains the OR of |EVP_MD_FLAG_*| values.
36   uint32_t flags;
37 
38   // init initialises the state in |ctx->md_data|.
39   void (*init)(EVP_MD_CTX *ctx);
40 
41   // update hashes |len| bytes of |data| into the state in |ctx->md_data|.
42   void (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
43 
44   // final completes the hash and writes |md_size| bytes of digest to |out|.
45   void (*final)(EVP_MD_CTX *ctx, uint8_t *out);
46 
47   // block_size contains the hash's native block size.
48   unsigned block_size;
49 
50   // ctx_size contains the size, in bytes, of the state of the hash function.
51   unsigned ctx_size;
52 };
53 
54 // evp_md_pctx_ops contains function pointers to allow the |pctx| member of
55 // |EVP_MD_CTX| to be manipulated without breaking layering by calling EVP
56 // functions.
57 struct evp_md_pctx_ops {
58   // free is called when an |EVP_MD_CTX| is being freed and the |pctx| also
59   // needs to be freed.
60   void (*free)(EVP_PKEY_CTX *pctx);
61 
62   // dup is called when an |EVP_MD_CTX| is copied and so the |pctx| also needs
63   // to be copied.
64   EVP_PKEY_CTX *(*dup)(EVP_PKEY_CTX *pctx);
65 };
66 
67 
68 #if defined(__cplusplus)
69 }  // extern C
70 #endif
71 
72 #endif  // OPENSSL_HEADER_CRYPTO_FIPSMODULE_DIGEST_INTERNAL_H
73