#!/bin/bash
#
# Test pkcs15-init
#
# Run this from the regression test directory.

. functions

p15_init --no-so-pin
p15_set_pin -a 01
p15_gen_key rsa/1024 -a 01 --key-usage sign
p15_exp_key key.pem

echo lalla > $p15temp/message

msg "Digesting the message"
run_check_status openssl dgst -sha1 \
	-binary -out $p15temp/sha1value \
	$p15temp/message 

msg "Signing message (with key)"
run_check_status $p15crypt --sign --sha-1 --pkcs1 \
	--input $p15temp/sha1value \
	--output $p15temp/signature \
	--pin 0000

msg "Verifying message (with software)"
run_check_output "Verified OK" openssl dgst -sha1 \
	-verify $p15temp/key.pem  \
	-signature $p15temp/signature \
	$p15temp/message  

success

p15_erase --secret @01=0000
