functo refacto ~!
This commit is contained in:
parent
0fef7fbd10
commit
83d053e900
2 changed files with 75 additions and 137 deletions
|
|
@ -4,13 +4,7 @@
|
||||||
|
|
||||||
open Include
|
open Include
|
||||||
|
|
||||||
(* TODO
|
(* TODO test *)
|
||||||
less boilerplate?
|
|
||||||
- type t abstract
|
|
||||||
- type t = { v = string }
|
|
||||||
padding issues?
|
|
||||||
how to encode union? not really needed?
|
|
||||||
test *)
|
|
||||||
|
|
||||||
(* -- Time -- *)
|
(* -- Time -- *)
|
||||||
|
|
||||||
|
|
@ -53,59 +47,67 @@ end
|
||||||
|
|
||||||
(* -- Cryptographic primitives -- *)
|
(* -- Cryptographic primitives -- *)
|
||||||
|
|
||||||
module Hash_code = struct
|
(* MK_BASIC_XX functor for structs like:
|
||||||
(* usually SHA-512 *)
|
struct Foo { uint8_t bar[XX]; } *)
|
||||||
type t = { hash: string (* = uint8_t hash[64] *) }
|
module MKMK_BASIC (Size : sig
|
||||||
|
val v : int
|
||||||
let size = 64
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun hash -> { hash })
|
|
||||||
|+ field (bytes size) (fun t -> t.hash)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module Short_hash_code = struct
|
|
||||||
type t = { hash: string }
|
|
||||||
|
|
||||||
let size = 32
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun hash -> { hash })
|
|
||||||
|+ field (bytes size) (fun t -> t.hash)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module MAKE_H (H : sig
|
|
||||||
type t = { hash: string }
|
|
||||||
|
|
||||||
val size : int
|
|
||||||
val bin : t Bin.t
|
|
||||||
end) =
|
end) =
|
||||||
struct
|
struct
|
||||||
type t = { hash: H.t }
|
type t = { v: string }
|
||||||
|
|
||||||
|
let size = Size.v
|
||||||
|
|
||||||
|
let bin =
|
||||||
|
let open Bin in
|
||||||
|
record (fun v -> { v }) |+ field (bytes size) (fun t -> t.v) |> sealr
|
||||||
|
end
|
||||||
|
|
||||||
|
module SIZE_32 = struct
|
||||||
|
let v = 32
|
||||||
|
end
|
||||||
|
|
||||||
|
module SIZE_64 = struct
|
||||||
|
let v = 64
|
||||||
|
end
|
||||||
|
|
||||||
|
module MK_BASIC_32 () = MKMK_BASIC (SIZE_32)
|
||||||
|
module MK_BASIC_64 () = MKMK_BASIC (SIZE_64)
|
||||||
|
|
||||||
|
(* MK_XX functor for structs like:
|
||||||
|
struct FooWrap { struct Foo { uint8_t bar[XX]; } } *)
|
||||||
|
module MKMK (Size : sig
|
||||||
|
val v : int
|
||||||
|
end) =
|
||||||
|
struct
|
||||||
|
module H = MKMK_BASIC (Size)
|
||||||
|
|
||||||
|
type t = { v: H.t }
|
||||||
|
|
||||||
let size = H.size
|
let size = H.size
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun hash -> { hash }) |+ field H.bin (fun t -> t.hash) |> sealr
|
record (fun v -> { v }) |+ field H.bin (fun t -> t.v) |> sealr
|
||||||
end
|
end
|
||||||
|
|
||||||
module Denomination_hash = MAKE_H (Hash_code)
|
module MK_32 () = MKMK (SIZE_32)
|
||||||
module Private_contract_hash = MAKE_H (Hash_code)
|
module MK_64 () = MKMK (SIZE_64)
|
||||||
module Extensions_policy_hash = MAKE_H (Hash_code)
|
(* - *)
|
||||||
module Merchant_wire_hash = MAKE_H (Hash_code)
|
|
||||||
|
module ShortHashCode = MK_BASIC_32 ()
|
||||||
|
module HashCode = MK_BASIC_64 ()
|
||||||
|
module Denomination_hash = MK_64 ()
|
||||||
|
module Private_contract_hash = MK_64 ()
|
||||||
|
module Extensions_policy_hash = MK_64 ()
|
||||||
|
module Merchant_wire_hash = MK_64 ()
|
||||||
|
|
||||||
(* Hash over a full payto://-URI, including receiver-name
|
(* Hash over a full payto://-URI, including receiver-name
|
||||||
(and possibly BIC and other optional fields). *)
|
(and possibly BIC and other optional fields). *)
|
||||||
module Full_payto_hash = MAKE_H (Short_hash_code)
|
module Full_payto_hash = MK_32 ()
|
||||||
|
|
||||||
(* Hash over a normalized payto://-URI, including all optional
|
(* Hash over a normalized payto://-URI, including all optional
|
||||||
fields and also with account-part canonicalized (so no BIC). *)
|
fields and also with account-part canonicalized (so no BIC). *)
|
||||||
module Normalized_payto_hash = MAKE_H (Short_hash_code)
|
module Normalized_payto_hash = MK_32 ()
|
||||||
|
|
||||||
(* Hash over:
|
(* Hash over:
|
||||||
a) the hash of the denomination's public key,
|
a) the hash of the denomination's public key,
|
||||||
|
|
@ -113,80 +115,18 @@ module Normalized_payto_hash = MAKE_H (Short_hash_code)
|
||||||
c) cipher-dependant blinded information.
|
c) cipher-dependant blinded information.
|
||||||
See implementation of `TALER_coin_ev_hash`
|
See implementation of `TALER_coin_ev_hash`
|
||||||
in libtalerexchange for details. *)
|
in libtalerexchange for details. *)
|
||||||
module Blinded_coin_hash = MAKE_H (Hash_code)
|
module Blinded_coin_hash = MK_64 ()
|
||||||
module Coin_pub_hash = MAKE_H (Hash_code)
|
module Coin_pub_hash = MK_64 ()
|
||||||
module Output_commitment_hash = MAKE_H (Hash_code)
|
module Output_commitment_hash = MK_64 ()
|
||||||
|
module Reserve_public_key_p = MK_32 ()
|
||||||
|
module Reserve_private_key_p = MK_32 ()
|
||||||
|
module Reserve_signature_p = MK_64 ()
|
||||||
|
module Merchant_public_key_p = MK_32 ()
|
||||||
|
module Merchant_private_key_p = MK_32 ()
|
||||||
|
(*module Merchant_signature_p = MK_64 () *)
|
||||||
|
|
||||||
module MAKE_EDDSA_PUB () = struct
|
module Transfert_public_key_p = MK_32 ()
|
||||||
type t = { eddsa_pub: string }
|
module Transfert_private_key_p = MK_32 ()
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun eddsa_pub -> { eddsa_pub })
|
|
||||||
|+ field (bytes 32) (fun t -> t.eddsa_pub)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module MAKE_EDDSA_PRIV () = struct
|
|
||||||
type t = { eddsa_priv: string }
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun eddsa_priv -> { eddsa_priv })
|
|
||||||
|+ field (bytes 32) (fun t -> t.eddsa_priv)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module MAKE_EDDSA_SIG () = struct
|
|
||||||
(* 64 bytes *)
|
|
||||||
type t = { eddsa_signature: string }
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun eddsa_signature -> { eddsa_signature })
|
|
||||||
|+ field (bytes 64) (fun t -> t.eddsa_signature)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module MAKE_ECDHE_PUB () = struct
|
|
||||||
type t = { ecdhe_pub: string }
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun ecdhe_pub -> { ecdhe_pub })
|
|
||||||
|+ field (bytes 32) (fun t -> t.ecdhe_pub)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module MAKE_ECDHE_PRIV () = struct
|
|
||||||
type t = { ecdhe_priv: string }
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun ecdhe_priv -> { ecdhe_priv })
|
|
||||||
|+ field (bytes 32) (fun t -> t.ecdhe_priv)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module Ecdh_ephemeral_public_key_p = struct
|
|
||||||
type t = { ecdh_pub: string (* = uint8_t ecdh_pub[32] *) }
|
|
||||||
|
|
||||||
let bin =
|
|
||||||
let open Bin in
|
|
||||||
record (fun ecdh_pub -> { ecdh_pub })
|
|
||||||
|+ field (bytes 32) (fun t -> t.ecdh_pub)
|
|
||||||
|> sealr
|
|
||||||
end
|
|
||||||
|
|
||||||
module Reserve_public_key_p = MAKE_EDDSA_PUB ()
|
|
||||||
module Reserve_private_key_p = MAKE_EDDSA_PRIV ()
|
|
||||||
module Reserve_signature_p = MAKE_EDDSA_SIG ()
|
|
||||||
module Merchant_public_key_p = MAKE_EDDSA_PUB ()
|
|
||||||
module Merchant_private_key_p = MAKE_EDDSA_PRIV ()
|
|
||||||
(*module Merchant_signature_p = MAKE_EDDSA_SIG ()*)
|
|
||||||
|
|
||||||
module Transfert_public_key_p = MAKE_ECDHE_PUB ()
|
|
||||||
module Transfert_private_key_p = MAKE_ECDHE_PRIV ()
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
enum TALER_AmlDecisionState {
|
enum TALER_AmlDecisionState {
|
||||||
|
|
@ -194,14 +134,14 @@ enum TALER_AmlDecisionState {
|
||||||
};
|
};
|
||||||
*)
|
*)
|
||||||
|
|
||||||
module Aml_officer_public_key_p = MAKE_EDDSA_PUB ()
|
module Aml_officer_public_key_p = MK_32 ()
|
||||||
module Aml_officer_private_key_p = MAKE_EDDSA_PRIV ()
|
module Aml_officer_private_key_p = MK_32 ()
|
||||||
module Exchange_public_key_p = MAKE_EDDSA_PUB ()
|
module Exchange_public_key_p = MK_32 ()
|
||||||
module Exchange_private_key_p = MAKE_EDDSA_PRIV ()
|
module Exchange_private_key_p = MK_32 ()
|
||||||
module Exchange_signature_p = MAKE_EDDSA_SIG ()
|
module Exchange_signature_p = MK_64 ()
|
||||||
module Master_public_key_p = MAKE_EDDSA_PUB ()
|
module Master_public_key_p = MK_32 ()
|
||||||
module Master_private_key_p = MAKE_EDDSA_PRIV ()
|
module Master_private_key_p = MK_32 ()
|
||||||
module Master_signature_p = MAKE_EDDSA_SIG ()
|
module Master_signature_p = MK_64 ()
|
||||||
|
|
||||||
module Wire_transfert_identifier_raw_p = struct
|
module Wire_transfert_identifier_raw_p = struct
|
||||||
(* uint8_t raw[32]; *)
|
(* uint8_t raw[32]; *)
|
||||||
|
|
@ -245,9 +185,9 @@ union TALER_CoinSpendPrivateKeyP {
|
||||||
uint8_t ecdhe_priv[32];
|
uint8_t ecdhe_priv[32];
|
||||||
};
|
};
|
||||||
*)
|
*)
|
||||||
module Coin_spend_public_key_p = MAKE_EDDSA_PUB ()
|
module Coin_spend_public_key_p = MK_32 ()
|
||||||
module Coin_spend_private_key_p = MAKE_EDDSA_PRIV ()
|
module Coin_spend_private_key_p = MK_32 ()
|
||||||
module Coin_spend_signature_p = MAKE_EDDSA_SIG ()
|
module Coin_spend_signature_p = MK_64 ()
|
||||||
|
|
||||||
(* TODO padding: sizeof used here (assume no padding for now) *)
|
(* TODO padding: sizeof used here (assume no padding for now) *)
|
||||||
(*
|
(*
|
||||||
|
|
@ -260,9 +200,9 @@ struct TALER_EncryptedLinkSecretP {
|
||||||
uint8_t enc[sizeof (struct TALER_LinkSecretP)];
|
uint8_t enc[sizeof (struct TALER_LinkSecretP)];
|
||||||
};
|
};
|
||||||
*)
|
*)
|
||||||
module Transfert_secret_p = MAKE_H (Hash_code)
|
module Transfert_secret_p = MK_64 ()
|
||||||
module Link_secret_p = MAKE_H (Hash_code)
|
module Link_secret_p = MK_64 ()
|
||||||
module Encrypted_link_secret_p = MAKE_H (Hash_code)
|
module Encrypted_link_secret_p = MK_64 ()
|
||||||
|
|
||||||
(*
|
(*
|
||||||
union TALER_TokenPublicKeyP {
|
union TALER_TokenPublicKeyP {
|
||||||
|
|
@ -270,7 +210,7 @@ union TALER_TokenPublicKeyP {
|
||||||
uint8_t ecdhe_pub[32];
|
uint8_t ecdhe_pub[32];
|
||||||
};
|
};
|
||||||
*)
|
*)
|
||||||
module Token_public_key_p = MAKE_EDDSA_PUB ()
|
module Token_public_key_p = MK_32 ()
|
||||||
|
|
||||||
(* -- Signatures -- *)
|
(* -- Signatures -- *)
|
||||||
|
|
||||||
|
|
@ -304,7 +244,7 @@ end
|
||||||
Note that each `TALER_BlindedCoinHashP` itself
|
Note that each `TALER_BlindedCoinHashP` itself
|
||||||
captures the hash of the corresponding denomination's
|
captures the hash of the corresponding denomination's
|
||||||
public key. *)
|
public key. *)
|
||||||
module Hash_planchets_p = MAKE_H (Hash_code)
|
module Hash_planchets_p = MK_64 ()
|
||||||
|
|
||||||
(* Binary representation of the age groups.
|
(* Binary representation of the age groups.
|
||||||
The bits set in the mask mark the edges at the beginning of a next age
|
The bits set in the mask mark the edges at the beginning of a next age
|
||||||
|
|
|
||||||
|
|
@ -75,9 +75,7 @@ let () =
|
||||||
let () =
|
let () =
|
||||||
let open Binary_formats.Withdraw_confirmation_ps in
|
let open Binary_formats.Withdraw_confirmation_ps in
|
||||||
let str64 = String.make 64 '0' in
|
let str64 = String.make 64 '0' in
|
||||||
let dummy_t =
|
let dummy_t = { h_planchets= { v= { v= str64 } }; noreveal_index= 0_l } in
|
||||||
{ h_planchets= { hash= { hash= str64 } }; noreveal_index= 0_l }
|
|
||||||
in
|
|
||||||
let size' = Bin.size_of_value bin dummy_t |> Option.get in
|
let size' = Bin.size_of_value bin dummy_t |> Option.get in
|
||||||
assert (size = size');
|
assert (size = size');
|
||||||
assert (size = 76);
|
assert (size = 76);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue