Skip to content

Commit

Permalink
code review round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
incertia committed Feb 16, 2024
1 parent 0b497dc commit 8e74c6b
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 41 deletions.
2 changes: 0 additions & 2 deletions lms/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions lms/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ 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).

## 0.1.0 (2024-01-30)
- Initial release
225 changes: 225 additions & 0 deletions lms/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lms-signature"
version = "0.1.0"
version = "0.0.0"
edition = "2021"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/RustCrypto/signatures/tree/master/lms"
Expand Down
14 changes: 4 additions & 10 deletions lms/src/lms/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ use std::error::Error;
use std::fmt::{Display, Formatter, Result};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LmsSigningError {
OutOfPrivateKeys,
}
pub struct LmsOutOfPrivateKeys {}

impl Display for LmsSigningError {
impl Display for LmsOutOfPrivateKeys {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::OutOfPrivateKeys => {
write!(f, "private key has been exhausted")
}
}
write!(f, "private key has been exhausted")
}
}

impl Error for LmsSigningError {}
impl Error for LmsOutOfPrivateKeys {}
4 changes: 2 additions & 2 deletions lms/src/lms/private.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::constants::{D_INTR, D_LEAF, ID_LEN};
use crate::error::LmsDeserializeError;
use crate::lms::error::LmsSigningError;
use crate::lms::error::LmsOutOfPrivateKeys;
use crate::lms::{LmsMode, Signature, VerifyingKey};
use crate::ots::SigningKey as OtsPrivateKey;
use crate::types::{Identifier, Typecode};
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<Mode: LmsMode> RandomizedSignerMut<Signature<Mode>> for SigningKey<Mode> {
msg: &[u8],
) -> Result<Signature<Mode>, Error> {
if self.q >= Mode::LEAVES {
return Err(Error::from_source(LmsSigningError::OutOfPrivateKeys));
return Err(Error::from_source(LmsOutOfPrivateKeys {}));
}

let mut ots_priv_key =
Expand Down
4 changes: 2 additions & 2 deletions lms/src/lms/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<Mode: LmsMode> Verifier<Signature<Mode>> for VerifyingKey<Mode> {
}
}

/// Converts a [VerifyingKey] into its byte representation
/// Converts a [`VerifyingKey`] into its byte representation
impl<Mode: LmsMode> From<VerifyingKey<Mode>>
for GenericArray<u8, Sum<<Mode::Hasher as OutputSizeUser>::OutputSize, U24>>
where
Expand All @@ -117,7 +117,7 @@ where
}
}

/// Tries to parse a [VerifyingKey] from an exact slice
/// Tries to parse a [`VerifyingKey`] from an exact slice
impl<'a, Mode: LmsMode> TryFrom<&'a [u8]> for VerifyingKey<Mode> {
type Error = LmsDeserializeError;

Expand Down
4 changes: 2 additions & 2 deletions lms/src/lms/signature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Contains the [Signature] type
//! Contains the [`Signature`] type
use crate::error::LmsDeserializeError;
use crate::lms::LmsMode;
Expand Down Expand Up @@ -77,7 +77,7 @@ where
}
}

/// Tries to parse a [Signature] from an exact slice
/// Tries to parse a [`Signature`] from an exact slice
impl<Mode: LmsMode> TryFrom<&[u8]> for Signature<Mode> {
type Error = LmsDeserializeError;

Expand Down
14 changes: 4 additions & 10 deletions lms/src/ots/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ use std::error::Error;
use std::fmt::{Display, Formatter, Result};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LmsOtsSigningError {
InvalidPrivateKey,
}
pub struct LmsOtsInvalidPrivateKey {}

impl Display for LmsOtsSigningError {
impl Display for LmsOtsInvalidPrivateKey {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
Self::InvalidPrivateKey => {
write!(f, "private key is no longer valid")
}
}
write!(f, "private key is no longer valid")
}
}

impl Error for LmsOtsSigningError {}
impl Error for LmsOtsInvalidPrivateKey {}
4 changes: 2 additions & 2 deletions lms/src/ots/private.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::constants::{D_MESG, D_PBLC};
use crate::ots::error::LmsOtsSigningError;
use crate::ots::error::LmsOtsInvalidPrivateKey;
use crate::ots::modes::LmsOtsMode;
use crate::ots::public::VerifyingKey;
use crate::ots::signature::Signature;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<Mode: LmsOtsMode> RandomizedSignerMut<Signature<Mode>> for SigningKey<Mode>
msg: &[u8],
) -> Result<Signature<Mode>, Error> {
if !self.valid {
return Err(Error::from_source(LmsOtsSigningError::InvalidPrivateKey));
return Err(Error::from_source(LmsOtsInvalidPrivateKey {}));
}

// Generate the message randomizer C
Expand Down
6 changes: 3 additions & 3 deletions lms/src/ots/public.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Contains the [VerifyingKey] type
//! Contains the [`VerifyingKey`] type
use crate::constants::ID_LEN;
use crate::error::LmsDeserializeError;
Expand Down Expand Up @@ -60,7 +60,7 @@ where
}
}

/// Converts a [VerifyingKey] into its byte representation
/// Converts a [`VerifyingKey`] into its byte representation
impl<Mode: LmsOtsMode> From<VerifyingKey<Mode>>
for GenericArray<u8, Sum<<Mode::Hasher as OutputSizeUser>::OutputSize, U24>>
where
Expand All @@ -80,7 +80,7 @@ where
}
}

/// Tries to parse a [VerifyingKey] from an exact slice
/// Tries to parse a [`VerifyingKey`] from an exact slice
impl<'a, Mode: LmsOtsMode> TryFrom<&'a [u8]> for VerifyingKey<Mode> {
type Error = LmsDeserializeError;

Expand Down
Loading

0 comments on commit 8e74c6b

Please sign in to comment.