~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-tpm2/bin/test_tpm2_rsadecrypt.sh

  • Committer: Sylvain Pineau
  • Author(s): Sylvain Pineau
  • Date: 2016-05-09 22:02:27 UTC
  • mfrom: (4323.2.1 launchpad/tpm2-provider)
  • Revision ID: sylvain_pineau-20160509220227-wt2e8boo9ktitvzl
"automatic merge of lp:~sylvain-pineau/checkbox/tpm2-provider/ by tarmac [r=sylvain-pineau][bug=][author=sylvain-pineau]"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
new_path=`pwd`
 
3
PATH="$PATH":"$new_path"
 
4
 
 
5
file_primary_key_ctx=context.p_B1
 
6
file_rsaencrypt_key_pub=opuB1_B8
 
7
file_rsaencrypt_key_priv=oprB1_B8
 
8
file_rsaencrypt_key_ctx=context_loadext_out_B1_B8
 
9
file_rsadecrypt_key_ctx=context_load_out_B1_B8
 
10
file_rsaencrypt_key_name=name.load.B1_B8
 
11
 
 
12
file_rsa_en_output_data=rsa_en.out 
 
13
file_rsa_de_output_data=rsa_de.out
 
14
file_input_data=secret.data 
 
15
  
 
16
alg_hash=0x000B
 
17
alg_primary_key=0x0001
 
18
alg_rsaencrypt_key=0x0001
 
19
 
 
20
if [ ! -e "$file_input_data" ]   
 
21
  then    
 
22
echo "12345678" > $file_input_data
 
23
fi 
 
24
rm $file_primary_key_ctx $file_rsaencrypt_key_pub $file_rsaencrypt_key_priv $file_rsaencrypt_key_ctx $file_rsaencrypt_key_name $file_output_data $file_rsa_en_output_data $file_rsa_de_output_data -rf
 
25
 
 
26
tpm2_takeownership -c
 
27
 
 
28
tpm2_createprimary -A e -g $alg_hash -G $alg_primary_key -C $file_primary_key_ctx
 
29
if [ $? != 0 ];then
 
30
echo "createprimary fail, please check the environment or parameters!"
 
31
exit 1
 
32
fi
 
33
tpm2_create -g $alg_hash -G $alg_rsaencrypt_key -o $file_rsaencrypt_key_pub -O $file_rsaencrypt_key_priv  -c $file_primary_key_ctx
 
34
if [ $? != 0 ];then
 
35
echo "create fail, please check the environment or parameters!"
 
36
exit 1
 
37
fi
 
38
tpm2_loadexternal -H n   -u $file_rsaencrypt_key_pub  -C $file_rsaencrypt_key_ctx
 
39
if [ $? != 0 ];then
 
40
echo "loadexternal fail, please check the environment or parameters!"
 
41
exit 1
 
42
fi
 
43
tpm2_rsaencrypt -c $file_rsaencrypt_key_ctx -I $file_input_data -o $file_rsa_en_output_data 
 
44
if [ $? != 0 ];then
 
45
echo "rsa encrypt fail, please check the environment or parameters!"
 
46
exit 1
 
47
fi
 
48
 
 
49
tpm2_load -c $file_primary_key_ctx -u $file_rsaencrypt_key_pub -r $file_rsaencrypt_key_priv  -n $file_rsaencrypt_key_name  -C $file_rsadecrypt_key_ctx 
 
50
if [ $? != 0 ];then
 
51
echo "load fail, please check the environment or parameters!"
 
52
exit 1
 
53
fi
 
54
 
 
55
tpm2_rsadecrypt -c $file_rsadecrypt_key_ctx  -I  $file_rsa_en_output_data -o  $file_rsa_de_output_data
 
56
if [ $? != 0 ];then
 
57
echo "rsa decrypt fail, please check the environment or parameters!"
 
58
exit 1
 
59
fi