#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
)]
#![forbid(unsafe_code)]
#![warn(
clippy::mod_module_files,
clippy::unwrap_used,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
unused_qualifications
)]
#[cfg(feature = "arithmetic")]
mod arithmetic;
#[cfg(feature = "ecdh")]
pub mod ecdh;
#[cfg(feature = "ecdsa-core")]
pub mod ecdsa;
#[cfg(any(feature = "test-vectors", test))]
pub mod test_vectors;
#[cfg(feature = "arithmetic")]
pub use arithmetic::{AffinePoint, ProjectivePoint, scalar::Scalar};
#[cfg(feature = "expose-field")]
pub use arithmetic::field::FieldElement;
#[cfg(feature = "hash2curve")]
pub use hash2curve;
pub use elliptic_curve;
#[cfg(feature = "pkcs8")]
pub use elliptic_curve::pkcs8;
use elliptic_curve::{
FieldBytesEncoding,
array::Array,
bigint::{Odd, cpubits},
consts::{U66, U67},
};
cpubits! {
32 => { use elliptic_curve::bigint::U544 as Uint; }
64 => { use elliptic_curve::bigint::U576 as Uint; }
}
const ORDER_HEX: &str = {
cpubits! {
32 => {
"000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"
}
64 => {
"00000000000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"
}
}
};
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
pub struct NistP521;
impl elliptic_curve::Curve for NistP521 {
type FieldBytesSize = U66;
type Uint = Uint;
const ORDER: Odd<Uint> = Odd::<Uint>::from_be_hex(ORDER_HEX);
}
impl elliptic_curve::PrimeCurve for NistP521 {}
impl elliptic_curve::point::PointCompression for NistP521 {
const COMPRESS_POINTS: bool = false;
}
impl elliptic_curve::point::PointCompaction for NistP521 {
const COMPACT_POINTS: bool = false;
}
#[cfg(feature = "pkcs8")]
impl pkcs8::AssociatedOid for NistP521 {
const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.35");
}
pub type CompressedPoint = Array<u8, U67>;
pub type Sec1Point = elliptic_curve::sec1::Sec1Point<NistP521>;
pub type FieldBytes = elliptic_curve::FieldBytes<NistP521>;
impl FieldBytesEncoding<NistP521> for Uint {}
#[cfg(feature = "arithmetic")]
pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP521>;
#[cfg(feature = "arithmetic")]
pub type PublicKey = elliptic_curve::PublicKey<NistP521>;
pub type SecretKey = elliptic_curve::SecretKey<NistP521>;
#[cfg(feature = "oprf")]
impl hash2curve::OprfParameters for NistP521 {
const ID: &'static [u8] = b"P521-SHA512";
}
#[cfg(test)]
mod tests {
use super::{CompressedPoint, NistP521};
use core::mem::size_of;
use elliptic_curve::sec1::CompressedPoint as Sec1Compressed;
#[test]
fn compressed_point_size_matches_sec1() {
assert_eq!(size_of::<CompressedPoint>(), 67);
assert_eq!(
size_of::<CompressedPoint>(),
size_of::<Sec1Compressed<NistP521>>(),
);
}
}