From: Ezra Peisach Date: Mon, 23 Dec 2002 18:01:54 +0000 (+0000) Subject: Cleanup unused X-Git-Tag: krb5-1.3-alpha1~209 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3dfda778fd007686f1d5edd0f434d45d74ac982b;p=krb5.git Cleanup unused variables. Signed vs unsigned cleanup. Ensure variables set before use. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15065 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/ChangeLog b/src/lib/crypto/ChangeLog index c7af891f1..a3ffa7b39 100644 --- a/src/lib/crypto/ChangeLog +++ b/src/lib/crypto/ChangeLog @@ -1,3 +1,9 @@ +2002-12-23 Ezra Peisach + + * pbkdf2.c, t_encrypt.c, t_hmac.c, t_nfold.c: Cleanup unused + variables. Signed vs unsigned cleanup. Ensure variables set before + use. + 2002-12-19 Ken Raeburn * old_api_glue.c (krb5_encrypt, krb5_decrypt, diff --git a/src/lib/crypto/des/ChangeLog b/src/lib/crypto/des/ChangeLog index dd03be7e0..7a8d1d8b7 100644 --- a/src/lib/crypto/des/ChangeLog +++ b/src/lib/crypto/des/ChangeLog @@ -1,3 +1,7 @@ +2002-12-23 Ezra Peisach + + * t_verify.c: Signed vs. unsigned cleanups. Remove unsused variables. + 2002-10-09 Ken Raeburn * string2key.c (mit_des_string_to_key_int): If PRINT_TEST_VECTORS diff --git a/src/lib/crypto/des/t_verify.c b/src/lib/crypto/des/t_verify.c index c31b6c0d3..a6ad07cb8 100644 --- a/src/lib/crypto/des/t_verify.c +++ b/src/lib/crypto/des/t_verify.c @@ -62,6 +62,9 @@ #include #include "com_err.h" +static void do_encrypt(unsigned char *, unsigned char *); +static void do_decrypt(unsigned char *, unsigned char *); + char *progname; int nflag = 2; int vflag; @@ -129,9 +132,8 @@ main(argc,argv) char *argv[]; { /* Local Declarations */ - int in_length, retval; - void do_encrypt(); - void do_decrypt(); + size_t in_length; + int retval; int i, j; #ifdef WINDOWS @@ -314,7 +316,7 @@ main(argc,argv) printf("\tchecksum\t58 d2 e7 7e 86 06 27 33, "); printf("or some part thereof\n"); input = clear_text2; - mit_des_cbc_cksum(input,cipher_text,(long) strlen((char *)input), + mit_des_cbc_cksum(input,cipher_text, strlen((char *)input), sched,ivec); printf("ACTUAL CBC checksum\n"); printf("\t\tencrypted cksum = (low to high bytes)\n\t\t"); @@ -331,6 +333,7 @@ main(argc,argv) exit(0); } +#if 0 void flip(array) char *array; @@ -352,11 +355,12 @@ flip(array) array++; } } +#endif -void +static void do_encrypt(in,out) - char *in; - char *out; + unsigned char *in; + unsigned char *out; { int i, j; for (i =1; i<=nflag; i++) { @@ -377,10 +381,10 @@ do_encrypt(in,out) } } -void +static void do_decrypt(in,out) - char *out; - char *in; + unsigned char *out; + unsigned char *in; /* try to invert it */ { int i, j; diff --git a/src/lib/crypto/pbkdf2.c b/src/lib/crypto/pbkdf2.c index b5d0bfcae..03b729335 100644 --- a/src/lib/crypto/pbkdf2.c +++ b/src/lib/crypto/pbkdf2.c @@ -75,7 +75,7 @@ static void printd (const char *descr, krb5_data *d) { } static void printk(const char *descr, krb5_keyblock *k) { krb5_data d; - d.data = k->contents; + d.data = (char *) k->contents; d.length = k->length; printd(descr, &d); } @@ -226,7 +226,7 @@ static krb5_error_code hmac1(const struct krb5_hash_provider *h, abort(); if (key->length > blocksize) { krb5_data d, d2; - d.data = key->contents; + d.data = (char *) key->contents; d.length = key->length; d2.data = tmp; d2.length = hashsize; @@ -234,7 +234,7 @@ static krb5_error_code hmac1(const struct krb5_hash_provider *h, if (err) return err; key->length = d2.length; - key->contents = d2.data; + key->contents = (krb5_octet *) d2.data; if (debug_hmac) printk(" pre-hashed key", key); } diff --git a/src/lib/crypto/sha1/ChangeLog b/src/lib/crypto/sha1/ChangeLog index d9b71e9d0..e3444481d 100644 --- a/src/lib/crypto/sha1/ChangeLog +++ b/src/lib/crypto/sha1/ChangeLog @@ -1,3 +1,7 @@ +2002-12-23 Ezra Peisach + + * t_shs3.c: Signed/unsigned cleanup. Provide function prototypes. + 2002-08-29 Ken Raeburn * Makefile.in: Revert $(S)=>/ change, for Windows support. diff --git a/src/lib/crypto/sha1/t_shs3.c b/src/lib/crypto/sha1/t_shs3.c index 1ba030da7..cefec45eb 100644 --- a/src/lib/crypto/sha1/t_shs3.c +++ b/src/lib/crypto/sha1/t_shs3.c @@ -5,13 +5,22 @@ #include #include "shs.h" +static void process(void); +static void test1(void); +static void test2(void); +static void test3(void); +static void test4(void); +static void test5(void); +static void test6(void); +static void test7(void); + /* When run on a little-endian CPU we need to perform byte reversal on an array of longwords. It is possible to make the code endianness- independant by fiddling around with data at the byte level, but this makes for very slow code, so we rely on the user to sort out endianness at compile time */ -void longReverse( SHS_LONG *buffer, int byteCount ) +static void longReverse( SHS_LONG *buffer, int byteCount ) { SHS_LONG value; static int init = 0; @@ -44,10 +53,10 @@ int rc; int mode; int Dflag; +int main(argc,argv) char **argv; { - int f = 0; char *argp; while (--argc > 0) if (*(argp = *++argv)=='-') @@ -82,7 +91,7 @@ main(argc,argv) exit(rc); } -process() +static void process(void) { switch(mode) { @@ -119,7 +128,7 @@ process() } #ifndef shsDigest -unsigned char * +static unsigned char * shsDigest(si) SHS_INFO *si; { @@ -132,7 +141,7 @@ unsigned char results1[SHS_DIGESTSIZE] = { 0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a,0xba,0x3e, 0x25,0x71,0x78,0x50,0xc2,0x6c,0x9c,0xd0,0xd8,0x9d}; -test1() +static void test1(void) { SHS_INFO si[1]; unsigned char digest[SHS_DIGESTSIZE]; @@ -141,10 +150,10 @@ test1() printf("Running SHS test 1 ...\n"); shsInit(si); - shsUpdate(si, "abc", 3); + shsUpdate(si, (SHS_BYTE *) "abc", 3); shsFinal(si); memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results1, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results1, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 1 failed!\n"); rc = 1; @@ -165,7 +174,7 @@ unsigned char results2[SHS_DIGESTSIZE] = { 0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e,0xba,0xae, 0x4a,0xa1,0xf9,0x51,0x29,0xe5,0xe5,0x46,0x70,0xf1}; -test2() +static void test2(void) { SHS_INFO si[1]; unsigned char digest[SHS_DIGESTSIZE]; @@ -175,11 +184,11 @@ test2() printf("Running SHS test 2 ...\n"); shsInit(si); shsUpdate(si, -"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + (SHS_BYTE *) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56); shsFinal(si); memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results2, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results2, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 2 failed!\n"); rc = 1; @@ -200,7 +209,7 @@ unsigned char results3[SHS_DIGESTSIZE] = { 0x34,0xaa,0x97,0x3c,0xd4,0xc4,0xda,0xa4,0xf6,0x1e, 0xeb,0x2b,0xdb,0xad,0x27,0x31,0x65,0x34,0x01,0x6f}; -test3() +static void test3(void) { SHS_INFO si[1]; unsigned char digest[SHS_DIGESTSIZE]; @@ -211,11 +220,11 @@ test3() shsInit(si); for (i = 0; i < 15625; ++i) shsUpdate(si, -"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", +(SHS_BYTE *) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 64); shsFinal(si); memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results3, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results3, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 3 failed!\n"); rc = 1; @@ -270,19 +279,19 @@ unsigned char results4[SHS_DIGESTSIZE] = { 0x13,0x62,0xfc,0x87,0x68,0x33,0xd5,0x1d,0x2f,0x0c, 0x73,0xe3,0xfb,0x87,0x6a,0x6b,0xc3,0x25,0x54,0xfc}; -test4() +static void test4(void) { SHS_INFO si[1]; unsigned char digest[SHS_DIGESTSIZE]; int failed; - int i, j, k; + int i; printf("Running SHS test 4 ...\n"); shsInit(si); shsUpdate(si, randdata, 19); shsFinal(si); memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results4, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results4, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 4 failed!\n"); rc = 1; @@ -303,12 +312,12 @@ unsigned char results5[SHS_DIGESTSIZE] = { 0x19,0x4d,0xf6,0xeb,0x8e,0x02,0x6d,0x37,0x58,0x64, 0xe5,0x95,0x19,0x2a,0xdd,0x1c,0xc4,0x3c,0x24,0x86}; -test5() +static void test5(void) { SHS_INFO si[1]; unsigned char digest[SHS_DIGESTSIZE]; int failed; - int i, j, k; + int i; printf("Running SHS test 5 ...\n"); shsInit(si); @@ -316,7 +325,7 @@ test5() shsUpdate(si, randdata+32, 15); shsFinal(si); memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results5, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results5, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 5 failed!\n"); rc = 1; @@ -337,7 +346,7 @@ unsigned char results6[SHS_DIGESTSIZE] = { 0x4e,0x16,0x57,0x9d,0x4b,0x48,0xa9,0x1c,0x88,0x72, 0x83,0xdb,0x88,0xd1,0xea,0x3a,0x45,0xdf,0xa1,0x10}; -test6() +static void test6(void) { struct { long pad1; @@ -348,7 +357,7 @@ test6() } sdata; unsigned char digest[SHS_DIGESTSIZE]; int failed; - int i, j, k; + int i, j; printf("Running SHS test 6 ...\n"); sdata.pad1 = 0x12345678; @@ -422,11 +431,11 @@ sdata.pad3 = 0x78563412; if (Dflag & 2) printf ("%d: %08lx%08lx%08lx%08lx%08lx\n", i, - sdata.si2.digest[0], - sdata.si2.digest[1], - sdata.si2.digest[2], - sdata.si2.digest[3], - sdata.si2.digest[4]); + (unsigned long) sdata.si2.digest[0], + (unsigned long) sdata.si2.digest[1], + (unsigned long) sdata.si2.digest[2], + (unsigned long) sdata.si2.digest[3], + (unsigned long) sdata.si2.digest[4]); } shsFinal((&sdata.si2)); if (sdata.pad2 != 0x87654321) { @@ -440,7 +449,7 @@ sdata.pad3); sdata.pad3 = 0x78563412; } memcpy(digest, shsDigest((&sdata.si2)), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results6, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results6, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 6 failed!\n"); rc = 1; @@ -468,7 +477,7 @@ int jfsize[] = {0,1,31,32, 119,120,123,127}; int kfsize[] = {0,1,31,32,33,55,56,63}; -test7() +static void test7(void) { struct { long pad1; @@ -557,15 +566,15 @@ sdata.pad3 = 0x78563412; if (Dflag & 2) printf ("%d,%d,%d: %08lx%08lx%08lx%08lx%08lx\n", i,j,k, - sdata.si2.digest[0], - sdata.si2.digest[1], - sdata.si2.digest[2], - sdata.si2.digest[3], - sdata.si2.digest[4]); + (unsigned long) sdata.si2.digest[0], + (unsigned long) sdata.si2.digest[1], + (unsigned long) sdata.si2.digest[2], + (unsigned long) sdata.si2.digest[3], + (unsigned long) sdata.si2.digest[4]); } shsFinal((&sdata.si2)); memcpy(digest, shsDigest((&sdata.si2)), SHS_DIGESTSIZE); - if (failed = memcmp(digest, results7, SHS_DIGESTSIZE)) + if ((failed = memcmp(digest, results7, SHS_DIGESTSIZE)) != 0) { fprintf(stderr,"SHS test 7 failed!\n"); rc = 1; diff --git a/src/lib/crypto/t_encrypt.c b/src/lib/crypto/t_encrypt.c index e15d2d039..2a6e09e31 100644 --- a/src/lib/crypto/t_encrypt.c +++ b/src/lib/crypto/t_encrypt.c @@ -56,7 +56,7 @@ if( retval) { \ int main () { - krb5_context context ; + krb5_context context = 0; krb5_data in, out, check, state; int i; size_t len; diff --git a/src/lib/crypto/t_hmac.c b/src/lib/crypto/t_hmac.c index 2f65f9133..96c2357a5 100644 --- a/src/lib/crypto/t_hmac.c +++ b/src/lib/crypto/t_hmac.c @@ -40,22 +40,12 @@ const char *whoami; -static void printhex (size_t len, const char *p) { - while (len--) - printf ("%02x", 0xff & *p++); -} - -static void printstringhex (const char *p) { printhex (strlen (p), p); } - -static void printdata (krb5_data *d) { printhex (d->length, d->data); } - -static void printkey (krb5_keyblock *k) { printhex (k->length, k->contents); } - static void keyToData (krb5_keyblock *k, krb5_data *d) { d->length = k->length; - d->data = k->contents; + d->data = (char *) k->contents; } +#if 0 static void check_error (int r, int line) { if (r != 0) { fprintf (stderr, "%s:%d: %s\n", __FILE__, line, @@ -64,6 +54,7 @@ static void check_error (int r, int line) { } } #define CHECK check_error(r, __LINE__) +#endif static void printd (const char *descr, krb5_data *d) { int i, j; @@ -101,7 +92,8 @@ struct hmac_test { const char *hexdigest; }; -static krb5_error_code hmac1(struct krb5_hash_provider *h, krb5_keyblock *key, +static krb5_error_code hmac1(const struct krb5_hash_provider *h, + krb5_keyblock *key, krb5_data *in, krb5_data *out) { char tmp[40]; @@ -115,7 +107,7 @@ static krb5_error_code hmac1(struct krb5_hash_provider *h, krb5_keyblock *key, abort(); if (key->length > blocksize) { krb5_data d, d2; - d.data = key->contents; + d.data = (char *) key->contents; d.length = key->length; d2.data = tmp; d2.length = hashsize; @@ -125,7 +117,7 @@ static krb5_error_code hmac1(struct krb5_hash_provider *h, krb5_keyblock *key, exit(1); } key->length = d2.length; - key->contents = d2.data; + key->contents = (krb5_octet *) d2.data; printk(" pre-hashed key", key); } printd(" hmac input", in); @@ -232,77 +224,6 @@ static void test_hmac() "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", "0x6f630fad67cda0ee1fb1f562db3aa53e" }, - }, sha1tests[] = { - { -/* -test_case = 1 -key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b -key_len = 20 -data = "Hi There" -data_len = 8 -digest = 0xb617318655057264e28bc0b6fb378c8ef146be00 - -test_case = 2 -key = "Jefe" -key_len = 4 -data = "what do ya want for nothing?" -data_len = 28 -digest = 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79 - -test_case = 3 -key = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -key_len = 20 -data = 0xdd repeated 50 times -data_len = 50 -digest = 0x125d7342b9ac11cd91a39af48aa17b4f63f175d3 - -test_case = 4 -key = 0x0102030405060708090a0b0c0d0e0f10111213141516171819 -key_len = 25 -data = 0xcd repeated 50 times -data_len = 50 -digest = 0x4c9007f4026250c6bc8414f9bf50c86c2d7235da - -test_case = 5 -key = 0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c -key_len = 20 -data = "Test With Truncation" -data_len = 20 -digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04 - -test_case = 6 -key = 0xaa repeated 80 times -key_len = 80 -data = "Test Using Larger Than Block-Size Key - Hash Key First" -data_len = 54 -digest = 0xaa4ae5e15272d00e95705637ce8a3b55ed402112 - -test_case = 7 -key = 0xaa repeated 80 times -key_len = 80 -data = "Test Using Larger Than Block-Size Key and Larger - Than One Block-Size Data" -data_len = 73 -digest = 0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91 -data_len = 20 -digest = 0x4c1a03424b55e07fe7f27be1d58bb9324a9a5a04 - -test_case = 6 -key = 0xaa repeated 80 times -key_len = 80 -data = "Test Using Larger Than Block-Size Key - Hash Key First" -data_len = 54 -digest = 0xaa4ae5e15272d00e95705637ce8a3b55ed402112 - -test_case = 7 -key = 0xaa repeated 80 times -key_len = 80 -data = "Test Using Larger Than Block-Size Key and Larger " - "Than One Block-Size Data" -data_len = 73 -digest = 0xe8e99d0f45237d786d6bbaa7965c7808bbff1a91 -*/ - 0 }, }; for (i = 0; i < sizeof(md5tests)/sizeof(md5tests[0]); i++) { diff --git a/src/lib/crypto/t_nfold.c b/src/lib/crypto/t_nfold.c index eb368db05..f2eff2441 100644 --- a/src/lib/crypto/t_nfold.c +++ b/src/lib/crypto/t_nfold.c @@ -38,20 +38,22 @@ #define ASIZE(ARRAY) (sizeof(ARRAY)/sizeof(ARRAY[0])) -void printhex (size_t len, const char *p) +static void printhex (size_t len, const unsigned char *p) { while (len--) printf ("%02x", 0xff & *p++); } -void printstringhex (const char *p) { printhex (strlen (p), p); } +static void printstringhex (const unsigned char *p) { + printhex (strlen ((const char *) p), p); +} -void rfc_tests () +static void rfc_tests () { int i; struct { char *input; - int n; + unsigned int n; unsigned char exp[192/8]; } tests[] = { { "012345", 64, @@ -78,9 +80,9 @@ void rfc_tests () printf ("RFC tests:\n"); for (i = 0; i < ASIZE (tests); i++) { - char *p = tests[i].input; + unsigned char *p = (unsigned char *) tests[i].input; assert (tests[i].n / 8 <= sizeof (outbuf)); - krb5_nfold (8 * strlen (p), p, tests[i].n, 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); @@ -96,10 +98,10 @@ void rfc_tests () } unsigned char *nfold_in[] = { - "basch", - "eichin", - "sommerfeld", - "MASSACHVSETTS INSTITVTE OF TECHNOLOGY" }; + (unsigned char *) "basch", + (unsigned char *) "eichin", + (unsigned char *) "sommerfeld", + (unsigned char *) "MASSACHVSETTS INSTITVTE OF TECHNOLOGY" }; unsigned char nfold_192[4][24] = { { 0x1a, 0xab, 0x6b, 0x42, 0x96, 0x4b, 0x98, 0xb2, 0x1f, 0x8c, 0xde, 0x2d, @@ -122,9 +124,11 @@ main(argc, argv) printf("N-fold\n"); for (i=0; i