Skip to content

Commit

Permalink
house style
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed May 7, 2024
1 parent ff1ae5b commit 34b0c1b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions ec/mirage_crypto_ec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -632,29 +632,28 @@ module Make_dsa (Param : Parameters) (F : Fn) (P : Point) (S : Scalar) (H : Dige

let g ~key msg =
let g = Mirage_crypto_rng.create ~strict:true drbg in
Mirage_crypto_rng.reseed ~g
(S.to_octets key ^ msg);
Mirage_crypto_rng.reseed ~g (S.to_octets key ^ msg);
g

(* Defined in RFC 6979 sec 2.3.2 with
- blen = 8 * Param.byte_length
- qlen = Param.bit_length *)
let bits2int r =
(* keep qlen *leftmost* bits *)
let shift = (8 * Param.byte_length) - Param.bit_length in
if shift = 0 then Bytes.unsafe_to_string r
else (
(* Assuming shift is < 8 *)
let r' = Bytes.create Param.byte_length in
let p = ref 0x00 in
for i = 0 to Param.byte_length - 1 do
let x = Bytes.get_uint8 r i in
let v = (x lsr shift) lor (!p lsl (8 - shift)) in
p := x;
Bytes.set_uint8 r' i v
done;
Bytes.unsafe_to_string r'
)
(* keep qlen *leftmost* bits *)
let shift = (8 * Param.byte_length) - Param.bit_length in
if shift = 0 then
Bytes.unsafe_to_string r
else
(* Assuming shift is < 8 *)
let r' = Bytes.create Param.byte_length in
let p = ref 0x00 in
for i = 0 to Param.byte_length - 1 do
let x = Bytes.get_uint8 r i in
let v = (x lsr shift) lor (!p lsl (8 - shift)) in
p := x;
Bytes.set_uint8 r' i v
done;
Bytes.unsafe_to_string r'

(* take qbit length, and ensure it is suitable for ECDSA (> 0 & < n) *)
let gen g =
Expand Down

0 comments on commit 34b0c1b

Please sign in to comment.