Skip to content

Commit

Permalink
Minor code modification (#76)
Browse files Browse the repository at this point in the history
1)Minor code modification
  • Loading branch information
ying-css authored Nov 13, 2024
1 parent 873ab8a commit 12997b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 41 deletions.
44 changes: 23 additions & 21 deletions trustm_provider/trustm_provider_signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ static OSSL_FUNC_signature_gettable_ctx_params_fn trustm_signature_gettable_ctx_
static OSSL_FUNC_signature_sign_init_fn trustm_rsa_signature_sign_init;
static OSSL_FUNC_signature_sign_fn trustm_rsa_signature_sign;

static OSSL_FUNC_signature_digest_sign_init_fn trustm_rsa_signature_digest_sign_init;
static OSSL_FUNC_signature_digest_sign_update_fn trustm_rsa_signature_digest_sign_update;
static OSSL_FUNC_signature_digest_sign_init_fn trustm_rsa_signature_digest_init;
static OSSL_FUNC_signature_digest_sign_update_fn trustm_rsa_signature_digest_update;
static OSSL_FUNC_signature_digest_sign_final_fn trustm_rsa_signature_digest_sign_final;
static OSSL_FUNC_signature_digest_sign_fn trustm_rsa_signature_digest_sign;

Expand All @@ -53,8 +53,8 @@ static OSSL_FUNC_signature_settable_ctx_params_fn trustm_rsa_signature_settable_
static OSSL_FUNC_signature_sign_init_fn trustm_ecdsa_signature_sign_init;
static OSSL_FUNC_signature_sign_fn trustm_ecdsa_signature_sign;

static OSSL_FUNC_signature_digest_sign_init_fn trustm_ecdsa_signature_digest_sign_init;
static OSSL_FUNC_signature_digest_sign_update_fn trustm_ecdsa_signature_digest_sign_update;
static OSSL_FUNC_signature_digest_sign_init_fn trustm_ecdsa_signature_digest_init;
static OSSL_FUNC_signature_digest_sign_update_fn trustm_ecdsa_signature_digest_update;
static OSSL_FUNC_signature_digest_sign_final_fn trustm_ecdsa_signature_digest_sign_final;
static OSSL_FUNC_signature_digest_sign_fn trustm_ecdsa_signature_digest_sign;

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

