untested: rsa pub binary format
This commit is contained in:
parent
9ee9c787fd
commit
716826f0f1
2 changed files with 74 additions and 7 deletions
|
|
@ -22,6 +22,61 @@
|
|||
exchange and gana master branch are not in sync
|
||||
and we should use a specific git tag instead *)
|
||||
|
||||
(* -- Crypto keys -- *)
|
||||
|
||||
module RsaPublicKey = struct
|
||||
(* libgnuutil format:
|
||||
https://docs.gnunet.org/doxygen/d9/dbe/structGNUNET__CRYPTO__RsaPublicKeyHeaderP.html
|
||||
https://docs.gnunet.org/doxygen/d6/d70/group__libgnunetutil.html#ga9c99a81e8cd649c1c925d23211a0738f
|
||||
https://www.gnupg.org/documentation/manuals/gcrypt/MPI-formats.html
|
||||
|
||||
format:
|
||||
- rsa header
|
||||
- modulus
|
||||
- public_exponent
|
||||
|
||||
integer in big-endian format (MSB first).
|
||||
Leading zeroes are stripped unless they are required to keep a value positive.
|
||||
*)
|
||||
type header = {
|
||||
n_len: int;
|
||||
e_len: int;
|
||||
}
|
||||
|
||||
type t = {
|
||||
header: header;
|
||||
n: Z.t;
|
||||
e: Z.t;
|
||||
}
|
||||
|
||||
(* need to strip leading zeros or something? *)
|
||||
let z_to_bigendian_bits v =
|
||||
let s = Z.to_bits v in
|
||||
let len = String.length s in
|
||||
let s = String.init len (fun i -> s.[len - 1 - i]) in
|
||||
s
|
||||
|
||||
let header_bin =
|
||||
let open Bin in
|
||||
record (fun n_len e_len -> { n_len; e_len })
|
||||
|+ field beint16 (fun t -> t.n_len)
|
||||
|+ field beint16 (fun t -> t.e_len)
|
||||
|> sealr
|
||||
|
||||
let bin =
|
||||
let open Bin in
|
||||
record (fun header n e ->
|
||||
let n = Z.of_bits n in
|
||||
let e = Z.of_bits e in
|
||||
{ header; n; e })
|
||||
|+ field header_bin (fun t -> t.header)
|
||||
(* TODO
|
||||
Z.to_bits is in little endian but we need it in big endian *)
|
||||
|+ field cstring (fun t -> z_to_bigendian_bits t.n)
|
||||
|+ field cstring (fun t -> z_to_bigendian_bits t.e)
|
||||
|> sealr
|
||||
end
|
||||
|
||||
open Include
|
||||
|
||||
let int32_size = 4
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue