diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-23 12:02:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-23 12:02:42 -0400 |
commit | 6f73b3629f774c6cba589b15fd095112b25ca923 (patch) | |
tree | 50a60feae71cb5f40078f552b9b08468bc7b29c9 /drivers/crypto/nx/nx-aes-cbc.c | |
parent | 3a8580f82024e30b31c662aa49346adf7a3bcdb5 (diff) | |
parent | 2074b1d9d53ae696dd3f49482bad43254f40f01d (diff) |
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
Pull powerpc updates from Benjamin Herrenschmidt:
"Here are the powerpc goodies for 3.5. Main highlights are:
- Support for the NX crypto engine in Power7+
- A bunch of Anton goodness, including some micro optimization of our
syscall entry on Power7
- I converted a pile of our thermal control drivers to the new i2c
APIs (essentially turning the old therm_pm72 into a proper set of
windfarm drivers). That's one more step toward removing the
deprecated i2c APIs, there's still a few drivers to fix, but we are
getting close
- kexec/kdump support for 47x embedded cores
The big missing thing here is no updates from Freescale. Not sure
what's up here, but with Kumar not working for them anymore things are
a bit in a state of flux in that area."
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc: (71 commits)
powerpc: Fix irq distribution
Revert "powerpc/hw-breakpoint: Use generic hw-breakpoint interfaces for new PPC ptrace flags"
powerpc: Fixing a cputhread code documentation
powerpc/crypto: Enable the PFO-based encryption device
powerpc/crypto: Build files for the nx device driver
powerpc/crypto: debugfs routines and docs for the nx device driver
powerpc/crypto: SHA512 hash routines for nx encryption
powerpc/crypto: SHA256 hash routines for nx encryption
powerpc/crypto: AES-XCBC mode routines for nx encryption
powerpc/crypto: AES-GCM mode routines for nx encryption
powerpc/crypto: AES-ECB mode routines for nx encryption
powerpc/crypto: AES-CTR mode routines for nx encryption
powerpc/crypto: AES-CCM mode routines for nx encryption
powerpc/crypto: AES-CBC mode routines for nx encryption
powerpc/crypto: nx driver code supporting nx encryption
powerpc/pseries: Enable the PFO-based RNG accelerator
powerpc/pseries/hwrng: PFO-based hwrng driver
powerpc/pseries: Add PFO support to the VIO bus
powerpc/pseries: Add pseries update notifier for OFDT prop changes
powerpc/pseries: Add new hvcall constants to support PFO
...
Diffstat (limited to 'drivers/crypto/nx/nx-aes-cbc.c')
-rw-r--r-- | drivers/crypto/nx/nx-aes-cbc.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/drivers/crypto/nx/nx-aes-cbc.c b/drivers/crypto/nx/nx-aes-cbc.c new file mode 100644 index 000000000000..69ed796ee327 --- /dev/null +++ b/drivers/crypto/nx/nx-aes-cbc.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /** | ||
2 | * AES CBC routines supporting the Power 7+ Nest Accelerators driver | ||
3 | * | ||
4 | * Copyright (C) 2011-2012 International Business Machines Inc. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 only. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | * | ||
19 | * Author: Kent Yoder <yoder1@us.ibm.com> | ||
20 | */ | ||
21 | |||
22 | #include <crypto/aes.h> | ||
23 | #include <crypto/algapi.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/types.h> | ||
26 | #include <linux/crypto.h> | ||
27 | #include <asm/vio.h> | ||
28 | |||
29 | #include "nx_csbcpb.h" | ||
30 | #include "nx.h" | ||
31 | |||
32 | |||
33 | static int cbc_aes_nx_set_key(struct crypto_tfm *tfm, | ||
34 | const u8 *in_key, | ||
35 | unsigned int key_len) | ||
36 | { | ||
37 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); | ||
38 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | ||
39 | |||
40 | nx_ctx_init(nx_ctx, HCOP_FC_AES); | ||
41 | |||
42 | switch (key_len) { | ||
43 | case AES_KEYSIZE_128: | ||
44 | NX_CPB_SET_KEY_SIZE(csbcpb, NX_KS_AES_128); | ||
45 | nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_128]; | ||
46 | break; | ||
47 | case AES_KEYSIZE_192: | ||
48 | NX_CPB_SET_KEY_SIZE(csbcpb, NX_KS_AES_192); | ||
49 | nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_192]; | ||
50 | break; | ||
51 | case AES_KEYSIZE_256: | ||
52 | NX_CPB_SET_KEY_SIZE(csbcpb, NX_KS_AES_256); | ||
53 | nx_ctx->ap = &nx_ctx->props[NX_PROPS_AES_256]; | ||
54 | break; | ||
55 | default: | ||
56 | return -EINVAL; | ||
57 | } | ||
58 | |||
59 | csbcpb->cpb.hdr.mode = NX_MODE_AES_CBC; | ||
60 | memcpy(csbcpb->cpb.aes_cbc.key, in_key, key_len); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int cbc_aes_nx_crypt(struct blkcipher_desc *desc, | ||
66 | struct scatterlist *dst, | ||
67 | struct scatterlist *src, | ||
68 | unsigned int nbytes, | ||
69 | int enc) | ||
70 | { | ||
71 | struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); | ||
72 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | ||
73 | int rc; | ||
74 | |||
75 | if (nbytes > nx_ctx->ap->databytelen) | ||
76 | return -EINVAL; | ||
77 | |||
78 | if (enc) | ||
79 | NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT; | ||
80 | else | ||
81 | NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT; | ||
82 | |||
83 | rc = nx_build_sg_lists(nx_ctx, desc, dst, src, nbytes, | ||
84 | csbcpb->cpb.aes_cbc.iv); | ||
85 | if (rc) | ||
86 | goto out; | ||
87 | |||
88 | if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) { | ||
89 | rc = -EINVAL; | ||
90 | goto out; | ||
91 | } | ||
92 | |||
93 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, | ||
94 | desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); | ||
95 | if (rc) | ||
96 | goto out; | ||
97 | |||
98 | atomic_inc(&(nx_ctx->stats->aes_ops)); | ||
99 | atomic64_add(csbcpb->csb.processed_byte_count, | ||
100 | &(nx_ctx->stats->aes_bytes)); | ||
101 | out: | ||
102 | return rc; | ||
103 | } | ||
104 | |||
105 | static int cbc_aes_nx_encrypt(struct blkcipher_desc *desc, | ||
106 | struct scatterlist *dst, | ||
107 | struct scatterlist *src, | ||
108 | unsigned int nbytes) | ||
109 | { | ||
110 | return cbc_aes_nx_crypt(desc, dst, src, nbytes, 1); | ||
111 | } | ||
112 | |||
113 | static int cbc_aes_nx_decrypt(struct blkcipher_desc *desc, | ||
114 | struct scatterlist *dst, | ||
115 | struct scatterlist *src, | ||
116 | unsigned int nbytes) | ||
117 | { | ||
118 | return cbc_aes_nx_crypt(desc, dst, src, nbytes, 0); | ||
119 | } | ||
120 | |||
121 | struct crypto_alg nx_cbc_aes_alg = { | ||
122 | .cra_name = "cbc(aes)", | ||
123 | .cra_driver_name = "cbc-aes-nx", | ||
124 | .cra_priority = 300, | ||
125 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
126 | .cra_blocksize = AES_BLOCK_SIZE, | ||
127 | .cra_ctxsize = sizeof(struct nx_crypto_ctx), | ||
128 | .cra_type = &crypto_blkcipher_type, | ||
129 | .cra_module = THIS_MODULE, | ||
130 | .cra_list = LIST_HEAD_INIT(nx_cbc_aes_alg.cra_list), | ||
131 | .cra_init = nx_crypto_ctx_aes_cbc_init, | ||
132 | .cra_exit = nx_crypto_ctx_exit, | ||
133 | .cra_blkcipher = { | ||
134 | .min_keysize = AES_MIN_KEY_SIZE, | ||
135 | .max_keysize = AES_MAX_KEY_SIZE, | ||
136 | .ivsize = AES_BLOCK_SIZE, | ||
137 | .setkey = cbc_aes_nx_set_key, | ||
138 | .encrypt = cbc_aes_nx_encrypt, | ||
139 | .decrypt = cbc_aes_nx_decrypt, | ||
140 | } | ||
141 | }; | ||