xref: /aosp_15_r20/external/tink/go/hybrid/internal/hpke/kdf.go (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15////////////////////////////////////////////////////////////////////////////////
16
17package hpke
18
19// kdf is a package-internal interface for the Hybrid Public Key Encryption
20// (HPKE) key derivation function (KDF).
21//
22// The HPKE RFC is available at
23// https://www.rfc-editor.org/rfc/rfc9180.html.
24type kdf interface {
25	// labeledExtract extracts a pseudorandom key from salt, ikm using the
26	// HPKE-specified values suiteID, ikmLabel to facilitate domain separation
27	// and context binding.
28	//
29	// https://www.rfc-editor.org/rfc/rfc9180.html#section-4-9
30	labeledExtract(salt, ikm []byte, ikmLabel string, suiteID []byte) []byte
31
32	// labeledExpand expands the pseudorandom key prk into length pseudorandom
33	// bytes using info with other HPKE-specific values infoLabel, suiteID to
34	// facilitate domain separation and context binding.
35	//
36	// https://www.rfc-editor.org/rfc/rfc9180.html#section-4-9
37	labeledExpand(prk, info []byte, infoLabel string, suiteID []byte, length int) ([]byte, error)
38
39	// extractAndExpand calls labeledExtract and labeledExpand in order.
40	//
41	// https://www.rfc-editor.org/rfc/rfc9180.html#section-4.1-3
42	extractAndExpand(salt, ikm []byte, ikmLabel string, info []byte, infoLabel string, suiteID []byte, length int) ([]byte, error)
43
44	// id returns the HPKE KDF algorithm identifier for the underlying KDF
45	// implementation.
46	//
47	// https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2
48	id() uint16
49}
50