gitlab.com/go-extension/tls@v0.0.0-20240304171319-e6745021905e/hpke.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package tls
     6  
     7  import (
     8  	"errors"
     9  
    10  	"github.com/cloudflare/circl/hpke"
    11  )
    12  
    13  // The mandatory-to-implement HPKE cipher suite for use with the ECH extension.
    14  var (
    15  	dummyX25519PublicKey = []byte{
    16  		143, 38, 37, 36, 12, 6, 229, 30, 140, 27, 167, 73, 26, 100, 203, 107, 216,
    17  		81, 163, 222, 52, 211, 54, 210, 46, 37, 78, 216, 157, 97, 241, 244,
    18  	}
    19  	defaultHpkeSuite = hpke.NewSuite(hpke.KEM_X25519_HKDF_SHA256, hpke.KDF_HKDF_SHA256, hpke.AEAD_AES128GCM)
    20  )
    21  
    22  func hpkeAssembleSuite(kemId, kdfId, aeadId uint16) (hpke.Suite, error) {
    23  	kem := hpke.KEM(kemId)
    24  	if !kem.IsValid() {
    25  		return hpke.Suite{}, errors.New("KEM is not supported")
    26  	}
    27  	kdf := hpke.KDF(kdfId)
    28  	if !kdf.IsValid() {
    29  		return hpke.Suite{}, errors.New("KDF is not supported")
    30  	}
    31  	aead := hpke.AEAD(aeadId)
    32  	if !aead.IsValid() {
    33  		return hpke.Suite{}, errors.New("AEAD is not supported")
    34  	}
    35  	return hpke.NewSuite(kem, kdf, aead), nil
    36  }
    37  
    38  // HpkeSymmetricCipherSuite represents an ECH ciphersuite, a KDF/AEAD algorithm pair. This
    39  // is different from an HPKE ciphersuite, which represents a KEM/KDF/AEAD
    40  // triple.
    41  type hpkeSymmetricCipherSuite struct {
    42  	KDF, AEAD uint16
    43  }