2019-06-11 11:16:56 +02:00
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright IBM Corp . 2019
* Author ( s ) : Harald Freudenberger < freude @ linux . ibm . com >
* Ingo Franzki < ifranzki @ linux . ibm . com >
*
* Collection of CCA misc functions used by zcrypt and pkey
*/
# ifndef _ZCRYPT_CCAMISC_H_
# define _ZCRYPT_CCAMISC_H_
# include <asm/zcrypt.h>
# include <asm/pkey.h>
/* Key token types */
2020-09-21 10:45:55 +02:00
# define TOKTYPE_NON_CCA 0x00 /* Non-CCA key token */
# define TOKTYPE_CCA_INTERNAL 0x01 /* CCA internal sym key token */
# define TOKTYPE_CCA_INTERNAL_PKA 0x1f /* CCA internal asym key token */
2019-06-11 11:16:56 +02:00
/* For TOKTYPE_NON_CCA: */
# define TOKVER_PROTECTED_KEY 0x01 /* Protected key token */
2019-09-27 11:16:42 +02:00
# define TOKVER_CLEAR_KEY 0x02 /* Clear key token */
2019-06-11 11:16:56 +02:00
/* For TOKTYPE_CCA_INTERNAL: */
# define TOKVER_CCA_AES 0x04 /* CCA AES key token */
2019-07-03 13:16:51 +02:00
# define TOKVER_CCA_VLSC 0x05 /* var length sym cipher key token */
/* Max size of a cca variable length cipher key token */
# define MAXCCAVLSCTOKENSIZE 725
2019-06-11 11:16:56 +02:00
/* header part of a CCA key token */
struct keytoken_header {
u8 type ; /* one of the TOKTYPE values */
2019-07-03 13:16:51 +02:00
u8 res0 [ 1 ] ;
u16 len ; /* vlsc token: total length in bytes */
2019-06-11 11:16:56 +02:00
u8 version ; /* one of the TOKVER values */
u8 res1 [ 3 ] ;
} __packed ;
/* inside view of a CCA secure key token (only type 0x01 version 0x04) */
struct secaeskeytoken {
u8 type ; /* 0x01 for internal key token */
u8 res0 [ 3 ] ;
u8 version ; /* should be 0x04 */
u8 res1 [ 1 ] ;
u8 flag ; /* key flags */
u8 res2 [ 1 ] ;
u64 mkvp ; /* master key verification pattern */
u8 key [ 32 ] ; /* key value (encrypted) */
u8 cv [ 8 ] ; /* control vector */
u16 bitsize ; /* key bit size */
u16 keysize ; /* key byte size */
u8 tvv [ 4 ] ; /* token validation value */
} __packed ;
2019-07-03 13:16:51 +02:00
/* inside view of a variable length symmetric cipher AES key token */
struct cipherkeytoken {
u8 type ; /* 0x01 for internal key token */
u8 res0 [ 1 ] ;
u16 len ; /* total key token length in bytes */
u8 version ; /* should be 0x05 */
u8 res1 [ 3 ] ;
u8 kms ; /* key material state, 0x03 means wrapped with MK */
u8 kvpt ; /* key verification pattern type, should be 0x01 */
u64 mkvp0 ; /* master key verification pattern, lo part */
u64 mkvp1 ; /* master key verification pattern, hi part (unused) */
u8 eskwm ; /* encrypted section key wrapping method */
u8 hashalg ; /* hash algorithmus used for wrapping key */
u8 plfver ; /* pay load format version */
u8 res2 [ 1 ] ;
u8 adsver ; /* associated data section version */
u8 res3 [ 1 ] ;
u16 adslen ; /* associated data section length */
u8 kllen ; /* optional key label length */
u8 ieaslen ; /* optional extended associated data length */
u8 uadlen ; /* optional user definable associated data length */
u8 res4 [ 1 ] ;
u16 wpllen ; /* wrapped payload length in bits: */
/* plfver 0x00 0x01 */
/* AES-128 512 640 */
/* AES-192 576 640 */
/* AES-256 640 640 */
u8 res5 [ 1 ] ;
u8 algtype ; /* 0x02 for AES cipher */
u16 keytype ; /* 0x0001 for 'cipher' */
u8 kufc ; /* key usage field count */
u16 kuf1 ; /* key usage field 1 */
u16 kuf2 ; /* key usage field 2 */
u8 kmfc ; /* key management field count */
u16 kmf1 ; /* key management field 1 */
u16 kmf2 ; /* key management field 2 */
u16 kmf3 ; /* key management field 3 */
2020-02-21 09:06:12 -06:00
u8 vdata [ ] ; /* variable part data follows */
2019-07-03 13:16:51 +02:00
} __packed ;
2020-09-21 10:45:55 +02:00
/* inside view of an CCA secure ECC private key */
struct eccprivkeytoken {
u8 type ; /* 0x1f for internal asym key token */
u8 version ; /* should be 0x00 */
u16 len ; /* total key token length in bytes */
u8 res1 [ 4 ] ;
u8 secid ; /* 0x20 for ECC priv key section marker */
u8 secver ; /* section version */
u16 seclen ; /* section length */
u8 wtype ; /* wrapping method, 0x00 clear, 0x01 AES */
u8 htype ; /* hash method, 0x02 for SHA-256 */
u8 res2 [ 2 ] ;
u8 kutc ; /* key usage and translation control */
u8 ctype ; /* curve type */
u8 kfs ; /* key format and security */
u8 ksrc ; /* key source */
u16 pbitlen ; /* length of prime p in bits */
u16 ibmadlen ; /* IBM associated data length in bytes */
u64 mkvp ; /* master key verification pattern */
u8 opk [ 48 ] ; /* encrypted object protection key data */
u16 adatalen ; /* associated data length in bytes */
u16 fseclen ; /* formated section length in bytes */
u8 more_data [ ] ; /* more data follows */
} __packed ;
2019-07-03 13:16:51 +02:00
/* Some defines for the CCA AES cipherkeytoken kmf1 field */
# define KMF1_XPRT_SYM 0x8000
# define KMF1_XPRT_UASY 0x4000
# define KMF1_XPRT_AASY 0x2000
# define KMF1_XPRT_RAW 0x1000
# define KMF1_XPRT_CPAC 0x0800
# define KMF1_XPRT_DES 0x0080
# define KMF1_XPRT_AES 0x0040
# define KMF1_XPRT_RSA 0x0008
2019-06-11 11:16:56 +02:00
/*
* Simple check if the token is a valid CCA secure AES data key
* token . If keybitsize is given , the bitsize of the key is
* also checked . Returns 0 on success or errno value on failure .
*/
int cca_check_secaeskeytoken ( debug_info_t * dbg , int dbflvl ,
const u8 * token , int keybitsize ) ;
2019-07-03 13:16:51 +02:00
/*
* Simple check if the token is a valid CCA secure AES cipher key
* token . If keybitsize is given , the bitsize of the key is
* also checked . If checkcpacfexport is enabled , the key is also
* checked for the export flag to allow CPACF export .
* Returns 0 on success or errno value on failure .
*/
int cca_check_secaescipherkey ( debug_info_t * dbg , int dbflvl ,
const u8 * token , int keybitsize ,
int checkcpacfexport ) ;
2020-09-21 10:45:55 +02:00
/*
* Simple check if the token is a valid CCA secure ECC private
* key token . Returns 0 on success or errno value on failure .
*/
int cca_check_sececckeytoken ( debug_info_t * dbg , int dbflvl ,
const u8 * token , size_t keysize ,
int checkcpacfexport ) ;
2019-06-11 11:16:56 +02:00
/*
* Generate ( random ) CCA AES DATA secure key .
*/
s390/pkey: add CCA AES cipher key support
Introduce new ioctls and structs to be used with these new ioctls
which are able to handle CCA AES secure keys and CCA AES cipher keys:
PKEY_GENSECK2: Generate secure key, version 2.
Generate either a CCA AES secure key or a CCA AES cipher key.
PKEY_CLR2SECK2: Generate secure key from clear key value, version 2.
Construct a CCA AES secure key or CCA AES cipher key from a given
clear key value.
PKEY_VERIFYKEY2: Verify the given secure key, version 2.
Check for correct key type. If cardnr and domain are given, also
check if this apqn is able to handle this type of key. If cardnr and
domain are 0xFFFF, on return these values are filled with an apqn
able to handle this key. The function also checks for the master key
verification patterns of the key matching to the current or
alternate mkvp of the apqn. CCA AES cipher keys are also checked
for CPACF export allowed (CPRTCPAC flag). Currently CCA AES secure
keys and CCA AES cipher keys are supported (may get extended in the
future).
PKEY_KBLOB2PROTK2: Transform a key blob (of any type) into
a protected key, version 2. Difference to version 1 is only that
this new ioctl has additional parameters to provide a list of
apqns to be used for the transformation.
PKEY_APQNS4K: Generate a list of APQNs based on the key blob given.
Is able to find out which type of secure key is given (CCA AES
secure key or CCA AES cipher key) and tries to find all matching
crypto cards based on the MKVP and maybe other criterias (like CCA
AES cipher keys need a CEX6C or higher). The list of APQNs is
further filtered by the key's mkvp which needs to match to either
the current mkvp or the alternate mkvp (which is the old mkvp on CCA
adapters) of the apqns. The flags argument may be used to limit the
matching apqns. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the
current mkvp of each apqn is compared. Likewise with the
PKEY_FLAGS_MATCH_ALT_MKVP. If both are given it is assumed to return
apqns where either the current or the alternate mkvp matches. If no
matching APQN is found, the ioctl returns with 0 but the
apqn_entries value is 0.
PKEY_APQNS4KT: Generate a list of APQNs based on the key type given.
Build a list of APQNs based on the given key type and maybe further
restrict the list by given master key verification patterns.
For different key types there may be different ways to match the
master key verification patterns. For CCA keys (CCA data key and CCA
cipher key) the first 8 bytes of cur_mkvp refer to the current mkvp
value of the apqn and the first 8 bytes of the alt_mkvp refer to the
old mkvp. The flags argument controls if the apqns current and/or
alternate mkvp should match. If the PKEY_FLAGS_MATCH_CUR_MKVP is
given, only the current mkvp of each apqn is compared. Likewise with
the PKEY_FLAGS_MATCH_ALT_MKVP. If both are given, it is assumed to
return apqns where either the current or the alternate mkvp
matches. If no matching APQN is found, the ioctl returns with 0 but
the apqn_entries value is 0.
These new ioctls are now prepared for another new type of secure key
blob which may come in the future. They all use a pointer to the key
blob and a key blob length information instead of some hardcoded byte
array. They all use the new enums pkey_key_type, pkey_key_size and
pkey_key_info for getting/setting key type, key size and additional
info about the key. All but the PKEY_VERIFY2 ioctl now work based on a
list of apqns. This list is walked through trying to perform the
operation on exactly this apqn without any further checking (like card
type or online state). If the apqn fails, simple the next one in the
list is tried until success (return 0) or the end of the list is
reached (return -1 with errno ENODEV). All apqns in the list need to
be exact apqns (0xFFFF as any card or domain is not allowed). There
are two new ioctls which can be used to build a list of apqns based on
a key or key type and maybe restricted by match to a current or
alternate master key verifcation pattern.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2019-06-19 14:26:05 +02:00
int cca_genseckey ( u16 cardnr , u16 domain , u32 keybitsize , u8 * seckey ) ;
2019-06-11 11:16:56 +02:00
/*
* Generate CCA AES DATA secure key with given clear key value .
*/
s390/pkey: add CCA AES cipher key support
Introduce new ioctls and structs to be used with these new ioctls
which are able to handle CCA AES secure keys and CCA AES cipher keys:
PKEY_GENSECK2: Generate secure key, version 2.
Generate either a CCA AES secure key or a CCA AES cipher key.
PKEY_CLR2SECK2: Generate secure key from clear key value, version 2.
Construct a CCA AES secure key or CCA AES cipher key from a given
clear key value.
PKEY_VERIFYKEY2: Verify the given secure key, version 2.
Check for correct key type. If cardnr and domain are given, also
check if this apqn is able to handle this type of key. If cardnr and
domain are 0xFFFF, on return these values are filled with an apqn
able to handle this key. The function also checks for the master key
verification patterns of the key matching to the current or
alternate mkvp of the apqn. CCA AES cipher keys are also checked
for CPACF export allowed (CPRTCPAC flag). Currently CCA AES secure
keys and CCA AES cipher keys are supported (may get extended in the
future).
PKEY_KBLOB2PROTK2: Transform a key blob (of any type) into
a protected key, version 2. Difference to version 1 is only that
this new ioctl has additional parameters to provide a list of
apqns to be used for the transformation.
PKEY_APQNS4K: Generate a list of APQNs based on the key blob given.
Is able to find out which type of secure key is given (CCA AES
secure key or CCA AES cipher key) and tries to find all matching
crypto cards based on the MKVP and maybe other criterias (like CCA
AES cipher keys need a CEX6C or higher). The list of APQNs is
further filtered by the key's mkvp which needs to match to either
the current mkvp or the alternate mkvp (which is the old mkvp on CCA
adapters) of the apqns. The flags argument may be used to limit the
matching apqns. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the
current mkvp of each apqn is compared. Likewise with the
PKEY_FLAGS_MATCH_ALT_MKVP. If both are given it is assumed to return
apqns where either the current or the alternate mkvp matches. If no
matching APQN is found, the ioctl returns with 0 but the
apqn_entries value is 0.
PKEY_APQNS4KT: Generate a list of APQNs based on the key type given.
Build a list of APQNs based on the given key type and maybe further
restrict the list by given master key verification patterns.
For different key types there may be different ways to match the
master key verification patterns. For CCA keys (CCA data key and CCA
cipher key) the first 8 bytes of cur_mkvp refer to the current mkvp
value of the apqn and the first 8 bytes of the alt_mkvp refer to the
old mkvp. The flags argument controls if the apqns current and/or
alternate mkvp should match. If the PKEY_FLAGS_MATCH_CUR_MKVP is
given, only the current mkvp of each apqn is compared. Likewise with
the PKEY_FLAGS_MATCH_ALT_MKVP. If both are given, it is assumed to
return apqns where either the current or the alternate mkvp
matches. If no matching APQN is found, the ioctl returns with 0 but
the apqn_entries value is 0.
These new ioctls are now prepared for another new type of secure key
blob which may come in the future. They all use a pointer to the key
blob and a key blob length information instead of some hardcoded byte
array. They all use the new enums pkey_key_type, pkey_key_size and
pkey_key_info for getting/setting key type, key size and additional
info about the key. All but the PKEY_VERIFY2 ioctl now work based on a
list of apqns. This list is walked through trying to perform the
operation on exactly this apqn without any further checking (like card
type or online state). If the apqn fails, simple the next one in the
list is tried until success (return 0) or the end of the list is
reached (return -1 with errno ENODEV). All apqns in the list need to
be exact apqns (0xFFFF as any card or domain is not allowed). There
are two new ioctls which can be used to build a list of apqns based on
a key or key type and maybe restricted by match to a current or
alternate master key verifcation pattern.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2019-06-19 14:26:05 +02:00
int cca_clr2seckey ( u16 cardnr , u16 domain , u32 keybitsize ,
2019-06-11 11:16:56 +02:00
const u8 * clrkey , u8 * seckey ) ;
/*
* Derive proteced key from an CCA AES DATA secure key .
*/
int cca_sec2protkey ( u16 cardnr , u16 domain ,
const u8 seckey [ SECKEYBLOBSIZE ] ,
s390/pkey: add CCA AES cipher key support
Introduce new ioctls and structs to be used with these new ioctls
which are able to handle CCA AES secure keys and CCA AES cipher keys:
PKEY_GENSECK2: Generate secure key, version 2.
Generate either a CCA AES secure key or a CCA AES cipher key.
PKEY_CLR2SECK2: Generate secure key from clear key value, version 2.
Construct a CCA AES secure key or CCA AES cipher key from a given
clear key value.
PKEY_VERIFYKEY2: Verify the given secure key, version 2.
Check for correct key type. If cardnr and domain are given, also
check if this apqn is able to handle this type of key. If cardnr and
domain are 0xFFFF, on return these values are filled with an apqn
able to handle this key. The function also checks for the master key
verification patterns of the key matching to the current or
alternate mkvp of the apqn. CCA AES cipher keys are also checked
for CPACF export allowed (CPRTCPAC flag). Currently CCA AES secure
keys and CCA AES cipher keys are supported (may get extended in the
future).
PKEY_KBLOB2PROTK2: Transform a key blob (of any type) into
a protected key, version 2. Difference to version 1 is only that
this new ioctl has additional parameters to provide a list of
apqns to be used for the transformation.
PKEY_APQNS4K: Generate a list of APQNs based on the key blob given.
Is able to find out which type of secure key is given (CCA AES
secure key or CCA AES cipher key) and tries to find all matching
crypto cards based on the MKVP and maybe other criterias (like CCA
AES cipher keys need a CEX6C or higher). The list of APQNs is
further filtered by the key's mkvp which needs to match to either
the current mkvp or the alternate mkvp (which is the old mkvp on CCA
adapters) of the apqns. The flags argument may be used to limit the
matching apqns. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the
current mkvp of each apqn is compared. Likewise with the
PKEY_FLAGS_MATCH_ALT_MKVP. If both are given it is assumed to return
apqns where either the current or the alternate mkvp matches. If no
matching APQN is found, the ioctl returns with 0 but the
apqn_entries value is 0.
PKEY_APQNS4KT: Generate a list of APQNs based on the key type given.
Build a list of APQNs based on the given key type and maybe further
restrict the list by given master key verification patterns.
For different key types there may be different ways to match the
master key verification patterns. For CCA keys (CCA data key and CCA
cipher key) the first 8 bytes of cur_mkvp refer to the current mkvp
value of the apqn and the first 8 bytes of the alt_mkvp refer to the
old mkvp. The flags argument controls if the apqns current and/or
alternate mkvp should match. If the PKEY_FLAGS_MATCH_CUR_MKVP is
given, only the current mkvp of each apqn is compared. Likewise with
the PKEY_FLAGS_MATCH_ALT_MKVP. If both are given, it is assumed to
return apqns where either the current or the alternate mkvp
matches. If no matching APQN is found, the ioctl returns with 0 but
the apqn_entries value is 0.
These new ioctls are now prepared for another new type of secure key
blob which may come in the future. They all use a pointer to the key
blob and a key blob length information instead of some hardcoded byte
array. They all use the new enums pkey_key_type, pkey_key_size and
pkey_key_info for getting/setting key type, key size and additional
info about the key. All but the PKEY_VERIFY2 ioctl now work based on a
list of apqns. This list is walked through trying to perform the
operation on exactly this apqn without any further checking (like card
type or online state). If the apqn fails, simple the next one in the
list is tried until success (return 0) or the end of the list is
reached (return -1 with errno ENODEV). All apqns in the list need to
be exact apqns (0xFFFF as any card or domain is not allowed). There
are two new ioctls which can be used to build a list of apqns based on
a key or key type and maybe restricted by match to a current or
alternate master key verifcation pattern.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2019-06-19 14:26:05 +02:00
u8 * protkey , u32 * protkeylen , u32 * protkeytype ) ;
2019-06-11 11:16:56 +02:00
2019-07-03 13:16:51 +02:00
/*
* Generate ( random ) CCA AES CIPHER secure key .
*/
int cca_gencipherkey ( u16 cardnr , u16 domain , u32 keybitsize , u32 keygenflags ,
u8 * keybuf , size_t * keybufsize ) ;
/*
* Derive proteced key from CCA AES cipher secure key .
*/
int cca_cipher2protkey ( u16 cardnr , u16 domain , const u8 * ckey ,
u8 * protkey , u32 * protkeylen , u32 * protkeytype ) ;
/*
* Build CCA AES CIPHER secure key with a given clear key value .
*/
int cca_clr2cipherkey ( u16 cardnr , u16 domain , u32 keybitsize , u32 keygenflags ,
const u8 * clrkey , u8 * keybuf , size_t * keybufsize ) ;
2020-09-21 10:45:55 +02:00
/*
* Derive proteced key from CCA ECC secure private key .
*/
int cca_ecc2protkey ( u16 cardnr , u16 domain , const u8 * key ,
u8 * protkey , u32 * protkeylen , u32 * protkeytype ) ;
2019-06-11 11:16:56 +02:00
/*
* Query cryptographic facility from CCA adapter
*/
int cca_query_crypto_facility ( u16 cardnr , u16 domain ,
const char * keyword ,
u8 * rarray , size_t * rarraylen ,
u8 * varray , size_t * varraylen ) ;
/*
* Search for a matching crypto card based on the Master Key
* Verification Pattern provided inside a secure key .
s390/pkey: add CCA AES cipher key support
Introduce new ioctls and structs to be used with these new ioctls
which are able to handle CCA AES secure keys and CCA AES cipher keys:
PKEY_GENSECK2: Generate secure key, version 2.
Generate either a CCA AES secure key or a CCA AES cipher key.
PKEY_CLR2SECK2: Generate secure key from clear key value, version 2.
Construct a CCA AES secure key or CCA AES cipher key from a given
clear key value.
PKEY_VERIFYKEY2: Verify the given secure key, version 2.
Check for correct key type. If cardnr and domain are given, also
check if this apqn is able to handle this type of key. If cardnr and
domain are 0xFFFF, on return these values are filled with an apqn
able to handle this key. The function also checks for the master key
verification patterns of the key matching to the current or
alternate mkvp of the apqn. CCA AES cipher keys are also checked
for CPACF export allowed (CPRTCPAC flag). Currently CCA AES secure
keys and CCA AES cipher keys are supported (may get extended in the
future).
PKEY_KBLOB2PROTK2: Transform a key blob (of any type) into
a protected key, version 2. Difference to version 1 is only that
this new ioctl has additional parameters to provide a list of
apqns to be used for the transformation.
PKEY_APQNS4K: Generate a list of APQNs based on the key blob given.
Is able to find out which type of secure key is given (CCA AES
secure key or CCA AES cipher key) and tries to find all matching
crypto cards based on the MKVP and maybe other criterias (like CCA
AES cipher keys need a CEX6C or higher). The list of APQNs is
further filtered by the key's mkvp which needs to match to either
the current mkvp or the alternate mkvp (which is the old mkvp on CCA
adapters) of the apqns. The flags argument may be used to limit the
matching apqns. If the PKEY_FLAGS_MATCH_CUR_MKVP is given, only the
current mkvp of each apqn is compared. Likewise with the
PKEY_FLAGS_MATCH_ALT_MKVP. If both are given it is assumed to return
apqns where either the current or the alternate mkvp matches. If no
matching APQN is found, the ioctl returns with 0 but the
apqn_entries value is 0.
PKEY_APQNS4KT: Generate a list of APQNs based on the key type given.
Build a list of APQNs based on the given key type and maybe further
restrict the list by given master key verification patterns.
For different key types there may be different ways to match the
master key verification patterns. For CCA keys (CCA data key and CCA
cipher key) the first 8 bytes of cur_mkvp refer to the current mkvp
value of the apqn and the first 8 bytes of the alt_mkvp refer to the
old mkvp. The flags argument controls if the apqns current and/or
alternate mkvp should match. If the PKEY_FLAGS_MATCH_CUR_MKVP is
given, only the current mkvp of each apqn is compared. Likewise with
the PKEY_FLAGS_MATCH_ALT_MKVP. If both are given, it is assumed to
return apqns where either the current or the alternate mkvp
matches. If no matching APQN is found, the ioctl returns with 0 but
the apqn_entries value is 0.
These new ioctls are now prepared for another new type of secure key
blob which may come in the future. They all use a pointer to the key
blob and a key blob length information instead of some hardcoded byte
array. They all use the new enums pkey_key_type, pkey_key_size and
pkey_key_info for getting/setting key type, key size and additional
info about the key. All but the PKEY_VERIFY2 ioctl now work based on a
list of apqns. This list is walked through trying to perform the
operation on exactly this apqn without any further checking (like card
type or online state). If the apqn fails, simple the next one in the
list is tried until success (return 0) or the end of the list is
reached (return -1 with errno ENODEV). All apqns in the list need to
be exact apqns (0xFFFF as any card or domain is not allowed). There
are two new ioctls which can be used to build a list of apqns based on
a key or key type and maybe restricted by match to a current or
alternate master key verifcation pattern.
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2019-06-19 14:26:05 +02:00
* Works with CCA AES data and cipher keys .
2019-06-11 11:16:56 +02:00
* Returns < 0 on failure , 0 if CURRENT MKVP matches and
* 1 if OLD MKVP matches .
*/
2019-06-18 15:53:12 +02:00
int cca_findcard ( const u8 * key , u16 * pcardnr , u16 * pdomain , int verify ) ;
2019-06-11 11:16:56 +02:00
2019-07-03 13:16:51 +02:00
/*
* Build a list of cca apqns meeting the following constrains :
* - apqn is online and is in fact a CCA apqn
* - if cardnr is not FFFF only apqns with this cardnr
* - if domain is not FFFF only apqns with this domainnr
* - if minhwtype > 0 only apqns with hwtype > = minhwtype
* - if cur_mkvp ! = 0 only apqns where cur_mkvp = = mkvp
* - if old_mkvp ! = 0 only apqns where old_mkvp = = mkvp
* - if verify is enabled and a cur_mkvp and / or old_mkvp
* value is given , then refetch the cca_info and make sure the current
* cur_mkvp or old_mkvp values of the apqn are used .
2020-09-04 16:11:37 +02:00
* The mktype determines which set of master keys to use :
* 0 = AES_MK_SET - AES MK set , 1 = APKA MK_SET - APKA MK set
2019-07-03 13:16:51 +02:00
* The array of apqn entries is allocated with kmalloc and returned in * apqns ;
* the number of apqns stored into the list is returned in * nr_apqns . One apqn
* entry is simple a 32 bit value with 16 bit cardnr and 16 bit domain nr and
* may be casted to struct pkey_apqn . The return value is either 0 for success
* or a negative errno value . If no apqn meeting the criterias is found ,
* - ENODEV is returned .
*/
int cca_findcard2 ( u32 * * apqns , u32 * nr_apqns , u16 cardnr , u16 domain ,
2020-09-04 16:11:37 +02:00
int minhwtype , int mktype , u64 cur_mkvp , u64 old_mkvp ,
int verify ) ;
# define AES_MK_SET 0
# define APKA_MK_SET 1
2019-07-03 13:16:51 +02:00
2019-06-12 15:05:34 +02:00
/* struct to hold info for each CCA queue */
struct cca_info {
2020-09-04 16:11:37 +02:00
int hwtype ; /* one of the defined AP_DEVICE_TYPE_* */
char new_aes_mk_state ; /* '1' empty, '2' partially full, '3' full */
char cur_aes_mk_state ; /* '1' invalid, '2' valid */
char old_aes_mk_state ; /* '1' invalid, '2' valid */
char new_apka_mk_state ; /* '1' empty, '2' partially full, '3' full */
char cur_apka_mk_state ; /* '1' invalid, '2' valid */
char old_apka_mk_state ; /* '1' invalid, '2' valid */
u64 new_aes_mkvp ; /* truncated sha256 of new aes master key */
u64 cur_aes_mkvp ; /* truncated sha256 of current aes master key */
u64 old_aes_mkvp ; /* truncated sha256 of old aes master key */
u64 new_apka_mkvp ; /* truncated sha256 of new apka master key */
u64 cur_apka_mkvp ; /* truncated sha256 of current apka mk */
u64 old_apka_mkvp ; /* truncated sha256 of old apka mk */
char serial [ 9 ] ; /* serial number (8 ascii numbers + 0x00) */
2019-06-12 15:05:34 +02:00
} ;
/*
* Fetch cca information about an CCA queue .
*/
int cca_get_info ( u16 card , u16 dom , struct cca_info * ci , int verify ) ;
2019-06-11 11:16:56 +02:00
void zcrypt_ccamisc_exit ( void ) ;
# endif /* _ZCRYPT_CCAMISC_H_ */