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 26 : 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 26 : size_t bufsize = 1000;
474 : char *buf;
475 : char *largebuf_base;
476 : char *largebuf;
477 : char digest[512/8];
478 26 : gcry_error_t err = GPG_ERR_NO_ERROR;
479 :
480 26 : 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 25 : md_bench (gcry_md_algo_name (i));
487 1 : return;
488 : }
489 :
490 25 : buf = buf_base + ((16 - ((size_t)buf_base & 0x0f)) % buffer_alignment);
491 :
492 25 : algo = gcry_md_map_name (algoname);
493 25 : if (!algo)
494 : {
495 0 : fprintf (stderr, PGM ": invalid hash algorithm `%s'\n", algoname);
496 0 : exit (1);
497 : }
498 :
499 25 : err = gcry_md_open (&hd, algo, 0);
500 25 : if (err)
501 : {
502 0 : fprintf (stderr, PGM ": error opening hash algorithm `%s'\n", algoname);
503 0 : exit (1);
504 : }
505 :
506 25025 : for (i=0; i < bufsize; i++)
507 25000 : buf[i] = i;
508 :
509 25 : printf ("%-12s", gcry_md_algo_name (algo));
510 :
511 25 : start_timer ();
512 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
513 25025 : for (i=0; i < 1000; i++)
514 25000 : gcry_md_write (hd, buf, bufsize);
515 25 : gcry_md_final (hd);
516 25 : stop_timer ();
517 25 : printf (" %s", elapsed_time (1));
518 25 : fflush (stdout);
519 :
520 25 : gcry_md_reset (hd);
521 25 : start_timer ();
522 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
523 250025 : for (i=0; i < 10000; i++)
524 250000 : gcry_md_write (hd, buf, bufsize/10);
525 25 : gcry_md_final (hd);
526 25 : stop_timer ();
527 25 : printf (" %s", elapsed_time (1));
528 25 : fflush (stdout);
529 :
530 25 : gcry_md_reset (hd);
531 25 : start_timer ();
532 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
533 25000025 : for (i=0; i < 1000000; i++)
534 25000000 : gcry_md_write (hd, buf, 1);
535 25 : gcry_md_final (hd);
536 25 : stop_timer ();
537 25 : printf (" %s", elapsed_time (1));
538 25 : fflush (stdout);
539 :
540 25 : start_timer ();
541 50 : for (repcount=0; repcount < hash_repetitions; repcount++)
542 25025 : for (i=0; i < 1000; i++)
543 25025000 : for (j=0; j < bufsize; j++)
544 25000000 : gcry_md_putc (hd, buf[j]);
545 25 : gcry_md_final (hd);
546 25 : stop_timer ();
547 25 : printf (" %s", elapsed_time (1));
548 25 : fflush (stdout);
549 :
550 25 : 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 25 : if (gcry_md_get_algo_dlen (algo) > sizeof digest)
556 0 : die ("digest buffer too short\n");
557 :
558 25 : if (gcry_md_get_algo_dlen (algo))
559 : {
560 23 : largebuf_base = malloc (10000+15);
561 23 : if (!largebuf_base)
562 0 : die ("out of core\n");
563 23 : largebuf = (largebuf_base
564 23 : + ((16 - ((size_t)largebuf_base & 0x0f)) % buffer_alignment));
565 :
566 230023 : for (i=0; i < 10000; i++)
567 230000 : largebuf[i] = i;
568 23 : start_timer ();
569 46 : for (repcount=0; repcount < hash_repetitions; repcount++)
570 2323 : for (i=0; i < 100; i++)
571 2300 : gcry_md_hash_buffer (algo, digest, largebuf, 10000);
572 23 : stop_timer ();
573 23 : printf (" %s", elapsed_time (1));
574 23 : free (largebuf_base);
575 : }
576 :
577 25 : putchar ('\n');
578 25 : 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 : } modes[] = {
768 : { GCRY_CIPHER_MODE_ECB, " ECB/Stream", 1 },
769 : { GCRY_CIPHER_MODE_CBC, " CBC", 1 },
770 : { GCRY_CIPHER_MODE_CFB, " CFB", 0 },
771 : { GCRY_CIPHER_MODE_OFB, " OFB", 0 },
772 : { GCRY_CIPHER_MODE_CTR, " CTR", 0 },
773 : { GCRY_CIPHER_MODE_CCM, " CCM", 0,
774 : ccm_aead_init, GCRY_CCM_BLOCK_LEN, 8 },
775 : { GCRY_CIPHER_MODE_GCM, " GCM", 0,
776 : NULL, GCRY_GCM_BLOCK_LEN, GCRY_GCM_BLOCK_LEN },
777 : { GCRY_CIPHER_MODE_OCB, " OCB", 1,
778 : NULL, 16, 16, 15 },
779 : { GCRY_CIPHER_MODE_STREAM, "", 0 },
780 : {0}
781 : };
782 : int modeidx;
783 25 : gcry_error_t err = GPG_ERR_NO_ERROR;
784 :
785 :
786 25 : if (!algoname)
787 : {
788 400 : for (i=1; i < 400; i++)
789 399 : if ( !gcry_cipher_test_algo (i) )
790 24 : cipher_bench (gcry_cipher_algo_name (i));
791 1 : return;
792 : }
793 :
794 24 : if (large_buffers)
795 : {
796 0 : allocated_buflen = 1024 * 100;
797 0 : repetitions = 10;
798 : }
799 : else
800 : {
801 24 : allocated_buflen = 1024;
802 24 : repetitions = 1000;
803 : }
804 24 : repetitions *= cipher_repetitions;
805 :
806 24 : raw_buf = gcry_xcalloc (allocated_buflen+15, 1);
807 24 : buf = (raw_buf
808 24 : + ((16 - ((size_t)raw_buf & 0x0f)) % buffer_alignment));
809 24 : outbuf = raw_outbuf = gcry_xmalloc (allocated_buflen+15);
810 24 : outbuf = (raw_outbuf
811 24 : + ((16 - ((size_t)raw_outbuf & 0x0f)) % buffer_alignment));
812 :
813 24 : if (!header_printed)
814 : {
815 1 : if (cipher_repetitions != 1)
816 0 : printf ("Running each test %d times.\n", cipher_repetitions);
817 1 : printf ("%-12s", "");
818 10 : for (modeidx=0; modes[modeidx].mode; modeidx++)
819 9 : if (*modes[modeidx].name)
820 8 : printf (" %-15s", modes[modeidx].name );
821 1 : putchar ('\n');
822 1 : printf ("%-12s", "");
823 10 : for (modeidx=0; modes[modeidx].mode; modeidx++)
824 9 : if (*modes[modeidx].name)
825 8 : printf (" ---------------" );
826 1 : putchar ('\n');
827 1 : header_printed = 1;
828 : }
829 :
830 24 : algo = gcry_cipher_map_name (algoname);
831 24 : if (!algo)
832 : {
833 0 : fprintf (stderr, PGM ": invalid cipher algorithm `%s'\n", algoname);
834 0 : exit (1);
835 : }
836 :
837 24 : keylen = gcry_cipher_get_algo_keylen (algo);
838 24 : if (!keylen)
839 : {
840 0 : fprintf (stderr, PGM ": failed to get key length for algorithm `%s'\n",
841 : algoname);
842 0 : exit (1);
843 : }
844 24 : if ( keylen > sizeof key )
845 : {
846 0 : fprintf (stderr, PGM ": algo %d, keylength problem (%d)\n",
847 : algo, keylen );
848 0 : exit (1);
849 : }
850 549 : for (i=0; i < keylen; i++)
851 525 : key[i] = i + (clock () & 0xff);
852 :
853 24 : blklen = gcry_cipher_get_algo_blklen (algo);
854 24 : if (!blklen)
855 : {
856 0 : fprintf (stderr, PGM ": failed to get block length for algorithm `%s'\n",
857 : algoname);
858 0 : exit (1);
859 : }
860 :
861 24 : printf ("%-12s", gcry_cipher_algo_name (algo));
862 24 : fflush (stdout);
863 :
864 240 : for (modeidx=0; modes[modeidx].mode; modeidx++)
865 : {
866 216 : if ((blklen > 1 && modes[modeidx].mode == GCRY_CIPHER_MODE_STREAM)
867 196 : || (blklen == 1 && modes[modeidx].mode != GCRY_CIPHER_MODE_STREAM))
868 52 : continue;
869 :
870 164 : if (modes[modeidx].req_blocksize > 0
871 60 : && blklen != modes[modeidx].req_blocksize)
872 : {
873 24 : printf (" %7s %7s", "-", "-" );
874 24 : continue;
875 : }
876 :
877 1260 : for (i=0; i < sizeof buf; i++)
878 1120 : buf[i] = i;
879 :
880 140 : err = gcry_cipher_open (&hd, algo, modes[modeidx].mode, 0);
881 140 : if (err)
882 : {
883 0 : fprintf (stderr, PGM ": error opening cipher `%s'\n", algoname);
884 0 : exit (1);
885 : }
886 :
887 140 : if (!cipher_with_keysetup)
888 : {
889 140 : err = gcry_cipher_setkey (hd, key, keylen);
890 140 : if (err)
891 : {
892 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
893 : gpg_strerror (err));
894 0 : gcry_cipher_close (hd);
895 0 : exit (1);
896 : }
897 : }
898 :
899 140 : buflen = allocated_buflen;
900 140 : if (modes[modeidx].blocked)
901 52 : buflen = (buflen / blklen) * blklen;
902 :
903 140 : start_timer ();
904 140140 : for (i=err=0; !err && i < repetitions; i++)
905 : {
906 140000 : if (cipher_with_keysetup)
907 : {
908 0 : err = gcry_cipher_setkey (hd, key, keylen);
909 0 : if (err)
910 : {
911 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
912 : gpg_strerror (err));
913 0 : gcry_cipher_close (hd);
914 0 : exit (1);
915 : }
916 : }
917 :
918 140000 : if (modes[modeidx].noncelen)
919 : {
920 : char nonce[100];
921 : size_t noncelen;
922 :
923 12000 : noncelen = modes[modeidx].noncelen;
924 12000 : if (noncelen > sizeof nonce)
925 0 : noncelen = sizeof nonce;
926 12000 : memset (nonce, 42, noncelen);
927 12000 : err = gcry_cipher_setiv (hd, nonce, noncelen);
928 12000 : if (err)
929 : {
930 0 : fprintf (stderr, "gcry_cipher_setiv failed: %s\n",
931 : gpg_strerror (err));
932 0 : gcry_cipher_close (hd);
933 0 : exit (1);
934 : }
935 : }
936 :
937 140000 : if (modes[modeidx].aead_init)
938 : {
939 12000 : (*modes[modeidx].aead_init) (hd, buflen, modes[modeidx].authlen);
940 12000 : gcry_cipher_final (hd);
941 12000 : err = gcry_cipher_encrypt (hd, outbuf, buflen, buf, buflen);
942 12000 : if (err)
943 0 : break;
944 12000 : err = gcry_cipher_gettag (hd, outbuf, modes[modeidx].authlen);
945 : }
946 : else
947 : {
948 128000 : err = gcry_cipher_encrypt (hd, outbuf, buflen, buf, buflen);
949 : }
950 : }
951 140 : stop_timer ();
952 :
953 140 : printf (" %s", elapsed_time (1));
954 140 : fflush (stdout);
955 140 : gcry_cipher_close (hd);
956 140 : if (err)
957 : {
958 0 : fprintf (stderr, "gcry_cipher_encrypt failed: %s\n",
959 : gpg_strerror (err) );
960 0 : exit (1);
961 : }
962 :
963 140 : err = gcry_cipher_open (&hd, algo, modes[modeidx].mode, 0);
964 140 : if (err)
965 : {
966 0 : fprintf (stderr, PGM ": error opening cipher `%s'/n", algoname);
967 0 : exit (1);
968 : }
969 :
970 140 : if (!cipher_with_keysetup)
971 : {
972 140 : err = gcry_cipher_setkey (hd, key, keylen);
973 140 : if (err)
974 : {
975 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
976 : gpg_strerror (err));
977 0 : gcry_cipher_close (hd);
978 0 : exit (1);
979 : }
980 : }
981 :
982 140 : start_timer ();
983 140140 : for (i=err=0; !err && i < repetitions; i++)
984 : {
985 140000 : if (cipher_with_keysetup)
986 : {
987 0 : err = gcry_cipher_setkey (hd, key, keylen);
988 0 : if (err)
989 : {
990 0 : fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
991 : gpg_strerror (err));
992 0 : gcry_cipher_close (hd);
993 0 : exit (1);
994 : }
995 : }
996 :
997 140000 : if (modes[modeidx].noncelen)
998 : {
999 : char nonce[100];
1000 : size_t noncelen;
1001 :
1002 12000 : noncelen = modes[modeidx].noncelen;
1003 12000 : if (noncelen > sizeof nonce)
1004 0 : noncelen = sizeof nonce;
1005 12000 : memset (nonce, 42, noncelen);
1006 12000 : err = gcry_cipher_setiv (hd, nonce, noncelen);
1007 12000 : if (err)
1008 : {
1009 0 : fprintf (stderr, "gcry_cipher_setiv failed: %s\n",
1010 : gpg_strerror (err));
1011 0 : gcry_cipher_close (hd);
1012 0 : exit (1);
1013 : }
1014 : }
1015 :
1016 140000 : if (modes[modeidx].aead_init)
1017 : {
1018 12000 : (*modes[modeidx].aead_init) (hd, buflen, modes[modeidx].authlen);
1019 12000 : gcry_cipher_final (hd);
1020 12000 : err = gcry_cipher_decrypt (hd, outbuf, buflen, buf, buflen);
1021 12000 : if (err)
1022 0 : break;
1023 12000 : err = gcry_cipher_checktag (hd, outbuf, modes[modeidx].authlen);
1024 12000 : if (gpg_err_code (err) == GPG_ERR_CHECKSUM)
1025 12000 : err = 0;
1026 : }
1027 : else
1028 : {
1029 128000 : gcry_cipher_final (hd);
1030 128000 : err = gcry_cipher_decrypt (hd, outbuf, buflen, buf, buflen);
1031 : }
1032 : }
1033 140 : stop_timer ();
1034 140 : printf (" %s", elapsed_time (1));
1035 140 : fflush (stdout);
1036 140 : gcry_cipher_close (hd);
1037 140 : if (err)
1038 : {
1039 0 : fprintf (stderr, "gcry_cipher_decrypt failed: %s\n",
1040 : gpg_strerror (err) );
1041 0 : exit (1);
1042 : }
1043 : }
1044 :
1045 24 : putchar ('\n');
1046 24 : gcry_free (raw_buf);
1047 24 : gcry_free (raw_outbuf);
1048 : }
1049 :
1050 :
1051 :
1052 : static void
1053 1 : rsa_bench (int iterations, int print_header, int no_blinding)
1054 : {
1055 : gpg_error_t err;
1056 1 : int p_sizes[] = { 1024, 2048, 3072, 4096 };
1057 : int testno;
1058 :
1059 1 : if (print_header)
1060 1 : printf ("Algorithm generate %4d*priv %4d*public\n"
1061 : "------------------------------------------------\n",
1062 : iterations, iterations );
1063 5 : for (testno=0; testno < DIM (p_sizes); testno++)
1064 : {
1065 : gcry_sexp_t key_spec, key_pair, pub_key, sec_key;
1066 : gcry_mpi_t x;
1067 : gcry_sexp_t data;
1068 4 : gcry_sexp_t sig = NULL;
1069 : int count;
1070 4 : unsigned nbits = p_sizes[testno];
1071 :
1072 4 : printf ("RSA %3d bit ", nbits);
1073 4 : fflush (stdout);
1074 :
1075 4 : if (in_fips_mode && !(nbits == 2048 || nbits == 3072))
1076 : {
1077 0 : puts ("[skipped in fips mode]");
1078 0 : continue;
1079 : }
1080 :
1081 4 : err = gcry_sexp_build (&key_spec, NULL,
1082 4 : gcry_fips_mode_active ()
1083 : ? "(genkey (RSA (nbits %d)))"
1084 : : "(genkey (RSA (nbits %d)(transient-key)))",
1085 : nbits);
1086 4 : if (err)
1087 0 : die ("creating S-expression failed: %s\n", gcry_strerror (err));
1088 :
1089 4 : start_timer ();
1090 4 : err = gcry_pk_genkey (&key_pair, key_spec);
1091 4 : if (err)
1092 0 : die ("creating %d bit RSA key failed: %s\n",
1093 : nbits, gcry_strerror (err));
1094 :
1095 4 : pub_key = gcry_sexp_find_token (key_pair, "public-key", 0);
1096 4 : if (! pub_key)
1097 0 : die ("public part missing in key\n");
1098 4 : sec_key = gcry_sexp_find_token (key_pair, "private-key", 0);
1099 4 : if (! sec_key)
1100 0 : die ("private part missing in key\n");
1101 4 : gcry_sexp_release (key_pair);
1102 4 : gcry_sexp_release (key_spec);
1103 :
1104 4 : stop_timer ();
1105 4 : printf (" %s", elapsed_time (1));
1106 4 : fflush (stdout);
1107 :
1108 4 : x = gcry_mpi_new (nbits);
1109 4 : gcry_mpi_randomize (x, nbits-8, GCRY_WEAK_RANDOM);
1110 4 : err = gcry_sexp_build (&data, NULL,
1111 : "(data (flags raw) (value %m))", x);
1112 4 : gcry_mpi_release (x);
1113 4 : if (err)
1114 0 : die ("converting data failed: %s\n", gcry_strerror (err));
1115 :
1116 4 : start_timer ();
1117 44 : for (count=0; count < iterations; count++)
1118 : {
1119 40 : gcry_sexp_release (sig);
1120 40 : err = gcry_pk_sign (&sig, data, sec_key);
1121 40 : if (err)
1122 0 : die ("signing failed (%d): %s\n", count, gpg_strerror (err));
1123 : }
1124 4 : stop_timer ();
1125 4 : printf (" %s", elapsed_time (1));
1126 4 : fflush (stdout);
1127 :
1128 4 : start_timer ();
1129 44 : for (count=0; count < iterations; count++)
1130 : {
1131 40 : err = gcry_pk_verify (sig, data, pub_key);
1132 40 : if (err)
1133 : {
1134 0 : putchar ('\n');
1135 0 : show_sexp ("seckey:\n", sec_key);
1136 0 : show_sexp ("data:\n", data);
1137 0 : show_sexp ("sig:\n", sig);
1138 0 : die ("verify failed (%d): %s\n", count, gpg_strerror (err));
1139 : }
1140 : }
1141 4 : stop_timer ();
1142 4 : printf (" %s", elapsed_time (1));
1143 :
1144 4 : if (no_blinding)
1145 : {
1146 0 : fflush (stdout);
1147 0 : x = gcry_mpi_new (nbits);
1148 0 : gcry_mpi_randomize (x, nbits-8, GCRY_WEAK_RANDOM);
1149 0 : err = gcry_sexp_build (&data, NULL,
1150 : "(data (flags no-blinding) (value %m))", x);
1151 0 : gcry_mpi_release (x);
1152 0 : if (err)
1153 0 : die ("converting data failed: %s\n", gcry_strerror (err));
1154 :
1155 0 : start_timer ();
1156 0 : for (count=0; count < iterations; count++)
1157 : {
1158 0 : gcry_sexp_release (sig);
1159 0 : err = gcry_pk_sign (&sig, data, sec_key);
1160 0 : if (err)
1161 0 : die ("signing failed (%d): %s\n", count, gpg_strerror (err));
1162 : }
1163 0 : stop_timer ();
1164 0 : printf (" %s", elapsed_time (1));
1165 0 : fflush (stdout);
1166 : }
1167 :
1168 4 : putchar ('\n');
1169 4 : fflush (stdout);
1170 :
1171 4 : gcry_sexp_release (sig);
1172 4 : gcry_sexp_release (data);
1173 4 : gcry_sexp_release (sec_key);
1174 4 : gcry_sexp_release (pub_key);
1175 : }
1176 1 : }
1177 :
1178 :
1179 : static void
1180 1 : elg_bench (int iterations, int print_header)
1181 : {
1182 : gpg_error_t err;
1183 : gcry_sexp_t pub_key[3], sec_key[3];
1184 1 : int p_sizes[3] = { 1024, 2048, 3072 };
1185 1 : gcry_sexp_t data = NULL;
1186 1 : gcry_sexp_t enc = NULL;
1187 1 : gcry_sexp_t plain = NULL;
1188 : int i, j;
1189 :
1190 1 : err = gcry_sexp_sscan (pub_key+0, NULL, sample_public_elg_key_1024,
1191 : strlen (sample_public_elg_key_1024));
1192 1 : if (!err)
1193 1 : err = gcry_sexp_sscan (sec_key+0, NULL, sample_private_elg_key_1024,
1194 : strlen (sample_private_elg_key_1024));
1195 1 : if (!err)
1196 1 : err = gcry_sexp_sscan (pub_key+1, NULL, sample_public_elg_key_2048,
1197 : strlen (sample_public_elg_key_2048));
1198 1 : if (!err)
1199 1 : err = gcry_sexp_sscan (sec_key+1, NULL, sample_private_elg_key_2048,
1200 : strlen (sample_private_elg_key_2048));
1201 1 : if (!err)
1202 1 : err = gcry_sexp_sscan (pub_key+2, NULL, sample_public_elg_key_3072,
1203 : strlen (sample_public_elg_key_3072));
1204 1 : if (!err)
1205 1 : err = gcry_sexp_sscan (sec_key+2, NULL, sample_private_elg_key_3072,
1206 : strlen (sample_private_elg_key_3072));
1207 1 : if (err)
1208 : {
1209 0 : fprintf (stderr, PGM ": converting sample keys failed: %s\n",
1210 : gcry_strerror (err));
1211 0 : exit (1);
1212 : }
1213 :
1214 1 : if (print_header)
1215 0 : printf ("Algorithm generate %4d*priv %4d*public\n"
1216 : "------------------------------------------------\n",
1217 : iterations, iterations );
1218 4 : for (i=0; i < DIM (p_sizes); i++)
1219 : {
1220 : char timerbuf1[100];
1221 :
1222 : {
1223 3 : gcry_mpi_t x = gcry_mpi_new (p_sizes[i]);
1224 3 : gcry_mpi_randomize (x, p_sizes[i] - 16, GCRY_WEAK_RANDOM);
1225 3 : err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
1226 3 : gcry_mpi_release (x);
1227 : }
1228 3 : if (err)
1229 : {
1230 0 : fprintf (stderr, PGM ": converting data failed: %s\n",
1231 : gcry_strerror (err));
1232 0 : exit (1);
1233 : }
1234 :
1235 3 : printf ("ELG %d bit -", p_sizes[i]);
1236 3 : fflush (stdout);
1237 :
1238 3 : start_timer ();
1239 33 : for (j=0; j < iterations; j++)
1240 : {
1241 30 : gcry_sexp_release (enc);
1242 30 : err = gcry_pk_encrypt (&enc, data, pub_key[i]);
1243 30 : if (err)
1244 : {
1245 0 : putchar ('\n');
1246 0 : fprintf (stderr, PGM ": encrypt failed: %s\n",
1247 : gpg_strerror (err));
1248 0 : exit (1);
1249 : }
1250 : }
1251 3 : stop_timer ();
1252 3 : snprintf (timerbuf1, sizeof timerbuf1, " %s", elapsed_time (1));
1253 3 : fflush (stdout);
1254 :
1255 3 : start_timer ();
1256 33 : for (j=0; j < iterations; j++)
1257 : {
1258 30 : gcry_sexp_release (plain);
1259 30 : err = gcry_pk_decrypt (&plain, enc, sec_key[i]);
1260 30 : if (err)
1261 : {
1262 0 : putchar ('\n');
1263 0 : fprintf (stderr, PGM ": decrypt failed: %s\n",
1264 : gpg_strerror (err));
1265 0 : exit (1);
1266 : }
1267 : }
1268 3 : stop_timer ();
1269 :
1270 3 : printf (" %s %s\n", elapsed_time (1), timerbuf1);
1271 3 : fflush (stdout);
1272 :
1273 3 : gcry_sexp_release (plain);
1274 3 : plain = NULL;
1275 3 : gcry_sexp_release (enc);
1276 3 : enc = NULL;
1277 3 : gcry_sexp_release (data);
1278 3 : data = NULL;
1279 : }
1280 :
1281 4 : for (i=0; i < DIM (p_sizes); i++)
1282 : {
1283 3 : gcry_sexp_release (sec_key[i]);
1284 3 : gcry_sexp_release (pub_key[i]);
1285 : }
1286 1 : }
1287 :
1288 :
1289 : static void
1290 1 : dsa_bench (int iterations, int print_header)
1291 : {
1292 : gpg_error_t err;
1293 : gcry_sexp_t pub_key[3], sec_key[3];
1294 1 : int p_sizes[3] = { 1024, 2048, 3072 };
1295 1 : int q_sizes[3] = { 160, 224, 256 };
1296 : gcry_sexp_t data;
1297 1 : gcry_sexp_t sig = NULL;
1298 : int i, j;
1299 :
1300 1 : err = gcry_sexp_sscan (pub_key+0, NULL, sample_public_dsa_key_1024,
1301 : strlen (sample_public_dsa_key_1024));
1302 1 : if (!err)
1303 1 : err = gcry_sexp_sscan (sec_key+0, NULL, sample_private_dsa_key_1024,
1304 : strlen (sample_private_dsa_key_1024));
1305 1 : if (!err)
1306 1 : err = gcry_sexp_sscan (pub_key+1, NULL, sample_public_dsa_key_2048,
1307 : strlen (sample_public_dsa_key_2048));
1308 1 : if (!err)
1309 1 : err = gcry_sexp_sscan (sec_key+1, NULL, sample_private_dsa_key_2048,
1310 : strlen (sample_private_dsa_key_2048));
1311 1 : if (!err)
1312 1 : err = gcry_sexp_sscan (pub_key+2, NULL, sample_public_dsa_key_3072,
1313 : strlen (sample_public_dsa_key_3072));
1314 1 : if (!err)
1315 1 : err = gcry_sexp_sscan (sec_key+2, NULL, sample_private_dsa_key_3072,
1316 : strlen (sample_private_dsa_key_3072));
1317 1 : if (err)
1318 : {
1319 0 : fprintf (stderr, PGM ": converting sample keys failed: %s\n",
1320 : gcry_strerror (err));
1321 0 : exit (1);
1322 : }
1323 :
1324 1 : if (print_header)
1325 0 : printf ("Algorithm generate %4d*priv %4d*public\n"
1326 : "------------------------------------------------\n",
1327 : iterations, iterations );
1328 4 : for (i=0; i < DIM (q_sizes); i++)
1329 : {
1330 : gcry_mpi_t x;
1331 :
1332 3 : x = gcry_mpi_new (q_sizes[i]);
1333 3 : gcry_mpi_randomize (x, q_sizes[i], GCRY_WEAK_RANDOM);
1334 3 : err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
1335 3 : gcry_mpi_release (x);
1336 3 : if (err)
1337 : {
1338 0 : fprintf (stderr, PGM ": converting data failed: %s\n",
1339 : gcry_strerror (err));
1340 0 : exit (1);
1341 : }
1342 :
1343 3 : printf ("DSA %d/%d -", p_sizes[i], q_sizes[i]);
1344 3 : fflush (stdout);
1345 :
1346 3 : start_timer ();
1347 33 : for (j=0; j < iterations; j++)
1348 : {
1349 30 : gcry_sexp_release (sig);
1350 30 : err = gcry_pk_sign (&sig, data, sec_key[i]);
1351 30 : if (err)
1352 : {
1353 0 : putchar ('\n');
1354 0 : fprintf (stderr, PGM ": signing failed: %s\n",
1355 : gpg_strerror (err));
1356 0 : exit (1);
1357 : }
1358 : }
1359 3 : stop_timer ();
1360 3 : printf (" %s", elapsed_time (1));
1361 3 : fflush (stdout);
1362 :
1363 3 : start_timer ();
1364 33 : for (j=0; j < iterations; j++)
1365 : {
1366 30 : err = gcry_pk_verify (sig, data, pub_key[i]);
1367 30 : if (err)
1368 : {
1369 0 : putchar ('\n');
1370 0 : fprintf (stderr, PGM ": verify failed: %s\n",
1371 : gpg_strerror (err));
1372 0 : exit (1);
1373 : }
1374 : }
1375 3 : stop_timer ();
1376 3 : printf (" %s\n", elapsed_time (1));
1377 3 : fflush (stdout);
1378 :
1379 3 : gcry_sexp_release (sig);
1380 3 : gcry_sexp_release (data);
1381 3 : sig = NULL;
1382 : }
1383 :
1384 :
1385 4 : for (i=0; i < DIM (q_sizes); i++)
1386 : {
1387 3 : gcry_sexp_release (sec_key[i]);
1388 3 : gcry_sexp_release (pub_key[i]);
1389 : }
1390 1 : }
1391 :
1392 :
1393 : static void
1394 1 : ecc_bench (int iterations, int print_header)
1395 : {
1396 : #if USE_ECC
1397 : gpg_error_t err;
1398 1 : const char *p_sizes[] = { "192", "224", "256", "384", "521", "Ed25519",
1399 : "gost256", "gost512" };
1400 : int testno;
1401 :
1402 1 : if (print_header)
1403 0 : printf ("Algorithm generate %4d*priv %4d*public\n"
1404 : "------------------------------------------------\n",
1405 : iterations, iterations );
1406 9 : for (testno=0; testno < DIM (p_sizes); testno++)
1407 : {
1408 : gcry_sexp_t key_spec, key_pair, pub_key, sec_key;
1409 : gcry_mpi_t x;
1410 : gcry_sexp_t data;
1411 8 : gcry_sexp_t sig = NULL;
1412 : int count;
1413 : int p_size;
1414 : int is_ed25519;
1415 : int is_gost;
1416 :
1417 8 : is_ed25519 = !strcmp (p_sizes[testno], "Ed25519");
1418 8 : is_gost = !strncmp (p_sizes[testno], "gost", 4);
1419 :
1420 : /* Only P-{224,256,384,521} are allowed in fips mode */
1421 8 : if (gcry_fips_mode_active()
1422 0 : && (is_ed25519 || is_gost || !strcmp (p_sizes[testno], "192")))
1423 0 : continue;
1424 :
1425 8 : if (is_ed25519)
1426 : {
1427 1 : p_size = 256;
1428 1 : printf ("EdDSA Ed25519 ");
1429 1 : fflush (stdout);
1430 : }
1431 7 : else if (is_gost)
1432 : {
1433 2 : p_size = atoi (p_sizes[testno] + 4);
1434 2 : printf ("GOST %3d bit ", p_size);
1435 2 : fflush (stdout);
1436 : }
1437 : else
1438 : {
1439 5 : p_size = atoi (p_sizes[testno]);
1440 5 : printf ("ECDSA %3d bit ", p_size);
1441 : }
1442 8 : fflush (stdout);
1443 :
1444 8 : if (is_ed25519)
1445 1 : err = gcry_sexp_build (&key_spec, NULL,
1446 : "(genkey (ecdsa (curve \"Ed25519\")"
1447 : "(flags eddsa)))");
1448 7 : else if (is_gost)
1449 2 : err = gcry_sexp_build (&key_spec, NULL,
1450 : "(genkey (ecdsa (curve %s)))",
1451 : p_size == 256 ? "GOST2001-test" : "GOST2012-test");
1452 : else
1453 5 : err = gcry_sexp_build (&key_spec, NULL,
1454 : "(genkey (ECDSA (nbits %d)))", p_size);
1455 8 : if (err)
1456 0 : die ("creating S-expression failed: %s\n", gcry_strerror (err));
1457 :
1458 8 : start_timer ();
1459 8 : err = gcry_pk_genkey (&key_pair, key_spec);
1460 8 : if (err)
1461 0 : die ("creating %d bit ECC key failed: %s\n",
1462 : p_size, gcry_strerror (err));
1463 8 : if (verbose > 2)
1464 0 : show_sexp ("ECC key:\n", key_pair);
1465 :
1466 8 : pub_key = gcry_sexp_find_token (key_pair, "public-key", 0);
1467 8 : if (! pub_key)
1468 0 : die ("public part missing in key\n");
1469 8 : sec_key = gcry_sexp_find_token (key_pair, "private-key", 0);
1470 8 : if (! sec_key)
1471 0 : die ("private part missing in key\n");
1472 8 : gcry_sexp_release (key_pair);
1473 8 : gcry_sexp_release (key_spec);
1474 :
1475 8 : stop_timer ();
1476 8 : printf (" %s", elapsed_time (1));
1477 8 : fflush (stdout);
1478 :
1479 8 : x = gcry_mpi_new (p_size);
1480 8 : gcry_mpi_randomize (x, p_size, GCRY_WEAK_RANDOM);
1481 8 : if (is_ed25519)
1482 1 : err = gcry_sexp_build (&data, NULL,
1483 : "(data (flags eddsa)(hash-algo sha512)"
1484 : " (value %m))", x);
1485 7 : else if (is_gost)
1486 2 : err = gcry_sexp_build (&data, NULL, "(data (flags gost) (value %m))", x);
1487 : else
1488 5 : err = gcry_sexp_build (&data, NULL, "(data (flags raw) (value %m))", x);
1489 8 : gcry_mpi_release (x);
1490 :
1491 8 : if (err)
1492 0 : die ("converting data failed: %s\n", gcry_strerror (err));
1493 :
1494 8 : start_timer ();
1495 88 : for (count=0; count < iterations; count++)
1496 : {
1497 80 : gcry_sexp_release (sig);
1498 80 : err = gcry_pk_sign (&sig, data, sec_key);
1499 80 : if (err)
1500 : {
1501 0 : if (verbose)
1502 : {
1503 0 : putc ('\n', stderr);
1504 0 : show_sexp ("signing key:\n", sec_key);
1505 0 : show_sexp ("signed data:\n", data);
1506 : }
1507 0 : die ("signing failed: %s\n", gpg_strerror (err));
1508 : }
1509 : }
1510 8 : stop_timer ();
1511 8 : printf (" %s", elapsed_time (1));
1512 8 : fflush (stdout);
1513 :
1514 8 : start_timer ();
1515 88 : for (count=0; count < iterations; count++)
1516 : {
1517 80 : err = gcry_pk_verify (sig, data, pub_key);
1518 80 : if (err)
1519 : {
1520 0 : putchar ('\n');
1521 0 : show_sexp ("seckey:\n", sec_key);
1522 0 : show_sexp ("data:\n", data);
1523 0 : show_sexp ("sig:\n", sig);
1524 0 : die ("verify failed: %s\n", gpg_strerror (err));
1525 : }
1526 : }
1527 8 : stop_timer ();
1528 8 : printf (" %s\n", elapsed_time (1));
1529 8 : fflush (stdout);
1530 :
1531 8 : gcry_sexp_release (sig);
1532 8 : gcry_sexp_release (data);
1533 8 : gcry_sexp_release (sec_key);
1534 8 : gcry_sexp_release (pub_key);
1535 : }
1536 : #endif /*USE_ECC*/
1537 1 : }
1538 :
1539 :
1540 :
1541 : static void
1542 3 : do_powm ( const char *n_str, const char *e_str, const char *m_str)
1543 : {
1544 : gcry_mpi_t e, n, msg, cip;
1545 : gcry_error_t err;
1546 : int i;
1547 :
1548 3 : err = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX, n_str, 0, 0);
1549 3 : if (err) BUG ();
1550 3 : err = gcry_mpi_scan (&e, GCRYMPI_FMT_HEX, e_str, 0, 0);
1551 3 : if (err) BUG ();
1552 3 : err = gcry_mpi_scan (&msg, GCRYMPI_FMT_HEX, m_str, 0, 0);
1553 3 : if (err) BUG ();
1554 :
1555 3 : cip = gcry_mpi_new (0);
1556 :
1557 3 : start_timer ();
1558 3003 : for (i=0; i < 1000; i++)
1559 3000 : gcry_mpi_powm (cip, msg, e, n);
1560 3 : stop_timer ();
1561 3 : printf (" %s", elapsed_time (1)); fflush (stdout);
1562 : /* { */
1563 : /* char *buf; */
1564 :
1565 : /* if (gcry_mpi_aprint (GCRYMPI_FMT_HEX, (void**)&buf, NULL, cip)) */
1566 : /* BUG (); */
1567 : /* printf ("result: %s\n", buf); */
1568 : /* gcry_free (buf); */
1569 : /* } */
1570 3 : gcry_mpi_release (cip);
1571 3 : gcry_mpi_release (msg);
1572 3 : gcry_mpi_release (n);
1573 3 : gcry_mpi_release (e);
1574 3 : }
1575 :
1576 :
1577 : static void
1578 1 : mpi_bench (void)
1579 : {
1580 1 : printf ("%-10s", "powm"); fflush (stdout);
1581 :
1582 1 : do_powm (
1583 : "20A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E4",
1584 : "29",
1585 : "B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8"
1586 : );
1587 1 : do_powm (
1588 : "20A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E41071F0246879A442658FBD18C1771571E7073EEEB2160BA0CBFB3404D627069A6CFBD53867AD2D9D40231648000787B5C84176B4336144644AE71A403CA40716",
1589 : "29",
1590 : "B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8FC4EE4BB446B83E48ABED7DB81CBF5E81DE4759E8D68AC985846D999F96B0D8A80E5C69D272C766AB8A23B40D50A4FA889FBC2BD2624222D8EB297F4BAEF8593847"
1591 : );
1592 1 : do_powm (
1593 : "20A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E41071F0246879A442658FBD18C1771571E7073EEEB2160BA0CBFB3404D627069A6CFBD53867AD2D9D40231648000787B5C84176B4336144644AE71A403CA4071620A94417D4D5EF2B2DA99165C7DC87DADB3979B72961AF90D09D59BA24CB9A10166FDCCC9C659F2B9626EC23F3FA425F564A072BA941B03FA81767CC289E41071F0246879A442658FBD18C1771571E7073EEEB2160BA0CBFB3404D627069A6CFBD53867AD2D9D40231648000787B5C84176B4336144644AE71A403CA40716",
1594 : "29",
1595 : "B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8FC4EE4BB446B83E48ABED7DB81CBF5E81DE4759E8D68AC985846D999F96B0D8A80E5C69D272C766AB8A23B40D50A4FA889FBC2BD2624222D8EB297F4BAEF8593847B870187A323F1ECD5B8A0B4249507335A1C4CE8394F38FD76B08C78A42C58F6EA136ACF90DFE8603697B1694A3D81114D6117AC1811979C51C4DD013D52F8FC4EE4BB446B83E48ABED7DB81CBF5E81DE4759E8D68AC985846D999F96B0D8A80E5C69D272C766AB8A23B40D50A4FA889FBC2BD2624222D8EB297F4BAEF8593847"
1596 : );
1597 :
1598 1 : putchar ('\n');
1599 :
1600 :
1601 1 : }
1602 :
1603 :
1604 : static void
1605 0 : prime_bench (void)
1606 : {
1607 : gpg_error_t err;
1608 : int i;
1609 : gcry_mpi_t prime;
1610 0 : int old_prog = single_char_progress;
1611 :
1612 0 : single_char_progress = 1;
1613 0 : if (!with_progress)
1614 0 : printf ("%-10s", "prime");
1615 0 : fflush (stdout);
1616 0 : start_timer ();
1617 0 : for (i=0; i < 10; i++)
1618 : {
1619 0 : if (with_progress)
1620 0 : fputs ("primegen ", stdout);
1621 0 : err = gcry_prime_generate (&prime,
1622 : 1024, 0,
1623 : NULL,
1624 : NULL, NULL,
1625 : GCRY_WEAK_RANDOM,
1626 : GCRY_PRIME_FLAG_SECRET);
1627 0 : if (with_progress)
1628 : {
1629 0 : fputc ('\n', stdout);
1630 0 : fflush (stdout);
1631 : }
1632 0 : if (err)
1633 : {
1634 0 : fprintf (stderr, PGM ": error creating prime: %s\n",
1635 : gpg_strerror (err));
1636 0 : exit (1);
1637 : }
1638 0 : gcry_mpi_release (prime);
1639 : }
1640 0 : stop_timer ();
1641 0 : if (with_progress)
1642 0 : printf ("%-10s", "prime");
1643 0 : printf (" %s\n", elapsed_time (1)); fflush (stdout);
1644 :
1645 0 : single_char_progress = old_prog;
1646 0 : }
1647 :
1648 :
1649 : int
1650 1 : main( int argc, char **argv )
1651 : {
1652 1 : int last_argc = -1;
1653 1 : int no_blinding = 0;
1654 1 : int use_random_daemon = 0;
1655 1 : int use_secmem = 0;
1656 1 : int pk_count = 100;
1657 :
1658 1 : buffer_alignment = 1;
1659 :
1660 1 : if (argc)
1661 1 : { argc--; argv++; }
1662 :
1663 : /* We skip this test if we are running under the test suite (no args
1664 : and srcdir defined) and GCRYPT_NO_BENCHMARKS is set. */
1665 1 : if (!argc && getenv ("srcdir") && getenv ("GCRYPT_NO_BENCHMARKS"))
1666 0 : exit (77);
1667 :
1668 1 : if (getenv ("GCRYPT_IN_REGRESSION_TEST"))
1669 : {
1670 1 : in_regression_test = 1;
1671 1 : pk_count = 10;
1672 : }
1673 :
1674 2 : while (argc && last_argc != argc )
1675 : {
1676 0 : last_argc = argc;
1677 0 : if (!strcmp (*argv, "--"))
1678 : {
1679 0 : argc--; argv++;
1680 0 : break;
1681 : }
1682 0 : else if (!strcmp (*argv, "--help"))
1683 : {
1684 0 : fputs ("usage: benchmark "
1685 : "[md|mac|cipher|random|mpi|rsa|dsa|ecc|prime [algonames]]\n",
1686 : stdout);
1687 0 : exit (0);
1688 : }
1689 0 : else if (!strcmp (*argv, "--verbose"))
1690 : {
1691 0 : verbose++;
1692 0 : argc--; argv++;
1693 : }
1694 0 : else if (!strcmp (*argv, "--debug"))
1695 : {
1696 0 : verbose += 2;
1697 0 : debug++;
1698 0 : argc--; argv++;
1699 : }
1700 0 : else if (!strcmp (*argv, "--use-random-daemon"))
1701 : {
1702 0 : use_random_daemon = 1;
1703 0 : argc--; argv++;
1704 : }
1705 0 : else if (!strcmp (*argv, "--use-secmem"))
1706 : {
1707 0 : use_secmem = 1;
1708 0 : argc--; argv++;
1709 : }
1710 0 : else if (!strcmp (*argv, "--prefer-standard-rng"))
1711 : {
1712 : /* This is anyway the default, but we may want to use it for
1713 : debugging. */
1714 0 : xgcry_control (GCRYCTL_SET_PREFERRED_RNG_TYPE, GCRY_RNG_TYPE_STANDARD);
1715 0 : argc--; argv++;
1716 : }
1717 0 : else if (!strcmp (*argv, "--prefer-fips-rng"))
1718 : {
1719 0 : xgcry_control (GCRYCTL_SET_PREFERRED_RNG_TYPE, GCRY_RNG_TYPE_FIPS);
1720 0 : argc--; argv++;
1721 : }
1722 0 : else if (!strcmp (*argv, "--prefer-system-rng"))
1723 : {
1724 0 : xgcry_control (GCRYCTL_SET_PREFERRED_RNG_TYPE, GCRY_RNG_TYPE_SYSTEM);
1725 0 : argc--; argv++;
1726 : }
1727 0 : else if (!strcmp (*argv, "--no-blinding"))
1728 : {
1729 0 : no_blinding = 1;
1730 0 : argc--; argv++;
1731 : }
1732 0 : else if (!strcmp (*argv, "--large-buffers"))
1733 : {
1734 0 : large_buffers = 1;
1735 0 : argc--; argv++;
1736 : }
1737 0 : else if (!strcmp (*argv, "--cipher-repetitions"))
1738 : {
1739 0 : argc--; argv++;
1740 0 : if (argc)
1741 : {
1742 0 : cipher_repetitions = atoi(*argv);
1743 0 : argc--; argv++;
1744 : }
1745 : }
1746 0 : else if (!strcmp (*argv, "--cipher-with-keysetup"))
1747 : {
1748 0 : cipher_with_keysetup = 1;
1749 0 : argc--; argv++;
1750 : }
1751 0 : else if (!strcmp (*argv, "--hash-repetitions"))
1752 : {
1753 0 : argc--; argv++;
1754 0 : if (argc)
1755 : {
1756 0 : hash_repetitions = atoi(*argv);
1757 0 : argc--; argv++;
1758 : }
1759 : }
1760 0 : else if (!strcmp (*argv, "--mac-repetitions"))
1761 : {
1762 0 : argc--; argv++;
1763 0 : if (argc)
1764 : {
1765 0 : mac_repetitions = atoi(*argv);
1766 0 : argc--; argv++;
1767 : }
1768 : }
1769 0 : else if (!strcmp (*argv, "--pk-count"))
1770 : {
1771 0 : argc--; argv++;
1772 0 : if (argc)
1773 : {
1774 0 : pk_count = atoi(*argv);
1775 0 : argc--; argv++;
1776 : }
1777 : }
1778 0 : else if (!strcmp (*argv, "--alignment"))
1779 : {
1780 0 : argc--; argv++;
1781 0 : if (argc)
1782 : {
1783 0 : buffer_alignment = atoi(*argv);
1784 0 : argc--; argv++;
1785 : }
1786 : }
1787 0 : else if (!strcmp (*argv, "--disable-hwf"))
1788 : {
1789 0 : argc--; argv++;
1790 0 : if (argc)
1791 : {
1792 0 : if (gcry_control (GCRYCTL_DISABLE_HWF, *argv, NULL))
1793 0 : fprintf (stderr, PGM ": unknown hardware feature `%s'"
1794 : " - option ignored\n", *argv);
1795 0 : argc--; argv++;
1796 : }
1797 : }
1798 0 : else if (!strcmp (*argv, "--fips"))
1799 : {
1800 0 : argc--; argv++;
1801 : /* This command needs to be called before gcry_check_version. */
1802 0 : xgcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
1803 : }
1804 0 : else if (!strcmp (*argv, "--progress"))
1805 : {
1806 0 : argc--; argv++;
1807 0 : with_progress = 1;
1808 : }
1809 : }
1810 :
1811 1 : if (buffer_alignment < 1 || buffer_alignment > 16)
1812 0 : die ("value for --alignment must be in the range 1 to 16\n");
1813 :
1814 1 : xgcry_control (GCRYCTL_SET_VERBOSITY, (int)verbose);
1815 :
1816 1 : if (!gcry_check_version (GCRYPT_VERSION))
1817 : {
1818 0 : fprintf (stderr, PGM ": version mismatch; pgm=%s, library=%s\n",
1819 : GCRYPT_VERSION, gcry_check_version (NULL));
1820 0 : exit (1);
1821 : }
1822 :
1823 1 : if (debug)
1824 0 : xgcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
1825 :
1826 1 : if (gcry_fips_mode_active ())
1827 0 : in_fips_mode = 1;
1828 1 : else if (!use_secmem)
1829 1 : xgcry_control (GCRYCTL_DISABLE_SECMEM, 0);
1830 :
1831 1 : if (use_random_daemon)
1832 0 : xgcry_control (GCRYCTL_USE_RANDOM_DAEMON, 1);
1833 :
1834 1 : if (with_progress)
1835 0 : gcry_set_progress_handler (progress_cb, NULL);
1836 :
1837 1 : xgcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
1838 :
1839 1 : if (cipher_repetitions < 1)
1840 1 : cipher_repetitions = 1;
1841 1 : if (hash_repetitions < 1)
1842 1 : hash_repetitions = 1;
1843 1 : if (mac_repetitions < 1)
1844 1 : mac_repetitions = 1;
1845 :
1846 1 : if (in_regression_test)
1847 1 : fputs ("Note: " PGM " running in quick regression test mode.\n", stdout);
1848 :
1849 1 : if ( !argc )
1850 : {
1851 1 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1852 1 : md_bench (NULL);
1853 1 : putchar ('\n');
1854 1 : mac_bench (NULL);
1855 1 : putchar ('\n');
1856 1 : cipher_bench (NULL);
1857 1 : putchar ('\n');
1858 1 : rsa_bench (pk_count, 1, no_blinding);
1859 1 : elg_bench (pk_count, 0);
1860 1 : dsa_bench (pk_count, 0);
1861 1 : ecc_bench (pk_count, 0);
1862 1 : putchar ('\n');
1863 1 : mpi_bench ();
1864 1 : putchar ('\n');
1865 1 : random_bench (0);
1866 : }
1867 0 : else if ( !strcmp (*argv, "random") || !strcmp (*argv, "strongrandom"))
1868 : {
1869 0 : if (argc == 1)
1870 0 : random_bench ((**argv == 's'));
1871 0 : else if (argc == 2)
1872 : {
1873 0 : xgcry_control (GCRYCTL_SET_RANDOM_SEED_FILE, argv[1]);
1874 0 : random_bench ((**argv == 's'));
1875 0 : xgcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE);
1876 : }
1877 : else
1878 0 : fputs ("usage: benchmark [strong]random [seedfile]\n", stdout);
1879 : }
1880 0 : else if ( !strcmp (*argv, "md"))
1881 : {
1882 0 : if (argc == 1)
1883 0 : md_bench (NULL);
1884 : else
1885 0 : for (argc--, argv++; argc; argc--, argv++)
1886 0 : md_bench ( *argv );
1887 : }
1888 0 : else if ( !strcmp (*argv, "mac"))
1889 : {
1890 0 : if (argc == 1)
1891 0 : mac_bench (NULL);
1892 : else
1893 0 : for (argc--, argv++; argc; argc--, argv++)
1894 0 : mac_bench ( *argv );
1895 : }
1896 0 : else if ( !strcmp (*argv, "cipher"))
1897 : {
1898 0 : if (argc == 1)
1899 0 : cipher_bench (NULL);
1900 : else
1901 0 : for (argc--, argv++; argc; argc--, argv++)
1902 0 : cipher_bench ( *argv );
1903 : }
1904 0 : else if ( !strcmp (*argv, "mpi"))
1905 : {
1906 0 : mpi_bench ();
1907 : }
1908 0 : else if ( !strcmp (*argv, "pubkey"))
1909 : {
1910 0 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1911 0 : rsa_bench (pk_count, 1, no_blinding);
1912 0 : elg_bench (pk_count, 0);
1913 0 : dsa_bench (pk_count, 0);
1914 0 : ecc_bench (pk_count, 0);
1915 : }
1916 0 : else if ( !strcmp (*argv, "rsa"))
1917 : {
1918 0 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1919 0 : rsa_bench (pk_count, 1, no_blinding);
1920 : }
1921 0 : else if ( !strcmp (*argv, "elg"))
1922 : {
1923 0 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1924 0 : elg_bench (pk_count, 1);
1925 : }
1926 0 : else if ( !strcmp (*argv, "dsa"))
1927 : {
1928 0 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1929 0 : dsa_bench (pk_count, 1);
1930 : }
1931 0 : else if ( !strcmp (*argv, "ecc"))
1932 : {
1933 0 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1934 0 : ecc_bench (pk_count, 1);
1935 : }
1936 0 : else if ( !strcmp (*argv, "prime"))
1937 : {
1938 0 : xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
1939 0 : prime_bench ();
1940 : }
1941 : else
1942 : {
1943 0 : fprintf (stderr, PGM ": bad arguments\n");
1944 0 : return 1;
1945 : }
1946 :
1947 :
1948 1 : if (in_fips_mode && !gcry_fips_mode_active ())
1949 0 : fprintf (stderr, PGM ": FIPS mode is not anymore active\n");
1950 :
1951 1 : return 0;
1952 : }
|