98#define SHA1_DIGEST_SIZE 20
100#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
113blk0(CHAR64LONG16 *block,
int i)
115 static const uint32_t
n = 1u;
118 block->l[i] = (
rol(block->l[i], 24) & 0xFF00FF00)
119 | (
rol(block->l[i], 8) & 0x00FF00FF);
124#define blk(block, i) \
125 ((block)->l[(i)&15] = \
126 rol((block)->l[((i) + 13) & 15] ^ (block)->l[((i) + 8) & 15] \
127 ^ (block)->l[((i) + 2) & 15] ^ (block)->l[(i)&15], \
131#define R0(v, w, x, y, z, i) \
132 z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); \
134#define R1(v, w, x, y, z, i) \
135 z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + rol(v, 5); \
137#define R2(v, w, x, y, z, i) \
138 z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + rol(v, 5); \
140#define R3(v, w, x, y, z, i) \
141 z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + rol(v, 5); \
143#define R4(v, w, x, y, z, i) \
144 z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + rol(v, 5); \
152 uint32_t
a,
b,
c,
d,
e;
155 CHAR64LONG16 block[1];
156 memcpy(block, buffer,
sizeof(block));
261 context->state[0] = 0x67452301;
262 context->state[1] = 0xEFCDAB89;
263 context->state[2] = 0x98BADCFE;
264 context->state[3] = 0x10325476;
265 context->state[4] = 0xC3D2E1F0;
266 context->count[0] = context->count[1] = 0;
275 j = context->count[0];
276 if ((context->count[0] += (len << 3)) < j) {
279 context->count[1] += (len >> 29);
281 if ((j + len) > 63) {
283 memcpy(&context->buffer[j], data, i);
285 for (; i + 63 < len; i += 64) {
292 memcpy(&context->buffer[j], &data[i], len - i);
303 for (i = 0; i < 8; i++) {
305 (
uint8_t)((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8))
309 while ((context->count[0] & 504) != 448) {
315 (
uint8_t)((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
319 memset(context,
'\0',
sizeof(*context));
static void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64])
SHA_API void SHA1_Init(SHA_CTX *context)
#define R1(v, w, x, y, z, i)
SHA_API void SHA1_Update(SHA_CTX *context, const uint8_t *data, const uint32_t len)
#define R2(v, w, x, y, z, i)
SHA_API void SHA1_Final(unsigned char *digest, SHA_CTX *context)
#define R0(v, w, x, y, z, i)
#define R3(v, w, x, y, z, i)
#define R4(v, w, x, y, z, i)