mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge pull request #152 from ARMmbed/psa-test-psa_constant_names
Test psa_constant_names
This commit is contained in:
@ -103,7 +103,7 @@ EXTRA_GENERATED += psa/psa_constant_names_generated.c
|
||||
endif
|
||||
|
||||
psa/psa_constant_names$(EXEXT): psa/psa_constant_names_generated.c
|
||||
psa/psa_constant_names_generated.c: ../scripts/generate_psa_constants.py ../include/psa/crypto_values.h
|
||||
psa/psa_constant_names_generated.c: ../scripts/generate_psa_constants.py ../include/psa/crypto_values.h ../include/psa/crypto_extra.h
|
||||
../scripts/generate_psa_constants.py
|
||||
|
||||
aes/aescrypt2$(EXEXT): aes/aescrypt2.c $(DEP)
|
||||
|
@ -1,7 +1,26 @@
|
||||
add_executable(crypto_examples crypto_examples.c)
|
||||
target_link_libraries(crypto_examples mbedtls)
|
||||
|
||||
install(TARGETS crypto_examples
|
||||
add_executable(key_ladder_demo key_ladder_demo.c)
|
||||
target_link_libraries(key_ladder_demo mbedtls)
|
||||
|
||||
add_executable(psa_constant_names psa_constant_names.c)
|
||||
target_link_libraries(psa_constant_names mbedtls)
|
||||
|
||||
add_custom_target(
|
||||
psa_constant_names_generated
|
||||
COMMAND ${PYTHON_EXECUTABLE} scripts/generate_psa_constants.py
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../
|
||||
)
|
||||
add_dependencies(psa_constant_names psa_constant_names_generated)
|
||||
|
||||
install(TARGETS
|
||||
crypto_examples
|
||||
key_ladder_demo
|
||||
psa_constant_names
|
||||
DESTINATION "bin"
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
|
||||
install(PROGRAMS
|
||||
key_ladder_demo.sh
|
||||
DESTINATION "bin")
|
||||
|
@ -620,9 +620,9 @@ static void usage( void )
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
char *key_file_name = "master.key";
|
||||
char *input_file_name = NULL;
|
||||
char *output_file_name = NULL;
|
||||
const char *key_file_name = "master.key";
|
||||
const char *input_file_name = NULL;
|
||||
const char *output_file_name = NULL;
|
||||
const char *ladder[MAX_LADDER_DEPTH];
|
||||
size_t ladder_depth = 0;
|
||||
int i;
|
||||
|
@ -138,7 +138,7 @@ static int psa_snprint_ecc_curve(char *buffer, size_t buffer_size,
|
||||
|
||||
static void usage(const char *program_name)
|
||||
{
|
||||
printf("Usage: %s TYPE VALUE\n",
|
||||
printf("Usage: %s TYPE VALUE [VALUE...]\n",
|
||||
program_name == NULL ? "psa_constant_names" : program_name);
|
||||
printf("Print the symbolic name whose numerical value is VALUE in TYPE.\n");
|
||||
printf("Supported types (with = between aliases):\n");
|
||||
@ -149,11 +149,19 @@ static void usage(const char *program_name)
|
||||
printf(" error=status Status code (psa_status_t)\n");
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
TYPE_STATUS,
|
||||
TYPE_ALGORITHM,
|
||||
TYPE_ECC_CURVE,
|
||||
TYPE_KEY_TYPE,
|
||||
TYPE_KEY_USAGE,
|
||||
} value_type;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char buffer[200];
|
||||
unsigned long value;
|
||||
char *end;
|
||||
value_type type;
|
||||
unsigned long max;
|
||||
int i;
|
||||
|
||||
if (argc <= 1 ||
|
||||
!strcmp(argv[1], "help") ||
|
||||
@ -162,31 +170,64 @@ int main(int argc, char *argv[])
|
||||
usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (argc != 3) {
|
||||
usage(argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
value = strtoul(argv[2], &end, 0);
|
||||
if (*end) {
|
||||
printf("Non-numeric value: %s\n", argv[2]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "error") || !strcmp(argv[1], "status"))
|
||||
psa_snprint_status(buffer, sizeof(buffer), (psa_status_t) value);
|
||||
else if (!strcmp(argv[1], "alg") || !strcmp(argv[1], "algorithm"))
|
||||
psa_snprint_algorithm(buffer, sizeof(buffer), (psa_algorithm_t) value);
|
||||
else if (!strcmp(argv[1], "curve") || !strcmp(argv[1], "ecc_curve"))
|
||||
psa_snprint_ecc_curve(buffer, sizeof(buffer), (psa_ecc_curve_t) value);
|
||||
else if (!strcmp(argv[1], "type") || !strcmp(argv[1], "key_type"))
|
||||
psa_snprint_key_type(buffer, sizeof(buffer), (psa_key_type_t) value);
|
||||
else if (!strcmp(argv[1], "usage") || !strcmp(argv[1], "key_usage"))
|
||||
psa_snprint_key_usage(buffer, sizeof(buffer), (psa_key_usage_t) value);
|
||||
else {
|
||||
if (!strcmp(argv[1], "error") || !strcmp(argv[1], "status")) {
|
||||
type = TYPE_STATUS;
|
||||
max = 0x7fffffff; /* hard-coded because psa_status_t is signed */
|
||||
} else if (!strcmp(argv[1], "alg") || !strcmp(argv[1], "algorithm")) {
|
||||
type = TYPE_ALGORITHM;
|
||||
max = (psa_algorithm_t)( -1 );
|
||||
} else if (!strcmp(argv[1], "curve") || !strcmp(argv[1], "ecc_curve")) {
|
||||
type = TYPE_ECC_CURVE;
|
||||
max = (psa_ecc_curve_t)( -1 );
|
||||
} else if (!strcmp(argv[1], "type") || !strcmp(argv[1], "key_type")) {
|
||||
type = TYPE_KEY_TYPE;
|
||||
max = (psa_key_type_t)( -1 );
|
||||
} else if (!strcmp(argv[1], "usage") || !strcmp(argv[1], "key_usage")) {
|
||||
type = TYPE_KEY_USAGE;
|
||||
max = (psa_key_usage_t)( -1 );
|
||||
} else {
|
||||
printf("Unknown type: %s\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
puts(buffer);
|
||||
for (i = 2; i < argc; i++) {
|
||||
char buffer[200];
|
||||
char *end;
|
||||
unsigned long value = strtoul(argv[i], &end, 0);
|
||||
if (*end) {
|
||||
printf("Non-numeric value: %s\n", argv[i]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (value > max) {
|
||||
printf("Value out of range: %s\n", argv[i]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TYPE_STATUS:
|
||||
psa_snprint_status(buffer, sizeof(buffer),
|
||||
(psa_status_t) value);
|
||||
break;
|
||||
case TYPE_ALGORITHM:
|
||||
psa_snprint_algorithm(buffer, sizeof(buffer),
|
||||
(psa_algorithm_t) value);
|
||||
break;
|
||||
case TYPE_ECC_CURVE:
|
||||
psa_snprint_ecc_curve(buffer, sizeof(buffer),
|
||||
(psa_ecc_curve_t) value);
|
||||
break;
|
||||
case TYPE_KEY_TYPE:
|
||||
psa_snprint_key_type(buffer, sizeof(buffer),
|
||||
(psa_key_type_t) value);
|
||||
break;
|
||||
case TYPE_KEY_USAGE:
|
||||
psa_snprint_key_usage(buffer, sizeof(buffer),
|
||||
(psa_key_usage_t) value);
|
||||
break;
|
||||
}
|
||||
puts(buffer);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user