使用TSS / C ++创建椭圆曲线签名密钥

时间:2019-01-11 15:03:47

标签: c++ security sign

我需要使用TSS / C ++库创建一个椭圆签名密钥。 但是,当我创建它时,我从TPM模拟器中收到一个奇怪的错误: TPM错误-TPM_RC :::指定的路径无效。

这是我用来创建签名密钥的方法。有人可以告诉我我做错了什么吗

DWORD CreateKeyPair(Tpm2 tpm)
{
    DWORD retCode = 0;

    try
    {
        //Create a dummy PIN for now
        ByteVec userAuth = ByteVec{ 1, 2, 3, 4 };
        TPMS_SENSITIVE_CREATE sensCreate(userAuth, vector<BYTE>());

        vector<TPMS_PCR_SELECTION> pcrSelectSigning{};


        //signing key
        TPMS_ECC_PARMS signingKeyParams(TPMT_SYM_DEF_OBJECT(), 
            TPMS_SCHEME_ECDSA(TPM_ALG_ID::SHA256), 
            TPM_ECC_CURVE::NIST_P256, 
            TPMS_NULL_KDF_SCHEME());

        //Signing key public template   
        TPMT_PUBLIC signingKeyTemplate(TPM_ALG_ID::SHA256,
            TPMA_OBJECT::sign |                        // Key attribues
            // Not needed, TPMA_OBJECT::encrypt |
            TPMA_OBJECT::fixedParent |
            TPMA_OBJECT::fixedTPM |
            TPMA_OBJECT::sensitiveDataOrigin |
            TPMA_OBJECT::userWithAuth, 
            vector<BYTE>(),
            signingKeyParams,
            TPMS_ECC_POINT()
        );

        CreatePrimaryResponse singingPrimary = tpm.CreatePrimary(TPM_RH::OWNER, 
            sensCreate, 
            signingKeyTemplate, 
            vector<BYTE>(), 
            pcrSelectSigning);
    }
    catch (exception e)
    {
        cout << "Exception thrown: " << e.what() << endl;
    }

    return retCode;
}

0 个答案:

没有答案