|
Lines 46-67
A million repetitions of "a"
Link Here
|
| 46 |
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); |
46 |
#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); |
| 47 |
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); |
47 |
#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); |
| 48 |
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); |
48 |
#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); |
| 49 |
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); |
49 |
#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); |
| 50 |
|
50 |
|
| 51 |
|
51 |
|
| 52 |
/* Hash a single 512-bit block. This is the core of the algorithm. */ |
52 |
/* Hash a single 512-bit block. This is the core of the algorithm. */ |
| 53 |
|
53 |
|
| 54 |
void SHA1Transform(unsigned long state[5], unsigned char buffer[64]) |
54 |
void SHA1Transform(UINT4 state[5], unsigned char buffer[64]) |
| 55 |
{ |
55 |
{ |
| 56 |
unsigned long a, b, c, d, e; |
56 |
UINT4 a, b, c, d, e; |
| 57 |
typedef union { |
57 |
typedef union { |
| 58 |
unsigned char c[64]; |
58 |
unsigned char c[64]; |
| 59 |
unsigned long l[16]; |
59 |
UINT4 l[16]; |
| 60 |
} CHAR64LONG16; |
60 |
} CHAR64LONG16; |
| 61 |
CHAR64LONG16* block; |
61 |
CHAR64LONG16* block; |
| 62 |
#ifdef SHA1HANDSOFF |
62 |
#ifdef SHA1HANDSOFF |
| 63 |
static CHAR64LONG16 workspace; |
63 |
static CHAR64LONG16 workspace; |
| 64 |
block = &workspace; |
64 |
block = &workspace; |
| 65 |
memcpy(block, buffer, 64); |
65 |
memcpy(block, buffer, 64); |
| 66 |
#else |
66 |
#else |
| 67 |
block = (CHAR64LONG16*)buffer; |
67 |
block = (CHAR64LONG16*)buffer; |
|
Lines 118-134
void SHA1Init(SHA1_CTX* context)
Link Here
|
| 118 |
} |
118 |
} |
| 119 |
|
119 |
|
| 120 |
|
120 |
|
| 121 |
/* Run your data through this. */ |
121 |
/* Run your data through this. */ |
| 122 |
|
122 |
|
| 123 |
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len) |
123 |
void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len) |
| 124 |
{ |
124 |
{ |
| 125 |
unsigned int i; |
125 |
unsigned int i; |
| 126 |
unsigned long j; |
126 |
UINT4 j; |
| 127 |
|
127 |
|
| 128 |
j = context->count[0]; |
128 |
j = context->count[0]; |
| 129 |
if ((context->count[0] += len << 3) < j) context->count[1] += (len>>29)+1; |
129 |
if ((context->count[0] += len << 3) < j) context->count[1] += (len>>29)+1; |
| 130 |
j = (j >> 3) & 63; |
130 |
j = (j >> 3) & 63; |
| 131 |
if ((j + len) > 63) { |
131 |
if ((j + len) > 63) { |
| 132 |
memcpy(&context->buffer[j], data, (i = 64-j)); |
132 |
memcpy(&context->buffer[j], data, (i = 64-j)); |
| 133 |
SHA1Transform(context->state, context->buffer); |
133 |
SHA1Transform(context->state, context->buffer); |
| 134 |
for ( ; i + 63 < len; i += 64) { |
134 |
for ( ; i + 63 < len; i += 64) { |
|
Lines 140-156
unsigned long j;
Link Here
|
| 140 |
memcpy(&context->buffer[j], &data[i], len - i); |
140 |
memcpy(&context->buffer[j], &data[i], len - i); |
| 141 |
} |
141 |
} |
| 142 |
|
142 |
|
| 143 |
|
143 |
|
| 144 |
/* Add padding and return the message digest. */ |
144 |
/* Add padding and return the message digest. */ |
| 145 |
|
145 |
|
| 146 |
void SHA1Final(unsigned char digest[20], SHA1_CTX* context) |
146 |
void SHA1Final(unsigned char digest[20], SHA1_CTX* context) |
| 147 |
{ |
147 |
{ |
| 148 |
unsigned long i, j; |
148 |
UINT4 i, j; |
| 149 |
unsigned char finalcount[8]; |
149 |
unsigned char finalcount[8]; |
| 150 |
|
150 |
|
| 151 |
for (i = 0; i < 8; i++) { |
151 |
for (i = 0; i < 8; i++) { |
| 152 |
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] |
152 |
finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] |
| 153 |
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ |
153 |
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ |
| 154 |
} |
154 |
} |
| 155 |
SHA1Update(context, (unsigned char *)"\200", 1); |
155 |
SHA1Update(context, (unsigned char *)"\200", 1); |
| 156 |
while ((context->count[0] & 504) != 448) { |
156 |
while ((context->count[0] & 504) != 448) { |