aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypto-ops.c14
-rw-r--r--src/crypto/crypto-ops.h8
-rw-r--r--src/crypto/crypto.cpp6
-rw-r--r--src/crypto/crypto.h21
-rw-r--r--src/crypto/keccak.c6
-rw-r--r--src/crypto/keccak.h4
6 files changed, 43 insertions, 16 deletions
diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c
index a9b659a6b..1b390e402 100644
--- a/src/crypto/crypto-ops.c
+++ b/src/crypto/crypto-ops.c
@@ -40,17 +40,15 @@ DISABLE_VS_WARNINGS(4146 4244)
static void fe_mul(fe, const fe, const fe);
static void fe_sq(fe, const fe);
-static void fe_tobytes(unsigned char *, const fe);
static void ge_madd(ge_p1p1 *, const ge_p3 *, const ge_precomp *);
static void ge_msub(ge_p1p1 *, const ge_p3 *, const ge_precomp *);
static void ge_p2_0(ge_p2 *);
static void ge_p3_dbl(ge_p1p1 *, const ge_p3 *);
-static void ge_sub(ge_p1p1 *, const ge_p3 *, const ge_cached *);
static void fe_divpowm1(fe, const fe, const fe);
/* Common functions */
-static uint64_t load_3(const unsigned char *in) {
+uint64_t load_3(const unsigned char *in) {
uint64_t result;
result = (uint64_t) in[0];
result |= ((uint64_t) in[1]) << 8;
@@ -58,7 +56,7 @@ static uint64_t load_3(const unsigned char *in) {
return result;
}
-static uint64_t load_4(const unsigned char *in)
+uint64_t load_4(const unsigned char *in)
{
uint64_t result;
result = (uint64_t) in[0];
@@ -120,7 +118,7 @@ Postconditions:
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*/
-static void fe_add(fe h, const fe f, const fe g) {
+void fe_add(fe h, const fe f, const fe g) {
int32_t f0 = f[0];
int32_t f1 = f[1];
int32_t f2 = f[2];
@@ -258,7 +256,7 @@ static void fe_copy(fe h, const fe f) {
/* From fe_invert.c */
-static void fe_invert(fe out, const fe z) {
+void fe_invert(fe out, const fe z) {
fe t0;
fe t1;
fe t2;
@@ -1031,7 +1029,7 @@ Proof:
so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
*/
-static void fe_tobytes(unsigned char *s, const fe h) {
+void fe_tobytes(unsigned char *s, const fe h) {
int32_t h0 = h[0];
int32_t h1 = h[1];
int32_t h2 = h[2];
@@ -1591,7 +1589,7 @@ void ge_scalarmult_base(ge_p3 *h, const unsigned char *a) {
r = p - q
*/
-static void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
+void ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
fe t0;
fe_add(r->X, p->Y, p->X);
fe_sub(r->Y, p->Y, p->X);
diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h
index cdc5ac1ee..4986499f4 100644
--- a/src/crypto/crypto-ops.h
+++ b/src/crypto/crypto-ops.h
@@ -143,3 +143,11 @@ void sc_sub(unsigned char *, const unsigned char *, const unsigned char *);
void sc_mulsub(unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *);
int sc_check(const unsigned char *);
int sc_isnonzero(const unsigned char *); /* Doesn't normalize */
+
+// internal
+uint64_t load_3(const unsigned char *in);
+uint64_t load_4(const unsigned char *in);
+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);
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index f5e655274..250779ac3 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -151,7 +151,7 @@ namespace crypto {
return true;
}
- static void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res) {
+ void crypto_ops::derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res) {
struct {
key_derivation derivation;
char output_index[(sizeof(size_t) * 8 + 6) / 7];
@@ -230,7 +230,7 @@ namespace crypto {
buf.h = prefix_hash;
buf.key = pub;
if (ge_frombytes_vartime(&tmp3, &pub) != 0) {
- abort();
+ return false;
}
if (sc_check(&sig.c) != 0 || sc_check(&sig.r) != 0) {
return false;
@@ -364,7 +364,7 @@ POP_WARNINGS
return false;
}
if (ge_frombytes_vartime(&tmp3, &*pubs[i]) != 0) {
- abort();
+ return false;
}
ge_double_scalarmult_base_vartime(&tmp2, &sig[i].c, &tmp3, &sig[i].r);
ge_tobytes(&buf->ab[i].a, &tmp2);
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h
index fa55c2aab..b396fc7db 100644
--- a/src/crypto/crypto.h
+++ b/src/crypto/crypto.h
@@ -64,6 +64,22 @@ namespace crypto {
friend class crypto_ops;
};
+ POD_CLASS public_keyV {
+ std::vector<public_key> keys;
+ int rows;
+ };
+
+ POD_CLASS secret_keyV {
+ std::vector<secret_key> keys;
+ int rows;
+ };
+
+ POD_CLASS public_keyM {
+ int cols;
+ int rows;
+ std::vector<secret_keyV> column_vectors;
+ };
+
POD_CLASS key_derivation: ec_point {
friend class crypto_ops;
};
@@ -97,6 +113,8 @@ namespace crypto {
friend bool secret_key_to_public_key(const secret_key &, public_key &);
static bool generate_key_derivation(const public_key &, const secret_key &, key_derivation &);
friend bool generate_key_derivation(const public_key &, const secret_key &, key_derivation &);
+ static void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res);
+ friend void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res);
static bool derive_public_key(const key_derivation &, std::size_t, const public_key &, public_key &);
friend bool derive_public_key(const key_derivation &, std::size_t, const public_key &, public_key &);
static void derive_secret_key(const key_derivation &, std::size_t, const secret_key &, secret_key &);
@@ -165,6 +183,9 @@ namespace crypto {
const public_key &base, public_key &derived_key) {
return crypto_ops::derive_public_key(derivation, output_index, base, derived_key);
}
+ inline void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res) {
+ return crypto_ops::derivation_to_scalar(derivation, output_index, res);
+ }
inline void derive_secret_key(const key_derivation &derivation, std::size_t output_index,
const secret_key &base, secret_key &derived_key) {
crypto_ops::derive_secret_key(derivation, output_index, base, derived_key);
diff --git a/src/crypto/keccak.c b/src/crypto/keccak.c
index 3ee2a887c..090d563a2 100644
--- a/src/crypto/keccak.c
+++ b/src/crypto/keccak.c
@@ -73,11 +73,11 @@ void keccakf(uint64_t st[25], int rounds)
// compute a keccak hash (md) of given byte length from "in"
typedef uint64_t state_t[25];
-int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen)
+int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
{
state_t st;
uint8_t temp[144];
- int i, rsiz, rsizw;
+ size_t i, rsiz, rsizw;
rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen;
rsizw = rsiz / 8;
@@ -106,7 +106,7 @@ int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen)
return 0;
}
-void keccak1600(const uint8_t *in, int inlen, uint8_t *md)
+void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md)
{
keccak(in, inlen, md, sizeof(state_t));
}
diff --git a/src/crypto/keccak.h b/src/crypto/keccak.h
index 4f7f85729..fbd8e1904 100644
--- a/src/crypto/keccak.h
+++ b/src/crypto/keccak.h
@@ -16,11 +16,11 @@
#endif
// compute a keccak hash (md) of given byte length from "in"
-int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen);
+int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen);
// update the state
void keccakf(uint64_t st[25], int norounds);
-void keccak1600(const uint8_t *in, int inlen, uint8_t *md);
+void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md);
#endif