1#![no_std]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![doc = include_str!("../README.md")]
4#![doc(
5 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
6 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
7)]
8#![allow(clippy::needless_range_loop)]
9#![forbid(unsafe_code)]
10#![warn(
11 clippy::mod_module_files,
12 clippy::unwrap_used,
13 missing_docs,
14 rust_2018_idioms,
15 unused_lifetimes,
16 unused_qualifications
17)]
18
19#[cfg(feature = "alloc")]
31#[allow(unused_imports)]
32#[macro_use]
33extern crate alloc;
34#[cfg(feature = "std")]
35extern crate std;
36
37#[cfg(feature = "arithmetic")]
38mod arithmetic;
39
40#[cfg(feature = "ecdh")]
41pub mod ecdh;
42
43#[cfg(feature = "ecdsa-core")]
44pub mod ecdsa;
45
46#[cfg(feature = "schnorr")]
47pub mod schnorr;
48
49#[cfg(any(feature = "test-vectors", test))]
50pub mod test_vectors;
51
52#[cfg(feature = "hash2curve")]
53pub use hash2curve;
54
55pub use elliptic_curve::{self, bigint::U256};
56
57#[cfg(feature = "arithmetic")]
58pub use arithmetic::{affine::AffinePoint, projective::ProjectivePoint, scalar::Scalar};
59#[cfg(feature = "pkcs8")]
60pub use elliptic_curve::pkcs8;
61#[cfg(feature = "sha2")]
62pub use sha2;
63
64use elliptic_curve::{
65 array::Array,
66 bigint::Odd,
67 consts::{U32, U33, U64},
68};
69
70const ORDER_HEX: &str = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141";
72
73const ORDER: Odd<U256> = Odd::<U256>::from_be_hex(ORDER_HEX);
75
76#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
88pub struct Secp256k1;
89
90impl elliptic_curve::Curve for Secp256k1 {
91 type FieldBytesSize = U32;
93
94 type Uint = U256;
96
97 const ORDER: Odd<U256> = ORDER;
99}
100
101impl elliptic_curve::PrimeCurve for Secp256k1 {}
102
103impl elliptic_curve::point::PointCompression for Secp256k1 {
104 const COMPRESS_POINTS: bool = true;
106}
107
108#[cfg(feature = "pkcs8")]
109impl pkcs8::AssociatedOid for Secp256k1 {
110 const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.10");
111}
112
113pub type CompressedPoint = Array<u8, U33>;
115
116pub type Sec1Point = elliptic_curve::sec1::Sec1Point<Secp256k1>;
118
119pub type FieldBytes = elliptic_curve::FieldBytes<Secp256k1>;
123
124pub type WideBytes = Array<u8, U64>;
126
127#[cfg(feature = "arithmetic")]
129pub type NonZeroScalar = elliptic_curve::NonZeroScalar<Secp256k1>;
130
131#[cfg(feature = "arithmetic")]
133pub type PublicKey = elliptic_curve::PublicKey<Secp256k1>;
134
135pub type SecretKey = elliptic_curve::SecretKey<Secp256k1>;
137
138#[cfg(not(feature = "arithmetic"))]
139impl elliptic_curve::sec1::ValidatePublicKey for Secp256k1 {}