16 #define NOTEENCRYPTION_CIPHER_KEYSIZE 32
33 unsigned char block[128] = {};
39 unsigned char personalization[crypto_generichash_blake2b_PERSONALBYTES] = {};
40 memcpy(personalization,
"Zcash_Derive_ock", 16);
49 throw std::logic_error(
"hash function failure");
59 unsigned char block[64] = {};
63 unsigned char personalization[crypto_generichash_blake2b_PERSONALBYTES] = {};
64 memcpy(personalization,
"Zcash_SaplingKDF", 16);
73 throw std::logic_error(
"hash function failure");
86 throw std::logic_error(
"no additional nonce space for KDF");
89 unsigned char block[128] = {};
95 unsigned char personalization[crypto_generichash_blake2b_PERSONALBYTES] = {};
96 memcpy(personalization,
"ZcashKDF", 8);
106 throw std::logic_error(
"hash function failure");
133 throw std::logic_error(
"already encrypted to the recipient using this key");
147 unsigned char cipher_nonce[crypto_aead_chacha20poly1305_IETF_NPUBBYTES] = {};
151 crypto_aead_chacha20poly1305_ietf_encrypt(
152 ciphertext.begin(),
nullptr,
155 nullptr, cipher_nonce, K
180 unsigned char cipher_nonce[crypto_aead_chacha20poly1305_IETF_NPUBBYTES] = {};
184 if (crypto_aead_chacha20poly1305_ietf_decrypt(
185 plaintext.begin(),
nullptr,
190 cipher_nonce, K) != 0)
216 unsigned char cipher_nonce[crypto_aead_chacha20poly1305_IETF_NPUBBYTES] = {};
220 if (crypto_aead_chacha20poly1305_ietf_decrypt(
221 plaintext.begin(),
nullptr,
226 cipher_nonce, K) != 0)
243 throw std::logic_error(
"already encrypted to the recipient using this key");
251 unsigned char cipher_nonce[crypto_aead_chacha20poly1305_IETF_NPUBBYTES] = {};
255 crypto_aead_chacha20poly1305_ietf_encrypt(
256 ciphertext.begin(),
nullptr,
259 nullptr, cipher_nonce, K
280 unsigned char cipher_nonce[crypto_aead_chacha20poly1305_IETF_NPUBBYTES] = {};
284 if (crypto_aead_chacha20poly1305_ietf_decrypt(
285 plaintext.begin(),
nullptr,
290 cipher_nonce, K) != 0)
bool already_encrypted_enc
SaplingOutCiphertext encrypt_to_ourselves(const uint256 &ovk, const uint256 &cv, const uint256 &cm, const SaplingOutPlaintext &message)
static Optional< SaplingNoteEncryption > FromDiversifier(diversifier_t d)
SaplingNoteEncryption(uint256 epk, uint256 esk)
Optional< SaplingEncCiphertext > encrypt_to_recipient(const uint256 &pk_d, const SaplingEncPlaintext &message)
bool already_encrypted_out
void * memcpy(void *a, const void *b, size_t c)
bool librustzcash_sapling_ka_agree(const unsigned char *p, const unsigned char *sk, unsigned char *result)
Compute [sk] [8] P for some 32-byte point P, and 32-byte Fs.
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.
void librustzcash_sapling_generate_r(unsigned char *result)
Generate uniformly random scalar in Jubjub.
std::array< unsigned char, ZC_SAPLING_ENCPLAINTEXT_SIZE > SaplingEncPlaintext
Optional< SaplingEncPlaintext > AttemptSaplingEncDecryption(const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk)
std::array< unsigned char, ZC_SAPLING_OUTPLAINTEXT_SIZE > SaplingOutPlaintext
std::array< unsigned char, ZC_SAPLING_ENCCIPHERTEXT_SIZE > SaplingEncCiphertext
Optional< SaplingOutPlaintext > AttemptSaplingOutDecryption(const SaplingOutCiphertext &ciphertext, const uint256 &ovk, const uint256 &cv, const uint256 &cm, const uint256 &epk)
std::array< unsigned char, ZC_SAPLING_OUTCIPHERTEXT_SIZE > SaplingOutCiphertext
#define NOTEENCRYPTION_CIPHER_KEYSIZE
void KDF_Sapling(unsigned char K[NOTEENCRYPTION_CIPHER_KEYSIZE], const uint256 &dhsecret, const uint256 &epk)
void KDF(unsigned char K[NOTEENCRYPTION_CIPHER_KEYSIZE], const uint256 &dhsecret, const uint256 &epk, const uint256 &pk_enc, const uint256 &hSig, unsigned char nonce)
void PRF_ock(unsigned char K[NOTEENCRYPTION_CIPHER_KEYSIZE], const uint256 &ovk, const uint256 &cv, const uint256 &cm, const uint256 &epk)
void clamp_curve25519(unsigned char key[crypto_scalarmult_SCALARBYTES])
boost::optional< T > Optional
Substitute for C++17 std::optional.
#define ZC_SAPLING_ENCPLAINTEXT_SIZE
std::array< unsigned char, ZC_DIVERSIFIER_SIZE > diversifier_t
#define ZC_SAPLING_ENCCIPHERTEXT_SIZE
#define ZC_SAPLING_OUTPLAINTEXT_SIZE
#define ZC_SAPLING_OUTCIPHERTEXT_SIZE