Skip to content

Commit

Permalink
p521: initial NistP521 type definitions
Browse files Browse the repository at this point in the history
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
tarcieri committed Jun 13, 2022
1 parent 0dd58a0 commit 36e0a87
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions p521/CHANGELOG.md
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).
16 changes: 9 additions & 7 deletions p521/Cargo.toml
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
2 changes: 1 addition & 1 deletion p521/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020 RustCrypto Developers
Copyright (c) 2020-2022 RustCrypto Developers

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
29 changes: 16 additions & 13 deletions p521/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
[![Build Status][build-image]][build-link]
![Apache2/MIT licensed][license-image]
![Rust Version][rustc-image]
[![Build Status][build-image]][build-link]
[![Project Chat][chat-image]][chat-link]

NIST P-521 elliptic curve (a.k.a. secp521r1) types.
Pure Rust implementation of the NIST P-521 (a.k.a. secp521r1) elliptic curve.

[Documentation][docs-link]

## Stub!
## About P-521

NIST P-521 is a Weierstrass curve specified in FIPS 186-4: Digital Signature
Standard (DSS):

This crate is a placeholder for implementing NIST P-521 in terms of traits
from the [`elliptic-curve`] crate, however no actual implementation work has
been done yet. If you are actually interested in P-521 support, please open
an issue about it.
<https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf>

## Minimum Supported Rust Version

Rust **1.41** or higher.
Rust **1.57** or higher.

Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.
Expand All @@ -46,15 +47,17 @@ dual licensed as above, without any additional terms or conditions.

[//]: # (badges)

[crate-image]: https://img.shields.io/crates/v/p521.svg
[crate-image]: https://buildstats.info/crate/p521
[crate-link]: https://crates.io/crates/p521
[docs-image]: https://docs.rs/p521/badge.svg
[docs-link]: https://docs.rs/p521/
[build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p521.yml/badge.svg
[build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p521.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg
[build-image]: https://github.com/RustCrypto/elliptic-curves/workflows/p521/badge.svg?branch=master&event=push
[build-link]: https://github.com/RustCrypto/elliptic-curves/actions?query=workflow%3Ap521
[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260040-elliptic-curves

[//]: # (general links)
[//]: # (links)

[`elliptic-curve`]: https://github.com/RustCrypto/traits/tree/master/elliptic-curve
74 changes: 62 additions & 12 deletions p521/src/lib.rs
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>;

0 comments on commit 36e0a87

Please sign in to comment.