mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
![Eric Biggers](/assets/img/avatar_default.png)
The CRYPTO_TFM_RES_BAD_KEY_LEN flag was apparently meant as a way to make the ->setkey() functions provide more information about errors. However, no one actually checks for this flag, which makes it pointless. Also, many algorithms fail to set this flag when given a bad length key. Reviewing just the generic implementations, this is the case for aes-fixed-time, cbcmac, echainiv, nhpoly1305, pcrypt, rfc3686, rfc4309, rfc7539, rfc7539esp, salsa20, seqiv, and xcbc. But there are probably many more in arch/*/crypto/ and drivers/crypto/. Some algorithms can even set this flag when the key is the correct length. For example, authenc and authencesn set it when the key payload is malformed in any way (not just a bad length), the atmel-sha and ccree drivers can set it if a memory allocation fails, and the chelsio driver sets it for bad auth tag lengths, not just bad key lengths. So even if someone actually wanted to start checking this flag (which seems unlikely, since it's been unused for a long time), there would be a lot of work needed to get it working correctly. But it would probably be much better to go back to the drawing board and just define different return values, like -EINVAL if the key is invalid for the algorithm vs. -EKEYREJECTED if the key was rejected by a policy like "no weak keys". That would be much simpler, less error-prone, and easier to test. So just remove this flag. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
91 lines
2.8 KiB
C
91 lines
2.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef ASM_X86_CAMELLIA_H
|
|
#define ASM_X86_CAMELLIA_H
|
|
|
|
#include <crypto/b128ops.h>
|
|
#include <linux/crypto.h>
|
|
#include <linux/kernel.h>
|
|
|
|
#define CAMELLIA_MIN_KEY_SIZE 16
|
|
#define CAMELLIA_MAX_KEY_SIZE 32
|
|
#define CAMELLIA_BLOCK_SIZE 16
|
|
#define CAMELLIA_TABLE_BYTE_LEN 272
|
|
#define CAMELLIA_PARALLEL_BLOCKS 2
|
|
|
|
struct crypto_skcipher;
|
|
|
|
struct camellia_ctx {
|
|
u64 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u64)];
|
|
u32 key_length;
|
|
};
|
|
|
|
struct camellia_xts_ctx {
|
|
struct camellia_ctx tweak_ctx;
|
|
struct camellia_ctx crypt_ctx;
|
|
};
|
|
|
|
extern int __camellia_setkey(struct camellia_ctx *cctx,
|
|
const unsigned char *key,
|
|
unsigned int key_len);
|
|
|
|
extern int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key,
|
|
unsigned int keylen);
|
|
|
|
/* regular block cipher functions */
|
|
asmlinkage void __camellia_enc_blk(const void *ctx, u8 *dst, const u8 *src,
|
|
bool xor);
|
|
asmlinkage void camellia_dec_blk(const void *ctx, u8 *dst, const u8 *src);
|
|
|
|
/* 2-way parallel cipher functions */
|
|
asmlinkage void __camellia_enc_blk_2way(const void *ctx, u8 *dst, const u8 *src,
|
|
bool xor);
|
|
asmlinkage void camellia_dec_blk_2way(const void *ctx, u8 *dst, const u8 *src);
|
|
|
|
/* 16-way parallel cipher functions (avx/aes-ni) */
|
|
asmlinkage void camellia_ecb_enc_16way(const void *ctx, u8 *dst, const u8 *src);
|
|
asmlinkage void camellia_ecb_dec_16way(const void *ctx, u8 *dst, const u8 *src);
|
|
|
|
asmlinkage void camellia_cbc_dec_16way(const void *ctx, u8 *dst, const u8 *src);
|
|
asmlinkage void camellia_ctr_16way(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
|
|
asmlinkage void camellia_xts_enc_16way(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
asmlinkage void camellia_xts_dec_16way(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
|
|
static inline void camellia_enc_blk(const void *ctx, u8 *dst, const u8 *src)
|
|
{
|
|
__camellia_enc_blk(ctx, dst, src, false);
|
|
}
|
|
|
|
static inline void camellia_enc_blk_xor(const void *ctx, u8 *dst, const u8 *src)
|
|
{
|
|
__camellia_enc_blk(ctx, dst, src, true);
|
|
}
|
|
|
|
static inline void camellia_enc_blk_2way(const void *ctx, u8 *dst,
|
|
const u8 *src)
|
|
{
|
|
__camellia_enc_blk_2way(ctx, dst, src, false);
|
|
}
|
|
|
|
static inline void camellia_enc_blk_xor_2way(const void *ctx, u8 *dst,
|
|
const u8 *src)
|
|
{
|
|
__camellia_enc_blk_2way(ctx, dst, src, true);
|
|
}
|
|
|
|
/* glue helpers */
|
|
extern void camellia_decrypt_cbc_2way(const void *ctx, u8 *dst, const u8 *src);
|
|
extern void camellia_crypt_ctr(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
extern void camellia_crypt_ctr_2way(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
|
|
extern void camellia_xts_enc(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
extern void camellia_xts_dec(const void *ctx, u8 *dst, const u8 *src,
|
|
le128 *iv);
|
|
|
|
#endif /* ASM_X86_CAMELLIA_H */
|