2 * Crypto wrapper for internal crypto implementation - modexp
3 * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "tls/bignum.h"
22 int crypto_mod_exp(const u8
*base
, size_t base_len
,
23 const u8
*power
, size_t power_len
,
24 const u8
*modulus
, size_t modulus_len
,
25 u8
*result
, size_t *result_len
)
27 struct bignum
*bn_base
, *bn_exp
, *bn_modulus
, *bn_result
;
30 bn_base
= bignum_init();
31 bn_exp
= bignum_init();
32 bn_modulus
= bignum_init();
33 bn_result
= bignum_init();
35 if (bn_base
== NULL
|| bn_exp
== NULL
|| bn_modulus
== NULL
||
39 if (bignum_set_unsigned_bin(bn_base
, base
, base_len
) < 0 ||
40 bignum_set_unsigned_bin(bn_exp
, power
, power_len
) < 0 ||
41 bignum_set_unsigned_bin(bn_modulus
, modulus
, modulus_len
) < 0)
44 if (bignum_exptmod(bn_base
, bn_exp
, bn_modulus
, bn_result
) < 0)
47 ret
= bignum_get_unsigned_bin(bn_result
, result
, result_len
);
50 bignum_deinit(bn_base
);
51 bignum_deinit(bn_exp
);
52 bignum_deinit(bn_modulus
);
53 bignum_deinit(bn_result
);