# -*- tcl -*-
# Tcl Benchmark File
#
# This file contains a number of benchmarks for the 'aes' module.
# This allow developers to monitor/gauge/track package performance.
#
# (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net>

# We need at least version 8.2 for the package and thus the
# benchmarks.

if {![package vsatisfies [package provide Tcl] 8.2]} {
    return
}

# ### ### ### ######### ######### ######### ###########################
## Setting up the environment ...

package forget aes
catch {namespace delete ::aes}
source [file join [file dirname [info script]] aes.tcl]

set i [binary format H* 00000000000000000000000000000000]
set p [binary format H* 00112233445566778899aabbccddeeff]

# ### ### ### ######### ######### ######### ###########################
## Benchmarks.

foreach {len k c} [list \
	128 \
	[binary format H* 000102030405060708090a0b0c0d0e0f] \
	[binary format H* 69c4e0d86a7b0430d8cdb78070b4c55a] \
	192 \
	[binary format H* 000102030405060708090a0b0c0d0e0f1011121314151617] \
	[binary format H* dda97ca4864cdfe06eaf70a0ec0d7191] \
	256 \
	[binary format H* 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f] \
	[binary format H* 8ea2b7ca516745bfeafc49904b496089] \
	] {

    bench -desc "AES-${len} ECB encryption" -body {
	aes::aes -mode ecb -dir enc -key $k -iv $i $p
    }

    bench -desc "AES-${len} ECB decryption" -body {
	aes::aes -mode ecb -dir dec -key $k -iv $i $c
    }

    bench -desc "AES-${len} ECB encryption core" -pre {
	set key [aes::Init ecb $k $i]
    } -body {
	aes::Encrypt $key $p
    } -post {
	aes::Final $key
    }

    bench -desc "AES-${len} ECB decryption core" -pre {
	set key [aes::Init ecb $k $i]
    } -body {
	aes::Decrypt $key $c
    } -post {
	aes::Final $key
    }

    bench -desc "AES-${len} ECB keyschedule" -body {
	aes::Final [aes::Init ecb $k $i]
    }

    bench -desc "AES-${len} CBC keyschedule" -body {
	aes::Final [aes::Init cbc $k $i]
    }
}

# ### ### ### ######### ######### ######### ###########################
## Complete
