Monero
Loading...
Searching...
No Matches
rctSigs.h
Go to the documentation of this file.
1// Copyright (c) 2016, Monero Research Labs
2//
3// Author: Shen Noether <shen.noether@gmx.com>
4//
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without modification, are
8// permitted provided that the following conditions are met:
9//
10// 1. Redistributions of source code must retain the above copyright notice, this list of
11// conditions and the following disclaimer.
12//
13// 2. Redistributions in binary form must reproduce the above copyright notice, this list
14// of conditions and the following disclaimer in the documentation and/or other
15// materials provided with the distribution.
16//
17// 3. Neither the name of the copyright holder nor the names of its contributors may be
18// used to endorse or promote products derived from this software without specific
19// prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
22// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
24// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#pragma once
32
33//#define DBG
34
35#ifndef RCTSIGS_H
36#define RCTSIGS_H
37
38#include <cstddef>
39#include <vector>
40#include <tuple>
41
42#include "crypto/generic-ops.h"
43
44extern "C" {
45#include "crypto/random.h"
46#include "crypto/keccak.h"
47}
48#include "crypto/crypto.h"
49
50
51#include "rctTypes.h"
52#include "rctOps.h"
53
54//Define this flag when debugging to get additional info on the console
55#ifdef DBG
56#define DP(x) dp(x)
57#else
58#define DP(x)
59#endif
60
61namespace hw {
62 class device;
63}
64
65
66namespace rct {
67
68 boroSig genBorromean(const key64 x, const key64 P1, const key64 P2, const bits indices);
69 bool verifyBorromean(const boroSig &bb, const key64 P1, const key64 P2);
70
71 //Multilayered Spontaneous Anonymous Group Signatures (MLSAG signatures)
72 //These are aka MG signatutes in earlier drafts of the ring ct paper
73 // c.f. https://eprint.iacr.org/2015/1098 section 2.
74 // Gen creates a signature which proves that for some column in the keymatrix "pk"
75 // the signer knows a secret key for each row in that column
76 // Ver verifies that the MG sig was created correctly
77 mgSig MLSAG_Gen(const key &message, const keyM & pk, const keyV & xx, const unsigned int index, size_t dsRows, hw::device &hwdev);
78 bool MLSAG_Ver(const key &message, const keyM &pk, const mgSig &sig, size_t dsRows);
79
80 clsag CLSAG_Gen(const key &message, const keyV & P, const key & p, const keyV & C, const key & z, const keyV & C_nonzero, const key & C_offset, const unsigned int l, hw::device &hwdev);
81 clsag CLSAG_Gen(const key &message, const keyV & P, const key & p, const keyV & C, const key & z, const keyV & C_nonzero, const key & C_offset, const unsigned int l);
82 clsag proveRctCLSAGSimple(const key &, const ctkeyV &, const ctkey &, const key &, const key &, unsigned int, hw::device &);
83 bool verRctCLSAGSimple(const key &, const clsag &, const ctkeyV &, const key &);
84
85 //proveRange and verRange
86 //proveRange gives C, and mask such that \sumCi = C
87 // c.f. https://eprint.iacr.org/2015/1098 section 5.1
88 // and Ci is a commitment to either 0 or 2^i, i=0,...,63
89 // thus this proves that "amount" is in [0, 2^64]
90 // mask is a such that C = aG + bH, and b = amount
91 //verRange verifies that \sum Ci = C and that each Ci is a commitment to 0 or 2^i
92 rangeSig proveRange(key & C, key & mask, const xmr_amount & amount);
93 bool verRange(const key & C, const rangeSig & as);
94
95 //Ring-ct MG sigs
96 //Prove:
97 // c.f. https://eprint.iacr.org/2015/1098 section 4. definition 10.
98 // This does the MG sig on the "dest" part of the given key matrix, and
99 // the last row is the sum of input commitments from that column - sum output commitments
100 // this shows that sum inputs = sum outputs
101 //Ver:
102 // verifies the above sig is created corretly
103 mgSig proveRctMG(const ctkeyM & pubs, const ctkeyV & inSk, const keyV &outMasks, const ctkeyV & outPk, unsigned int index, const key &txnFee, const key &message, hw::device &hwdev);
104 mgSig proveRctMGSimple(const key & message, const ctkeyV & pubs, const ctkey & inSk, const key &a , const key &Cout, unsigned int index, hw::device &hwdev);
105 bool verRctMG(const mgSig &mg, const ctkeyM & pubs, const ctkeyV & outPk, const key &txnFee, const key &message);
106 bool verRctMGSimple(const key &message, const mgSig &mg, const ctkeyV & pubs, const key & C);
107
108 //These functions get keys from blockchain
109 //replace these when connecting blockchain
110 //getKeyFromBlockchain grabs a key from the blockchain at "reference_index" to mix with
111 //populateFromBlockchain creates a keymatrix with "mixin" columns and one of the columns is inPk
112 // the return value are the key matrix, and the index where inPk was put (random).
113 void getKeyFromBlockchain(ctkey & a, size_t reference_index);
114 std::tuple<ctkeyM, xmr_amount> populateFromBlockchain(ctkeyV inPk, int mixin);
115
116 //RingCT protocol
117 //genRct:
118 // creates an rctSig with all data necessary to verify the rangeProofs and that the signer owns one of the
119 // columns that are claimed as inputs, and that the sum of inputs = sum of outputs.
120 // Also contains masked "amount" and "mask" so the receiver can see how much they received
121 //verRct:
122 // verifies that all signatures (rangeProogs, MG sig, sum inputs = outputs) are correct
123 //decodeRct: (c.f. https://eprint.iacr.org/2015/1098 section 5.1.1)
124 // uses the attached ecdh info to find the amounts represented by each output commitment
125 // must know the destination private key to find the correct amount, else will return a random number
126 rctSig genRct(const key &message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const ctkeyM &mixRing, const keyV &amount_keys, unsigned int index, ctkeyV &outSk, const RCTConfig &rct_config, hw::device &hwdev);
127 rctSig genRct(const key &message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const keyV &amount_keys, const int mixin, const RCTConfig &rct_config, hw::device &hwdev);
128 rctSig genRctSimple(const key & message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, const keyV &amount_keys, xmr_amount txnFee, unsigned int mixin, const RCTConfig &rct_config, hw::device &hwdev);
129 rctSig genRctSimple(const key & message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, xmr_amount txnFee, const ctkeyM & mixRing, const keyV &amount_keys, const std::vector<unsigned int> & index, ctkeyV &outSk, const RCTConfig &rct_config, hw::device &hwdev);
130 bool verRct(const rctSig & rv, bool semantics);
131 static inline bool verRct(const rctSig & rv) { return verRct(rv, true) && verRct(rv, false); }
132 bool verRctSemanticsSimple(const rctSig & rv);
133 bool verRctSemanticsSimple(const std::vector<const rctSig*> & rv);
134 bool verRctNonSemanticsSimple(const rctSig & rv);
135 static inline bool verRctSimple(const rctSig & rv) { return verRctSemanticsSimple(rv) && verRctNonSemanticsSimple(rv); }
136 xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
137 xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
138 xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
139 xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
140 key get_pre_mlsag_hash(const rctSig &rv, hw::device &hwdev);
141}
142#endif /* RCTSIGS_H */
143
Definition device.hpp:87
const char * key
Definition hmac_keccak.cpp:40
Definition device.cpp:38
Definition bulletproofs.cc:64
rangeSig proveRange(key &C, key &mask, const xmr_amount &amount)
Definition rctSigs.cpp:533
clsag CLSAG_Gen(const key &message, const keyV &P, const key &p, const keyV &C, const key &z, const keyV &C_nonzero, const key &C_offset, const unsigned int l, hw::device &hwdev)
Definition rctSigs.cpp:241
std::vector< key > keyV
Definition rctTypes.h:89
std::vector< keyV > keyM
Definition rctTypes.h:90
std::vector< ctkeyV > ctkeyM
Definition rctTypes.h:110
void getKeyFromBlockchain(ctkey &a, size_t reference_index)
Definition rctSigs.cpp:991
bool verRange(const key &C, const rangeSig &as)
Definition rctSigs.cpp:565
key get_pre_mlsag_hash(const rctSig &rv, hw::device &hwdev)
Definition rctSigs.cpp:600
tuple< ctkeyM, xmr_amount > populateFromBlockchain(ctkeyV inPk, int mixin)
Definition rctSigs.cpp:1001
bool verRctCLSAGSimple(const key &message, const clsag &sig, const ctkeyV &pubs, const key &C_offset)
Definition rctSigs.cpp:872
static bool verRctSimple(const rctSig &rv)
Definition rctSigs.h:135
boroSig genBorromean(const key64 x, const key64 P1, const key64 P2, const bits indices)
Definition rctSigs.cpp:176
key key64[64]
Definition rctTypes.h:153
bool verRct(const rctSig &rv, bool semantics)
Definition rctSigs.cpp:1318
rctSig genRctSimple(const key &message, const ctkeyV &inSk, const keyV &destinations, const vector< xmr_amount > &inamounts, const vector< xmr_amount > &outamounts, xmr_amount txnFee, const ctkeyM &mixRing, const keyV &amount_keys, const std::vector< unsigned int > &index, ctkeyV &outSk, const RCTConfig &rct_config, hw::device &hwdev)
Definition rctSigs.cpp:1105
unsigned int bits[ATOMS]
Definition rctTypes.h:152
mgSig proveRctMGSimple(const key &message, const ctkeyV &pubs, const ctkey &inSk, const key &a, const key &Cout, unsigned int index, hw::device &hwdev)
Definition rctSigs.cpp:743
clsag proveRctCLSAGSimple(const key &message, const ctkeyV &pubs, const ctkey &inSk, const key &a, const key &Cout, unsigned int index, hw::device &hwdev)
Definition rctSigs.cpp:764
rctSig genRct(const key &message, const ctkeyV &inSk, const keyV &destinations, const vector< xmr_amount > &amounts, const ctkeyM &mixRing, const keyV &amount_keys, unsigned int index, ctkeyV &outSk, const RCTConfig &rct_config, hw::device &hwdev)
Definition rctSigs.cpp:1046
std::vector< ctkey > ctkeyV
Definition rctTypes.h:109
xmr_amount decodeRctSimple(const rctSig &rv, const key &sk, unsigned int i, key &mask, hw::device &hwdev)
Definition rctSigs.cpp:1621
bool verRctSemanticsSimple(const std::vector< const rctSig * > &rvv)
Definition rctSigs.cpp:1381
bool verRctNonSemanticsSimple(const rctSig &rv)
Definition rctSigs.cpp:1521
uint64_t xmr_amount
Definition rctTypes.h:151
bool verRctMGSimple(const key &message, const mgSig &mg, const ctkeyV &pubs, const key &C)
Definition rctSigs.cpp:841
mgSig proveRctMG(const key &message, const ctkeyM &pubs, const ctkeyV &inSk, const ctkeyV &outSk, const ctkeyV &outPk, unsigned int index, const key &txnFeeKey, hw::device &hwdev)
Definition rctSigs.cpp:687
bool MLSAG_Ver(const key &message, const keyM &pk, const mgSig &rv, size_t dsRows)
Definition rctSigs.cpp:460
xmr_amount decodeRct(const rctSig &rv, const key &sk, unsigned int i, key &mask, hw::device &hwdev)
Definition rctSigs.cpp:1591
bool verifyBorromean(const boroSig &bb, const ge_p3 P1[64], const ge_p3 P2[64])
Definition rctSigs.cpp:208
mgSig MLSAG_Gen(const key &message, const keyM &pk, const keyV &xx, const unsigned int index, size_t dsRows, hw::device &hwdev)
Definition rctSigs.cpp:375
bool verRctMG(const mgSig &mg, const ctkeyM &pubs, const ctkeyV &outPk, const key &txnFeeKey, const key &message)
Definition rctSigs.cpp:802
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
Definition minissdpd.c:75
Definition rctTypes.h:308
Definition rctTypes.h:155
Definition rctTypes.h:181
Definition rctTypes.h:97
Definition rctTypes.h:79
Definition rctTypes.h:168
Definition rctTypes.h:202
Definition rctTypes.h:613