Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mirage-crypto-ec: provide Dh.secret_to_octets #244

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ec/mirage_crypto_ec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module type Dh = sig
type secret
val secret_of_octets : ?compress:bool -> string ->
(secret * string, error) result
val secret_to_octets : secret -> string
val gen_key : ?compress:bool -> ?g:Mirage_crypto_rng.g -> unit ->
secret * string
val key_exchange : secret -> string -> (string, error) result
Expand Down Expand Up @@ -505,6 +506,9 @@ module Make_dh (Param : Parameters) (P : Point) (S : Scalar) : Dh = struct
| Ok p -> Ok (p, share ?compress p)
| Error _ as e -> e

let secret_to_octets s =
S.to_octets s

let rec generate_private_key ?g () =
let candidate = Mirage_crypto_rng.generate ?g Param.byte_length in
match S.of_octets candidate with
Expand Down Expand Up @@ -953,6 +957,8 @@ module X25519 = struct
else
Error `Invalid_length

let secret_to_octets s = s

let is_zero =
let zero = String.make key_len '\000' in
fun buf -> String.equal zero buf
Expand Down
4 changes: 4 additions & 0 deletions ec/mirage_crypto_ec.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ module type Dh = sig
the shared part will be compressed. May result in an error if the buffer
had an invalid length or was not in bounds. *)

val secret_to_octets : secret -> string
(** [secret_to_octets secret] encodes the provided secret into a freshly
allocated buffer. *)

val gen_key : ?compress:bool -> ?g:Mirage_crypto_rng.g -> unit ->
secret * string
(** [gen_key ~compress ~g ()] generates a private and a public key for
Expand Down
Loading