aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2009-02-05 16:57:26 (GMT)
committerJouni Malinen <j@w1.fi>2009-02-08 10:35:11 (GMT)
commit36740bafd19e2f21779480c6d092cccf941a1a3d (patch)
tree13dfc582b4886965e79267b006872d5dc1fef01c /src
parent421f219be8b475bfec735f0e4350d52c9e782fb3 (diff)
downloadhostap-06-36740bafd19e2f21779480c6d092cccf941a1a3d.zip
hostap-06-36740bafd19e2f21779480c6d092cccf941a1a3d.tar.gz
hostap-06-36740bafd19e2f21779480c6d092cccf941a1a3d.tar.bz2
Add crypto_mod_exp() for GnuTLS (libgcrypt)
This allows WPS to be linked with GnuTLS. (cherry picked from commit 3a19555445ea909ea1d26dcd394f365a4990355c)
Diffstat (limited to 'src')
-rw-r--r--src/crypto/crypto_gnutls.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/crypto/crypto_gnutls.c b/src/crypto/crypto_gnutls.c
index 7ab54df..20cbc35 100644
--- a/src/crypto/crypto_gnutls.c
+++ b/src/crypto/crypto_gnutls.c
@@ -163,3 +163,38 @@ void aes_decrypt_deinit(void *ctx)
gcry_cipher_close(hd);
}
#endif /* EAP_TLS_FUNCS */
+
+
+int crypto_mod_exp(const u8 *base, size_t base_len,
+ const u8 *power, size_t power_len,
+ const u8 *modulus, size_t modulus_len,
+ u8 *result, size_t *result_len)
+{
+ gcry_mpi_t bn_base = NULL, bn_exp = NULL, bn_modulus = NULL,
+ bn_result = NULL;
+ int ret = -1;
+
+ if (gcry_mpi_scan(&bn_base, GCRYMPI_FMT_USG, base, base_len, NULL) !=
+ GPG_ERR_NO_ERROR ||
+ gcry_mpi_scan(&bn_exp, GCRYMPI_FMT_USG, power, power_len, NULL) !=
+ GPG_ERR_NO_ERROR ||
+ gcry_mpi_scan(&bn_modulus, GCRYMPI_FMT_USG, modulus, modulus_len,
+ NULL) != GPG_ERR_NO_ERROR)
+ goto error;
+ bn_result = gcry_mpi_new(modulus_len * 8);
+
+ gcry_mpi_powm(bn_result, bn_base, bn_exp, bn_modulus);
+
+ if (gcry_mpi_print(GCRYMPI_FMT_USG, result, *result_len, result_len,
+ bn_result) != GPG_ERR_NO_ERROR)
+ goto error;
+
+ ret = 0;
+
+error:
+ gcry_mpi_release(bn_base);
+ gcry_mpi_release(bn_exp);
+ gcry_mpi_release(bn_modulus);
+ gcry_mpi_release(bn_result);
+ return ret;
+}