test_aesni 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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-ctr aes-128-ecb aes-128-cbc aes-128-cfb aes-128-ofb \
  17. aes-192-ctr aes-192-ecb aes-192-cbc aes-192-cfb aes-192-ofb \
  18. aes-256-ctr aes-256-ecb aes-256-cbc aes-256-cfb aes-256-ofb"
  19. BUFSIZE="16 32 48 64 80 96 128 144 999"
  20. nerr=0
  21. for alg in $AES_ALGS; do
  22. echo $alg
  23. for bufsize in $BUFSIZE; do
  24. TEST=`( cat $PROG | \
  25. $PROG enc -e -k "$HASH" -$alg -bufsize $bufsize -engine aesni | \
  26. $PROG enc -d -k "$HASH" -$alg | \
  27. $PROG dgst -hex ) 2>/dev/null`
  28. if [ "$TEST" != "$HASH" ]; then
  29. echo "-$alg/$bufsize encrypt test failed"
  30. nerr=`expr $nerr + 1`
  31. fi
  32. done
  33. for bufsize in $BUFSIZE; do
  34. TEST=`( cat $PROG | \
  35. $PROG enc -e -k "$HASH" -$alg | \
  36. $PROG enc -d -k "$HASH" -$alg -bufsize $bufsize -engine aesni | \
  37. $PROG dgst -hex ) 2>/dev/null`
  38. if [ "$TEST" != "$HASH" ]; then
  39. echo "-$alg/$bufsize decrypt test failed"
  40. nerr=`expr $nerr + 1`
  41. fi
  42. done
  43. TEST=`( cat $PROG | \
  44. $PROG enc -e -k "$HASH" -$alg -engine aesni | \
  45. $PROG enc -d -k "$HASH" -$alg -engine aesni | \
  46. $PROG dgst -hex ) 2>/dev/null`
  47. if [ "$TEST" != "$HASH" ]; then
  48. echo "-$alg en/decrypt test failed"
  49. nerr=`expr $nerr + 1`
  50. fi
  51. done
  52. if [ $nerr -gt 0 ]; then
  53. echo "AESNI engine test failed."
  54. exit 1;
  55. fi
  56. else
  57. echo "AESNI engine is not available"
  58. fi
  59. exit 0