Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 4178
b: refs/heads/master
c: 915e856
h: refs/heads/master
v: v3
  • Loading branch information
Herbert Xu authored and David S. Miller committed Jul 6, 2005
1 parent 86272d9 commit 66d1a64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fbdae9f3e7fb57c07cb0d973f113eb25da2e8ff2
refs/heads/master: 915e8561d559abba1b81934e31e54a3f850fa7bf
29 changes: 27 additions & 2 deletions trunk/crypto/cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,31 @@ static int crypt(const struct cipher_desc *desc,
return 0;
}

static int crypt_iv_unaligned(struct cipher_desc *desc,
struct scatterlist *dst,
struct scatterlist *src,
unsigned int nbytes)
{
struct crypto_tfm *tfm = desc->tfm;
unsigned int alignmask = crypto_tfm_alg_alignmask(tfm);
u8 *iv = desc->info;

if (unlikely(((unsigned long)iv & alignmask))) {
unsigned int ivsize = tfm->crt_cipher.cit_ivsize;
u8 buffer[ivsize + alignmask];
u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
int err;

desc->info = memcpy(tmp, iv, ivsize);
err = crypt(desc, dst, src, nbytes);
memcpy(iv, tmp, ivsize);

return err;
}

return crypt(desc, dst, src, nbytes);
}

static unsigned int cbc_process_encrypt(const struct cipher_desc *desc,
u8 *dst, const u8 *src,
unsigned int nbytes)
Expand Down Expand Up @@ -298,7 +323,7 @@ static int cbc_encrypt_iv(struct crypto_tfm *tfm,
desc.prfn = cipher->cia_encrypt_cbc ?: cbc_process_encrypt;
desc.info = iv;

return crypt(&desc, dst, src, nbytes);
return crypt_iv_unaligned(&desc, dst, src, nbytes);
}

static int cbc_decrypt(struct crypto_tfm *tfm,
Expand Down Expand Up @@ -330,7 +355,7 @@ static int cbc_decrypt_iv(struct crypto_tfm *tfm,
desc.prfn = cipher->cia_decrypt_cbc ?: cbc_process_decrypt;
desc.info = iv;

return crypt(&desc, dst, src, nbytes);
return crypt_iv_unaligned(&desc, dst, src, nbytes);
}

static int nocrypt(struct crypto_tfm *tfm,
Expand Down

0 comments on commit 66d1a64

Please sign in to comment.