Lines Matching +full:a +full:- +full:c

3  * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
24 * sha1_vector - SHA-1 hash for data vector
29 * Returns: 0 on success, -1 of failure
37 return -1; in sha1_vector()
48 /* ===== start - public domain SHA1 implementation ===== */
51 SHA-1 in C
52 By Steve Reid <sreid@sea-to-sky.net>
55 -----------------
60 Corrected a problem which generated improper hash values on 16 bit machines
72 greater than 8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
74 Since the file IO in main() reads 16K at a time, any file 8K or larger would
75 be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
76 "a"s).
83 int and a long are the same size in those environments.
85 --
86 I also corrected a few compiler warnings generated by Borland C.
92 -----------------
94 By Steve Reid <sreid@sea-to-sky.net>
97 1- Removed #include <process.h> and used return() instead of exit()
98 2- Fixed overwriting of finalcount in SHA1Final() (discovered by Chris Hall)
99 3- Changed email address from steve@edmweb.com to sreid@sea-to-sky.net
101 -----------------
107 -----------------
119 Test Vectors (from FIPS PUB 180-1)
121 A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
124 A million repetitions of "a"
130 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
135 #define blk0(i) (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | \
136 (rol(block->l[i], 8) & 0x00FF00FF))
138 #define blk0(i) block->l[i]
140 #define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ \
141 block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1))
165 context->count[0], context->count[1], in SHAPrintContext()
166 context->state[0], in SHAPrintContext()
167 context->state[1], in SHAPrintContext()
168 context->state[2], in SHAPrintContext()
169 context->state[3], in SHAPrintContext()
170 context->state[4]); in SHAPrintContext()
174 /* Hash a single 512-bit block. This is the core of the algorithm. */
178 u32 a, b, c, d, e; in SHA1Transform() local
180 unsigned char c[64]; in SHA1Transform() member
191 /* Copy context->state[] to working vars */ in SHA1Transform()
192 a = state[0]; in SHA1Transform()
194 c = state[2]; in SHA1Transform()
198 R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); in SHA1Transform()
199 R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); in SHA1Transform()
200 R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); in SHA1Transform()
201 R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); in SHA1Transform()
202 R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); in SHA1Transform()
203 R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); in SHA1Transform()
204 R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); in SHA1Transform()
205 R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); in SHA1Transform()
206 R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); in SHA1Transform()
207 R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); in SHA1Transform()
208 R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); in SHA1Transform()
209 R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); in SHA1Transform()
210 R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); in SHA1Transform()
211 R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); in SHA1Transform()
212 R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); in SHA1Transform()
213 R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); in SHA1Transform()
214 R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); in SHA1Transform()
215 R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); in SHA1Transform()
216 R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); in SHA1Transform()
217 R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); in SHA1Transform()
219 state[0] += a; in SHA1Transform()
221 state[2] += c; in SHA1Transform()
225 a = b = c = d = e = 0; in SHA1Transform()
232 /* SHA1Init - Initialize new context */
237 context->state[0] = 0x67452301; in SHA1Init()
238 context->state[1] = 0xEFCDAB89; in SHA1Init()
239 context->state[2] = 0x98BADCFE; in SHA1Init()
240 context->state[3] = 0x10325476; in SHA1Init()
241 context->state[4] = 0xC3D2E1F0; in SHA1Init()
242 context->count[0] = context->count[1] = 0; in SHA1Init()
256 j = (context->count[0] >> 3) & 63; in SHA1Update()
257 if ((context->count[0] += len << 3) < (len << 3)) in SHA1Update()
258 context->count[1]++; in SHA1Update()
259 context->count[1] += (len >> 29); in SHA1Update()
261 os_memcpy(&context->buffer[j], data, (i = 64-j)); in SHA1Update()
262 SHA1Transform(context->state, context->buffer); in SHA1Update()
264 SHA1Transform(context->state, &data[i]); in SHA1Update()
269 os_memcpy(&context->buffer[j], &data[i], len - i); in SHA1Update()
285 ((context->count[(i >= 4 ? 0 : 1)] >> in SHA1Final()
286 ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ in SHA1Final()
289 while ((context->count[0] & 504) != 448) { in SHA1Final()
292 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() in SHA1Final()
296 ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & in SHA1Final()
300 os_memset(context->buffer, 0, 64); in SHA1Final()
301 os_memset(context->state, 0, 20); in SHA1Final()
302 os_memset(context->count, 0, 8); in SHA1Final()
306 /* ===== end - public domain SHA1 implementation ===== */