RustCrypto / RustCrypto/signatures

LMS breaking with HLen at or over 15 on 0.1.0-rc.2

Open
#1,438 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
661
Forks
196
Avg merge
1h 45m
Merged PRs (30d)
1

Description

LMS on 0.1.0-rc.2 breaks at compile-time when the bigger types (HLen >= 15) are being used.
Apparently, it breaks because hybrid-array does not support sizes used by the type TreeLen in modes.rs.
Adding this type (U65535) into hybrid-array does let it compile, but it seems to cause a Stack Overflow at runtime when compiled in dev mode.
I added the size for HLen = 15 to a local copy of hybrid-array by adding the below to sizes.rs.

diff --git a/src/sizes.rs b/src/sizes.rs
index 43cb00e..c07c1a1 100644
--- a/src/sizes.rs
+++ b/src/sizes.rs
@@ -864,6 +864,7 @@ mod extra_sizes {
     pub type U2180 = uint!(0 0 1 0 0 0 0 1 0 0 0 1);
     pub type U4292 = uint!(0 0 1 0 0 0 1 1 0 0 0 0 1);
     pub type U8516 = uint!(0 0 1 0 0 0 1 0 1 0 0 0 0 1);
+    pub type U65535 = uint!(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1);
 
     // FrodoKEM640 sizes
 
@@ -1154,6 +1155,7 @@ mod extra_sizes {
         2180 => U2180,
         4292 => U4292,
         8516 => U8516,
+        65535 => U65535,
     }
 
     // Frodo sizes

My minimal example:

use lms_signature::lms::{LmsSha256M32H15, SigningKey};
use lms_signature::ots::LmsOtsSha256N32W2;
use getrandom::{SysRng, rand_core::UnwrapErr};
use signature::{RandomizedSignerMut, Verifier};
fn main() {
    let mut rng = UnwrapErr(SysRng);
    let mut sigkey = SigningKey::<LmsSha256M32H15<LmsOtsSha256N32W2>>::new(&mut rng);
    let pubkey = sigkey.public();
    let sig = sigkey.try_sign_with_rng(&mut rng, "example".as_bytes()).unwrap();
    let sig_valid = pubkey.verify("example".as_bytes(), &sig).is_ok();
    if sig_valid {
        println!("Signature valid!");
    } else {
        println!("Signature invalid!");
    }
}

Compiling with --release seems to work in my minimal example, although I don't know what may have been optimized out there.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modes.rs and the TreeLen type, then reproduce the supplied LmsSha256M32H15 example in dev mode. Inspect hybrid-array's sizes.rs support for the required size and compare debug and release behavior. Done means HLen 15 compiles and the example signs and verifies without a runtime stack overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.