ver
[libexssl.git] / test / kspeed.c
blob9be95d105d46ba3aeb267823822d77ed71635898
1 #include <unistd.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7 #include <time.h>
8 #include <crpt.h>
10 int main () {
11 int count = 0;
12 char buf [256];
13 if (-1 == cr_init()) return 1;
14 cr_key_t *priv = cr_key_init(), *pub = cr_key_init();
15 if (0 == cr_load_priv_fl("./priv.pem", "masterkey", priv) && 0 == cr_load_pub_fl("./pub.pem", pub)) {
16 str_t *src = mkstr(CONST_STR_LEN("Good luck"), 8), *crp = NULL, *dcr = NULL;
17 time_t t0 = time(0), t1 = t0 + 60;
18 const struct tm *tm = localtime(&t0);
19 strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT ", tm);
20 printf("%s\n", buf);
21 while (time(0) < t1) {
22 if (0 == cr_encrypt_pub(pub, src->ptr, src->len, &crp)) {
23 if (0 == cr_decrypt_priv(priv, crp->ptr, crp->len, &dcr)) {
24 free(dcr);
25 dcr = NULL;
26 ++count;
28 free(crp);
29 crp = NULL;
32 printf("%d\n", count);
33 tm = localtime(&t1);
34 strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT ", tm);
35 printf("%s\n", buf);
37 cr_free_key(priv);
38 cr_free_key(pub);
39 cr_done();