Skip to content

Commit

Permalink
Merge pull request #232 from hannesm/updates
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
hannesm authored Jun 9, 2024
2 parents dc08c71 + 2183839 commit 9650c3f
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 38 deletions.
18 changes: 3 additions & 15 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
freebsd_instance:
image_family: freebsd-13-2
image_family: freebsd-14-1

freebsd_task:
env:
Expand All @@ -14,20 +14,8 @@ freebsd_task:
- opam env

pin_packages_script:
- opam install -y --deps-only -t ./mirage-crypto.opam ./mirage-crypto-rng.opam ./mirage-crypto-rng-lwt.opam ./mirage-crypto-rng-mirage.opam ./mirage-crypto-rng-async.opam ./mirage-crypto-ec.opam ./mirage-crypto-pk.opam
- opam install -y --deps-only -t ./mirage-crypto.opam ./mirage-crypto-rng.opam ./mirage-crypto-rng-lwt.opam ./mirage-crypto-rng-mirage.opam ./mirage-crypto-ec.opam ./mirage-crypto-pk.opam

test_script: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec,mirage-crypto-rng-async
test_script: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-lwt,mirage-crypto-rng-mirage,mirage-crypto-pk,mirage-crypto-ec

test_mirage_script: eval `opam env` && ./.test-mirage.sh

freebsd_eio_task:
pkg_install_script: pkg install -y ocaml-opam gmake pkgconf bash

ocaml_script:
- opam init -a --comp=5.0.0
- opam env

pin_packages_script:
- opam install -y --deps-only -t ./mirage-crypto.opam ./mirage-crypto-rng.opam ./mirage-crypto-rng-eio.opam

test_script: opam exec -- dune runtest -p mirage-crypto,mirage-crypto-rng,mirage-crypto-rng-eio
1 change: 1 addition & 0 deletions .test-mirage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ echo $version >> mirage-crypto-rng-mirage.opam
echo $version >> mirage-crypto-rng.opam
echo $version >> mirage-crypto.opam
echo $version >> mirage-crypto-pk.opam
opam pin add -yn mirage-random.3.99 --dev
(mirage configure -t unix -f mirage/config.ml && gmake depend && dune build --root . mirage/dist/ && mirage/dist/crypto-test) || exit 1
(mirage configure -t hvt -f mirage/config.ml && gmake depend && dune build --root . mirage/dist/) || exit 1
if [ $(uname -m) = "amd64" ] || [ $(uname -m) = "x86_64" ]; then
Expand Down
9 changes: 5 additions & 4 deletions mirage/config.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
open Mirage

let main = foreign "Unikernel.Main" (random @-> job)

let () =
let main =
let packages = [
package "mirage-crypto-rng" ;
package "mirage-crypto-pk" ;
Expand All @@ -11,4 +9,7 @@ let () =
package "ohex" ;
]
in
register ~packages "crypto-test" [main $ default_random]
main ~packages "Unikernel.Main" (random @-> job)

let () =
register "crypto-test" [main $ default_random]
2 changes: 1 addition & 1 deletion pk/rsa.ml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ module MGF1 (H : Digestif.S) = struct

let mask ~seed buf =
let mgf_data = mgf ~seed (String.length buf) in
xor_into buf mgf_data (String.length buf);
xor_into buf ~src_off:0 mgf_data ~dst_off:0 (String.length buf);
mgf_data
end

Expand Down
2 changes: 1 addition & 1 deletion rng/entropy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ let cpu_rng_bootstrap =
| Some insn ->
let cpu_rng_bootstrap id =
let r = cpu_rng insn () in
if r = 0 then failwith "bad CPU RNG value";
if r = 0 then failwith "Mirage_crypto_rng.Entropy: 0 is a bad CPU RNG value";
let buf = Bytes.create 10 in
Bytes.set_int64_le buf 2 (Int64.of_int r);
write_header id buf;
Expand Down
2 changes: 1 addition & 1 deletion src/ccm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ let crypto_core ~cipher ~mode ~key ~nonce ~maclen ~adata data =
let crypto_t t nonce cipher key =
let ctr = gen_ctr nonce 0 in
cipher ~key (Bytes.unsafe_to_string ctr) ~src_off:0 ctr ~dst_off:0 ;
xor_into (Bytes.unsafe_to_string ctr) t (Bytes.length t)
xor_into (Bytes.unsafe_to_string ctr) ~src_off:0 t ~dst_off:0 (Bytes.length t)

