pub mod boxed;
mod curve25519;
mod curve448;
pub mod curves;
pub mod ecdh;
pub mod ecdsa;
pub mod ed25519;
pub mod ed448;
pub mod edwards25519;
mod p256;
#[cfg(feature = "x509")]
pub(crate) mod registry;
#[cfg(feature = "ristretto255")]
pub mod ristretto255;
#[cfg(feature = "hazmat-secp256k1")]
pub mod secp256k1;
pub mod sm2;
mod weierstrass;
pub mod x25519;
pub mod x448;
pub use boxed::{
BoxedEcdhPrivateKey, BoxedEcdsaPrivateKey, BoxedEcdsaPublicKey, BoxedEcdsaSignature,
};
pub use curves::CurveId;
pub use ed448::{Ed448PrivateKey, Ed448PublicKey, Ed448Signature};
pub use ed25519::{Ed25519PrivateKey, Ed25519PublicKey, Ed25519Signature};
pub use sm2::{Sm2PrivateKey, Sm2PublicKey, Sm2Signature};
pub use x448::{X448PrivateKey, X448PublicKey};
pub use x25519::{X25519PrivateKey, X25519PublicKey};
#[cfg(feature = "key")]
mod key_impl;
pub(crate) fn uint_from_be_hex<const LIMBS: usize>(hex: &str) -> crate::bignum::Uint<LIMBS> {
const fn nibble(c: u8) -> u8 {
match c {
b'0'..=b'9' => c - b'0',
b'a'..=b'f' => c - b'a' + 10,
b'A'..=b'F' => c - b'A' + 10,
_ => 0,
}
}
let h = hex.as_bytes();
debug_assert!(h.len().is_multiple_of(2), "hex must have even length");
let n = h.len() / 2;
let mut bytes = [0u8; 72];
let mut i = 0;
while i < n {
bytes[i] = (nibble(h[2 * i]) << 4) | nibble(h[2 * i + 1]);
i += 1;
}
crate::bignum::Uint::from_be_bytes(&bytes[..n])
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
InvalidInput,
Verification,
Malformed,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::InvalidInput => f.write_str("invalid elliptic-curve input"),
Error::Verification => f.write_str("ECDSA signature verification failed"),
Error::Malformed => f.write_str("malformed elliptic-curve encoding"),
}
}
}
impl core::error::Error for Error {}