Skip to content

Fixed hash algo to be selected based on input and not hardcoded #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion extras/tls/mbedtls_alt/ecdsa_se05x.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp,

smStatus_t status = SM_NOT_OK;
SE05x_Result_t result;
SE05x_ECSignatureAlgo_t ecSignAlgo;
uint32_t keyID = 0;
uint8_t magic_bytes[] = ALT_KEYS_MAGIC;
uint8_t buffer[150] = {0};
Expand Down Expand Up @@ -166,9 +167,32 @@ int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp,
return -1;
}

// decide on the algo based on the input size
// (input being the hash)
switch(blen) {
case 20:
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA;
break;
case 28:
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_224;
break;
case 32:
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_256;
break;
case 48:
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_384;
break;
case 64:
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_512;
break;
default:
SMLOG_E("Unsupported hash length: %d\r\n", blen);
return -1;
}

SMLOG_I("Using SE05x for ecdsa sign. blen: %d\r\n", blen);
status = Se05x_API_ECDSASign(
pSession, keyID, kSE05x_ECSignatureAlgo_SHA_384, (uint8_t *)buf, blen, signature, &signature_len);
pSession, keyID, ecSignAlgo, (uint8_t *)buf, blen, signature, &signature_len);
if (status != SM_OK) {
SMLOG_E("Error in Se05x_API_ECDSASign\r\n");
return -1;
Expand Down
Binary file modified libraries/SSLClient/src/cortex-m33/libmbedse05x.a
Binary file not shown.