[BACK]Return to camelliatest.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_ntl / crypt / camellia

Annotation of OpenXM/src/ox_ntl/crypt/camellia/camelliatest.c, Revision 1.1

1.1     ! iwane       1: /* $OpenXM$ */
        !             2: /*
        !             3:  * Camellia
        !             4:  * http://info.isl.ntt.co.jp/crypt/camellia/index.html
        !             5:  */
        !             6:
        !             7: #include "camellia.h"
        !             8:
        !             9: #include <stdio.h>
        !            10:
        !            11:
        !            12: #if HAVE_CONFIG_H
        !            13: #include "config.h"
        !            14: #endif /* HAVE_CONFIG_H */
        !            15:
        !            16:
        !            17: #define DPRINTF(str, x, n)   do DPRINTF__(str, (x), (n)) while(0)
        !            18:
        !            19: /*
        !            20: */
        !            21: #define DPRINTF__(str, x, n)    { \
        !            22:         int _i;                    \
        !            23:         printf("%s: ", str);       \
        !            24:         for (_i = 0; _i < n; _i++) {             \
        !            25:                 printf("%02x", x[_i] & 0xff);    \
        !            26:                 if (_i % 8 == 7)                 \
        !            27:                         printf(" ");             \
        !            28:         }                                        \
        !            29:        printf("\n"); \
        !            30: }
        !            31:
        !            32:
        !            33:
        !            34: int
        !            35: main(int argc, char *argv[])
        !            36: {
        !            37:        char k[1028] = "\x01\x23\x45\x67\x89\xab\xcd\xef\xfe\xdc\xba\x98\x76\x54\x32\x10\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff";
        !            38:        char v[1028] = "\x01\x23\x45\x67\x89\xab\xcd\xef\xfe\xdc\xba\x98\x76\x54\x32\x10";
        !            39:        char e1[1000];
        !            40:        char m1[1000];
        !            41:        camellia_key ckey;
        !            42:        int len = 256;
        !            43:        int bits[] = {128, 192, 256};
        !            44:        const char *ans[] = {
        !            45:                "\x67\x67\x31\x38\x54\x96\x69\x73\x08\x57\x06\x56\x48\xea\xbe\x43",
        !            46:                "\xb4\x99\x34\x01\xb3\xe9\x96\xf8\x4e\xe5\xce\xe7\xd7\x9b\x09\xb9",
        !            47:                "\x9a\xcc\x23\x7d\xff\x16\xd7\x6c\x20\xef\x7c\x91\x9e\x3a\x75\x09",
        !            48:        };
        !            49:        int i;
        !            50:
        !            51:        if (argc > 1) {
        !            52:                memcpy(k, argv[1], strlen(argv[1]));
        !            53:                ans[0] = ans[1] = ans[2] = NULL;
        !            54:        }
        !            55:        if (argc > 2) {
        !            56:                memcpy(v, argv[2], strlen(argv[2]));
        !            57:        }
        !            58:
        !            59:
        !            60:        for (i = 0; i < sizeof(bits) / sizeof(bits[0]); i++) {
        !            61:                len = bits[i];
        !            62:                printf("----\n");
        !            63:
        !            64:                DPRINTF("key", k, len / 8);
        !            65:
        !            66:                camellia_keyset(k, len / 8, &ckey);
        !            67:                camellia_enc(&ckey, v, e1);
        !            68:
        !            69:                DPRINTF("enc", e1, 128 / 8);
        !            70:
        !            71:                if (ans[i] && memcmp(e1, ans[i], 128 / 8)) {
        !            72:                        printf("ENC ERROR\n");
        !            73:                        exit(1);
        !            74:                }
        !            75:
        !            76:
        !            77:                camellia_dec(&ckey, e1, m1);
        !            78:                DPRINTF("dec", m1, 128 / 8);
        !            79:
        !            80:                if (memcmp(m1, v, 128 / 8)) {
        !            81:                        printf("DEC ERROR\n");
        !            82:                        exit(1);
        !            83:                }
        !            84:        }
        !            85:
        !            86:
        !            87:        return (0);
        !            88: }
        !            89:
        !            90: /* EOF */
        !            91:

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