package hacl_x25519
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Primitives for Elliptic Curve Cryptography taken from Project Everest
Install
dune-project
Dependency
Authors
Maintainers
Sources
hacl_x25519-v0.2.2.tbz
sha256=816754a8e8f9739d0e6d98ced6e50b026a28d59232445c5051a66e4332cc572d
sha512=9a0fb07af4af999a12cb65f3bc15487c5999ddf6fff0a923cf4b8087a15933632266be55ec01cff3b15d354c9e526d906a7e15aee84c743f58f8cdfe899b110d
doc/src/hacl_x25519/hacl_x25519.ml.html
Source file hacl_x25519.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62let key_length_bytes = 32 let ( >>= ) r f = match r with Ok x -> f x | Error _ as e -> e let ( >>| ) r f = r >>= fun x -> Ok (f x) type error = [ `Invalid_length | `Low_order ] let pp_error ppf = function | `Invalid_length -> Format.fprintf ppf "Invalid key size" | `Low_order -> Format.fprintf ppf "Public key with low order" type secret = [ `Checked of Cstruct.t ] let key_of_cstruct cs = if Cstruct.len cs = key_length_bytes then Ok (`Checked cs) else Error `Invalid_length (* pk -> sk -> basepoint -> unit *) external scalarmult_raw : Cstruct.buffer -> Cstruct.buffer -> Cstruct.buffer -> unit = "ml_Hacl_Curve25519_crypto_scalarmult" [@@noalloc] let checked_buffer (`Checked cs) = Cstruct.to_bigarray cs let key_exchange_buffer ~priv ~checked_pub = let cs = Cstruct.create key_length_bytes in let result = `Checked cs in scalarmult_raw (checked_buffer result) (checked_buffer priv) checked_pub; cs let all_zeroes = String.make key_length_bytes '\x00' let is_zero_output cs = let s = Cstruct.to_string cs in Eqaf.equal s all_zeroes let key_exchange priv pub = key_of_cstruct pub >>| checked_buffer >>= fun checked_pub -> let = key_exchange_buffer ~priv ~checked_pub in if is_zero_output shared then Error `Low_order else Ok shared let basepoint = let cs = Cstruct.create key_length_bytes in Cstruct.set_uint8 cs 0 9; Cstruct.to_bigarray cs let public priv = key_exchange_buffer ~priv ~checked_pub:basepoint let gen_key ~rng = let secret_cstruct = rng key_length_bytes in let secret = match key_of_cstruct secret_cstruct with | Ok k -> k | Error `Invalid_length -> failwith "Hacl_x25519.gen_key: generator returned an invalid length" in let pub_key = public secret in (secret, pub_key) let encode_secret (`Checked cs) = cs
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>