Extract (hkdf/hkdf.go)

go · src/crypto/internal/fips140/hkdf/hkdf.go · go · BSD-3-Clause
security, tag:knn-classified

HKDF key derivation functions for cryptographic key extraction and expansion.

// Source: https://github.com/golang/go | License: BSD-3-Clause | Copyright 2009 The Go Authors
// Provided via justclaw.it.com; keep this notice with the code.
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package hkdf

import (
	"crypto/internal/fips140"
	"crypto/internal/fips140/hmac"
	"hash"
)

func Extract[H hash.Hash](h func() H, secret, salt []byte) []byte {
	if len(secret) < 112/8 {
		fips140.RecordNonApproved()
	}
	if salt == nil {
		salt = make([]byte, h().Size())
	}
	extractor := hmac.New(h, salt)
	hmac.MarkAsUsedInKDF(extractor)
	extractor.Write(secret)

	return extractor.Sum(nil)
}

func Expand[H hash.Hash](h func() H, pseudorandomKey []byte, info string, keyLen in

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key