#include <time.h>
#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;
int mode;
int Dflag;
+int
main(argc,argv)
char **argv;
{
- int f = 0;
char *argp;
while (--argc > 0) if (*(argp = *++argv)=='-')
exit(rc);
}
-process()
+static void process(void)
{
switch(mode)
{
}
#ifndef shsDigest
-unsigned char *
+static unsigned char *
shsDigest(si)
SHS_INFO *si;
{
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];
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;
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];
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;
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];
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;
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;
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);
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;
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;
} sdata;
unsigned char digest[SHS_DIGESTSIZE];
int failed;
- int i, j, k;
+ int i, j;
printf("Running SHS test 6 ...\n");
sdata.pad1 = 0x12345678;
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) {
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;
119,120,123,127};
int kfsize[] = {0,1,31,32,33,55,56,63};
-test7()
+static void test7(void)
{
struct {
long pad1;
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;
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,
}
}
#define CHECK check_error(r, __LINE__)
+#endif
static void printd (const char *descr, krb5_data *d) {
int i, j;
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];
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;
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);
"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++) {
#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,
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);
}
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,
printf("N-fold\n");
for (i=0; i<sizeof(nfold_in)/sizeof(char *); i++) {
- printf("\tInput:\t\"%.*s\"\n", (int) strlen(nfold_in[i]), nfold_in[i]);
+ printf("\tInput:\t\"%.*s\"\n", (int) strlen((char *) nfold_in[i]),
+ nfold_in[i]);
printf("\t192-Fold:\t");
- krb5_nfold(strlen(nfold_in[i])*8, nfold_in[i], 24*8, cipher_text);
+ krb5_nfold(strlen((char *) nfold_in[i])*8, nfold_in[i], 24*8,
+ cipher_text);
for (j=0; j<24; j++)
printf("%s%02x", (j&3) ? "" : " ", cipher_text[j]);
printf("\n");