History

crypto: blake2s - optimize blake2s initialization

If no key was provided, then don't waste time initializing the block buffer, as its initial contents won't be used. Also, make crypto_blake2s_init() and blake2s() call a single internal function __blake2s_init() which treats the key as optional, rather than conditionally calling blake2s_init() or blake2s_init_key(). This reduces the compiled code size, as previously both blake2s_init() and blake2s_init_key() were being inlined into these two callers, except when the key size passed to blake2s() was a compile-time constant. These optimizations aren't that significant for BLAKE2s. However, the equivalent optimizations will be more significant for BLAKE2b, as everything is twice as big in BLAKE2b. And it's good to keep things consistent rather than making optimizations for BLAKE2b but not BLAKE2s.

Eric Biggers committed 5 years ago

Commit 42ad8cf1 parent 8c4a93a2 files · +28 −30Browse files

Showing the changes to include/crypto/internal (1 of 2 files). Show all

Unified · Split

include/crypto/internal/blake2s.h+1−4
@@ -93,10 +93,7 @@ static inline int crypto_blake2s_init(struct shash_desc *desc) · 92 unmodified lines
93 struct blake2s_state *state = shash_desc_ctx(desc);93 struct blake2s_state *state = shash_desc_ctx(desc);
94 unsigned int outlen = crypto_shash_digestsize(desc->tfm);94 unsigned int outlen = crypto_shash_digestsize(desc->tfm);
95 95
96 if (tctx->keylen)96 __blake2s_init(state, outlen, tctx->key, tctx->keylen);
97 blake2s_init_key(state, outlen, tctx->key, tctx->keylen);
98 else
99 blake2s_init(state, outlen);
100 return 0;97 return 0;
101}98}
102 99

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t