-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
p521: initial
NistP521
type definitions
Adds an initial type which impls the `elliptic_curve::Curve` trait and defines the order, JWK identifier, and PKCS#8 OID for secp521r1.
- Loading branch information
Showing
6 changed files
with
96 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
[package] | ||
name = "p521" | ||
description = "NIST P-521 (secp521r1) elliptic curve" | ||
version = "0.0.0" | ||
version = "0.11.1" | ||
description = "Pure Rust implementation of the NIST P-521 (a.k.a. secp521r1) elliptic curve" | ||
authors = ["RustCrypto Developers"] | ||
license = "Apache-2.0 OR MIT" | ||
documentation = "https://docs.rs/elliptic-curve" | ||
documentation = "https://docs.rs/p521" | ||
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p521" | ||
readme = "README.md" | ||
edition = "2018" | ||
categories = ["cryptography", "no-std"] | ||
keywords = ["crypto", "ecc", "nist", "secp521r1"] | ||
edition = "2021" | ||
rust-version = "1.57" | ||
|
||
[dependencies] | ||
elliptic-curve = { version = "0.12.1", default-features = false, features = ["hazmat", "sec1"] } | ||
|
||
[features] | ||
default = ["pem", "std"] | ||
jwk = ["elliptic-curve/jwk"] | ||
pem = ["elliptic-curve/pem", "pkcs8"] | ||
pkcs8 = ["elliptic-curve/pkcs8"] | ||
std = ["elliptic-curve/std"] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,67 @@ | ||
//! NIST P-521 elliptic curve | ||
//! | ||
//! ## Minimum Supported Rust Version | ||
//! | ||
//! Rust **1.41** or higher. | ||
//! | ||
//! Minimum supported Rust version can be changed in the future, but it will be | ||
//! done with a minor version bump. | ||
|
||
#![no_std] | ||
#![cfg_attr(docsrs, feature(doc_cfg))] | ||
#![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(missing_docs, rust_2018_idioms, unused_qualifications)] | ||
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] | ||
#![doc = include_str!("../README.md")] | ||
|
||
pub use elliptic_curve::{self, bigint::U576}; | ||
|
||
#[cfg(feature = "pkcs8")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))] | ||
pub use elliptic_curve::pkcs8; | ||
|
||
use elliptic_curve::{consts::U66, generic_array::GenericArray}; | ||
|
||
/// NIST P-521 elliptic curve. | ||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct NistP521; | ||
|
||
impl elliptic_curve::Curve for NistP521 { | ||
/// 521-bit integer type used for internally representing field elements. | ||
type UInt = U576; | ||
|
||
/// Order of NIST P-521's elliptic curve group (i.e. scalar modulus). | ||
const ORDER: U576 = U576::from_be_hex("00000000000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"); | ||
} | ||
|
||
impl elliptic_curve::PrimeCurve for NistP521 {} | ||
|
||
impl elliptic_curve::PointCompression for NistP521 { | ||
/// NIST P-521 points are typically uncompressed. | ||
const COMPRESS_POINTS: bool = false; | ||
} | ||
|
||
impl elliptic_curve::PointCompaction for NistP521 { | ||
/// NIST P-521 points are typically uncompressed. | ||
const COMPACT_POINTS: bool = false; | ||
} | ||
|
||
#[cfg(feature = "jwk")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "jwk")))] | ||
impl elliptic_curve::JwkParameters for NistP521 { | ||
const CRV: &'static str = "P-521"; | ||
} | ||
|
||
#[cfg(feature = "pkcs8")] | ||
impl pkcs8::AssociatedOid for NistP521 { | ||
const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.35"); | ||
} | ||
|
||
/// Compressed SEC1-encoded NIST P-521 curve point. | ||
pub type CompressedPoint = GenericArray<u8, U66>; | ||
|
||
/// NIST P-521 field element serialized as bytes. | ||
/// | ||
/// Byte array containing a serialized field element value (base field or | ||
/// scalar). | ||
pub type FieldBytes = elliptic_curve::FieldBytes<NistP521>; | ||
|
||
pub use elliptic_curve; | ||
/// NIST P-521 SEC1 encoded point. | ||
pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP521>; | ||
|
||
// TODO(tarcieri): curve definition | ||
/// NIST P-521 secret key. | ||
pub type SecretKey = elliptic_curve::SecretKey<NistP521>; |