Skip to content

Commit d37b453

Browse files
e2e_tests: Add sign_verify test for when sig = NULL
According to: https://www.openssl.org/docs/man3.0/man7/provider-signature.html "If sig is NULL then the maximum length of the signature should be written to *siglen." * Add some checks to test this functionality Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
1 parent 4791d4a commit d37b453

File tree

1 file changed

+33
-1
lines changed
  • parsec-openssl-provider-shared/e2e_tests/tests

1 file changed

+33
-1
lines changed

parsec-openssl-provider-shared/e2e_tests/tests/sign.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fn sign_verify(
2121
sign_algorithm: AsymmetricSignature,
2222
key_type: &[u8],
2323
) -> Result<(), Openssl2Error> {
24+
// These are a backup to be used with different modalities of EVP_PKEY_sign
25+
let mut other_signature: Vec<u8> = vec![0; signature.len()];
26+
let mut other_len = signature.len();
27+
2428
let provider_path = String::from("../../target/debug/");
2529
let provider_name = String::from("libparsec_openssl_provider_shared");
2630

@@ -43,10 +47,21 @@ fn sign_verify(
4347
PARSEC_PROVIDER_DFLT_PROPERTIES.as_ptr() as *const ::std::os::raw::c_char,
4448
);
4549

46-
let mut sign_len = signature.len();
50+
let mut sign_len = 0;
4751

4852
// Initialize and perform signing operation using EVP interfaces
4953
openssl_returns_1(EVP_PKEY_sign_init(evp_ctx)).unwrap();
54+
55+
openssl_returns_1(EVP_PKEY_sign(
56+
evp_ctx,
57+
std::ptr::null_mut(),
58+
&mut sign_len,
59+
hash.as_ptr(),
60+
hash.len(),
61+
))
62+
.unwrap();
63+
assert_eq!(sign_len, signature.len());
64+
5065
openssl_returns_1(EVP_PKEY_sign(
5166
evp_ctx,
5267
signature.as_mut_ptr(),
@@ -56,6 +71,15 @@ fn sign_verify(
5671
))
5772
.unwrap();
5873

74+
openssl_returns_1(EVP_PKEY_sign(
75+
evp_ctx,
76+
other_signature.as_mut_ptr(),
77+
&mut other_len,
78+
hash.as_ptr(),
79+
hash.len(),
80+
))
81+
.unwrap();
82+
5983
EVP_PKEY_free(parsec_pkey);
6084
}
6185

@@ -64,6 +88,14 @@ fn sign_verify(
6488
client
6589
.psa_verify_hash(key_name, &hash, sign_algorithm, signature)
6690
.unwrap();
91+
client
92+
.psa_verify_hash(
93+
key_name,
94+
&hash,
95+
sign_algorithm,
96+
other_signature.as_mut_slice(),
97+
)
98+
.unwrap();
6799
Ok(())
68100
}
69101

0 commit comments

Comments
 (0)