rename crockford

This commit is contained in:
swrup 2026-03-31 13:28:40 +02:00 committed by Swrup
parent 34b979a9bc
commit 10df5181a0
14 changed files with 80 additions and 70 deletions

View file

@ -54,15 +54,16 @@ module Account_operation = struct
|> Jsont.enum ~kind:"account operation type"
end
module B32 = struct
include B32
module Crockford = struct
include Crockford
let jsont = Jsont.of_of_string ~kind:"B32" B32.decode ~enc:B32.encode
let jsont =
Jsont.of_of_string ~kind:"Crockford" Crockford.decode ~enc:Crockford.encode
let caqti =
Caqti_type.custom
~encode:(fun v -> Ok (B32.encode v))
~decode:B32.decode Caqti_type.string
~encode:(fun v -> Ok (Crockford.encode v))
~decode:Crockford.decode Caqti_type.string
end
module ErrorDetail = struct

View file

@ -209,4 +209,4 @@ let rsa_keysize s =
(* because of [kdf_mod_n] *)
failure "RSA keysize must be multiple of 8, found `%d`" nbits
let ed25519 s = Eddsa.pub_of_b32 s |> unwrap_or_failure
let ed25519 s = Eddsa.pub_of_crockford s |> unwrap_or_failure

View file

@ -65,7 +65,7 @@
signatures
api)
(libraries
(re_export b32)
(re_export crockford)
(re_export taler_signature_purpose_codes)
;
angstrom
@ -89,9 +89,9 @@
;
))
(library ; crockford base32
(name b32)
(modules b32)
(library
(name crockford)
(modules crockford)
(libraries base32))
(rule

View file

@ -25,14 +25,15 @@ module Priv = struct
Mirage_eddsa.priv_of_octets o
|> Result.map_error (Fmt.str "%a" pp_mirage_error)
let priv_to_b32 t = priv_to_octets t |> B32.encode
let priv_to_crockford t = priv_to_octets t |> Crockford.encode
let priv_of_b32 s =
let* octets = B32.decode s in
let priv_of_crockford s =
let* octets = Crockford.decode s in
priv_of_octets octets
let priv_jsont =
Jsont.of_of_string ~kind:"EddsaPrivateKey" priv_of_b32 ~enc:priv_to_b32
Jsont.of_of_string ~kind:"EddsaPrivateKey" priv_of_crockford
~enc:priv_to_crockford
let priv_bin =
let priv_of_octets_exn t =
@ -48,14 +49,15 @@ module Pub = struct
Mirage_eddsa.pub_of_octets t
|> Result.map_error (Fmt.str "%a" pp_mirage_error)
let pub_to_b32 t = pub_to_octets t |> B32.encode
let pub_to_crockford t = pub_to_octets t |> Crockford.encode
let pub_of_b32 s =
let* octets = B32.decode s in
let pub_of_crockford s =
let* octets = Crockford.decode s in
pub_of_octets octets
let pub_jsont =
Jsont.of_of_string ~kind:"EddsaPublicKey" pub_of_b32 ~enc:pub_to_b32
Jsont.of_of_string ~kind:"EddsaPublicKey" pub_of_crockford
~enc:pub_to_crockford
let pub_bin =
let pub_of_octets_exn t =
@ -77,14 +79,15 @@ module Sig_ = struct
| false -> Error "invalid eddsa signature length"
| true -> Ok (S s)
let sig_of_b32 s =
let* s = B32.decode s in
let sig_of_crockford s =
let* s = Crockford.decode s in
sig_of_octets s
let sig_to_b32 (S s) = B32.encode s
let sig_to_crockford (S s) = Crockford.encode s
let sig_jsont =
Jsont.of_of_string ~kind:"EddsaSignature" sig_of_b32 ~enc:sig_to_b32
Jsont.of_of_string ~kind:"EddsaSignature" sig_of_crockford
~enc:sig_to_crockford
let sig_bin =
let sig_of_octets_exn t =
@ -102,4 +105,4 @@ include Priv
include Pub
include Sig_
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_b32 pub)
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_crockford pub)

View file

@ -5,8 +5,8 @@ module type S = sig
val hash : string -> t
val to_octets : t -> string
val to_b32 : t -> B32.t
val of_b32 : B32.t -> (t, string) result
val to_crockford : t -> Crockford.t
val of_crockford : Crockford.t -> (t, string) result
val pp_hex : Format.formatter -> t -> unit
val pp : Format.formatter -> t -> unit
val bin : t Bin.t
@ -25,14 +25,14 @@ module MK (H : Digestif.S) : S = struct
| Some t -> Ok t
let to_octets = H.to_raw_string
let to_b32 t = B32.encode (to_octets t)
let to_crockford t = Crockford.encode (to_octets t)
let of_b32 s =
let* o = B32.decode s in
let of_crockford s =
let* o = Crockford.decode s in
of_octets o
let pp_hex = H.pp
let pp ppf t = Fmt.pf ppf "%s" (to_b32 t)
let pp ppf t = Fmt.pf ppf "%s" (to_crockford t)
let bin =
let of_octets_exn s =
@ -45,7 +45,7 @@ module MK (H : Digestif.S) : S = struct
let open Caqti_type in
custom ~encode:(fun v -> Ok (to_octets v)) ~decode:of_octets octets
let jsont = Jsont.of_of_string ~kind:"hash" of_b32 ~enc:to_b32
let jsont = Jsont.of_of_string ~kind:"hash" of_crockford ~enc:to_crockford
end
module H32 = MK (Digestif.SHA256)

View file

