+ define Hash_64 with include
This commit is contained in:
parent
f7a33e2dd4
commit
f1e7ab9676
2 changed files with 59 additions and 44 deletions
|
|
@ -37,10 +37,11 @@
|
||||||
!! not strings that are raw-bytes-data-like
|
!! not strings that are raw-bytes-data-like
|
||||||
*)
|
*)
|
||||||
|
|
||||||
module UTIL = struct
|
|
||||||
let int32_size = 4
|
let int32_size = 4
|
||||||
let int64_size = 8
|
let int64_size = 8
|
||||||
|
|
||||||
|
(* todo clean up: maybe rm it *)
|
||||||
|
module UTIL_FUNC = struct
|
||||||
(* microseconds since the UNIX Epoch
|
(* microseconds since the UNIX Epoch
|
||||||
UINT64_MAX represents "never" *)
|
UINT64_MAX represents "never" *)
|
||||||
module MK_TIME () = struct
|
module MK_TIME () = struct
|
||||||
|
|
@ -125,21 +126,17 @@ module UTIL = struct
|
||||||
|+ field (bytes 64) (fun t -> t.hash)
|
|+ field (bytes 64) (fun t -> t.hash)
|
||||||
|> sealr
|
|> sealr
|
||||||
end
|
end
|
||||||
(*
|
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
|
|
||||||
*)
|
|
||||||
|
|
||||||
module HASH_64 : sig
|
module UTIL_HASH = struct
|
||||||
|
module type H_sig = sig
|
||||||
type t
|
type t
|
||||||
|
|
||||||
val hash : string -> t
|
val hash : string -> t
|
||||||
val bin : t Bin.t
|
val bin : t Bin.t
|
||||||
end = struct
|
end
|
||||||
|
|
||||||
|
module HHH_64 : H_sig = struct
|
||||||
type t = { hash: Digestif.SHA512.t }
|
type t = { hash: Digestif.SHA512.t }
|
||||||
|
|
||||||
let hash s =
|
let hash s =
|
||||||
|
|
@ -154,9 +151,30 @@ module UTIL = struct
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun hash -> { hash }) |+ field hash_bin (fun t -> t.hash) |> sealr
|
record (fun hash -> { hash }) |+ field hash_bin (fun t -> t.hash) |> sealr
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
open UTIL
|
(* sha512 but add a null termination to the given string
|
||||||
|
this is "HashCode" in GNU TALER *)
|
||||||
|
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
|
module Taler_signatures = Include.Taler_signatures
|
||||||
|
|
||||||
(* -- Time -- *)
|
(* -- Time -- *)
|
||||||
|
|
@ -233,7 +251,7 @@ module GNUNET_RsaPublicKey = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
module DenominationHash = struct
|
module DenominationHash = struct
|
||||||
include HASH_64
|
include Hash_64
|
||||||
|
|
||||||
let hash (pub : Mirage_crypto_pk.Rsa.pub) =
|
let hash (pub : Mirage_crypto_pk.Rsa.pub) =
|
||||||
pub
|
pub
|
||||||
|
|
@ -244,9 +262,6 @@ end
|
||||||
|
|
||||||
(* --- Hashes --- *)
|
(* --- Hashes --- *)
|
||||||
|
|
||||||
module ShortHashCode = MK_HASH_32 ()
|
|
||||||
module HashCode = MK_HASH_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 FullPaytoHash = MK_HASH_32 ()
|
module FullPaytoHash = MK_HASH_32 ()
|
||||||
|
|
@ -499,7 +514,7 @@ module DenominationKeyAnnouncementPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_SM_DENOMINATION_KEY *)
|
(* purpose.purpose = TALER_SIGNATURE_SM_DENOMINATION_KEY *)
|
||||||
type t = {
|
type t = {
|
||||||
h_denom_pub: DenominationHash.t;
|
h_denom_pub: DenominationHash.t;
|
||||||
h_section_name: HashCode.t;
|
h_section_name: Cstring_hash_64.t;
|
||||||
anchor_time: TimeAbsoluteNBO.t;
|
anchor_time: TimeAbsoluteNBO.t;
|
||||||
duration_withdraw: TimeRelativeNBO.t;
|
duration_withdraw: TimeRelativeNBO.t;
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +527,7 @@ module DenominationKeyAnnouncementPS = struct
|
||||||
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw })
|
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw })
|
||||||
|+ Purpose.field purpose
|
|+ Purpose.field purpose
|
||||||
|+ field DenominationHash.bin (fun t -> t.h_denom_pub)
|
|+ 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 TimeAbsoluteNBO.bin (fun t -> t.anchor_time)
|
||||||
|+ field TimeRelativeNBO.bin (fun t -> t.duration_withdraw)
|
|+ field TimeRelativeNBO.bin (fun t -> t.duration_withdraw)
|
||||||
|> sealr
|
|> sealr
|
||||||
|
|
@ -562,7 +577,7 @@ module DepositRequestPS = struct
|
||||||
amount_with_fee: AmountNBO.t;
|
amount_with_fee: AmountNBO.t;
|
||||||
deposit_fee: AmountNBO.t;
|
deposit_fee: AmountNBO.t;
|
||||||
merchant: MerchantPublicKeyP.t;
|
merchant: MerchantPublicKeyP.t;
|
||||||
wallet_data_hash: HashCode.t;
|
wallet_data_hash: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -613,7 +628,7 @@ module ExchangeKeySetPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_EXCHANGE_KEY_SET *)
|
(* purpose.purpose = TALER_SIGNATURE_EXCHANGE_KEY_SET *)
|
||||||
type t = {
|
type t = {
|
||||||
list_issue_date: TimeAbsoluteNBO.t;
|
list_issue_date: TimeAbsoluteNBO.t;
|
||||||
hc: HashCode.t;
|
hc: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -637,16 +652,16 @@ module MasterWireDetailsPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_DETAILS *)
|
(* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_DETAILS *)
|
||||||
type t = {
|
type t = {
|
||||||
h_wire_details: FullPaytoHash.t;
|
h_wire_details: FullPaytoHash.t;
|
||||||
h_conversion_url: HashCode.t;
|
h_conversion_url: Cstring_hash_64.t;
|
||||||
h_credit_restrictions: HashCode.t;
|
h_credit_restrictions: Cstring_hash_64.t;
|
||||||
h_debit_restrictions: HashCode.t;
|
h_debit_restrictions: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
module MasterWireFeePS = struct
|
module MasterWireFeePS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_FEES *)
|
(* purpose.purpose = TALER_SIGNATURE_MASTER_WIRE_FEES *)
|
||||||
type t = {
|
type t = {
|
||||||
h_wire_method: HashCode.t;
|
h_wire_method: Cstring_hash_64.t;
|
||||||
start_date: TimeAbsoluteNBO.t;
|
start_date: TimeAbsoluteNBO.t;
|
||||||
end_date: TimeAbsoluteNBO.t;
|
end_date: TimeAbsoluteNBO.t;
|
||||||
wire_fee: AmountNBO.t;
|
wire_fee: AmountNBO.t;
|
||||||
|
|
@ -676,7 +691,7 @@ module MasterDrainProfitPS = struct
|
||||||
wtid: WireTransferIdentifierRawP.t;
|
wtid: WireTransferIdentifierRawP.t;
|
||||||
date: TimeAbsoluteNBO.t;
|
date: TimeAbsoluteNBO.t;
|
||||||
amount: AmountNBO.t;
|
amount: AmountNBO.t;
|
||||||
h_section: HashCode.t;
|
h_section: Cstring_hash_64.t;
|
||||||
h_payto: FullPaytoHash.t;
|
h_payto: FullPaytoHash.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -707,14 +722,14 @@ module WireDepositDataPS = struct
|
||||||
wire_fee: AmountNBO.t;
|
wire_fee: AmountNBO.t;
|
||||||
merchant_pub: MerchantPublicKeyP.t;
|
merchant_pub: MerchantPublicKeyP.t;
|
||||||
h_wire: MerchantWireHash.t;
|
h_wire: MerchantWireHash.t;
|
||||||
h_details: HashCode.t;
|
h_details: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
module ExchangeKeyValidityPS = struct
|
module ExchangeKeyValidityPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS *)
|
(* purpose.purpose = TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS *)
|
||||||
type t = {
|
type t = {
|
||||||
auditor_url_hash: HashCode.t;
|
auditor_url_hash: Cstring_hash_64.t;
|
||||||
master: MasterPublicKeyP.t;
|
master: MasterPublicKeyP.t;
|
||||||
start: TimeAbsoluteNBO.t;
|
start: TimeAbsoluteNBO.t;
|
||||||
expire_withdraw: TimeAbsoluteNBO.t;
|
expire_withdraw: TimeAbsoluteNBO.t;
|
||||||
|
|
@ -785,7 +800,7 @@ end
|
||||||
module MerchantRefundConfirmationPS = struct
|
module MerchantRefundConfirmationPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_MERCHANT_REFUND_OK *)
|
(* purpose.purpose = TALER_SIGNATURE_MERCHANT_REFUND_OK *)
|
||||||
(* Hash of the order ID (a string), hashed without the 0-termination. *)
|
(* 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
|
end
|
||||||
|
|
||||||
module RecoupRequestPS = struct
|
module RecoupRequestPS = struct
|
||||||
|
|
@ -910,7 +925,7 @@ module PurseDepositSignaturePS = struct
|
||||||
h_denom_pub: DenominationHash.t;
|
h_denom_pub: DenominationHash.t;
|
||||||
h_age_commitment: AgeCommitmentHash.t;
|
h_age_commitment: AgeCommitmentHash.t;
|
||||||
purse_pub: PursePublicKey.t;
|
purse_pub: PursePublicKey.t;
|
||||||
h_exchange_base_url: HashCode.t;
|
h_exchange_base_url: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -977,7 +992,7 @@ module WadDataSignaturePS = struct
|
||||||
type t = {
|
type t = {
|
||||||
wad_execution_time: TimeAbsoluteNBO.t;
|
wad_execution_time: TimeAbsoluteNBO.t;
|
||||||
total_amount: AmountNBO.t;
|
total_amount: AmountNBO.t;
|
||||||
h_items: HashCode.t;
|
h_items: Cstring_hash_64.t;
|
||||||
wad_id: WadId.t;
|
wad_id: WadId.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -985,7 +1000,7 @@ end
|
||||||
module WadPartnerSignaturePS = struct
|
module WadPartnerSignaturePS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_MASTER_PARTNER_DETAILS *)
|
(* purpose.purpose = TALER_SIGNATURE_MASTER_PARTNER_DETAILS *)
|
||||||
type t = {
|
type t = {
|
||||||
h_partner_base_url: HashCode.t;
|
h_partner_base_url: Cstring_hash_64.t;
|
||||||
master_public_key: MasterPublicKeyP.t;
|
master_public_key: MasterPublicKeyP.t;
|
||||||
start_date: TimeAbsoluteNBO.t;
|
start_date: TimeAbsoluteNBO.t;
|
||||||
end_date: TimeAbsoluteNBO.t;
|
end_date: TimeAbsoluteNBO.t;
|
||||||
|
|
@ -1034,7 +1049,7 @@ module MasterAddAuditorPS = struct
|
||||||
type t = {
|
type t = {
|
||||||
start_date: TimeAbsoluteNBO.t;
|
start_date: TimeAbsoluteNBO.t;
|
||||||
auditor_pub: AuditorPublicKeyP.t;
|
auditor_pub: AuditorPublicKeyP.t;
|
||||||
h_auditor_url: HashCode.t;
|
h_auditor_url: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1051,9 +1066,9 @@ module MasterAddWirePS = struct
|
||||||
type t = {
|
type t = {
|
||||||
start_date: TimeAbsoluteNBO.t;
|
start_date: TimeAbsoluteNBO.t;
|
||||||
h_wire: FullPaytoHash.t;
|
h_wire: FullPaytoHash.t;
|
||||||
h_conversion_url: HashCode.t;
|
h_conversion_url: Cstring_hash_64.t;
|
||||||
h_credit_restrictions: HashCode.t;
|
h_credit_restrictions: Cstring_hash_64.t;
|
||||||
h_debit_restrictions: HashCode.t;
|
h_debit_restrictions: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1070,7 +1085,7 @@ module MasterAmlOfficerStatusPS = struct
|
||||||
type t = {
|
type t = {
|
||||||
change_date: TimestampNBO.t;
|
change_date: TimestampNBO.t;
|
||||||
officer_pub: AmlOfficerPublicKeyP.t;
|
officer_pub: AmlOfficerPublicKeyP.t;
|
||||||
h_officer_name: HashCode.t;
|
h_officer_name: Cstring_hash_64.t;
|
||||||
is_active: int;
|
is_active: int;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -1078,11 +1093,11 @@ end
|
||||||
module AmlDecisionPS = struct
|
module AmlDecisionPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_AML_DECISION *)
|
(* purpose.purpose = TALER_SIGNATURE_AML_DECISION *)
|
||||||
type t = {
|
type t = {
|
||||||
h_justification: HashCode.t;
|
h_justification: Cstring_hash_64.t;
|
||||||
decision_time: TimestampNBO.t;
|
decision_time: TimestampNBO.t;
|
||||||
new_threshold: AmountNBO.t;
|
new_threshold: AmountNBO.t;
|
||||||
h_payto: NormalizedPaytoHash.t;
|
h_payto: NormalizedPaytoHash.t;
|
||||||
h_kyc_requirements: HashCode.t;
|
h_kyc_requirements: Cstring_hash_64.t;
|
||||||
new_state: int;
|
new_state: int;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -1095,7 +1110,7 @@ module PartnerConfigurationPS = struct
|
||||||
end_date: TimestampNBO.t;
|
end_date: TimestampNBO.t;
|
||||||
wad_frequency: TimeRelativeNBO.t;
|
wad_frequency: TimeRelativeNBO.t;
|
||||||
wad_fee: AmountNBO.t;
|
wad_fee: AmountNBO.t;
|
||||||
h_url: HashCode.t;
|
h_url: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1121,7 +1136,7 @@ module ReserveAttestRequestPS = struct
|
||||||
(* purpose.purpose = TALER_SIGNATURE_WALLET_ATTEST_REQUEST *)
|
(* purpose.purpose = TALER_SIGNATURE_WALLET_ATTEST_REQUEST *)
|
||||||
type t = {
|
type t = {
|
||||||
request_timestamp: TimestampNBO.t;
|
request_timestamp: TimestampNBO.t;
|
||||||
h_details: HashCode.t;
|
h_details: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1131,6 +1146,6 @@ module ExchangeAttestPS = struct
|
||||||
attest_timestamp: TimestampNBO.t;
|
attest_timestamp: TimestampNBO.t;
|
||||||
expiration_time: TimestampNBO.t;
|
expiration_time: TimestampNBO.t;
|
||||||
reserve_pub: ReservePublicKeyP.t;
|
reserve_pub: ReservePublicKeyP.t;
|
||||||
h_attributes: HashCode.t;
|
h_attributes: Cstring_hash_64.t;
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ let mk_future_denom denom_secmod_sign_f
|
||||||
let denom_secmod_sig =
|
let denom_secmod_sig =
|
||||||
let open Binary_formats in
|
let open Binary_formats in
|
||||||
let h_denom_pub = DenominationHash.hash pub 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 =
|
let anchor_time =
|
||||||
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
||||||
in
|
in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue