Expand description
§FN-DSA implementation
This crate is really a wrapper for the tide-fn-dsa-kgen, tide-fn-dsa-sign and tide-fn-dsa-vrfy crates that implement the various elements of the FN-DSA signature algorithm. All the relevant types, functions and constants are re-exported here. Users of this implementation only need to import this crate; the division into sub-crates is meant to help with specialized situations where code footprint reduction is important (typically, embedded systems that only need to verify signatures, but not generate keys or signatures).
§Tidecoin compatibility
Use sign_falcon / verify_falcon (on the corresponding signing or
verifying type) with an explicit FalconProfile. TidecoinStrict
requires canonical, exactly consumed compressed signatures for degrees
512 and 1024. TidecoinLegacyFalcon512 preserves historical Falcon-512
encodings and the exclusive legacy norm bound. PqClean retains its
padded-format compatibility. The generic API described below is separate.
The raw Falcon API consumes the supplied message bytes without adding
FN-DSA context/domain metadata or a transaction sighash byte.
§WARNING
The generic FN-DSA API is experimental and is not claimed to conform to a final FIPS 206 standard. Its encodings, pre-hashing and domain separation may evolve. The explicit Tidecoin profiles and deterministic PQHD key mapping have a separate compatibility contract and must not be changed silently to follow future FN-DSA revisions.
§Implementation notes
The whole code is written in pure Rust and is compatible with no_std.
Production dependencies include rand_core, zeroize, sha2 and
cpufeatures; unit tests use additional crates.
On x86 (both 32-bit and 64-bit), AVX2 opcodes are automatically used for faster operations if their support is detected at runtime. No special compilation flag nor extra runtime check is needed for that; the compiled code remains compatible with plain non-AVX2-aware CPUs.
On 64-bit x86 (x86_64) and ARMv8 (aarch64, arm64ec), native
(hardware) floating-point support is used, since in both these cases
the architecture ABI mandates a strict IEEE-754 unit and can more or
less be assumed to operate in constant-time for non-exceptional
inputs. This makes signature generation much faster on these
platforms (on x86_64, this furthermore combines with AVX2
optimizations if available in the current CPU). On other platforms, a
portable emulation of floating-point operations is used (this
emulation makes a best effort at operating in constant-time, though
some recent compiler optimizations might introduce variable-time
operations).
Numeric behavior differs by subsystem:
- classic/native key generation uses integer and fixed-point arithmetic
- PQClean/Tidecoin deterministic key generation uses an integer-only emulation of Falcon FLR/FFT semantics
- signature verification uses integer arithmetic
The key pair generation implementation is a translation of the
ntrugen code, which is faster than the originally submitted Falcon
code. The signature generation engine follows the steps of the
sign_dyn operations from the original falcon code (indeed, an
internal unit tests checks that the sampler returns the same values
for the same inputs). Achieved performance on x86_64 is very close
to that offered by the C code (signature verification performance is
even better).
§Example usage
For deterministic Falcon key derivation, there are now two explicit seeded key-generation families on the Falcon key generators:
keygen_from_seed_native()uses the upstreamfn-dsa/ntrugenseeded Falcon path.keygen_from_seed_pqclean()andkeygen_from_stream_key_tidecoin()use PQClean/Tidecoin-compatible seeded Falcon key generation.
These APIs are intentionally separate because the same 48-byte seed does not map to the same Falcon key pair in the two families. The PQClean/Tidecoin APIs are compatibility-oriented deterministic key-derivation entrypoints; they preserve the original seeded Falcon mapping and rejection behavior, but they do not imply that PQClean code is used for signing or verification.
use tide_fn_dsa::{
SIGN_KEY_SIZE_512, VRFY_KEY_SIZE_512, SIGNATURE_SIZE_512, FN_DSA_LOGN_512,
KeyPairGenerator, KeyPairGeneratorStandard,
SigningKey, SigningKeyStandard,
VerifyingKey, VerifyingKeyStandard,
DOMAIN_NONE, HASH_ID_RAW, CryptoRng, RngCore, RngError,
};
// Generate key pair.
let mut rng = DemoRng(1);
let mut kg = KeyPairGeneratorStandard::default();
let mut sign_key = [0u8; SIGN_KEY_SIZE_512];
let mut vrfy_key = [0u8; VRFY_KEY_SIZE_512];
kg.keygen(FN_DSA_LOGN_512, &mut rng, &mut sign_key, &mut vrfy_key)
.unwrap();
// Sign a message with the signing key.
let mut sk = SigningKeyStandard::decode(&sign_key)
.expect("valid signing key bytes");
let mut sig = [0u8; SIGNATURE_SIZE_512];
sk.sign(&mut rng, &DOMAIN_NONE, &HASH_ID_RAW, b"message", &mut sig)
.unwrap();
// Verify a signature with the verifying key.
match VerifyingKeyStandard::decode(&vrfy_key) {
Some(vk) => {
if vk.verify(&sig, &DOMAIN_NONE, &HASH_ID_RAW, b"message") {
// signature is valid
} else {
// signature is not valid
}
}
_ => {
// could not decode verifying key
}
}Falcon compatibility APIs are also exposed explicitly:
use tide_fn_dsa::{
SIGN_KEY_SIZE_512, VRFY_KEY_SIZE_512, TIDECOIN_LEGACY_FALCON512_SIG_MAX,
FN_DSA_LOGN_512, FalconProfile,
KeyPairGenerator, KeyPairGeneratorStandard,
SigningKey, SigningKeyStandard,
VerifyingKey, VerifyingKeyStandard,
CryptoRng, RngCore, RngError,
};
let mut rng = DemoRng(7);
let mut kg = KeyPairGeneratorStandard::default();
let mut sign_key = [0u8; SIGN_KEY_SIZE_512];
let mut vrfy_key = [0u8; VRFY_KEY_SIZE_512];
kg.keygen(FN_DSA_LOGN_512, &mut rng, &mut sign_key, &mut vrfy_key)
.unwrap();
let mut sk = SigningKeyStandard::decode(&sign_key).unwrap();
let vk = VerifyingKeyStandard::decode(&vrfy_key).unwrap();
let mut sig = [0u8; TIDECOIN_LEGACY_FALCON512_SIG_MAX];
let sig_len = sk.sign_falcon(
&mut rng,
FalconProfile::TidecoinLegacyFalcon512,
b"message",
&mut sig,
).unwrap();
assert!(vk.verify_falcon(
FalconProfile::TidecoinLegacyFalcon512,
&sig[..sig_len],
b"message",
));Structs§
- Domain
Context - When a message is signed or verified, it is accompanied with a domain
separation context, which is an arbitrary sequence of bytes of length
at most 255. Such a context is wrapped in a
DomainContextstructure. - Hash
Identifier - The message for which a signature is to be generated or verified is pre-hashed by the caller and provided as a hash value along with an identifier of the used hash function. The identifier is normally an encoded ASN.1 OID. A special identifier is used for “raw” messages (i.e. not pre-hashed at all); it uses a single byte of value 0x00.
- KeyPair
Generator512 - Key pair generator for degrees (
logn) 9 to 9 only. - KeyPair
Generator1024 - Key pair generator for degrees (
logn) 10 to 10 only. - KeyPair
Generator Standard - Key pair generator for degrees (
logn) 9 to 10 only. - KeyPair
Generator Weak - Key pair generator for degrees (
logn) 2 to 8 only. - RngError
- Error type of random number generators
- SHA3_
224 - SHA3-224 implementation.
- SHA3_
256 - SHA3-256 implementation.
- SHA3_
384 - SHA3-384 implementation.
- SHA3_
512 - SHA3-512 implementation.
- SHAKE
- SHAKE implementation.
- Signing
Key512 - Signature generator for degrees (
logn) 9 to 9 only. - Signing
Key1024 - Signature generator for degrees (
logn) 10 to 10 only. - Signing
KeyStandard - Signature generator for degrees (
logn) 9 to 10 only. - Signing
KeyWeak - Signature generator for degrees (
logn) 2 to 8 only. - Verifying
Key512 - Signature verifier for degrees (
logn) 9 to 9 only. - Verifying
Key1024 - Signature verifier for degrees (
logn) 10 to 10 only. - Verifying
KeyStandard - Signature verifier for degrees (
logn) 9 to 10 only. - Verifying
KeyWeak - Signature verifier for degrees (
logn) 2 to 8 only.
Enums§
- Deterministic
KeyGen Error - Error type for deterministic Falcon key pair generation.
- Domain
Context Error - Error type for domain-separation contexts.
- Falcon
Profile - Falcon-compatible raw-message profile.
- Hash
Identifier Error - Error type for hash identifiers.
- Hash
ToPoint Error - Error type for message hashing into a point.
- KeyGen
Error - Error type for key pair generation.
- LogN
Error - Error type for invalid degree parameters.
- Shake
Error - Error type for SHAKE state transitions.
- Signing
KeyError - Error type for signing-key operations with caller-supplied buffers.
Constants§
- DOMAIN_
NONE - Empty domain separation context.
- FALCON_
KEYGEN_ SEED_ SIZE - Seed length for deterministic Falcon key generation.
- FALCON_
NONCE_ LEN - Falcon nonce length in bytes.
- FN_
DSA_ LOGN_ 512 - Symbolic constant for FN-DSA with degree 512 (
logn = 9). - FN_
DSA_ LOGN_ 1024 - Symbolic constant for FN-DSA with degree 1024 (
logn = 10). - HASH_
ID_ RAW - Hash function identifier: none.
- HASH_
ID_ SHA3_ 256 - Hash function identifier: SHA3-256
- HASH_
ID_ SHA3_ 384 - Hash function identifier: SHA3-384
- HASH_
ID_ SHA3_ 512 - Hash function identifier: SHA3-512
- HASH_
ID_ SHA256 - Hash function identifier: SHA-256
- HASH_
ID_ SHA384 - Hash function identifier: SHA-384
- HASH_
ID_ SHA512 - Hash function identifier: SHA-512
- HASH_
ID_ SHA512_ 256 - Hash function identifier: SHA-512-256
- HASH_
ID_ SHAK E128 - Hash function identifier: SHAKE128
- HASH_
ID_ SHAK E256 - Hash function identifier: SHAKE256
- PQHD_
KEYGEN_ STREAM_ SIZE - Stream-key length for Tidecoin PQHD deterministic Falcon key generation.
- PQHD_
MAX_ DETERMINISTIC_ ATTEMPTS - Maximum number of deterministic stream-key retry attempts.
- SIGNATURE_
SIZE_ 512 - Signature size for degree 512 (
logn = 9). - SIGNATURE_
SIZE_ 1024 - Signature size for degree 1024 (
logn = 10). - SIGN_
KEY_ SIZE_ 512 - Signing key size for degree 512 (
logn = 9). - SIGN_
KEY_ SIZE_ 1024 - Signing key size for degree 1024 (
logn = 10). - TIDECOIN_
LEGACY_ FALCO N512_ SIG_ BODY_ MAX - Historical Falcon-512 signer body capacity; not a verification limit.
- TIDECOIN_
LEGACY_ FALCO N512_ SIG_ MAX - Historical Falcon-512 signer capacity; not the node wallet signing bound (666 bytes) and not a verification limit.
- VRFY_
KEY_ SIZE_ 512 - Verifying key size for degree 512 (
logn = 9). - VRFY_
KEY_ SIZE_ 1024 - Verifying key size for degree 1024 (
logn = 10).
Traits§
- Crypto
Rng - A marker trait used to indicate that an
RngCoreorBlockRngCoreimplementation is supposed to be cryptographically secure. - KeyPair
Generator - Key pair generator and temporary buffers.
- RngCore
- The core of a random number generator.
- Signing
Key - Signing key handler and temporary buffers.
- Verifying
Key - Verifying key handler.
Functions§
- hash_
to_ point - Hash a message into a polynomial modulo q = 12289.
- hash_
to_ point_ falcon - Hash a raw Falcon/PQClean message into a polynomial modulo q = 12289.
- is_
noncanonical_ legacy_ falcon512 - Format-only classifier for historical Tidecoin Falcon-512 encodings. Classify a complete raw Falcon-512 signature as a noncanonical historical encoding. Returns false for canonical encodings and malformed buffers, including trailing bytes. This does not verify the signature, strip a transaction sighash byte, or select relay policy.
- sign_
key_ size - Get the size (in bytes) of a signing key for the provided degree
(degree is
n = 2^logn, with2 <= logn <= 10). - signature_
size - Get the size (in bytes) of a signature for the provided degree
(degree is
n = 2^logn, with2 <= logn <= 10). - vrfy_
key_ size - Get the size (in bytes) of a verifying key for the provided degree
(degree is
n = 2^logn, with2 <= logn <= 10).