ring/ec/curve25519/ed25519/
verification.rs1use super::{super::ops::*, eddsa_digest};
18use crate::{error, sealed, signature};
19
20pub struct EdDSAParameters;
22
23impl core::fmt::Debug for EdDSAParameters {
24 fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
25 write!(f, "ring::signature::ED25519")
26 }
27}
28
29pub static ED25519: EdDSAParameters = EdDSAParameters {};
35
36impl signature::VerificationAlgorithm for EdDSAParameters {
37 fn verify(
38 &self,
39 public_key: untrusted::Input,
40 msg: untrusted::Input,
41 signature: untrusted::Input,
42 ) -> Result<(), error::Unspecified> {
43 let public_key: &[u8; ELEM_LEN] = public_key.as_slice_less_safe().try_into()?;
44 let (signature_r, signature_s) = signature.read_all(error::Unspecified, |input| {
45 let signature_r: &[u8; ELEM_LEN] = input
46 .read_bytes(ELEM_LEN)?
47 .as_slice_less_safe()
48 .try_into()?;
49 let signature_s: &[u8; SCALAR_LEN] = input
50 .read_bytes(SCALAR_LEN)?
51 .as_slice_less_safe()
52 .try_into()?;
53 Ok((signature_r, signature_s))
54 })?;
55
56 let signature_s = Scalar::from_bytes_checked(*signature_s)?;
57
58 let mut a = ExtPoint::from_encoded_point_vartime(public_key)?;
59 a.invert_vartime();
60
61 let h_digest = eddsa_digest(signature_r, public_key, msg.as_slice_less_safe());
62 let h = Scalar::from_sha512_digest_reduced(h_digest);
63
64 let mut r = Point::new_at_infinity();
65 unsafe { x25519_ge_double_scalarmult_vartime(&mut r, &h, &a, &signature_s) };
66 let r_check = r.into_encoded_point();
67 if *signature_r != r_check {
68 return Err(error::Unspecified);
69 }
70 Ok(())
71 }
72}
73
74impl sealed::Sealed for EdDSAParameters {}
75
76prefixed_extern! {
77 fn x25519_ge_double_scalarmult_vartime(
78 r: &mut Point,
79 a_coeff: &Scalar,
80 a: &ExtPoint,
81 b_coeff: &Scalar,
82 );
83}