]>
Commit | Line | Data |
---|---|---|
2e9ab56e P |
1 | #! /usr/bin/env perl |
2 | # Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. | |
3 | # | |
4 | # Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | # this file except in compliance with the License. You can obtain a copy | |
6 | # in the file LICENSE in the source distribution or at | |
7 | # https://www.openssl.org/source/license.html | |
8 | ||
9 | ||
10 | use strict; | |
11 | use warnings; | |
12 | ||
13 | use OpenSSL::Test; | |
14 | use OpenSSL::Test::Utils; | |
15 | ||
16 | setup("test_rand_config"); | |
17 | ||
18 | my @rand_tests = ( | |
19 | { drbg => 'HASH-DRBG', | |
20 | digest => 'SHA2-512/256', | |
21 | properties => '', | |
22 | expected => ["HASH-DRBG", "digest: 'SHA2-512/256'"], | |
23 | desc => 'HASH-DRBG SHA2-512/256' }, | |
24 | ||
25 | { drbg => 'HASH-DRBG', | |
26 | digest => 'SHA3-256', | |
27 | properties => '', | |
28 | expected => ["HASH-DRBG", "digest: 'SHA3-512'"], | |
29 | desc => 'HASH-DRBG SHA3/512' }, | |
30 | ||
31 | { drbg => 'HMAC-DRBG', | |
32 | digest => 'SHA3-256', | |
33 | properties => '', | |
34 | expected => ["HMAC-DRBG", "mac: HMAC", "digest: 'SHA3-256'"], | |
35 | desc => 'HMAC-DRBG SHA3/256' }, | |
36 | ||
37 | { cipher => 'AES-128-CTR', | |
38 | expected => ["CTR-DRBG", "cipher: 'AES-128-CTR'"], | |
39 | desc => 'CTR-DRBG AES-128 no DRBG' }, | |
40 | { expected => ["CTR-DRBG", "cipher: 'AES-256-CTR'"], | |
41 | desc => 'CTR-DRBG AES-256 defaults' }, | |
42 | ); | |
43 | ||
44 | my @aria_tests = ( | |
45 | { drbg => 'CTR-DRBG', | |
46 | cipher => 'ARIA-128-CTR', | |
47 | properties => '', | |
48 | expected => ["CTR-DRBG", "cipher: 'ARIA-128-CTR'"], | |
49 | desc => 'CTR-DRBG ARIA-128' }, | |
50 | ||
51 | { drbg => 'CTR-DRBG', | |
52 | cipher => 'ARIA-128-CTR', | |
53 | properties => '', | |
54 | expected => ["CTR-DRBG", "cipher: 'ARIA-128-CTR'"], | |
55 | desc => 'CTR-DRBG ARIA-256' }, | |
56 | ); | |
57 | ||
58 | push @rand_tests, @aria_tests unless disabled("aria"); | |
59 | ||
60 | plan tests => scalar @rand_tests; | |
61 | ||
62 | my $contents =<<'CONFIGEND'; | |
63 | openssl_conf = openssl_init | |
64 | ||
65 | [openssl_init] | |
66 | random = random_section | |
67 | ||
68 | [random_section] | |
69 | CONFIGEND | |
70 | ||
71 | foreach (@rand_tests) { | |
72 | my $tmpfile = 'rand_config.cfg'; | |
73 | open(my $cfg, '>', $tmpfile) or die "Could not open file"; | |
74 | print $cfg $contents; | |
75 | if ($_->{drbg}) { | |
76 | print $cfg "random = $_->{drbg}\n"; | |
77 | } | |
78 | if ($_->{cipher}) { | |
79 | print $cfg "cipher = $_->{cipher}\n"; | |
80 | } | |
81 | if ($_->{digest}) { | |
82 | print $cfg "digest = $_->{digest}\n" | |
83 | } | |
84 | close $cfg; | |
85 | ||
86 | $ENV{OPENSSL_CONF} = $tmpfile; | |
87 | ||
88 | ok(comparelines($_->{expected}), $_->{desc}); | |
89 | } | |
90 | ||
91 | # Check that the stdout output contains the expected values. | |
92 | sub comparelines { | |
93 | my @lines = run(app(["openssl", "list", "--random-instances"]), | |
94 | capture => 1); | |
95 | ||
96 | foreach (@_) { | |
97 | if ( !grep( /$_/, @lines ) ) { | |
98 | print "Cannot find: $_\n"; | |
99 | return 0; | |
100 | } | |
101 | } | |
102 | return 1; | |
103 | } |