| 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 sha256 |
| 6 |
|
| 7 |
import ( |
| 8 |
"bytes" |
| 9 |
"crypto/internal/fips140" |
| 10 |
"errors" |
| 11 |
) |
| 12 |
|
| 13 |
func init() { |
| 14 |
fips140.CAST("SHA2-256", func() error { |
| 15 |
input := []byte{ |
| 16 |
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 17 |
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
| 18 |
} |
| 19 |
want := []byte{ |
| 20 |
0x5d, 0xfb, 0xab, 0xee, 0xdf, 0x31, 0x8b, 0xf3, |
| 21 |
0x3c, 0x09, 0x27, 0xc4, 0x3d, 0x76, 0x30, 0xf5, |
| 22 |
0x1b, 0x82, 0xf3, 0x51, 0x74, 0x03, 0x01, 0x35, |
| 23 |
0x4f, 0xa3, 0xd7, 0xfc, 0x51, 0xf0, 0x13, 0x2e, |
| 24 |
} |
| 25 |
h := New() |
| 26 |
h.Write(input) |
| 27 |
if got := h.Sum(nil); !bytes.Equal(got, want) { |
| 28 |
return errors.New("unexpected result") |
| 29 |
} |
| 30 |
return nil |
| 31 |
}) |
| 32 |
} |