Skip to content

Commit 9b4ecc2

Browse files
committed
Implement VerifySignature API
This is needed for multiplart ML-DSA signature verifications Signed-off-by: Jakub Jelen <jjelen@redhat.com>
1 parent 24e2553 commit 9b4ecc2

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

cryptoki/src/session/signing_macing.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,67 @@ impl Session {
194194

195195
Ok(())
196196
}
197+
198+
/// Initialize Signature verification operation, by including the signature at initialization
199+
pub fn verify_signature_init(
200+
&self,
201+
mechanism: &Mechanism,
202+
key: ObjectHandle,
203+
signature: &[u8],
204+
) -> Result<()> {
205+
let mut mechanism: CK_MECHANISM = mechanism.into();
206+
207+
unsafe {
208+
Rv::from(get_pkcs11!(self.client(), C_VerifySignatureInit)(
209+
self.handle(),
210+
&mut mechanism as CK_MECHANISM_PTR,
211+
key.handle(),
212+
signature.as_ptr() as *mut u8,
213+
signature.len().try_into()?,
214+
))
215+
.into_result(Function::VerifySignatureInit)?;
216+
}
217+
218+
Ok(())
219+
}
220+
221+
/// Verify Signature in single-part operation
222+
pub fn verify_signature(&self, data: &[u8]) -> Result<()> {
223+
unsafe {
224+
Rv::from(get_pkcs11!(self.client(), C_VerifySignature)(
225+
self.handle(),
226+
data.as_ptr() as *mut u8,
227+
data.len().try_into()?,
228+
))
229+
.into_result(Function::VerifySignature)?;
230+
}
231+
232+
Ok(())
233+
}
234+
235+
/// continue multi-part Verify Signature operation
236+
pub fn verify_signature_update(&self, data: &[u8]) -> Result<()> {
237+
unsafe {
238+
Rv::from(get_pkcs11!(self.client(), C_VerifySignatureUpdate)(
239+
self.handle(),
240+
data.as_ptr() as *mut u8,
241+
data.len().try_into()?,
242+
))
243+
.into_result(Function::VerifySignatureUpdate)?;
244+
}
245+
246+
Ok(())
247+
}
248+
249+
/// finalize multi-part Verify Signature operation
250+
pub fn verify_signature_final(&self) -> Result<()> {
251+
unsafe {
252+
Rv::from(get_pkcs11!(self.client(), C_VerifySignatureFinal)(
253+
self.handle(),
254+
))
255+
.into_result(Function::VerifySignatureFinal)?;
256+
}
257+
258+
Ok(())
259+
}
197260
}

0 commit comments

Comments
 (0)