6 #include <crypto/diffie_hellman.h>
10 printf("usage: dh_speed plugins rounds group1 [group2 [...]]\n");
16 diffie_hellman_group_t group
;
18 {"modp768", MODP_768_BIT
},
19 {"modp1024", MODP_1024_BIT
},
20 {"modp1536", MODP_1536_BIT
},
21 {"modp2048", MODP_2048_BIT
},
22 {"modp3072", MODP_3072_BIT
},
23 {"modp4096", MODP_4096_BIT
},
24 {"modp6144", MODP_6144_BIT
},
25 {"modp8192", MODP_8192_BIT
},
26 {"ecp256", ECP_256_BIT
},
27 {"ecp384", ECP_384_BIT
},
28 {"ecp521", ECP_521_BIT
},
29 {"ecp192", ECP_192_BIT
},
30 {"ecp224", ECP_224_BIT
},
33 static void start_timing(struct timespec
*start
)
35 clock_gettime(CLOCK_THREAD_CPUTIME_ID
, start
);
38 static double end_timing(struct timespec
*start
)
42 clock_gettime(CLOCK_THREAD_CPUTIME_ID
, &end
);
43 return (end
.tv_nsec
- start
->tv_nsec
) / 1000000000.0 +
44 (end
.tv_sec
- start
->tv_sec
) * 1.0;
47 static void run_test(diffie_hellman_group_t group
, int rounds
)
49 diffie_hellman_t
*l
[rounds
], *r
;
51 struct timespec timing
;
54 r
= lib
->crypto
->create_dh(lib
->crypto
, group
);
57 printf("skipping %N, not supported\n",
58 diffie_hellman_group_names
, group
);
63 diffie_hellman_group_names
, group
);
65 start_timing(&timing
);
66 for (round
= 0; round
< rounds
; round
++)
68 l
[round
] = lib
->crypto
->create_dh(lib
->crypto
, group
);
70 printf("A = g^a/s: %8.1f", rounds
/ end_timing(&timing
));
72 for (round
= 0; round
< rounds
; round
++)
74 l
[round
]->get_my_public_value(l
[round
], &chunk
);
75 r
->set_other_public_value(r
, chunk
);
79 r
->get_my_public_value(r
, &chunk
);
80 start_timing(&timing
);
81 for (round
= 0; round
< rounds
; round
++)
83 l
[round
]->set_other_public_value(l
[round
], chunk
);
85 printf(" | S = B^a/s: %8.1f\n", rounds
/ end_timing(&timing
));
88 for (round
= 0; round
< rounds
; round
++)
90 l
[round
]->destroy(l
[round
]);
95 int main(int argc
, char *argv
[])
104 library_init(STRONGSWAN_CONF
);
105 lib
->plugins
->load(lib
->plugins
, IPSEC_PLUGINDIR
, argv
[1]);
106 atexit(library_deinit
);
108 rounds
= atoi(argv
[2]);
110 for (i
= 3; i
< argc
; i
++)
114 for (j
= 0; j
< countof(groups
); j
++)
116 if (streq(groups
[j
].name
, argv
[i
]))
118 run_test(groups
[j
].group
, rounds
);
124 printf("group %s not found\n", argv
[i
]);