crypto_internal-modexp.c
Go to the documentation of this file.
00001 /*
00002  * Crypto wrapper for internal crypto implementation - modexp
00003  * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
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 }


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:26:36