summaryrefslogtreecommitdiffstats
path: root/third_party/heimdal/lib/hcrypto/test_crypto.in
blob: d5b3893164ab85de8ea30c7b20e896e2a2f877a7 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
#
# Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden). 
# All rights reserved. 
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions 
# are met: 
#
# 1. Redistributions of source code must retain the above copyright 
#    notice, this list of conditions and the following disclaimer. 
#
# 2. Redistributions in binary form must reproduce the above copyright 
#    notice, this list of conditions and the following disclaimer in the 
#    documentation and/or other materials provided with the distribution. 
#
# 3. Neither the name of the Institute nor the names of its contributors 
#    may be used to endorse or promote products derived from this software 
#    without specific prior written permission. 
#
# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
# ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
# SUCH DAMAGE. 
#
# $Id$
#

srcdir="@srcdir@"

rsa="${TESTS_ENVIRONMENT} ./test_rsa@exeext@"
engine="${TESTS_ENVIRONMENT} ./test_engine_dso@exeext@"
rand="${TESTS_ENVIRONMENT} ./test_rand@exeext@"

${engine} --test-random > /dev/null || { echo "missing random"; exit 77; }

${rsa} --key=${srcdir}/rsakey.der || \
	{ echo "rsa test failed" ; exit 1; }

${rsa} --time-key=${srcdir}/rsakey.der || \
	{ echo "rsa test failed" ; exit 1; }

${rsa} --time-key=${srcdir}/rsakey2048.der || \
	{ echo "rsa test failed" ; exit 1; }

${rsa} --time-key=generate || \
	{ echo "rsa test failed" ; exit 1; }

${engine} --rsa=${srcdir}/rsakey.der || \
	{ echo "engine test failed" ; exit 1; }

${rsa} --loops=4 || { echo "rsa test for 4 loops failed" ; exit 1; }

for a in unix fortuna egd w32crypto ;do
	${rand} --method=${a} --file=crypto-test 2>error
	res=$?
	if test "X$res" != X0 ; then
            grep "unknown method" error && \
                { echo "random $a is not available" ; continue; }
	    grep "random not ready yet" error || \
		{ echo "random $a ready failing" ; cat error; exit 1; }
	    echo "random method $a out for lunch"
	    continue
	fi
	${rand} --method=${a} --file=crypto-test2 2>error
	res=$?
	if test "X$res" != X0 ; then
	    grep "random not ready yet" error || \
		{ echo "random $a ready failing" ; cat error; exit 1; }
	    echo "random metod $a out for dinner"
	    continue
	fi
	cmp crypto-test crypto-test2 >/dev/null 2>/dev/null && \
	    { echo "rand output same!" ; exit 1; }
done

./example_evp_cipher 1 ${srcdir}/test_crypto.in test-out-1 || \
    { echo "1 failed" ; exit 1; }

for a in 7 15 16 17 31 32 33 ; do
    ./example_evp_cipher $a ${srcdir}/test_crypto.in test-out-$a
    cmp test-out-1 test-out-$a || { echo "cmp $a failed" ; exit 1; }
done

#
# Last time we run is w/o HOME and RANDFILE to make sure we can do
# RAND_file_name() when the environment is lacking those.
#

if [ -r /dev/random -o -r /dev/urandom -o -r /dev/srandom -o -r /dev/arandom ] ; then

    # try hard to unset HOME and RANDFILE
    HOME=
    RANDFILE=

    unset HOME
    unset RANDFILE

    ${rand} --method=unix --file=unix 2>error
    res=$?
    if test "X$res" != X0 ; then
        grep "unknown method" error && \
        { echo "random unix is not available"; exit 0; }
        grep "random not ready yet" error || \
    	{ echo "random unix ready failing" ; cat error; exit 1; }
        echo "random method unix out for lunch"
        continue
    fi

fi

exit 0