mirror of
https://github.com/cuberite/polarssl.git
synced 2025-10-05 03:24:17 -04:00
test_driver_asymmetric_encryption: implement opaque [en/de]cryption functions
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
66a827fc83
commit
62b6f10f64
@ -13,11 +13,15 @@
|
|||||||
#include "psa_crypto_rsa.h"
|
#include "psa_crypto_rsa.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "test/drivers/asymmetric_encryption.h"
|
#include "test/drivers/asymmetric_encryption.h"
|
||||||
|
#include "test/drivers/key_management.h"
|
||||||
|
|
||||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||||
#include "libtestdriver1/library/psa_crypto_rsa.h"
|
#include "libtestdriver1/library/psa_crypto_rsa.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define PSA_RSA_KEY_PAIR_MAX_SIZE \
|
||||||
|
PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)
|
||||||
|
|
||||||
mbedtls_test_driver_asymmetric_encryption_hooks_t mbedtls_test_driver_asymmetric_encryption_hooks =
|
mbedtls_test_driver_asymmetric_encryption_hooks_t mbedtls_test_driver_asymmetric_encryption_hooks =
|
||||||
MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
|
MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT;
|
||||||
|
|
||||||
@ -104,7 +108,7 @@ psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* opaque versions - TODO
|
* opaque versions
|
||||||
*/
|
*/
|
||||||
psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
|
psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
|
||||||
const psa_key_attributes_t *attributes, const uint8_t *key,
|
const psa_key_attributes_t *attributes, const uint8_t *key,
|
||||||
@ -112,17 +116,31 @@ psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
|
|||||||
size_t input_length, const uint8_t *salt, size_t salt_length,
|
size_t input_length, const uint8_t *salt, size_t salt_length,
|
||||||
uint8_t *output, size_t output_size, size_t *output_length)
|
uint8_t *output, size_t output_size, size_t *output_length)
|
||||||
{
|
{
|
||||||
(void) attributes;
|
unsigned char unwrapped_key[PSA_RSA_KEY_PAIR_MAX_SIZE];
|
||||||
(void) key;
|
size_t unwrapped_key_length;
|
||||||
(void) key_length;
|
psa_status_t status;
|
||||||
(void) alg;
|
|
||||||
(void) input;
|
status = mbedtls_test_opaque_unwrap_key(key, key_length,
|
||||||
(void) input_length;
|
unwrapped_key, sizeof(unwrapped_key),
|
||||||
(void) salt;
|
&unwrapped_key_length);
|
||||||
(void) salt_length;
|
if (status != PSA_SUCCESS) {
|
||||||
(void) output;
|
return status;
|
||||||
(void) output_size;
|
}
|
||||||
(void) output_length;
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
(defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP) || defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT))
|
||||||
|
return libtestdriver1_mbedtls_psa_asymmetric_encrypt(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||||
|
unwrapped_key, unwrapped_key_length,
|
||||||
|
alg, input, input_length, salt, salt_length,
|
||||||
|
output, output_size, output_length);
|
||||||
|
#else
|
||||||
|
return mbedtls_psa_asymmetric_encrypt(
|
||||||
|
attributes, unwrapped_key, unwrapped_key_length,
|
||||||
|
alg, input, input_length, salt, salt_length,
|
||||||
|
output, output_size, output_length);
|
||||||
|
#endif
|
||||||
|
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,17 +150,31 @@ psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
|
|||||||
size_t input_length, const uint8_t *salt, size_t salt_length,
|
size_t input_length, const uint8_t *salt, size_t salt_length,
|
||||||
uint8_t *output, size_t output_size, size_t *output_length)
|
uint8_t *output, size_t output_size, size_t *output_length)
|
||||||
{
|
{
|
||||||
(void) attributes;
|
unsigned char unwrapped_key[PSA_RSA_KEY_PAIR_MAX_SIZE];
|
||||||
(void) key;
|
size_t unwrapped_key_length;
|
||||||
(void) key_length;
|
psa_status_t status;
|
||||||
(void) alg;
|
|
||||||
(void) input;
|
status = mbedtls_test_opaque_unwrap_key(key, key_length,
|
||||||
(void) input_length;
|
unwrapped_key, sizeof(unwrapped_key),
|
||||||
(void) salt;
|
&unwrapped_key_length);
|
||||||
(void) salt_length;
|
if (status != PSA_SUCCESS) {
|
||||||
(void) output;
|
return status;
|
||||||
(void) output_size;
|
}
|
||||||
(void) output_length;
|
|
||||||
|
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||||
|
(defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP) || defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT))
|
||||||
|
return libtestdriver1_mbedtls_psa_asymmetric_decrypt(
|
||||||
|
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||||
|
unwrapped_key, unwrapped_key_length,
|
||||||
|
alg, input, input_length, salt, salt_length,
|
||||||
|
output, output_size, output_length);
|
||||||
|
#else
|
||||||
|
return mbedtls_psa_asymmetric_decrypt(
|
||||||
|
attributes, unwrapped_key, unwrapped_key_length,
|
||||||
|
alg, input, input_length, salt, salt_length,
|
||||||
|
output, output_size, output_length);
|
||||||
|
#endif
|
||||||
|
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user