#include <stdio.h>
#include <stdint.h>
#include "sha2.h"
Go to the source code of this file.
Defines |
#define | GET_U32_BE(n, b, i) |
#define | PUT_U32_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 (const unsigned char *input, size_t ilen, unsigned char output[32], int is224) |
| Output = SHA-256( input buffer )
|
int | sha2_file (const char *path, unsigned char output[32], int is224) |
| Output = SHA-256( file contents )
|
Define Documentation
#define F0 |
( |
|
x, |
|
|
|
y, |
|
|
|
z |
|
) |
| ((x & y) | (z & (x | y))) |
#define F1 |
( |
|
x, |
|
|
|
y, |
|
|
|
z |
|
) |
| (z ^ (x & (y ^ z))) |
Value:{ \
(n) = ( (uint32_t) (b)[(i) ] << 24 ) \
| ( (uint32_t) (b)[(i) + 1] << 16 ) \
| ( (uint32_t) (b)[(i) + 2] << 8 ) \
| ( (uint32_t) (b)[(i) + 3] ); \
}
Definition at line 53 of file sha2.c.
#define P |
( |
|
a, |
|
|
|
b, |
|
|
|
c, |
|
|
|
d, |
|
|
|
e, |
|
|
|
f, |
|
|
|
g, |
|
|
|
h, |
|
|
|
x, |
|
|
|
K |
|
) |
| |
Value:{ \
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
temp2 = S2(a) + F0(a,b,c); \
d += temp1; h = temp1 + temp2; \
}
Value:{ \
(b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 3] = (unsigned char) ( (n) ); \
}
Definition at line 63 of file sha2.c.
Value:( \
W[t] = S1(W[t - 2]) + W[t - 7] + \
S0(W[t - 15]) + W[t - 16] \
)
#define ROTR |
( |
|
x, |
|
|
|
n |
|
) |
| (SHR(x,n) | (x << (32 - n))) |
#define SHR |
( |
|
x, |
|
|
|
n |
|
) |
| ((x & 0xFFFFFFFF) >> n) |
Function Documentation
void sha2 |
( |
const unsigned char * |
input, |
|
|
size_t |
ilen, |
|
|
unsigned char |
output[32], |
|
|
int |
is224 |
|
) |
| |
Output = SHA-256( input buffer )
- Parameters:
-
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 328 of file sha2.c.
int sha2_file |
( |
const char * |
path, |
|
|
unsigned char |
output[32], |
|
|
int |
is224 |
|
) |
| |
Output = SHA-256( file contents )
- Parameters:
-
path | input file name |
output | SHA-224/256 checksum result |
is224 | 0 = use SHA256, 1 = use SHA224 |
- Returns:
- 0 if successful, 1 if fopen failed, or 2 if fread failed
Definition at line 343 of file sha2.c.
Referenced by alpm_compute_sha256sum().