]> git.proxmox.com Git - rustc.git/blob - vendor/p384/src/lib.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / p384 / src / lib.rs
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 )]
7 #![forbid(unsafe_code)]
8 #![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
9 #![doc = include_str!("../README.md")]
10
11 //! ## `serde` support
12 //!
13 //! When the `serde` feature of this crate is enabled, `Serialize` and
14 //! `Deserialize` are impl'd for the following types:
15 //!
16 //! - [`AffinePoint`]
17 //! - [`Scalar`]
18 //! - [`ecdsa::VerifyingKey`]
19 //!
20 //! Please see type-specific documentation for more information.
21
22 #[cfg(feature = "arithmetic")]
23 mod arithmetic;
24
25 #[cfg(feature = "ecdh")]
26 #[cfg_attr(docsrs, doc(cfg(feature = "ecdh")))]
27 pub mod ecdh;
28
29 #[cfg(feature = "ecdsa-core")]
30 #[cfg_attr(docsrs, doc(cfg(feature = "ecdsa-core")))]
31 pub mod ecdsa;
32
33 #[cfg(any(feature = "test-vectors", test))]
34 #[cfg_attr(docsrs, doc(cfg(feature = "test-vectors")))]
35 pub mod test_vectors;
36
37 pub use elliptic_curve::{self, bigint::U384};
38
39 #[cfg(feature = "arithmetic")]
40 pub use arithmetic::{affine::AffinePoint, projective::ProjectivePoint, scalar::Scalar};
41
42 #[cfg(feature = "expose-field")]
43 pub use arithmetic::field::FieldElement;
44
45 #[cfg(feature = "pkcs8")]
46 #[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
47 pub use elliptic_curve::pkcs8;
48
49 use elliptic_curve::{consts::U49, generic_array::GenericArray};
50
51 /// NIST P-384 elliptic curve.
52 #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
53 pub struct NistP384;
54
55 impl elliptic_curve::Curve for NistP384 {
56 /// 384-bit integer type used for internally representing field elements.
57 type UInt = U384;
58
59 /// Order of NIST P-384's elliptic curve group (i.e. scalar modulus).
60 const ORDER: U384 = U384::from_be_hex("ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973");
61 }
62
63 impl elliptic_curve::PrimeCurve for NistP384 {}
64
65 impl elliptic_curve::PointCompression for NistP384 {
66 /// NIST P-384 points are typically uncompressed.
67 const COMPRESS_POINTS: bool = false;
68 }
69
70 impl elliptic_curve::PointCompaction for NistP384 {
71 /// NIST P-384 points are typically uncompressed.
72 const COMPACT_POINTS: bool = false;
73 }
74
75 #[cfg(feature = "jwk")]
76 #[cfg_attr(docsrs, doc(cfg(feature = "jwk")))]
77 impl elliptic_curve::JwkParameters for NistP384 {
78 const CRV: &'static str = "P-384";
79 }
80
81 #[cfg(feature = "pkcs8")]
82 impl pkcs8::AssociatedOid for NistP384 {
83 const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.34");
84 }
85
86 /// Compressed SEC1-encoded NIST P-384 curve point.
87 pub type CompressedPoint = GenericArray<u8, U49>;
88
89 /// NIST P-384 field element serialized as bytes.
90 ///
91 /// Byte array containing a serialized field element value (base field or
92 /// scalar).
93 pub type FieldBytes = elliptic_curve::FieldBytes<NistP384>;
94
95 /// NIST P-384 SEC1 encoded point.
96 pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP384>;
97
98 /// Non-zero NIST P-384 scalar field element.
99 #[cfg(feature = "arithmetic")]
100 pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP384>;
101
102 /// NIST P-384 public key.
103 #[cfg(feature = "arithmetic")]
104 pub type PublicKey = elliptic_curve::PublicKey<NistP384>;
105
106 /// NIST P-384 secret key.
107 pub type SecretKey = elliptic_curve::SecretKey<NistP384>;
108
109 #[cfg(not(feature = "arithmetic"))]
110 impl elliptic_curve::sec1::ValidatePublicKey for NistP384 {}
111
112 /// Bit representation of a NIST P-384 scalar field element.
113 #[cfg(feature = "bits")]
114 #[cfg_attr(docsrs, doc(cfg(feature = "bits")))]
115 pub type ScalarBits = elliptic_curve::ScalarBits<NistP384>;
116
117 #[cfg(feature = "voprf")]
118 #[cfg_attr(docsrs, doc(cfg(feature = "voprf")))]
119 impl elliptic_curve::VoprfParameters for NistP384 {
120 /// See <https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-08.html#section-4.4-1.2>.
121 type Hash = sha2::Sha384;
122
123 /// See <https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-08.html#section-4.4-1.3>.
124 const ID: u16 = 0x0004;
125 }