2 * Crypto wrapper for internal crypto implementation - modexp
3 * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "tls/bignum.h"
16 int crypto_mod_exp(const u8 *base, size_t base_len,
17 const u8 *power, size_t power_len,
18 const u8 *modulus, size_t modulus_len,
19 u8 *result, size_t *result_len)
21 struct bignum *bn_base, *bn_exp, *bn_modulus, *bn_result;
24 bn_base = bignum_init();
25 bn_exp = bignum_init();
26 bn_modulus = bignum_init();
27 bn_result = bignum_init();
29 if (bn_base == NULL || bn_exp == NULL || bn_modulus == NULL ||
33 if (bignum_set_unsigned_bin(bn_base, base, base_len) < 0 ||
34 bignum_set_unsigned_bin(bn_exp, power, power_len) < 0 ||
35 bignum_set_unsigned_bin(bn_modulus, modulus, modulus_len) < 0)
38 if (bignum_exptmod(bn_base, bn_exp, bn_modulus, bn_result) < 0)
41 ret = bignum_get_unsigned_bin(bn_result, result, result_len);
44 bignum_deinit(bn_base);
45 bignum_deinit(bn_exp);
46 bignum_deinit(bn_modulus);
47 bignum_deinit(bn_result);