package hpke
import (
- "crypto/aes"
"crypto/cipher"
"errors"
"fmt"
id: 0x0003,
}
-func newAESGCM(key []byte) (cipher.AEAD, error) {
- b, err := aes.NewCipher(key)
- if err != nil {
- return nil, err
- }
- return cipher.NewGCM(b)
-}
-
func (a *aead) ID() uint16 {
return a.id
}
--- /dev/null
+// Copyright 2025 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.
+
+//go:build fips140v1.0
+
+package hpke
+
+import (
+ "crypto/aes"
+ "crypto/cipher"
+)
+
+func newAESGCM(key []byte) (cipher.AEAD, error) {
+ b, err := aes.NewCipher(key)
+ if err != nil {
+ return nil, err
+ }
+ return cipher.NewGCM(b)
+}
--- /dev/null
+// Copyright 2025 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.
+
+//go:build !fips140v1.0
+
+package hpke
+
+import (
+ "crypto/cipher"
+ "crypto/internal/fips140/aes"
+ "crypto/internal/fips140/aes/gcm"
+)
+
+func newAESGCM(key []byte) (cipher.AEAD, error) {
+ b, err := aes.New(key)
+ if err != nil {
+ return nil, err
+ }
+ return gcm.NewGCMForHPKE(b)
+}
return &GCMWithXORCounterNonce{g: *g}, nil
}
+// NewGCMForHPKE returns a new AEAD that works like GCM, but enforces the
+// construction of nonces as specified in RFC 9180, Section 5.2.
+//
+// This complies with FIPS 140-3 IG C.H Scenario 5.
+func NewGCMForHPKE(cipher *aes.Block) (*GCMWithXORCounterNonce, error) {
+ g, err := newGCM(&GCM{}, cipher, gcmStandardNonceSize, gcmTagSize)
+ if err != nil {
+ return nil, err
+ }
+ return &GCMWithXORCounterNonce{g: *g}, nil
+}
+
// NewGCMForQUIC returns a new AEAD that works like GCM, but enforces the
// construction of nonces as specified in RFC 9001, Section 5.3.
//