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