Skip to content

Commit

Permalink
Support no_std for ed25519-consensus.
Browse files Browse the repository at this point in the history
This moves the `std::error::Error` impl for `Error` and the `batch` module behind the `std` feature flag.
  • Loading branch information
hdevalence committed Oct 30, 2021
1 parent 8c0007e commit f42273e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 55 deletions.
22 changes: 0 additions & 22 deletions .github/dependabot.yml

This file was deleted.

73 changes: 58 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
name: CI
on: [push, pull_request]

on: [push]
name: Continuous integration

jobs:
test_nightly:
name: test on nightly
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
# Because we use nightly features for building docs,
# using --all-features will fail without nightly toolchain.
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

nostd:
name: Build on no_std
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: thumbv7em-none-eabihf
override: true
- uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features --target thumbv7em-none-eabihf
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ license = "MIT OR Apache-2.0"
edition = "2018"
repository = "https://github.com/penumbra-zone/ed25519-consensus"
description = "Ed25519 suitable for use in consensus-critical contexts."
resolver = "2"

[dependencies]
hex = "0.4"
sha2 = "0.9"
rand_core = "0.6"
thiserror = "1"
curve25519-dalek = { package = "curve25519-dalek-ng", version = "4.1" }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
sha2 = { version = "0.9", default-features = false }
rand_core = { version = "0.6", default-features = false }
curve25519-dalek = { package = "curve25519-dalek-ng", version = "4.1", default-features = false, features = ["u64_backend", "alloc"] }
serde = { version = "1", optional = true, features = ["derive"] }
zeroize = "1.1"
zeroize = { version = "1.1", default-features = false }
thiserror = { version = "1", optional = true }

[dev-dependencies]
rand = "0.8"
Expand All @@ -28,8 +29,8 @@ color-eyre = "0.5"
once_cell = "1.4"

[features]
nightly = []
default = ["serde"]
std = ["thiserror"]
default = ["serde", "std"]

[[test]]
name = "rfc8032"
Expand Down
2 changes: 1 addition & 1 deletion src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl Verifier {
A_coeffs.push(A_coeff);
}

use core::iter::once;
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT as B;
use std::iter::once;
let check = EdwardsPoint::vartime_multiscalar_mul(
once(&B_coeff).chain(A_coeffs.iter()).chain(R_coeffs.iter()),
once(&B).chain(As.iter()).chain(Rs.iter()),
Expand Down
12 changes: 7 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#[cfg(feature = "std")]
use thiserror::Error;

/// An error related to Ed25519 signatures.
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum Error {
/// The encoding of a secret key was malformed.
#[error("Malformed secret key encoding.")]
#[cfg_attr(feature = "std", error("Malformed secret key encoding."))]
MalformedSecretKey,
/// The encoding of a public key was malformed.
#[error("Malformed public key encoding.")]
#[cfg_attr(feature = "std", error("Malformed public key encoding."))]
MalformedPublicKey,
/// Signature verification failed.
#[error("Invalid signature.")]
#[cfg_attr(feature = "std", error("Invalid signature."))]
InvalidSignature,
/// A byte slice of the wrong length was supplied during parsing.
#[error("Invalid length when parsing byte slice.")]
#[cfg_attr(feature = "std", error("Invalid length when parsing byte slice."))]
InvalidSliceLength,
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![doc(html_root_url = "https://docs.rs/ed25519-consensus/1.0.0")]
#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
pub mod batch;
mod error;
mod signature;
Expand Down
2 changes: 1 addition & 1 deletion src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Error;
use std::convert::TryFrom;
use core::convert::TryFrom;

/// An Ed25519 signature.
#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/signing_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::TryFrom;
use core::convert::TryFrom;

use curve25519_dalek::{constants, scalar::Scalar};
use rand_core::{CryptoRng, RngCore};
Expand Down
4 changes: 2 additions & 2 deletions src/verification_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::{TryFrom, TryInto};
use core::convert::{TryFrom, TryInto};

use curve25519_dalek::{
edwards::{CompressedEdwardsY, EdwardsPoint},
Expand All @@ -19,7 +19,7 @@ use crate::{Error, Signature};
/// A `VerificationKeyBytes` can be used to verify a single signature using the
/// following idiom:
/// ```
/// use std::convert::TryFrom;
/// use core::convert::TryFrom;
/// # use rand::thread_rng;
/// # use ed25519_consensus::*;
/// # let msg = b"ed25519-consensus";
Expand Down

0 comments on commit f42273e

Please sign in to comment.