Skip to content

Commit 62260d8

Browse files
committed
encryption/decryption: Workaround tokens finalizing operation when there is nothing to return
The NSS softokn finalizes the multipart operation even though the NULL return argument was passed. Signed-off-by: Jakub Jelen <jjelen@redhat.com>
1 parent d09e11e commit 62260d8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cryptoki/src/session/decryption.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ impl Session {
125125
.into_result(Function::DecryptFinal)?;
126126
}
127127

128+
// Some pkcs11 modules might finalize the operation when there
129+
// no more output even if we pass in NULL.
130+
if data_len == 0 {
131+
return Ok(Vec::new());
132+
}
133+
128134
let mut data = vec![0; data_len.try_into()?];
129135

130136
unsafe {

cryptoki/src/session/encryption.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ impl Session {
124124
.into_result(Function::EncryptFinal)?;
125125
}
126126

127+
// Some pkcs11 modules might finalize the operation when there
128+
// no more output even if we pass in NULL.
129+
if encrypted_data_len == 0 {
130+
return Ok(Vec::new());
131+
}
132+
127133
let mut encrypted_data = vec![0; encrypted_data_len.try_into()?];
128134

129135
unsafe {

0 commit comments

Comments
 (0)