]> www.average.org Git - pam_pcsc_cr.git/blob - test_crypto.c
695c4fe249fbe0178f434973ef82a397d36fac77
[pam_pcsc_cr.git] / test_crypto.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include "crypto.h"
6
7 unsigned char pt[48] = "the quick brown fox jumps over a lazy dog";
8 unsigned char key[16] = {
9 0x0f,0x65,0xd1,0x3a,0xfe,0xcb,0xc4,0xb9,0x52,0xb1,0x60,0xcf,0xe8,0x55,0x6a,0xdd
10 };
11
12 static void usage(const char const *cmd)
13 {
14         fprintf(stderr, "usage: %s\n", cmd);
15 }
16
17 #define printh(p,x) printh_f(p, x, sizeof(x))
18 void printh_f(char *p, unsigned char *x, size_t l)
19 {
20         int i;
21         printf("%s:", p);
22         for (i=0; i<l; i++) printf(" %02x", x[i]);
23         printf("\n");
24 }
25
26 int main(int argc, char *argv[])
27 {
28         unsigned long err;
29         unsigned char ct1[48], re1[48];
30         unsigned char sha1[20], sha2[20];
31         unsigned char hmac1[20], hmac2[20];
32
33         printf("source: %s\n", pt);
34         printh("source", pt);
35         printh("key", key);
36         if (select_crypto_if(0)) return 1;
37         if (err = encrypt(key, sizeof(key), pt, ct1, sizeof(pt)))
38                 printf("encrypt error: %s\n", crypto_errstr(err));
39         printh("ct1", ct1);
40         if (err = decrypt(key, sizeof(key), ct1, re1, sizeof(re1)))
41                 printf("decrypt error: %s\n", crypto_errstr(err));
42         printh("re1", re1);
43         if (select_crypto_if(1)) return 1;
44         return 0;
45 }