• genEcc256-test


      // Get a random value to sign using the built in DRBG state
            DRBG_Generate(NULL, digest.t.buffer, digest.t.size);
            if(g_inFailureMode)

     
    5322080903370CCDEA83B6FE92607D5A642506F792D4D4E8CAF8567F948A2D0E759125B2DE3AFF293CA5DD81D5D7374Cg_inFailureMode1 = 0
    g_inFailureMode2 = 0
    g_inFailureMode3 = 0
    g_inFailureMode4 = 0
    g_inFailureMode5 = 0
    g_inFailureMode6 = 1

    LIB_EXPORT BOOL
    CryptRandStartup(
        void
        )
    {
    #if ! _DRBG_STATE_SAVE
        // If not saved in NV, re-instantiate on each startup
        return DRBG_Instantiate(&drbgDefault, 0, NULL);
    #else
        // If the running state is saved in NV, NV has to be loaded before it can
        // be updated
        if(go.drbgState.magic == DRBG_MAGIC)
            return DRBG_Reseed(&go.drbgState, NULL, NULL);
        else
            return DRBG_Instantiate(&go.drbgState, 0, NULL);
    #endif
    }

     

    1. /* 通过rand计算出ECC256 ECC384 SM2密钥对*/
    2. int
    3. main(
    4. int argc,
    5. char* argv[]
    6. )
    7. {
    8. int i; /* argc iterator */
    9. int irc;
    10. printf("C:begin genEcc256\n");
    11. UINT32 e = 0;
    12. TPMT_PUBLIC publicArea;
    13. TPMT_SENSITIVE sensitive;
    14. RAND_STATE rand;
    15. // 初始化全局的go.drbgState,在 CryptEccGenerateKey中的 DRBG_Generate 中用到
    16. CryptRandStartup();
    17. // 5322080903370CCDEA83B6FE92607D5A642506F792D4D4E8CAF8567F948A2D0E759125B2DE3AFF293CA5DD81D5D7374C
    18. unsigned char c[] = { 0x53, 0x22, 0x08, 0x09, 0x03, 0x37, 0x0C, 0xCD, 0xEA, 0x83, 0xB6, 0xFE, 0x92, 0x60, 0x7D, 0x5A, 0x64, 0x25, 0x06, 0xF7, 0x92, 0xD4, 0xD4, 0xE8, 0xCA, 0xF8, 0x56, 0x7F, 0x94, 0x8A, 0x2D, 0x0E, 0x75, 0x91, 0x25, 0xB2, 0xDE, 0x3A, 0xFF, 0x29, 0x3C, 0xA5, 0xDD, 0x81, 0xD5, 0xD7, 0x37, 0x4C };
    19. memset(rand.drbg.seed.bytes, 0, 48);
    20. memcpy(rand.drbg.seed.bytes, c, 48);
    21. char name9[] = "after copy rand.seed";
    22. myprintf2(name9, rand.drbg.seed.bytes, 48);
    23. rand.drbg.magic = DRBG_MAGIC;
    24. rand.drbg.reseedCounter = 0x0000000000000064;
    25. publicArea.type = 0x0023;
    26. publicArea.nameAlg = 0x000b;
    27. publicArea.objectAttributes = 0x00040060;
    28. publicArea.authPolicy.t.size = 0;
    29. //#define TPM_ECC_NIST_P256 (TPM_ECC_CURVE)(0x0003)
    30. //#define TPM_ECC_NIST_P384 (TPM_ECC_CURVE)(0x0004)
    31. //#define TPM_ECC_SM2_P256 (TPM_ECC_CURVE)(0x0020)
    32. // 根据这个来决定使用哪个曲线对应的n
    33. publicArea.parameters.eccDetail.curveID = 0x20;
    34. publicArea.parameters.eccDetail.symmetric.algorithm = 0x0010;
    35. publicArea.parameters.eccDetail.symmetric.keyBits.aes = 0;
    36. publicArea.parameters.eccDetail.symmetric.keyBits.camellia = 0;
    37. publicArea.parameters.eccDetail.symmetric.keyBits.sym = 0;
    38. publicArea.parameters.eccDetail.symmetric.keyBits.xor = 0;
    39. publicArea.parameters.eccDetail.symmetric.mode.aes = 0;
    40. publicArea.parameters.eccDetail.symmetric.mode.camellia = 0;
    41. publicArea.parameters.eccDetail.symmetric.mode.sym = 0;
    42. publicArea.parameters.eccDetail.scheme.scheme = 0x0018;
    43. publicArea.parameters.eccDetail.scheme.details.ecdh.hashAlg = 0x000b;
    44. publicArea.parameters.eccDetail.scheme.details.ecdaa.hashAlg = 0x000b;
    45. publicArea.parameters.eccDetail.scheme.details.ecdaa.count = 0;
    46. sensitive.sensitiveType = 0x0023;
    47. sensitive.authValue.t.size = 0x0020;
    48. sensitive.seedValue.t.size = 0;
    49. sensitive.sensitive.ecc.t.size = 0;
    50. TPM_RC ret = CryptEccGenerateKey(
    51. &publicArea,
    52. &sensitive,
    53. &rand
    54. );
    55. printf("C:CryptEccGenerateKey = %d \n", ret);
    56. return ret;
    57. }

     

  • 相关阅读:
    跨站攻击CSRF实验
    通过WiSE-FT 大模型微调 (“灾难性遗忘”catastrophic forgetting)
    【framework-4】界面数据快照
    京东金融客户端用户触达方式的探索与实践
    工龄10年的测试员从大厂“裸辞”后...
    Day31 Web端自动化基础
    OpenAI api密钥申请
    学会自学 学会学习本身比学什么都重要
    人脸核身基础版 SDK 接入 > 合作方后台上送身份信息
    【 Git 和 SVN 的区别】
  • 原文地址:https://blog.csdn.net/liudong200618/article/details/132877632