Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: sparc - Remove des and des3_ede code

Since DES and Triple DES are obsolete, there is very little point in
maintining architecture-optimized code for them. Remove it.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
0e28a1a6 622d42ef

-917
-14
arch/sparc/crypto/Kconfig
··· 2 2 3 3 menu "Accelerated Cryptographic Algorithms for CPU (sparc64)" 4 4 5 - config CRYPTO_DES_SPARC64 6 - tristate "Ciphers: DES and Triple DES EDE, modes: ECB/CBC" 7 - depends on SPARC64 8 - select CRYPTO_ALGAPI 9 - select CRYPTO_LIB_DES 10 - select CRYPTO_SKCIPHER 11 - help 12 - Block cipher: DES (FIPS 46-2) cipher algorithm 13 - Block cipher: Triple DES EDE (FIPS 46-3) cipher algorithm 14 - Length-preserving ciphers: DES with ECB and CBC modes 15 - Length-preserving ciphers: Tripe DES EDE with ECB and CBC modes 16 - 17 - Architecture: sparc64 18 - 19 5 config CRYPTO_AES_SPARC64 20 6 tristate "Ciphers: AES, modes: ECB, CBC, CTR" 21 7 depends on SPARC64
-2
arch/sparc/crypto/Makefile
··· 4 4 # 5 5 6 6 obj-$(CONFIG_CRYPTO_AES_SPARC64) += aes-sparc64.o 7 - obj-$(CONFIG_CRYPTO_DES_SPARC64) += des-sparc64.o 8 7 obj-$(CONFIG_CRYPTO_CAMELLIA_SPARC64) += camellia-sparc64.o 9 8 10 9 aes-sparc64-y := aes_glue.o 11 - des-sparc64-y := des_asm.o des_glue.o 12 10 camellia-sparc64-y := camellia_asm.o camellia_glue.o
-419
arch/sparc/crypto/des_asm.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #include <linux/linkage.h> 3 - #include <asm/opcodes.h> 4 - #include <asm/visasm.h> 5 - 6 - .align 32 7 - ENTRY(des_sparc64_key_expand) 8 - /* %o0=input_key, %o1=output_key */ 9 - VISEntryHalf 10 - ld [%o0 + 0x00], %f0 11 - ld [%o0 + 0x04], %f1 12 - DES_KEXPAND(0, 0, 0) 13 - DES_KEXPAND(0, 1, 2) 14 - DES_KEXPAND(2, 3, 6) 15 - DES_KEXPAND(2, 2, 4) 16 - DES_KEXPAND(6, 3, 10) 17 - DES_KEXPAND(6, 2, 8) 18 - DES_KEXPAND(10, 3, 14) 19 - DES_KEXPAND(10, 2, 12) 20 - DES_KEXPAND(14, 1, 16) 21 - DES_KEXPAND(16, 3, 20) 22 - DES_KEXPAND(16, 2, 18) 23 - DES_KEXPAND(20, 3, 24) 24 - DES_KEXPAND(20, 2, 22) 25 - DES_KEXPAND(24, 3, 28) 26 - DES_KEXPAND(24, 2, 26) 27 - DES_KEXPAND(28, 1, 30) 28 - std %f0, [%o1 + 0x00] 29 - std %f2, [%o1 + 0x08] 30 - std %f4, [%o1 + 0x10] 31 - std %f6, [%o1 + 0x18] 32 - std %f8, [%o1 + 0x20] 33 - std %f10, [%o1 + 0x28] 34 - std %f12, [%o1 + 0x30] 35 - std %f14, [%o1 + 0x38] 36 - std %f16, [%o1 + 0x40] 37 - std %f18, [%o1 + 0x48] 38 - std %f20, [%o1 + 0x50] 39 - std %f22, [%o1 + 0x58] 40 - std %f24, [%o1 + 0x60] 41 - std %f26, [%o1 + 0x68] 42 - std %f28, [%o1 + 0x70] 43 - std %f30, [%o1 + 0x78] 44 - retl 45 - VISExitHalf 46 - ENDPROC(des_sparc64_key_expand) 47 - 48 - .align 32 49 - ENTRY(des_sparc64_crypt) 50 - /* %o0=key, %o1=input, %o2=output */ 51 - VISEntry 52 - ldd [%o1 + 0x00], %f32 53 - ldd [%o0 + 0x00], %f0 54 - ldd [%o0 + 0x08], %f2 55 - ldd [%o0 + 0x10], %f4 56 - ldd [%o0 + 0x18], %f6 57 - ldd [%o0 + 0x20], %f8 58 - ldd [%o0 + 0x28], %f10 59 - ldd [%o0 + 0x30], %f12 60 - ldd [%o0 + 0x38], %f14 61 - ldd [%o0 + 0x40], %f16 62 - ldd [%o0 + 0x48], %f18 63 - ldd [%o0 + 0x50], %f20 64 - ldd [%o0 + 0x58], %f22 65 - ldd [%o0 + 0x60], %f24 66 - ldd [%o0 + 0x68], %f26 67 - ldd [%o0 + 0x70], %f28 68 - ldd [%o0 + 0x78], %f30 69 - DES_IP(32, 32) 70 - DES_ROUND(0, 2, 32, 32) 71 - DES_ROUND(4, 6, 32, 32) 72 - DES_ROUND(8, 10, 32, 32) 73 - DES_ROUND(12, 14, 32, 32) 74 - DES_ROUND(16, 18, 32, 32) 75 - DES_ROUND(20, 22, 32, 32) 76 - DES_ROUND(24, 26, 32, 32) 77 - DES_ROUND(28, 30, 32, 32) 78 - DES_IIP(32, 32) 79 - std %f32, [%o2 + 0x00] 80 - retl 81 - VISExit 82 - ENDPROC(des_sparc64_crypt) 83 - 84 - .align 32 85 - ENTRY(des_sparc64_load_keys) 86 - /* %o0=key */ 87 - VISEntry 88 - ldd [%o0 + 0x00], %f0 89 - ldd [%o0 + 0x08], %f2 90 - ldd [%o0 + 0x10], %f4 91 - ldd [%o0 + 0x18], %f6 92 - ldd [%o0 + 0x20], %f8 93 - ldd [%o0 + 0x28], %f10 94 - ldd [%o0 + 0x30], %f12 95 - ldd [%o0 + 0x38], %f14 96 - ldd [%o0 + 0x40], %f16 97 - ldd [%o0 + 0x48], %f18 98 - ldd [%o0 + 0x50], %f20 99 - ldd [%o0 + 0x58], %f22 100 - ldd [%o0 + 0x60], %f24 101 - ldd [%o0 + 0x68], %f26 102 - ldd [%o0 + 0x70], %f28 103 - retl 104 - ldd [%o0 + 0x78], %f30 105 - ENDPROC(des_sparc64_load_keys) 106 - 107 - .align 32 108 - ENTRY(des_sparc64_ecb_crypt) 109 - /* %o0=input, %o1=output, %o2=len */ 110 - 1: ldd [%o0 + 0x00], %f32 111 - add %o0, 0x08, %o0 112 - DES_IP(32, 32) 113 - DES_ROUND(0, 2, 32, 32) 114 - DES_ROUND(4, 6, 32, 32) 115 - DES_ROUND(8, 10, 32, 32) 116 - DES_ROUND(12, 14, 32, 32) 117 - DES_ROUND(16, 18, 32, 32) 118 - DES_ROUND(20, 22, 32, 32) 119 - DES_ROUND(24, 26, 32, 32) 120 - DES_ROUND(28, 30, 32, 32) 121 - DES_IIP(32, 32) 122 - std %f32, [%o1 + 0x00] 123 - subcc %o2, 0x08, %o2 124 - bne,pt %icc, 1b 125 - add %o1, 0x08, %o1 126 - retl 127 - nop 128 - ENDPROC(des_sparc64_ecb_crypt) 129 - 130 - .align 32 131 - ENTRY(des_sparc64_cbc_encrypt) 132 - /* %o0=input, %o1=output, %o2=len, %o3=IV */ 133 - ldd [%o3 + 0x00], %f32 134 - 1: ldd [%o0 + 0x00], %f34 135 - fxor %f32, %f34, %f32 136 - DES_IP(32, 32) 137 - DES_ROUND(0, 2, 32, 32) 138 - DES_ROUND(4, 6, 32, 32) 139 - DES_ROUND(8, 10, 32, 32) 140 - DES_ROUND(12, 14, 32, 32) 141 - DES_ROUND(16, 18, 32, 32) 142 - DES_ROUND(20, 22, 32, 32) 143 - DES_ROUND(24, 26, 32, 32) 144 - DES_ROUND(28, 30, 32, 32) 145 - DES_IIP(32, 32) 146 - std %f32, [%o1 + 0x00] 147 - add %o0, 0x08, %o0 148 - subcc %o2, 0x08, %o2 149 - bne,pt %icc, 1b 150 - add %o1, 0x08, %o1 151 - retl 152 - std %f32, [%o3 + 0x00] 153 - ENDPROC(des_sparc64_cbc_encrypt) 154 - 155 - .align 32 156 - ENTRY(des_sparc64_cbc_decrypt) 157 - /* %o0=input, %o1=output, %o2=len, %o3=IV */ 158 - ldd [%o3 + 0x00], %f34 159 - 1: ldd [%o0 + 0x00], %f36 160 - DES_IP(36, 32) 161 - DES_ROUND(0, 2, 32, 32) 162 - DES_ROUND(4, 6, 32, 32) 163 - DES_ROUND(8, 10, 32, 32) 164 - DES_ROUND(12, 14, 32, 32) 165 - DES_ROUND(16, 18, 32, 32) 166 - DES_ROUND(20, 22, 32, 32) 167 - DES_ROUND(24, 26, 32, 32) 168 - DES_ROUND(28, 30, 32, 32) 169 - DES_IIP(32, 32) 170 - fxor %f32, %f34, %f32 171 - fsrc2 %f36, %f34 172 - std %f32, [%o1 + 0x00] 173 - add %o0, 0x08, %o0 174 - subcc %o2, 0x08, %o2 175 - bne,pt %icc, 1b 176 - add %o1, 0x08, %o1 177 - retl 178 - std %f36, [%o3 + 0x00] 179 - ENDPROC(des_sparc64_cbc_decrypt) 180 - 181 - .align 32 182 - ENTRY(des3_ede_sparc64_crypt) 183 - /* %o0=key, %o1=input, %o2=output */ 184 - VISEntry 185 - ldd [%o1 + 0x00], %f32 186 - ldd [%o0 + 0x00], %f0 187 - ldd [%o0 + 0x08], %f2 188 - ldd [%o0 + 0x10], %f4 189 - ldd [%o0 + 0x18], %f6 190 - ldd [%o0 + 0x20], %f8 191 - ldd [%o0 + 0x28], %f10 192 - ldd [%o0 + 0x30], %f12 193 - ldd [%o0 + 0x38], %f14 194 - ldd [%o0 + 0x40], %f16 195 - ldd [%o0 + 0x48], %f18 196 - ldd [%o0 + 0x50], %f20 197 - ldd [%o0 + 0x58], %f22 198 - ldd [%o0 + 0x60], %f24 199 - ldd [%o0 + 0x68], %f26 200 - ldd [%o0 + 0x70], %f28 201 - ldd [%o0 + 0x78], %f30 202 - DES_IP(32, 32) 203 - DES_ROUND(0, 2, 32, 32) 204 - ldd [%o0 + 0x80], %f0 205 - ldd [%o0 + 0x88], %f2 206 - DES_ROUND(4, 6, 32, 32) 207 - ldd [%o0 + 0x90], %f4 208 - ldd [%o0 + 0x98], %f6 209 - DES_ROUND(8, 10, 32, 32) 210 - ldd [%o0 + 0xa0], %f8 211 - ldd [%o0 + 0xa8], %f10 212 - DES_ROUND(12, 14, 32, 32) 213 - ldd [%o0 + 0xb0], %f12 214 - ldd [%o0 + 0xb8], %f14 215 - DES_ROUND(16, 18, 32, 32) 216 - ldd [%o0 + 0xc0], %f16 217 - ldd [%o0 + 0xc8], %f18 218 - DES_ROUND(20, 22, 32, 32) 219 - ldd [%o0 + 0xd0], %f20 220 - ldd [%o0 + 0xd8], %f22 221 - DES_ROUND(24, 26, 32, 32) 222 - ldd [%o0 + 0xe0], %f24 223 - ldd [%o0 + 0xe8], %f26 224 - DES_ROUND(28, 30, 32, 32) 225 - ldd [%o0 + 0xf0], %f28 226 - ldd [%o0 + 0xf8], %f30 227 - DES_IIP(32, 32) 228 - DES_IP(32, 32) 229 - DES_ROUND(0, 2, 32, 32) 230 - ldd [%o0 + 0x100], %f0 231 - ldd [%o0 + 0x108], %f2 232 - DES_ROUND(4, 6, 32, 32) 233 - ldd [%o0 + 0x110], %f4 234 - ldd [%o0 + 0x118], %f6 235 - DES_ROUND(8, 10, 32, 32) 236 - ldd [%o0 + 0x120], %f8 237 - ldd [%o0 + 0x128], %f10 238 - DES_ROUND(12, 14, 32, 32) 239 - ldd [%o0 + 0x130], %f12 240 - ldd [%o0 + 0x138], %f14 241 - DES_ROUND(16, 18, 32, 32) 242 - ldd [%o0 + 0x140], %f16 243 - ldd [%o0 + 0x148], %f18 244 - DES_ROUND(20, 22, 32, 32) 245 - ldd [%o0 + 0x150], %f20 246 - ldd [%o0 + 0x158], %f22 247 - DES_ROUND(24, 26, 32, 32) 248 - ldd [%o0 + 0x160], %f24 249 - ldd [%o0 + 0x168], %f26 250 - DES_ROUND(28, 30, 32, 32) 251 - ldd [%o0 + 0x170], %f28 252 - ldd [%o0 + 0x178], %f30 253 - DES_IIP(32, 32) 254 - DES_IP(32, 32) 255 - DES_ROUND(0, 2, 32, 32) 256 - DES_ROUND(4, 6, 32, 32) 257 - DES_ROUND(8, 10, 32, 32) 258 - DES_ROUND(12, 14, 32, 32) 259 - DES_ROUND(16, 18, 32, 32) 260 - DES_ROUND(20, 22, 32, 32) 261 - DES_ROUND(24, 26, 32, 32) 262 - DES_ROUND(28, 30, 32, 32) 263 - DES_IIP(32, 32) 264 - 265 - std %f32, [%o2 + 0x00] 266 - retl 267 - VISExit 268 - ENDPROC(des3_ede_sparc64_crypt) 269 - 270 - .align 32 271 - ENTRY(des3_ede_sparc64_load_keys) 272 - /* %o0=key */ 273 - VISEntry 274 - ldd [%o0 + 0x00], %f0 275 - ldd [%o0 + 0x08], %f2 276 - ldd [%o0 + 0x10], %f4 277 - ldd [%o0 + 0x18], %f6 278 - ldd [%o0 + 0x20], %f8 279 - ldd [%o0 + 0x28], %f10 280 - ldd [%o0 + 0x30], %f12 281 - ldd [%o0 + 0x38], %f14 282 - ldd [%o0 + 0x40], %f16 283 - ldd [%o0 + 0x48], %f18 284 - ldd [%o0 + 0x50], %f20 285 - ldd [%o0 + 0x58], %f22 286 - ldd [%o0 + 0x60], %f24 287 - ldd [%o0 + 0x68], %f26 288 - ldd [%o0 + 0x70], %f28 289 - ldd [%o0 + 0x78], %f30 290 - ldd [%o0 + 0x80], %f32 291 - ldd [%o0 + 0x88], %f34 292 - ldd [%o0 + 0x90], %f36 293 - ldd [%o0 + 0x98], %f38 294 - ldd [%o0 + 0xa0], %f40 295 - ldd [%o0 + 0xa8], %f42 296 - ldd [%o0 + 0xb0], %f44 297 - ldd [%o0 + 0xb8], %f46 298 - ldd [%o0 + 0xc0], %f48 299 - ldd [%o0 + 0xc8], %f50 300 - ldd [%o0 + 0xd0], %f52 301 - ldd [%o0 + 0xd8], %f54 302 - ldd [%o0 + 0xe0], %f56 303 - retl 304 - ldd [%o0 + 0xe8], %f58 305 - ENDPROC(des3_ede_sparc64_load_keys) 306 - 307 - #define DES3_LOOP_BODY(X) \ 308 - DES_IP(X, X) \ 309 - DES_ROUND(0, 2, X, X) \ 310 - DES_ROUND(4, 6, X, X) \ 311 - DES_ROUND(8, 10, X, X) \ 312 - DES_ROUND(12, 14, X, X) \ 313 - DES_ROUND(16, 18, X, X) \ 314 - ldd [%o0 + 0xf0], %f16; \ 315 - ldd [%o0 + 0xf8], %f18; \ 316 - DES_ROUND(20, 22, X, X) \ 317 - ldd [%o0 + 0x100], %f20; \ 318 - ldd [%o0 + 0x108], %f22; \ 319 - DES_ROUND(24, 26, X, X) \ 320 - ldd [%o0 + 0x110], %f24; \ 321 - ldd [%o0 + 0x118], %f26; \ 322 - DES_ROUND(28, 30, X, X) \ 323 - ldd [%o0 + 0x120], %f28; \ 324 - ldd [%o0 + 0x128], %f30; \ 325 - DES_IIP(X, X) \ 326 - DES_IP(X, X) \ 327 - DES_ROUND(32, 34, X, X) \ 328 - ldd [%o0 + 0x130], %f0; \ 329 - ldd [%o0 + 0x138], %f2; \ 330 - DES_ROUND(36, 38, X, X) \ 331 - ldd [%o0 + 0x140], %f4; \ 332 - ldd [%o0 + 0x148], %f6; \ 333 - DES_ROUND(40, 42, X, X) \ 334 - ldd [%o0 + 0x150], %f8; \ 335 - ldd [%o0 + 0x158], %f10; \ 336 - DES_ROUND(44, 46, X, X) \ 337 - ldd [%o0 + 0x160], %f12; \ 338 - ldd [%o0 + 0x168], %f14; \ 339 - DES_ROUND(48, 50, X, X) \ 340 - DES_ROUND(52, 54, X, X) \ 341 - DES_ROUND(56, 58, X, X) \ 342 - DES_ROUND(16, 18, X, X) \ 343 - ldd [%o0 + 0x170], %f16; \ 344 - ldd [%o0 + 0x178], %f18; \ 345 - DES_IIP(X, X) \ 346 - DES_IP(X, X) \ 347 - DES_ROUND(20, 22, X, X) \ 348 - ldd [%o0 + 0x50], %f20; \ 349 - ldd [%o0 + 0x58], %f22; \ 350 - DES_ROUND(24, 26, X, X) \ 351 - ldd [%o0 + 0x60], %f24; \ 352 - ldd [%o0 + 0x68], %f26; \ 353 - DES_ROUND(28, 30, X, X) \ 354 - ldd [%o0 + 0x70], %f28; \ 355 - ldd [%o0 + 0x78], %f30; \ 356 - DES_ROUND(0, 2, X, X) \ 357 - ldd [%o0 + 0x00], %f0; \ 358 - ldd [%o0 + 0x08], %f2; \ 359 - DES_ROUND(4, 6, X, X) \ 360 - ldd [%o0 + 0x10], %f4; \ 361 - ldd [%o0 + 0x18], %f6; \ 362 - DES_ROUND(8, 10, X, X) \ 363 - ldd [%o0 + 0x20], %f8; \ 364 - ldd [%o0 + 0x28], %f10; \ 365 - DES_ROUND(12, 14, X, X) \ 366 - ldd [%o0 + 0x30], %f12; \ 367 - ldd [%o0 + 0x38], %f14; \ 368 - DES_ROUND(16, 18, X, X) \ 369 - ldd [%o0 + 0x40], %f16; \ 370 - ldd [%o0 + 0x48], %f18; \ 371 - DES_IIP(X, X) 372 - 373 - .align 32 374 - ENTRY(des3_ede_sparc64_ecb_crypt) 375 - /* %o0=key, %o1=input, %o2=output, %o3=len */ 376 - 1: ldd [%o1 + 0x00], %f60 377 - DES3_LOOP_BODY(60) 378 - std %f60, [%o2 + 0x00] 379 - add %o1, 0x08, %o1 380 - subcc %o3, 0x08, %o3 381 - bne,pt %icc, 1b 382 - add %o2, 0x08, %o2 383 - retl 384 - nop 385 - ENDPROC(des3_ede_sparc64_ecb_crypt) 386 - 387 - .align 32 388 - ENTRY(des3_ede_sparc64_cbc_encrypt) 389 - /* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */ 390 - ldd [%o4 + 0x00], %f60 391 - 1: ldd [%o1 + 0x00], %f62 392 - fxor %f60, %f62, %f60 393 - DES3_LOOP_BODY(60) 394 - std %f60, [%o2 + 0x00] 395 - add %o1, 0x08, %o1 396 - subcc %o3, 0x08, %o3 397 - bne,pt %icc, 1b 398 - add %o2, 0x08, %o2 399 - retl 400 - std %f60, [%o4 + 0x00] 401 - ENDPROC(des3_ede_sparc64_cbc_encrypt) 402 - 403 - .align 32 404 - ENTRY(des3_ede_sparc64_cbc_decrypt) 405 - /* %o0=key, %o1=input, %o2=output, %o3=len, %o4=IV */ 406 - ldd [%o4 + 0x00], %f62 407 - 1: ldx [%o1 + 0x00], %g1 408 - MOVXTOD_G1_F60 409 - DES3_LOOP_BODY(60) 410 - fxor %f62, %f60, %f60 411 - MOVXTOD_G1_F62 412 - std %f60, [%o2 + 0x00] 413 - add %o1, 0x08, %o1 414 - subcc %o3, 0x08, %o3 415 - bne,pt %icc, 1b 416 - add %o2, 0x08, %o2 417 - retl 418 - stx %g1, [%o4 + 0x00] 419 - ENDPROC(des3_ede_sparc64_cbc_decrypt)
-482
arch/sparc/crypto/des_glue.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* Glue code for DES encryption optimized for sparc64 crypto opcodes. 3 - * 4 - * Copyright (C) 2012 David S. Miller <davem@davemloft.net> 5 - */ 6 - 7 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8 - 9 - #include <linux/crypto.h> 10 - #include <linux/init.h> 11 - #include <linux/module.h> 12 - #include <linux/mm.h> 13 - #include <linux/types.h> 14 - #include <crypto/algapi.h> 15 - #include <crypto/internal/des.h> 16 - #include <crypto/internal/skcipher.h> 17 - 18 - #include <asm/fpumacro.h> 19 - #include <asm/opcodes.h> 20 - #include <asm/pstate.h> 21 - #include <asm/elf.h> 22 - 23 - struct des_sparc64_ctx { 24 - u64 encrypt_expkey[DES_EXPKEY_WORDS / 2]; 25 - u64 decrypt_expkey[DES_EXPKEY_WORDS / 2]; 26 - }; 27 - 28 - struct des3_ede_sparc64_ctx { 29 - u64 encrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2]; 30 - u64 decrypt_expkey[DES3_EDE_EXPKEY_WORDS / 2]; 31 - }; 32 - 33 - static void encrypt_to_decrypt(u64 *d, const u64 *e) 34 - { 35 - const u64 *s = e + (DES_EXPKEY_WORDS / 2) - 1; 36 - int i; 37 - 38 - for (i = 0; i < DES_EXPKEY_WORDS / 2; i++) 39 - *d++ = *s--; 40 - } 41 - 42 - extern void des_sparc64_key_expand(const u32 *input_key, u64 *key); 43 - 44 - static int des_set_key(struct crypto_tfm *tfm, const u8 *key, 45 - unsigned int keylen) 46 - { 47 - struct des_sparc64_ctx *dctx = crypto_tfm_ctx(tfm); 48 - int err; 49 - 50 - /* Even though we have special instructions for key expansion, 51 - * we call des_verify_key() so that we don't have to write our own 52 - * weak key detection code. 53 - */ 54 - err = crypto_des_verify_key(tfm, key); 55 - if (err) 56 - return err; 57 - 58 - des_sparc64_key_expand((const u32 *) key, &dctx->encrypt_expkey[0]); 59 - encrypt_to_decrypt(&dctx->decrypt_expkey[0], &dctx->encrypt_expkey[0]); 60 - 61 - return 0; 62 - } 63 - 64 - static int des_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key, 65 - unsigned int keylen) 66 - { 67 - return des_set_key(crypto_skcipher_tfm(tfm), key, keylen); 68 - } 69 - 70 - extern void des_sparc64_crypt(const u64 *key, const u64 *input, 71 - u64 *output); 72 - 73 - static void sparc_des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 74 - { 75 - struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 76 - const u64 *K = ctx->encrypt_expkey; 77 - 78 - des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); 79 - } 80 - 81 - static void sparc_des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 82 - { 83 - struct des_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 84 - const u64 *K = ctx->decrypt_expkey; 85 - 86 - des_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); 87 - } 88 - 89 - extern void des_sparc64_load_keys(const u64 *key); 90 - 91 - extern void des_sparc64_ecb_crypt(const u64 *input, u64 *output, 92 - unsigned int len); 93 - 94 - static int __ecb_crypt(struct skcipher_request *req, bool encrypt) 95 - { 96 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 97 - const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm); 98 - struct skcipher_walk walk; 99 - unsigned int nbytes; 100 - int err; 101 - 102 - err = skcipher_walk_virt(&walk, req, true); 103 - if (err) 104 - return err; 105 - 106 - if (encrypt) 107 - des_sparc64_load_keys(&ctx->encrypt_expkey[0]); 108 - else 109 - des_sparc64_load_keys(&ctx->decrypt_expkey[0]); 110 - while ((nbytes = walk.nbytes) != 0) { 111 - des_sparc64_ecb_crypt(walk.src.virt.addr, walk.dst.virt.addr, 112 - round_down(nbytes, DES_BLOCK_SIZE)); 113 - err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE); 114 - } 115 - fprs_write(0); 116 - return err; 117 - } 118 - 119 - static int ecb_encrypt(struct skcipher_request *req) 120 - { 121 - return __ecb_crypt(req, true); 122 - } 123 - 124 - static int ecb_decrypt(struct skcipher_request *req) 125 - { 126 - return __ecb_crypt(req, false); 127 - } 128 - 129 - extern void des_sparc64_cbc_encrypt(const u64 *input, u64 *output, 130 - unsigned int len, u64 *iv); 131 - 132 - extern void des_sparc64_cbc_decrypt(const u64 *input, u64 *output, 133 - unsigned int len, u64 *iv); 134 - 135 - static int __cbc_crypt(struct skcipher_request *req, bool encrypt) 136 - { 137 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 138 - const struct des_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm); 139 - struct skcipher_walk walk; 140 - unsigned int nbytes; 141 - int err; 142 - 143 - err = skcipher_walk_virt(&walk, req, true); 144 - if (err) 145 - return err; 146 - 147 - if (encrypt) 148 - des_sparc64_load_keys(&ctx->encrypt_expkey[0]); 149 - else 150 - des_sparc64_load_keys(&ctx->decrypt_expkey[0]); 151 - while ((nbytes = walk.nbytes) != 0) { 152 - if (encrypt) 153 - des_sparc64_cbc_encrypt(walk.src.virt.addr, 154 - walk.dst.virt.addr, 155 - round_down(nbytes, 156 - DES_BLOCK_SIZE), 157 - walk.iv); 158 - else 159 - des_sparc64_cbc_decrypt(walk.src.virt.addr, 160 - walk.dst.virt.addr, 161 - round_down(nbytes, 162 - DES_BLOCK_SIZE), 163 - walk.iv); 164 - err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE); 165 - } 166 - fprs_write(0); 167 - return err; 168 - } 169 - 170 - static int cbc_encrypt(struct skcipher_request *req) 171 - { 172 - return __cbc_crypt(req, true); 173 - } 174 - 175 - static int cbc_decrypt(struct skcipher_request *req) 176 - { 177 - return __cbc_crypt(req, false); 178 - } 179 - 180 - static int des3_ede_set_key(struct crypto_tfm *tfm, const u8 *key, 181 - unsigned int keylen) 182 - { 183 - struct des3_ede_sparc64_ctx *dctx = crypto_tfm_ctx(tfm); 184 - u64 k1[DES_EXPKEY_WORDS / 2]; 185 - u64 k2[DES_EXPKEY_WORDS / 2]; 186 - u64 k3[DES_EXPKEY_WORDS / 2]; 187 - int err; 188 - 189 - err = crypto_des3_ede_verify_key(tfm, key); 190 - if (err) 191 - return err; 192 - 193 - des_sparc64_key_expand((const u32 *)key, k1); 194 - key += DES_KEY_SIZE; 195 - des_sparc64_key_expand((const u32 *)key, k2); 196 - key += DES_KEY_SIZE; 197 - des_sparc64_key_expand((const u32 *)key, k3); 198 - 199 - memcpy(&dctx->encrypt_expkey[0], &k1[0], sizeof(k1)); 200 - encrypt_to_decrypt(&dctx->encrypt_expkey[DES_EXPKEY_WORDS / 2], &k2[0]); 201 - memcpy(&dctx->encrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2], 202 - &k3[0], sizeof(k3)); 203 - 204 - encrypt_to_decrypt(&dctx->decrypt_expkey[0], &k3[0]); 205 - memcpy(&dctx->decrypt_expkey[DES_EXPKEY_WORDS / 2], 206 - &k2[0], sizeof(k2)); 207 - encrypt_to_decrypt(&dctx->decrypt_expkey[(DES_EXPKEY_WORDS / 2) * 2], 208 - &k1[0]); 209 - 210 - return 0; 211 - } 212 - 213 - static int des3_ede_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *key, 214 - unsigned int keylen) 215 - { 216 - return des3_ede_set_key(crypto_skcipher_tfm(tfm), key, keylen); 217 - } 218 - 219 - extern void des3_ede_sparc64_crypt(const u64 *key, const u64 *input, 220 - u64 *output); 221 - 222 - static void sparc_des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 223 - { 224 - struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 225 - const u64 *K = ctx->encrypt_expkey; 226 - 227 - des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); 228 - } 229 - 230 - static void sparc_des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 231 - { 232 - struct des3_ede_sparc64_ctx *ctx = crypto_tfm_ctx(tfm); 233 - const u64 *K = ctx->decrypt_expkey; 234 - 235 - des3_ede_sparc64_crypt(K, (const u64 *) src, (u64 *) dst); 236 - } 237 - 238 - extern void des3_ede_sparc64_load_keys(const u64 *key); 239 - 240 - extern void des3_ede_sparc64_ecb_crypt(const u64 *expkey, const u64 *input, 241 - u64 *output, unsigned int len); 242 - 243 - static int __ecb3_crypt(struct skcipher_request *req, bool encrypt) 244 - { 245 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 246 - const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm); 247 - struct skcipher_walk walk; 248 - const u64 *K; 249 - unsigned int nbytes; 250 - int err; 251 - 252 - err = skcipher_walk_virt(&walk, req, true); 253 - if (err) 254 - return err; 255 - 256 - if (encrypt) 257 - K = &ctx->encrypt_expkey[0]; 258 - else 259 - K = &ctx->decrypt_expkey[0]; 260 - des3_ede_sparc64_load_keys(K); 261 - while ((nbytes = walk.nbytes) != 0) { 262 - des3_ede_sparc64_ecb_crypt(K, walk.src.virt.addr, 263 - walk.dst.virt.addr, 264 - round_down(nbytes, DES_BLOCK_SIZE)); 265 - err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE); 266 - } 267 - fprs_write(0); 268 - return err; 269 - } 270 - 271 - static int ecb3_encrypt(struct skcipher_request *req) 272 - { 273 - return __ecb3_crypt(req, true); 274 - } 275 - 276 - static int ecb3_decrypt(struct skcipher_request *req) 277 - { 278 - return __ecb3_crypt(req, false); 279 - } 280 - 281 - extern void des3_ede_sparc64_cbc_encrypt(const u64 *expkey, const u64 *input, 282 - u64 *output, unsigned int len, 283 - u64 *iv); 284 - 285 - extern void des3_ede_sparc64_cbc_decrypt(const u64 *expkey, const u64 *input, 286 - u64 *output, unsigned int len, 287 - u64 *iv); 288 - 289 - static int __cbc3_crypt(struct skcipher_request *req, bool encrypt) 290 - { 291 - struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 292 - const struct des3_ede_sparc64_ctx *ctx = crypto_skcipher_ctx(tfm); 293 - struct skcipher_walk walk; 294 - const u64 *K; 295 - unsigned int nbytes; 296 - int err; 297 - 298 - err = skcipher_walk_virt(&walk, req, true); 299 - if (err) 300 - return err; 301 - 302 - if (encrypt) 303 - K = &ctx->encrypt_expkey[0]; 304 - else 305 - K = &ctx->decrypt_expkey[0]; 306 - des3_ede_sparc64_load_keys(K); 307 - while ((nbytes = walk.nbytes) != 0) { 308 - if (encrypt) 309 - des3_ede_sparc64_cbc_encrypt(K, walk.src.virt.addr, 310 - walk.dst.virt.addr, 311 - round_down(nbytes, 312 - DES_BLOCK_SIZE), 313 - walk.iv); 314 - else 315 - des3_ede_sparc64_cbc_decrypt(K, walk.src.virt.addr, 316 - walk.dst.virt.addr, 317 - round_down(nbytes, 318 - DES_BLOCK_SIZE), 319 - walk.iv); 320 - err = skcipher_walk_done(&walk, nbytes % DES_BLOCK_SIZE); 321 - } 322 - fprs_write(0); 323 - return err; 324 - } 325 - 326 - static int cbc3_encrypt(struct skcipher_request *req) 327 - { 328 - return __cbc3_crypt(req, true); 329 - } 330 - 331 - static int cbc3_decrypt(struct skcipher_request *req) 332 - { 333 - return __cbc3_crypt(req, false); 334 - } 335 - 336 - static struct crypto_alg cipher_algs[] = { 337 - { 338 - .cra_name = "des", 339 - .cra_driver_name = "des-sparc64", 340 - .cra_priority = SPARC_CR_OPCODE_PRIORITY, 341 - .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 342 - .cra_blocksize = DES_BLOCK_SIZE, 343 - .cra_ctxsize = sizeof(struct des_sparc64_ctx), 344 - .cra_alignmask = 7, 345 - .cra_module = THIS_MODULE, 346 - .cra_u = { 347 - .cipher = { 348 - .cia_min_keysize = DES_KEY_SIZE, 349 - .cia_max_keysize = DES_KEY_SIZE, 350 - .cia_setkey = des_set_key, 351 - .cia_encrypt = sparc_des_encrypt, 352 - .cia_decrypt = sparc_des_decrypt 353 - } 354 - } 355 - }, { 356 - .cra_name = "des3_ede", 357 - .cra_driver_name = "des3_ede-sparc64", 358 - .cra_priority = SPARC_CR_OPCODE_PRIORITY, 359 - .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 360 - .cra_blocksize = DES3_EDE_BLOCK_SIZE, 361 - .cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx), 362 - .cra_alignmask = 7, 363 - .cra_module = THIS_MODULE, 364 - .cra_u = { 365 - .cipher = { 366 - .cia_min_keysize = DES3_EDE_KEY_SIZE, 367 - .cia_max_keysize = DES3_EDE_KEY_SIZE, 368 - .cia_setkey = des3_ede_set_key, 369 - .cia_encrypt = sparc_des3_ede_encrypt, 370 - .cia_decrypt = sparc_des3_ede_decrypt 371 - } 372 - } 373 - } 374 - }; 375 - 376 - static struct skcipher_alg skcipher_algs[] = { 377 - { 378 - .base.cra_name = "ecb(des)", 379 - .base.cra_driver_name = "ecb-des-sparc64", 380 - .base.cra_priority = SPARC_CR_OPCODE_PRIORITY, 381 - .base.cra_blocksize = DES_BLOCK_SIZE, 382 - .base.cra_ctxsize = sizeof(struct des_sparc64_ctx), 383 - .base.cra_alignmask = 7, 384 - .base.cra_module = THIS_MODULE, 385 - .min_keysize = DES_KEY_SIZE, 386 - .max_keysize = DES_KEY_SIZE, 387 - .setkey = des_set_key_skcipher, 388 - .encrypt = ecb_encrypt, 389 - .decrypt = ecb_decrypt, 390 - }, { 391 - .base.cra_name = "cbc(des)", 392 - .base.cra_driver_name = "cbc-des-sparc64", 393 - .base.cra_priority = SPARC_CR_OPCODE_PRIORITY, 394 - .base.cra_blocksize = DES_BLOCK_SIZE, 395 - .base.cra_ctxsize = sizeof(struct des_sparc64_ctx), 396 - .base.cra_alignmask = 7, 397 - .base.cra_module = THIS_MODULE, 398 - .min_keysize = DES_KEY_SIZE, 399 - .max_keysize = DES_KEY_SIZE, 400 - .ivsize = DES_BLOCK_SIZE, 401 - .setkey = des_set_key_skcipher, 402 - .encrypt = cbc_encrypt, 403 - .decrypt = cbc_decrypt, 404 - }, { 405 - .base.cra_name = "ecb(des3_ede)", 406 - .base.cra_driver_name = "ecb-des3_ede-sparc64", 407 - .base.cra_priority = SPARC_CR_OPCODE_PRIORITY, 408 - .base.cra_blocksize = DES3_EDE_BLOCK_SIZE, 409 - .base.cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx), 410 - .base.cra_alignmask = 7, 411 - .base.cra_module = THIS_MODULE, 412 - .min_keysize = DES3_EDE_KEY_SIZE, 413 - .max_keysize = DES3_EDE_KEY_SIZE, 414 - .setkey = des3_ede_set_key_skcipher, 415 - .encrypt = ecb3_encrypt, 416 - .decrypt = ecb3_decrypt, 417 - }, { 418 - .base.cra_name = "cbc(des3_ede)", 419 - .base.cra_driver_name = "cbc-des3_ede-sparc64", 420 - .base.cra_priority = SPARC_CR_OPCODE_PRIORITY, 421 - .base.cra_blocksize = DES3_EDE_BLOCK_SIZE, 422 - .base.cra_ctxsize = sizeof(struct des3_ede_sparc64_ctx), 423 - .base.cra_alignmask = 7, 424 - .base.cra_module = THIS_MODULE, 425 - .min_keysize = DES3_EDE_KEY_SIZE, 426 - .max_keysize = DES3_EDE_KEY_SIZE, 427 - .ivsize = DES3_EDE_BLOCK_SIZE, 428 - .setkey = des3_ede_set_key_skcipher, 429 - .encrypt = cbc3_encrypt, 430 - .decrypt = cbc3_decrypt, 431 - } 432 - }; 433 - 434 - static bool __init sparc64_has_des_opcode(void) 435 - { 436 - unsigned long cfr; 437 - 438 - if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO)) 439 - return false; 440 - 441 - __asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr)); 442 - if (!(cfr & CFR_DES)) 443 - return false; 444 - 445 - return true; 446 - } 447 - 448 - static int __init des_sparc64_mod_init(void) 449 - { 450 - int err; 451 - 452 - if (!sparc64_has_des_opcode()) { 453 - pr_info("sparc64 des opcodes not available.\n"); 454 - return -ENODEV; 455 - } 456 - pr_info("Using sparc64 des opcodes optimized DES implementation\n"); 457 - err = crypto_register_algs(cipher_algs, ARRAY_SIZE(cipher_algs)); 458 - if (err) 459 - return err; 460 - err = crypto_register_skciphers(skcipher_algs, 461 - ARRAY_SIZE(skcipher_algs)); 462 - if (err) 463 - crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs)); 464 - return err; 465 - } 466 - 467 - static void __exit des_sparc64_mod_fini(void) 468 - { 469 - crypto_unregister_algs(cipher_algs, ARRAY_SIZE(cipher_algs)); 470 - crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs)); 471 - } 472 - 473 - module_init(des_sparc64_mod_init); 474 - module_exit(des_sparc64_mod_fini); 475 - 476 - MODULE_LICENSE("GPL"); 477 - MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms, sparc64 des opcode accelerated"); 478 - 479 - MODULE_ALIAS_CRYPTO("des"); 480 - MODULE_ALIAS_CRYPTO("des3_ede"); 481 - 482 - #include "crop_devid.c"