18 #include <boost/test/unit_test.hpp>
29 libzcash::SaplingPaymentAddress addr = *ivk.address({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
31 std::array<unsigned char, ZC_MEMO_SIZE> memo;
34 memo[i] = (
unsigned char) i;
38 auto cmu_opt = note.
cmu();
40 BOOST_ERROR(
"SaplingNote cm failed");
47 BOOST_ERROR(
"SaplingNotePlaintext encrypt failed");
53 auto encryptor = enc.second;
54 auto epk = encryptor.get_epk();
73 BOOST_ERROR(
"SaplingNotePlaintext decrypt failed");
83 auto foobar = bar.note(ivk);
87 BOOST_ERROR(
"Invalid note");
90 auto new_note = foobar.get();
100 out_pt.
esk = encryptor.get_esk();
113 auto decrypted_out_ct = out_pt.
decrypt(
121 if (!decrypted_out_ct) {
122 BOOST_ERROR(
"SaplingOutgoingPlaintext decrypt failed");
125 auto decrypted_out_ct_unwrapped = decrypted_out_ct.get();
134 decrypted_out_ct_unwrapped.esk,
135 decrypted_out_ct_unwrapped.pk_d,
143 decrypted_out_ct_unwrapped.esk,
144 decrypted_out_ct_unwrapped.pk_d,
149 BOOST_ERROR(
"Sender decrypt note ciphertext failed.");
166 libzcash::SaplingPaymentAddress pk_1 = *ivk.address({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
167 libzcash::SaplingPaymentAddress pk_2 = *ivk.address({4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
170 std::array<unsigned char, ZC_SAPLING_ENCPLAINTEXT_SIZE> message;
173 message[i] = (
unsigned char) i;
176 std::array<unsigned char, ZC_SAPLING_OUTPLAINTEXT_SIZE> small_message;
179 small_message[i] = (
unsigned char) i;
183 BOOST_CHECK(boost::none ==
libzcash::SaplingNoteEncryption::FromDiversifier({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
187 auto ciphertext_1 = *enc.encrypt_to_recipient(
191 auto epk_1 = enc.get_epk();
194 uint256 test_esk = enc.get_esk();
200 auto out_ciphertext_1 = enc.encrypt_to_ourselves(
209 auto ciphertext_2 = *enc.encrypt_to_recipient(
213 auto epk_2 = enc.get_epk();
217 auto out_ciphertext_2 = enc.encrypt_to_ourselves(
228 tmp_enc.encrypt_to_recipient(
236 ), std::logic_error);
238 tmp_enc.encrypt_to_ourselves(
250 ), std::logic_error);
const std::array< unsigned char, ZC_MEMO_SIZE > & memo() const
SaplingFullViewingKey full_viewing_key() const
SaplingIncomingViewingKey in_viewing_key() const
static Optional< SaplingNoteEncryption > FromDiversifier(diversifier_t d)
Optional< uint256 > cmu() const
Optional< SaplingNotePlaintextEncryptionResult > encrypt(const uint256 &pk_d) const
static Optional< SaplingNotePlaintext > decrypt(const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk, const uint256 &cmu)
SaplingOutCiphertext encrypt(const uint256 &ovk, const uint256 &cv, const uint256 &cm, SaplingNoteEncryption &enc) const
static Optional< SaplingOutgoingPlaintext > decrypt(const SaplingOutCiphertext &ciphertext, const uint256 &ovk, const uint256 &cv, const uint256 &cm, const uint256 &epk)
SaplingExpandedSpendingKey expanded_spending_key() const
BOOST_AUTO_TEST_SUITE_END()
bool librustzcash_sapling_ka_derivepublic(const unsigned char *diversifier, const unsigned char *esk, unsigned char *result)
Compute g_d = GH(diversifier) and returns false if the diversifier is invalid.
Optional< SaplingEncPlaintext > AttemptSaplingEncDecryption(const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk)
Optional< SaplingOutPlaintext > AttemptSaplingOutDecryption(const SaplingOutCiphertext &ciphertext, const uint256 &ovk, const uint256 &cv, const uint256 &cm, const uint256 &epk)
BOOST_AUTO_TEST_CASE(note_plain_text_test)
#define BOOST_CHECK_THROW(stmt, excMatch)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK(expr)
#define ZC_SAPLING_ENCPLAINTEXT_SIZE
#define ZC_SAPLING_OUTPLAINTEXT_SIZE