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

Function SHA1Final

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

Source from the content-addressed store, hash-verified

153/* Add padding and return the message digest. */
154
155void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
156{
157 unsigned i;
158 unsigned char finalcount[8];
159 unsigned char c;
160
161#if 0 /* untested "improvement" by DHR */
162 /* Convert context->count to a sequence of bytes
163 * in finalcount. Second element first, but
164 * big-endian order within element.
165 * But we do it all backwards.
166 */
167 unsigned char *fcp = &finalcount[8];
168
169 for (i = 0; i < 2; i++)
170 {
171 uint32_t t = context->count[i];
172 int j;
173
174 for (j = 0; j < 4; t >>= 8, j++)
175 *--fcp = (unsigned char) t;
176 }
177#else
178 for (i = 0; i < 8; i++) {
179 finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)]
180 >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
181 }
182#endif
183 c = 0200;
184 SHA1Update(context, &c, 1);
185 while ((context->count[0] & 504) != 448) {
186 c = 0000;
187 SHA1Update(context, &c, 1);
188 }
189 SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
190 for (i = 0; i < 20; i++) {
191 digest[i] = (unsigned char)
192 ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
193 }
194 /* Wipe variables */
195 memset(context, '\0', sizeof(*context));
196 memset(&finalcount, '\0', sizeof(finalcount));
197}
198/* ================ end of sha1.c ================ */
199
200#ifdef REDIS_TEST

Callers 5

sha1hexFunction · 0.70
xorDigestFunction · 0.70
mixDigestFunction · 0.70
sha1TestFunction · 0.70
sha1HashFunction · 0.50

Calls 2

memsetFunction · 0.85
SHA1UpdateFunction · 0.70

Tested by

no test coverage detected