1 /**
2  * \file md_internal.h
3  *
4  * \brief Message digest wrappers.
5  *
6  * \warning This in an internal header. Do not include directly.
7  *
8  * \author Adriaan de Jong <dejong@fox-it.com>
9  *
10  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
11  *  SPDX-License-Identifier: Apache-2.0
12  *
13  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
14  *  not use this file except in compliance with the License.
15  *  You may obtain a copy of the License at
16  *
17  *  http://www.apache.org/licenses/LICENSE-2.0
18  *
19  *  Unless required by applicable law or agreed to in writing, software
20  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the License for the specific language governing permissions and
23  *  limitations under the License.
24  *
25  *  This file is part of mbed TLS (https://tls.mbed.org)
26  */
27 #ifndef MBEDTLS_MD_WRAP_H
28 #define MBEDTLS_MD_WRAP_H
29 
30 #if !defined(MBEDTLS_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include MBEDTLS_CONFIG_FILE
34 #endif
35 
36 #include "md.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43  * Message digest information.
44  * Allows message digest functions to be called in a generic way.
45  */
46 struct mbedtls_md_info_t
47 {
48     /** Digest identifier */
49     mbedtls_md_type_t type;
50 
51     /** Name of the message digest */
52     const char * name;
53 
54     /** Output length of the digest function in bytes */
55     int size;
56 
57     /** Block length of the digest function in bytes */
58     int block_size;
59 
60     /** Digest initialisation function */
61     void (*starts_func)( void *ctx );
62 
63     /** Digest update function */
64     void (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
65 
66     /** Digest finalisation function */
67     void (*finish_func)( void *ctx, unsigned char *output );
68 
69     /** Generic digest function */
70     void (*digest_func)( const unsigned char *input, size_t ilen,
71                          unsigned char *output );
72 
73     /** Allocate a new context */
74     void * (*ctx_alloc_func)( void );
75 
76     /** Free the given context */
77     void (*ctx_free_func)( void *ctx );
78 
79     /** Clone state from a context */
80     void (*clone_func)( void *dst, const void *src );
81 
82     /** Internal use only */
83     void (*process_func)( void *ctx, const unsigned char *input );
84 };
85 
86 #if defined(MBEDTLS_MD2_C)
87 extern const mbedtls_md_info_t mbedtls_md2_info;
88 #endif
89 #if defined(MBEDTLS_MD4_C)
90 extern const mbedtls_md_info_t mbedtls_md4_info;
91 #endif
92 #if defined(MBEDTLS_MD5_C)
93 extern const mbedtls_md_info_t mbedtls_md5_info;
94 #endif
95 #if defined(MBEDTLS_RIPEMD160_C)
96 extern const mbedtls_md_info_t mbedtls_ripemd160_info;
97 #endif
98 #if defined(MBEDTLS_SHA1_C)
99 extern const mbedtls_md_info_t mbedtls_sha1_info;
100 #endif
101 #if defined(MBEDTLS_SHA256_C)
102 extern const mbedtls_md_info_t mbedtls_sha224_info;
103 extern const mbedtls_md_info_t mbedtls_sha256_info;
104 #endif
105 #if defined(MBEDTLS_SHA512_C)
106 extern const mbedtls_md_info_t mbedtls_sha384_info;
107 extern const mbedtls_md_info_t mbedtls_sha512_info;
108 #endif
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif /* MBEDTLS_MD_WRAP_H */
115