PIVX Core  5.6.99
P2P Digital Currency
noteencryption.h
Go to the documentation of this file.
1 // Copyright (c) 2016-2020 The ZCash developers
2 // Copyright (c) 2021 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
5 
6 /*
7 See the Zcash protocol specification for more information.
8 https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
9 */
10 
11 #ifndef PIVX_SAPLING_NOTEENCRYPTION_H
12 #define PIVX_SAPLING_NOTEENCRYPTION_H
13 
14 #include "optional.h"
15 #include "sapling/sapling.h"
16 #include "uint256.h"
17 
18 #include <array>
19 
20 namespace libzcash {
21 
22 // Ciphertext for the recipient to decrypt
23 typedef std::array<unsigned char, ZC_SAPLING_ENCCIPHERTEXT_SIZE> SaplingEncCiphertext;
24 typedef std::array<unsigned char, ZC_SAPLING_ENCPLAINTEXT_SIZE> SaplingEncPlaintext;
25 
26 // Ciphertext for outgoing viewing key to decrypt
27 typedef std::array<unsigned char, ZC_SAPLING_OUTCIPHERTEXT_SIZE> SaplingOutCiphertext;
28 typedef std::array<unsigned char, ZC_SAPLING_OUTPLAINTEXT_SIZE> SaplingOutPlaintext;
29 
32 protected:
33  // Ephemeral public key
35 
36  // Ephemeral secret key
38 
41 
43 
44  }
45 
46 public:
47 
49 
51  const uint256 &pk_d,
52  const SaplingEncPlaintext &message
53  );
54 
56  const uint256 &ovk,
57  const uint256 &cv,
58  const uint256 &cm,
59  const SaplingOutPlaintext &message
60  );
61 
62  uint256 get_epk() const {
63  return epk;
64  }
65 
66  uint256 get_esk() const {
67  return esk;
68  }
69 };
70 
71 // Attempts to decrypt a Sapling note. This will not check that the contents
72 // of the ciphertext are correct.
74  const SaplingEncCiphertext &ciphertext,
75  const uint256 &ivk,
76  const uint256 &epk
77 );
78 
79 // Attempts to decrypt a Sapling note using outgoing plaintext.
80 // This will not check that the contents of the ciphertext are correct.
82  const SaplingEncCiphertext &ciphertext,
83  const uint256 &epk,
84  const uint256 &esk,
85  const uint256 &pk_d
86 );
87 
88 // Attempts to decrypt a Sapling note. This will not check that the contents
89 // of the ciphertext are correct.
91  const SaplingOutCiphertext &ciphertext,
92  const uint256 &ovk,
93  const uint256 &cv,
94  const uint256 &cm,
95  const uint256 &epk
96 );
97 
98 }
99 
100 #endif // PIVX_SAPLING_NOTEENCRYPTION_H
false
Definition: bls_dkg.cpp:151
This is not a thread-safe API.
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)
256-bit opaque blob.
Definition: uint256.h:138
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
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
std::array< unsigned char, ZC_DIVERSIFIER_SIZE > diversifier_t
Definition: sapling.h:38