1 /**********************************************************************
2 * Copyright (c) 2018 Cryptocom LTD *
3 * This file is distributed under the same license as OpenSSL *
4 **********************************************************************/
9 #include <openssl/rand.h>
10 #include <openssl/conf.h>
11 #include <openssl/err.h>
12 #include <openssl/evp.h>
13 #include <openssl/pem.h>
14 #include <openssl/engine.h>
16 static EVP_PKEY *create_key(char *algname, char *param)
18 EVP_PKEY *key1 = EVP_PKEY_new(), *newkey = NULL;
19 EVP_PKEY_CTX *ctx = NULL;
21 if(EVP_PKEY_set_type_str(key1, algname, strlen(algname)) <= 0)
25 if(!(ctx = EVP_PKEY_CTX_new(key1, NULL)))
29 EVP_PKEY_keygen_init(ctx);
30 if(ERR_peek_last_error())
34 if(EVP_PKEY_CTX_ctrl_str(ctx, "paramset", param) <= 0)
38 if(EVP_PKEY_keygen(ctx, &newkey) <= 0)
44 EVP_PKEY_CTX_free(ctx);
49 void usage(char *name)
51 fprintf(stderr, "usage: %s [-l data_len] [-c cycles]\n", name);
55 int main(int argc, char **argv)
61 unsigned char *sigbuf;
65 unsigned int data_len = 1024;
66 unsigned int cycles = 8000;
69 while((option = getopt(argc, argv, "l:c:")) >= 0)
71 if(option == ':') option = optopt;
72 if(optarg && (optarg[0] == '-')) { optind--; optarg = NULL; }
76 data_len = atoi(optarg);
79 cycles = atoi(optarg);
86 if (optind < argc) usage(argv[0]);
88 ERR_load_crypto_strings();
89 OpenSSL_add_all_algorithms();
90 mdtype = EVP_get_digestbyname("md_gost12_256");
91 pkey = create_key("gost2012_256", "A");
92 data = (unsigned char *) malloc(data_len);
93 printf("wait"); fflush(stdout);
94 siglen = EVP_PKEY_size(pkey);
95 sigbuf = malloc(siglen);
97 for(compter = 0; compter < cycles; compter++)
99 EVP_SignInit(&md_ctx, mdtype);
100 EVP_SignUpdate(&md_ctx, data, data_len);
101 EVP_SignFinal(&md_ctx, sigbuf, (unsigned int *) &siglen, pkey);
102 EVP_MD_CTX_cleanup(&md_ctx);
106 if ((fin - debut) < 3) { printf("cycles too low\n"); exit(1); }
107 printf("sign: %d/s\n", compter / (unsigned int)(fin - debut));