1 /* 2 * Copyright (c) 2019,2020, 2021, 2023 Linaro Limited 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/sys/printk.h> 9 10 #include "tfm_ns_interface.h" 11 #ifdef TFM_PSA_API 12 #include "psa_manifest/sid.h" 13 #include "psa/crypto.h" 14 #endif 15 16 /** 17 * \brief Retrieve the version of the PSA Framework API. 18 * 19 * \note This is a functional test only and doesn't 20 * mean to test all possible combinations of 21 * input parameters and return values. 22 */ tfm_get_version(void)23static void tfm_get_version(void) 24 { 25 uint32_t version; 26 27 version = psa_framework_version(); 28 if (version == PSA_FRAMEWORK_VERSION) { 29 printk("The version of the PSA Framework API is %d.\n", 30 version); 31 } else { 32 printk("The version of the PSA Framework API is not valid!\n"); 33 return; 34 } 35 } 36 37 #ifdef TFM_PSA_API 38 /** 39 * \brief Retrieve the minor version of a RoT Service. 40 */ tfm_get_sid(void)41static void tfm_get_sid(void) 42 { 43 uint32_t version; 44 45 version = psa_version(TFM_CRYPTO_SID); 46 if (version == PSA_VERSION_NONE) { 47 printk("RoT Service is not implemented or caller is not "); 48 printk("authorized to access it!\n"); 49 return; 50 } 51 52 /* Valid version number */ 53 printk("The PSA Crypto service minor version is %d.\n", version); 54 } 55 56 /** 57 * \brief Generates random data using the TF-M crypto service. 58 */ tfm_psa_crypto_rng(void)59void tfm_psa_crypto_rng(void) 60 { 61 psa_status_t status; 62 uint8_t outbuf[256] = { 0 }; 63 64 status = psa_generate_random(outbuf, 256); 65 printk("Generating 256 bytes of random data:"); 66 for (uint16_t i = 0; i < 256; i++) { 67 if (!(i % 16)) { 68 printk("\n"); 69 } 70 printk("%02X ", (uint8_t)(outbuf[i] & 0xFF)); 71 } 72 printk("\n"); 73 } 74 #endif 75 main(void)76int main(void) 77 { 78 printk("TF-M IPC on %s\n", CONFIG_BOARD); 79 80 tfm_get_version(); 81 #ifdef TFM_PSA_API 82 tfm_get_sid(); 83 tfm_psa_crypto_rng(); 84 #endif 85 return 0; 86 } 87