diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2022-05-08 22:02:30 +0300 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2022-05-11 20:14:33 +0300 |
commit | a9700956361d280746f2bffe94cbdb72c95eb3ed (patch) | |
tree | 2904eeba74f056890b54578097a17493107d0c69 /cipher/sm4.c | |
parent | 9ab61ba24b72bc109b7578a7868716910d2ea9d1 (diff) | |
download | libgcrypt-a9700956361d280746f2bffe94cbdb72c95eb3ed.tar.gz |
cipher: move CBC/CFB/CTR self-tests to tests/basic
* cipher/Makefile.am: Remove 'cipher-selftest.c' and 'cipher-selftest.h'.
* cipher/cipher-selftest.c: Remove (refactor these tests to
tests/basic.c).
* cipher/cipher-selftest.h: Remove.
* cipher/blowfish.c (selftest_ctr, selftest_cbc, selftest_cfb): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/camellia-glue.c (selftest_ctr_128, selftest_cbc_128)
(selftest_cfb_128): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/cast5.c (selftest_ctr, selftest_cbc, selftest_cfb): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/des.c (bulk_selftest_setkey, selftest_ctr, selftest_cbc)
(selftest_cfb): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/rijndael.c (selftest_basic_128, selftest_basic_192)
(selftest_basic_256): Allocate context from stack instead of heap and
handle alignment manually.
(selftest_ctr_128, selftest_cbc_128, selftest_cfb_128): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/serpent.c (selftest_ctr_128, selftest_cbc_128)
(selftest_cfb_128): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/sm4.c (selftest_ctr_128, selftest_cbc_128)
(selftest_cfb_128): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* cipher/twofish.c (selftest_ctr, selftest_cbc, selftest_cfb): Remove.
(selftest): Remove CTR/CBC/CFB bulk self-tests.
* tests/basic.c (buf_xor, cipher_cbc_bulk_test, buf_xor_2dst)
(cipher_cfb_bulk_test, cipher_ctr_bulk_test): New.
(check_ciphers): Run cipher_cbc_bulk_test(), cipher_cfb_bulk_test() and
cipher_ctr_bulk_test() for block ciphers.
---
CBC/CFB/CTR bulk self-tests are quite computationally heavy and
slow down use cases where application opens cipher context once,
does processing and exits. Better place for these tests is in
`tests/basic`.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/sm4.c')
-rw-r--r-- | cipher/sm4.c | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/cipher/sm4.c b/cipher/sm4.c index 7c7bc1ff..5f8bf224 100644 --- a/cipher/sm4.c +++ b/cipher/sm4.c @@ -29,7 +29,6 @@ #include "cipher.h" #include "bufhelp.h" #include "cipher-internal.h" -#include "cipher-selftest.h" #include "bulkhelp.h" /* Helper macro to force alignment to 64 bytes. */ @@ -1429,51 +1428,11 @@ _gcry_sm4_ocb_auth (gcry_cipher_hd_t c, const void *abuf_arg, size_t nblocks) return 0; } -/* Run the self-tests for SM4-CTR, tests IV increment of bulk CTR - encryption. Returns NULL on success. */ -static const char* -selftest_ctr_128 (void) -{ - const int nblocks = 16 - 1; - const int blocksize = 16; - const int context_size = sizeof(SM4_context); - - return _gcry_selftest_helper_ctr("SM4", &sm4_setkey, - &sm4_encrypt, nblocks, blocksize, context_size); -} - -/* Run the self-tests for SM4-CBC, tests bulk CBC decryption. - Returns NULL on success. */ -static const char* -selftest_cbc_128 (void) -{ - const int nblocks = 16 - 1; - const int blocksize = 16; - const int context_size = sizeof(SM4_context); - - return _gcry_selftest_helper_cbc("SM4", &sm4_setkey, - &sm4_encrypt, nblocks, blocksize, context_size); -} - -/* Run the self-tests for SM4-CFB, tests bulk CFB decryption. - Returns NULL on success. */ -static const char* -selftest_cfb_128 (void) -{ - const int nblocks = 16 - 1; - const int blocksize = 16; - const int context_size = sizeof(SM4_context); - - return _gcry_selftest_helper_cfb("SM4", &sm4_setkey, - &sm4_encrypt, nblocks, blocksize, context_size); -} - static const char * sm4_selftest (void) { SM4_context ctx; byte scratch[16]; - const char *r; static const byte plaintext[16] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, @@ -1498,15 +1457,6 @@ sm4_selftest (void) if (memcmp (scratch, plaintext, sizeof (plaintext))) return "SM4 test decryption failed."; - if ( (r = selftest_ctr_128 ()) ) - return r; - - if ( (r = selftest_cbc_128 ()) ) - return r; - - if ( (r = selftest_cfb_128 ()) ) - return r; - return NULL; } |