mbed TLS v2.16.1
md.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
10  * SPDX-License-Identifier: GPL-2.0
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * This file is part of Mbed TLS (https://tls.mbed.org)
27  */
28 
29 #ifndef MBEDTLS_MD_H
30 #define MBEDTLS_MD_H
31 
32 #include <stddef.h>
33 
34 #if !defined(MBEDTLS_CONFIG_FILE)
35 #include "config.h"
36 #else
37 #include MBEDTLS_CONFIG_FILE
38 #endif
39 
40 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
41 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
42 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
43 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
45 /* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */
46 #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
60 typedef enum {
72 
73 #if defined(MBEDTLS_SHA512_C)
74 #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
75 #else
76 #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
77 #endif
78 
83 
87 typedef struct mbedtls_md_context_t
88 {
91 
93  void *md_ctx;
94 
96  void *hmac_ctx;
98 
108 const int *mbedtls_md_list( void );
109 
119 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
120 
131 
141 
156 
157 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
158 #if defined(MBEDTLS_DEPRECATED_WARNING)
159 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
160 #else
161 #define MBEDTLS_DEPRECATED
162 #endif
163 
182 #undef MBEDTLS_DEPRECATED
183 #endif /* MBEDTLS_DEPRECATED_REMOVED */
184 
204 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
205 
226  const mbedtls_md_context_t *src );
227 
237 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
238 
249 
259 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
260 
275 
292 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
293 
312 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
313 
332 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
333  unsigned char *output );
334 
335 #if defined(MBEDTLS_FS_IO)
336 
353 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
354  unsigned char *output );
355 #endif /* MBEDTLS_FS_IO */
356 
375 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
376  size_t keylen );
377 
397 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
398  size_t ilen );
399 
418 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
419 
436 
459 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
460  const unsigned char *input, size_t ilen,
461  unsigned char *output );
462 
463 /* Internal use */
464 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
465 
466 #ifdef __cplusplus
467 }
468 #endif
469 
470 #endif /* MBEDTLS_MD_H */