mbed TLS v3.1.0
md.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright The Mbed TLS Contributors
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 
25 #ifndef MBEDTLS_MD_H
26 #define MBEDTLS_MD_H
27 #include "mbedtls/private_access.h"
28 
29 #include <stddef.h>
30 
31 #include "mbedtls/build_info.h"
32 #include "mbedtls/platform_util.h"
33 
35 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
36 
37 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
38 
39 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
40 
41 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
55 typedef enum {
65 
66 #if defined(MBEDTLS_SHA512_C)
67 #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
68 #else
69 #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
70 #endif
71 
72 #if defined(MBEDTLS_SHA512_C)
73 #define MBEDTLS_MD_MAX_BLOCK_SIZE 128
74 #else
75 #define MBEDTLS_MD_MAX_BLOCK_SIZE 64
76 #endif
77 
87 /* Defined internally in library/md_wrap.h. */
89 
93 typedef struct mbedtls_md_context_t
94 {
97 
99  void *MBEDTLS_PRIVATE(md_ctx);
100 
102  void *MBEDTLS_PRIVATE(hmac_ctx);
104 
116 const int *mbedtls_md_list( void );
117 
127 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
128 
139 
149 
164 
165 
186 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
187 
209  const mbedtls_md_context_t *src );
210 
220 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
221 
232 
242 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
243 
259 
277 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
278 
298 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
299 
319 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
320  unsigned char *output );
321 
322 #if defined(MBEDTLS_FS_IO)
323 
341 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
342  unsigned char *output );
343 #endif /* MBEDTLS_FS_IO */
344 
364 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
365  size_t keylen );
366 
387 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
388  size_t ilen );
389 
409 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
410 
428 
452 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
453  const unsigned char *input, size_t ilen,
454  unsigned char *output );
455 
456 /* Internal use */
458 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
459 
460 #ifdef __cplusplus
461 }
462 #endif
463 
464 #endif /* MBEDTLS_MD_H */
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_CHECK_RETURN_TYPICAL int mbedtls_md_starts(mbedtls_md_context_t *ctx)
This function starts a message-digest computation.
#define MBEDTLS_CHECK_RETURN_TYPICAL
MBEDTLS_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL int mbedtls_md_process(mbedtls_md_context_t *ctx, const unsigned char *data)
void mbedtls_md_free(mbedtls_md_context_t *ctx)
This function clears the internal structure of ctx and frees any embedded internal structure...
void mbedtls_md_init(mbedtls_md_context_t *ctx)
This function initializes a message-digest context without binding it to a particular message-digest ...
#define MBEDTLS_PRIVATE(member)
MBEDTLS_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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...
Common and shared functions used by multiple modules in the Mbed TLS library.
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_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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.
Macro wrapper for struct's memebrs.
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...
struct mbedtls_md_context_t mbedtls_md_context_t
Build-time configuration info.
const int * mbedtls_md_list(void)
This function returns the list of digests supported by the generic digest module. ...
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_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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.
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:88
mbedtls_md_type_t
Supported message digests.
Definition: md.h:55
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...
MBEDTLS_CHECK_RETURN_TYPICAL 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...