Source file src/crypto/internal/fips140/hmac/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 hmac
     6  
     7  import (
     8  	"bytes"
     9  	"crypto/internal/fips140"
    10  	"crypto/internal/fips140/sha256"
    11  	"errors"
    12  )
    13  
    14  func init() {
    15  	fips140.CAST("HMAC-SHA2-256", func() error {
    16  		input := []byte{
    17  			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
    18  			0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
    19  		}
    20  		want := []byte{
    21  			0xf0, 0x8d, 0x82, 0x8d, 0x4c, 0x9e, 0xad, 0x3d,
    22  			0xdc, 0x12, 0x9c, 0x4e, 0x70, 0xc4, 0x19, 0x2a,
    23  			0x4f, 0x12, 0x73, 0x23, 0x73, 0x77, 0x66, 0x05,
    24  			0x10, 0xee, 0x57, 0x6b, 0x3a, 0xc7, 0x14, 0x41,
    25  		}
    26  		h := New(sha256.New, input)
    27  		h.Write(input)
    28  		h.Write(input)
    29  		if got := h.Sum(nil); !bytes.Equal(got, want) {
    30  			return errors.New("unexpected result")
    31  		}
    32  		return nil
    33  	})
    34  }
    35  

View as plain text