miden-crypto/src/dsa/rpo_falcon512/error.rs
src/dsa/rpo_falcon512/error.rsRaw
1use core::fmt;
2
3use super::{LOG_N, MODULUS, PK_LEN};
4
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub enum FalconError {
7 KeyGenerationFailed,
8 PubKeyDecodingExtraData,
9 PubKeyDecodingInvalidCoefficient(u32),
10 PubKeyDecodingInvalidLength(usize),
11 PubKeyDecodingInvalidTag(u8),
12 SigDecodingTooBigHighBits(u32),
13 SigDecodingInvalidRemainder,
14 SigDecodingNonZeroUnusedBitsLastByte,
15 SigDecodingMinusZero,
16 SigDecodingIncorrectEncodingAlgorithm,
17 SigDecodingNotSupportedDegree(u8),
18 SigGenerationFailed,
19}
20
21impl fmt::Display for FalconError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 use FalconError::*;
24 match self {
25 KeyGenerationFailed => write!(f, "Failed to generate a private-public key pair"),
26 PubKeyDecodingExtraData => {
27 write!(f, "Failed to decode public key: input not fully consumed")
28 }
29 PubKeyDecodingInvalidCoefficient(val) => {
30 write!(f, "Failed to decode public key: coefficient {val} is greater than or equal to the field modulus {MODULUS}")
31 }
32 PubKeyDecodingInvalidLength(len) => {
33 write!(f, "Failed to decode public key: expected {PK_LEN} bytes but received {len}")
34 }
35 PubKeyDecodingInvalidTag(byte) => {
36 write!(f, "Failed to decode public key: expected the first byte to be {LOG_N} but was {byte}")
37 }
38 SigDecodingTooBigHighBits(m) => {
39 write!(f, "Failed to decode signature: high bits {m} exceed 2048")
40 }
41 SigDecodingInvalidRemainder => {
42 write!(f, "Failed to decode signature: incorrect remaining data")
43 }
44 SigDecodingNonZeroUnusedBitsLastByte => {
45 write!(f, "Failed to decode signature: Non-zero unused bits in the last byte")
46 }
47 SigDecodingMinusZero => write!(f, "Failed to decode signature: -0 is forbidden"),
48 SigDecodingIncorrectEncodingAlgorithm => write!(f, "Failed to decode signature: not supported encoding algorithm"),
49 SigDecodingNotSupportedDegree(log_n) => write!(f, "Failed to decode signature: only supported irreducible polynomial degree is 512, 2^{log_n} was provided"),
50 SigGenerationFailed => write!(f, "Failed to generate a signature"),
51 }
52 }
53}
54
55#[cfg(feature = "std")]
56impl std::error::Error for FalconError {}