Subject: small patch queue

Hello Herbert,

Patch 1 and 2 are shrinking the speed template a little. Did you had
something like this in mind?
Patch 3 removes the return parameter from the AES-i586 asm module
because it is unused anyway.
Patch 4 + 5 is not an attempt to touch as many file as possible but
something you asked for [1] :) I'm not sure if the patches are worth it.
The problem I have is patch 5 since 4 is easy :) I'm touching only ecb &
cbc. I don't thing error recovery makes sense here. If an error occurs in
ecb mode and the operation is not inplace than you can repeat it without a
problem. If the operation is inplace than you may have destroyed your src.
In case of cbc you are in trouble anyway because your IV is undefined.
The error recovery could get quite complex here, so maybe a BUG() statement
isn't that bad at all or?

[1] http://www.mail-archive.com/[email protected]/msg01236.html

Sebastian


Subject: [PATCH] [crypto] tcrypto group common used speed-templates

Some crypto ciphers which are impleneted support similar key sizes
(16,24 & 32 byte). They can be grouped together and use a common
templatte instead of their own which contains the same data.
Signed-off-by: Sebastian Siewior <[email protected]>
---
crypto/tcrypt.c | 70 ++++++++++++-------------
crypto/tcrypt.h | 158 ++++++++++++++++++++-----------------------------------
2 files changed, 91 insertions(+), 137 deletions(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 1ab8c01..cff1836 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -1621,89 +1621,85 @@ static void do_test(void)

case 200:
test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
- aes_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
- aes_lrw_speed_template);
+ speed_template_32_40_48);
test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
- aes_lrw_speed_template);
+ speed_template_32_40_48);
test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
- aes_xts_speed_template);
+ speed_template_32_48_64);
test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
- aes_xts_speed_template);
+ speed_template_32_48_64);
break;

case 201:
test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
- des3_ede_enc_tv_template,
- DES3_EDE_ENC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
- des3_ede_dec_tv_template,
- DES3_EDE_DEC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
- des3_ede_enc_tv_template,
- DES3_EDE_ENC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
- des3_ede_dec_tv_template,
- DES3_EDE_DEC_TEST_VECTORS,
- des3_ede_speed_template);
+ des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
+ speed_template_24);
break;

case 202:
test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
- twofish_speed_template);
+ speed_template_16_24_32);
break;

case 203:
test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
- blowfish_speed_template);
+ speed_template_8_32);
break;

case 204:
test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
- des_speed_template);
+ speed_template_8);
break;

case 205:
test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
- camellia_speed_template);
+ speed_template_16_24_32);
break;

case 206:
test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
- salsa20_speed_template);
+ speed_template_16_32);
break;

