/* SPDX-License-Identifier: GPL-2.0-only */

#ifndef _TME_HWKM_MASTER_DEFS_H_
#define _TME_HWKM_MASTER_DEFS_H_

#include <linux/types.h>

#define UINT32_C(x)  (x ## U)




#define TME_KID_CHIP_UNIQUE_SEED 8

#define TME_KID_CHIP_RAND_BASE   9

#define TME_KID_CHIP_FAM_L1      10


#define TME_KID_TP               11



struct tme_key_policy {
	uint32_t low;
	uint32_t high;
} __packed;

#define TME_KPHALFBITS                32

#define TME_KPCOMBINE(lo32, hi32) (((uint64_t)(lo32)) | \
		(((uint64_t)(hi32)) << TME_KPHALFBITS))





#define TME_KT_Shift          0

#define TME_KT_Mask           (UINT32_C(0x07) << TME_KT_Shift)

#define TME_KT_Symmetric      (UINT32_C(0x00) << TME_KT_Shift)

#define TME_KT_Asymmetric_ECC (UINT32_C(0x01) << TME_KT_Shift)

#define TME_KT_Asymmetric_RSA (UINT32_C(0x05) << TME_KT_Shift)



#define TME_KL_Shift 3

#define TME_KL_Mask  (UINT32_C(0x0F) << TME_KL_Shift)

#define TME_KL_64    (UINT32_C(0x00) << TME_KL_Shift)

#define TME_KL_128   (UINT32_C(0x01) << TME_KL_Shift)

#define TME_KL_192   (UINT32_C(0x02) << TME_KL_Shift)

#define TME_KL_224   (UINT32_C(0x03) << TME_KL_Shift)

#define TME_KL_256   (UINT32_C(0x04) << TME_KL_Shift)

#define TME_KL_384   (UINT32_C(0x05) << TME_KL_Shift)

#define TME_KL_448   (UINT32_C(0x06) << TME_KL_Shift)

#define TME_KL_512   (UINT32_C(0x07) << TME_KL_Shift)

#define TME_KL_521   (UINT32_C(0x08) << TME_KL_Shift)

#define TME_KL_2048  (UINT32_C(0x09) << TME_KL_Shift)

#define TME_KL_3072  (UINT32_C(0x0A) << TME_KL_Shift)

#define TME_KL_4096  (UINT32_C(0x0B) << TME_KL_Shift)



#define TME_KP_Shift         7

#define TME_KP_Mask          (UINT32_C(0x07) << TME_KP_Shift)

#define TME_KP_Generic       (UINT32_C(0x00) << TME_KP_Shift)

#define TME_KP_KeyDerivation (UINT32_C(0x01) << TME_KP_Shift)

#define TME_KP_KWK_STORAGE   (UINT32_C(0x02) << TME_KP_Shift)

#define TME_KP_KWK_SESSION   (UINT32_C(0x03) << TME_KP_Shift)

#define TME_KP_KWK_TRANSPORT (UINT32_C(0x04) << TME_KP_Shift)

#define TME_KP_KWK_XPORT     (UINT32_C(0x05) << TME_KP_Shift)

#define TME_KP_Unused        (UINT32_C(0x00) << TME_KP_Shift)



#define TME_KOP_Shift             10

#define TME_KOP_Mask              (UINT32_C(0x0F) << TME_KOP_Shift)

#define TME_KOP_Encryption        (UINT32_C(0x01) << TME_KOP_Shift)

#define TME_KOP_Decryption        (UINT32_C(0x02) << TME_KOP_Shift)

#define TME_KOP_MAC               (UINT32_C(0x04) << TME_KOP_Shift)

#define TME_KOP_NISTDerive        (UINT32_C(0x04) << TME_KOP_Shift)

#define TME_KOP_HKDFExtract       (UINT32_C(0x08) << TME_KOP_Shift)

#define TME_KOP_HKDFExpand        (UINT32_C(0x09) << TME_KOP_Shift)

#define TME_KOP_ECDSASign         (UINT32_C(0x01) << TME_KOP_Shift)

#define TME_KOP_ECDSAVerify       (UINT32_C(0x02) << TME_KOP_Shift)

#define TME_KOP_ECDHSharedSecret  (UINT32_C(0x04) << TME_KOP_Shift)

#define TME_KOP_RSAASign          (UINT32_C(0x01) << TME_KOP_Shift)

#define TME_KOP_RSAAVerify        (UINT32_C(0x02) << TME_KOP_Shift)

#define TME_KOP_RSAEnc            (UINT32_C(0x04) << TME_KOP_Shift)

#define TME_KOP_RSADec            (UINT32_C(0x08) << TME_KOP_Shift)



#define TME_KAL_Shift             14

#define TME_KAL_Mask              (UINT32_C(0x3F) << TME_KAL_Shift)

#define TME_KAL_AES128_ECB        (UINT32_C(0x00) << TME_KAL_Shift)
#define TME_KAL_AES256_ECB        (UINT32_C(0x01) << TME_KAL_Shift)
#define TME_KAL_DES_ECB           (UINT32_C(0x02) << TME_KAL_Shift)
#define TME_KAL_TDES_ECB          (UINT32_C(0x03) << TME_KAL_Shift)
#define TME_KAL_AES128_CBC        (UINT32_C(0x04) << TME_KAL_Shift)
#define TME_KAL_AES256_CBC        (UINT32_C(0x05) << TME_KAL_Shift)
#define TME_KAL_DES_CBC           (UINT32_C(0x06) << TME_KAL_Shift)
#define TME_KAL_TDES_CBC          (UINT32_C(0x07) << TME_KAL_Shift)
#define TME_KAL_AES128_CCM_TC     (UINT32_C(0x08) << TME_KAL_Shift)
#define TME_KAL_AES128_CCM_NTC    (UINT32_C(0x09) << TME_KAL_Shift)
#define TME_KAL_AES256_CCM_TC     (UINT32_C(0x0A) << TME_KAL_Shift)
#define TME_KAL_AES256_CCM_NTC    (UINT32_C(0x0B) << TME_KAL_Shift)
#define TME_KAL_AES256_SIV        (UINT32_C(0x0C) << TME_KAL_Shift)
#define TME_KAL_AES128_CTR        (UINT32_C(0x0D) << TME_KAL_Shift)
#define TME_KAL_AES256_CTR        (UINT32_C(0x0E) << TME_KAL_Shift)
#define TME_KAL_AES128_XTS        (UINT32_C(0x0F) << TME_KAL_Shift)
#define TME_KAL_AES256_XTS        (UINT32_C(0x10) << TME_KAL_Shift)
#define TME_KAL_SHA1_HMAC         (UINT32_C(0x11) << TME_KAL_Shift)
#define TME_KAL_SHA256_HMAC       (UINT32_C(0x12) << TME_KAL_Shift)
#define TME_KAL_AES128_CMAC       (UINT32_C(0x13) << TME_KAL_Shift)
#define TME_KAL_AES256_CMAC       (UINT32_C(0x14) << TME_KAL_Shift)
#define TME_KAL_SHA384_HMAC       (UINT32_C(0x15) << TME_KAL_Shift)
#define TME_KAL_SHA512_HMAC       (UINT32_C(0x16) << TME_KAL_Shift)
#define TME_KAL_AES128_GCM        (UINT32_C(0x17) << TME_KAL_Shift)
#define TME_KAL_AES256_GCM        (UINT32_C(0x18) << TME_KAL_Shift)
#define TME_KAL_KASUMI            (UINT32_C(0x19) << TME_KAL_Shift)
#define TME_KAL_SNOW3G            (UINT32_C(0x1A) << TME_KAL_Shift)
#define TME_KAL_ZUC               (UINT32_C(0x1B) << TME_KAL_Shift)
#define TME_KAL_PRINCE            (UINT32_C(0x1C) << TME_KAL_Shift)
#define TME_KAL_SIPHASH           (UINT32_C(0x1D) << TME_KAL_Shift)
#define TME_KAL_TDES_2KEY_CBC     (UINT32_C(0x1E) << TME_KAL_Shift)
#define TME_KAL_TDES_2KEY_ECB     (UINT32_C(0x1F) << TME_KAL_Shift)
#define TME_KAL_KDF_NIST          (UINT32_C(0x20) << TME_KAL_Shift)
#define TME_KAL_KDF_HKDF          (UINT32_C(0x21) << TME_KAL_Shift)

#define TME_KAL_ECC_ALGO_ECDSA    (UINT32_C(0x00) << TME_KAL_Shift)

#define TME_KAL_ECC_ALGO_ECDH     (UINT32_C(0x01) << TME_KAL_Shift)

#define TME_KAL_ECC_CURVE_NIST    (UINT32_C(0x00) << TME_KAL_Shift)

#define TME_KAL_ECC_CURVE_BPOOL   (UINT32_C(0x08) << TME_KAL_Shift)

#define TME_KAL_DSA               (UINT32_C(0x00) << TME_KAL_Shift)

#define TME_KAL_DH                (UINT32_C(0x01) << TME_KAL_Shift)



#define TME_KSL_Shift             20

#define TME_KSL_Mask              (UINT32_C(0x03) << TME_KSL_Shift)

#define TME_KSL_SWKey             (UINT32_C(0x00) << TME_KSL_Shift)

#define TME_KSL_HWManagedKey      (UINT32_C(0x01) << TME_KSL_Shift)

#define TME_KSL_HWKey             (UINT32_C(0x02) << TME_KSL_Shift)



#define TME_KD_Shift              22

#define TME_KD_Mask               (UINT32_C(0x0F) << TME_KD_Shift)

#define TME_KD_TME_HW             (UINT32_C(0x01) << TME_KD_Shift)

#define TME_KD_ICE                (UINT32_C(0x02) << TME_KD_Shift)

#define TME_KD_GPCE               (UINT32_C(0x04) << TME_KD_Shift)

#define TME_KD_MDM_CE             (UINT32_C(0x08) << TME_KD_Shift)



#define TME_KO_Shift              26

#define TME_KO_Mask               (UINT32_C(0x0F) << TME_KO_Shift)

#define TME_KO_TME_HW             (UINT32_C(0x00) << TME_KO_Shift)

#define TME_KO_TME_FW             (UINT32_C(0x01) << TME_KO_Shift)

#define TME_KO_TZ                 (UINT32_C(0x02) << TME_KO_Shift)

#define TME_KO_HLOS_HYP           (UINT32_C(0x03) << TME_KO_Shift)

#define TME_KO_MDM                (UINT32_C(0x04) << TME_KO_Shift)

#define TME_KO_SPU                (UINT32_C(0x0F) << TME_KO_Shift)



#define TME_KLI_Shift             30

#define TME_KLI_Mask              (UINT32_C(0x03) << TME_KLI_Shift)

#define TME_KLI_NA                (UINT32_C(0x00) << TME_KLI_Shift)

#define TME_KLI_NP_CU             (UINT32_C(0x01) << TME_KLI_Shift)

#define TME_KLI_P_NCU             (UINT32_C(0x02) << TME_KLI_Shift)

#define TME_KLI_P_CU              (UINT32_C(0x03) << TME_KLI_Shift)





#define TME_KR1_Shift             (32 - TME_KPHALFBITS)

#define TME_KR1_Mask              (UINT32_C(0x01) << TME_KR1_Shift)



#define TME_KWC_Shift             (33 - TME_KPHALFBITS)

#define TME_KWC_Mask              (UINT32_C(0x0F) << TME_KWC_Shift)

#define TME_KWC_Wrappable_KXP     (UINT32_C(0x01) << TME_KWC_Shift)

#define TME_KWC_Wrappable_KWK     (UINT32_C(0x02) << TME_KWC_Shift)

#define TME_KWC_Wrappable_KTP     (UINT32_C(0x04) << TME_KWC_Shift)

#define TME_KWC_Wrappable_KSK     (UINT32_C(0x08) << TME_KWC_Shift)



#define TME_KTH_Shift             (37 - TME_KPHALFBITS)

#define TME_KTH_Mask              (UINT32_C(0x01) << TME_KTH_Shift)

#define TME_KTH_Enabled           (UINT32_C(0x01) << TME_KTH_Shift)



#define TME_KR2_Shift             (38 - TME_KPHALFBITS)

#define TME_KR2_Mask              (UINT32_C(0x3F) << TME_KR2_Shift)



