18 #define ROTLEFT(a, b) ((a << b) | (a >> (32 - b)))
23 uint32_t a, b, c,
d, e,
i,
j, t, m[80];
25 for (i = 0, j = 0; i < 16; ++
i, j += 4)
26 m[i] = (data[j] << 24) + (data[j + 1] << 16) + (data[j + 2] << 8) + (data[j + 3]);
27 for ( ; i < 80; ++
i) {
28 m[
i] = (m[i - 3] ^ m[i - 8] ^ m[i - 14] ^ m[i - 16]);
29 m[
i] = (m[
i] << 1) | (m[i] >> 31);
38 for (i = 0; i < 20; ++
i) {
39 t =
ROTLEFT(a, 5) + ((b & c) ^ (~b & d)) + e + ctx->
k[0] + m[i];
46 for ( ; i < 40; ++
i) {
47 t =
ROTLEFT(a, 5) + (b ^ c ^
d) + e + ctx->
k[1] + m[i];
54 for ( ; i < 60; ++
i) {
55 t =
ROTLEFT(a, 5) + ((b & c) ^ (b & d) ^ (c &
d)) + e + ctx->
k[2] + m[
i];
62 for ( ; i < 80; ++
i) {
63 t =
ROTLEFT(a, 5) + (b ^ c ^
d) + e + ctx->
k[3] + m[i];
82 ctx->
state[0] = 0x67452301;
83 ctx->
state[1] = 0xEFCDAB89;
84 ctx->
state[2] = 0x98BADCFE;
85 ctx->
state[3] = 0x10325476;
86 ctx->
state[4] = 0xc3d2e1f0;
87 ctx->
k[0] = 0x5a827999;
88 ctx->
k[1] = 0x6ed9eba1;
89 ctx->
k[2] = 0x8f1bbcdc;
90 ctx->
k[3] = 0xca62c1d6;
97 for (i = 0; i < len; ++
i) {
116 ctx->
data[i++] = 0x80;
118 ctx->
data[i++] = 0x00;
121 ctx->
data[i++] = 0x80;
123 ctx->
data[i++] = 0x00;
125 memset(ctx->
data, 0, 56);
142 for (i = 0; i < 4; ++
i) {
143 hash[
i] = (ctx->
state[0] >> (24 - i * 8)) & 0x000000ff;
144 hash[i + 4] = (ctx->
state[1] >> (24 - i * 8)) & 0x000000ff;
145 hash[i + 8] = (ctx->
state[2] >> (24 - i * 8)) & 0x000000ff;
146 hash[i + 12] = (ctx->
state[3] >> (24 - i * 8)) & 0x000000ff;
147 hash[i + 16] = (ctx->
state[4] >> (24 - i * 8)) & 0x000000ff;
void sha1_transform(SHA1_CTX *ctx, const uint8_t data[])
uint8_t data[XFER_BYTES_PER_PACKET]
void sha1_init(SHA1_CTX *ctx)
void sha1_update(SHA1_CTX *ctx, const uint8_t data[], size_t len)
void sha1_final(SHA1_CTX *ctx, uint8_t hash[])