void Tpm2::RollNonces() { for (size_t j = 0; j < Sessions.size(); j++) { if (Sessions[j]->IsPWAP()) { continue; } // Roll the nonceCaller ByteVec newNonceCaller = GetRandomBytes(Sessions[j]->NonceCaller.size()); Sessions[j]->NonceCaller = newNonceCaller; } }
int CreateRandomBytes(const char *name, int size) { unsigned char *buff = (unsigned char*)malloc(size); if (buff) { GetRandomBytes(buff, size); PrintBytes(name, buff, size); free(buff); return 0; } fprintf(stderr, "Insufficient memory error.\n"); return 1; }
int CreateBlindingContext(IN const char *name) { /* Create a random blind */ unsigned char seed[64]; EDP_BLINDING_CTX B; GetRandomBytes(seed, (int)sizeof(seed)); ed25519_Blinding_Init((void *)&B, seed, sizeof(seed)); printf( "#include \"curve25519_mehdi.h\"\n\n" "EDP_BLINDING_CTX %s = \n", name); PrintWords("{\n W256(",B.bl, K_WORDS); PrintWords("),\n W256(",B.zr, K_WORDS); PrintWords("),\n {\n W256(",B.BP.YpX, K_WORDS); PrintWords("),\n W256(",B.BP.YmX, K_WORDS); PrintWords("),\n W256(",B.BP.T2d, K_WORDS); PrintWords("),\n W256(",B.BP.Z2, K_WORDS); printf(")\n }\n};\n"); return 0; }
int CreateSignTestVector(const char *seed, const char *msg) { unsigned char md[SHA512_DIGEST_LENGTH]; unsigned char Kpub[ed25519_public_key_size]; unsigned char Kprv[ed25519_private_key_size]; unsigned char sig[ed25519_signature_size]; int len = (int)strlen(msg); if (seed) { SHA512_CTX H; SHA512_Init(&H); SHA512_Update(&H, seed, strlen(seed)); SHA512_Final(md, &H); } else { GetRandomBytes(md, 32); } PrintBytes("sk", md, 32); ed25519_CreateKeyPair(Kpub, Kprv, 0, md); PrintBytes("Kpub", Kpub, ed25519_public_key_size); PrintBytes("Kprv", Kprv, ed25519_private_key_size); PrintBytes("m", (const unsigned char*)msg, len); ed25519_SignMessage(sig, Kprv, 0, (const unsigned char*)msg, len); PrintBytes("sig", sig, ed25519_signature_size); if (ed25519_VerifySignature(sig, Kpub, (const unsigned char*)msg, len)) return 0; fprintf(stderr, "Signature verification failed.\n"); return 1; }