首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在TPM芯片中读取和存储数据

如何在TPM芯片中读取和存储数据
EN

Stack Overflow用户
提问于 2020-06-26 20:39:38
回答 1查看 1.1K关注 0票数 1

我正在通过TPM(Trusted Platform Module,可信平台模块)并尝试执行一些任务。如何将数据存储到TPM(可信平台模块)芯片,以及如何读取这些数据。有人能在这方面帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-01 22:55:55

这是使用NV存储命令完成的。使用TSS.MSR、from their samples

代码语言:javascript
复制
static void NVReadWrite(Tpm2 tpm)
{
    //
    // AuthValue encapsulates an authorization value: essentially a byte-array.
    // OwnerAuth is the owner authorization value of the TPM-under-test.  We
    // assume that it (and other) auths are set to the default (null) value.
    // If running on a real TPM, which has been provisioned by Windows, this
    // value will be different. An administrator can retrieve the owner
    // authorization value from the registry.
    //
    var ownerAuth = new AuthValue();
    TpmHandle nvHandle = TpmHandle.NV(3001);

    //
    // Clean up any slot that was left over from an earlier run
    // 
    tpm._AllowErrors()
       .NvUndefineSpace(TpmRh.Owner, nvHandle);
    //
    // Scenario 1 - write and read a 32-byte NV-slot
    // 
    AuthValue nvAuth = AuthValue.FromRandom(8);
    tpm.NvDefineSpace(TpmRh.Owner, nvAuth,
                      new NvPublic(nvHandle, TpmAlgId.Sha1,
                                   NvAttr.Authread | NvAttr.Authwrite,
                                   null, 32));

    //
    // Write some data
    // 
    var nvData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
    tpm.NvWrite(nvHandle, nvHandle, nvData, 0);
    //
    // And read it back
    // 
    byte[] nvRead = tpm.NvRead(nvHandle, nvHandle, (ushort)nvData.Length, 0);

    //
    // Is it correct?
    // 
    bool correct = nvData.SequenceEqual(nvRead);
    if (!correct)
    {
        throw new Exception("NV data was incorrect.");
    }

    Console.WriteLine("NV data written and read.");

    //
    // And clean up
    // 
    tpm.NvUndefineSpace(TpmRh.Owner, nvHandle);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62594943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档