~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc/crypto/des_glue.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/sparc/crypto/des_glue.c (Architecture m68k) and /arch/sparc/crypto/des_glue.c (Architecture sparc)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Glue code for DES encryption optimized for       2 /* Glue code for DES encryption optimized for sparc64 crypto opcodes.
  3  *                                                  3  *
  4  * Copyright (C) 2012 David S. Miller <davem@d      4  * Copyright (C) 2012 David S. Miller <davem@davemloft.net>
  5  */                                                 5  */
  6                                                     6 
  7 #define pr_fmt(fmt)     KBUILD_MODNAME ": " fm      7 #define pr_fmt(fmt)     KBUILD_MODNAME ": " fmt
  8                                                     8 
  9 #include <linux/crypto.h>                           9 #include <linux/crypto.h>
 10 #include <linux/init.h>                            10 #include <linux/init.h>
 11 #include <linux/module.h>                          11 #include <linux/module.h>
 12 #include <linux/mm.h>                              12 #include <linux/mm.h>
 13 #include <linux/types.h>                           13 #include <linux/types.h>
 14 #include <crypto/algapi.h>                         14 #include <crypto/algapi.h>
 15 #include <crypto/internal/des.h>                   15 #include <crypto/internal/des.h>
 16 #include <crypto/internal/skcipher.h>              16 #include <crypto/internal/skcipher.h>
 17                                                    17 
 18 #include <asm/fpumacro.h>                          18 #include <asm/fpumacro.h>
 19 #include <asm/pstate.h>                            19 #include <asm/pstate.h>
 20 #include <asm/elf.h>                               20 #include <asm/elf.h>
 21                                                    21 
 22 #include "opcodes.h"                               22 #include "opcodes.h"
 23                                                    23 
 24 struct des_sparc64_ctx {                           24 struct des_sparc64_ctx {
 25         u64 encrypt_expkey[DES_EXPKEY_WORDS /      25         u64 encrypt_expkey[DES_EXPKEY_WORDS / 2];
 26         u64 decrypt_expkey[DES_EXPKEY_WORDS /      26         u64 decrypt_expkey[DES_EXPKEY_WORDS / 2];
 27 };                                                 27 };
 28                                                    28 
 29 struct des3_ede_sparc64_ctx {                      29 struct des3_ede_sparc64_ctx {
 30         u64 encrypt_expkey[DES3_EDE_EXPKEY_WOR     30         u64 encrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2];
 31         u64 decrypt_expkey[DES3_EDE_EXPKEY_WOR     31         u64 decrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2];
 32 };                                                 32 };
 33                                                    33 
 34 static void encrypt_to_decrypt(u64 *d, const u     34 static void encrypt_to_decrypt(u64 *d, const u64 *e)
 35 {                                                  35 {
 36         const u64 *s = e + (DES_EXPKEY_WORDS /     36         const u64 *s = e + (DES_EXPKEY_WORDS / 2) - 1;
 37         int i;                                     37         int i;
 38                                                    38 
 39         for (i = 0; i < DES_EXPKEY_WORDS / 2;      39         for (i = 0; i < DES_EXPKEY_WORDS / 2; i++)
 40                 *d++ = *s--;                       40                 *d++ = *s--;
 41 }                                                  41 }
 42                                                    42 
 43 extern void des_sparc64_key_expand(const u32 *     43 extern void des_sparc64_key_expand(const u32 *input_key, u64 *key);
 44                                                    44 
 45 static int des_set_key(struct crypto_tfm *tfm,     45 static int des_set_key(struct crypto_tfm *tfm, const u8 *key,
 46                        unsigned int keylen)        46                        unsigned int keylen)
 47 {                                                  47 {
 48         struct des_sparc64_ctx *dctx = crypto_     48         struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
 49         int err;                                   49         int err;
 50                                                    50 
 51         /* Even though we have special instruc     51         /* Even though we have special instructions for key expansion,
 52          * we call des_verify_key() so that we     52          * we call des_verify_key() so that we don't have to write our own
 53          * weak key detection code.                53          * weak key detection code.
 54          */                                        54          */
 55         err = crypto_des_verify_key(tfm, key);     55         err = crypto_des_verify_key(tfm, key);
 56         if (err)                                   56         if (err)
 57                 return err;                        57                 return err;
 58                                                    58 
 59         des_sparc64_key_expand((const u32 *) k     59         des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]);
 60         encrypt_to_decrypt(&dctx->decrypt_expk     60         encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]);
 61                                                    61 
 62         return 0;                                  62         return 0;
 63 }                                                  63 }
 64                                                    64 
 65 static int des_set_key_skcipher(struct crypto_     65 static int des_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key,
 66                                 unsigned int k     66                                 unsigned int keylen)
 67 {                                                  67 {
 68         return des_set_key(crypto_skcipher_tfm     68         return des_set_key(crypto_skcipher_tfm(tfm), key, keylen);
 69 }                                                  69 }
 70                                                    70 
 71 extern void des_sparc64_crypt(const u64 *key,      71 extern void des_sparc64_crypt(const u64 *key, const u64 *input,
 72                               u64 *output);        72                               u64 *output);
 73                                                    73 
 74 static void sparc_des_encrypt(struct crypto_tf     74 static void sparc_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 75 {                                                  75 {
 76         struct des_sparc64_ctx *ctx = crypto_t     76         struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
 77         const u64 *K = ctx->encrypt_expkey;        77         const u64 *K = ctx->encrypt_expkey;
 78                                                    78 
 79         des_sparc64_crypt(K, (const u64 *) src     79         des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
 80 }                                                  80 }
 81                                                    81 
 82 static void sparc_des_decrypt(struct crypto_tf     82 static void sparc_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 83 {                                                  83 {
 84         struct des_sparc64_ctx *ctx = crypto_t     84         struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
 85         const u64 *K = ctx->decrypt_expkey;        85         const u64 *K = ctx->decrypt_expkey;
 86                                                    86 
 87         des_sparc64_crypt(K, (const u64 *) src     87         des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
 88 }                                                  88 }
 89                                                    89 
 90 extern void des_sparc64_load_keys(const u64 *k     90 extern void des_sparc64_load_keys(const u64 *key);
 91                                                    91 
 92 extern void des_sparc64_ecb_crypt(const u64 *i     92 extern void des_sparc64_ecb_crypt(const u64 *input, u64 *output,
 93                                   unsigned int     93                                   unsigned int len);
 94                                                    94 
 95 static int __ecb_crypt(struct skcipher_request     95 static int __ecb_crypt(struct skcipher_request *req, bool encrypt)
 96 {                                                  96 {
 97         struct crypto_skcipher *tfm = crypto_s     97         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
 98         const struct des_sparc64_ctx *ctx = cr     98         const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
 99         struct skcipher_walk walk;                 99         struct skcipher_walk walk;
100         unsigned int nbytes;                      100         unsigned int nbytes;
101         int err;                                  101         int err;
102                                                   102 
103         err = skcipher_walk_virt(&walk, req, t    103         err = skcipher_walk_virt(&walk, req, true);
104         if (err)                                  104         if (err)
105                 return err;                       105                 return err;
106                                                   106 
107         if (encrypt)                              107         if (encrypt)
108                 des_sparc64_load_keys(&ctx->en    108                 des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
109         else                                      109         else
110                 des_sparc64_load_keys(&ctx->de    110                 des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
111         while ((nbytes = walk.nbytes) != 0) {     111         while ((nbytes = walk.nbytes) != 0) {
112                 des_sparc64_ecb_crypt(walk.src    112                 des_sparc64_ecb_crypt(walk.src.virt.addr, walk.dst.virt.addr,
113                                       round_do    113                                       round_down(nbytes, DES_BLOCK_SIZE));
114                 err = skcipher_walk_done(&walk    114                 err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
115         }                                         115         }
116         fprs_write(0);                            116         fprs_write(0);
117         return err;                               117         return err;
118 }                                                 118 }
119                                                   119 
120 static int ecb_encrypt(struct skcipher_request    120 static int ecb_encrypt(struct skcipher_request *req)
121 {                                                 121 {
122         return __ecb_crypt(req, true);            122         return __ecb_crypt(req, true);
123 }                                                 123 }
124                                                   124 
125 static int ecb_decrypt(struct skcipher_request    125 static int ecb_decrypt(struct skcipher_request *req)
126 {                                                 126 {
127         return __ecb_crypt(req, false);           127         return __ecb_crypt(req, false);
128 }                                                 128 }
129                                                   129 
130 extern void des_sparc64_cbc_encrypt(const u64     130 extern void des_sparc64_cbc_encrypt(const u64 *input, u64 *output,
131                                     unsigned i    131                                     unsigned int len, u64 *iv);
132                                                   132 
133 extern void des_sparc64_cbc_decrypt(const u64     133 extern void des_sparc64_cbc_decrypt(const u64 *input, u64 *output,
134                                     unsigned i    134                                     unsigned int len, u64 *iv);
135                                                   135 
136 static int __cbc_crypt(struct skcipher_request    136 static int __cbc_crypt(struct skcipher_request *req, bool encrypt)
137 {                                                 137 {
138         struct crypto_skcipher *tfm = crypto_s    138         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
139         const struct des_sparc64_ctx *ctx = cr    139         const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
140         struct skcipher_walk walk;                140         struct skcipher_walk walk;
141         unsigned int nbytes;                      141         unsigned int nbytes;
142         int err;                                  142         int err;
143                                                   143 
144         err = skcipher_walk_virt(&walk, req, t    144         err = skcipher_walk_virt(&walk, req, true);
145         if (err)                                  145         if (err)
146                 return err;                       146                 return err;
147                                                   147 
148         if (encrypt)                              148         if (encrypt)
149                 des_sparc64_load_keys(&ctx->en    149                 des_sparc64_load_keys(&ctx->encrypt_expkey[0]);
150         else                                      150         else
151                 des_sparc64_load_keys(&ctx->de    151                 des_sparc64_load_keys(&ctx->decrypt_expkey[0]);
152         while ((nbytes = walk.nbytes) != 0) {     152         while ((nbytes = walk.nbytes) != 0) {
153                 if (encrypt)                      153                 if (encrypt)
154                         des_sparc64_cbc_encryp    154                         des_sparc64_cbc_encrypt(walk.src.virt.addr,
155                                                   155                                                 walk.dst.virt.addr,
156                                                   156                                                 round_down(nbytes,
157                                                   157                                                            DES_BLOCK_SIZE),
158                                                   158                                                 walk.iv);
159                 else                              159                 else
160                         des_sparc64_cbc_decryp    160                         des_sparc64_cbc_decrypt(walk.src.virt.addr,
161                                                   161                                                 walk.dst.virt.addr,
162                                                   162                                                 round_down(nbytes,
163                                                   163                                                            DES_BLOCK_SIZE),
164                                                   164                                                 walk.iv);
165                 err = skcipher_walk_done(&walk    165                 err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
166         }                                         166         }
167         fprs_write(0);                            167         fprs_write(0);
168         return err;                               168         return err;
169 }                                                 169 }
170                                                   170 
171 static int cbc_encrypt(struct skcipher_request    171 static int cbc_encrypt(struct skcipher_request *req)
172 {                                                 172 {
173         return __cbc_crypt(req, true);            173         return __cbc_crypt(req, true);
174 }                                                 174 }
175                                                   175 
176 static int cbc_decrypt(struct skcipher_request    176 static int cbc_decrypt(struct skcipher_request *req)
177 {                                                 177 {
178         return __cbc_crypt(req, false);           178         return __cbc_crypt(req, false);
179 }                                                 179 }
180                                                   180 
181 static int des3_ede_set_key(struct crypto_tfm     181 static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key,
182                             unsigned int keyle    182                             unsigned int keylen)
183 {                                                 183 {
184         struct des3_ede_sparc64_ctx *dctx = cr    184         struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm);
185         u64 k1[DES_EXPKEY_WORDS / 2];             185         u64 k1[DES_EXPKEY_WORDS / 2];
186         u64 k2[DES_EXPKEY_WORDS / 2];             186         u64 k2[DES_EXPKEY_WORDS / 2];
187         u64 k3[DES_EXPKEY_WORDS / 2];             187         u64 k3[DES_EXPKEY_WORDS / 2];
188         int err;                                  188         int err;
189                                                   189 
190         err = crypto_des3_ede_verify_key(tfm,     190         err = crypto_des3_ede_verify_key(tfm, key);
191         if (err)                                  191         if (err)
192                 return err;                       192                 return err;
193                                                   193 
194         des_sparc64_key_expand((const u32 *)ke    194         des_sparc64_key_expand((const u32 *)key, k1);
195         key += DES_KEY_SIZE;                      195         key += DES_KEY_SIZE;
196         des_sparc64_key_expand((const u32 *)ke    196         des_sparc64_key_expand((const u32 *)key, k2);
197         key += DES_KEY_SIZE;                      197         key += DES_KEY_SIZE;
198         des_sparc64_key_expand((const u32 *)ke    198         des_sparc64_key_expand((const u32 *)key, k3);
199                                                   199 
200         memcpy(&dctx->encrypt_expkey[0], &k1[0    200         memcpy(&dctx->encrypt_expkey[0], &k1[0], sizeof(k1));
201         encrypt_to_decrypt(&dctx->encrypt_expk    201         encrypt_to_decrypt(&dctx->encrypt_expkey[DES_EXPKEY_WORDS / 2], &k2[0]);
202         memcpy(&dctx->encrypt_expkey[(DES_EXPK    202         memcpy(&dctx->encrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2],
203                &k3[0], sizeof(k3));               203                &k3[0], sizeof(k3));
204                                                   204 
205         encrypt_to_decrypt(&dctx->decrypt_expk    205         encrypt_to_decrypt(&dctx->decrypt_expkey[0], &k3[0]);
206         memcpy(&dctx->decrypt_expkey[DES_EXPKE    206         memcpy(&dctx->decrypt_expkey[DES_EXPKEY_WORDS / 2],
207                &k2[0], sizeof(k2));               207                &k2[0], sizeof(k2));
208         encrypt_to_decrypt(&dctx->decrypt_expk    208         encrypt_to_decrypt(&dctx->decrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2],
209                            &k1[0]);               209                            &k1[0]);
210                                                   210 
211         return 0;                                 211         return 0;
212 }                                                 212 }
213                                                   213 
214 static int des3_ede_set_key_skcipher(struct cr    214 static int des3_ede_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key,
215                                      unsigned     215                                      unsigned int keylen)
216 {                                                 216 {
217         return des3_ede_set_key(crypto_skciphe    217         return des3_ede_set_key(crypto_skcipher_tfm(tfm), key, keylen);
218 }                                                 218 }
219                                                   219 
220 extern void des3_ede_sparc64_crypt(const u64 *    220 extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input,
221                                    u64 *output    221                                    u64 *output);
222                                                   222 
223 static void sparc_des3_ede_encrypt(struct cryp    223 static void sparc_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
224 {                                                 224 {
225         struct des3_ede_sparc64_ctx *ctx = cry    225         struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
226         const u64 *K = ctx->encrypt_expkey;       226         const u64 *K = ctx->encrypt_expkey;
227                                                   227 
228         des3_ede_sparc64_crypt(K, (const u64 *    228         des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
229 }                                                 229 }
230                                                   230 
231 static void sparc_des3_ede_decrypt(struct cryp    231 static void sparc_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
232 {                                                 232 {
233         struct des3_ede_sparc64_ctx *ctx = cry    233         struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm);
234         const u64 *K = ctx->decrypt_expkey;       234         const u64 *K = ctx->decrypt_expkey;
235                                                   235 
236         des3_ede_sparc64_crypt(K, (const u64 *    236         des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst);
237 }                                                 237 }
238                                                   238 
239 extern void des3_ede_sparc64_load_keys(const u    239 extern void des3_ede_sparc64_load_keys(const u64 *key);
240                                                   240 
241 extern void des3_ede_sparc64_ecb_crypt(const u    241 extern void des3_ede_sparc64_ecb_crypt(const u64 *expkey, const u64 *input,
242                                        u64 *ou    242                                        u64 *output, unsigned int len);
243                                                   243 
244 static int __ecb3_crypt(struct skcipher_reques    244 static int __ecb3_crypt(struct skcipher_request *req, bool encrypt)
245 {                                                 245 {
246         struct crypto_skcipher *tfm = crypto_s    246         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
247         const struct des3_ede_sparc64_ctx *ctx    247         const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
248         struct skcipher_walk walk;                248         struct skcipher_walk walk;
249         const u64 *K;                             249         const u64 *K;
250         unsigned int nbytes;                      250         unsigned int nbytes;
251         int err;                                  251         int err;
252                                                   252 
253         err = skcipher_walk_virt(&walk, req, t    253         err = skcipher_walk_virt(&walk, req, true);
254         if (err)                                  254         if (err)
255                 return err;                       255                 return err;
256                                                   256 
257         if (encrypt)                              257         if (encrypt)
258                 K = &ctx->encrypt_expkey[0];      258                 K = &ctx->encrypt_expkey[0];
259         else                                      259         else
260                 K = &ctx->decrypt_expkey[0];      260                 K = &ctx->decrypt_expkey[0];
261         des3_ede_sparc64_load_keys(K);            261         des3_ede_sparc64_load_keys(K);
262         while ((nbytes = walk.nbytes) != 0) {     262         while ((nbytes = walk.nbytes) != 0) {
263                 des3_ede_sparc64_ecb_crypt(K,     263                 des3_ede_sparc64_ecb_crypt(K, walk.src.virt.addr,
264                                            wal    264                                            walk.dst.virt.addr,
265                                            rou    265                                            round_down(nbytes, DES_BLOCK_SIZE));
266                 err = skcipher_walk_done(&walk    266                 err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
267         }                                         267         }
268         fprs_write(0);                            268         fprs_write(0);
269         return err;                               269         return err;
270 }                                                 270 }
271                                                   271 
272 static int ecb3_encrypt(struct skcipher_reques    272 static int ecb3_encrypt(struct skcipher_request *req)
273 {                                                 273 {
274         return __ecb3_crypt(req, true);           274         return __ecb3_crypt(req, true);
275 }                                                 275 }
276                                                   276 
277 static int ecb3_decrypt(struct skcipher_reques    277 static int ecb3_decrypt(struct skcipher_request *req)
278 {                                                 278 {
279         return __ecb3_crypt(req, false);          279         return __ecb3_crypt(req, false);
280 }                                                 280 }
281                                                   281 
282 extern void des3_ede_sparc64_cbc_encrypt(const    282 extern void des3_ede_sparc64_cbc_encrypt(const u64 *expkey, const u64 *input,
283                                          u64 *    283                                          u64 *output, unsigned int len,
284                                          u64 *    284                                          u64 *iv);
285                                                   285 
286 extern void des3_ede_sparc64_cbc_decrypt(const    286 extern void des3_ede_sparc64_cbc_decrypt(const u64 *expkey, const u64 *input,
287                                          u64 *    287                                          u64 *output, unsigned int len,
288                                          u64 *    288                                          u64 *iv);
289                                                   289 
290 static int __cbc3_crypt(struct skcipher_reques    290 static int __cbc3_crypt(struct skcipher_request *req, bool encrypt)
291 {                                                 291 {
292         struct crypto_skcipher *tfm = crypto_s    292         struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
293         const struct des3_ede_sparc64_ctx *ctx    293         const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm);
294         struct skcipher_walk walk;                294         struct skcipher_walk walk;
295         const u64 *K;                             295         const u64 *K;
296         unsigned int nbytes;                      296         unsigned int nbytes;
297         int err;                                  297         int err;
298                                                   298 
299         err = skcipher_walk_virt(&walk, req, t    299         err = skcipher_walk_virt(&walk, req, true);
300         if (err)                                  300         if (err)
301                 return err;                       301                 return err;
302                                                   302 
303         if (encrypt)                              303         if (encrypt)
304                 K = &ctx->encrypt_expkey[0];      304                 K = &ctx->encrypt_expkey[0];
305         else                                      305         else
306                 K = &ctx->decrypt_expkey[0];      306                 K = &ctx->decrypt_expkey[0];
307         des3_ede_sparc64_load_keys(K);            307         des3_ede_sparc64_load_keys(K);
308         while ((nbytes = walk.nbytes) != 0) {     308         while ((nbytes = walk.nbytes) != 0) {
309                 if (encrypt)                      309                 if (encrypt)
310                         des3_ede_sparc64_cbc_e    310                         des3_ede_sparc64_cbc_encrypt(K, walk.src.virt.addr,
311                                                   311                                                      walk.dst.virt.addr,
312                                                   312                                                      round_down(nbytes,
313                                                   313                                                                 DES_BLOCK_SIZE),
314                                                   314                                                      walk.iv);
315                 else                              315                 else
316                         des3_ede_sparc64_cbc_d    316                         des3_ede_sparc64_cbc_decrypt(K, walk.src.virt.addr,
317                                                   317                                                      walk.dst.virt.addr,
318                                                   318                                                      round_down(nbytes,
319                                                   319                                                                 DES_BLOCK_SIZE),
320                                                   320                                                      walk.iv);
321                 err = skcipher_walk_done(&walk    321                 err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE);
322         }                                         322         }
323         fprs_write(0);                            323         fprs_write(0);
324         return err;                               324         return err;
325 }                                                 325 }
326                                                   326 
327 static int cbc3_encrypt(struct skcipher_reques    327 static int cbc3_encrypt(struct skcipher_request *req)
328 {                                                 328 {
329         return __cbc3_crypt(req, true);           329         return __cbc3_crypt(req, true);
330 }                                                 330 }
331                                                   331 
332 static int cbc3_decrypt(struct skcipher_reques    332 static int cbc3_decrypt(struct skcipher_request *req)
333 {                                                 333 {
334         return __cbc3_crypt(req, false);          334         return __cbc3_crypt(req, false);
335 }                                                 335 }
336                                                   336 
337 static struct crypto_alg cipher_algs[] = {        337 static struct crypto_alg cipher_algs[] = {
338         {                                         338         {
339                 .cra_name               = "des    339                 .cra_name               = "des",
340                 .cra_driver_name        = "des    340                 .cra_driver_name        = "des-sparc64",
341                 .cra_priority           = SPAR    341                 .cra_priority           = SPARC_CR_OPCODE_PRIORITY,
342                 .cra_flags              = CRYP    342                 .cra_flags              = CRYPTO_ALG_TYPE_CIPHER,
343                 .cra_blocksize          = DES_    343                 .cra_blocksize          = DES_BLOCK_SIZE,
344                 .cra_ctxsize            = size    344                 .cra_ctxsize            = sizeof(struct des_sparc64_ctx),
345                 .cra_alignmask          = 7,      345                 .cra_alignmask          = 7,
346                 .cra_module             = THIS    346                 .cra_module             = THIS_MODULE,
347                 .cra_u  = {                       347                 .cra_u  = {
348                         .cipher = {               348                         .cipher = {
349                                 .cia_min_keysi    349                                 .cia_min_keysize        = DES_KEY_SIZE,
350                                 .cia_max_keysi    350                                 .cia_max_keysize        = DES_KEY_SIZE,
351                                 .cia_setkey       351                                 .cia_setkey             = des_set_key,
352                                 .cia_encrypt      352                                 .cia_encrypt            = sparc_des_encrypt,
353                                 .cia_decrypt      353                                 .cia_decrypt            = sparc_des_decrypt
354                         }                         354                         }
355                 }                                 355                 }
356         }, {                                      356         }, {
357                 .cra_name               = "des    357                 .cra_name               = "des3_ede",
358                 .cra_driver_name        = "des    358                 .cra_driver_name        = "des3_ede-sparc64",
359                 .cra_priority           = SPAR    359                 .cra_priority           = SPARC_CR_OPCODE_PRIORITY,
360                 .cra_flags              = CRYP    360                 .cra_flags              = CRYPTO_ALG_TYPE_CIPHER,
361                 .cra_blocksize          = DES3    361                 .cra_blocksize          = DES3_EDE_BLOCK_SIZE,
362                 .cra_ctxsize            = size    362                 .cra_ctxsize            = sizeof(struct des3_ede_sparc64_ctx),
363                 .cra_alignmask          = 7,      363                 .cra_alignmask          = 7,
364                 .cra_module             = THIS    364                 .cra_module             = THIS_MODULE,
365                 .cra_u  = {                       365                 .cra_u  = {
366                         .cipher = {               366                         .cipher = {
367                                 .cia_min_keysi    367                                 .cia_min_keysize        = DES3_EDE_KEY_SIZE,
368                                 .cia_max_keysi    368                                 .cia_max_keysize        = DES3_EDE_KEY_SIZE,
369                                 .cia_setkey       369                                 .cia_setkey             = des3_ede_set_key,
370                                 .cia_encrypt      370                                 .cia_encrypt            = sparc_des3_ede_encrypt,
371                                 .cia_decrypt      371                                 .cia_decrypt            = sparc_des3_ede_decrypt
372                         }                         372                         }
373                 }                                 373                 }
374         }                                         374         }
375 };                                                375 };
376                                                   376 
377 static struct skcipher_alg skcipher_algs[] = {    377 static struct skcipher_alg skcipher_algs[] = {
378         {                                         378         {
379                 .base.cra_name          = "ecb    379                 .base.cra_name          = "ecb(des)",
380                 .base.cra_driver_name   = "ecb    380                 .base.cra_driver_name   = "ecb-des-sparc64",
381                 .base.cra_priority      = SPAR    381                 .base.cra_priority      = SPARC_CR_OPCODE_PRIORITY,
382                 .base.cra_blocksize     = DES_    382                 .base.cra_blocksize     = DES_BLOCK_SIZE,
383                 .base.cra_ctxsize       = size    383                 .base.cra_ctxsize       = sizeof(struct des_sparc64_ctx),
384                 .base.cra_alignmask     = 7,      384                 .base.cra_alignmask     = 7,
385                 .base.cra_module        = THIS    385                 .base.cra_module        = THIS_MODULE,
386                 .min_keysize            = DES_    386                 .min_keysize            = DES_KEY_SIZE,
387                 .max_keysize            = DES_    387                 .max_keysize            = DES_KEY_SIZE,
388                 .setkey                 = des_    388                 .setkey                 = des_set_key_skcipher,
389                 .encrypt                = ecb_    389                 .encrypt                = ecb_encrypt,
390                 .decrypt                = ecb_    390                 .decrypt                = ecb_decrypt,
391         }, {                                      391         }, {
392                 .base.cra_name          = "cbc    392                 .base.cra_name          = "cbc(des)",
393                 .base.cra_driver_name   = "cbc    393                 .base.cra_driver_name   = "cbc-des-sparc64",
394                 .base.cra_priority      = SPAR    394                 .base.cra_priority      = SPARC_CR_OPCODE_PRIORITY,
395                 .base.cra_blocksize     = DES_    395                 .base.cra_blocksize     = DES_BLOCK_SIZE,
396                 .base.cra_ctxsize       = size    396                 .base.cra_ctxsize       = sizeof(struct des_sparc64_ctx),
397                 .base.cra_alignmask     = 7,      397                 .base.cra_alignmask     = 7,
398                 .base.cra_module        = THIS    398                 .base.cra_module        = THIS_MODULE,
399                 .min_keysize            = DES_    399                 .min_keysize            = DES_KEY_SIZE,
400                 .max_keysize            = DES_    400                 .max_keysize            = DES_KEY_SIZE,
401                 .ivsize                 = DES_    401                 .ivsize                 = DES_BLOCK_SIZE,
402                 .setkey                 = des_    402                 .setkey                 = des_set_key_skcipher,
403                 .encrypt                = cbc_    403                 .encrypt                = cbc_encrypt,
404                 .decrypt                = cbc_    404                 .decrypt                = cbc_decrypt,
405         }, {                                      405         }, {
406                 .base.cra_name          = "ecb    406                 .base.cra_name          = "ecb(des3_ede)",
407                 .base.cra_driver_name   = "ecb    407                 .base.cra_driver_name   = "ecb-des3_ede-sparc64",
408                 .base.cra_priority      = SPAR    408                 .base.cra_priority      = SPARC_CR_OPCODE_PRIORITY,
409                 .base.cra_blocksize     = DES3    409                 .base.cra_blocksize     = DES3_EDE_BLOCK_SIZE,
410                 .base.cra_ctxsize       = size    410                 .base.cra_ctxsize       = sizeof(struct des3_ede_sparc64_ctx),
411                 .base.cra_alignmask     = 7,      411                 .base.cra_alignmask     = 7,
412                 .base.cra_module        = THIS    412                 .base.cra_module        = THIS_MODULE,
413                 .min_keysize            = DES3    413                 .min_keysize            = DES3_EDE_KEY_SIZE,
414                 .max_keysize            = DES3    414                 .max_keysize            = DES3_EDE_KEY_SIZE,
415                 .setkey                 = des3    415                 .setkey                 = des3_ede_set_key_skcipher,
416                 .encrypt                = ecb3    416                 .encrypt                = ecb3_encrypt,
417                 .decrypt                = ecb3    417                 .decrypt                = ecb3_decrypt,
418         }, {                                      418         }, {
419                 .base.cra_name          = "cbc    419                 .base.cra_name          = "cbc(des3_ede)",
420                 .base.cra_driver_name   = "cbc    420                 .base.cra_driver_name   = "cbc-des3_ede-sparc64",
421                 .base.cra_priority      = SPAR    421                 .base.cra_priority      = SPARC_CR_OPCODE_PRIORITY,
422                 .base.cra_blocksize     = DES3    422                 .base.cra_blocksize     = DES3_EDE_BLOCK_SIZE,
423                 .base.cra_ctxsize       = size    423                 .base.cra_ctxsize       = sizeof(struct des3_ede_sparc64_ctx),
424                 .base.cra_alignmask     = 7,      424                 .base.cra_alignmask     = 7,
425                 .base.cra_module        = THIS    425                 .base.cra_module        = THIS_MODULE,
426                 .min_keysize            = DES3    426                 .min_keysize            = DES3_EDE_KEY_SIZE,
427                 .max_keysize            = DES3    427                 .max_keysize            = DES3_EDE_KEY_SIZE,
428                 .ivsize                 = DES3    428                 .ivsize                 = DES3_EDE_BLOCK_SIZE,
429                 .setkey                 = des3    429                 .setkey                 = des3_ede_set_key_skcipher,
430                 .encrypt                = cbc3    430                 .encrypt                = cbc3_encrypt,
431                 .decrypt                = cbc3    431                 .decrypt                = cbc3_decrypt,
432         }                                         432         }
433 };                                                433 };
434                                                   434 
435 static bool __init sparc64_has_des_opcode(void    435 static bool __init sparc64_has_des_opcode(void)
436 {                                                 436 {
437         unsigned long cfr;                        437         unsigned long cfr;
438                                                   438 
439         if (!(sparc64_elf_hwcap & HWCAP_SPARC_    439         if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
440                 return false;                     440                 return false;
441                                                   441 
442         __asm__ __volatile__("rd %%asr26, %0"     442         __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
443         if (!(cfr & CFR_DES))                     443         if (!(cfr & CFR_DES))
444                 return false;                     444                 return false;
445                                                   445 
446         return true;                              446         return true;
447 }                                                 447 }
448                                                   448 
449 static int __init des_sparc64_mod_init(void)      449 static int __init des_sparc64_mod_init(void)
450 {                                                 450 {
451         int err;                                  451         int err;
452                                                   452 
453         if (!sparc64_has_des_opcode()) {          453         if (!sparc64_has_des_opcode()) {
454                 pr_info("sparc64 des opcodes n    454                 pr_info("sparc64 des opcodes not available.\n");
455                 return -ENODEV;                   455                 return -ENODEV;
456         }                                         456         }
457         pr_info("Using sparc64 des opcodes opt    457         pr_info("Using sparc64 des opcodes optimized DES implementation\n");
458         err = crypto_register_algs(cipher_algs    458         err = crypto_register_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
459         if (err)                                  459         if (err)
460                 return err;                       460                 return err;
461         err = crypto_register_skciphers(skciph    461         err = crypto_register_skciphers(skcipher_algs,
462                                         ARRAY_    462                                         ARRAY_SIZE(skcipher_algs));
463         if (err)                                  463         if (err)
464                 crypto_unregister_algs(cipher_    464                 crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
465         return err;                               465         return err;
466 }                                                 466 }
467                                                   467 
468 static void __exit des_sparc64_mod_fini(void)     468 static void __exit des_sparc64_mod_fini(void)
469 {                                                 469 {
470         crypto_unregister_algs(cipher_algs, AR    470         crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs));
471         crypto_unregister_skciphers(skcipher_a    471         crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
472 }                                                 472 }
473                                                   473 
474 module_init(des_sparc64_mod_init);                474 module_init(des_sparc64_mod_init);
475 module_exit(des_sparc64_mod_fini);                475 module_exit(des_sparc64_mod_fini);
476                                                   476 
477 MODULE_LICENSE("GPL");                            477 MODULE_LICENSE("GPL");
478 MODULE_DESCRIPTION("DES & Triple DES EDE Ciphe    478 MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms, sparc64 des opcode accelerated");
479                                                   479 
480 MODULE_ALIAS_CRYPTO("des");                       480 MODULE_ALIAS_CRYPTO("des");
481 MODULE_ALIAS_CRYPTO("des3_ede");                  481 MODULE_ALIAS_CRYPTO("des3_ede");
482                                                   482 
483 #include "crop_devid.c"                           483 #include "crop_devid.c"
484                                                   484 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php