38 #define PTHREAD_THREADS_MAX 2048
59 "[-c config] -r repository [-i iterations] [-s keysize] [-t threads]\n",
70 unsigned int iterations = 0;
73 ldns_rr *rr, *sig, *dnskey_rr;
83 fprintf(stderr,
"Signer thread #%d started...\n", sign_arg->
id);
86 rrset = ldns_rr_list_new();
87 status = ldns_rr_new_frm_str(&rr,
"regress.opendnssec.se. IN A 123.123.123.123", 0, NULL, NULL);
88 if (status == LDNS_STATUS_OK) ldns_rr_list_push_rr(rrset, rr);
89 status = ldns_rr_new_frm_str(&rr,
"regress.opendnssec.se. IN A 124.124.124.124", 0, NULL, NULL);
90 if (status == LDNS_STATUS_OK) ldns_rr_list_push_rr(rrset, rr);
93 sign_params->
owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
"opendnssec.se.");
95 sign_params->
keytag = ldns_calc_keytag(dnskey_rr);
98 for (i=0; i<iterations; i++) {
102 "hsm_sign_rrset() returned error: %s in %s\n",
112 ldns_rr_list_deep_free(rrset);
114 ldns_rr_free(dnskey_rr);
117 fprintf(stderr,
"Signer thread #%d done.\n", sign_arg->
id);
130 unsigned int keysize = 1024;
131 unsigned int iterations = 1;
132 unsigned int threads = 1;
134 static struct timeval start,end;
137 const char *repository = NULL;
142 pthread_attr_t thread_attr;
147 double elapsed, speed;
151 while ((ch = getopt(argc, argv,
"c:i:r:s:t:")) != -1) {
157 iterations = atoi(
optarg);
160 repository = strdup(
optarg);
187 fprintf(stderr,
"Opening HSM Library...\n");
190 fprintf(stderr,
"hsm_open() returned %d\n", result);
197 fprintf(stderr,
"hsm_create_context() returned error\n");
202 fprintf(stderr,
"Generating temporary key...\n");
206 fprintf(stderr,
"Temporary key created: %s\n",
id);
209 fprintf(stderr,
"Could not generate a key pair in repository \"%s\"\n", repository);
214 pthread_attr_init(&thread_attr);
215 pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
217 for (n=0; n<threads; n++) {
218 sign_arg_array[n].
id = n;
220 if (! sign_arg_array[n].ctx) {
221 fprintf(stderr,
"hsm_create_context() returned error\n");
224 sign_arg_array[n].
key = key;
228 fprintf(stderr,
"Signing %d RRsets with %s using %d %s...\n",
229 iterations,
algoname, threads, (threads > 1 ?
"threads" :
"thread"));
230 gettimeofday(&start, NULL);
233 for (n=0; n<threads; n++) {
234 result = pthread_create(&thread_array[n], &thread_attr,
235 sign, (
void *) &sign_arg_array[n]);
237 fprintf(stderr,
"pthread_create() returned %d\n", result);
243 for (n=0; n<threads; n++) {
244 result = pthread_join(thread_array[n], &thread_status);
246 fprintf(stderr,
"pthread_join() returned %d\n", result);
251 gettimeofday(&end, NULL);
252 fprintf(stderr,
"Signing done.\n");
255 end.tv_sec -= start.tv_sec;
256 end.tv_usec-= start.tv_usec;
257 elapsed =(double)(end.tv_sec)+(double)(end.tv_usec)*.000001;
258 speed = iterations / elapsed * threads;
259 printf(
"%d %s, %d signatures per thread, %.2f sig/s (RSA %d bits)\n",
260 threads, (threads > 1 ?
"threads" :
"thread"), iterations,
264 fprintf(stderr,
"Deleting temporary key...\n");
267 fprintf(stderr,
"hsm_remove_key() returned %d\n", result);
274 if (config) free(config);