crypto: skcipher - Add internal state support
authorHerbert Xu <herbert@gondor.apana.org.au>
Mon, 27 Nov 2023 10:14:08 +0000 (18:14 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 8 Dec 2023 03:59:46 +0000 (11:59 +0800)
commit0ae4dcc1ebf63118364d540b84c70352e8b2b2a4
tree34e64203306550392bd1f459adf7cbfa953abfa2
parent412ac51ce0b8c5581b6ff57fff6501e905a5471f
crypto: skcipher - Add internal state support

Unlike chaining modes such as CBC, stream ciphers other than CTR
usually hold an internal state that must be preserved if the
operation is to be done piecemeal.  This has not been represented
in the API, resulting in the inability to split up stream cipher
operations.

This patch adds the basic representation of an internal state to
skcipher and lskcipher.  In the interest of backwards compatibility,
the default has been set such that existing users are assumed to
be operating in one go as opposed to piecemeal.

With the new API, each lskcipher/skcipher algorithm has a new
attribute called statesize.  For skcipher, this is the size of
the buffer that can be exported or imported similar to ahash.
For lskcipher, instead of providing a buffer of ivsize, the user
now has to provide a buffer of ivsize + statesize.

Each skcipher operation is assumed to be final as they are now,
but this may be overridden with a request flag.  When the override
occurs, the user may then export the partial state and reimport
it later.

For lskcipher operations this is reversed.  All operations are
not final and the state will be exported unless the FINAL bit is
set.  However, the CONT bit still has to be set for the state
to be used.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/arc4.c
crypto/cbc.c
crypto/ecb.c
crypto/lskcipher.c
include/crypto/skcipher.h