-
Notifications
You must be signed in to change notification settings - Fork 803
Sym crypt hw #2473
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
Sym crypt hw #2473
Conversation
src/pkcs11/mechanism.c
Outdated
| sc_pkcs11_encrypt_init(sc_pkcs11_operation_t *operation, | ||
| struct sc_pkcs11_object *key) | ||
| { | ||
| struct signature_data *data; |
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.
The usage of signature_data is confusing here. If I see right, only the key part is used. Would it make sense to assign the key directly into the operation->priv_data? Or create generic operation_data if we envision there will be some more data needed to share between the functions?
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.
We already have same confusing name in sc_pkcs11_decrypt_init(). It doesn't make sense to fix this in this PR just because of the new operation sc_pkcs11_encrypt_init (), we have to fix it globally (so also for the function sc_pkcs11_decrypt_init ())
static CK_RV
sc_pkcs11_decrypt_init(sc_pkcs11_operation_t *operation,
struct sc_pkcs11_object *key)
{
struct signature_data *data;
CK_RV rv;
if (!(data = new_signature_data()))
return CKR_HOST_MEMORY;
Would it make sense to assign the key directly into the operation->priv_data?
This solution complicates the freeing of memory (in sc_pkcs11_new_fw_mechanism () we use mt-> release = sc_pkcs11_signature_release;)
It might be a good idea to rename struct signature_data to operation_data and similarly rename functions that operate with it: new_signature_data(), signature_data_release(), signature_data_buffer_append() and of course sc_pkcs11_signature_release().
The question is whether this renaming will not impair the readability of the code in sign and verify operations. I believe that this renaming should be done outside this PR.
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.
could you create a PR with the suggested fix to the naming?
|
Then it looks ok to me, even though I did not go into detail of the operations. One more thing, can you rebase on top of current master to get also CI results with OpenSSL 3.0? In any case, I would like also somebody else to go through this before merging. |
265e4ab to
3827515
Compare
|
Rebased, CI tests with openssl 3.0 and libressl are OK. This PR is designed so as not to interfere with current asymmetric operations in OpenSC. Code for symmetric decryption may affect asymmetric decipher operation and therefore decipher code is planned to be submitted as separate PR . Preliminary code for symmetric decipher is available here: https://github.com/popovec/OpenSC/tree/sym_crypt_hw_test Some details about implementation: Symmetric encrypt allow us to encrypt large amount of data, there is no way to accumulate all data in buffer and then encrypt them. The sc * functions must allow us to initialize encryption and then allow us to repetitive call (to update data) from However, only one version of C_EncryptInit is mapped to sc_pkcs15_encrypt_sym (...., NULL, 0, NULL,NULL) If the above conversion is unsatisfactory for some reason, I would be happy if someone suggests another way to map the pkcs11 function to the pkcs15 interface. |
src/pkcs11/mechanism.c
Outdated
| sc_pkcs11_encrypt_init(sc_pkcs11_operation_t *operation, | ||
| struct sc_pkcs11_object *key) | ||
| { | ||
| struct signature_data *data; |
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.
could you create a PR with the suggested fix to the naming?
Jakuje
left a comment
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.
thank you! Look good
Jakuje
left a comment
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.
I just went through the code and noticed only couple of formatting issues, which I would like to tackle before merging. You can use as a help the clang-format from #2017, but do not take every suggestion as a rule as we did not finalize the formatting rules yet.
initial implementation: pkcs#11: C_EncryptInit, C_Encrypt, C_EncryptUpdate, C_EncryptFinal pkcs#15: pkcs15_skey_encrypt, sc_pkcs15_encrypt_sym also implements: sc_encrypt_sym This code is inspired by: https://github.com/carblue/OpenSC-1/tree/sym_hw_encrypt
AES-ECB, AEC-CBC, AES-CBC-PAD Tested: MyEID 4.0.1, 4.5.5 card, pkcs11-tool --encrypt, 128 bit AES key (small file encryption by C_encrypt, and big file by C_EncryptUpdate and C_EncrytpFinal), all supported mechanisms: AES-ECB, AEC-CBC, AES-CBC-PAD.
modified: .github/test-oseid.sh
Old name (signature_data) was confusing, because this structure is already used in encrypt and decrypt operation. Related functions are also renamed.
|
Rebased, formating fixed to match definitions in
This is fixed by macro |
|
@frankmorgner do you have some more comments regarding this or can I merge this for the 0.23.0 release? |
|
This patch introduced two defects reported by "coverity scan". I'm not sure if these are false negative reports or if they are real bugs. I will look into both reported issues. |
symmetric encryption
New code:
pkcs#11: C_EncryptInit, C_Encrypt, C_EncryptUpdate, C_EncryptFinal
pkcs#15: pkcs15_skey_encrypt, sc_pkcs15_encrypt_sym
also implements: sc_encrypt_sym
MyEID driver: support for symmetric crypt
Tested: MyEID 4.0.1, 4.5.5 card, pkcs11-tool --encrypt, 128 bit AES key (small file encryption by C_encrypt, and big file by C_EncryptUpdate and C_EncrytpFinal), all supported mechanisms: AES-ECB, AEC-CBC, AES-CBC-PAD.