summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2016-02-03 18:51:02 +0000
committerDr. Stephen Henson <steve@openssl.org>2016-02-05 00:33:33 +0000
commit907e95006820c84d2efe1adb2c8af8340f3ba6cc (patch)
tree7c115df5efaf450d75ed641c0da358b723c5c55f /crypto
parentd6755bb6ac6676cf0f219cd4caf352ac48907206 (diff)
Use BN_bn2binpad
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ec/ec_key.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 13324982d5..19628b1435 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -551,7 +551,7 @@ int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
size_t EC_KEY_priv2oct(const EC_KEY *eckey, unsigned char *buf, size_t len)
{
- size_t buf_len, bn_len;
+ size_t buf_len;
if (eckey->group == NULL || eckey->group->meth == NULL)
return 0;
@@ -563,23 +563,13 @@ size_t EC_KEY_priv2oct(const EC_KEY *eckey, unsigned char *buf, size_t len)
else if (len < buf_len)
return 0;
- bn_len = (size_t)BN_num_bytes(eckey->priv_key);
-
/* Octetstring may need leading zeros if BN is to short */
- if (bn_len > buf_len) {
+ if (BN_bn2binpad(eckey->priv_key, buf, buf_len) == -1) {
ECerr(EC_F_EC_KEY_PRIV2OCT, EC_R_BUFFER_TOO_SMALL);
return 0;
}
- if (!BN_bn2bin(eckey->priv_key, buf + buf_len - bn_len)) {
- ECerr(EC_F_EC_KEY_PRIV2OCT, ERR_R_BN_LIB);
- return 0;
- }
-
- if (buf_len - bn_len > 0)
- memset(buf, 0, buf_len - bn_len);
-
return buf_len;
}