1 1.1 christos #! /usr/bin/env perl 2 1.1 christos # Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos # 4 1.1 christos # Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos # this file except in compliance with the License. You can obtain a copy 6 1.1 christos # in the file LICENSE in the source distribution or at 7 1.1 christos # https://www.openssl.org/source/license.html 8 1.1 christos 9 1.1 christos 10 1.1 christos use strict; 11 1.1 christos use warnings; 12 1.1 christos 13 1.1 christos use File::Spec; 14 1.1 christos use File::Basename; 15 1.1 christos use OpenSSL::Test qw/:DEFAULT with srctop_file bldtop_dir/; 16 1.1 christos use OpenSSL::Test::Utils; 17 1.1 christos 18 1.1 christos setup("test_speed"); 19 1.1 christos 20 1.1 christos plan tests => 25; 21 1.1 christos 22 1.1 christos ok(run(app(['openssl', 'speed', '-testmode'])), 23 1.1 christos "Simple test of all speed algorithms"); 24 1.1 christos 25 1.1 christos #Test various options to speed. In all cases we use the -testmode option to 26 1.1 christos #ensure we don't spend too long in this test. That option also causes the speed 27 1.1 christos #app to return an error code if anything unexpectedly goes wrong. 28 1.1 christos 29 1.1 christos 30 1.1 christos SKIP: { 31 1.1 christos skip "Multi option is not supported by this OpenSSL build", 1 32 1.1 christos if $^O =~ /^(VMS|MSWin32)$/; 33 1.1 christos 34 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-multi', 2])), 35 1.1 christos "Test the multi option"); 36 1.1 christos } 37 1.1 christos 38 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-misalign', 1])), 39 1.1 christos "Test the misalign option"); 40 1.1 christos 41 1.1 christos SKIP: { 42 1.1 christos skip "Multiblock is not supported by this OpenSSL build", 1 43 1.1 christos if disabled("multiblock") 44 1.1 christos # The AES-128-CBC-HMAC-SHA1 cipher isn't available on all platforms 45 1.1 christos # We test its availability without the "-mb" option. We only do the 46 1.1 christos # multiblock test via "-mb" if the cipher seems to exist. 47 1.1 christos || !run(app(['openssl', 'speed', '-testmode', '-evp', 48 1.1 christos 'AES-128-CBC-HMAC-SHA1'])); 49 1.1 christos 50 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-mb', '-evp', 51 1.1 christos 'AES-128-CBC-HMAC-SHA1'])), 52 1.1 christos "Test the EVP and mb options"); 53 1.1 christos } 54 1.1 christos 55 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-kem-algorithms'])), 56 1.1 christos "Test the kem-algorithms option"); 57 1.1 christos 58 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-signature-algorithms'])), 59 1.1 christos "Test the signature-algorithms option"); 60 1.1 christos 61 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-primes', 3, 'rsa1024'])), 62 1.1 christos "Test the primes option"); 63 1.1 christos 64 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-mr'])), 65 1.1 christos "Test the mr option"); 66 1.1 christos 67 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-decrypt', '-evp', 'aes-128-cbc'])), 68 1.1 christos "Test the decrypt and evp options"); 69 1.1 christos 70 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-evp', 'sha256'])), 71 1.1 christos "Test the evp option with a digest"); 72 1.1 christos 73 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-hmac', 'sha256'])), 74 1.1 christos "Test the hmac option"); 75 1.1 christos 76 1.1 christos SKIP: { 77 1.1 christos skip "CMAC is not supported by this OpenSSL build", 1 78 1.1 christos if disabled("cmac"); 79 1.1 christos 80 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-cmac', 'aes-128-cbc'])), 81 1.1 christos "Test the cmac option"); 82 1.1 christos } 83 1.1 christos 84 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-aead', '-evp', 'aes-128-gcm'])), 85 1.1 christos "Test the aead and evp options"); 86 1.1 christos 87 1.1 christos SKIP: { 88 1.1 christos skip "ASYNC/threads not supported by this OpenSSL build", 1 89 1.1 christos if disabled("async") || disabled("threads"); 90 1.1 christos 91 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-async_jobs', '1'])), 92 1.1 christos "Test the async_jobs option"); 93 1.1 christos } 94 1.1 christos 95 1.1 christos SKIP: { 96 1.1 christos skip "Mlock option is not supported by this OpenSSL build", 1 97 1.1 christos if $^O !~ /^(linux|MSWin32)$/; 98 1.1 christos 99 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-mlock'])), 100 1.1 christos "Test the mlock option"); 101 1.1 christos } 102 1.1 christos 103 1.1 christos #We don't expect these options to have an effect in testmode but we at least 104 1.1 christos #test that the option parsing works ok 105 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-seconds', 1, '-bytes', 16, 106 1.1 christos '-elapsed'])), 107 1.1 christos "Test the seconds, bytes and elapsed options"); 108 1.1 christos 109 1.1 christos #Test that this won't crash on sparc 110 1.1 christos ok(run(app(['openssl', 'speed', '-testmode', '-seconds', 1, '-bytes', 1, 111 1.1 christos 'aes-128-cbc'])), 112 1.1 christos "Test that bad bytes value doesn't make speed to crash"); 113 1.1 christos 114 1.1 christos #No need to -testmode for testing -help. All we're doing is testing the option 115 1.1 christos #parsing. We don't sanity check the output 116 1.1 christos ok(run(app(['openssl', 'speed', '-help'])), 117 1.1 christos "Test the help option"); 118 1.1 christos 119 1.1 christos #Now test some invalid options. The speed app should fail 120 1.1 christos ok(!run(app(['openssl', 'speed', 'blah'])), 121 1.1.1.2 christos "Test an unknown algorithm"); 122 1.1 christos 123 1.1 christos ok(!run(app(['openssl', 'speed', '-evp', 'blah'])), 124 1.1 christos "Test a unknown evp algorithm"); 125 1.1 christos 126 1.1 christos ok(!run(app(['openssl', 'speed', '-hmac', 'blah'])), 127 1.1 christos "Test a unknown hmac algorithm"); 128 1.1 christos 129 1.1 christos ok(!run(app(['openssl', 'speed', '-cmac', 'blah'])), 130 1.1 christos "Test a unknown cmac algorithm"); 131 1.1 christos 132 1.1 christos ok(!run(app(['openssl', 'speed', '-async_jobs', 100000])), 133 1.1 christos "Test an invalid number of async_jobs"); 134 1.1 christos 135 1.1 christos ok(!run(app(['openssl', 'speed', '-misalign', 65])), 136 1.1 christos "Test an invalid misalign number"); 137 1.1 christos 138 1.1 christos SKIP: { 139 1.1 christos skip "Multiblock is not supported by this OpenSSL build", 1 140 1.1 christos if disabled("multiblock"); 141 1.1 christos 142 1.1 christos ok(!run(app(['openssl', 'speed', '-testmode', '-mb', '-evp', 143 1.1 christos 'AES-128-CBC'])), 144 1.1 christos "Test a non multiblock cipher with -mb"); 145 1.1 christos } 146