176
/* What we test here is that we don't overwrite our args and that
177
using thne same mpi for several args works. */
184
gcry_mpi_t base = gcry_mpi_set_ui (NULL, b_int);
185
gcry_mpi_t exp = gcry_mpi_set_ui (NULL, e_int);
186
gcry_mpi_t mod = gcry_mpi_set_ui (NULL, m_int);
187
gcry_mpi_t res = gcry_mpi_new (0);
189
gcry_mpi_powm (res, base, exp, mod);
190
if (gcry_mpi_cmp_ui (base, b_int))
191
die ("test_powm failed for base at %d\n", __LINE__);
192
if (gcry_mpi_cmp_ui (exp, e_int))
193
die ("test_powm_ui failed for exp at %d\n", __LINE__);
194
if (gcry_mpi_cmp_ui (mod, m_int))
195
die ("test_powm failed for mod at %d\n", __LINE__);
197
/* Check using base for the result. */
198
gcry_mpi_set_ui (base, b_int);
199
gcry_mpi_set_ui (exp, e_int);
200
gcry_mpi_set_ui(mod, m_int);
201
gcry_mpi_powm (base, base, exp, mod);
202
if (gcry_mpi_cmp (res, base))
203
die ("test_powm failed at %d\n", __LINE__);
204
if (gcry_mpi_cmp_ui (exp, e_int))
205
die ("test_powm_ui failed for exp at %d\n", __LINE__);
206
if (gcry_mpi_cmp_ui (mod, m_int))
207
die ("test_powm failed for mod at %d\n", __LINE__);
209
/* Check using exp for the result. */
210
gcry_mpi_set_ui (base, b_int);
211
gcry_mpi_set_ui (exp, e_int);
212
gcry_mpi_set_ui(mod, m_int);
213
gcry_mpi_powm (exp, base, exp, mod);
214
if (gcry_mpi_cmp (res, exp))
215
die ("test_powm failed at %d\n", __LINE__);
216
if (gcry_mpi_cmp_ui (base, b_int))
217
die ("test_powm failed for base at %d\n", __LINE__);
218
if (gcry_mpi_cmp_ui (mod, m_int))
219
die ("test_powm failed for mod at %d\n", __LINE__);
221
/* Check using mod for the result. */
222
gcry_mpi_set_ui (base, b_int);
223
gcry_mpi_set_ui (exp, e_int);
224
gcry_mpi_set_ui(mod, m_int);
225
gcry_mpi_powm (mod, base, exp, mod);
226
if (gcry_mpi_cmp (res, mod))
227
die ("test_powm failed at %d\n", __LINE__);
228
if (gcry_mpi_cmp_ui (base, b_int))
229
die ("test_powm failed for base at %d\n", __LINE__);
230
if (gcry_mpi_cmp_ui (exp, e_int))
231
die ("test_powm_ui failed for exp at %d\n", __LINE__);
233
/* Now check base ^ base mod mod. */
234
gcry_mpi_set_ui (base, b_int);
235
gcry_mpi_set_ui(mod, m_int);
236
gcry_mpi_powm (res, base, base, mod);
237
if (gcry_mpi_cmp_ui (base, b_int))
238
die ("test_powm failed for base at %d\n", __LINE__);
239
if (gcry_mpi_cmp_ui (mod, m_int))
240
die ("test_powm failed for mod at %d\n", __LINE__);
242
/* Check base ^ base mod mod with base as result. */
243
gcry_mpi_set_ui (base, b_int);
244
gcry_mpi_set_ui(mod, m_int);
245
gcry_mpi_powm (base, base, base, mod);
246
if (gcry_mpi_cmp (res, base))
247
die ("test_powm failed at %d\n", __LINE__);
248
if (gcry_mpi_cmp_ui (mod, m_int))
249
die ("test_powm failed for mod at %d\n", __LINE__);
251
/* Check base ^ base mod mod with mod as result. */
252
gcry_mpi_set_ui (base, b_int);
253
gcry_mpi_set_ui(mod, m_int);
254
gcry_mpi_powm (mod, base, base, mod);
255
if (gcry_mpi_cmp (res, mod))
256
die ("test_powm failed at %d\n", __LINE__);
257
if (gcry_mpi_cmp_ui (base, b_int))
258
die ("test_powm failed for base at %d\n", __LINE__);
260
/* Now check base ^ base mod base. */
261
gcry_mpi_set_ui (base, b_int);
262
gcry_mpi_powm (res, base, base, base);
263
if (gcry_mpi_cmp_ui (base, b_int))
264
die ("test_powm failed for base at %d\n", __LINE__);
266
/* Check base ^ base mod base with base as result. */
267
gcry_mpi_set_ui (base, b_int);
268
gcry_mpi_powm (base, base, base, base);
269
if (gcry_mpi_cmp (res, base))
270
die ("test_powm failed at %d\n", __LINE__);
272
/* Fixme: We should add the rest of the cases of course. */
161
281
main (int argc, char* argv[])