case 300:
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index f785e56..4180a74 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -8032,7 +8032,62 @@ static struct hash_testvec crc32c_tv_template[] = {
/*
* Cipher speed tests
*/
-static struct cipher_speed aes_speed_template[] = {
+static struct cipher_speed speed_template_8[] = {
+ { .klen = 8, .blen = 16, },
+ { .klen = 8, .blen = 64, },
+ { .klen = 8, .blen = 256, },
+ { .klen = 8, .blen = 1024, },
+ { .klen = 8, .blen = 8192, },
+
+ /* End marker */
+ { .klen = 0, .blen = 0, }
+};
+
+static struct cipher_speed speed_template_24[] = {
+ { .klen = 24, .blen = 16, },
+ { .klen = 24, .blen = 64, },
+ { .klen = 24, .blen = 256, },
+ { .klen = 24, .blen = 1024, },
+ { .klen = 24, .blen = 8192, },
+
+ /* End marker */
+ { .klen = 0, .blen = 0, }
+};
+
+static struct cipher_speed speed_template_8_32[] = {
+ /* Don't support blowfish keys > 256 bit in this test */
+ { .klen = 8, .blen = 16, },
+ { .klen = 8, .blen = 64, },
+ { .klen = 8, .blen = 256, },
+ { .klen = 8, .blen = 1024, },
+ { .klen = 8, .blen = 8192, },
+ { .klen = 32, .blen = 16, },
+ { .klen = 32, .blen = 64, },
+ { .klen = 32, .blen = 256, },
+ { .klen = 32, .blen = 1024, },
+ { .klen = 32, .blen = 8192, },
+
+ /* End marker */
+ { .klen = 0, .blen = 0, }
+};
+
+static struct cipher_speed speed_template_16_32[] = {
+ { .klen = 16, .blen = 16, },
+ { .klen = 16, .blen = 64, },
+ { .klen = 16, .blen = 256, },
+ { .klen = 16, .blen = 1024, },
+ { .klen = 16, .blen = 8192, },
+ { .klen = 32, .blen = 16, },
+ { .klen = 32, .blen = 64, },
+ { .klen = 32, .blen = 256, },
+ { .klen = 32, .blen = 1024, },
+ { .klen = 32, .blen = 8192, },
+
+ /* End marker */
+ { .klen = 0, .blen = 0, }
+};
+
+static struct cipher_speed speed_template_16_24_32[] = {
{ .klen = 16, .blen = 16, },
{ .klen = 16, .blen = 64, },
{ .klen = 16, .blen = 256, },
@@ -8053,7 +8108,7 @@ static struct cipher_speed aes_speed_template[] = {
{ .klen = 0, .blen = 0, }
};

-static struct cipher_speed aes_lrw_speed_template[] = {
+static struct cipher_speed speed_template_32_40_48[] = {
{ .klen = 32, .blen = 16, },
{ .klen = 32, .blen = 64, },
{ .klen = 32, .blen = 256, },
@@ -8074,7 +8129,7 @@ static struct cipher_speed aes_lrw_speed_template[] = {
{ .klen = 0, .blen = 0, }
};

-static struct cipher_speed aes_xts_speed_template[] = {
+static struct cipher_speed speed_template_32_48_64[] = {
{ .klen = 32, .blen = 16, },
{ .klen = 32, .blen = 64, },
{ .klen = 32, .blen = 256, },
@@ -8095,66 +8150,6 @@ static struct cipher_speed aes_xts_speed_template[] = {
{ .klen = 0, .blen = 0, }
};

-static struct cipher_speed des3_ede_speed_template[] = {
- { .klen = 24, .blen = 16, },
- { .klen = 24, .blen = 64, },
- { .klen = 24, .blen = 256, },
- { .klen = 24, .blen = 1024, },
- { .klen = 24, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed twofish_speed_template[] = {
- { .klen = 16, .blen = 16, },
- { .klen = 16, .blen = 64, },
- { .klen = 16, .blen = 256, },
- { .klen = 16, .blen = 1024, },
- { .klen = 16, .blen = 8192, },
- { .klen = 24, .blen = 16, },
- { .klen = 24, .blen = 64, },
- { .klen = 24, .blen = 256, },
- { .klen = 24, .blen = 1024, },
- { .klen = 24, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed blowfish_speed_template[] = {
- /* Don't support blowfish keys > 256 bit in this test */
- { .klen = 8, .blen = 16, },
- { .klen = 8, .blen = 64, },
- { .klen = 8, .blen = 256, },
- { .klen = 8, .blen = 1024, },
- { .klen = 8, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed des_speed_template[] = {
- { .klen = 8, .blen = 16, },
- { .klen = 8, .blen = 64, },
- { .klen = 8, .blen = 256, },
- { .klen = 8, .blen = 1024, },
- { .klen = 8, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
/*
* Digest speed tests
*/
@@ -8186,41 +8181,4 @@ static struct hash_speed generic_hash_speed_template[] = {
{ .blen = 0, .plen = 0, }
};

-static struct cipher_speed camellia_speed_template[] = {
- { .klen = 16, .blen = 16, },
- { .klen = 16, .blen = 64, },
- { .klen = 16, .blen = 256, },
- { .klen = 16, .blen = 1024, },
- { .klen = 16, .blen = 8192, },
- { .klen = 24, .blen = 16, },
- { .klen = 24, .blen = 64, },
- { .klen = 24, .blen = 256, },
- { .klen = 24, .blen = 1024, },
- { .klen = 24, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed salsa20_speed_template[] = {
- { .klen = 16, .blen = 16, },
- { .klen = 16, .blen = 64, },
- { .klen = 16, .blen = 256, },
- { .klen = 16, .blen = 1024, },
- { .klen = 16, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
#endif /* _CRYPTO_TCRYPT_H */
--
1.5.3.6

Subject: [PATCH] [crypto] tcrypt: shrink speed templates

The speed templates as it look always the same. The key size
is repeated for each block size and we test always the same
block size. The addition of one inner loop makes it possible
to get rid of the struct and it is possible to use a tiny
u8 array :)
Signed-off-by: Sebastian Siewior <[email protected]>
---
crypto/tcrypt.c | 89 +++++++++++++++++++++-----------------
crypto/tcrypt.h | 129 +++----------------------------------------------------
2 files changed, 57 insertions(+), 161 deletions(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index cff1836..6b8315b 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -721,15 +721,18 @@ out:
return ret;
}

+static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
+
static void test_cipher_speed(char *algo, int enc, unsigned int sec,
struct cipher_testvec *template,
- unsigned int tcount, struct cipher_speed *speed)
+ unsigned int tcount, u8 *keysize)
{
unsigned int ret, i, j, iv_len;
unsigned char *key, *p, iv[128];
struct crypto_blkcipher *tfm;
struct blkcipher_desc desc;
const char *e;
+ u32 *b_size;

if (enc == ENCRYPT)
e = "encryption";
@@ -748,52 +751,60 @@ static void test_cipher_speed(char *algo, int enc, unsigned int sec,
desc.tfm = tfm;
desc.flags = 0;

- for (i = 0; speed[i].klen != 0; i++) {
- if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
- printk("template (%u) too big for tvmem (%u)\n",
- speed[i].blen + speed[i].klen, TVMEMSIZE);
- goto out;
- }
+ i = 0;
+ do {

- printk("test %u (%d bit key, %d byte blocks): ", i,
- speed[i].klen * 8, speed[i].blen);
+ b_size = block_sizes;
+ do {

- memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
+ if ((*keysize + *b_size) > TVMEMSIZE) {
+ printk("template (%u) too big for tvmem (%u)\n",
+ *keysize + *b_size, TVMEMSIZE);
+ goto out;
+ }

- /* set key, plain text and IV */
- key = (unsigned char *)tvmem;
- for (j = 0; j < tcount; j++) {
- if (template[j].klen == speed[i].klen) {
- key = template[j].key;
- break;
+ printk("test %u (%d bit key, %d byte blocks): ", i,
+ *keysize * 8, *b_size);
+
+ memset(tvmem, 0xff, *keysize + *b_size);
+
+ /* set key, plain text and IV */
+ key = (unsigned char *)tvmem;
+ for (j = 0; j < tcount; j++) {
+ if (template[j].klen == *keysize) {
+ key = template[j].key;
+ break;
+ }
}
- }
- p = (unsigned char *)tvmem + speed[i].klen;
+ p = (unsigned char *)tvmem + *keysize;

- ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
- if (ret) {
- printk("setkey() failed flags=%x\n",
- crypto_blkcipher_get_flags(tfm));
- goto out;
- }
+ ret = crypto_blkcipher_setkey(tfm, key, *keysize);
+ if (ret) {
+ printk("setkey() failed flags=%x\n",
+ crypto_blkcipher_get_flags(tfm));
+ goto out;
+ }

- iv_len = crypto_blkcipher_ivsize(tfm);
- if (iv_len) {
- memset(&iv, 0xff, iv_len);
- crypto_blkcipher_set_iv(tfm, iv, iv_len);
- }
+ iv_len = crypto_blkcipher_ivsize(tfm);
+ if (iv_len) {
+ memset(&iv, 0xff, iv_len);
+ crypto_blkcipher_set_iv(tfm, iv, iv_len);
+ }

- if (sec)
- ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
- sec);
- else
- ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
+ if (sec)
+ ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
+ else
+ ret = test_cipher_cycles(&desc, enc, p, *b_size);

- if (ret) {
- printk("%s() failed flags=%x\n", e, desc.flags);
- break;
- }
- }
+ if (ret) {
+ printk("%s() failed flags=%x\n", e, desc.flags);
+ break;
+ }
+ b_size++;
+ i++;
+ } while (*b_size);
+ keysize++;
+ } while (*keysize);

out:
crypto_free_blkcipher(tfm);
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 4180a74..45e79b5 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -72,11 +72,6 @@ struct aead_testvec {
unsigned short rlen;
};

-struct cipher_speed {
- unsigned char klen;
- unsigned int blen;
-};
-
struct hash_speed {
unsigned int blen; /* buffer length */
unsigned int plen; /* per-update length */
@@ -8032,123 +8027,13 @@ static struct hash_testvec crc32c_tv_template[] = {
/*
* Cipher speed tests
*/
-static struct cipher_speed speed_template_8[] = {
- { .klen = 8, .blen = 16, },
- { .klen = 8, .blen = 64, },
- { .klen = 8, .blen = 256, },
- { .klen = 8, .blen = 1024, },
- { .klen = 8, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed speed_template_24[] = {
- { .klen = 24, .blen = 16, },
- { .klen = 24, .blen = 64, },
- { .klen = 24, .blen = 256, },
- { .klen = 24, .blen = 1024, },
- { .klen = 24, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed speed_template_8_32[] = {
- /* Don't support blowfish keys > 256 bit in this test */
- { .klen = 8, .blen = 16, },
- { .klen = 8, .blen = 64, },
- { .klen = 8, .blen = 256, },
- { .klen = 8, .blen = 1024, },
- { .klen = 8, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed speed_template_16_32[] = {
- { .klen = 16, .blen = 16, },
- { .klen = 16, .blen = 64, },
- { .klen = 16, .blen = 256, },
- { .klen = 16, .blen = 1024, },
- { .klen = 16, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed speed_template_16_24_32[] = {
- { .klen = 16, .blen = 16, },
- { .klen = 16, .blen = 64, },
- { .klen = 16, .blen = 256, },
- { .klen = 16, .blen = 1024, },
- { .klen = 16, .blen = 8192, },
- { .klen = 24, .blen = 16, },
- { .klen = 24, .blen = 64, },
- { .klen = 24, .blen = 256, },
- { .klen = 24, .blen = 1024, },
- { .klen = 24, .blen = 8192, },
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed speed_template_32_40_48[] = {
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
- { .klen = 40, .blen = 16, },
- { .klen = 40, .blen = 64, },
- { .klen = 40, .blen = 256, },
- { .klen = 40, .blen = 1024, },
- { .klen = 40, .blen = 8192, },
- { .klen = 48, .blen = 16, },
- { .klen = 48, .blen = 64, },
- { .klen = 48, .blen = 256, },
- { .klen = 48, .blen = 1024, },
- { .klen = 48, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
-
-static struct cipher_speed speed_template_32_48_64[] = {
- { .klen = 32, .blen = 16, },
- { .klen = 32, .blen = 64, },
- { .klen = 32, .blen = 256, },
- { .klen = 32, .blen = 1024, },
- { .klen = 32, .blen = 8192, },
- { .klen = 48, .blen = 16, },
- { .klen = 48, .blen = 64, },
- { .klen = 48, .blen = 256, },
- { .klen = 48, .blen = 1024, },
- { .klen = 48, .blen = 8192, },
- { .klen = 64, .blen = 16, },
- { .klen = 64, .blen = 64, },
- { .klen = 64, .blen = 256, },
- { .klen = 64, .blen = 1024, },
- { .klen = 64, .blen = 8192, },
-
- /* End marker */
- { .klen = 0, .blen = 0, }
-};
+static u8 speed_template_8[] = {8, 0};
+static u8 speed_template_24[] = {24, 0};
+static u8 speed_template_8_32[] = {8, 32, 0};
+static u8 speed_template_16_32[] = {16, 32, 0};
+static u8 speed_template_16_24_32[] = {16, 24, 32, 0};
+static u8 speed_template_32_40_48[] = {32, 40, 48, 0};
+static u8 speed_template_32_48_64[] = {32, 48, 64, 0};

/*
* Digest speed tests
--
1.5.3.6

Subject: [PATCH] [crypto] aes-asm x86-i586 remove unused return code

The return parameter isn't used remove it.
Signed-off-by: Sebastian Siewior <[email protected]>
---
arch/x86/crypto/aes-i586-asm_32.S | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/arch/x86/crypto/aes-i586-asm_32.S b/arch/x86/crypto/aes-i586-asm_32.S
index 1093bed..e41b147 100644
--- a/arch/x86/crypto/aes-i586-asm_32.S
+++ b/arch/x86/crypto/aes-i586-asm_32.S
@@ -289,7 +289,6 @@ aes_enc_blk:
pop %ebx
mov %r0,(%ebp)
pop %ebp
- mov $1,%eax
ret

// AES (Rijndael) Decryption Subroutine
@@ -365,6 +364,4 @@ aes_dec_blk:
pop %ebx
mov %r0,(%ebp)
pop %ebp
- mov $1,%eax
ret
-
--
1.5.3.6

Subject: [PATCH] [crypto] cipher: add return parameter

Software usually can't fail because they don't do anything
dangerous. However HW implementation could fail for $reason.
This patch changes the prototype and adjusts all ciphers. Most
of them return zero except s390 and geode since the HW provides
a return parameter.

Signed-off-by: Sebastian Siewior <[email protected]>
---
arch/s390/crypto/aes_s390.c | 14 ++++++------
arch/s390/crypto/des_s390.c | 24 +++++++++++-----------
arch/x86/crypto/aes_glue.c | 6 +++-
arch/x86/crypto/twofish_glue.c | 6 +++-
crypto/aes_generic.c | 6 +++-
crypto/anubis.c | 6 +++-
crypto/arc4.c | 3 +-
crypto/blowfish.c | 6 +++-
crypto/camellia.c | 6 +++-
crypto/cast5.c | 6 +++-
crypto/cast6.c | 6 +++-
crypto/cbc.c | 8 +++---
crypto/cipher.c | 20 +++++++++---------
crypto/crypto_null.c | 3 +-
crypto/ctr.c | 4 +-
crypto/des_generic.c | 12 +++++++---
crypto/ecb.c | 2 +-
crypto/fcrypt.c | 6 +++-
crypto/khazad.c | 6 +++-
crypto/lrw.c | 4 +-
crypto/pcbc.c | 6 ++--
crypto/seed.c | 6 +++-
crypto/serpent.c | 12 +++++++---
crypto/tea.c | 18 +++++++++++-----
crypto/twofish.c | 8 +++---
crypto/xts.c | 6 ++--
drivers/crypto/geode-aes.c | 42 +++++++++++++++++++--------------------
drivers/crypto/padlock-aes.c | 6 +++-
include/linux/crypto.h | 8 +++---
29 files changed, 152 insertions(+), 114 deletions(-)

diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 46c9705..dc12e07 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -110,7 +110,7 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
return setkey_fallback_cip(tfm, in_key, key_len);
}

-static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);

@@ -121,15 +121,15 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)

switch (sctx->key_len) {
case 16:
- crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in,
+ return crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in,
AES_BLOCK_SIZE);
break;
case 24:
- crypt_s390_km(KM_AES_192_ENCRYPT, &sctx->key, out, in,
+ return crypt_s390_km(KM_AES_192_ENCRYPT, &sctx->key, out, in,
AES_BLOCK_SIZE);
break;
case 32:
- crypt_s390_km(KM_AES_256_ENCRYPT, &sctx->key, out, in,
+ return crypt_s390_km(KM_AES_256_ENCRYPT, &sctx->key, out, in,
AES_BLOCK_SIZE);
break;
}
@@ -146,15 +146,15 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)

switch (sctx->key_len) {
case 16:
- crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in,
+ return crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in,
AES_BLOCK_SIZE);
break;
case 24:
- crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in,
+ return crypt_s390_km(KM_AES_192_DECRYPT, &sctx->key, out, in,
AES_BLOCK_SIZE);
break;
case 32:
- crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in,
+ return crypt_s390_km(KM_AES_256_DECRYPT, &sctx->key, out, in,
AES_BLOCK_SIZE);
break;
}
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index ea22707..c3fa6dd 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -59,18 +59,18 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
return ret;
}

-static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);

- crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
+ return crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
}

-static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);

- crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
+ return crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
}

static struct crypto_alg des_alg = {
@@ -263,19 +263,19 @@ static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
return 0;
}

-static void des3_128_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des3_128_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);

- crypt_s390_km(KM_TDEA_128_ENCRYPT, dctx->key, dst, (void*)src,
+ return crypt_s390_km(KM_TDEA_128_ENCRYPT, dctx->key, dst, (void*)src,
DES3_128_BLOCK_SIZE);
}

-static void des3_128_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des3_128_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);

- crypt_s390_km(KM_TDEA_128_DECRYPT, dctx->key, dst, (void*)src,
+ return crypt_s390_km(KM_TDEA_128_DECRYPT, dctx->key, dst, (void*)src,
DES3_128_BLOCK_SIZE);
}

@@ -425,19 +425,19 @@ static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
return 0;
}

-static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);

- crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src,
+ return crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src,
DES3_192_BLOCK_SIZE);
}

-static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);

- crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src,
+ return crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src,
DES3_192_BLOCK_SIZE);
}

diff --git a/arch/x86/crypto/aes_glue.c b/arch/x86/crypto/aes_glue.c
index 71f4578..d844afd 100644
--- a/arch/x86/crypto/aes_glue.c
+++ b/arch/x86/crypto/aes_glue.c
@@ -8,14 +8,16 @@
asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);

-static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
aes_enc_blk(tfm, dst, src);
+ return 0;
}

-static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
aes_dec_blk(tfm, dst, src);
+ return 0;
}

static struct crypto_alg aes_alg = {
diff --git a/arch/x86/crypto/twofish_glue.c b/arch/x86/crypto/twofish_glue.c
index cefaf8b..028a1ae 100644
--- a/arch/x86/crypto/twofish_glue.c
+++ b/arch/x86/crypto/twofish_glue.c
@@ -47,14 +47,16 @@
asmlinkage void twofish_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
asmlinkage void twofish_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);

-static void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
twofish_enc_blk(tfm, dst, src);
+ return 0;
}

-static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
twofish_dec_blk(tfm, dst, src);
+ return 0;
}

static struct crypto_alg alg = {
diff --git a/crypto/aes_generic.c b/crypto/aes_generic.c
index cf30af7..f33a99c 100644
--- a/crypto/aes_generic.c
+++ b/crypto/aes_generic.c
@@ -317,7 +317,7 @@ EXPORT_SYMBOL_GPL(crypto_aes_set_key);
f_rl(bo, bi, 3, k); \
} while (0)

-static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
const __le32 *src = (const __le32 *)in;
@@ -356,6 +356,7 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
dst[1] = cpu_to_le32(b0[1]);
dst[2] = cpu_to_le32(b0[2]);
dst[3] = cpu_to_le32(b0[3]);
+ return 0;
}

/* decrypt a block of text */
@@ -389,7 +390,7 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
i_rl(bo, bi, 3, k); \
} while (0)

-static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
const __le32 *src = (const __le32 *)in;
@@ -428,6 +429,7 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
dst[1] = cpu_to_le32(b0[1]);
dst[2] = cpu_to_le32(b0[2]);
dst[3] = cpu_to_le32(b0[3]);
+ return 0;
}

static struct crypto_alg aes_alg = {
diff --git a/crypto/anubis.c b/crypto/anubis.c
index 4ff0e1e..8241f62 100644
--- a/crypto/anubis.c
+++ b/crypto/anubis.c
@@ -659,16 +659,18 @@ static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
dst[i] = cpu_to_be32(inter[i]);
}

-static void anubis_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int anubis_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
anubis_crypt(ctx->E, dst, src, ctx->R);
+ return 0;
}

-static void anubis_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int anubis_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
anubis_crypt(ctx->D, dst, src, ctx->R);
+ return 0;
}

static struct crypto_alg anubis_alg = {
diff --git a/crypto/arc4.c b/crypto/arc4.c
index 8be47e1..2f27a07 100644
--- a/crypto/arc4.c
+++ b/crypto/arc4.c
@@ -49,7 +49,7 @@ static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
return 0;
}

-static void arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);

@@ -68,6 +68,7 @@ static void arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)

ctx->x = x;
ctx->y = y;
+ return 0;
}

static struct crypto_alg arc4_alg = {
diff --git a/crypto/blowfish.c b/crypto/blowfish.c
index 80c3fd8..7385bcd 100644
--- a/crypto/blowfish.c
+++ b/crypto/blowfish.c
@@ -348,7 +348,7 @@ static void encrypt_block(struct bf_ctx *bctx, u32 *dst, u32 *src)
dst[1] = yl;
}

-static void bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
const __be32 *in_blk = (const __be32 *)src;
__be32 *const out_blk = (__be32 *)dst;
@@ -359,9 +359,10 @@ static void bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
encrypt_block(crypto_tfm_ctx(tfm), out32, in32);
out_blk[0] = cpu_to_be32(out32[0]);
out_blk[1] = cpu_to_be32(out32[1]);
+ return 0;
}

-static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
const __be32 *in_blk = (const __be32 *)src;
@@ -393,6 +394,7 @@ static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out_blk[0] = cpu_to_be32(yr);
out_blk[1] = cpu_to_be32(yl);
+ return 0;
}

/*
diff --git a/crypto/camellia.c b/crypto/camellia.c
index 493fee7..37d416e 100644
--- a/crypto/camellia.c
+++ b/crypto/camellia.c
@@ -1042,7 +1042,7 @@ camellia_set_key(struct crypto_tfm *tfm, const u8 *in_key,
return 0;
}

-static void camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)in;
@@ -1064,9 +1064,10 @@ static void camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
dst[1] = cpu_to_be32(tmp[3]);
dst[2] = cpu_to_be32(tmp[0]);
dst[3] = cpu_to_be32(tmp[1]);
+ return 0;
}

-static void camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)in;
@@ -1088,6 +1089,7 @@ static void camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
dst[1] = cpu_to_be32(tmp[3]);
dst[2] = cpu_to_be32(tmp[0]);
dst[3] = cpu_to_be32(tmp[1]);
+ return 0;
}

static struct crypto_alg camellia_alg = {
diff --git a/crypto/cast5.c b/crypto/cast5.c
index 13ea60a..4eef890 100644
--- a/crypto/cast5.c
+++ b/crypto/cast5.c
@@ -577,7 +577,7 @@ static const u32 sb8[256] = {
(((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff]) )


-static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
+static int cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
{
struct cast5_ctx *c = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)inbuf;
@@ -640,9 +640,10 @@ static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
* concatenate to form the ciphertext.) */
dst[0] = cpu_to_be32(r);
dst[1] = cpu_to_be32(l);
+ return 0;
}

-static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
+static int cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
{
struct cast5_ctx *c = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)inbuf;
@@ -692,6 +693,7 @@ static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)

dst[0] = cpu_to_be32(r);
dst[1] = cpu_to_be32(l);
+ return 0;
}

static void key_schedule(u32 * x, u32 * z, u32 * k)
diff --git a/crypto/cast6.c b/crypto/cast6.c
index 5fd9420..0e23e26 100644
--- a/crypto/cast6.c
+++ b/crypto/cast6.c
@@ -445,7 +445,7 @@ static void QBAR (u32 * block, u8 * Kr, u32 * Km) {
block[2] ^= F1(block[3], Kr[0], Km[0]);
}

-static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
+static int cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
{
struct cast6_ctx *c = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)inbuf;
@@ -476,9 +476,10 @@ static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
dst[1] = cpu_to_be32(block[1]);
dst[2] = cpu_to_be32(block[2]);
dst[3] = cpu_to_be32(block[3]);
+ return 0;
}

-static void cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) {
+static int cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) {
struct cast6_ctx * c = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)inbuf;
__be32 *dst = (__be32 *)outbuf;
@@ -508,6 +509,7 @@ static void cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) {
dst[1] = cpu_to_be32(block[1]);
dst[2] = cpu_to_be32(block[2]);
dst[3] = cpu_to_be32(block[3]);
+ return 0;
}

static struct crypto_alg alg = {
diff --git a/crypto/cbc.c b/crypto/cbc.c
index 6affff8..a525dcc 100644
--- a/crypto/cbc.c
+++ b/crypto/cbc.c
@@ -43,7 +43,7 @@ static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_encrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
@@ -67,7 +67,7 @@ static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_encrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
@@ -115,7 +115,7 @@ static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_decrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
@@ -141,7 +141,7 @@ static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_decrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 9a1a731..625ad73 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -60,47 +60,47 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
return cia->cia_setkey(tfm, key, keylen);
}

-static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *,
+static int cipher_crypt_unaligned(int (*fn)(struct crypto_tfm *, u8 *,
const u8 *),
struct crypto_tfm *tfm,
u8 *dst, const u8 *src)
{
+ int ret;
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
unsigned int size = crypto_tfm_alg_blocksize(tfm);
u8 buffer[size + alignmask];
u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);

memcpy(tmp, src, size);
- fn(tfm, tmp, tmp);
+ ret = fn(tfm, tmp, tmp);
memcpy(dst, tmp, size);
+ return ret;
}

-static void cipher_encrypt_unaligned(struct crypto_tfm *tfm,
+static int cipher_encrypt_unaligned(struct crypto_tfm *tfm,
u8 *dst, const u8 *src)
{
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

if (unlikely(((unsigned long)dst | (unsigned long)src) & alignmask)) {
- cipher_crypt_unaligned(cipher->cia_encrypt, tfm, dst, src);
- return;
+ return cipher_crypt_unaligned(cipher->cia_encrypt, tfm, dst, src);
}

- cipher->cia_encrypt(tfm, dst, src);
+ return cipher->cia_encrypt(tfm, dst, src);
}

-static void cipher_decrypt_unaligned(struct crypto_tfm *tfm,
+static int cipher_decrypt_unaligned(struct crypto_tfm *tfm,
u8 *dst, const u8 *src)
{
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;

if (unlikely(((unsigned long)dst | (unsigned long)src) & alignmask)) {
- cipher_crypt_unaligned(cipher->cia_decrypt, tfm, dst, src);
- return;
+ return cipher_crypt_unaligned(cipher->cia_decrypt, tfm, dst, src);
}

- cipher->cia_decrypt(tfm, dst, src);
+ return cipher->cia_decrypt(tfm, dst, src);
}

int crypto_init_cipher_ops(struct crypto_tfm *tfm)
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index ff7b3de..cef6f15 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -52,9 +52,10 @@ static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
unsigned int keylen)
{ return 0; }

-static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
memcpy(dst, src, NULL_BLOCK_SIZE);
+ return 0;
}

static int skcipher_null_crypt(struct blkcipher_desc *desc,
diff --git a/crypto/ctr.c b/crypto/ctr.c
index 2d7425f..c2f74f3 100644
--- a/crypto/ctr.c
+++ b/crypto/ctr.c
@@ -68,7 +68,7 @@ static void crypto_ctr_crypt_final(struct blkcipher_walk *walk,
static int crypto_ctr_crypt_segment(struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_encrypt;
unsigned int bsize = crypto_cipher_blocksize(tfm);
u8 *ctrblk = walk->iv;
@@ -94,7 +94,7 @@ static int crypto_ctr_crypt_segment(struct blkcipher_walk *walk,
static int crypto_ctr_crypt_inplace(struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_encrypt;
unsigned int bsize = crypto_cipher_blocksize(tfm);
unsigned long alignmask = crypto_cipher_alignmask(tfm);
diff --git a/crypto/des_generic.c b/crypto/des_generic.c
index 355ecb7..7554b80 100644
--- a/crypto/des_generic.c
+++ b/crypto/des_generic.c
@@ -800,7 +800,7 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
return 0;
}

-static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct des_ctx *ctx = crypto_tfm_ctx(tfm);
const u32 *K = ctx->expkey;
@@ -821,9 +821,10 @@ static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

d[0] = cpu_to_le32(R);
d[1] = cpu_to_le32(L);
+ return 0;
}

-static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct des_ctx *ctx = crypto_tfm_ctx(tfm);
const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2;
@@ -844,6 +845,7 @@ static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

d[0] = cpu_to_le32(R);
d[1] = cpu_to_le32(L);
+ return 0;
}

/*
@@ -881,7 +883,7 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
return 0;
}

-static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
const u32 *K = dctx->expkey;
@@ -910,9 +912,10 @@ static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

d[0] = cpu_to_le32(R);
d[1] = cpu_to_le32(L);
+ return 0;
}

-static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2;
@@ -941,6 +944,7 @@ static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

d[0] = cpu_to_le32(R);
d[1] = cpu_to_le32(L);
+ return 0;
}

static struct crypto_alg des_alg = {
diff --git a/crypto/ecb.c b/crypto/ecb.c
index 6310387..1edb94f 100644
--- a/crypto/ecb.c
+++ b/crypto/ecb.c
@@ -41,7 +41,7 @@ static int crypto_ecb_setkey(struct crypto_tfm *parent, const u8 *key,
static int crypto_ecb_crypt(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm,
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *))
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *))
{
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes;
diff --git a/crypto/fcrypt.c b/crypto/fcrypt.c
index a32cb68..1cc94d5 100644
--- a/crypto/fcrypt.c
+++ b/crypto/fcrypt.c
@@ -233,7 +233,7 @@ do { \
/*
* encryptor
*/
-static void fcrypt_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int fcrypt_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
const struct fcrypt_ctx *ctx = crypto_tfm_ctx(tfm);
struct {
@@ -260,12 +260,13 @@ static void fcrypt_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
F_ENCRYPT(X.l, X.r, ctx->sched[0xf]);

memcpy(dst, &X, sizeof(X));
+ return 0;
}

/*
* decryptor
*/
-static void fcrypt_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int fcrypt_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
const struct fcrypt_ctx *ctx = crypto_tfm_ctx(tfm);
struct {
@@ -292,6 +293,7 @@ static void fcrypt_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
F_ENCRYPT(X.r, X.l, ctx->sched[0x0]);

memcpy(dst, &X, sizeof(X));
+ return 0;
}

/*
diff --git a/crypto/khazad.c b/crypto/khazad.c
index 704ebfe..9eaff36 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -834,16 +834,18 @@ static void khazad_crypt(const u64 roundKey[KHAZAD_ROUNDS + 1],
*dst = cpu_to_be64(state);
}

-static void khazad_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int khazad_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
khazad_crypt(ctx->E, dst, src);
+ return 0;
}

-static void khazad_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int khazad_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
khazad_crypt(ctx->D, dst, src);
+ return 0;
}

static struct crypto_alg khazad_alg = {
diff --git a/crypto/lrw.c b/crypto/lrw.c
index 621095d..b15f3f8 100644
--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -86,7 +86,7 @@ static int setkey(struct crypto_tfm *parent, const u8 *key,
struct sinfo {
be128 t;
struct crypto_tfm *tfm;
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *);
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *);
};

static inline void inc(be128 *iv)
@@ -123,7 +123,7 @@ static inline int get_index128(be128 *block)

static int crypt(struct blkcipher_desc *d,
struct blkcipher_walk *w, struct priv *ctx,
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *))
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *))
{
int err;
unsigned int avail;
diff --git a/crypto/pcbc.c b/crypto/pcbc.c
index fe70477..819504c 100644
--- a/crypto/pcbc.c
+++ b/crypto/pcbc.c
@@ -71,7 +71,7 @@ static int crypto_pcbc_encrypt_inplace(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_encrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
@@ -124,7 +124,7 @@ static int crypto_pcbc_decrypt_segment(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_decrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
@@ -151,7 +151,7 @@ static int crypto_pcbc_decrypt_inplace(struct blkcipher_desc *desc,
struct blkcipher_walk *walk,
struct crypto_cipher *tfm)
{
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
crypto_cipher_alg(tfm)->cia_decrypt;
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes = walk->nbytes;
diff --git a/crypto/seed.c b/crypto/seed.c
index d3e422f..af750bc 100644
--- a/crypto/seed.c
+++ b/crypto/seed.c
@@ -365,7 +365,7 @@ static int seed_set_key(struct crypto_tfm *tfm, const u8 *in_key,

/* encrypt a block of text */

-static void seed_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int seed_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct seed_ctx *ctx = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)in;
@@ -399,11 +399,12 @@ static void seed_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
dst[1] = cpu_to_be32(x4);
dst[2] = cpu_to_be32(x1);
dst[3] = cpu_to_be32(x2);
+ return 0;
}

/* decrypt a block of text */

-static void seed_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int seed_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
const struct seed_ctx *ctx = crypto_tfm_ctx(tfm);
const __be32 *src = (const __be32 *)in;
@@ -437,6 +438,7 @@ static void seed_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
dst[1] = cpu_to_be32(x4);
dst[2] = cpu_to_be32(x1);
dst[3] = cpu_to_be32(x2);
+ return 0;
}


diff --git a/crypto/serpent.c b/crypto/serpent.c
index 2b0a19a..2e4ff9a 100644
--- a/crypto/serpent.c
+++ b/crypto/serpent.c
@@ -360,7 +360,7 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
return 0;
}

-static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
const u32
@@ -417,9 +417,10 @@ static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
d[1] = cpu_to_le32(r1);
d[2] = cpu_to_le32(r2);
d[3] = cpu_to_le32(r3);
+ return 0;
}

-static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
const u32
@@ -471,6 +472,7 @@ static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
d[1] = cpu_to_le32(r3);
d[2] = cpu_to_le32(r1);
d[3] = cpu_to_le32(r4);
+ return 0;
}

static struct crypto_alg serpent_alg = {
@@ -501,7 +503,7 @@ static int tnepres_setkey(struct crypto_tfm *tfm, const u8 *key,
return serpent_setkey(tfm, rev_key, keylen);
}

-static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
const u32 * const s = (const u32 * const)src;
u32 * const d = (u32 * const)dst;
@@ -519,9 +521,10 @@ static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
d[1] = swab32(rd[2]);
d[2] = swab32(rd[1]);
d[3] = swab32(rd[0]);
+ return 0;
}

-static void tnepres_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int tnepres_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
const u32 * const s = (const u32 * const)src;
u32 * const d = (u32 * const)dst;
@@ -539,6 +542,7 @@ static void tnepres_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
d[1] = swab32(rd[2]);
d[2] = swab32(rd[1]);
d[3] = swab32(rd[0]);
+ return 0;
}

static struct crypto_alg tnepres_alg = {
diff --git a/crypto/tea.c b/crypto/tea.c
index 6893b3f..efb23a3 100644
--- a/crypto/tea.c
+++ b/crypto/tea.c
@@ -59,7 +59,7 @@ static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key,

}

-static void tea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int tea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
u32 y, z, n, sum = 0;
u32 k0, k1, k2, k3;
@@ -85,9 +85,10 @@ static void tea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out[0] = cpu_to_le32(y);
out[1] = cpu_to_le32(z);
+ return 0;
}

-static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
u32 y, z, n, sum;
u32 k0, k1, k2, k3;
@@ -115,6 +116,7 @@ static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out[0] = cpu_to_le32(y);
out[1] = cpu_to_le32(z);
+ return 0;
}

static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
@@ -132,7 +134,7 @@ static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key,

}

-static void xtea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int xtea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
u32 y, z, sum = 0;
u32 limit = XTEA_DELTA * XTEA_ROUNDS;
@@ -151,9 +153,10 @@ static void xtea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out[0] = cpu_to_le32(y);
out[1] = cpu_to_le32(z);
+ return 0;
}

-static void xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
u32 y, z, sum;
struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
@@ -173,10 +176,11 @@ static void xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out[0] = cpu_to_le32(y);
out[1] = cpu_to_le32(z);
+ return 0;
}


-static void xeta_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int xeta_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
u32 y, z, sum = 0;
u32 limit = XTEA_DELTA * XTEA_ROUNDS;
@@ -195,9 +199,10 @@ static void xeta_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out[0] = cpu_to_le32(y);
out[1] = cpu_to_le32(z);
+ return 0;
}

-static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
+static int xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
{
u32 y, z, sum;
struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
@@ -217,6 +222,7 @@ static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)

out[0] = cpu_to_le32(y);
out[1] = cpu_to_le32(z);
+ return 0;
}

static struct crypto_alg tea_alg = {
diff --git a/crypto/twofish.c b/crypto/twofish.c
index 4979a2b..aa9beaf 100644
--- a/crypto/twofish.c
+++ b/crypto/twofish.c
@@ -106,7 +106,7 @@


/* Encrypt one block. in and out may be the same. */
-static void twofish_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int twofish_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
const __le32 *src = (const __le32 *)in;
@@ -139,11 +139,11 @@ static void twofish_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
OUTUNPACK (1, d, 5);
OUTUNPACK (2, a, 6);
OUTUNPACK (3, b, 7);
-
+ return 0;
}

/* Decrypt one block. in and out may be the same. */
-static void twofish_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int twofish_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
const __le32 *src = (const __le32 *)in;
@@ -176,7 +176,7 @@ static void twofish_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
OUTUNPACK (1, b, 1);
OUTUNPACK (2, c, 2);
OUTUNPACK (3, d, 3);
-
+ return 0;
}

static struct crypto_alg alg = {
diff --git a/crypto/xts.c b/crypto/xts.c
index 8eb08bf..a154b2c 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -79,7 +79,7 @@ static int setkey(struct crypto_tfm *parent, const u8 *key,
struct sinfo {
be128 t;
struct crypto_tfm *tfm;
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *);
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *);
};

static inline void xts_round(struct sinfo *s, void *dst, const void *src)
@@ -91,8 +91,8 @@ static inline void xts_round(struct sinfo *s, void *dst, const void *src)

static int crypt(struct blkcipher_desc *d,
struct blkcipher_walk *w, struct priv *ctx,
- void (*tw)(struct crypto_tfm *, u8 *, const u8 *),
- void (*fn)(struct crypto_tfm *, u8 *, const u8 *))
+ int (*tw)(struct crypto_tfm *, u8 *, const u8 *),
+ int (*fn)(struct crypto_tfm *, u8 *, const u8 *))
{
int err;
unsigned int avail;
diff --git a/drivers/crypto/geode-aes.c b/drivers/crypto/geode-aes.c
index 4801162..a757d2b 100644
--- a/drivers/crypto/geode-aes.c
+++ b/drivers/crypto/geode-aes.c
@@ -63,7 +63,7 @@ do_crypt(void *src, void *dst, int len, u32 flags)

/* Clear the event */
iowrite32((status & 0xFF) | AES_INTRA_PENDING, _iobase + AES_INTR_REG);
- return counter ? 0 : 1;
+ return counter ? 0 : -1;
}

static unsigned int
@@ -101,14 +101,13 @@ geode_aes_crypt(struct geode_aes_op *op)
}

