Annotation of truecrypt/crypto/rmd160.c, revision 1.1.1.6

1.1.1.6 ! root        1: // RIPEMD-160 written and placed in the public domain by Wei Dai
        !             2: 
1.1       root        3: /*
1.1.1.6 ! root        4:  * This code implements the MD4 message-digest algorithm.
        !             5:  * The algorithm is due to Ron Rivest.  This code was
        !             6:  * written by Colin Plumb in 1993, no copyright is claimed.
        !             7:  * This code is in the public domain; do with it what you wish.
1.1       root        8:  */
                      9: 
1.1.1.3   root       10: /* Adapted by TrueCrypt Foundation */
                     11: 
1.1       root       12: #include <memory.h>
1.1.1.6 ! root       13: #include "Common/Tcdefs.h"
        !            14: #include "Common/Endian.h"
        !            15: #include "Rmd160.h"
1.1       root       16: 
1.1.1.6 ! root       17: #define F(x, y, z)    (x ^ y ^ z) 
        !            18: #define G(x, y, z)    (z ^ (x & (y^z)))
        !            19: #define H(x, y, z)    (z ^ (x | ~y))
        !            20: #define I(x, y, z)    (y ^ (z & (x^y)))
        !            21: #define J(x, y, z)    (x ^ (y | ~z))
        !            22: 
        !            23: #define PUT_64BIT_LE(cp, value) do {                                    \
        !            24:        (cp)[7] = (byte) ((value) >> 56);                                        \
        !            25:        (cp)[6] = (byte) ((value) >> 48);                                        \
        !            26:        (cp)[5] = (byte) ((value) >> 40);                                        \
        !            27:        (cp)[4] = (byte) ((value) >> 32);                                        \
        !            28:        (cp)[3] = (byte) ((value) >> 24);                                        \
        !            29:        (cp)[2] = (byte) ((value) >> 16);                                        \
        !            30:        (cp)[1] = (byte) ((value) >> 8);                                         \
        !            31:        (cp)[0] = (byte) (value); } while (0)
        !            32: 
        !            33: #define PUT_32BIT_LE(cp, value) do {                                    \
        !            34:        (cp)[3] = (byte) ((value) >> 24);                                        \
        !            35:        (cp)[2] = (byte) ((value) >> 16);                                        \
        !            36:        (cp)[1] = (byte) ((value) >> 8);                                         \
        !            37:        (cp)[0] = (byte) (value); } while (0)
1.1       root       38: 
1.1.1.3   root       39: #ifndef TC_MINIMIZE_CODE_SIZE
                     40: 
1.1.1.6 ! root       41: static byte PADDING[64] = {
1.1       root       42:        0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     43:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     44:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                     45: };
                     46: 
1.1.1.3   root       47: #else
                     48: 
1.1.1.6 ! root       49: static byte PADDING[64];
1.1.1.3   root       50: 
1.1.1.6 ! root       51: #endif
1.1.1.3   root       52: 
1.1.1.6 ! root       53: void RMD160Init (RMD160_CTX *ctx)
1.1       root       54: {
                     55:        ctx->count = 0;
1.1.1.6 ! root       56:        ctx->state[0] = 0x67452301;
        !            57:        ctx->state[1] = 0xefcdab89;
        !            58:        ctx->state[2] = 0x98badcfe;
        !            59:        ctx->state[3] = 0x10325476;
        !            60:        ctx->state[4] = 0xc3d2e1f0;
1.1.1.3   root       61:        PADDING[0] = 0x80;
1.1       root       62: }
                     63: 
1.1.1.6 ! root       64: /*
        !            65: * Update context to reflect the concatenation of another buffer full
        !            66: * of bytes.
        !            67: */
        !            68: void RMD160Update (RMD160_CTX *ctx, const unsigned char *input, unsigned __int32 len)
