Skip to content

Commit 0604415

Browse files
authored
Merge pull request #229 from pennam/lago-hash-algo
Fixed hash algo to be selected based on input and not hardcoded
2 parents e19a1b6 + c04a5cb commit 0604415

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: extras/tls/mbedtls_alt/ecdsa_se05x.c

+25-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp,
126126

127127
smStatus_t status = SM_NOT_OK;
128128
SE05x_Result_t result;
129+
SE05x_ECSignatureAlgo_t ecSignAlgo;
129130
uint32_t keyID = 0;
130131
uint8_t magic_bytes[] = ALT_KEYS_MAGIC;
131132
uint8_t buffer[150] = {0};
@@ -166,9 +167,32 @@ int mbedtls_ecdsa_sign(mbedtls_ecp_group *grp,
166167
return -1;
167168
}
168169

170+
// decide on the algo based on the input size
171+
// (input being the hash)
172+
switch(blen) {
173+
case 20:
174+
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA;
175+
break;
176+
case 28:
177+
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_224;
178+
break;
179+
case 32:
180+
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_256;
181+
break;
182+
case 48:
183+
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_384;
184+
break;
185+
case 64:
186+
ecSignAlgo = kSE05x_ECSignatureAlgo_SHA_512;
187+
break;
188+
default:
189+
SMLOG_E("Unsupported hash length: %d\r\n", blen);
190+
return -1;
191+
}
192+
169193
SMLOG_I("Using SE05x for ecdsa sign. blen: %d\r\n", blen);
170194
status = Se05x_API_ECDSASign(
171-
pSession, keyID, kSE05x_ECSignatureAlgo_SHA_384, (uint8_t *)buf, blen, signature, &signature_len);
195+
pSession, keyID, ecSignAlgo, (uint8_t *)buf, blen, signature, &signature_len);
172196
if (status != SM_OK) {
173197
SMLOG_E("Error in Se05x_API_ECDSASign\r\n");
174198
return -1;

Diff for: libraries/SSLClient/src/cortex-m33/libmbedse05x.a

104 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)