ret = do_crypt(op->src, op->dst, op->len, flags);
- BUG_ON(ret);

if (op->mode == AES_MODE_CBC)
_readfield(AES_WRITEIV0_REG, op->iv);

spin_unlock_irqrestore(&lock, iflags);

- return op->len;
+ return ret;
}

/* CRYPTO-API Functions */
@@ -212,14 +211,14 @@ static int fallback_blk_enc(struct blkcipher_desc *desc,
return ret;
}

-static void
+static int
geode_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct geode_aes_op *op = crypto_tfm_ctx(tfm);

if (unlikely(op->keylen != AES_KEYSIZE_128)) {
crypto_cipher_encrypt_one(op->fallback.cip, out, in);
- return;
+ return 0;
}

op->src = (void *) in;
@@ -229,18 +228,18 @@ geode_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
op->len = AES_MIN_BLOCK_SIZE;
op->dir = AES_DIR_ENCRYPT;

- geode_aes_crypt(op);
+ return geode_aes_crypt(op);
}


-static void
+static int
geode_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct geode_aes_op *op = crypto_tfm_ctx(tfm);

if (unlikely(op->keylen != AES_KEYSIZE_128)) {
crypto_cipher_decrypt_one(op->fallback.cip, out, in);
- return;
+ return 0;
}

op->src = (void *) in;
@@ -250,7 +249,7 @@ geode_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
op->len = AES_MIN_BLOCK_SIZE;
op->dir = AES_DIR_DECRYPT;

- geode_aes_crypt(op);
+ return geode_aes_crypt(op);
}

static int fallback_init_cip(struct crypto_tfm *tfm)
@@ -308,7 +307,7 @@ geode_cbc_decrypt(struct blkcipher_desc *desc,
{
struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm);
struct blkcipher_walk walk;
- int err, ret;
+ int err, ret = 0;

if (unlikely(op->keylen != AES_KEYSIZE_128))
return fallback_blk_dec(desc, dst, src, nbytes);
@@ -325,12 +324,11 @@ geode_cbc_decrypt(struct blkcipher_desc *desc,
op->dir = AES_DIR_DECRYPT;

ret = geode_aes_crypt(op);
-
- nbytes -= ret;
+ nbytes -= op->len;
err = blkcipher_walk_done(desc, &walk, nbytes);
}

- return err;
+ return err ? err : ret;
}

static int
@@ -340,7 +338,7 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
{
struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm);
struct blkcipher_walk walk;
- int err, ret;
+ int err, ret = 0;

if (unlikely(op->keylen != AES_KEYSIZE_128))
return fallback_blk_enc(desc, dst, src, nbytes);
@@ -357,11 +355,11 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
op->dir = AES_DIR_ENCRYPT;

