]> git.codecow.com Git - Monocypher.git/commitdiff
Added dangerous X25519 speed benchmarks
authorLoup Vaillant <loup@loup-vaillant.fr>
Tue, 24 Mar 2020 12:34:29 +0000 (13:34 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Tue, 24 Mar 2020 12:34:29 +0000 (13:34 +0100)
src/monocypher.c
tests/speed/speed.c

index 8a9c7923469639595a4ed7c859f20eb8e9b5a9e5..c52d62504c08604253a9212bbff93be66a84eac9 100644 (file)
@@ -2296,6 +2296,9 @@ static void add_xl(u8 s[32], u8 x)
 }
 
 // "Small" dangerous ephemeral key.
+// Use if you need to shrink the size of the binary, and can tolerate a
+// slowdow by a factor of two (compared to the fast version)
+//
 // This version works by decoupling the cofactor from the main factor.
 //
 // - The trimmed scalar determines the main factor
@@ -2336,11 +2339,12 @@ void crypto_x25519_dangerous_small(u8 public_key[32], const u8 secret_key[32])
 }
 
 // "Fast" dangerous ephemeral key
+// We use this one by default.
 //
 // This version works by performing a regular scalar multiplication,
 // then add a low order point.  The scalar multiplication is done in
-// Edwards space for more speed.  The cost is a bigger binary programs
-// that don't also sign messages.
+// Edwards space for more speed (*2 compared to the "small" version).
+// The cost is a bigger binary programs that don't also sign messages.
 void crypto_x25519_dangerous_fast(u8 public_key[32], const u8 secret_key[32])
 {
     static const fe lop_x = {
index a626efd033ccc73a4e7d104eeb85b37e7c0c4ee8..258c37c5e74cbddb83043d82ae7afef976bc4046 100644 (file)
@@ -184,6 +184,24 @@ static u64 x25519_inverse(void)
     TIMING_END;
 }
 
+static u64 x25519_sp_fast(void)
+{
+    RANDOM_INPUT(sk, 32);
+    TIMING_START {
+        crypto_x25519_dangerous_fast(sk, sk);
+    }
+    TIMING_END;
+}
+
+static u64 x25519_sp_small(void)
+{
+    RANDOM_INPUT(sk, 32);
+    TIMING_START {
+        crypto_x25519_dangerous_small(sk, sk);
+    }
+    TIMING_END;
+}
+
 int main()
 {
     print("Chacha20            ",chacha20()     *MUL ,"megabytes  per second");
@@ -196,6 +214,8 @@ int main()
     print("EdDSA(sign)         ",edDSA_sign()        ,"signatures per second");
     print("EdDSA(check)        ",edDSA_check()       ,"checks     per second");
     print("x25519 inverse      ",x25519_inverse()    ,"scalar inv per second");
+    print("x25519 special fast ",x25519_sp_fast()    ,"scalar inv per second");
+    print("x25519 special small",x25519_sp_small()    ,"scalar inv per second");
     printf("\n");
     return 0;
 }