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

Dune #158

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Dune #158

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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ _build
*.install
*.native
*.byte
.merlin

*~
\.\#*
\#*#

gmon.out
.gdb_history
*.prof
perf.data*
*.json
rondom
8 changes: 0 additions & 8 deletions .merlin

This file was deleted.

17 changes: 9 additions & 8 deletions .ocamlinit
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#require "cstruct, zarith, sexplib"
#directory "_build/src"
#load "nocrypto.cma"

(* #require "oUnit" *)
(* #directory "_build/tests" *)
(* #load "testlib.cma" *)
#directory "_build/default/src"
#directory "_build/default/src/.nocrypto.objs/byte"
#directory "_build/default/unix"
#directory "_build/default/unix/.nocrypto_entropy_unix.objs/byte"
#directory "_build/default/lwt"
#directory "_build/default/lwt/.nocrypto_entropy_lwt.objs/byte"

#directory "_build/unix"
#require "cstruct, ocplib-endian, zarith"
#load "nocrypto.cma"
#load "nocrypto_entropy_unix.cmo"
#load "nocrypto_entropy_lwt.cmo"

open Nocrypto
let _ = Nocrypto_entropy_unix.initialize ()
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ env:
- UPDATE_GCC_BINUTILS=1
- TESTS=true
matrix:
- OCAML_VERSION=4.02
- OCAML_VERSION=4.03
- OCAML_VERSION=4.04
- OCAML_VERSION=4.05
Expand All @@ -17,5 +16,6 @@ env:
- OCAML_VERSION=4.06 DEPOPTS="lwt cstruct-lwt"
- OCAML_VERSION=4.04 DEPOPTS="mirage-xen"
- OCAML_VERSION=4.06 DEPOPTS="mirage-solo5 mirage-entropy"
- OCAML_VERSION=4.07
notifications:
email: false
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ delegating to AES-NI.
## Build

```bash
./pkg/pkg.ml build
--with-unix BOOL
--with-lwt BOOL
--xen BOOL
--freestanding BOOL

./pkg/pkg.ml test
dune build
dune runtest
```

## FAQ
Expand Down Expand Up @@ -59,11 +54,12 @@ Program terminated with signal SIGILL, Illegal instruction.
autodetection yet. You compiled the library with acceleration, but you are using
it on a machine that does not support it.

`pkg/pkg.ml build --accelerate false` force-disables non-portable code.
The environment variable `NOCRYPTO_ACCELERATE` can be used to override
detection:

`pkg/pkg.ml build --accelerate true` force-enables non-portable code.
- `NOCRYPTO_ACCELERATE=false dune build` force-disables non-portable code.
- `NOCRYPTO_ACCELERATE=true dune build` force-enables non-portable code.
- Otherwise, it matches the capabilities of the build machine.

The flag can also be set via the `NOCRYPTO_ACCELERATE` environment variable.
When unset, it maches the capabilities of the build machine.

[![Build Status](https://travis-ci.org/mirleft/ocaml-nocrypto.svg?branch=master)](https://travis-ci.org/mirleft/ocaml-nocrypto)
26 changes: 0 additions & 26 deletions _tags

This file was deleted.

4 changes: 4 additions & 0 deletions bench/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executables
(names speed)
(modules speed)
(libraries nocrypto))
2 changes: 1 addition & 1 deletion bench/speed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let throughput title f =
sizes |> List.iter @@ fun size ->
Gc.full_major () ;
let (iters, time, bw) = burn f size in
Printf.printf " % 5d: %04.f MB/s (%d iters in %.03f s)\n%!"
Printf.printf " % 5d: %04f MB/s (%d iters in %.03f s)\n%!"
size (bw /. mb) iters time

let bm name f = (name, fun () -> f name)
Expand Down
9 changes: 0 additions & 9 deletions build

This file was deleted.

12 changes: 12 additions & 0 deletions config/cfg.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let evar = "NOCRYPTO_ACCELERATE"
let needs = [`SSSE3; `AES; `PCLMULQDQ]
let flags = ["-DACCELERATE"; "-mssse3"; "-maes"; "-mpclmul"]

let _ =
let auto = match Cpuid.supports needs with Ok true -> flags | _ -> [] in
let fs = match Sys.getenv evar with
"true" -> flags
| "false" -> []
| _ -> auto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be an error (or at least a warning)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... right, if you set it but not to true or false. I was hoping I'd snatch a parser for configuration things from somewhere else, before I start writing that in the discovery tool.

I did try to emit text to confirm override, but dune seems to swallow my stderr.

| exception Not_found -> auto in
Format.(printf "(@[%a@])%!" (fun ppf -> List.iter (fprintf ppf "%s@ ")) fs)
3 changes: 3 additions & 0 deletions config/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executables
(names cfg)
(libraries dune.configurator result cpuid))
4 changes: 0 additions & 4 deletions doc/api.odocl

This file was deleted.

3 changes: 3 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 1.7)
(name nocrypto)
(version %%VERSION_NUM%%)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is necessary

Suggested change
(version %%VERSION_NUM%%)
(version %%VERSION_NUM%%)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it's not strictly necessary. But it adds version to META files.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

META files are automatically generated with the correct version. For example, ̀cstructdoesn't have(version)` here, and you can check that the installed META file has the correct version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what I'm seeing while playing with a pinned package. I won't pretend to understand why.

7 changes: 7 additions & 0 deletions lwt/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(library
(name nocrypto_entropy_lwt)
(public_name nocrypto.lwt)
(synopsis "Unix+Lwt entropy seeding")
(libraries nocrypto nocrypto.unix lwt.unix)
(optional))

30 changes: 16 additions & 14 deletions lwt/nocrypto_entropy_lwt.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
open Lwt
open Lwt.Infix
open Nocrypto

let chunk = 32
and period = 30
and device = Nocrypto_entropy_unix.sys_rng


let mvar_map v f =
Lwt_mvar.take v >>= fun x ->
catch (fun () -> f x >>= Lwt_mvar.put v)
(fun exn -> Lwt_mvar.put v x >>= fun () -> fail exn)
Lwt.catch (fun () -> f x >>= Lwt_mvar.put v)
(fun exn -> Lwt_mvar.put v x >>= fun () -> Lwt.fail exn)

let some x = Some x

[@@@ocaml.warning "-3"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's for Lwt_sequence it's now possible to use Lwt_dllist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or more precisely, Lwt_main.Enter_iter_hooks. This is not the changeset for that.


type t = {
fd : Lwt_unix.file_descr ;
Expand All @@ -25,34 +25,36 @@ let background ~period f =
and live = ref false
and period = float period in
fun () ->
let t1 = !last
and t2 = Unix.gettimeofday () in
if (not !live) && (t2 -. t1 >= period) then begin
last := t2 ;
let t = Unix.gettimeofday () in
if (not !live) && (t -. !last >= period) then begin
last := t ;
live := true ;
async @@ fun () -> f () >|= fun () -> live := false
Lwt.async @@ fun () -> f () >|= fun () -> live := false
end

let rec read_cs fd cs =
Lwt_bytes.read fd cs.Cstruct.buffer cs.Cstruct.off cs.Cstruct.len >>=
function 0 -> Lwt.return_unit | n -> read_cs fd (Cstruct.shift cs n)

let attach ~period ?(device = device) g =
Lwt_unix.(openfile device [O_RDONLY] 0) >|= fun fd ->
let buf = Cstruct.create chunk in
let seed () =
Lwt_cstruct.(complete (read fd) buf) >|= fun () -> Rng.reseed ~g buf in
let seed () = read_cs fd buf >|= fun () -> Rng.reseed ~g buf in
let remove =
Lwt_sequence.add_r (background ~period seed) Lwt_main.enter_iter_hooks in
{ g ; fd ; remove }

let stop t =
Lwt_sequence.remove t.remove ;
catch (fun () -> Lwt_unix.close t.fd)
Unix.(function Unix_error (EBADF, _, _) -> return_unit | exn -> fail exn)
Lwt.(catch (fun () -> Lwt_unix.close t.fd)
Unix.(function Unix_error (EBADF, _, _) -> return_unit | exn -> fail exn))

let active = Lwt_mvar.create None

let initialize () =
Nocrypto_entropy_unix.initialize () ;
let g = !Rng.generator in
mvar_map active @@ function
| Some t when t.g == g -> return (Some t)
| Some t when t.g == g -> Lwt.return_some t
| Some t -> stop t >>= fun () -> attach ~period g >|= some
| None -> attach ~period g >|= some
1 change: 0 additions & 1 deletion lwt/nocrypto_lwt.mllib

This file was deleted.

6 changes: 6 additions & 0 deletions mirage/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name nocrypto_entropy_mirage)
(public_name nocrypto.mirage)
(synopsis "Mirage entropy seeding")
(libraries nocrypto lwt mirage-entropy)
(optional))
1 change: 0 additions & 1 deletion mirage/nocrypto_mirage.mllib

This file was deleted.

5 changes: 0 additions & 5 deletions myocamlbuild.ml

This file was deleted.

29 changes: 29 additions & 0 deletions nocrypto.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
opam-version: "2.0"
homepage: "https://github.com/mirleft/ocaml-nocrypto"
dev-repo: "git+https://github.com/mirleft/ocaml-nocrypto.git"
bug-reports: "https://github.com/mirleft/ocaml-nocrypto/issues"
doc: "https://mirleft.github.io/ocaml-nocrypto/doc"
authors: ["David Kaloper <[email protected]>"]
maintainer: "David Kaloper <[email protected]>"
license: "ISC"
synopsis: "Simple crypto for the modern age"

build: [ ["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs ]
["dune" "runtest"] {with-test} ]

depends: [
"ocaml" {>= "4.03.0"}
"dune" {build & >= "1.7"}
"cpuid" {build}
"ounit" {with-test}
"cstruct" {>="3.0.0"}
"ocplib-endian"
"zarith"
("mirage-no-xen" | ("mirage-xen" & "zarith-xen"))
("mirage-no-solo5" | ("mirage-solo5" & "zarith-freestanding"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these still needed since the mirage packages are removed from this repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mirage package, nocrypto.mirage, is still present. It's just that it's meaningless because the stubs are not cross-compiled.

Hence the PR: the state of this branch is still incoherent.

]

depopts: [ "unix" "lwt" "mirage-entropy" ]

conflicts: [ "mirage-xen" {< "2.2.0"} ]
46 changes: 0 additions & 46 deletions opam

This file was deleted.

43 changes: 0 additions & 43 deletions pkg/META

This file was deleted.

Loading