Annotation of pgp/contrib/idea/test.c, revision 1.1

1.1     ! root        1: /* Copyright (c) 1993 Colin Plumb.  This code may be freely
        !             2:    distributed under the terms of the GNU General Public Licence. */
        !             3: 
        !             4:    /* This was developed using Borland C for the IBM PC */
        !             5: 
        !             6: #include "idea.h"
        !             7: #include <stdio.h>
        !             8: #include <time.h>
        !             9: 
        !            10: #define RAND16 (rand() ^ rand() << 1)
        !            11: 
        !            12: uint16 huge bigbuf1[32764];
        !            13: uint16 huge bigbuf2[32764];
        !            14: 
        !            15: void
        !            16: timetest(uint16 iv[4], uint16 *key)
        !            17: {
        !            18:        clock_t start, finish;
        !            19:        uint16 iv2[4];
        !            20:        uint16 i;
        !            21: 
        !            22:        iv2[0]=iv[0]; iv2[1]=iv[1]; iv2[2]=iv[2]; iv2[3]=iv[3];
        !            23: 
        !            24:        printf("Starting time test.\n");
        !            25: 
        !            26:        start = clock();
        !            27: #if 0
        !            28:        IdeaCFB(iv, key, bigbuf1, bigbuf2, 8192);
        !            29:        IdeaCFB(iv, key, bigbuf2, bigbuf1, 8192);
        !            30:        IdeaCFBx(iv2, key, bigbuf1, bigbuf2, 8192);
        !            31:        IdeaCFBx(iv2, key, bigbuf2, bigbuf1, 8192);
        !            32: #else
        !            33:        for (i = 0; i < 32; i++) {
        !            34:                IdeaCFB(iv, key, bigbuf1, bigbuf2, 8192);
        !            35:                IdeaCFBx(iv, key, bigbuf2, bigbuf2, 8192);
        !            36:        }
        !            37: #endif
        !            38:        finish = clock();
        !            39:        printf("%4x / %4x  %4x / %4x  %4x / %4x  %4x / %4x\n",
        !            40:                iv[0], iv2[0], iv[1], iv2[1], iv[2], iv2[2], iv[3], iv2[3]);
        !            41:        finish -= start;
        !            42:        printf("Time taken for 64 64K buffers (4096 K): %lu clocks, %f seconds\n",
        !            43:                finish, (float)finish/CLK_TCK);
        !            44: }
        !            45: 
        !            46: int
        !            47: main(int argc, char **argv)
        !            48: {
        !            49:        ulong j;
        !            50:        uint16 a, b, c, d, i;
        !            51:        uint16 key[KEYSIZE], in[4], out1[4], out2[4], out3[4];
        !            52:        uint16 buf1[8], buf2[8], buf3[8];
        !            53: 
        !            54:        if (argc < 2)
        !            55:                srand((unsigned)time(0));
        !            56:        else {
        !            57:                argv++; /* suppress silly warning */
        !            58:                srand(argc);
        !            59:        }
        !            60: 
        !            61:        printf("Starting to test...\n");
        !            62: for (j = 0; j < 10000; j++) {
        !            63:        if (j % 100 == 0)
        !            64:                printf("%5lu\r", j);
        !            65:        a = RAND16;
        !            66:        b = RAND16;
        !            67:        c = Mul(a,b);
        !            68:        d = Mul2(a,b);
        !            69:        if (c != d)
        !            70:                printf("%u * %u = %u / %u\n", a, b, c, d);
        !            71: 
        !            72:        for (i = 0; i < 4; i++)
        !            73:                in[i] = RAND16;
        !            74:        for (i = 0; i < KEYSIZE; i++)
        !            75:                key[i] = RAND16;
        !            76:        Idea(in, out1, key);
        !            77: #if 0
        !            78:        Idea2(in, out2, key);
        !            79:        Idea3(in, out3, key);
        !            80: #else
        !            81:        for (i = 0; i < 4; i++)
        !            82:                out3[i] = out2[i] = in[i];
        !            83:        IdeaCFB(out2, key, buf1, buf1, 1);      /* buf1 args are dummies */
        !            84:        IdeaCFBx(out3, key, buf1, buf1, 1);
        !            85: #endif
        !            86:        Idea3(in, out3, key);
        !            87:        for (i = 0; i < 4; i++)
        !            88:                if (out1[i] != out2[i] || out2[i] != out3[i]) {
        !            89:                        printf("Unequal for j = %lu\n", j);
        !            90:                        for (i = 0; i < 4; i++)
        !            91:                                printf("%4x - %4x / %4x / %4x    %4x\n",
        !            92:                                       in[i], out1[i], out2[i], out3[i], key[i]);
        !            93:                        break;
        !            94:                }
        !            95:        for (i = 0; i < 8; i++)
        !            96:                buf1[i] = RAND16;
        !            97:        IdeaCFB(out2, key, buf1, buf2, 3);
        !            98:        IdeaCFBx(out3, key, buf2, buf3, 3);
        !            99:        a = 0;
        !           100:        for (i = 0; i < 4; i++)
        !           101:                if (out2[i] != out3[i])
        !           102:                        a = 1;
        !           103:        for (i = 0; i < 8; i++)
        !           104:                if (buf1[i] != buf3[i])
        !           105:                        a = 1;
        !           106:        if (a) {
        !           107:                printf("CFB problem for j = %lu\n", j);
        !           108:                for (i = 0; i < 4; i++)
        !           109:                        printf("%4x / %4x = %4x     %4x\n",
        !           110:                             out1[i], out2[i], out3[i], key[i]);
        !           111:                for (i = 0; i < 8; i++)
        !           112:                        printf("%4x -> %4x -> %4x   %4x\n",
        !           113:                             buf1[i], buf2[i], buf3[i], key[i+4]);
        !           114:        }
        !           115: } /* for (j) */
        !           116:        timetest(in, key);
        !           117:        return 0;
        !           118: }

unix.superglobalmegacorp.com

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