MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / p_hash

Function p_hash

extra/yassl/src/handshake.cpp:423–455  ·  view source on GitHub ↗

compute p_hash for MD5 or SHA-1 for TLSv1 PRF

Source from the content-addressed store, hash-verified

421
422// compute p_hash for MD5 or SHA-1 for TLSv1 PRF
423void p_hash(output_buffer& result, const output_buffer& secret,
424 const output_buffer& seed, MACAlgorithm hash)
425{
426 uint len = hash == md5 ? MD5_LEN : SHA_LEN;
427 uint times = result.get_capacity() / len;
428 uint lastLen = result.get_capacity() % len;
429 opaque previous[SHA_LEN]; // max size
430 opaque current[SHA_LEN]; // max size
431 mySTL::auto_ptr<Digest> hmac;
432
433 if (lastLen) times += 1;
434
435 if (hash == md5)
436 hmac.reset(NEW_YS HMAC_MD5(secret.get_buffer(), secret.get_size()));
437 else
438 hmac.reset(NEW_YS HMAC_SHA(secret.get_buffer(), secret.get_size()));
439 // A0 = seed
440 hmac->get_digest(previous, seed.get_buffer(), seed.get_size());// A1
441 uint lastTime = times - 1;
442
443 for (uint i = 0; i < times; i++) {
444 hmac->update(previous, len);
445 hmac->get_digest(current, seed.get_buffer(), seed.get_size());
446
447 if (lastLen && (i == lastTime))
448 result.write(current, lastLen);
449 else {
450 result.write(current, len);
451 //memcpy(previous, current, len);
452 hmac->get_digest(previous, previous, len);
453 }
454 }
455}
456
457
458// calculate XOR for TLSv1 PRF

Callers 1

PRFFunction · 0.85

Calls 9

HMAC_MD5Class · 0.85
HMAC_SHAClass · 0.85
get_capacityMethod · 0.80
get_sizeMethod · 0.80
get_digestMethod · 0.80
resetMethod · 0.45
get_bufferMethod · 0.45
updateMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected