1# Copyright 2022 The BoringSSL Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# This script attempts to break each of the known KATs and checks that doing so
16# seems to work and at least mentions the correct KAT in the output.
17
18set -x
19set -e
20
21TEST_FIPS_BIN="build/test_fips"
22
23if [ ! -f $TEST_FIPS_BIN ]; then
24  echo "$TEST_FIPS_BIN is missing. Run this script from the top level of a"
25  echo "BoringSSL checkout and ensure that ./build-fips-break-test-binaries.sh"
26  echo "has been run first."
27  exit 1
28fi
29
30KATS=$(go run util/fipstools/break-kat.go --list-tests)
31
32for kat in $KATS; do
33  go run util/fipstools/break-kat.go $TEST_FIPS_BIN $kat > break-kat-bin
34  chmod u+x ./break-kat-bin
35  if ! (./break-kat-bin 2>&1 >/dev/null || true) | \
36       egrep -q "^$kat[^a-zA-Z0-9]"; then
37    echo "Failure for $kat did not mention that name in the output"
38    exit 1
39  fi
40  rm ./break-kat-bin
41done
42