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

1.1       root        1: /*
                      2:  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
                      3:  *
                      4:  * Redistribution and use in source and binary forms, with or without
                      5:  * modification, are permitted provided that the following conditions
                      6:  * are met:
                      7:  * 1. Redistributions of source code must retain the above copyright
                      8:  *    notice, this list of conditions and the following disclaimer.
                      9:  * 2. Redistributions in binary form must reproduce the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer in the
                     11:  *    documentation and/or other materials provided with the distribution.
                     12:  *
                     13:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     15:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     16:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     17:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     18:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     19:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     20:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     21:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     22:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     23:  */
                     24: /*
                     25:  * Preneel, Bosselaers, Dobbertin, "The Cryptographic Hash Function RIPEMD-160",
                     26:  * RSA Laboratories, CryptoBytes, Volume 3, Number 2, Autumn 1997,
                     27:  * ftp://ftp.rsasecurity.com/pub/cryptobytes/crypto3n2.pdf
                     28:  */
                     29: 
1.1.1.3   root       30: /* Adapted by TrueCrypt Foundation */
                     31: 
1.1.1.2   root       32: #include "Rmd160.h"
                     33: #include "../Common/Endian.h"
1.1       root       34: #include <memory.h>
                     35: 
                     36: #define PUT_64BIT_LE(cp, value) do { \
                     37:        (cp)[7] = (unsigned char)((value) >> 56); \
                     38:        (cp)[6] = (unsigned char)((value) >> 48); \
                     39:        (cp)[5] = (unsigned char)((value) >> 40); \
                     40:        (cp)[4] = (unsigned char)((value) >> 32); \
                     41:        (cp)[3] = (unsigned char)((value) >> 24); \
                     42:        (cp)[2] = (unsigned char)((value) >> 16); \
                     43:        (cp)[1] = (unsigned char)((value) >> 8); \
                     44:        (cp)[0] = (unsigned char)(value); } while (0)
                     45: 
                     46: #define PUT_32BIT_LE(cp, value) do { \
                     47:        (cp)[3] = (unsigned char)((value) >> 24); \
                     48:        (cp)[2] = (unsigned char)((value) >> 16); \
                     49:        (cp)[1] = (unsigned char)((value) >> 8); \
                     50:        (cp)[0] = (unsigned char)(value); } while (0)
                     51: 
                     52: #define        H0      0x67452301U
                     53: #define        H1      0xEFCDAB89U
                     54: #define        H2      0x98BADCFEU
                     55: #define        H3      0x10325476U
                     56: #define        H4      0xC3D2E1F0U
                     57: 
                     58: #define        K0      0x00000000U
                     59: #define        K1      0x5A827999U
                     60: #define        K2      0x6ED9EBA1U
                     61: #define        K3      0x8F1BBCDCU
                     62: #define        K4      0xA953FD4EU
                     63: 
                     64: #define        KK0     0x50A28BE6U
                     65: #define        KK1     0x5C4DD124U
                     66: #define        KK2     0x6D703EF3U
                     67: #define        KK3     0x7A6D76E9U
                     68: #define        KK4     0x00000000U
                     69: 
                     70: /* rotate x left n bits.  */
1.1.1.3   root       71: 
                     72: #if defined (_MSC_VER) && !defined (_DEBUG)
                     73: #include <stdlib.h>
                     74: #      pragma intrinsic (_lrotl)
                     75: #      define ROL(n, x) (_lrotl (x, n))
                     76: #else
                     77: #      define ROL(n, x) (((x) << (n)) | ((x) >> (32-(n))))
                     78: #endif
1.1       root       79: 
                     80: #define F0(x, y, z) ((x) ^ (y) ^ (z))
                     81: #define F1(x, y, z) (((x) & (y)) | ((~x) & (z)))
                     82: #define F2(x, y, z) (((x) | (~y)) ^ (z))
                     83: #define F3(x, y, z) (((x) & (z)) | ((y) & (~z)))
                     84: #define F4(x, y, z) ((x) ^ ((y) | (~z)))
                     85: 
                     86: #define R(a, b, c, d, e, Fj, Kj, sj, rj) \
                     87:        do { \
                     88:                a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \
                     89:                c = ROL(10, c); \
                     90:        } while(0)
                     91: 
                     92: #define X(i)   x[i]
                     93: 
1.1.1.3   root       94: #ifndef TC_MINIMIZE_CODE_SIZE
                     95: 
