From e538b1e84bc7594f05824444fef95b3796bc307c Mon Sep 17 00:00:00 2001 From: Love Hornquist Astrand Date: Sat, 19 Sep 2009 12:57:30 -0700 Subject: [PATCH] simplify, make sure length is set properly --- lib/hx509/crypto.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/hx509/crypto.c b/lib/hx509/crypto.c index b203ec389..050a0902b 100644 --- a/lib/hx509/crypto.c +++ b/lib/hx509/crypto.c @@ -558,6 +558,7 @@ rsa_verify_signature(hx509_context context, spi = &signer->tbsCertificate.subjectPublicKeyInfo; p = spi->subjectPublicKey.data; + size = spi->subjectPublicKey.length / 8; rsa = d2i_RSAPublicKey(NULL, &p, size); if (rsa == NULL) { @@ -1577,39 +1578,23 @@ _hx509_public_encrypt(hx509_context context, int tosize; int ret; RSA *rsa; - RSAPublicKey pk; size_t size; + const unsigned char *p; ciphertext->data = NULL; ciphertext->length = 0; spi = &cert->tbsCertificate.subjectPublicKeyInfo; - rsa = RSA_new(); + p = spi->subjectPublicKey.data; + size = spi->subjectPublicKey.length / 8; + + rsa = d2i_RSAPublicKey(NULL, &p, size); if (rsa == NULL) { hx509_set_error_string(context, 0, ENOMEM, "out of memory"); return ENOMEM; } - ret = decode_RSAPublicKey(spi->subjectPublicKey.data, - spi->subjectPublicKey.length / 8, - &pk, &size); - if (ret) { - RSA_free(rsa); - hx509_set_error_string(context, 0, ret, "RSAPublicKey decode failure"); - return ret; - } - rsa->n = heim_int2BN(&pk.modulus); - rsa->e = heim_int2BN(&pk.publicExponent); - - free_RSAPublicKey(&pk); - - if (rsa->n == NULL || rsa->e == NULL) { - RSA_free(rsa); - hx509_set_error_string(context, 0, ENOMEM, "out of memory"); - return ENOMEM; - } - tosize = RSA_size(rsa); to = malloc(tosize); if (to == NULL) {