blob: bf2917d197a018d13f1bc48ad4c93c0b0a93ccde [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Cryptographic API.
3 *
4 * Support for VIA PadLock hardware crypto engine.
5 *
6 * Copyright (c) 2004 Michal Ludvig <michal@logix.cz>
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Herbert Xu28ce7282006-08-21 21:38:42 +100010#include <crypto/algapi.h>
Sebastian Siewior89e126542007-10-17 23:18:57 +080011#include <crypto/aes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/types.h>
15#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/interrupt.h>
Herbert Xu6789b2d2005-07-06 13:52:27 -070017#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/byteorder.h>
Suresh Siddhae4914012008-08-13 22:02:26 +100019#include <asm/i387.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "padlock.h"
21
Michal Ludvigccc17c32006-07-15 10:23:49 +100022/* Control word. */
23struct cword {
24 unsigned int __attribute__ ((__packed__))
25 rounds:4,
26 algo:3,
27 keygen:1,
28 interm:1,
29 encdec:1,
30 ksize:2;
31} __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
32
Michal Ludvigcc086322006-07-15 11:08:50 +100033/* Whenever making any changes to the following
34 * structure *make sure* you keep E, d_data
Sebastian Siewior7dc748e2008-04-01 21:24:50 +080035 * and cword aligned on 16 Bytes boundaries and
36 * the Hardware can access 16 * 16 bytes of E and d_data
37 * (only the first 15 * 16 bytes matter but the HW reads
38 * more).
39 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070040struct aes_ctx {
Sebastian Siewior7dc748e2008-04-01 21:24:50 +080041 u32 E[AES_MAX_KEYLENGTH_U32]
42 __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
43 u32 d_data[AES_MAX_KEYLENGTH_U32]
44 __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
Herbert Xu6789b2d2005-07-06 13:52:27 -070045 struct {
46 struct cword encrypt;
47 struct cword decrypt;
48 } cword;
Herbert Xu82062c72006-05-16 22:20:34 +100049 u32 *D;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* Tells whether the ACE is capable to generate
53 the extended key for a given key_len. */
54static inline int
55aes_hw_extkey_available(uint8_t key_len)
56{
57 /* TODO: We should check the actual CPU model/stepping
58 as it's possible that the capability will be
59 added in the next CPU revisions. */
60 if (key_len == 16)
61 return 1;
62 return 0;
63}
64
Herbert Xu28ce7282006-08-21 21:38:42 +100065static inline struct aes_ctx *aes_ctx_common(void *ctx)
Herbert Xu6789b2d2005-07-06 13:52:27 -070066{
Herbert Xu28ce7282006-08-21 21:38:42 +100067 unsigned long addr = (unsigned long)ctx;
Herbert Xuf10b7892006-01-25 22:34:01 +110068 unsigned long align = PADLOCK_ALIGNMENT;
69
70 if (align <= crypto_tfm_ctx_alignment())
71 align = 1;
Herbert Xu6c2bb982006-05-16 22:09:29 +100072 return (struct aes_ctx *)ALIGN(addr, align);
Herbert Xu6789b2d2005-07-06 13:52:27 -070073}
74
Herbert Xu28ce7282006-08-21 21:38:42 +100075static inline struct aes_ctx *aes_ctx(struct crypto_tfm *tfm)
76{
77 return aes_ctx_common(crypto_tfm_ctx(tfm));
78}
79
80static inline struct aes_ctx *blk_aes_ctx(struct crypto_blkcipher *tfm)
81{
82 return aes_ctx_common(crypto_blkcipher_ctx(tfm));
83}
84
Herbert Xu6c2bb982006-05-16 22:09:29 +100085static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
Herbert Xu560c06a2006-08-13 14:16:39 +100086 unsigned int key_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Herbert Xu6c2bb982006-05-16 22:09:29 +100088 struct aes_ctx *ctx = aes_ctx(tfm);
Herbert Xu06ace7a2005-10-30 21:25:15 +110089 const __le32 *key = (const __le32 *)in_key;
Herbert Xu560c06a2006-08-13 14:16:39 +100090 u32 *flags = &tfm->crt_flags;
Sebastian Siewior7dc748e2008-04-01 21:24:50 +080091 struct crypto_aes_ctx gen_aes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Herbert Xu560c06a2006-08-13 14:16:39 +100093 if (key_len % 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
95 return -EINVAL;
96 }
97
Herbert Xu6789b2d2005-07-06 13:52:27 -070098 /*
99 * If the hardware is capable of generating the extended key
100 * itself we must supply the plain key for both encryption
101 * and decryption.
102 */
Herbert Xu82062c72006-05-16 22:20:34 +1000103 ctx->D = ctx->E;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Sebastian Siewior7dc748e2008-04-01 21:24:50 +0800105 ctx->E[0] = le32_to_cpu(key[0]);
106 ctx->E[1] = le32_to_cpu(key[1]);
107 ctx->E[2] = le32_to_cpu(key[2]);
108 ctx->E[3] = le32_to_cpu(key[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Herbert Xu6789b2d2005-07-06 13:52:27 -0700110 /* Prepare control words. */
111 memset(&ctx->cword, 0, sizeof(ctx->cword));
112
113 ctx->cword.decrypt.encdec = 1;
114 ctx->cword.encrypt.rounds = 10 + (key_len - 16) / 4;
115 ctx->cword.decrypt.rounds = ctx->cword.encrypt.rounds;
116 ctx->cword.encrypt.ksize = (key_len - 16) / 8;
117 ctx->cword.decrypt.ksize = ctx->cword.encrypt.ksize;
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 /* Don't generate extended keys if the hardware can do it. */
120 if (aes_hw_extkey_available(key_len))
121 return 0;
122
Herbert Xu6789b2d2005-07-06 13:52:27 -0700123 ctx->D = ctx->d_data;
124 ctx->cword.encrypt.keygen = 1;
125 ctx->cword.decrypt.keygen = 1;
126
Sebastian Siewior7dc748e2008-04-01 21:24:50 +0800127 if (crypto_aes_expand_key(&gen_aes, in_key, key_len)) {
128 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
129 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
Sebastian Siewior7dc748e2008-04-01 21:24:50 +0800132 memcpy(ctx->E, gen_aes.key_enc, AES_MAX_KEYLENGTH);
133 memcpy(ctx->D, gen_aes.key_dec, AES_MAX_KEYLENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return 0;
135}
136
137/* ====== Encryption/decryption routines ====== */
138
Herbert Xu28e8c3a2005-07-06 13:52:43 -0700139/* These are the real call to PadLock. */
Herbert Xu866cd902007-12-27 00:04:44 +1100140static inline void padlock_reset_key(void)
141{
142 asm volatile ("pushfl; popfl");
143}
144
Suresh Siddhae4914012008-08-13 22:02:26 +1000145/*
146 * While the padlock instructions don't use FP/SSE registers, they
147 * generate a spurious DNA fault when cr0.ts is '1'. These instructions
148 * should be used only inside the irq_ts_save/restore() context
149 */
150
Herbert Xud4a7dd82007-12-28 11:05:46 +1100151static inline void padlock_xcrypt(const u8 *input, u8 *output, void *key,
152 void *control_word)
153{
154 asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
155 : "+S"(input), "+D"(output)
156 : "d"(control_word), "b"(key), "c"(1));
157}
158
159static void aes_crypt_copy(const u8 *in, u8 *out, u32 *key, struct cword *cword)
160{
Herbert Xu490fe3f2008-01-11 08:09:35 +1100161 u8 buf[AES_BLOCK_SIZE * 2 + PADLOCK_ALIGNMENT - 1];
162 u8 *tmp = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT);
Herbert Xud4a7dd82007-12-28 11:05:46 +1100163
164 memcpy(tmp, in, AES_BLOCK_SIZE);
165 padlock_xcrypt(tmp, out, key, cword);
166}
167
168static inline void aes_crypt(const u8 *in, u8 *out, u32 *key,
169 struct cword *cword)
170{
Herbert Xud4a7dd82007-12-28 11:05:46 +1100171 /* padlock_xcrypt requires at least two blocks of data. */
172 if (unlikely(!(((unsigned long)in ^ (PAGE_SIZE - AES_BLOCK_SIZE)) &
173 (PAGE_SIZE - 1)))) {
174 aes_crypt_copy(in, out, key, cword);
175 return;
176 }
177
178 padlock_xcrypt(in, out, key, cword);
179}
180
Herbert Xu6789b2d2005-07-06 13:52:27 -0700181static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
182 void *control_word, u32 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Herbert Xud4a7dd82007-12-28 11:05:46 +1100184 if (count == 1) {
185 aes_crypt(input, output, key, control_word);
186 return;
187 }
188
Herbert Xud4a7dd82007-12-28 11:05:46 +1100189 asm volatile ("test $1, %%cl;"
190 "je 1f;"
191 "lea -1(%%ecx), %%eax;"
192 "mov $1, %%ecx;"
193 ".byte 0xf3,0x0f,0xa7,0xc8;" /* rep xcryptecb */
194 "mov %%eax, %%ecx;"
195 "1:"
196 ".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 : "+S"(input), "+D"(output)
Herbert Xud4a7dd82007-12-28 11:05:46 +1100198 : "d"(control_word), "b"(key), "c"(count)
199 : "ax");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
Herbert Xu476df252005-07-06 13:54:09 -0700202static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
203 u8 *iv, void *control_word, u32 count)
Herbert Xu28e8c3a2005-07-06 13:52:43 -0700204{
Herbert Xu28e8c3a2005-07-06 13:52:43 -0700205 /* rep xcryptcbc */
206 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0"
207 : "+S" (input), "+D" (output), "+a" (iv)
208 : "d" (control_word), "b" (key), "c" (count));
Herbert Xu476df252005-07-06 13:54:09 -0700209 return iv;
Herbert Xu28e8c3a2005-07-06 13:52:43 -0700210}
211
Herbert Xu6c2bb982006-05-16 22:09:29 +1000212static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Herbert Xu6c2bb982006-05-16 22:09:29 +1000214 struct aes_ctx *ctx = aes_ctx(tfm);
Suresh Siddhae4914012008-08-13 22:02:26 +1000215 int ts_state;
Herbert Xu866cd902007-12-27 00:04:44 +1100216 padlock_reset_key();
Suresh Siddhae4914012008-08-13 22:02:26 +1000217
218 ts_state = irq_ts_save();
Herbert Xud4a7dd82007-12-28 11:05:46 +1100219 aes_crypt(in, out, ctx->E, &ctx->cword.encrypt);
Suresh Siddhae4914012008-08-13 22:02:26 +1000220 irq_ts_restore(ts_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Herbert Xu6c2bb982006-05-16 22:09:29 +1000223static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Herbert Xu6c2bb982006-05-16 22:09:29 +1000225 struct aes_ctx *ctx = aes_ctx(tfm);
Suresh Siddhae4914012008-08-13 22:02:26 +1000226 int ts_state;
Herbert Xu866cd902007-12-27 00:04:44 +1100227 padlock_reset_key();
Suresh Siddhae4914012008-08-13 22:02:26 +1000228
229 ts_state = irq_ts_save();
Herbert Xud4a7dd82007-12-28 11:05:46 +1100230 aes_crypt(in, out, ctx->D, &ctx->cword.decrypt);
Suresh Siddhae4914012008-08-13 22:02:26 +1000231 irq_ts_restore(ts_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
234static struct crypto_alg aes_alg = {
235 .cra_name = "aes",
Herbert Xuc8a19c92005-11-05 18:06:26 +1100236 .cra_driver_name = "aes-padlock",
Michal Ludvigccc17c32006-07-15 10:23:49 +1000237 .cra_priority = PADLOCK_CRA_PRIORITY,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
239 .cra_blocksize = AES_BLOCK_SIZE,
Herbert Xufbdae9f2005-07-06 13:53:29 -0700240 .cra_ctxsize = sizeof(struct aes_ctx),
Herbert Xu6789b2d2005-07-06 13:52:27 -0700241 .cra_alignmask = PADLOCK_ALIGNMENT - 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .cra_module = THIS_MODULE,
243 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
244 .cra_u = {
245 .cipher = {
246 .cia_min_keysize = AES_MIN_KEY_SIZE,
247 .cia_max_keysize = AES_MAX_KEY_SIZE,
248 .cia_setkey = aes_set_key,
249 .cia_encrypt = aes_encrypt,
Herbert Xu28e8c3a2005-07-06 13:52:43 -0700250 .cia_decrypt = aes_decrypt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252 }
253};
254
Herbert Xu28ce7282006-08-21 21:38:42 +1000255static int ecb_aes_encrypt(struct blkcipher_desc *desc,
256 struct scatterlist *dst, struct scatterlist *src,
257 unsigned int nbytes)
258{
259 struct aes_ctx *ctx = blk_aes_ctx(desc->tfm);
260 struct blkcipher_walk walk;
261 int err;
Suresh Siddhae4914012008-08-13 22:02:26 +1000262 int ts_state;
Herbert Xu28ce7282006-08-21 21:38:42 +1000263
Herbert Xu866cd902007-12-27 00:04:44 +1100264 padlock_reset_key();
265
Herbert Xu28ce7282006-08-21 21:38:42 +1000266 blkcipher_walk_init(&walk, dst, src, nbytes);
267 err = blkcipher_walk_virt(desc, &walk);
268
Suresh Siddhae4914012008-08-13 22:02:26 +1000269 ts_state = irq_ts_save();
Herbert Xu28ce7282006-08-21 21:38:42 +1000270 while ((nbytes = walk.nbytes)) {
271 padlock_xcrypt_ecb(walk.src.virt.addr, walk.dst.virt.addr,
272 ctx->E, &ctx->cword.encrypt,
273 nbytes / AES_BLOCK_SIZE);
274 nbytes &= AES_BLOCK_SIZE - 1;
275 err = blkcipher_walk_done(desc, &walk, nbytes);
276 }
Suresh Siddhae4914012008-08-13 22:02:26 +1000277 irq_ts_restore(ts_state);
Herbert Xu28ce7282006-08-21 21:38:42 +1000278
279 return err;
280}
281
282static int ecb_aes_decrypt(struct blkcipher_desc *desc,
283 struct scatterlist *dst, struct scatterlist *src,
284 unsigned int nbytes)
285{
286 struct aes_ctx *ctx = blk_aes_ctx(desc->tfm);
287 struct blkcipher_walk walk;
288 int err;
Suresh Siddhae4914012008-08-13 22:02:26 +1000289 int ts_state;
Herbert Xu28ce7282006-08-21 21:38:42 +1000290
Herbert Xu866cd902007-12-27 00:04:44 +1100291 padlock_reset_key();
292
Herbert Xu28ce7282006-08-21 21:38:42 +1000293 blkcipher_walk_init(&walk, dst, src, nbytes);
294 err = blkcipher_walk_virt(desc, &walk);
295
Suresh Siddhae4914012008-08-13 22:02:26 +1000296 ts_state = irq_ts_save();
Herbert Xu28ce7282006-08-21 21:38:42 +1000297 while ((nbytes = walk.nbytes)) {
298 padlock_xcrypt_ecb(walk.src.virt.addr, walk.dst.virt.addr,
299 ctx->D, &ctx->cword.decrypt,
300 nbytes / AES_BLOCK_SIZE);
301 nbytes &= AES_BLOCK_SIZE - 1;
302 err = blkcipher_walk_done(desc, &walk, nbytes);
303 }
Suresh Siddhae4914012008-08-13 22:02:26 +1000304 irq_ts_restore(ts_state);
Herbert Xu28ce7282006-08-21 21:38:42 +1000305 return err;
306}
307
308static struct crypto_alg ecb_aes_alg = {
309 .cra_name = "ecb(aes)",
310 .cra_driver_name = "ecb-aes-padlock",
311 .cra_priority = PADLOCK_COMPOSITE_PRIORITY,
312 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
313 .cra_blocksize = AES_BLOCK_SIZE,
314 .cra_ctxsize = sizeof(struct aes_ctx),
315 .cra_alignmask = PADLOCK_ALIGNMENT - 1,
316 .cra_type = &crypto_blkcipher_type,
317 .cra_module = THIS_MODULE,
318 .cra_list = LIST_HEAD_INIT(ecb_aes_alg.cra_list),
319 .cra_u = {
320 .blkcipher = {
321 .min_keysize = AES_MIN_KEY_SIZE,
322 .max_keysize = AES_MAX_KEY_SIZE,
323 .setkey = aes_set_key,
324 .encrypt = ecb_aes_encrypt,
325 .decrypt = ecb_aes_decrypt,
326 }
327 }
328};
329
330static int cbc_aes_encrypt(struct blkcipher_desc *desc,
331 struct scatterlist *dst, struct scatterlist *src,
332 unsigned int nbytes)
333{
334 struct aes_ctx *ctx = blk_aes_ctx(desc->tfm);
335 struct blkcipher_walk walk;
336 int err;
Suresh Siddhae4914012008-08-13 22:02:26 +1000337 int ts_state;
Herbert Xu28ce7282006-08-21 21:38:42 +1000338
Herbert Xu866cd902007-12-27 00:04:44 +1100339 padlock_reset_key();
340
Herbert Xu28ce7282006-08-21 21:38:42 +1000341 blkcipher_walk_init(&walk, dst, src, nbytes);
342 err = blkcipher_walk_virt(desc, &walk);
343
Suresh Siddhae4914012008-08-13 22:02:26 +1000344 ts_state = irq_ts_save();
Herbert Xu28ce7282006-08-21 21:38:42 +1000345 while ((nbytes = walk.nbytes)) {
346 u8 *iv = padlock_xcrypt_cbc(walk.src.virt.addr,
347 walk.dst.virt.addr, ctx->E,
348 walk.iv, &ctx->cword.encrypt,
349 nbytes / AES_BLOCK_SIZE);
350 memcpy(walk.iv, iv, AES_BLOCK_SIZE);
351 nbytes &= AES_BLOCK_SIZE - 1;
352 err = blkcipher_walk_done(desc, &walk, nbytes);
353 }
Suresh Siddhae4914012008-08-13 22:02:26 +1000354 irq_ts_restore(ts_state);
Herbert Xu28ce7282006-08-21 21:38:42 +1000355
356 return err;
357}
358
359static int cbc_aes_decrypt(struct blkcipher_desc *desc,
360 struct scatterlist *dst, struct scatterlist *src,
361 unsigned int nbytes)
362{
363 struct aes_ctx *ctx = blk_aes_ctx(desc->tfm);
364 struct blkcipher_walk walk;
365 int err;
Suresh Siddhae4914012008-08-13 22:02:26 +1000366 int ts_state;
Herbert Xu28ce7282006-08-21 21:38:42 +1000367
Herbert Xu866cd902007-12-27 00:04:44 +1100368 padlock_reset_key();
369
Herbert Xu28ce7282006-08-21 21:38:42 +1000370 blkcipher_walk_init(&walk, dst, src, nbytes);
371 err = blkcipher_walk_virt(desc, &walk);
372
Suresh Siddhae4914012008-08-13 22:02:26 +1000373 ts_state = irq_ts_save();
Herbert Xu28ce7282006-08-21 21:38:42 +1000374 while ((nbytes = walk.nbytes)) {
375 padlock_xcrypt_cbc(walk.src.virt.addr, walk.dst.virt.addr,
376 ctx->D, walk.iv, &ctx->cword.decrypt,
377 nbytes / AES_BLOCK_SIZE);
378 nbytes &= AES_BLOCK_SIZE - 1;
379 err = blkcipher_walk_done(desc, &walk, nbytes);
380 }
381
Suresh Siddhae4914012008-08-13 22:02:26 +1000382 irq_ts_restore(ts_state);
Herbert Xu28ce7282006-08-21 21:38:42 +1000383 return err;
384}
385
386static struct crypto_alg cbc_aes_alg = {
387 .cra_name = "cbc(aes)",
388 .cra_driver_name = "cbc-aes-padlock",
389 .cra_priority = PADLOCK_COMPOSITE_PRIORITY,
390 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
391 .cra_blocksize = AES_BLOCK_SIZE,
392 .cra_ctxsize = sizeof(struct aes_ctx),
393 .cra_alignmask = PADLOCK_ALIGNMENT - 1,
394 .cra_type = &crypto_blkcipher_type,
395 .cra_module = THIS_MODULE,
396 .cra_list = LIST_HEAD_INIT(cbc_aes_alg.cra_list),
397 .cra_u = {
398 .blkcipher = {
399 .min_keysize = AES_MIN_KEY_SIZE,
400 .max_keysize = AES_MAX_KEY_SIZE,
401 .ivsize = AES_BLOCK_SIZE,
402 .setkey = aes_set_key,
403 .encrypt = cbc_aes_encrypt,
404 .decrypt = cbc_aes_decrypt,
405 }
406 }
407};
408
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000409static int __init padlock_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000411 int ret;
412
413 if (!cpu_has_xcrypt) {
Jeremy Katzb43e7262008-07-03 19:03:31 +0800414 printk(KERN_NOTICE PFX "VIA PadLock not detected.\n");
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000415 return -ENODEV;
416 }
417
418 if (!cpu_has_xcrypt_enabled) {
Jeremy Katzb43e7262008-07-03 19:03:31 +0800419 printk(KERN_NOTICE PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n");
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000420 return -ENODEV;
421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Herbert Xu28ce7282006-08-21 21:38:42 +1000423 if ((ret = crypto_register_alg(&aes_alg)))
424 goto aes_err;
425
426 if ((ret = crypto_register_alg(&ecb_aes_alg)))
427 goto ecb_aes_err;
428
429 if ((ret = crypto_register_alg(&cbc_aes_alg)))
430 goto cbc_aes_err;
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000431
432 printk(KERN_NOTICE PFX "Using VIA PadLock ACE for AES algorithm.\n");
433
Herbert Xu28ce7282006-08-21 21:38:42 +1000434out:
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000435 return ret;
Herbert Xu28ce7282006-08-21 21:38:42 +1000436
437cbc_aes_err:
438 crypto_unregister_alg(&ecb_aes_alg);
439ecb_aes_err:
440 crypto_unregister_alg(&aes_alg);
441aes_err:
442 printk(KERN_ERR PFX "VIA PadLock AES initialization failed.\n");
443 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000446static void __exit padlock_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Herbert Xu28ce7282006-08-21 21:38:42 +1000448 crypto_unregister_alg(&cbc_aes_alg);
449 crypto_unregister_alg(&ecb_aes_alg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 crypto_unregister_alg(&aes_alg);
451}
Michal Ludvig1191f0a2006-08-06 22:46:20 +1000452
453module_init(padlock_init);
454module_exit(padlock_fini);
455
456MODULE_DESCRIPTION("VIA PadLock AES algorithm support");
457MODULE_LICENSE("GPL");
458MODULE_AUTHOR("Michal Ludvig");
459
Sebastian Siewiorf8246af2007-10-05 16:52:01 +0800460MODULE_ALIAS("aes");