aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShen Noether <Shen.Noether@gmx.com>2016-07-09 20:04:23 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-08-28 21:29:16 +0100
commitdbb5f2d6a3d34c0fa899fd26313873cc69dbad9d (patch)
treec0ec7fe483b6918479bfa62a65396f9800fad82d
parentringct: "simple" ringct variant (diff)
downloadmonero-dbb5f2d6a3d34c0fa899fd26313873cc69dbad9d.tar.xz
ringct: optimization/cleanup of hash functions
-rw-r--r--src/ringct/rctOps.cpp25
-rw-r--r--src/ringct/rctOps.h3
-rw-r--r--src/ringct/rctSigs.cpp39
3 files changed, 45 insertions, 22 deletions
diff --git a/src/ringct/rctOps.cpp b/src/ringct/rctOps.cpp
index 3fa870fd0..c18ee6f2b 100644
--- a/src/ringct/rctOps.cpp
+++ b/src/ringct/rctOps.cpp
@@ -423,6 +423,31 @@ namespace rct {
return rv;
}
+ //cn_fast_hash for a key-vector of arbitrary length
+ //this is useful since you take a number of keys
+ //put them in the key vector and it concatenates them
+ //and then hashes them
+ key cn_fast_hash(const keyV &keys) {
+ size_t l = keys.size();
+ vector<unsigned char> m(l * 32);
+ size_t i, j;
+ for (i = 0 ; i < l ; i++) {
+ for (j = 0 ; j < 32 ; j++) {
+ m[i * 32 + j] = keys[i][j];
+ }
+ }
+ key rv;
+ cn_fast_hash(rv, &m[0], 32 * l);
+ //dp(rv);
+ return rv;
+ }
+
+ key hash_to_scalar(const keyV &keys) {
+ key rv = cn_fast_hash(keys);
+ sc_reduce32(rv.bytes);
+ return rv;
+ }
+
key hashToPointSimple(const key & hh) {
key pointk;
ge_p1p1 point2;
diff --git a/src/ringct/rctOps.h b/src/ringct/rctOps.h
index ad6c520da..6438a1f03 100644
--- a/src/ringct/rctOps.h
+++ b/src/ringct/rctOps.h
@@ -151,6 +151,9 @@ namespace rct {
key hash_to_scalar128(const void * in);
key cn_fast_hash(ctkeyV PC);
key hash_to_scalar(ctkeyV PC);
+ //for mg sigs
+ key cn_fast_hash(const keyV &keys);
+ key hash_to_scalar(const keyV &keys);
//returns hashToPoint as described in https://github.com/ShenNoether/ge_fromfe_writeup
key hashToPointSimple(const key &in);
diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp
index c9e34ddb6..7fcb8e158 100644
--- a/src/ringct/rctSigs.cpp
+++ b/src/ringct/rctSigs.cpp
@@ -169,22 +169,21 @@ namespace rct {
keyV alpha(rows);
keyV aG(rows);
keyV aHP(rows);
- key m2hash;
- unsigned char m2[128];
- memcpy(m2, message.bytes, 32);
+ keyV toHash(1 + 3 * rows);
+ toHash[0] = message;
DP("here1");
for (i = 0; i < rows; i++) {
skpkGen(alpha[i], aG[i]); //need to save alphas for later..
Hi = hashToPoint(pk[index][i]);
aHP[i] = scalarmultKey(Hi, alpha[i]);
- memcpy(m2+32, pk[index][i].bytes, 32);
- memcpy(m2 + 64, aG[i].bytes, 32);
- memcpy(m2 + 96, aHP[i].bytes, 32);
+ toHash[3 * i + 1] = pk[index][i];
+ toHash[3 * i + 2] = aG[i];
+ toHash[3 * i + 3] = aHP[i];
rv.II[i] = scalarmultKey(Hi, xx[i]);
precomp(Ip[i].k, rv.II[i]);
- m2hash = hash_to_scalar128(m2);
- sc_add(c_old.bytes, c_old.bytes, m2hash.bytes);
}
+ c_old = hash_to_scalar(toHash);
+
i = (index + 1) % cols;
if (i == 0) {
@@ -198,12 +197,11 @@ namespace rct {
addKeys2(L, rv.ss[i][j], c_old, pk[i][j]);
hashToPoint(Hi, pk[i][j]);
addKeys3(R, rv.ss[i][j], Hi, c_old, Ip[j].k);
- memcpy(m2+32, pk[i][j].bytes, 32);
- memcpy(m2 + 64, L.bytes, 32);
- memcpy(m2 + 96, R.bytes, 32);
- m2hash = hash_to_scalar128(m2);
- sc_add(c.bytes, c.bytes, m2hash.bytes);
+ toHash[3 * j + 1] = pk[i][j];
+ toHash[3 * j + 2] = L;
+ toHash[3 * j + 3] = R;
}
+ c = hash_to_scalar(toHash);
copy(c_old, c);
i = (i + 1) % cols;
@@ -248,10 +246,8 @@ namespace rct {
for (i= 0 ; i< rows ; i++) {
precomp(Ip[i].k, II[i]);
}
- unsigned char m2[128];
- memcpy(m2, message.bytes, 32);
-
- key m2hash;
+ keyV toHash(1 + 3 * rows);
+ toHash[0] = message;
i = 0;
while (i < cols) {
sc_0(c.bytes);
@@ -259,12 +255,11 @@ namespace rct {
addKeys2(L, rv.ss[i][j], c_old, pk[i][j]);
hashToPoint(Hi, pk[i][j]);
addKeys3(R, rv.ss[i][j], Hi, c_old, Ip[j].k);
- memcpy(m2 + 32, pk[i][j].bytes, 32);
- memcpy(m2 + 64, L.bytes, 32);
- memcpy(m2 + 96, R.bytes, 32);
- m2hash = hash_to_scalar128(m2);
- sc_add(c.bytes, c.bytes, m2hash.bytes);
+ toHash[3 * j + 1] = pk[i][j];
+ toHash[3 * j + 2] = L;
+ toHash[3 * j + 3] = R;
}
+ c = hash_to_scalar(toHash);
copy(c_old, c);
i = (i + 1);
}