signature-crate: move to RustCrypto/traits

Moved as of c82b51e (most recent commit in `signature-crate`)

New location:

https://github.com/RustCrypto/traits/tree/master/signature
This commit is contained in:
Tony Arcieri
2020-03-07 19:28:31 -08:00
parent ba861b962f
commit aaac055829
17 changed files with 5 additions and 609 deletions
-2
View File
@@ -14,8 +14,6 @@ env:
script:
- cargo test --verbose --release
- cargo test --verbose --all-features --release
# Can't use `--no-default-features` with a workspace. See rust-lang/cargo#4753
- cd signature-crate && cargo build --no-default-features --release
matrix:
fast_finish: true
+1 -6
View File
@@ -1,7 +1,2 @@
[workspace]
members = [
"ecdsa",
"ed25519",
"signature-crate",
"signature-crate/signature_derive"
]
members = ["ecdsa", "ed25519"]
+1 -1
View File
@@ -9,7 +9,7 @@ DIRS=`ls -d */`
TARGET="thumbv7em-none-eabi"
for dir in $DIRS; do
if [ $dir = "target/" ]
if [ $dir = "target/" -o $dir = "signature-crate/" ]
then
continue
fi
-1
View File
@@ -45,7 +45,6 @@ default-features = false
[dependencies.signature]
version = "1.0.0-pre.1"
path = "../signature-crate"
default-features = false
[features]
-1
View File
@@ -13,7 +13,6 @@ keywords = ["crypto", "curve25519", "ecc", "signature", "signing"]
[dependencies.signature]
version = "1.0.0-pre.1"
path = "../signature-crate"
default-features = false
[dependencies.serde]
-47
View File
@@ -1,47 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.0.0-pre.1 (2019-10-27)
### Changed
- Use `Error::source` instead of `::cause` ([#37])
### Removed
- Remove `alloc` feature; MSRV 1.34+ ([#38])
[#38]: https://github.com/RustCrypto/signatures/pull/38
[#37]: https://github.com/RustCrypto/signatures/pull/37
## 1.0.0-pre.0 (2019-10-11)
### Changed
- Revert removal of `DigestSignature` ([#33])
- 1.0 stabilization proposal ([#32])
[#33]: https://github.com/RustCrypto/signatures/pull/33
[#32]: https://github.com/RustCrypto/signatures/pull/32
## 0.3.0 (2019-10-10)
### Changed
- Simplify alloc gating; MSRV 1.36+ ([#28])
- Replace `DigestSignature` trait with `#[digest(...)]` attribute ([#27])
- signature_derive: Upgrade to 1.x proc macro crates ([#26])
[#28]: https://github.com/RustCrypto/signatures/pull/28
[#27]: https://github.com/RustCrypto/signatures/pull/27
[#26]: https://github.com/RustCrypto/signatures/pull/27
## 0.2.0 (2019-06-06)
### Added
- `signature_derive`: Custom derive support for `Signer`/`Verifier` ([#18])
### Changed
- Have `DigestSigner`/`DigestVerifier` take `Digest` instance ([#17])
[#18]: https://github.com/RustCrypto/signatures/pull/18
[#17]: https://github.com/RustCrypto/signatures/pull/17
## 0.1.0 (2019-05-25)
- Initial release
-35
View File
@@ -1,35 +0,0 @@
[package]
name = "signature"
description = "Traits for cryptographic signature algorithms (e.g. ECDSA, Ed25519)"
version = "1.0.0-pre.1" # Also update html_root_url in lib.rs when bumping this
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/signature"
repository = "https://github.com/RustCrypto/signatures/tree/master/signature-crate"
readme = "README.md"
edition = "2018"
keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"]
categories = ["cryptography", "no-std"]
[dependencies.digest]
version = "0.8"
optional = true
default-features = false
[dependencies.signature_derive]
version = "1.0.0-pre.0"
optional = true
path = "signature_derive"
[dev-dependencies]
hex-literal = "0.2"
sha2 = { version = "0.8", default-features = false }
[features]
default = ["std"]
derive-preview = ["digest-preview", "signature_derive"]
digest-preview = ["digest"]
std = []
[package.metadata.docs.rs]
all-features = true
+3 -62
View File
@@ -1,64 +1,5 @@
# `signature` crate
# MOVED
[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![Apache2/MIT licensed][license-image]
![Rust Version][rustc-image]
[![Build Status][build-image]][build-link]
The `signature` crate has moved to:
This crate contains traits which provide generic, object-safe APIs for
generating and verifying [digital signatures][1].
It's presently useful in conjunction with the [`ed25519`][2] crate.
Support is also planned for the [`ecdsa`][3] and [`rsa`][4] crates.
[Documentation][docs-link]
## Minimum Supported Rust Version
All crates in this repository support Rust **1.37** or higher.
Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.
## SemVer Policy
- All on-by-default features of this library are covered by SemVer
- MSRV is considered exempt from SemVer as noted above
- The off-by-default features `derive-preview` and `digest-preview` are
unstable "preview" features which are also considered exempt from SemVer.
Breaking changes to these features will, like MSRV, be done with a minor
version bump.
## License
All crates licensed under either of
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
[//]: # (badges)
[crate-image]: https://img.shields.io/crates/v/signature.svg
[crate-link]: https://crates.io/crates/signature
[docs-image]: https://docs.rs/signature/badge.svg
[docs-link]: https://docs.rs/signature/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.34+-blue.svg
[build-image]: https://travis-ci.org/RustCrypto/signatures.svg?branch=master
[build-link]: https://travis-ci.org/RustCrypto/signatures
[//]: # (general links)
[1]: https://en.wikipedia.org/wiki/Digital_signature
[2]: https://github.com/RustCrypto/signatures/tree/master/ed25519
[3]: https://github.com/RustCrypto/signatures/tree/master/ecdsa
[4]: https://github.com/RustCrypto/RSA
https://github.com/RustCrypto/traits/tree/master/signature
@@ -1,21 +0,0 @@
[package]
name = "signature_derive"
version = "1.0.0-pre.0"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
description = "Custom derive support for the 'signature' crate"
documentation = "https://docs.rs/signature"
repository = "https://github.com/RustCrypto/signatures/tree/master/signature-crate/"
readme = "README.md"
edition = "2018"
keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"]
categories = ["cryptography", "no-std"]
[lib]
proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = "1"
synstructure = "0.12"
@@ -1,27 +0,0 @@
# `signature` crate custom derive support
[![Build Status](https://travis-ci.org/RustCrypto/signatures.svg?branch=master)](https://travis-ci.org/RustCrypto/signatures)
This crate provides proc macros used by the `signature` crate.
It's not intended to be used directly. See the signature crate's documentation
for additional details:
[Documentation][docs]
## License
All crates licensed under either of
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
[Documentation]: https://docs.rs/signature/
-107
View File
@@ -1,107 +0,0 @@
//! Custom derive support for the `signature` crate.
//!
//! This crate can be used to derive `Signer` and `Verifier` impls for
//! types that impl `DigestSigner` or `DigestVerifier` respectively.
#![crate_type = "proc-macro"]
#![recursion_limit = "128"]
#![deny(warnings, unused_import_braces, unused_qualifications)]
#![forbid(unsafe_code)]
extern crate proc_macro;
use proc_macro2::TokenStream;
use quote::quote;
use synstructure::{decl_derive, AddBounds};
/// Derive the `Signer` trait for `DigestSigner` types
fn derive_signer(mut s: synstructure::Structure) -> TokenStream {
s.add_bounds(AddBounds::None);
s.gen_impl(quote! {
gen impl<S> signature::Signer<S> for @Self
where
S: signature::DigestSignature,
Self: signature::DigestSigner<S::Digest, S>
{
fn try_sign(&self, msg: &[u8]) -> Result<S, signature::Error> {
self.try_sign_digest(S::Digest::new().chain(msg))
}
}
})
}
decl_derive!([Signer] => derive_signer);
/// Derive the `Verifier` trait for `DigestVerifier` types
fn derive_verifier(mut s: synstructure::Structure) -> TokenStream {
s.add_bounds(AddBounds::None);
s.gen_impl(quote! {
gen impl<S> signature::Verifier<S> for @Self
where
S: signature::DigestSignature,
Self: signature::DigestVerifier<S::Digest, S>
{
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), signature::Error> {
self.verify_digest(S::Digest::new().chain(msg), signature)
}
}
})
}
decl_derive!([Verifier] => derive_verifier);
#[cfg(test)]
mod tests {
use super::*;
use synstructure::test_derive;
#[test]
fn signer() {
test_derive! {
derive_signer {
struct MySigner<C: EllipticCurve> {
scalar: Scalar<C::ScalarSize>
}
}
expands to {
#[allow(non_upper_case_globals)]
const _DERIVE_signature_Signer_S_FOR_MySigner: () = {
impl<S, C: EllipticCurve> signature::Signer<S> for MySigner<C>
where
S: signature::DigestSignature,
Self: signature::DigestSigner<S::Digest, S>
{
fn try_sign(&self, msg: &[u8]) -> Result <S, signature::Error> {
self.try_sign_digest(S::Digest::new().chain(msg))
}
}
};
}
no_build // tests in `signature-crate/tests`
}
}
#[test]
fn verifier() {
test_derive! {
derive_verifier {
struct MyVerifier<C: EllipticCurve> {
point: UncompressedPoint<C>
}
}
expands to {
#[allow(non_upper_case_globals)]
const _DERIVE_signature_Verifier_S_FOR_MyVerifier: () = {
impl<S, C: EllipticCurve> signature::Verifier<S> for MyVerifier<C>
where
S: signature::DigestSignature,
Self: signature::DigestVerifier<S::Digest, S>
{
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), signature::Error> {
self.verify_digest(S::Digest::new().chain(msg), signature)
}
}
};
}
no_build // tests in `signature-crate/tests`
}
}
}
-63
View File
@@ -1,63 +0,0 @@
//! Signature error types
use core::fmt::{self, Display};
#[cfg(feature = "std")]
use std::boxed::Box;
/// Box containing a thread-safe + `'static` error suitable for use as a
/// as an `std::error::Error::source`
#[cfg(feature = "std")]
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
/// Signature errors
#[derive(Debug, Default)]
pub struct Error {
/// Source of the error (if applicable).
#[cfg(feature = "std")]
source: Option<BoxError>,
}
impl Error {
/// Create a new error with no associated source
pub fn new() -> Self {
Self::default()
}
/// Create a new error with an associated source.
///
/// **NOTE:** The "source" should NOT be used to propagate cryptographic
/// errors e.g. signature parsing or verification errors. The intended use
/// cases are for propagating errors related to external signers, e.g.
/// communication/authentication errors with HSMs, KMS, etc.
#[cfg(feature = "std")]
pub fn from_source(source: impl Into<BoxError>) -> Self {
Self {
source: Some(source.into()),
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "signature error")?;
#[cfg(feature = "std")]
{
if let Some(ref source) = self.source {
write!(f, ": {}", source)?;
}
}
Ok(())
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.source
.as_ref()
.map(|source| source.as_ref() as &(dyn std::error::Error + 'static))
}
}
-50
View File
@@ -1,50 +0,0 @@
//! Traits which provide generic, object-safe APIs for generating and verifying
//! digital signatures, which provide message authentication using public-key
//! cryptography.
//!
//! ## Minimum Supported Rust Version
//!
//! Rust **1.34** or higher.
//!
//! Minimum supported Rust version can be changed in the future, but it will be
//! done with a minor version bump.
//!
//! ## SemVer Policy
//!
//! - All on-by-default features of this library are covered by SemVer
//! - MSRV is considered exempt from SemVer as noted above
//! - The off-by-default features `derive-preview` and `digest-preview` are
//! unstable "preview" features which are also considered exempt from SemVer.
//! Breaking changes to these features will, like MSRV, be done with a minor
//! version bump.
#![no_std]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png",
html_root_url = "https://docs.rs/signature/1.0.0-pre.1"
)]
#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[cfg(feature = "derive-preview")]
#[allow(unused_imports)]
#[macro_use]
extern crate signature_derive;
#[cfg(feature = "derive-preview")]
#[doc(hidden)]
pub use signature_derive::{Signer, Verifier};
#[cfg(feature = "digest-preview")]
pub use digest;
mod error;
mod signature;
mod signer;
mod verifier;
pub use crate::{error::*, signature::*, signer::*, verifier::*};
-31
View File
@@ -1,31 +0,0 @@
//! Signature traits
use crate::error::Error;
use core::fmt::Debug;
/// Trait impl'd by concrete types that represent digital signatures
pub trait Signature: AsRef<[u8]> + Debug + Sized {
/// Parse a signature from its byte representation
fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, Error>;
/// Borrow this signature as serialized bytes
fn as_slice(&self) -> &[u8] {
self.as_ref()
}
}
/// Marker trait for `Signature` types computable as `S(H(m))`
///
/// - `S`: signature algorithm
/// - `H`: hash (a.k.a. digest) function
/// - `m`: message
///
/// For signature types that implement this trait, when the `derive-preview`
/// Cargo feature is enabled a custom derive for `Signer` is available for any
/// types that impl `DigestSigner`, and likewise for deriving `Verifier` for
/// types which impl `DigestVerifier`.
#[cfg(feature = "digest")]
pub trait DigestSignature: Signature {
/// Preferred `Digest` algorithm to use when computing this signature type.
type Digest: digest::Digest;
}
-44
View File
@@ -1,44 +0,0 @@
//! Traits for generating digital signatures
#[cfg(feature = "digest-preview")]
use crate::digest::Digest;
use crate::{error::Error, Signature};
/// Sign the provided message bytestring using `Self` (e.g. a cryptographic key
/// or connection to an HSM), returning a digital signature.
pub trait Signer<S: Signature> {
/// Sign the given message and return a digital signature
fn sign(&self, msg: &[u8]) -> S {
self.try_sign(msg).expect("signature operation failed")
}
/// Attempt to sign the given message, returning a digital signature on
/// success, or an error if something went wrong.
///
/// The main intended use case for signing errors is when communicating
/// with external signers, e.g. cloud KMS, HSMs, or other hardware tokens.
fn try_sign(&self, msg: &[u8]) -> Result<S, Error>;
}
/// Sign the given prehashed message `Digest` using `Self`.
///
/// This trait is only available when the `digest-preview` cargo feature is
/// enabled.
#[cfg(feature = "digest-preview")]
pub trait DigestSigner<D, S>
where
D: Digest,
S: Signature,
{
/// Sign the given prehashed message `Digest`, returning a signature.
///
/// Panics in the event of a signing error.
fn sign_digest(&self, digest: D) -> S {
self.try_sign_digest(digest)
.expect("signature operation failed")
}
/// Attempt to sign the given prehashed message `Digest`, returning a
/// digital signature on success, or an error if something went wrong.
fn try_sign_digest(&self, digest: D) -> Result<S, Error>;
}
-35
View File
@@ -1,35 +0,0 @@
//! Trait for verifying digital signatures
#[cfg(feature = "digest-preview")]
use crate::digest::Digest;
use crate::{error::Error, Signature};
/// Verify the provided message bytestring using `Self` (e.g. a public key)
pub trait Verifier<S: Signature> {
/// Use `Self` to verify that the provided signature for a given message
/// bytestring is authentic.
///
/// Returns `Error` if it is inauthentic, or otherwise returns `()`.
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>;
}
/// Verify the provided signature for the given prehashed message `Digest`
/// is authentic.
///
/// This trait is only available when the `digest-preview` cargo feature is
/// enabled.
///
/// It accepts a [`Digest`] instance, as opposed to a raw digest byte array,
/// as the security of signature algorithms built on hash functions often
/// depends critically on the input being a random oracle as opposed to a
/// value an attacker can choose and solve for. This is enforced at the API
/// level by taking a [`Digest`] instance in order to better resist misuse.
#[cfg(feature = "digest-preview")]
pub trait DigestVerifier<D, S>
where
D: Digest,
S: Signature,
{
/// Verify the signature against the given `Digest` output.
fn verify_digest(&self, digest: D, signature: &S) -> Result<(), Error>;
}
-76
View File
@@ -1,76 +0,0 @@
/// "Tests" for code generated by `signature_derive`
#[cfg(all(test, feature = "derive-preview"))]
mod tests {
use digest::{generic_array::GenericArray, Digest};
use hex_literal::hex;
use sha2::Sha256;
use signature::{
DigestSignature, DigestSigner, DigestVerifier, Error, Signature, Signer, Verifier,
};
/// Test vector to compute SHA-256 digest of
const INPUT_STRING: &[u8] = b"abc";
/// Expected SHA-256 digest for the input string
const INPUT_STRING_DIGEST: [u8; 32] =
hex!("ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad");
/// Dummy signature which just contains a digest output
#[derive(Debug)]
struct DummySignature(GenericArray<u8, <Sha256 as Digest>::OutputSize>);
impl Signature for DummySignature {
fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, Error> {
Ok(DummySignature(GenericArray::clone_from_slice(
bytes.as_ref(),
)))
}
}
impl AsRef<[u8]> for DummySignature {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl DigestSignature for DummySignature {
type Digest = Sha256;
}
/// Dummy signer which just returns the message digest as a `DummySignature`
#[derive(Signer, Default)]
struct DummySigner {}
impl DigestSigner<Sha256, DummySignature> for DummySigner {
fn try_sign_digest(&self, digest: Sha256) -> Result<DummySignature, Error> {
DummySignature::from_bytes(digest.result())
}
}
/// Dummy verifier which ensures the `DummySignature` digest matches the
/// expected value.
///
/// Panics (via `assert_eq!`) if the value is not what is expected.
#[derive(Verifier, Default)]
struct DummyVerifier {}
impl DigestVerifier<Sha256, DummySignature> for DummyVerifier {
fn verify_digest(&self, digest: Sha256, signature: &DummySignature) -> Result<(), Error> {
let actual_digest = digest.result();
assert_eq!(signature.as_ref(), actual_digest.as_ref());
Ok(())
}
}
#[test]
fn derived_signer_impl() {
let sig: DummySignature = DummySigner::default().sign(INPUT_STRING);
assert_eq!(sig.as_ref(), INPUT_STRING_DIGEST.as_ref())
}
#[test]
fn derived_verifier_impl() {
let sig: DummySignature = DummySigner::default().sign(INPUT_STRING);
assert!(DummyVerifier::default().verify(INPUT_STRING, &sig).is_ok());
}
}