00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef MBEDTLS_MD_H
00055 #define MBEDTLS_MD_H
00056
00057 #include <stddef.h>
00058
00059 #if !defined(MBEDTLS_CONFIG_FILE)
00060 #include "config.h"
00061 #else
00062 #include MBEDTLS_CONFIG_FILE
00063 #endif
00064
00065 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
00066 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
00067 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
00068 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
00069 #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
00071 #ifdef __cplusplus
00072 extern "C" {
00073 #endif
00074
00083 typedef enum {
00084 MBEDTLS_MD_NONE=0,
00085 MBEDTLS_MD_MD2,
00086 MBEDTLS_MD_MD4,
00087 MBEDTLS_MD_MD5,
00088 MBEDTLS_MD_SHA1,
00089 MBEDTLS_MD_SHA224,
00090 MBEDTLS_MD_SHA256,
00091 MBEDTLS_MD_SHA384,
00092 MBEDTLS_MD_SHA512,
00093 MBEDTLS_MD_RIPEMD160,
00094 } mbedtls_md_type_t;
00095
00096 #if defined(MBEDTLS_SHA512_C)
00097 #define MBEDTLS_MD_MAX_SIZE 64
00098 #else
00099 #define MBEDTLS_MD_MAX_SIZE 32
00100 #endif
00101
00105 typedef struct mbedtls_md_info_t mbedtls_md_info_t;
00106
00110 typedef struct {
00112 const mbedtls_md_info_t *md_info;
00113
00115 void *md_ctx;
00116
00118 void *hmac_ctx;
00119 } mbedtls_md_context_t;
00120
00132 const int *mbedtls_md_list( void );
00133
00143 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
00144
00154 const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
00155
00164 void mbedtls_md_init( mbedtls_md_context_t *ctx );
00165
00179 void mbedtls_md_free( mbedtls_md_context_t *ctx );
00180
00181 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
00182 #if defined(MBEDTLS_DEPRECATED_WARNING)
00183 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
00184 #else
00185 #define MBEDTLS_DEPRECATED
00186 #endif
00187
00204 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
00205 #undef MBEDTLS_DEPRECATED
00206 #endif
00207
00226 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
00227
00247 int mbedtls_md_clone( mbedtls_md_context_t *dst,
00248 const mbedtls_md_context_t *src );
00249
00259 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
00260
00270 mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
00271
00281 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
00282
00295 int mbedtls_md_starts( mbedtls_md_context_t *ctx );
00296
00312 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
00313
00331 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
00332
00350 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
00351 unsigned char *output );
00352
00353 #if defined(MBEDTLS_FS_IO)
00354
00370 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
00371 unsigned char *output );
00372 #endif
00373
00391 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
00392 size_t keylen );
00393
00412 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
00413 size_t ilen );
00414
00432 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
00433
00448 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
00449
00471 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
00472 const unsigned char *input, size_t ilen,
00473 unsigned char *output );
00474
00475
00476 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
00477
00478 #ifdef __cplusplus
00479 }
00480 #endif
00481
00482 #endif