aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 14:03:29 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 14:03:29 -0400
commit972d19e837833b93466c6f6a8ef2a7d653000aa3 (patch)
tree069258492d5347cf440b8240dadfa20621f54842 /drivers
parentcdf4f383a4b0ffbf458f65380ecffbeee1f79841 (diff)
parentb9d0a25a484a90c1d60b974d115eff2fe580ce16 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6: [CRYPTO] tcrypt: Forbid tcrypt from being built-in [CRYPTO] aes: Add wrappers for assembly routines [CRYPTO] tcrypt: Speed benchmark support for digest algorithms [CRYPTO] tcrypt: Return -EAGAIN from module_init() [CRYPTO] api: Allow replacement when registering new algorithms [CRYPTO] api: Removed const from cra_name/cra_driver_name [CRYPTO] api: Added cra_init/cra_exit [CRYPTO] api: Fixed incorrect passing of context instead of tfm [CRYPTO] padlock: Rearrange context structure to reduce code size [CRYPTO] all: Pass tfm instead of ctx to algorithms [CRYPTO] digest: Remove unnecessary zeroing during init [CRYPTO] aes-i586: Get rid of useless function wrappers [CRYPTO] digest: Add alignment handling [CRYPTO] khazad: Use 32-bit reads on key
Diffstat (limited to 'drivers')
-rw-r--r--drivers/crypto/padlock-aes.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 5158a9db4bc5..17ee684144f9 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -60,15 +60,14 @@
60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t)) 60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t))
61 61
62struct aes_ctx { 62struct aes_ctx {
63 uint32_t e_data[AES_EXTENDED_KEY_SIZE];
64 uint32_t d_data[AES_EXTENDED_KEY_SIZE];
65 struct { 63 struct {
66 struct cword encrypt; 64 struct cword encrypt;
67 struct cword decrypt; 65 struct cword decrypt;
68 } cword; 66 } cword;
69 uint32_t *E; 67 u32 *D;
70 uint32_t *D;
71 int key_length; 68 int key_length;
69 u32 E[AES_EXTENDED_KEY_SIZE];
70 u32 d_data[AES_EXTENDED_KEY_SIZE];
72}; 71};
73 72
74/* ====== Key management routines ====== */ 73/* ====== Key management routines ====== */
@@ -282,19 +281,20 @@ aes_hw_extkey_available(uint8_t key_len)
282 return 0; 281 return 0;
283} 282}
284 283
285static inline struct aes_ctx *aes_ctx(void *ctx) 284static inline struct aes_ctx *aes_ctx(struct crypto_tfm *tfm)
286{ 285{
286 unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm);
287 unsigned long align = PADLOCK_ALIGNMENT; 287 unsigned long align = PADLOCK_ALIGNMENT;
288 288
289 if (align <= crypto_tfm_ctx_alignment()) 289 if (align <= crypto_tfm_ctx_alignment())
290 align = 1; 290 align = 1;
291 return (struct aes_ctx *)ALIGN((unsigned long)ctx, align); 291 return (struct aes_ctx *)ALIGN(addr, align);
292} 292}
293 293
294static int 294static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
295aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t *flags) 295 unsigned int key_len, u32 *flags)
296{ 296{
297 struct aes_ctx *ctx = aes_ctx(ctx_arg); 297 struct aes_ctx *ctx = aes_ctx(tfm);
298 const __le32 *key = (const __le32 *)in_key; 298 const __le32 *key = (const __le32 *)in_key;
299 uint32_t i, t, u, v, w; 299 uint32_t i, t, u, v, w;
300 uint32_t P[AES_EXTENDED_KEY_SIZE]; 300 uint32_t P[AES_EXTENDED_KEY_SIZE];
@@ -312,8 +312,7 @@ aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t
312 * itself we must supply the plain key for both encryption 312 * itself we must supply the plain key for both encryption
313 * and decryption. 313 * and decryption.
314 */ 314 */
315 ctx->E = ctx->e_data; 315 ctx->D = ctx->E;
316 ctx->D = ctx->e_data;
317 316
318 E_KEY[0] = le32_to_cpu(key[0]); 317 E_KEY[0] = le32_to_cpu(key[0]);
319 E_KEY[1] = le32_to_cpu(key[1]); 318 E_KEY[1] = le32_to_cpu(key[1]);
@@ -414,24 +413,22 @@ static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
414 return iv; 413 return iv;
415} 414}
416 415
417static void 416static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
418aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
419{ 417{
420 struct aes_ctx *ctx = aes_ctx(ctx_arg); 418 struct aes_ctx *ctx = aes_ctx(tfm);
421 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 1); 419 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 1);
422} 420}
423 421
424static void 422static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
425aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
426{ 423{
427 struct aes_ctx *ctx = aes_ctx(ctx_arg); 424 struct aes_ctx *ctx = aes_ctx(tfm);
428 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1); 425 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1);
429} 426}
430 427
431static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out, 428static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
432 const u8 *in, unsigned int nbytes) 429 const u8 *in, unsigned int nbytes)
433{ 430{
434 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm)); 431 struct aes_ctx *ctx = aes_ctx(desc->tfm);
435 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 432 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt,
436 nbytes / AES_BLOCK_SIZE); 433 nbytes / AES_BLOCK_SIZE);
437 return nbytes & ~(AES_BLOCK_SIZE - 1); 434 return nbytes & ~(AES_BLOCK_SIZE - 1);
@@ -440,7 +437,7 @@ static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
440static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out, 437static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
441 const u8 *in, unsigned int nbytes) 438 const u8 *in, unsigned int nbytes)
442{ 439{
443 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm)); 440 struct aes_ctx *ctx = aes_ctx(desc->tfm);
444 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 441 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt,
445 nbytes / AES_BLOCK_SIZE); 442 nbytes / AES_BLOCK_SIZE);
446 return nbytes & ~(AES_BLOCK_SIZE - 1); 443 return nbytes & ~(AES_BLOCK_SIZE - 1);
@@ -449,7 +446,7 @@ static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
449static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out, 446static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
450 const u8 *in, unsigned int nbytes) 447 const u8 *in, unsigned int nbytes)
451{ 448{
452 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm)); 449 struct aes_ctx *ctx = aes_ctx(desc->tfm);
453 u8 *iv; 450 u8 *iv;
454 451
455 iv = padlock_xcrypt_cbc(in, out, ctx->E, desc->info, 452 iv = padlock_xcrypt_cbc(in, out, ctx->E, desc->info,
@@ -462,7 +459,7 @@ static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
462static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out, 459static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
463 const u8 *in, unsigned int nbytes) 460 const u8 *in, unsigned int nbytes)
464{ 461{
465 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm)); 462 struct aes_ctx *ctx = aes_ctx(desc->tfm);
466 padlock_xcrypt_cbc(in, out, ctx->D, desc->info, &ctx->cword.decrypt, 463 padlock_xcrypt_cbc(in, out, ctx->D, desc->info, &ctx->cword.decrypt,
467 nbytes / AES_BLOCK_SIZE); 464 nbytes / AES_BLOCK_SIZE);
468 return nbytes & ~(AES_BLOCK_SIZE - 1); 465 return nbytes & ~(AES_BLOCK_SIZE - 1);