Skip to content
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 encryption and decyption for streams #170

Closed
wants to merge 2 commits into from

Conversation

lo1ol
Copy link

@lo1ol lo1ol commented Nov 18, 2020

Hello,

Our package depends on your package v. 4.1.1. Recently, we noticed that encryption and decryption doesn't work properly for streams. After viewing the sources, we've found the incorrect using of C_EncryptUpdate function inside Encrypt/Decrypt override for streams. The problem arises when length of output buffer doesn't equal to length of input buffer (such as inside my pkcs11 lib librtpkcs11ecp). So, I've creating a patch which resolve this problem by getting the length of the output buffer before encryption and decryption.

If the patch is right, I can create the same patch for 5.1.1 version (problem doesn't still resolve for it). But I'm waiting for that you will releases a new version 4.1.2 with this patch.

@jariq
Copy link
Member

jariq commented Nov 18, 2020

Thanks for the PR. I'll take a look at it soon:tm: 😉

@jariq jariq self-assigned this Nov 18, 2020
@lo1ol
Copy link
Author

lo1ol commented Dec 10, 2020

Hello, guys!

Did you not forget about issue?...

@jariq
Copy link
Member

jariq commented Dec 11, 2020

Nope. I'm on it 👍🏻

@jariq
Copy link
Member

jariq commented Dec 12, 2020

The problem arises...

@lo1ol can you please describe the problem in more details?
What encryption mechanism were you using?
Did C_EncryptUpdate throw an exception?
Was ciphertext (encryptedPart) longer than plaintext (part) ?

@lo1ol
Copy link
Author

lo1ol commented Dec 12, 2020

What encryption mechanism were you using?

The problem appears when I'm using CKM_GOST28147 mechanism and pass data using streams.

Was ciphertext (encryptedPart) longer than plaintext (part) ?

No.

Did C_EncryptUpdate throw an exception?

Yes. First iteration return zero length output buffer. And next iteration return the buffer with length more then partLen. I don’t know the reason of this behaviour, but the implementation of CKM_GOST28147 works this way.

@jariq
Copy link
Member

jariq commented Dec 12, 2020

So C_EncryptUpdate returned CKR_BUFFER_TOO_SMALL ?

@lo1ol
Copy link
Author

lo1ol commented Dec 12, 2020

I don't remember exact return code, but probably that.

@lo1ol
Copy link
Author

lo1ol commented Dec 12, 2020

You solution is more efficient:)

@jariq
Copy link
Member

jariq commented Dec 12, 2020

Can you please test my alternative implementation from stream-encryption branch and check whether it solves your problem with CKM_GOST28147? It should be more efficient for other mechanisms than code in this PR.

@lo1ol
Copy link
Author

lo1ol commented Dec 12, 2020

No problem. I'm not close to a computer right now. I will give you feedback tomorrow.

@lo1ol
Copy link
Author

lo1ol commented Dec 13, 2020

I have tested your solution. It's work!

@jariq
Copy link
Member

jariq commented Dec 13, 2020

Thanks for testing. I'll release fix asap ™️ 😉

@lo1ol
Copy link
Author

lo1ol commented Dec 13, 2020

Thank you so much!

@jariq
Copy link
Member

jariq commented Dec 13, 2020

Closing this PR as the problem was resolved in #172.

@jariq jariq closed this Dec 13, 2020
@jariq
Copy link
Member

jariq commented Dec 13, 2020

@lo1ol the fix is available in freshly published Pkcs11Interop 4.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants