Skip to content

Commit

Permalink
hack out sexplib
Browse files Browse the repository at this point in the history
  • Loading branch information
pqwy committed Feb 4, 2019
1 parent de1578f commit a58c653
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 77 deletions.
2 changes: 1 addition & 1 deletion _tags
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ true: warn(A-4-29-33-40-41-42-43-34-44-48)
true: package(bytes cstruct)

<src>: include
<src/*.ml{,i}>: package(zarith sexplib ppx_sexp_conv)
<src/*.ml{,i}>: package(zarith)
<src/*.cm{x,o}> and not <src/nocrypto.cmx>: for-pack(Nocrypto)
<src/*.cm{,x}a>: link_stubs(src/libnocrypto_stubs)

Expand Down
5 changes: 1 addition & 4 deletions opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ depends: [
"topkg" {build}
"cpuid" {build}
"ocb-stubblr" {build}
"ppx_deriving" {build}
"ppx_sexp_conv" {build}
"ounit" {test}
"cstruct" {>="3.0.0" & <"3.2.0"}
"ocplib-endian"
"zarith"
"sexplib"
("mirage-no-xen" | ("mirage-xen" & "zarith-xen"))
("mirage-no-solo5" | ("mirage-solo5" & "zarith-freestanding"))
]
Expand All @@ -45,5 +43,4 @@ conflicts: [
"topkg" {<"0.8.0"}
"ocb-stubblr" {<"0.1.0"}
"mirage-xen" {<"2.2.0"}
"sexplib" {="v0.9.0"}
]
2 changes: 1 addition & 1 deletion pkg/META
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = "%%VERSION_NUM%%"
description = "Simple crypto for the modern age"
requires = "cstruct zarith sexplib"
requires = "cstruct zarith"
archive(byte) = "nocrypto.cma"
archive(native) = "nocrypto.cmxa"
plugin(byte) = "nocrypto.cma"
Expand Down
5 changes: 2 additions & 3 deletions src/dh.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open Sexplib.Conv
open Uncommon

type bits = int
Expand All @@ -9,9 +8,9 @@ type group = {
p : Z.t ; (* The prime modulus *)
gg : Z.t ; (* Group generator *)
q : Z.t option ; (* `gg`'s order, maybe *)
} [@@deriving sexp]
}

type secret = { x : Z.t } [@@deriving sexp]
type secret = { x : Z.t }

(*
* Estimates of equivalent-strength exponent sizes for the moduli sizes.
Expand Down
3 changes: 0 additions & 3 deletions src/dsa.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
open Sexplib.Conv
open Uncommon

type bits = int

type pub = { p : Z.t ; q : Z.t ; gg : Z.t ; y : Z.t }
[@@deriving sexp]

type priv = { p : Z.t ; q : Z.t ; gg : Z.t ; x : Z.t ; y : Z.t }
[@@deriving sexp]

let pub_of_priv { p; q; gg; y; _ } = { p; q; gg; y }

Expand Down
1 change: 0 additions & 1 deletion src/hash.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ module SHAd256 = struct
end

type hash = [ `MD5 | `SHA1 | `SHA224 | `SHA256 | `SHA384 | `SHA512 ]
[@@deriving sexp]

let hashes = [ `MD5; `SHA1; `SHA224; `SHA256; `SHA384; `SHA512 ]

Expand Down
67 changes: 7 additions & 60 deletions src/nocrypto.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
{e %%VERSION%% — {{:%%PKG_HOMEPAGE%% }homepage}} *)

(*
* Doc note: Sexplib conversions are noted explicitly instead of using
* `[@@deriving sexp]` because the syntax extension interacts badly with
* ocamldoc.
*)

(** {1 Utilities} *)

(** Base64 conversion.
Expand Down Expand Up @@ -290,9 +284,7 @@ module Hash : sig
(** {1 Codes-based interface} *)

type hash = [ `MD5 | `SHA1 | `SHA224 | `SHA256 | `SHA384 | `SHA512 ]
(** Algorithm codes.
{e [Sexplib] convertible}. *)
(** Algorithm codes. *)

val module_of : [< hash ] -> (module S)
(** [module_of hash] is the (first-class) module corresponding to the code
Expand All @@ -310,12 +302,6 @@ module Hash : sig

type 'a or_digest = [ `Message of 'a | `Digest of digest ]
(** Either an ['a] or its digest, according to some hash algorithm. *)

(**/**)
val hash_of_sexp : Sexplib.Sexp.t -> hash
val sexp_of_hash : hash -> Sexplib.Sexp.t
(**/**)

end


Expand Down Expand Up @@ -855,9 +841,7 @@ module Rsa : sig
e : Z.t ; (** Public exponent *)
n : Z.t ; (** Modulus *)
}
(** The public portion of the key.
{e [Sexplib] convertible}. *)
(** The public portion of the key. *)

type priv = {
e : Z.t ; (** Public exponent *)
Expand All @@ -876,9 +860,7 @@ module Rsa : sig
Some systems assume otherwise. When using keys produced by a system that
computes [u = p^(-1) mod q], either exchange [p] with [q] and [dp] with
[dq], or re-generate the full private key using
{{!priv_of_primes}[priv_of_primes]}.
{e [Sexplib] convertible}. *)
{{!priv_of_primes}[priv_of_primes]}. *)

val pub_bits : pub -> bits
(** Bit-size of a public key. *)
Expand Down Expand Up @@ -1094,15 +1076,6 @@ module Rsa : sig
@raise Invalid_argument if message is a [`Digest] of the wrong size. *)
end

(**/**)
val pub_of_sexp : Sexplib.Sexp.t -> pub
val sexp_of_pub : pub -> Sexplib.Sexp.t

val priv_of_sexp : Sexplib.Sexp.t -> priv
val sexp_of_priv : priv -> Sexplib.Sexp.t
(**/**)

end


Expand All @@ -1120,19 +1093,15 @@ module Dsa : sig
x : Z.t ; (** Private key proper *)
y : Z.t ; (** Public component *)
}
(** Private key. [p], [q] and [gg] comprise {i domain parameters}.
{e [Sexplib] convertible}. *)
(** Private key. [p], [q] and [gg] comprise {i domain parameters}. *)

type pub = {
p : Z.t ;
q : Z.t ;
gg : Z.t ;
y : Z.t ;
}
(** Public key, a subset of {{!priv}private key}.
{e [Sexplib] convertible}. *)
(** Public key, a subset of {{!priv}private key}. *)

type keysize = [ `Fips1024 | `Fips2048 | `Fips3072 | `Exactly of bits * bits ]
(** Key size request. Three {e Fips} variants refer to FIPS-standardized
Expand Down Expand Up @@ -1190,15 +1159,6 @@ module Dsa : sig
(** [generate key digest] deterministically takes the given private key and
message digest to a [k] suitable for seeding the signing process. *)
end

(**/**)
val pub_of_sexp : Sexplib.Sexp.t -> pub
val sexp_of_pub : pub -> Sexplib.Sexp.t

val priv_of_sexp : Sexplib.Sexp.t -> priv
val sexp_of_priv : priv -> Sexplib.Sexp.t
(**/**)

end


Expand All @@ -1218,14 +1178,10 @@ module Dh : sig
gg : Z.t ; (** generator *)
q : Z.t option ; (** subgroup order; potentially unknown *)
}
(** A DH group.
{e [Sexplib] convertible}. *)
(** A DH group. *)

type secret = private { x : Z.t }
(** A private secret.
{e [Sexplib] convertible.} *)
(** A private secret. *)

val modulus_size : group -> bits
(** Bit size of the modulus. *)
Expand Down Expand Up @@ -1289,13 +1245,4 @@ module Dh : sig
val ffdhe8192 : group

end

(**/**)
val group_of_sexp : Sexplib.Sexp.t -> group
val sexp_of_group : group -> Sexplib.Sexp.t

val secret_of_sexp : Sexplib.Sexp.t -> secret
val sexp_of_secret : secret -> Sexplib.Sexp.t
(**/**)

end
5 changes: 2 additions & 3 deletions src/rsa.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
open Sexplib.Conv
open Uncommon

type bits = int

exception Insufficient_key

type pub = { e : Z.t ; n : Z.t } [@@deriving sexp]
type pub = { e : Z.t ; n : Z.t }

type priv = {
e : Z.t ; d : Z.t ; n : Z.t ;
p : Z.t ; q : Z.t ; dp : Z.t ; dq : Z.t ; q' : Z.t
} [@@deriving sexp]
}

type mask = [ `No | `Yes | `Yes_with of Rng.g ]

Expand Down
3 changes: 2 additions & 1 deletion tests/testlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ let b64_selftest n =
let gen_rsa ~bits =
let e = Z.(if bits < 24 then ~$3 else ~$0x10001) in
let key = Rsa.(generate ~e bits) in
let key_s = Sexplib.Sexp.to_string_hum Rsa.(sexp_of_priv key) in
(* let key_s = Sexplib.Sexp.to_string_hum Rsa.(sexp_of_priv key) in *)
let key_s = "" in
assert_equal
~msg:Printf.(sprintf "key size not %d bits:\n%s" bits key_s)
bits Rsa.(priv_bits key);
Expand Down

0 comments on commit a58c653

Please sign in to comment.