]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_ameth.c
Add Grasshopper, CMake
[openssl-gost/engine.git] / gost_ameth.c
index f967283dff04529398fe9c3ec0bc59437385d6fb..3d1382e8d517f6721ee019820d8346f8acc289de 100644 (file)
@@ -19,6 +19,8 @@
 #include "gost_lcl.h"
 #include "e_gost_err.h"
 
+#include <internal/evp_int.h>
+
 /*
  * Pack bignum into byte buffer of given size, filling all leading bytes by
  * zeros
@@ -34,22 +36,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 +670,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)) {
@@ -893,6 +879,9 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth,
                                  pkey_size_gost, pkey_bits_gost);
 
         EVP_PKEY_asn1_set_ctrl(*ameth, pkey_ctrl_gost);
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+        EVP_PKEY_asn1_set_security_bits(*ameth, pkey_bits_gost);
+#endif
         break;
     case NID_id_GostR3410_2012_256:
     case NID_id_GostR3410_2012_512: