test_aesni 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh
  2. PROG=$1
  3. if [ -x $PROG ]; then
  4. if expr "x`$PROG version`" : "xOpenSSL" > /dev/null; then
  5. :
  6. else
  7. echo "$PROG is not OpenSSL executable"
  8. exit 1
  9. fi
  10. else
  11. echo "$PROG is not executable"
  12. exit 1;
  13. fi
  14. if $PROG engine aesni | grep -v no-aesni; then
  15. HASH=`cat $PROG | $PROG dgst -hex`
  16. AES_ALGS=" aes-128-ecb aes-192-ecb aes-256-ecb \
  17. aes-128-cbc aes-192-cbc aes-256-cbc \
  18. aes-128-cfb aes-192-cfb aes-256-cfb \
  19. aes-128-ofb aes-192-ofb aes-256-ofb"
  20. BUFSIZE="16 32 48 64 80 96 128 144 999"
  21. nerr=0
  22. for alg in $AES_ALGS; do
  23. echo $alg
  24. for bufsize in $BUFSIZE; do
  25. TEST=`( cat $PROG | \
  26. $PROG enc -e -k "$HASH" -$alg -bufsize $bufsize -engine aesni | \
  27. $PROG enc -d -k "$HASH" -$alg | \
  28. $PROG dgst -hex ) 2>/dev/null`
  29. if [ "$TEST" != "$HASH" ]; then
  30. echo "-$alg/$bufsize encrypt test failed"
  31. nerr=`expr $nerr + 1`
  32. fi
  33. done
  34. for bufsize in $BUFSIZE; do
  35. TEST=`( cat $PROG | \
  36. $PROG enc -e -k "$HASH" -$alg | \
  37. $PROG enc -d -k "$HASH" -$alg -bufsize $bufsize -engine aesni | \
  38. $PROG dgst -hex ) 2>/dev/null`
  39. if [ "$TEST" != "$HASH" ]; then
  40. echo "-$alg/$bufsize decrypt test failed"
  41. nerr=`expr $nerr + 1`
  42. fi
  43. done
  44. TEST=`( cat $PROG | \
  45. $PROG enc -e -k "$HASH" -$alg -engine aesni | \
  46. $PROG enc -d -k "$HASH" -$alg -engine aesni | \
  47. $PROG dgst -hex ) 2>/dev/null`
  48. if [ "$TEST" != "$HASH" ]; then
  49. echo "-$alg en/decrypt test failed"
  50. nerr=`expr $nerr + 1`
  51. fi
  52. done
  53. if [ $nerr -gt 0 ]; then
  54. echo "AESNI engine test failed."
  55. exit 1;
  56. fi
  57. else
  58. echo "AESNI engine is not available"
  59. fi
  60. exit 0