pHash implements the P_hash function, as defined in RFC 5246, Section 5.
(hash1 func() H, result, secret, seed []byte)
| 23 | |
| 24 | // pHash implements the P_hash function, as defined in RFC 5246, Section 5. |
| 25 | func pHash[H hash.Hash](hash1 func() H, result, secret, seed []byte) { |
| 26 | h := hmac.New(any(hash1).(func() hash.Hash), secret) |
| 27 | h.Write(seed) |
| 28 | a := h.Sum(nil) |
| 29 | |
| 30 | for len(result) > 0 { |
| 31 | h.Reset() |
| 32 | h.Write(a) |
| 33 | h.Write(seed) |
| 34 | b := h.Sum(nil) |
| 35 | n := copy(result, b) |
| 36 | result = result[n:] |
| 37 | |
| 38 | h.Reset() |
| 39 | h.Write(a) |
| 40 | a = h.Sum(nil) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | const masterSecretLength = 48 |
| 45 | const extendedMasterSecretLabel = "extended master secret" |