This commit is contained in:
parent
f10791fa33
commit
74dfe2da06
2 changed files with 18 additions and 14 deletions
|
|
@ -64,7 +64,12 @@ let rsa_blind pub ~bks ~msg =
|
|||
let data_r_e = Z.rem (Z.mul data r_e) pub.n in
|
||||
Z_extra.to_octets_be data_r_e
|
||||
|
||||
(* decrypt <=> sign *)
|
||||
let rsa_sign_blinded priv ~msg_blind =
|
||||
Mirage_crypto_pk.Rsa.decrypt ~crt_hardening:true ~key:priv msg_blind
|
||||
|
||||
let rsa_unblind pub ~bks ~sig_ =
|
||||
let data = Z_extra.of_octets_be sig_ in
|
||||
let bkey = rsa_blinding_key_derive pub bks in
|
||||
let r_inv =
|
||||
try Z.invert bkey pub.n
|
||||
|
|
@ -72,22 +77,15 @@ let rsa_unblind pub ~bks ~sig_ =
|
|||
(* => gcd(r,n) <> 1, should be already checked for *)
|
||||
assert false
|
||||
in
|
||||
let ubsig = Z.rem (Z.mul sig_ r_inv) pub.n in
|
||||
ubsig
|
||||
|
||||
let rsa_sign_fdh priv msg =
|
||||
let pub = RsaPrivateKey.pub_of_priv priv in
|
||||
let r = rsa_full_domain_hash pub msg in
|
||||
let data = Z_extra.to_octets_be r in
|
||||
(* decrypt <=> sign *)
|
||||
Mirage_crypto_pk.Rsa.decrypt ~crt_hardening:true ~key:priv data
|
||||
let data = Z.rem (Z.mul data r_inv) pub.n in
|
||||
Z_extra.to_octets_be data
|
||||
|
||||
(* TODO crypto
|
||||
look into mirage-crypto for this
|
||||
at least use Eqaf for constant time string compare *)
|
||||
let rsa_verify pub ~msg ~sig_ =
|
||||
let r = rsa_full_domain_hash pub msg in
|
||||
let s1 = Z_extra.to_octets_be r in
|
||||
let msg_fdh = rsa_full_domain_hash pub msg in
|
||||
let s1 = Z_extra.to_octets_be msg_fdh in
|
||||
let s2 = Mirage_crypto_pk.Rsa.encrypt ~key:pub sig_ in
|
||||
match String.equal s1 s2 with
|
||||
| false -> Fmt.error "RSA signature verification failed"
|
||||
|
|
|
|||
|
|
@ -99,12 +99,18 @@ let () =
|
|||
"3KHKZJZ30ABB4E56MA2V0EQWGCWH0QQG9P2ZHYHR186C5HZXJMM4N9WXAQTKS94QSV9Y17GGNXN5MB1PZZFG7Q0FY88QPKKRG4MYCPSMTZK5W59R0MJVNJ4P4AQM96TDG5W7RV8GSNR1QQZ1GNHW3CX6D6ZRTMXB2NKB5SSYTDJS79F5ZFBRZ4HVED9JBBPWSR79KVV5QQ4APBGHBCKGMF9NJJS53A1BVYHDEVYAGFYF2SNEP827ZP50FKJ5GKGV8NQ15ESEZ69AT7GJG0T3TZVENY2YN9CVR98W3BKEZ53J7VTANARG8SJS8AMJQ7S23P5HRJ7XE9KTNRNXKH49MXV9JHHYE5535N7AGWEKR47SBCGNF44Z7XJ9RV5BQV12ZRJKN4HBZQHDNCMH3QKX9Z6G64"
|
||||
in
|
||||
let open Crypto in
|
||||
let msg = message_hash |> decode in
|
||||
let pub =
|
||||
rsa_public_key |> decode |> RsaPublicKey.of_octets |> Result.get_ok
|
||||
in
|
||||
let bks = blinding_key_secret |> decode in
|
||||
let s = Fdh_rsa.rsa_blind pub ~bks ~msg |> encode in
|
||||
assert (s = blinded_message);
|
||||
let msg = decode message_hash in
|
||||
let msg_blind = Fdh_rsa.rsa_blind pub ~bks ~msg in
|
||||
assert (encode msg_blind = blinded_message);
|
||||
let msg_fdh =
|
||||
Mirage_crypto_pk.Z_extra.to_octets_be
|
||||
@@ Fdh_rsa.rsa_full_domain_hash pub msg
|
||||
in
|
||||
let msg_fdh' = Fdh_rsa.rsa_unblind pub ~bks ~sig_:msg_blind in
|
||||
assert (msg_fdh' = msg_fdh);
|
||||
|
||||
()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue