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 undefined behaviour of AES cipher #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mahairod
Copy link

Fix undefined behaviour of AES cipher

@monich
Copy link
Owner

monich commented Dec 22, 2024

Are you sure that AES_set_encrypt_key can possibly fail here? AFAICT the only reason for the failure is the wrong key size but it can't be wrong because the size is checked when the key gets created.

@mahairod
Copy link
Author

mahairod commented Dec 22, 2024

Are you sure that AES_set_encrypt_key can possibly fail here? AFAICT the only reason for the failure is the wrong key size but it can't be wrong because the size is checked when the key gets created.

As I said earlier in foil repo, this can happen (to be exact: should happen) if your libcrypto implementation behaves very strangely. For example if it does not behave at all, because it was not loaded.

@monich
Copy link
Owner

monich commented Dec 22, 2024

OK, if you're sure that this can happen, then the next question - how this can happen. Ideally, I'd prefer a test case added to test_cipher_aes demonstrating the failure and the recovery. foil_openssl_cipher_aes_decrypt.c has 100% test coverage and I'd like to keep it that way.

I actually tried to write a test case myself but couldn't find a way to reproduce this failure.

@mahairod
Copy link
Author

mahairod commented Dec 22, 2024

OK, if you're sure that this can happen, then the next question - how this can happen. Ideally, I'd prefer a test case added to test_cipher_aes demonstrating the failure and the recovery. foil_openssl_cipher_aes_decrypt.c has 100% test coverage and I'd like to keep it that way.

I actually tried to write a test case myself but couldn't find a way to reproduce this failure.

Very simple case: remove libcypto: mv /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.10_; mv /usr/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1_

To be clear: the reason we should check error here is your unwillingness to fail fast during loading libcrypto. If libcrypto is not loaded AND you terminate app as a consequence this check is not neseccary. But you prefer to treat fatal loading errors as warnings.

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.

2 participants