mbed TLS v2.23.0: md.h Source File

mbed TLS v2.23.0

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: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 * This file is part of Mbed TLS (https://tls.mbed.org)
25 */
26
27 #ifndef MBEDTLS_MD_H
28 #define MBEDTLS_MD_H
29
30 #include <stddef.h>
31
32 #if !defined(MBEDTLS_CONFIG_FILE)
33 #include "mbedtls/config.h"
34 #else
35 #include MBEDTLS_CONFIG_FILE
36 #endif
37
38 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
39 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
40 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
41 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
43 /* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */
44 #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
58 typedef enum {
59 MBEDTLS_MD_NONE=0,
60 MBEDTLS_MD_MD2,
61 MBEDTLS_MD_MD4,
62 MBEDTLS_MD_MD5,
63 MBEDTLS_MD_SHA1,
64 MBEDTLS_MD_SHA224,
65 MBEDTLS_MD_SHA256,
66 MBEDTLS_MD_SHA384,
67 MBEDTLS_MD_SHA512,
68 MBEDTLS_MD_RIPEMD160,
69 } mbedtls_md_type_t;
70
71 #if defined(MBEDTLS_SHA512_C)
72 #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
73 #else
74 #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
75 #endif
76
77 #if defined(MBEDTLS_SHA512_C)
78 #define MBEDTLS_MD_MAX_BLOCK_SIZE 128
79 #else
80 #define MBEDTLS_MD_MAX_BLOCK_SIZE 64
81 #endif
82
86 typedef struct mbedtls_md_info_t mbedtls_md_info_t;
87
91 typedef struct mbedtls_md_context_t
92 {
94 const mbedtls_md_info_t *md_info;
95
97 void *md_ctx;
98
100 void *hmac_ctx;
101 } mbedtls_md_context_t;
102
114 const int *mbedtls_md_list( void );
115
125 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
126
136 const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
137
146 void mbedtls_md_init( mbedtls_md_context_t *ctx );
147
161 void mbedtls_md_free( mbedtls_md_context_t *ctx );
162
163 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
164 #if defined(MBEDTLS_DEPRECATED_WARNING)
165 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
166 #else
167 #define MBEDTLS_DEPRECATED
168 #endif
169
187 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
188 #undef MBEDTLS_DEPRECATED
189 #endif /* MBEDTLS_DEPRECATED_REMOVED */
190
210 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
211
231 int mbedtls_md_clone( mbedtls_md_context_t *dst,
232 const mbedtls_md_context_t *src );
233
243 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
244
254 mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
255
265 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
266
280 int mbedtls_md_starts( mbedtls_md_context_t *ctx );
281
298 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
299
318 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
319
338 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
339 unsigned char *output );
340
341 #if defined(MBEDTLS_FS_IO)
342
359 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
360 unsigned char *output );
361 #endif /* MBEDTLS_FS_IO */
362
381 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
382 size_t keylen );
383
403 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
404 size_t ilen );
405
424 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
425
441 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
442
465 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
466 const unsigned char *input, size_t ilen,
467 unsigned char *output );
468
469 /* Internal use */
470 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
471
472 #ifdef __cplusplus
473 }
474 #endif
475
476 #endif /* MBEDTLS_MD_H */
mbedtls_md_free
void mbedtls_md_free(mbedtls_md_context_t *ctx)
This function clears the internal structure of ctx and frees any embedded internal structure,...
mbedtls_md_hmac_finish
int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the HMAC operation, and writes the result to the output buffer.
mbedtls_md_type_t
mbedtls_md_type_t
Supported message digests.
Definition: md.h:58
mbedtls_md_init_ctx
int mbedtls_md_init_ctx(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info) MBEDTLS_DEPRECATED
This function selects the message digest algorithm to use, and allocates internal structures.
mbedtls_md_init
void mbedtls_md_init(mbedtls_md_context_t *ctx)
This function initializes a message-digest context without binding it to a particular message-digest ...
mbedtls_md_starts
int mbedtls_md_starts(mbedtls_md_context_t *ctx)
This function starts a message-digest computation.
mbedtls_md
int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the message-digest of a buffer, with respect to a configurable message-diges...
mbedtls_md_get_type
mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info)
This function extracts the message-digest type from the message-digest information structure.
MBEDTLS_MD_NONE
@ MBEDTLS_MD_NONE
Definition: md.h:59
MBEDTLS_MD_MD4
@ MBEDTLS_MD_MD4
Definition: md.h:61
MBEDTLS_MD_SHA224
@ MBEDTLS_MD_SHA224
Definition: md.h:64
mbedtls_md_info_from_type
const mbedtls_md_info_t * mbedtls_md_info_from_type(mbedtls_md_type_t md_type)
This function returns the message-digest information associated with the given digest type.
mbedtls_md_get_name
const char * mbedtls_md_get_name(const mbedtls_md_info_t *md_info)
This function extracts the message-digest name from the message-digest information structure.
MBEDTLS_MD_RIPEMD160
@ MBEDTLS_MD_RIPEMD160
Definition: md.h:68
mbedtls_md_context_t::md_info
const mbedtls_md_info_t * md_info
Definition: md.h:94
MBEDTLS_MD_SHA1
@ MBEDTLS_MD_SHA1
Definition: md.h:63
mbedtls_md_file
int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, unsigned char *output)
This function calculates the message-digest checksum result of the contents of the provided file.
mbedtls_md_clone
int mbedtls_md_clone(mbedtls_md_context_t *dst, const mbedtls_md_context_t *src)
This function clones the state of an message-digest context.
mbedtls_md_setup
int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac)
This function selects the message digest algorithm to use, and allocates internal structures.
mbedtls_md_info_t
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:86
mbedtls_md_context_t::hmac_ctx
void * hmac_ctx
Definition: md.h:100
mbedtls_md_process
int mbedtls_md_process(mbedtls_md_context_t *ctx, const unsigned char *data)
mbedtls_md_hmac_reset
int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx)
This function prepares to authenticate a new message with the same key as the previous HMAC operation...
MBEDTLS_MD_SHA512
@ MBEDTLS_MD_SHA512
Definition: md.h:67
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: md.h:167
mbedtls_md_context_t::md_ctx
void * md_ctx
Definition: md.h:97
mbedtls_md_hmac
int mbedtls_md_hmac(const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output)
This function calculates the full generic HMAC on the input buffer with the provided key.
mbedtls_md_context_t
struct mbedtls_md_context_t mbedtls_md_context_t
mbedtls_md_finish
int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output)
This function finishes the digest operation, and writes the result to the output buffer.
mbedtls_md_info_from_string
const mbedtls_md_info_t * mbedtls_md_info_from_string(const char *md_name)
This function returns the message-digest information associated with the given digest name.
config.h
Configuration options (set of defines)
mbedtls_md_update
int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing message-digest computation.
mbedtls_md_context_t
Definition: md.h:92
MBEDTLS_MD_SHA384
@ MBEDTLS_MD_SHA384
Definition: md.h:66
mbedtls_md_list
const int * mbedtls_md_list(void)
This function returns the list of digests supported by the generic digest module.
mbedtls_md_hmac_update
int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen)
This function feeds an input buffer into an ongoing HMAC computation.
MBEDTLS_MD_MD2
@ MBEDTLS_MD_MD2
Definition: md.h:60
mbedtls_md_get_size
unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info)
This function extracts the message-digest size from the message-digest information structure.
MBEDTLS_MD_SHA256
@ MBEDTLS_MD_SHA256
Definition: md.h:65
MBEDTLS_MD_MD5
@ MBEDTLS_MD_MD5
Definition: md.h:62
mbedtls_md_hmac_starts
int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen)
This function sets the HMAC key and prepares to authenticate a new message.