Skip to content

Commit 635e25e

Browse files
authored
p521: initial NistP521 type definitions (#607)
Adds an initial type which impls the `elliptic_curve::Curve` trait and defines the order, JWK identifier, and PKCS#8 OID for secp521r1.
1 parent 0dd58a0 commit 635e25e

File tree

6 files changed

+96
-36
lines changed

6 files changed

+96
-36
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

p521/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

p521/Cargo.toml

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
[package]
22
name = "p521"
3-
description = "NIST P-521 (secp521r1) elliptic curve"
4-
version = "0.0.0"
3+
version = "0.11.1"
4+
description = "Pure Rust implementation of the NIST P-521 (a.k.a. secp521r1) elliptic curve"
55
authors = ["RustCrypto Developers"]
66
license = "Apache-2.0 OR MIT"
7-
documentation = "https://docs.rs/elliptic-curve"
7+
documentation = "https://docs.rs/p521"
88
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p521"
99
readme = "README.md"
10-
edition = "2018"
1110
categories = ["cryptography", "no-std"]
1211
keywords = ["crypto", "ecc", "nist", "secp521r1"]
12+
edition = "2021"
13+
rust-version = "1.57"
1314

1415
[dependencies]
1516
elliptic-curve = { version = "0.12.1", default-features = false, features = ["hazmat", "sec1"] }
1617

1718
[features]
19+
default = ["pem", "std"]
20+
jwk = ["elliptic-curve/jwk"]
21+
pem = ["elliptic-curve/pem", "pkcs8"]
22+
pkcs8 = ["elliptic-curve/pkcs8"]
1823
std = ["elliptic-curve/std"]
19-
20-
[package.metadata.docs.rs]
21-
all-features = true

p521/LICENSE-MIT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020 RustCrypto Developers
1+
Copyright (c) 2020-2022 RustCrypto Developers
22

33
Permission is hereby granted, free of charge, to any
44
person obtaining a copy of this software and associated

p521/README.md

+16-13
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
[![crate][crate-image]][crate-link]
44
[![Docs][docs-image]][docs-link]
5+
[![Build Status][build-image]][build-link]
56
![Apache2/MIT licensed][license-image]
67
![Rust Version][rustc-image]
7-
[![Build Status][build-image]][build-link]
8+
[![Project Chat][chat-image]][chat-link]
89

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

1112
[Documentation][docs-link]
1213

13-
## Stub!
14+
## About P-521
15+
16+
NIST P-521 is a Weierstrass curve specified in FIPS 186-4: Digital Signature
17+
Standard (DSS):
1418

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

2021
## Minimum Supported Rust Version
2122

22-
Rust **1.41** or higher.
23+
Rust **1.57** or higher.
2324

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

4748
[//]: # (badges)
4849

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

58-
[//]: # (general links)
61+
[//]: # (links)
5962

6063
[`elliptic-curve`]: https://github.com/RustCrypto/traits/tree/master/elliptic-curve

p521/src/lib.rs

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,67 @@
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-
101
#![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+
)]
117
#![forbid(unsafe_code)]
128
#![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>;
1462

15-
pub use elliptic_curve;
63+
/// NIST P-521 SEC1 encoded point.
64+
pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP521>;
1665

17-
// TODO(tarcieri): curve definition
66+
/// NIST P-521 secret key.
67+
pub type SecretKey = elliptic_curve::SecretKey<NistP521>;

0 commit comments

Comments
 (0)