-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PKCS#11 C_Decrypt, C_Encrypt, C_Sign, C_SignFinal buffer output size. #1979
Fix PKCS#11 C_Decrypt, C_Encrypt, C_Sign, C_SignFinal buffer output size. #1979
Conversation
Actually I'm a little tired and it looks like this is actually a bug in botan and not the PKCS#11 module. Will update title and such. |
Codecov Report
@@ Coverage Diff @@
## master #1979 +/- ##
==========================================
+ Coverage 91.64% 91.64% +<.01%
==========================================
Files 533 533
Lines 57324 57323 -1
Branches 6083 6083
==========================================
Hits 52533 52533
+ Misses 4791 4790 -1
Continue to review full report at Codecov.
|
Section 5.2 of the spec states that there are two ways to call functions that return a variable-length buffer: 1. When the output buffer is NULL, an estimated size is returned (which may be larger than required). 2. When the output buffer is not NULL, the exact size must be returned. So only after the second call to C_Decrypt has the final output size been determined, and we must resize the output buffer.
0bf1325
to
a82fdf2
Compare
Copy & paste error on the title fixed :P, I should get some sleep before I hurt myself. |
@neusdan can you review? |
It looks like there are similar bugs in other places, so I'll add some commits here and update the title. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I have checked the specification. This change definitely makes sense. Unit tests with SoftHSM and a CardOS card were successful.
The spec does say that modules should set pulBufLen to the exact bytecount when pBuf is not NULL. However, some modules fail to do this and
it's easy to work around here.
EDIT: See below.
This is a contribution from Ribose Inc (@riboseinc).