mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Remove build.rs.
This was more useful at the time when we were determining, e.g., optimal lookup table sizes and could regenerate them more easily, but it came at a massive complexity cost. It also meant that we were unable to implement backend autoselection. This commit removes the `build.rs` entirely. In the future, a different `build.rs` could be added that auto-selects a backend, but it seems like the current default-u64 setup has been working fine.
This commit is contained in:
parent
8602ec0724
commit
574217694e
13 changed files with 12306 additions and 291 deletions
27
Cargo.toml
27
Cargo.toml
|
|
@ -16,7 +16,6 @@ exclude = [
|
|||
".gitignore",
|
||||
".travis.yml",
|
||||
]
|
||||
build = "build.rs"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
# Disabled for now since this is borked; tracking https://github.com/rust-lang/docs.rs/issues/302
|
||||
|
|
@ -37,12 +36,6 @@ rand = "0.6"
|
|||
name = "dalek_benchmarks"
|
||||
harness = false
|
||||
|
||||
# Note: we generate precomputed tables by building the crate twice: once as
|
||||
# part of build.rs, and then once "for real".
|
||||
#
|
||||
# This means that the [dependencies] and [build-dependencies] sections must
|
||||
# match exactly, since the build.rs uses the crate itself as a library.
|
||||
|
||||
[dependencies]
|
||||
rand_core = { version = "0.3.0", default-features = false }
|
||||
byteorder = { version = "^1.2.3", default-features = false, features = ["i128"] }
|
||||
|
|
@ -52,21 +45,11 @@ subtle = { version = "2", default-features = false }
|
|||
serde = { version = "1.0", default-features = false, optional = true }
|
||||
packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
rand_core = { version = "0.3.0", default-features = false }
|
||||
byteorder = { version = "^1.2.3", default-features = false, features = ["i128"] }
|
||||
digest = { version = "0.8", default-features = false }
|
||||
clear_on_drop = "=0.2.3"
|
||||
subtle = { version = "2", default-features = false }
|
||||
serde = { version = "1.0", default-features = false, optional = true }
|
||||
packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true }
|
||||
|
||||
[features]
|
||||
nightly = ["subtle/nightly", "clear_on_drop/nightly"]
|
||||
default = ["std", "u64_backend"]
|
||||
std = ["alloc", "subtle/std", "rand_core/std"]
|
||||
alloc = []
|
||||
yolocrypto = []
|
||||
|
||||
# The u32 backend uses u32s with u64 products.
|
||||
u32_backend = []
|
||||
|
|
@ -74,12 +57,6 @@ u32_backend = []
|
|||
u64_backend = []
|
||||
# The SIMD backend uses parallel formulas, using either AVX2 or AVX512-IFMA.
|
||||
simd_backend = ["nightly", "u64_backend", "packed_simd"]
|
||||
# Old name for the SIMD backend, preserved for compatibility
|
||||
# DEPRECATED: this is now an alias for `simd_backend` and may be removed
|
||||
# in some future release.
|
||||
avx2_backend = ["simd_backend"]
|
||||
|
||||
# Signals that we're in the main build stage. This is off by default,
|
||||
# to signal stage 1 of the build, where build.rs loads the library
|
||||
# into the build script. Then, the build.rs emits the stage2_build
|
||||
# feature before the main-stage compilation.
|
||||
stage2_build = []
|
||||
|
||||
|
|
|
|||
131
build.rs
131
build.rs
|
|
@ -1,131 +0,0 @@
|
|||
#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))]
|
||||
#![cfg_attr(feature = "nightly", feature(doc_cfg))]
|
||||
#![cfg_attr(feature = "simd_backend", feature(stdsimd))]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
extern crate alloc;
|
||||
extern crate byteorder;
|
||||
extern crate clear_on_drop;
|
||||
extern crate core;
|
||||
extern crate digest;
|
||||
extern crate rand_core;
|
||||
extern crate subtle;
|
||||
|
||||
#[cfg(all(feature = "nightly", feature = "packed_simd"))]
|
||||
extern crate packed_simd;
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
// Replicate lib.rs in the build.rs, since we're effectively building the whole crate twice.
|
||||
//
|
||||
// This should be fixed up by refactoring our code to seperate the "minimal" parts from the rest.
|
||||
//
|
||||
// For instance, this shouldn't exist here at all, but it does.
|
||||
#[cfg(feature = "serde")]
|
||||
extern crate serde;
|
||||
|
||||
// Macros come first!
|
||||
#[path = "src/macros.rs"]
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
// Public modules
|
||||
|
||||
#[path = "src/constants.rs"]
|
||||
mod constants;
|
||||
#[path = "src/edwards.rs"]
|
||||
mod edwards;
|
||||
#[path = "src/montgomery.rs"]
|
||||
mod montgomery;
|
||||
#[path = "src/ristretto.rs"]
|
||||
mod ristretto;
|
||||
#[path = "src/scalar.rs"]
|
||||
mod scalar;
|
||||
#[path = "src/traits.rs"]
|
||||
mod traits;
|
||||
|
||||
// Internal modules
|
||||
|
||||
#[path = "src/backend/mod.rs"]
|
||||
mod backend;
|
||||
#[path = "src/field.rs"]
|
||||
mod field;
|
||||
#[path = "src/prelude.rs"]
|
||||
mod prelude;
|
||||
#[path = "src/window.rs"]
|
||||
mod window;
|
||||
|
||||
use edwards::EdwardsBasepointTable;
|
||||
|
||||
fn main() {
|
||||
// Enable the "stage2_build" feature in the main build stage
|
||||
println!("cargo:rustc-cfg=feature=\"stage2_build\"\n");
|
||||
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let dest_path = Path::new(&out_dir).join("basepoint_table.rs");
|
||||
let mut f = File::create(&dest_path).unwrap();
|
||||
|
||||
// Generate a table of precomputed multiples of the basepoint
|
||||
let table = EdwardsBasepointTable::create(&constants::ED25519_BASEPOINT_POINT);
|
||||
|
||||
f.write_all(
|
||||
format!(
|
||||
"\n
|
||||
#[cfg(feature = \"u32_backend\")]
|
||||
use backend::serial::u32::field::FieldElement2625;
|
||||
|
||||
#[cfg(feature = \"u64_backend\")]
|
||||
use backend::serial::u64::field::FieldElement51;
|
||||
|
||||
use edwards::EdwardsBasepointTable;
|
||||
|
||||
use backend::serial::curve_models::AffineNielsPoint;
|
||||
|
||||
use window::LookupTable;
|
||||
|
||||
/// Table containing precomputed multiples of the Ed25519 basepoint \\\\(B = (x, 4/5)\\\\).
|
||||
pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN;
|
||||
|
||||
/// Inner constant, used to avoid filling the docs with precomputed points.
|
||||
#[doc(hidden)]
|
||||
pub const ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN: EdwardsBasepointTable = {:?};
|
||||
\n\n",
|
||||
&table
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Now generate AFFINE_ODD_MULTIPLES_OF_BASEPOINT
|
||||
// if we are going to build the serial scalar_mul backend
|
||||
#[cfg(not(all(
|
||||
feature = "simd_backend",
|
||||
any(target_feature = "avx2", target_feature = "avx512ifma")
|
||||
)))]
|
||||
{
|
||||
use backend::serial::curve_models::AffineNielsPoint;
|
||||
use window::NafLookupTable8;
|
||||
|
||||
let B = &constants::ED25519_BASEPOINT_POINT;
|
||||
let odd_multiples = NafLookupTable8::<AffineNielsPoint>::from(B);
|
||||
|
||||
f.write_all(
|
||||
format!(
|
||||
"\n
|
||||
use window::NafLookupTable8;
|
||||
/// Odd multiples of the basepoint `[B, 3B, 5B, 7B, 9B, 11B, 13B, 15B, ..., 127B]`.
|
||||
pub(crate) const AFFINE_ODD_MULTIPLES_OF_BASEPOINT: NafLookupTable8<AffineNielsPoint> = {:?};
|
||||
\n\n",
|
||||
&odd_multiples
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
pub mod variable_base;
|
||||
|
||||
#[cfg(feature = "stage2_build")]
|
||||
pub mod vartime_double_base;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -8,17 +8,8 @@
|
|||
// - Isis Agora Lovecruft <isis@patternsinthevoid.net>
|
||||
// - Henry de Valence <hdevalence@hdevalence.ca>
|
||||
|
||||
// Conditionally include the AVX2 notes if:
|
||||
// - we're on nightly (so we can include docs at all)
|
||||
// - we're in stage 2 of the build.
|
||||
// The latter point prevents a really silly and annoying problem,
|
||||
// where the location of ".." is different depending on whether we're
|
||||
// building the crate for real, or whether we're in build.rs
|
||||
// generating the lookup tables (in which case we're relative to the
|
||||
// location of build.rs, not lib.rs, so the markdown file appears
|
||||
// missing).
|
||||
#![cfg_attr(
|
||||
all(feature = "nightly", feature = "stage2_build"),
|
||||
feature = "nightly",
|
||||
doc(include = "../../../../docs/avx2-notes.md")
|
||||
)]
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
// - Henry de Valence <hdevalence@hdevalence.ca>
|
||||
|
||||
#![cfg_attr(
|
||||
all(feature = "nightly", feature = "stage2_build"),
|
||||
feature = "nightly",
|
||||
doc(include = "../../../../docs/ifma-notes.md")
|
||||
)]
|
||||
|
||||
|
|
|
|||
|
|
@ -8,17 +8,9 @@
|
|||
// - Isis Agora Lovecruft <isis@patternsinthevoid.net>
|
||||
// - Henry de Valence <hdevalence@hdevalence.ca>
|
||||
|
||||
// Conditionally include the notes if:
|
||||
// - we're on nightly (so we can include docs at all)
|
||||
// - we're in stage 2 of the build.
|
||||
// The latter point prevents a really silly and annoying problem,
|
||||
// where the location of ".." is different depending on whether we're
|
||||
// building the crate for real, or whether we're in build.rs
|
||||
// generating the lookup tables (in which case we're relative to the
|
||||
// location of build.rs, not lib.rs, so the markdown file appears
|
||||
// missing).
|
||||
// Conditionally include the notes if we're on nightly (so we can include docs at all).
|
||||
#![cfg_attr(
|
||||
all(feature = "nightly", feature = "stage2_build"),
|
||||
feature = "nightly",
|
||||
doc(include = "../../../docs/parallel-formulas.md")
|
||||
)]
|
||||
|
||||
|
|
|
|||
|
|
@ -83,16 +83,8 @@ pub const BASEPOINT_ORDER: Scalar = Scalar{
|
|||
],
|
||||
};
|
||||
|
||||
// Precomputed basepoint table is generated into a file by build.rs
|
||||
|
||||
#[cfg(feature = "stage2_build")]
|
||||
include!(concat!(env!("OUT_DIR"), "/basepoint_table.rs"));
|
||||
|
||||
#[cfg(feature = "stage2_build")]
|
||||
use ristretto::RistrettoBasepointTable;
|
||||
|
||||
/// The Ristretto basepoint, as a `RistrettoBasepointTable` for scalar multiplication.
|
||||
#[cfg(feature = "stage2_build")]
|
||||
pub const RISTRETTO_BASEPOINT_TABLE: RistrettoBasepointTable
|
||||
= RistrettoBasepointTable(ED25519_BASEPOINT_TABLE);
|
||||
|
||||
|
|
|
|||
|
|
@ -726,7 +726,6 @@ impl VartimePrecomputedMultiscalarMul for VartimeEdwardsPrecomputation {
|
|||
|
||||
impl EdwardsPoint {
|
||||
/// Compute \\(aA + bB\\) in variable time, where \\(B\\) is the Ed25519 basepoint.
|
||||
#[cfg(feature = "stage2_build")]
|
||||
pub fn vartime_double_scalar_mul_basepoint(
|
||||
a: &Scalar,
|
||||
A: &EdwardsPoint,
|
||||
|
|
@ -937,7 +936,7 @@ impl Debug for EdwardsBasepointTable {
|
|||
// Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
#[cfg(all(test, feature = "stage2_build"))]
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use field::FieldElement;
|
||||
use scalar::Scalar;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ extern crate byteorder;
|
|||
extern crate clear_on_drop;
|
||||
pub extern crate digest;
|
||||
extern crate rand_core;
|
||||
#[cfg(all(test, feature = "stage2_build"))]
|
||||
#[cfg(test)]
|
||||
extern crate rand_os;
|
||||
|
||||
// Used for traits related to constant-time code.
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ impl<'a, 'b> Mul<&'b MontgomeryPoint> for &'a Scalar {
|
|||
// Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
#[cfg(all(test, feature = "stage2_build"))]
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use constants;
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -955,7 +955,6 @@ impl VartimePrecomputedMultiscalarMul for VartimeRistrettoPrecomputation {
|
|||
impl RistrettoPoint {
|
||||
/// Compute \\(aA + bB\\) in variable time, where \\(B\\) is the
|
||||
/// Ristretto basepoint.
|
||||
#[cfg(feature = "stage2_build")]
|
||||
pub fn vartime_double_scalar_mul_basepoint(
|
||||
a: &Scalar,
|
||||
A: &RistrettoPoint,
|
||||
|
|
@ -1073,7 +1072,7 @@ impl Debug for RistrettoPoint {
|
|||
// Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
#[cfg(all(test, feature = "stage2_build"))]
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[cfg(feature = "rand")]
|
||||
use rand_os::OsRng;
|
||||
|
|
|
|||
Loading…
Reference in a new issue