00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MBEDTLS_MD_H
00028 #define MBEDTLS_MD_H
00029
00030 #include <stddef.h>
00031
00032 #if !defined(MBEDTLS_CONFIG_FILE)
00033 #include "config.h"
00034 #else
00035 #include MBEDTLS_CONFIG_FILE
00036 #endif
00037
00038 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
00039 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
00040 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
00041 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
00042 #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047
00056 typedef enum {
00057 MBEDTLS_MD_NONE=0,
00058 MBEDTLS_MD_MD2,
00059 MBEDTLS_MD_MD4,
00060 MBEDTLS_MD_MD5,
00061 MBEDTLS_MD_SHA1,
00062 MBEDTLS_MD_SHA224,
00063 MBEDTLS_MD_SHA256,
00064 MBEDTLS_MD_SHA384,
00065 MBEDTLS_MD_SHA512,
00066 MBEDTLS_MD_RIPEMD160,
00067 } mbedtls_md_type_t;
00068
00069 #if defined(MBEDTLS_SHA512_C)
00070 #define MBEDTLS_MD_MAX_SIZE 64
00071 #else
00072 #define MBEDTLS_MD_MAX_SIZE 32
00073 #endif
00074
00078 typedef struct mbedtls_md_info_t mbedtls_md_info_t;
00079
00083 typedef struct {
00085 const mbedtls_md_info_t *md_info;
00086
00088 void *md_ctx;
00089
00091 void *hmac_ctx;
00092 } mbedtls_md_context_t;
00093
00103 const int *mbedtls_md_list( void );
00104
00114 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
00115
00125 const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
00126
00135 void mbedtls_md_init( mbedtls_md_context_t *ctx );
00136
00150 void mbedtls_md_free( mbedtls_md_context_t *ctx );
00151
00152 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
00153 #if defined(MBEDTLS_DEPRECATED_WARNING)
00154 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
00155 #else
00156 #define MBEDTLS_DEPRECATED
00157 #endif
00158
00175 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
00176 #undef MBEDTLS_DEPRECATED
00177 #endif
00178
00197 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
00198
00218 int mbedtls_md_clone( mbedtls_md_context_t *dst,
00219 const mbedtls_md_context_t *src );
00220
00230 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
00231
00241 mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
00242
00252 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
00253
00266 int mbedtls_md_starts( mbedtls_md_context_t *ctx );
00267
00283 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
00284
00302 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
00303
00321 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
00322 unsigned char *output );
00323
00324 #if defined(MBEDTLS_FS_IO)
00325
00341 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
00342 unsigned char *output );
00343 #endif
00344
00362 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
00363 size_t keylen );
00364
00383 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
00384 size_t ilen );
00385
00403 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
00404
00419 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
00420
00442 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
00443 const unsigned char *input, size_t ilen,
00444 unsigned char *output );
00445
00446
00447 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
00448
00449 #ifdef __cplusplus
00450 }
00451 #endif
00452
00453 #endif