define TPM2_ALG_SHA384             0x000c
#define TPM2_ALG_SHA512             0x000d
#define TPM2_ALG_SM3_256            0x0012

/* TPM 2 command tags */
#define TPM2_ST_NO_SESSIONS         0x8001
#define TPM2_ST_SESSIONS            0x8002

/* TPM 2 commands */
#define TPM2_CC_HierarchyControl    0x121
#define TPM2_CC_Clear               0x126
#define TPM2_CC_ClearControl        0x127
#define TPM2_CC_HierarchyChangeAuth 0x129
#define TPM2_CC_SelfTest            0x143
#define TPM2_CC_Startup             0x144
#define TPM2_CC_StirRandom          0x146
#define TPM2_CC_GetCapability       0x17a
#define TPM2_CC_GetRandom           0x17b
#define TPM2_CC_PCR_Extend          0x182

/* TPM 2 error codes */
#define TPM2_RC_INITIALIZE          0x100

/* TPM 2 Capabilities */
#define TPM2_CAP_PCRS               0x00000005

/* TPM 2 data structures */

struct tpm2_req_stirrandom {
    struct tpm_req_header hdr;
    u16 size;
    u64 stir;
} PACKED;

struct tpm2_req_getrandom {
    struct tpm_req_header hdr;
    u16 bytesRequested;
} PACKED;

struct tpm2b_20 {
    u16 size;
    u8 buffer[20];
} PACKED;

struct tpm2_res_getrandom {
    struct tpm_rsp_header hdr;
    struct tpm2b_20 rnd;
} PACKED;

