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