#define TME_KPV_Shift             (44 - TME_KPHALFBITS)

#define TME_KPV_Mask              (UINT32_C(0x0F) << TME_KPV_Shift)

#define TME_KPV_Version           (UINT32_C(0x03) << TME_KPV_Shift)



#define TME_KAU_Shift             (48 - TME_KPHALFBITS)

#define TME_KAU_Mask              (UINT32_C(0xFF) << TME_KAU_Shift)

#define TME_KAU_TME_HW            (UINT32_C(0x01) << TME_KAU_Shift)

#define TME_KAU_TME_FW            (UINT32_C(0x02) << TME_KAU_Shift)

#define TME_KAU_TZ                (UINT32_C(0x04) << TME_KAU_Shift)

#define TME_KAU_HLOS_HYP          (UINT32_C(0x08) << TME_KAU_Shift)

#define TME_KAU_MDM               (UINT32_C(0x10) << TME_KAU_Shift)

#define TME_KAU_SPU               (UINT32_C(0x20) << TME_KAU_Shift)

#define TME_KAU_ALL               TME_KAU_Mask


#define TME_CRED_SLOT_ID_NONE     0  
#define TME_CRED_SLOT_ID_1        1  
#define TME_CRED_SLOT_ID_2        2  



#define TME_KDF_SW_CONTEXT_BYTES_MAX  128
#define TME_KDF_SALT_LABEL_BYTES_MAX   64


#define TME_KSC_SOCTestSignState  0x00000001  
#define TME_KSC_SOCSecBootState   0x00000002  
#define TME_KSC_SOCDebugState     0x00000004  
#define TME_KSC_TMELifecycleState 0x00000008  
#define TME_KSC_BootStageOTP      0x00000010  
#define TME_KSC_SWContext         0x00000020  
#define TME_KSC_ChildKeyPolicy    0x00000040  
#define TME_KSC_MixingKey         0x00000080  
#define TME_KSC_ChipUniqueID      0x00000100  
#define TME_KSC_ChipDeviceNumber  0x00000200  
#define TME_KSC_TMEPatchVer       0x00000400  
#define TME_KSC_SOCPatchVer       0x00000800  
#define TME_KSC_OEMID             0x00001000  
#define TME_KSC_OEMProductID      0x00002000  
#define TME_KSC_TMEImgSecVer      0x00004000  
#define TME_KSC_SOCInitImgSecVer  0x00008000  
#define TME_KSC_OEMMRCHash        0x00010000  
#define TME_KSC_OEMProductSeed    0x00020000  
#define TME_KSC_SeqPatchVer       0x00040000  
#define TME_KSC_HWMeasurement1    0x00080000  
#define TME_KSC_HWMeasurement2    0x00100000  
#define TME_KSC_Reserved          0xFFE00000  


struct tme_kdf_spec {
	
	
	uint32_t                kdfalgo;
	
	uint32_t                inputkey;
	
	uint32_t                mixkey;
	
	uint32_t                l2key;
	
	struct tme_key_policy   policy;
	
	uint8_t                 swcontext[TME_KDF_SW_CONTEXT_BYTES_MAX];
	
	uint32_t                swcontextLength;
	
	uint32_t                security_context;
	
	uint8_t                 salt_label[TME_KDF_SALT_LABEL_BYTES_MAX];
	
	uint32_t                salt_labelLength;
	
	
	uint32_t                prf_digest_algo;
} __packed;




#define TME_WK_CONTEXT_BYTES_MAX  100
struct tme_wrapped_key {
	
	uint8_t   key[TME_WK_CONTEXT_BYTES_MAX];
	
	uint32_t  length;
} __packed;



#define TME_PT_KEY_BYTES_MAX  68


struct tme_plaintext_key {
	
	uint8_t   key[TME_PT_KEY_BYTES_MAX];
	
	uint32_t  length;
} __packed;


struct tme_ext_err_info {
	
	
	uint32_t  tme_err_status;

	
	
	uint32_t  seq_err_status;

	
	
	uint32_t  seq_kp_err_status0;
	
	uint32_t  seq_kp_err_status1;

	
	
	uint32_t  seq_rsp_status;
} __packed;

#endif 

