[CRYPTO] xts: Use proper alignment
The XTS blockmode uses a copy of the IV which is saved on the stack and may or may not be properly aligned. If it is not, it will break hardware cipher like the geode or padlock. This patch encrypts the IV in place so we don't have to worry about alignment. Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc> Tested-by: Stefan Hellermann <stefan@the2masters.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
bc97f19dc8
commit
6212f2c7f7
1 changed files with 6 additions and 7 deletions
13
crypto/xts.c
13
crypto/xts.c
|
@ -77,16 +77,16 @@ static int setkey(struct crypto_tfm *parent, const u8 *key,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sinfo {
|
struct sinfo {
|
||||||
be128 t;
|
be128 *t;
|
||||||
struct crypto_tfm *tfm;
|
struct crypto_tfm *tfm;
|
||||||
void (*fn)(struct crypto_tfm *, u8 *, const u8 *);
|
void (*fn)(struct crypto_tfm *, u8 *, const u8 *);
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void xts_round(struct sinfo *s, void *dst, const void *src)
|
static inline void xts_round(struct sinfo *s, void *dst, const void *src)
|
||||||
{
|
{
|
||||||
be128_xor(dst, &s->t, src); /* PP <- T xor P */
|
be128_xor(dst, s->t, src); /* PP <- T xor P */
|
||||||
s->fn(s->tfm, dst, dst); /* CC <- E(Key1,PP) */
|
s->fn(s->tfm, dst, dst); /* CC <- E(Key1,PP) */
|
||||||
be128_xor(dst, dst, &s->t); /* C <- T xor CC */
|
be128_xor(dst, dst, s->t); /* C <- T xor CC */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int crypt(struct blkcipher_desc *d,
|
static int crypt(struct blkcipher_desc *d,
|
||||||
|
@ -101,7 +101,6 @@ static int crypt(struct blkcipher_desc *d,
|
||||||
.tfm = crypto_cipher_tfm(ctx->child),
|
.tfm = crypto_cipher_tfm(ctx->child),
|
||||||
.fn = fn
|
.fn = fn
|
||||||
};
|
};
|
||||||
be128 *iv;
|
|
||||||
u8 *wsrc;
|
u8 *wsrc;
|
||||||
u8 *wdst;
|
u8 *wdst;
|
||||||
|
|
||||||
|
@ -109,20 +108,20 @@ static int crypt(struct blkcipher_desc *d,
|
||||||
if (!w->nbytes)
|
if (!w->nbytes)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
s.t = (be128 *)w->iv;
|
||||||
avail = w->nbytes;
|
avail = w->nbytes;
|
||||||
|
|
||||||
wsrc = w->src.virt.addr;
|
wsrc = w->src.virt.addr;
|
||||||
wdst = w->dst.virt.addr;
|
wdst = w->dst.virt.addr;
|
||||||
|
|
||||||
/* calculate first value of T */
|
/* calculate first value of T */
|
||||||
iv = (be128 *)w->iv;
|
tw(crypto_cipher_tfm(ctx->tweak), w->iv, w->iv);
|
||||||
tw(crypto_cipher_tfm(ctx->tweak), (void *)&s.t, w->iv);
|
|
||||||
|
|
||||||
goto first;
|
goto first;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
do {
|
do {
|
||||||
gf128mul_x_ble(&s.t, &s.t);
|
gf128mul_x_ble(s.t, s.t);
|
||||||
|
|
||||||
first:
|
first:
|
||||||
xts_round(&s, wdst, wsrc);
|
xts_round(&s, wdst, wsrc);
|
||||||
|
|
Loading…
Reference in a new issue