From c83176bf1b3c19aabf615894f0df2670423d7f2c Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Wed, 5 Aug 2020 16:51:56 +0100 Subject: [PATCH 01/22] Add .merlin to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ffcec6b..21e1863 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ setup.data setup.log *.native *~ +.merlin From e4f6d7ccd24e12ce65a63f529d1c03accc636239 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Wed, 5 Aug 2020 17:06:34 +0100 Subject: [PATCH 02/22] Add a first draft, including generated OPAM file --- cryptokit.opam | 34 ++++++++++++++++++++++++++++++++++ dune-project | 21 +++++++++++++++++++++ src/dune | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 cryptokit.opam create mode 100644 dune-project create mode 100644 src/dune diff --git a/cryptokit.opam b/cryptokit.opam new file mode 100644 index 0000000..0d4d7de --- /dev/null +++ b/cryptokit.opam @@ -0,0 +1,34 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A library of cryptographic primitives" +description: """ +Cryptokit includes block ciphers (AES, DES, 3DES), stream ciphers +(ARCfour), public-key crypto (RSA, DH), hashes (SHA-1, SHA-256, +SHA-3), MACs, compression, random number generation -- all presented +with a compositional, extensible interface.""" +maintainer: ["Xavier Leroy "] +authors: ["Xavier Leroy"] +homepage: "https://github.com/xavierleroy/cryptokit" +bug-reports: "https://github.com/xavierleroy/cryptokit/issues" +depends: [ + "dune" {>= "2.0"} + "ocaml" {>= "4.02.0"} + "zarith" {>= "1.4"} + "conf-zlib" + "conf-gmp-powm-sec" +] +build: [ + ["dune" "subst"] {pinned} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/xavierleroy/cryptokit.git" diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..34bd786 --- /dev/null +++ b/dune-project @@ -0,0 +1,21 @@ +(lang dune 2.0) +(generate_opam_files true) + +(source (github xavierleroy/cryptokit)) +(authors "Xavier Leroy") +(maintainers "Xavier Leroy ") + +(package + (name cryptokit) + (synopsis "A library of cryptographic primitives") + + (description "Cryptokit includes block ciphers (AES, DES, 3DES), stream ciphers +(ARCfour), public-key crypto (RSA, DH), hashes (SHA-1, SHA-256, +SHA-3), MACs, compression, random number generation -- all presented +with a compositional, extensible interface.") + + (depends + (ocaml (>= 4.02.0)) + (zarith (>= 1.4)) + conf-zlib + conf-gmp-powm-sec)) diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..5552ea6 --- /dev/null +++ b/src/dune @@ -0,0 +1,33 @@ +(library (name cryptokit) (public_name cryptokit) + (libraries unix zarith) + (modules CryptokitBignum Cryptokit) + (foreign_stubs + (language c) + (names aesni + arcfour + stubs-arcfour + blowfish + stubs-blowfish + d3des + stubs-des + rijndael-alg-fst + ripemd160 + stubs-ripemd160 + sha1 + stubs-sha1 + sha256 + stubs-sha256 + sha512 + stubs-sha512 + stubs-aes + stubs-md5 + stubs-misc + stubs-rng + stubs-zlib + keccak + stubs-sha3 + chacha20 + stubs-chacha20 + blake2 + stubs-blake2)) + (flags :standard -w -7 -w -27 -w -37)) From f0e28aca30edb7fecf6e616b04c48b4b825922b1 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Wed, 5 Aug 2020 17:10:57 +0100 Subject: [PATCH 03/22] Add -safe-string --- src/dune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dune b/src/dune index 5552ea6..2ddf4f2 100644 --- a/src/dune +++ b/src/dune @@ -30,4 +30,4 @@ stubs-chacha20 blake2 stubs-blake2)) - (flags :standard -w -7 -w -27 -w -37)) + (flags :standard -safe-string -w -7 -w -27 -w -37)) From 777156fa9afc8b6998fd2b75db1948505953dbdd Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Wed, 5 Aug 2020 17:12:17 +0100 Subject: [PATCH 04/22] Delete _tags --- _tags | 128 ---------------------------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 _tags diff --git a/_tags b/_tags deleted file mode 100644 index 2375723..0000000 --- a/_tags +++ /dev/null @@ -1,128 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 552f3e8992f1455e10be051255154125) -# Ignore VCS directories, you can use the same kind of rule outside -# OASIS_START/STOP if you want to exclude directories that contains -# useless stuff for the build process -true: annot, bin_annot -<**/.svn>: -traverse -<**/.svn>: not_hygienic -".bzr": -traverse -".bzr": not_hygienic -".hg": -traverse -".hg": not_hygienic -".git": -traverse -".git": not_hygienic -"_darcs": -traverse -"_darcs": not_hygienic -# Library cryptokit -"src/cryptokit.cmxs": use_cryptokit -: oasis_library_cryptokit_ccopt -"src/aesni.c": oasis_library_cryptokit_ccopt -"src/arcfour.c": oasis_library_cryptokit_ccopt -"src/stubs-arcfour.c": oasis_library_cryptokit_ccopt -"src/blowfish.c": oasis_library_cryptokit_ccopt -"src/stubs-blowfish.c": oasis_library_cryptokit_ccopt -"src/d3des.c": oasis_library_cryptokit_ccopt -"src/stubs-des.c": oasis_library_cryptokit_ccopt -"src/rijndael-alg-fst.c": oasis_library_cryptokit_ccopt -"src/ripemd160.c": oasis_library_cryptokit_ccopt -"src/stubs-ripemd160.c": oasis_library_cryptokit_ccopt -"src/sha1.c": oasis_library_cryptokit_ccopt -"src/stubs-sha1.c": oasis_library_cryptokit_ccopt -"src/sha256.c": oasis_library_cryptokit_ccopt -"src/stubs-sha256.c": oasis_library_cryptokit_ccopt -"src/sha512.c": oasis_library_cryptokit_ccopt -"src/stubs-sha512.c": oasis_library_cryptokit_ccopt -"src/stubs-aes.c": oasis_library_cryptokit_ccopt -"src/stubs-md5.c": oasis_library_cryptokit_ccopt -"src/stubs-misc.c": oasis_library_cryptokit_ccopt -"src/stubs-rng.c": oasis_library_cryptokit_ccopt -"src/stubs-zlib.c": oasis_library_cryptokit_ccopt -"src/keccak.c": oasis_library_cryptokit_ccopt -"src/stubs-sha3.c": oasis_library_cryptokit_ccopt -"src/chacha20.c": oasis_library_cryptokit_ccopt -"src/stubs-chacha20.c": oasis_library_cryptokit_ccopt -"src/blake2.c": oasis_library_cryptokit_ccopt -"src/stubs-blake2.c": oasis_library_cryptokit_ccopt -: oasis_library_cryptokit_cclib -"src/libcryptokit_stubs.lib": oasis_library_cryptokit_cclib -"src/dllcryptokit_stubs.dll": oasis_library_cryptokit_cclib -"src/libcryptokit_stubs.a": oasis_library_cryptokit_cclib -"src/dllcryptokit_stubs.so": oasis_library_cryptokit_cclib -: use_libcryptokit_stubs -: pkg_unix -: pkg_zarith -"src/aesni.c": pkg_unix -"src/aesni.c": pkg_zarith -"src/arcfour.c": pkg_unix -"src/arcfour.c": pkg_zarith -"src/stubs-arcfour.c": pkg_unix -"src/stubs-arcfour.c": pkg_zarith -"src/blowfish.c": pkg_unix -"src/blowfish.c": pkg_zarith -"src/stubs-blowfish.c": pkg_unix -"src/stubs-blowfish.c": pkg_zarith -"src/d3des.c": pkg_unix -"src/d3des.c": pkg_zarith -"src/stubs-des.c": pkg_unix -"src/stubs-des.c": pkg_zarith -"src/rijndael-alg-fst.c": pkg_unix -"src/rijndael-alg-fst.c": pkg_zarith -"src/ripemd160.c": pkg_unix -"src/ripemd160.c": pkg_zarith -"src/stubs-ripemd160.c": pkg_unix -"src/stubs-ripemd160.c": pkg_zarith -"src/sha1.c": pkg_unix -"src/sha1.c": pkg_zarith -"src/stubs-sha1.c": pkg_unix -"src/stubs-sha1.c": pkg_zarith -"src/sha256.c": pkg_unix -"src/sha256.c": pkg_zarith -"src/stubs-sha256.c": pkg_unix -"src/stubs-sha256.c": pkg_zarith -"src/sha512.c": pkg_unix -"src/sha512.c": pkg_zarith -"src/stubs-sha512.c": pkg_unix -"src/stubs-sha512.c": pkg_zarith -"src/stubs-aes.c": pkg_unix -"src/stubs-aes.c": pkg_zarith -"src/stubs-md5.c": pkg_unix -"src/stubs-md5.c": pkg_zarith -"src/stubs-misc.c": pkg_unix -"src/stubs-misc.c": pkg_zarith -"src/stubs-rng.c": pkg_unix -"src/stubs-rng.c": pkg_zarith -"src/stubs-zlib.c": pkg_unix -"src/stubs-zlib.c": pkg_zarith -"src/keccak.c": pkg_unix -"src/keccak.c": pkg_zarith -"src/stubs-sha3.c": pkg_unix -"src/stubs-sha3.c": pkg_zarith -"src/chacha20.c": pkg_unix -"src/chacha20.c": pkg_zarith -"src/stubs-chacha20.c": pkg_unix -"src/stubs-chacha20.c": pkg_zarith -"src/blake2.c": pkg_unix -"src/blake2.c": pkg_zarith -"src/stubs-blake2.c": pkg_unix -"src/stubs-blake2.c": pkg_zarith -# Executable test -"test/test.native": pkg_unix -"test/test.native": pkg_zarith -"test/test.native": use_cryptokit -# Executable prngtest -"test/prngtest.native": pkg_unix -"test/prngtest.native": pkg_zarith -"test/prngtest.native": use_cryptokit -# Executable speedtest -"test/speedtest.native": pkg_unix -"test/speedtest.native": pkg_zarith -"test/speedtest.native": use_cryptokit -: pkg_unix -: pkg_zarith -: use_cryptokit -# OASIS_STOP -"build": not_hygienic -"build": -traverse -"src/cryptokit.cmxs": use_libcryptokit_stubs -<*/*.cm{o,x}>: safe_string From cbd1995658cd5dcc4c8b9b0a4081994d5b7fb4e4 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Wed, 5 Aug 2020 17:33:15 +0100 Subject: [PATCH 05/22] Add tests --- test/dune | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/dune diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..4ce938a --- /dev/null +++ b/test/dune @@ -0,0 +1,21 @@ +(executable + (public_name test) + (modules test) + (libraries cryptokit) + (flags :standard -w -35)) + +(executable + (public_name prngtest) + (modules prngtest) + (libraries cryptokit)) + +(executable + (public_name speedtest) + (modules speedtest) + (libraries cryptokit) + (flags :standard -w -35)) + +; We only add test.exe to the standard runtest target +(rule + (alias runtest) + (action (run ./test.exe))) From b884eb600ee88b50ae8ef792ce0d4ffe2831db40 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 09:36:56 +0100 Subject: [PATCH 06/22] Restore _tags --- _tags | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 _tags diff --git a/_tags b/_tags new file mode 100644 index 0000000..2375723 --- /dev/null +++ b/_tags @@ -0,0 +1,128 @@ +# OASIS_START +# DO NOT EDIT (digest: 552f3e8992f1455e10be051255154125) +# Ignore VCS directories, you can use the same kind of rule outside +# OASIS_START/STOP if you want to exclude directories that contains +# useless stuff for the build process +true: annot, bin_annot +<**/.svn>: -traverse +<**/.svn>: not_hygienic +".bzr": -traverse +".bzr": not_hygienic +".hg": -traverse +".hg": not_hygienic +".git": -traverse +".git": not_hygienic +"_darcs": -traverse +"_darcs": not_hygienic +# Library cryptokit +"src/cryptokit.cmxs": use_cryptokit +: oasis_library_cryptokit_ccopt +"src/aesni.c": oasis_library_cryptokit_ccopt +"src/arcfour.c": oasis_library_cryptokit_ccopt +"src/stubs-arcfour.c": oasis_library_cryptokit_ccopt +"src/blowfish.c": oasis_library_cryptokit_ccopt +"src/stubs-blowfish.c": oasis_library_cryptokit_ccopt +"src/d3des.c": oasis_library_cryptokit_ccopt +"src/stubs-des.c": oasis_library_cryptokit_ccopt +"src/rijndael-alg-fst.c": oasis_library_cryptokit_ccopt +"src/ripemd160.c": oasis_library_cryptokit_ccopt +"src/stubs-ripemd160.c": oasis_library_cryptokit_ccopt +"src/sha1.c": oasis_library_cryptokit_ccopt +"src/stubs-sha1.c": oasis_library_cryptokit_ccopt +"src/sha256.c": oasis_library_cryptokit_ccopt +"src/stubs-sha256.c": oasis_library_cryptokit_ccopt +"src/sha512.c": oasis_library_cryptokit_ccopt +"src/stubs-sha512.c": oasis_library_cryptokit_ccopt +"src/stubs-aes.c": oasis_library_cryptokit_ccopt +"src/stubs-md5.c": oasis_library_cryptokit_ccopt +"src/stubs-misc.c": oasis_library_cryptokit_ccopt +"src/stubs-rng.c": oasis_library_cryptokit_ccopt +"src/stubs-zlib.c": oasis_library_cryptokit_ccopt +"src/keccak.c": oasis_library_cryptokit_ccopt +"src/stubs-sha3.c": oasis_library_cryptokit_ccopt +"src/chacha20.c": oasis_library_cryptokit_ccopt +"src/stubs-chacha20.c": oasis_library_cryptokit_ccopt +"src/blake2.c": oasis_library_cryptokit_ccopt +"src/stubs-blake2.c": oasis_library_cryptokit_ccopt +: oasis_library_cryptokit_cclib +"src/libcryptokit_stubs.lib": oasis_library_cryptokit_cclib +"src/dllcryptokit_stubs.dll": oasis_library_cryptokit_cclib +"src/libcryptokit_stubs.a": oasis_library_cryptokit_cclib +"src/dllcryptokit_stubs.so": oasis_library_cryptokit_cclib +: use_libcryptokit_stubs +: pkg_unix +: pkg_zarith +"src/aesni.c": pkg_unix +"src/aesni.c": pkg_zarith +"src/arcfour.c": pkg_unix +"src/arcfour.c": pkg_zarith +"src/stubs-arcfour.c": pkg_unix +"src/stubs-arcfour.c": pkg_zarith +"src/blowfish.c": pkg_unix +"src/blowfish.c": pkg_zarith +"src/stubs-blowfish.c": pkg_unix +"src/stubs-blowfish.c": pkg_zarith +"src/d3des.c": pkg_unix +"src/d3des.c": pkg_zarith +"src/stubs-des.c": pkg_unix +"src/stubs-des.c": pkg_zarith +"src/rijndael-alg-fst.c": pkg_unix +"src/rijndael-alg-fst.c": pkg_zarith +"src/ripemd160.c": pkg_unix +"src/ripemd160.c": pkg_zarith +"src/stubs-ripemd160.c": pkg_unix +"src/stubs-ripemd160.c": pkg_zarith +"src/sha1.c": pkg_unix +"src/sha1.c": pkg_zarith +"src/stubs-sha1.c": pkg_unix +"src/stubs-sha1.c": pkg_zarith +"src/sha256.c": pkg_unix +"src/sha256.c": pkg_zarith +"src/stubs-sha256.c": pkg_unix +"src/stubs-sha256.c": pkg_zarith +"src/sha512.c": pkg_unix +"src/sha512.c": pkg_zarith +"src/stubs-sha512.c": pkg_unix +"src/stubs-sha512.c": pkg_zarith +"src/stubs-aes.c": pkg_unix +"src/stubs-aes.c": pkg_zarith +"src/stubs-md5.c": pkg_unix +"src/stubs-md5.c": pkg_zarith +"src/stubs-misc.c": pkg_unix +"src/stubs-misc.c": pkg_zarith +"src/stubs-rng.c": pkg_unix +"src/stubs-rng.c": pkg_zarith +"src/stubs-zlib.c": pkg_unix +"src/stubs-zlib.c": pkg_zarith +"src/keccak.c": pkg_unix +"src/keccak.c": pkg_zarith +"src/stubs-sha3.c": pkg_unix +"src/stubs-sha3.c": pkg_zarith +"src/chacha20.c": pkg_unix +"src/chacha20.c": pkg_zarith +"src/stubs-chacha20.c": pkg_unix +"src/stubs-chacha20.c": pkg_zarith +"src/blake2.c": pkg_unix +"src/blake2.c": pkg_zarith +"src/stubs-blake2.c": pkg_unix +"src/stubs-blake2.c": pkg_zarith +# Executable test +"test/test.native": pkg_unix +"test/test.native": pkg_zarith +"test/test.native": use_cryptokit +# Executable prngtest +"test/prngtest.native": pkg_unix +"test/prngtest.native": pkg_zarith +"test/prngtest.native": use_cryptokit +# Executable speedtest +"test/speedtest.native": pkg_unix +"test/speedtest.native": pkg_zarith +"test/speedtest.native": use_cryptokit +: pkg_unix +: pkg_zarith +: use_cryptokit +# OASIS_STOP +"build": not_hygienic +"build": -traverse +"src/cryptokit.cmxs": use_libcryptokit_stubs +<*/*.cm{o,x}>: safe_string From e8386cb8c4435e842ed26edec299034cd8b34b55 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 11:38:15 +0100 Subject: [PATCH 07/22] Refactor tests --- test/dune | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/dune b/test/dune index 4ce938a..3e89187 100644 --- a/test/dune +++ b/test/dune @@ -1,21 +1,16 @@ -(executable - (public_name test) +(test + (name test) (modules test) (libraries cryptokit) (flags :standard -w -35)) (executable - (public_name prngtest) + (name prngtest) (modules prngtest) (libraries cryptokit)) (executable - (public_name speedtest) + (name speedtest) (modules speedtest) (libraries cryptokit) (flags :standard -w -35)) - -; We only add test.exe to the standard runtest target -(rule - (alias runtest) - (action (run ./test.exe))) From 01830e3bb8e3d247fd0784ec20a134df5d534374 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 11:38:49 +0100 Subject: [PATCH 08/22] Compute flags --- src/compute_flags.ml | 37 +++++++++++++++++++++++++++++++++++++ src/dune | 8 ++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/compute_flags.ml diff --git a/src/compute_flags.ml b/src/compute_flags.ml new file mode 100644 index 0000000..a572590 --- /dev/null +++ b/src/compute_flags.ml @@ -0,0 +1,37 @@ +(* Compute compilation and linking flags *) + +let write_sexp file list = + let oc = open_out file in + let content = String.concat " " list in + Printf.fprintf oc "(%s)" content; + close_out oc + +(* TODO: Allow overriding [zlib] and [hardwaresupport]. *) +let compute_flags ~os_type ~system ~architecture = + let zlib = os_type <> "Win32" in + let hardwaresupport = + architecture = "amd64" || (architecture = "i386" && os_type <> "Win32") + in + let append_if c y x = if c then x @ [ y ] else x in + let flags = + [ "-DCAML_NAME_SPACE" ] + |> append_if zlib "-DHAVE_ZLIB" + |> append_if hardwaresupport "-maes" + in + let library_flags = + [] + |> append_if (zlib && (system = "win32" || system = "win64")) "zlib.lib" + |> append_if (zlib && system <> "win32" && system <> "win64") "-lz" + |> append_if (system = "win32" || system = "win64") "advapi32.lib" + |> append_if (system = "mingw" || system = "mingw64") "-ladvapi32" + in + write_sexp "flags.sexp" flags; + write_sexp "library_flags.sexp" library_flags + +let () = + match Sys.argv with + | [| + _; "-os_type"; os_type; "-system"; system; "-architecture"; architecture; + |] -> + compute_flags ~os_type ~system ~architecture + | _ -> failwith "unexpected command line arguments" diff --git a/src/dune b/src/dune index 2ddf4f2..e5eb96b 100644 --- a/src/dune +++ b/src/dune @@ -3,6 +3,7 @@ (modules CryptokitBignum Cryptokit) (foreign_stubs (language c) + (flags (:include flags.sexp)) (names aesni arcfour stubs-arcfour @@ -30,4 +31,11 @@ stubs-chacha20 blake2 stubs-blake2)) + (c_library_flags (:include library_flags.sexp)) (flags :standard -safe-string -w -7 -w -27 -w -37)) + +; compute flags +(rule (targets flags.sexp library_flags.sexp) + (deps (:first_dep compute_flags.ml)) + (action + (run %{ocaml} %{first_dep} -os_type %{os_type} -system %{system} -architecture %{architecture}))) From 1684fb32415a04c2f639e8849b6cae60aef4633d Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 11:53:05 +0100 Subject: [PATCH 09/22] Minor tweaks --- src/compute_flags.ml | 6 +++--- src/dune | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compute_flags.ml b/src/compute_flags.ml index a572590..0d0c9cc 100644 --- a/src/compute_flags.ml +++ b/src/compute_flags.ml @@ -2,11 +2,11 @@ let write_sexp file list = let oc = open_out file in - let content = String.concat " " list in + let content = List.map (Printf.sprintf "%S") list |> String.concat " " in Printf.fprintf oc "(%s)" content; close_out oc -(* TODO: Allow overriding [zlib] and [hardwaresupport]. *) +(* We could also allow the user to override [zlib] and [hardwaresupport]. *) let compute_flags ~os_type ~system ~architecture = let zlib = os_type <> "Win32" in let hardwaresupport = @@ -14,7 +14,7 @@ let compute_flags ~os_type ~system ~architecture = in let append_if c y x = if c then x @ [ y ] else x in let flags = - [ "-DCAML_NAME_SPACE" ] + [] |> append_if zlib "-DHAVE_ZLIB" |> append_if hardwaresupport "-maes" in diff --git a/src/dune b/src/dune index e5eb96b..6d5c119 100644 --- a/src/dune +++ b/src/dune @@ -3,7 +3,7 @@ (modules CryptokitBignum Cryptokit) (foreign_stubs (language c) - (flags (:include flags.sexp)) + (flags -DCAML_NAME_SPACE (:include flags.sexp)) (names aesni arcfour stubs-arcfour From 151a4b31df0a4d872c4b18ed6fd80a6ad2d5a977 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 12:06:12 +0100 Subject: [PATCH 10/22] Update README --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b05b631..e83d05d 100644 --- a/README.md +++ b/README.md @@ -17,28 +17,28 @@ This library is distributed under the conditions of the GNU Library General Publ ## Requirements * OCaml 4.02 or more recent. -* The findlib/ocamlfind tool. -* The OASIS tool. +* The Dune build system. * The Zarith library, version 1.4 or more recent. * The Zlib C library, version 1.1.3 or up is recommended. If it is not installed on your system (look for libz.a or libz.so), get it from http://www.gzip.org/, or indicate in the Makefile that you do not have it. If you are running Linux or BSD or MacOS, your distribution provides precompiled binaries for this library. * If the operating system does not provide the `/dev/random` device for random number generation, consider installing the [EGD](http://egd.sourceforge.net/) entropy gathering daemon. Without `/dev/random` nor EGD, this library cannot generate cryptographically-strong random data nor RSA keys. The remainder of the library still works, though. -## Installation +## Build, test and install -``` -./configure --enable-tests -make -make test -make install -``` +* To build, run `dune build`. -## Documentation +* To execute a test, run `dune exec test/.exe` where `` can be `test`, + `prngtest` or `speedtest`, supplying additional command line parameters if needed. + The main test file `test/test.ml` is also included into the `runtest` alias, so it + can be executed simply by `dune test`. + +* To install, run `dune install`. -See the extensive documentation comments in file src/cryptokit.mli. +## Documentation -Compilation options: `ocamlfind ocamlopt -package cryptokit`... +See the extensive documentation comments in file `src/cryptokit.mli`. -Linking options: `ocamlfind ocamlopt -linkpkg -package cryptokit`... +To build HTML documentation, run `dune build @doc`. The resulting index file is +located at `_build/default/_doc/_html/cryptokit/Cryptokit/index.html`. ## Warnings and disclaimers From dec10173d3d6091b927ad94c63a321d457a09ce8 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 12:07:56 +0100 Subject: [PATCH 11/22] Delete OASIS files --- Makefile | 41 ---------- _oasis | 148 ------------------------------------ _tags | 128 ------------------------------- configure | 27 ------- setup.ml | 39 ---------- src/META | 12 --- src/api-cryptokit.odocl | 5 -- src/cryptokit.mldylib | 5 -- src/cryptokit.mllib | 5 -- src/libcryptokit_stubs.clib | 30 -------- 10 files changed, 440 deletions(-) delete mode 100644 Makefile delete mode 100644 _oasis delete mode 100644 _tags delete mode 100755 configure delete mode 100644 setup.ml delete mode 100644 src/META delete mode 100644 src/api-cryptokit.odocl delete mode 100644 src/cryptokit.mldylib delete mode 100644 src/cryptokit.mllib delete mode 100644 src/libcryptokit_stubs.clib diff --git a/Makefile b/Makefile deleted file mode 100644 index 3639f14..0000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: a3c674b4239234cbbe53afe090018954) - -SETUP = ocaml setup.ml - -build: setup.data - $(SETUP) -build $(BUILDFLAGS) - -doc: setup.data build - $(SETUP) -doc $(DOCFLAGS) - -test: setup.data build - $(SETUP) -test $(TESTFLAGS) - -all: - $(SETUP) -all $(ALLFLAGS) - -install: setup.data - $(SETUP) -install $(INSTALLFLAGS) - -uninstall: setup.data - $(SETUP) -uninstall $(UNINSTALLFLAGS) - -reinstall: setup.data - $(SETUP) -reinstall $(REINSTALLFLAGS) - -clean: - $(SETUP) -clean $(CLEANFLAGS) - -distclean: - $(SETUP) -distclean $(DISTCLEANFLAGS) - -setup.data: - $(SETUP) -configure $(CONFIGUREFLAGS) - -configure: - $(SETUP) -configure $(CONFIGUREFLAGS) - -.PHONY: build doc test all install uninstall reinstall clean distclean configure - -# OASIS_STOP diff --git a/_oasis b/_oasis deleted file mode 100644 index 67b6d0b..0000000 --- a/_oasis +++ /dev/null @@ -1,148 +0,0 @@ -OASISFormat: 0.4 -Name: cryptokit -Version: 1.15 -Authors: Xavier Leroy -License: LGPL-2 with OCaml linking exception -BuildTools: ocamlbuild, ocamldoc -Plugins: META (0.4), DevFiles (0.4) - -Synopsis: Cryptographic primitives -Description: - This library provides a variety of cryptographic primitives that can be used - to implement cryptographic protocols in security-sensitive applications. The - primitives provided include: - . - - Symmetric-key ciphers: AES, Chacha20, Blowfish, DES, Triple-DES, ARCfour, - in ECB, CBC, CFB, OFB and counter modes. - - Public-key cryptography: RSA encryption, Diffie-Hellman key agreement. - - Hash functions and MACs: SHA-1, SHA-2, SHA-3, RIPEMD160, MD5, - and MACs based on AES and DES. - - Random number generation. - - Encodings and compression: base 64, hexadecimal, Zlib compression. - . - Additional ciphers and hashes can easily be used in conjunction with - the library. In particular, basic mechanisms such as chaining modes, - output buffering, and padding are provided by generic classes that can - easily be composed with user-provided ciphers. More generally, the library - promotes a "Lego"-like style of constructing and composing - transformations over character streams. - -Flag zlib - Description: Enable ZLib - Default$: !os_type(Win32) - -Flag hardwaresupport - Description: Enable hardware support for AES and GCM (needs GCC or Clang) - Default$: (architecture(amd64) || architecture(i386)) && !os_type(Win32) - -Library cryptokit - Path: src - Modules: CryptokitBignum, Cryptokit - CSources: aesni.c, - aesni.h, - arcfour.c, - arcfour.h, - stubs-arcfour.c, - blowfish.c, - blowfish.h, - stubs-blowfish.c, - d3des.c, - d3des.h, - stubs-des.c, - rijndael-alg-fst.c, - rijndael-alg-fst.h, - ripemd160.c, - ripemd160.h, - stubs-ripemd160.c, - sha1.c, - sha1.h, - stubs-sha1.c, - sha256.c, - sha256.h, - stubs-sha256.c, - sha512.c, - sha512.h, - stubs-sha512.c, - stubs-aes.c, - stubs-md5.c, - stubs-misc.c, - stubs-rng.c, - stubs-zlib.c, - keccak.h, - keccak.c, - stubs-sha3.c, - chacha20.h, - chacha20.c, - stubs-chacha20.c, - blake2.h, - blake2.c, - stubs-blake2.c - BuildDepends: unix, zarith - CCOpt: -DCAML_NAME_SPACE - if flag(zlib) - CCOpt+: -DHAVE_ZLIB - if system(win32) || system(win64) - CCLib: zlib.lib - else - CCLib: -lz - if system(win32) || system(win64) - CCLib+: advapi32.lib - else if system(mingw) || system(mingw64) - CCLib+: -ladvapi32 - if flag(hardwaresupport) - CCOpt+: -maes - -Executable test - Path: test - MainIs: test.ml - CompiledObject: native - BuildDepends: cryptokit - Build$: flag(tests) - Install: false - -Executable prngtest - Path: test - MainIs: prngtest.ml - CompiledObject: native - BuildDepends: cryptokit - Build$: flag(tests) - Install: false - -Test main - Command: $test - TestTools: test - -Flag bench - Description: Build and run benchmark - Default: false - -Executable speedtest - Path: test - MainIs: speedtest.ml - CompiledObject: native - BuildDepends: cryptokit - Install: false - Build$: flag(bench) - -Test bench - Command: $speedtest - Run$: flag(bench) - TestTools: speedtest - -Document "api-cryptokit" - Title: API reference for Cryptokit - Type: ocamlbuild (0.3) - InstallDir: $htmldir/cryptokit - BuildTools+: ocamldoc - XOCamlBuildPath: src/ - XOCamlbuildLibraries: cryptokit - -SourceRepository head - Type: git - Location: https://github.com/xavierleroy/cryptokit - Browser: https://github.com/xavierleroy/cryptokit - -SourceRepository this - Type: git - Location: https://github.com/xavierleroy/cryptokit/releases/tag/release113 - Browser: https://github.com/xavierleroy/cryptokit/releases/tag/release113 diff --git a/_tags b/_tags deleted file mode 100644 index 2375723..0000000 --- a/_tags +++ /dev/null @@ -1,128 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 552f3e8992f1455e10be051255154125) -# Ignore VCS directories, you can use the same kind of rule outside -# OASIS_START/STOP if you want to exclude directories that contains -# useless stuff for the build process -true: annot, bin_annot -<**/.svn>: -traverse -<**/.svn>: not_hygienic -".bzr": -traverse -".bzr": not_hygienic -".hg": -traverse -".hg": not_hygienic -".git": -traverse -".git": not_hygienic -"_darcs": -traverse -"_darcs": not_hygienic -# Library cryptokit -"src/cryptokit.cmxs": use_cryptokit -: oasis_library_cryptokit_ccopt -"src/aesni.c": oasis_library_cryptokit_ccopt -"src/arcfour.c": oasis_library_cryptokit_ccopt -"src/stubs-arcfour.c": oasis_library_cryptokit_ccopt -"src/blowfish.c": oasis_library_cryptokit_ccopt -"src/stubs-blowfish.c": oasis_library_cryptokit_ccopt -"src/d3des.c": oasis_library_cryptokit_ccopt -"src/stubs-des.c": oasis_library_cryptokit_ccopt -"src/rijndael-alg-fst.c": oasis_library_cryptokit_ccopt -"src/ripemd160.c": oasis_library_cryptokit_ccopt -"src/stubs-ripemd160.c": oasis_library_cryptokit_ccopt -"src/sha1.c": oasis_library_cryptokit_ccopt -"src/stubs-sha1.c": oasis_library_cryptokit_ccopt -"src/sha256.c": oasis_library_cryptokit_ccopt -"src/stubs-sha256.c": oasis_library_cryptokit_ccopt -"src/sha512.c": oasis_library_cryptokit_ccopt -"src/stubs-sha512.c": oasis_library_cryptokit_ccopt -"src/stubs-aes.c": oasis_library_cryptokit_ccopt -"src/stubs-md5.c": oasis_library_cryptokit_ccopt -"src/stubs-misc.c": oasis_library_cryptokit_ccopt -"src/stubs-rng.c": oasis_library_cryptokit_ccopt -"src/stubs-zlib.c": oasis_library_cryptokit_ccopt -"src/keccak.c": oasis_library_cryptokit_ccopt -"src/stubs-sha3.c": oasis_library_cryptokit_ccopt -"src/chacha20.c": oasis_library_cryptokit_ccopt -"src/stubs-chacha20.c": oasis_library_cryptokit_ccopt -"src/blake2.c": oasis_library_cryptokit_ccopt -"src/stubs-blake2.c": oasis_library_cryptokit_ccopt -: oasis_library_cryptokit_cclib -"src/libcryptokit_stubs.lib": oasis_library_cryptokit_cclib -"src/dllcryptokit_stubs.dll": oasis_library_cryptokit_cclib -"src/libcryptokit_stubs.a": oasis_library_cryptokit_cclib -"src/dllcryptokit_stubs.so": oasis_library_cryptokit_cclib -: use_libcryptokit_stubs -: pkg_unix -: pkg_zarith -"src/aesni.c": pkg_unix -"src/aesni.c": pkg_zarith -"src/arcfour.c": pkg_unix -"src/arcfour.c": pkg_zarith -"src/stubs-arcfour.c": pkg_unix -"src/stubs-arcfour.c": pkg_zarith -"src/blowfish.c": pkg_unix -"src/blowfish.c": pkg_zarith -"src/stubs-blowfish.c": pkg_unix -"src/stubs-blowfish.c": pkg_zarith -"src/d3des.c": pkg_unix -"src/d3des.c": pkg_zarith -"src/stubs-des.c": pkg_unix -"src/stubs-des.c": pkg_zarith -"src/rijndael-alg-fst.c": pkg_unix -"src/rijndael-alg-fst.c": pkg_zarith -"src/ripemd160.c": pkg_unix -"src/ripemd160.c": pkg_zarith -"src/stubs-ripemd160.c": pkg_unix -"src/stubs-ripemd160.c": pkg_zarith -"src/sha1.c": pkg_unix -"src/sha1.c": pkg_zarith -"src/stubs-sha1.c": pkg_unix -"src/stubs-sha1.c": pkg_zarith -"src/sha256.c": pkg_unix -"src/sha256.c": pkg_zarith -"src/stubs-sha256.c": pkg_unix -"src/stubs-sha256.c": pkg_zarith -"src/sha512.c": pkg_unix -"src/sha512.c": pkg_zarith -"src/stubs-sha512.c": pkg_unix -"src/stubs-sha512.c": pkg_zarith -"src/stubs-aes.c": pkg_unix -"src/stubs-aes.c": pkg_zarith -"src/stubs-md5.c": pkg_unix -"src/stubs-md5.c": pkg_zarith -"src/stubs-misc.c": pkg_unix -"src/stubs-misc.c": pkg_zarith -"src/stubs-rng.c": pkg_unix -"src/stubs-rng.c": pkg_zarith -"src/stubs-zlib.c": pkg_unix -"src/stubs-zlib.c": pkg_zarith -"src/keccak.c": pkg_unix -"src/keccak.c": pkg_zarith -"src/stubs-sha3.c": pkg_unix -"src/stubs-sha3.c": pkg_zarith -"src/chacha20.c": pkg_unix -"src/chacha20.c": pkg_zarith -"src/stubs-chacha20.c": pkg_unix -"src/stubs-chacha20.c": pkg_zarith -"src/blake2.c": pkg_unix -"src/blake2.c": pkg_zarith -"src/stubs-blake2.c": pkg_unix -"src/stubs-blake2.c": pkg_zarith -# Executable test -"test/test.native": pkg_unix -"test/test.native": pkg_zarith -"test/test.native": use_cryptokit -# Executable prngtest -"test/prngtest.native": pkg_unix -"test/prngtest.native": pkg_zarith -"test/prngtest.native": use_cryptokit -# Executable speedtest -"test/speedtest.native": pkg_unix -"test/speedtest.native": pkg_zarith -"test/speedtest.native": use_cryptokit -: pkg_unix -: pkg_zarith -: use_cryptokit -# OASIS_STOP -"build": not_hygienic -"build": -traverse -"src/cryptokit.cmxs": use_libcryptokit_stubs -<*/*.cm{o,x}>: safe_string diff --git a/configure b/configure deleted file mode 100755 index 6acfaeb..0000000 --- a/configure +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# OASIS_START -# DO NOT EDIT (digest: dc86c2ad450f91ca10c931b6045d0499) -set -e - -FST=true -for i in "$@"; do - if $FST; then - set -- - FST=false - fi - - case $i in - --*=*) - ARG=${i%%=*} - VAL=${i##*=} - set -- "$@" "$ARG" "$VAL" - ;; - *) - set -- "$@" "$i" - ;; - esac -done - -ocaml setup.ml -configure "$@" -# OASIS_STOP diff --git a/setup.ml b/setup.ml deleted file mode 100644 index a07ec9f..0000000 --- a/setup.ml +++ /dev/null @@ -1,39 +0,0 @@ -(* setup.ml generated for the first time by OASIS v0.4.6 *) - -(* OASIS_START *) -(* DO NOT EDIT (digest: a426e2d026defb34183b787d31fbdcff) *) -(******************************************************************************) -(* OASIS: architecture for building OCaml libraries and applications *) -(* *) -(* Copyright (C) 2011-2016, Sylvain Le Gall *) -(* Copyright (C) 2008-2011, OCamlCore SARL *) -(* *) -(* This library is free software; you can redistribute it and/or modify it *) -(* under the terms of the GNU Lesser General Public License as published by *) -(* the Free Software Foundation; either version 2.1 of the License, or (at *) -(* your option) any later version, with the OCaml static compilation *) -(* exception. *) -(* *) -(* This library is distributed in the hope that it will be useful, but *) -(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *) -(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more *) -(* details. *) -(* *) -(* You should have received a copy of the GNU Lesser General Public License *) -(* along with this library; if not, write to the Free Software Foundation, *) -(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *) -(******************************************************************************) - -let () = - try - Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") - with Not_found -> () -;; -#use "topfind";; -#require "oasis.dynrun";; -open OASISDynRun;; - -let setup_t = BaseCompat.Compat_0_4.adapt_setup_t setup_t -open BaseCompat.Compat_0_4 -(* OASIS_STOP *) -let () = setup ();; diff --git a/src/META b/src/META deleted file mode 100644 index 98a8e7d..0000000 --- a/src/META +++ /dev/null @@ -1,12 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 0b7c5c15af8df30a424bef17dc87d1b1) -version = "1.15" -description = "Cryptographic primitives" -requires = "unix zarith" -archive(byte) = "cryptokit.cma" -archive(byte, plugin) = "cryptokit.cma" -archive(native) = "cryptokit.cmxa" -archive(native, plugin) = "cryptokit.cmxs" -exists_if = "cryptokit.cma" -# OASIS_STOP - diff --git a/src/api-cryptokit.odocl b/src/api-cryptokit.odocl deleted file mode 100644 index c8577fb..0000000 --- a/src/api-cryptokit.odocl +++ /dev/null @@ -1,5 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: f65b9dc92e3f638af8533b26ac90c400) -CryptokitBignum -Cryptokit -# OASIS_STOP diff --git a/src/cryptokit.mldylib b/src/cryptokit.mldylib deleted file mode 100644 index c8577fb..0000000 --- a/src/cryptokit.mldylib +++ /dev/null @@ -1,5 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: f65b9dc92e3f638af8533b26ac90c400) -CryptokitBignum -Cryptokit -# OASIS_STOP diff --git a/src/cryptokit.mllib b/src/cryptokit.mllib deleted file mode 100644 index c8577fb..0000000 --- a/src/cryptokit.mllib +++ /dev/null @@ -1,5 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: f65b9dc92e3f638af8533b26ac90c400) -CryptokitBignum -Cryptokit -# OASIS_STOP diff --git a/src/libcryptokit_stubs.clib b/src/libcryptokit_stubs.clib deleted file mode 100644 index 610e2e2..0000000 --- a/src/libcryptokit_stubs.clib +++ /dev/null @@ -1,30 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 460f3639307284eb4bb0467641bc366c) -aesni.o -arcfour.o -stubs-arcfour.o -blowfish.o -stubs-blowfish.o -d3des.o -stubs-des.o -rijndael-alg-fst.o -ripemd160.o -stubs-ripemd160.o -sha1.o -stubs-sha1.o -sha256.o -stubs-sha256.o -sha512.o -stubs-sha512.o -stubs-aes.o -stubs-md5.o -stubs-misc.o -stubs-rng.o -stubs-zlib.o -keccak.o -stubs-sha3.o -chacha20.o -stubs-chacha20.o -blake2.o -stubs-blake2.o -# OASIS_STOP From a00931f3d213f265585a1c6dd32950eb1fefd8b5 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 12:10:08 +0100 Subject: [PATCH 12/22] Tweak wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e83d05d..1732b6d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ This library is distributed under the conditions of the GNU Library General Publ * To build, run `dune build`. * To execute a test, run `dune exec test/.exe` where `` can be `test`, - `prngtest` or `speedtest`, supplying additional command line parameters if needed. + `prngtest` or `speedtest`, supplying additional command line arguments if needed. The main test file `test/test.ml` is also included into the `runtest` alias, so it can be executed simply by `dune test`. From 09b0e9672503e9b818114b1cf9c2f183d7b59a80 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 6 Aug 2020 12:10:57 +0100 Subject: [PATCH 13/22] Specify Dune version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1732b6d..ed83468 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This library is distributed under the conditions of the GNU Library General Publ ## Requirements * OCaml 4.02 or more recent. -* The Dune build system. +* The Dune build system, version 2.0 or more recent. * The Zarith library, version 1.4 or more recent. * The Zlib C library, version 1.1.3 or up is recommended. If it is not installed on your system (look for libz.a or libz.so), get it from http://www.gzip.org/, or indicate in the Makefile that you do not have it. If you are running Linux or BSD or MacOS, your distribution provides precompiled binaries for this library. * If the operating system does not provide the `/dev/random` device for random number generation, consider installing the [EGD](http://egd.sourceforge.net/) entropy gathering daemon. Without `/dev/random` nor EGD, this library cannot generate cryptographically-strong random data nor RSA keys. The remainder of the library still works, though. From c8aa43191f33a10592a05d67fa849b6b7c343dbc Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 20 Aug 2020 14:51:19 +0100 Subject: [PATCH 14/22] Update src/compute_flags.ml Co-authored-by: Xavier Leroy --- src/compute_flags.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compute_flags.ml b/src/compute_flags.ml index 0d0c9cc..e146b4b 100644 --- a/src/compute_flags.ml +++ b/src/compute_flags.ml @@ -10,7 +10,7 @@ let write_sexp file list = let compute_flags ~os_type ~system ~architecture = let zlib = os_type <> "Win32" in let hardwaresupport = - architecture = "amd64" || (architecture = "i386" && os_type <> "Win32") + (architecture = "amd64" || architecture = "i386") && os_type <> "Win32" in let append_if c y x = if c then x @ [ y ] else x in let flags = From 350a6b88ec9ccace0a988c9fd4907ec970e28e94 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Fri, 21 Aug 2020 12:35:33 +0100 Subject: [PATCH 15/22] Move configuration logic into a subdirectory --- src/config/dune | 3 +++ src/{compute_flags.ml => config/flags.ml} | 0 src/dune | 3 +-- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 src/config/dune rename src/{compute_flags.ml => config/flags.ml} (100%) diff --git a/src/config/dune b/src/config/dune new file mode 100644 index 0000000..6efd03e --- /dev/null +++ b/src/config/dune @@ -0,0 +1,3 @@ +(executable + (name flags) + (libraries dune-configurator)) diff --git a/src/compute_flags.ml b/src/config/flags.ml similarity index 100% rename from src/compute_flags.ml rename to src/config/flags.ml diff --git a/src/dune b/src/dune index 6d5c119..fd34860 100644 --- a/src/dune +++ b/src/dune @@ -36,6 +36,5 @@ ; compute flags (rule (targets flags.sexp library_flags.sexp) - (deps (:first_dep compute_flags.ml)) (action - (run %{ocaml} %{first_dep} -os_type %{os_type} -system %{system} -architecture %{architecture}))) + (run config/flags.exe -os_type %{os_type} -system %{system} -architecture %{architecture}))) From 4f9956c8fdcef5b14bac031b4de2f10f8cd7ca0e Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Fri, 21 Aug 2020 12:57:13 +0100 Subject: [PATCH 16/22] Test -maes flag --- src/config/flags.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config/flags.ml b/src/config/flags.ml index e146b4b..95a324e 100644 --- a/src/config/flags.ml +++ b/src/config/flags.ml @@ -6,11 +6,16 @@ let write_sexp file list = Printf.fprintf oc "(%s)" content; close_out oc -(* We could also allow the user to override [zlib] and [hardwaresupport]. *) +(* Compile and link a dummy C program with the given flags. *) +let test ~c_flags ~link_flags = + let test_program = "int main() { return 0; }" in + let c = Configurator.V1.create "cryptokit" in + Configurator.V1.c_test c test_program ~c_flags ~link_flags + let compute_flags ~os_type ~system ~architecture = let zlib = os_type <> "Win32" in let hardwaresupport = - (architecture = "amd64" || architecture = "i386") && os_type <> "Win32" + (architecture = "amd64" || architecture = "i386") && test ~c_flags:["-maes"] ~link_flags:[] in let append_if c y x = if c then x @ [ y ] else x in let flags = From 54e728bcc3584c8e6300ea0ec8b0dd9d082f5d7e Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Fri, 21 Aug 2020 13:03:38 +0100 Subject: [PATCH 17/22] Use configurator's [write_sexp] --- src/config/flags.ml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/config/flags.ml b/src/config/flags.ml index 95a324e..02a7ed1 100644 --- a/src/config/flags.ml +++ b/src/config/flags.ml @@ -1,21 +1,18 @@ (* Compute compilation and linking flags *) -let write_sexp file list = - let oc = open_out file in - let content = List.map (Printf.sprintf "%S") list |> String.concat " " in - Printf.fprintf oc "(%s)" content; - close_out oc +module Configurator = Configurator.V1 (* Compile and link a dummy C program with the given flags. *) let test ~c_flags ~link_flags = let test_program = "int main() { return 0; }" in - let c = Configurator.V1.create "cryptokit" in - Configurator.V1.c_test c test_program ~c_flags ~link_flags + let c = Configurator.create "cryptokit" in + Configurator.c_test c test_program ~c_flags ~link_flags let compute_flags ~os_type ~system ~architecture = let zlib = os_type <> "Win32" in let hardwaresupport = - (architecture = "amd64" || architecture = "i386") && test ~c_flags:["-maes"] ~link_flags:[] + (architecture = "amd64" || architecture = "i386") + && test ~c_flags:[ "-maes" ] ~link_flags:[] in let append_if c y x = if c then x @ [ y ] else x in let flags = @@ -30,13 +27,13 @@ let compute_flags ~os_type ~system ~architecture = |> append_if (system = "win32" || system = "win64") "advapi32.lib" |> append_if (system = "mingw" || system = "mingw64") "-ladvapi32" in - write_sexp "flags.sexp" flags; - write_sexp "library_flags.sexp" library_flags + Configurator.Flags.write_sexp "flags.sexp" flags; + Configurator.Flags.write_sexp "library_flags.sexp" library_flags let () = match Sys.argv with - | [| - _; "-os_type"; os_type; "-system"; system; "-architecture"; architecture; - |] -> - compute_flags ~os_type ~system ~architecture + | [| _; "-os_type"; os_type; + "-system"; system; + "-architecture"; architecture; + |] -> compute_flags ~os_type ~system ~architecture | _ -> failwith "unexpected command line arguments" From 460e48220f2f4ff5e393a22deb92f8054b455d40 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Mon, 7 Sep 2020 17:56:44 +0100 Subject: [PATCH 18/22] Simplify configuration code --- src/config/flags.ml | 22 ++++++++-------------- src/dune | 3 +-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/config/flags.ml b/src/config/flags.ml index 02a7ed1..6bfe1f1 100644 --- a/src/config/flags.ml +++ b/src/config/flags.ml @@ -3,16 +3,18 @@ module Configurator = Configurator.V1 (* Compile and link a dummy C program with the given flags. *) -let test ~c_flags ~link_flags = +let test ~cfg ~c_flags ~link_flags = let test_program = "int main() { return 0; }" in - let c = Configurator.create "cryptokit" in - Configurator.c_test c test_program ~c_flags ~link_flags + Configurator.c_test cfg test_program ~c_flags ~link_flags -let compute_flags ~os_type ~system ~architecture = +let () = Configurator.main ~name:"cryptokit" (fun cfg -> + let os_type = Configurator.ocaml_config_var_exn cfg "os_type" in + let system = Configurator.ocaml_config_var_exn cfg "system" in + let architecture = Configurator.ocaml_config_var_exn cfg "architecture" in let zlib = os_type <> "Win32" in let hardwaresupport = (architecture = "amd64" || architecture = "i386") - && test ~c_flags:[ "-maes" ] ~link_flags:[] + && test ~cfg ~c_flags:[ "-maes" ] ~link_flags:[] in let append_if c y x = if c then x @ [ y ] else x in let flags = @@ -28,12 +30,4 @@ let compute_flags ~os_type ~system ~architecture = |> append_if (system = "mingw" || system = "mingw64") "-ladvapi32" in Configurator.Flags.write_sexp "flags.sexp" flags; - Configurator.Flags.write_sexp "library_flags.sexp" library_flags - -let () = - match Sys.argv with - | [| _; "-os_type"; os_type; - "-system"; system; - "-architecture"; architecture; - |] -> compute_flags ~os_type ~system ~architecture - | _ -> failwith "unexpected command line arguments" + Configurator.Flags.write_sexp "library_flags.sexp" library_flags) diff --git a/src/dune b/src/dune index fd34860..4260e4c 100644 --- a/src/dune +++ b/src/dune @@ -36,5 +36,4 @@ ; compute flags (rule (targets flags.sexp library_flags.sexp) - (action - (run config/flags.exe -os_type %{os_type} -system %{system} -architecture %{architecture}))) + (action (run config/flags.exe))) From 49cc7f9d39e21d9663a6d186d1bb52f0b0acee37 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Mon, 7 Sep 2020 18:04:21 +0100 Subject: [PATCH 19/22] Update dependencies --- cryptokit.opam | 3 ++- dune-project | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cryptokit.opam b/cryptokit.opam index 0d4d7de..132bd7d 100644 --- a/cryptokit.opam +++ b/cryptokit.opam @@ -11,8 +11,9 @@ authors: ["Xavier Leroy"] homepage: "https://github.com/xavierleroy/cryptokit" bug-reports: "https://github.com/xavierleroy/cryptokit/issues" depends: [ - "dune" {>= "2.0"} "ocaml" {>= "4.02.0"} + "dune" {>= "2.0"} + "dune-configurator" "zarith" {>= "1.4"} "conf-zlib" "conf-gmp-powm-sec" diff --git a/dune-project b/dune-project index 34bd786..600aca7 100644 --- a/dune-project +++ b/dune-project @@ -16,6 +16,8 @@ with a compositional, extensible interface.") (depends (ocaml (>= 4.02.0)) + (dune (>= 2.0)) + dune-configurator (zarith (>= 1.4)) conf-zlib conf-gmp-powm-sec)) From de79dbf8335578cca5be8a6e621aa28f9729a2c6 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Fri, 11 Sep 2020 17:33:22 +0100 Subject: [PATCH 20/22] Add name to dune-project --- dune-project | 1 + 1 file changed, 1 insertion(+) diff --git a/dune-project b/dune-project index 600aca7..9796530 100644 --- a/dune-project +++ b/dune-project @@ -1,6 +1,7 @@ (lang dune 2.0) (generate_opam_files true) +(name cryptokit) (source (github xavierleroy/cryptokit)) (authors "Xavier Leroy") (maintainers "Xavier Leroy ") From 1a72f5aa350fa79865e9abd03f44771a55d06028 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 8 Oct 2020 12:10:09 +0100 Subject: [PATCH 21/22] Add configure --- .gitignore | 2 ++ configure | 48 +++++++++++++++++++++++++++++++ src/config/config_vars.ml.default | 7 +++++ src/config/dune | 5 ++++ src/config/flags.ml | 24 ++++++++++++---- src/dune | 4 ++- 6 files changed, 83 insertions(+), 7 deletions(-) create mode 100755 configure create mode 100644 src/config/config_vars.ml.default diff --git a/.gitignore b/.gitignore index 21e1863..1d79768 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ setup.log *.native *~ .merlin +# This file is generated by the configure script +src/config/config_vars.ml diff --git a/configure b/configure new file mode 100755 index 0000000..0037908 --- /dev/null +++ b/configure @@ -0,0 +1,48 @@ +#!/usr/bin/env ocaml +(* -*- tuareg -*- *) + +type 'a value = + | This of 'a + | Auto + +let string_of_value to_string = function + | This a -> "This (" ^ to_string a ^ ")" + | Auto -> "Auto" + +let () = + let declare_flag arg description = + let reference = ref Auto in + let args = + [ "--enable-" ^ arg, Arg.Unit (fun () -> reference := This true), + " Enable " ^ description + ; "--disable-" ^ arg, Arg.Unit (fun () -> reference := This false), + " Disable " ^ description + ] + in args, reference + in + let args_zlib, ref_zlib = declare_flag "zlib" "ZLib" in + let args_hardware_support, ref_hardware_support = + declare_flag "hardwaresupport" + "hardware support for AES and GCM (needs GCC or Clang)" in + Arg.parse + (Arg.align (args_zlib @ args_hardware_support)) + (fun s -> raise (Arg.Bad (Printf.sprintf "don't know what to do with %S" s))) + "Usage: ./configure [OPTIONS]"; + let oc = open_out_bin "src/config/config_vars.ml" in + Printf.fprintf oc {| +type 'a value = + | This of 'a + | Auto + +let enable_zlib = %s +let enable_hardware_support = %s +|} + (string_of_value string_of_bool !ref_zlib) + (string_of_value string_of_bool !ref_hardware_support); + close_out oc; + (* Below is a temporary workaround to make sure the configuration happens + every time this script is run. *) + (try + Sys.remove "_build/default/src/flags.sexp"; + with _ -> ()); + exit (Sys.command "dune build @configure --release") diff --git a/src/config/config_vars.ml.default b/src/config/config_vars.ml.default new file mode 100644 index 0000000..1b56c41 --- /dev/null +++ b/src/config/config_vars.ml.default @@ -0,0 +1,7 @@ +type 'a value = + | This of 'a + | Auto + +let enable_zlib = Auto + +let enable_hardware_support = Auto diff --git a/src/config/dune b/src/config/dune index 6efd03e..fd353e0 100644 --- a/src/config/dune +++ b/src/config/dune @@ -1,3 +1,8 @@ (executable (name flags) (libraries dune-configurator)) + +(rule + (mode fallback) + + (action (copy config_vars.ml.default config_vars.ml))) \ No newline at end of file diff --git a/src/config/flags.ml b/src/config/flags.ml index 6bfe1f1..a4c30e0 100644 --- a/src/config/flags.ml +++ b/src/config/flags.ml @@ -1,5 +1,7 @@ (* Compute compilation and linking flags *) +open Config_vars + module Configurator = Configurator.V1 (* Compile and link a dummy C program with the given flags. *) @@ -11,16 +13,20 @@ let () = Configurator.main ~name:"cryptokit" (fun cfg -> let os_type = Configurator.ocaml_config_var_exn cfg "os_type" in let system = Configurator.ocaml_config_var_exn cfg "system" in let architecture = Configurator.ocaml_config_var_exn cfg "architecture" in - let zlib = os_type <> "Win32" in - let hardwaresupport = - (architecture = "amd64" || architecture = "i386") - && test ~cfg ~c_flags:[ "-maes" ] ~link_flags:[] + let zlib = match enable_zlib with + | This bool -> bool + | Auto -> os_type <> "Win32" + in + let hardware_support = match enable_hardware_support with + | This bool -> bool + | Auto -> (architecture = "amd64" || architecture = "i386") + && test ~cfg ~c_flags:[ "-maes" ] ~link_flags:[] in let append_if c y x = if c then x @ [ y ] else x in let flags = [] |> append_if zlib "-DHAVE_ZLIB" - |> append_if hardwaresupport "-maes" + |> append_if hardware_support "-maes" in let library_flags = [] @@ -30,4 +36,10 @@ let () = Configurator.main ~name:"cryptokit" (fun cfg -> |> append_if (system = "mingw" || system = "mingw64") "-ladvapi32" in Configurator.Flags.write_sexp "flags.sexp" flags; - Configurator.Flags.write_sexp "library_flags.sexp" library_flags) + Configurator.Flags.write_sexp "library_flags.sexp" library_flags; + let describe_bool = function + | true -> "enabled" + | false -> "disabled" + in + Printf.printf "ZLib: ............................... %s\n" (describe_bool zlib); + Printf.printf "Hardware support for AES and GCM: ... %s\n" (describe_bool hardware_support)) diff --git a/src/dune b/src/dune index 4260e4c..a6642bc 100644 --- a/src/dune +++ b/src/dune @@ -35,5 +35,7 @@ (flags :standard -safe-string -w -7 -w -27 -w -37)) ; compute flags -(rule (targets flags.sexp library_flags.sexp) +(rule + (alias configure) + (targets flags.sexp library_flags.sexp) (action (run config/flags.exe))) From 7d170c97bc313ab1e1ee454639ee06732e24f62b Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 8 Oct 2020 12:13:18 +0100 Subject: [PATCH 22/22] Fix whitespace --- src/config/dune | 3 +-- src/config/flags.ml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/config/dune b/src/config/dune index fd353e0..ece93d5 100644 --- a/src/config/dune +++ b/src/config/dune @@ -4,5 +4,4 @@ (rule (mode fallback) - - (action (copy config_vars.ml.default config_vars.ml))) \ No newline at end of file + (action (copy config_vars.ml.default config_vars.ml))) diff --git a/src/config/flags.ml b/src/config/flags.ml index a4c30e0..f8f2157 100644 --- a/src/config/flags.ml +++ b/src/config/flags.ml @@ -20,7 +20,7 @@ let () = Configurator.main ~name:"cryptokit" (fun cfg -> let hardware_support = match enable_hardware_support with | This bool -> bool | Auto -> (architecture = "amd64" || architecture = "i386") - && test ~cfg ~c_flags:[ "-maes" ] ~link_flags:[] + && test ~cfg ~c_flags:[ "-maes" ] ~link_flags:[] in let append_if c y x = if c then x @ [ y ] else x in let flags =