From 210ad772b67ec4fc0104643c771251b637b4d1cc Mon Sep 17 00:00:00 2001 From: Dmitry Belyavskiy Date: Sun, 3 Jan 2016 23:23:59 +0300 Subject: [PATCH] Backport commit 22dc08d00ae9517048b1ca44cd3810128eba0273 --- gost_ameth.c | 20 ++------------------ gost_ec_sign.c | 2 +- gost_lcl.h | 2 -- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/gost_ameth.c b/gost_ameth.c index f967283..0ea1583 100644 --- a/gost_ameth.c +++ b/gost_ameth.c @@ -34,22 +34,6 @@ int store_bignum(BIGNUM *bn, unsigned char *buf, int len) return 1; } -/* Convert byte buffer to bignum, skipping leading zeros*/ -BIGNUM *getbnfrombuf(const unsigned char *buf, size_t len) -{ - BIGNUM *b; - - while (*buf == 0 && len > 0) { - buf++; - len--; - } - if (len) - return BN_bin2bn(buf, len, NULL); - b = BN_new(); - BN_zero(b); - return b; -} - static int pkey_bits_gost(const EVP_PKEY *pk) { if (!pk) @@ -684,8 +668,8 @@ static int pub_decode_gost_ec(EVP_PKEY *pk, X509_PUBKEY *pub) len = octet->length / 2; ASN1_OCTET_STRING_free(octet); - Y = getbnfrombuf(databuf, len); - X = getbnfrombuf(databuf + len, len); + Y = BN_bin2bn(databuf, len, NULL); + X = BN_bin2bn(databuf + len, len, NULL); OPENSSL_free(databuf); pub_key = EC_POINT_new(group); if (!EC_POINT_set_affine_coordinates_GFp(group, pub_key, X, Y, NULL)) { diff --git a/gost_ec_sign.c b/gost_ec_sign.c index c700ac2..c3e1e01 100644 --- a/gost_ec_sign.c +++ b/gost_ec_sign.c @@ -35,7 +35,7 @@ BIGNUM *hashsum2bn(const unsigned char *dgst, int len) for (i = 0; i < len; i++) { buf[len - i - 1] = dgst[i]; } - return getbnfrombuf(buf, len); + return BN_bin2bn(buf, len, NULL); } static R3410_ec_params *gost_nid2params(int nid) diff --git a/gost_lcl.h b/gost_lcl.h index 3cc15f7..68f40b6 100644 --- a/gost_lcl.h +++ b/gost_lcl.h @@ -245,8 +245,6 @@ BIGNUM *hashsum2bn(const unsigned char *dgst, int len); * nesseccary */ int store_bignum(BIGNUM *bn, unsigned char *buf, int len); -/* Read bignum, which can have few MSB all-zeros from buffer*/ -BIGNUM *getbnfrombuf(const unsigned char *buf, size_t len); /* Pack GOST R 34.10 signature according to CryptoPro rules */ int pack_sign_cp(DSA_SIG *s, int order, unsigned char *sig, size_t *siglen); /* from ameth.c */ -- 2.39.2