1.1       root       69: {
1.1.1.6 ! root       70:        size_t have, need;
        !            71: 
        !            72:        /* Check how many bytes we already have and how many more we need. */
        !            73:        have = (size_t)((ctx->count >> 3) & (RIPEMD160_BLOCK_LENGTH - 1));
        !            74:        need = RIPEMD160_BLOCK_LENGTH - have;
1.1       root       75: 
1.1.1.6 ! root       76:        /* Update bitcount */
        !            77:        ctx->count += 
        !            78: #ifndef TC_NO_COMPILER_INT64
        !            79:                (uint64)
        !            80: #endif
        !            81:                len << 3;
1.1       root       82: 
                     83:        if (len >= need) {
1.1.1.6 ! root       84:                if (have != 0) {
        !            85:                        memcpy (ctx->buffer + have, input, need);
        !            86:                        RMD160Transform ((uint32 *) ctx->state, (const uint32 *) ctx->buffer);
        !            87:                        input += need;
        !            88:                        len -= need;
1.1       root       89:                        have = 0;
                     90:                }
1.1.1.6 ! root       91: 
        !            92:                /* Process data in RIPEMD160_BLOCK_LENGTH-byte chunks. */
        !            93:                while (len >= RIPEMD160_BLOCK_LENGTH) {
        !            94:                        RMD160Transform ((uint32 *) ctx->state, (const uint32 *) input);
        !            95:                        input += RIPEMD160_BLOCK_LENGTH;
        !            96:                        len -= RIPEMD160_BLOCK_LENGTH;
1.1       root       97:                }
                     98:        }
1.1.1.6 ! root       99: 
        !           100:        /* Handle any remaining bytes of data. */
        !           101:        if (len != 0)
        !           102:                memcpy (ctx->buffer + have, input, (size_t) len);
1.1       root      103: }
                    104: 
1.1.1.6 ! root      105: /*
        !           106: * Pad pad to 64-byte boundary with the bit pattern
        !           107: * 1 0* (64-bit count of bits processed, MSB-first)
        !           108: */
        !           109: static void RMD160Pad(RMD160_CTX *ctx)
1.1       root      110: {
1.1.1.6 ! root      111:        byte count[8];
        !           112:        size_t padlen;
        !           113: 
        !           114:        /* Convert count to 8 bytes in little endian order. */
1.1       root      115: 
1.1.1.3   root      116: #ifndef TC_NO_COMPILER_INT64
1.1.1.6 ! root      117:        PUT_64BIT_LE(count, ctx->count);
1.1.1.3   root      118: #else
1.1.1.6 ! root      119:        *(unsigned __int32 *) (count + 4) = 0;
        !           120:        PUT_32BIT_LE(count, ctx->count);
1.1.1.3   root      121: #endif
1.1.1.6 ! root      122: 
        !           123:        /* Pad out to 56 mod 64. */
        !           124:        padlen = RIPEMD160_BLOCK_LENGTH -
        !           125:                (size_t)((ctx->count >> 3) & (RIPEMD160_BLOCK_LENGTH - 1));
1.1       root      126:        if (padlen < 1 + 8)
1.1.1.6 ! root      127:                padlen += RIPEMD160_BLOCK_LENGTH;
        !           128:        RMD160Update(ctx, PADDING, padlen - 8);            /* padlen - 8 <= 64 */
        !           129:        RMD160Update(ctx, count, 8);
        !           130: }
1.1       root      131: 
1.1.1.6 ! root      132: /*
        !           133: * Final wrapup--call RMD160Pad, fill in digest and zero out ctx.
        !           134: */
        !           135: void RMD160Final(unsigned char *digest, RMD160_CTX *ctx)
        !           136: {
        !           137:        int i;
1.1       root      138: 
1.1.1.6 ! root      139:        RMD160Pad(ctx);
        !           140:        if (digest) {
        !           141:                for (i = 0; i < 5; i++)
        !           142:                        PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
        !           143:                memset (ctx, 0, sizeof(*ctx));
        !           144:        }
1.1       root      145: }
                    146: 
