mirror of
https://github.com/yuzu-mirror/mbedtls.git
synced 2026-01-02 06:40:06 +01:00
Allow the function to support DER buffers than what it is nominally required by the provided coordinates. In other words let's ignore padding zeros in the raw number. Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
78 lines
2.3 KiB
C
78 lines
2.3 KiB
C
/* BEGIN_HEADER */
|
|
#include <test/helpers.h>
|
|
#include <mbedtls/psa_util.h>
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PSA_UTIL_HAVE_ECDSA */
|
|
void ecdsa_raw_to_der(int key_bits, data_t *input, data_t *exp_result, int exp_ret)
|
|
{
|
|
unsigned char *tmp_buf = NULL;
|
|
size_t tmp_buf_len = exp_result->len;
|
|
size_t ret_len;
|
|
|
|
TEST_CALLOC(tmp_buf, tmp_buf_len);
|
|
|
|
TEST_EQUAL(mbedtls_ecdsa_raw_to_der(key_bits, input->x, input->len,
|
|
tmp_buf, tmp_buf_len, &ret_len), exp_ret);
|
|
|
|
if (exp_ret == 0) {
|
|
ASSERT_COMPARE(exp_result->x, exp_result->len, tmp_buf, ret_len);
|
|
}
|
|
|
|
exit:
|
|
mbedtls_free(tmp_buf);
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PSA_UTIL_HAVE_ECDSA */
|
|
void ecdsa_raw_to_der_incremental(int key_bits, data_t *input, data_t *exp_result)
|
|
{
|
|
unsigned char *tmp_buf = NULL;
|
|
size_t tmp_buf_len = exp_result->len;
|
|
size_t ret_len;
|
|
size_t i;
|
|
|
|
/* Test with an output buffer smaller than required (expexted to fail). */
|
|
for (i = 1; i < tmp_buf_len; i++) {
|
|
TEST_CALLOC(tmp_buf, i);
|
|
TEST_ASSERT(mbedtls_ecdsa_raw_to_der(key_bits, input->x, input->len,
|
|
tmp_buf, i, &ret_len) != 0);
|
|
mbedtls_free(tmp_buf);
|
|
tmp_buf = NULL;
|
|
}
|
|
/* Test with an output buffer larger/equal than required (expexted to
|
|
* succeed). */
|
|
for (i = tmp_buf_len; i < (2 * tmp_buf_len); i++) {
|
|
TEST_CALLOC(tmp_buf, i);
|
|
TEST_ASSERT(mbedtls_ecdsa_raw_to_der(key_bits, input->x, input->len,
|
|
tmp_buf, i, &ret_len) == 0);
|
|
mbedtls_free(tmp_buf);
|
|
tmp_buf = NULL;
|
|
}
|
|
|
|
exit:
|
|
mbedtls_free(tmp_buf);
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_PSA_UTIL_HAVE_ECDSA */
|
|
void ecdsa_der_to_raw(int key_bits, data_t *input, data_t *exp_result, int exp_ret)
|
|
{
|
|
unsigned char *tmp_buf = NULL;
|
|
size_t tmp_buf_len = exp_result->len;
|
|
size_t ret_len;
|
|
|
|
TEST_CALLOC(tmp_buf, tmp_buf_len);
|
|
|
|
TEST_EQUAL(mbedtls_ecdsa_der_to_raw(key_bits, input->x, input->len,
|
|
tmp_buf, tmp_buf_len, &ret_len), exp_ret);
|
|
|
|
if (exp_ret == 0) {
|
|
ASSERT_COMPARE(exp_result->x, exp_result->len, tmp_buf, ret_len);
|
|
}
|
|
|
|
exit:
|
|
mbedtls_free(tmp_buf);
|
|
}
|
|
/* END_CASE */
|