#include "polarssl/config.h"#include "polarssl/sha256.h"#include <stdio.h>
Go to the source code of this file.
Defines | |
| #define | SHR(x, n) ((x & 0xFFFFFFFF) >> n) |
| #define | ROTR(x, n) (SHR(x,n) | (x << (32 - n))) |
| #define | S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) |
| #define | S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) |
| #define | S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) |
| #define | S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) |
| #define | F0(x, y, z) ((x & y) | (z & (x | y))) |
| #define | F1(x, y, z) (z ^ (x & (y ^ z))) |
| #define | R(t) |
| #define | P(a, b, c, d, e, f, g, h, x, K) |
Functions | |
| void | sha256_starts (sha256_context *ctx, int is224) |
| SHA-256 context setup. | |
| void | sha256_process (sha256_context *ctx, const unsigned char data[64]) |
| void | sha256_update (sha256_context *ctx, const unsigned char *input, size_t ilen) |
| SHA-256 process buffer. | |
| void | sha256_finish (sha256_context *ctx, unsigned char output[32]) |
| SHA-256 final digest. | |
| void | sha256 (const unsigned char *input, size_t ilen, unsigned char output[32], int is224) |
| Output = SHA-256( input buffer ). | |
| int | sha256_file (const char *path, unsigned char output[32], int is224) |
| Output = SHA-256( file contents ). | |
| void | sha256_hmac_starts (sha256_context *ctx, const unsigned char *key, size_t keylen, int is224) |
| SHA-256 HMAC context setup. | |
| void | sha256_hmac_update (sha256_context *ctx, const unsigned char *input, size_t ilen) |
| SHA-256 HMAC process buffer. | |
| void | sha256_hmac_finish (sha256_context *ctx, unsigned char output[32]) |
| SHA-256 HMAC final digest. | |
| void | sha256_hmac_reset (sha256_context *ctx) |
| SHA-256 HMAC context reset. | |
| void | sha256_hmac (const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[32], int is224) |
| Output = HMAC-SHA-256( hmac key, input buffer ). | |
| int | sha256_self_test (int verbose) |
| Checkup routine. | |
Variables | |
| static const unsigned char | sha256_padding [64] |
| static unsigned char | sha256_test_buf [3][57] |
| static const int | sha256_test_buflen [3] |
| static const unsigned char | sha256_test_sum [6][32] |
| static unsigned char | sha256_hmac_test_key [7][26] |
| static const int | sha256_hmac_test_keylen [7] |
| static unsigned char | sha256_hmac_test_buf [7][153] |
| static const int | sha256_hmac_test_buflen [7] |
| static const unsigned char | sha256_hmac_test_sum [14][32] |
| #define F0 | ( | x, | |||
| y, | |||||
| z | ) | ((x & y) | (z & (x | y))) |
| #define F1 | ( | x, | |||
| y, | |||||
| z | ) | (z ^ (x & (y ^ z))) |
| #define ROTR | ( | x, | |||
| n | ) | (SHR(x,n) | (x << (32 - n))) |
| #define S0 | ( | x | ) | (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) |
Referenced by sha512_process().
| #define S1 | ( | x | ) | (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) |
Referenced by sha512_process(), and tls1_prf().
| #define S2 | ( | x | ) | (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) |
Referenced by tls1_prf().
| #define S3 | ( | x | ) | (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) |
| #define SHR | ( | x, | |||
| n | ) | ((x & 0xFFFFFFFF) >> n) |
| void sha256 | ( | const unsigned char * | input, | |
| size_t | ilen, | |||
| unsigned char | output[32], | |||
| int | is224 | |||
| ) |
Output = SHA-256( input buffer ).
| input | buffer holding the data | |
| ilen | length of the input data | |
| output | SHA-224/256 checksum result | |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 320 of file sha256.c.
References sha256_finish(), sha256_starts(), and sha256_update().
Referenced by entropy_func(), entropy_update(), sha224_wrap(), sha256_hmac_starts(), sha256_wrap(), ssl_calc_finished_tls_sha256(), and ssl_calc_verify_tls_sha256().
| int sha256_file | ( | const char * | path, | |
| unsigned char | output[32], | |||
| int | is224 | |||
| ) |
Output = SHA-256( file contents ).
| path | input file name | |
| output | SHA-224/256 checksum result | |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 336 of file sha256.c.
References POLARSSL_ERR_SHA256_FILE_IO_ERROR, sha256_finish(), sha256_starts(), and sha256_update().
Referenced by sha224_file_wrap(), and sha256_file_wrap().
| void sha256_finish | ( | sha256_context * | ctx, | |
| unsigned char | output[32] | |||
| ) |
SHA-256 final digest.
| ctx | SHA-256 context | |
| output | SHA-224/256 checksum result |
Definition at line 284 of file sha256.c.
References sha256_context::is224, PUT_UINT32_BE, sha256_padding, sha256_update(), sha256_context::state, and sha256_context::total.
Referenced by entropy_func(), sha224_finish_wrap(), sha256(), sha256_file(), sha256_finish_wrap(), sha256_hmac_finish(), sha256_self_test(), ssl_calc_finished_tls_sha256(), and ssl_calc_verify_tls_sha256().
| void sha256_hmac | ( | const unsigned char * | key, | |
| size_t | keylen, | |||
| const unsigned char * | input, | |||
| size_t | ilen, | |||
| unsigned char | output[32], | |||
| int | is224 | |||
| ) |
Output = HMAC-SHA-256( 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-224/256 result | |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 437 of file sha256.c.
References sha256_hmac_finish(), sha256_hmac_starts(), and sha256_hmac_update().
Referenced by sha224_hmac_wrap(), sha256_hmac_wrap(), ssl_parse_ticket(), ssl_write_ticket(), and tls_prf_sha256().
| void sha256_hmac_finish | ( | sha256_context * | ctx, | |
| unsigned char | output[32] | |||
| ) |
SHA-256 HMAC final digest.
| ctx | HMAC context | |
| output | SHA-224/256 HMAC checksum result |
Definition at line 408 of file sha256.c.
References sha256_context::is224, sha256_context::opad, sha256_finish(), sha256_starts(), and sha256_update().
Referenced by sha224_hmac_finish_wrap(), sha256_hmac(), sha256_hmac_finish_wrap(), and sha256_self_test().
| void sha256_hmac_reset | ( | sha256_context * | ctx | ) |
SHA-256 HMAC context reset.
| ctx | HMAC context to be reset |
Definition at line 428 of file sha256.c.
References sha256_context::ipad, sha256_context::is224, sha256_starts(), and sha256_update().
Referenced by sha224_hmac_reset_wrap(), and sha256_hmac_reset_wrap().
| void sha256_hmac_starts | ( | sha256_context * | ctx, | |
| const unsigned char * | key, | |||
| size_t | keylen, | |||
| int | is224 | |||
| ) |
SHA-256 HMAC context setup.
| ctx | HMAC context to be initialized | |
| key | HMAC secret key | |
| keylen | length of the HMAC key | |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 369 of file sha256.c.
References sha256_context::ipad, sha256_context::opad, sha256(), sha256_starts(), and sha256_update().
Referenced by sha224_hmac_starts_wrap(), sha256_hmac(), sha256_hmac_starts_wrap(), and sha256_self_test().
| void sha256_hmac_update | ( | sha256_context * | ctx, | |
| const unsigned char * | input, | |||
| size_t | ilen | |||
| ) |
SHA-256 HMAC process buffer.
| ctx | HMAC context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 400 of file sha256.c.
References sha256_update().
Referenced by sha224_hmac_update_wrap(), sha256_hmac(), sha256_hmac_update_wrap(), and sha256_self_test().
| void sha256_process | ( | sha256_context * | ctx, | |
| const unsigned char | data[64] | |||
| ) |
Definition at line 102 of file sha256.c.
References A, F, GET_UINT32_BE, P, R, and sha256_context::state.
Referenced by sha224_process_wrap(), sha256_process_wrap(), and sha256_update().
| int sha256_self_test | ( | int | verbose | ) |
Checkup routine.
Definition at line 616 of file sha256.c.
References sha256_finish(), sha256_hmac_finish(), sha256_hmac_starts(), sha256_hmac_test_buf, sha256_hmac_test_buflen, sha256_hmac_test_key, sha256_hmac_test_keylen, sha256_hmac_test_sum, sha256_hmac_update(), sha256_starts(), sha256_test_buf, sha256_test_buflen, sha256_test_sum, and sha256_update().
| void sha256_starts | ( | sha256_context * | ctx, | |
| int | is224 | |||
| ) |
SHA-256 context setup.
| ctx | context to be initialized | |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 69 of file sha256.c.
References sha256_context::is224, sha256_context::state, and sha256_context::total.
Referenced by entropy_func(), entropy_init(), sha224_starts_wrap(), sha256(), sha256_file(), sha256_hmac_finish(), sha256_hmac_reset(), sha256_hmac_starts(), sha256_self_test(), sha256_starts_wrap(), and ssl_handshake_init().
| void sha256_update | ( | sha256_context * | ctx, | |
| const unsigned char * | input, | |||
| size_t | ilen | |||
| ) |
SHA-256 process buffer.
| ctx | SHA-256 context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 236 of file sha256.c.
References sha256_context::buffer, sha256_process(), and sha256_context::total.
Referenced by entropy_func(), entropy_update(), sha224_update_wrap(), sha256(), sha256_file(), sha256_finish(), sha256_hmac_finish(), sha256_hmac_reset(), sha256_hmac_starts(), sha256_hmac_update(), sha256_self_test(), sha256_update_wrap(), ssl_update_checksum_sha256(), and ssl_update_checksum_start().
unsigned char sha256_hmac_test_buf[7][153] [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" },
{ "This is a test using a larger than block-size key "
"and a larger than block-size data. The key needs to "
"be hashed before being used by the HMAC algorithm." }
}
Definition at line 524 of file sha256.c.
Referenced by sha256_self_test().
const int sha256_hmac_test_buflen[7] [static] |
{
8, 28, 50, 50, 20, 54, 152
}
Definition at line 545 of file sha256.c.
Referenced by sha256_self_test().
unsigned char sha256_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 504 of file sha256.c.
Referenced by sha256_self_test().
const int sha256_hmac_test_keylen[7] [static] |
{
20, 4, 20, 25, 20, 131, 131
}
Definition at line 519 of file sha256.c.
Referenced by sha256_self_test().
const unsigned char sha256_hmac_test_sum[14][32] [static] |
Definition at line 550 of file sha256.c.
Referenced by sha256_self_test().
const unsigned char sha256_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 273 of file sha256.c.
Referenced by sha256_finish().
unsigned char sha256_test_buf[3][57] [static] |
{
{ "abc" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
{ "" }
}
Definition at line 454 of file sha256.c.
Referenced by sha256_self_test().
const int sha256_test_buflen[3] [static] |
{
3, 56, 1000
}
Definition at line 461 of file sha256.c.
Referenced by sha256_self_test().
const unsigned char sha256_test_sum[6][32] [static] |
{
{ 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
0xE3, 0x6C, 0x9D, 0xA7 },
{ 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
0x52, 0x52, 0x25, 0x25 },
{ 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8,
0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B,
0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE,
0x4E, 0xE7, 0xAD, 0x67 },
{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 },
{ 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92,
0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67,
0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E,
0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 }
}
Definition at line 466 of file sha256.c.
Referenced by sha256_self_test().
1.6.1