summaryrefslogtreecommitdiff
path: root/drivers/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-07-06 13:52:43 -0700
committerDavid S. Miller <davem@davemloft.net>2005-07-06 13:52:43 -0700
commit28e8c3ad9464de54a632f00ab3df88fa5f4652d1 (patch)
treeba62694afc67bcd6dc817d137e8259cb526a51c6 /drivers/crypto
parent6789b2dc455b90efc9c88886c9366adc9abb7347 (diff)
downloadlinux-3.10-28e8c3ad9464de54a632f00ab3df88fa5f4652d1.tar.gz
linux-3.10-28e8c3ad9464de54a632f00ab3df88fa5f4652d1.tar.bz2
linux-3.10-28e8c3ad9464de54a632f00ab3df88fa5f4652d1.zip
[PADLOCK] Implement multi-block operations
By operating on multiple blocks at once, we expect to extract more performance out of the VIA Padlock. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/padlock-aes.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 5f28909d401..d2745ff4699 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -390,7 +390,7 @@ aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t
/* ====== Encryption/decryption routines ====== */
-/* This is the real call to PadLock. */
+/* These are the real call to PadLock. */
static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
void *control_word, u32 count)
{
@@ -400,6 +400,17 @@ static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
: "d"(control_word), "b"(key), "c"(count));
}
+static inline void padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
+ u8 *iv, void *control_word, u32 count)
+{
+ /* Enforce key reload. */
+ asm volatile ("pushfl; popfl");
+ /* rep xcryptcbc */
+ asm volatile (".byte 0xf3,0x0f,0xa7,0xd0"
+ : "+S" (input), "+D" (output), "+a" (iv)
+ : "d" (control_word), "b" (key), "c" (count));
+}
+
static void
aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
{
@@ -414,6 +425,42 @@ aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1);
}
+static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
+ const u8 *in, unsigned int nbytes)
+{
+ struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
+ padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt,
+ nbytes / AES_BLOCK_SIZE);
+ return nbytes & ~(AES_BLOCK_SIZE - 1);
+}
+
+static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
+ const u8 *in, unsigned int nbytes)
+{
+ struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
+ padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt,
+ nbytes / AES_BLOCK_SIZE);
+ return nbytes & ~(AES_BLOCK_SIZE - 1);
+}
+
+static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
+ const u8 *in, unsigned int nbytes)
+{
+ struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
+ padlock_xcrypt_cbc(in, out, ctx->E, desc->info, &ctx->cword.encrypt,
+ nbytes / AES_BLOCK_SIZE);
+ return nbytes & ~(AES_BLOCK_SIZE - 1);
+}
+
+static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
+ const u8 *in, unsigned int nbytes)
+{
+ struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
+ padlock_xcrypt_cbc(in, out, ctx->D, desc->info, &ctx->cword.decrypt,
+ nbytes / AES_BLOCK_SIZE);
+ return nbytes & ~(AES_BLOCK_SIZE - 1);
+}
+
static struct crypto_alg aes_alg = {
.cra_name = "aes",
.cra_flags = CRYPTO_ALG_TYPE_CIPHER,
@@ -429,7 +476,11 @@ static struct crypto_alg aes_alg = {
.cia_max_keysize = AES_MAX_KEY_SIZE,
.cia_setkey = aes_set_key,
.cia_encrypt = aes_encrypt,
- .cia_decrypt = aes_decrypt
+ .cia_decrypt = aes_decrypt,
+ .cia_encrypt_ecb = aes_encrypt_ecb,
+ .cia_decrypt_ecb = aes_decrypt_ecb,
+ .cia_encrypt_cbc = aes_encrypt_cbc,
+ .cia_decrypt_cbc = aes_decrypt_cbc,
}
}
};