Home GnuPG

Optimize Blowfish weak key check
8e1c0f9b894cUnpublished

Unpublished Commit ยท Learn More

Not On Permanent Ref: This commit is not an ancestor of any permanent ref.

Description

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>

Details

Provenance
jukiviliAuthored on Nov 4 2013, 12:32 PM
Parents
rC2590a5df6f5f: Fix __builtin_bswap32/64 checks
Branches
Unknown
Tags
Unknown

Event Timeline

Jussi Kivilinna <jussi.kivilinna@iki.fi> committed rC8e1c0f9b894c: Optimize Blowfish weak key check (authored by Jussi Kivilinna <jussi.kivilinna@iki.fi>).Nov 6 2013, 6:22 PM