Line data Source code
1 : /* benchmark.c - for libgcrypt
2 : * Copyright (C) 2002, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
3 : *
4 : * This file is part of Libgcrypt.
5 : *
6 : * Libgcrypt is free software; you can redistribute it and/or modify
7 : * it under the terms of the GNU Lesser general Public License as
8 : * published by the Free Software Foundation; either version 2.1 of
9 : * the License, or (at your option) any later version.
10 : *
11 : * Libgcrypt is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU Lesser General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public
17 : * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #ifdef HAVE_CONFIG_H
21 : #include <config.h>
22 : #endif
23 : #include <stdio.h>
24 : #include <stdlib.h>
25 : #include <stdarg.h>
26 :
27 : #ifdef _GCRYPT_IN_LIBGCRYPT
28 : # include "../src/gcrypt-int.h"
29 : # include "../compat/libcompat.h"
30 : #else
31 : # include <gcrypt.h>
32 : #endif
33 :
34 : #include "stopwatch.h"
35 :
36 :
37 : #define PGM "benchmark"
38 :
39 : static int verbose;
40 :
41 : /* Do encryption tests with large buffers. */
42 : static int large_buffers;
43 :
44 : /* Number of cipher repetitions. */
45 : static int cipher_repetitions;
46 :
47 : /* Number of hash repetitions. */
48 : static int hash_repetitions;
49 :
50 : /* Number of hash repetitions. */
51 : static int mac_repetitions;
52 :
53 : /* Alignment of the buffers. */
54 : static int buffer_alignment;
55 :
56 : /* Whether to include the keysetup in the cipher timings. */
57 : static int cipher_with_keysetup;
58 :
59 : /* Whether fips mode was active at startup. */
60 : static int in_fips_mode;
61 :
62 : /* Whether we are running as part of the regression test suite. */
63 : static int in_regression_test;
64 :
65 : /* Whether --progress is in use. */
66 : static int with_progress;
67 :
68 : /* Runtime flag to switch to a different progress output. */
69 : static int single_char_progress;
70 :
71 :
72 : static const char sample_private_dsa_key_1024[] =
73 : "(private-key\n"
74 : " (dsa\n"
75 : " (p #00A126202D592214C5A8F6016E2C3F4256052ACB1CB17D88E64B1293FAF08F5E4685"
76 : "03E6F68366B326A56284370EB2103E92D8346A163E44A08FDC422AC8E9E44268557A"
77 : "853539A6AF39353A59CE5E78FD98B57D0F3E3A7EBC8A256AC9A775BA59689F3004BF"
78 : "C3035730C4C0C51626C5D7F5852637EC589BB29DAB46C161572E4B#)\n"
79 : " (q #00DEB5A296421887179ECA1762884DE2AF8185AFC5#)\n"
80 : " (g #3958B34AE7747194ECBD312F8FEE8CBE3918E94DF9FD11E2912E56318F33BDC38622"
81 : "B18DDFF393074BCA8BAACF50DF27AEE529F3E8AEECE55C398DAB3A5E04C2EA142312"
82 : "FACA2FE7F0A88884F8DAC3979EE67598F9A383B2A2325F035C796F352A5C3CDF2CB3"
83 : "85AD24EC52A6E55247E1BB37D260F79E617D2A4446415B6AD79A#)\n"
84 : " (y #519E9FE9AB0545A6724E74603B7B04E48DC1437E0284A11EA605A7BA8AB1CF354FD4"
85 : "ECC93880AC293391C69B558AD84E7AAFA88F11D028CF3A378F241D6B056A90C588F6"
86 : "66F68D27262B4DA84657D15057D371BCEC1F6504032507D5B881E45FC93A1B973155"
87 : "D91C57219D090C3ACD75E7C2B9F1176A208AC03D6C12AC28A271#)\n"
88 : " (x #4186F8A58C5DF46C5BCFC7006BEEBF05E93C0CA7#)\n"
89 : "))\n";
90 :
91 : static const char sample_public_dsa_key_1024[] =
92 : "(public-key\n"
93 : " (dsa\n"
94 : " (p #00A126202D592214C5A8F6016E2C3F4256052ACB1CB17D88E64B1293FAF08F5E4685"
95 : "03E6F68366B326A56284370EB2103E92D8346A163E44A08FDC422AC8E9E44268557A"
96 : "853539A6AF39353A59CE5E78FD98B57D0F3E3A7EBC8A256AC9A775BA59689F3004BF"
97 : "C3035730C4C0C51626C5D7F5852637EC589BB29DAB46C161572E4B#)\n"
98 : " (q #00DEB5A296421887179ECA1762884DE2AF8185AFC5#)\n"
99 : " (g #3958B34AE7747194ECBD312F8FEE8CBE3918E94DF9FD11E2912E56318F33BDC38622"
100 : "B18DDFF393074BCA8BAACF50DF27AEE529F3E8AEECE55C398DAB3A5E04C2EA142312"
101 : "FACA2FE7F0A88884F8DAC3979EE67598F9A383B2A2325F035C796F352A5C3CDF2CB3"
102 : "85AD24EC52A6E55247E1BB37D260F79E617D2A4446415B6AD79A#)\n"
103 : " (y #519E9FE9AB0545A6724E74603B7B04E48DC1437E0284A11EA605A7BA8AB1CF354FD4"
104 : "ECC93880AC293391C69B558AD84E7AAFA88F11D028CF3A378F241D6B056A90C588F6"
105 : "66F68D27262B4DA84657D15057D371BCEC1F6504032507D5B881E45FC93A1B973155"
106 : "D91C57219D090C3ACD75E7C2B9F1176A208AC03D6C12AC28A271#)\n"
107 : "))\n";
108 :
109 :
110 : static const char sample_private_dsa_key_2048[] =
111 : "(private-key\n"
112 : " (dsa\n"
113 : " (p #00B54636673962B64F7DC23C71ACEF6E7331796F607560B194DFCC0CA370E858A365"
114 : "A413152FB6EB8C664BD171AC316FE5B381CD084D07377571599880A068EF1382D85C"
115 : "308B4E9DEAC12D66DE5C4A826EBEB5ED94A62E7301E18927E890589A2F230272A150"
116 : "C118BC3DC2965AE0D05BE4F65C6137B2BA7EDABB192C3070D202C10AA3F534574970"
117 : "71454DB8A73DDB6511A5BA98EF1450FD90DE5BAAFC9FD3AC22EBEA612DD075BB7405"
118 : "D56866D125E33982C046808F7CEBA8E5C0B9F19A6FE451461660A1CBA9EF68891179"
119 : "0256A573D3B8F35A5C7A0C6C31F2DB90E25A26845252AD9E485EF2D339E7B5890CD4"
120 : "2F9C9F315ED409171EC35CA04CC06B275577B3#)\n"
121 : " (q #00DA67989167FDAC4AE3DF9247A716859A30C0CF9C5A6DBA01EABA3481#)\n"
122 : " (g #48E35DA584A089D05142AA63603FDB00D131B07A0781E2D5A8F9614D2B33D3E40A78"
123 : "98A9E10CDBB612CF093F95A3E10D09566726F2C12823836B2D9CD974BB695665F3B3"
124 : "5D219A9724B87F380BD5207EDA0AE38C79E8F18122C3F76E4CEB0ABED3250914987F"
125 : "B30D4B9E19C04C28A5D4F45560AF586F6A1B41751EAD90AE7F044F4E2A4A50C1F508"
126 : "4FC202463F478F678B9A19392F0D2961C5391C546EF365368BB46410C9C1CEE96E9F"
127 : "0C953570C2ED06328B11C90E86E57CAA7FA5ABAA278E22A4C8C08E16EE59F484EC44"
128 : "2CF55535BAA2C6BEA8833A555372BEFE1E665D3C7DAEF58061D5136331EF4EB61BC3"
129 : "6EE4425A553AF8885FEA15A88135BE133520#)\n"
130 : " (y #66E0D1A69D663466F8FEF2B7C0878DAC93C36A2FB2C05E0306A53B926021D4B92A1C"
131 : "2FA6860061E88E78CBBBA49B0E12700F07DBF86F72CEB2927EDAC0C7E3969C3A47BB"
132 : "4E0AE93D8BB3313E93CC7A72DFEEE442EFBC81B3B2AEC9D8DCBE21220FB760201D79"
133 : "328C41C773866587A44B6954767D022A88072900E964089D9B17133603056C985C4F"
134 : "8A0B648F297F8D2C3CB43E4371DC6002B5B12CCC085BDB2CFC5074A0587566187EE3"
135 : "E11A2A459BD94726248BB8D6CC62938E11E284C2C183576FBB51749EB238C4360923"
136 : "79C08CE1C8CD77EB57404CE9B4744395ACF721487450BADE3220576F2F816248B0A7"
137 : "14A264330AECCB24DE2A1107847B23490897#)\n"
138 : " (x #477BD14676E22563C5ABA68025CEBA2A48D485F5B2D4AD4C0EBBD6D0#)\n"
139 : "))\n";
140 :
141 :
142 : static const char sample_public_dsa_key_2048[] =
143 : "(public-key\n"
144 : " (dsa\n"
145 : " (p #00B54636673962B64F7DC23C71ACEF6E7331796F607560B194DFCC0CA370E858A365"
146 : "A413152FB6EB8C664BD171AC316FE5B381CD084D07377571599880A068EF1382D85C"
147 : "308B4E9DEAC12D66DE5C4A826EBEB5ED94A62E7301E18927E890589A2F230272A150"
148 : "C118BC3DC2965AE0D05BE4F65C6137B2BA7EDABB192C3070D202C10AA3F534574970"
149 : "71454DB8A73DDB6511A5BA98EF1450FD90DE5BAAFC9FD3AC22EBEA612DD075BB7405"
150 : "D56866D125E33982C046808F7CEBA8E5C0B9F19A6FE451461660A1CBA9EF68891179"
151 : "0256A573D3B8F35A5C7A0C6C31F2DB90E25A26845252AD9E485EF2D339E7B5890CD4"
152 : "2F9C9F315ED409171EC35CA04CC06B275577B3#)\n"
153 : " (q #00DA67989167FDAC4AE3DF9247A716859A30C0CF9C5A6DBA01EABA3481#)\n"
154 : " (g #48E35DA584A089D05142AA63603FDB00D131B07A0781E2D5A8F9614D2B33D3E40A78"
155 : "98A9E10CDBB612CF093F95A3E10D09566726F2C12823836B2D9CD974BB695665F3B3"
156 : "5D219A9724B87F380BD5207EDA0AE38C79E8F18122C3F76E4CEB0ABED3250914987F"
157 : "B30D4B9E19C04C28A5D4F45560AF586F6A1B41751EAD90AE7F044F4E2A4A50C1F508"
158 : "4FC202463F478F678B9A19392F0D2961C5391C546EF365368BB46410C9C1CEE96E9F"
159 : "0C953570C2ED06328B11C90E86E57CAA7FA5ABAA278E22A4C8C08E16EE59F484EC44"
160 : "2CF55535BAA2C6BEA8833A555372BEFE1E665D3C7DAEF58061D5136331EF4EB61BC3"
161 : "6EE4425A553AF8885FEA15A88135BE133520#)\n"
162 : " (y #66E0D1A69D663466F8FEF2B7C0878DAC93C36A2FB2C05E0306A53B926021D4B92A1C"
163 : "2FA6860061E88E78CBBBA49B0E12700F07DBF86F72CEB2927EDAC0C7E3969C3A47BB"
164 : "4E0AE93D8BB3313E93CC7A72DFEEE442EFBC81B3B2AEC9D8DCBE21220FB760201D79"
165 : "328C41C773866587A44B6954767D022A88072900E964089D9B17133603056C985C4F"
166 : "8A0B648F297F8D2C3CB43E4371DC6002B5B12CCC085BDB2CFC5074A0587566187EE3"
167 : "E11A2A459BD94726248BB8D6CC62938E11E284C2C183576FBB51749EB238C4360923"
168 : "79C08CE1C8CD77EB57404CE9B4744395ACF721487450BADE3220576F2F816248B0A7"
169 : "14A264330AECCB24DE2A1107847B23490897#)\n"
170 : "))\n";
171 :
172 :
173 : static const char sample_private_dsa_key_3072[] =
174 : "(private-key\n"
175 : " (dsa\n"
176 : " (p #00BA73E148AEA5E8B64878AF5BE712B8302B9671C5F3EEB7722A9D0D9868D048C938"
177 : "877C91C335C7819292E69C7D34264F1578E32EC2DA8408DF75D0EB76E0D3030B84B5"
178 : "62D8EF93AB53BAB6B8A5DE464F5CA87AEA43BDCF0FB0B7815AA3114CFC84FD916A83"
179 : "B3D5FD78390189332232E9D037D215313FD002FF46C048B66703F87FAE092AAA0988"
180 : "AC745336EBE672A01DEDBD52395783579B67CF3AE1D6F1602CCCB12154FA0E00AE46"
181 : "0D9B289CF709194625BCB919B11038DEFC50ADBBA20C3F320078E4E9529B4F6848E2"
182 : "AB5E6278DB961FE226F2EEBD201E071C48C5BEF98B4D9BEE42C1C7102D893EBF8902"
183 : "D7A91266340AFD6CE1D09E52282FFF5B97EAFA3886A3FCF84FF76D1E06538D0D8E60"
184 : "B3332145785E07D29A5965382DE3470D1D888447FA9C00A2373378FC3FA7B9F7D17E"
185 : "95A6A5AE1397BE46D976EF2C96E89913AC4A09351CA661BF6F67E30407DA846946C7"
186 : "62D9BAA6B77825097D3E7B886456BB32E3E74516BF3FD93D71B257AA8F723E01CE33"
187 : "8015353D3778B02B892AF7#)\n"
188 : " (q #00BFF3F3CC18FA018A5B8155A8695E1E4939660D5E4759322C39D50F3B93E5F68B#)\n"
189 : " (g #6CCFD8219F5FCE8EF2BEF3262929787140847E38674B1EF8DB20255E212CB6330EC4"
190 : "DFE8A26AB7ECC5760DEB9BBF59A2B2821D510F1868172222867558B8D204E889C474"
191 : "7CA30FBF9D8CF41AE5D5BD845174641101593849FF333E6C93A6550931B2B9D56B98"
192 : "9CAB01729D9D736FA6D24A74D2DDE1E9E648D141473E443DD6BBF0B3CAB64F9FE4FC"
193 : "134B2EB57437789F75C744DF1FA67FA8A64603E5441BC7ECE29E00BDF262BDC81E8C"
194 : "7330A18A412DE38E7546D342B89A0AF675A89E6BEF00540EB107A2FE74EA402B0D89"
195 : "F5C02918DEEEAF8B8737AC866B09B50810AB8D8668834A1B9E1E53866E2B0A926FAB"
196 : "120A0CDE5B3715FFFE6ACD1AB73588DCC1EC4CE9392FE57F8D1D35811200CB07A0E6"
197 : "374E2C4B0AEB7E3D077B8545C0E438DCC0F1AE81E186930E99EBC5B91B77E92803E0"
198 : "21602887851A4FFDB3A7896AC655A0901218C121C5CBB0931E7D5EAC243F37711B5F"
199 : "D5A62B1B38A83F03D8F6703D8B98DF367FC8A76990335F62173A5391836F0F2413EC"
200 : "4997AF9EB55C6660B01A#)\n"
201 : " (y #2320B22434C5DB832B4EC267CC52E78DD5CCFA911E8F0804E7E7F32B186B2D4167AE"
202 : "4AA6869822E76400492D6A193B0535322C72B0B7AA4A87E33044FDC84BE24C64A053"
203 : "A37655EE9EABDCDC1FDF63F3F1C677CEB41595DF7DEFE9178D85A3D621B4E4775492"
204 : "8C0A58D2458D06F9562E4DE2FE6129A64063A99E88E54485B97484A28188C4D33F15"
205 : "DDC903B6CEA0135E3E3D27B4EA39319696305CE93D7BA7BE00367DBE3AAF43491E71"
206 : "CBF254744A5567F5D70090D6139E0C990239627B3A1C5B20B6F9F6374B8D8D8A8997"
207 : "437265BE1E3B4810D4B09254400DE287A0DFFBAEF339E48D422B1D41A37E642BC026"
208 : "73314701C8FA9792845C129351A87A945A03E6C895860E51D6FB8B7340A94D1A8A7B"
209 : "FA85AC83B4B14E73AB86CB96C236C8BFB0978B61B2367A7FE4F7891070F56C78D5DD"
210 : "F5576BFE5BE4F333A4E2664E79528B3294907AADD63F4F2E7AA8147B928D8CD69765"
211 : "3DB98C4297CB678046ED55C0DBE60BF7142C594603E4D705DC3D17270F9F086EC561"
212 : "2703D518D8D49FF0EBE6#)\n"
213 : " (x #00A9FFFC88E67D6F7B810E291C050BAFEA7FC4A75E8D2F16CFED3416FD77607232#)\n"
214 : "))\n";
215 :
216 : static const char sample_public_dsa_key_3072[] =
217 : "(public-key\n"
218 : " (dsa\n"
219 : " (p #00BA73E148AEA5E8B64878AF5BE712B8302B9671C5F3EEB7722A9D0D9868D048C938"
220 : "877C91C335C7819292E69C7D34264F1578E32EC2DA8408DF75D0EB76E0D3030B84B5"
221 : "62D8EF93AB53BAB6B8A5DE464F5CA87AEA43BDCF0FB0B7815AA3114CFC84FD916A83"
222 : "B3D5FD78390189332232E9D037D215313FD002FF46C048B66703F87FAE092AAA0988"
223 : "AC745336EBE672A01DEDBD52395783579B67CF3AE1D6F1602CCCB12154FA0E00AE46"
224 : "0D9B289CF709194625BCB919B11038DEFC50ADBBA20C3F320078E4E9529B4F6848E2"
225 : "AB5E6278DB961FE226F2EEBD201E071C48C5BEF98B4D9BEE42C1C7102D893EBF8902"
226 : "D7A91266340AFD6CE1D09E52282FFF5B97EAFA3886A3FCF84FF76D1E06538D0D8E60"
227 : "B3332145785E07D29A5965382DE3470D1D888447FA9C00A2373378FC3FA7B9F7D17E"
228 : "95A6A5AE1397BE46D976EF2C96E89913AC4A09351CA661BF6F67E30407DA846946C7"
229 : "62D9BAA6B77825097D3E7B886456BB32E3E74516BF3FD93D71B257AA8F723E01CE33"
230 : "8015353D3778B02B892AF7#)\n"
231 : " (q #00BFF3F3CC18FA018A5B8155A8695E1E4939660D5E4759322C39D50F3B93E5F68B#)\n"
232 : " (g #6CCFD8219F5FCE8EF2BEF3262929787140847E38674B1EF8DB20255E212CB6330EC4"
233 : "DFE8A26AB7ECC5760DEB9BBF59A2B2821D510F1868172222867558B8D204E889C474"
234 : "7CA30FBF9D8CF41AE5D5BD845174641101593849FF333E6C93A6550931B2B9D56B98"
235 : "9CAB01729D9D736FA6D24A74D2DDE1E9E648D141473E443DD6BBF0B3CAB64F9FE4FC"
236 : "134B2EB57437789F75C744DF1FA67FA8A64603E5441BC7ECE29E00BDF262BDC81E8C"
237 : "7330A18A412DE38E7546D342B89A0AF675A89E6BEF00540EB107A2FE74EA402B0D89"
238 : "F5C02918DEEEAF8B8737AC866B09B50810AB8D8668834A1B9E1E53866E2B0A926FAB"
239 : "120A0CDE5B3715FFFE6ACD1AB73588DCC1EC4CE9392FE57F8D1D35811200CB07A0E6"
240 : "374E2C4B0AEB7E3D077B8545C0E438DCC0F1AE81E186930E99EBC5B91B77E92803E0"
241 : "21602887851A4FFDB3A7896AC655A0901218C121C5CBB0931E7D5EAC243F37711B5F"
242 : "D5A62B1B38A83F03D8F6703D8B98DF367FC8A76990335F62173A5391836F0F2413EC"
243 : "4997AF9EB55C6660B01A#)\n"
244 : " (y #2320B22434C5DB832B4EC267CC52E78DD5CCFA911E8F0804E7E7F32B186B2D4167AE"
245 : "4AA6869822E76400492D6A193B0535322C72B0B7AA4A87E33044FDC84BE24C64A053"
246 : "A37655EE9EABDCDC1FDF63F3F1C677CEB41595DF7DEFE9178D85A3D621B4E4775492"
247 : "8C0A58D2458D06F9562E4DE2FE6129A64063A99E88E54485B97484A28188C4D33F15"
248 : "DDC903B6CEA0135E3E3D27B4EA39319696305CE93D7BA7BE00367DBE3AAF43491E71"
249 : "CBF254744A5567F5D70090D6139E0C990239627B3A1C5B20B6F9F6374B8D8D8A8997"
250 : "437265BE1E3B4810D4B09254400DE287A0DFFBAEF339E48D422B1D41A37E642BC026"
251 : "73314701C8FA9792845C129351A87A945A03E6C895860E51D6FB8B7340A94D1A8A7B"
252 : "FA85AC83B4B14E73AB86CB96C236C8BFB0978B61B2367A7FE4F7891070F56C78D5DD"
253 : "F5576BFE5BE4F333A4E2664E79528B3294907AADD63F4F2E7AA8147B928D8CD69765"
254 : "3DB98C4297CB678046ED55C0DBE60BF7142C594603E4D705DC3D17270F9F086EC561"
255 : "2703D518D8D49FF0EBE6#)\n"
256 : "))\n";
257 :
258 :
259 : static const char sample_public_elg_key_1024[] =
260 : "(public-key"
261 : " (elg"
262 : " (p #00F7CC7C08AF096B620C545C9353B1140D698FF8BE2D97A3515C17C7F8DABCDB8FB6"
263 : "64A46416C90C530C18DF5ABB6C1DDE3AE2FA9DDC9CE40DF644CDE2E759F6DE43F31A"
264 : "EEEBC136A460B3E4B0A8F99326A335145B19F4C81B13804894B7D2A30F78A8A7D7F4"
265 : "52B83836FDB0DE90BE327FB5E5318757BEF5FE0FC3A5461CBEA0D3#)"
266 : " (g #06#)"
267 : " (y #36B38FB63E3340A0DD8A0468E9FAA512A32DA010BF7110201D0A3DF1B8FEA0E16F3C"
268 : "80374584E554804B96EAA8C270FE531F75D0DBD81BA65640EDB1F76D46C27D2925B7"
269 : "3EC3B295CDAEEF242904A84D74FB2879425F82D4C5B59BB49A992F85D574168DED85"
270 : "D227600BBEF7AF0B8F0DEB785528370E4C4B3E4D65C536122A5A#)"
271 : " ))";
272 : static const char sample_private_elg_key_1024[] =
273 : "(private-key"
274 : " (elg"
275 : " (p #00F7CC7C08AF096B620C545C9353B1140D698FF8BE2D97A3515C17C7F8DABCDB8FB6"
276 : "64A46416C90C530C18DF5ABB6C1DDE3AE2FA9DDC9CE40DF644CDE2E759F6DE43F31A"
277 : "EEEBC136A460B3E4B0A8F99326A335145B19F4C81B13804894B7D2A30F78A8A7D7F4"
278 : "52B83836FDB0DE90BE327FB5E5318757BEF5FE0FC3A5461CBEA0D3#)"
279 : " (g #06#)"
280 : " (y #36B38FB63E3340A0DD8A0468E9FAA512A32DA010BF7110201D0A3DF1B8FEA0E16F3C"
281 : "80374584E554804B96EAA8C270FE531F75D0DBD81BA65640EDB1F76D46C27D2925B7"
282 : "3EC3B295CDAEEF242904A84D74FB2879425F82D4C5B59BB49A992F85D574168DED85"
283 : "D227600BBEF7AF0B8F0DEB785528370E4C4B3E4D65C536122A5A#)"
284 : " (x #03656C6186FCD27D4A4B1F5010DC0D2AE7833B501E423FCD51DE5EB6D80DACFE#)"
285 : " ))";
286 :
287 :
288 : static const char sample_public_elg_key_2048[] =
289 : "(public-key"
290 : " (elg"
291 : " (p #00BE5A2BB4E562D7B644E3D01321CB818DBA27295C339FC2C47EAE9823225EE1E7B6"
292 : "38C5DE300E931080E09CC89A18C9D180C16559FEF0D89D6A09534BB86489CCCEE30D"
293 : "C18E007A8726BB99F2B2D90D2694597757B120CD2435C0098AD1B74C20004C25BA97"
294 : "73EAA4FBEC594EE17F8B25867EEB0F9F857C751116ADED68ADA2A1E9F9F4F40D18F0"
295 : "EC1221CA6A746FC5F4CDA2B8B5D0AB83834564ACF6FDBB1AB01D4BFBD1E2C0108FF5"
296 : "5FB3190C6D6DA4D95EA683EFA44935CFBC0BF5C6118ACC3768AEA9A98D06024841B8"
297 : "D07C234289D22A5E3948F199C397AA991C59A55BEA0C01E91902E039116946FEA135"
298 : "768011AF6B622C5AF366EF0196FC4EAEAA8127#)"
299 : " (g #07#)"
300 : " (y #5AFF87BC23D8B97AA62897A5C1CDFFA86C59F39EDBD6012B6F333CE23D872009B8C8"
301 : "D1E220E18CFCADFE0AA16346BA2EA132472FFEC746D11C6E758896052313BB501210"
302 : "2389C683A25A3464E9B35A192BAE0A3BB99C973126F7560D968C4A754901DC967354"
303 : "D61A90ACD56D90DCC4337AFB71FAE3FD18C60EB0D6DD173877DF5DB5199C4931FE4E"
304 : "5046F814422580E1162798406FC6554781142DBB7922D4B5B37A111F23761636090F"
305 : "6212681E133365191CF15753AE737F17943ED4B7506DE0A85C3B6D63227F9D65ADF8"
306 : "2C3DF0676C8F43B5B1C07D9AD4E6D0C812401D7DA7B9484DBA8CD3B73B19A95EB237"
307 : "D493E092AEA2371AA904009C8960B0969D12#)"
308 : " ))";
309 : static const char sample_private_elg_key_2048[] =
310 : "(private-key"
311 : " (elg"
312 : " (p #00BE5A2BB4E562D7B644E3D01321CB818DBA27295C339FC2C47EAE9823225EE1E7B6"
313 : "38C5DE300E931080E09CC89A18C9D180C16559FEF0D89D6A09534BB86489CCCEE30D"
314 : "C18E007A8726BB99F2B2D90D2694597757B120CD2435C0098AD1B74C20004C25BA97"
315 : "73EAA4FBEC594EE17F8B25867EEB0F9F857C751116ADED68ADA2A1E9F9F4F40D18F0"
316 : "EC1221CA6A746FC5F4CDA2B8B5D0AB83834564ACF6FDBB1AB01D4BFBD1E2C0108FF5"
317 : "5FB3190C6D6DA4D95EA683EFA44935CFBC0BF5C6118ACC3768AEA9A98D06024841B8"
318 : "D07C234289D22A5E3948F199C397AA991C59A55BEA0C01E91902E039116946FEA135"
319 : "768011AF6B622C5AF366EF0196FC4EAEAA8127#)"
320 : " (g #07#)"
321 : " (y #5AFF87BC23D8B97AA62897A5C1CDFFA86C59F39EDBD6012B6F333CE23D872009B8C8"
322 : "D1E220E18CFCADFE0AA16346BA2EA132472FFEC746D11C6E758896052313BB501210"
323 : "2389C683A25A3464E9B35A192BAE0A3BB99C973126F7560D968C4A754901DC967354"
324 : "D61A90ACD56D90DCC4337AFB71FAE3FD18C60EB0D6DD173877DF5DB5199C4931FE4E"
325 : "5046F814422580E1162798406FC6554781142DBB7922D4B5B37A111F23761636090F"
326 : "6212681E133365191CF15753AE737F17943ED4B7506DE0A85C3B6D63227F9D65ADF8"
327 : "2C3DF0676C8F43B5B1C07D9AD4E6D0C812401D7DA7B9484DBA8CD3B73B19A95EB237"
328 : "D493E092AEA2371AA904009C8960B0969D12#)"
329 : " (x #0628C3903972C55BDC1BC4223075616D3F3BA57D55532DDB40CB14CF72070E0D28BF"
330 : "D0402B9088D25ED8FC#)"
331 : " ))";
332 :
333 : static const char sample_public_elg_key_3072[] =
334 : "(public-key"
335 : " (elg"
336 : " (p #008EAA3497AFE3706E1A57FFA52E68C64C500731B58EBAFEB51C4A20AB15BA57FA72"
337 : "BA1510A4703D5AA6F05DB67E4A776F92AD08800577DC686D00B793167A5D79C997E0"
338 : "5B9A9E5974B4B68B4D71ED8EC37F2F45235D901997D72915643F058E712AA18275A2"
339 : "C6F9F7C2B9B7CD1E814D215F12A840800B546AEF2A2E6C077CDD1A322738FFD36DB2"
340 : "FA5420B5848EED870BC1A6CF55040AE8D2A5945F11AE2BCBE107B41A59EFDBD3B05C"
341 : "F4C876C02C9AEAE22CD4C86806A415302936E4C1E5AA59DBBCCD2F83C20941A29888"
342 : "A70ADB94D3B8A6489C46BF2C5219CD9FD2341EA21D4E68A4ECC468FD09D215FE96D4"
343 : "7AEA12FD22B2456D2CC13672FC7E9772A365C68668157C51E46966B6A1831C429BA0"
344 : "D513519713C49C13C5FC7C14BE0A117627B204C4478D0A93C6B57929E448C9B65BF2"
345 : "390E04BC5940320C0262FC1A221E7C796493432239A6F12BC62C5CF32E8ADBC1730C"
346 : "84C6E6E6BD95AF62835941F3F344AF46BFE5A8F629D5FA699FE37EF8B8C6A2484E42"
347 : "D226206FDF7D1FB93A5457#)"
348 : " (g #0B#)"
349 : " (y #18E734FF645AE169079AEAFC78772371089AD3088627ECF77034AFBDF33ADF594AAF"
350 : "3288F6979E0DB59CE3D2F0FEE031DFF187F1E4549D3C79668794CB19C14481ECDE2D"
351 : "D50861AB674F87A011D50D35F28E424D0D2353850899C2CDD0CC8FDBFC5A0CA395F0"
352 : "E605D46CBDD140DBEF426EBD638C9ADD83C195C45CE84ED2D2B21B87800C783A4F79"
353 : "12226FEFBDA01C66B254534A51765AF09687275AA80C5DFBA143A6262E47C547D7E2"
354 : "289413F8C5C56AED3FA7E5DF5526958E2294FE318AF590C0E720029C202563E6E686"
355 : "9EC810F39A859262FB6047C1D418CAA9047A00BDB127B44B69CF6BC8E6B3709B4C23"
356 : "79783C5F8457EFE23EDA6FF00D1DDCC29268FC4A6C18577BE2B7004089CBB824027A"
357 : "A53C86B51DB054CC83B4F50C8923E2E9431F0A77D741237226CC68591083A2E40171"
358 : "5C7B74100BB74003E2264F8B44A0B0BC5404C44218ABE65C04AA573877506CE4F48C"
359 : "9E3F8AD1CD8DD9F285DD015C2FC5DEBCFA5779AD87F0BBC62E9EC6246021AB450DB9"
360 : "4DDDEFAFD2C7C66E235D#)"
361 : " ))";
362 : static const char sample_private_elg_key_3072[] =
363 : "(private-key"
364 : " (elg"
365 : " (p #008EAA3497AFE3706E1A57FFA52E68C64C500731B58EBAFEB51C4A20AB15BA57FA72"
366 : "BA1510A4703D5AA6F05DB67E4A776F92AD08800577DC686D00B793167A5D79C997E0"
367 : "5B9A9E5974B4B68B4D71ED8EC37F2F45235D901997D72915643F058E712AA18275A2"
368 : "C6F9F7C2B9B7CD1E814D215F12A840800B546AEF2A2E6C077CDD1A322738FFD36DB2"
369 : "FA5420B5848EED870BC1A6CF55040AE8D2A5945F11AE2BCBE107B41A59EFDBD3B05C"
370 : "F4C876C02C9AEAE22CD4C86806A415302936E4C1E5AA59DBBCCD2F83C20941A29888"
371 : "A70ADB94D3B8A6489C46BF2C5219CD9FD2341EA21D4E68A4ECC468FD09D215FE96D4"
372 : "7AEA12FD22B2456D2CC13672FC7E9772A365C68668157C51E46966B6A1831C429BA0"
373 : "D513519713C49C13C5FC7C14BE0A117627B204C4478D0A93C6B57929E448C9B65BF2"
374 : "390E04BC5940320C0262FC1A221E7C796493432239A6F12BC62C5CF32E8ADBC1730C"
375 : "84C6E6E6BD95AF62835941F3F344AF46BFE5A8F629D5FA699FE37EF8B8C6A2484E42"
376 : "D226206FDF7D1FB93A5457#)"
377 : " (g #0B#)"
378 : " (y #18E734FF645AE169079AEAFC78772371089AD3088627ECF77034AFBDF33ADF594AAF"
379 : "3288F6979E0DB59CE3D2F0FEE031DFF187F1E4549D3C79668794CB19C14481ECDE2D"
380 : "D50861AB674F87A011D50D35F28E424D0D2353850899C2CDD0CC8FDBFC5A0CA395F0"
381 : "E605D46CBDD140DBEF426EBD638C9ADD83C195C45CE84ED2D2B21B87800C783A4F79"
382 : "12226FEFBDA01C66B254534A51765AF09687275AA80C5DFBA143A6262E47C547D7E2"
383 : "289413F8C5C56AED3FA7E5DF5526958E2294FE318AF590C0E720029C202563E6E686"
384 : "9EC810F39A859262FB6047C1D418CAA9047A00BDB127B44B69CF6BC8E6B3709B4C23"
385 : "79783C5F8457EFE23EDA6FF00D1DDCC29268FC4A6C18577BE2B7004089CBB824027A"
386 : "A53C86B51DB054CC83B4F50C8923E2E9431F0A77D741237226CC68591083A2E40171"
387 : "5C7B74100BB74003E2264F8B44A0B0BC5404C44218ABE65C04AA573877506CE4F48C"
388 : "9E3F8AD1CD8DD9F285DD015C2FC5DEBCFA5779AD87F0BBC62E9EC6246021AB450DB9"
389 : "4DDDEFAFD2C7C66E235D#)"
390 : " (x #03A73F0389E470AAC831B039F8AA0C4EBD3A47DD083E32EEA08E4911236CD597C272"
391 : "9823D47A51C8535DA52FE6DAB3E8D1C20D#)"
392 : " ))";
393 :
394 :
395 : #define DIM(v) (sizeof(v)/sizeof((v)[0]))
396 : #define DIMof(type,member) DIM(((type *)0)->member)
397 : #define BUG() do {fprintf ( stderr, "Ooops at %s:%d\n", __FILE__ , __LINE__ );\
398 : exit(2);} while(0)
399 :
400 :
401 : static void
402 0 : die (const char *format, ...)
403 : {
404 : va_list arg_ptr ;
405 :
406 0 : va_start( arg_ptr, format ) ;
407 0 : putchar ('\n');
408 0 : fputs ( PGM ": ", stderr);
409 0 : vfprintf (stderr, format, arg_ptr );
410 0 : va_end(arg_ptr);
411 0 : exit (1);
412 : }
413 :
414 :
415 : static void
416 0 : show_sexp (const char *prefix, gcry_sexp_t a)
417 : {
418 : char *buf;
419 : size_t size;
420 :
421 0 : fputs (prefix, stderr);
422 0 : size = gcry_sexp_sprint (a, GCRYSEXP_FMT_ADVANCED, NULL, 0);
423 0 : buf = malloc (size);
424 0 : if (!buf)
425 0 : die ("out of core\n");
426 :
427 0 : gcry_sexp_sprint (a, GCRYSEXP_FMT_ADVANCED, buf, size);
428 0 : fprintf (stderr, "%.*s", (int)size, buf);
429 0 : }
430 :
431 :
432 : static void
433 0 : progress_cb (void *cb_data, const char *what, int printchar,
434 : int current, int total)
435 : {
436 : (void)cb_data;
437 :
438 0 : if (single_char_progress)
439 : {
440 0 : fputc (printchar, stdout);
441 0 : fflush (stderr);
442 : }
443 : else
444 : {
445 0 : fprintf (stderr, PGM ": progress (%s %c %d %d)\n",
446 : what, printchar, current, total);
447 0 : fflush (stderr);
448 : }
449 0 : }
450 :
451 :
452 : static void
453 1 : random_bench (int very_strong)
454 : {
455 : char buf[128];
456 : int i;
457 :
458 1 : printf ("%-10s", "random");
459 :
460 1 : if (!very_strong)
461 : {
462 1 : start_timer ();
463 101 : for (i=0; i < 100; i++)
464 100 : gcry_randomize (buf, sizeof buf, GCRY_STRONG_RANDOM);
465 1 : stop_timer ();
466 1 : printf (" %s", elapsed_time (1));
467 : }
468 :
469 1 : start_timer ();
470 101 : for (i=0; i < 100; i++)
471 100 : gcry_randomize (buf, 8,
472 : very_strong? GCRY_VERY_STRONG_RANDOM:GCRY_STRONG_RANDOM);
473 1 : stop_timer ();
474 1 : printf (" %s", elapsed_time (1));
475 :
476 1 : putchar ('\n');
477 1 : if (verbose)
478 0 : gcry_control (GCRYCTL_DUMP_RANDOM_STATS);
479 1 : }
480 :
481 :
482 :
483 : static void
484 26 : md_bench ( const char *algoname )
485 : {
486 : int algo;
487 : gcry_md_hd_t hd;
488 : int i, j, repcount;
489 : char buf_base[1000+15];
490 26 : size_t bufsize = 1000;
491 : char *buf;
492 : char *largebuf_base;
493 : char *largebuf;
494 : char digest[512/8];
495 26 : gcry_error_t err = GPG_ERR_NO_ERROR;
496 :
497 26 : if (!algoname)
498 : {
499 400 : for (i=1; i < 400; i++)
500 399 : if (in_fips_mode && i == GCRY_MD_MD5)
501 : ; /* Don't use MD5 in fips mode. */
502 399 : else if ( !gcry_md_test_algo (i) )
503 25 : md_bench (gcry_md_algo_name (i));
504 27 : return;
505 : }
506 :
507 25 : buf = buf_base + ((16 - ((size_t)buf_base & 0x0f)) % buffer_alignment);
508 :
509 25 : algo = gcry_md_map_name (algoname);
510 25 : if (!algo)
511 : {
512 0 : fprintf (stderr, PGM ": invalid hash algorithm `%s'\n", algoname);
513 0 : exit (1);
514 : }
515 :
516 25 : err = gcry_md_open (&hd, algo, 0);
517 25 : if (err)
518 : {
519 0 : fprintf (stderr, PGM ": error opening hash algorithm `%s'\n", algoname);
520 0 : exit (1);
521 : }
522 :
523 25025 : for (i=0; i < bufsize; i++)
524 25000 : buf[i] = i;
525 :
526 25 : printf ("%-12s", gcry_md_algo_name (algo));
527 :
528 25 : start_timer ();
529 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
530 25025 : for (i=0; i < 1000; i++)
531 25000 : gcry_md_write (hd, buf, bufsize);
532 25 : gcry_md_final (hd);
533 25 : stop_timer ();
534 25 : printf (" %s", elapsed_time (1));
535 25 : fflush (stdout);
536 :
537 25 : gcry_md_reset (hd);
538 25 : start_timer ();
539 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
540 250025 : for (i=0; i < 10000; i++)
541 250000 : gcry_md_write (hd, buf, bufsize/10);
542 25 : gcry_md_final (hd);
543 25 : stop_timer ();
544 25 : printf (" %s", elapsed_time (1));
545 25 : fflush (stdout);
546 :
547 25 : gcry_md_reset (hd);
548 25 : start_timer ();
549 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
550 25000025 : for (i=0; i < 1000000; i++)
551 25000000 : gcry_md_write (hd, buf, 1);
552 25 : gcry_md_final (hd);
553 25 : stop_timer ();
554 25 : printf (" %s", elapsed_time (1));
555 25 : fflush (stdout);
556 :
557 25 : start_timer ();
558 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
559 25025 : for (i=0; i < 1000; i++)
560 25025000 : for (j=0; j < bufsize; j++)
561 25000000 : gcry_md_putc (hd, buf[j]);
562 25 : gcry_md_final (hd);
563 25 : stop_timer ();
564 25 : printf (" %s", elapsed_time (1));
565 25 : fflush (stdout);
566 :
567 25 : gcry_md_close (hd);
568 :
569 : /* Now 100 hash operations on 10000 bytes using the fast function.
570 : We initialize the buffer so that all memory pages are committed
571 : and we have repeatable values. */
572 25 : if (gcry_md_get_algo_dlen (algo) > sizeof digest)
573 0 : die ("digest buffer too short\n");
574 :
575 25 : largebuf_base = malloc (10000+15);
576 25 : if (!largebuf_base)
577 0 : die ("out of core\n");
578 25 : largebuf = (largebuf_base
579 25 : + ((16 - ((size_t)largebuf_base & 0x0f)) % buffer_alignment));
580 :
581 250025 : for (i=0; i < 10000; i++)
582 250000 : largebuf[i] = i;
583 25 : start_timer ();
584 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
585 2525 : for (i=0; i < 100; i++)
586 2500 : gcry_md_hash_buffer (algo, digest, largebuf, 10000);
587 25 : stop_timer ();
588 25 : printf (" %s", elapsed_time (1));
589 25 : free (largebuf_base);
590 :
591 25 : putchar ('\n');
592 25 : fflush (stdout);
593 : }
594 :
595 :
596 :
597 : static void
598 40 : mac_bench ( const char *algoname )
599 : {
600 : int algo;
601 : gcry_mac_hd_t hd;
602 : int step, pos, j, i, repcount;
603 : char buf_base[1000+15];
604 40 : size_t bufsize = 1000;
605 : char *buf;
606 : char mac[3][512];
607 : char key[512];
608 : unsigned int maclen, keylen;
609 : size_t macoutlen;
610 40 : gcry_error_t err = GPG_ERR_NO_ERROR;
611 :
612 40 : if (!algoname)
613 : {
614 600 : for (i=1; i < 600; i++)
615 599 : if (in_fips_mode && i == GCRY_MAC_HMAC_MD5)
616 : ; /* Don't use MD5 in fips mode. */
617 599 : else if ( !gcry_mac_test_algo (i) )
618 39 : mac_bench (gcry_mac_algo_name (i));
619 41 : return;
620 : }
621 :
622 39 : buf = buf_base + ((16 - ((size_t)buf_base & 0x0f)) % buffer_alignment);
623 :
624 39 : algo = gcry_mac_map_name (algoname);
625 39 : if (!algo)
626 : {
627 0 : fprintf (stderr, PGM ": invalid hash algorithm `%s'\n", algoname);
628 0 : exit (1);
629 : }
630 :
631 39 : maclen = gcry_mac_get_algo_maclen (algo);
632 39 : if (maclen > sizeof(mac))
633 0 : maclen = sizeof(mac);
634 :
635 39 : keylen = gcry_mac_get_algo_keylen (algo);
636 39 : if (keylen == 0)
637 0 : keylen = 32;
638 39 : if (keylen > sizeof(key))
639 0 : keylen = sizeof(key);
640 1727 : for (i=0; i < keylen; i++)
641 1688 : key[i] = (keylen - i) ^ 0x54;
642 :
643 39 : err = gcry_mac_open (&hd, algo, 0, NULL);
644 39 : if (err)
645 : {
646 0 : fprintf (stderr, PGM ": error opening mac algorithm `%s': %s\n", algoname,
647 : gpg_strerror (err));
648 0 : exit (1);
649 : }
650 :
651 39 : err = gcry_mac_setkey (hd, key, keylen);
652 39 : if (err)
653 : {
654 0 : fprintf (stderr, PGM ": error setting key for mac algorithm `%s': %s\n",
655 : algoname, gpg_strerror (err));
656 0 : exit (1);
657 : }
658 :
659 39039 : for (i=0; i < bufsize; i++)
660 39000 : buf[i] = i;
661 :
662 39 : if (algo >= GCRY_MAC_POLY1305_AES && algo <= GCRY_MAC_POLY1305_SEED)
663 : {
664 : static const char iv[16] = { 1, 2, 3, 4, };
665 5 : err = gcry_mac_setiv(hd, iv, sizeof(iv));
666 5 : if (err)
667 : {
668 0 : fprintf (stderr, PGM ": error setting nonce for mac algorithm `%s': %s\n",
669 : algoname, gpg_strerror (err));
670 0 : exit (1);
671 : }
672 : }
673 :
674 39 : printf ("%-20s", gcry_mac_algo_name (algo));
675 :
676 39 : start_timer ();
677 78 : for (repcount=0; repcount < mac_repetitions; repcount++)
678 39039 : for (i=0; i < 1000; i++)
679 39000 : gcry_mac_write (hd, buf, bufsize);
680 39 : macoutlen = maclen;
681 39 : gcry_mac_read (hd, mac[0], &macoutlen);
682 39 : stop_timer ();
683 39 : printf (" %s", elapsed_time (1));
684 39 : fflush (stdout);
685 :
686 39 : gcry_mac_reset (hd);
687 39 : start_timer ();
688 78 : for (repcount=0; repcount < mac_repetitions; repcount++)
689 39039 : for (i=0; i < 1000; i++)
690 429000 : for (step=bufsize/10, pos=0, j=0; j < 10; j++, pos+=step)
691 390000 : gcry_mac_write (hd, &buf[pos], step);
692 39 : macoutlen = maclen;
693 39 : gcry_mac_read (hd, mac[1], &macoutlen);
694 39 : stop_timer ();
695 39 : printf (" %s", elapsed_time (1));
696 39 : fflush (stdout);
697 :
698 39 : gcry_mac_reset (hd);
699 39 : start_timer ();
700 78 : for (repcount=0; repcount < mac_repetitions; repcount++)
701 39039 : for (i=0; i < 1000; i++)
702 3939000 : for (step=bufsize/100, pos=0, j=0; j < 100; j++, pos+=step)
703 3900000 : gcry_mac_write (hd, &buf[pos], step);
704 39 : macoutlen = maclen;
705 39 : gcry_mac_read (hd, mac[2], &macoutlen);
706 39 : stop_timer ();
707 39 : printf (" %s", elapsed_time (1));
708 39 : fflush (stdout);
709 :
710 39 : gcry_mac_close (hd);
711 :
712 117 : for (i=1; i < 3; i++)
713 : {
714 78 : if (memcmp(mac[i-1], mac[i], maclen))
715 : {
716 0 : fprintf (stderr, PGM ": mac mismatch with algorithm `%s'\n",
717 : algoname);
718 0 : exit(1);
719 : }
720 : }
721 :
722 39 : putchar ('\n');
723 39 : fflush (stdout);
724 : }
725 :
726 :
727 : #ifdef HAVE_U64_TYPEDEF
728 24000 : static void ccm_aead_init(gcry_cipher_hd_t hd, size_t buflen, int authlen)
729 : {
730 24000 : const int _L = 4;
731 24000 : const int noncelen = 15 - _L;
732 24000 : char nonce[noncelen];
733 : u64 params[3];
734 24000 : gcry_error_t err = GPG_ERR_NO_ERROR;
735 :
736 24000 : memset (nonce, 0x33, noncelen);
737 :
738 24000 : err = gcry_cipher_setiv (hd, nonce, noncelen);
739 24000 : if (err)
740 : {
741 0 : fprintf (stderr, "gcry_cipher_setiv failed: %s\n",
742 : gpg_strerror (err));
743 0 : gcry_cipher_close (hd);
744 0 : exit (1);
745 : }
746 :
747 24000 : params[0] = buflen; /* encryptedlen */
748 24000 : params[1] = 0; /* aadlen */
749 24000 : params[2] = authlen; /* authtaglen */
750 24000 : err = gcry_cipher_ctl (hd, GCRYCTL_SET_CCM_LENGTHS, params, sizeof(params));
751 24000 : if (err)
752 : {
753 0 : fprintf (stderr, "gcry_cipher_setiv failed: %s\n",
754 : gpg_strerror (err));
755 0 : gcry_cipher_close (hd);
756 0 : exit (1);
757 : }
758 24000 : }
759 : #endif
760 :
761 :
762 : static void
763 25 : cipher_bench ( const char *algoname )
764 : {
765 : static int header_printed;
766 : int algo;
767 : gcry_cipher_hd_t hd;
768 : int i;
769 : int keylen, blklen;
770 : char key[128];
771 : char *outbuf, *buf;
772 : char *raw_outbuf, *raw_buf;
773 : size_t allocated_buflen, buflen;
774 : int repetitions;
775 : static const struct {
776 : int mode;
777 : const char *name;
778 : int blocked;
779 : void (* const aead_init)(gcry_cipher_hd_t hd, size_t buflen, int authlen);
780 : int req_blocksize;
781 : int authlen;
782 : int noncelen;
783 : } modes[] = {
784 : { GCRY_CIPHER_MODE_ECB, " ECB/Stream", 1 },
785 : { GCRY_CIPHER_MODE_CBC, " CBC", 1 },
786 : { GCRY_CIPHER_MODE_CFB, " CFB", 0 },
787 : { GCRY_CIPHER_MODE_OFB, " OFB", 0 },
788 : { GCRY_CIPHER_MODE_CTR, " CTR", 0 },
789 : #ifdef HAVE_U64_TYPEDEF
790 : { GCRY_CIPHER_MODE_CCM, " CCM", 0,
791 : ccm_aead_init, GCRY_CCM_BLOCK_LEN, 8 },
792 : #endif
793 : { GCRY_CIPHER_MODE_GCM, " GCM", 0,
794 : NULL, GCRY_GCM_BLOCK_LEN, GCRY_GCM_BLOCK_LEN },
795 : { GCRY_CIPHER_MODE_OCB, " OCB", 1,
796 : NULL, 16, 16, 15 },
797 : { GCRY_CIPHER_MODE_STREAM, "", 0 },
798 : {0}
799 : };
800 : int modeidx;
801 25 : gcry_error_t err = GPG_ERR_NO_ERROR;
802 :
803 :
804 25 : if (!algoname)
805 : {
806 400 : for (i=1; i < 400; i++)
807 399 : if ( !gcry_cipher_test_algo (i) )
808 24 : cipher_bench (gcry_cipher_algo_name (i));
809 26 : return;
810 : }
811 :
812 24 : if (large_buffers)
813 : {
814 0 : allocated_buflen = 1024 * 100;
815 0 : repetitions = 10;
816 : }
817 : else
818 : {
819 24 : allocated_buflen = 1024;
820 24 : repetitions = 1000;
821 : }
822 24 : repetitions *= cipher_repetitions;
823 :
824 24 : raw_buf = gcry_xcalloc (allocated_buflen+15, 1);
825 24 : buf = (raw_buf
826 24 : + ((16 - ((size_t)raw_buf & 0x0f)) % buffer_alignment));
827 24 : outbuf = raw_outbuf = gcry_xmalloc (allocated_buflen+15);
828 24 : outbuf = (raw_outbuf
829 24 : + ((16 - ((size_t)raw_outbuf & 0x0f)) % buffer_alignment));
830 :
831 24 : if (!header_printed)
832 : {
833 1 : if (cipher_repetitions != 1)
834 0 : printf ("Running each test %d times.\n", cipher_repetitions);
835 1 : printf ("%-12s", "");
836 10 : for (modeidx=0; modes[modeidx].mode; modeidx++)
837 9 : if (*modes[modeidx].name)
838 8 : printf (" %-15s", modes[modeidx].name );
839 1 : putchar ('\n');
840 1 : printf ("%-12s", "");
841 10 : for (modeidx=0; modes[modeidx].mode; modeidx++)
842 9 : if (*modes[modeidx].name)
843 8 : printf (" ---------------" );
844 1 : putchar ('\n');
845 1 : header_printed = 1;
846 : }
847 :
848 24 : algo = gcry_cipher_map_name (algoname);
849 24 : if (!algo)
850 : {
851 0 : fprintf (stderr, PGM ": invalid cipher algorithm `%s'\n", algoname);
852 0 : exit (1);
853 : }
854 :
855 24 : keylen = gcry_cipher_get_algo_keylen (algo);
856 24 : if (!keylen)
857 : {
858 0 : fprintf (stderr, PGM ": failed to get key length for algorithm `%s'\n",
859 : algoname);
860 0 : exit (1);
861 : }
862 24 : if ( keylen > sizeof key )
863 : {
864 0 : fprintf (stderr, PGM ": algo %d, keylength problem (%d)\n",
865 : algo, keylen );
866 0 : exit (1);
867 : }
868 549 : for (i=0; i < keylen; i++)
869 525 : key[i] = i + (clock () & 0xff);
870 :
871 24 : blklen = gcry_cipher_get_algo_blklen (algo);
872 24 : if (!blklen)
873 : {
874 0 : fprintf (stderr, PGM ": failed to get block length for algorithm `%s'\n",
875 : algoname);
876 0 : exit (1);
877 : }
878 :
879 24 : printf ("%-12s", gcry_cipher_algo_name (algo));
880 24 : fflush (stdout);
881 :
882 240 : for (modeidx=0; modes[modeidx].mode; modeidx++)
883 : {
884 216 : if ((blklen > 1 && modes[modeidx].mode == GCRY_CIPHER_MODE_STREAM)
885 196 : || (blklen == 1 && modes[modeidx].mode != GCRY_CIPHER_MODE_STREAM))
886 52 : continue;
887 :
888 164 : if (modes[modeidx].req_blocksize > 0
889 60 : && blklen != modes[modeidx].req_blocksize)
890 : {
891 24 : printf (" %7s %7s", "-", "-" );
892 24 : continue;
893 : }
894 :
895 1260 : for (i=0; i < sizeof buf; i++)
896 1120 : buf[i] = i;
897 :
898 140 : err = gcry_cipher_open (&hd, algo, modes[modeidx].mode, 0);
899 140 : if (err)
900 : {
901 0 : fprintf (stderr, PGM ": error opening cipher `%s'\n", algoname);
902 0 : exit (1);
903 : }
904 :
905 140 : if (!cipher_with_keysetup)
906 : {
907 140 : err = gcry_cipher_setkey (hd, key, keylen);
908 140 : if (err)
909 : {
910 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
911 : gpg_strerror (err));
912 0 : gcry_cipher_close (hd);
913 0 : exit (1);
914 : }
915 : }
916 :
917 140 : buflen = allocated_buflen;
918 140 : if (modes[modeidx].blocked)
919 52 : buflen = (buflen / blklen) * blklen;
920 :
921 140 : start_timer ();
922 140140 : for (i=err=0; !err && i < repetitions; i++)
923 : {
924 140000 : if (cipher_with_keysetup)
925 : {
926 0 : err = gcry_cipher_setkey (hd, key, keylen);
927 0 : if (err)
928 : {
929 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
930 : gpg_strerror (err));
931 0 : gcry_cipher_close (hd);
932 0 : exit (1);
933 : }
934 : }
935 :
936 140000 : if (modes[modeidx].noncelen)
937 : {
938 : char nonce[100];
939 : size_t noncelen;
940 :
941 12000 : noncelen = modes[modeidx].noncelen;
942 12000 : if (noncelen > sizeof nonce)
943 0 : noncelen = sizeof nonce;
944 12000 : memset (nonce, 42, noncelen);
945 12000 : err = gcry_cipher_setiv (hd, nonce, noncelen);
946 12000 : if (err)
947 : {
948 0 : fprintf (stderr, "gcry_cipher_setiv failed: %s\n",
949 : gpg_strerror (err));
950 0 : gcry_cipher_close (hd);
951 0 : exit (1);
952 : }
953 : }
954 :
955 140000 : if (modes[modeidx].aead_init)
956 : {
957 12000 : (*modes[modeidx].aead_init) (hd, buflen, modes[modeidx].authlen);
958 12000 : gcry_cipher_final (hd);
959 12000 : err = gcry_cipher_encrypt (hd, outbuf, buflen, buf, buflen);
960 12000 : if (err)
961 0 : break;
962 12000 : err = gcry_cipher_gettag (hd, outbuf, modes[modeidx].authlen);
963 : }
964 : else
965 : {
966 128000 : err = gcry_cipher_encrypt (hd, outbuf, buflen, buf, buflen);
967 : }
968 : }
969 140 : stop_timer ();
970 :
971 140 : printf (" %s", elapsed_time (1));
972 140 : fflush (stdout);
973 140 : gcry_cipher_close (hd);
974 140 : if (err)
975 : {
976 0 : fprintf (stderr, "gcry_cipher_encrypt failed: %s\n",
977 : gpg_strerror (err) );
978 0 : exit (1);
979 : }
980 :
981 140 : err = gcry_cipher_open (&hd, algo, modes[modeidx].mode, 0);
982 140 : if (err)
983 : {
984 0 : fprintf (stderr, PGM ": error opening cipher `%s'/n", algoname);
985 0 : exit (1);
986 : }
987 :
988 140 : if (!cipher_with_keysetup)
989 : {
990 140 : err = gcry_cipher_setkey (hd, key, keylen);
991 140 : if (err)
992 : {
993 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
994 : gpg_strerror (err));
995 0 : gcry_cipher_close (hd);
996 0 : exit (1);
997 : }
998 : }
999 :
1000 140 : start_timer ();
1001 140140 : for (i=err=0; !err && i < repetitions; i++)
1002 : {
1003 140000 : if (cipher_with_keysetup)
1004 : {
1005 0 : err = gcry_cipher_setkey (hd, key, keylen);
1006 0 : if (err)
1007 : {
1008 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
1009 : gpg_strerror (err));
1010 0 : gcry_cipher_close (hd);
1011 0 : exit (1);
1012 : }
1013 : }
1014 :
1015 140000 : if (modes[modeidx].noncelen)
1016 : {
1017 : char nonce[100];
1018 : size_t noncelen;
1019 :
1020 12000 : noncelen = modes[modeidx].noncelen;
1021 12000 : if (noncelen > sizeof nonce)
1022 0 : noncelen = sizeof nonce;
1023 12000 : memset (nonce, 42, noncelen);
1024 12000 : err = gcry_cipher_setiv (hd, nonce, noncelen);
1025 12000 : if (err)
1026 : {
1027 0 : fprintf (stderr, "gcry_cipher_setiv failed: %s\n",
1028 : gpg_strerror (err));
1029 0 : gcry_cipher_close (hd);
1030 0 : exit (1);
1031 : }
1032 : }
1033 :
1034 140000 : if (modes[modeidx].aead_init)
1035 : {
1036 12000 : (*modes[modeidx].aead_init) (hd, buflen, modes[modeidx].authlen);
1037 12000 : gcry_cipher_final (hd);
1038 12000 : err = gcry_cipher_decrypt (hd, outbuf, buflen, buf, buflen);
1039 12000 : if (err)
1040 0 : break;
1041 12000 : err = gcry_cipher_checktag (hd, outbuf, modes[modeidx].authlen);
1042 12000 : if (gpg_err_code (err) == GPG_ERR_CHECKSUM)
1043 12000 : err = 0;
1044 : }
1045 : else
1046 : {
1047 128000 : gcry_cipher_final (hd);
1048 128000 : err = gcry_cipher_decrypt (hd, outbuf, buflen, buf, buflen);
1049 : }
1050 : }
1051 140 : stop_timer ();
1052 140 : printf (" %s", elapsed_time (1));
1053 140 : fflush (stdout);
1054 140 : gcry_cipher_close (hd);
1055 140 : if (err)
1056 : {
1057 0 : fprintf (stderr, "gcry_cipher_decrypt failed: %s\n",
1058 : gpg_strerror (err) );
1059 0 : exit (1);
1060 : }
1061 : }
1062 :
1063 24 : putchar ('\n');
1064 24 : gcry_free (raw_buf);
1065 24 : gcry_free (raw_outbuf);
1066 : }
1067 :
1068 :
1069 :
1070 : static void
1071 1 : rsa_bench (int iterations, int print_header, int no_blinding)
1072 : {
1073 : gpg_error_t err;
1074 1 : int p_sizes[] = { 1024, 2048, 3072, 4096 };
1075 : int testno;
1076 :
1077 1 : if (print_header)
1078 1 : printf ("Algorithm generate %4d*priv %4d*public\n"
1079 : "------------------------------------------------\n",
1080 : iterations, iterations );
1081 5 : for (testno=0; testno < DIM (p_sizes); testno++)
1082 : {
1083 : gcry_sexp_t key_spec, key_pair, pub_key, sec_key;
1084 : gcry_mpi_t x;
1085 : gcry_sexp_t data;
1086 4 : gcry_sexp_t sig = NULL;
1087 : int count;
1088 :
1089 4 : printf ("RSA %3d bit ", p_sizes[testno]);
1090 4 : fflush (stdout);
1091 :
1092 8 : err = gcry_sexp_build (&key_spec, NULL,
1093 4 : gcry_fips_mode_active ()
1094 : ? "(genkey (RSA (nbits %d)))"
1095 : : "(genkey (RSA (nbits %d)(transient-key)))",
1096 : p_sizes[testno]);
1097 4 : if (err)
1098 0 : die ("creating S-expression failed: %s\n", gcry_strerror (err));
1099 :
1100 4 : start_timer ();
1101 4 : err = gcry_pk_genkey (&key_pair, key_spec);
1102 4 : if (err)
1103 0 : die ("creating %d bit RSA key failed: %s\n",
1104 : p_sizes[testno], gcry_strerror (err));
1105 :
1106 4 : pub_key = gcry_sexp_find_token (key_pair, "public-key", 0);
1107 4 : if (! pub_key)
1108 0 : die ("public part missing in key\n");
1109 4 : sec_key = gcry_sexp_find_token (key_pair, "private-key", 0);
1110 4 : if (! sec_key)
1111 0 : die ("private part missing in key\n");
1112 4 : gcry_sexp_release (key_pair);
1113 4 : gcry_sexp_release (key_spec);
1114 :
1115 4 : stop_timer ();
1116 4 : printf (" %s", elapsed_time (1));
1117 4 : fflush (stdout);
1118 :
1119 4 : x = gcry_mpi_new (p_sizes[testno]);
1120 4 : gcry_mpi_randomize (x, p_sizes[testno]-8, GCRY_WEAK_RANDOM);
1121 4 : err = gcry_sexp_build (&data, NULL,
1122 : "(data (flags raw) (value %m))", x);
1123 4 : gcry_mpi_release (x);
1124 4 : if (err)
1125 0 : die ("converting data failed: %s\n", gcry_strerror (err));
1126 :
1127 4 : start_timer ();
1128 44 : for (count=0; count < iterations; count++)
1129 : {
1130 40 : gcry_sexp_release (sig);
1131 40 : err = gcry_pk_sign (&sig, data, sec_key);
1132 40 : if (err)
1133 0 : die ("signing failed (%d): %s\n", count, gpg_strerror (err));
1134 : }
1135 4 : stop_timer ();
1136 4 : printf (" %s", elapsed_time (1));
1137 4 : fflush (stdout);
1138 :
1139 4 : start_timer ();
1140 44 : for (count=0; count < iterations; count++)
1141 : {
1142 40 : err = gcry_pk_verify (sig, data, pub_key);
1143 40 : if (err)
1144 : {
1145 0 : putchar ('\n');
1146 0 : show_sexp ("seckey:\n", sec_key);
1147 0 : show_sexp ("data:\n", data);
1148 0 : show_sexp ("sig:\n", sig);
1149 0 : die ("verify failed (%d): %s\n", count, gpg_strerror (err));
1150 : }
1151 : }
1152 4 : stop_timer ();
1153 4 : printf (" %s", elapsed_time (1));
1154 :
1155 4 : if (no_blinding)
1156 : {
1157 0 : fflush (stdout);
1158 0 : x = gcry_mpi_new (p_sizes[testno]);
1159 0 : gcry_mpi_randomize (x, p_sizes[testno]-8, GCRY_WEAK_RANDOM);
1160 0 : err = gcry_sexp_build (&data, NULL,
1161 : "(data (flags no-blinding) (value %m))", x);
1162 0 : gcry_mpi_release (x);
1163 0 : if (err)
1164 0 : die ("converting data failed: %s\n", gcry_strerror (err));
1165 :
1166 0 : start_timer ();
1167 0 : for (count=0; count < iterations; count++)
1168 : {
1169 0 : gcry_sexp_release (sig);
1170 0 : err = gcry_pk_sign (&sig, data, sec_key);
1171 0 : if (err)
1172 0 : die ("signing failed (%d): %s\n", count, gpg_strerror (err));
1173 : }
1174 0 : stop_timer ();
1175 0 : printf (" %s", elapsed_time (1));
1176 0 : fflush (stdout);
1177 : }
1178 :
1179 4 : putchar ('\n');
1180 4 : fflush (stdout);
1181 :
1182 4 : gcry_sexp_release (sig);
1183 4 : gcry_sexp_release (data);
1184 4 : gcry_sexp_release (sec_key);
1185 4 : gcry_sexp_release (pub_key);
1186 : }
1187 1 : }
1188 :
1189 :
1190 : static void
1191 1 : elg_bench (int iterations, int print_header)
1192 : {
1193 : gpg_error_t err;
1194 : gcry_sexp_t pub_key[3], sec_key[3];
1195 1 : int p_sizes[3] = { 1024, 2048, 3072 };
1196 1 : gcry_sexp_t data = NULL;
1197 1 : gcry_sexp_t enc = NULL;
1198 1 : gcry_sexp_t plain = NULL;
1199 : int i, j;
1200 :
1201 1 : err = gcry_sexp_sscan (pub_key+0, NULL, sample_public_elg_key_1024,
1202 : strlen (sample_public_elg_key_1024));
1203 1 : if (!err)
1204 1 : err = gcry_sexp_sscan (sec_key+0, NULL, sample_private_elg_key_1024,
1205 : strlen (sample_private_elg_key_1024));
1206 1 : if (!err)
1207 1 : err = gcry_sexp_sscan (pub_key+1, NULL, sample_public_elg_key_2048,
1208 : strlen (sample_public_elg_key_2048));
1209 1 : if (!err)
1210 1 : err = gcry_sexp_sscan (sec_key+1, NULL, sample_private_elg_key_2048,
1211 : strlen (sample_private_elg_key_2048));
1212 1 : if (!err)
1213 1 : err = gcry_sexp_sscan (pub_key+2, NULL, sample_public_elg_key_3072,
1214 : strlen (sample_public_elg_key_3072));
1215 1 : if (!err)
1216 1 : err = gcry_sexp_sscan (sec_key+2, NULL, sample_private_elg_key_3072,
1217 : strlen (sample_private_elg_key_3072));
1218 1 : if (err)
1219 : {
1220 0 : fprintf (stderr, PGM ": converting sample keys failed: %s\n",
1221 : gcry_strerror (err));
1222 0 : exit (1);
1223 : }
1224 :
1225 1 : if (print_header)
1226 0 : printf ("Algorithm generate %4d*priv %4d*public\n"
1227 : "------------------------------------------------\n",
1228 : iterations, iterations );
1229 4 : for (i=0; i < DIM (p_sizes); i++)
1230 : {
1231 : char timerbuf1[100];
1232 :
1233 : {
1234 3 : gcry_mpi_t x = gcry_mpi_new (p_sizes[i]);
1235 3 : gcry_mpi_randomize (x, p_sizes[i] - 16, GCRY_WEAK_RANDOM);
1236 3 : err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
1237 3 : gcry_mpi_release (x);
1238 : }
1239 3 : if (err)
1240 : {
1241 0 : fprintf (stderr, PGM ": converting data failed: %s\n",
1242 : gcry_strerror (err));
1243 0 : exit (1);
1244 : }
1245 :
1246 3 : printf ("ELG %d bit -", p_sizes[i]);
1247 3 : fflush (stdout);
1248 :
1249 3 : start_timer ();
1250 33 : for (j=0; j < iterations; j++)
1251 : {
1252 30 : gcry_sexp_release (enc);
1253 30 : err = gcry_pk_encrypt (&enc, data, pub_key[i]);
1254 30 : if (err)
1255 : {
1256 0 : putchar ('\n');
1257 0 : fprintf (stderr, PGM ": encrypt failed: %s\n",
1258 : gpg_strerror (err));
1259 0 : exit (1);
1260 : }
1261 : }
1262 3 : stop_timer ();
1263 3 : snprintf (timerbuf1, sizeof timerbuf1, " %s", elapsed_time (1));
1264 3 : fflush (stdout);
1265 :
1266 3 : start_timer ();
1267 33 : for (j=0; j < iterations; j++)
1268 : {
1269 30 : gcry_sexp_release (plain);
1270 30 : err = gcry_pk_decrypt (&plain, enc, sec_key[i]);
1271 30 : if (err)
1272 : {
1273 0 : putchar ('\n');
1274 0 : fprintf (stderr, PGM ": decrypt failed: %s\n",
1275 : gpg_strerror (err));
1276 0 : exit (1);
1277 : }
1278 : }
1279 3 : stop_timer ();
1280 :
1281 3 : printf (" %s %s\n", elapsed_time (1), timerbuf1);
1282 3 : fflush (stdout);
1283 :
1284 3 : gcry_sexp_release (plain);
1285 3 : plain = NULL;
1286 3 : gcry_sexp_release (enc);
1287 3 : enc = NULL;
1288 3 : gcry_sexp_release (data);
1289 3 : data = NULL;
1290 : }
1291 :
1292 4 : for (i=0; i < DIM (p_sizes); i++)
1293 : {
1294 3 : gcry_sexp_release (sec_key[i]);
1295 3 : gcry_sexp_release (pub_key[i]);
1296 : }
1297 1 : }
1298 :
1299 :
1300 : static void
1301 1 : dsa_bench (int iterations, int print_header)
1302 : {
1303 : gpg_error_t err;
1304 : gcry_sexp_t pub_key[3], sec_key[3];
1305 1 : int p_sizes[3] = { 1024, 2048, 3072 };
1306 1 : int q_sizes[3] = { 160, 224, 256 };
1307 : gcry_sexp_t data;
1308 1 : gcry_sexp_t sig = NULL;
1309 : int i, j;
1310 :
1311 1 : err = gcry_sexp_sscan (pub_key+0, NULL, sample_public_dsa_key_1024,
1312 : strlen (sample_public_dsa_key_1024));
1313 1 : if (!err)
1314 1 : err = gcry_sexp_sscan (sec_key+0, NULL, sample_private_dsa_key_1024,
1315 : strlen (sample_private_dsa_key_1024));
1316 1 : if (!err)
1317 1 : err = gcry_sexp_sscan (pub_key+1, NULL, sample_public_dsa_key_2048,
1318 : strlen (sample_public_dsa_key_2048));
1319 1 : if (!err)
1320 1 : err = gcry_sexp_sscan (sec_key+1, NULL, sample_private_dsa_key_2048,
1321 : strlen (sample_private_dsa_key_2048));
1322 1 : if (!err)
1323 1 : err = gcry_sexp_sscan (pub_key+2, NULL, sample_public_dsa_key_3072,
1324 : strlen (sample_public_dsa_key_3072));
1325 1 : if (!err)
1326 1 : err = gcry_sexp_sscan (sec_key+2, NULL, sample_private_dsa_key_3072,
1327 : strlen (sample_private_dsa_key_3072));
1328 1 : if (err)
1329 : {
1330 0 : fprintf (stderr, PGM ": converting sample keys failed: %s\n",
1331 : gcry_strerror (err));
1332 0 : exit (1);
1333 : }
1334 :
1335 1 : if (print_header)
1336 0 : printf ("Algorithm generate %4d*priv %4d*public\n"
1337 : "------------------------------------------------\n",
1338 : iterations, iterations );
1339 4 : for (i=0; i < DIM (q_sizes); i++)
1340 : {
1341 : gcry_mpi_t x;
1342 :
1343 3 : x = gcry_mpi_new (q_sizes[i]);
1344 3 : gcry_mpi_randomize (x, q_sizes[i], GCRY_WEAK_RANDOM);
1345 3 : err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
1346 3 : gcry_mpi_release (x);
1347 3 : if (err)
1348 : {
1349 0 : fprintf (stderr, PGM ": converting data failed: %s\n",
1350 : gcry_strerror (err));
1351 0 : exit (1);
1352 : }
1353 :
1354 3 : printf ("DSA %d/%d -", p_sizes[i], q_sizes[i]);
1355 3 : fflush (stdout);
1356 :
1357 3 : start_timer ();
1358 33 : for (j=0; j < iterations; j++)
1359 : {
1360 30 : gcry_sexp_release (sig);
1361 30 : err = gcry_pk_sign (&sig, data, sec_key[i]);
1362 30 : if (err)
1363 : {
1364 0 : putchar ('\n');
1365 0 : fprintf (stderr, PGM ": signing failed: %s\n",
1366 : gpg_strerror (err));
1367 0 : exit (1);
1368 : }
1369 : }
1370 3 : stop_timer ();
1371 3 : printf (" %s", elapsed_time (1));
1372 3 : fflush (stdout);
1373 :
1374 3 : start_timer ();
1375 33 : for (j=0; j < iterations; j++)
1376 : {
1377 30 : err = gcry_pk_verify (sig, data, pub_key[i]);
1378 30 : if (err)
1379 : {
1380 0 : putchar ('\n');
1381 0 : fprintf (stderr, PGM ": verify failed: %s\n",
1382 : gpg_strerror (err));
1383 0 : exit (1);
1384 : }
1385 : }
1386 3 : stop_timer ();
1387 3 : printf (" %s\n", elapsed_time (1));
1388 3 : fflush (stdout);
1389 :
1390 3 : gcry_sexp_release (sig);
1391 3 : gcry_sexp_release (data);
1392 3 : sig = NULL;
1393 : }
1394 :
1395 :
1396 4 : for (i=0; i < DIM (q_sizes); i++)
1397 : {
1398 3 : gcry_sexp_release (sec_key[i]);
1399 3 : gcry_sexp_release (pub_key[i]);
1400 : }
1401 1 : }
1402 :
1403 :
1404 : static void
1405 1 : ecc_bench (int iterations, int print_header)
1406 : {
1407 : #if USE_ECC
1408 : gpg_error_t err;
1409 1 : const char *p_sizes[] = { "192", "224", "256", "384", "521", "Ed25519",
1410 : "gost256", "gost512" };
1411 : int testno;
1412 :
1413 1 : if (print_header)
1414 0 : printf ("Algorithm generate %4d*priv %4d*public\n"
1415 : "------------------------------------------------\n",
1416 : iterations, iterations );
1417 9 : for (testno=0; testno < DIM (p_sizes); testno++)
1418 : {
1419 : gcry_sexp_t key_spec, key_pair, pub_key, sec_key;
1420 : gcry_mpi_t x;
1421 : gcry_sexp_t data;
1422 8 : gcry_sexp_t sig = NULL;
1423 : int count;
1424 : int p_size;
1425 : int is_ed25519;
1426 : int is_gost;
1427 :
1428 8 : is_ed25519 = !strcmp (p_sizes[testno], "Ed25519");
1429 8 : is_gost = !strncmp (p_sizes[testno], "gost", 4);
1430 8 : if (is_ed25519)
1431 : {
1432 1 : p_size = 256;
1433 1 : printf ("EdDSA Ed25519 ");
1434 1 : fflush (stdout);
1435 : }
1436 7 : else if (is_gost)
1437 : {
1438 2 : p_size = atoi (p_sizes[testno] + 4);
1439 2 : printf ("GOST %3d bit ", p_size);
1440 2 : fflush (stdout);
1441 : }
1442 : else
1443 : {
1444 5 : p_size = atoi (p_sizes[testno]);
1445 5 : printf ("ECDSA %3d bit ", p_size);
1446 : }
1447 8 : fflush (stdout);
1448 :
1449 8 : if (is_ed25519)
1450 1 : err = gcry_sexp_build (&key_spec, NULL,
1451 : "(genkey (ecdsa (curve \"Ed25519\")"
1452 : "(flags eddsa)))");
1453 7 : else if (is_gost)
1454 2 : err = gcry_sexp_build (&key_spec, NULL,
1455 : "(genkey (ecdsa (curve %s)))",
1456 : p_size == 256 ? "GOST2001-test" : "GOST2012-test");
1457 : else
1458 5 : err = gcry_sexp_build (&key_spec, NULL,
1459 : "(genkey (ECDSA (nbits %d)))", p_size);
1460 8 : if (err)
1461 0 : die ("creating S-expression failed: %s\n", gcry_strerror (err));
1462 :
1463 8 : start_timer ();
1464 8 : err = gcry_pk_genkey (&key_pair, key_spec);
1465 8 : if (err)
1466 0 : die ("creating %d bit ECC key failed: %s\n",
1467 : p_size, gcry_strerror (err));
1468 8 : if (verbose > 2)
1469 0 : show_sexp ("ECC key:\n", key_pair);
1470 :
1471 8 : pub_key = gcry_sexp_find_token (key_pair, "public-key", 0);
1472 8 : if (! pub_key)
1473 0 : die ("public part missing in key\n");
1474 8 : sec_key = gcry_sexp_find_token (key_pair, "private-key", 0);
1475 8 : if (! sec_key)
1476 0 : die ("private part missing in key\n");
1477 8 : gcry_sexp_release (key_pair);
1478 8 : gcry_sexp_release (key_spec);
1479 :
1480 8 : stop_timer ();
1481 8 : printf (" %s", elapsed_time (1));
1482 8 : fflush (stdout);
1483 :
1484 8 : x = gcry_mpi_new (p_size);
1485 8 : gcry_mpi_randomize (x, p_size, GCRY_WEAK_RANDOM);
1486 8 : if (is_ed25519)
1487 1 : err = gcry_sexp_build (&data, NULL,
1488 : "(data (flags eddsa)(hash-algo sha512)"
1489 : " (value %m))", x);
1490 7 : else if (is_gost)
1491 2 : err = gcry_sexp_build (&data, NULL, "(data (flags gost) (value %m))", x);
1492 : else
1493 5 : err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
1494 8 : gcry_mpi_release (x);
1495 :
1496 8 : if (err)
1497 0 : die ("converting data failed: %s\n", gcry_strerror (err));
1498 :
1499 8 : start_timer ();
1500 88 : for (count=0; count < iterations; count++)
1501 : {
1502 80 : gcry_sexp_release (sig);
1503 80 : err = gcry_pk_sign (&sig, data, sec_key);
1504 80 : if (err)
1505 : {
1506 0 : if (verbose)
1507 : {
1508 0 : putc ('\n', stderr);
1509 0 : show_sexp ("signing key:\n", sec_key);
1510 0 : show_sexp ("signed data:\n", data);
1511 : }
1512 0 : die ("signing failed: %s\n", gpg_strerror (err));
1513 : }
1514 : }
1515 8 : stop_timer ();
1516 8 : printf (" %s", elapsed_time (1));
1517 8 : fflush (stdout);
1518 :
1519 8 : start_timer ();
1520 88 : for (count=0; count < iterations; count++)
1521 : {
1522 80 : err = gcry_pk_verify (sig, data, pub_key);
1523 80 : if (err)
1524 : {
1525 0 : putchar ('\n');
1526 0 : show_sexp ("seckey:\n", sec_key);
1527 0 : show_sexp ("data:\n", data);
1528 0 : show_sexp ("sig:\n", sig);
1529 0 : die ("verify failed: %s\n", gpg_strerror (err));
1530 : }
1531 : }
1532 8 : stop_timer ();
1533 8 : printf (" %s\n", elapsed_time (1));
1534 8 : fflush (stdout);
1535 :
1536 8 : gcry_sexp_release (sig);
1537 8 : gcry_sexp_release (data);
1538 8 : gcry_sexp_release (sec_key);
1539 8 : gcry_sexp_release (pub_key);
1540 : }
1541 : #endif /*USE_ECC*/
1542 1 : }
1543 :
1544 :
1545 :
1546 : static void
1547 3 : do_powm ( const char *n_str, const char *e_str, const char *m_str)
1548 : {
1549 : gcry_mpi_t e, n, msg, cip;
1550 : gcry_error_t err;
1551 : int i;
1552 :
1553 3 : err = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX, n_str, 0, 0);
1554 3 : if (err) BUG ();
1555 3 : err = gcry_mpi_scan (&e, GCRYMPI_FMT_HEX, e_str, 0, 0);
1556 3 : if (err) BUG ();
1557 3 : err = gcry_mpi_scan (&msg, GCRYMPI_FMT_HEX, m_str, 0, 0);
1558 3 : if (err) BUG ();
1559 :
1560 3 : cip = gcry_mpi_new (0);
1561 :
1562 3 : start_timer ();
1563 3003 : for (i=0; i < 1000; i++)
1564 3000 : gcry_mpi_powm (cip, msg, e, n);
1565 3 : stop_timer ();
1566 3 : printf (" %s", elapsed_time (1)); fflush (stdout);
1567 : /* { */
1568 : /* char *buf; */
1569 :
1570 : /* if (gcry_mpi_aprint (GCRYMPI_FMT_HEX, (void**)&buf, NULL, cip)) */
1571 : /* BUG (); */
1572 : /* printf ("result: %s\n", buf); */
1573 : /* gcry_free (buf); */
1574 : /* } */
1575 3 : gcry_mpi_release (cip);
1576 3 : gcry_mpi_release (msg);
1577 3 : gcry_mpi_release (n);
1578 3 : gcry_mpi_release (e);
1579 3 : }
1580 :
1581 :
1582 : static void
1583 1 : mpi_bench (void)
1584 : {
1585 1 : printf ("%-10s", "powm"); fflush (stdout);
1586 :
1587 1 : do_powm (
1588 : "20A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E4",
1589 : "29",
1590 : "B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8"
1591 : );
1592 1 : do_powm (
1593 : "20A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E41071F0246879A442658FBD18C1771571E7073EEEB2160BA0CBFB3404D627069A6CFBD53867AD2D9D40231648000787B5C84176B4336144644AE71A403CA40716",
1594 : "29",
1595 : "B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8FC4EE4BB446B83E48ABED7DB81CBF5E81DE4759E8D68AC985846D999F96B0D8A80E5C69D272C766AB8A23B40D50A4FA889FBC2BD2624222D8EB297F4BAEF8593847"
1596 : );
1597 1 : do_powm (
1598 : "20A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E41071F0246879A442658FBD18C1771571E7073EEEB2160BA0CBFB3404D627069A6CFBD53867AD2D9D40231648000787B5C84176B4336144644AE71A403CA4071620A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E41071F0246879A442658FBD18C1771571E7073EEEB2160BA0CBFB3404D627069A6CFBD53867AD2D9D40231648000787B5C84176B4336144644AE71A403CA40716",
1599 : "29",
1600 : "B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8FC4EE4BB446B83E48ABED7DB81CBF5E81DE4759E8D68AC985846D999F96B0D8A80E5C69D272C766AB8A23B40D50A4FA889FBC2BD2624222D8EB297F4BAEF8593847B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8FC4EE4BB446B83E48ABED7DB81CBF5E81DE4759E8D68AC985846D999F96B0D8A80E5C69D272C766AB8A23B40D50A4FA889FBC2BD2624222D8EB297F4BAEF8593847"
1601 : );
1602 :
1603 1 : putchar ('\n');
1604 :
1605 :
1606 1 : }
1607 :
1608 :
1609 : static void
1610 0 : prime_bench (void)
1611 : {
1612 : gpg_error_t err;
1613 : int i;
1614 : gcry_mpi_t prime;
1615 0 : int old_prog = single_char_progress;
1616 :
1617 0 : single_char_progress = 1;
1618 0 : if (!with_progress)
1619 0 : printf ("%-10s", "prime");
1620 0 : fflush (stdout);
1621 0 : start_timer ();
1622 0 : for (i=0; i < 10; i++)
1623 : {
1624 0 : if (with_progress)
1625 0 : fputs ("primegen ", stdout);
1626 0 : err = gcry_prime_generate (&prime,
1627 : 1024, 0,
1628 : NULL,
1629 : NULL, NULL,
1630 : GCRY_WEAK_RANDOM,
1631 : GCRY_PRIME_FLAG_SECRET);
1632 0 : if (with_progress)
1633 : {
1634 0 : fputc ('\n', stdout);
1635 0 : fflush (stdout);
1636 : }
1637 0 : if (err)
1638 : {
1639 0 : fprintf (stderr, PGM ": error creating prime: %s\n",
1640 : gpg_strerror (err));
1641 0 : exit (1);
1642 : }
1643 0 : gcry_mpi_release (prime);
1644 : }
1645 0 : stop_timer ();
1646 0 : if (with_progress)
1647 0 : printf ("%-10s", "prime");
1648 0 : printf (" %s\n", elapsed_time (1)); fflush (stdout);
1649 :
1650 0 : single_char_progress = old_prog;
1651 0 : }
1652 :
1653 :
1654 : int
1655 1 : main( int argc, char **argv )
1656 : {
1657 1 : int last_argc = -1;
1658 1 : int no_blinding = 0;
1659 1 : int use_random_daemon = 0;
1660 1 : int use_secmem = 0;
1661 1 : int debug = 0;
1662 1 : int pk_count = 100;
1663 :
1664 1 : buffer_alignment = 1;
1665 :
1666 1 : if (argc)
1667 1 : { argc--; argv++; }
1668 :
1669 : /* We skip this test if we are running under the test suite (no args
1670 : and srcdir defined) and GCRYPT_NO_BENCHMARKS is set. */
1671 1 : if (!argc && getenv ("srcdir") && getenv ("GCRYPT_NO_BENCHMARKS"))
1672 0 : exit (77);
1673 :
1674 1 : if (getenv ("GCRYPT_IN_REGRESSION_TEST"))
1675 : {
1676 1 : in_regression_test = 1;
1677 1 : pk_count = 10;
1678 : }
1679 :
1680 2 : while (argc && last_argc != argc )
1681 : {
1682 0 : last_argc = argc;
1683 0 : if (!strcmp (*argv, "--"))
1684 : {
1685 0 : argc--; argv++;
1686 0 : break;
1687 : }
1688 0 : else if (!strcmp (*argv, "--help"))
1689 : {
1690 0 : fputs ("usage: benchmark "
1691 : "[md|mac|cipher|random|mpi|rsa|dsa|ecc|prime [algonames]]\n",
1692 : stdout);
1693 0 : exit (0);
1694 : }
1695 0 : else if (!strcmp (*argv, "--verbose"))
1696 : {
1697 0 : verbose++;
1698 0 : argc--; argv++;
1699 : }
1700 0 : else if (!strcmp (*argv, "--debug"))
1701 : {
1702 0 : verbose += 2;
1703 0 : debug++;
1704 0 : argc--; argv++;
1705 : }
1706 0 : else if (!strcmp (*argv, "--use-random-daemon"))
1707 : {
1708 0 : use_random_daemon = 1;
1709 0 : argc--; argv++;
1710 : }
1711 0 : else if (!strcmp (*argv, "--use-secmem"))
1712 : {
1713 0 : use_secmem = 1;
1714 0 : argc--; argv++;
1715 : }
1716 0 : else if (!strcmp (*argv, "--prefer-standard-rng"))
1717 : {
1718 : /* This is anyway the default, but we may want to use it for
1719 : debugging. */
1720 0 : gcry_control (GCRYCTL_SET_PREFERRED_RNG_TYPE, GCRY_RNG_TYPE_STANDARD);
1721 0 : argc--; argv++;
1722 : }
1723 0 : else if (!strcmp (*argv, "--prefer-fips-rng"))
1724 : {
1725 0 : gcry_control (GCRYCTL_SET_PREFERRED_RNG_TYPE, GCRY_RNG_TYPE_FIPS);
1726 0 : argc--; argv++;
1727 : }
1728 0 : else if (!strcmp (*argv, "--prefer-system-rng"))
1729 : {
1730 0 : gcry_control (GCRYCTL_SET_PREFERRED_RNG_TYPE, GCRY_RNG_TYPE_SYSTEM);
1731 0 : argc--; argv++;
1732 : }
1733 0 : else if (!strcmp (*argv, "--no-blinding"))
1734 : {
1735 0 : no_blinding = 1;
1736 0 : argc--; argv++;
1737 : }
1738 0 : else if (!strcmp (*argv, "--large-buffers"))
1739 : {
1740 0 : large_buffers = 1;
1741 0 : argc--; argv++;
1742 : }
1743 0 : else if (!strcmp (*argv, "--cipher-repetitions"))
1744 : {
1745 0 : argc--; argv++;
1746 0 : if (argc)
1747 : {
1748 0 : cipher_repetitions = atoi(*argv);
1749 0 : argc--; argv++;
1750 : }
1751 : }
1752 0 : else if (!strcmp (*argv, "--cipher-with-keysetup"))
1753 : {
1754 0 : cipher_with_keysetup = 1;
1755 0 : argc--; argv++;
1756 : }
1757 0 : else if (!strcmp (*argv, "--hash-repetitions"))
1758 : {
1759 0 : argc--; argv++;
1760 0 : if (argc)
1761 : {
1762 0 : hash_repetitions = atoi(*argv);
1763 0 : argc--; argv++;
1764 : }
1765 : }
1766 0 : else if (!strcmp (*argv, "--mac-repetitions"))
1767 : {
1768 0 : argc--; argv++;
1769 0 : if (argc)
1770 : {
1771 0 : mac_repetitions = atoi(*argv);
1772 0 : argc--; argv++;
1773 : }
1774 : }
1775 0 : else if (!strcmp (*argv, "--pk-count"))
1776 : {
1777 0 : argc--; argv++;
1778 0 : if (argc)
1779 : {
1780 0 : pk_count = atoi(*argv);
1781 0 : argc--; argv++;
1782 : }
1783 : }
1784 0 : else if (!strcmp (*argv, "--alignment"))
1785 : {
1786 0 : argc--; argv++;
1787 0 : if (argc)
1788 : {
1789 0 : buffer_alignment = atoi(*argv);
1790 0 : argc--; argv++;
1791 : }
1792 : }
1793 0 : else if (!strcmp (*argv, "--disable-hwf"))
1794 : {
1795 0 : argc--; argv++;
1796 0 : if (argc)
1797 : {
1798 0 : if (gcry_control (GCRYCTL_DISABLE_HWF, *argv, NULL))
1799 0 : fprintf (stderr, PGM ": unknown hardware feature `%s'"
1800 : " - option ignored\n", *argv);
1801 0 : argc--; argv++;
1802 : }
1803 : }
1804 0 : else if (!strcmp (*argv, "--fips"))
1805 : {
1806 0 : argc--; argv++;
1807 : /* This command needs to be called before gcry_check_version. */
1808 0 : gcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
1809 : }
1810 0 : else if (!strcmp (*argv, "--progress"))
1811 : {
1812 0 : argc--; argv++;
1813 0 : with_progress = 1;
1814 : }
1815 : }
1816 :
1817 1 : if (buffer_alignment < 1 || buffer_alignment > 16)
1818 0 : die ("value for --alignment must be in the range 1 to 16\n");
1819 :
1820 1 : gcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose);
1821 :
1822 1 : if (!gcry_check_version (GCRYPT_VERSION))
1823 : {
1824 0 : fprintf (stderr, PGM ": version mismatch; pgm=%s, library=%s\n",
1825 : GCRYPT_VERSION, gcry_check_version (NULL));
1826 0 : exit (1);
1827 : }
1828 :
1829 1 : if (debug)
1830 0 : gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
1831 :
1832 1 : if (gcry_fips_mode_active ())
1833 0 : in_fips_mode = 1;
1834 1 : else if (!use_secmem)
1835 1 : gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
1836 :
1837 1 : if (use_random_daemon)
1838 0 : gcry_control (GCRYCTL_USE_RANDOM_DAEMON, 1);
1839 :
1840 1 : if (with_progress)
1841 0 : gcry_set_progress_handler (progress_cb, NULL);
1842 :
1843 1 : gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
1844 :
1845 1 : if (cipher_repetitions < 1)
1846 1 : cipher_repetitions = 1;
1847 1 : if (hash_repetitions < 1)
1848 1 : hash_repetitions = 1;
1849 1 : if (mac_repetitions < 1)
1850 1 : mac_repetitions = 1;
1851 :
1852 1 : if (in_regression_test)
1853 1 : fputs ("Note: " PGM " running in quick regression test mode.\n", stdout);
1854 :
1855 1 : if ( !argc )
1856 : {
1857 1 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1858 1 : md_bench (NULL);
1859 1 : putchar ('\n');
1860 1 : mac_bench (NULL);
1861 1 : putchar ('\n');
1862 1 : cipher_bench (NULL);
1863 1 : putchar ('\n');
1864 1 : rsa_bench (pk_count, 1, no_blinding);
1865 1 : elg_bench (pk_count, 0);
1866 1 : dsa_bench (pk_count, 0);
1867 1 : ecc_bench (pk_count, 0);
1868 1 : putchar ('\n');
1869 1 : mpi_bench ();
1870 1 : putchar ('\n');
1871 1 : random_bench (0);
1872 : }
1873 0 : else if ( !strcmp (*argv, "random") || !strcmp (*argv, "strongrandom"))
1874 : {
1875 0 : if (argc == 1)
1876 0 : random_bench ((**argv == 's'));
1877 0 : else if (argc == 2)
1878 : {
1879 0 : gcry_control (GCRYCTL_SET_RANDOM_SEED_FILE, argv[1]);
1880 0 : random_bench ((**argv == 's'));
1881 0 : gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE);
1882 : }
1883 : else
1884 0 : fputs ("usage: benchmark [strong]random [seedfile]\n", stdout);
1885 : }
1886 0 : else if ( !strcmp (*argv, "md"))
1887 : {
1888 0 : if (argc == 1)
1889 0 : md_bench (NULL);
1890 : else
1891 0 : for (argc--, argv++; argc; argc--, argv++)
1892 0 : md_bench ( *argv );
1893 : }
1894 0 : else if ( !strcmp (*argv, "mac"))
1895 : {
1896 0 : if (argc == 1)
1897 0 : mac_bench (NULL);
1898 : else
1899 0 : for (argc--, argv++; argc; argc--, argv++)
1900 0 : mac_bench ( *argv );
1901 : }
1902 0 : else if ( !strcmp (*argv, "cipher"))
1903 : {
1904 0 : if (argc == 1)
1905 0 : cipher_bench (NULL);
1906 : else
1907 0 : for (argc--, argv++; argc; argc--, argv++)
1908 0 : cipher_bench ( *argv );
1909 : }
1910 0 : else if ( !strcmp (*argv, "mpi"))
1911 : {
1912 0 : mpi_bench ();
1913 : }
1914 0 : else if ( !strcmp (*argv, "pubkey"))
1915 : {
1916 0 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1917 0 : rsa_bench (pk_count, 1, no_blinding);
1918 0 : elg_bench (pk_count, 0);
1919 0 : dsa_bench (pk_count, 0);
1920 0 : ecc_bench (pk_count, 0);
1921 : }
1922 0 : else if ( !strcmp (*argv, "rsa"))
1923 : {
1924 0 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1925 0 : rsa_bench (pk_count, 1, no_blinding);
1926 : }
1927 0 : else if ( !strcmp (*argv, "elg"))
1928 : {
1929 0 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1930 0 : elg_bench (pk_count, 1);
1931 : }
1932 0 : else if ( !strcmp (*argv, "dsa"))
1933 : {
1934 0 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1935 0 : dsa_bench (pk_count, 1);
1936 : }
1937 0 : else if ( !strcmp (*argv, "ecc"))
1938 : {
1939 0 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1940 0 : ecc_bench (pk_count, 1);
1941 : }
1942 0 : else if ( !strcmp (*argv, "prime"))
1943 : {
1944 0 : gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1945 0 : prime_bench ();
1946 : }
1947 : else
1948 : {
1949 0 : fprintf (stderr, PGM ": bad arguments\n");
1950 0 : return 1;
1951 : }
1952 :
1953 :
1954 1 : if (in_fips_mode && !gcry_fips_mode_active ())
1955 0 : fprintf (stderr, PGM ": FIPS mode is not anymore active\n");
1956 :
1957 1 : return 0;
1958 : }
|