1515#endif
1616
1717#if defined(CONFIG_UUID_V5 )
18- #include <mbedtls/md .h>
18+ #include <psa/crypto .h>
1919#endif
2020
2121#if defined(CONFIG_UUID_BASE64 )
@@ -82,54 +82,32 @@ int uuid_generate_v4(struct uuid *out)
8282int uuid_generate_v5 (const struct uuid * ns , const void * data , size_t data_size ,
8383 struct uuid * out )
8484{
85+ uint8_t sha_result [PSA_HASH_LENGTH (PSA_ALG_SHA_1 )];
86+ size_t sha_len = 0 ;
87+ psa_hash_operation_t hash_operation = PSA_HASH_OPERATION_INIT ;
88+ psa_status_t status ;
89+
8590 if (out == NULL ) {
8691 return - EINVAL ;
8792 }
88- int ret = 0 ;
89- int mbedtls_err = 0 ;
90- mbedtls_md_context_t ctx = {0 };
91- const mbedtls_md_info_t * md_info = mbedtls_md_info_from_type (MBEDTLS_MD_SHA1 );
92- const size_t sha_1_bytes = 20 ;
93- uint8_t sha_result [sha_1_bytes ];
94-
95- mbedtls_md_init (& ctx );
96- mbedtls_err = mbedtls_md_setup (& ctx , md_info , 0 );
97- /* Might return: MBEDTLS_ERR_MD_BAD_INPUT_DATA or MBEDTLS_ERR_MD_ALLOC_FAILED */
98- switch (mbedtls_err ) {
99- case 0 :
100- break ;
101- case MBEDTLS_ERR_MD_BAD_INPUT_DATA :
102- ret = - EINVAL ;
103- goto exit ;
104- case MBEDTLS_ERR_MD_ALLOC_FAILED :
105- ret = - ENOMEM ;
106- goto exit ;
107- default :
108- ret = - ENOTSUP ;
109- goto exit ;
110- }
111- mbedtls_err = mbedtls_md_starts (& ctx );
112- if (mbedtls_err != 0 ) {
113- /* Might return MBEDTLS_ERR_MD_BAD_INPUT_DATA */
114- ret = - EINVAL ;
93+
94+ status = psa_hash_setup (& hash_operation , PSA_ALG_SHA_1 );
95+ if (status != PSA_SUCCESS ) {
11596 goto exit ;
11697 }
117- mbedtls_err = mbedtls_md_update (& ctx , ns -> val , UUID_SIZE );
118- if (mbedtls_err != 0 ) {
119- /* Might return MBEDTLS_ERR_MD_BAD_INPUT_DATA */
120- ret = - EINVAL ;
98+
99+ status = psa_hash_update (& hash_operation , ns -> val , UUID_SIZE );
100+ if (status != PSA_SUCCESS ) {
121101 goto exit ;
122102 }
123- mbedtls_err = mbedtls_md_update (& ctx , data , data_size );
124- if (mbedtls_err != 0 ) {
125- /* Might return MBEDTLS_ERR_MD_BAD_INPUT_DATA */
126- ret = - EINVAL ;
103+
104+ status = psa_hash_update (& hash_operation , data , data_size );
105+ if (status != PSA_SUCCESS ) {
127106 goto exit ;
128107 }
129- mbedtls_err = mbedtls_md_finish (& ctx , sha_result );
130- if (mbedtls_err != 0 ) {
131- /* Might return MBEDTLS_ERR_MD_BAD_INPUT_DATA */
132- ret = - EINVAL ;
108+
109+ status = psa_hash_finish (& hash_operation , sha_result , sizeof (sha_result ), & sha_len );
110+ if (status != PSA_SUCCESS ) {
133111 goto exit ;
134112 }
135113
@@ -141,8 +119,9 @@ int uuid_generate_v5(const struct uuid *ns, const void *data, size_t data_size,
141119 overwrite_uuid_version_and_variant (UUID_V5_VERSION , UUID_V5_VARIANT , out );
142120
143121exit :
144- mbedtls_md_free (& ctx );
145- return ret ;
122+ psa_hash_abort (& hash_operation );
123+
124+ return (status == PSA_SUCCESS ) ? 0 : - EINVAL ;
146125}
147126#endif
148127
0 commit comments