Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/attack/polynonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub struct PolynonceAttack {

impl PolynonceAttack {
pub fn new(degree: usize) -> Self {
assert!(
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This public constructor now panics on invalid input. That is fine for a private invariant, but here it turns a caller mistake into a process abort for library users instead of a normal error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/attack/polynonce.rs, line 18:

<comment>This public constructor now panics on invalid input. That is fine for a private invariant, but here it turns a caller mistake into a process abort for library users instead of a normal error.</comment>

<file context>
@@ -15,6 +15,10 @@ pub struct PolynonceAttack {
 
 impl PolynonceAttack {
     pub fn new(degree: usize) -> Self {
+        assert!(
+            degree == 1,
+            "only linear polynonce (degree=1) is implemented, got degree={degree}"
</file context>
Fix with Cubic

degree == 1,
"only linear polynonce (degree=1) is implemented, got degree={degree}"
);
Self { degree }
}

Expand Down Expand Up @@ -385,6 +389,12 @@ mod tests {
.collect()
}

#[test]
#[should_panic(expected = "only linear polynonce")]
fn test_degree_above_1_panics() {
PolynonceAttack::new(2);
}

#[test]
fn test_modular_sqrt() {
// Test sqrt of a perfect square
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ fn run(cli: Cli) -> Result<bool> {
}
#[cfg(feature = "polynonce")]
"polynonce" => {
if _polynonce_degree != 1 {
anyhow::bail!(
"Only degree=1 (linear) is supported for polynonce attack, got {}",
_polynonce_degree
);
}
let attack = PolynonceAttack::new(_polynonce_degree);
let vulns = attack.detect(&signatures);
(vulns, Box::new(attack))
Expand Down
Loading