]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/s390/include/asm/cpacf.h
2 * CP Assist for Cryptographic Functions (CPACF)
4 * Copyright IBM Corp. 2003, 2016
5 * Author(s): Thomas Spatzier
7 * Harald Freudenberger (freude@de.ibm.com)
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
10 #ifndef _ASM_S390_CPACF_H
11 #define _ASM_S390_CPACF_H
13 #include <asm/facility.h>
16 * Instruction opcodes for the CPACF instructions
18 #define CPACF_KMAC 0xb91e /* MSA */
19 #define CPACF_KM 0xb92e /* MSA */
20 #define CPACF_KMC 0xb92f /* MSA */
21 #define CPACF_KIMD 0xb93e /* MSA */
22 #define CPACF_KLMD 0xb93f /* MSA */
23 #define CPACF_PCKMO 0xb928 /* MSA3 */
24 #define CPACF_KMF 0xb92a /* MSA4 */
25 #define CPACF_KMO 0xb92b /* MSA4 */
26 #define CPACF_PCC 0xb92c /* MSA4 */
27 #define CPACF_KMCTR 0xb92d /* MSA4 */
28 #define CPACF_PPNO 0xb93c /* MSA5 */
31 * Function codes for the KM (CIPHER MESSAGE)
32 * instruction (0x80 is the decipher modifier bit)
34 #define CPACF_KM_QUERY 0x00
35 #define CPACF_KM_DEA_ENC 0x01
36 #define CPACF_KM_DEA_DEC 0x81
37 #define CPACF_KM_TDEA_128_ENC 0x02
38 #define CPACF_KM_TDEA_128_DEC 0x82
39 #define CPACF_KM_TDEA_192_ENC 0x03
40 #define CPACF_KM_TDEA_192_DEC 0x83
41 #define CPACF_KM_AES_128_ENC 0x12
42 #define CPACF_KM_AES_128_DEC 0x92
43 #define CPACF_KM_AES_192_ENC 0x13
44 #define CPACF_KM_AES_192_DEC 0x93
45 #define CPACF_KM_AES_256_ENC 0x14
46 #define CPACF_KM_AES_256_DEC 0x94
47 #define CPACF_KM_XTS_128_ENC 0x32
48 #define CPACF_KM_XTS_128_DEC 0xb2
49 #define CPACF_KM_XTS_256_ENC 0x34
50 #define CPACF_KM_XTS_256_DEC 0xb4
53 * Function codes for the KMC (CIPHER MESSAGE WITH CHAINING)
54 * instruction (0x80 is the decipher modifier bit)
56 #define CPACF_KMC_QUERY 0x00
57 #define CPACF_KMC_DEA_ENC 0x01
58 #define CPACF_KMC_DEA_DEC 0x81
59 #define CPACF_KMC_TDEA_128_ENC 0x02
60 #define CPACF_KMC_TDEA_128_DEC 0x82
61 #define CPACF_KMC_TDEA_192_ENC 0x03
62 #define CPACF_KMC_TDEA_192_DEC 0x83
63 #define CPACF_KMC_AES_128_ENC 0x12
64 #define CPACF_KMC_AES_128_DEC 0x92
65 #define CPACF_KMC_AES_192_ENC 0x13
66 #define CPACF_KMC_AES_192_DEC 0x93
67 #define CPACF_KMC_AES_256_ENC 0x14
68 #define CPACF_KMC_AES_256_DEC 0x94
69 #define CPACF_KMC_PRNG 0x43
72 * Function codes for the KMCTR (CIPHER MESSAGE WITH COUNTER)
73 * instruction (0x80 is the decipher modifier bit)
75 #define CPACF_KMCTR_QUERY 0x00
76 #define CPACF_KMCTR_DEA_ENC 0x01
77 #define CPACF_KMCTR_DEA_DEC 0x81
78 #define CPACF_KMCTR_TDEA_128_ENC 0x02
79 #define CPACF_KMCTR_TDEA_128_DEC 0x82
80 #define CPACF_KMCTR_TDEA_192_ENC 0x03
81 #define CPACF_KMCTR_TDEA_192_DEC 0x83
82 #define CPACF_KMCTR_AES_128_ENC 0x12
83 #define CPACF_KMCTR_AES_128_DEC 0x92
84 #define CPACF_KMCTR_AES_192_ENC 0x13
85 #define CPACF_KMCTR_AES_192_DEC 0x93
86 #define CPACF_KMCTR_AES_256_ENC 0x14
87 #define CPACF_KMCTR_AES_256_DEC 0x94
90 * Function codes for the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST)
91 * instruction (0x80 is the decipher modifier bit)
93 #define CPACF_KIMD_QUERY 0x00
94 #define CPACF_KIMD_SHA_1 0x01
95 #define CPACF_KIMD_SHA_256 0x02
96 #define CPACF_KIMD_SHA_512 0x03
97 #define CPACF_KIMD_GHASH 0x41
100 * Function codes for the KLMD (COMPUTE LAST MESSAGE DIGEST)
101 * instruction (0x80 is the decipher modifier bit)
103 #define CPACF_KLMD_QUERY 0x00
104 #define CPACF_KLMD_SHA_1 0x01
105 #define CPACF_KLMD_SHA_256 0x02
106 #define CPACF_KLMD_SHA_512 0x03
109 * function codes for the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE)
110 * instruction (0x80 is the decipher modifier bit)
112 #define CPACF_KMAC_QUERY 0x00
113 #define CPACF_KMAC_DEA 0x01
114 #define CPACF_KMAC_TDEA_128 0x02
115 #define CPACF_KMAC_TDEA_192 0x03
118 * Function codes for the PPNO (PERFORM PSEUDORANDOM NUMBER OPERATION)
119 * instruction (0x80 is the decipher modifier bit)
121 #define CPACF_PPNO_QUERY 0x00
122 #define CPACF_PPNO_SHA512_DRNG_GEN 0x03
123 #define CPACF_PPNO_SHA512_DRNG_SEED 0x83
126 * cpacf_query() - check if a specific CPACF function is available
127 * @opcode: the opcode of the crypto instruction
128 * @func: the function code to test for
130 * Executes the query function for the given crypto instruction @opcode
131 * and checks if @func is available
133 * Returns 1 if @func is available for @opcode, 0 otherwise
135 static inline void __cpacf_query(unsigned int opcode
, unsigned char *status
)
137 typedef struct { unsigned char _
[16]; } status_type
;
138 register unsigned long r0
asm("0") = 0; /* query function */
139 register unsigned long r1
asm("1") = (unsigned long) status
;
142 " spm 0\n" /* pckmo doesn't change the cc */
143 /* Parameter registers are ignored, but may not be 0 */
144 "0: .insn rrf,%[opc] << 16,2,2,2,0\n"
145 " brc 1,0b\n" /* handle partial completion */
146 : "=m" (*(status_type
*) status
)
147 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (opcode
)
151 static inline int cpacf_query(unsigned int opcode
, unsigned int func
)
153 unsigned char status
[16];
161 if (!test_facility(17)) /* check for MSA */
165 if (!test_facility(76)) /* check for MSA3 */
172 if (!test_facility(77)) /* check for MSA4 */
176 if (!test_facility(57)) /* check for MSA5 */
182 __cpacf_query(opcode
, status
);
183 return (status
[func
>> 3] & (0x80 >> (func
& 7))) != 0;
187 * cpacf_km() - executes the KM (CIPHER MESSAGE) instruction
188 * @func: the function code passed to KM; see CPACF_KM_xxx defines
189 * @param: address of parameter block; see POP for details on each func
190 * @dest: address of destination memory area
191 * @src: address of source memory area
192 * @src_len: length of src operand in bytes
194 * Returns 0 for the query func, number of processed bytes for
195 * encryption/decryption funcs
197 static inline int cpacf_km(long func
, void *param
,
198 u8
*dest
, const u8
*src
, long src_len
)
200 register unsigned long r0
asm("0") = (unsigned long) func
;
201 register unsigned long r1
asm("1") = (unsigned long) param
;
202 register unsigned long r2
asm("2") = (unsigned long) src
;
203 register unsigned long r3
asm("3") = (unsigned long) src_len
;
204 register unsigned long r4
asm("4") = (unsigned long) dest
;
207 "0: .insn rre,%[opc] << 16,%[dst],%[src]\n"
208 " brc 1,0b\n" /* handle partial completion */
209 : [src
] "+a" (r2
), [len
] "+d" (r3
), [dst
] "+a" (r4
)
210 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_KM
)
217 * cpacf_kmc() - executes the KMC (CIPHER MESSAGE WITH CHAINING) instruction
218 * @func: the function code passed to KM; see CPACF_KMC_xxx defines
219 * @param: address of parameter block; see POP for details on each func
220 * @dest: address of destination memory area
221 * @src: address of source memory area
222 * @src_len: length of src operand in bytes
224 * Returns 0 for the query func, number of processed bytes for
225 * encryption/decryption funcs
227 static inline int cpacf_kmc(long func
, void *param
,
228 u8
*dest
, const u8
*src
, long src_len
)
230 register unsigned long r0
asm("0") = (unsigned long) func
;
231 register unsigned long r1
asm("1") = (unsigned long) param
;
232 register unsigned long r2
asm("2") = (unsigned long) src
;
233 register unsigned long r3
asm("3") = (unsigned long) src_len
;
234 register unsigned long r4
asm("4") = (unsigned long) dest
;
237 "0: .insn rre,%[opc] << 16,%[dst],%[src]\n"
238 " brc 1,0b\n" /* handle partial completion */
239 : [src
] "+a" (r2
), [len
] "+d" (r3
), [dst
] "+a" (r4
)
240 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_KMC
)
247 * cpacf_kimd() - executes the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST)
249 * @func: the function code passed to KM; see CPACF_KIMD_xxx defines
250 * @param: address of parameter block; see POP for details on each func
251 * @src: address of source memory area
252 * @src_len: length of src operand in bytes
254 * Returns 0 for the query func, number of processed bytes for digest funcs
256 static inline int cpacf_kimd(long func
, void *param
,
257 const u8
*src
, long src_len
)
259 register unsigned long r0
asm("0") = (unsigned long) func
;
260 register unsigned long r1
asm("1") = (unsigned long) param
;
261 register unsigned long r2
asm("2") = (unsigned long) src
;
262 register unsigned long r3
asm("3") = (unsigned long) src_len
;
265 "0: .insn rre,%[opc] << 16,0,%[src]\n"
266 " brc 1,0b\n" /* handle partial completion */
267 : [src
] "+a" (r2
), [len
] "+d" (r3
)
268 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_KIMD
)
275 * cpacf_klmd() - executes the KLMD (COMPUTE LAST MESSAGE DIGEST) instruction
276 * @func: the function code passed to KM; see CPACF_KLMD_xxx defines
277 * @param: address of parameter block; see POP for details on each func
278 * @src: address of source memory area
279 * @src_len: length of src operand in bytes
281 * Returns 0 for the query func, number of processed bytes for digest funcs
283 static inline int cpacf_klmd(long func
, void *param
,
284 const u8
*src
, long src_len
)
286 register unsigned long r0
asm("0") = (unsigned long) func
;
287 register unsigned long r1
asm("1") = (unsigned long) param
;
288 register unsigned long r2
asm("2") = (unsigned long) src
;
289 register unsigned long r3
asm("3") = (unsigned long) src_len
;
292 "0: .insn rre,%[opc] << 16,0,%[src]\n"
293 " brc 1,0b\n" /* handle partial completion */
294 : [src
] "+a" (r2
), [len
] "+d" (r3
)
295 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_KLMD
)
302 * cpacf_kmac() - executes the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE)
304 * @func: the function code passed to KM; see CPACF_KMAC_xxx defines
305 * @param: address of parameter block; see POP for details on each func
306 * @src: address of source memory area
307 * @src_len: length of src operand in bytes
309 * Returns 0 for the query func, number of processed bytes for digest funcs
311 static inline int cpacf_kmac(long func
, void *param
,
312 const u8
*src
, long src_len
)
314 register unsigned long r0
asm("0") = (unsigned long) func
;
315 register unsigned long r1
asm("1") = (unsigned long) param
;
316 register unsigned long r2
asm("2") = (unsigned long) src
;
317 register unsigned long r3
asm("3") = (unsigned long) src_len
;
320 "0: .insn rre,%[opc] << 16,0,%[src]\n"
321 " brc 1,0b\n" /* handle partial completion */
322 : [src
] "+a" (r2
), [len
] "+d" (r3
)
323 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_KMAC
)
330 * cpacf_kmctr() - executes the KMCTR (CIPHER MESSAGE WITH COUNTER) instruction
331 * @func: the function code passed to KMCTR; see CPACF_KMCTR_xxx defines
332 * @param: address of parameter block; see POP for details on each func
333 * @dest: address of destination memory area
334 * @src: address of source memory area
335 * @src_len: length of src operand in bytes
336 * @counter: address of counter value
338 * Returns 0 for the query func, number of processed bytes for
339 * encryption/decryption funcs
341 static inline int cpacf_kmctr(long func
, void *param
, u8
*dest
,
342 const u8
*src
, long src_len
, u8
*counter
)
344 register unsigned long r0
asm("0") = (unsigned long) func
;
345 register unsigned long r1
asm("1") = (unsigned long) param
;
346 register unsigned long r2
asm("2") = (unsigned long) src
;
347 register unsigned long r3
asm("3") = (unsigned long) src_len
;
348 register unsigned long r4
asm("4") = (unsigned long) dest
;
349 register unsigned long r6
asm("6") = (unsigned long) counter
;
352 "0: .insn rrf,%[opc] << 16,%[dst],%[src],%[ctr],0\n"
353 " brc 1,0b\n" /* handle partial completion */
354 : [src
] "+a" (r2
), [len
] "+d" (r3
),
355 [dst
] "+a" (r4
), [ctr
] "+a" (r6
)
356 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_KMCTR
)
363 * cpacf_ppno() - executes the PPNO (PERFORM PSEUDORANDOM NUMBER OPERATION)
365 * @func: the function code passed to PPNO; see CPACF_PPNO_xxx defines
366 * @param: address of parameter block; see POP for details on each func
367 * @dest: address of destination memory area
368 * @dest_len: size of destination memory area in bytes
369 * @seed: address of seed data
370 * @seed_len: size of seed data in bytes
372 * Returns 0 for the query func, number of random bytes stored in
373 * dest buffer for generate function
375 static inline int cpacf_ppno(long func
, void *param
,
376 u8
*dest
, long dest_len
,
377 const u8
*seed
, long seed_len
)
379 register unsigned long r0
asm("0") = (unsigned long) func
;
380 register unsigned long r1
asm("1") = (unsigned long) param
;
381 register unsigned long r2
asm("2") = (unsigned long) dest
;
382 register unsigned long r3
asm("3") = (unsigned long) dest_len
;
383 register unsigned long r4
asm("4") = (unsigned long) seed
;
384 register unsigned long r5
asm("5") = (unsigned long) seed_len
;
387 "0: .insn rre,%[opc] << 16,%[dst],%[seed]\n"
388 " brc 1,0b\n" /* handle partial completion */
389 : [dst
] "+a" (r2
), [dlen
] "+d" (r3
)
390 : [fc
] "d" (r0
), [pba
] "a" (r1
),
391 [seed
] "a" (r4
), [slen
] "d" (r5
), [opc
] "i" (CPACF_PPNO
)
394 return dest_len
- r3
;
398 * cpacf_pcc() - executes the PCC (PERFORM CRYPTOGRAPHIC COMPUTATION)
400 * @func: the function code passed to PCC; see CPACF_KM_xxx defines
401 * @param: address of parameter block; see POP for details on each func
405 static inline int cpacf_pcc(long func
, void *param
)
407 register unsigned long r0
asm("0") = (unsigned long) func
;
408 register unsigned long r1
asm("1") = (unsigned long) param
;
411 "0: .insn rre,%[opc] << 16,0,0\n" /* PCC opcode */
412 " brc 1,0b\n" /* handle partial completion */
414 : [fc
] "d" (r0
), [pba
] "a" (r1
), [opc
] "i" (CPACF_PCC
)
420 #endif /* _ASM_S390_CPACF_H */