Source file src/crypto/internal/fips140/aes/gcm/cast.go

     1  // Copyright 2024 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 gcm
     6  
     7  import (
     8  	"crypto/internal/fips140"
     9  	"crypto/internal/fips140/aes"
    10  	_ "crypto/internal/fips140/check"
    11  	"errors"
    12  )
    13  
    14  func init() {
    15  	// Counter KDF covers CMAC per IG 10.3.B, and CMAC covers GCM per IG 10.3.A
    16  	// Resolution 1.d(i). AES decryption is covered by the CBC CAST in package
    17  	// crypto/internal/fips140/aes.
    18  	fips140.CAST("CounterKDF", func() error {
    19  		key := []byte{
    20  			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
    21  			0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
    22  		}
    23  		context := [12]byte{
    24  			0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
    25  			0x29, 0x2a, 0x2b, 0x2c,
    26  		}
    27  		want := [32]byte{
    28  			0xe6, 0x86, 0x96, 0x97, 0x08, 0xfc, 0x90, 0x30,
    29  			0x36, 0x1c, 0x65, 0x94, 0xb2, 0x62, 0xa5, 0xf7,
    30  			0xcb, 0x9d, 0x93, 0x94, 0xda, 0xf1, 0x94, 0x09,
    31  			0x6a, 0x27, 0x5e, 0x85, 0x22, 0x5e, 0x7a, 0xee,
    32  		}
    33  		b, err := aes.New(key)
    34  		if err != nil {
    35  			return err
    36  		}
    37  		got := NewCounterKDF(b).DeriveKey(0xFF, context)
    38  		if got != want {
    39  			return errors.New("unexpected result")
    40  		}
    41  		return nil
    42  	})
    43  }
    44  

View as plain text