-
Notifications
You must be signed in to change notification settings - Fork 7
/
hpke.go
42 lines (36 loc) · 1.06 KB
/
hpke.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2020 Cloudflare, Inc. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
package tls
import (
"errors"
"fmt"
"github.com/cloudflare/circl/hpke"
)
// The mandatory-to-implement HPKE cipher suite for use with the ECH extension.
var defaultHPKESuite hpke.Suite
func init() {
var err error
defaultHPKESuite, err = hpkeAssembleSuite(
uint16(hpke.KEM_X25519_HKDF_SHA256),
uint16(hpke.KDF_HKDF_SHA256),
uint16(hpke.AEAD_AES128GCM),
)
if err != nil {
panic(fmt.Sprintf("hpke: mandatory-to-implement cipher suite not supported: %s", err))
}
}
func hpkeAssembleSuite(kemId, kdfId, aeadId uint16) (hpke.Suite, error) {
kem := hpke.KEM(kemId)
if !kem.IsValid() {
return hpke.Suite{}, errors.New("KEM is not supported")
}
kdf := hpke.KDF(kdfId)
if !kdf.IsValid() {
return hpke.Suite{}, errors.New("KDF is not supported")
}
aead := hpke.AEAD(aeadId)
if !aead.IsValid() {
return hpke.Suite{}, errors.New("AEAD is not supported")
}
return hpke.NewSuite(kem, kdf, aead), nil
}