Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Cryptographic API. |
| 3 | * |
| 4 | * Support for s390 cryptographic instructions. |
| 5 | * |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 6 | * Copyright IBM Corp. 2003,2007 |
| 7 | * Author(s): Thomas Spatzier |
| 8 | * Jan Glauber (jan.glauber@de.ibm.com) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | */ |
| 16 | #ifndef _CRYPTO_ARCH_S390_CRYPT_S390_H |
| 17 | #define _CRYPTO_ARCH_S390_CRYPT_S390_H |
| 18 | |
| 19 | #include <asm/errno.h> |
| 20 | |
| 21 | #define CRYPT_S390_OP_MASK 0xFF00 |
| 22 | #define CRYPT_S390_FUNC_MASK 0x00FF |
| 23 | |
Herbert Xu | 65b75c3 | 2006-08-21 21:18:50 +1000 | [diff] [blame] | 24 | #define CRYPT_S390_PRIORITY 300 |
Herbert Xu | a9e62fa | 2006-08-21 21:39:24 +1000 | [diff] [blame] | 25 | #define CRYPT_S390_COMPOSITE_PRIORITY 400 |
Herbert Xu | 65b75c3 | 2006-08-21 21:18:50 +1000 | [diff] [blame] | 26 | |
Jan Glauber | 1822bc9 | 2011-04-19 21:29:14 +0200 | [diff] [blame] | 27 | #define CRYPT_S390_MSA 0x1 |
| 28 | #define CRYPT_S390_MSA3 0x2 |
| 29 | #define CRYPT_S390_MSA4 0x4 |
| 30 | |
Ralph Wuerthner | bccdbdc | 2007-07-10 11:24:08 +0200 | [diff] [blame] | 31 | /* s390 cryptographic operations */ |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 32 | enum crypt_s390_operations { |
| 33 | CRYPT_S390_KM = 0x0100, |
| 34 | CRYPT_S390_KMC = 0x0200, |
| 35 | CRYPT_S390_KIMD = 0x0300, |
| 36 | CRYPT_S390_KLMD = 0x0400, |
| 37 | CRYPT_S390_KMAC = 0x0500 |
| 38 | }; |
| 39 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 40 | /* |
| 41 | * function codes for KM (CIPHER MESSAGE) instruction |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 42 | * 0x80 is the decipher modifier bit |
| 43 | */ |
| 44 | enum crypt_s390_km_func { |
Jan Glauber | bf754ae | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 45 | KM_QUERY = CRYPT_S390_KM | 0x0, |
| 46 | KM_DEA_ENCRYPT = CRYPT_S390_KM | 0x1, |
| 47 | KM_DEA_DECRYPT = CRYPT_S390_KM | 0x1 | 0x80, |
| 48 | KM_TDEA_128_ENCRYPT = CRYPT_S390_KM | 0x2, |
| 49 | KM_TDEA_128_DECRYPT = CRYPT_S390_KM | 0x2 | 0x80, |
| 50 | KM_TDEA_192_ENCRYPT = CRYPT_S390_KM | 0x3, |
| 51 | KM_TDEA_192_DECRYPT = CRYPT_S390_KM | 0x3 | 0x80, |
| 52 | KM_AES_128_ENCRYPT = CRYPT_S390_KM | 0x12, |
| 53 | KM_AES_128_DECRYPT = CRYPT_S390_KM | 0x12 | 0x80, |
| 54 | KM_AES_192_ENCRYPT = CRYPT_S390_KM | 0x13, |
| 55 | KM_AES_192_DECRYPT = CRYPT_S390_KM | 0x13 | 0x80, |
| 56 | KM_AES_256_ENCRYPT = CRYPT_S390_KM | 0x14, |
| 57 | KM_AES_256_DECRYPT = CRYPT_S390_KM | 0x14 | 0x80, |
Gerald Schaefer | 99d9722 | 2011-04-26 16:12:42 +1000 | [diff] [blame] | 58 | KM_XTS_128_ENCRYPT = CRYPT_S390_KM | 0x32, |
| 59 | KM_XTS_128_DECRYPT = CRYPT_S390_KM | 0x32 | 0x80, |
| 60 | KM_XTS_256_ENCRYPT = CRYPT_S390_KM | 0x34, |
| 61 | KM_XTS_256_DECRYPT = CRYPT_S390_KM | 0x34 | 0x80, |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 64 | /* |
| 65 | * function codes for KMC (CIPHER MESSAGE WITH CHAINING) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 66 | * instruction |
| 67 | */ |
| 68 | enum crypt_s390_kmc_func { |
Jan Glauber | bf754ae | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 69 | KMC_QUERY = CRYPT_S390_KMC | 0x0, |
| 70 | KMC_DEA_ENCRYPT = CRYPT_S390_KMC | 0x1, |
| 71 | KMC_DEA_DECRYPT = CRYPT_S390_KMC | 0x1 | 0x80, |
| 72 | KMC_TDEA_128_ENCRYPT = CRYPT_S390_KMC | 0x2, |
| 73 | KMC_TDEA_128_DECRYPT = CRYPT_S390_KMC | 0x2 | 0x80, |
| 74 | KMC_TDEA_192_ENCRYPT = CRYPT_S390_KMC | 0x3, |
| 75 | KMC_TDEA_192_DECRYPT = CRYPT_S390_KMC | 0x3 | 0x80, |
| 76 | KMC_AES_128_ENCRYPT = CRYPT_S390_KMC | 0x12, |
| 77 | KMC_AES_128_DECRYPT = CRYPT_S390_KMC | 0x12 | 0x80, |
| 78 | KMC_AES_192_ENCRYPT = CRYPT_S390_KMC | 0x13, |
| 79 | KMC_AES_192_DECRYPT = CRYPT_S390_KMC | 0x13 | 0x80, |
| 80 | KMC_AES_256_ENCRYPT = CRYPT_S390_KMC | 0x14, |
| 81 | KMC_AES_256_DECRYPT = CRYPT_S390_KMC | 0x14 | 0x80, |
Jan Glauber | 1b27829 | 2007-02-05 21:18:22 +0100 | [diff] [blame] | 82 | KMC_PRNG = CRYPT_S390_KMC | 0x43, |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 85 | /* |
| 86 | * function codes for KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 87 | * instruction |
| 88 | */ |
| 89 | enum crypt_s390_kimd_func { |
| 90 | KIMD_QUERY = CRYPT_S390_KIMD | 0, |
| 91 | KIMD_SHA_1 = CRYPT_S390_KIMD | 1, |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 92 | KIMD_SHA_256 = CRYPT_S390_KIMD | 2, |
Jan Glauber | 291dc7c | 2008-03-06 19:52:00 +0800 | [diff] [blame] | 93 | KIMD_SHA_512 = CRYPT_S390_KIMD | 3, |
Gerald Schaefer | df1309c | 2011-04-19 21:29:18 +0200 | [diff] [blame^] | 94 | KIMD_GHASH = CRYPT_S390_KIMD | 65, |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 97 | /* |
| 98 | * function codes for KLMD (COMPUTE LAST MESSAGE DIGEST) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 99 | * instruction |
| 100 | */ |
| 101 | enum crypt_s390_klmd_func { |
| 102 | KLMD_QUERY = CRYPT_S390_KLMD | 0, |
| 103 | KLMD_SHA_1 = CRYPT_S390_KLMD | 1, |
Jan Glauber | 0a497c17 | 2006-01-06 00:19:18 -0800 | [diff] [blame] | 104 | KLMD_SHA_256 = CRYPT_S390_KLMD | 2, |
Jan Glauber | 291dc7c | 2008-03-06 19:52:00 +0800 | [diff] [blame] | 105 | KLMD_SHA_512 = CRYPT_S390_KLMD | 3, |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 106 | }; |
| 107 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 108 | /* |
| 109 | * function codes for KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 110 | * instruction |
| 111 | */ |
| 112 | enum crypt_s390_kmac_func { |
| 113 | KMAC_QUERY = CRYPT_S390_KMAC | 0, |
| 114 | KMAC_DEA = CRYPT_S390_KMAC | 1, |
| 115 | KMAC_TDEA_128 = CRYPT_S390_KMAC | 2, |
| 116 | KMAC_TDEA_192 = CRYPT_S390_KMAC | 3 |
| 117 | }; |
| 118 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 119 | /** |
| 120 | * crypt_s390_km: |
| 121 | * @func: the function code passed to KM; see crypt_s390_km_func |
| 122 | * @param: address of parameter block; see POP for details on each func |
| 123 | * @dest: address of destination memory area |
| 124 | * @src: address of source memory area |
| 125 | * @src_len: length of src operand in bytes |
| 126 | * |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 127 | * Executes the KM (CIPHER MESSAGE) operation of the CPU. |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 128 | * |
| 129 | * Returns -1 for failure, 0 for the query func, number of processed |
| 130 | * bytes for encryption/decryption funcs |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 131 | */ |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 132 | static inline int crypt_s390_km(long func, void *param, |
| 133 | u8 *dest, const u8 *src, long src_len) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 134 | { |
| 135 | register long __func asm("0") = func & CRYPT_S390_FUNC_MASK; |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 136 | register void *__param asm("1") = param; |
| 137 | register const u8 *__src asm("2") = src; |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 138 | register long __src_len asm("3") = src_len; |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 139 | register u8 *__dest asm("4") = dest; |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 140 | int ret; |
| 141 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 142 | asm volatile( |
| 143 | "0: .insn rre,0xb92e0000,%3,%1 \n" /* KM opcode */ |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 144 | "1: brc 1,0b \n" /* handle partial completion */ |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 145 | " la %0,0\n" |
| 146 | "2:\n" |
| 147 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 148 | : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest) |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 149 | : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 150 | if (ret < 0) |
| 151 | return ret; |
| 152 | return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len; |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /** |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 156 | * crypt_s390_kmc: |
| 157 | * @func: the function code passed to KM; see crypt_s390_kmc_func |
| 158 | * @param: address of parameter block; see POP for details on each func |
| 159 | * @dest: address of destination memory area |
| 160 | * @src: address of source memory area |
| 161 | * @src_len: length of src operand in bytes |
| 162 | * |
| 163 | * Executes the KMC (CIPHER MESSAGE WITH CHAINING) operation of the CPU. |
| 164 | * |
| 165 | * Returns -1 for failure, 0 for the query func, number of processed |
| 166 | * bytes for encryption/decryption funcs |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 167 | */ |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 168 | static inline int crypt_s390_kmc(long func, void *param, |
| 169 | u8 *dest, const u8 *src, long src_len) |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 170 | { |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 171 | register long __func asm("0") = func & CRYPT_S390_FUNC_MASK; |
| 172 | register void *__param asm("1") = param; |
| 173 | register const u8 *__src asm("2") = src; |
| 174 | register long __src_len asm("3") = src_len; |
| 175 | register u8 *__dest asm("4") = dest; |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 176 | int ret; |
| 177 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 178 | asm volatile( |
| 179 | "0: .insn rre,0xb92f0000,%3,%1 \n" /* KMC opcode */ |
| 180 | "1: brc 1,0b \n" /* handle partial completion */ |
| 181 | " la %0,0\n" |
| 182 | "2:\n" |
| 183 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
| 184 | : "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest) |
| 185 | : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); |
| 186 | if (ret < 0) |
| 187 | return ret; |
| 188 | return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len; |
Jan Glauber | c1e26e1 | 2006-01-06 00:19:17 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 191 | /** |
| 192 | * crypt_s390_kimd: |
| 193 | * @func: the function code passed to KM; see crypt_s390_kimd_func |
| 194 | * @param: address of parameter block; see POP for details on each func |
| 195 | * @src: address of source memory area |
| 196 | * @src_len: length of src operand in bytes |
| 197 | * |
| 198 | * Executes the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) operation |
| 199 | * of the CPU. |
| 200 | * |
| 201 | * Returns -1 for failure, 0 for the query func, number of processed |
| 202 | * bytes for digest funcs |
| 203 | */ |
| 204 | static inline int crypt_s390_kimd(long func, void *param, |
| 205 | const u8 *src, long src_len) |
| 206 | { |
| 207 | register long __func asm("0") = func & CRYPT_S390_FUNC_MASK; |
| 208 | register void *__param asm("1") = param; |
| 209 | register const u8 *__src asm("2") = src; |
| 210 | register long __src_len asm("3") = src_len; |
| 211 | int ret; |
| 212 | |
| 213 | asm volatile( |
| 214 | "0: .insn rre,0xb93e0000,%1,%1 \n" /* KIMD opcode */ |
| 215 | "1: brc 1,0b \n" /* handle partial completion */ |
| 216 | " la %0,0\n" |
| 217 | "2:\n" |
| 218 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
| 219 | : "=d" (ret), "+a" (__src), "+d" (__src_len) |
| 220 | : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); |
| 221 | if (ret < 0) |
| 222 | return ret; |
| 223 | return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * crypt_s390_klmd: |
| 228 | * @func: the function code passed to KM; see crypt_s390_klmd_func |
| 229 | * @param: address of parameter block; see POP for details on each func |
| 230 | * @src: address of source memory area |
| 231 | * @src_len: length of src operand in bytes |
| 232 | * |
| 233 | * Executes the KLMD (COMPUTE LAST MESSAGE DIGEST) operation of the CPU. |
| 234 | * |
| 235 | * Returns -1 for failure, 0 for the query func, number of processed |
| 236 | * bytes for digest funcs |
| 237 | */ |
| 238 | static inline int crypt_s390_klmd(long func, void *param, |
| 239 | const u8 *src, long src_len) |
| 240 | { |
| 241 | register long __func asm("0") = func & CRYPT_S390_FUNC_MASK; |
| 242 | register void *__param asm("1") = param; |
| 243 | register const u8 *__src asm("2") = src; |
| 244 | register long __src_len asm("3") = src_len; |
| 245 | int ret; |
| 246 | |
| 247 | asm volatile( |
| 248 | "0: .insn rre,0xb93f0000,%1,%1 \n" /* KLMD opcode */ |
| 249 | "1: brc 1,0b \n" /* handle partial completion */ |
| 250 | " la %0,0\n" |
| 251 | "2:\n" |
| 252 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
| 253 | : "=d" (ret), "+a" (__src), "+d" (__src_len) |
| 254 | : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); |
| 255 | if (ret < 0) |
| 256 | return ret; |
| 257 | return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * crypt_s390_kmac: |
| 262 | * @func: the function code passed to KM; see crypt_s390_klmd_func |
| 263 | * @param: address of parameter block; see POP for details on each func |
| 264 | * @src: address of source memory area |
| 265 | * @src_len: length of src operand in bytes |
| 266 | * |
| 267 | * Executes the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) operation |
| 268 | * of the CPU. |
| 269 | * |
| 270 | * Returns -1 for failure, 0 for the query func, number of processed |
| 271 | * bytes for digest funcs |
| 272 | */ |
| 273 | static inline int crypt_s390_kmac(long func, void *param, |
| 274 | const u8 *src, long src_len) |
| 275 | { |
| 276 | register long __func asm("0") = func & CRYPT_S390_FUNC_MASK; |
| 277 | register void *__param asm("1") = param; |
| 278 | register const u8 *__src asm("2") = src; |
| 279 | register long __src_len asm("3") = src_len; |
| 280 | int ret; |
| 281 | |
| 282 | asm volatile( |
| 283 | "0: .insn rre,0xb91e0000,%1,%1 \n" /* KLAC opcode */ |
| 284 | "1: brc 1,0b \n" /* handle partial completion */ |
| 285 | " la %0,0\n" |
| 286 | "2:\n" |
| 287 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
| 288 | : "=d" (ret), "+a" (__src), "+d" (__src_len) |
| 289 | : "d" (__func), "a" (__param), "0" (-1) : "cc", "memory"); |
| 290 | if (ret < 0) |
| 291 | return ret; |
| 292 | return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * crypt_s390_func_available: |
| 297 | * @func: the function code of the specific function; 0 if op in general |
| 298 | * |
| 299 | * Tests if a specific crypto function is implemented on the machine. |
| 300 | * |
| 301 | * Returns 1 if func available; 0 if func or op in general not available |
| 302 | */ |
Jan Glauber | 1822bc9 | 2011-04-19 21:29:14 +0200 | [diff] [blame] | 303 | static inline int crypt_s390_func_available(int func, |
| 304 | unsigned int facility_mask) |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 305 | { |
| 306 | unsigned char status[16]; |
| 307 | int ret; |
| 308 | |
Jan Glauber | 1822bc9 | 2011-04-19 21:29:14 +0200 | [diff] [blame] | 309 | if (facility_mask & CRYPT_S390_MSA && !test_facility(17)) |
| 310 | return 0; |
| 311 | if (facility_mask & CRYPT_S390_MSA3 && !test_facility(76)) |
| 312 | return 0; |
| 313 | if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77)) |
Jan Glauber | a72f0db | 2008-07-12 15:42:11 +0800 | [diff] [blame] | 314 | return 0; |
| 315 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 316 | switch (func & CRYPT_S390_OP_MASK) { |
| 317 | case CRYPT_S390_KM: |
| 318 | ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0); |
| 319 | break; |
| 320 | case CRYPT_S390_KMC: |
| 321 | ret = crypt_s390_kmc(KMC_QUERY, &status, NULL, NULL, 0); |
| 322 | break; |
| 323 | case CRYPT_S390_KIMD: |
| 324 | ret = crypt_s390_kimd(KIMD_QUERY, &status, NULL, 0); |
| 325 | break; |
| 326 | case CRYPT_S390_KLMD: |
| 327 | ret = crypt_s390_klmd(KLMD_QUERY, &status, NULL, 0); |
| 328 | break; |
| 329 | case CRYPT_S390_KMAC: |
| 330 | ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0); |
| 331 | break; |
| 332 | default: |
| 333 | return 0; |
| 334 | } |
| 335 | if (ret < 0) |
| 336 | return 0; |
| 337 | func &= CRYPT_S390_FUNC_MASK; |
| 338 | func &= 0x7f; /* mask modifier bit */ |
| 339 | return (status[func >> 3] & (0x80 >> (func & 7))) != 0; |
| 340 | } |
| 341 | |
Gerald Schaefer | 99d9722 | 2011-04-26 16:12:42 +1000 | [diff] [blame] | 342 | /** |
| 343 | * crypt_s390_pcc: |
| 344 | * @func: the function code passed to KM; see crypt_s390_km_func |
| 345 | * @param: address of parameter block; see POP for details on each func |
| 346 | * |
| 347 | * Executes the PCC (PERFORM CRYPTOGRAPHIC COMPUTATION) operation of the CPU. |
| 348 | * |
| 349 | * Returns -1 for failure, 0 for success. |
| 350 | */ |
| 351 | static inline int crypt_s390_pcc(long func, void *param) |
| 352 | { |
| 353 | register long __func asm("0") = func & 0x7f; /* encrypt or decrypt */ |
| 354 | register void *__param asm("1") = param; |
| 355 | int ret = -1; |
| 356 | |
| 357 | asm volatile( |
| 358 | "0: .insn rre,0xb92c0000,0,0 \n" /* PCC opcode */ |
| 359 | "1: brc 1,0b \n" /* handle partial completion */ |
| 360 | " la %0,0\n" |
| 361 | "2:\n" |
| 362 | EX_TABLE(0b,2b) EX_TABLE(1b,2b) |
| 363 | : "+d" (ret) |
| 364 | : "d" (__func), "a" (__param) : "cc", "memory"); |
| 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | |
Jan Glauber | 86aa9fc | 2007-02-05 21:18:14 +0100 | [diff] [blame] | 369 | #endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */ |