upstream: https://github.com/mirage/mirage-crypto

Merge pull request #106 from mirleft/topkg

Topkg

authored by

David Kaloper and committed by
GitHub
9fc0147c 20a0e584

+259 -414
+6 -19
.gitignore
··· 1 - rondom 2 - 3 - _tags 4 - myocamlbuild.ml 5 - setup.ml 6 - */META 7 - */*.mllib 8 - */*.mldylib 9 - */*.clib 10 - */api.odocl 11 - 12 - _tags.local 13 - myocamlbuild.ml.local 14 - 15 1 _build 16 - setup.data 17 - setup.log 18 - 2 + *.install 19 3 *.native 20 4 *.byte 21 - *.docdir 22 5 23 - *.prof 6 + *~ 7 + \.\#* 8 + \#*# 24 9 25 10 gmon.out 11 + *.prof 12 + rondom
+3 -3
.ocamlinit
··· 2 2 #directory "_build/src" 3 3 #load "nocrypto.cma" 4 4 5 - #require "oUnit" 6 - #directory "_build/tests" 7 - #load "testlib.cma" 5 + (* #require "oUnit" *) 6 + (* #directory "_build/tests" *) 7 + (* #load "testlib.cma" *) 8 8 9 9 #directory "_build/unix" 10 10 #load "nocrypto_entropy_unix.cmo"
+3 -1
CHANGES.md
··· 1 - (trunk): 1 + 0.5.4 (??): 2 + * Solo5 support. 3 + * Moved the build to `topkg`. 2 4 3 5 0.5.3 (2016-03-21): 4 6 * Move from Camlp4 to PPX.
LICENSE LICENSE.md
-47
Makefile
··· 1 - SETUP = ocaml setup.ml 2 - 3 - build: setup.data 4 - $(SETUP) -build $(BUILDFLAGS) 5 - 6 - doc: setup.data build 7 - $(SETUP) -doc $(DOCFLAGS) 8 - 9 - test: setup.data build 10 - $(SETUP) -test $(TESTFLAGS) 11 - 12 - all: 13 - $(SETUP) -all $(ALLFLAGS) 14 - 15 - install: setup.data 16 - $(SETUP) -install $(INSTALLFLAGS) 17 - 18 - uninstall: setup.data 19 - $(SETUP) -uninstall $(UNINSTALLFLAGS) 20 - 21 - reinstall: setup.data 22 - $(SETUP) -reinstall $(REINSTALLFLAGS) 23 - 24 - clean: setup.ml 25 - $(SETUP) -clean $(CLEANFLAGS) 26 - 27 - distclean: setup.ml 28 - $(SETUP) -distclean $(DISTCLEANFLAGS) 29 - rm -f myocamlbuild.ml setup.ml _tags 30 - rm -f */META */*.mllib */*.mldylib */*.clib */api.odocl 31 - 32 - setup.data: setup.ml 33 - $(SETUP) -configure $(CONFIGUREFLAGS) 34 - 35 - configure: setup.ml 36 - $(SETUP) -configure $(CONFIGUREFLAGS) 37 - 38 - setup.ml: _oasis 39 - @mkdir -p xen solo5 40 - oasis setup 41 - @if [ -e _tags.extra ]; then cat _tags.extra >> _tags; fi 42 - @if [ -e _tags.local ]; then cat _tags.local >> _tags; fi 43 - @if [ -e myocamlbuild.ml.extra ]; then cat myocamlbuild.ml.extra >> myocamlbuild.ml; fi 44 - @if [ -e myocamlbuild.ml.local ]; then cat myocamlbuild.ml.local >> myocamlbuild.ml; fi 45 - 46 - 47 - .PHONY: build doc test all install uninstall reinstall clean distclean configure
+25 -11
README.md
··· 2 2 3 3 ## Documentation 4 4 5 - Comments in the single interface file, [`nocrypto.mli`][nocrypto-mli]. Also available [online][docs]. 5 + Comments in the single interface file, [`nocrypto.mli`][nocrypto-mli]. 6 + Also available [online][docs]. 6 7 7 8 The documentation is a work in progress. :) 8 9 10 + ## Build 11 + 12 + ```bash 13 + pkg/pkg.ml build 14 + --with-unix BOOL 15 + --with-lwt BOOL 16 + --xen BOOL 17 + --freestanding BOOL` 18 + 19 + pkg/pkg.ml test 20 + ``` 21 + 9 22 ## FAQ 10 23 11 24 #### RNG seeding 12 25 13 - You get something like `Fatal error: exception Uncommon.Boot.Unseeded_generator` and ask yourself: "Is there a simple way to forget about seeding and have the thing working?" 26 + You get something like `Fatal error: exception Uncommon.Boot.Unseeded_generator` 27 + and ask yourself: "Is there a simple way to forget about seeding and have the 28 + thing working?" 14 29 15 30 ```OCaml 16 31 (* On pure Unix: *) ··· 29 44 #0 _mm_aeskeygenassist_si128 (__C=<optimized out>, __X=...) 30 45 ``` 31 46 32 - `Nocrypto` has CPU acceleration support (`SSE2`+`AES-NI`), but it has no run-time autodetection yet. You 33 - compiled the library with acceleration, but you are using it on a machine that does not support it. 47 + `Nocrypto` has CPU acceleration support (`SSE2`+`AES-NI`), but it has no 48 + run-time autodetection yet. You compiled the library with acceleration, but you 49 + are using it on a machine that does not support it. 34 50 35 - `./configure --disable-modernity` disables non-portable code. 51 + `pkg/pkg.ml build --accelerate false` force-disables non-portable code. 36 52 37 - `./configure --enable-modernity` enables non-portable code if the build machine supports it. 53 + `pkg/pkg.ml build --accelerate true` force-enables non-portable code. 38 54 39 - The flag defaults to `enable`. 40 - 41 - A second way to disable this feature is by exporting `$NOCRYPTO_NO_ACCEL` 42 - environment variable during build. This is desirable, for example, when building 43 - via `opam`. 55 + Another way to specify the flags is not the `NOCRYPTO_ACCELERATE` environment 56 + variable. When `--accelerate` is not specified, it maches the capabilities of 57 + the build machine. 44 58 45 59 [docs]: http://mirleft.github.io/ocaml-nocrypto 46 60 [nocrypto-mli]: https://github.com/mirleft/ocaml-nocrypto/blob/master/src/nocrypto.mli
-201
_oasis
··· 1 - OASISFormat: 0.4 2 - Name: nocrypto 3 - Version: 0.5.3 4 - Synopsis: Simple crypto for the modern age 5 - Authors: David Kaloper <david@numm.org> 6 - Maintainers: David Kaloper <david@numm.org> 7 - License: BSD-2-clause 8 - Homepage: https://github.com/mirleft/ocaml-nocrypto 9 - Plugins: META (0.4) 10 - BuildTools: ocamlbuild 11 - OCamlVersion: >= 4.02.0 12 - PostConfCommand: ./postconf 13 - AlphaFeatures: ocamlbuild_more_args 14 - Categories: http://org:mirage 15 - Description: 16 - A simple cryptographic library. 17 - 18 - Flag xen 19 - Description: Build Xen support 20 - Default: false 21 - 22 - Flag solo5 23 - Description: Build Solo5 support 24 - Default: false 25 - 26 - Flag lwt 27 - Description: Build Lwt/Unix support 28 - Default: true 29 - 30 - Flag unix 31 - Description: Build Unix support 32 - Default: true 33 - 34 - Flag modernity 35 - Description: Use CPU extensions (SSE2, AES-NI) 36 - Default: true 37 - 38 - Flag benchmarks 39 - Description: Build the benchmark programs 40 - Default: false 41 - 42 - Library nocrypto 43 - Path: src/ 44 - Pack: true 45 - Modules: Uncommon, 46 - Base64, 47 - Hash, 48 - Cipher_stream, 49 - Cipher_block, 50 - Numeric, 51 - Rng, 52 - Rsa, 53 - Dsa, 54 - Dh 55 - InternalModules: Native, 56 - Fortuna, 57 - Hmac_drgb, 58 - Gcm, 59 - Ccm 60 - CSources: native/nocrypto.h, 61 - native/misc.c, 62 - native/hash/stubs.c, 63 - native/hash/bitfn.h, 64 - native/hash/md5.c, 65 - native/hash/md5.h, 66 - native/hash/sha1.c, 67 - native/hash/sha1.h, 68 - native/hash/sha256.c, 69 - native/hash/sha256.h, 70 - native/hash/sha512.c, 71 - native/hash/sha512.h, 72 - native/aes/generic.c, 73 - native/aes/aesni.c, 74 - native/des/generic.c, 75 - native/des/generic.h 76 - BuildDepends: cstruct (>= 1.6.0), zarith, sexplib, ppx_sexp_conv 77 - XMETARequires: cstruct, zarith, sexplib 78 - XMETAExtraLines: xen_linkopts = "-lnocrypto_xen_stubs" 79 - ByteOpt: -w A-4-29-33-40-41-42-43-34-44 80 - CCOpt: --std=c99 -Wall -Wextra -Werror -O3 81 - if flag(modernity) && architecture(amd64) 82 - CCOpt+: -DACCELERATE -msse2 -maes 83 - 84 - Library nocrypto_unix 85 - Path: unix/ 86 - Findlibparent: nocrypto 87 - Findlibname: unix 88 - Build$: flag(unix) 89 - Modules: Nocrypto_entropy_unix 90 - BuildDepends: nocrypto, unix, bytes 91 - 92 - Library nocrypto_lwt 93 - Path: lwt/ 94 - Findlibparent: nocrypto 95 - Findlibname: lwt 96 - Build$: flag(unix) && flag(lwt) 97 - Modules: Nocrypto_entropy_lwt 98 - BuildDepends: nocrypto, nocrypto.unix, lwt.unix, cstruct.lwt 99 - 100 - Library nocrypto_mirage 101 - Path: mirage/ 102 - Findlibparent: nocrypto 103 - Findlibname: mirage 104 - Build$: flag(xen) || flag(solo5) 105 - Modules: Nocrypto_entropy_mirage 106 - BuildDepends: nocrypto, lwt, mirage-entropy-xen 107 - 108 - Library nocrypto_xen 109 - Path: xen/ 110 - Findlibparent: nocrypto 111 - Findlibname: xen 112 - Build$: flag(xen) 113 - CSources: native/nocrypto.h, 114 - native/misc.c, 115 - native/hash/stubs.c, 116 - native/hash/bitfn.h, 117 - native/hash/md5.c, 118 - native/hash/md5.h, 119 - native/hash/sha1.c, 120 - native/hash/sha1.h, 121 - native/hash/sha256.c, 122 - native/hash/sha256.h, 123 - native/hash/sha512.c, 124 - native/hash/sha512.h, 125 - native/aes/generic.c, 126 - native/aes/aesni.c, 127 - native/des/generic.c, 128 - native/des/generic.h 129 - CCOpt: --std=c99 -Wall -Wextra -Werror -O3 -DNDEBUG $XEN_CFLAGS 130 - if flag(modernity) && architecture(amd64) 131 - CCOpt+: -DACCELERATE -msse2 -maes 132 - 133 - Library nocrypto_solo5 134 - Path: solo5/ 135 - Findlibparent: nocrypto 136 - Findlibname: solo5 137 - Build$: flag(solo5) 138 - CSources: native/nocrypto.h, 139 - native/misc.c, 140 - native/hash/stubs.c, 141 - native/hash/bitfn.h, 142 - native/hash/md5.c, 143 - native/hash/md5.h, 144 - native/hash/sha1.c, 145 - native/hash/sha1.h, 146 - native/hash/sha256.c, 147 - native/hash/sha256.h, 148 - native/hash/sha512.c, 149 - native/hash/sha512.h, 150 - native/aes/generic.c, 151 - native/aes/aesni.c, 152 - native/des/generic.c, 153 - native/des/generic.h 154 - CCOpt: --std=c99 -Wall -Wextra -Werror -O3 -DNDEBUG $FREESTANDING_CFLAGS 155 - if flag(modernity) && architecture(amd64) 156 - CCOpt+: -DACCELERATE -msse2 -maes 157 - 158 - Library testlib 159 - Path: tests/ 160 - Modules: Notest, Hmac_tests, Dsa_tests, Testlib 161 - Install: false 162 - Build$: flag(tests) 163 - BuildDepends: nocrypto, oUnit 164 - 165 - Executable test_runner 166 - Path: tests/ 167 - Install: false 168 - CompiledObject: best 169 - MainIs: testrunner.ml 170 - Build$: flag(tests) 171 - BuildDepends: testlib 172 - 173 - Test the_things 174 - Command: $test_runner 175 - TestTools: test_runner 176 - Run$: flag(tests) 177 - 178 - Executable speed 179 - Path: bench/ 180 - Install: false 181 - CompiledObject: native 182 - MainIs: speed.ml 183 - Build$: flag(benchmarks) 184 - BuildDepends: nocrypto, cstruct, cstruct.unix 185 - 186 - Document api 187 - Title: Documentation and API reference 188 - Type: ocamlbuild (0.3) 189 - BuildTools+: ocamldoc 190 - XOCamlbuildPath: doc 191 - XOCamlbuildModules: src/Nocrypto, 192 - unix/Nocrypto_entropy_unix, 193 - lwt/Nocrypto_entropy_lwt, 194 - mirage/Nocrypto_entropy_mirage 195 - Install: false 196 - XOCamlbuildExtraArgs: -docflags -colorize-code,-charset,utf-8 197 - 198 - SourceRepository trunk 199 - Type: git 200 - Location: https://github.com/mirleft/ocaml-nocrypto.git 201 - Browser: https://github.com/mirleft/ocaml-nocrypto
+25
_tags
··· 1 + true: color(always) 2 + true: bin_annot, safe_string 3 + true: warn(A-4-29-33-40-41-42-43-34-44-48) 4 + true: package(bytes), package(cstruct) 5 + 6 + <src>: include 7 + <src/*.ml{,i}>: package(zarith), package(sexplib), package(ppx_sexp_conv) 8 + <src/*.cm{x,o}> and not <src/nocrypto.cmx>: for-pack(Nocrypto) 9 + <src/*.cm{,x}a>: link_stubs(src/libnocrypto_stubs) 10 + 11 + <unix>: include 12 + <unix/*.ml{,i}>: package(unix), package(bytes) 13 + 14 + <lwt>: include 15 + <lwt/*.ml{,i}>: package(lwt.unix), package(cstruct.lwt) 16 + 17 + <mirage>: include 18 + <mirage/*.ml{,i}>: package(lwt), package(mirage-entropy) 19 + 20 + <**/*.c>: ccopt(--std=c99 -Wall -Wextra -O3) 21 + 22 + <bench/*>: use_nocrypto, package(zarith), package(cstruct.unix) 23 + <tests/*>: use_nocrypto, package(zarith), package(oUnit) 24 + 25 + <rondom>: -traverse
+1 -1
bench/speed.ml
··· 9 9 10 10 let time ~n f a = 11 11 let t1 = Sys.time () in 12 - for i = 1 to n do ignore (f a) done ; 12 + for _ = 1 to n do ignore (f a) done ; 13 13 let t2 = Sys.time () in 14 14 (t2 -. t1) 15 15
+8
build
··· 1 + #!/bin/sh 2 + 3 + function has { opam config var "${1}:installed"; } 4 + 5 + topkg build -- \ 6 + --with-lwt $(has 'lwt') \ 7 + --xen $(has 'mirage-xen') \ 8 + --freestanding $(has 'ocaml-freestanding')
-4
configure
··· 1 - #!/bin/sh 2 - 3 - make setup.ml 4 - ocaml setup.ml -configure "$@"
+4
doc/api.odocl
··· 1 + src/Nocrypto 2 + unix/Nocrypto_entropy_unix 3 + lwt/Nocrypto_entropy_lwt 4 + mirage/Nocrypto_entropy_mirage
+1
lwt/nocrypto_lwt.mllib
··· 1 + Nocrypto_entropy_lwt
+1
mirage/nocrypto_mirage.mllib
··· 1 + Nocrypto_entropy_mirage
+5
myocamlbuild.ml
··· 1 + open Ocamlbuild_plugin 2 + 3 + let () = dispatch Ocb_stubblr.( 4 + init & ccopt_flags ~tags:["accelerate"] "-DACCELERATE -msse2 -maes"; 5 + )
-15
myocamlbuild.ml.local
··· 1 - open Ocamlbuild_plugin;; 2 - 3 - dispatch @@ MyOCamlbuildBase.dispatch_combine [ 4 - begin function 5 - | After_rules -> 6 - copy_rule "xen_cstubs: copy generated source to xen directory" 7 - "src/native/%" 8 - "xen/native/%"; 9 - copy_rule "solo5_cstubs: copy generated source to solo5 directory" 10 - "src/native/%" 11 - "solo5/native/%" 12 - | _ -> () 13 - end; 14 - dispatch_default 15 - ]
+18 -29
opam
··· 2 2 homepage: "https://github.com/mirleft/ocaml-nocrypto" 3 3 dev-repo: "https://github.com/mirleft/ocaml-nocrypto.git" 4 4 bug-reports: "https://github.com/mirleft/ocaml-nocrypto/issues" 5 - author: "David Kaloper <david@numm.org>" 5 + authors: ["David Kaloper <david@numm.org>"] 6 6 maintainer: "David Kaloper <david@numm.org>" 7 7 license: "BSD2" 8 + tags: [ "org:mirage" ] 9 + available: [ ocaml-version >= "4.02.0" ] 8 10 9 - build: [ 10 - [ "./configure" "--prefix" prefix 11 - "--%{lwt:enable}%-lwt" 12 - "--%{mirage-xen+mirage-entropy-xen:enable}%-xen" 13 - "--%{mirage-solo5+mirage-entropy-solo5:enable}%-solo5" ] 14 - [ make ] 15 - ] 16 - install: [ make "install" ] 17 - remove: [ "ocamlfind" "remove" "nocrypto" ] 11 + build: [ "ocaml" "pkg/pkg.ml" "build" 12 + "--pinned" "%{pinned}%" 13 + "--with-lwt" "%{lwt:installed}%" 14 + "--xen" "%{mirage-xen:installed}%" 15 + "--freestanding" "%{ocaml-freestanding:installed}%" ] 16 + 17 + build-test: [ "ocaml" "pkg/pkg.ml" "test" ] 18 18 19 19 depends: [ 20 20 "ocamlfind" {build} 21 21 "ocamlbuild" {build} 22 - "oasis" {build} 22 + "topkg" {build} 23 23 "ppx_sexp_conv" {build} 24 + "cpuid" {build} 25 + "ocb-stubblr" {build} 26 + "ounit" {test} 24 27 "cstruct" {>= "1.6.0"} 25 28 "zarith" 26 29 "sexplib" 27 - ("mirage-no-xen" | ("mirage-xen" & "mirage-entropy-xen" & "zarith-xen")) 28 - ("mirage-no-solo5" | ("mirage-solo5" & "mirage-entropy-solo5" & "zarith-freestanding")) 29 - "ounit" {test} 30 + ("mirage-no-xen" | ("mirage-xen" & "mirage-entropy" & "zarith-xen")) 31 + ("mirage-no-solo5" | ("mirage-solo5" & "mirage-entropy" & "zarith-freestanding")) 30 32 ] 31 33 32 - depopts: [ 33 - "lwt" 34 - ] 34 + depopts: [ "lwt" ] 35 + conflicts: [ "mirage-xen" {<"2.2.0"} ] 35 36 36 - conflicts: [ 37 - "mirage-xen" {<"2.2.0"} 38 - "mirage-entropy-xen" {<"0.3.0"} 39 - ] 40 - 41 - build-test: [ 42 - [ "./configure" "--%{ounit:enable}%-tests" ] 43 - [ make "test" ] 44 - ] 45 - 46 - tags: [ "org:mirage" ] 47 - available: [ ocaml-version >= "4.02.0" ]
+43
pkg/META
··· 1 + version = "%%VERSION%%" 2 + description = "Simple crypto for the modern age" 3 + requires = "cstruct zarith sexplib" 4 + archive(byte) = "nocrypto.cma" 5 + archive(native) = "nocrypto.cmxa" 6 + plugin(byte) = "nocrypto.cma" 7 + plugin(native) = "nocrypto.cmxs" 8 + xen_linkopts = "-lnocrypto_stubs+mirage-xen" 9 + freestanding_linkopts = "-lnocrypto_stubs+mirage-freestanding" 10 + exists_if = "nocrypto.cma" 11 + 12 + package "unix" ( 13 + version = "%%VERSION%%" 14 + description = "Simple crypto for the modern age" 15 + requires = "nocrypto unix bytes" 16 + archive(byte) = "nocrypto_unix.cma" 17 + archive(native) = "nocrypto_unix.cmxa" 18 + plugin(byte) = "nocrypto_unix.cma" 19 + plugin(native) = "nocrypto_unix.cmxs" 20 + exists_if = "nocrypto_unix.cma" 21 + ) 22 + 23 + package "lwt" ( 24 + version = "%%VERSION%%" 25 + description = "Simple crypto for the modern age" 26 + requires = "nocrypto nocrypto.unix lwt.unix cstruct.lwt" 27 + archive(byte) = "nocrypto_lwt.cma" 28 + archive(native) = "nocrypto_lwt.cmxa" 29 + plugin(byte) = "nocrypto_lwt.cma" 30 + plugin(native) = "nocrypto_lwt.cmxs" 31 + exists_if = "nocrypto_lwt.cma" 32 + ) 33 + 34 + package "mirage" ( 35 + version = "%%VERSION%%" 36 + description = "Simple crypto for the modern age" 37 + requires = "nocrypto lwt mirage-entropy" 38 + archive(byte) = "nocrypto_mirage.cma" 39 + archive(native) = "nocrypto_mirage.cmxa" 40 + plugin(byte) = "nocrypto_mirage.cma" 41 + plugin(native) = "nocrypto_mirage.cmxs" 42 + exists_if = "nocrypto_mirage.cma" 43 + )
+47
pkg/pkg.ml
··· 1 + #!/usr/bin/env ocaml 2 + #use "topfind" 3 + #require "topkg" 4 + #require "cpuid" 5 + #require "ocb-stubblr.topkg" 6 + open Topkg 7 + open Ocb_stubblr_topkg 8 + 9 + let cpudetect () = 10 + match Cpuid.supports [`SSE2; `AES] with Ok r -> Ok r | Error _ -> Ok false 11 + 12 + let unix = Conf.with_pkg ~default:true "unix" 13 + let lwt = Conf.with_pkg ~default:true "lwt" 14 + let xen = Conf.(key "xen" bool ~absent:false 15 + ~doc:"Build Mirage/Xen support.") 16 + let fs = Conf.(key "freestanding" bool ~absent:false 17 + ~doc:"Build Mirage/Solo5 support.") 18 + let accelerate = Conf.(discovered_key "accelerate" bool 19 + ~absent:cpudetect 20 + ~env:"NOCRYPTO_ACCELERATE" 21 + ~doc:"Enable the use of extended CPU features (SSE2, AES-NI). \ 22 + If unspecified, matches build machine's capabilities.") 23 + 24 + let tags = [(accelerate, "accelerate")] 25 + 26 + let cmd_with_tags tags c os files = 27 + let tags = Cmd.of_list ~slip:"-tag" 28 + List.(tags |> filter (fun (v, _) -> Conf.value c v) |> map snd) in 29 + OS.Cmd.run Cmd.(build_cmd c os %% tags %% of_list files) 30 + 31 + let () = 32 + let build = Pkg.(build ~cmd:(cmd_with_tags tags) ()) in 33 + Pkg.describe "nocrypto" ~build @@ fun c -> 34 + let unix = Conf.value c unix in 35 + let lwt = Conf.value c lwt && unix 36 + and xen = Conf.value c xen 37 + and fs = Conf.value c fs in 38 + Ok ([ 39 + Pkg.clib "src/libnocrypto_stubs.clib"; 40 + Pkg.mllib "src/nocrypto.mllib"; 41 + Pkg.mllib ~cond:unix "unix/nocrypto_unix.mllib"; 42 + Pkg.mllib ~cond:lwt "lwt/nocrypto_lwt.mllib"; 43 + Pkg.mllib ~cond:(xen||fs) "mirage/nocrypto_mirage.mllib"; 44 + Pkg.test "tests/testrunner"; 45 + Pkg.test ~run:false "bench/speed"; ] @ 46 + mirage ~xen ~fs "src/libnocrypto_stubs.clib" 47 + )
-29
postconf
··· 1 - #!/bin/sh 2 - 3 - export PKG_CONFIG_PATH="$(opam config var prefix)/lib/pkgconfig" 4 - 5 - # Bridge through $XEN_CFLAGS from the environment into Oasis' world. 6 - # 7 - XEN_CFLAGS="disabled" 8 - grep -q '^xen="true"' setup.data && XEN_CFLAGS="$(pkg-config --static mirage-xen --cflags)" 9 - echo "XEN_CFLAGS=\"${XEN_CFLAGS}\"" >> setup.data 10 - 11 - FREESTANDING_CFLAGS="disabled" 12 - grep -q '^solo5="true"' setup.data && FREESTANDING_CFLAGS="$(pkg-config ocaml-freestanding --cflags)" 13 - echo "FREESTANDING_CFLAGS=\"${FREESTANDING_CFLAGS}\"" >> setup.data 14 - 15 - # Kill CPU acceleration if requested in ./configure, but: 16 - # * unsupported by the current host CPU; 17 - # * unsupported by the current toolchain; or 18 - # * disabled via NOCRYPTO_NO_ACCEL env var. 19 - # 20 - test_platform () { 21 - CPUDETECT=$(mktemp -t nocrypto.XXXXXX) 22 - (cc src/native/cpudetect_static.c -o ${CPUDETECT} > /dev/null 2>&1 && ${CPUDETECT}) 23 - ok=$? 24 - rm -f ${CPUDETECT} 25 - return $ok 26 - } 27 - if grep -q '^modernity="true"' setup.data; then 28 - [ -z $NOCRYPTO_NO_ACCEL ] && test_platform || echo "modernity=\"false\"" >> setup.data 29 - fi
+9
src/libnocrypto_stubs.clib
··· 1 + native/misc.o 2 + native/hash/stubs.o 3 + native/hash/md5.o 4 + native/hash/sha1.o 5 + native/hash/sha256.o 6 + native/hash/sha512.o 7 + native/aes/generic.o 8 + native/aes/aesni.o 9 + native/des/generic.o
+39 -39
src/native.ml
··· 15 15 16 16 17 17 module AES = struct 18 - external enc : buffer -> off -> buffer -> off -> key -> int -> size -> unit = "caml_nc_aes_enc_bc" "caml_nc_aes_enc" "noalloc" 19 - external dec : buffer -> off -> buffer -> off -> key -> int -> size -> unit = "caml_nc_aes_dec_bc" "caml_nc_aes_dec" "noalloc" 20 - external derive_e : secret -> off -> key -> int -> unit = "caml_nc_aes_derive_e_key" "noalloc" 21 - external derive_d : secret -> off -> key -> int -> key option -> unit = "caml_nc_aes_derive_d_key" "noalloc" 22 - external rk_s : int -> int = "caml_nc_aes_rk_size" "noalloc" 23 - external mode : unit -> int = "caml_nc_aes_mode" "noalloc" 18 + external enc : buffer -> off -> buffer -> off -> key -> int -> size -> unit = "caml_nc_aes_enc_bc" "caml_nc_aes_enc" [@@noalloc] 19 + external dec : buffer -> off -> buffer -> off -> key -> int -> size -> unit = "caml_nc_aes_dec_bc" "caml_nc_aes_dec" [@@noalloc] 20 + external derive_e : secret -> off -> key -> int -> unit = "caml_nc_aes_derive_e_key" [@@noalloc] 21 + external derive_d : secret -> off -> key -> int -> key option -> unit = "caml_nc_aes_derive_d_key" [@@noalloc] 22 + external rk_s : int -> int = "caml_nc_aes_rk_size" [@@noalloc] 23 + external mode : unit -> int = "caml_nc_aes_mode" [@@noalloc] 24 24 end 25 25 26 26 module DES = struct 27 - external ddes : buffer -> off -> buffer -> off -> int -> unit = "caml_nc_des_ddes" "noalloc" 28 - external des3key : secret -> off -> int -> unit = "caml_nc_des_des3key" "noalloc" 29 - external cp3key : key -> unit = "caml_nc_des_cp3key" "noalloc" 30 - external use3key : key -> unit = "caml_nc_des_use3key" "noalloc" 31 - external k_s : unit -> int = "caml_nc_des_key_size" "noalloc" 27 + external ddes : buffer -> off -> buffer -> off -> int -> unit = "caml_nc_des_ddes" [@@noalloc] 28 + external des3key : secret -> off -> int -> unit = "caml_nc_des_des3key" [@@noalloc] 29 + external cp3key : key -> unit = "caml_nc_des_cp3key" [@@noalloc] 30 + external use3key : key -> unit = "caml_nc_des_use3key" [@@noalloc] 31 + external k_s : unit -> int = "caml_nc_des_key_size" [@@noalloc] 32 32 end 33 33 34 34 module MD5 = struct 35 - external init : ctx -> unit = "caml_nc_md5_init" "noalloc" 36 - external update : ctx -> buffer -> off -> size -> unit = "caml_nc_md5_update" "noalloc" 37 - external finalize : ctx -> buffer -> off -> unit = "caml_nc_md5_finalize" "noalloc" 38 - external ctx_size : unit -> int = "caml_nc_md5_ctx_size" "noalloc" 35 + external init : ctx -> unit = "caml_nc_md5_init" [@@noalloc] 36 + external update : ctx -> buffer -> off -> size -> unit = "caml_nc_md5_update" [@@noalloc] 37 + external finalize : ctx -> buffer -> off -> unit = "caml_nc_md5_finalize" [@@noalloc] 38 + external ctx_size : unit -> int = "caml_nc_md5_ctx_size" [@@noalloc] 39 39 end 40 40 41 41 module SHA1 = struct 42 - external init : ctx -> unit = "caml_nc_sha1_init" "noalloc" 43 - external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha1_update" "noalloc" 44 - external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha1_finalize" "noalloc" 45 - external ctx_size : unit -> int = "caml_nc_sha1_ctx_size" "noalloc" 42 + external init : ctx -> unit = "caml_nc_sha1_init" [@@noalloc] 43 + external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha1_update" [@@noalloc] 44 + external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha1_finalize" [@@noalloc] 45 + external ctx_size : unit -> int = "caml_nc_sha1_ctx_size" [@@noalloc] 46 46 end 47 47 48 48 module SHA224 = struct 49 - external init : ctx -> unit = "caml_nc_sha224_init" "noalloc" 50 - external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha224_update" "noalloc" 51 - external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha224_finalize" "noalloc" 52 - external ctx_size : unit -> int = "caml_nc_sha224_ctx_size" "noalloc" 49 + external init : ctx -> unit = "caml_nc_sha224_init" [@@noalloc] 50 + external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha224_update" [@@noalloc] 51 + external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha224_finalize" [@@noalloc] 52 + external ctx_size : unit -> int = "caml_nc_sha224_ctx_size" [@@noalloc] 53 53 end 54 54 55 55 module SHA256 = struct 56 - external init : ctx -> unit = "caml_nc_sha256_init" "noalloc" 57 - external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha256_update" "noalloc" 58 - external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha256_finalize" "noalloc" 59 - external ctx_size : unit -> int = "caml_nc_sha256_ctx_size" "noalloc" 56 + external init : ctx -> unit = "caml_nc_sha256_init" [@@noalloc] 57 + external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha256_update" [@@noalloc] 58 + external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha256_finalize" [@@noalloc] 59 + external ctx_size : unit -> int = "caml_nc_sha256_ctx_size" [@@noalloc] 60 60 end 61 61 62 62 module SHA384 = struct 63 - external init : ctx -> unit = "caml_nc_sha384_init" "noalloc" 64 - external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha384_update" "noalloc" 65 - external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha384_finalize" "noalloc" 66 - external ctx_size : unit -> int = "caml_nc_sha384_ctx_size" "noalloc" 63 + external init : ctx -> unit = "caml_nc_sha384_init" [@@noalloc] 64 + external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha384_update" [@@noalloc] 65 + external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha384_finalize" [@@noalloc] 66 + external ctx_size : unit -> int = "caml_nc_sha384_ctx_size" [@@noalloc] 67 67 end 68 68 69 69 module SHA512 = struct 70 - external init : ctx -> unit = "caml_nc_sha512_init" "noalloc" 71 - external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha512_update" "noalloc" 72 - external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha512_finalize" "noalloc" 73 - external ctx_size : unit -> int = "caml_nc_sha512_ctx_size" "noalloc" 70 + external init : ctx -> unit = "caml_nc_sha512_init" [@@noalloc] 71 + external update : ctx -> buffer -> off -> size -> unit = "caml_nc_sha512_update" [@@noalloc] 72 + external finalize : ctx -> buffer -> off -> unit = "caml_nc_sha512_finalize" [@@noalloc] 73 + external ctx_size : unit -> int = "caml_nc_sha512_ctx_size" [@@noalloc] 74 74 end 75 75 76 76 (* XXX TODO 77 77 * Unsolved: bounds-checked XORs are slowing things down considerably... *) 78 - external xor_into : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_xor_into" "noalloc" 78 + external xor_into : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_xor_into" [@@noalloc] 79 79 80 - external count8be : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_count_8_be" "noalloc" 81 - external count16be : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_count_16_be" "noalloc" 80 + external count8be : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_count_8_be" [@@noalloc] 81 + external count16be : buffer -> off -> buffer -> off -> size -> unit = "caml_nc_count_16_be" [@@noalloc] 82 82 83 - external blit : buffer -> off -> buffer -> off -> size -> unit = "caml_blit_bigstring_to_bigstring" "noalloc" 83 + external blit : buffer -> off -> buffer -> off -> size -> unit = "caml_blit_bigstring_to_bigstring" [@@noalloc]
+1
src/nocrypto.mllib
··· 1 + Nocrypto
-3
src/nocrypto.mlpack
··· 1 - # OASIS_START 2 - # DO NOT EDIT (digest: 2bc9bac9457cbd1ffbed67ed78dcd301) 3 1 Uncommon 4 2 Base64 5 3 Hash ··· 15 13 Hmac_drgb 16 14 Gcm 17 15 Ccm 18 - # OASIS_STOP
+1 -1
tests/dsa_tests.ml
··· 2182 2182 2183 2183 let private_key ~p ~q ~g ~x ~y = priv_of_hex ~p ~q ~gg:g ~x ~y 2184 2184 2185 - let test_rfc6979 ~priv:({ Dsa.q; x } as priv) ~msg ~hash ~k ~r ~s _ = 2185 + let test_rfc6979 ~priv ~msg ~hash ~k ~r ~s _ = 2186 2186 let h1 = Hash.digest hash msg in 2187 2187 let k' = 2188 2188 let module H = (val (Hash.module_of hash)) in
+6 -6
tests/testlib.ml
··· 261 261 a5 23 69 38 7e ec b5 fc 4b 89 42 c4 32 fa e5 58 262 262 6f 39 5d a7 4e cd b5 da dc 1e 52 fe a4 33 72 c1 263 263 82 48 8a 5b c1 44 bc 60 9b 38 5b 80 5f 44 14 93" 264 - and x = Cs.of_hex 264 + and s = Cs.of_hex 265 265 "f9 47 87 95 d2 a1 6d d1 7c c8 a9 c0 71 28 a2 82 266 266 71 95 7e 79 87 0b fc 34 a2 42 ec 42 ac cc 42 81 267 267 7b f6 c4 f5 80 a9 70 e3 35 93 9b a3 21 81 a4 e3 ··· 290 290 in 291 291 let grp = Dh.Group.oakley_5 in 292 292 293 - match Dh.(shared grp (fst (key_of_secret grp x)) gy) with 293 + match Dh.(shared grp (fst (key_of_secret grp ~s)) gy) with 294 294 | None -> assert_failure "degenerate shared secret" 295 295 | Some shared' -> 296 296 assert_cs_equal ~msg:"shared secret" shared shared' ··· 877 877 ]; 878 878 879 879 "RNG extraction" >::: [ 880 - random_n_selftest "int" Fc.Rng.int 1000 [ 880 + random_n_selftest ~typ:"int" Fc.Rng.int 1000 [ 881 881 (1, 2); (0, 129); (7, 136); (0, 536870913); 882 882 ] ; 883 - random_n_selftest "int32" Fc.Rng.int32 1000 [ 883 + random_n_selftest ~typ:"int32" Fc.Rng.int32 1000 [ 884 884 (7l, 136l); (0l, 536870913l); 885 885 ] ; 886 - random_n_selftest "int64" Fc.Rng.int64 1000 [ 886 + random_n_selftest ~typ:"int64" Fc.Rng.int64 1000 [ 887 887 (7L, 136L); (0L, 536870913L); (0L, 2305843009213693953L); 888 888 ] ; 889 - random_n_selftest "Z" Fc.Rng.z 1000 [ 889 + random_n_selftest ~typ:"Z" Fc.Rng.z 1000 [ 890 890 Z.(of_int 7, of_int 135); 891 891 Z.(of_int 0, of_int 536870913); 892 892 Z.(of_int 0, of_int64 2305843009213693953L)
+11 -4
tests/testrunner.ml
··· 2 2 open OUnit2 3 3 4 4 (* Gather quantum uncertainty. *) 5 + (* let () = *) 6 + (* let t = Unix.gettimeofday () in *) 7 + (* let cs = Cstruct.create 8 in *) 8 + (* Cstruct.BE.set_uint64 cs 0 Int64.(of_float (t *. 1000.)) ; *) 9 + (* Nocrypto.Rng.reseed cs *) 10 + 11 + let () = Nocrypto_entropy_unix.initialize () 12 + 5 13 let () = 6 - let t = Unix.gettimeofday () in 7 - let cs = Cstruct.create 8 in 8 - Cstruct.BE.set_uint64 cs 0 Int64.(of_float (t *. 1000.)) ; 9 - Nocrypto.Rng.reseed cs 14 + Format.printf "AES mode: %s\n%!" 15 + (match Nocrypto.Cipher_block.AES.mode with 16 + | `AES_NI -> "AES-NI" | `Generic -> "soft") 10 17 11 18 let () = 12 19 (* Nocrypto.Rng.reseed @@ Cstruct.of_string "\001\002\003\004" ; *)
+1 -1
unix/nocrypto_entropy_unix.ml
··· 20 20 let buf = Bytes.create n in 21 21 let k = Unix.read fd buf 0 n in 22 22 let cs = Cstruct.create k in 23 - Cstruct.blit_from_string buf 0 cs 0 k ; 23 + Cstruct.blit_from_bytes buf 0 cs 0 k ; 24 24 cs 25 25 26 26 let reseed ?(bytes = a_little) ?(device = sys_rng) g =
+1
unix/nocrypto_unix.mllib
··· 1 + Nocrypto_entropy_unix