1.1       root       96: static u_char PADDING[64] = {
                     97:        0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     98:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                     99:        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                    100: };
                    101: 
1.1.1.3   root      102: #else
                    103: 
                    104: static u_char PADDING[64];
                    105: 
                    106: #endif 
                    107: 
1.1       root      108: void
                    109: RMD160Init(RMD160_CTX *ctx)
                    110: {
                    111:        ctx->count = 0;
                    112:        ctx->state[0] = H0;
                    113:        ctx->state[1] = H1;
                    114:        ctx->state[2] = H2;
                    115:        ctx->state[3] = H3;
                    116:        ctx->state[4] = H4;
1.1.1.3   root      117: 
                    118:        PADDING[0] = 0x80;
1.1       root      119: }
                    120: 
                    121: void
                    122: RMD160Update(RMD160_CTX *ctx, const u_char *input, u_int32_t len)
                    123: {
                    124:        u_int32_t have, off, need;
                    125: 
1.1.1.2   root      126:        have = (unsigned __int32)((ctx->count/8) % 64);
1.1       root      127:        need = 64 - have;
                    128:        ctx->count += 8 * len;
                    129:        off = 0;
                    130: 
                    131:        if (len >= need) {
                    132:                if (have) {
1.1.1.3   root      133:                        memcpy(ctx->buffer + have, input, (size_t) need);
1.1       root      134:                        RMD160Transform(ctx->state, ctx->buffer);
                    135:                        off = need;
                    136:                        have = 0;
                    137:                }
                    138:                /* now the buffer is empty */
                    139:                while (off + 64 <= len) {
                    140:                        RMD160Transform(ctx->state, input+off);
                    141:                        off += 64;
                    142:                }
                    143:        }
                    144:        if (off < len)
1.1.1.3   root      145:                memcpy(ctx->buffer + have, input+off, (size_t) (len-off));
1.1       root      146: }
                    147: 
1.1.1.3   root      148: void RMD160Final(u_char digest[20], RMD160_CTX *ctx)
1.1       root      149: {
                    150:        int i;
                    151:        u_char size[8];
                    152:        u_int32_t padlen;
                    153: 
1.1.1.3   root      154: #ifndef TC_NO_COMPILER_INT64
1.1       root      155:        PUT_64BIT_LE(size, ctx->count);
1.1.1.3   root      156: #else
                    157:        *(unsigned __int32 *) (size + 4) = 0;
                    158:        PUT_32BIT_LE(size, ctx->count);
                    159: #endif
1.1       root      160:        /*
                    161:         * pad to 64 byte blocks, at least one byte from PADDING plus 8 bytes
                    162:         * for the size
                    163:         */
1.1.1.2   root      164:        padlen = (unsigned __int32)(64 - ((ctx->count/8) % 64));
1.1       root      165:        if (padlen < 1 + 8)
                    166:                padlen += 64;
                    167:        RMD160Update(ctx, PADDING, padlen - 8);         /* padlen - 8 <= 64 */
                    168:        RMD160Update(ctx, size, 8);
                    169: 
                    170:        if (digest != 0)
                    171:                for (i = 0; i < 5; i++)
                    172:                        PUT_32BIT_LE(digest + i*4, ctx->state[i]);
                    173: 
                    174:        memset(ctx, 0, sizeof (*ctx));
                    175: }
                    176: 
1.1.1.3   root      177: #ifndef TC_MINIMIZE_CODE_SIZE
                    178: 
