]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit - crypto/ofb.c
crypto: ofb - fix handling partial blocks and make thread-safe
authorEric Biggers <ebiggers@google.com>
Fri, 4 Jan 2019 04:16:12 +0000 (20:16 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 11 Jan 2019 06:16:57 +0000 (14:16 +0800)
commitb3e3e2db7de4a1ffe8845876c3520b866cd48de1
tree054f67cb1ec199892e706dabe17e95b7cd2b6a87
parent6c2e322b3621dc8be72e5c86d4fdb587434ba625
crypto: ofb - fix handling partial blocks and make thread-safe

Fix multiple bugs in the OFB implementation:

1. It stored the per-request state 'cnt' in the tfm context, which can be
   used by multiple threads concurrently (e.g. via AF_ALG).
2. It didn't support messages not a multiple of the block cipher size,
   despite being a stream cipher.
3. It didn't set cra_blocksize to 1 to indicate it is a stream cipher.

To fix these, set the 'chunksize' property to the cipher block size to
guarantee that when walking through the scatterlist, a partial block can
only occur at the end.  Then change the implementation to XOR a block at
a time at first, then XOR the partial block at the end if needed.  This
is the same way CTR and CFB are implemented.  As a bonus, this also
improves performance in most cases over the current approach.

Fixes: e497c51896b3 ("crypto: ofb - add output feedback mode")
Cc: <stable@vger.kernel.org> # v4.20+
Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/ofb.c
crypto/testmgr.h