compute p_hash for MD5 or SHA-1 for TLSv1 PRF
| 421 | |
| 422 | // compute p_hash for MD5 or SHA-1 for TLSv1 PRF |
| 423 | void 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 |
no test coverage detected