1.1.1.6 ! root      147: 
1.1.1.3   root      148: #ifndef TC_MINIMIZE_CODE_SIZE
                    149: 
1.1.1.6 ! root      150: #define word32 unsigned __int32
        !           151: 
        !           152: #define k0 0
        !           153: #define k1 0x5a827999UL
        !           154: #define k2 0x6ed9eba1UL
        !           155: #define k3 0x8f1bbcdcUL
        !           156: #define k4 0xa953fd4eUL
        !           157: #define k5 0x50a28be6UL
        !           158: #define k6 0x5c4dd124UL
        !           159: #define k7 0x6d703ef3UL
        !           160: #define k8 0x7a6d76e9UL
        !           161: #define k9 0
        !           162: 
        !           163: static word32 rotlFixed (word32 x, unsigned int y)
1.1       root      164: {
1.1.1.6 ! root      165:        return (word32)((x<<y) | (x>>(sizeof(word32)*8-y)));
        !           166: }
1.1       root      167: 
1.1.1.6 ! root      168: #define Subround(f, a, b, c, d, e, x, s, k)        \
        !           169:        a += f(b, c, d) + x + k;\
        !           170:        a = rotlFixed((word32)a, s) + e;\
        !           171:        c = rotlFixed((word32)c, 10U)
        !           172: 
        !           173: void RMD160Transform (unsigned __int32 *digest, const unsigned __int32 *data)
        !           174: {
1.1       root      175: #if BYTE_ORDER == LITTLE_ENDIAN
1.1.1.6 ! root      176:        const word32 *X = data;
1.1       root      177: #else
1.1.1.6 ! root      178:        word32 X[16];
1.1       root      179:        int i;
                    180: #endif
                    181: 
1.1.1.6 ! root      182:        word32 a1, b1, c1, d1, e1, a2, b2, c2, d2, e2;
        !           183:        a1 = a2 = digest[0];
        !           184:        b1 = b2 = digest[1];
        !           185:        c1 = c2 = digest[2];
        !           186:        d1 = d2 = digest[3];
        !           187:        e1 = e2 = digest[4];
1.1       root      188: 
1.1.1.6 ! root      189: #if BYTE_ORDER == BIG_ENDIAN
        !           190:        for (i = 0; i < 16; i++)
        !           191:        {
        !           192:                X[i] = LE32 (data[i]);
        !           193:        }
        !           194: #endif
1.1       root      195: 
1.1.1.6 ! root      196:        Subround(F, a1, b1, c1, d1, e1, X[ 0], 11, k0);
        !           197:        Subround(F, e1, a1, b1, c1, d1, X[ 1], 14, k0);
        !           198:        Subround(F, d1, e1, a1, b1, c1, X[ 2], 15, k0);
        !           199:        Subround(F, c1, d1, e1, a1, b1, X[ 3], 12, k0);
        !           200:        Subround(F, b1, c1, d1, e1, a1, X[ 4],  5, k0);
        !           201:        Subround(F, a1, b1, c1, d1, e1, X[ 5],  8, k0);
        !           202:        Subround(F, e1, a1, b1, c1, d1, X[ 6],  7, k0);
        !           203:        Subround(F, d1, e1, a1, b1, c1, X[ 7],  9, k0);
        !           204:        Subround(F, c1, d1, e1, a1, b1, X[ 8], 11, k0);
        !           205:        Subround(F, b1, c1, d1, e1, a1, X[ 9], 13, k0);
        !           206:        Subround(F, a1, b1, c1, d1, e1, X[10], 14, k0);
        !           207:        Subround(F, e1, a1, b1, c1, d1, X[11], 15, k0);
        !           208:        Subround(F, d1, e1, a1, b1, c1, X[12],  6, k0);
        !           209:        Subround(F, c1, d1, e1, a1, b1, X[13],  7, k0);
        !           210:        Subround(F, b1, c1, d1, e1, a1, X[14],  9, k0);
        !           211:        Subround(F, a1, b1, c1, d1, e1, X[15],  8, k0);
        !           212: 
        !           213:        Subround(G, e1, a1, b1, c1, d1, X[ 7],  7, k1);
        !           214:        Subround(G, d1, e1, a1, b1, c1, X[ 4],  6, k1);
        !           215:        Subround(G, c1, d1, e1, a1, b1, X[13],  8, k1);
        !           216:        Subround(G, b1, c1, d1, e1, a1, X[ 1], 13, k1);
        !           217:        Subround(G, a1, b1, c1, d1, e1, X[10], 11, k1);
        !           218:        Subround(G, e1, a1, b1, c1, d1, X[ 6],  9, k1);
        !           219:        Subround(G, d1, e1, a1, b1, c1, X[15],  7, k1);
        !           220:        Subround(G, c1, d1, e1, a1, b1, X[ 3], 15, k1);
        !           221:        Subround(G, b1, c1, d1, e1, a1, X[12],  7, k1);
        !           222:        Subround(G, a1, b1, c1, d1, e1, X[ 0], 12, k1);
        !           223:        Subround(G, e1, a1, b1, c1, d1, X[ 9], 15, k1);
        !           224:        Subround(G, d1, e1, a1, b1, c1, X[ 5],  9, k1);
        !           225:        Subround(G, c1, d1, e1, a1, b1, X[ 2], 11, k1);
        !           226:        Subround(G, b1, c1, d1, e1, a1, X[14],  7, k1);
        !           227:        Subround(G, a1, b1, c1, d1, e1, X[11], 13, k1);
        !           228:        Subround(G, e1, a1, b1, c1, d1, X[ 8], 12, k1);
        !           229: 
        !           230:        Subround(H, d1, e1, a1, b1, c1, X[ 3], 11, k2);
        !           231:        Subround(H, c1, d1, e1, a1, b1, X[10], 13, k2);
        !           232:        Subround(H, b1, c1, d1, e1, a1, X[14],  6, k2);
        !           233:        Subround(H, a1, b1, c1, d1, e1, X[ 4],  7, k2);
        !           234:        Subround(H, e1, a1, b1, c1, d1, X[ 9], 14, k2);
        !           235:        Subround(H, d1, e1, a1, b1, c1, X[15],  9, k2);
        !           236:        Subround(H, c1, d1, e1, a1, b1, X[ 8], 13, k2);
        !           237:        Subround(H, b1, c1, d1, e1, a1, X[ 1], 15, k2);
        !           238:        Subround(H, a1, b1, c1, d1, e1, X[ 2], 14, k2);
        !           239:        Subround(H, e1, a1, b1, c1, d1, X[ 7],  8, k2);
        !           240:        Subround(H, d1, e1, a1, b1, c1, X[ 0], 13, k2);
        !           241:        Subround(H, c1, d1, e1, a1, b1, X[ 6],  6, k2);
        !           242:        Subround(H, b1, c1, d1, e1, a1, X[13],  5, k2);
        !           243:        Subround(H, a1, b1, c1, d1, e1, X[11], 12, k2);
        !           244:        Subround(H, e1, a1, b1, c1, d1, X[ 5],  7, k2);
        !           245:        Subround(H, d1, e1, a1, b1, c1, X[12],  5, k2);
        !           246: 
        !           247:        Subround(I, c1, d1, e1, a1, b1, X[ 1], 11, k3);
        !           248:        Subround(I, b1, c1, d1, e1, a1, X[ 9], 12, k3);
        !           249:        Subround(I, a1, b1, c1, d1, e1, X[11], 14, k3);
        !           250:        Subround(I, e1, a1, b1, c1, d1, X[10], 15, k3);
        !           251:        Subround(I, d1, e1, a1, b1, c1, X[ 0], 14, k3);
        !           252:        Subround(I, c1, d1, e1, a1, b1, X[ 8], 15, k3);
        !           253:        Subround(I, b1, c1, d1, e1, a1, X[12],  9, k3);
        !           254:        Subround(I, a1, b1, c1, d1, e1, X[ 4],  8, k3);
        !           255:        Subround(I, e1, a1, b1, c1, d1, X[13],  9, k3);
        !           256:        Subround(I, d1, e1, a1, b1, c1, X[ 3], 14, k3);
        !           257:        Subround(I, c1, d1, e1, a1, b1, X[ 7],  5, k3);
        !           258:        Subround(I, b1, c1, d1, e1, a1, X[15],  6, k3);
        !           259:        Subround(I, a1, b1, c1, d1, e1, X[14],  8, k3);
        !           260:        Subround(I, e1, a1, b1, c1, d1, X[ 5],  6, k3);
        !           261:        Subround(I, d1, e1, a1, b1, c1, X[ 6],  5, k3);
        !           262:        Subround(I, c1, d1, e1, a1, b1, X[ 2], 12, k3);
        !           263: 
        !           264:        Subround(J, b1, c1, d1, e1, a1, X[ 4],  9, k4);
        !           265:        Subround(J, a1, b1, c1, d1, e1, X[ 0], 15, k4);
        !           266:        Subround(J, e1, a1, b1, c1, d1, X[ 5],  5, k4);
        !           267:        Subround(J, d1, e1, a1, b1, c1, X[ 9], 11, k4);
        !           268:        Subround(J, c1, d1, e1, a1, b1, X[ 7],  6, k4);
        !           269:        Subround(J, b1, c1, d1, e1, a1, X[12],  8, k4);
        !           270:        Subround(J, a1, b1, c1, d1, e1, X[ 2], 13, k4);
        !           271:        Subround(J, e1, a1, b1, c1, d1, X[10], 12, k4);
        !           272:        Subround(J, d1, e1, a1, b1, c1, X[14],  5, k4);
        !           273:        Subround(J, c1, d1, e1, a1, b1, X[ 1], 12, k4);
        !           274:        Subround(J, b1, c1, d1, e1, a1, X[ 3], 13, k4);
        !           275:        Subround(J, a1, b1, c1, d1, e1, X[ 8], 14, k4);
        !           276:        Subround(J, e1, a1, b1, c1, d1, X[11], 11, k4);
        !           277:        Subround(J, d1, e1, a1, b1, c1, X[ 6],  8, k4);
        !           278:        Subround(J, c1, d1, e1, a1, b1, X[15],  5, k4);
        !           279:        Subround(J, b1, c1, d1, e1, a1, X[13],  6, k4);
        !           280: 
        !           281:        Subround(J, a2, b2, c2, d2, e2, X[ 5],  8, k5);
        !           282:        Subround(J, e2, a2, b2, c2, d2, X[14],  9, k5);
        !           283:        Subround(J, d2, e2, a2, b2, c2, X[ 7],  9, k5);
        !           284:        Subround(J, c2, d2, e2, a2, b2, X[ 0], 11, k5);
        !           285:        Subround(J, b2, c2, d2, e2, a2, X[ 9], 13, k5);
        !           286:        Subround(J, a2, b2, c2, d2, e2, X[ 2], 15, k5);
        !           287:        Subround(J, e2, a2, b2, c2, d2, X[11], 15, k5);
        !           288:        Subround(J, d2, e2, a2, b2, c2, X[ 4],  5, k5);
        !           289:        Subround(J, c2, d2, e2, a2, b2, X[13],  7, k5);
        !           290:        Subround(J, b2, c2, d2, e2, a2, X[ 6],  7, k5);
        !           291:        Subround(J, a2, b2, c2, d2, e2, X[15],  8, k5);
        !           292:        Subround(J, e2, a2, b2, c2, d2, X[ 8], 11, k5);
        !           293:        Subround(J, d2, e2, a2, b2, c2, X[ 1], 14, k5);
        !           294:        Subround(J, c2, d2, e2, a2, b2, X[10], 14, k5);
        !           295:        Subround(J, b2, c2, d2, e2, a2, X[ 3], 12, k5);
        !           296:        Subround(J, a2, b2, c2, d2, e2, X[12],  6, k5);
        !           297: 
        !           298:        Subround(I, e2, a2, b2, c2, d2, X[ 6],  9, k6); 
        !           299:        Subround(I, d2, e2, a2, b2, c2, X[11], 13, k6);
        !           300:        Subround(I, c2, d2, e2, a2, b2, X[ 3], 15, k6);
        !           301:        Subround(I, b2, c2, d2, e2, a2, X[ 7],  7, k6);
        !           302:        Subround(I, a2, b2, c2, d2, e2, X[ 0], 12, k6);
        !           303:        Subround(I, e2, a2, b2, c2, d2, X[13],  8, k6);
        !           304:        Subround(I, d2, e2, a2, b2, c2, X[ 5],  9, k6);
        !           305:        Subround(I, c2, d2, e2, a2, b2, X[10], 11, k6);
        !           306:        Subround(I, b2, c2, d2, e2, a2, X[14],  7, k6);
        !           307:        Subround(I, a2, b2, c2, d2, e2, X[15],  7, k6);
        !           308:        Subround(I, e2, a2, b2, c2, d2, X[ 8], 12, k6);
        !           309:        Subround(I, d2, e2, a2, b2, c2, X[12],  7, k6);
        !           310:        Subround(I, c2, d2, e2, a2, b2, X[ 4],  6, k6);
        !           311:        Subround(I, b2, c2, d2, e2, a2, X[ 9], 15, k6);
        !           312:        Subround(I, a2, b2, c2, d2, e2, X[ 1], 13, k6);
        !           313:        Subround(I, e2, a2, b2, c2, d2, X[ 2], 11, k6);
        !           314: 
        !           315:        Subround(H, d2, e2, a2, b2, c2, X[15],  9, k7);
        !           316:        Subround(H, c2, d2, e2, a2, b2, X[ 5],  7, k7);
        !           317:        Subround(H, b2, c2, d2, e2, a2, X[ 1], 15, k7);
        !           318:        Subround(H, a2, b2, c2, d2, e2, X[ 3], 11, k7);
        !           319:        Subround(H, e2, a2, b2, c2, d2, X[ 7],  8, k7);
        !           320:        Subround(H, d2, e2, a2, b2, c2, X[14],  6, k7);
        !           321:        Subround(H, c2, d2, e2, a2, b2, X[ 6],  6, k7);
        !           322:        Subround(H, b2, c2, d2, e2, a2, X[ 9], 14, k7);
        !           323:        Subround(H, a2, b2, c2, d2, e2, X[11], 12, k7);
        !           324:        Subround(H, e2, a2, b2, c2, d2, X[ 8], 13, k7);
        !           325:        Subround(H, d2, e2, a2, b2, c2, X[12],  5, k7);
        !           326:        Subround(H, c2, d2, e2, a2, b2, X[ 2], 14, k7);
        !           327:        Subround(H, b2, c2, d2, e2, a2, X[10], 13, k7);
        !           328:        Subround(H, a2, b2, c2, d2, e2, X[ 0], 13, k7);
        !           329:        Subround(H, e2, a2, b2, c2, d2, X[ 4],  7, k7);
        !           330:        Subround(H, d2, e2, a2, b2, c2, X[13],  5, k7);
        !           331: 
        !           332:        Subround(G, c2, d2, e2, a2, b2, X[ 8], 15, k8);
        !           333:        Subround(G, b2, c2, d2, e2, a2, X[ 6],  5, k8);
        !           334:        Subround(G, a2, b2, c2, d2, e2, X[ 4],  8, k8);
        !           335:        Subround(G, e2, a2, b2, c2, d2, X[ 1], 11, k8);
        !           336:        Subround(G, d2, e2, a2, b2, c2, X[ 3], 14, k8);
        !           337:        Subround(G, c2, d2, e2, a2, b2, X[11], 14, k8);
        !           338:        Subround(G, b2, c2, d2, e2, a2, X[15],  6, k8);
        !           339:        Subround(G, a2, b2, c2, d2, e2, X[ 0], 14, k8);
        !           340:        Subround(G, e2, a2, b2, c2, d2, X[ 5],  6, k8);
        !           341:        Subround(G, d2, e2, a2, b2, c2, X[12],  9, k8);
        !           342:        Subround(G, c2, d2, e2, a2, b2, X[ 2], 12, k8);
        !           343:        Subround(G, b2, c2, d2, e2, a2, X[13],  9, k8);
        !           344:        Subround(G, a2, b2, c2, d2, e2, X[ 9], 12, k8);
        !           345:        Subround(G, e2, a2, b2, c2, d2, X[ 7],  5, k8);
        !           346:        Subround(G, d2, e2, a2, b2, c2, X[10], 15, k8);
        !           347:        Subround(G, c2, d2, e2, a2, b2, X[14],  8, k8);
        !           348: 
        !           349:        Subround(F, b2, c2, d2, e2, a2, X[12],  8, k9);
        !           350:        Subround(F, a2, b2, c2, d2, e2, X[15],  5, k9);
        !           351:        Subround(F, e2, a2, b2, c2, d2, X[10], 12, k9);
        !           352:        Subround(F, d2, e2, a2, b2, c2, X[ 4],  9, k9);
        !           353:        Subround(F, c2, d2, e2, a2, b2, X[ 1], 12, k9);
        !           354:        Subround(F, b2, c2, d2, e2, a2, X[ 5],  5, k9);
        !           355:        Subround(F, a2, b2, c2, d2, e2, X[ 8], 14, k9);
        !           356:        Subround(F, e2, a2, b2, c2, d2, X[ 7],  6, k9);
        !           357:        Subround(F, d2, e2, a2, b2, c2, X[ 6],  8, k9);
        !           358:        Subround(F, c2, d2, e2, a2, b2, X[ 2], 13, k9);
        !           359:        Subround(F, b2, c2, d2, e2, a2, X[13],  6, k9);
        !           360:        Subround(F, a2, b2, c2, d2, e2, X[14],  5, k9);
        !           361:        Subround(F, e2, a2, b2, c2, d2, X[ 0], 15, k9);
        !           362:        Subround(F, d2, e2, a2, b2, c2, X[ 3], 13, k9);
        !           363:        Subround(F, c2, d2, e2, a2, b2, X[ 9], 11, k9);
        !           364:        Subround(F, b2, c2, d2, e2, a2, X[11], 11, k9);
        !           365: 
        !           366:        c1        = digest[1] + c1 + d2;
        !           367:        digest[1] = digest[2] + d1 + e2;
        !           368:        digest[2] = digest[3] + e1 + a2;
        !           369:        digest[3] = digest[4] + a1 + b2;
        !           370:        digest[4] = digest[0] + b1 + c2;
        !           371:        digest[0] = c1;
1.1       root      372: }
1.1.1.3   root      373: 
                    374: #else // TC_MINIMIZE_CODE_SIZE
                    375: 
                    376: /*
                    377:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
                    378: 
1.1.1.6 ! root      379:  Governed by the TrueCrypt License 2.6 the full text of which is contained
1.1.1.3   root      380:  in the file License.txt included in TrueCrypt binary and source code
                    381:  distribution packages.
                    382: */
                    383: 
