curve25519_elligator2/lib.rs
1// -*- mode: rust; -*-
2//
3// This file is part of curve25519-elligator2.
4// Copyright (c) 2016-2021 isis lovecruft
5// Copyright (c) 2016-2019 Henry de Valence
6// See LICENSE for licensing information.
7//
8// Authors:
9// - isis agora lovecruft <isis@patternsinthevoid.net>
10// - Henry de Valence <hdevalence@hdevalence.ca>
11
12#![no_std]
13#![cfg_attr(
14 all(
15 curve25519_dalek_backend = "simd",
16 nightly,
17 any(target_arch = "x86", target_arch = "x86_64")
18 ),
19 feature(stdarch_x86_avx512)
20)]
21#![cfg_attr(
22 all(curve25519_dalek_backend = "simd", nightly),
23 feature(avx512_target_feature)
24)]
25#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg, doc_cfg_hide))]
26#![cfg_attr(docsrs, doc(cfg_hide(docsrs)))]
27//------------------------------------------------------------------------
28// Documentation:
29//------------------------------------------------------------------------
30#![doc(
31 html_logo_url = "https://cdn.jsdelivr.net/gh/dalek-cryptography/curve25519-dalek/docs/assets/dalek-logo-clear.png"
32)]
33#![doc = include_str!("../README.md")]
34//------------------------------------------------------------------------
35// Linting:
36//------------------------------------------------------------------------
37#![cfg_attr(allow_unused_unsafe, allow(unused_unsafe))]
38#![warn(
39 clippy::unwrap_used,
40 missing_docs,
41 rust_2018_idioms,
42 unused_lifetimes,
43 unused_qualifications
44)]
45
46//------------------------------------------------------------------------
47// External dependencies:
48//------------------------------------------------------------------------
49
50#[cfg(feature = "alloc")]
51#[allow(unused_imports)]
52#[macro_use]
53extern crate alloc;
54
55// TODO: move std-dependent tests to `tests/`
56#[cfg(test)]
57#[macro_use]
58extern crate std;
59
60#[cfg(feature = "digest")]
61pub use digest;
62
63// Internal macros. Must come first!
64#[macro_use]
65pub(crate) mod macros;
66
67//------------------------------------------------------------------------
68// curve25519-elligator2 public modules
69//------------------------------------------------------------------------
70
71// Scalar arithmetic mod l = 2^252 + ..., the order of the Ristretto group
72pub mod scalar;
73
74// Point operations on the Montgomery form of Curve25519
75pub mod montgomery;
76
77// Point operations on the Edwards form of Curve25519
78pub mod edwards;
79
80// Group operations on the Ristretto group
81pub mod ristretto;
82
83// Useful constants, like the Ed25519 basepoint
84pub mod constants;
85
86// External (and internal) traits.
87pub mod traits;
88
89//------------------------------------------------------------------------
90// curve25519-elligator2 internal modules
91//------------------------------------------------------------------------
92
93// Finite field arithmetic mod p = 2^255 - 19
94pub(crate) mod field;
95
96// elligator2 implementation for encoding/decoding points to representatives and
97// vice versa.
98#[cfg(feature = "elligator2")]
99pub mod elligator2;
100
101// Arithmetic backends (using u32, u64, etc) live here
102#[cfg(docsrs)]
103pub mod backend;
104#[cfg(not(docsrs))]
105pub(crate) mod backend;
106
107// Generic code for window lookups
108pub(crate) mod window;
109
110pub use crate::{
111 edwards::EdwardsPoint, montgomery::MontgomeryPoint, ristretto::RistrettoPoint, scalar::Scalar,
112};
113
114#[cfg(feature = "elligator2")]
115pub use elligator2::{representative_from_privkey, MapToPointVariant, Randomized, RFC9380};
116
117// Build time diagnostics for validation
118#[cfg(curve25519_dalek_diagnostics = "build")]
119mod diagnostics;