1use ecdsa::{
2 hazmat::{DigestPrimitive, SignPrimitive},
3 SignatureSize,
4};
5use primeorder::{
6 elliptic_curve::{
7 generic_array::ArrayLength, ops::Reduce, CurveArithmetic, FieldBytes, PrimeCurve,
8 },
9 PrimeField,
10};
11
12use crate::{
13 curve16::TinyCurve16,
14 curve32::TinyCurve32,
15 curve64::TinyCurve64,
16 hash::TinyHash,
17 prime_field::FieldElement,
18 traits::{Modulus, PrimeFieldConstants, PrimitiveUint},
19};
20
21impl<C, T, const M: u64> SignPrimitive<C> for FieldElement<T, M>
22where
23 T: PrimitiveUint,
24 Modulus<T, M>: PrimeFieldConstants<T>,
25 C: PrimeCurve + CurveArithmetic<Scalar = Self>,
26 SignatureSize<C>: ArrayLength<u8>,
27 Self: Reduce<C::Uint, Bytes = FieldBytes<C>>
28 + PrimeField<Repr = FieldBytes<C>>
29 + Into<FieldBytes<C>>,
30{
31}
32
33impl DigestPrimitive for TinyCurve16 {
34 type Digest = TinyHash<2>;
35}
36
37impl DigestPrimitive for TinyCurve32 {
38 type Digest = TinyHash<4>;
39}
40
41impl DigestPrimitive for TinyCurve64 {
42 type Digest = TinyHash<8>;
43}
44
45#[cfg(test)]
46mod tests {
47 use ecdsa::SigningKey;
48 use rand_core::OsRng;
49
50 use crate::TinyCurve64;
51
52 #[test]
53 fn sign() {
54 let prehash = b"12345678";
55 let sk = SigningKey::<TinyCurve64>::random(&mut OsRng);
56 let _signature = sk.sign_prehash_recoverable(prehash);
57 }
58}