-
-
Notifications
You must be signed in to change notification settings - Fork 652
src/sage/crypto/block_cipher/des.py: run fewer DES test cases #40475
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We have one DES doctest that checks all of the test vectors given in its reference, but checking them is slow: 2025-07-24T02:20:21.8128567Z ##[warning]slow doctest: 2025-07-24T02:20:21.8129623Z for K, P, C in test: # long time ... 2025-07-24T02:20:21.8131458Z Test ran for 31.91s cpu, 31.97s wall 2025-07-24T02:20:21.8131872Z Check ran for 0.00s cpu, 0.00s wall Rather than check them all (there are 171 in total), we may check only a random subset. This commit takes a random sample of 5 test vectors, and checks those. This speeds up the test significantly and should still detect problems.
optimizing this looks hard enough. Also it's just a toy implementation anyway (use pycryptodome for any serious purpose) |
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Jul 26, 2025
sagemathgh-40475: src/sage/crypto/block_cipher/des.py: run fewer DES test cases We have one DES doctest that checks all of the test vectors given in its reference, but checking them is slow: ``` 2025-07-24T02:20:21.8128567Z ##[warning]slow doctest: 2025-07-24T02:20:21.8129623Z for K, P, C in test: # long time 2025-07-24T02:20:21.8130081Z if des.encrypt(P, K) != C or des.decrypt(C, K) != P: 2025-07-24T02:20:21.8130602Z print("DES tests failed for K=0x%s, P=0x%s, C=0x%s" % 2025-07-24T02:20:21.8131064Z (K.hex(), P.hex(), C.hex())) 2025-07-24T02:20:21.8131458Z Test ran for 31.91s cpu, 31.97s wall ``` Rather than check them all (there are 171 in total), we may check only a random subset. This commit takes a random sample of 5 test vectors, and checks those. This speeds up the test significantly and should still detect problems. URL: sagemath#40475 Reported by: Michael Orlitzky Reviewer(s):
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Jul 27, 2025
sagemathgh-40475: src/sage/crypto/block_cipher/des.py: run fewer DES test cases We have one DES doctest that checks all of the test vectors given in its reference, but checking them is slow: ``` 2025-07-24T02:20:21.8128567Z ##[warning]slow doctest: 2025-07-24T02:20:21.8129623Z for K, P, C in test: # long time 2025-07-24T02:20:21.8130081Z if des.encrypt(P, K) != C or des.decrypt(C, K) != P: 2025-07-24T02:20:21.8130602Z print("DES tests failed for K=0x%s, P=0x%s, C=0x%s" % 2025-07-24T02:20:21.8131064Z (K.hex(), P.hex(), C.hex())) 2025-07-24T02:20:21.8131458Z Test ran for 31.91s cpu, 31.97s wall ``` Rather than check them all (there are 171 in total), we may check only a random subset. This commit takes a random sample of 5 test vectors, and checks those. This speeds up the test significantly and should still detect problems. URL: sagemath#40475 Reported by: Michael Orlitzky Reviewer(s):
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Jul 28, 2025
sagemathgh-40475: src/sage/crypto/block_cipher/des.py: run fewer DES test cases We have one DES doctest that checks all of the test vectors given in its reference, but checking them is slow: ``` 2025-07-24T02:20:21.8128567Z ##[warning]slow doctest: 2025-07-24T02:20:21.8129623Z for K, P, C in test: # long time 2025-07-24T02:20:21.8130081Z if des.encrypt(P, K) != C or des.decrypt(C, K) != P: 2025-07-24T02:20:21.8130602Z print("DES tests failed for K=0x%s, P=0x%s, C=0x%s" % 2025-07-24T02:20:21.8131064Z (K.hex(), P.hex(), C.hex())) 2025-07-24T02:20:21.8131458Z Test ran for 31.91s cpu, 31.97s wall ``` Rather than check them all (there are 171 in total), we may check only a random subset. This commit takes a random sample of 5 test vectors, and checks those. This speeds up the test significantly and should still detect problems. URL: sagemath#40475 Reported by: Michael Orlitzky Reviewer(s):
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Jul 29, 2025
sagemathgh-40475: src/sage/crypto/block_cipher/des.py: run fewer DES test cases We have one DES doctest that checks all of the test vectors given in its reference, but checking them is slow: ``` 2025-07-24T02:20:21.8128567Z ##[warning]slow doctest: 2025-07-24T02:20:21.8129623Z for K, P, C in test: # long time 2025-07-24T02:20:21.8130081Z if des.encrypt(P, K) != C or des.decrypt(C, K) != P: 2025-07-24T02:20:21.8130602Z print("DES tests failed for K=0x%s, P=0x%s, C=0x%s" % 2025-07-24T02:20:21.8131064Z (K.hex(), P.hex(), C.hex())) 2025-07-24T02:20:21.8131458Z Test ran for 31.91s cpu, 31.97s wall ``` Rather than check them all (there are 171 in total), we may check only a random subset. This commit takes a random sample of 5 test vectors, and checks those. This speeds up the test significantly and should still detect problems. URL: sagemath#40475 Reported by: Michael Orlitzky Reviewer(s):
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have one DES doctest that checks all of the test vectors given in its reference, but checking them is slow:
Rather than check them all (there are 171 in total), we may check only a random subset. This commit takes a random sample of 5 test vectors, and checks those. This speeds up the test significantly and should still detect problems.