Annotation of OpenXM/src/ox_ntl/crypt/sha1/ntlsha.cpp, Revision 1.3
1.3 ! iwane 1: /* $OpenXM: OpenXM/src/ox_ntl/crypt/sha1/ntlsha.cpp,v 1.2 2004/03/25 13:34:19 iwane Exp $ */
1.2 iwane 2: /* RFC 3174 -- see sha1.c */
1.1 iwane 3:
4: #include <NTL/ZZ.h>
5:
6: #include <stdlib.h>
1.3 ! iwane 7: #include <stdio.h>
1.1 iwane 8:
9: #include "sha1.h"
10:
11: int
12: ntl_sha1_h(ZZ &sha, const ZZ &m, unsigned int *t)
13: {
14: unsigned char h[20]; // 160 bit
15: unsigned char *msg, msg_buf[1024];
16: unsigned int msglen = sizeof(msg);
17: unsigned int i;
18: unsigned char uch;
19: int ret;
20:
21: msglen = NumBytes(m);
1.3 ! iwane 22: if (msglen <= sizeof(msg_buf)) {
1.1 iwane 23: msg = msg_buf;
24: } else {
25: msg = new unsigned char[msglen];
26: }
27:
28: BytesFromZZ(msg, m, msglen);
29:
30: for (i = 0; i < msglen / 2; i++) {
31: uch = msg[i];
32: msg[i] = msg[msglen - i - 1];
33: msg[msglen - i - 1] = uch;
34: }
35:
1.3 ! iwane 36: ret = sha1_h(h, msg, msglen, t);
1.1 iwane 37:
38: if (msg != msg_buf)
39: delete [] msg;
40:
41: for (i = 0; i < sizeof(h) / 2; i++) {
42: uch = h[i];
43: h[i] = h[sizeof(h) - i - 1];
44: h[sizeof(h) - i - 1] = uch;
45: }
46:
47: ZZFromBytes(sha, h, sizeof(h));
48:
49: return (ret);
50: }
51:
52: int
53: ntl_sha1(ZZ &sha, const ZZ &m)
54: {
55: return (ntl_sha1_h(sha, m, NULL));
56: }
57:
58:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>