4 #include <crypto/b128ops.h>
5 #include <crypto/internal/skcipher.h>
6 #include <linux/fips.h>
11 #define XTS_BLOCK_SIZE 16
13 struct xts_crypt_req
{
18 void (*tweak_fn
)(void *ctx
, u8
* dst
, const u8
* src
);
20 void (*crypt_fn
)(void *ctx
, u8
*blks
, unsigned int nbytes
);
23 #define XTS_TWEAK_CAST(x) ((void (*)(void *, u8*, const u8*))(x))
25 int xts_crypt(struct blkcipher_desc
*desc
, struct scatterlist
*dst
,
26 struct scatterlist
*src
, unsigned int nbytes
,
27 struct xts_crypt_req
*req
);
29 static inline int xts_check_key(struct crypto_tfm
*tfm
,
30 const u8
*key
, unsigned int keylen
)
32 u32
*flags
= &tfm
->crt_flags
;
35 * key consists of keys of equal size concatenated, therefore
36 * the length must be even.
39 *flags
|= CRYPTO_TFM_RES_BAD_KEY_LEN
;
43 /* ensure that the AES and tweak key are not identical */
45 !crypto_memneq(key
, key
+ (keylen
/ 2), keylen
/ 2)) {
46 *flags
|= CRYPTO_TFM_RES_WEAK_KEY
;
53 static inline int xts_verify_key(struct crypto_skcipher
*tfm
,
54 const u8
*key
, unsigned int keylen
)
57 * key consists of keys of equal size concatenated, therefore
58 * the length must be even.
61 crypto_skcipher_set_flags(tfm
, CRYPTO_TFM_RES_BAD_KEY_LEN
);
65 /* ensure that the AES and tweak key are not identical */
66 if ((fips_enabled
|| crypto_skcipher_get_flags(tfm
) &
67 CRYPTO_TFM_REQ_WEAK_KEY
) &&
68 !crypto_memneq(key
, key
+ (keylen
/ 2), keylen
/ 2)) {
69 crypto_skcipher_set_flags(tfm
, CRYPTO_TFM_RES_WEAK_KEY
);
76 #endif /* _CRYPTO_XTS_H */