mirror of
https://github.com/polhenarejos/pico-hsm.git
synced 2024-09-20 03:10:09 +00:00
Added AES pkcs11 tests.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
185d19504f
commit
654cb1e4e0
38
tests/scripts/aes.sh
Executable file
38
tests/scripts/aes.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./tests/scripts/func.sh
|
||||
reset
|
||||
test $? -eq 0 || exit $?
|
||||
|
||||
TEST_DATA="This is a text."
|
||||
|
||||
echo "${TEST_DATA}" > test
|
||||
|
||||
sc_tool() {
|
||||
pkcs11-tool --module /usr/local/lib/libsc-hsm-pkcs11.so -l --pin 648219 $@
|
||||
}
|
||||
|
||||
aeses=("16" "24" "32")
|
||||
|
||||
for aes in ${aeses[*]}; do
|
||||
echo " Test AES (AES:${aes})"
|
||||
echo -n " Keygen... "
|
||||
sc_tool --keygen --key-type "AES:${aes}" --id 1 --label "AES:${aes}" > /dev/null 2>&1
|
||||
test $? -eq 0 && echo -n "." || exit $?
|
||||
e=$(sc_tool --list-object --type secrkey 2>&1)
|
||||
test $? -eq 0 && echo -n "." || exit $?
|
||||
grep -q "AES length ${aes}" <<< $e && echo -n "." || exit $?
|
||||
grep -q "AES:${aes}" <<< $e && echo -e ".\t${OK}" || exit $?
|
||||
|
||||
echo -n " Encryption..."
|
||||
sc_tool --encrypt --id 1 --input-file test --mechanism aes-cbc > crypted.aes 2>/dev/null
|
||||
test $? -eq 0 && echo -e ".\t${OK}" || exit $?
|
||||
|
||||
echo -n " Decryption..."
|
||||
e=$(sc_tool --decrypt --id 1 --input-file crypted.aes --mechanism aes-cbc 2>/dev/null)
|
||||
test $? -eq 0 && echo -n "." || exit $?
|
||||
grep -q "${TEST_DATA}" <<< $e && echo -e ".\t${OK}" || exit $?
|
||||
|
||||
sc_tool --delete --type secrkey --id 1 > /dev/null 2>&1
|
||||
done
|
||||
rm -rf test crypted.aes
|
@ -35,3 +35,10 @@ test $? -eq 0 || {
|
||||
echo -e "\t${FAIL}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "==== Test AES ===="
|
||||
./tests/scripts/aes.sh
|
||||
test $? -eq 0 || {
|
||||
echo -e "\t${FAIL}"
|
||||
exit 1
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user