Implementation of Sapling in-band secret distribution.
This commit is contained in:
@@ -10,12 +10,70 @@ https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
|
||||
#include "uint252.h"
|
||||
|
||||
#include "zcash/Zcash.h"
|
||||
#include "zcash/Address.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace libzcash {
|
||||
|
||||
#define NOTEENCRYPTION_AUTH_BYTES 16
|
||||
// Ciphertext for the recipient to decrypt
|
||||
typedef std::array<unsigned char, ZC_SAPLING_ENCCIPHERTEXT_SIZE> SaplingEncCiphertext;
|
||||
typedef std::array<unsigned char, ZC_SAPLING_ENCPLAINTEXT_SIZE> SaplingEncPlaintext;
|
||||
|
||||
// Ciphertext for outgoing viewing key to decrypt
|
||||
typedef std::array<unsigned char, ZC_SAPLING_OUTCIPHERTEXT_SIZE> SaplingOutCiphertext;
|
||||
typedef std::array<unsigned char, ZC_SAPLING_OUTPLAINTEXT_SIZE> SaplingOutPlaintext;
|
||||
|
||||
class SaplingNoteEncryption {
|
||||
protected:
|
||||
// Ephemeral public key
|
||||
uint256 epk;
|
||||
|
||||
// Ephemeral secret key
|
||||
uint256 esk;
|
||||
|
||||
SaplingNoteEncryption(uint256 epk, uint256 esk) : epk(epk), esk(esk) {
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static boost::optional<SaplingNoteEncryption> FromDiversifier(diversifier_t d);
|
||||
|
||||
boost::optional<SaplingEncCiphertext> encrypt_to_recipient(
|
||||
const uint256 &pk_d,
|
||||
const SaplingEncPlaintext &message
|
||||
);
|
||||
|
||||
SaplingOutCiphertext encrypt_to_ourselves(
|
||||
const uint256 &ovk,
|
||||
const uint256 &cv,
|
||||
const uint256 &cm,
|
||||
const SaplingOutPlaintext &message
|
||||
);
|
||||
|
||||
uint256 get_epk() const {
|
||||
return epk;
|
||||
}
|
||||
};
|
||||
|
||||
// Attempts to decrypt a Sapling note. This will not check that the contents
|
||||
// of the ciphertext are correct.
|
||||
boost::optional<SaplingEncPlaintext> AttemptSaplingEncDecryption(
|
||||
const SaplingEncCiphertext &ciphertext,
|
||||
const uint256 &ivk,
|
||||
const uint256 &epk
|
||||
);
|
||||
|
||||
// Attempts to decrypt a Sapling note. This will not check that the contents
|
||||
// of the ciphertext are correct.
|
||||
boost::optional<SaplingOutPlaintext> AttemptSaplingOutDecryption(
|
||||
const SaplingOutCiphertext &ciphertext,
|
||||
const uint256 &ovk,
|
||||
const uint256 &cv,
|
||||
const uint256 &cm,
|
||||
const uint256 &epk
|
||||
);
|
||||
|
||||
template<size_t MLEN>
|
||||
class NoteEncryption {
|
||||
|
||||
Reference in New Issue
Block a user