Skip to main content

ark_vrf/utils/
mod.rs

1//! # Common utilities
2//!
3//! This module provides cryptographic utility functions and curve mappings used
4//! throughout the VRF implementations.
5
6pub mod common;
7pub mod hash_to_curve;
8pub mod straus;
9pub mod te_sw_map;
10pub mod transcript;
11
12/// Standard cryptographic procedures.
13///
14/// Includes challenge generation, nonce derivation, and point-to-hash conversions
15/// inspired by RFC-9381 and RFC-8032.
16pub use common::*;
17
18/// Hash-to-curve implementations (TAI, Elligator2 with XMD/XOF).
19pub use hash_to_curve::*;
20
21/// Twisted Edwards to Short Weierstrass curve mapping.
22///
23/// Provides bidirectional mappings between different curve representations,
24/// allowing operations to be performed in the most convenient form.
25pub use te_sw_map::*;
26
27/// Fiat-Shamir transcript abstraction.
28pub use transcript::*;
29
30/// Point scalar multiplication with optional secret splitting.
31///
32/// When the `secret-split` feature is enabled, this macro splits the secret scalar
33/// into the sum of two randomly generated scalars that retain the same sum. This
34/// technique provides side-channel resistance at the cost of doubling the number
35/// of scalar multiplications.
36///
37/// Without the feature enabled, it performs a standard scalar multiplication.
38mod secret_split {
39    #[cfg(feature = "secret-split")]
40    #[doc(hidden)]
41    #[macro_export]
42    macro_rules! smul {
43        ($p:expr, $s:expr) => {{
44            #[inline(always)]
45            fn get_rand<T: ark_std::UniformRand>(_: &T) -> T {
46                T::rand(&mut ark_std::rand::rngs::OsRng)
47            }
48            let x1 = get_rand(&$s);
49            let x2 = $s - x1;
50            $p * x1 + $p * x2
51        }};
52    }
53
54    #[cfg(not(feature = "secret-split"))]
55    #[doc(hidden)]
56    #[macro_export]
57    macro_rules! smul {
58        ($p:expr, $s:expr) => {
59            $p * $s
60        };
61    }
62}