Skip to content

Commit

Permalink
Added test script for RSA Encrypt/Decrypt concurrency test using Trus…
Browse files Browse the repository at this point in the history
…t M provider (#75)

1)Added more debugging message printout

2)Added test script for RSA Encrypt/Decrypt concurrency test using Trust M provider

3)updated the dependency
  • Loading branch information
ying-css authored Nov 6, 2024
1 parent afcb99a commit 873ab8a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
source config.sh

echo "input1" >mydata1.txt
echo "input2" >mydata2.txt

for i in $(seq 1 5); do
echo "$(date +'%m/%d:%r') --------------> test $i"
set +e
rm *.enc
rm *.dec
set -e
echo "-----> Encrypt with public key using Trust M provider"
openssl pkeyutl -provider trustm_provider -inkey 0xe0fd:^ -encrypt -in mydata1.txt -out mydata1.enc &
P1=$!
echo "-----> Encrypt with public key using Trust M provider"
openssl pkeyutl -provider trustm_provider -inkey 0xe0fd:^ -encrypt -in mydata2.txt -out mydata2.enc &
P2=$!

wait $P1 $P2

echo "-----> Decrypt with private key using Trust M provider"
openssl pkeyutl -provider trustm_provider -inkey 0xe0fd:^ -decrypt -in mydata1.enc -out mydata1.dec &
P1=$!
echo "-----> Decrypt with private key using Trust M provider"
openssl pkeyutl -provider trustm_provider -inkey 0xe0fd:^ -decrypt -in mydata2.enc -out mydata2.dec &
P2=$!

wait $P1 $P2
done

2 changes: 1 addition & 1 deletion provider_installation_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


sudo apt update
sudo apt -y install git gcc libssl-dev
sudo apt -y install git gcc libssl-dev gpiod libgpiod-dev


set -e
Expand Down
2 changes: 1 addition & 1 deletion trustm_provider/trustm_keymgmt_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static void *trustm_rsa_keymgmt_gen(void *ctx, OSSL_CALLBACK *cb, void *cbarg)

if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_rsa_generate_keypair\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_rsa_generate_keypair\nError code : 0x%.4X\n", return_status);
OPENSSL_clear_free(trustm_rsa_key, sizeof(trustm_rsa_key_t));
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions trustm_provider/trustm_provider_asym_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int rsa_asymcipher_encrypt(void *ctx, unsigned char *out, size_t *outlen,

optiga_lib_status_t return_status;
public_key_from_host_t public_key_from_host;

TRUSTM_PROVIDER_DBGFN(">");
TRUSTM_PROVIDER_SSL_MUTEX_ACQUIRE

Expand All @@ -99,7 +99,7 @@ static int rsa_asymcipher_encrypt(void *ctx, unsigned char *out, size_t *outlen,
&trustm_rsa_asymcipher_ctx->encrypted_message_length);
if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_rsa_encrypt_message");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_rsa_encrypt_message\nError code : 0x%.4X\n", return_status);
TRUSTM_PROVIDER_SSL_MUTEX_RELEASE;
return 0;
}
Expand Down
7 changes: 1 addition & 6 deletions trustm_provider/trustm_provider_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,10 @@
*/
//#define TRUSTM_PROVIDER_SSL_MUTEX_ACQUIRE trustmProvider_SSLMutex_Acquire();
//#define TRUSTM_PROVIDER_SSL_MUTEX_RELEASE trustmProvider_SSLMutex_Release();
#ifdef TRUSTM_PROVIDER_DEBUG
#define TRUSTM_PROVIDER_SSL_MUTEX_ACQUIRE TRUSTM_PROVIDER_DBGFN(">");trustmProvider_App_Open_Recovery();
#define TRUSTM_PROVIDER_SSL_MUTEX_RELEASE TRUSTM_PROVIDER_DBGFN("<");trustmProvider_App_Release();
#else

#define TRUSTM_PROVIDER_SSL_MUTEX_ACQUIRE trustmProvider_App_Open_Recovery();
#define TRUSTM_PROVIDER_SSL_MUTEX_RELEASE trustmProvider_App_Release();

#endif

#ifdef TRUST_ENG_CLOSE_APP_ENABLE
#define TRUSTM_PROVIDER_APP_CLOSE trustmProvider_App_Close();
#else
Expand Down
18 changes: 9 additions & 9 deletions trustm_provider/trustm_provider_signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static int trustm_rsa_signature_sign(void *ctx, unsigned char *sig, size_t *sigl

if (return_status != OPTIGA_LIB_SUCCESS)
{
TRUSTM_PROVIDER_ERRFN("Error signing in trustm_rsa_signature_sign\n");
TRUSTM_PROVIDER_ERRFN("Error signing in trustm_rsa_signature_sign\nError code : 0x%.4X\n", return_status);
return 0;
}

Expand Down Expand Up @@ -290,7 +290,7 @@ static int trustm_ecdsa_signature_sign(void *ctx, unsigned char *sig, size_t *si

if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error signing in optiga_crypt_ecdsa_sign\n");
TRUSTM_PROVIDER_ERRFN("Error signing in optiga_crypt_ecdsa_sign\nError code : 0x%.4X\n", return_status);
return 0;
}
// Wait until the optiga_util_read_metadata operation is completed
Expand Down Expand Up @@ -352,7 +352,7 @@ static int trustm_rsa_signature_digest_sign_init(void *ctx, const char *mdname,

if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_start\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_start\nError code : 0x%.4X\n", return_status);
return 0;
}

Expand Down Expand Up @@ -389,7 +389,7 @@ static int trustm_ecdsa_signature_digest_sign_init(void *ctx, const char *mdname

if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_start\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_start\nError code : 0x%.4X\n", return_status);
return 0;
}

Expand Down Expand Up @@ -430,7 +430,7 @@ static int trustm_rsa_signature_digest_sign_update(void *ctx, const unsigned cha

if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_update\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_update\nError code : 0x%.4X\n", return_status);
return 0;
}

Expand All @@ -450,7 +450,7 @@ static int trustm_rsa_signature_digest_sign_update(void *ctx, const unsigned cha

if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_finalize\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_hash_finalize\nError code : 0x%.4X\n", return_status);
return 0;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ static int trustm_rsa_signature_digest_sign_final(void *ctx, unsigned char *sig,
0x0000);
if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_rsa_sign\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_rsa_sign\nError code : 0x%.4X\n", return_status);
return 0;
}
// Wait until the optiga_util_read_metadata operation is completed
Expand Down Expand Up @@ -606,7 +606,7 @@ static int trustm_ecdsa_signature_digest_sign_final(void *ctx, unsigned char *si
&temp_siglen);
if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_ecdsa_sign\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_ecdsa_sign\nError code : 0x%.4X\n", return_status);
return 0;
}
// Wait until the optiga_util_read_metadata operation is completed
Expand Down Expand Up @@ -838,7 +838,7 @@ static int trustm_ecdsa_signature_digest_sign(void *ctx, unsigned char *sig, siz
&temp_siglen);
if (OPTIGA_LIB_SUCCESS != return_status)
{
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_ecdsa_sign\n");
TRUSTM_PROVIDER_ERRFN("Error in optiga_crypt_ecdsa_sign\nError code : 0x%.4X\n", return_status);
return 0;
}
// Wait until the optiga_util_read_metadata operation is completed
Expand Down

0 comments on commit 873ab8a

Please sign in to comment.