wip FDH-RSA
This commit is contained in:
parent
cdd490fbb8
commit
ee871ad6d2
3 changed files with 69 additions and 5 deletions
|
|
@ -259,15 +259,10 @@ end
|
|||
module RsaSignature : sig
|
||||
type t
|
||||
|
||||
val sign : key:Mirage_crypto_pk.Rsa.priv -> string -> t
|
||||
val jsont : t Jsont.t
|
||||
end = struct
|
||||
type t = string
|
||||
|
||||
(* TODO rsa sign *)
|
||||
let sign ~key s =
|
||||
Mirage_crypto_pk.Rsa.decrypt ~crt_hardening:true ~mask:`Yes ~key s
|
||||
|
||||
let jsont =
|
||||
let of_b32 s = B32.decode s in
|
||||
let to_b32 t = B32.encode t in
|
||||
|
|
@ -282,3 +277,22 @@ type rsa_priv = RsaPrivateKey.t
|
|||
type rsa_pub = RsaPublicKey.t
|
||||
type rsa_sig = RsaSignature.t
|
||||
type denomination_hash = Hash.DenominationHash.t
|
||||
|
||||
let rsa_full_domain_hash pub msg =
|
||||
let xts = RsaPublicKey.to_octets pub in
|
||||
let ctx = "RSA-FDA FTpsW!" in
|
||||
let r = Fdh.kdf_mod_n ~n:pub.n ~xts ~ikm:msg ~ctx in
|
||||
r
|
||||
|
||||
let rsa_blinding_key_derive (pub : RsaPublicKey.t) bks =
|
||||
let xts = "Blinding KDF extractor HMAC key" in
|
||||
let ctx = "Blinding KDF" in
|
||||
let r = Fdh.kdf_mod_n ~n:pub.n ~xts ~ikm:bks ~ctx in
|
||||
r
|
||||
|
||||
let rsa_blind pub ~bks ~msg =
|
||||
let data = rsa_full_domain_hash pub msg in
|
||||
let bkey = rsa_blinding_key_derive pub bks in
|
||||
let r_e = Z.powm bkey pub.e pub.n in
|
||||
let data_r_e = Z.rem (Z.mul data r_e) pub.n in
|
||||
Mirage_crypto_pk.Z_extra.to_octets_be data_r_e
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue