Added WirelessManager, a port of wpa_supplicant.
[AROS.git] / workbench / network / WirelessManager / src / crypto / crypto_internal-modexp.c
blob3124742e87cd48f4d2e3714dcbb392014a0ab235
1 /*
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
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
17 #include "common.h"
18 #include "tls/bignum.h"
19 #include "crypto.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;
28 int ret = -1;
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 ||
36 bn_result == NULL)
37 goto error;
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)
42 goto error;
44 if (bignum_exptmod(bn_base, bn_exp, bn_modulus, bn_result) < 0)
45 goto error;
47 ret = bignum_get_unsigned_bin(bn_result, result, result_len);
49 error:
50 bignum_deinit(bn_base);
51 bignum_deinit(bn_exp);
52 bignum_deinit(bn_modulus);
53 bignum_deinit(bn_result);
54 return ret;