mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/digest] Revert tab-expansion in external files
https://github.com/ruby/digest/commit/5ca2b5b91e
This commit is contained in:
parent
af265d73fb
commit
48b09aae7e
8 changed files with 964 additions and 964 deletions
|
@ -34,8 +34,8 @@
|
||||||
that follows (in reverse chronological order):
|
that follows (in reverse chronological order):
|
||||||
|
|
||||||
2000-07-03 lpd Patched to eliminate warnings about "constant is
|
2000-07-03 lpd Patched to eliminate warnings about "constant is
|
||||||
unsigned in ANSI C, signed in traditional";
|
unsigned in ANSI C, signed in traditional";
|
||||||
made test program self-checking.
|
made test program self-checking.
|
||||||
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||||
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
|
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
|
||||||
1999-05-03 lpd Original version.
|
1999-05-03 lpd Original version.
|
||||||
|
@ -64,32 +64,32 @@ int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
static const char *const test[7*2] = {
|
static const char *const test[7*2] = {
|
||||||
"", "d41d8cd98f00b204e9800998ecf8427e",
|
"", "d41d8cd98f00b204e9800998ecf8427e",
|
||||||
"a", "0cc175b9c0f1b6a831c399e269772661",
|
"a", "0cc175b9c0f1b6a831c399e269772661",
|
||||||
"abc", "900150983cd24fb0d6963f7d28e17f72",
|
"abc", "900150983cd24fb0d6963f7d28e17f72",
|
||||||
"message digest", "f96b697d7cb7938d525a2f31aaf161d0",
|
"message digest", "f96b697d7cb7938d525a2f31aaf161d0",
|
||||||
"abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b",
|
"abcdefghijklmnopqrstuvwxyz", "c3fcd3d76192e4007dfb496cca67e13b",
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||||
"d174ab98d277d9f5a5611c2c9f419d9f",
|
"d174ab98d277d9f5a5611c2c9f419d9f",
|
||||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a"
|
"12345678901234567890123456789012345678901234567890123456789012345678901234567890", "57edf4a22be3c955ac49da2e2107b67a"
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 7*2; i += 2) {
|
for (i = 0; i < 7*2; i += 2) {
|
||||||
MD5_CTX state;
|
MD5_CTX state;
|
||||||
uint8_t digest[16];
|
uint8_t digest[16];
|
||||||
char hex_output[16*2 + 1];
|
char hex_output[16*2 + 1];
|
||||||
int di;
|
int di;
|
||||||
|
|
||||||
MD5_Init(&state);
|
MD5_Init(&state);
|
||||||
MD5_Update(&state, (const uint8_t *)test[i], strlen(test[i]));
|
MD5_Update(&state, (const uint8_t *)test[i], strlen(test[i]));
|
||||||
MD5_Final(digest, &state);
|
MD5_Final(digest, &state);
|
||||||
printf("MD5 (\"%s\") = ", test[i]);
|
printf("MD5 (\"%s\") = ", test[i]);
|
||||||
for (di = 0; di < 16; ++di)
|
for (di = 0; di < 16; ++di)
|
||||||
sprintf(hex_output + di * 2, "%02x", digest[di]);
|
sprintf(hex_output + di * 2, "%02x", digest[di]);
|
||||||
puts(hex_output);
|
puts(hex_output);
|
||||||
if (strcmp(hex_output, test[i + 1]))
|
if (strcmp(hex_output, test[i + 1]))
|
||||||
printf("**** ERROR, should be: %s\n", test[i + 1]);
|
printf("**** ERROR, should be: %s\n", test[i + 1]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -106,18 +106,18 @@ main(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i <= 64; ++i) {
|
for (i = 1; i <= 64; ++i) {
|
||||||
unsigned long v = (unsigned long)(4294967296.0 * fabs(sin((double)i)));
|
unsigned long v = (unsigned long)(4294967296.0 * fabs(sin((double)i)));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following nonsense is only to avoid compiler warnings about
|
* The following nonsense is only to avoid compiler warnings about
|
||||||
* "integer constant is unsigned in ANSI C, signed with -traditional".
|
* "integer constant is unsigned in ANSI C, signed with -traditional".
|
||||||
*/
|
*/
|
||||||
if (v >> 31) {
|
if (v >> 31) {
|
||||||
printf("#define T%d /* 0x%08lx */ (T_MASK ^ 0x%08lx)\n", i,
|
printf("#define T%d /* 0x%08lx */ (T_MASK ^ 0x%08lx)\n", i,
|
||||||
v, (unsigned long)(unsigned int)(~v));
|
v, (unsigned long)(unsigned int)(~v));
|
||||||
} else {
|
} else {
|
||||||
printf("#define T%d 0x%08lx\n", i, v);
|
printf("#define T%d 0x%08lx\n", i, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -199,8 +199,8 @@ static void
|
||||||
md5_process(MD5_CTX *pms, const uint8_t *data /*[64]*/)
|
md5_process(MD5_CTX *pms, const uint8_t *data /*[64]*/)
|
||||||
{
|
{
|
||||||
uint32_t
|
uint32_t
|
||||||
a = pms->state[0], b = pms->state[1],
|
a = pms->state[0], b = pms->state[1],
|
||||||
c = pms->state[2], d = pms->state[3];
|
c = pms->state[2], d = pms->state[3];
|
||||||
uint32_t t;
|
uint32_t t;
|
||||||
|
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
@ -214,7 +214,7 @@ md5_process(MD5_CTX *pms, const uint8_t *data /*[64]*/)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 16; ++i, xp += 4)
|
for (i = 0; i < 16; ++i, xp += 4)
|
||||||
X[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
X[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -226,12 +226,12 @@ md5_process(MD5_CTX *pms, const uint8_t *data /*[64]*/)
|
||||||
const uint32_t *X;
|
const uint32_t *X;
|
||||||
|
|
||||||
if (!(((uintptr_t)data) & 3)) {
|
if (!(((uintptr_t)data) & 3)) {
|
||||||
/* data are properly aligned */
|
/* data are properly aligned */
|
||||||
X = (const uint32_t *)data;
|
X = (const uint32_t *)data;
|
||||||
} else {
|
} else {
|
||||||
/* not aligned */
|
/* not aligned */
|
||||||
memcpy(xbuf, data, 64);
|
memcpy(xbuf, data, 64);
|
||||||
X = xbuf;
|
X = xbuf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -370,55 +370,55 @@ MD5_Update(MD5_CTX *pms, const uint8_t *data, size_t nbytes)
|
||||||
uint32_t nbits = (uint32_t)(nbytes << 3);
|
uint32_t nbits = (uint32_t)(nbytes << 3);
|
||||||
|
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Update the message length. */
|
/* Update the message length. */
|
||||||
pms->count[1] += nbytes >> 29;
|
pms->count[1] += nbytes >> 29;
|
||||||
pms->count[0] += nbits;
|
pms->count[0] += nbits;
|
||||||
if (pms->count[0] < nbits)
|
if (pms->count[0] < nbits)
|
||||||
pms->count[1]++;
|
pms->count[1]++;
|
||||||
|
|
||||||
/* Process an initial partial block. */
|
/* Process an initial partial block. */
|
||||||
if (offset) {
|
if (offset) {
|
||||||
size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
|
size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
|
||||||
|
|
||||||
memcpy(pms->buffer + offset, p, copy);
|
memcpy(pms->buffer + offset, p, copy);
|
||||||
if (offset + copy < 64)
|
if (offset + copy < 64)
|
||||||
return;
|
return;
|
||||||
p += copy;
|
p += copy;
|
||||||
left -= copy;
|
left -= copy;
|
||||||
md5_process(pms, pms->buffer);
|
md5_process(pms, pms->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process full blocks. */
|
/* Process full blocks. */
|
||||||
for (; left >= 64; p += 64, left -= 64)
|
for (; left >= 64; p += 64, left -= 64)
|
||||||
md5_process(pms, p);
|
md5_process(pms, p);
|
||||||
|
|
||||||
/* Process a final partial block. */
|
/* Process a final partial block. */
|
||||||
if (left)
|
if (left)
|
||||||
memcpy(pms->buffer, p, left);
|
memcpy(pms->buffer, p, left);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
MD5_Finish(MD5_CTX *pms, uint8_t *digest)
|
MD5_Finish(MD5_CTX *pms, uint8_t *digest)
|
||||||
{
|
{
|
||||||
static const uint8_t pad[64] = {
|
static const uint8_t pad[64] = {
|
||||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* Save the length before padding. */
|
/* Save the length before padding. */
|
||||||
for (i = 0; i < 8; ++i)
|
for (i = 0; i < 8; ++i)
|
||||||
data[i] = (uint8_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
data[i] = (uint8_t)(pms->count[i >> 2] >> ((i & 3) << 3));
|
||||||
/* Pad to 56 bytes mod 64. */
|
/* Pad to 56 bytes mod 64. */
|
||||||
MD5_Update(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
MD5_Update(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
|
||||||
/* Append the length. */
|
/* Append the length. */
|
||||||
MD5_Update(pms, data, 8);
|
MD5_Update(pms, data, 8);
|
||||||
for (i = 0; i < 16; ++i)
|
for (i = 0; i < 16; ++i)
|
||||||
digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
|
digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
|
|
||||||
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||||
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
|
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
|
||||||
added conditionalization for C++ compilation from Martin
|
added conditionalization for C++ compilation from Martin
|
||||||
Purschke <purschke@bnl.gov>.
|
Purschke <purschke@bnl.gov>.
|
||||||
1999-05-03 lpd Original version.
|
1999-05-03 lpd Original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -128,17 +128,17 @@ int
|
||||||
RMD160_Init(RMD160_CTX *context)
|
RMD160_Init(RMD160_CTX *context)
|
||||||
{
|
{
|
||||||
|
|
||||||
_DIAGASSERT(context != NULL);
|
_DIAGASSERT(context != NULL);
|
||||||
|
|
||||||
/* ripemd-160 initialization constants */
|
/* ripemd-160 initialization constants */
|
||||||
context->state[0] = 0x67452301U;
|
context->state[0] = 0x67452301U;
|
||||||
context->state[1] = 0xefcdab89U;
|
context->state[1] = 0xefcdab89U;
|
||||||
context->state[2] = 0x98badcfeU;
|
context->state[2] = 0x98badcfeU;
|
||||||
context->state[3] = 0x10325476U;
|
context->state[3] = 0x10325476U;
|
||||||
context->state[4] = 0xc3d2e1f0U;
|
context->state[4] = 0xc3d2e1f0U;
|
||||||
context->length[0] = context->length[1] = 0;
|
context->length[0] = context->length[1] = 0;
|
||||||
context->buflen = 0;
|
context->buflen = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
@ -146,205 +146,205 @@ RMD160_Init(RMD160_CTX *context)
|
||||||
void
|
void
|
||||||
RMD160_Transform(uint32_t state[5], const uint32_t block[16])
|
RMD160_Transform(uint32_t state[5], const uint32_t block[16])
|
||||||
{
|
{
|
||||||
uint32_t aa, bb, cc, dd, ee;
|
uint32_t aa, bb, cc, dd, ee;
|
||||||
uint32_t aaa, bbb, ccc, ddd, eee;
|
uint32_t aaa, bbb, ccc, ddd, eee;
|
||||||
|
|
||||||
_DIAGASSERT(state != NULL);
|
_DIAGASSERT(state != NULL);
|
||||||
_DIAGASSERT(block != NULL);
|
_DIAGASSERT(block != NULL);
|
||||||
|
|
||||||
aa = aaa = state[0];
|
aa = aaa = state[0];
|
||||||
bb = bbb = state[1];
|
bb = bbb = state[1];
|
||||||
cc = ccc = state[2];
|
cc = ccc = state[2];
|
||||||
dd = ddd = state[3];
|
dd = ddd = state[3];
|
||||||
ee = eee = state[4];
|
ee = eee = state[4];
|
||||||
|
|
||||||
/* round 1 */
|
/* round 1 */
|
||||||
FF(aa, bb, cc, dd, ee, block[ 0], 11);
|
FF(aa, bb, cc, dd, ee, block[ 0], 11);
|
||||||
FF(ee, aa, bb, cc, dd, block[ 1], 14);
|
FF(ee, aa, bb, cc, dd, block[ 1], 14);
|
||||||
FF(dd, ee, aa, bb, cc, block[ 2], 15);
|
FF(dd, ee, aa, bb, cc, block[ 2], 15);
|
||||||
FF(cc, dd, ee, aa, bb, block[ 3], 12);
|
FF(cc, dd, ee, aa, bb, block[ 3], 12);
|
||||||
FF(bb, cc, dd, ee, aa, block[ 4], 5);
|
FF(bb, cc, dd, ee, aa, block[ 4], 5);
|
||||||
FF(aa, bb, cc, dd, ee, block[ 5], 8);
|
FF(aa, bb, cc, dd, ee, block[ 5], 8);
|
||||||
FF(ee, aa, bb, cc, dd, block[ 6], 7);
|
FF(ee, aa, bb, cc, dd, block[ 6], 7);
|
||||||
FF(dd, ee, aa, bb, cc, block[ 7], 9);
|
FF(dd, ee, aa, bb, cc, block[ 7], 9);
|
||||||
FF(cc, dd, ee, aa, bb, block[ 8], 11);
|
FF(cc, dd, ee, aa, bb, block[ 8], 11);
|
||||||
FF(bb, cc, dd, ee, aa, block[ 9], 13);
|
FF(bb, cc, dd, ee, aa, block[ 9], 13);
|
||||||
FF(aa, bb, cc, dd, ee, block[10], 14);
|
FF(aa, bb, cc, dd, ee, block[10], 14);
|
||||||
FF(ee, aa, bb, cc, dd, block[11], 15);
|
FF(ee, aa, bb, cc, dd, block[11], 15);
|
||||||
FF(dd, ee, aa, bb, cc, block[12], 6);
|
FF(dd, ee, aa, bb, cc, block[12], 6);
|
||||||
FF(cc, dd, ee, aa, bb, block[13], 7);
|
FF(cc, dd, ee, aa, bb, block[13], 7);
|
||||||
FF(bb, cc, dd, ee, aa, block[14], 9);
|
FF(bb, cc, dd, ee, aa, block[14], 9);
|
||||||
FF(aa, bb, cc, dd, ee, block[15], 8);
|
FF(aa, bb, cc, dd, ee, block[15], 8);
|
||||||
|
|
||||||
/* round 2 */
|
/* round 2 */
|
||||||
GG(ee, aa, bb, cc, dd, block[ 7], 7);
|
GG(ee, aa, bb, cc, dd, block[ 7], 7);
|
||||||
GG(dd, ee, aa, bb, cc, block[ 4], 6);
|
GG(dd, ee, aa, bb, cc, block[ 4], 6);
|
||||||
GG(cc, dd, ee, aa, bb, block[13], 8);
|
GG(cc, dd, ee, aa, bb, block[13], 8);
|
||||||
GG(bb, cc, dd, ee, aa, block[ 1], 13);
|
GG(bb, cc, dd, ee, aa, block[ 1], 13);
|
||||||
GG(aa, bb, cc, dd, ee, block[10], 11);
|
GG(aa, bb, cc, dd, ee, block[10], 11);
|
||||||
GG(ee, aa, bb, cc, dd, block[ 6], 9);
|
GG(ee, aa, bb, cc, dd, block[ 6], 9);
|
||||||
GG(dd, ee, aa, bb, cc, block[15], 7);
|
GG(dd, ee, aa, bb, cc, block[15], 7);
|
||||||
GG(cc, dd, ee, aa, bb, block[ 3], 15);
|
GG(cc, dd, ee, aa, bb, block[ 3], 15);
|
||||||
GG(bb, cc, dd, ee, aa, block[12], 7);
|
GG(bb, cc, dd, ee, aa, block[12], 7);
|
||||||
GG(aa, bb, cc, dd, ee, block[ 0], 12);
|
GG(aa, bb, cc, dd, ee, block[ 0], 12);
|
||||||
GG(ee, aa, bb, cc, dd, block[ 9], 15);
|
GG(ee, aa, bb, cc, dd, block[ 9], 15);
|
||||||
GG(dd, ee, aa, bb, cc, block[ 5], 9);
|
GG(dd, ee, aa, bb, cc, block[ 5], 9);
|
||||||
GG(cc, dd, ee, aa, bb, block[ 2], 11);
|
GG(cc, dd, ee, aa, bb, block[ 2], 11);
|
||||||
GG(bb, cc, dd, ee, aa, block[14], 7);
|
GG(bb, cc, dd, ee, aa, block[14], 7);
|
||||||
GG(aa, bb, cc, dd, ee, block[11], 13);
|
GG(aa, bb, cc, dd, ee, block[11], 13);
|
||||||
GG(ee, aa, bb, cc, dd, block[ 8], 12);
|
GG(ee, aa, bb, cc, dd, block[ 8], 12);
|
||||||
|
|
||||||
/* round 3 */
|
/* round 3 */
|
||||||
HH(dd, ee, aa, bb, cc, block[ 3], 11);
|
HH(dd, ee, aa, bb, cc, block[ 3], 11);
|
||||||
HH(cc, dd, ee, aa, bb, block[10], 13);
|
HH(cc, dd, ee, aa, bb, block[10], 13);
|
||||||
HH(bb, cc, dd, ee, aa, block[14], 6);
|
HH(bb, cc, dd, ee, aa, block[14], 6);
|
||||||
HH(aa, bb, cc, dd, ee, block[ 4], 7);
|
HH(aa, bb, cc, dd, ee, block[ 4], 7);
|
||||||
HH(ee, aa, bb, cc, dd, block[ 9], 14);
|
HH(ee, aa, bb, cc, dd, block[ 9], 14);
|
||||||
HH(dd, ee, aa, bb, cc, block[15], 9);
|
HH(dd, ee, aa, bb, cc, block[15], 9);
|
||||||
HH(cc, dd, ee, aa, bb, block[ 8], 13);
|
HH(cc, dd, ee, aa, bb, block[ 8], 13);
|
||||||
HH(bb, cc, dd, ee, aa, block[ 1], 15);
|
HH(bb, cc, dd, ee, aa, block[ 1], 15);
|
||||||
HH(aa, bb, cc, dd, ee, block[ 2], 14);
|
HH(aa, bb, cc, dd, ee, block[ 2], 14);
|
||||||
HH(ee, aa, bb, cc, dd, block[ 7], 8);
|
HH(ee, aa, bb, cc, dd, block[ 7], 8);
|
||||||
HH(dd, ee, aa, bb, cc, block[ 0], 13);
|
HH(dd, ee, aa, bb, cc, block[ 0], 13);
|
||||||
HH(cc, dd, ee, aa, bb, block[ 6], 6);
|
HH(cc, dd, ee, aa, bb, block[ 6], 6);
|
||||||
HH(bb, cc, dd, ee, aa, block[13], 5);
|
HH(bb, cc, dd, ee, aa, block[13], 5);
|
||||||
HH(aa, bb, cc, dd, ee, block[11], 12);
|
HH(aa, bb, cc, dd, ee, block[11], 12);
|
||||||
HH(ee, aa, bb, cc, dd, block[ 5], 7);
|
HH(ee, aa, bb, cc, dd, block[ 5], 7);
|
||||||
HH(dd, ee, aa, bb, cc, block[12], 5);
|
HH(dd, ee, aa, bb, cc, block[12], 5);
|
||||||
|
|
||||||
/* round 4 */
|
/* round 4 */
|
||||||
II(cc, dd, ee, aa, bb, block[ 1], 11);
|
II(cc, dd, ee, aa, bb, block[ 1], 11);
|
||||||
II(bb, cc, dd, ee, aa, block[ 9], 12);
|
II(bb, cc, dd, ee, aa, block[ 9], 12);
|
||||||
II(aa, bb, cc, dd, ee, block[11], 14);
|
II(aa, bb, cc, dd, ee, block[11], 14);
|
||||||
II(ee, aa, bb, cc, dd, block[10], 15);
|
II(ee, aa, bb, cc, dd, block[10], 15);
|
||||||
II(dd, ee, aa, bb, cc, block[ 0], 14);
|
II(dd, ee, aa, bb, cc, block[ 0], 14);
|
||||||
II(cc, dd, ee, aa, bb, block[ 8], 15);
|
II(cc, dd, ee, aa, bb, block[ 8], 15);
|
||||||
II(bb, cc, dd, ee, aa, block[12], 9);
|
II(bb, cc, dd, ee, aa, block[12], 9);
|
||||||
II(aa, bb, cc, dd, ee, block[ 4], 8);
|
II(aa, bb, cc, dd, ee, block[ 4], 8);
|
||||||
II(ee, aa, bb, cc, dd, block[13], 9);
|
II(ee, aa, bb, cc, dd, block[13], 9);
|
||||||
II(dd, ee, aa, bb, cc, block[ 3], 14);
|
II(dd, ee, aa, bb, cc, block[ 3], 14);
|
||||||
II(cc, dd, ee, aa, bb, block[ 7], 5);
|
II(cc, dd, ee, aa, bb, block[ 7], 5);
|
||||||
II(bb, cc, dd, ee, aa, block[15], 6);
|
II(bb, cc, dd, ee, aa, block[15], 6);
|
||||||
II(aa, bb, cc, dd, ee, block[14], 8);
|
II(aa, bb, cc, dd, ee, block[14], 8);
|
||||||
II(ee, aa, bb, cc, dd, block[ 5], 6);
|
II(ee, aa, bb, cc, dd, block[ 5], 6);
|
||||||
II(dd, ee, aa, bb, cc, block[ 6], 5);
|
II(dd, ee, aa, bb, cc, block[ 6], 5);
|
||||||
II(cc, dd, ee, aa, bb, block[ 2], 12);
|
II(cc, dd, ee, aa, bb, block[ 2], 12);
|
||||||
|
|
||||||
/* round 5 */
|
/* round 5 */
|
||||||
JJ(bb, cc, dd, ee, aa, block[ 4], 9);
|
JJ(bb, cc, dd, ee, aa, block[ 4], 9);
|
||||||
JJ(aa, bb, cc, dd, ee, block[ 0], 15);
|
JJ(aa, bb, cc, dd, ee, block[ 0], 15);
|
||||||
JJ(ee, aa, bb, cc, dd, block[ 5], 5);
|
JJ(ee, aa, bb, cc, dd, block[ 5], 5);
|
||||||
JJ(dd, ee, aa, bb, cc, block[ 9], 11);
|
JJ(dd, ee, aa, bb, cc, block[ 9], 11);
|
||||||
JJ(cc, dd, ee, aa, bb, block[ 7], 6);
|
JJ(cc, dd, ee, aa, bb, block[ 7], 6);
|
||||||
JJ(bb, cc, dd, ee, aa, block[12], 8);
|
JJ(bb, cc, dd, ee, aa, block[12], 8);
|
||||||
JJ(aa, bb, cc, dd, ee, block[ 2], 13);
|
JJ(aa, bb, cc, dd, ee, block[ 2], 13);
|
||||||
JJ(ee, aa, bb, cc, dd, block[10], 12);
|
JJ(ee, aa, bb, cc, dd, block[10], 12);
|
||||||
JJ(dd, ee, aa, bb, cc, block[14], 5);
|
JJ(dd, ee, aa, bb, cc, block[14], 5);
|
||||||
JJ(cc, dd, ee, aa, bb, block[ 1], 12);
|
JJ(cc, dd, ee, aa, bb, block[ 1], 12);
|
||||||
JJ(bb, cc, dd, ee, aa, block[ 3], 13);
|
JJ(bb, cc, dd, ee, aa, block[ 3], 13);
|
||||||
JJ(aa, bb, cc, dd, ee, block[ 8], 14);
|
JJ(aa, bb, cc, dd, ee, block[ 8], 14);
|
||||||
JJ(ee, aa, bb, cc, dd, block[11], 11);
|
JJ(ee, aa, bb, cc, dd, block[11], 11);
|
||||||
JJ(dd, ee, aa, bb, cc, block[ 6], 8);
|
JJ(dd, ee, aa, bb, cc, block[ 6], 8);
|
||||||
JJ(cc, dd, ee, aa, bb, block[15], 5);
|
JJ(cc, dd, ee, aa, bb, block[15], 5);
|
||||||
JJ(bb, cc, dd, ee, aa, block[13], 6);
|
JJ(bb, cc, dd, ee, aa, block[13], 6);
|
||||||
|
|
||||||
/* parallel round 1 */
|
/* parallel round 1 */
|
||||||
JJJ(aaa, bbb, ccc, ddd, eee, block[ 5], 8);
|
JJJ(aaa, bbb, ccc, ddd, eee, block[ 5], 8);
|
||||||
JJJ(eee, aaa, bbb, ccc, ddd, block[14], 9);
|
JJJ(eee, aaa, bbb, ccc, ddd, block[14], 9);
|
||||||
JJJ(ddd, eee, aaa, bbb, ccc, block[ 7], 9);
|
JJJ(ddd, eee, aaa, bbb, ccc, block[ 7], 9);
|
||||||
JJJ(ccc, ddd, eee, aaa, bbb, block[ 0], 11);
|
JJJ(ccc, ddd, eee, aaa, bbb, block[ 0], 11);
|
||||||
JJJ(bbb, ccc, ddd, eee, aaa, block[ 9], 13);
|
JJJ(bbb, ccc, ddd, eee, aaa, block[ 9], 13);
|
||||||
JJJ(aaa, bbb, ccc, ddd, eee, block[ 2], 15);
|
JJJ(aaa, bbb, ccc, ddd, eee, block[ 2], 15);
|
||||||
JJJ(eee, aaa, bbb, ccc, ddd, block[11], 15);
|
JJJ(eee, aaa, bbb, ccc, ddd, block[11], 15);
|
||||||
JJJ(ddd, eee, aaa, bbb, ccc, block[ 4], 5);
|
JJJ(ddd, eee, aaa, bbb, ccc, block[ 4], 5);
|
||||||
JJJ(ccc, ddd, eee, aaa, bbb, block[13], 7);
|
JJJ(ccc, ddd, eee, aaa, bbb, block[13], 7);
|
||||||
JJJ(bbb, ccc, ddd, eee, aaa, block[ 6], 7);
|
JJJ(bbb, ccc, ddd, eee, aaa, block[ 6], 7);
|
||||||
JJJ(aaa, bbb, ccc, ddd, eee, block[15], 8);
|
JJJ(aaa, bbb, ccc, ddd, eee, block[15], 8);
|
||||||
JJJ(eee, aaa, bbb, ccc, ddd, block[ 8], 11);
|
JJJ(eee, aaa, bbb, ccc, ddd, block[ 8], 11);
|
||||||
JJJ(ddd, eee, aaa, bbb, ccc, block[ 1], 14);
|
JJJ(ddd, eee, aaa, bbb, ccc, block[ 1], 14);
|
||||||
JJJ(ccc, ddd, eee, aaa, bbb, block[10], 14);
|
JJJ(ccc, ddd, eee, aaa, bbb, block[10], 14);
|
||||||
JJJ(bbb, ccc, ddd, eee, aaa, block[ 3], 12);
|
JJJ(bbb, ccc, ddd, eee, aaa, block[ 3], 12);
|
||||||
JJJ(aaa, bbb, ccc, ddd, eee, block[12], 6);
|
JJJ(aaa, bbb, ccc, ddd, eee, block[12], 6);
|
||||||
|
|
||||||
/* parallel round 2 */
|
/* parallel round 2 */
|
||||||
III(eee, aaa, bbb, ccc, ddd, block[ 6], 9);
|
III(eee, aaa, bbb, ccc, ddd, block[ 6], 9);
|
||||||
III(ddd, eee, aaa, bbb, ccc, block[11], 13);
|
III(ddd, eee, aaa, bbb, ccc, block[11], 13);
|
||||||
III(ccc, ddd, eee, aaa, bbb, block[ 3], 15);
|
III(ccc, ddd, eee, aaa, bbb, block[ 3], 15);
|
||||||
III(bbb, ccc, ddd, eee, aaa, block[ 7], 7);
|
III(bbb, ccc, ddd, eee, aaa, block[ 7], 7);
|
||||||
III(aaa, bbb, ccc, ddd, eee, block[ 0], 12);
|
III(aaa, bbb, ccc, ddd, eee, block[ 0], 12);
|
||||||
III(eee, aaa, bbb, ccc, ddd, block[13], 8);
|
III(eee, aaa, bbb, ccc, ddd, block[13], 8);
|
||||||
III(ddd, eee, aaa, bbb, ccc, block[ 5], 9);
|
III(ddd, eee, aaa, bbb, ccc, block[ 5], 9);
|
||||||
III(ccc, ddd, eee, aaa, bbb, block[10], 11);
|
III(ccc, ddd, eee, aaa, bbb, block[10], 11);
|
||||||
III(bbb, ccc, ddd, eee, aaa, block[14], 7);
|
III(bbb, ccc, ddd, eee, aaa, block[14], 7);
|
||||||
III(aaa, bbb, ccc, ddd, eee, block[15], 7);
|
III(aaa, bbb, ccc, ddd, eee, block[15], 7);
|
||||||
III(eee, aaa, bbb, ccc, ddd, block[ 8], 12);
|
III(eee, aaa, bbb, ccc, ddd, block[ 8], 12);
|
||||||
III(ddd, eee, aaa, bbb, ccc, block[12], 7);
|
III(ddd, eee, aaa, bbb, ccc, block[12], 7);
|
||||||
III(ccc, ddd, eee, aaa, bbb, block[ 4], 6);
|
III(ccc, ddd, eee, aaa, bbb, block[ 4], 6);
|
||||||
III(bbb, ccc, ddd, eee, aaa, block[ 9], 15);
|
III(bbb, ccc, ddd, eee, aaa, block[ 9], 15);
|
||||||
III(aaa, bbb, ccc, ddd, eee, block[ 1], 13);
|
III(aaa, bbb, ccc, ddd, eee, block[ 1], 13);
|
||||||
III(eee, aaa, bbb, ccc, ddd, block[ 2], 11);
|
III(eee, aaa, bbb, ccc, ddd, block[ 2], 11);
|
||||||
|
|
||||||
/* parallel round 3 */
|
/* parallel round 3 */
|
||||||
HHH(ddd, eee, aaa, bbb, ccc, block[15], 9);
|
HHH(ddd, eee, aaa, bbb, ccc, block[15], 9);
|
||||||
HHH(ccc, ddd, eee, aaa, bbb, block[ 5], 7);
|
HHH(ccc, ddd, eee, aaa, bbb, block[ 5], 7);
|
||||||
HHH(bbb, ccc, ddd, eee, aaa, block[ 1], 15);
|
HHH(bbb, ccc, ddd, eee, aaa, block[ 1], 15);
|
||||||
HHH(aaa, bbb, ccc, ddd, eee, block[ 3], 11);
|
HHH(aaa, bbb, ccc, ddd, eee, block[ 3], 11);
|
||||||
HHH(eee, aaa, bbb, ccc, ddd, block[ 7], 8);
|
HHH(eee, aaa, bbb, ccc, ddd, block[ 7], 8);
|
||||||
HHH(ddd, eee, aaa, bbb, ccc, block[14], 6);
|
HHH(ddd, eee, aaa, bbb, ccc, block[14], 6);
|
||||||
HHH(ccc, ddd, eee, aaa, bbb, block[ 6], 6);
|
HHH(ccc, ddd, eee, aaa, bbb, block[ 6], 6);
|
||||||
HHH(bbb, ccc, ddd, eee, aaa, block[ 9], 14);
|
HHH(bbb, ccc, ddd, eee, aaa, block[ 9], 14);
|
||||||
HHH(aaa, bbb, ccc, ddd, eee, block[11], 12);
|
HHH(aaa, bbb, ccc, ddd, eee, block[11], 12);
|
||||||
HHH(eee, aaa, bbb, ccc, ddd, block[ 8], 13);
|
HHH(eee, aaa, bbb, ccc, ddd, block[ 8], 13);
|
||||||
HHH(ddd, eee, aaa, bbb, ccc, block[12], 5);
|
HHH(ddd, eee, aaa, bbb, ccc, block[12], 5);
|
||||||
HHH(ccc, ddd, eee, aaa, bbb, block[ 2], 14);
|
HHH(ccc, ddd, eee, aaa, bbb, block[ 2], 14);
|
||||||
HHH(bbb, ccc, ddd, eee, aaa, block[10], 13);
|
HHH(bbb, ccc, ddd, eee, aaa, block[10], 13);
|
||||||
HHH(aaa, bbb, ccc, ddd, eee, block[ 0], 13);
|
HHH(aaa, bbb, ccc, ddd, eee, block[ 0], 13);
|
||||||
HHH(eee, aaa, bbb, ccc, ddd, block[ 4], 7);
|
HHH(eee, aaa, bbb, ccc, ddd, block[ 4], 7);
|
||||||
HHH(ddd, eee, aaa, bbb, ccc, block[13], 5);
|
HHH(ddd, eee, aaa, bbb, ccc, block[13], 5);
|
||||||
|
|
||||||
/* parallel round 4 */
|
/* parallel round 4 */
|
||||||
GGG(ccc, ddd, eee, aaa, bbb, block[ 8], 15);
|
GGG(ccc, ddd, eee, aaa, bbb, block[ 8], 15);
|
||||||
GGG(bbb, ccc, ddd, eee, aaa, block[ 6], 5);
|
GGG(bbb, ccc, ddd, eee, aaa, block[ 6], 5);
|
||||||
GGG(aaa, bbb, ccc, ddd, eee, block[ 4], 8);
|
GGG(aaa, bbb, ccc, ddd, eee, block[ 4], 8);
|
||||||
GGG(eee, aaa, bbb, ccc, ddd, block[ 1], 11);
|
GGG(eee, aaa, bbb, ccc, ddd, block[ 1], 11);
|
||||||
GGG(ddd, eee, aaa, bbb, ccc, block[ 3], 14);
|
GGG(ddd, eee, aaa, bbb, ccc, block[ 3], 14);
|
||||||
GGG(ccc, ddd, eee, aaa, bbb, block[11], 14);
|
GGG(ccc, ddd, eee, aaa, bbb, block[11], 14);
|
||||||
GGG(bbb, ccc, ddd, eee, aaa, block[15], 6);
|
GGG(bbb, ccc, ddd, eee, aaa, block[15], 6);
|
||||||
GGG(aaa, bbb, ccc, ddd, eee, block[ 0], 14);
|
GGG(aaa, bbb, ccc, ddd, eee, block[ 0], 14);
|
||||||
GGG(eee, aaa, bbb, ccc, ddd, block[ 5], 6);
|
GGG(eee, aaa, bbb, ccc, ddd, block[ 5], 6);
|
||||||
GGG(ddd, eee, aaa, bbb, ccc, block[12], 9);
|
GGG(ddd, eee, aaa, bbb, ccc, block[12], 9);
|
||||||
GGG(ccc, ddd, eee, aaa, bbb, block[ 2], 12);
|
GGG(ccc, ddd, eee, aaa, bbb, block[ 2], 12);
|
||||||
GGG(bbb, ccc, ddd, eee, aaa, block[13], 9);
|
GGG(bbb, ccc, ddd, eee, aaa, block[13], 9);
|
||||||
GGG(aaa, bbb, ccc, ddd, eee, block[ 9], 12);
|
GGG(aaa, bbb, ccc, ddd, eee, block[ 9], 12);
|
||||||
GGG(eee, aaa, bbb, ccc, ddd, block[ 7], 5);
|
GGG(eee, aaa, bbb, ccc, ddd, block[ 7], 5);
|
||||||
GGG(ddd, eee, aaa, bbb, ccc, block[10], 15);
|
GGG(ddd, eee, aaa, bbb, ccc, block[10], 15);
|
||||||
GGG(ccc, ddd, eee, aaa, bbb, block[14], 8);
|
GGG(ccc, ddd, eee, aaa, bbb, block[14], 8);
|
||||||
|
|
||||||
/* parallel round 5 */
|
/* parallel round 5 */
|
||||||
FFF(bbb, ccc, ddd, eee, aaa, block[12] , 8);
|
FFF(bbb, ccc, ddd, eee, aaa, block[12] , 8);
|
||||||
FFF(aaa, bbb, ccc, ddd, eee, block[15] , 5);
|
FFF(aaa, bbb, ccc, ddd, eee, block[15] , 5);
|
||||||
FFF(eee, aaa, bbb, ccc, ddd, block[10] , 12);
|
FFF(eee, aaa, bbb, ccc, ddd, block[10] , 12);
|
||||||
FFF(ddd, eee, aaa, bbb, ccc, block[ 4] , 9);
|
FFF(ddd, eee, aaa, bbb, ccc, block[ 4] , 9);
|
||||||
FFF(ccc, ddd, eee, aaa, bbb, block[ 1] , 12);
|
FFF(ccc, ddd, eee, aaa, bbb, block[ 1] , 12);
|
||||||
FFF(bbb, ccc, ddd, eee, aaa, block[ 5] , 5);
|
FFF(bbb, ccc, ddd, eee, aaa, block[ 5] , 5);
|
||||||
FFF(aaa, bbb, ccc, ddd, eee, block[ 8] , 14);
|
FFF(aaa, bbb, ccc, ddd, eee, block[ 8] , 14);
|
||||||
FFF(eee, aaa, bbb, ccc, ddd, block[ 7] , 6);
|
FFF(eee, aaa, bbb, ccc, ddd, block[ 7] , 6);
|
||||||
FFF(ddd, eee, aaa, bbb, ccc, block[ 6] , 8);
|
FFF(ddd, eee, aaa, bbb, ccc, block[ 6] , 8);
|
||||||
FFF(ccc, ddd, eee, aaa, bbb, block[ 2] , 13);
|
FFF(ccc, ddd, eee, aaa, bbb, block[ 2] , 13);
|
||||||
FFF(bbb, ccc, ddd, eee, aaa, block[13] , 6);
|
FFF(bbb, ccc, ddd, eee, aaa, block[13] , 6);
|
||||||
FFF(aaa, bbb, ccc, ddd, eee, block[14] , 5);
|
FFF(aaa, bbb, ccc, ddd, eee, block[14] , 5);
|
||||||
FFF(eee, aaa, bbb, ccc, ddd, block[ 0] , 15);
|
FFF(eee, aaa, bbb, ccc, ddd, block[ 0] , 15);
|
||||||
FFF(ddd, eee, aaa, bbb, ccc, block[ 3] , 13);
|
FFF(ddd, eee, aaa, bbb, ccc, block[ 3] , 13);
|
||||||
FFF(ccc, ddd, eee, aaa, bbb, block[ 9] , 11);
|
FFF(ccc, ddd, eee, aaa, bbb, block[ 9] , 11);
|
||||||
FFF(bbb, ccc, ddd, eee, aaa, block[11] , 11);
|
FFF(bbb, ccc, ddd, eee, aaa, block[11] , 11);
|
||||||
|
|
||||||
/* combine results */
|
/* combine results */
|
||||||
ddd += cc + state[1]; /* final result for state[0] */
|
ddd += cc + state[1]; /* final result for state[0] */
|
||||||
state[1] = state[2] + dd + eee;
|
state[1] = state[2] + dd + eee;
|
||||||
state[2] = state[3] + ee + aaa;
|
state[2] = state[3] + ee + aaa;
|
||||||
state[3] = state[4] + aa + bbb;
|
state[3] = state[4] + aa + bbb;
|
||||||
state[4] = state[0] + bb + ccc;
|
state[4] = state[0] + bb + ccc;
|
||||||
state[0] = ddd;
|
state[0] = ddd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
@ -352,26 +352,26 @@ RMD160_Transform(uint32_t state[5], const uint32_t block[16])
|
||||||
void
|
void
|
||||||
RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
|
RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
|
||||||
{
|
{
|
||||||
uint32_t X[16];
|
uint32_t X[16];
|
||||||
uint32_t ofs = 0;
|
uint32_t ofs = 0;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_DIAGASSERT(context != NULL);
|
_DIAGASSERT(context != NULL);
|
||||||
_DIAGASSERT(data != NULL);
|
_DIAGASSERT(data != NULL);
|
||||||
|
|
||||||
/* update length[] */
|
/* update length[] */
|
||||||
#if SIZEOF_SIZE_T * CHAR_BIT > 32
|
#if SIZEOF_SIZE_T * CHAR_BIT > 32
|
||||||
context->length[1] += (uint32_t)((context->length[0] + nbytes) >> 32);
|
context->length[1] += (uint32_t)((context->length[0] + nbytes) >> 32);
|
||||||
#else
|
#else
|
||||||
if (context->length[0] + nbytes < context->length[0])
|
if (context->length[0] + nbytes < context->length[0])
|
||||||
context->length[1]++; /* overflow to msb of length */
|
context->length[1]++; /* overflow to msb of length */
|
||||||
#endif
|
#endif
|
||||||
context->length[0] += (uint32_t)nbytes;
|
context->length[0] += (uint32_t)nbytes;
|
||||||
|
|
||||||
(void)memset(X, 0, sizeof(X));
|
(void)memset(X, 0, sizeof(X));
|
||||||
|
|
||||||
if ( context->buflen + nbytes < 64 )
|
if ( context->buflen + nbytes < 64 )
|
||||||
{
|
{
|
||||||
|
@ -416,48 +416,48 @@ RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
|
||||||
int
|
int
|
||||||
RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
|
RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t X[16];
|
uint32_t X[16];
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_DIAGASSERT(digest != NULL);
|
_DIAGASSERT(digest != NULL);
|
||||||
_DIAGASSERT(context != NULL);
|
_DIAGASSERT(context != NULL);
|
||||||
|
|
||||||
/* append the bit m_n == 1 */
|
/* append the bit m_n == 1 */
|
||||||
context->bbuffer[context->buflen] = (uint8_t)'\200';
|
context->bbuffer[context->buflen] = (uint8_t)'\200';
|
||||||
|
|
||||||
(void)memset(context->bbuffer + context->buflen + 1, 0,
|
(void)memset(context->bbuffer + context->buflen + 1, 0,
|
||||||
63 - context->buflen);
|
63 - context->buflen);
|
||||||
#ifndef WORDS_BIGENDIAN
|
#ifndef WORDS_BIGENDIAN
|
||||||
(void)memcpy(X, context->bbuffer, sizeof(X));
|
(void)memcpy(X, context->bbuffer, sizeof(X));
|
||||||
#else
|
#else
|
||||||
for (j=0; j < 16; j++)
|
for (j=0; j < 16; j++)
|
||||||
X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
|
X[j] = BYTES_TO_DWORD(context->bbuffer + (4 * j));
|
||||||
#endif
|
#endif
|
||||||
if ((context->buflen) > 55) {
|
if ((context->buflen) > 55) {
|
||||||
/* length goes to next block */
|
/* length goes to next block */
|
||||||
RMD160_Transform(context->state, X);
|
RMD160_Transform(context->state, X);
|
||||||
(void)memset(X, 0, sizeof(X));
|
(void)memset(X, 0, sizeof(X));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* append length in bits */
|
/* append length in bits */
|
||||||
X[14] = context->length[0] << 3;
|
X[14] = context->length[0] << 3;
|
||||||
X[15] = (context->length[0] >> 29) |
|
X[15] = (context->length[0] >> 29) |
|
||||||
(context->length[1] << 3);
|
(context->length[1] << 3);
|
||||||
RMD160_Transform(context->state, X);
|
RMD160_Transform(context->state, X);
|
||||||
|
|
||||||
if (digest != NULL) {
|
if (digest != NULL) {
|
||||||
for (i = 0; i < 20; i += 4) {
|
for (i = 0; i < 20; i += 4) {
|
||||||
/* extracts the 8 least significant bits. */
|
/* extracts the 8 least significant bits. */
|
||||||
digest[i] = context->state[i>>2];
|
digest[i] = context->state[i>>2];
|
||||||
digest[i + 1] = (context->state[i>>2] >> 8);
|
digest[i + 1] = (context->state[i>>2] >> 8);
|
||||||
digest[i + 2] = (context->state[i>>2] >> 16);
|
digest[i + 2] = (context->state[i>>2] >> 16);
|
||||||
digest[i + 3] = (context->state[i>>2] >> 24);
|
digest[i + 3] = (context->state[i>>2] >> 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************ end of file rmd160.c **********************/
|
/************************ end of file rmd160.c **********************/
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t state[5]; /* state (ABCDE) */
|
uint32_t state[5]; /* state (ABCDE) */
|
||||||
uint32_t length[2]; /* number of bits */
|
uint32_t length[2]; /* number of bits */
|
||||||
uint8_t bbuffer[64]; /* overflow buffer */
|
uint8_t bbuffer[64]; /* overflow buffer */
|
||||||
uint32_t buflen; /* number of chars in bbuffer */
|
uint32_t buflen; /* number of chars in bbuffer */
|
||||||
} RMD160_CTX;
|
} RMD160_CTX;
|
||||||
|
|
||||||
#ifdef RUBY
|
#ifdef RUBY
|
||||||
|
|
|
@ -227,16 +227,16 @@ void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
|
||||||
|
|
||||||
j = context->count[0];
|
j = context->count[0];
|
||||||
if ((context->count[0] += len << 3) < j)
|
if ((context->count[0] += len << 3) < j)
|
||||||
context->count[1] += (len>>29)+1;
|
context->count[1] += (len>>29)+1;
|
||||||
j = (j >> 3) & 63;
|
j = (j >> 3) & 63;
|
||||||
if ((j + len) > 63) {
|
if ((j + len) > 63) {
|
||||||
(void)memcpy(&context->buffer[j], data, (i = 64-j));
|
(void)memcpy(&context->buffer[j], data, (i = 64-j));
|
||||||
SHA1_Transform(context->state, context->buffer);
|
SHA1_Transform(context->state, context->buffer);
|
||||||
for ( ; i + 63 < len; i += 64)
|
for ( ; i + 63 < len; i += 64)
|
||||||
SHA1_Transform(context->state, &data[i]);
|
SHA1_Transform(context->state, &data[i]);
|
||||||
j = 0;
|
j = 0;
|
||||||
} else {
|
} else {
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
(void)memcpy(&context->buffer[j], &data[i], len - i);
|
(void)memcpy(&context->buffer[j], &data[i], len - i);
|
||||||
}
|
}
|
||||||
|
@ -254,18 +254,18 @@ int SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
|
||||||
_DIAGASSERT(context != 0);
|
_DIAGASSERT(context != 0);
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)]
|
finalcount[i] = (uint8_t)((context->count[(i >= 4 ? 0 : 1)]
|
||||||
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
>> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */
|
||||||
}
|
}
|
||||||
SHA1_Update(context, (const uint8_t *)"\200", 1);
|
SHA1_Update(context, (const uint8_t *)"\200", 1);
|
||||||
while ((context->count[0] & 504) != 448)
|
while ((context->count[0] & 504) != 448)
|
||||||
SHA1_Update(context, (const uint8_t *)"\0", 1);
|
SHA1_Update(context, (const uint8_t *)"\0", 1);
|
||||||
SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
|
SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */
|
||||||
|
|
||||||
if (digest) {
|
if (digest) {
|
||||||
for (i = 0; i < 20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
digest[i] = (uint8_t)
|
digest[i] = (uint8_t)
|
||||||
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
#include "../defs.h"
|
#include "../defs.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t state[5];
|
uint32_t state[5];
|
||||||
uint32_t count[2];
|
uint32_t count[2];
|
||||||
uint8_t buffer[64];
|
uint8_t buffer[64];
|
||||||
} SHA1_CTX;
|
} SHA1_CTX;
|
||||||
|
|
||||||
#ifdef RUBY
|
#ifdef RUBY
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -120,14 +120,14 @@ typedef unsigned long long uint64_t; /* 8-bytes (64-bits) */
|
||||||
* cc -DSHA2_USE_INTTYPES_H ...
|
* cc -DSHA2_USE_INTTYPES_H ...
|
||||||
*/
|
*/
|
||||||
typedef struct _SHA256_CTX {
|
typedef struct _SHA256_CTX {
|
||||||
uint32_t state[8];
|
uint32_t state[8];
|
||||||
uint64_t bitcount;
|
uint64_t bitcount;
|
||||||
uint8_t buffer[SHA256_BLOCK_LENGTH];
|
uint8_t buffer[SHA256_BLOCK_LENGTH];
|
||||||
} SHA256_CTX;
|
} SHA256_CTX;
|
||||||
typedef struct _SHA512_CTX {
|
typedef struct _SHA512_CTX {
|
||||||
uint64_t state[8];
|
uint64_t state[8];
|
||||||
uint64_t bitcount[2];
|
uint64_t bitcount[2];
|
||||||
uint8_t buffer[SHA512_BLOCK_LENGTH];
|
uint8_t buffer[SHA512_BLOCK_LENGTH];
|
||||||
} SHA512_CTX;
|
} SHA512_CTX;
|
||||||
|
|
||||||
typedef SHA512_CTX SHA384_CTX;
|
typedef SHA512_CTX SHA384_CTX;
|
||||||
|
|
Loading…
Reference in a new issue