summaryrefslogtreecommitdiffhomepage
path: root/lib/crypto-mbedtls.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/crypto-mbedtls.c')
-rw-r--r--lib/crypto-mbedtls.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/crypto-mbedtls.c b/lib/crypto-mbedtls.c
index 20fff30..31b57f8 100644
--- a/lib/crypto-mbedtls.c
+++ b/lib/crypto-mbedtls.c
@@ -44,6 +44,15 @@ static mbedtls_entropy_context entropy;
static void __attribute__((constructor)) load();
static void __attribute__((destructor)) unload();
+static void raise_mbedtls_exception(uc_vm_t *vm, int errnum, const char *msg)
+{
+ char buf[120] = "";
+
+ mbedtls_strerror(errnum, buf, sizeof(buf));
+ uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, msg, buf);
+}
+
+
static uc_value_t *
md_digest(uc_vm_t *vm, size_t nargs)
{
@@ -268,9 +277,7 @@ pk_set_public_key(uc_vm_t *vm, size_t nargs)
int err = mbedtls_pk_parse_public_key(&ctx->pk, (const unsigned char*)ucv_string_get(key), ucv_string_length(key));
if (err)
- uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, "not a valid DER key %s: %s",
- mbedtls_high_level_strerr(err),
- mbedtls_low_level_strerr(err));
+ raise_mbedtls_exception(vm, err, "not a valid DER key %s");
return NULL;
}
@@ -376,9 +383,7 @@ pk_verify(uc_vm_t *vm, size_t nargs)
hash, hash_size,
(const unsigned char*)ucv_string_get(sig), ucv_string_length(sig));
if (err) {
- uc_vm_raise_exception(vm, EXCEPTION_RUNTIME, "validation failed: %s: %s",
- mbedtls_high_level_strerr(err),
- mbedtls_low_level_strerr(err));
+ raise_mbedtls_exception(vm, err, "validation failed: %s");
return FALSE;
}