aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2014-05-19 20:19:08 (GMT)
committerJouni Malinen <j@w1.fi>2014-05-19 20:27:30 (GMT)
commitab6d047405cc97793f3a37c56c037f27dada7fad (patch)
tree0646232d97a43d22ea6fd3090cf1509e2bda9995 /src/tls
parent6c5be116dd6997f68e524247751cff53c74519d7 (diff)
downloadhostap-ab6d047405cc97793f3a37c56c037f27dada7fad.zip
hostap-ab6d047405cc97793f3a37c56c037f27dada7fad.tar.gz
hostap-ab6d047405cc97793f3a37c56c037f27dada7fad.tar.bz2
Add function for building RSA public key from n and e parameters
This is similar to the existing functionality that parsed ASN.1-encoded RSA public key by generating a similar public key instance from already parsed n and e parameters. Signed-off-by: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'src/tls')
-rw-r--r--src/tls/rsa.c25
-rw-r--r--src/tls/rsa.h3
2 files changed, 27 insertions, 1 deletions
diff --git a/src/tls/rsa.c b/src/tls/rsa.c
index 125c420..0b7b530 100644
--- a/src/tls/rsa.c
+++ b/src/tls/rsa.c
@@ -1,6 +1,6 @@
/*
* RSA
- * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2006-2014, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
@@ -116,6 +116,29 @@ error:
}
+struct crypto_rsa_key *
+crypto_rsa_import_public_key_parts(const u8 *n, size_t n_len,
+ const u8 *e, size_t e_len)
+{
+ struct crypto_rsa_key *key;
+
+ key = os_zalloc(sizeof(*key));
+ if (key == NULL)
+ return NULL;
+
+ key->n = bignum_init();
+ key->e = bignum_init();
+ if (key->n == NULL || key->e == NULL ||
+ bignum_set_unsigned_bin(key->n, n, n_len) < 0 ||
+ bignum_set_unsigned_bin(key->e, e, e_len) < 0) {
+ crypto_rsa_free(key);
+ return NULL;
+ }
+
+ return key;
+}
+
+
/**
* crypto_rsa_import_private_key - Import an RSA private key
* @buf: Key buffer (DER encoded RSA private key)
diff --git a/src/tls/rsa.h b/src/tls/rsa.h
index c236a9d..b65818e 100644
--- a/src/tls/rsa.h
+++ b/src/tls/rsa.h
@@ -14,6 +14,9 @@ struct crypto_rsa_key;
struct crypto_rsa_key *
crypto_rsa_import_public_key(const u8 *buf, size_t len);
struct crypto_rsa_key *
+crypto_rsa_import_public_key_parts(const u8 *n, size_t n_len,
+ const u8 *e, size_t e_len);
+struct crypto_rsa_key *
crypto_rsa_import_private_key(const u8 *buf, size_t len);
size_t crypto_rsa_get_modulus_len(struct crypto_rsa_key *key);
int crypto_rsa_exptmod(const u8 *in, size_t inlen, u8 *out, size_t *outlen,