1#![no_std]
2#![cfg_attr(docsrs, feature(doc_auto_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)]
7#![forbid(unsafe_code)]
8#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
9#![doc = include_str!("../README.md")]
10
11#[cfg(feature = "arithmetic")]
23mod arithmetic;
24
25#[cfg(feature = "ecdh")]
26pub mod ecdh;
27
28#[cfg(feature = "ecdsa-core")]
29pub mod ecdsa;
30
31#[cfg(any(feature = "test-vectors", test))]
32pub mod test_vectors;
33
34pub use elliptic_curve::{self, bigint::U384, consts::U48};
35
36#[cfg(feature = "arithmetic")]
37pub use arithmetic::{AffinePoint, ProjectivePoint, scalar::Scalar};
38
39#[cfg(feature = "expose-field")]
40pub use arithmetic::field::FieldElement;
41
42#[cfg(feature = "pkcs8")]
43pub use elliptic_curve::pkcs8;
44
45use elliptic_curve::{FieldBytesEncoding, array::Array, bigint::ArrayEncoding, consts::U49};
46
47const ORDER_HEX: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973";
49
50#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
52pub struct NistP384;
53
54impl elliptic_curve::Curve for NistP384 {
55 type FieldBytesSize = U48;
57
58 type Uint = U384;
60
61 const ORDER: U384 = U384::from_be_hex(ORDER_HEX);
63}
64
65impl elliptic_curve::PrimeCurve for NistP384 {}
66
67impl elliptic_curve::point::PointCompression for NistP384 {
68 const COMPRESS_POINTS: bool = false;
70}
71
72impl elliptic_curve::point::PointCompaction for NistP384 {
73 const COMPACT_POINTS: bool = false;
75}
76
77#[cfg(feature = "jwk")]
78impl elliptic_curve::JwkParameters for NistP384 {
79 const CRV: &'static str = "P-384";
80}
81
82#[cfg(feature = "pkcs8")]
83impl pkcs8::AssociatedOid for NistP384 {
84 const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.34");
85}
86
87pub type CompressedPoint = Array<u8, U49>;
89
90pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP384>;
92
93pub type FieldBytes = elliptic_curve::FieldBytes<NistP384>;
98
99impl FieldBytesEncoding<NistP384> for U384 {
100 fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
101 U384::from_be_byte_array(*field_bytes)
102 }
103
104 fn encode_field_bytes(&self) -> FieldBytes {
105 self.to_be_byte_array()
106 }
107}
108
109#[cfg(feature = "arithmetic")]
111pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP384>;
112
113#[cfg(feature = "arithmetic")]
115pub type PublicKey = elliptic_curve::PublicKey<NistP384>;
116
117pub type SecretKey = elliptic_curve::SecretKey<NistP384>;
119
120#[cfg(not(feature = "arithmetic"))]
121impl elliptic_curve::sec1::ValidatePublicKey for NistP384 {}
122
123#[cfg(feature = "bits")]
125pub type ScalarBits = elliptic_curve::scalar::ScalarBits<NistP384>;
126
127#[cfg(feature = "oprf")]
128impl elliptic_curve::OprfParameters for NistP384 {
129 const ID: &'static [u8] = b"P384-SHA384";
131
132 type Hash = sha2::Sha384;
134
135 type ExpandMsg = elliptic_curve::hash2curve::ExpandMsgXmd<sha2::Sha384>;
138}