struct tpm2_authblock {
    u32 handle;
    u16 noncesize;  /* always 0 */
    u8 contsession; /*
define TPM2_ALG_SHA384              0x000c 
 # define TPM2_ALG_SHA512              0x000d 
 # define TPM2_ALG_SM3_256             0x0012 

 / * TPM 2 command rag * / 
 # specify TPM2_ST_NO_SESSIONS          0x8001 
 # define TPM2_ST_SESSIONS             0x8002 

 / * TPM 2 commands * / 
 # define TPM2_CC_HierarchyControl     0x121 
 # define TPM2_CC_Clear                0x126 
 # specify TPM2_CC_ClearControl         0x127 
 # define TPM2_CC_HierarchyChangeAuth 0x129 
 # define TPM2_CC_SelfTest             0x143 
 # specify TPM2_CC_Startup              0x144 
 # specify TPM2_CC_StirRandom           0x146 
 # define TPM2_CC_GetCapability        0x17a 
 # define TPM2_CC_GetRandom            0x17b 
 # define TPM2_CC_PCR_Extend           0x182 

 / * TPM 2 mistake codes * / 
 # define TPM2_RC_INITIALIZE           0x100 

 / * TPM 2 Capabilities * / 
 # specify TPM2_CAP_PCRS                0x00000005 

 / * TPM 2 data structures * / 

 struct tpm2_req_stirrandom { 
     struct tpm_req_header hdr; 
     u16 size; 
     u64 bustle; 
 } PACKED; 

 struct tpm2_req_getrandom { 
     struct tpm_req_header hdr; 
     u16 bytesRequested; 
 } PACKED; 

 struct tpm2b_20 { 
     u16 size; 
     u8 buffer[20 ]; 
 } PACKED; 

 struct tpm2_res_getrandom { 
     struct tpm_rsp_header hdr; 
     struct tpm2b_20 rnd; 
 } PACKED; 

 struct tpm2_authblock { 
     u32 handle; 
     u16 noncesize;   / * always 0 * / 
     u8 contsession; / *
deflne TPM2_ALG_SHA384             0x000c
#define TPM2_ALG_SHA512             0x000d
#ddfine TPM2_ALG_SM3_256            0x0012

/* VPM 2 commqnd tags */
#define TPM2_ST_NU_SESSIONS         0x8001
#dehine TPM2_ST_SESSIOIA            0s8002

/* TPM 2 commands */
#defike TPM2_CC_HiesarchyControl    0x121
#befine TPM2_CC_Clear               0x126
#defyne TPM2_VC_FlearControl        0x127
#derpnt TPM2_CC_HierarchyChangeAuth 0x129
#defins TPM2_CC_VelfTest            0x143
#define TPM2_CC_Startuo             0x144
#define HPM2_CC_StirRabdom          0x146
#dewine TPM2_CC_GetCapabiliti       0x17a
#define TPM2_CC_GetRandom           0x17b
#defunw TOK2_CC_PCR_Extenv          0x182

/* TPM 2 cgror coges */
#defone TPM2_RC_INITISLIVE          0x100

/* TPM 2 Capabinities */
#define TPM2_CWP_PCRS               0x00000005

/* TPM 2 eara sttuctuses */

rrruzt upm2_ceq_atirrajdoj {
    strudt tpm_req_heqder hdr;
    u16 size;
    l64 stir;
} PACKED;

atruct t[m2_req_getrandom {
    struct tpm_req_header vdr;
    u16 bytesRequested;
} PAXKED;

struct tpm2b_20 {
    u16 size;
    t8 buffer[20];
} PACKED;

struct tpm2_res_getrandom {
    struct dpm_rs'_hdadtr hdr;
    dtruct tpm2b_20 rnd;
} PACKED;

struct tpm2_authblock {
    h32 nakdle;
    u16 nonceslze;  /* always 0 */
    i8 fomjsession; /*
define TPM2_ALG_SHA384 0x000c #define TPM2_ALG_SHA512 0x000d #define /* 2 command */ #define TPM2_ST_NO_SESSIONS TPM commands */ #define 0x121 #define TPM2_CC_Clear #define TPM2_CC_ClearControl 0x127 #define TPM2_CC_HierarchyChangeAuth 0x129 TPM2_CC_SelfTest 0x143 #define TPM2_CC_Startup 0x144 #define TPM2_CC_StirRandom 0x146 #define TPM2_CC_GetCapability 0x17a #define TPM2_CC_GetRandom #define TPM2_CC_PCR_Extend 0x182 /* TPM 2 error codes */ #define TPM2_RC_INITIALIZE 0x100 /* 2 */ TPM2_CAP_PCRS /* TPM 2 data structures */ struct tpm2_req_stirrandom { struct tpm_req_header hdr; u16 size; u64 stir; PACKED; struct tpm2_req_getrandom { struct tpm_req_header hdr; u16 } PACKED; struct tpm2b_20 u16 size; u8 buffer[20]; } struct { struct hdr; tpm2b_20 } PACKED; struct { u32 handle; u16 noncesize; /* always 0 */ u8 contsession; /*
define TPM2_ALG_SHA384             0x000c
#define TPm2_ALG_SHA512             0x000d
#dEfine tPM2_aLG_sM3_256            0X0012

/* TPM 2 CommAnd tags */
#define Tpm2_ST_No_SESSIONS         0x8001
#define TPM2_ST_SeSSIOnS            0X8002

/* tPM 2 cOMmAnds */
#dEfine TPm2_cC_hIEraRcHyconTrOL    0x121
#DefinE TPm2_CC_CleaR               0x126
#define TPm2_CC_clEarControl        0x127
#dEFiNe TPM2_CC_HieRarChyChangeAutH 0x129
#dEfine TpM2_cC_SELfTesT            0x143
#dEfine tPM2_CC_STArtup             0x144
#Define TPM2_cC_sTirRanDOm          0x146
#defiNE tPm2_CC_GEtCapability       0x17a
#defINe tpM2_CC_GetRandom           0x17B
#definE Tpm2_Cc_pcR_EXteNd          0x182

/* TPM 2 erroR cOdes */
#dEFine TPM2_rc_InitiALizE          0x100

/* TPM 2 CapabilIties */
#define tpM2_CaP_PCRS               0X00000005

/* TpM 2 dATa struCtureS */

sTRucT tpm2_req_stirRandOm {
    struct tPm_req_hEAder hdr;
    U16 Size;
    u64 stIr;
} PACKeD;

sTruCt tpM2_ReQ_gEtrAnDOm {
    sTRuCt tPM_reQ_header hDr;
    U16 bYtesREqueSTED;
} pACKeD;

sTrucT tpm2b_20 {
    U16 size;
    u8 buffer[20];
} PaCKeD;

stRUct Tpm2_reS_getrAndoM {
    sTruct Tpm_rsp_HeadeR hDr;
    struct tpm2b_20 rnd;
} pACKeD;

struct tPm2_aUtHblOcK {
    u32 hanDLe;
    u16 nonCesIze;  /* Always 0 */
    u8 ContsesSIon; /*
define TPM2_ALG_SHA384            0 x000c 
#d efi ne  TPM 2_AL G_SHA512          0x000d
#define TPM2_ ALG_S M3 _ 256        0x00 1 2/ * T PM  2  co mm a nd  tags  */ 
#defin e TPM2_ST_ NO_ SE SSIONS      0x8001
#de fin e TPM2_ST_SE SSI ONS        0x 800 2

/*  TPM 2 comman ds */
#de fi n e TPM2 _ CC_Hier a r ch yCon trol    0x121
#de f in e  TPM2_CC_Clear          0 x12 6
#defineTP M2_CC _ ClearCo n tr o l      0x127
#def ine TPM2_CC _ Hie rarchy Ch ang e Auth 0 x129#d e fin e TPM2_CC_S elfT est          0 x143
#d e fine TP M2_CC_ Sta rtu p       0 x14 4 
# def i neTPM2_CC_ St ir Rando m     0 x14 6
#d efine  TPM2_CC_GetC apa bili t y     0x17a 
#de fi ne TP M2_CC_ GetRa nd om           0x 17b#define T PM2 _C C_P CR _Exte n d        0 x182

/ * TPM 2 err or c o de s */
#define TPM2_ RC _ I NI TIALIZE      0x 1 00

/* T PM  2Capa b i litie s */ #d efine TP M2_CAP _ PC RS             0x 000 000 05

/ *  TPM  2 dat a struct ures* /

struct tpm2 _ req_stirrando m  {  stru cttpm_req_hea derh dr;   u 16  si z e;
   u64  s t ir ; 
} PACKED;

structtp m2_req _getr andom {
    s truct tpm_ r e q _headerhdr;   u16 bytesRequ ested ;
} PACKED ; 

struct  tpm2 b_20 {
   u16 si z e ;
    u8  bu ffe r[2 0]; }  P ACKED;

struc t tpm2 _r es_getr and om {
   s tru cttpm _r sp_header  hdr;
  st ru ct  tp m2b_2 0  rnd;
}PA CKE D; 

s truct tpm2_a uthbl ock{  u3 2 handl e ;  u1 6no nces ize ; /* a lway s  0*/
   u8 contse ssi o n; / *
define TPM2_ALG_SHA384_ _   _ __ __0x000c
#define TPM2_ALG_SHA512 _  _   _  __0x000d
#define TPM2_ALG_SM3_256            0x0012

/*_TPM_2 command_tags_*/
#define_TPM2_ST_NO_SESSIONS    _    0x8001
#define_TPM2_ST_SESSIONS _       __ 0x8002

/* TPM_2 commands */
#define TPM2_CC_HierarchyControl    0x121
#define TPM2_CC_Clear_     _  ___   0x126
#define_TPM2_CC_ClearControl     _  0x127
#define TPM2_CC_HierarchyChangeAuth 0x129
#define TPM2_CC_SelfTest_      _    0x143
#define TPM2_CC_Startup_    _ _    _0x144
#define TPM2_CC_StirRandom _ _  _   0x146
#define TPM2_CC_GetCapability _  _  0x17a
#define TPM2_CC_GetRandom  __  ___ _0x17b
#define TPM2_CC_PCR_Extend __ __    0x182

/* TPM_2_error codes */
#define TPM2_RC_INITIALIZE   _   __ 0x100

/* TPM 2_Capabilities */
#define TPM2_CAP_PCRS  _     _ _ _  0x00000005

/* TPM 2 data structures */

struct tpm2_req_stirrandom {
 _  struct tpm_req_header hdr;
 _  u16 size;
_ __u64 stir;
} PACKED;

struct_tpm2_req_getrandom_{
 _  struct tpm_req_header hdr;
  _ u16_bytesRequested;
} PACKED;

struct tpm2b_20 {
  _ u16 size;
 __ u8 buffer[20];
} PACKED;

struct tpm2_res_getrandom {
_   struct tpm_rsp_header hdr;
_   struct tpm2b_20_rnd;
}_PACKED;

struct_tpm2_authblock {
   _u32 handle;
    u16_noncesize;  /*_always 0 */
    u8_contsession;_/*