2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 static void start_timing(struct timespec
*start
)
23 clock_gettime(CLOCK_THREAD_CPUTIME_ID
, start
);
26 static double end_timing(struct timespec
*start
)
30 clock_gettime(CLOCK_THREAD_CPUTIME_ID
, &end
);
31 return (end
.tv_nsec
- start
->tv_nsec
) / 1000000000.0 +
32 (end
.tv_sec
- start
->tv_sec
) * 1.0;
36 /*******************************************************************************
37 * public key sign/verify speed test
38 ******************************************************************************/
42 diffie_hellman_group_t group
;
46 { MODP_1024_BIT
, 400},
47 { MODP_1536_BIT
, 200},
48 { MODP_2048_BIT
, 100},
57 for (group
= 0; group
< countof(groups
); group
++)
59 diffie_hellman_t
*l
[groups
[group
].rounds
], *r
;
61 struct timespec timing
;
63 r
= lib
->crypto
->create_dh(lib
->crypto
, groups
[group
].group
);
66 DBG1(DBG_CFG
, "skipping dh group %N, not supported",
67 diffie_hellman_group_names
, groups
[group
].group
);
71 DBG1(DBG_CFG
, "testing dh group %N:",
72 diffie_hellman_group_names
, groups
[group
].group
);
74 start_timing(&timing
);
75 for (round
= 0; round
< groups
[group
].rounds
; round
++)
77 l
[round
] = lib
->crypto
->create_dh(lib
->crypto
, groups
[group
].group
);
79 DBG1(DBG_CFG
, " %.0f A = g^a/s",
80 groups
[group
].rounds
/ end_timing(&timing
));
82 for (round
= 0; round
< groups
[group
].rounds
; round
++)
84 l
[round
]->get_my_public_value(l
[round
], &chunk
);
85 r
->set_other_public_value(r
, chunk
);
89 r
->get_my_public_value(r
, &chunk
);
90 start_timing(&timing
);
91 for (round
= 0; round
< groups
[group
].rounds
; round
++)
93 l
[round
]->set_other_public_value(l
[round
], chunk
);
95 DBG1(DBG_CFG
, " %.0f S = B^a/s",
96 groups
[group
].rounds
/ end_timing(&timing
));
99 for (round
= 0; round
< groups
[group
].rounds
; round
++)
101 l
[round
]->destroy(l
[round
]);