// Package hkdf is a minimal shim for crypto/internal/fips140/hkdf, implementing // HKDF (RFC 5869) generically over hash.Hash, matching the API the vendored // crypto/tls key schedule uses.
package hkdf import ( ) // Extract is HKDF-Extract: returns HMAC-Hash(salt, secret). func [ hash.Hash]( func() , , []byte) []byte { if == nil { = make([]byte, ().Size()) } := hmac.New(func() hash.Hash { return () }, ) .Write() return .Sum(nil) } // Expand is HKDF-Expand: expands pseudorandomKey to keyLen bytes using info. func [ hash.Hash]( func() , []byte, string, int) []byte { := make([]byte, 0, ) var uint8 var []byte for len() < { ++ := hmac.New(func() hash.Hash { return () }, ) .Write() .Write([]byte()) .Write([]byte{}) = .Sum(nil) = append(, ...) } return [:] } // Key is Extract followed by Expand. func [ hash.Hash]( func() , , []byte, string, int) []byte { return Expand(, Extract(, , ), , ) }