let valid_nonce nonce =
let nsize = String.length nonce in
Expand Down
13 changes: 5 additions & 8 deletions src/mirage_crypto.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ module Uncommon : sig
val iter3 : 'a -> 'a -> 'a -> ('a -> unit) -> unit

val xor : string -> string -> string
val xor_into : string -> ?src_off:int -> bytes -> ?dst_off:int -> int -> unit
val xor_into : string -> src_off:int -> bytes -> dst_off:int -> int -> unit

val invalid_arg : ('a, Format.formatter, unit, unit, unit, 'b) format6 -> 'a
val failwith : ('a, Format.formatter, unit, unit, unit, 'b) format6 -> 'a
end

(**/**)

(** The poly1305 message authentication code *)
module Poly1305 : sig
type mac = string

type 'a iter = ('a -> unit) -> unit

type t
Expand All @@ -66,18 +63,18 @@ module Poly1305 : sig
val feedi : t -> string iter -> t
(** [feedi t iter] feeds iter into [t]. *)

val get : t -> mac
val get : t -> string
(** [get t] is the mac corresponding to [t]. *)

val mac : key:string -> string -> mac
val mac : key:string -> string -> string
(** [mac ~key msg] is the all-in-one mac computation:
[get (feed (empty ~key) msg)]. *)

val maci : key:string -> string iter -> mac
val maci : key:string -> string iter -> string
(** [maci ~key iter] is the all-in-one mac computation:
[get (feedi (empty ~key) iter)]. *)

val macl : key:string -> string list -> mac
val macl : key:string -> string list -> string
(** [macl ~key datas] computes the [mac] of [datas]. *)
end

Expand Down
8 changes: 3 additions & 5 deletions src/poly1305.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module type S = sig
type mac = string
type 'a iter = 'a Uncommon.iter

type t
Expand All @@ -10,13 +9,12 @@ module type S = sig
val feedi : t -> string iter -> t
val get : t -> string

val mac : key:string -> string -> mac
val maci : key:string -> string iter -> mac
val macl : key:string -> string list -> mac
val mac : key:string -> string -> string
val maci : key:string -> string iter -> string
val macl : key:string -> string list -> string
end

module It : S = struct
type mac = string
type 'a iter = 'a Uncommon.iter

module P = Native.Poly1305
Expand Down
5 changes: 2 additions & 3 deletions src/uncommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ let kasprintf k fmt =
Format.(kfprintf (fun _ -> k (flush_str_formatter ())) str_formatter fmt)

let invalid_arg fmt = kasprintf invalid_arg ("Mirage_crypto: " ^^ fmt)
let failwith fmt = kasprintf failwith ("Mirage_crypto: " ^^ fmt)

let (//) x y =
if y < 1 then raise Division_by_zero else
Expand All @@ -18,13 +17,13 @@ type 'a iter = ('a -> unit) -> unit
let iter2 a b f = f a; f b
let iter3 a b c f = f a; f b; f c

let xor_into src ?(src_off = 0) dst ?(dst_off = 0) n =
let xor_into src ~src_off dst ~dst_off n =
Native.xor_into_bytes src src_off dst dst_off n

let xor a b =
assert (String.length a = String.length b);
let b' = Bytes.of_string b in
xor_into a b' (Bytes.length b');
xor_into a ~src_off:0 b' ~dst_off:0 (Bytes.length b');
Bytes.unsafe_to_string b'

(* revise once OCaml 4.13 is the lower bound *)
Expand Down

0 comments on commit 9650c3f

Please sign in to comment.