1.1.1.4   root      384: #pragma optimize ("tl", on)
                    385: 
1.1.1.3   root      386: typedef unsigned __int32 uint32;
                    387: typedef unsigned __int8 byte;
                    388: 
1.1.1.6 ! root      389: #include <stdlib.h>
        !           390: #pragma intrinsic (_lrotl)
        !           391: 
1.1.1.3   root      392: static const byte OrderTab[] = {
                    393:        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                    394:        7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
                    395:        3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
                    396:        1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
                    397:        4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13,
                    398:        5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
                    399:        6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
                    400:        15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
                    401:        8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
                    402:        12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
                    403: };
                    404: 
                    405: static const byte RolTab[] = {
                    406:        11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
                    407:        7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
                    408:        11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
                    409:        11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
                    410:        9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6,
                    411:        8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
                    412:        9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
                    413:        9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
                    414:        15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
                    415:        8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
                    416: };
                    417: 
                    418: static const uint32 KTab[] = {
                    419:        0x00000000UL,
                    420:        0x5A827999UL,
                    421:        0x6ED9EBA1UL,
                    422:        0x8F1BBCDCUL,
                    423:        0xA953FD4EUL,
                    424:        0x50A28BE6UL,
                    425:        0x5C4DD124UL,
                    426:        0x6D703EF3UL,
                    427:        0x7A6D76E9UL,
                    428:        0x00000000UL
                    429: };
                    430: 
                    431: 
