]> granicus.if.org Git - pdns/commitdiff
Fix "random" ECDSA signature failures when using cryptopp
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 23 Dec 2015 23:58:49 +0000 (00:58 +0100)
committermind04 <mind04@monshouwer.org>
Thu, 24 Dec 2015 00:02:02 +0000 (01:02 +0100)
pdns/cryptoppsigners.cc

index 348ac81246e5e63aa1685eee4427d27d5b1d872d..df4241da83d59466595d97ffbce2b84cbc1830c0 100644 (file)
@@ -80,8 +80,9 @@ DNSCryptoKeyEngine::storvector_t CryptoPPECDSADNSCryptoKeyEngine<HASHER,CURVE,BI
   storvect.push_back(make_pair("Algorithm", algostr));
   
   const CryptoPP::Integer& pe=d_key->GetPrivateExponent();
-  unsigned char buffer[pe.MinEncodedSize()];
-  pe.Encode(buffer, pe.MinEncodedSize());
+  size_t len = BITS/8;
+  unsigned char buffer[len];
+  pe.Encode(buffer, len);
   storvect.push_back(make_pair("PrivateKey", string((char*)buffer, sizeof(buffer))));
   return storvect;
 }
@@ -117,11 +118,12 @@ std::string CryptoPPECDSADNSCryptoKeyEngine<HASHER,CURVE,BITS>::getPublicKeyStri
 
   const CryptoPP::Integer& qx = q.x;
   const CryptoPP::Integer& qy = q.y;
-  
-  unsigned char buffer[qx.MinEncodedSize() + qy.MinEncodedSize()];
-  qx.Encode(buffer, qx.MinEncodedSize());
-  qy.Encode(buffer + qx.MinEncodedSize(), qy.MinEncodedSize());
-  
+
+  size_t len = BITS/8;
+  unsigned char buffer[len*2];
+  qx.Encode(buffer, len);
+  qy.Encode(buffer + len, len);
+
   return string((char*)buffer, sizeof(buffer));
 }
 template<class HASHER, class CURVE, int BITS>