@Test
public void doSM2primaryKey(){
byte[] authPolicy = HexUtils.toByteArray("167860A35F2C5C3567F9C927AC56C032F3B3A6462F8D037998E7A10F77FA454A");
// Do the same thing with an ECDSA key
// Create an RSA signing public key in the owner hierarchy
TPMT_PUBLIC eccTemplate = new TPMT_PUBLIC(
TPM_ALG_ID.SM3_256,
new TPMA_OBJECT(TPMA_OBJECT.fixedTPM,TPMA_OBJECT.fixedParent, TPMA_OBJECT.sensitiveDataOrigin, TPMA_OBJECT.userWithAuth, TPMA_OBJECT.adminWithPolicy, TPMA_OBJECT.restricted, TPMA_OBJECT.decrypt),
authPolicy,
new TPMS_ECC_PARMS
(
//new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.NULL, 0, TPM_ALG_ID.NULL),
new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.SM4, 128, TPM_ALG_ID.CFB),
new TPMS_SIG_SCHEME_ECDSA(TPM_ALG_ID.NULL),
TPM_ECC_CURVE.SM2_P256,
new TPMS_NULL_KDF_SCHEME()
),
new TPMS_ECC_POINT());
// Tell the TPM to make a key with a non-null auth value.
TPMS_SENSITIVE_CREATE eccSens = new TPMS_SENSITIVE_CREATE(Helpers.RandomBytes(10), new byte[0]);
CreatePrimaryResponse eccPrimary = tpm.CreatePrimary(TPM_HANDLE.from(TPM_RH.OWNER), eccSens,
eccTemplate, new byte[0], new TPMS_PCR_SELECTION[0]);
System.out.println("SM2 Primary Key: \n" + eccPrimary.toString());
System.out.println("SM2 EK: " + eccPrimary.outPublic.toString());
}
上面是客户端代码
ibmtpm1682\src\CommandDispatcher.c :
FlagFunction *f = unmarshalArray[dType];
result = f(&commandIn[offset], &command->parameterBuffer,
&command->parameterSize,
(type & 0x80) != 0);
TPMT_PUBLIC_Unmarshal(TPMT_PUBLIC *target, BYTE **buffer, INT32 *size, BOOL allowNull)
TPMI_ALG_HASH_Unmarshal(TPMI_ALG_HASH *target, BYTE **buffer, INT32 *size, BOOL allowNull)
#ifndef ALG_SM3_256
#define ALG_SM3_256 ALG_NO
#endif
改为 ALG_YES
否则出现异常错误:
tss.TpmException: TPM Exception: {HASH}
加上后编译报错了:
调用堆栈: