aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-09-11 15:45:56 +0200
committerRiccardo Spagni <ric@spagni.net>2018-09-11 15:45:56 +0200
commite6d36c17015e179aaa21f2353bdc608967833303 (patch)
tree39fb0829fe9f3b0d468bbb27393cd79fdefbda15 /src/crypto
parentMerge pull request #4218 (diff)
parentblockchain: add a testnet v9 a day after v8 (diff)
downloadmonero-e6d36c17015e179aaa21f2353bdc608967833303.tar.xz
Merge pull request #4219
9137ad2c blockchain: add a testnet v9 a day after v8 (moneromooo-monero) ac4f71c2 wallet2: bump testnet rollback to account for coming reorg (moneromooo-monero) 8f418a6d bulletproofs: #include <openssl/bn.h> (moneromooo-monero) 2bf63650 bulletproofs: speed up the latest changes a bit (moneromooo-monero) 044dff5a bulletproofs: scale points by 8 to ensure subgroup validity (moneromooo-monero) c83012c4 bulletproofs: match aggregated verification to sarang's latest prototype (moneromooo-monero) ce0c7432 performance_tests: add padded bulletproof construction (moneromooo-monero) 1224e53b core_tests: add a test for 4-aggregated BP verification (moneromooo-monero) 0e6ed559 fuzz_tests: add a bulletproof fuzz test (moneromooo-monero) 463434d1 more comprehensive test for ge_p3 comparison to identity/point at infinity (moneromooo-monero) d0a0565f unit_tests: add a few more multiexp unit tests (moneromooo-monero) 6526d87f core_tests: add a test for a tx with empty bulletproof (moneromooo-monero) a129bbd9 multiexp: fix maxscalar off by one (moneromooo-monero) 7ed496cc ringct: error out when hashToPoint* returns the point at infinity (moneromooo-monero) d1591853 cryptonote_basic: check output type before using it (moneromooo-monero) 61632dc1 ringct: prevent a potential very large allocation (moneromooo-monero) a4317e61 crypto: some paranoid checks in generate_signature/check_signature (moneromooo-monero) 7434df1c crypto: never return zero in random32_unbiased (moneromooo-monero) 0825e974 multiexp: fix wrong Bos-Coster result for 1 non trivial input (moneromooo-monero) a1359ad4 Check inputs to addKeys are in range (moneromooo-monero) fe0fa3b9 bulletproofs: reject x, y, z, or w[i] being zero (moneromooo-monero) 5ffb2ff9 v8: per byte fee, pad bulletproofs, fixed 11 ring size (moneromooo-monero) 869b3bf8 bulletproofs: a few fixes from the Kudelski review (moneromooo-monero) c4291762 bulletproofs: reject points not in the main subgroup (moneromooo-monero) 15697177 bulletproofs: speed up a few multiplies using existing Hi cache (moneromooo-monero) 0b05a0fa Add Pippenger cache and limit Straus cache size (moneromooo-monero) 51eb3bdc add pippenger unit tests (moneromooo-monero) b17b8db3 performance_tests: add stats and loop count multiplier options (moneromooo-monero) 7314d919 perf_timer: split timer class into a base one and a logging one (moneromooo-monero) d126a02b performance_tests: add aggregated bulletproof tx verification (moneromooo-monero) 263431c4 Pippenger multiexp (moneromooo-monero) 1ed0ed4d multiexp: cut down on memory allocations (moneromooo-monero) 1b867e7f precalc the ge_p3 representation of H (moneromooo-monero) ef56529f performance_tests: document the tested bulletproof layouts (moneromooo-monero) 30111780 unit_tests: a couple more bulletproof unit tests for gamma (moneromooo-monero) c444b1b2 require canonical multi output bulletproof layout (moneromooo-monero) 7e67c52f Add a define for the max number of bulletproof multi-outputs (moneromooo-monero) 2a8fcb42 Bulletproof aggregated verification and tests (moneromooo-monero) 126196b0 multiexp: some speedups (moneromooo-monero) 71d67bda aligned: aligned memory alloc/realloc/free (moneromooo-monero) cb9ecab1 performance_tests: add signature generation/verification (moneromooo-monero) bacf0a1e bulletproofs: add aggregated verification (moneromooo-monero) e895c3de make straus cached mode thread safe, and add tests for it (moneromooo-monero) 7f48bf05 multiexp: bos coster now works for just one point (moneromooo-monero) 9ce9f8ca bulletproofs: add multi output bulletproofs to rct (moneromooo-monero) f34e2e20 performance_tests: add tx checking tests with more than 2 outputs (moneromooo-monero) 0793184b performance_tests: add a --verbose flag, and default to terse (moneromooo-monero) 939bc223 add Straus multiexp (moneromooo-monero) 9ff6e6a0 ringct: add bos coster multiexp (moneromooo-monero) e9164bb3 bulletproofs: misc optimizations (moneromooo-monero) 112f32f0 performance_tests: add crypto ops (moneromooo-monero) f5d7b993 performance_tests: add bulletproofs (moneromooo-monero) 8f4ce989 performance_tests: add RingCT MLSAG gen/ver tests (moneromooo-monero) 1aa10c43 performance_tests: add (Borromean) range proofs (moneromooo-monero) aacfd6e3 bulletproofs: multi-output bulletproofs (moneromooo-monero) cb1cc757 performance_tests: don't override log level to 0 (moneromooo-monero)
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypto-ops-data.c6
-rw-r--r--src/crypto/crypto-ops.c16
-rw-r--r--src/crypto/crypto-ops.h3
-rw-r--r--src/crypto/crypto.cpp14
4 files changed, 35 insertions, 4 deletions
diff --git a/src/crypto/crypto-ops-data.c b/src/crypto/crypto-ops-data.c
index 4ff4310de..1f77513ca 100644
--- a/src/crypto/crypto-ops-data.c
+++ b/src/crypto/crypto-ops-data.c
@@ -871,3 +871,9 @@ const fe fe_fffb2 = {8166131, -6741800, -17040804, 3154616, 21461005, 1466302, -
const fe fe_fffb3 = {-13620103, 14639558, 4532995, 7679154, 16815101, -15883539, -22863840, -14813421, 13716513, -6477756}; /* sqrt(-sqrt(-1) * A * (A + 2)) */
const fe fe_fffb4 = {-21786234, -12173074, 21573800, 4524538, -4645904, 16204591, 8012863, -8444712, 3212926, 6885324}; /* sqrt(sqrt(-1) * A * (A + 2)) */
const ge_p3 ge_p3_identity = { {0}, {1, 0}, {1, 0}, {0} };
+const ge_p3 ge_p3_H = {
+ {7329926, -15101362, 31411471, 7614783, 27996851, -3197071, -11157635, -6878293, 466949, -7986503},
+ {5858699, 5096796, 21321203, -7536921, -5553480, -11439507, -5627669, 15045946, 19977121, 5275251},
+ {1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {23443568, -5110398, -8776029, -4345135, 6889568, -14710814, 7474843, 3279062, 14550766, -7453428}
+};
diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c
index 45d412ac6..09296d6f9 100644
--- a/src/crypto/crypto-ops.c
+++ b/src/crypto/crypto-ops.c
@@ -3707,9 +3707,8 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
s[31] = s11 >> 17;
}
-/* Assumes that a != INT64_MIN */
static int64_t signum(int64_t a) {
- return (a >> 63) - ((-a) >> 63);
+ return a > 0 ? 1 : a < 0 ? -1 : 0;
}
int sc_check(const unsigned char *s) {
@@ -3730,3 +3729,16 @@ int sc_isnonzero(const unsigned char *s) {
s[18] | s[19] | s[20] | s[21] | s[22] | s[23] | s[24] | s[25] | s[26] |
s[27] | s[28] | s[29] | s[30] | s[31]) - 1) >> 8) + 1;
}
+
+int ge_p3_is_point_at_infinity(const ge_p3 *p) {
+ // X = 0 and Y == Z
+ int n;
+ for (n = 0; n < 10; ++n)
+ {
+ if (p->X[n] | p->T[n])
+ return 0;
+ if (p->Y[n] != p->Z[n])
+ return 0;
+ }
+ return 1;
+}
diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h
index dc3c60794..2910dafd4 100644
--- a/src/crypto/crypto-ops.h
+++ b/src/crypto/crypto-ops.h
@@ -140,6 +140,7 @@ extern const fe fe_fffb2;
extern const fe fe_fffb3;
extern const fe fe_fffb4;
extern const ge_p3 ge_p3_identity;
+extern const ge_p3 ge_p3_H;
void ge_fromfe_frombytes_vartime(ge_p2 *, const unsigned char *);
void sc_0(unsigned char *);
void sc_reduce32(unsigned char *);
@@ -158,3 +159,5 @@ void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
void fe_add(fe h, const fe f, const fe g);
void fe_tobytes(unsigned char *, const fe);
void fe_invert(fe out, const fe z);
+
+int ge_p3_is_point_at_infinity(const ge_p3 *p);
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index 4243c71fd..ad7721cf0 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -116,7 +116,7 @@ namespace crypto {
do
{
generate_random_bytes_thread_safe(32, bytes);
- } while (!less32(bytes, limit)); // should be good about 15/16 of the time
+ } while (!sc_isnonzero(bytes) && !less32(bytes, limit)); // should be good about 15/16 of the time
sc_reduce32(bytes);
}
/* generate a random 32-byte (256-bit) integer and copy it to res */
@@ -274,11 +274,18 @@ namespace crypto {
#endif
buf.h = prefix_hash;
buf.key = pub;
+ try_again:
random_scalar(k);
+ if (((const uint32_t*)(&k))[7] == 0) // we don't want tiny numbers here
+ goto try_again;
ge_scalarmult_base(&tmp3, &k);
ge_p3_tobytes(&buf.comm, &tmp3);
hash_to_scalar(&buf, sizeof(s_comm), sig.c);
+ if (!sc_isnonzero((const unsigned char*)sig.c.data))
+ goto try_again;
sc_mulsub(&sig.r, &sig.c, &unwrap(sec), &k);
+ if (!sc_isnonzero((const unsigned char*)sig.r.data))
+ goto try_again;
}
bool crypto_ops::check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig) {
@@ -292,11 +299,14 @@ namespace crypto {
if (ge_frombytes_vartime(&tmp3, &pub) != 0) {
return false;
}
- if (sc_check(&sig.c) != 0 || sc_check(&sig.r) != 0) {
+ if (sc_check(&sig.c) != 0 || sc_check(&sig.r) != 0 || !sc_isnonzero(&sig.c)) {
return false;
}
ge_double_scalarmult_base_vartime(&tmp2, &sig.c, &tmp3, &sig.r);
ge_tobytes(&buf.comm, &tmp2);
+ static const ec_point infinity = {{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+ if (memcmp(&buf.comm, &infinity, 32) == 0)
+ return false;
hash_to_scalar(&buf, sizeof(s_comm), c);
sc_sub(&c, &c, &sig.c);
return sc_isnonzero(&c) == 0;