mbed TLS v2.16.7
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 OR GPL-2.0-or-later
11  *
12  * This file is provided under the Apache License 2.0, or the
13  * GNU General Public License v2.0 or later.
14  *
15  * **********
16  * Apache License 2.0:
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License"); you may
19  * not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
26  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  *
30  * **********
31  *
32  * **********
33  * GNU General Public License v2.0 or later:
34  *
35  * This program is free software; you can redistribute it and/or modify
36  * it under the terms of the GNU General Public License as published by
37  * the Free Software Foundation; either version 2 of the License, or
38  * (at your option) any later version.
39  *
40  * This program is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43  * GNU General Public License for more details.
44  *
45  * You should have received a copy of the GNU General Public License along
46  * with this program; if not, write to the Free Software Foundation, Inc.,
47  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
48  *
49  * **********
50  *
51  * This file is part of Mbed TLS (https://tls.mbed.org)
52  */
53 
54 #ifndef MBEDTLS_MD_H
55 #define MBEDTLS_MD_H
56 
57 #include <stddef.h>
58 
59 #if !defined(MBEDTLS_CONFIG_FILE)
60 #include "config.h"
61 #else
62 #include MBEDTLS_CONFIG_FILE
63 #endif
64 
65 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
66 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
67 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
68 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
70 /* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */
71 #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
85 typedef enum {
97 
98 #if defined(MBEDTLS_SHA512_C)
99 #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
100 #else
101 #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
102 #endif
103 
108 
112 typedef struct mbedtls_md_context_t
113 {
116 
118  void *md_ctx;
119 
121  void *hmac_ctx;
123 
135 const int *mbedtls_md_list( void );
136 
146 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
147 
158 
168 
183 
184 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
185 #if defined(MBEDTLS_DEPRECATED_WARNING)
186 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
187 #else
188 #define MBEDTLS_DEPRECATED
189 #endif
190 
209 #undef MBEDTLS_DEPRECATED
210 #endif /* MBEDTLS_DEPRECATED_REMOVED */
211 
231 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
232 
253  const mbedtls_md_context_t *src );
254 
264 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
265 
276 
286 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
287 
302 
319 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
320 
339 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
340 
359 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
360  unsigned char *output );
361 
362 #if defined(MBEDTLS_FS_IO)
363 
380 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
381  unsigned char *output );
382 #endif /* MBEDTLS_FS_IO */
383 
402 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
403  size_t keylen );
404 
424 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
425  size_t ilen );
426 
445 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
446 
463 
486 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
487  const unsigned char *input, size_t ilen,
488  unsigned char *output );
489 
490 /* Internal use */
491 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
492 
493 #ifdef __cplusplus
494 }
495 #endif
496 
497 #endif /* MBEDTLS_MD_H */
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...
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_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...
int mbedtls_md_starts(mbedtls_md_context_t *ctx)
This function starts a message-digest computation.
void * hmac_ctx
Definition: md.h:121
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.
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 ...
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.
void * md_ctx
Definition: md.h:118
Configuration options (set of defines)
int mbedtls_md_process(mbedtls_md_context_t *ctx, const unsigned char *data)
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...
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.
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...
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...
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...
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.
#define MBEDTLS_DEPRECATED
Definition: md.h:188
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
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...
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...
struct mbedtls_md_info_t mbedtls_md_info_t
Definition: md.h:107
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.
mbedtls_md_type_t
Supported message digests.
Definition: md.h:85
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...
const mbedtls_md_info_t * md_info
Definition: md.h:115
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.