I'm trying to run the FIPS 186-3 ECDSA test vectors to check that I'm using 
the Crypto++ library (5.6.1) correctly, but I'm running into trouble 
reproducing FIPS's results for any hash function other than SHA-1.  I 
assume I must be using the library incorrectly.  Can anyone show me what 
I'm doing wrong?  I've provided some relevant snippets of my code below.


byte                           digest1[SHA1::DIGESTSIZE];
byte                           digest256[SHA256::DIGESTSIZE];
ECDSA<ECP, SHA1>::PrivateKey   signer192sha1;
ECDSA<ECP, SHA256>::PrivateKey signer192sha256;
ECDSA<ECP, SHA1>::Signer       signer192sha1;
ECDSA<ECP, SHA256>::Signer     signer192sha256;

...
// qx, qy, d, k, and line(containing the message) all provided by FIPS

q  = ECPPoint(qx,qy);

// line contains "Msg = <Message>.  Hence, (line.length() - 6)/2 is the 
number of bytes in <Message>
// data is a byte array containing the message

if        (strcmp (sha.c_str(), "SHA1") == 0) {
  SHA1().CalculateDigest(digest1, data, (line.length() - 6)/2);
  e = Integer(digest1, SHA1::DIGESTSIZE);

  privateKey192sha1.Initialize( ASN::secp192r1(), d);
  signer192sha1 = ECDSA<ECP, SHA1>::Signer(privateKey192sha1);

  publicKey192sha1.Initialize(ASN1::secp192r1(), q);
  result = publicKey192sha1.Validate(rng, 3);

  signer192sha1.RawSign(k, e, r, s);

} else if (strcmp (sha.c_str(), "SHA256") == 0) {
  SHA256().CalculateDigest(digest256, data, (line.length() - 6)/2);
  e = Integer(digest256, SHA256::DIGESTSIZE);

  privateKey192sha256.Initialize( ASN::secp192r1(), d);
  signer192sha256 = ECDSA<ECP, SHA256>::Signer(privateKey192sha256);

  publicKey192sha256.Initialize(ASN1::secp192r1(), q);
  result = publicKey192sha256.Validate(rng, 3);

  signer192sha256.RawSign(k, e, r, s);
} 

cout << "E:  " << std::hex << e << endl;
cout << "R:  " << std::hex << r << endl;
cout << "S:  " << std::hex << s << endl;

// E matches a second SHA implementation.  R matches FIPS.
// S matches FIPS in the SHA1 case but not SHA256 (or any of the other SHA2 
hashes)


-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to