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 #ifndef MBEDTLS_MD_H
00053 #define MBEDTLS_MD_H
00054
00055 #include <stddef.h>
00056
00057 #if !defined(MBEDTLS_CONFIG_FILE)
00058 #include "config.h"
00059 #else
00060 #include MBEDTLS_CONFIG_FILE
00061 #endif
00062
00063 #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080
00064 #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100
00065 #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180
00066 #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200
00067 #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280
00069 #ifdef __cplusplus
00070 extern "C" {
00071 #endif
00072
00081 typedef enum {
00082 MBEDTLS_MD_NONE=0,
00083 MBEDTLS_MD_MD2,
00084 MBEDTLS_MD_MD4,
00085 MBEDTLS_MD_MD5,
00086 MBEDTLS_MD_SHA1,
00087 MBEDTLS_MD_SHA224,
00088 MBEDTLS_MD_SHA256,
00089 MBEDTLS_MD_SHA384,
00090 MBEDTLS_MD_SHA512,
00091 MBEDTLS_MD_RIPEMD160,
00092 } mbedtls_md_type_t;
00093
00094 #if defined(MBEDTLS_SHA512_C)
00095 #define MBEDTLS_MD_MAX_SIZE 64
00096 #else
00097 #define MBEDTLS_MD_MAX_SIZE 32
00098 #endif
00099
00103 typedef struct mbedtls_md_info_t mbedtls_md_info_t;
00104
00108 typedef struct {
00110 const mbedtls_md_info_t *md_info;
00111
00113 void *md_ctx;
00114
00116 void *hmac_ctx;
00117 } mbedtls_md_context_t;
00118
00130 const int *mbedtls_md_list( void );
00131
00141 const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
00142
00152 const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
00153
00162 void mbedtls_md_init( mbedtls_md_context_t *ctx );
00163
00177 void mbedtls_md_free( mbedtls_md_context_t *ctx );
00178
00179 #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
00180 #if defined(MBEDTLS_DEPRECATED_WARNING)
00181 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
00182 #else
00183 #define MBEDTLS_DEPRECATED
00184 #endif
00185
00202 int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
00203 #undef MBEDTLS_DEPRECATED
00204 #endif
00205
00224 int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
00225
00245 int mbedtls_md_clone( mbedtls_md_context_t *dst,
00246 const mbedtls_md_context_t *src );
00247
00257 unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
00258
00268 mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
00269
00279 const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
00280
00293 int mbedtls_md_starts( mbedtls_md_context_t *ctx );
00294
00310 int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
00311
00329 int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
00330
00348 int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
00349 unsigned char *output );
00350
00351 #if defined(MBEDTLS_FS_IO)
00352
00368 int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
00369 unsigned char *output );
00370 #endif
00371
00389 int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
00390 size_t keylen );
00391
00410 int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
00411 size_t ilen );
00412
00430 int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
00431
00446 int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
00447
00469 int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
00470 const unsigned char *input, size_t ilen,
00471 unsigned char *output );
00472
00473
00474 int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
00475
00476 #ifdef __cplusplus
00477 }
00478 #endif
00479
00480 #endif