+ define Hash_64 with include
This commit is contained in:
parent
f7a33e2dd4
commit
03855ed40d
2 changed files with 61 additions and 44 deletions
|
|
@ -37,10 +37,11 @@
|
|||
!! not strings that are raw-bytes-data-like
|
||||
*)
|
||||
|
||||
module UTIL = struct
|
||||
let int32_size = 4
|
||||
let int64_size = 8
|
||||
|
||||
(* todo clean up: maybe rm it *)
|
||||
module UTIL_FUNC = struct
|
||||
(* microseconds since the UNIX Epoch
|
||||
UINT64_MAX represents "never" *)
|
||||
module MK_TIME () = struct
|
||||
|
|
@ -125,21 +126,17 @@ module UTIL = struct
|
|||
|+ field (bytes 64) (fun t -> t.hash)
|
||||
|> sealr
|
||||
end
|
||||
(*
|
||||
let to_null_terminated s =
|
||||
let len = String.length s in
|
||||
let b = Bytes.create (len + 1) in
|
||||
Bytes.blit_string s 0 b 0 len;
|
||||
Bytes.set b len '\x00';
|
||||
Bytes.unsafe_to_string b
|
||||
*)
|
||||
end
|
||||
|
||||
module HASH_64 : sig
|
||||
module UTIL_HASH = struct
|
||||
module type H_sig = sig
|
||||
type t
|
||||
|
||||
val hash : string -> t
|
||||
val bin : t Bin.t
|
||||
end = struct
|
||||
end
|
||||
|
||||
module HHH_64 : H_sig = struct
|
||||
type t = { hash: Digestif.SHA512.t }
|
||||
|
||||
let hash s =
|
||||
|
|
@ -154,9 +151,32 @@ module UTIL = struct
|
|||
let open Bin in
|
||||
record (fun hash -> { hash }) |+ field hash_bin (fun t -> t.hash) |> sealr
|
||||
end
|
||||
|
||||
(* sha512 with string size check *)
|
||||
module Hash_64 : H_sig = struct
|
||||
include HHH_64
|
||||
|
||||
let hash s =
|
||||
match String.length s = 64 with
|
||||
| false -> Fmt.failwith "SHA512 failure: data is not 64 bytes"
|
||||
| true -> hash s
|
||||
end
|
||||
|
||||
open UTIL
|
||||
(* sha512 but add a null termination to the given string
|
||||
this is "HashCode" in GNU TALER
|
||||
|
||||
todo: maybe need to have a cstring.ml *)
|
||||
module Cstring_hash_64 : H_sig = struct
|
||||
include HHH_64
|
||||
|
||||
let hash s =
|
||||
let s = s ^ "\x00" in
|
||||
hash s
|
||||
end
|
||||
end
|
||||
|
||||
open UTIL_FUNC
|
||||
include UTIL_HASH
|
||||
module Taler_signatures = Include.Taler_signatures
|
||||
|
||||
(* -- Time -- *)
|
||||
|
|
@ -233,7 +253,7 @@ module GNUNET_RsaPublicKey = struct
|
|||
end
|
||||
|
||||
module DenominationHash = struct
|
||||
include HASH_64
|
||||
include Hash_64
|
||||
|
||||
let hash (pub : Mirage_crypto_pk.Rsa.pub) =
|
||||
pub
|
||||
|
|
@ -244,9 +264,6 @@ end
|
|||
|
||||
(* --- Hashes --- *)
|
||||
|
||||
module ShortHashCode = MK_HASH_32 ()
|
||||
module HashCode = MK_HASH_64 ()
|
||||
|
||||
(* Hash over a full payto://-URI, including receiver-name
|
||||
(and possibly BIC and other optional fields). *)
|
||||
module FullPaytoHash = MK_HASH_32 ()
|
||||
|
|
@ -499,7 +516,7 @@ module DenominationKeyAnnouncementPS = struct
|
|||
(* purpose.purpose = TALER_SIGNATURE_SM_DENOMINATION_KEY *)
|
||||
type t = {
|
||||
h_denom_pub: DenominationHash.t;
|
||||
h_section_name: HashCode.t;
|
||||
h_section_name: Cstring_hash_64.t;
|
||||
anchor_time: TimeAbsoluteNBO.t;
|
||||
duration_withdraw: TimeRelativeNBO.t;
|
||||
}
|
||||
|
|
@ -512,7 +529,7 @@ module DenominationKeyAnnouncementPS = struct
|
|||
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw })
|
||||
|+ Purpose.field purpose
|
||||
|+ field DenominationHash.bin (fun t -> t.h_denom_pub)
|
||||
|+ field HashCode.bin (fun t -> t.h_section_name)
|
||||
|+ field Cstring_hash_64.bin (fun t -> t.h_section_name)
|
||||
|+ field TimeAbsoluteNBO.bin (fun t -> t.anchor_time)
|
||||
|+ field TimeRelativeNBO.bin (fun t -> t.duration_withdraw)
|
||||
|> sealr
|
||||
|
|
@ -562,7 +579,7 @@ module DepositRequestPS = struct
|
|||
amount_with_fee: AmountNBO.t;
|
||||
deposit_fee: AmountNBO.t;
|
||||
merchant: MerchantPublicKeyP.t;
|
||||
wallet_data_hash: HashCode.t;
|
||||
wallet_data_hash: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -613,7 +630,7 @@ module ExchangeKeySetPS = struct
|
|||
(* purpose.purpose = TALER_SIGNATURE_EXCHANGE_KEY_SET *)
|
||||
type t = {
|
||||
list_issue_date: TimeAbsoluteNBO.t;
|
||||
hc: HashCode.t;
|
||||
hc: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -637,16 +654,16 @@ module MasterWireDetailsPS = struct
|
|||
(* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_DETAILS *)
|
||||
type t = {
|
||||
h_wire_details: FullPaytoHash.t;
|
||||
h_conversion_url: HashCode.t;
|
||||
h_credit_restrictions: HashCode.t;
|
||||
h_debit_restrictions: HashCode.t;
|
||||
h_conversion_url: Cstring_hash_64.t;
|
||||
h_credit_restrictions: Cstring_hash_64.t;
|
||||
h_debit_restrictions: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
module MasterWireFeePS = struct
|
||||
(* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_FEES *)
|
||||
type t = {
|
||||
h_wire_method: HashCode.t;
|
||||
h_wire_method: Cstring_hash_64.t;
|
||||
start_date: TimeAbsoluteNBO.t;
|
||||
end_date: TimeAbsoluteNBO.t;
|
||||
wire_fee: AmountNBO.t;
|
||||
|
|
@ -676,7 +693,7 @@ module MasterDrainProfitPS = struct
|
|||
wtid: WireTransferIdentifierRawP.t;
|
||||
date: TimeAbsoluteNBO.t;
|
||||
amount: AmountNBO.t;
|
||||
h_section: HashCode.t;
|
||||
h_section: Cstring_hash_64.t;
|
||||
h_payto: FullPaytoHash.t;
|
||||
}
|
||||
end
|
||||
|
|
@ -707,14 +724,14 @@ module WireDepositDataPS = struct
|
|||
wire_fee: AmountNBO.t;
|
||||
merchant_pub: MerchantPublicKeyP.t;
|
||||
h_wire: MerchantWireHash.t;
|
||||
h_details: HashCode.t;
|
||||
h_details: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
module ExchangeKeyValidityPS = struct
|
||||
(* purpose.purpose = TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS *)
|
||||
type t = {
|
||||
auditor_url_hash: HashCode.t;
|
||||
auditor_url_hash: Cstring_hash_64.t;
|
||||
master: MasterPublicKeyP.t;
|
||||
start: TimeAbsoluteNBO.t;
|
||||
expire_withdraw: TimeAbsoluteNBO.t;
|
||||
|
|
@ -785,7 +802,7 @@ end
|
|||
module MerchantRefundConfirmationPS = struct
|
||||
(* purpose.purpose = TALER_SIGNATURE_MERCHANT_REFUND_OK *)
|
||||
(* Hash of the order ID (a string), hashed without the 0-termination. *)
|
||||
type t = { h_order_id: HashCode.t }
|
||||
type t = { h_order_id: Cstring_hash_64.t }
|
||||
end
|
||||
|
||||
module RecoupRequestPS = struct
|
||||
|
|
@ -910,7 +927,7 @@ module PurseDepositSignaturePS = struct
|
|||
h_denom_pub: DenominationHash.t;
|
||||
h_age_commitment: AgeCommitmentHash.t;
|
||||
purse_pub: PursePublicKey.t;
|
||||
h_exchange_base_url: HashCode.t;
|
||||
h_exchange_base_url: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -977,7 +994,7 @@ module WadDataSignaturePS = struct
|
|||
type t = {
|
||||
wad_execution_time: TimeAbsoluteNBO.t;
|
||||
total_amount: AmountNBO.t;
|
||||
h_items: HashCode.t;
|
||||
h_items: Cstring_hash_64.t;
|
||||
wad_id: WadId.t;
|
||||
}
|
||||
end
|
||||
|
|
@ -985,7 +1002,7 @@ end
|
|||
module WadPartnerSignaturePS = struct
|
||||
(* purpose.purpose = TALER_SIGNATURE_MASTER_PARTNER_DETAILS *)
|
||||
type t = {
|
||||
h_partner_base_url: HashCode.t;
|
||||
h_partner_base_url: Cstring_hash_64.t;
|
||||
master_public_key: MasterPublicKeyP.t;
|
||||
start_date: TimeAbsoluteNBO.t;
|
||||
end_date: TimeAbsoluteNBO.t;
|
||||
|
|
@ -1034,7 +1051,7 @@ module MasterAddAuditorPS = struct
|
|||
type t = {
|
||||
start_date: TimeAbsoluteNBO.t;
|
||||
auditor_pub: AuditorPublicKeyP.t;
|
||||
h_auditor_url: HashCode.t;
|
||||
h_auditor_url: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1051,9 +1068,9 @@ module MasterAddWirePS = struct
|
|||
type t = {
|
||||
start_date: TimeAbsoluteNBO.t;
|
||||
h_wire: FullPaytoHash.t;
|
||||
h_conversion_url: HashCode.t;
|
||||
h_credit_restrictions: HashCode.t;
|
||||
h_debit_restrictions: HashCode.t;
|
||||
h_conversion_url: Cstring_hash_64.t;
|
||||
h_credit_restrictions: Cstring_hash_64.t;
|
||||
h_debit_restrictions: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1070,7 +1087,7 @@ module MasterAmlOfficerStatusPS = struct
|
|||
type t = {
|
||||
change_date: TimestampNBO.t;
|
||||
officer_pub: AmlOfficerPublicKeyP.t;
|
||||
h_officer_name: HashCode.t;
|
||||
h_officer_name: Cstring_hash_64.t;
|
||||
is_active: int;
|
||||
}
|
||||
end
|
||||
|
|
@ -1078,11 +1095,11 @@ end
|
|||
module AmlDecisionPS = struct
|
||||
(* purpose.purpose = TALER_SIGNATURE_AML_DECISION *)
|
||||
type t = {
|
||||
h_justification: HashCode.t;
|
||||
h_justification: Cstring_hash_64.t;
|
||||
decision_time: TimestampNBO.t;
|
||||
new_threshold: AmountNBO.t;
|
||||
h_payto: NormalizedPaytoHash.t;
|
||||
h_kyc_requirements: HashCode.t;
|
||||
h_kyc_requirements: Cstring_hash_64.t;
|
||||
new_state: int;
|
||||
}
|
||||
end
|
||||
|
|
@ -1095,7 +1112,7 @@ module PartnerConfigurationPS = struct
|
|||
end_date: TimestampNBO.t;
|
||||
wad_frequency: TimeRelativeNBO.t;
|
||||
wad_fee: AmountNBO.t;
|
||||
h_url: HashCode.t;
|
||||
h_url: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1121,7 +1138,7 @@ module ReserveAttestRequestPS = struct
|
|||
(* purpose.purpose = TALER_SIGNATURE_WALLET_ATTEST_REQUEST *)
|
||||
type t = {
|
||||
request_timestamp: TimestampNBO.t;
|
||||
h_details: HashCode.t;
|
||||
h_details: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -1131,6 +1148,6 @@ module ExchangeAttestPS = struct
|
|||
attest_timestamp: TimestampNBO.t;
|
||||
expiration_time: TimestampNBO.t;
|
||||
reserve_pub: ReservePublicKeyP.t;
|
||||
h_attributes: HashCode.t;
|
||||
h_attributes: Cstring_hash_64.t;
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ let mk_future_denom denom_secmod_sign_f
|
|||
let denom_secmod_sig =
|
||||
let open Binary_formats in
|
||||
let h_denom_pub = DenominationHash.hash pub in
|
||||
let h_section_name = HashCode.of_string section_name in
|
||||
let h_section_name = Cstring_hash_64.hash section_name in
|
||||
let anchor_time =
|
||||
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue