kernel-ark/include/crypto/xts.h
Stephan Mueller 28856a9e52 crypto: xts - consolidate sanity check for keys
The patch centralizes the XTS key check logic into the service function
xts_check_key which is invoked from the different XTS implementations.
With this, the XTS implementations in ARM, ARM64, PPC and S390 have now
a sanity check for the XTS keys similar to the other arches.

In addition, this service function received a check to ensure that the
key != the tweak key which is mandated by FIPS 140-2 IG A.9. As the
check is not present in the standards defining XTS, it is only enforced
in FIPS mode of the kernel.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2016-02-17 04:07:51 +08:00

55 lines
1.2 KiB
C

#ifndef _CRYPTO_XTS_H
#define _CRYPTO_XTS_H
#include <crypto/b128ops.h>
#include <linux/crypto.h>
#include <crypto/algapi.h>
#include <linux/fips.h>
struct scatterlist;
struct blkcipher_desc;
#define XTS_BLOCK_SIZE 16
struct xts_crypt_req {
be128 *tbuf;
unsigned int tbuflen;
void *tweak_ctx;
void (*tweak_fn)(void *ctx, u8* dst, const u8* src);
void *crypt_ctx;
void (*crypt_fn)(void *ctx, u8 *blks, unsigned int nbytes);
};
#define XTS_TWEAK_CAST(x) ((void (*)(void *, u8*, const u8*))(x))
int xts_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
struct scatterlist *src, unsigned int nbytes,
struct xts_crypt_req *req);
static inline int xts_check_key(struct crypto_tfm *tfm,
const u8 *key, unsigned int keylen)
{
u32 *flags = &tfm->crt_flags;
/*
* key consists of keys of equal size concatenated, therefore
* the length must be even.
*/
if (keylen % 2) {
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL;
}
/* ensure that the AES and tweak key are not identical */
if (fips_enabled &&
!crypto_memneq(key, key + (keylen / 2), keylen / 2)) {
*flags |= CRYPTO_TFM_RES_WEAK_KEY;
return -EINVAL;
}
return 0;
}
#endif /* _CRYPTO_XTS_H */