Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Cryptographic API. |
| 3 | * |
| 4 | * Support for VIA PadLock hardware crypto engine. |
| 5 | * |
| 6 | * Copyright (c) 2006 Michal Ludvig <michal@logix.cz> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 15 | #include <crypto/internal/hash.h> |
Jan Glauber | 5265eeb | 2007-10-09 22:43:13 +0800 | [diff] [blame] | 16 | #include <crypto/sha.h> |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 17 | #include <linux/err.h> |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/errno.h> |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/scatterlist.h> |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 24 | #include <asm/i387.h> |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 25 | #include "padlock.h" |
| 26 | |
Herbert Xu | 4c6ab3e | 2009-09-21 23:21:53 -0700 | [diff] [blame] | 27 | #ifdef CONFIG_64BIT |
| 28 | #define STACK_ALIGN 16 |
| 29 | #else |
| 30 | #define STACK_ALIGN 4 |
| 31 | #endif |
| 32 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 33 | struct padlock_sha_desc { |
| 34 | struct shash_desc fallback; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 35 | }; |
| 36 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 37 | struct padlock_sha_ctx { |
| 38 | struct crypto_shash *fallback; |
| 39 | }; |
| 40 | |
| 41 | static int padlock_sha_init(struct shash_desc *desc) |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 42 | { |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 43 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
| 44 | struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm); |
| 45 | |
| 46 | dctx->fallback.tfm = ctx->fallback; |
| 47 | dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
| 48 | return crypto_shash_init(&dctx->fallback); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 49 | } |
| 50 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 51 | static int padlock_sha_update(struct shash_desc *desc, |
| 52 | const u8 *data, unsigned int length) |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 53 | { |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 54 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 55 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 56 | dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
| 57 | return crypto_shash_update(&dctx->fallback, data, length); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 58 | } |
| 59 | |
Herbert Xu | a8d7ac2 | 2010-02-01 09:17:56 +1100 | [diff] [blame] | 60 | static int padlock_sha_export(struct shash_desc *desc, void *out) |
| 61 | { |
| 62 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
| 63 | |
| 64 | return crypto_shash_export(&dctx->fallback, out); |
| 65 | } |
| 66 | |
| 67 | static int padlock_sha_import(struct shash_desc *desc, const void *in) |
| 68 | { |
| 69 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
| 70 | struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm); |
| 71 | |
| 72 | dctx->fallback.tfm = ctx->fallback; |
| 73 | dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
| 74 | return crypto_shash_import(&dctx->fallback, in); |
| 75 | } |
| 76 | |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 77 | static inline void padlock_output_block(uint32_t *src, |
| 78 | uint32_t *dst, size_t count) |
| 79 | { |
| 80 | while (count--) |
| 81 | *dst++ = swab32(*src++); |
| 82 | } |
| 83 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 84 | static int padlock_sha1_finup(struct shash_desc *desc, const u8 *in, |
| 85 | unsigned int count, u8 *out) |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 86 | { |
| 87 | /* We can't store directly to *out as it may be unaligned. */ |
| 88 | /* BTW Don't reduce the buffer size below 128 Bytes! |
| 89 | * PadLock microcode needs it that big. */ |
Herbert Xu | 4c6ab3e | 2009-09-21 23:21:53 -0700 | [diff] [blame] | 90 | char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__ |
| 91 | ((aligned(STACK_ALIGN))); |
| 92 | char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 93 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
| 94 | struct sha1_state state; |
| 95 | unsigned int space; |
| 96 | unsigned int leftover; |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 97 | int ts_state; |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 98 | int err; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 99 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 100 | dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
| 101 | err = crypto_shash_export(&dctx->fallback, &state); |
| 102 | if (err) |
| 103 | goto out; |
| 104 | |
| 105 | if (state.count + count > ULONG_MAX) |
| 106 | return crypto_shash_finup(&dctx->fallback, in, count, out); |
| 107 | |
| 108 | leftover = ((state.count - 1) & (SHA1_BLOCK_SIZE - 1)) + 1; |
| 109 | space = SHA1_BLOCK_SIZE - leftover; |
| 110 | if (space) { |
| 111 | if (count > space) { |
| 112 | err = crypto_shash_update(&dctx->fallback, in, space) ?: |
| 113 | crypto_shash_export(&dctx->fallback, &state); |
| 114 | if (err) |
| 115 | goto out; |
| 116 | count -= space; |
| 117 | in += space; |
| 118 | } else { |
| 119 | memcpy(state.buffer + leftover, in, count); |
| 120 | in = state.buffer; |
| 121 | count += leftover; |
Herbert Xu | e9b25f1 | 2009-07-16 10:33:27 +0800 | [diff] [blame] | 122 | state.count &= ~(SHA1_BLOCK_SIZE - 1); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | memcpy(result, &state.state, SHA1_DIGEST_SIZE); |
| 127 | |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 128 | /* prevent taking the spurious DNA fault with padlock. */ |
| 129 | ts_state = irq_ts_save(); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 130 | asm volatile (".byte 0xf3,0x0f,0xa6,0xc8" /* rep xsha1 */ |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 131 | : \ |
Herbert Xu | faae890 | 2009-07-15 18:37:48 +0800 | [diff] [blame] | 132 | : "c"((unsigned long)state.count + count), \ |
| 133 | "a"((unsigned long)state.count), \ |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 134 | "S"(in), "D"(result)); |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 135 | irq_ts_restore(ts_state); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 136 | |
| 137 | padlock_output_block((uint32_t *)result, (uint32_t *)out, 5); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 138 | |
| 139 | out: |
| 140 | return err; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 141 | } |
| 142 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 143 | static int padlock_sha1_final(struct shash_desc *desc, u8 *out) |
| 144 | { |
| 145 | u8 buf[4]; |
| 146 | |
| 147 | return padlock_sha1_finup(desc, buf, 0, out); |
| 148 | } |
| 149 | |
| 150 | static int padlock_sha256_finup(struct shash_desc *desc, const u8 *in, |
| 151 | unsigned int count, u8 *out) |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 152 | { |
| 153 | /* We can't store directly to *out as it may be unaligned. */ |
| 154 | /* BTW Don't reduce the buffer size below 128 Bytes! |
| 155 | * PadLock microcode needs it that big. */ |
Herbert Xu | 4c6ab3e | 2009-09-21 23:21:53 -0700 | [diff] [blame] | 156 | char buf[128 + PADLOCK_ALIGNMENT - STACK_ALIGN] __attribute__ |
| 157 | ((aligned(STACK_ALIGN))); |
| 158 | char *result = PTR_ALIGN(&buf[0], PADLOCK_ALIGNMENT); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 159 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
| 160 | struct sha256_state state; |
| 161 | unsigned int space; |
| 162 | unsigned int leftover; |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 163 | int ts_state; |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 164 | int err; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 165 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 166 | dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
| 167 | err = crypto_shash_export(&dctx->fallback, &state); |
| 168 | if (err) |
| 169 | goto out; |
| 170 | |
| 171 | if (state.count + count > ULONG_MAX) |
| 172 | return crypto_shash_finup(&dctx->fallback, in, count, out); |
| 173 | |
| 174 | leftover = ((state.count - 1) & (SHA256_BLOCK_SIZE - 1)) + 1; |
| 175 | space = SHA256_BLOCK_SIZE - leftover; |
| 176 | if (space) { |
| 177 | if (count > space) { |
| 178 | err = crypto_shash_update(&dctx->fallback, in, space) ?: |
| 179 | crypto_shash_export(&dctx->fallback, &state); |
| 180 | if (err) |
| 181 | goto out; |
| 182 | count -= space; |
| 183 | in += space; |
| 184 | } else { |
| 185 | memcpy(state.buf + leftover, in, count); |
| 186 | in = state.buf; |
| 187 | count += leftover; |
Herbert Xu | e9b25f1 | 2009-07-16 10:33:27 +0800 | [diff] [blame] | 188 | state.count &= ~(SHA1_BLOCK_SIZE - 1); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
| 192 | memcpy(result, &state.state, SHA256_DIGEST_SIZE); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 193 | |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 194 | /* prevent taking the spurious DNA fault with padlock. */ |
| 195 | ts_state = irq_ts_save(); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 196 | asm volatile (".byte 0xf3,0x0f,0xa6,0xd0" /* rep xsha256 */ |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 197 | : \ |
Herbert Xu | faae890 | 2009-07-15 18:37:48 +0800 | [diff] [blame] | 198 | : "c"((unsigned long)state.count + count), \ |
| 199 | "a"((unsigned long)state.count), \ |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 200 | "S"(in), "D"(result)); |
Suresh Siddha | e491401 | 2008-08-13 22:02:26 +1000 | [diff] [blame] | 201 | irq_ts_restore(ts_state); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 202 | |
| 203 | padlock_output_block((uint32_t *)result, (uint32_t *)out, 8); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 204 | |
| 205 | out: |
| 206 | return err; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 207 | } |
| 208 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 209 | static int padlock_sha256_final(struct shash_desc *desc, u8 *out) |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 210 | { |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 211 | u8 buf[4]; |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 212 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 213 | return padlock_sha256_finup(desc, buf, 0, out); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 214 | } |
| 215 | |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 216 | static int padlock_cra_init(struct crypto_tfm *tfm) |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 217 | { |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 218 | struct crypto_shash *hash = __crypto_shash_cast(tfm); |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 219 | const char *fallback_driver_name = tfm->__crt_alg->cra_name; |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 220 | struct padlock_sha_ctx *ctx = crypto_tfm_ctx(tfm); |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 221 | struct crypto_shash *fallback_tfm; |
| 222 | int err = -ENOMEM; |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 223 | |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 224 | /* Allocate a fallback and abort if it failed. */ |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 225 | fallback_tfm = crypto_alloc_shash(fallback_driver_name, 0, |
| 226 | CRYPTO_ALG_NEED_FALLBACK); |
Herbert Xu | 6010439 | 2006-08-26 18:34:10 +1000 | [diff] [blame] | 227 | if (IS_ERR(fallback_tfm)) { |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 228 | printk(KERN_WARNING PFX "Fallback driver '%s' could not be loaded!\n", |
| 229 | fallback_driver_name); |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 230 | err = PTR_ERR(fallback_tfm); |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 231 | goto out; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 232 | } |
| 233 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 234 | ctx->fallback = fallback_tfm; |
| 235 | hash->descsize += crypto_shash_descsize(fallback_tfm); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 236 | return 0; |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 237 | |
Herbert Xu | 7d02460 | 2009-07-10 17:26:44 +0800 | [diff] [blame] | 238 | out: |
| 239 | return err; |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 240 | } |
| 241 | |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 242 | static void padlock_cra_exit(struct crypto_tfm *tfm) |
| 243 | { |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 244 | struct padlock_sha_ctx *ctx = crypto_tfm_ctx(tfm); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 245 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 246 | crypto_free_shash(ctx->fallback); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 247 | } |
| 248 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 249 | static struct shash_alg sha1_alg = { |
| 250 | .digestsize = SHA1_DIGEST_SIZE, |
| 251 | .init = padlock_sha_init, |
| 252 | .update = padlock_sha_update, |
| 253 | .finup = padlock_sha1_finup, |
| 254 | .final = padlock_sha1_final, |
Herbert Xu | a8d7ac2 | 2010-02-01 09:17:56 +1100 | [diff] [blame] | 255 | .export = padlock_sha_export, |
| 256 | .import = padlock_sha_import, |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 257 | .descsize = sizeof(struct padlock_sha_desc), |
Herbert Xu | a8d7ac2 | 2010-02-01 09:17:56 +1100 | [diff] [blame] | 258 | .statesize = sizeof(struct sha1_state), |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 259 | .base = { |
| 260 | .cra_name = "sha1", |
| 261 | .cra_driver_name = "sha1-padlock", |
| 262 | .cra_priority = PADLOCK_CRA_PRIORITY, |
| 263 | .cra_flags = CRYPTO_ALG_TYPE_SHASH | |
| 264 | CRYPTO_ALG_NEED_FALLBACK, |
| 265 | .cra_blocksize = SHA1_BLOCK_SIZE, |
| 266 | .cra_ctxsize = sizeof(struct padlock_sha_ctx), |
| 267 | .cra_module = THIS_MODULE, |
| 268 | .cra_init = padlock_cra_init, |
| 269 | .cra_exit = padlock_cra_exit, |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 270 | } |
| 271 | }; |
| 272 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 273 | static struct shash_alg sha256_alg = { |
| 274 | .digestsize = SHA256_DIGEST_SIZE, |
| 275 | .init = padlock_sha_init, |
| 276 | .update = padlock_sha_update, |
| 277 | .finup = padlock_sha256_finup, |
| 278 | .final = padlock_sha256_final, |
Herbert Xu | a8d7ac2 | 2010-02-01 09:17:56 +1100 | [diff] [blame] | 279 | .export = padlock_sha_export, |
| 280 | .import = padlock_sha_import, |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 281 | .descsize = sizeof(struct padlock_sha_desc), |
Herbert Xu | a8d7ac2 | 2010-02-01 09:17:56 +1100 | [diff] [blame] | 282 | .statesize = sizeof(struct sha256_state), |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 283 | .base = { |
| 284 | .cra_name = "sha256", |
| 285 | .cra_driver_name = "sha256-padlock", |
| 286 | .cra_priority = PADLOCK_CRA_PRIORITY, |
| 287 | .cra_flags = CRYPTO_ALG_TYPE_SHASH | |
| 288 | CRYPTO_ALG_NEED_FALLBACK, |
| 289 | .cra_blocksize = SHA256_BLOCK_SIZE, |
| 290 | .cra_ctxsize = sizeof(struct padlock_sha_ctx), |
| 291 | .cra_module = THIS_MODULE, |
| 292 | .cra_init = padlock_cra_init, |
| 293 | .cra_exit = padlock_cra_exit, |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 294 | } |
| 295 | }; |
| 296 | |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 297 | static int __init padlock_init(void) |
| 298 | { |
| 299 | int rc = -ENODEV; |
| 300 | |
| 301 | if (!cpu_has_phe) { |
Jeremy Katz | b43e726 | 2008-07-03 19:03:31 +0800 | [diff] [blame] | 302 | printk(KERN_NOTICE PFX "VIA PadLock Hash Engine not detected.\n"); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 303 | return -ENODEV; |
| 304 | } |
| 305 | |
| 306 | if (!cpu_has_phe_enabled) { |
Jeremy Katz | b43e726 | 2008-07-03 19:03:31 +0800 | [diff] [blame] | 307 | printk(KERN_NOTICE PFX "VIA PadLock detected, but not enabled. Hmm, strange...\n"); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 308 | return -ENODEV; |
| 309 | } |
| 310 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 311 | rc = crypto_register_shash(&sha1_alg); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 312 | if (rc) |
| 313 | goto out; |
| 314 | |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 315 | rc = crypto_register_shash(&sha256_alg); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 316 | if (rc) |
| 317 | goto out_unreg1; |
| 318 | |
| 319 | printk(KERN_NOTICE PFX "Using VIA PadLock ACE for SHA1/SHA256 algorithms.\n"); |
| 320 | |
| 321 | return 0; |
| 322 | |
| 323 | out_unreg1: |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 324 | crypto_unregister_shash(&sha1_alg); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 325 | out: |
| 326 | printk(KERN_ERR PFX "VIA PadLock SHA1/SHA256 initialization failed.\n"); |
| 327 | return rc; |
| 328 | } |
| 329 | |
| 330 | static void __exit padlock_fini(void) |
| 331 | { |
Herbert Xu | bbbee46 | 2009-07-11 18:16:16 +0800 | [diff] [blame] | 332 | crypto_unregister_shash(&sha1_alg); |
| 333 | crypto_unregister_shash(&sha256_alg); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | module_init(padlock_init); |
| 337 | module_exit(padlock_fini); |
| 338 | |
| 339 | MODULE_DESCRIPTION("VIA PadLock SHA1/SHA256 algorithms support."); |
| 340 | MODULE_LICENSE("GPL"); |
| 341 | MODULE_AUTHOR("Michal Ludvig"); |
| 342 | |
Herbert Xu | a760a66 | 2009-02-26 14:06:31 +0800 | [diff] [blame] | 343 | MODULE_ALIAS("sha1-all"); |
| 344 | MODULE_ALIAS("sha256-all"); |
Michal Ludvig | 6c83327 | 2006-07-12 12:29:38 +1000 | [diff] [blame] | 345 | MODULE_ALIAS("sha1-padlock"); |
| 346 | MODULE_ALIAS("sha256-padlock"); |