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 "crypto.h"
00019 #include "tls/rsa.h"
00020 #include "tls/bignum.h"
00021 #include "tls/pkcs1.h"
00022 #include "tls/pkcs8.h"
00023
00024
00025 struct crypto_public_key;
00026 struct crypto_private_key;
00027
00028
00029 struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
00030 {
00031 return (struct crypto_public_key *)
00032 crypto_rsa_import_public_key(key, len);
00033 }
00034
00035
00036 struct crypto_private_key * crypto_private_key_import(const u8 *key,
00037 size_t len,
00038 const char *passwd)
00039 {
00040 struct crypto_private_key *res;
00041
00042
00043 res = pkcs8_key_import(key, len);
00044 if (res)
00045 return res;
00046
00047 if (passwd) {
00048
00049 res = pkcs8_enc_key_import(key, len, passwd);
00050 if (res)
00051 return res;
00052 }
00053
00054
00055 wpa_printf(MSG_DEBUG, "Trying to parse PKCS #1 encoded RSA private "
00056 "key");
00057 return (struct crypto_private_key *)
00058 crypto_rsa_import_private_key(key, len);
00059 }
00060
00061
00062 struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
00063 size_t len)
00064 {
00065
00066 return NULL;
00067 }
00068
00069
00070 int crypto_public_key_encrypt_pkcs1_v15(struct crypto_public_key *key,
00071 const u8 *in, size_t inlen,
00072 u8 *out, size_t *outlen)
00073 {
00074 return pkcs1_encrypt(2, (struct crypto_rsa_key *) key,
00075 0, in, inlen, out, outlen);
00076 }
00077
00078
00079 int crypto_private_key_decrypt_pkcs1_v15(struct crypto_private_key *key,
00080 const u8 *in, size_t inlen,
00081 u8 *out, size_t *outlen)
00082 {
00083 return pkcs1_v15_private_key_decrypt((struct crypto_rsa_key *) key,
00084 in, inlen, out, outlen);
00085 }
00086
00087
00088 int crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
00089 const u8 *in, size_t inlen,
00090 u8 *out, size_t *outlen)
00091 {
00092 return pkcs1_encrypt(1, (struct crypto_rsa_key *) key,
00093 1, in, inlen, out, outlen);
00094 }
00095
00096
00097 void crypto_public_key_free(struct crypto_public_key *key)
00098 {
00099 crypto_rsa_free((struct crypto_rsa_key *) key);
00100 }
00101
00102
00103 void crypto_private_key_free(struct crypto_private_key *key)
00104 {
00105 crypto_rsa_free((struct crypto_rsa_key *) key);
00106 }
00107
00108
00109 int crypto_public_key_decrypt_pkcs1(struct crypto_public_key *key,
00110 const u8 *crypt, size_t crypt_len,
00111 u8 *plain, size_t *plain_len)
00112 {
00113 return pkcs1_decrypt_public_key((struct crypto_rsa_key *) key,
00114 crypt, crypt_len, plain, plain_len);
00115 }