Prevent nonce reuse in Sapling note encryption API.

This commit is contained in:
Sean Bowe
2018-06-14 12:21:28 -06:00
parent 90073aeca5
commit c03e22612d
3 changed files with 45 additions and 1 deletions

View File

@@ -78,6 +78,35 @@ TEST(noteencryption, sapling_api)
small_message
);
// Test nonce-reuse resistance of API
{
auto tmp_enc = *SaplingNoteEncryption::FromDiversifier(pk_1.d);
tmp_enc.encrypt_to_recipient(
pk_1.pk_d,
message
);
ASSERT_THROW(tmp_enc.encrypt_to_recipient(
pk_1.pk_d,
message
), std::logic_error);
tmp_enc.encrypt_to_ourselves(
sk.ovk,
cv_2,
cm_2,
small_message
);
ASSERT_THROW(tmp_enc.encrypt_to_ourselves(
sk.ovk,
cv_2,
cm_2,
small_message
), std::logic_error);
}
// Try to decrypt
auto plaintext_1 = *AttemptSaplingEncDecryption(
ciphertext_1,