@ -63,7 +63,8 @@ module Denom_revoke = struct
@@
let keys = Vifu.Server.device Mte_device.keys server in
let* h_denom_pub =
DenominationHash.of_b32 h_denom_pub |> Result.map_error (fun e -> `Msg e)
DenominationHash.of_crockford h_denom_pub
|> Result.map_error (fun e -> `Msg e)
in
let* v = request_of_json req in
let* () = verify keys h_denom_pub v in
@ -90,7 +91,7 @@ module Signkey_revoke = struct
@@
let keys = Vifu.Server.device Mte_device.keys server in
let* exchange_pub =
Eddsa.pub_of_b32 exchange_pub |> Result.map_error (fun e -> `Msg e)
Eddsa.pub_of_crockford exchange_pub |> Result.map_error (fun e -> `Msg e)
in
let* v = request_of_json req in
let* () = verify keys exchange_pub v in
@ -186,7 +187,7 @@ module Auditors_disable = struct
let keys = Vifu.Server.device Mte_device.keys server in
let db_conn = Vifu.Server.device Mte_device.db_conn server in
let* auditor_pub =
Eddsa.pub_of_b32 auditor_pub |> Result.map_error (fun e -> `Msg e)
Eddsa.pub_of_crockford auditor_pub |> Result.map_error (fun e -> `Msg e)
in
let* v = request_of_json req in
let* () = verify keys auditor_pub v in

View file

@ -90,23 +90,24 @@ module Priv = struct
let priv_of_octets = RSA_BIN.priv_of_octets
let priv_to_octets = RSA_BIN.priv_to_octets
let priv_of_b32 s =
let* s = B32.decode s in
let priv_of_crockford s =
let* s = Crockford.decode s in
priv_of_octets s
let priv_to_b32 t = B32.encode (priv_to_octets t)
let priv_to_crockford t = Crockford.encode (priv_to_octets t)
let priv_jsont =
Jsont.of_of_string ~kind:"RsaPrivateKey" priv_of_b32 ~enc:priv_to_b32
Jsont.of_of_string ~kind:"RsaPrivateKey" priv_of_crockford
~enc:priv_to_crockford
end
module Pub = struct
let pub_to_octets = RSA_BIN.pub_to_octets
let pub_of_octets = RSA_BIN.pub_of_octets
let pub_to_b32 t = B32.encode (pub_to_octets t)
let pub_to_crockford t = Crockford.encode (pub_to_octets t)
let pub_of_b32 s =
let* s = B32.decode s in
let pub_of_crockford s =
let* s = Crockford.decode s in
pub_of_octets s
let pub_caqti =
@ -115,14 +116,15 @@ module Pub = struct
~decode:pub_of_octets Caqti_type.octets
let pub_jsont =
Jsont.of_of_string ~kind:"RsaPublicKey" pub_of_b32 ~enc:pub_to_b32
Jsont.of_of_string ~kind:"RsaPublicKey" pub_of_crockford
~enc:pub_to_crockford
end
include Priv
include Pub
let sig_jsont =
Jsont.of_of_string ~kind:"RsaSignature" B32.decode ~enc:B32.encode
Jsont.of_of_string ~kind:"RsaSignature" Crockford.decode ~enc:Crockford.encode
(* ---- *)
@ -208,4 +210,4 @@ let sign ~key bmsg : sig_ =
let sig_ = Mirage_rsa.decrypt ~crt_hardening:true ~key bmsg in
S sig_
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_b32 pub)
let pp_pub ppf pub = Fmt.pf ppf "%s" (pub_to_crockford pub)

View file

@ -60,7 +60,7 @@ let write_eddsa fs spath priv =
Fat.write fs spath data
let key_spath k =
let sfn = String.sub (Eddsa.pub_to_b32 k.pub) 0 8 in
let sfn = String.sub (Eddsa.pub_to_crockford k.pub) 0 8 in
Fat.Path.add Cfg.key_dir sfn
let read_key fs spath =

View file

@ -48,9 +48,9 @@ let find_exn h_pub section_name =
rsa keysize is not known and then we have to escape '\x00' *)
let rsa_private_key_bin =
let decode_exn o =
Rsa.priv_of_b32 o |> function Error e -> invalid_arg e | Ok v -> v
Rsa.priv_of_crockford o |> function Error e -> invalid_arg e | Ok v -> v
in
let encode o = Rsa.priv_to_b32 o in
let encode o = Rsa.priv_to_crockford o in
Bin.map Bin.cstring decode_exn encode
let key_bin =
@ -67,7 +67,7 @@ let key_bin =
|> sealr
let key_spath k =
let sfn = String.sub (DenominationHash.to_b32 k.h_pub) 0 8 in
let sfn = String.sub (DenominationHash.to_crockford k.h_pub) 0 8 in
Fat.Path.add Cfg.key_dir sfn
let read_eddsa fs spath =

View file

@ -72,8 +72,8 @@ module Bytes32 : BYTES = struct
| true -> Ok s
let jsont =
let decode s = Result.bind (B32.decode s) of_octets in
let encode b = to_octets b |> B32.encode in
let decode s = Result.bind (Crockford.decode s) of_octets in
let encode b = to_octets b |> Crockford.encode in
Jsont.of_of_string ~kind:"Bytes32" decode ~enc:encode
let caqti =
@ -101,8 +101,8 @@ module Bytes64 : BYTES = struct
| true -> Ok s
let jsont =
let decode s = Result.bind (B32.decode s) of_octets in
let encode b = to_octets b |> B32.encode in
let decode s = Result.bind (Crockford.decode s) of_octets in
let encode b = to_octets b |> Crockford.encode in
Jsont.of_of_string ~kind:"Bytes64" decode ~enc:encode
let caqti =