1.1       root      179: void
                    180: RMD160Transform(u_int32_t state[5], const u_char block[64])
                    181: {
                    182:        u_int32_t a, b, c, d, e, aa, bb, cc, dd, ee, t, x[16];
                    183: 
                    184: #if BYTE_ORDER == LITTLE_ENDIAN
                    185:        memcpy(x, block, 64);
                    186: #else
                    187:        int i;
                    188: 
                    189:        for (i = 0; i < 16; i++)
                    190:                x[i] = (u_int32_t)(
                    191:                    (u_int32_t)(block[i*4 + 0]) |
                    192:                    (u_int32_t)(block[i*4 + 1]) <<  8 |
                    193:                    (u_int32_t)(block[i*4 + 2]) << 16 |
                    194:                    (u_int32_t)(block[i*4 + 3]) << 24);
                    195: #endif
                    196: 
                    197:        a = state[0];
                    198:        b = state[1];
                    199:        c = state[2];
                    200:        d = state[3];
                    201:        e = state[4];
                    202: 
                    203:        /* Round 1 */
                    204:        R(a, b, c, d, e, F0, K0, 11,  0);
                    205:        R(e, a, b, c, d, F0, K0, 14,  1);
                    206:        R(d, e, a, b, c, F0, K0, 15,  2);
                    207:        R(c, d, e, a, b, F0, K0, 12,  3);
                    208:        R(b, c, d, e, a, F0, K0,  5,  4);
                    209:        R(a, b, c, d, e, F0, K0,  8,  5);
                    210:        R(e, a, b, c, d, F0, K0,  7,  6);
                    211:        R(d, e, a, b, c, F0, K0,  9,  7);
                    212:        R(c, d, e, a, b, F0, K0, 11,  8);
                    213:        R(b, c, d, e, a, F0, K0, 13,  9);
                    214:        R(a, b, c, d, e, F0, K0, 14, 10);
                    215:        R(e, a, b, c, d, F0, K0, 15, 11);
                    216:        R(d, e, a, b, c, F0, K0,  6, 12);
                    217:        R(c, d, e, a, b, F0, K0,  7, 13);
                    218:        R(b, c, d, e, a, F0, K0,  9, 14);
                    219:        R(a, b, c, d, e, F0, K0,  8, 15); /* #15 */
                    220:        /* Round 2 */
                    221:        R(e, a, b, c, d, F1, K1,  7,  7);
                    222:        R(d, e, a, b, c, F1, K1,  6,  4);
                    223:        R(c, d, e, a, b, F1, K1,  8, 13);
                    224:        R(b, c, d, e, a, F1, K1, 13,  1);
                    225:        R(a, b, c, d, e, F1, K1, 11, 10);
                    226:        R(e, a, b, c, d, F1, K1,  9,  6);
                    227:        R(d, e, a, b, c, F1, K1,  7, 15);
                    228:        R(c, d, e, a, b, F1, K1, 15,  3);
                    229:        R(b, c, d, e, a, F1, K1,  7, 12);
                    230:        R(a, b, c, d, e, F1, K1, 12,  0);
                    231:        R(e, a, b, c, d, F1, K1, 15,  9);
                    232:        R(d, e, a, b, c, F1, K1,  9,  5);
                    233:        R(c, d, e, a, b, F1, K1, 11,  2);
                    234:        R(b, c, d, e, a, F1, K1,  7, 14);
                    235:        R(a, b, c, d, e, F1, K1, 13, 11);
                    236:        R(e, a, b, c, d, F1, K1, 12,  8); /* #31 */
                    237:        /* Round 3 */
                    238:        R(d, e, a, b, c, F2, K2, 11,  3);
                    239:        R(c, d, e, a, b, F2, K2, 13, 10);
                    240:        R(b, c, d, e, a, F2, K2,  6, 14);
                    241:        R(a, b, c, d, e, F2, K2,  7,  4);
                    242:        R(e, a, b, c, d, F2, K2, 14,  9);
                    243:        R(d, e, a, b, c, F2, K2,  9, 15);
                    244:        R(c, d, e, a, b, F2, K2, 13,  8);
                    245:        R(b, c, d, e, a, F2, K2, 15,  1);
                    246:        R(a, b, c, d, e, F2, K2, 14,  2);
                    247:        R(e, a, b, c, d, F2, K2,  8,  7);
                    248:        R(d, e, a, b, c, F2, K2, 13,  0);
                    249:        R(c, d, e, a, b, F2, K2,  6,  6);
                    250:        R(b, c, d, e, a, F2, K2,  5, 13);
                    251:        R(a, b, c, d, e, F2, K2, 12, 11);
                    252:        R(e, a, b, c, d, F2, K2,  7,  5);
                    253:        R(d, e, a, b, c, F2, K2,  5, 12); /* #47 */
                    254:        /* Round 4 */
                    255:        R(c, d, e, a, b, F3, K3, 11,  1);
                    256:        R(b, c, d, e, a, F3, K3, 12,  9);
                    257:        R(a, b, c, d, e, F3, K3, 14, 11);
                    258:        R(e, a, b, c, d, F3, K3, 15, 10);
                    259:        R(d, e, a, b, c, F3, K3, 14,  0);
                    260:        R(c, d, e, a, b, F3, K3, 15,  8);
                    261:        R(b, c, d, e, a, F3, K3,  9, 12);
                    262:        R(a, b, c, d, e, F3, K3,  8,  4);
                    263:        R(e, a, b, c, d, F3, K3,  9, 13);
                    264:        R(d, e, a, b, c, F3, K3, 14,  3);
                    265:        R(c, d, e, a, b, F3, K3,  5,  7);
                    266:        R(b, c, d, e, a, F3, K3,  6, 15);
                    267:        R(a, b, c, d, e, F3, K3,  8, 14);
                    268:        R(e, a, b, c, d, F3, K3,  6,  5);
                    269:        R(d, e, a, b, c, F3, K3,  5,  6);
                    270:        R(c, d, e, a, b, F3, K3, 12,  2); /* #63 */
                    271:        /* Round 5 */
                    272:        R(b, c, d, e, a, F4, K4,  9,  4);
                    273:        R(a, b, c, d, e, F4, K4, 15,  0);
                    274:        R(e, a, b, c, d, F4, K4,  5,  5);
                    275:        R(d, e, a, b, c, F4, K4, 11,  9);
                    276:        R(c, d, e, a, b, F4, K4,  6,  7);
                    277:        R(b, c, d, e, a, F4, K4,  8, 12);
                    278:        R(a, b, c, d, e, F4, K4, 13,  2);
                    279:        R(e, a, b, c, d, F4, K4, 12, 10);
                    280:        R(d, e, a, b, c, F4, K4,  5, 14);
                    281:        R(c, d, e, a, b, F4, K4, 12,  1);
                    282:        R(b, c, d, e, a, F4, K4, 13,  3);
                    283:        R(a, b, c, d, e, F4, K4, 14,  8);
                    284:        R(e, a, b, c, d, F4, K4, 11, 11);
                    285:        R(d, e, a, b, c, F4, K4,  8,  6);
                    286:        R(c, d, e, a, b, F4, K4,  5, 15);
                    287:        R(b, c, d, e, a, F4, K4,  6, 13); /* #79 */
                    288: 
                    289:        aa = a ; bb = b; cc = c; dd = d; ee = e;
                    290: 
                    291:        a = state[0];
                    292:        b = state[1];
                    293:        c = state[2];
                    294:        d = state[3];
                    295:        e = state[4];
                    296: 
                    297:        /* Parallel round 1 */
                    298:        R(a, b, c, d, e, F4, KK0,  8,  5);
                    299:        R(e, a, b, c, d, F4, KK0,  9, 14);
                    300:        R(d, e, a, b, c, F4, KK0,  9,  7);
                    301:        R(c, d, e, a, b, F4, KK0, 11,  0);
                    302:        R(b, c, d, e, a, F4, KK0, 13,  9);
                    303:        R(a, b, c, d, e, F4, KK0, 15,  2);
                    304:        R(e, a, b, c, d, F4, KK0, 15, 11);
                    305:        R(d, e, a, b, c, F4, KK0,  5,  4);
                    306:        R(c, d, e, a, b, F4, KK0,  7, 13);
                    307:        R(b, c, d, e, a, F4, KK0,  7,  6);
                    308:        R(a, b, c, d, e, F4, KK0,  8, 15);
                    309:        R(e, a, b, c, d, F4, KK0, 11,  8);
                    310:        R(d, e, a, b, c, F4, KK0, 14,  1);
                    311:        R(c, d, e, a, b, F4, KK0, 14, 10);
                    312:        R(b, c, d, e, a, F4, KK0, 12,  3);
                    313:        R(a, b, c, d, e, F4, KK0,  6, 12); /* #15 */
                    314:        /* Parallel round 2 */
                    315:        R(e, a, b, c, d, F3, KK1,  9,  6);
                    316:        R(d, e, a, b, c, F3, KK1, 13, 11);
                    317:        R(c, d, e, a, b, F3, KK1, 15,  3);
                    318:        R(b, c, d, e, a, F3, KK1,  7,  7);
                    319:        R(a, b, c, d, e, F3, KK1, 12,  0);
                    320:        R(e, a, b, c, d, F3, KK1,  8, 13);
                    321:        R(d, e, a, b, c, F3, KK1,  9,  5);
                    322:        R(c, d, e, a, b, F3, KK1, 11, 10);
                    323:        R(b, c, d, e, a, F3, KK1,  7, 14);
                    324:        R(a, b, c, d, e, F3, KK1,  7, 15);
                    325:        R(e, a, b, c, d, F3, KK1, 12,  8);
                    326:        R(d, e, a, b, c, F3, KK1,  7, 12);
                    327:        R(c, d, e, a, b, F3, KK1,  6,  4);
                    328:        R(b, c, d, e, a, F3, KK1, 15,  9);
                    329:        R(a, b, c, d, e, F3, KK1, 13,  1);
                    330:        R(e, a, b, c, d, F3, KK1, 11,  2); /* #31 */
                    331:        /* Parallel round 3 */
                    332:        R(d, e, a, b, c, F2, KK2,  9, 15);
                    333:        R(c, d, e, a, b, F2, KK2,  7,  5);
                    334:        R(b, c, d, e, a, F2, KK2, 15,  1);
                    335:        R(a, b, c, d, e, F2, KK2, 11,  3);
                    336:        R(e, a, b, c, d, F2, KK2,  8,  7);
                    337:        R(d, e, a, b, c, F2, KK2,  6, 14);
                    338:        R(c, d, e, a, b, F2, KK2,  6,  6);
                    339:        R(b, c, d, e, a, F2, KK2, 14,  9);
                    340:        R(a, b, c, d, e, F2, KK2, 12, 11);
                    341:        R(e, a, b, c, d, F2, KK2, 13,  8);
                    342:        R(d, e, a, b, c, F2, KK2,  5, 12);
                    343:        R(c, d, e, a, b, F2, KK2, 14,  2);
                    344:        R(b, c, d, e, a, F2, KK2, 13, 10);
                    345:        R(a, b, c, d, e, F2, KK2, 13,  0);
                    346:        R(e, a, b, c, d, F2, KK2,  7,  4);
                    347:        R(d, e, a, b, c, F2, KK2,  5, 13); /* #47 */
                    348:        /* Parallel round 4 */
                    349:        R(c, d, e, a, b, F1, KK3, 15,  8);
                    350:        R(b, c, d, e, a, F1, KK3,  5,  6);
                    351:        R(a, b, c, d, e, F1, KK3,  8,  4);
                    352:        R(e, a, b, c, d, F1, KK3, 11,  1);
                    353:        R(d, e, a, b, c, F1, KK3, 14,  3);
                    354:        R(c, d, e, a, b, F1, KK3, 14, 11);
                    355:        R(b, c, d, e, a, F1, KK3,  6, 15);
                    356:        R(a, b, c, d, e, F1, KK3, 14,  0);
                    357:        R(e, a, b, c, d, F1, KK3,  6,  5);
                    358:        R(d, e, a, b, c, F1, KK3,  9, 12);
                    359:        R(c, d, e, a, b, F1, KK3, 12,  2);
                    360:        R(b, c, d, e, a, F1, KK3,  9, 13);
                    361:        R(a, b, c, d, e, F1, KK3, 12,  9);
                    362:        R(e, a, b, c, d, F1, KK3,  5,  7);
                    363:        R(d, e, a, b, c, F1, KK3, 15, 10);
                    364:        R(c, d, e, a, b, F1, KK3,  8, 14); /* #63 */
                    365:        /* Parallel round 5 */
                    366:        R(b, c, d, e, a, F0, KK4,  8, 12);
                    367:        R(a, b, c, d, e, F0, KK4,  5, 15);
                    368:        R(e, a, b, c, d, F0, KK4, 12, 10);
                    369:        R(d, e, a, b, c, F0, KK4,  9,  4);
                    370:        R(c, d, e, a, b, F0, KK4, 12,  1);
                    371:        R(b, c, d, e, a, F0, KK4,  5,  5);
                    372:        R(a, b, c, d, e, F0, KK4, 14,  8);
                    373:        R(e, a, b, c, d, F0, KK4,  6,  7);
                    374:        R(d, e, a, b, c, F0, KK4,  8,  6);
                    375:        R(c, d, e, a, b, F0, KK4, 13,  2);
                    376:        R(b, c, d, e, a, F0, KK4,  6, 13);
                    377:        R(a, b, c, d, e, F0, KK4,  5, 14);
                    378:        R(e, a, b, c, d, F0, KK4, 15,  0);
                    379:        R(d, e, a, b, c, F0, KK4, 13,  3);
                    380:        R(c, d, e, a, b, F0, KK4, 11,  9);
                    381:        R(b, c, d, e, a, F0, KK4, 11, 11); /* #79 */
                    382: 
                    383:        t =        state[1] + cc + d;
                    384:        state[1] = state[2] + dd + e;
                    385:        state[2] = state[3] + ee + a;
                    386:        state[3] = state[4] + aa + b;
                    387:        state[4] = state[0] + bb + c;
                    388:        state[0] = t;
                    389: }
1.1.1.3   root      390: 
                    391: #else // TC_MINIMIZE_CODE_SIZE
                    392: 
                    393: /*
                    394:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
                    395: 
1.1.1.5 ! root      396:  Governed by the TrueCrypt License 2.5 the full text of which is contained
1.1.1.3   root      397:  in the file License.txt included in TrueCrypt binary and source code
                    398:  distribution packages.
                    399: */
                    400: 
1.1.1.4   root      401: #pragma optimize ("tl", on)
                    402: 
1.1.1.3   root      403: typedef unsigned __int32 uint32;
                    404: typedef unsigned __int8 byte;
                    405: 
                    406: static const byte OrderTab[] = {
                    407:        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                    408:        7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
                    409:        3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
                    410:        1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
                    411:        4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13,
                    412:        5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
                    413:        6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
                    414:        15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
                    415:        8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
                    416:        12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
                    417: };
                    418: 
                    419: static const byte RolTab[] = {
                    420:        11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
                    421:        7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
                    422:        11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
                    423:        11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
                    424:        9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6,
                    425:        8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
                    426:        9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
                    427:        9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
                    428:        15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
                    429:        8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
                    430: };
                    431: 
                    432: static const uint32 KTab[] = {
                    433:        0x00000000UL,
                    434:        0x5A827999UL,
                    435:        0x6ED9EBA1UL,
                    436:        0x8F1BBCDCUL,
                    437:        0xA953FD4EUL,
                    438:        0x50A28BE6UL,
                    439:        0x5C4DD124UL,
                    440:        0x6D703EF3UL,
                    441:        0x7A6D76E9UL,
                    442:        0x00000000UL
                    443: };
                    444: 
                    445: 
                    446: void RMD160Transform (u_int32_t state[5], const u_char block[64])
                    447: {
                    448:        uint32 a, b, c, d, e;
                    449:        uint32 a2, b2, c2, d2, e2;
                    450:        uint32 *data = (uint32 *) block;
                    451:        byte pos;
                    452:        uint32 tmp;
                    453: 
                    454:        a = state[0];
                    455:        b = state[1];
                    456:        c = state[2];
                    457:        d = state[3];
                    458:        e = state[4];
                    459: 
                    460:        for (pos = 0; pos < 160; ++pos)
                    461:        {
                    462:                tmp = a + data[OrderTab[pos]] + KTab[pos >> 4];
                    463:                
                    464:                switch (pos >> 4)
                    465:                {
                    466:                case 0: case 9: tmp += F0 (b, c, d); break;
                    467:                case 1: case 8: tmp += F1 (b, c, d); break;
                    468:                case 2: case 7: tmp += F2 (b, c, d); break;
                    469:                case 3: case 6: tmp += F3 (b, c, d); break;
                    470:                case 4: case 5: tmp += F4 (b, c, d); break;
                    471:                }
                    472: 
                    473:                tmp = ROL (RolTab[pos], tmp) + e;
                    474:                a = e;
                    475:                e = d;
                    476:                d = ROL (10, c);
                    477:                c = b;
                    478:                b = tmp;
                    479: 
                    480:                if (pos == 79)
                    481:                {
                    482:                        a2 = a;
                    483:                        b2 = b;
                    484:                        c2 = c;
                    485:                        d2 = d;
                    486:                        e2 = e;
                    487: 
                    488:                        a = state[0];
                    489:                        b = state[1];
                    490:                        c = state[2];
                    491:                        d = state[3];
                    492:                        e = state[4];
                    493:                }
                    494:        }
                    495: 
                    496:        tmp = state[1] + c2 + d;
                    497:        state[1] = state[2] + d2 + e;
                    498:        state[2] = state[3] + e2 + a;
                    499:        state[3] = state[4] + a2 + b;
                    500:        state[4] = state[0] + b2 + c;
                    501:        state[0] = tmp;
                    502: }
                    503: 
                    504: #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.