1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#[cfg(feature = "arithmetic")]
use crate::SignatureSize;
#[cfg(feature = "arithmetic")]
use core::borrow::Borrow;
#[cfg(feature = "arithmetic")]
use elliptic_curve::{ff::PrimeField, ops::Invert, FieldBytes, ProjectiveArithmetic, Scalar};
#[cfg(feature = "arithmetic")]
use signature::Error;
#[cfg(feature = "digest")]
use crate::CheckSignatureBytes;
#[cfg(feature = "digest")]
use signature::{digest::Digest, PrehashSignature};
#[cfg(any(feature = "arithmetic", feature = "digest"))]
use crate::Signature;
#[cfg(any(feature = "arithmetic", feature = "digest"))]
use elliptic_curve::{generic_array::ArrayLength, weierstrass::Curve};
#[cfg(feature = "arithmetic")]
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
pub trait SignPrimitive<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
fn try_sign_prehashed<K: Borrow<Scalar<C>> + Invert<Output = Scalar<C>>>(
&self,
ephemeral_scalar: &K,
hashed_msg: &Scalar<C>,
) -> Result<Signature<C>, Error>;
}
#[cfg(feature = "arithmetic")]
#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
pub trait VerifyPrimitive<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
fn verify_prehashed(
&self,
hashed_msg: &Scalar<C>,
signature: &Signature<C>,
) -> Result<(), Error>;
}
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
pub trait DigestPrimitive: Curve {
type Digest: Digest;
}
#[cfg(feature = "digest")]
impl<C> PrehashSignature for Signature<C>
where
C: DigestPrimitive + CheckSignatureBytes,
<C::FieldSize as core::ops::Add>::Output: ArrayLength<u8>,
{
type Digest = C::Digest;
}