TLS type HAMC
| 658 | |
| 659 | // TLS type HAMC |
| 660 | void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, |
| 661 | ContentType content, bool verify) |
| 662 | { |
| 663 | mySTL::auto_ptr<Digest> hmac; |
| 664 | opaque seq[SEQ_SZ] = { 0x00, 0x00, 0x00, 0x00 }; |
| 665 | opaque length[LENGTH_SZ]; |
| 666 | opaque inner[SIZEOF_ENUM + VERSION_SZ + LENGTH_SZ]; // type + version + len |
| 667 | |
| 668 | c16toa(sz, length); |
| 669 | c32toa(ssl.get_SEQIncrement(verify), &seq[sizeof(uint32)]); |
| 670 | |
| 671 | MACAlgorithm algo = ssl.getSecurity().get_parms().mac_algorithm_; |
| 672 | |
| 673 | if (algo == sha) |
| 674 | hmac.reset(NEW_YS HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN)); |
| 675 | else if (algo == rmd) |
| 676 | hmac.reset(NEW_YS HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN)); |
| 677 | else |
| 678 | hmac.reset(NEW_YS HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN)); |
| 679 | |
| 680 | hmac->update(seq, SEQ_SZ); // seq_num |
| 681 | inner[0] = content; // type |
| 682 | inner[SIZEOF_ENUM] = ssl.getSecurity().get_connection().version_.major_; |
| 683 | inner[SIZEOF_ENUM + SIZEOF_ENUM] = |
| 684 | ssl.getSecurity().get_connection().version_.minor_; // version |
| 685 | memcpy(&inner[SIZEOF_ENUM + VERSION_SZ], length, LENGTH_SZ); // length |
| 686 | hmac->update(inner, sizeof(inner)); |
| 687 | hmac->get_digest(digest, buffer, sz); // content |
| 688 | } |
| 689 | |
| 690 | |
| 691 | // compute TLSv1 PRF (pseudo random function using HMAC) |
no test coverage detected