10 #define printh(x) printh_f(#x, x, sizeof(x))
11 void printh_f(char *p, unsigned char *x, size_t l)
15 for (i=0; i<l; i++) printf(" %02x", x[i]);
19 int test_enc_dec(int iface1, int iface2)
22 unsigned char pt[48] = "the quick brown fox jumps over a lazy dog";
23 unsigned char key[16] = {0x0f,0x65,0xd1,0x3a,0xfe,0xcb,0xc4,0xb9,
24 0x52,0xb1,0x60,0xcf,0xe8,0x55,0x6a,0xdd};
28 printf("%d -> %d\n", iface1, iface2);
31 if (select_crypto_if(iface1)) return 1;
32 memset(ct, 0xfe, sizeof(ct));
33 if ((err = encrypt(key, sizeof(key), pt, ct, sizeof(pt)))) {
34 printf("encrypt error: %s\n", crypto_errstr(err));
38 if (select_crypto_if(iface2)) return 1;
39 if ((err = decrypt(key, sizeof(key), ct, re, sizeof(re)))) {
40 printf("decrypt error: %s\n", crypto_errstr(err));
44 if (memcmp(pt, re, sizeof(pt))) {
51 int test_sha(int iface)
53 unsigned char sha1[20];
56 unsigned char spt[3] = "abc";
57 unsigned char sstd[20] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,
58 0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};
60 if (select_crypto_if(iface)) return 1;
62 if ((err = hash(spt, sizeof(spt), sha1, &shalen))) {
63 printf("hash error: %s\n", crypto_errstr(err));
66 printf("%d: len=%d ", iface, shalen);
68 if (memcmp(sha1, sstd, sizeof(sstd))) {
75 int test_hmac(int iface)
77 unsigned char hmac1[20];
80 unsigned char hpt[28] = "what do ya want for nothing?";
81 unsigned char hkey[4] = "Jefe";
82 unsigned char hstd[20] = {0xef,0xfc,0xdf,0x6a,0xe5,0xeb,0x2f,0xa2,
83 0xd2,0x74,0x16,0xd5,0xf1,0x84,0xdf,0x9c,0x25,0x9a,0x7c,0x79};
85 if (select_crypto_if(iface)) return 1;
87 if ((err = hmac(hkey, sizeof(hkey), hpt, sizeof(hpt),
89 printf("hash error: %s\n", crypto_errstr(err));
92 printf("%d: len=%d ", iface, hmaclen);
94 if (memcmp(hmac1, hstd, sizeof(hstd))) {
101 int main(int argc, char *argv[])
107 for (numifs = 0; (name = crypto_init(numifs)); numifs++)
108 printf("%d: %s\n", numifs, name);
109 printf("Testing %d interfaces\n\n", numifs);
111 for (i = 0; i < numifs; i++)
112 if ((rc = test_sha(i)) > maxrc) maxrc = rc;
113 for (i = 0; i < numifs; i++)
114 if ((rc = test_hmac(i)) > maxrc) maxrc = rc;
115 for (i = 0; i < numifs; i++) for (j = 0; j < numifs; j++)
116 if ((rc = test_enc_dec(i,j)) > maxrc) maxrc = rc;