@@ -8,29 +8,35 @@ pub use common::*;
88/// Twisted Edwards to Short Weierstrass mapping.
99pub use te_sw_map:: * ;
1010
11- use crate :: { AffinePoint , ScalarField , Suite } ;
12- use ark_ec:: AffineRepr ;
13-
14- type Projective < S > = <AffinePoint < S > as AffineRepr >:: Group ;
15-
16- /// Point scalar multiplication with secret splitting.
11+ /// Point scalar multiplication with optional secret splitting.
1712///
1813/// Secret scalar split into the sum of two scalars, which randomly mutate but
1914/// retain the same sum. Incurs 2x penalty in scalar multiplications, but provides
2015/// side channel defenses.
21- #[ cfg( feature = "secret-split" ) ]
22- #[ inline( always) ]
23- pub ( crate ) fn mul_secret < S : Suite > ( p : AffinePoint < S > , s : ScalarField < S > ) -> Projective < S > {
24- use ark_std:: UniformRand ;
25- let mut rng = ark_std:: rand:: rngs:: OsRng ;
26- let x1 = ScalarField :: < S > :: rand ( & mut rng) ;
27- let x2 = s - x1;
28- p * x1 + p * x2
29- }
16+ ///
17+ /// Note: actual secret splitting is enabled via the `secret-split` feature.
18+ mod secret_split {
19+ #[ cfg( feature = "secret-split" ) ]
20+ #[ doc( hidden) ]
21+ #[ macro_export]
22+ macro_rules! smul {
23+ ( $p: expr, $s: expr) => { {
24+ #[ inline( always) ]
25+ fn get_rand<T : ark_std:: UniformRand >( _: & T ) -> T {
26+ T :: rand( & mut ark_std:: rand:: rngs:: OsRng )
27+ }
28+ let x1 = get_rand( & $s) ;
29+ let x2 = $s - x1;
30+ $p * x1 + $p * x2
31+ } } ;
32+ }
3033
31- /// Point scalar multiplication with no secret splitting.
32- #[ cfg( not( feature = "secret-split" ) ) ]
33- #[ inline( always) ]
34- pub ( crate ) fn mul_secret < S : Suite > ( p : AffinePoint < S > , s : ScalarField < S > ) -> Projective < S > {
35- p * s
34+ #[ cfg( not( feature = "secret-split" ) ) ]
35+ #[ doc( hidden) ]
36+ #[ macro_export]
37+ macro_rules! smul {
38+ ( $p: expr, $s: expr) => {
39+ $p * $s
40+ } ;
41+ }
3642}
0 commit comments