xref: /OK3568_Linux_fs/kernel/arch/s390/include/uapi/asm/pkey.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Userspace interface to the pkey device driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright IBM Corp. 2017, 2019
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Harald Freudenberger <freude@de.ibm.com>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef _UAPI_PKEY_H
12*4882a593Smuzhiyun #define _UAPI_PKEY_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/ioctl.h>
15*4882a593Smuzhiyun #include <linux/types.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun  * Ioctl calls supported by the pkey device driver
19*4882a593Smuzhiyun  */
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define PKEY_IOCTL_MAGIC 'p'
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define SECKEYBLOBSIZE	64	   /* secure key blob size is always 64 bytes */
24*4882a593Smuzhiyun #define PROTKEYBLOBSIZE 80	/* protected key blob size is always 80 bytes */
25*4882a593Smuzhiyun #define MAXPROTKEYSIZE	64	/* a protected key blob may be up to 64 bytes */
26*4882a593Smuzhiyun #define MAXCLRKEYSIZE	32	   /* a clear key value may be up to 32 bytes */
27*4882a593Smuzhiyun #define MAXAESCIPHERKEYSIZE 136  /* our aes cipher keys have always 136 bytes */
28*4882a593Smuzhiyun #define MINEP11AESKEYBLOBSIZE 256  /* min EP11 AES key blob size  */
29*4882a593Smuzhiyun #define MAXEP11AESKEYBLOBSIZE 320  /* max EP11 AES key blob size */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* Minimum size of a key blob */
32*4882a593Smuzhiyun #define MINKEYBLOBSIZE	SECKEYBLOBSIZE
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* defines for the type field within the pkey_protkey struct */
35*4882a593Smuzhiyun #define PKEY_KEYTYPE_AES_128		      1
36*4882a593Smuzhiyun #define PKEY_KEYTYPE_AES_192		      2
37*4882a593Smuzhiyun #define PKEY_KEYTYPE_AES_256		      3
38*4882a593Smuzhiyun #define PKEY_KEYTYPE_ECC		      4
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* the newer ioctls use a pkey_key_type enum for type information */
41*4882a593Smuzhiyun enum pkey_key_type {
42*4882a593Smuzhiyun 	PKEY_TYPE_CCA_DATA   = (__u32) 1,
43*4882a593Smuzhiyun 	PKEY_TYPE_CCA_CIPHER = (__u32) 2,
44*4882a593Smuzhiyun 	PKEY_TYPE_EP11	     = (__u32) 3,
45*4882a593Smuzhiyun 	PKEY_TYPE_CCA_ECC    = (__u32) 0x1f,
46*4882a593Smuzhiyun 	PKEY_TYPE_EP11_AES   = (__u32) 6,
47*4882a593Smuzhiyun 	PKEY_TYPE_EP11_ECC   = (__u32) 7,
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun /* the newer ioctls use a pkey_key_size enum for key size information */
51*4882a593Smuzhiyun enum pkey_key_size {
52*4882a593Smuzhiyun 	PKEY_SIZE_AES_128 = (__u32) 128,
53*4882a593Smuzhiyun 	PKEY_SIZE_AES_192 = (__u32) 192,
54*4882a593Smuzhiyun 	PKEY_SIZE_AES_256 = (__u32) 256,
55*4882a593Smuzhiyun 	PKEY_SIZE_UNKNOWN = (__u32) 0xFFFFFFFF,
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* some of the newer ioctls use these flags */
59*4882a593Smuzhiyun #define PKEY_FLAGS_MATCH_CUR_MKVP  0x00000002
60*4882a593Smuzhiyun #define PKEY_FLAGS_MATCH_ALT_MKVP  0x00000004
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /* keygenflags defines for CCA AES cipher keys */
63*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_SYM  0x00008000
64*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_UASY 0x00004000
65*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_AASY 0x00002000
66*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_RAW  0x00001000
67*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_CPAC 0x00000800
68*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_DES  0x00000080
69*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_AES  0x00000040
70*4882a593Smuzhiyun #define PKEY_KEYGEN_XPRT_RSA  0x00000008
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /* Struct to hold apqn target info (card/domain pair) */
73*4882a593Smuzhiyun struct pkey_apqn {
74*4882a593Smuzhiyun 	__u16 card;
75*4882a593Smuzhiyun 	__u16 domain;
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /* Struct to hold a CCA AES secure key blob */
79*4882a593Smuzhiyun struct pkey_seckey {
80*4882a593Smuzhiyun 	__u8  seckey[SECKEYBLOBSIZE];		  /* the secure key blob */
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /* Struct to hold protected key and length info */
84*4882a593Smuzhiyun struct pkey_protkey {
85*4882a593Smuzhiyun 	__u32 type;	 /* key type, one of the PKEY_KEYTYPE_AES values */
86*4882a593Smuzhiyun 	__u32 len;		/* bytes actually stored in protkey[]	 */
87*4882a593Smuzhiyun 	__u8  protkey[MAXPROTKEYSIZE];	       /* the protected key blob */
88*4882a593Smuzhiyun };
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* Struct to hold an AES clear key value */
91*4882a593Smuzhiyun struct pkey_clrkey {
92*4882a593Smuzhiyun 	__u8  clrkey[MAXCLRKEYSIZE]; /* 16, 24, or 32 byte clear key value */
93*4882a593Smuzhiyun };
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /*
96*4882a593Smuzhiyun  * EP11 key blobs of type PKEY_TYPE_EP11_AES and PKEY_TYPE_EP11_ECC
97*4882a593Smuzhiyun  * are ep11 blobs prepended by this header:
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun struct ep11kblob_header {
100*4882a593Smuzhiyun 	__u8  type;	/* always 0x00 */
101*4882a593Smuzhiyun 	__u8  hver;	/* header version,  currently needs to be 0x00 */
102*4882a593Smuzhiyun 	__u16 len;	/* total length in bytes (including this header) */
103*4882a593Smuzhiyun 	__u8  version;	/* PKEY_TYPE_EP11_AES or PKEY_TYPE_EP11_ECC */
104*4882a593Smuzhiyun 	__u8  res0;	/* unused */
105*4882a593Smuzhiyun 	__u16 bitlen;	/* clear key bit len, 0 for unknown */
106*4882a593Smuzhiyun 	__u8  res1[8];	/* unused */
107*4882a593Smuzhiyun } __packed;
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /*
110*4882a593Smuzhiyun  * Generate CCA AES secure key.
111*4882a593Smuzhiyun  */
112*4882a593Smuzhiyun struct pkey_genseck {
113*4882a593Smuzhiyun 	__u16 cardnr;		    /* in: card to use or FFFF for any	 */
114*4882a593Smuzhiyun 	__u16 domain;		    /* in: domain or FFFF for any	 */
115*4882a593Smuzhiyun 	__u32 keytype;		    /* in: key type to generate		 */
116*4882a593Smuzhiyun 	struct pkey_seckey seckey;  /* out: the secure key blob		 */
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun #define PKEY_GENSECK _IOWR(PKEY_IOCTL_MAGIC, 0x01, struct pkey_genseck)
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /*
121*4882a593Smuzhiyun  * Construct CCA AES secure key from clear key value
122*4882a593Smuzhiyun  */
123*4882a593Smuzhiyun struct pkey_clr2seck {
124*4882a593Smuzhiyun 	__u16 cardnr;		    /* in: card to use or FFFF for any	 */
125*4882a593Smuzhiyun 	__u16 domain;		    /* in: domain or FFFF for any	 */
126*4882a593Smuzhiyun 	__u32 keytype;		    /* in: key type to generate		 */
127*4882a593Smuzhiyun 	struct pkey_clrkey clrkey;  /* in: the clear key value		 */
128*4882a593Smuzhiyun 	struct pkey_seckey seckey;  /* out: the secure key blob		 */
129*4882a593Smuzhiyun };
130*4882a593Smuzhiyun #define PKEY_CLR2SECK _IOWR(PKEY_IOCTL_MAGIC, 0x02, struct pkey_clr2seck)
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun /*
133*4882a593Smuzhiyun  * Fabricate AES protected key from a CCA AES secure key
134*4882a593Smuzhiyun  */
135*4882a593Smuzhiyun struct pkey_sec2protk {
136*4882a593Smuzhiyun 	__u16 cardnr;		     /* in: card to use or FFFF for any   */
137*4882a593Smuzhiyun 	__u16 domain;		     /* in: domain or FFFF for any	  */
138*4882a593Smuzhiyun 	struct pkey_seckey seckey;   /* in: the secure key blob		  */
139*4882a593Smuzhiyun 	struct pkey_protkey protkey; /* out: the protected key		  */
140*4882a593Smuzhiyun };
141*4882a593Smuzhiyun #define PKEY_SEC2PROTK _IOWR(PKEY_IOCTL_MAGIC, 0x03, struct pkey_sec2protk)
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun /*
144*4882a593Smuzhiyun  * Fabricate AES protected key from clear key value
145*4882a593Smuzhiyun  */
146*4882a593Smuzhiyun struct pkey_clr2protk {
147*4882a593Smuzhiyun 	__u32 keytype;		     /* in: key type to generate	  */
148*4882a593Smuzhiyun 	struct pkey_clrkey clrkey;   /* in: the clear key value		  */
149*4882a593Smuzhiyun 	struct pkey_protkey protkey; /* out: the protected key		  */
150*4882a593Smuzhiyun };
151*4882a593Smuzhiyun #define PKEY_CLR2PROTK _IOWR(PKEY_IOCTL_MAGIC, 0x04, struct pkey_clr2protk)
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /*
154*4882a593Smuzhiyun  * Search for matching crypto card based on the Master Key
155*4882a593Smuzhiyun  * Verification Pattern provided inside a CCA AES secure key.
156*4882a593Smuzhiyun  */
157*4882a593Smuzhiyun struct pkey_findcard {
158*4882a593Smuzhiyun 	struct pkey_seckey seckey;	       /* in: the secure key blob */
159*4882a593Smuzhiyun 	__u16  cardnr;			       /* out: card number	  */
160*4882a593Smuzhiyun 	__u16  domain;			       /* out: domain number	  */
161*4882a593Smuzhiyun };
162*4882a593Smuzhiyun #define PKEY_FINDCARD _IOWR(PKEY_IOCTL_MAGIC, 0x05, struct pkey_findcard)
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun /*
165*4882a593Smuzhiyun  * Combined together: findcard + sec2prot
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun struct pkey_skey2pkey {
168*4882a593Smuzhiyun 	struct pkey_seckey seckey;   /* in: the secure key blob		  */
169*4882a593Smuzhiyun 	struct pkey_protkey protkey; /* out: the protected key		  */
170*4882a593Smuzhiyun };
171*4882a593Smuzhiyun #define PKEY_SKEY2PKEY _IOWR(PKEY_IOCTL_MAGIC, 0x06, struct pkey_skey2pkey)
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun /*
174*4882a593Smuzhiyun  * Verify the given CCA AES secure key for being able to be useable with
175*4882a593Smuzhiyun  * the pkey module. Check for correct key type and check for having at
176*4882a593Smuzhiyun  * least one crypto card being able to handle this key (master key
177*4882a593Smuzhiyun  * or old master key verification pattern matches).
178*4882a593Smuzhiyun  * Return some info about the key: keysize in bits, keytype (currently
179*4882a593Smuzhiyun  * only AES), flag if key is wrapped with an old MKVP.
180*4882a593Smuzhiyun  */
181*4882a593Smuzhiyun struct pkey_verifykey {
182*4882a593Smuzhiyun 	struct pkey_seckey seckey;	       /* in: the secure key blob */
183*4882a593Smuzhiyun 	__u16  cardnr;			       /* out: card number	  */
184*4882a593Smuzhiyun 	__u16  domain;			       /* out: domain number	  */
185*4882a593Smuzhiyun 	__u16  keysize;			       /* out: key size in bits   */
186*4882a593Smuzhiyun 	__u32  attributes;		       /* out: attribute bits	  */
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun #define PKEY_VERIFYKEY _IOWR(PKEY_IOCTL_MAGIC, 0x07, struct pkey_verifykey)
189*4882a593Smuzhiyun #define PKEY_VERIFY_ATTR_AES	   0x00000001  /* key is an AES key */
190*4882a593Smuzhiyun #define PKEY_VERIFY_ATTR_OLD_MKVP  0x00000100  /* key has old MKVP value */
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /*
193*4882a593Smuzhiyun  * Generate AES random protected key.
194*4882a593Smuzhiyun  */
195*4882a593Smuzhiyun struct pkey_genprotk {
196*4882a593Smuzhiyun 	__u32 keytype;			       /* in: key type to generate */
197*4882a593Smuzhiyun 	struct pkey_protkey protkey;	       /* out: the protected key   */
198*4882a593Smuzhiyun };
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun #define PKEY_GENPROTK _IOWR(PKEY_IOCTL_MAGIC, 0x08, struct pkey_genprotk)
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun /*
203*4882a593Smuzhiyun  * Verify an AES protected key.
204*4882a593Smuzhiyun  */
205*4882a593Smuzhiyun struct pkey_verifyprotk {
206*4882a593Smuzhiyun 	struct pkey_protkey protkey;	/* in: the protected key to verify */
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun #define PKEY_VERIFYPROTK _IOW(PKEY_IOCTL_MAGIC, 0x09, struct pkey_verifyprotk)
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun /*
212*4882a593Smuzhiyun  * Transform an key blob (of any type) into a protected key
213*4882a593Smuzhiyun  */
214*4882a593Smuzhiyun struct pkey_kblob2pkey {
215*4882a593Smuzhiyun 	__u8 __user *key;		/* in: the key blob	   */
216*4882a593Smuzhiyun 	__u32 keylen;			/* in: the key blob length */
217*4882a593Smuzhiyun 	struct pkey_protkey protkey;	/* out: the protected key  */
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun #define PKEY_KBLOB2PROTK _IOWR(PKEY_IOCTL_MAGIC, 0x0A, struct pkey_kblob2pkey)
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun  * Generate secure key, version 2.
223*4882a593Smuzhiyun  * Generate CCA AES secure key, CCA AES cipher key or EP11 AES secure key.
224*4882a593Smuzhiyun  * There needs to be a list of apqns given with at least one entry in there.
225*4882a593Smuzhiyun  * All apqns in the list need to be exact apqns, 0xFFFF as ANY card or domain
226*4882a593Smuzhiyun  * is not supported. The implementation walks through the list of apqns and
227*4882a593Smuzhiyun  * tries to send the request to each apqn without any further checking (like
228*4882a593Smuzhiyun  * card type or online state). If the apqn fails, simple the next one in the
229*4882a593Smuzhiyun  * list is tried until success (return 0) or the end of the list is reached
230*4882a593Smuzhiyun  * (return -1 with errno ENODEV). You may use the PKEY_APQNS4KT ioctl to
231*4882a593Smuzhiyun  * generate a list of apqns based on the key type to generate.
232*4882a593Smuzhiyun  * The keygenflags argument is passed to the low level generation functions
233*4882a593Smuzhiyun  * individual for the key type and has a key type specific meaning. When
234*4882a593Smuzhiyun  * generating CCA cipher keys you can use one or more of the PKEY_KEYGEN_*
235*4882a593Smuzhiyun  * flags to widen the export possibilities. By default a cipher key is
236*4882a593Smuzhiyun  * only exportable for CPACF (PKEY_KEYGEN_XPRT_CPAC).
237*4882a593Smuzhiyun  * The keygenflag argument for generating an EP11 AES key should either be 0
238*4882a593Smuzhiyun  * to use the defaults which are XCP_BLOB_ENCRYPT, XCP_BLOB_DECRYPT and
239*4882a593Smuzhiyun  * XCP_BLOB_PROTKEY_EXTRACTABLE or a valid combination of XCP_BLOB_* flags.
240*4882a593Smuzhiyun  */
241*4882a593Smuzhiyun struct pkey_genseck2 {
242*4882a593Smuzhiyun 	struct pkey_apqn __user *apqns; /* in: ptr to list of apqn targets*/
243*4882a593Smuzhiyun 	__u32 apqn_entries;	    /* in: # of apqn target list entries  */
244*4882a593Smuzhiyun 	enum pkey_key_type type;    /* in: key type to generate		  */
245*4882a593Smuzhiyun 	enum pkey_key_size size;    /* in: key size to generate		  */
246*4882a593Smuzhiyun 	__u32 keygenflags;	    /* in: key generation flags		  */
247*4882a593Smuzhiyun 	__u8 __user *key;	    /* in: pointer to key blob buffer	  */
248*4882a593Smuzhiyun 	__u32 keylen;		    /* in: available key blob buffer size */
249*4882a593Smuzhiyun 				    /* out: actual key blob size	  */
250*4882a593Smuzhiyun };
251*4882a593Smuzhiyun #define PKEY_GENSECK2 _IOWR(PKEY_IOCTL_MAGIC, 0x11, struct pkey_genseck2)
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun /*
254*4882a593Smuzhiyun  * Generate secure key from clear key value, version 2.
255*4882a593Smuzhiyun  * Construct an CCA AES secure key, CCA AES cipher key or EP11 AES secure
256*4882a593Smuzhiyun  * key from a given clear key value.
257*4882a593Smuzhiyun  * There needs to be a list of apqns given with at least one entry in there.
258*4882a593Smuzhiyun  * All apqns in the list need to be exact apqns, 0xFFFF as ANY card or domain
259*4882a593Smuzhiyun  * is not supported. The implementation walks through the list of apqns and
260*4882a593Smuzhiyun  * tries to send the request to each apqn without any further checking (like
261*4882a593Smuzhiyun  * card type or online state). If the apqn fails, simple the next one in the
262*4882a593Smuzhiyun  * list is tried until success (return 0) or the end of the list is reached
263*4882a593Smuzhiyun  * (return -1 with errno ENODEV). You may use the PKEY_APQNS4KT ioctl to
264*4882a593Smuzhiyun  * generate a list of apqns based on the key type to generate.
265*4882a593Smuzhiyun  * The keygenflags argument is passed to the low level generation functions
266*4882a593Smuzhiyun  * individual for the key type and has a key type specific meaning. When
267*4882a593Smuzhiyun  * generating CCA cipher keys you can use one or more of the PKEY_KEYGEN_*
268*4882a593Smuzhiyun  * flags to widen the export possibilities. By default a cipher key is
269*4882a593Smuzhiyun  * only exportable for CPACF (PKEY_KEYGEN_XPRT_CPAC).
270*4882a593Smuzhiyun  * The keygenflag argument for generating an EP11 AES key should either be 0
271*4882a593Smuzhiyun  * to use the defaults which are XCP_BLOB_ENCRYPT, XCP_BLOB_DECRYPT and
272*4882a593Smuzhiyun  * XCP_BLOB_PROTKEY_EXTRACTABLE or a valid combination of XCP_BLOB_* flags.
273*4882a593Smuzhiyun  */
274*4882a593Smuzhiyun struct pkey_clr2seck2 {
275*4882a593Smuzhiyun 	struct pkey_apqn __user *apqns; /* in: ptr to list of apqn targets */
276*4882a593Smuzhiyun 	__u32 apqn_entries;	    /* in: # of apqn target list entries   */
277*4882a593Smuzhiyun 	enum pkey_key_type type;    /* in: key type to generate		   */
278*4882a593Smuzhiyun 	enum pkey_key_size size;    /* in: key size to generate		   */
279*4882a593Smuzhiyun 	__u32 keygenflags;	    /* in: key generation flags		   */
280*4882a593Smuzhiyun 	struct pkey_clrkey clrkey;  /* in: the clear key value		   */
281*4882a593Smuzhiyun 	__u8 __user *key;	    /* in: pointer to key blob buffer	   */
282*4882a593Smuzhiyun 	__u32 keylen;		    /* in: available key blob buffer size  */
283*4882a593Smuzhiyun 				    /* out: actual key blob size	   */
284*4882a593Smuzhiyun };
285*4882a593Smuzhiyun #define PKEY_CLR2SECK2 _IOWR(PKEY_IOCTL_MAGIC, 0x12, struct pkey_clr2seck2)
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun /*
288*4882a593Smuzhiyun  * Verify the given secure key, version 2.
289*4882a593Smuzhiyun  * Check for correct key type. If cardnr and domain are given (are not
290*4882a593Smuzhiyun  * 0xFFFF) also check if this apqn is able to handle this type of key.
291*4882a593Smuzhiyun  * If cardnr and/or domain is 0xFFFF, on return these values are filled
292*4882a593Smuzhiyun  * with one apqn able to handle this key.
293*4882a593Smuzhiyun  * The function also checks for the master key verification patterns
294*4882a593Smuzhiyun  * of the key matching to the current or alternate mkvp of the apqn.
295*4882a593Smuzhiyun  * For CCA AES secure keys and CCA AES cipher keys this means to check
296*4882a593Smuzhiyun  * the key's mkvp against the current or old mkvp of the apqns. The flags
297*4882a593Smuzhiyun  * field is updated with some additional info about the apqn mkvp
298*4882a593Smuzhiyun  * match: If the current mkvp matches to the key's mkvp then the
299*4882a593Smuzhiyun  * PKEY_FLAGS_MATCH_CUR_MKVP bit is set, if the alternate mkvp matches to
300*4882a593Smuzhiyun  * the key's mkvp the PKEY_FLAGS_MATCH_ALT_MKVP is set. For CCA keys the
301*4882a593Smuzhiyun  * alternate mkvp is the old master key verification pattern.
302*4882a593Smuzhiyun  * CCA AES secure keys are also checked to have the CPACF export allowed
303*4882a593Smuzhiyun  * bit enabled (XPRTCPAC) in the kmf1 field.
304*4882a593Smuzhiyun  * EP11 keys are also supported and the wkvp of the key is checked against
305*4882a593Smuzhiyun  * the current wkvp of the apqns. There is no alternate for this type of
306*4882a593Smuzhiyun  * key and so on a match the flag PKEY_FLAGS_MATCH_CUR_MKVP always is set.
307*4882a593Smuzhiyun  * EP11 keys are also checked to have XCP_BLOB_PROTKEY_EXTRACTABLE set.
308*4882a593Smuzhiyun  * The ioctl returns 0 as long as the given or found apqn matches to
309*4882a593Smuzhiyun  * matches with the current or alternate mkvp to the key's mkvp. If the given
310*4882a593Smuzhiyun  * apqn does not match or there is no such apqn found, -1 with errno
311*4882a593Smuzhiyun  * ENODEV is returned.
312*4882a593Smuzhiyun  */
313*4882a593Smuzhiyun struct pkey_verifykey2 {
314*4882a593Smuzhiyun 	__u8 __user *key;	    /* in: pointer to key blob		 */
315*4882a593Smuzhiyun 	__u32 keylen;		    /* in: key blob size		 */
316*4882a593Smuzhiyun 	__u16 cardnr;		    /* in/out: card number		 */
317*4882a593Smuzhiyun 	__u16 domain;		    /* in/out: domain number		 */
318*4882a593Smuzhiyun 	enum pkey_key_type type;    /* out: the key type		 */
319*4882a593Smuzhiyun 	enum pkey_key_size size;    /* out: the key size		 */
320*4882a593Smuzhiyun 	__u32 flags;		    /* out: additional key info flags	 */
321*4882a593Smuzhiyun };
322*4882a593Smuzhiyun #define PKEY_VERIFYKEY2 _IOWR(PKEY_IOCTL_MAGIC, 0x17, struct pkey_verifykey2)
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun /*
325*4882a593Smuzhiyun  * Transform a key blob into a protected key, version 2.
326*4882a593Smuzhiyun  * There needs to be a list of apqns given with at least one entry in there.
327*4882a593Smuzhiyun  * All apqns in the list need to be exact apqns, 0xFFFF as ANY card or domain
328*4882a593Smuzhiyun  * is not supported. The implementation walks through the list of apqns and
329*4882a593Smuzhiyun  * tries to send the request to each apqn without any further checking (like
330*4882a593Smuzhiyun  * card type or online state). If the apqn fails, simple the next one in the
331*4882a593Smuzhiyun  * list is tried until success (return 0) or the end of the list is reached
332*4882a593Smuzhiyun  * (return -1 with errno ENODEV). You may use the PKEY_APQNS4K ioctl to
333*4882a593Smuzhiyun  * generate a list of apqns based on the key.
334*4882a593Smuzhiyun  * Deriving ECC protected keys from ECC secure keys is not supported with
335*4882a593Smuzhiyun  * this ioctl, use PKEY_KBLOB2PROTK3 for this purpose.
336*4882a593Smuzhiyun  */
337*4882a593Smuzhiyun struct pkey_kblob2pkey2 {
338*4882a593Smuzhiyun 	__u8 __user *key;	     /* in: pointer to key blob		   */
339*4882a593Smuzhiyun 	__u32 keylen;		     /* in: key blob size		   */
340*4882a593Smuzhiyun 	struct pkey_apqn __user *apqns; /* in: ptr to list of apqn targets */
341*4882a593Smuzhiyun 	__u32 apqn_entries;	     /* in: # of apqn target list entries  */
342*4882a593Smuzhiyun 	struct pkey_protkey protkey; /* out: the protected key		   */
343*4882a593Smuzhiyun };
344*4882a593Smuzhiyun #define PKEY_KBLOB2PROTK2 _IOWR(PKEY_IOCTL_MAGIC, 0x1A, struct pkey_kblob2pkey2)
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /*
347*4882a593Smuzhiyun  * Build a list of APQNs based on a key blob given.
348*4882a593Smuzhiyun  * Is able to find out which type of secure key is given (CCA AES secure
349*4882a593Smuzhiyun  * key, CCA AES cipher key, CCA ECC private key, EP11 AES key, EP11 ECC private
350*4882a593Smuzhiyun  * key) and tries to find all matching crypto cards based on the MKVP and maybe
351*4882a593Smuzhiyun  * other criterias (like CCA AES cipher keys need a CEX5C or higher, EP11 keys
352*4882a593Smuzhiyun  * with BLOB_PKEY_EXTRACTABLE need a CEX7 and EP11 api version 4). The list of
353*4882a593Smuzhiyun  * APQNs is further filtered by the key's mkvp which needs to match to either
354*4882a593Smuzhiyun  * the current mkvp (CCA and EP11) or the alternate mkvp (old mkvp, CCA adapters
355*4882a593Smuzhiyun  * only) of the apqns. The flags argument may be used to limit the matching
356*4882a593Smuzhiyun  * apqns. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the current mkvp of
357*4882a593Smuzhiyun  * each apqn is compared. Likewise with the PKEY_FLAGS_MATCH_ALT_MKVP. If both
358*4882a593Smuzhiyun  * are given, it is assumed to return apqns where either the current or the
359*4882a593Smuzhiyun  * alternate mkvp matches. At least one of the matching flags needs to be given.
360*4882a593Smuzhiyun  * The flags argument for EP11 keys has no further action and is currently
361*4882a593Smuzhiyun  * ignored (but needs to be given as PKEY_FLAGS_MATCH_CUR_MKVP) as there is only
362*4882a593Smuzhiyun  * the wkvp from the key to match against the apqn's wkvp.
363*4882a593Smuzhiyun  * The list of matching apqns is stored into the space given by the apqns
364*4882a593Smuzhiyun  * argument and the number of stored entries goes into apqn_entries. If the list
365*4882a593Smuzhiyun  * is empty (apqn_entries is 0) the apqn_entries field is updated to the number
366*4882a593Smuzhiyun  * of apqn targets found and the ioctl returns with 0. If apqn_entries is > 0
367*4882a593Smuzhiyun  * but the number of apqn targets does not fit into the list, the apqn_targets
368*4882a593Smuzhiyun  * field is updatedd with the number of reqired entries but there are no apqn
369*4882a593Smuzhiyun  * values stored in the list and the ioctl returns with ENOSPC. If no matching
370*4882a593Smuzhiyun  * APQN is found, the ioctl returns with 0 but the apqn_entries value is 0.
371*4882a593Smuzhiyun  */
372*4882a593Smuzhiyun struct pkey_apqns4key {
373*4882a593Smuzhiyun 	__u8 __user *key;	   /* in: pointer to key blob		      */
374*4882a593Smuzhiyun 	__u32 keylen;		   /* in: key blob size			      */
375*4882a593Smuzhiyun 	__u32 flags;		   /* in: match controlling flags	      */
376*4882a593Smuzhiyun 	struct pkey_apqn __user *apqns; /* in/out: ptr to list of apqn targets*/
377*4882a593Smuzhiyun 	__u32 apqn_entries;	   /* in: max # of apqn entries in the list   */
378*4882a593Smuzhiyun 				   /* out: # apqns stored into the list	      */
379*4882a593Smuzhiyun };
380*4882a593Smuzhiyun #define PKEY_APQNS4K _IOWR(PKEY_IOCTL_MAGIC, 0x1B, struct pkey_apqns4key)
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun /*
383*4882a593Smuzhiyun  * Build a list of APQNs based on a key type given.
384*4882a593Smuzhiyun  * Build a list of APQNs based on a given key type and maybe further
385*4882a593Smuzhiyun  * restrict the list by given master key verification patterns.
386*4882a593Smuzhiyun  * For different key types there may be different ways to match the
387*4882a593Smuzhiyun  * master key verification patterns. For CCA keys (CCA data key and CCA
388*4882a593Smuzhiyun  * cipher key) the first 8 bytes of cur_mkvp refer to the current AES mkvp value
389*4882a593Smuzhiyun  * of the apqn and the first 8 bytes of the alt_mkvp refer to the old AES mkvp.
390*4882a593Smuzhiyun  * For CCA ECC keys it is similar but the match is against the APKA current/old
391*4882a593Smuzhiyun  * mkvp. The flags argument controls if the apqns current and/or alternate mkvp
392*4882a593Smuzhiyun  * should match. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the current
393*4882a593Smuzhiyun  * mkvp of each apqn is compared. Likewise with the PKEY_FLAGS_MATCH_ALT_MKVP.
394*4882a593Smuzhiyun  * If both are given, it is assumed to return apqns where either the
395*4882a593Smuzhiyun  * current or the alternate mkvp matches. If no match flag is given
396*4882a593Smuzhiyun  * (flags is 0) the mkvp values are ignored for the match process.
397*4882a593Smuzhiyun  * For EP11 keys there is only the current wkvp. So if the apqns should also
398*4882a593Smuzhiyun  * match to a given wkvp, then the PKEY_FLAGS_MATCH_CUR_MKVP flag should be
399*4882a593Smuzhiyun  * set. The wkvp value is 32 bytes but only the leftmost 16 bytes are compared
400*4882a593Smuzhiyun  * against the leftmost 16 byte of the wkvp of the apqn.
401*4882a593Smuzhiyun  * The list of matching apqns is stored into the space given by the apqns
402*4882a593Smuzhiyun  * argument and the number of stored entries goes into apqn_entries. If the list
403*4882a593Smuzhiyun  * is empty (apqn_entries is 0) the apqn_entries field is updated to the number
404*4882a593Smuzhiyun  * of apqn targets found and the ioctl returns with 0. If apqn_entries is > 0
405*4882a593Smuzhiyun  * but the number of apqn targets does not fit into the list, the apqn_targets
406*4882a593Smuzhiyun  * field is updatedd with the number of reqired entries but there are no apqn
407*4882a593Smuzhiyun  * values stored in the list and the ioctl returns with ENOSPC. If no matching
408*4882a593Smuzhiyun  * APQN is found, the ioctl returns with 0 but the apqn_entries value is 0.
409*4882a593Smuzhiyun  */
410*4882a593Smuzhiyun struct pkey_apqns4keytype {
411*4882a593Smuzhiyun 	enum pkey_key_type type;   /* in: key type			      */
412*4882a593Smuzhiyun 	__u8  cur_mkvp[32];	   /* in: current mkvp			      */
413*4882a593Smuzhiyun 	__u8  alt_mkvp[32];	   /* in: alternate mkvp		      */
414*4882a593Smuzhiyun 	__u32 flags;		   /* in: match controlling flags	      */
415*4882a593Smuzhiyun 	struct pkey_apqn __user *apqns; /* in/out: ptr to list of apqn targets*/
416*4882a593Smuzhiyun 	__u32 apqn_entries;	   /* in: max # of apqn entries in the list   */
417*4882a593Smuzhiyun 				   /* out: # apqns stored into the list	      */
418*4882a593Smuzhiyun };
419*4882a593Smuzhiyun #define PKEY_APQNS4KT _IOWR(PKEY_IOCTL_MAGIC, 0x1C, struct pkey_apqns4keytype)
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun /*
422*4882a593Smuzhiyun  * Transform a key blob into a protected key, version 3.
423*4882a593Smuzhiyun  * The difference to version 2 of this ioctl is that the protected key
424*4882a593Smuzhiyun  * buffer is now explicitly and not within a struct pkey_protkey any more.
425*4882a593Smuzhiyun  * So this ioctl is also able to handle EP11 and CCA ECC secure keys and
426*4882a593Smuzhiyun  * provide ECC protected keys.
427*4882a593Smuzhiyun  * There needs to be a list of apqns given with at least one entry in there.
428*4882a593Smuzhiyun  * All apqns in the list need to be exact apqns, 0xFFFF as ANY card or domain
429*4882a593Smuzhiyun  * is not supported. The implementation walks through the list of apqns and
430*4882a593Smuzhiyun  * tries to send the request to each apqn without any further checking (like
431*4882a593Smuzhiyun  * card type or online state). If the apqn fails, simple the next one in the
432*4882a593Smuzhiyun  * list is tried until success (return 0) or the end of the list is reached
433*4882a593Smuzhiyun  * (return -1 with errno ENODEV). You may use the PKEY_APQNS4K ioctl to
434*4882a593Smuzhiyun  * generate a list of apqns based on the key.
435*4882a593Smuzhiyun  */
436*4882a593Smuzhiyun struct pkey_kblob2pkey3 {
437*4882a593Smuzhiyun 	__u8 __user *key;	     /* in: pointer to key blob		   */
438*4882a593Smuzhiyun 	__u32 keylen;		     /* in: key blob size		   */
439*4882a593Smuzhiyun 	struct pkey_apqn __user *apqns; /* in: ptr to list of apqn targets */
440*4882a593Smuzhiyun 	__u32 apqn_entries;	     /* in: # of apqn target list entries  */
441*4882a593Smuzhiyun 	__u32 pkeytype;		/* out: prot key type (enum pkey_key_type) */
442*4882a593Smuzhiyun 	__u32 pkeylen;	 /* in/out: size of pkey buffer/actual len of pkey */
443*4882a593Smuzhiyun 	__u8 __user *pkey;		 /* in: pkey blob buffer space ptr */
444*4882a593Smuzhiyun };
445*4882a593Smuzhiyun #define PKEY_KBLOB2PROTK3 _IOWR(PKEY_IOCTL_MAGIC, 0x1D, struct pkey_kblob2pkey3)
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun #endif /* _UAPI_PKEY_H */
448