mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-16 22:20:56 +00:00
psasim: add AUT for psa_generate_random()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
5beb236835
commit
25afdc1309
@ -22,6 +22,7 @@
|
||||
int psa_hash_compute_main(void);
|
||||
int psa_hash_main(void);
|
||||
int psa_aead_main(char *cipher_name);
|
||||
int psa_random_main(void);
|
||||
|
||||
#define TEST_MODULE(main_func) \
|
||||
do { \
|
||||
@ -48,6 +49,8 @@ int main()
|
||||
TEST_MODULE(psa_aead_main("aes128-gcm_8"));
|
||||
TEST_MODULE(psa_aead_main("chachapoly"));
|
||||
|
||||
TEST_MODULE(psa_random_main());
|
||||
|
||||
exit:
|
||||
return (ret != 0) ? 1 : 0;
|
||||
}
|
||||
|
47
tests/psa-client-server/psasim/src/aut_psa_random.c
Normal file
47
tests/psa-client-server/psasim/src/aut_psa_random.c
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#include <psa/crypto.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mbedtls/entropy.h"
|
||||
|
||||
#define BUFFER_SIZE 100
|
||||
|
||||
int psa_random_main(void)
|
||||
{
|
||||
psa_status_t status;
|
||||
uint8_t output[BUFFER_SIZE] = { 0 };
|
||||
|
||||
status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_crypto_init failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
status = psa_generate_random(output, BUFFER_SIZE);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_generate_random failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Random bytes generated:\n");
|
||||
|
||||
for (size_t j = 0; j < BUFFER_SIZE; j++) {
|
||||
if (j % 8 == 0) {
|
||||
printf("\n ");
|
||||
}
|
||||
printf("%02x ", output[j]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
mbedtls_psa_crypto_free();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user