Skip to content

Commit

Permalink
Adapt to mbed2/mbed3 difference
Browse files Browse the repository at this point in the history
The signature of mbedtls_pk_parse_keyfile was changed in mbed3.
  • Loading branch information
shirok committed Nov 14, 2023
1 parent f436639 commit 73967fa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ext/tls/tls-mbed.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,27 @@ static ScmObj mbed_load_certificate(ScmTLS *tls,
return SCM_OBJ(tls);
}

#if MBEDTLS_VERSION_MAJOR >= 3
static int rng_get(void *prng, unsigned char *output, size_t output_len)
{
mbedtls_ctr_drbg_context *rng = prng;
return mbedtls_ctr_drbg_random(rng, output, output_len);
}
#endif /*MBEDTLS_VERSION_MAJOR >= 3*/

static ScmObj mbed_load_private_key(ScmTLS *tls,
const char *filename,
const char *password)
{
ScmMbedTLS *t = (ScmMbedTLS*)tls;
#if MBEDTLS_VERSION_MAJOR < 3
int r = mbedtls_pk_parse_keyfile(&t->pk, filename, password);
#else /*MBEDTLS_VERSION_MAJOR >= 3*/
mbedtls_ctr_drbg_context rng;
mbedtls_ctr_drbg_init(&rng);
int r = mbedtls_pk_parse_keyfile(&t->pk, filename, password,
rng_get, &rng);
#endif /*MBEDTLS_VERSION_MAJOR >= 3*/
if (r != 0) {
const int bufsiz = 4096;
char buf[bufsiz];
Expand Down

0 comments on commit 73967fa

Please sign in to comment.