#include "polarssl/config.h"#include "polarssl/sha1.h"#include <stdio.h>
Go to the source code of this file.
Defines | |
| #define | S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) |
| #define | R(t) |
| #define | P(a, b, c, d, e, x) |
| #define | F(x, y, z) (z ^ (x & (y ^ z))) |
| #define | K 0x5A827999 |
| #define | F(x, y, z) (x ^ y ^ z) |
| #define | K 0x6ED9EBA1 |
| #define | F(x, y, z) ((x & y) | (z & (x | y))) |
| #define | K 0x8F1BBCDC |
| #define | F(x, y, z) (x ^ y ^ z) |
| #define | K 0xCA62C1D6 |
Functions | |
| void | sha1_starts (sha1_context *ctx) |
| SHA-1 context setup. | |
| void | sha1_process (sha1_context *ctx, const unsigned char data[64]) |
| void | sha1_update (sha1_context *ctx, const unsigned char *input, size_t ilen) |
| SHA-1 process buffer. | |
| void | sha1_finish (sha1_context *ctx, unsigned char output[20]) |
| SHA-1 final digest. | |
| void | sha1 (const unsigned char *input, size_t ilen, unsigned char output[20]) |
| Output = SHA-1( input buffer ). | |
| int | sha1_file (const char *path, unsigned char output[20]) |
| Output = SHA-1( file contents ). | |
| void | sha1_hmac_starts (sha1_context *ctx, const unsigned char *key, size_t keylen) |
| SHA-1 HMAC context setup. | |
| void | sha1_hmac_update (sha1_context *ctx, const unsigned char *input, size_t ilen) |
| SHA-1 HMAC process buffer. | |
| void | sha1_hmac_finish (sha1_context *ctx, unsigned char output[20]) |
| SHA-1 HMAC final digest. | |
| void | sha1_hmac_reset (sha1_context *ctx) |
| SHA-1 HMAC context reset. | |
| void | sha1_hmac (const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[20]) |
| Output = HMAC-SHA-1( hmac key, input buffer ). | |
| int | sha1_self_test (int verbose) |
| Checkup routine. | |
Variables | |
| static const unsigned char | sha1_padding [64] |
| static unsigned char | sha1_test_buf [3][57] |
| static const int | sha1_test_buflen [3] |
| static const unsigned char | sha1_test_sum [3][20] |
| static unsigned char | sha1_hmac_test_key [7][26] |
| static const int | sha1_hmac_test_keylen [7] |
| static unsigned char | sha1_hmac_test_buf [7][74] |
| static const int | sha1_hmac_test_buflen [7] |
| static const unsigned char | sha1_hmac_test_sum [7][20] |
| #define F | ( | x, | |||
| y, | |||||
| z | ) | (x ^ y ^ z) |
| #define F | ( | x, | |||
| y, | |||||
| z | ) | ((x & y) | (z & (x | y))) |
| #define F | ( | x, | |||
| y, | |||||
| z | ) | (x ^ y ^ z) |
| #define F | ( | x, | |||
| y, | |||||
| z | ) | (z ^ (x & (y ^ z))) |
| #define K 0xCA62C1D6 |
| #define K 0x8F1BBCDC |
| #define K 0x6ED9EBA1 |
| #define K 0x5A827999 |
Referenced by sha512_process().
| #define R | ( | t | ) |
( \
temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \
W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \
( W[t & 0x0F] = S(temp,1) ) \
)
Referenced by ecdsa_sign(), ecdsa_verify(), mpi_is_prime(), sha1_process(), and sha256_process().
| #define S | ( | x, | |||
| n | ) | ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) |
| void sha1 | ( | const unsigned char * | input, | |
| size_t | ilen, | |||
| unsigned char | output[20] | |||
| ) |
Output = SHA-1( input buffer ).
| input | buffer holding the data | |
| ilen | length of the input data | |
| output | SHA-1 checksum result |
Definition at line 319 of file sha1.c.
References sha1_finish(), sha1_starts(), and sha1_update().
Referenced by rsa_self_test(), sha1_hmac_starts(), ssl3_prf(), ssl_calc_finished_ssl(), ssl_calc_finished_tls(), ssl_calc_verify_ssl(), ssl_calc_verify_tls(), ssl_parse_server_key_exchange(), ssl_write_server_key_exchange(), x509write_crt_set_authority_key_identifier(), and x509write_crt_set_subject_key_identifier().
| int sha1_file | ( | const char * | path, | |
| unsigned char | output[20] | |||
| ) |
Output = SHA-1( file contents ).
| path | input file name | |
| output | SHA-1 checksum result |
Definition at line 334 of file sha1.c.
References POLARSSL_ERR_SHA1_FILE_IO_ERROR, sha1_finish(), sha1_starts(), and sha1_update().
Referenced by sha1_file_wrap().
| void sha1_finish | ( | sha1_context * | ctx, | |
| unsigned char | output[20] | |||
| ) |
SHA-1 final digest.
| ctx | SHA-1 context | |
| output | SHA-1 checksum result |
Definition at line 288 of file sha1.c.
References PUT_UINT32_BE, sha1_padding, sha1_update(), sha1_context::state, and sha1_context::total.
Referenced by sha1(), sha1_file(), sha1_finish_wrap(), sha1_hmac_finish(), sha1_self_test(), ssl3_prf(), ssl_calc_finished_ssl(), ssl_calc_finished_tls(), ssl_calc_verify_ssl(), ssl_calc_verify_tls(), ssl_parse_server_key_exchange(), and ssl_write_server_key_exchange().
| void sha1_hmac | ( | const unsigned char * | key, | |
| size_t | keylen, | |||
| const unsigned char * | input, | |||
| size_t | ilen, | |||
| unsigned char | output[20] | |||
| ) |
Output = HMAC-SHA-1( hmac key, input buffer ).
| key | HMAC secret key | |
| keylen | length of the HMAC key | |
| input | buffer holding the data | |
| ilen | length of the input data | |
| output | HMAC-SHA-1 result |
Definition at line 430 of file sha1.c.
References sha1_hmac_finish(), sha1_hmac_starts(), and sha1_hmac_update().
Referenced by tls1_prf().
| void sha1_hmac_finish | ( | sha1_context * | ctx, | |
| unsigned char | output[20] | |||
| ) |
SHA-1 HMAC final digest.
| ctx | HMAC context | |
| output | SHA-1 HMAC checksum result |
Definition at line 405 of file sha1.c.
References sha1_context::opad, sha1_finish(), sha1_starts(), and sha1_update().
Referenced by sha1_hmac(), sha1_hmac_finish_wrap(), and sha1_self_test().
| void sha1_hmac_reset | ( | sha1_context * | ctx | ) |
SHA-1 HMAC context reset.
| ctx | HMAC context to be reset |
Definition at line 421 of file sha1.c.
References sha1_context::ipad, sha1_starts(), and sha1_update().
Referenced by sha1_hmac_reset_wrap().
| void sha1_hmac_starts | ( | sha1_context * | ctx, | |
| const unsigned char * | key, | |||
| size_t | keylen | |||
| ) |
SHA-1 HMAC context setup.
| ctx | HMAC context to be initialized | |
| key | HMAC secret key | |
| keylen | length of the HMAC key |
Definition at line 367 of file sha1.c.
References sha1_context::ipad, sha1_context::opad, sha1(), sha1_starts(), and sha1_update().
Referenced by sha1_hmac(), sha1_hmac_starts_wrap(), and sha1_self_test().
| void sha1_hmac_update | ( | sha1_context * | ctx, | |
| const unsigned char * | input, | |||
| size_t | ilen | |||
| ) |
SHA-1 HMAC process buffer.
| ctx | HMAC context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 397 of file sha1.c.
References sha1_update().
Referenced by sha1_hmac(), sha1_hmac_update_wrap(), and sha1_self_test().
| void sha1_process | ( | sha1_context * | ctx, | |
| const unsigned char | data[64] | |||
| ) |
Definition at line 81 of file sha1.c.
References A, GET_UINT32_BE, P, R, and sha1_context::state.
Referenced by sha1_process_wrap(), and sha1_update().
| int sha1_self_test | ( | int | verbose | ) |
Checkup routine.
Definition at line 538 of file sha1.c.
References sha1_finish(), sha1_hmac_finish(), sha1_hmac_starts(), sha1_hmac_test_buf, sha1_hmac_test_buflen, sha1_hmac_test_key, sha1_hmac_test_keylen, sha1_hmac_test_sum, sha1_hmac_update(), sha1_starts(), sha1_test_buf, sha1_test_buflen, sha1_test_sum, and sha1_update().
| void sha1_starts | ( | sha1_context * | ctx | ) |
SHA-1 context setup.
| ctx | context to be initialized |
Definition at line 69 of file sha1.c.
References sha1_context::state, and sha1_context::total.
Referenced by sha1(), sha1_file(), sha1_hmac_finish(), sha1_hmac_reset(), sha1_hmac_starts(), sha1_self_test(), sha1_starts_wrap(), ssl3_prf(), ssl_calc_finished_ssl(), ssl_calc_verify_ssl(), ssl_handshake_init(), ssl_parse_server_key_exchange(), and ssl_write_server_key_exchange().
| void sha1_update | ( | sha1_context * | ctx, | |
| const unsigned char * | input, | |||
| size_t | ilen | |||
| ) |
SHA-1 process buffer.
| ctx | SHA-1 context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 240 of file sha1.c.
References sha1_context::buffer, sha1_process(), and sha1_context::total.
Referenced by sha1(), sha1_file(), sha1_finish(), sha1_hmac_finish(), sha1_hmac_reset(), sha1_hmac_starts(), sha1_hmac_update(), sha1_self_test(), sha1_update_wrap(), ssl3_prf(), ssl_calc_finished_ssl(), ssl_calc_verify_ssl(), ssl_parse_server_key_exchange(), ssl_update_checksum_md5sha1(), ssl_update_checksum_start(), and ssl_write_server_key_exchange().
unsigned char sha1_hmac_test_buf[7][74] [static] |
{
{ "Hi There" },
{ "what do ya want for nothing?" },
{ "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD" },
{ "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
"\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
"\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
"\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD"
"\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" },
{ "Test With Truncation" },
{ "Test Using Larger Than Block-Size Key - Hash Key First" },
{ "Test Using Larger Than Block-Size Key and Larger"
" Than One Block-Size Data" }
}
Definition at line 492 of file sha1.c.
Referenced by sha1_self_test().
const int sha1_hmac_test_buflen[7] [static] |
{
8, 28, 50, 50, 20, 54, 73
}
Definition at line 512 of file sha1.c.
Referenced by sha1_self_test().
unsigned char sha1_hmac_test_key[7][26] [static] |
{
{ "\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B\x0B"
"\x0B\x0B\x0B\x0B" },
{ "Jefe" },
{ "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
"\xAA\xAA\xAA\xAA" },
{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
"\x11\x12\x13\x14\x15\x16\x17\x18\x19" },
{ "\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C\x0C"
"\x0C\x0C\x0C\x0C" },
{ "" },
{ "" }
}
Definition at line 472 of file sha1.c.
Referenced by sha1_self_test().
const int sha1_hmac_test_keylen[7] [static] |
{
20, 4, 20, 25, 20, 80, 80
}
Definition at line 487 of file sha1.c.
Referenced by sha1_self_test().
const unsigned char sha1_hmac_test_sum[7][20] [static] |
{
{ 0xB6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xE2, 0x8B,
0xC0, 0xB6, 0xFB, 0x37, 0x8C, 0x8E, 0xF1, 0x46, 0xBE, 0x00 },
{ 0xEF, 0xFC, 0xDF, 0x6A, 0xE5, 0xEB, 0x2F, 0xA2, 0xD2, 0x74,
0x16, 0xD5, 0xF1, 0x84, 0xDF, 0x9C, 0x25, 0x9A, 0x7C, 0x79 },
{ 0x12, 0x5D, 0x73, 0x42, 0xB9, 0xAC, 0x11, 0xCD, 0x91, 0xA3,
0x9A, 0xF4, 0x8A, 0xA1, 0x7B, 0x4F, 0x63, 0xF1, 0x75, 0xD3 },
{ 0x4C, 0x90, 0x07, 0xF4, 0x02, 0x62, 0x50, 0xC6, 0xBC, 0x84,
0x14, 0xF9, 0xBF, 0x50, 0xC8, 0x6C, 0x2D, 0x72, 0x35, 0xDA },
{ 0x4C, 0x1A, 0x03, 0x42, 0x4B, 0x55, 0xE0, 0x7F, 0xE7, 0xF2,
0x7B, 0xE1 },
{ 0xAA, 0x4A, 0xE5, 0xE1, 0x52, 0x72, 0xD0, 0x0E, 0x95, 0x70,
0x56, 0x37, 0xCE, 0x8A, 0x3B, 0x55, 0xED, 0x40, 0x21, 0x12 },
{ 0xE8, 0xE9, 0x9D, 0x0F, 0x45, 0x23, 0x7D, 0x78, 0x6D, 0x6B,
0xBA, 0xA7, 0x96, 0x5C, 0x78, 0x08, 0xBB, 0xFF, 0x1A, 0x91 }
}
Definition at line 517 of file sha1.c.
Referenced by sha1_self_test().
const unsigned char sha1_padding[64] [static] |
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
Definition at line 277 of file sha1.c.
Referenced by sha1_finish().
unsigned char sha1_test_buf[3][57] [static] |
{
{ "abc" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
{ "" }
}
Definition at line 447 of file sha1.c.
Referenced by sha1_self_test().
const int sha1_test_buflen[3] [static] |
{
3, 56, 1000
}
Definition at line 454 of file sha1.c.
Referenced by sha1_self_test().
const unsigned char sha1_test_sum[3][20] [static] |
{
{ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
{ 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
{ 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E,
0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F }
}
Definition at line 459 of file sha1.c.
Referenced by sha1_self_test().
1.6.1