/* * lib/crypto/t_nfold.c * * Copyright 1988, 1990 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may * require a specific license from the United States Government. * It is the responsibility of any person or organization contemplating * export to obtain such a license before exporting. * * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and * distribute this software and its documentation for any purpose and * without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, and that * the name of M.I.T. not be used in advertising or publicity pertaining * to distribution of the software without specific, written prior * permission. Furthermore if you modify this software you must label * your software as modified software and not distribute it in such a * fashion that it might be confused with the original M.I.T. software. * M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. * * * Program to test the correctness of nfold implementation. * * exit returns 0 ==> success * -1 ==> error */ #include #include #include #include "k5-int.h" #define ASIZE(ARRAY) (sizeof(ARRAY)/sizeof(ARRAY[0])) static void printhex (size_t len, const unsigned char *p) { while (len--) printf ("%02x", 0xff & *p++); } static void printstringhex (const unsigned char *p) { printhex (strlen ((const char *) p), p); } static void rfc_tests () { int i; struct { char *input; unsigned int n; unsigned char exp[192/8]; } tests[] = { { "012345", 64, { 0xbe,0x07,0x26,0x31,0x27,0x6b,0x19,0x55, } }, { "password", 56, { 0x78,0xa0,0x7b,0x6c,0xaf,0x85,0xfa, } }, { "Rough Consensus, and Running Code", 64, { 0xbb,0x6e,0xd3,0x08,0x70,0xb7,0xf0,0xe0, } }, { "password", 168, { 0x59,0xe4,0xa8,0xca,0x7c,0x03,0x85,0xc3, 0xc3,0x7b,0x3f,0x6d,0x20,0x00,0x24,0x7c, 0xb6,0xe6,0xbd,0x5b,0x3e, } }, { "MASSACHVSETTS INSTITVTE OF TECHNOLOGY", 192, { 0xdb,0x3b,0x0d,0x8f,0x0b,0x06,0x1e,0x60, 0x32,0x82,0xb3,0x08,0xa5,0x08,0x41,0x22, 0x9a,0xd7,0x98,0xfa,0xb9,0x54,0x0c,0x1b, } }, }; unsigned char outbuf[192/8]; printf ("RFC tests:\n"); for (i = 0; i < ASIZE (tests); i++) { unsigned char *p = (unsigned char *) tests[i].input; assert (tests[i].n / 8 <= sizeof (outbuf)); krb5_nfold (8 * strlen ((char *) p), p, tests[i].n, outbuf); printf ("%d-fold(\"%s\") =\n", tests[i].n, p); printf ("%d-fold(", tests[i].n); printstringhex (p); printf (") =\n\t"); printhex (tests[i].n / 8, outbuf); printf ("\n\n"); if (memcmp (outbuf, tests[i].exp, tests[i].n/8) != 0) { printf ("wrong value! expected:\n\t"); printhex (tests[i].n / 8, tests[i].exp); exit (1); } } } static void fold_kerberos(int nbytes) { unsigned char cipher_text[300]; int j; if (nbytes > 300) abort(); printf("%d-fold(\"kerberos\") =\n\t", nbytes*8); krb5_nfold(64, "kerberos", 8*nbytes, cipher_text); for (j=0; j