Skip to content

Commit e969714

Browse files
committed
mirage-crypto-ec: implementation of SECP256K1
This change implements the SECP256K1 curve (also known as the Bitcoin curve). - field primitives are generated by the fiat-crypto project[1] - point primitives are generated by the ECCKiila project[2] - Ocaml point operations are taken from NIST implementation, adapted to ECCKiila point primitives and optimized for a=0. - testvectors for ECDH and ECDSA verification from wycheproof[3] Closes: mirage#187 [1] https://github.com/mit-plv/fiat-crypto [2] https://gitlab.com/nisec/ecckiila [3] https://github.com/C2SP/wycheproof
1 parent cadf0e1 commit e969714

16 files changed

+29057
-100
lines changed

Diff for: bench/speed.ml

+11
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ let ecdsa_p256 =
193193

194194
let ecdsa_p256_sig () = Mirage_crypto_ec.P256.Dsa.sign ~key:ecdsa_p256 msg_str_32
195195

196+
let ecdsa_p256k1 =
197+
Result.get_ok
198+
(Mirage_crypto_ec.P256k1.Dsa.priv_of_octets
199+
"\x08\x9f\x4f\xfc\xcc\xf9\xba\x13\xfe\xdd\x09\x42\xef\x08\xcf\x2d\x90\x9f\x32\xe2\x93\x4a\xb5\xc9\x3b\x6c\x99\xbe\x5a\x9f\xf5\x27")
200+
201+
let ecdsa_p256k1_sig () = Mirage_crypto_ec.P256k1.Dsa.sign ~key:ecdsa_p256k1 msg_str_32
202+
196203
let ecdsa_p384 =
197204
Result.get_ok
198205
(Mirage_crypto_ec.P384.Dsa.priv_of_octets
@@ -215,6 +222,7 @@ let ed25519_sig () = Mirage_crypto_ec.Ed25519.sign ~key:ed25519 msg_str
215222

216223
let ecdsas = [
217224
("P256", `P256 (ecdsa_p256, ecdsa_p256_sig ()));
225+
("P256k1", `P256k1 (ecdsa_p256k1, ecdsa_p256k1_sig ()));
218226
("P384", `P384 (ecdsa_p384, ecdsa_p384_sig ()));
219227
("P521", `P521 (ecdsa_p521, ecdsa_p521_sig ()));
220228
("Ed25519", `Ed25519 (ed25519, ed25519_sig ()));
@@ -303,6 +311,7 @@ let benchmarks = [
303311
count name
304312
(fun (_, x) -> match x with
305313
| `P256 _ -> P256.Dsa.generate () |> ignore
314+
| `P256k1 _ -> P256k1.Dsa.generate () |> ignore
306315
| `P384 _ -> P384.Dsa.generate () |> ignore
307316
| `P521 _ -> P521.Dsa.generate () |> ignore
308317
| `Ed25519 _ -> Ed25519.generate () |> ignore
@@ -313,6 +322,7 @@ let benchmarks = [
313322
let open Mirage_crypto_ec in
314323
count name (fun (_, x) -> match x with
315324
| `P256 (key, _) -> P256.Dsa.sign ~key msg_str_32
325+
| `P256k1 (key, _) -> P256k1.Dsa.sign ~key msg_str_32
316326
| `P384 (key, _) -> P384.Dsa.sign ~key msg_str_48
317327
| `P521 (key, _) -> P521.Dsa.sign ~key msg_str_65
318328
| `Ed25519 (key, _) -> Ed25519.sign ~key msg_str, ""
@@ -323,6 +333,7 @@ let benchmarks = [
323333
let open Mirage_crypto_ec in
324334
count name (fun (_, x) -> match x with
325335
| `P256 (key, signature) -> P256.Dsa.(verify ~key:(pub_of_priv key) signature msg_str_32)
336+
| `P256k1 (key, signature) -> P256k1.Dsa.(verify ~key:(pub_of_priv key) signature msg_str_32)
326337
| `P384 (key, signature) -> P384.Dsa.(verify ~key:(pub_of_priv key) signature msg_str_48)
327338
| `P521 (key, signature) -> P521.Dsa.(verify ~key:(pub_of_priv key) signature msg_str_65)
328339
| `Ed25519 (key, signature) -> Ed25519.(verify ~key:(pub_of_priv key) signature ~msg:msg_str)

Diff for: ec/dune

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(foreign_stubs
66
(language c)
77
(names p256_stubs np256_stubs p384_stubs np384_stubs p521_stubs np521_stubs
8-
curve25519_stubs)
8+
curve25519_stubs secp256k1_stubs)
99
(include_dirs ../src/native)
1010
(flags
1111
(:standard -DNDEBUG)

0 commit comments

Comments
 (0)