// basically digest sign, can be used for both sign and verify operations
static int trustm_rsa_signature_digest_sign_init(void *ctx, const char *mdname, void *provkey, const OSSL_PARAM params[])
static int trustm_rsa_signature_digest_init(void *ctx, const char *mdname, void *provkey, const OSSL_PARAM params[])
{
trustm_signature_ctx_t *trustm_signature_ctx = ctx;
trustm_signature_ctx->trustm_rsa_key = provkey;
Expand All @@ -362,7 +362,7 @@ static int trustm_rsa_signature_digest_sign_init(void *ctx, const char *mdname,
return_status = optiga_lib_status;
if (return_status != OPTIGA_LIB_SUCCESS)
{
TRUSTM_PROVIDER_ERRFN("Error in trustm_rsa_signature_digest_sign_init\n");
TRUSTM_PROVIDER_ERRFN("Error in trustm_rsa_signature_digest_init\n");
return 0;
}

Expand All @@ -374,7 +374,7 @@ static int trustm_rsa_signature_digest_sign_init(void *ctx, const char *mdname,
}

// basically digest sign, can be used for both sign and verify operations
static int trustm_ecdsa_signature_digest_sign_init(void *ctx, const char *mdname, void *provkey, const OSSL_PARAM params[])
static int trustm_ecdsa_signature_digest_init(void *ctx, const char *mdname, void *provkey, const OSSL_PARAM params[])
{
trustm_signature_ctx_t *trustm_signature_ctx = ctx;
trustm_signature_ctx->trustm_ec_key = provkey;
Expand All @@ -399,7 +399,7 @@ static int trustm_ecdsa_signature_digest_sign_init(void *ctx, const char *mdname
return_status = optiga_lib_status;
if (return_status != OPTIGA_LIB_SUCCESS)
{
TRUSTM_PROVIDER_ERRFN("Error in trustm_ecdsa_signature_digest_sign_init\n");
TRUSTM_PROVIDER_ERRFN("Error in trustm_ecdsa_signature_digest_init\n");
return 0;
}

Expand All @@ -411,7 +411,7 @@ static int trustm_ecdsa_signature_digest_sign_init(void *ctx, const char *mdname
}

// basically digest update, can be used for both sign and verify operations
static int trustm_rsa_signature_digest_sign_update(void *ctx, const unsigned char *data, size_t datalen)
static int trustm_rsa_signature_digest_update(void *ctx, const unsigned char *data, size_t datalen)
{
trustm_signature_ctx_t *trustm_signature_ctx = ctx;
optiga_lib_status_t return_status;
Expand Down Expand Up @@ -440,7 +440,7 @@ static int trustm_rsa_signature_digest_sign_update(void *ctx, const unsigned cha
return_status = optiga_lib_status;
if (return_status != OPTIGA_LIB_SUCCESS)
{
TRUSTM_PROVIDER_ERRFN("Error in trustm_ecdsa_signature_digest_sign_update\n");
TRUSTM_PROVIDER_ERRFN("Error in trustm_ecdsa_signature_digest_update\n");
return 0;
}
optiga_lib_status = OPTIGA_LIB_BUSY;
Expand All @@ -460,7 +460,7 @@ static int trustm_rsa_signature_digest_sign_update(void *ctx, const unsigned cha
return_status = optiga_lib_status;
if (return_status != OPTIGA_LIB_SUCCESS)
{
TRUSTM_PROVIDER_ERRFN("Error in trustm_ecdsa_signature_digest_sign_update\n");
TRUSTM_PROVIDER_ERRFN("Error in trustm_ecdsa_signature_digest_update\n");
return 0;
}

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

// basically digest update, can be used for both sign and verify operations
static int trustm_ecdsa_signature_digest_sign_update(void *ctx, const unsigned char *data, size_t datalen)
static int trustm_ecdsa_signature_digest_update(void *ctx, const unsigned char *data, size_t datalen)
{
trustm_signature_ctx_t *trustm_signature_ctx = ctx;
optiga_lib_status_t return_status;
Expand Down Expand Up @@ -895,7 +895,9 @@ static int trustm_rsa_signature_digest_verify_final(void *ctx, const unsigned ch
TRUSTM_PROVIDER_DBGFN(">");
TRUSTM_PROVIDER_SSL_MUTEX_ACQUIRE
trustm_signature_ctx->me_crypt = me_crypt;

printf("siglen : %d\n", siglen);
if (sig == NULL)
printf("sig is NULL");
// convert public key to trustm's public key format
public_key_buffer[0] = 0x03;
if (trustm_signature_ctx->trustm_rsa_key->key_size == OPTIGA_RSA_KEY_2048_BIT_EXPONENTIAL)
Expand Down Expand Up @@ -1312,11 +1314,11 @@ const OSSL_DISPATCH trustm_rsa_signature_functions[] = {
{ OSSL_FUNC_SIGNATURE_DUPCTX, (void(*)(void))trustm_signature_dupctx },
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void(*)(void))trustm_rsa_signature_sign_init },
{ OSSL_FUNC_SIGNATURE_SIGN, (void(*)(void))trustm_rsa_signature_sign },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void(*)(void))trustm_rsa_signature_digest_sign_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, (void(*)(void))trustm_rsa_signature_digest_sign_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void(*)(void))trustm_rsa_signature_digest_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, (void(*)(void))trustm_rsa_signature_digest_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, (void(*)(void))trustm_rsa_signature_digest_sign_final },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void(*)(void))trustm_rsa_signature_digest_sign_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, (void(*)(void))trustm_rsa_signature_digest_sign_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void(*)(void))trustm_rsa_signature_digest_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, (void(*)(void))trustm_rsa_signature_digest_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, (void(*)(void))trustm_rsa_signature_digest_verify_final },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN, (void(*)(void))trustm_rsa_signature_digest_sign },
{ OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void(*)(void))trustm_signature_get_ctx_params },
Expand All @@ -1333,11 +1335,11 @@ const OSSL_DISPATCH trustm_ecdsa_signature_functions[] = {
{ OSSL_FUNC_SIGNATURE_DUPCTX, (void(*)(void))trustm_signature_dupctx },
{ OSSL_FUNC_SIGNATURE_SIGN_INIT, (void(*)(void))trustm_ecdsa_signature_sign_init },
{ OSSL_FUNC_SIGNATURE_SIGN, (void(*)(void))trustm_ecdsa_signature_sign },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void(*)(void))trustm_ecdsa_signature_digest_sign_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, (void(*)(void))trustm_ecdsa_signature_digest_sign_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT, (void(*)(void))trustm_ecdsa_signature_digest_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE, (void(*)(void))trustm_ecdsa_signature_digest_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL, (void(*)(void))trustm_ecdsa_signature_digest_sign_final },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void(*)(void))trustm_ecdsa_signature_digest_sign_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, (void(*)(void))trustm_ecdsa_signature_digest_sign_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT, (void(*)(void))trustm_ecdsa_signature_digest_init },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE, (void(*)(void))trustm_ecdsa_signature_digest_update },
{ OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL, (void(*)(void))trustm_ecdsa_signature_digest_verify_final },
{ OSSL_FUNC_SIGNATURE_DIGEST_SIGN, (void(*)(void))trustm_ecdsa_signature_digest_sign },
{ OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void(*)(void))trustm_signature_get_ctx_params },
Expand Down
33 changes: 13 additions & 20 deletions trustm_provider/trustm_provider_store_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,21 @@ static void *trustm_object_open(void *provctx, const char *uri)

