MCPcopy Create free account
hub / github.com/HomeSpan/HomeSpan / createVerifyCode

Method createVerifyCode

src/SRP.cpp:87–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85//////////////////////////////////////
86
87void SRP6A::createVerifyCode(const char *setupCode, Verification *vData){
88
89 TempBuffer<uint8_t> tBuf(80); // temporary buffer for staging
90 TempBuffer<uint8_t> tHash(64); // temporary buffer for storing SHA-512 results
91 char *icp; // storage for I:P
92
93 // generate random salt, s
94
95 randombytes_buf(vData->salt,16); // generate 16 random bytes for salt
96
97 // create I:P
98
99 asprintf(&icp,"%s:%.3s-%.2s-%.3s",I,setupCode,setupCode+3,setupCode+5);
100
101 // compute x = SHA512( s | SHA512( I | ":" | P ) )
102
103 memcpy(tBuf,vData->salt,16); // write salt into first 16 bytes of staging buffer
104 mbedtls_sha512((uint8_t *)icp,strlen(icp),tBuf+16,0); // create hash of username:password and write into last 64 bytes of staging buffer
105 mbedtls_sha512(tBuf,80,tHash,0); // create second hash of salted, hashed username:password
106 mbedtls_mpi_read_binary(&x,tHash,64); // load hash result into x
107
108 // compute v = g^x %N
109
110 mbedtls_mpi_exp_mod(&v,&g,&x,&N,&_rr); // create verifier, v (_rr is an internal "helper" structure that mbedtls uses to speed up subsequent exponential calculations)
111 mbedtls_mpi_write_binary(&v,vData->verifyCode,384); // write v into verifyCode (padding with initial zeros is less than 384 bytes)
112
113 free(icp);
114
115}
116
117//////////////////////////////////////
118

Callers 1

HomeSpan.cppFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected