Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "includes.h"
00016
00017 #include "common.h"
00018 #include "tls/bignum.h"
00019 #include "crypto.h"
00020
00021
00022 int crypto_mod_exp(const u8 *base, size_t base_len,
00023 const u8 *power, size_t power_len,
00024 const u8 *modulus, size_t modulus_len,
00025 u8 *result, size_t *result_len)
00026 {
00027 struct bignum *bn_base, *bn_exp, *bn_modulus, *bn_result;
00028 int ret = -1;
00029
00030 bn_base = bignum_init();
00031 bn_exp = bignum_init();
00032 bn_modulus = bignum_init();
00033 bn_result = bignum_init();
00034
00035 if (bn_base == NULL || bn_exp == NULL || bn_modulus == NULL ||
00036 bn_result == NULL)
00037 goto error;
00038
00039 if (bignum_set_unsigned_bin(bn_base, base, base_len) < 0 ||
00040 bignum_set_unsigned_bin(bn_exp, power, power_len) < 0 ||
00041 bignum_set_unsigned_bin(bn_modulus, modulus, modulus_len) < 0)
00042 goto error;
00043
00044 if (bignum_exptmod(bn_base, bn_exp, bn_modulus, bn_result) < 0)
00045 goto error;
00046
00047 ret = bignum_get_unsigned_bin(bn_result, result, result_len);
00048
00049 error:
00050 bignum_deinit(bn_base);
00051 bignum_deinit(bn_exp);
00052 bignum_deinit(bn_modulus);
00053 bignum_deinit(bn_result);
00054 return ret;
00055 }