Skip to content

Commit

Permalink
Teach aes.py to work with Python 3.x; updated osx-ramfs to work with
Browse files Browse the repository at this point in the history
newer OS X versions; updated hexlify to also output C like arrays
  • Loading branch information
[email protected] committed Feb 3, 2017
1 parent 8f8f380 commit 6725141
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 147 deletions.
60 changes: 48 additions & 12 deletions aes-test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#! /bin/bash
#! /usr/bin/env bash

# Self tests for aes.py
# Author: Sudhi Herle
# License: Public Domain

AES=./aes.py
#AES='python3.4 ./aes.py'

uname=`uname`
case $uname in
Linux) MD5=md5sum ;;
Darwin|OpenBSD) MD5='md5 -q' ;;

*) echo "$0: Don't know how to do md5 on $uname" 1>&2
exit 1
;;
esac

begin() {
echo -n "$@"
Expand All @@ -18,8 +29,8 @@ xverify() {
local inf=$1
local dec=$2

local a=`md5sum $inf| awk '{print $1}'`
local b=`md5sum $dec| awk '{print $1}'`
local a=`$MD5 $inf| awk '{print $1}'`
local b=`$MD5 $dec| awk '{print $1}'`
if [ $a != $b ]; then
end "Fail"
else
Expand All @@ -42,34 +53,59 @@ testsz() {
fi

begin "Testing file $sz .."
FX=abcdef $AES -e -k FX $inf -o $enc
FX=abcdef $AES -d -k FX $enc -o $dec
xverify $inf $dec
FX=abcdef $AES -e -k FX $inf -o $enc || exit 1
FX=abcdef $AES -d -k FX $enc -o $dec || exit 1
xverify $inf $dec || exit 1

begin "Testing inplace $sz .."
cp $inf $enc
FX=abcdef $AES -e -k FX $enc -o $enc
FX=abcdef $AES -e -k FX $enc -o $enc || exit 1

cp $enc $dec
FX=abcdef $AES -d -k FX $dec -o $dec
xverify $inf $dec
FX=abcdef $AES -d -k FX $dec -o $dec || exit 1
xverify $inf $dec || exit 1


begin "Testing stdio $sz .."
FX=abcdef $AES -e -k FX < $inf > $enc
FX=abcdef $AES -d -k FX < $enc > $dec
xverify $inf $dec
FX=abcdef $AES -e -k FX < $inf > $enc || exit 1
FX=abcdef $AES -d -k FX < $enc > $dec || exit 1
xverify $inf $dec || exit 1


rm -f $inf $enc $dec
}

# Generate random ints between [100, 100000)
randsz() {
local x=101
local y=100000
local r=$(( $y - $x + 1))
local n=0

while true; do
n=$(( $RANDOM * $RANDOM ))
n=$(( $n % $r ))
n=$(( $x + $n ))
if [ $n -gt 0 ]; then
echo $n
return 0
fi
done
}


trap 'exit 0' INT TERM QUIT

# Test various sizes
for s in 0 1 2 3 4 8 16 128 512 4096 16384 1048576
do
testsz $s
done

# Test random sizes
n=8
while [ $n -gt 0 ]; do
n=$(( $n - 1 ))
testsz $(randsz)
done

Loading

0 comments on commit 6725141

Please sign in to comment.