Generic message digest wrapper. More...
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | md_info_t |
Message digest information. More... | |
struct | md_context_t |
Generic message digest context. More... | |
Defines | |
#define | POLARSSL_ERR_MD_FEATURE_UNAVAILABLE -0x5080 |
The selected feature is not available. | |
#define | POLARSSL_ERR_MD_BAD_INPUT_DATA -0x5100 |
Bad input parameters to function. | |
#define | POLARSSL_ERR_MD_ALLOC_FAILED -0x5180 |
Failed to allocate memory. | |
#define | POLARSSL_ERR_MD_FILE_IO_ERROR -0x5200 |
Opening or reading of file failed. | |
#define | POLARSSL_MD_MAX_SIZE 64 |
#define | MD_CONTEXT_T_INIT |
Enumerations | |
enum | md_type_t { POLARSSL_MD_NONE = 0, POLARSSL_MD_MD2, POLARSSL_MD_MD4, POLARSSL_MD_MD5, POLARSSL_MD_SHA1, POLARSSL_MD_SHA224, POLARSSL_MD_SHA256, POLARSSL_MD_SHA384, POLARSSL_MD_SHA512 } |
Functions | |
const int * | md_list (void) |
Returns the list of digests supported by the generic digest module. | |
const md_info_t * | md_info_from_string (const char *md_name) |
Returns the message digest information associated with the given digest name. | |
const md_info_t * | md_info_from_type (md_type_t md_type) |
Returns the message digest information associated with the given digest type. | |
int | md_init_ctx (md_context_t *ctx, const md_info_t *md_info) |
Initialises and fills the message digest context structure with the appropriate values. | |
int | md_free_ctx (md_context_t *ctx) |
Free the message-specific context of ctx. | |
static unsigned char | md_get_size (const md_info_t *md_info) |
Returns the size of the message digest output. | |
static md_type_t | md_get_type (const md_info_t *md_info) |
Returns the type of the message digest output. | |
static const char * | md_get_name (const md_info_t *md_info) |
Returns the name of the message digest output. | |
int | md_starts (md_context_t *ctx) |
Set-up the given context for a new message digest. | |
int | md_update (md_context_t *ctx, const unsigned char *input, size_t ilen) |
Generic message digest process buffer. | |
int | md_finish (md_context_t *ctx, unsigned char *output) |
Generic message digest final digest. | |
int | md (const md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output) |
Output = message_digest( input buffer ). | |
int | md_file (const md_info_t *md_info, const char *path, unsigned char *output) |
Output = message_digest( file contents ). | |
int | md_hmac_starts (md_context_t *ctx, const unsigned char *key, size_t keylen) |
Generic HMAC context setup. | |
int | md_hmac_update (md_context_t *ctx, const unsigned char *input, size_t ilen) |
Generic HMAC process buffer. | |
int | md_hmac_finish (md_context_t *ctx, unsigned char *output) |
Generic HMAC final digest. | |
int | md_hmac_reset (md_context_t *ctx) |
Generic HMAC context reset. | |
int | md_hmac (const md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char *output) |
Output = Generic_HMAC( hmac key, input buffer ). | |
int | md_process (md_context_t *ctx, const unsigned char *data) |
Generic message digest wrapper.
Copyright (C) 2006-2013, Brainspark B.V.
This file is part of PolarSSL (http://www.polarssl.org) Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Definition in file md.h.
#define MD_CONTEXT_T_INIT |
{ \ NULL, /* md_info */ \ NULL, /* md_ctx */ \ }
Definition at line 137 of file md.h.
Referenced by test_suite_md_hex_multi(), test_suite_md_hmac_multi(), and test_suite_md_text_multi().
#define POLARSSL_ERR_MD_ALLOC_FAILED -0x5180 |
Failed to allocate memory.
Definition at line 44 of file md.h.
Referenced by md_init_ctx(), and polarssl_strerror().
#define POLARSSL_ERR_MD_BAD_INPUT_DATA -0x5100 |
Bad input parameters to function.
Definition at line 43 of file md.h.
Referenced by md(), md_file(), md_finish(), md_free_ctx(), md_hmac(), md_hmac_finish(), md_hmac_reset(), md_hmac_starts(), md_hmac_update(), md_init_ctx(), md_process(), md_starts(), md_update(), and polarssl_strerror().
#define POLARSSL_ERR_MD_FEATURE_UNAVAILABLE -0x5080 |
The selected feature is not available.
Definition at line 42 of file md.h.
Referenced by md5_file_wrap(), md_file(), polarssl_strerror(), sha1_file_wrap(), sha224_file_wrap(), sha256_file_wrap(), sha384_file_wrap(), and sha512_file_wrap().
#define POLARSSL_ERR_MD_FILE_IO_ERROR -0x5200 |
Opening or reading of file failed.
Definition at line 45 of file md.h.
Referenced by md_file(), and polarssl_strerror().
#define POLARSSL_MD_MAX_SIZE 64 |
Definition at line 64 of file md.h.
Referenced by mgf_mask(), pkcs12_derivation(), pkcs5_pbkdf2_hmac(), rsa_rsaes_oaep_decrypt(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), x509_crt_verify_child(), x509_crt_verify_top(), and x509_crt_verifycrl().
enum md_type_t |
int md | ( | const md_info_t * | md_info, | |
const unsigned char * | input, | |||
size_t | ilen, | |||
unsigned char * | output | |||
) |
Output = message_digest( input buffer ).
md_info | message digest info | |
input | buffer holding the data | |
ilen | length of the input data | |
output | Generic message digest checksum result |
Definition at line 212 of file md.c.
References md_info_t::digest_func, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by pkcs12_derivation(), rsa_rsaes_oaep_decrypt(), rsa_rsaes_oaep_encrypt(), test_suite_md_hex(), test_suite_md_text(), test_suite_pk_rsa_verify_test_vec(), test_suite_pkcs1_rsassa_pss_sign(), test_suite_pkcs1_rsassa_pss_verify(), test_suite_rsa_pkcs1_sign(), test_suite_rsa_pkcs1_verify(), x509_crt_verify_child(), x509_crt_verify_top(), x509_crt_verifycrl(), x509write_crt_der(), and x509write_csr_der().
int md_file | ( | const md_info_t * | md_info, | |
const char * | path, | |||
unsigned char * | output | |||
) |
Output = message_digest( file contents ).
md_info | message digest info | |
path | input file name | |
output | generic message digest checksum result |
Definition at line 223 of file md.c.
References md_info_t::file_func, POLARSSL_ERR_MD_BAD_INPUT_DATA, POLARSSL_ERR_MD_FEATURE_UNAVAILABLE, and POLARSSL_ERR_MD_FILE_IO_ERROR.
Referenced by test_suite_md_file().
int md_finish | ( | md_context_t * | ctx, | |
unsigned char * | output | |||
) |
Generic message digest final digest.
ctx | Generic message digest context | |
output | Generic message digest checksum result |
Definition at line 202 of file md.c.
References md_info_t::finish_func, md_context_t::md_ctx, md_context_t::md_info, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by mgf_mask(), pkcs12_derivation(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_mac(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), test_suite_md_hex_multi(), and test_suite_md_text_multi().
int md_free_ctx | ( | md_context_t * | ctx | ) |
Free the message-specific context of ctx.
Freeing ctx itself remains the responsibility of the caller.
ctx | Free the message-specific context |
Definition at line 171 of file md.c.
References md_info_t::ctx_free_func, md_context_t::md_ctx, md_context_t::md_info, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by pkcs12_derivation(), pkcs5_pbes2(), pkcs5_self_test(), rsa_rsaes_oaep_decrypt(), rsa_rsaes_oaep_encrypt(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_parse_server_key_exchange(), ssl_transform_free(), ssl_write_server_key_exchange(), test_suite_md_hex_multi(), test_suite_md_hmac_multi(), test_suite_md_text_multi(), and test_suite_pbkdf2_hmac().
static const char* md_get_name | ( | const md_info_t * | md_info | ) | [inline, static] |
Returns the name of the message digest output.
md_info | message digest info |
Definition at line 235 of file md.h.
References md_info_t::name.
static unsigned char md_get_size | ( | const md_info_t * | md_info | ) | [inline, static] |
Returns the size of the message digest output.
md_info | message digest info |
Definition at line 205 of file md.h.
References md_info_t::size.
Referenced by pkcs12_derivation(), pkcs5_pbkdf2_hmac(), rsa_rsaes_oaep_decrypt(), rsa_rsaes_oaep_encrypt(), rsa_rsassa_pkcs1_v15_sign(), rsa_rsassa_pkcs1_v15_verify(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_derive_keys(), ssl_mac(), test_suite_md_file(), test_suite_md_hex(), test_suite_md_hex_multi(), test_suite_md_hmac(), test_suite_md_hmac_multi(), test_suite_md_text(), and test_suite_md_text_multi().
Returns the type of the message digest output.
md_info | message digest info |
Definition at line 220 of file md.h.
References POLARSSL_MD_NONE, and md_info_t::type.
Referenced by ssl_mac().
int md_hmac | ( | const md_info_t * | md_info, | |
const unsigned char * | key, | |||
size_t | keylen, | |||
const unsigned char * | input, | |||
size_t | ilen, | |||
unsigned char * | output | |||
) |
Output = Generic_HMAC( hmac key, input buffer ).
md_info | message digest info | |
key | HMAC secret key | |
keylen | length of the HMAC key | |
input | buffer holding the data | |
ilen | length of the input data | |
output | Generic HMAC-result |
Definition at line 286 of file md.c.
References md_info_t::hmac_func, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by test_suite_md_hmac().
int md_hmac_finish | ( | md_context_t * | ctx, | |
unsigned char * | output | |||
) |
Generic HMAC final digest.
ctx | HMAC context | |
output | Generic HMAC checksum result |
Definition at line 266 of file md.c.
References md_info_t::hmac_finish_func, md_context_t::md_ctx, md_context_t::md_info, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by pkcs5_pbkdf2_hmac(), ssl_decrypt_buf(), ssl_encrypt_buf(), and test_suite_md_hmac_multi().
int md_hmac_reset | ( | md_context_t * | ctx | ) |
Generic HMAC context reset.
ctx | HMAC context to be reset |
Definition at line 276 of file md.c.
References md_info_t::hmac_reset_func, md_context_t::md_ctx, md_context_t::md_info, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by ssl_decrypt_buf(), and ssl_encrypt_buf().
int md_hmac_starts | ( | md_context_t * | ctx, | |
const unsigned char * | key, | |||
size_t | keylen | |||
) |
Generic HMAC context setup.
ctx | HMAC context to be initialized | |
key | HMAC secret key | |
keylen | length of the HMAC key |
Definition at line 246 of file md.c.
References md_info_t::hmac_starts_func, md_context_t::md_ctx, md_context_t::md_info, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by pkcs5_pbkdf2_hmac(), ssl_derive_keys(), and test_suite_md_hmac_multi().
int md_hmac_update | ( | md_context_t * | ctx, | |
const unsigned char * | input, | |||
size_t | ilen | |||
) |
Generic HMAC process buffer.
ctx | HMAC context | |
input | buffer holding the data | |
ilen | length of the input data |
Definition at line 256 of file md.c.
References md_info_t::hmac_update_func, md_context_t::md_ctx, md_context_t::md_info, and POLARSSL_ERR_MD_BAD_INPUT_DATA.
Referenced by pkcs5_pbkdf2_hmac(), ssl_decrypt_buf(), ssl_encrypt_buf(), and test_suite_md_hmac_multi().
const md_info_t* md_info_from_string | ( | const char * | md_name | ) |
Returns the message digest information associated with the given digest name.
md_name | Name of the digest to search for. |
Definition at line 80 of file md.c.
References md_info_from_type(), POLARSSL_MD_MD2, POLARSSL_MD_MD4, POLARSSL_MD_MD5, POLARSSL_MD_SHA1, POLARSSL_MD_SHA224, POLARSSL_MD_SHA256, POLARSSL_MD_SHA384, and POLARSSL_MD_SHA512.
Referenced by test_suite_md_file(), test_suite_md_hex(), test_suite_md_hex_multi(), test_suite_md_hmac(), test_suite_md_hmac_multi(), test_suite_md_text(), and test_suite_md_text_multi().
Returns the message digest information associated with the given digest type.
md_type | type of digest to search for. |
Definition at line 117 of file md.c.
References md5_info, POLARSSL_MD_MD2, POLARSSL_MD_MD4, POLARSSL_MD_MD5, POLARSSL_MD_SHA1, POLARSSL_MD_SHA224, POLARSSL_MD_SHA256, POLARSSL_MD_SHA384, POLARSSL_MD_SHA512, sha1_info, sha224_info, sha256_info, sha384_info, and sha512_info.
Referenced by md_info_from_string(), pk_hashlen_helper(), pkcs12_derivation(), pkcs5_pbes2(), pkcs5_self_test(), rsa_rsaes_oaep_decrypt(), rsa_rsaes_oaep_encrypt(), rsa_rsassa_pkcs1_v15_sign(), rsa_rsassa_pkcs1_v15_verify(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_derive_keys(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), test_suite_pbkdf2_hmac(), test_suite_pk_rsa_verify_test_vec(), test_suite_pkcs1_rsassa_pss_sign(), test_suite_pkcs1_rsassa_pss_verify(), test_suite_rsa_pkcs1_sign(), test_suite_rsa_pkcs1_verify(), x509_crt_verify_child(), x509_crt_verify_top(), x509_crt_verifycrl(), x509write_crt_der(), and x509write_csr_der().
int md_init_ctx | ( | md_context_t * | ctx, | |
const md_info_t * | md_info | |||
) |
Initialises and fills the message digest context structure with the appropriate values.
ctx | context to initialise. May not be NULL. The digest-specific context (ctx->md_ctx) must be NULL. It will be allocated, and must be freed using md_free_ctx() later. | |
md_info | message digest to use. |
0
on success, POLARSSL_ERR_MD_BAD_INPUT_DATA
on parameter failure, POLARSSL_ERR_MD_ALLOC_FAILED
if allocation of the digest-specific context failed. Definition at line 154 of file md.c.
References md_info_t::ctx_alloc_func, md_context_t::md_ctx, md_context_t::md_info, POLARSSL_ERR_MD_ALLOC_FAILED, POLARSSL_ERR_MD_BAD_INPUT_DATA, and md_info_t::starts_func.
Referenced by pkcs12_derivation(), pkcs5_pbes2(), pkcs5_self_test(), rsa_rsaes_oaep_decrypt(), rsa_rsaes_oaep_encrypt(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_derive_keys(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), test_suite_md_hex_multi(), test_suite_md_hmac_multi(), test_suite_md_text_multi(), and test_suite_pbkdf2_hmac().
const int* md_list | ( | void | ) |
Returns the list of digests supported by the generic digest module.
Definition at line 75 of file md.c.
References supported_digests.
int md_process | ( | md_context_t * | ctx, | |
const unsigned char * | data | |||
) |
Definition at line 298 of file md.c.
References md_context_t::md_ctx, md_context_t::md_info, POLARSSL_ERR_MD_BAD_INPUT_DATA, and md_info_t::process_func.
Referenced by ssl_decrypt_buf().
int md_starts | ( | md_context_t * | ctx | ) |
Set-up the given context for a new message digest.
ctx | generic message digest context. |
Definition at line 182 of file md.c.
References md_context_t::md_ctx, md_context_t::md_info, POLARSSL_ERR_MD_BAD_INPUT_DATA, and md_info_t::starts_func.
Referenced by mgf_mask(), pkcs12_derivation(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_mac(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), test_suite_md_hex_multi(), and test_suite_md_text_multi().
int md_update | ( | md_context_t * | ctx, | |
const unsigned char * | input, | |||
size_t | ilen | |||
) |
Generic message digest process buffer.
ctx | Generic message digest context | |
input | buffer holding the datal | |
ilen | length of the input data |
Definition at line 192 of file md.c.
References md_context_t::md_ctx, md_context_t::md_info, POLARSSL_ERR_MD_BAD_INPUT_DATA, and md_info_t::update_func.
Referenced by mgf_mask(), pkcs12_derivation(), rsa_rsassa_pss_sign(), rsa_rsassa_pss_verify(), ssl_mac(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), test_suite_md_hex_multi(), and test_suite_md_text_multi().