version 1.2, 2004/03/25 13:34:19 |
version 1.3, 2004/05/16 15:02:39 |
|
|
/* $OpenXM: OpenXM/src/ox_ntl/crypt/sha1/sha1.c,v 1.1 2004/01/12 13:16:28 iwane Exp $ */ |
/* $OpenXM: OpenXM/src/ox_ntl/crypt/sha1/sha1.c,v 1.2 2004/03/25 13:34:19 iwane Exp $ */ |
/* RFC 3174 - SHA-1 (US Secure Hash Algorithm 1 (SHA1))*/ |
/* RFC 3174 - SHA-1 (US Secure Hash Algorithm 1 (SHA1))*/ |
|
|
|
#include <stdio.h> |
|
|
#include "sha1.h" |
#include "sha1.h" |
|
|
/* Global Constant */ |
/* Global Constant */ |
Line 81 f(unsigned int t, unsigned int b, unsigned int c, unsi |
|
Line 83 f(unsigned int t, unsigned int b, unsigned int c, unsi |
|
/* sizeof(msg) == 512 / 8. |
/* sizeof(msg) == 512 / 8. |
* padding. |
* padding. |
*/ |
*/ |
static void |
void |
md(unsigned int *h, const unsigned char *msg) |
sha1_md(unsigned int *h, const unsigned char *msg) |
{ |
{ |
int t; |
int t; |
unsigned int a, b, c, d, e, temp; |
unsigned int a, b, c, d, e, temp; |
Line 114 md(unsigned int *h, const unsigned char *msg) |
|
Line 116 md(unsigned int *h, const unsigned char *msg) |
|
c = lshift32(b, 30); |
c = lshift32(b, 30); |
b = a; |
b = a; |
a = temp; |
a = temp; |
|
|
} |
} |
|
|
h[0] += a; |
h[0] += a; |
Line 131 sha1_h(unsigned char *Ph, const unsigned char *msg, in |
|
Line 132 sha1_h(unsigned char *Ph, const unsigned char *msg, in |
|
unsigned char buf[1024]; |
unsigned char buf[1024]; |
unsigned int h[sizeof(H) / sizeof(H[0])]; |
unsigned int h[sizeof(H) / sizeof(H[0])]; |
|
|
memcpy(h, hp, sizeof(h)); |
if (hp == NULL) |
|
memcpy(h, H, sizeof(H)); |
|
else |
|
memcpy(h, hp, sizeof(h)); |
|
|
while (l > BLOCK) { |
while (l > BLOCK) { |
md(h, msg); |
sha1_md(h, msg); |
msg += BLOCK; |
msg += BLOCK; |
l -= BLOCK; |
l -= BLOCK; |
} |
} |
|
|
cnt = padding(buf, msg, len); |
cnt = padding(buf, msg, len); |
for (i = 0; i < cnt; i++) { |
for (i = 0; i < cnt; i++) { |
md(h, buf + BLOCK * i); |
sha1_md(h, buf + BLOCK * i); |
} |
} |
|
|
memset(Ph, 0x00, sizeof(H)); |
memset(Ph, 0x00, sizeof(H)); |
Line 151 sha1_h(unsigned char *Ph, const unsigned char *msg, in |
|
Line 155 sha1_h(unsigned char *Ph, const unsigned char *msg, in |
|
} |
} |
} |
} |
|
|
|
|
return (0); |
return (0); |
} |
} |
|
|
Line 159 sha1_h(unsigned char *Ph, const unsigned char *msg, in |
|
Line 162 sha1_h(unsigned char *Ph, const unsigned char *msg, in |
|
int |
int |
sha1(unsigned char *Ph, const unsigned char *msg, int len) |
sha1(unsigned char *Ph, const unsigned char *msg, int len) |
{ |
{ |
return (sha1_h(Ph, msg, len, H)); |
return (sha1_h(Ph, msg, len, NULL)); |
} |
} |
|
|
|
|