1/* BEGIN_HEADER */
2
3#include <stdint.h>
4
5/* END_HEADER */
6
7/* BEGIN_DEPENDENCIES
8 * depends_on:MBEDTLS_PSA_CRYPTO_C
9 * END_DEPENDENCIES
10 */
11
12/* BEGIN_CASE */
13void hash_finish( int alg_arg, data_t *input, data_t *expected_hash )
14{
15    psa_algorithm_t alg = alg_arg;
16    unsigned char actual_hash[PSA_HASH_MAX_SIZE];
17    size_t actual_hash_length;
18    psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
19
20    PSA_ASSERT( psa_crypto_init( ) );
21
22    PSA_ASSERT( psa_hash_setup( &operation, alg ) );
23    PSA_ASSERT( psa_hash_update( &operation,
24                                 input->x, input->len ) );
25    PSA_ASSERT( psa_hash_finish( &operation,
26                                 actual_hash, sizeof( actual_hash ),
27                                 &actual_hash_length ) );
28    ASSERT_COMPARE( expected_hash->x, expected_hash->len,
29                    actual_hash, actual_hash_length );
30
31exit:
32    psa_hash_abort( &operation );
33    PSA_DONE( );
34}
35/* END_CASE */
36
37/* BEGIN_CASE */
38void hash_verify( int alg_arg, data_t *input, data_t *expected_hash )
39{
40    psa_algorithm_t alg = alg_arg;
41    psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
42
43    PSA_ASSERT( psa_crypto_init( ) );
44
45    PSA_ASSERT( psa_hash_setup( &operation, alg ) );
46    PSA_ASSERT( psa_hash_update( &operation,
47                                 input->x,
48                                 input->len ) );
49    PSA_ASSERT( psa_hash_verify( &operation,
50                                 expected_hash->x,
51                                 expected_hash->len ) );
52
53exit:
54    psa_hash_abort( &operation );
55    PSA_DONE( );
56}
57/* END_CASE */
58
59/* BEGIN_CASE */
60void hash_multi_part( int alg_arg, data_t *input, data_t *expected_hash )
61{
62    psa_algorithm_t alg = alg_arg;
63    unsigned char actual_hash[PSA_HASH_MAX_SIZE];
64    size_t actual_hash_length;
65    psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT;
66    psa_hash_operation_t operation2 = PSA_HASH_OPERATION_INIT;
67    uint32_t len = 0;
68
69    PSA_ASSERT( psa_crypto_init( ) );
70
71    do
72    {
73        memset( actual_hash, 0, sizeof( actual_hash ) );
74        PSA_ASSERT( psa_hash_setup( &operation, alg ) );
75
76        PSA_ASSERT( psa_hash_update( &operation,
77                                     input->x, len ) );
78        PSA_ASSERT( psa_hash_clone( &operation, &operation2 ) );
79        PSA_ASSERT( psa_hash_update( &operation,
80                                     input->x + len, input->len - len ) );
81        PSA_ASSERT( psa_hash_update( &operation2,
82                                     input->x + len, input->len - len ) );
83
84        PSA_ASSERT( psa_hash_finish( &operation,
85                                     actual_hash, sizeof( actual_hash ),
86                                     &actual_hash_length ) );
87        ASSERT_COMPARE( expected_hash->x, expected_hash->len,
88                        actual_hash, actual_hash_length );
89
90        PSA_ASSERT( psa_hash_finish( &operation2,
91                                     actual_hash, sizeof( actual_hash ),
92                                     &actual_hash_length ) );
93        ASSERT_COMPARE( expected_hash->x, expected_hash->len,
94                        actual_hash, actual_hash_length );
95    } while( len++ != input->len );
96
97exit:
98    psa_hash_abort( &operation );
99    psa_hash_abort( &operation2 );
100    PSA_DONE( );
101}
102/* END_CASE */
103