#include "polarssl/config.h"#include "polarssl/sha512.h"#include <stdio.h>
Go to the source code of this file.
Defines | |
| #define | GET_UINT64_BE(n, b, i) |
| #define | PUT_UINT64_BE(n, b, i) |
| #define | SHR(x, n) (x >> n) |
| #define | ROTR(x, n) (SHR(x,n) | (x << (64 - n))) |
| #define | S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7)) |
| #define | S1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x, 6)) |
| #define | S2(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39)) |
| #define | S3(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41)) |
| #define | F0(x, y, z) ((x & y) | (z & (x | y))) |
| #define | F1(x, y, z) (z ^ (x & (y ^ z))) |
| #define | P(a, b, c, d, e, f, g, h, x, K) |
Functions | |
| void | sha512_starts (sha512_context *ctx, int is384) |
| SHA-512 context setup. | |
| void | sha512_process (sha512_context *ctx, const unsigned char data[128]) |
| void | sha512_update (sha512_context *ctx, const unsigned char *input, size_t ilen) |
| SHA-512 process buffer. | |
| void | sha512_finish (sha512_context *ctx, unsigned char output[64]) |
| SHA-512 final digest. | |
| void | sha512 (const unsigned char *input, size_t ilen, unsigned char output[64], int is384) |
| Output = SHA-512( input buffer ). | |
| int | sha512_file (const char *path, unsigned char output[64], int is384) |
| Output = SHA-512( file contents ). | |
| void | sha512_hmac_starts (sha512_context *ctx, const unsigned char *key, size_t keylen, int is384) |
| SHA-512 HMAC context setup. | |
| void | sha512_hmac_update (sha512_context *ctx, const unsigned char *input, size_t ilen) |
| SHA-512 HMAC process buffer. | |
| void | sha512_hmac_finish (sha512_context *ctx, unsigned char output[64]) |
| SHA-512 HMAC final digest. | |
| void | sha512_hmac_reset (sha512_context *ctx) |
| SHA-512 HMAC context reset. | |
| void | sha512_hmac (const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[64], int is384) |
| Output = HMAC-SHA-512( hmac key, input buffer ). | |
| int | sha512_self_test (int verbose) |
| Checkup routine. | |
Variables | |
| static const uint64_t | K [80] |
| static const unsigned char | sha512_padding [128] |
| static unsigned char | sha512_test_buf [3][113] |
| static const int | sha512_test_buflen [3] |
| static const unsigned char | sha512_test_sum [6][64] |
| static unsigned char | sha512_hmac_test_key [7][26] |
| static const int | sha512_hmac_test_keylen [7] |
| static unsigned char | sha512_hmac_test_buf [7][153] |
| static const int | sha512_hmac_test_buflen [7] |
| static const unsigned char | sha512_hmac_test_sum [14][64] |
| #define F0 | ( | x, | |||
| y, | |||||
| z | ) | ((x & y) | (z & (x | y))) |
| #define F1 | ( | x, | |||
| y, | |||||
| z | ) | (z ^ (x & (y ^ z))) |
| #define GET_UINT64_BE | ( | n, | |||
| b, | |||||
| i | ) |
{ \
(n) = ( (uint64_t) (b)[(i) ] << 56 ) \
| ( (uint64_t) (b)[(i) + 1] << 48 ) \
| ( (uint64_t) (b)[(i) + 2] << 40 ) \
| ( (uint64_t) (b)[(i) + 3] << 32 ) \
| ( (uint64_t) (b)[(i) + 4] << 24 ) \
| ( (uint64_t) (b)[(i) + 5] << 16 ) \
| ( (uint64_t) (b)[(i) + 6] << 8 ) \
| ( (uint64_t) (b)[(i) + 7] ); \
}
Definition at line 47 of file sha512.c.
Referenced by sha512_process().
| #define PUT_UINT64_BE | ( | n, | |||
| b, | |||||
| i | ) |
{ \
(b)[(i) ] = (unsigned char) ( (n) >> 56 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 48 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 40 ); \
(b)[(i) + 3] = (unsigned char) ( (n) >> 32 ); \
(b)[(i) + 4] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 5] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 6] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 7] = (unsigned char) ( (n) ); \
}
Definition at line 61 of file sha512.c.
Referenced by sha512_finish().
| #define ROTR | ( | x, | |||
| n | ) | (SHR(x,n) | (x << (64 - n))) |
| #define S0 | ( | x | ) | (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7)) |
| #define S1 | ( | x | ) | (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x, 6)) |
| #define S2 | ( | x | ) | (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39)) |
| #define S3 | ( | x | ) | (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41)) |
| #define SHR | ( | x, | |||
| n | ) | (x >> n) |
| void sha512 | ( | const unsigned char * | input, | |
| size_t | ilen, | |||
| unsigned char | output[64], | |||
| int | is384 | |||
| ) |
Output = SHA-512( input buffer ).
| input | buffer holding the data | |
| ilen | length of the input data | |
| output | SHA-384/512 checksum result | |
| is384 | 0 = use SHA512, 1 = use SHA384 |
Definition at line 318 of file sha512.c.
References sha512_finish(), sha512_starts(), and sha512_update().
Referenced by entropy_func(), entropy_update(), sha384_wrap(), sha512_hmac_starts(), sha512_wrap(), ssl_calc_finished_tls_sha384(), and ssl_calc_verify_tls_sha384().
| int sha512_file | ( | const char * | path, | |
| unsigned char | output[64], | |||
| int | is384 | |||
| ) |
Output = SHA-512( file contents ).
| path | input file name | |
| output | SHA-384/512 checksum result | |
| is384 | 0 = use SHA512, 1 = use SHA384 |
Definition at line 334 of file sha512.c.
References POLARSSL_ERR_SHA512_FILE_IO_ERROR, sha512_finish(), sha512_starts(), and sha512_update().
Referenced by sha384_file_wrap(), and sha512_file_wrap().
| void sha512_finish | ( | sha512_context * | ctx, | |
| unsigned char | output[64] | |||
| ) |
SHA-512 final digest.
| ctx | SHA-512 context | |
| output | SHA-384/512 checksum result |
Definition at line 280 of file sha512.c.
References sha512_context::is384, PUT_UINT64_BE, sha512_padding, sha512_update(), sha512_context::state, and sha512_context::total.
Referenced by entropy_func(), sha384_finish_wrap(), sha512(), sha512_file(), sha512_finish_wrap(), sha512_hmac_finish(), sha512_self_test(), ssl_calc_finished_tls_sha384(), and ssl_calc_verify_tls_sha384().
| void sha512_hmac | ( | const unsigned char * | key, | |
| size_t | keylen, | |||
| const unsigned char * | input, | |||
| size_t | ilen, | |||
| unsigned char | output[64], | |||
| int | is384 | |||
| ) |
Output = HMAC-SHA-512( 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-384/512 result | |
| is384 | 0 = use SHA512, 1 = use SHA384 |
Definition at line 436 of file sha512.c.
References sha512_hmac_finish(), sha512_hmac_starts(), and sha512_hmac_update().
Referenced by sha384_hmac_wrap(), sha512_hmac_wrap(), and tls_prf_sha384().
| void sha512_hmac_finish | ( | sha512_context * | ctx, | |
| unsigned char | output[64] | |||
| ) |
SHA-512 HMAC final digest.
| ctx | HMAC context | |
| output | SHA-384/512 HMAC checksum result |
Definition at line 407 of file sha512.c.
References sha512_context::is384, sha512_context::opad, sha512_finish(), sha512_starts(), and sha512_update().
Referenced by sha384_hmac_finish_wrap(), sha512_hmac(), sha512_hmac_finish_wrap(), and sha512_self_test().
| void sha512_hmac_reset | ( | sha512_context * | ctx | ) |
SHA-512 HMAC context reset.
| ctx | HMAC context to be reset |
Definition at line 427 of file sha512.c.
References sha512_context::ipad, sha512_context::is384, sha512_starts(), and sha512_update().
Referenced by sha384_hmac_reset_wrap(), and sha512_hmac_reset_wrap().
| void sha512_hmac_starts | ( | sha512_context * | ctx, | |
| const unsigned char * | key, | |||
| size_t | keylen, | |||
| int | is384 | |||
| ) |
SHA-512 HMAC context setup.
| ctx | HMAC context to be initialized | |
| is384 | 0 = use SHA512, 1 = use SHA384 | |
| key | HMAC secret key | |
| keylen | length of the HMAC key |
Definition at line 367 of file sha512.c.
References sha512_context::ipad, sha512_context::opad, sha512(), sha512_starts(), and sha512_update().
Referenced by sha384_hmac_starts_wrap(), sha512_hmac(), sha512_hmac_starts_wrap(), and sha512_self_test().
| void sha512_hmac_update | ( | sha512_context * | ctx, | |
| const unsigned char * | input, | |||
| size_t | ilen | |||
| ) |
SHA-512 HMAC process buffer.
| ctx | HMAC context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 398 of file sha512.c.
References sha512_update().
Referenced by sha384_hmac_update_wrap(), sha512_hmac(), sha512_hmac_update_wrap(), and sha512_self_test().
| void sha512_process | ( | sha512_context * | ctx, | |
| const unsigned char | data[128] | |||
| ) |
Definition at line 157 of file sha512.c.
References A, F, GET_UINT64_BE, K, P, S0, S1, and sha512_context::state.
Referenced by sha384_process_wrap(), sha512_process_wrap(), and sha512_update().
| int sha512_self_test | ( | int | verbose | ) |
Checkup routine.
Definition at line 671 of file sha512.c.
References sha512_finish(), sha512_hmac_finish(), sha512_hmac_starts(), sha512_hmac_test_buf, sha512_hmac_test_buflen, sha512_hmac_test_key, sha512_hmac_test_keylen, sha512_hmac_test_sum, sha512_hmac_update(), sha512_starts(), sha512_test_buf, sha512_test_buflen, sha512_test_sum, and sha512_update().
| void sha512_starts | ( | sha512_context * | ctx, | |
| int | is384 | |||
| ) |
SHA-512 context setup.
| ctx | context to be initialized | |
| is384 | 0 = use SHA512, 1 = use SHA384 |
Definition at line 124 of file sha512.c.
References sha512_context::is384, sha512_context::state, sha512_context::total, and UL64.
Referenced by entropy_func(), entropy_init(), sha384_starts_wrap(), sha512(), sha512_file(), sha512_hmac_finish(), sha512_hmac_reset(), sha512_hmac_starts(), sha512_self_test(), sha512_starts_wrap(), and ssl_handshake_init().
| void sha512_update | ( | sha512_context * | ctx, | |
| const unsigned char * | input, | |||
| size_t | ilen | |||
| ) |
SHA-512 process buffer.
| ctx | SHA-512 context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 229 of file sha512.c.
References sha512_context::buffer, sha512_process(), and sha512_context::total.
Referenced by entropy_func(), entropy_update(), sha384_update_wrap(), sha512(), sha512_file(), sha512_finish(), sha512_hmac_finish(), sha512_hmac_reset(), sha512_hmac_starts(), sha512_hmac_update(), sha512_self_test(), sha512_update_wrap(), ssl_update_checksum_sha384(), and ssl_update_checksum_start().
unsigned char sha512_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 543 of file sha512.c.
Referenced by sha512_self_test().
const int sha512_hmac_test_buflen[7] [static] |
{
8, 28, 50, 50, 20, 54, 152
}
Definition at line 564 of file sha512.c.
Referenced by sha512_self_test().
unsigned char sha512_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 523 of file sha512.c.
Referenced by sha512_self_test().
const int sha512_hmac_test_keylen[7] [static] |
{
20, 4, 20, 25, 20, 131, 131
}
Definition at line 538 of file sha512.c.
Referenced by sha512_self_test().
const unsigned char sha512_hmac_test_sum[14][64] [static] |
Definition at line 569 of file sha512.c.
Referenced by sha512_self_test().
const unsigned char sha512_padding[128] [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,
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, 0
}
Definition at line 265 of file sha512.c.
Referenced by sha512_finish().
unsigned char sha512_test_buf[3][113] [static] |
{
{ "abc" },
{ "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" },
{ "" }
}
Definition at line 454 of file sha512.c.
Referenced by sha512_self_test().
const int sha512_test_buflen[3] [static] |
{
3, 112, 1000
}
Definition at line 462 of file sha512.c.
Referenced by sha512_self_test().
const unsigned char sha512_test_sum[6][64] [static] |
Definition at line 467 of file sha512.c.
Referenced by sha512_self_test().
1.6.1