summaryrefslogtreecommitdiff
path: root/tests/futility/test_show_rwsig.sh
blob: 7ff255717480ed4276d1a9c06e6941690f29761e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash -eux
# Copyright 2017 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

me=${0##*/}
TMP="$me.tmp"

# Work in scratch directory
cd "$OUTDIR"

DATADIR="${SCRIPTDIR}/data"
TESTKEYS=${SRCDIR}/tests/testkeys

# Do not test 8192 as the signature length is > 1024 bytes
SIGS="1024 2048 4096"
HASHES="SHA1 SHA256 SHA512"

set -o pipefail

for s in $SIGS; do
    echo -n "$s " 1>&3

    for h in $HASHES; do
        pemfile=${TESTKEYS}/key_rsa${s}.pem
        outfile=${TMP}.${s}_${h}.new
        infile=${DATADIR}/random_noise.bin
        outkeys=${TMP}.${s}_${h}
        outsig=${TMP}.${s}_${h}.signature

        ${FUTILITY} create --desc "Test key" --hash_alg ${h} \
                    ${pemfile} ${outkeys}

        ${FUTILITY} sign --type rwsig --prikey ${outkeys}.vbprik2 \
                ${infile} ${outsig}
        dd if=/dev/zero bs=$((4096 + 1024)) count=1 of=${outfile}
        dd if=${infile} of=${outfile} conv=notrunc
        dd if=${outsig} of=${outfile} bs=4096 seek=1 conv=notrunc

        ${FUTILITY} show --type rwsig --pubkey ${outkeys}.vbpubk2 ${outfile}
    done
done

# cleanup
rm -rf ${TMP}*
exit 0