1.1.1.6 ! root      432: void RMD160Transform (unsigned __int32 *state, const unsigned __int32 *data)
1.1.1.3   root      433: {
                    434:        uint32 a, b, c, d, e;
                    435:        uint32 a2, b2, c2, d2, e2;
                    436:        byte pos;
                    437:        uint32 tmp;
                    438: 
                    439:        a = state[0];
                    440:        b = state[1];
                    441:        c = state[2];
                    442:        d = state[3];
                    443:        e = state[4];
                    444: 
                    445:        for (pos = 0; pos < 160; ++pos)
                    446:        {
                    447:                tmp = a + data[OrderTab[pos]] + KTab[pos >> 4];
                    448:                
                    449:                switch (pos >> 4)
                    450:                {
1.1.1.6 ! root      451:                case 0: case 9: tmp += F (b, c, d); break;
        !           452:                case 1: case 8: tmp += G (b, c, d); break;
        !           453:                case 2: case 7: tmp += H (b, c, d); break;
        !           454:                case 3: case 6: tmp += I (b, c, d); break;
        !           455:                case 4: case 5: tmp += J (b, c, d); break;
1.1.1.3   root      456:                }
                    457: 
1.1.1.6 ! root      458:                tmp = _lrotl (tmp, RolTab[pos]) + e;
1.1.1.3   root      459:                a = e;
                    460:                e = d;
1.1.1.6 ! root      461:                d = _lrotl (c, 10);
1.1.1.3   root      462:                c = b;
                    463:                b = tmp;
                    464: 
                    465:                if (pos == 79)
                    466:                {
                    467:                        a2 = a;
                    468:                        b2 = b;
                    469:                        c2 = c;
                    470:                        d2 = d;
                    471:                        e2 = e;
                    472: 
                    473:                        a = state[0];
                    474:                        b = state[1];
                    475:                        c = state[2];
                    476:                        d = state[3];
                    477:                        e = state[4];
                    478:                }
                    479:        }
                    480: 
                    481:        tmp = state[1] + c2 + d;
                    482:        state[1] = state[2] + d2 + e;
                    483:        state[2] = state[3] + e2 + a;
                    484:        state[3] = state[4] + a2 + b;
                    485:        state[4] = state[0] + b2 + c;
                    486:        state[0] = tmp;
                    487: }
                    488: 
                    489: #endif // TC_MINIMIZE_CODE_SIZE

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.