Optimize Blowfish weak key check
* cipher/blowfish.c (hashset_elem, val_to_hidx, add_val): New. (do_bf_setkey): Use faster algorithm for detecting weak keys. (bf_setkey): Move stack burning to do_bf_setkey.
Patch optimizes the weak key check for Blowfish. Instead of iterating through
sbox-tables for duplicates, insert values to hash-set and detect collisions.
Old check code was taking slightly longer time than the actual key setup of
Blowfish, which by itself is already quite slow.
After:
$ tests/benchmark --cipher-with-keysetup --cipher-repetitions 10 cipher blowfish
Running each test 10 times.
ECB/Stream CBC CFB OFB CTR CCM --------------- --------------- --------------- --------------- --------------- ---------------
BLOWFISH 410ms 440ms 430ms 370ms 440ms 370ms 430ms 440ms 370ms 370ms - -
Before:
$ tests/benchmark --cipher-with-keysetup --cipher-repetitions 10 cipher blowfish
Running each test 10 times.
ECB/Stream CBC CFB OFB CTR CCM --------------- --------------- --------------- --------------- --------------- ---------------
BLOWFISH 780ms 770ms 780ms 730ms 780ms 730ms 780ms 790ms 720ms 730ms - -
Without key-setup:
$ tests/benchmark --cipher-repetitions 10 cipher blowfish
Running each test 10 times.
ECB/Stream CBC CFB OFB CTR CCM --------------- --------------- --------------- --------------- --------------- ---------------
BLOWFISH 70ms 70ms 80ms 30ms 80ms 30ms 80ms 90ms 20ms 30ms - -
- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>