|
1 |
| -//! NIST P-521 elliptic curve |
2 |
| -//! |
3 |
| -//! ## Minimum Supported Rust Version |
4 |
| -//! |
5 |
| -//! Rust **1.41** or higher. |
6 |
| -//! |
7 |
| -//! Minimum supported Rust version can be changed in the future, but it will be |
8 |
| -//! done with a minor version bump. |
9 |
| -
|
10 | 1 | #![no_std]
|
| 2 | +#![cfg_attr(docsrs, feature(doc_cfg))] |
| 3 | +#![doc( |
| 4 | + html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", |
| 5 | + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg" |
| 6 | +)] |
11 | 7 | #![forbid(unsafe_code)]
|
12 | 8 | #![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
|
13 |
| -#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] |
| 9 | +#![doc = include_str!("../README.md")] |
| 10 | + |
| 11 | +pub use elliptic_curve::{self, bigint::U576}; |
| 12 | + |
| 13 | +#[cfg(feature = "pkcs8")] |
| 14 | +#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))] |
| 15 | +pub use elliptic_curve::pkcs8; |
| 16 | + |
| 17 | +use elliptic_curve::{consts::U66, generic_array::GenericArray}; |
| 18 | + |
| 19 | +/// NIST P-521 elliptic curve. |
| 20 | +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] |
| 21 | +pub struct NistP521; |
| 22 | + |
| 23 | +impl elliptic_curve::Curve for NistP521 { |
| 24 | + /// 521-bit integer type used for internally representing field elements. |
| 25 | + type UInt = U576; |
| 26 | + |
| 27 | + /// Order of NIST P-521's elliptic curve group (i.e. scalar modulus). |
| 28 | + const ORDER: U576 = U576::from_be_hex("00000000000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"); |
| 29 | +} |
| 30 | + |
| 31 | +impl elliptic_curve::PrimeCurve for NistP521 {} |
| 32 | + |
| 33 | +impl elliptic_curve::PointCompression for NistP521 { |
| 34 | + /// NIST P-521 points are typically uncompressed. |
| 35 | + const COMPRESS_POINTS: bool = false; |
| 36 | +} |
| 37 | + |
| 38 | +impl elliptic_curve::PointCompaction for NistP521 { |
| 39 | + /// NIST P-521 points are typically uncompressed. |
| 40 | + const COMPACT_POINTS: bool = false; |
| 41 | +} |
| 42 | + |
| 43 | +#[cfg(feature = "jwk")] |
| 44 | +#[cfg_attr(docsrs, doc(cfg(feature = "jwk")))] |
| 45 | +impl elliptic_curve::JwkParameters for NistP521 { |
| 46 | + const CRV: &'static str = "P-521"; |
| 47 | +} |
| 48 | + |
| 49 | +#[cfg(feature = "pkcs8")] |
| 50 | +impl pkcs8::AssociatedOid for NistP521 { |
| 51 | + const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.35"); |
| 52 | +} |
| 53 | + |
| 54 | +/// Compressed SEC1-encoded NIST P-521 curve point. |
| 55 | +pub type CompressedPoint = GenericArray<u8, U66>; |
| 56 | + |
| 57 | +/// NIST P-521 field element serialized as bytes. |
| 58 | +/// |
| 59 | +/// Byte array containing a serialized field element value (base field or |
| 60 | +/// scalar). |
| 61 | +pub type FieldBytes = elliptic_curve::FieldBytes<NistP521>; |
14 | 62 |
|
15 |
| -pub use elliptic_curve; |
| 63 | +/// NIST P-521 SEC1 encoded point. |
| 64 | +pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP521>; |
16 | 65 |
|
17 |
| -// TODO(tarcieri): curve definition |
| 66 | +/// NIST P-521 secret key. |
| 67 | +pub type SecretKey = elliptic_curve::SecretKey<NistP521>; |
0 commit comments