Skip to content

Commit f6b3613

Browse files
committed
ec 25519: less arguments (offset being always 0)
1 parent db4f556 commit f6b3613

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

ec/mirage_crypto_ec.ml

+4-5
Original file line numberDiff line numberDiff line change
@@ -926,14 +926,13 @@ end
926926

927927
module X25519 = struct
928928
(* RFC 7748 *)
929-
external x25519_scalar_mult_generic : bytes -> bytes -> int -> bytes -> int -> unit = "mc_x25519_scalar_mult_generic" [@@noalloc]
929+
external x25519_scalar_mult_generic : bytes -> bytes -> bytes -> unit = "mc_x25519_scalar_mult_generic" [@@noalloc]
930930

931931
let key_len = 32
932932

933933
let scalar_mult in_ base =
934934
let out = Bytes.make key_len '\000' in
935-
x25519_scalar_mult_generic out
936-
in_ 0 base 0;
935+
x25519_scalar_mult_generic out in_ base;
937936
out
938937

939938
type secret = bytes
@@ -985,7 +984,7 @@ module Ed25519 = struct
985984
external scalar_mult_base_to_bytes : bytes -> bytes -> unit = "mc_25519_scalar_mult_base" [@@noalloc]
986985
external reduce_l : bytes -> unit = "mc_25519_reduce_l" [@@noalloc]
987986
external muladd : bytes -> bytes -> bytes -> bytes -> unit = "mc_25519_muladd" [@@noalloc]
988-
external double_scalar_mult : bytes -> bytes -> bytes -> bytes -> int -> bool = "mc_25519_double_scalar_mult" [@@noalloc]
987+
external double_scalar_mult : bytes -> bytes -> bytes -> bytes -> bool = "mc_25519_double_scalar_mult" [@@noalloc]
989988
external pub_ok : bytes -> bool = "mc_25519_pub_ok" [@@noalloc]
990989

991990
type pub = bytes
@@ -1081,7 +1080,7 @@ module Ed25519 = struct
10811080
let k = Cstruct.to_bytes k in
10821081
reduce_l k;
10831082
let r' = Bytes.make key_len '\000' in
1084-
let success = double_scalar_mult r' k key s 0 in
1083+
let success = double_scalar_mult r' k key s in
10851084
success && Bytes.equal r r'
10861085
end else
10871086
false

ec/native/curve25519_stubs.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -1803,12 +1803,11 @@ static void sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b,
18031803
}
18041804

18051805
#include <caml/memory.h>
1806-
#define _st_uint8_off(st, off) ((uint8_t*) String_val (st) + Long_val (off))
18071806

1808-
CAMLprim value mc_x25519_scalar_mult_generic(value out, value scalar, value soff, value point, value poff)
1807+
CAMLprim value mc_x25519_scalar_mult_generic(value out, value scalar, value point)
18091808
{
1810-
CAMLparam5(out, scalar, soff, point, poff);
1811-
x25519_scalar_mult_generic(Bytes_val(out), _st_uint8_off(scalar, soff), _st_uint8_off(point, poff));
1809+
CAMLparam3(out, scalar, point);
1810+
x25519_scalar_mult_generic(Bytes_val(out), Bytes_val(scalar), Bytes_val(point));
18121811
CAMLreturn(Val_unit);
18131812
}
18141813

@@ -1836,9 +1835,9 @@ CAMLprim value mc_25519_muladd(value out, value a, value b, value c)
18361835
CAMLreturn(Val_unit);
18371836
}
18381837

1839-
CAMLprim value mc_25519_double_scalar_mult(value out, value k, value key, value c, value coff)
1838+
CAMLprim value mc_25519_double_scalar_mult(value out, value k, value key, value c)
18401839
{
1841-
CAMLparam5(out, k, key, c, coff);
1840+
CAMLparam4(out, k, key, c);
18421841
ge_p2 R;
18431842
ge_p3 B;
18441843
fe_loose t;
@@ -1848,7 +1847,7 @@ CAMLprim value mc_25519_double_scalar_mult(value out, value k, value key, value
18481847
fe_carry(&B.X, &t);
18491848
fe_neg(&t, &B.T);
18501849
fe_carry(&B.T, &t);
1851-
ge_double_scalarmult_vartime(&R, Bytes_val(k), &B, _st_uint8_off(c, coff));
1850+
ge_double_scalarmult_vartime(&R, Bytes_val(k), &B, Bytes_val(c));
18521851
x25519_ge_tobytes(Bytes_val(out), &R);
18531852
CAMLreturn(Val_bool(success));
18541853
}

0 commit comments

Comments
 (0)