xref: /netbsd-src/crypto/external/bsd/heimdal/dist/lib/hcrypto/test_crypto.in (revision b9d004c6cc8d38329417ae29768c81e5f2a296cf)
1ca1c9b0cSelric#!/bin/sh
2ca1c9b0cSelric#
3ca1c9b0cSelric# Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
4ca1c9b0cSelric# (Royal Institute of Technology, Stockholm, Sweden).
5ca1c9b0cSelric# All rights reserved.
6ca1c9b0cSelric#
7ca1c9b0cSelric# Redistribution and use in source and binary forms, with or without
8ca1c9b0cSelric# modification, are permitted provided that the following conditions
9ca1c9b0cSelric# are met:
10ca1c9b0cSelric#
11ca1c9b0cSelric# 1. Redistributions of source code must retain the above copyright
12ca1c9b0cSelric#    notice, this list of conditions and the following disclaimer.
13ca1c9b0cSelric#
14ca1c9b0cSelric# 2. Redistributions in binary form must reproduce the above copyright
15ca1c9b0cSelric#    notice, this list of conditions and the following disclaimer in the
16ca1c9b0cSelric#    documentation and/or other materials provided with the distribution.
17ca1c9b0cSelric#
18ca1c9b0cSelric# 3. Neither the name of the Institute nor the names of its contributors
19ca1c9b0cSelric#    may be used to endorse or promote products derived from this software
20ca1c9b0cSelric#    without specific prior written permission.
21ca1c9b0cSelric#
22ca1c9b0cSelric# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23ca1c9b0cSelric# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ca1c9b0cSelric# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ca1c9b0cSelric# ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26ca1c9b0cSelric# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ca1c9b0cSelric# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ca1c9b0cSelric# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ca1c9b0cSelric# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ca1c9b0cSelric# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ca1c9b0cSelric# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ca1c9b0cSelric# SUCH DAMAGE.
33ca1c9b0cSelric#
34b40995a4Selric# Id
35ca1c9b0cSelric#
36ca1c9b0cSelric
37ca1c9b0cSelricsrcdir="@srcdir@"
38ca1c9b0cSelric
39ca1c9b0cSelricrsa="${TESTS_ENVIRONMENT} ./test_rsa@exeext@"
40ca1c9b0cSelricengine="${TESTS_ENVIRONMENT} ./test_engine_dso@exeext@"
41ca1c9b0cSelricrand="${TESTS_ENVIRONMENT} ./test_rand@exeext@"
42ca1c9b0cSelric
43ca1c9b0cSelric${engine} --test-random > /dev/null || { echo "missing random"; exit 77; }
44ca1c9b0cSelric
45ca1c9b0cSelric${rsa} --key=${srcdir}/rsakey.der || \
46ca1c9b0cSelric	{ echo "rsa test failed" ; exit 1; }
47ca1c9b0cSelric
48ca1c9b0cSelric${rsa} --time-key=${srcdir}/rsakey.der || \
49ca1c9b0cSelric	{ echo "rsa test failed" ; exit 1; }
50ca1c9b0cSelric
51ca1c9b0cSelric${rsa} --time-key=${srcdir}/rsakey2048.der || \
52ca1c9b0cSelric	{ echo "rsa test failed" ; exit 1; }
53ca1c9b0cSelric
54ca1c9b0cSelric${rsa} --time-key=generate || \
55ca1c9b0cSelric	{ echo "rsa test failed" ; exit 1; }
56ca1c9b0cSelric
57ca1c9b0cSelric${engine} --rsa=${srcdir}/rsakey.der || \
58ca1c9b0cSelric	{ echo "engine test failed" ; exit 1; }
59ca1c9b0cSelric
60ca1c9b0cSelric${rsa} --loops=4 || { echo "rsa test for 4 loops failed" ; exit 1; }
61ca1c9b0cSelric
62ca1c9b0cSelricfor a in unix fortuna egd w32crypto ;do
63ca1c9b0cSelric	${rand} --method=${a} --file=crypto-test 2>error
64ca1c9b0cSelric	res=$?
65ca1c9b0cSelric	if test "X$res" != X0 ; then
66ca1c9b0cSelric            grep "unknown method" error && \
67ca1c9b0cSelric                { echo "random $a is not available" ; continue; }
68ca1c9b0cSelric	    grep "random not ready yet" error || \
69ca1c9b0cSelric		{ echo "random $a ready failing" ; cat error; exit 1; }
70ca1c9b0cSelric	    echo "random method $a out for lunch"
71ca1c9b0cSelric	    continue
72ca1c9b0cSelric	fi
73ca1c9b0cSelric	${rand} --method=${a} --file=crypto-test2 2>error
74ca1c9b0cSelric	res=$?
75ca1c9b0cSelric	if test "X$res" != X0 ; then
76ca1c9b0cSelric	    grep "random not ready yet" error || \
77ca1c9b0cSelric		{ echo "random $a ready failing" ; cat error; exit 1; }
78ca1c9b0cSelric	    echo "random metod $a out for dinner"
79ca1c9b0cSelric	    continue
80ca1c9b0cSelric	fi
814f77a458Spettai	cmp crypto-test crypto-test2 >/dev/null 2>/dev/null && \
824f77a458Spettai	    { echo "rand output same!" ; exit 1; }
83ca1c9b0cSelricdone
84ca1c9b0cSelric
85ca1c9b0cSelric./example_evp_cipher 1 ${srcdir}/test_crypto.in test-out-1 || \
86ca1c9b0cSelric    { echo "1 failed" ; exit 1; }
87ca1c9b0cSelric
88ca1c9b0cSelricfor a in 7 15 16 17 31 32 33 ; do
89ca1c9b0cSelric    ./example_evp_cipher $a ${srcdir}/test_crypto.in test-out-$a
90ca1c9b0cSelric    cmp test-out-1 test-out-$a || { echo "cmp $a failed" ; exit 1; }
91ca1c9b0cSelricdone
92ca1c9b0cSelric
93ca1c9b0cSelric#
94ca1c9b0cSelric# Last time we run is w/o HOME and RANDFILE to make sure we can do
95*b9d004c6Schristos# RAND_file_name() when the environment is lacking those.
96ca1c9b0cSelric#
97ca1c9b0cSelric
984f77a458Spettaiif [ -r /dev/random -o -r /dev/urandom -o -r /dev/srandom -o -r /dev/arandom ] ; then
99ca1c9b0cSelric
100ca1c9b0cSelric    # try hard to unset HOME and RANDFILE
101ca1c9b0cSelric    HOME=
102ca1c9b0cSelric    RANDFILE=
103ca1c9b0cSelric
104ca1c9b0cSelric    unset HOME
105ca1c9b0cSelric    unset RANDFILE
106ca1c9b0cSelric
107ca1c9b0cSelric    ${rand} --method=unix --file=unix 2>error
108ca1c9b0cSelric    res=$?
109ca1c9b0cSelric    if test "X$res" != X0 ; then
110ca1c9b0cSelric        grep "unknown method" error && \
111ca1c9b0cSelric        { echo "random unix is not available"; exit 0; }
112ca1c9b0cSelric        grep "random not ready yet" error || \
113ca1c9b0cSelric    	{ echo "random unix ready failing" ; cat error; exit 1; }
114ca1c9b0cSelric        echo "random method unix out for lunch"
115ca1c9b0cSelric        continue
116ca1c9b0cSelric    fi
117ca1c9b0cSelric
118ca1c9b0cSelricfi
119ca1c9b0cSelric
120ca1c9b0cSelricexit 0
121