1#![no_std]
3#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4#![doc = include_str!("../README.md")]
5#![doc(
6 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
7 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
8)]
9#![forbid(unsafe_code)]
10#![warn(
11 clippy::mod_module_files,
12 clippy::cast_lossless,
13 clippy::cast_possible_truncation,
14 clippy::cast_possible_wrap,
15 clippy::cast_precision_loss,
16 clippy::cast_sign_loss,
17 clippy::checked_conversions,
18 clippy::implicit_saturating_sub,
19 clippy::arithmetic_side_effects,
20 clippy::panic,
21 clippy::panic_in_result_fn,
22 clippy::unwrap_used,
23 missing_docs,
24 rust_2018_idioms,
25 unused_lifetimes,
26 unused_qualifications
27)]
28
29#[cfg(feature = "alloc")]
30#[allow(unused_extern_crates)]
31extern crate alloc;
32
33#[cfg(feature = "arithmetic")]
34pub mod arithmetic;
35
36#[cfg(any(feature = "test-vectors", test))]
37pub mod test_vectors;
38
39#[cfg(feature = "dsa")]
40pub mod dsa;
41
42pub use elliptic_curve::{self, bigint::U256};
43
44#[cfg(feature = "arithmetic")]
45pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint};
46
47#[cfg(feature = "pkcs8")]
48pub use elliptic_curve::pkcs8;
49
50use elliptic_curve::{
51 bigint::ArrayEncoding,
52 consts::{U32, U33},
53 generic_array::GenericArray,
54 FieldBytesEncoding,
55};
56
57#[cfg(feature = "dsa")]
58type Hash = belt_hash::digest::Output<belt_hash::BeltHash>;
59
60const ORDER_HEX: &str = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD95C8ED60DFB4DFC7E5ABF99263D6607";
62
63#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
80pub struct BignP256;
81
82impl elliptic_curve::Curve for BignP256 {
83 type FieldBytesSize = U32;
85 type Uint = U256;
86
87 const ORDER: U256 = U256::from_be_hex(ORDER_HEX);
89}
90
91impl elliptic_curve::PrimeCurve for BignP256 {}
92
93impl elliptic_curve::point::PointCompression for BignP256 {
94 const COMPRESS_POINTS: bool = false;
96}
97
98impl elliptic_curve::point::PointCompaction for BignP256 {
99 const COMPACT_POINTS: bool = false;
101}
102
103#[cfg(feature = "pkcs8")]
104impl pkcs8::AssociatedOid for BignP256 {
105 const OID: pkcs8::ObjectIdentifier =
106 pkcs8::ObjectIdentifier::new_unwrap("1.2.112.0.2.0.34.101.45.1");
107}
108
109pub type CompressedPoint = GenericArray<u8, U33>;
111
112pub type FieldBytes = elliptic_curve::FieldBytes<BignP256>;
116
117pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<BignP256>;
119
120impl FieldBytesEncoding<BignP256> for U256 {
121 fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
122 U256::from_be_byte_array(*field_bytes)
123 }
124
125 fn encode_field_bytes(&self) -> FieldBytes {
126 self.to_be_byte_array()
127 }
128}
129
130#[cfg(feature = "arithmetic")]
132pub type NonZeroScalar = elliptic_curve::NonZeroScalar<BignP256>;
133
134#[cfg(feature = "arithmetic")]
136pub type PublicKey = elliptic_curve::PublicKey<BignP256>;
137
138pub type SecretKey = elliptic_curve::SecretKey<BignP256>;
140
141#[cfg(not(feature = "arithmetic"))]
142impl elliptic_curve::sec1::ValidatePublicKey for BignP256 {}
143
144#[cfg(feature = "bits")]
146pub type ScalarBits = elliptic_curve::ScalarBits<BignP256>;