aboutsummaryrefslogtreecommitdiff
path: root/crypto/pem
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2016-02-01 00:02:05 +0000
committerDr. Stephen Henson <steve@openssl.org>2016-02-02 17:17:38 +0000
commit85a4807f94580b9b666b3e24fff5752515470b1c (patch)
treee2e4f5242dcfe694575a1b003badc5b56e14f71e /crypto/pem
parent19f7130beb97170b8e825aee1ae9e309520f5f29 (diff)
downloadopenssl-85a4807f94580b9b666b3e24fff5752515470b1c.zip
openssl-85a4807f94580b9b666b3e24fff5752515470b1c.tar.gz
openssl-85a4807f94580b9b666b3e24fff5752515470b1c.tar.bz2
New BN functions.
Add new function BN_bn2binpad() which checks the length of the output buffer and pads the result with zeroes if necessary. New functions BN_bn2lebinpad() and BN_lebin2bn() which use little endian format. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/pem')
-rw-r--r--crypto/pem/pvkfmt.c42
1 files changed, 6 insertions, 36 deletions
diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c
index 625b488..736eb27 100644
--- a/crypto/pem/pvkfmt.c
+++ b/crypto/pem/pvkfmt.c
@@ -93,23 +93,11 @@ static unsigned int read_ledword(const unsigned char **in)
static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r)
{
- const unsigned char *p;
- unsigned char *tmpbuf, *q;
- unsigned int i;
- p = *in + nbyte - 1;
- tmpbuf = OPENSSL_malloc(nbyte);
- if (tmpbuf == NULL)
- return 0;
- q = tmpbuf;
- for (i = 0; i < nbyte; i++)
- *q++ = *p--;
- *r = BN_bin2bn(tmpbuf, nbyte, NULL);
- OPENSSL_free(tmpbuf);
- if (*r) {
- *in += nbyte;
- return 1;
- } else
+ *r = BN_lebin2bn(*in, nbyte, NULL);
+ if (*r == NULL)
return 0;
+ *in += nbyte;
+ return 1;
}
/* Convert private key blob to EVP_PKEY: RSA and DSA keys supported */
@@ -417,26 +405,8 @@ static void write_ledword(unsigned char **out, unsigned int dw)
static void write_lebn(unsigned char **out, const BIGNUM *bn, int len)
{
- int nb, i;
- unsigned char *p = *out, *q, c;
- nb = BN_num_bytes(bn);
- BN_bn2bin(bn, p);
- q = p + nb - 1;
- /* In place byte order reversal */
- for (i = 0; i < nb / 2; i++) {
- c = *p;
- *p++ = *q;
- *q-- = c;
- }
- *out += nb;
- /* Pad with zeroes if we have to */
- if (len > 0) {
- len -= nb;
- if (len > 0) {
- memset(*out, 0, len);
- *out += len;
- }
- }
+ BN_bn2lebinpad(bn, *out, len);
+ *out += len;
}
static int check_bitlen_rsa(RSA *rsa, int ispub, unsigned int *magic);