Commit fda5e142 authored by Jan Glauber's avatar Jan Glauber Committed by Linus Torvalds

[PATCH] s390: aes crypto code fixes

Call KM[C] only with a multiple of block size.  Check return value of KM[C]
instructions and complain about erros
Signed-off-by: default avatarJan Glauber <jan.glauber@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b8dc6038
...@@ -114,80 +114,108 @@ static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out, ...@@ -114,80 +114,108 @@ static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
const u8 *in, unsigned int nbytes) const u8 *in, unsigned int nbytes)
{ {
struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
int ret;
/* only use complete blocks */
nbytes &= ~(AES_BLOCK_SIZE - 1);
switch (sctx->key_len) { switch (sctx->key_len) {
case 16: case 16:
crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in, nbytes); ret = crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 24: case 24:
crypt_s390_km(KM_AES_192_ENCRYPT, &sctx->key, out, in, nbytes); ret = crypt_s390_km(KM_AES_192_ENCRYPT, &sctx->key, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 32: case 32:
crypt_s390_km(KM_AES_256_ENCRYPT, &sctx->key, out, in, nbytes); ret = crypt_s390_km(KM_AES_256_ENCRYPT, &sctx->key, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
} }
return nbytes & ~(AES_BLOCK_SIZE - 1); return nbytes;
} }
static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out, static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
const u8 *in, unsigned int nbytes) const u8 *in, unsigned int nbytes)
{ {
struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
int ret;
/* only use complete blocks */
nbytes &= ~(AES_BLOCK_SIZE - 1);
switch (sctx->key_len) { switch (sctx->key_len) {
case 16: case 16:
crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in, nbytes); ret = crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 24: case 24:
crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in, nbytes); ret = crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 32: case 32:
crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in, nbytes); ret = crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
} }
return nbytes & ~(AES_BLOCK_SIZE - 1); return nbytes;
} }
static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out, static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
const u8 *in, unsigned int nbytes) const u8 *in, unsigned int nbytes)
{ {
struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
int ret;
/* only use complete blocks */
nbytes &= ~(AES_BLOCK_SIZE - 1);
memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE); memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE);
switch (sctx->key_len) { switch (sctx->key_len) {
case 16: case 16:
crypt_s390_kmc(KMC_AES_128_ENCRYPT, &sctx->iv, out, in, nbytes); ret = crypt_s390_kmc(KMC_AES_128_ENCRYPT, &sctx->iv, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 24: case 24:
crypt_s390_kmc(KMC_AES_192_ENCRYPT, &sctx->iv, out, in, nbytes); ret = crypt_s390_kmc(KMC_AES_192_ENCRYPT, &sctx->iv, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 32: case 32:
crypt_s390_kmc(KMC_AES_256_ENCRYPT, &sctx->iv, out, in, nbytes); ret = crypt_s390_kmc(KMC_AES_256_ENCRYPT, &sctx->iv, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
} }
memcpy(desc->info, &sctx->iv, AES_BLOCK_SIZE); memcpy(desc->info, &sctx->iv, AES_BLOCK_SIZE);
return nbytes & ~(AES_BLOCK_SIZE - 1); return nbytes;
} }
static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out, static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
const u8 *in, unsigned int nbytes) const u8 *in, unsigned int nbytes)
{ {
struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm); struct s390_aes_ctx *sctx = crypto_tfm_ctx(desc->tfm);
int ret;
/* only use complete blocks */
nbytes &= ~(AES_BLOCK_SIZE - 1);
memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE); memcpy(&sctx->iv, desc->info, AES_BLOCK_SIZE);
switch (sctx->key_len) { switch (sctx->key_len) {
case 16: case 16:
crypt_s390_kmc(KMC_AES_128_DECRYPT, &sctx->iv, out, in, nbytes); ret = crypt_s390_kmc(KMC_AES_128_DECRYPT, &sctx->iv, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 24: case 24:
crypt_s390_kmc(KMC_AES_192_DECRYPT, &sctx->iv, out, in, nbytes); ret = crypt_s390_kmc(KMC_AES_192_DECRYPT, &sctx->iv, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
case 32: case 32:
crypt_s390_kmc(KMC_AES_256_DECRYPT, &sctx->iv, out, in, nbytes); ret = crypt_s390_kmc(KMC_AES_256_DECRYPT, &sctx->iv, out, in, nbytes);
BUG_ON((ret < 0) || (ret != nbytes));
break; break;
} }
return nbytes & ~(AES_BLOCK_SIZE - 1); return nbytes;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment