diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2018-06-19 18:34:33 +0300 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2018-06-19 19:29:25 +0300 |
commit | ca21a24808efa5d562ac91f683504ae0d6dfa69f (patch) | |
tree | b0088b2bfbe08948d4275e9036e7fdce9adbb8e4 /cipher/twofish.c | |
parent | b6e6ace324440f564df664e27f8276ef01f76795 (diff) | |
download | libgcrypt-ca21a24808efa5d562ac91f683504ae0d6dfa69f.tar.gz |
Pass cipher object pointer to setkey functions
* cipher/cipher.c (cipher_setkey): Pass cipher object pointer to
cipher's setkey function.
* cipher/arcfour.c: Add gcry_cipher_hd_t parameter for setkey
functions and update selftests to pass NULL pointer.
* cipher/blowfish.c: Ditto.
* cipher/camellia-glue.c: Ditto.
* cipher/cast5.c: Ditto.
* cipher/chacha20.c: Ditto.
* cipher/cipher-selftest.c: Ditto.
* cipher/des.c: Ditto.
* cipher/gost28147.c: Ditto.
* cipher/idea.c: Ditto.
* cipher/rfc2268.c: Ditto.
* cipher/rijndael.c: Ditto.
* cipher/salsa20.c: Ditto.
* cipher/seed.c: Ditto.
* cipher/serpent.c: Ditto.
* cipher/twofish.c: Ditto.
* src/cipher-proto.h: Ditto.
--
This allows setkey function to replace bulk cipher operations
with faster alternative.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/twofish.c')
-rw-r--r-- | cipher/twofish.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/cipher/twofish.c b/cipher/twofish.c index 48feaae9..0d187bda 100644 --- a/cipher/twofish.c +++ b/cipher/twofish.c @@ -734,12 +734,15 @@ do_twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen) } static gcry_err_code_t -twofish_setkey (void *context, const byte *key, unsigned int keylen) +twofish_setkey (void *context, const byte *key, unsigned int keylen, + gcry_cipher_hd_t hd) { TWOFISH_context *ctx = context; unsigned int hwfeatures = _gcry_get_hw_features (); int rc; + (void)hd; + rc = do_twofish_setkey (ctx, key, keylen); #ifdef USE_AVX2 @@ -1623,7 +1626,7 @@ selftest (void) 0x05, 0x93, 0x1C, 0xB6, 0xD4, 0x08, 0xE7, 0xFA }; - twofish_setkey (&ctx, key, sizeof(key)); + twofish_setkey (&ctx, key, sizeof(key), NULL); twofish_encrypt (&ctx, scratch, plaintext); if (memcmp (scratch, ciphertext, sizeof (ciphertext))) return "Twofish-128 test encryption failed."; @@ -1631,7 +1634,7 @@ selftest (void) if (memcmp (scratch, plaintext, sizeof (plaintext))) return "Twofish-128 test decryption failed."; - twofish_setkey (&ctx, key_256, sizeof(key_256)); + twofish_setkey (&ctx, key_256, sizeof(key_256), NULL); twofish_encrypt (&ctx, scratch, plaintext_256); if (memcmp (scratch, ciphertext_256, sizeof (ciphertext_256))) return "Twofish-256 test encryption failed."; @@ -1713,13 +1716,13 @@ main() /* Encryption test. */ for (i = 0; i < 125; i++) { - twofish_setkey (&ctx, buffer[0], sizeof (buffer[0])); + twofish_setkey (&ctx, buffer[0], sizeof (buffer[0]), NULL); for (j = 0; j < 1000; j++) twofish_encrypt (&ctx, buffer[2], buffer[2]); - twofish_setkey (&ctx, buffer[1], sizeof (buffer[1])); + twofish_setkey (&ctx, buffer[1], sizeof (buffer[1]), NULL); for (j = 0; j < 1000; j++) twofish_encrypt (&ctx, buffer[3], buffer[3]); - twofish_setkey (&ctx, buffer[2], sizeof (buffer[2])*2); + twofish_setkey (&ctx, buffer[2], sizeof (buffer[2])*2, NULL); for (j = 0; j < 1000; j++) { twofish_encrypt (&ctx, buffer[0], buffer[0]); twofish_encrypt (&ctx, buffer[1], buffer[1]); @@ -1731,15 +1734,15 @@ main() /* Decryption test. */ for (i = 0; i < 125; i++) { - twofish_setkey (&ctx, buffer[2], sizeof (buffer[2])*2); + twofish_setkey (&ctx, buffer[2], sizeof (buffer[2])*2, NULL); for (j = 0; j < 1000; j++) { twofish_decrypt (&ctx, buffer[0], buffer[0]); twofish_decrypt (&ctx, buffer[1], buffer[1]); } - twofish_setkey (&ctx, buffer[1], sizeof (buffer[1])); + twofish_setkey (&ctx, buffer[1], sizeof (buffer[1]), NULL); for (j = 0; j < 1000; j++) twofish_decrypt (&ctx, buffer[3], buffer[3]); - twofish_setkey (&ctx, buffer[0], sizeof (buffer[0])); + twofish_setkey (&ctx, buffer[0], sizeof (buffer[0]), NULL); for (j = 0; j < 1000; j++) twofish_decrypt (&ctx, buffer[2], buffer[2]); } |