MCPcopy Create free account
hub / github.com/F-Stack/f-stack / SHA1Transform

Function SHA1Transform

app/redis-6.2.6/src/sha1.c:56–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54/* Hash a single 512-bit block. This is the core of the algorithm. */
55
56void SHA1Transform(uint32_t state[5], const unsigned char buffer[64])
57{
58 uint32_t a, b, c, d, e;
59 typedef union {
60 unsigned char c[64];
61 uint32_t l[16];
62 } CHAR64LONG16;
63#ifdef SHA1HANDSOFF
64 CHAR64LONG16 block[1]; /* use array to appear as a pointer */
65 memcpy(block, buffer, 64);
66#else
67 /* The following had better never be used because it causes the
68 * pointer-to-const buffer to be cast into a pointer to non-const.
69 * And the result is written through. I threw a "const" in, hoping
70 * this will cause a diagnostic.
71 */
72 CHAR64LONG16* block = (const CHAR64LONG16*)buffer;
73#endif
74 /* Copy context->state[] to working vars */
75 a = state[0];
76 b = state[1];
77 c = state[2];
78 d = state[3];
79 e = state[4];
80 /* 4 rounds of 20 operations each. Loop unrolled. */
81 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);
82 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);
83 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);
84 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);
85 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);
86 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);
87 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);
88 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);
89 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);
90 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);
91 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);
92 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);
93 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);
94 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);
95 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);
96 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);
97 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);
98 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);
99 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);
100 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);
101 /* Add the working vars back into context.state[] */
102 state[0] += a;
103 state[1] += b;
104 state[2] += c;
105 state[3] += d;
106 state[4] += e;
107 /* Wipe variables */
108 a = b = c = d = e = 0;
109#ifdef SHA1HANDSOFF
110 memset(block, '\0', sizeof(block));
111#endif
112}
113

Callers 1

SHA1UpdateFunction · 0.70

Calls 2

memsetFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected