From: Loup Vaillant Date: Tue, 21 Feb 2017 12:36:23 +0000 (+0100) Subject: more tests X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=946ecb3929c33819b3bd39acbe5f9dc0644945f1;p=Monocypher.git more tests --- diff --git a/monocypher.c b/monocypher.c index be79723..0d1fdf6 100644 --- a/monocypher.c +++ b/monocypher.c @@ -1220,18 +1220,14 @@ void crypto_sign(u8 signature[64], const u8 public_key[32], const u8 *message, size_t message_size) { - u8 h[64]; - u8 *a = h; // secret scalar - u8 *prefix = h + 32; // prefix for nonce generation - HASH(h, secret_key, 32); + u8 a[64], *prefix = a + 32; + HASH(a, secret_key, 32); trim_scalar(a); - ge A; u8 pk_buf[32]; const u8 *pk = public_key; if (public_key == 0) { - ge_scalarmult_base(&A, a); - ge_tobytes(pk_buf, &A); + crypto_sign_public_key(pk_buf, secret_key); pk = pk_buf; } @@ -1284,14 +1280,14 @@ int crypto_check(const u8 signature[64], //////////////////// /// Key exchange /// //////////////////// -void crypto_lock_key(u8 shared_key[32], - const u8 your_secret_key [32], - const u8 their_public_key[32]) +void crypto_key_exchange(u8 shared_key[32], + const u8 your_secret_key [32], + const u8 their_public_key[32]) { - static const u8 _0[16] = {0}; + static const u8 zero[16] = {0}; u8 shared_secret[32]; crypto_x25519(shared_secret, your_secret_key, their_public_key); - crypto_chacha20_H(shared_key, shared_secret, _0); + crypto_chacha20_H(shared_key, shared_secret, zero); } //////////////////////////////// diff --git a/monocypher.h b/monocypher.h index 425ca2d..1f8e6ed 100644 --- a/monocypher.h +++ b/monocypher.h @@ -128,9 +128,9 @@ int crypto_check(const uint8_t signature[64], //////////////////// /// Key exchange /// //////////////////// -void crypto_lock_key(uint8_t shared_key [32], - const uint8_t your_secret_key [32], - const uint8_t their_public_key[32]); +void crypto_key_exchange(uint8_t shared_key [32], + const uint8_t your_secret_key [32], + const uint8_t their_public_key[32]); //////////////////////////////// /// Authenticated encryption /// diff --git a/test.c b/test.c index 5161891..b7e5437 100644 --- a/test.c +++ b/test.c @@ -262,6 +262,11 @@ sv blake2b(const vector in[], vector *out) msg->buf, msg->size); } +sv blake2b_easy(const vector in[], vector *out) +{ + crypto_blake2b(out->buf, in->buf, in->size); +} + sv poly1305(const vector in[], vector *out) { const vector *key = in; @@ -313,7 +318,7 @@ static int test_x25519() uint8_t k[32] = {9}; uint8_t u[32] = {9}; - iterate_x25519(k, u); + crypto_x25519_public_key(k, u); int status = crypto_memcmp(k, _1, 32); printf("%s: x25519 1\n", status != 0 ? "FAILED" : "OK"); @@ -346,20 +351,21 @@ sv ed25519_key(const vector in[], vector *out) crypto_sign_public_key(out->buf, in->buf); } -sv ed25519_sign(const vector in[], vector *out) +sv ed25519_sign1(const vector in[], vector *out) +{ + const vector *secret_k = in; + const vector *msg = in + 2; + // reconsruct public key before signing + crypto_sign(out->buf, secret_k->buf, 0, msg->buf, msg->size); +} + +sv ed25519_sign2(const vector in[], vector *out) { const vector *secret_k = in; const vector *public_k = in + 1; const vector *msg = in + 2; - - // Test that signature matches the test vector (out->buf). - // Both signature modes must yield the same signature. - u8 signature[64]; - crypto_sign(out->buf , secret_k->buf, 0 , msg->buf, msg->size); - crypto_sign(signature, secret_k->buf, public_k->buf, msg->buf, msg->size); - if (crypto_memcmp(signature, out->buf, 64)) { - printf("FAILURE: signature modes yield different signatures!\n"); - } + // Use cached public key to sign + crypto_sign(out->buf, secret_k->buf, public_k->buf, msg->buf, msg->size); // test successful signature verification if (crypto_check(out->buf, public_k->buf, msg->buf, msg->size)) { @@ -378,6 +384,14 @@ sv ed25519_sign(const vector in[], vector *out) } } +sv key_exchange(const vector in[], vector *out) +{ + const vector *secret_key = in; + const vector *public_key = in + 1; + crypto_key_exchange(out->buf, secret_key->buf, public_key->buf); + +} + static int test_aead() { uint8_t key[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, @@ -415,12 +429,15 @@ int main(void) status |= test(hchacha20 , "vectors_h_chacha20" , 2); status |= test(xchacha20 , "vectors_x_chacha20" , 2); status |= test(blake2b , "vectors_blake2b" , 2); + status |= test(blake2b_easy , "vectors_blake2b_easy", 1); status |= test(poly1305 , "vectors_poly1305" , 2); status |= test(argon2i , "vectors_argon2i" , 6); status |= test(x25519 , "vectors_x25519" , 2); + status |= test(key_exchange , "vectors_key_exchange", 2); status |= test(sha512 , "vectors_sha512" , 1); status |= test(ed25519_key , "vectors_ed25519_key" , 1); - status |= test(ed25519_sign , "vectors_ed25519_sign", 3); + status |= test(ed25519_sign1, "vectors_ed25519_sign", 3); + status |= test(ed25519_sign2, "vectors_ed25519_sign", 3); status |= test_x25519(); status |= test_aead(); printf(status ? "TESTS FAILED\n" : "ALL TESTS OK\n"); diff --git a/vectors_blake2b_easy b/vectors_blake2b_easy new file mode 100644 index 0000000..6cfa910 --- /dev/null +++ b/vectors_blake2b_easy @@ -0,0 +1,5 @@ +6162636465660a: +13c203e14b36cdf9dc4585775fd2d02e271c63d5094a4b1c0632aa2373b4b95d62b97b80a7de3409286a9ef294012921b563d98e9eaa6e65efc0654960ad865a: + +616263646566: +dde410524e3569b303e494aa82a3afb3e426f9df24c1398e9ff87aafbc2f5b7b3c1a4c9400409de3b45d37a00e5eae2a93cc9c4a108b00f05217d41a424d2b8a: diff --git a/vectors_h_chacha20 b/vectors_h_chacha20 index 9e1eeef..6f447e3 100644 --- a/vectors_h_chacha20 +++ b/vectors_h_chacha20 @@ -37,3 +37,19 @@ ebc5224cf41ea97473683b6c2f38a084bf6e1feaaeff62676db59d5b719d999b: c49758f00003714c38f1d4972bde57ee8271f543b91e07ebce56b554eb7fa6a7: 31f0204e10cf4f2035f9e62bb5ba7303: 0dd8cc400f702d2c06ed920be52048a287076b86480ae273c6d568a2e9e7518c: + +c3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a28552: +00000000000000000000000000000000: +c7328db7e9756741bf3eb4f082c5bc57c58c77a5be31df0a02340cf235f81828: + +95cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac7957: +00000000000000000000000000000000: +85041b68835411fbec93a848d3f97816c28b4a778f8e4793bb6b68b8573cbe2d: + +4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742: +00000000000000000000000000000000: +8e47ca376bdc7e59d2ced8107ceb2c27f4a80e8575f996baffb1a869ffcd5179: + +422c8e7a6227d7bca1350b3e2bb7279f7897b87bb6854b783c60e80311ae3079: +00000000000000000000000000000000: +a60c2a7a4be7a39b1208f7cb7305c0caa711174f425d932b86b201896251f452: \ No newline at end of file diff --git a/vectors_key_exchange b/vectors_key_exchange new file mode 100644 index 0000000..8a3f5b2 --- /dev/null +++ b/vectors_key_exchange @@ -0,0 +1,19 @@ +a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4: +e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c: +c7328db7e9756741bf3eb4f082c5bc57c58c77a5be31df0a02340cf235f81828: + +4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d: +e5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a493: +85041b68835411fbec93a848d3f97816c28b4a778f8e4793bb6b68b8573cbe2d: + +77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a: +de9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f: +8e47ca376bdc7e59d2ced8107ceb2c27f4a80e8575f996baffb1a869ffcd5179: + +5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb: +8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a: +8e47ca376bdc7e59d2ced8107ceb2c27f4a80e8575f996baffb1a869ffcd5179: + +0900000000000000000000000000000000000000000000000000000000000000: +0900000000000000000000000000000000000000000000000000000000000000: +a60c2a7a4be7a39b1208f7cb7305c0caa711174f425d932b86b201896251f452: