Conversation
|
Note: the tests have been written with the help of Claude Code. Not sure what's the policy on this repo for this kind of contibutions. |
|
I barely remember the code and the invariants. Since you have looked into it more deeply, are there all the necessary checks (i.e. length and value) done that there are no surprises (exceptions) when these primitive operations are used with any input? |
|
What was the idea behind the tests? I mean did you generate them based on a RFC or another implementation, or just "let the AI do some tests"? |
ec/mirage_crypto_ec.mli
Outdated
| (** Digital signature algorithm. *) | ||
| module Dsa : Dsa | ||
|
|
||
| (** Low-level point arithmetic. *) |
There was a problem hiding this comment.
I'm confused by your naming. You introduce a module Point, with two types, point and scalar...
Now, is this really a point?
Then there is an of_octets and to_octets, which work on point. And in addition scalar_of/to_octets. This naming doesn't scale well.
Also, there is already a Point module, thus you introduce shadowing. I'm not in favour.
And then you define it for NIST curves, is there a story for 25519?
There was a problem hiding this comment.
I've just exposed the existing Point module but with a more abstract API (and the operations I needed for spake2). I'm happy to do something a bit more intrusive if you think that's useful!
Expose a Group module containing Point and Scalar submodules. Tests use RFC 5903 Section 8 vectors for P-256, P-384, P-521 (scalar multiplication and DH shared secret) + add invalid input tests
|
Now with a proper "Group" name + test vectors from the RFC + negative tests for invalid inputs |
|
Hard to review when you force-push. Still there are some questions remaining:
From your code, as I understand this could be mostly implemented on top of mirage-crypto-ec: module Group (D : Mirage_crypto_ec.Dh_dsa) = struct
module Point = struct
type t = D.Dsa.pub
let of_octets = D.Dsa.pub_of_octets
let to_octets = D,Dsa.pub_to_octets
let generator = `<here we need to expose the Make_point.params_g>`
let add = `<here we need to expose the Make_point.add>`
end
module Scalar = struct
type t = D.Dh.secret
let of_octets = D.Dh.secret_of_octets
let to_octets = D.Dh.secret_to_octets
let mult s p =
let p' = Point.to_octets p in
Result.map Point.of_octets (D.Dh.key_exchange s p')
end
endBut I see that exposing some functionality would be more efficient. Coming back here, my trouble with this PR is:
Another approach could be to extend the module Primitive : sig
val generator : Dsa.pub
val add : Dsa.pub -> Dsa.pub -> Dsa.pub
val scalar_mul(t?) : Dsa.priv -> Dsa.pub -> Dsa.pub
endThis would mean: no new functors, nothing to add to each curve definition; no new types. Would this work for you? |
|
To get a better idea what I have in mind, please take a look at #278 (documentation comments taken from this PR) |
…plication) This adds a new module, Dsa.Primitive, for NIST curves only. The intention is described by @samoht in mirage#277 "implement SPAKE2"
CHANGES: * Add new module Mirage_crypto_ec.Dsa.Primitive exposing the generator, point add, scalar multiplication for NIST curves. This is useful for implementing some protocols (such as spake2) (mirage/mirage-crypto#278 mirage/mirage-crypto#277 @samoht @hannesm) * Cleanup gen_tables (mirage/mirage-crypto#273 mirage/mirage-crypto#275 @reynir) * Use 'architecture' 'riscv' to not execute the entropy test on riscv64 (mirage/mirage-crypto#272 mirage/mirage-crypto#273 mirage/mirage-crypto#274 @reynir @hannesm)
This is useful for accessing those constant-time operations in other protocols (for instance spake2).