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