add `no_std` support (#57)
This commit is contained in:
parent
7b8447ad79
commit
15e028616c
12
Cargo.toml
12
Cargo.toml
|
@ -8,18 +8,19 @@ license = "MIT OR Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
repository = "https://github.com/ZcashFoundation/ed25519-zebra"
|
repository = "https://github.com/ZcashFoundation/ed25519-zebra"
|
||||||
description = "Zcash-flavored Ed25519 for use in Zebra."
|
description = "Zcash-flavored Ed25519 for use in Zebra."
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["nightly"]
|
features = ["nightly"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hex = "0.4"
|
hex = { version = "0.4", default-features = false, features = ["alloc"] }
|
||||||
sha2 = "0.9"
|
sha2 = { version = "0.9", default-features = false }
|
||||||
rand_core = "0.6"
|
rand_core = "0.6"
|
||||||
thiserror = "1"
|
curve25519-dalek = { version = "3", default-features = false, features = ["alloc", "u64_backend"] }
|
||||||
curve25519-dalek = "3"
|
|
||||||
serde = { version = "1", optional = true, features = ["derive"] }
|
serde = { version = "1", optional = true, features = ["derive"] }
|
||||||
zeroize = "1.2"
|
zeroize = "1.2"
|
||||||
|
hashbrown = "0.12.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
@ -31,7 +32,8 @@ once_cell = "1.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
nightly = []
|
nightly = []
|
||||||
default = ["serde"]
|
default = ["serde", "std"]
|
||||||
|
std = []
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "rfc8032"
|
name = "rfc8032"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||||
|
|
||||||
|
use core::convert::TryFrom;
|
||||||
use ed25519_zebra::*;
|
use ed25519_zebra::*;
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
fn sigs_with_distinct_pubkeys() -> impl Iterator<Item = (VerificationKeyBytes, Signature)> {
|
fn sigs_with_distinct_pubkeys() -> impl Iterator<Item = (VerificationKeyBytes, Signature)> {
|
||||||
std::iter::repeat_with(|| {
|
std::iter::repeat_with(|| {
|
||||||
|
|
|
@ -48,13 +48,15 @@
|
||||||
//!
|
//!
|
||||||
//! [ZIP215]: https://github.com/zcash/zips/blob/master/zip-0215.rst
|
//! [ZIP215]: https://github.com/zcash/zips/blob/master/zip-0215.rst
|
||||||
|
|
||||||
use std::{collections::HashMap, convert::TryFrom};
|
use alloc::vec::Vec;
|
||||||
|
use core::convert::TryFrom;
|
||||||
|
|
||||||
use curve25519_dalek::{
|
use curve25519_dalek::{
|
||||||
edwards::{CompressedEdwardsY, EdwardsPoint},
|
edwards::{CompressedEdwardsY, EdwardsPoint},
|
||||||
scalar::Scalar,
|
scalar::Scalar,
|
||||||
traits::{IsIdentity, VartimeMultiscalarMul},
|
traits::{IsIdentity, VartimeMultiscalarMul},
|
||||||
};
|
};
|
||||||
|
use hashbrown::HashMap;
|
||||||
use rand_core::{CryptoRng, RngCore};
|
use rand_core::{CryptoRng, RngCore};
|
||||||
use sha2::{Digest, Sha512};
|
use sha2::{Digest, Sha512};
|
||||||
|
|
||||||
|
@ -202,8 +204,8 @@ impl Verifier {
|
||||||
A_coeffs.push(A_coeff);
|
A_coeffs.push(A_coeff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use core::iter::once;
|
||||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT as B;
|
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT as B;
|
||||||
use std::iter::once;
|
|
||||||
let check = EdwardsPoint::vartime_multiscalar_mul(
|
let check = EdwardsPoint::vartime_multiscalar_mul(
|
||||||
once(&B_coeff).chain(A_coeffs.iter()).chain(R_coeffs.iter()),
|
once(&B_coeff).chain(A_coeffs.iter()).chain(R_coeffs.iter()),
|
||||||
once(&B).chain(As.iter()).chain(Rs.iter()),
|
once(&B).chain(As.iter()).chain(Rs.iter()),
|
||||||
|
|
24
src/error.rs
24
src/error.rs
|
@ -1,18 +1,30 @@
|
||||||
use thiserror::Error;
|
use core::fmt;
|
||||||
|
|
||||||
/// An error related to Ed25519 signatures.
|
/// An error related to Ed25519 signatures.
|
||||||
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// The encoding of a secret key was malformed.
|
/// The encoding of a secret key was malformed.
|
||||||
#[error("Malformed secret key encoding.")]
|
|
||||||
MalformedSecretKey,
|
MalformedSecretKey,
|
||||||
/// The encoding of a public key was malformed.
|
/// The encoding of a public key was malformed.
|
||||||
#[error("Malformed public key encoding.")]
|
|
||||||
MalformedPublicKey,
|
MalformedPublicKey,
|
||||||
/// Signature verification failed.
|
/// Signature verification failed.
|
||||||
#[error("Invalid signature.")]
|
|
||||||
InvalidSignature,
|
InvalidSignature,
|
||||||
/// A byte slice of the wrong length was supplied during parsing.
|
/// A byte slice of the wrong length was supplied during parsing.
|
||||||
#[error("Invalid length when parsing byte slice.")]
|
|
||||||
InvalidSliceLength,
|
InvalidSliceLength,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let msg = match self {
|
||||||
|
Self::MalformedSecretKey => "Malformed secret key encoding.",
|
||||||
|
Self::MalformedPublicKey => "Malformed public key encoding.",
|
||||||
|
Self::InvalidSignature => "Invalid signature.",
|
||||||
|
Self::InvalidSliceLength => "Invalid length when parsing byte slice.",
|
||||||
|
};
|
||||||
|
|
||||||
|
msg.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl std::error::Error for Error {}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
//! Docs require the `nightly` feature until RFC 1990 lands.
|
//! Docs require the `nightly` feature until RFC 1990 lands.
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
extern crate std;
|
||||||
|
|
||||||
pub mod batch;
|
pub mod batch;
|
||||||
mod error;
|
mod error;
|
||||||
mod signature;
|
mod signature;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use std::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
|
|
||||||
/// An Ed25519 signature.
|
/// An Ed25519 signature.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
|
|
||||||
use curve25519_dalek::{constants, scalar::Scalar};
|
use curve25519_dalek::{constants, scalar::Scalar};
|
||||||
use rand_core::{CryptoRng, RngCore};
|
use rand_core::{CryptoRng, RngCore};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::convert::{TryFrom, TryInto};
|
use core::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
use curve25519_dalek::{
|
use curve25519_dalek::{
|
||||||
edwards::{CompressedEdwardsY, EdwardsPoint},
|
edwards::{CompressedEdwardsY, EdwardsPoint},
|
||||||
|
@ -19,7 +19,7 @@ use crate::{Error, Signature};
|
||||||
/// A `VerificationKeyBytes` can be used to verify a single signature using the
|
/// A `VerificationKeyBytes` can be used to verify a single signature using the
|
||||||
/// following idiom:
|
/// following idiom:
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::convert::TryFrom;
|
/// use core::convert::TryFrom;
|
||||||
/// # use rand::thread_rng;
|
/// # use rand::thread_rng;
|
||||||
/// # use ed25519_zebra::*;
|
/// # use ed25519_zebra::*;
|
||||||
/// # let msg = b"Zcash";
|
/// # let msg = b"Zcash";
|
||||||
|
|
|
@ -87,8 +87,8 @@ fn conformance() -> Result<(), Report> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn individual_matches_batch_verification() -> Result<(), Report> {
|
fn individual_matches_batch_verification() -> Result<(), Report> {
|
||||||
|
use core::convert::TryFrom;
|
||||||
use ed25519_zebra::{batch, Signature, VerificationKey, VerificationKeyBytes};
|
use ed25519_zebra::{batch, Signature, VerificationKey, VerificationKeyBytes};
|
||||||
use std::convert::TryFrom;
|
|
||||||
for case in SMALL_ORDER_SIGS.iter() {
|
for case in SMALL_ORDER_SIGS.iter() {
|
||||||
let msg = b"Zcash";
|
let msg = b"Zcash";
|
||||||
let sig = Signature::from(case.sig_bytes);
|
let sig = Signature::from(case.sig_bytes);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
|
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use color_eyre::{eyre::eyre, Report};
|
||||||
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
|
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
|
||||||
use ed25519_zebra as ed25519_zebra_zip215;
|
use ed25519_zebra as ed25519_zebra_zip215;
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
pub struct TestCase {
|
pub struct TestCase {
|
||||||
pub vk_bytes: [u8; 32],
|
pub vk_bytes: [u8; 32],
|
||||||
pub sig_bytes: [u8; 64],
|
pub sig_bytes: [u8; 64],
|
||||||
|
|
Loading…
Reference in New Issue