Browse Source

EdDSA blinding test

pull/1813/head
orignal 2 years ago
parent
commit
b4c226f4b3
  1. 18
      tests/test-blinding.cpp

18
tests/test-blinding.cpp

@ -16,28 +16,26 @@ void BlindTest (SigningKeyType sigType)
auto timestamp = GetSecondsSinceEpoch (); auto timestamp = GetSecondsSinceEpoch ();
char date[9]; char date[9];
GetDateString (timestamp, date); GetDateString (timestamp, date);
uint8_t blindedPriv[64], blindedPub[128]; uint8_t blindedPriv[32], blindedPub[32];
auto publicKeyLen = blindedKey.BlindPrivateKey (keys.GetSigningPrivateKey (), date, blindedPriv, blindedPub); auto publicKeyLen = blindedKey.BlindPrivateKey (keys.GetSigningPrivateKey (), date, blindedPriv, blindedPub);
uint8_t blindedPub1[128]; uint8_t blindedPub1[32];
blindedKey.GetBlindedKey (date, blindedPub1); blindedKey.GetBlindedKey (date, blindedPub1);
// check if public key produced from private blinded key matches blided public key // check if public key produced from private blinded key matches blided public key
assert (!memcmp (blindedPub, blindedPub1, publicKeyLen)); assert (!memcmp (blindedPub, blindedPub1, publicKeyLen));
// try to sign and verify // try to sign and verify
std::unique_ptr<Signer> blindedSigner (PrivateKeys::CreateSigner (sigType, blindedPriv)); std::unique_ptr<Signer> blindedSigner (PrivateKeys::CreateSigner (blindedKey.GetBlindedSigType (), blindedPriv));
uint8_t buf[100], signature[128]; uint8_t buf[100], signature[64];
memset (buf, 1, 100); memset (buf, 1, 100);
blindedSigner->Sign (buf, 100, signature); blindedSigner->Sign (buf, 100, signature);
std::unique_ptr<Verifier> blindedVerifier (IdentityEx::CreateVerifier (sigType)); std::unique_ptr<Verifier> blindedVerifier (IdentityEx::CreateVerifier (blindedKey.GetBlindedSigType ()));
blindedVerifier->SetPublicKey (blindedPub1); blindedVerifier->SetPublicKey (blindedPub);
assert (blindedVerifier->Verify (buf, 100, signature)); assert (blindedVerifier->Verify (buf, 100, signature));
} }
int main () int main ()
{ {
// EdDSA test
BlindTest (SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519);
// RedDSA test // RedDSA test
BlindTest (SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519); BlindTest (SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519);
// P256 test
BlindTest (SIGNING_KEY_TYPE_ECDSA_SHA256_P256);
// P384 test
BlindTest (SIGNING_KEY_TYPE_ECDSA_SHA384_P384);
} }

Loading…
Cancel
Save