Skip to content

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
merged 1 commit into from
Aug 2, 2025

Conversation

orlitzky
Copy link
Contributor

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.

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.
@user202729
Copy link
Contributor

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):
@vbraun vbraun merged commit 1a0520c into sagemath:develop Aug 2, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants