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

The CTR test does not test decryption #78

Closed
amosnier opened this issue Dec 8, 2017 · 3 comments
Closed

The CTR test does not test decryption #78

amosnier opened this issue Dec 8, 2017 · 3 comments

Comments

@amosnier
Copy link

amosnier commented Dec 8, 2017

Hi,

In the CTR test (test.c), the test_xcrypt_ctr() function is invoked twice, once for encryption, once for decryption. However, the only difference between both invocations is the printed string, not the transformed data. Both invocations transform the in buffer and verify that the result is equal to the out buffer. Instead, the second invocation should transform (decrypt) the out buffer, and verify that the result is equal to the in buffer.

The change in code to achieve that is trivial, and fortunately, that test too passes on my old 16-bit DSP. :-)

Thanks again for sharing.

Best regards,

Alain Mosnier

@kokke
Copy link
Owner

kokke commented Dec 8, 2017

Hi @amosnier -

When I uploaded the CTR-mode test code, I was pondering how long before someone would comment on that :D

The intuitive thing would be to decrypt the cipher text and check for equivalence with the plain text.

However, in the NIST test-vectors from 800-38A the test-vectors are equal for encryption and decryption. Same input and output to test both encryption and decryption.

I have done a lot more testing than what is in test.c and indeed encryption and decryption in CTR (all all the other modes) works as advertised even though the test-file doesn't test very thoroughly.

The test-code is meant to be a quick way for users to verify against the NIST vectors.
It is not meant to convince you of correctness or robustness.

Thanks again for pointing this out :)

@kokke kokke closed this as completed Dec 8, 2017
@amosnier
Copy link
Author

amosnier commented Dec 8, 2017

Hi @kokke ,

Thanks for your answer. I realize that you are right when checking again SP 800-38A. The test strings are inverted between Encrypt and Decrypt, but so are the field names "Cyphertext" and "Plaintext". :-)

Not so intuitive.

Anyway, thanks again.

Best regards,

Alain Mosnier

@kokke
Copy link
Owner

kokke commented Dec 8, 2017

Hi @amosnier - yeah that surprised me as well when I implemented the test code :)

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

No branches or pull requests

2 participants