ret = geode_aes_crypt(op);
- nbytes -= ret;
+ nbytes -= op->len;
err = blkcipher_walk_done(desc, &walk, nbytes);
}

- return err;
+ return err ? err : ret;
}

static int fallback_init_blk(struct crypto_tfm *tfm)
@@ -421,7 +419,7 @@ geode_ecb_decrypt(struct blkcipher_desc *desc,
{
struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm);
struct blkcipher_walk walk;
- int err, ret;
+ int err, ret = 0;

if (unlikely(op->keylen != AES_KEYSIZE_128))
return fallback_blk_dec(desc, dst, src, nbytes);
@@ -437,11 +435,11 @@ geode_ecb_decrypt(struct blkcipher_desc *desc,
op->dir = AES_DIR_DECRYPT;

ret = geode_aes_crypt(op);
- nbytes -= ret;
+ nbytes -= op->len;
err = blkcipher_walk_done(desc, &walk, nbytes);
}

- return err;
+ return err ? err : ret;
}

static int
@@ -451,7 +449,7 @@ geode_ecb_encrypt(struct blkcipher_desc *desc,
{
struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm);
struct blkcipher_walk walk;
- int err, ret;
+ int err, ret = 0;

if (unlikely(op->keylen != AES_KEYSIZE_128))
return fallback_blk_enc(desc, dst, src, nbytes);
@@ -467,11 +465,11 @@ geode_ecb_encrypt(struct blkcipher_desc *desc,
op->dir = AES_DIR_ENCRYPT;

ret = geode_aes_crypt(op);
- nbytes -= ret;
+ nbytes -= op->len;
ret = blkcipher_walk_done(desc, &walk, nbytes);
}

- return err;
+ return err ? err : ret;
}

static struct crypto_alg geode_ecb_alg = {
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 2f3ad3f..08fc240 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -483,18 +483,20 @@ static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
return iv;
}

-static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct aes_ctx *ctx = aes_ctx(tfm);
padlock_reset_key();
aes_crypt(in, out, ctx->E, &ctx->cword.encrypt);
+ return 0;
}

-static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
+static int aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
{
struct aes_ctx *ctx = aes_ctx(tfm);
padlock_reset_key();
aes_crypt(in, out, ctx->D, &ctx->cword.decrypt);
+ return 0;
}

static struct crypto_alg aes_alg = {
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 5e02d1b..9ee7fea 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -232,8 +232,8 @@ struct cipher_alg {
unsigned int cia_max_keysize;
int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
unsigned int keylen);
- void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
- void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+ int (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+ int (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
};

struct digest_alg {
@@ -374,8 +374,8 @@ struct blkcipher_tfm {
struct cipher_tfm {
int (*cit_setkey)(struct crypto_tfm *tfm,
const u8 *key, unsigned int keylen);
- void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
- void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+ int (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
+ int (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
};

struct hash_tfm {
--
1.5.3.6

Subject: [PATCH] [crypto] blockmode, use cipher ret val

Signed-off-by: Sebastian Siewior <[email protected]>
---
crypto/cbc.c | 22 +++++++++++++---------
crypto/ecb.c | 7 ++++---
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/crypto/cbc.c b/crypto/cbc.c
index a525dcc..15c8095 100644
--- a/crypto/cbc.c
+++ b/crypto/cbc.c
@@ -50,17 +50,18 @@ static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc,
u8 *src = walk->src.virt.addr;
u8 *dst = walk->dst.virt.addr;
u8 *iv = walk->iv;
+ int ret;

do {
crypto_xor(iv, src, bsize);
- fn(crypto_cipher_tfm(tfm), dst, iv);
+ ret = fn(crypto_cipher_tfm(tfm), dst, iv);
memcpy(iv, dst, bsize);

src += bsize;
dst += bsize;
- } while ((nbytes -= bsize) >= bsize);
+ } while (!ret && (nbytes -= bsize) >= bsize);

- return nbytes;
+ return nbytes ? nbytes : ret;
}

static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc,
@@ -73,14 +74,15 @@ static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc,
unsigned int nbytes = walk->nbytes;
u8 *src = walk->src.virt.addr;
u8 *iv = walk->iv;
+ int ret;

do {
crypto_xor(src, iv, bsize);
- fn(crypto_cipher_tfm(tfm), src, src);
+ ret = fn(crypto_cipher_tfm(tfm), src, src);
iv = src;

src += bsize;
- } while ((nbytes -= bsize) >= bsize);
+ } while (!ret && (nbytes -= bsize) >= bsize);

memcpy(walk->iv, iv, bsize);

@@ -122,15 +124,16 @@ static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc,
u8 *src = walk->src.virt.addr;
u8 *dst = walk->dst.virt.addr;
u8 *iv = walk->iv;
+ int ret;

do {
- fn(crypto_cipher_tfm(tfm), dst, src);
+ ret = fn(crypto_cipher_tfm(tfm), dst, src);
crypto_xor(dst, iv, bsize);
iv = src;

src += bsize;
dst += bsize;
- } while ((nbytes -= bsize) >= bsize);
+ } while (!ret && (nbytes -= bsize) >= bsize);

memcpy(walk->iv, iv, bsize);

@@ -147,14 +150,15 @@ static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc,
unsigned int nbytes = walk->nbytes;
u8 *src = walk->src.virt.addr;
u8 last_iv[bsize];
+ int ret;

/* Start of the last block. */
src += nbytes - (nbytes & (bsize - 1)) - bsize;
memcpy(last_iv, src, bsize);

for (;;) {
- fn(crypto_cipher_tfm(tfm), src, src);
- if ((nbytes -= bsize) < bsize)
+ ret = fn(crypto_cipher_tfm(tfm), src, src);
+ if (ret || (nbytes -= bsize) < bsize)
break;
crypto_xor(src, src - bsize, bsize);
src -= bsize;
diff --git a/crypto/ecb.c b/crypto/ecb.c
index 1edb94f..04a5083 100644
--- a/crypto/ecb.c
+++ b/crypto/ecb.c
@@ -46,6 +46,7 @@ static int crypto_ecb_crypt(struct blkcipher_desc *desc,
int bsize = crypto_cipher_blocksize(tfm);
unsigned int nbytes;
int err;
+ int ret = 0;

err = blkcipher_walk_virt(desc, walk);

@@ -54,16 +55,16 @@ static int crypto_ecb_crypt(struct blkcipher_desc *desc,
u8 *wdst = walk->dst.virt.addr;

do {
- fn(crypto_cipher_tfm(tfm), wdst, wsrc);
+ ret = fn(crypto_cipher_tfm(tfm), wdst, wsrc);

wsrc += bsize;
wdst += bsize;
- } while ((nbytes -= bsize) >= bsize);
+ } while ((nbytes -= bsize) >= bsize && !ret);

err = blkcipher_walk_done(desc, walk, nbytes);
}

- return err;
+ return err ? err : ret;
}

static int crypto_ecb_encrypt(struct blkcipher_desc *desc,
--
1.5.3.6

Subject: Re: small patch queue

* Herbert Xu | 2008-03-11 21:32:38 [+0800]:

>> The error recovery could get quite complex here, so maybe a BUG() statement
>> isn't that bad at all or?
>
>OK it seems that the only one that can really fail here is Geode.
>At this point I don't think we want to make such an intrusive change
>just for the Geode.
That's what I though :)

>Perhaps a better solution for it would be to convert it to the
>async interface and use polling from a kernel thread? How fast
>is it anyway?
Something like 1.7 MB/sec on dm-crypt if I remember correctly. It was
faster than software.
I thing there is no need for polling because the geode has an interrupt.

>Cheers,

Sebastian

2008-03-13 11:24:03

by Herbert Xu

[permalink] [raw]
Subject: Re: small patch queue

On Wed, Mar 12, 2008 at 06:18:13PM +0100, Sebastian Siewior wrote:
>
> Something like 1.7 MB/sec on dm-crypt if I remember correctly. It was
> faster than software.
> I thing there is no need for polling because the geode has an interrupt.

OK then async is definitely the way to go.

Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt