#!/bin/bash # opensslEncTime - Quick bench about performances cost of iteration's encryption # Comparison of time to encrypt 64 bytes or 1Mb, with 1 to 1'000'000 iterations # Version: 0.0.40 -- Last update: Mon Mar 23 15:17:02 2026 # (C) 2025-2026 Felix Hauri - felix@f-hauri.ch # openSslOpt=( -aes-256-cbc -pbkdf2 ) # No arguments required. # There are two function: `texte` will dump a 64 bytes text string and `image` # will dump an 1 megabytes jpeg image. # main will first compute sha1sums of both `image` and `texte`, then for each # texte and image, will run openssl encrypt | openssl decrypt | sha1sum, and # compare result. Operation of encryption / decryption will be repeated 15 time # and shortest execution time will be printed out. The main script run this # both operation successively with number of iteration set to 1, 10, 100, 1'000, # 10'000, 100'000 and 1'000'000. main() { local pass sums oper size ms rMsg local -i iter i ns l stime set -- {a..z} {0..9} {A..Z} + - / _ \# . , \; \! \( \) \{ \} printf -v pass %s "${*:RANDOM%$#+1:1}"{,,,,,,}{,,} oper=( texte image ) for i in ${!oper[@]}; do read -r sums[i] _ < <(exec sha1sum < <( ${oper[i]} ) ) read -r l _ < <(wc -c < <( ${oper[i]} ) ) txsz $l "size[$i]" # size[i]=${size[i]/.00b/b} done exec {encFd}<> <(:) exec {decFd}<> <(:) for iter in 1 10 100 1000 10000 100000 1000000; do for i in ${!oper[@]}; do stime=() for l in {1..15}; do # run 15x same in order to reach quickest echo "$pass" >&$encFd echo "$pass" >&$decFd ns=-${EPOCHREALTIME/.} read sha _ < <( exec openssl enc -d -a "${openSslOpt[@]}" -iter $iter -in <( exec openssl enc -a "${openSslOpt[@]}" -iter $iter < <( ${oper[i]} ) -pass fd:$encFd ) -pass fd:$decFd | sha1sum ) ns+=${EPOCHREALTIME/.} stime[ns]='' done stime=(${!stime[@]}) # sorted array ms=00${stime[0]} # quickest operation if [[ $sha == "${sums[i]}" ]]; then rMsg="match, Ok!" else rMsg="don't match!!" fi printf 'Sums %s:%6s %8s: %8.2fms -> %s\n' "${oper[i]}" \ "${size[i]}" $iter ${ms::-3}.${ms: -3} "$rMsg" done done exec {encFd}>&- exec {decFd}>&- } txsz(){ local i=$(($1>=1<<50?5:$1>=1<<40?4:$1>=1<<30?3:$1>=1<<20?2:$1>1023?1:0 )) a=(b K M G T P);((i>4?i+=-2:0))&&a=(${a[@]:2})&&set -- $(($1>>20)) $2;local\ r=00$((1000*$1/(1024**i)));if ((i));then printf -v "$2" %.2f%s ${r::-3}.${r: -3} ${a[i]};else printf -v "$2" %.0f%s ${r::-3} ${a[i]};fi;} texte() { echo "This simple text phrase is a sixty-four characters text string!" } image() { base64 -d <