[BACK]Return to ntlsha.cpp CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_ntl / crypt / sha1

Annotation of OpenXM/src/ox_ntl/crypt/sha1/ntlsha.cpp, Revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>