#include <string.h>#include <stdio.h>#include "xyssl/sha2.h"Go to the source code of this file.
Defines | |
| #define | _CRT_SECURE_NO_DEPRECATE 1 |
| #define | GET_UINT32_BE(n, b, i) |
| #define | PUT_UINT32_BE(n, b, i) |
| #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 | sha2_starts (sha2_context *ctx, int is224) |
| SHA-256 context setup. | |
| static void | sha2_process (sha2_context *ctx, unsigned char data[64]) |
| void | sha2_update (sha2_context *ctx, unsigned char *input, int ilen) |
| SHA-256 process buffer. | |
| void | sha2_finish (sha2_context *ctx, unsigned char *output) |
| SHA-256 final digest. | |
| void | sha2 (unsigned char *input, int ilen, unsigned char *output, int is224) |
| Output = SHA-256( input buffer ). | |
| int | sha2_file (char *path, unsigned char *output, int is224) |
| Output = SHA-256( file contents ). | |
| void | sha2_hmac_starts (sha2_context *ctx, int is224, unsigned char *key, int keylen) |
| SHA-256 HMAC context setup. | |
| void | sha2_hmac_update (sha2_context *ctx, unsigned char *input, int ilen) |
| SHA-256 HMAC process buffer. | |
| void | sha2_hmac_finish (sha2_context *ctx, unsigned char *output) |
| SHA-256 HMAC final digest. | |
| void | sha2_hmac (unsigned char *key, int keylen, unsigned char *input, int ilen, unsigned char *output, int is224) |
| Output = HMAC-SHA-256( hmac key, input buffer ). | |
| int | sha2_self_test (int verbose) |
| Checkup routine. | |
Variables | |
| static const unsigned char | sha2_padding [64] |
| static const char | _sha2_src [] = "_sha2_src" |
| #define F0 | ( | x, | |||
| y, | |||||
| z | ) | ((x & y) | (z & (x | y))) |
| #define F1 | ( | x, | |||
| y, | |||||
| z | ) | (z ^ (x & (y ^ z))) |
| #define GET_UINT32_BE | ( | n, | |||
| b, | |||||
| i | ) |
| #define PUT_UINT32_BE | ( | n, | |||
| b, | |||||
| i | ) |
| #define ROTR | ( | x, | |||
| n | ) | (SHR(x,n) | (x << (32 - n))) |
| #define S0 | ( | x | ) | (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) |
Referenced by sha4_process().
| #define S1 | ( | x | ) | (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) |
Referenced by sha4_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) |
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 317 of file sha2.c.
References sha2_finish(), sha2_starts(), and sha2_update().
Referenced by main().
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 332 of file sha2.c.
References f, sha2_finish(), sha2_starts(), and sha2_update().
Referenced by sha2_wrapper().
| void sha2_finish | ( | sha2_context * | ctx, | |
| unsigned char * | output | |||
| ) |
SHA-256 final digest.
| ctx | SHA-256 context | |
| output | SHA-224/256 checksum result |
Definition at line 283 of file sha2.c.
References sha2_context::is224, PUT_UINT32_BE, sha2_padding, sha2_update(), sha2_context::state, and sha2_context::total.
Referenced by main(), sha2(), sha2_file(), and sha2_hmac_finish().
| void sha2_hmac | ( | unsigned char * | key, | |
| int | keylen, | |||
| unsigned char * | input, | |||
| int | ilen, | |||
| unsigned char * | output, | |||
| 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 416 of file sha2.c.
References sha2_hmac_finish(), sha2_hmac_starts(), and sha2_hmac_update().
| void sha2_hmac_finish | ( | sha2_context * | ctx, | |
| unsigned char * | output | |||
| ) |
SHA-256 HMAC final digest.
| ctx | HMAC context | |
| output | SHA-224/256 HMAC checksum result |
Definition at line 396 of file sha2.c.
References sha2_context::is224, sha2_context::opad, sha2_finish(), sha2_starts(), and sha2_update().
Referenced by main(), and sha2_hmac().
| void sha2_hmac_starts | ( | sha2_context * | ctx, | |
| int | is224, | |||
| unsigned char * | key, | |||
| int | keylen | |||
| ) |
SHA-256 HMAC context setup.
| ctx | HMAC context to be initialized | |
| is224 | 0 = use SHA256, 1 = use SHA224 | |
| key | HMAC secret key | |
| keylen | length of the HMAC key |
Definition at line 364 of file sha2.c.
References sha2_context::ipad, sha2_context::opad, sha2_starts(), and sha2_update().
Referenced by main(), and sha2_hmac().
| void sha2_hmac_update | ( | sha2_context * | ctx, | |
| unsigned char * | input, | |||
| int | ilen | |||
| ) |
SHA-256 HMAC process buffer.
| ctx | HMAC context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 387 of file sha2.c.
References sha2_update().
Referenced by main(), and sha2_hmac().
| static void sha2_process | ( | sha2_context * | ctx, | |
| unsigned char | data[64] | |||
| ) | [static] |
Definition at line 97 of file sha2.c.
References F, GET_UINT32_BE, P, R, and sha2_context::state.
Referenced by sha2_update().
| void sha2_starts | ( | sha2_context * | ctx, | |
| int | is224 | |||
| ) |
SHA-256 context setup.
| ctx | context to be initialized | |
| is224 | 0 = use SHA256, 1 = use SHA224 |
Definition at line 64 of file sha2.c.
References sha2_context::is224, sha2_context::state, and sha2_context::total.
Referenced by main(), sha2(), sha2_file(), sha2_hmac_finish(), and sha2_hmac_starts().
| void sha2_update | ( | sha2_context * | ctx, | |
| unsigned char * | input, | |||
| int | ilen | |||
| ) |
SHA-256 process buffer.
| ctx | SHA-256 context | |
| input | buffer holding the data | |
| ilen | length of the input data |
Definition at line 231 of file sha2.c.
References sha2_context::buffer, sha2_process(), and sha2_context::total.
Referenced by main(), sha2(), sha2_file(), sha2_finish(), sha2_hmac_finish(), sha2_hmac_starts(), and sha2_hmac_update().
const unsigned char sha2_padding[64] [static] |
Initial value:
{
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 272 of file sha2.c.
Referenced by sha2_finish().
1.5.4