Skip to content

Commit d9ee55e

Browse files
committed
Add randomness to rcm1 (rcm1 in created by the client, so it's deterministic)
1 parent 8d150a2 commit d9ee55e

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

utt/include/client.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Client {
6969
*
7070
* @return Commitment
7171
*/
72-
Commitment generateInputRCM();
72+
Commitment generateInputRCM(uint64_t nonce = 0);
7373

7474
/**
7575
* @brief The full PRF key is composed by a client secret (s1) and an unpredictable s2 (choose by the bank). This

utt/include/commitment.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class Commitment {
5151
* @param withG2 Indicates if we want to have the commitment in the G2 group. In the regular case this should be
5252
* always true
5353
*/
54-
Commitment(const UTTParams& p, Type t, const std::vector<types::CurvePoint>& messages, bool withG2);
54+
Commitment(
55+
const UTTParams& p, Type t, const std::vector<types::CurvePoint>& messages, bool withG2, uint64_t nonce = 0);
5556
Commitment(const Commitment& comm);
5657
Commitment();
5758
Commitment& operator=(const Commitment&);

utt/libutt/src/api/client.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <utt/DataUtils.hpp>
1414
#include <vector>
1515
#include <sstream>
16+
#include <random>
1617
namespace libutt::api {
1718
Client::Client(const std::string& pid, const std::string& bpk, const std::string& rvk, const std::string& rsaSk) {
1819
if (pid.empty() || bpk.empty() || rvk.empty() || rsaSk.empty())
@@ -68,9 +69,17 @@ Client& Client::operator=(Client&& other) {
6869
pImpl_->decryptor_ = std::move(other.pImpl_->decryptor_);
6970
return *this;
7071
}
71-
Commitment Client::generateInputRCM() {
72+
Commitment Client::generateInputRCM(uint64_t nonce) {
7273
Commitment comm;
73-
auto h1 = hashToHex(getPidHash());
74+
if (nonce == 0) {
75+
std::random_device rd;
76+
std::mt19937_64 gen(rd());
77+
std::uniform_int_distribution<uint64_t> dis;
78+
comm.pImpl_->nonce = dis(gen);
79+
}
80+
auto hash_base = getPidHash();
81+
hash_base.push_back(comm.pImpl_->nonce);
82+
auto h1 = hashToHex(hash_base);
7483
G1 H = libutt::hashToGroup<G1>("ps16base|" + h1);
7584
comm.pImpl_->comm_ = (pImpl_->ask_.s * H);
7685
return comm;

utt/libutt/src/api/commitment.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ libutt::api::Commitment operator+(libutt::api::Commitment lhs, const libutt::api
1010
}
1111

1212
std::ostream& operator<<(std::ostream& out, const libutt::api::Commitment& comm) {
13-
out << comm.pImpl_->comm_;
13+
out << comm.pImpl_->comm_ << endl;
14+
out << comm.pImpl_->nonce << endl;
1415
return out;
1516
}
1617
std::istream& operator>>(std::istream& in, libutt::api::Commitment& comm) {
1718
in >> comm.pImpl_->comm_;
19+
libff::consume_OUTPUT_NEWLINE(in);
20+
in >> comm.pImpl_->nonce;
21+
libff::consume_OUTPUT_NEWLINE(in);
1822
return in;
1923
}
2024

@@ -25,12 +29,14 @@ bool operator==(const libutt::api::Commitment& comm1, const libutt::api::Commitm
2529
}
2630
namespace libutt::api {
2731

28-
Commitment::Commitment(const UTTParams& d, Type t, const std::vector<types::CurvePoint>& messages, bool withG2) {
32+
Commitment::Commitment(
33+
const UTTParams& d, Type t, const std::vector<types::CurvePoint>& messages, bool withG2, uint64_t nonce) {
2934
std::vector<Fr> fr_messages(messages.size());
3035
for (size_t i = 0; i < messages.size(); i++) {
3136
fr_messages[i].from_words(messages.at(i));
3237
}
3338
pImpl_ = new Commitment::Impl();
39+
pImpl_->nonce = nonce;
3440
pImpl_->comm_ =
3541
libutt::Comm::create(Impl::getCommitmentKey(d.pImpl_->p, (Commitment::Impl::Type)t), fr_messages, withG2);
3642
}

utt/libutt/src/api/include/commitment.impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace libutt::api {
66
struct Commitment::Impl {
77
enum Type { REGISTRATION = 0, COIN };
88
libutt::Comm comm_;
9+
uint64_t nonce = 0;
910
static const libutt::CommKey& getCommitmentKey(const libutt::Params& d, Type t) {
1011
switch (t) {
1112
case Type::REGISTRATION:

utt/libutt/src/api/registrator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ std::pair<types::CurvePoint, types::Signature> Registrator::signRCM(const types:
4747
fr_pid.from_words(pid_hash);
4848
Fr fr_s2;
4949
fr_s2.from_words(s2);
50-
auto h1 = hashToHex(pid_hash);
50+
auto hash_base = pid_hash;
51+
hash_base.push_back(rcm1.pImpl_->nonce);
52+
auto h1 = hashToHex(hash_base);
5153
G1 H = libutt::hashToGroup<G1>("ps16base|" + h1);
5254
auto res = pImpl_->rsk_.sk.shareSign({(fr_pid * H), (fr_s2 * H) + rcm1.pImpl_->comm_}, H);
5355
auto res_str = libutt::serialize<libutt::RandSigShare>(res);
@@ -62,7 +64,9 @@ bool Registrator::validatePartialRCMSig(uint16_t id,
6264
fr_pid.from_words(pid_hash);
6365
Fr fr_s2;
6466
fr_s2.from_words(s2);
65-
auto h1 = hashToHex(pid_hash);
67+
auto hash_base = pid_hash;
68+
hash_base.push_back(rcm1.pImpl_->nonce);
69+
auto h1 = hashToHex(hash_base);
6670
G1 H = libutt::hashToGroup<G1>("ps16base|" + h1);
6771
libutt::RandSigShare rsig = libutt::deserialize<libutt::RandSigShare>(sig);
6872
return rsig.verify({(fr_pid * H), (fr_s2 * H) + rcm1.pImpl_->comm_}, pImpl_->validation_keys_.at(id).vk);

0 commit comments

Comments
 (0)