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 if ((err = encrypt(key, sizeof(key), pt, ct, sizeof(pt)))) {
33 printf("encrypt error: %s\n", crypto_errstr(err));
37 if (select_crypto_if(iface2)) return 1;
38 if ((err = decrypt(key, sizeof(key), ct, re, sizeof(ct)))) {
39 printf("decrypt error: %s\n", crypto_errstr(err));
43 if (memcmp(pt, re, sizeof(pt))) {
50 int test_sha(int iface)
52 unsigned char sha1[20];
55 unsigned char spt[3] = "abc";
56 unsigned char sstd[20] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,
57 0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};
59 if (select_crypto_if(iface)) return 1;
61 if ((err = hash(spt, sizeof(spt), sha1, &shalen))) {
62 printf("hash error: %s\n", crypto_errstr(err));
65 printf("%d: len=%d ", iface, shalen);
67 if (memcmp(sha1, sstd, sizeof(sstd))) {
74 int test_hmac(int iface)
76 unsigned char hmac1[20];
79 unsigned char hpt[28] = "what do ya want for nothing?";
80 unsigned char hkey[4] = "Jefe";
81 unsigned char hstd[20] = {0xef,0xfc,0xdf,0x6a,0xe5,0xeb,0x2f,0xa2,
82 0xd2,0x74,0x16,0xd5,0xf1,0x84,0xdf,0x9c,0x25,0x9a,0x7c,0x79};
84 if (select_crypto_if(iface)) return 1;
86 if ((err = hmac(hkey, sizeof(hkey), hpt, sizeof(hpt),
88 printf("hash error: %s\n", crypto_errstr(err));
91 printf("%d: len=%d ", iface, hmaclen);
93 if (memcmp(hmac1, hstd, sizeof(hstd))) {
100 int main(int argc, char *argv[])
105 for (numifs = 0; select_crypto_if(numifs) == 0; numifs++)
106 printf("%d: %s\n", numifs, if_name(numifs));
107 printf("Testing %d interfaces\n", numifs);
109 for (i = 0; i < numifs; i++)
110 if ((rc = test_sha(i)) > maxrc) maxrc = rc;
111 for (i = 0; i < numifs; i++)
112 if ((rc = test_hmac(i)) > maxrc) maxrc = rc;
113 for (i = 0; i < numifs; i++) for (j = 0; j < numifs; j++)
114 if ((rc = test_enc_dec(i,j)) > maxrc) maxrc = rc;