# -*- tcl -*- # sha256.test: tests for the sha256 commands # # This file contains a collection of tests for one or more of the Tcl # built-in commands. Sourcing this file into Tcl runs the tests and # generates output for errors. No output means no errors were found. # # RCS: @(#) $Id: sha256.test,v 1.6 2006/10/13 06:23:29 andreas_kupries Exp $ # ------------------------------------------------------------------------- source [file join \ [file dirname [file dirname [file join [pwd] [info script]]]] \ devtools testutilities.tcl] testsNeedTcl 8.2 testsNeedTcltest 1.0 testing { if {[useTcllibC]} { useLocalKeep sha256.tcl sha256 ::sha2 } else { useLocal sha256.tcl sha256 ::sha2 } TestAccelInit ::sha2 } # ------------------------------------------------------------------------- # Now the package specific tests.... # ------------------------------------------------------------------------- test sha256-1.0 {sha256 usage} { catch {::sha2::sha256} result set result } "wrong # args: should be \"::sha2::sha256 ?-hex|-bin? -filename file | -channel channel | string\"" test sha224-1.0 {sha224 usage} { catch {::sha2::sha224} result set result } "wrong # args: should be \"::sha2::sha224 ?-hex|-bin? -filename file | -channel channel | string\"" # ------------------------------------------------------------------------- # Digest # FIPS 180-2 test vectors SHA-256 set vectorsD \ [list \ "abc" \ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" \ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \ "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" \ [string repeat a 1000000] \ "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" ] # FIPS 180-2 test vectors SHA-224 set vectorsDT \ [list \ "abc" \ "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" \ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \ "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" \ [string repeat a 1000000] \ "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" ] # ------------------------------------------------------------------------- TestAccelDo sha2 impl { set n 0 foreach {msg hash} $vectorsD { test sha256-${impl}-2.$n {FIPS-180-2 test vectors for SHA-256} { list [catch {::sha2::sha256 $msg} r] $r } [list 0 $hash] ; # {} incr n } set n 0 foreach {msg hash} $vectorsDT { test sha224-${impl}-2.$n {FIPS-180-2 test vectors for SHA-224} { list [catch {::sha2::sha224 $msg} r] $r } [list 0 $hash] ; # {} incr n } } # ------------------------------------------------------------------------- TestAccelExit sha2 testsuiteCleanup # ------------------------------------------------------------------------- # Local Variables: # mode: tcl # indent-tabs-mode: nil # End: