summaryrefslogtreecommitdiff
path: root/validat7.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-12-25 18:16:14 -0500
committerJeffrey Walton <noloader@gmail.com>2018-12-25 18:16:14 -0500
commit2ccac19de11fa891acca207c5d44e3b0ce0a248e (patch)
treef48de2ee9b67180110a454bbe154c88710b37c26 /validat7.cpp
parent0311daf7e20922ca628af99187d1469f7411370e (diff)
downloadcryptopp-git-2ccac19de11fa891acca207c5d44e3b0ce0a248e.tar.gz
Use variable length messages in TestEd25519
Diffstat (limited to 'validat7.cpp')
-rw-r--r--validat7.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/validat7.cpp b/validat7.cpp
index 8dfa40da..e1e06bd3 100644
--- a/validat7.cpp
+++ b/validat7.cpp
@@ -436,6 +436,7 @@ bool TestEd25519()
std::cout << "\nTesting ed25519 Signatures...\n\n";
bool pass = true;
+ // Test key loads
try {
FileSource f1(DataDir("TestData/ed25519.dat").c_str(), true, new HexDecoder);
FileSource f2(DataDir("TestData/ed25519v0.dat").c_str(), true, new HexDecoder);
@@ -496,13 +497,14 @@ bool TestEd25519()
// Message and signatures
byte msg[MSG_SIZE], sig1[MSG_SIZE+NACL_EXTRA], sig2[64];
GlobalRNG().GenerateBlock(msg, MSG_SIZE);
+ size_t len = GlobalRNG().GenerateWord32(0, MSG_SIZE);
// Spike the signatures
sig1[1] = 1; sig2[2] = 2;
word64 smlen = sizeof(sig1);
- int ret1 = NaCl::crypto_sign(sig1, &smlen, msg, MSG_SIZE, sk1);
- int ret2 = Donna::ed25519_sign(msg, MSG_SIZE, sk2, pk2, sig2);
+ int ret1 = NaCl::crypto_sign(sig1, &smlen, msg, len, sk1);
+ int ret2 = Donna::ed25519_sign(msg, len, sk2, pk2, sig2);
int ret3 = std::memcmp(sig1, sig2, 64);
bool fail = ret1 != 0 || ret2 != 0 || ret3 != 0;
@@ -527,14 +529,15 @@ bool TestEd25519()
byte msg1[MSG_SIZE+NACL_EXTRA], msg2[MSG_SIZE];
byte sig1[MSG_SIZE+NACL_EXTRA], sig2[64];
GlobalRNG().GenerateBlock(msg1, MSG_SIZE);
- std::memcpy(msg2, msg1, MSG_SIZE);
+ size_t len = GlobalRNG().GenerateWord32(0, MSG_SIZE);
+ std::memcpy(msg2, msg1, len);
// Spike the signatures
sig1[1] = 1; sig2[2] = 2;
word64 smlen = sizeof(sig1);
- int ret1 = NaCl::crypto_sign(sig1, &smlen, msg1, MSG_SIZE, sk1);
- int ret2 = Donna::ed25519_sign(msg2, MSG_SIZE, sk2, pk2, sig2);
+ int ret1 = NaCl::crypto_sign(sig1, &smlen, msg1, len, sk1);
+ int ret2 = Donna::ed25519_sign(msg2, len, sk2, pk2, sig2);
int ret3 = std::memcmp(sig1, sig2, 64);
bool tamper = !!GlobalRNG().GenerateBit();
@@ -545,9 +548,9 @@ bool TestEd25519()
}
// Verify the other's signature using the other's key
- word64 mlen = MSG_SIZE+NACL_EXTRA;
+ word64 mlen = len+NACL_EXTRA;
int ret4 = NaCl::crypto_sign_open(msg1, &mlen, sig1, smlen, pk2);
- int ret5 = Donna::ed25519_sign_open(msg2, MSG_SIZE, pk1, sig2);
+ int ret5 = Donna::ed25519_sign_open(msg2, len, pk1, sig2);
bool fail = ret1 != 0 || ret2 != 0 || ret3 != 0 || ((ret4 != 0) ^ tamper) || ((ret5 != 0) ^ tamper);
pass = pass && !fail;