| 81 | } |
| 82 | |
| 83 | pub fn verify( |
| 84 | &self, |
| 85 | messages: &[G::ScalarField], |
| 86 | user_public_key: &UserPublicKey<G>, |
| 87 | sk: impl AsRef<G::ScalarField>, |
| 88 | params: impl AsRef<MACParams<G>>, |
| 89 | ) -> Result<(), KVACError> { |
| 90 | if messages.is_empty() { |
| 91 | return Err(KVACError::NoMessageGiven); |
| 92 | } |
| 93 | let params = params.as_ref(); |
| 94 | expect_equality!( |
| 95 | messages.len(), |
| 96 | params.supported_message_count(), |
| 97 | KVACError::MessageCountIncompatibleWithMACParams |
| 98 | ); |
| 99 | let b = params.b(messages.iter().enumerate(), user_public_key)?; |
| 100 | let e_plus_x_inv = (self.e + sk.as_ref()) |
| 101 | .inverse() |
| 102 | .ok_or(KVACError::CannotInvert0)?; |
| 103 | if (b * e_plus_x_inv).into_affine() != self.A { |
| 104 | return Err(KVACError::InvalidMAC); |
| 105 | } |
| 106 | Ok(()) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | impl<G: AffineRepr> ProofOfValidityOfMAC<G> { |