if ((baseuri = OPENSSL_strdup(uri)) == NULL)
{
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}

char *ptr = strstr(baseuri, needle);
if (ptr == NULL)
{
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}

// extract arguments
opts[0] = strtok(baseuri, ":");
if (opts[0] == NULL)
{
TRUSTM_PROVIDER_ERRFN("No OID input. Abortting...\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}

while (opts[i] != NULL)
Expand All @@ -91,8 +88,7 @@ static void *trustm_object_open(void *provctx, const char *uri)

if (i > 6)
{
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}

// processing opts[0]
Expand All @@ -109,8 +105,7 @@ static void *trustm_object_open(void *provctx, const char *uri)
((key_id < 0xE0FC) || (key_id > 0xE0FD)))
{
TRUSTM_PROVIDER_ERRFN("Invalid key OID\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}

// assign primary key object id
Expand All @@ -121,8 +116,7 @@ static void *trustm_object_open(void *provctx, const char *uri)
if (opts[1] == NULL)
{
TRUSTM_PROVIDER_ERRFN("Specify public key input\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}

// if just reading out the public key
Expand Down Expand Up @@ -155,16 +149,14 @@ static void *trustm_object_open(void *provctx, const char *uri)
if (opts[3] == NULL)
{
TRUSTM_PROVIDER_ERRFN("Specify key size\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}
sscanf(opts[3],"%x", &(trustm_object_ctx->key_size));

if (opts[4] == NULL)
{
TRUSTM_PROVIDER_ERRFN("Specify key usage\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}
sscanf(opts[4], "%x", &(trustm_object_ctx->key_usage));
}
Expand All @@ -175,16 +167,14 @@ static void *trustm_object_open(void *provctx, const char *uri)
if (opts[3] == NULL)
{
TRUSTM_PROVIDER_ERRFN("Specify key curve\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}
sscanf(opts[3],"%x", &(trustm_object_ctx->key_curve));

if (opts[4] == NULL)
{
TRUSTM_PROVIDER_ERRFN("Specify key usage\n");
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
goto error;
}
sscanf(opts[4], "%x", &(trustm_object_ctx->key_usage));
}
Expand All @@ -194,6 +184,9 @@ static void *trustm_object_open(void *provctx, const char *uri)
OPENSSL_free(baseuri);
TRUSTM_PROVIDER_DBGFN("<");
return trustm_object_ctx;
error:
OPENSSL_clear_free(trustm_object_ctx, sizeof(trustm_object_ctx_t));
return NULL;
}

static void *trustm_object_attach(void *provctx, OSSL_CORE_BIO *cin)
Expand Down

0 comments on commit 12997b5

Please sign in to comment.