hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: BSD-2-Clause
/*
 * Copyright (c) 2014, STMicroelectronics International N.V.
 * All rights reserved.
 */
 
#include "sha2_taf.h"
#include "sha2_impl.h"
 
TEE_Result ta_entry_sha224(uint32_t param_types, TEE_Param params[4])
{
   /*
    * It is expected that memRef[0] is input buffer and memRef[1] is
    * output buffer.
    */
   if (param_types !=
       TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
               TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE,
               TEE_PARAM_TYPE_NONE)) {
       return TEE_ERROR_BAD_PARAMETERS;
   }
 
   if (params[1].memref.size < SHA224_DIGEST_SIZE)
       return TEE_ERROR_BAD_PARAMETERS;
 
   sha224((unsigned char *)params[0].memref.buffer,
          (unsigned int)params[0].memref.size,
          (unsigned char *)params[1].memref.buffer);
 
   return TEE_SUCCESS;
}
 
TEE_Result ta_entry_sha256(uint32_t param_types, TEE_Param params[4])
{
   /*
    * It is expected that memRef[0] is input buffer and memRef[1] is
    * output buffer.
    */
   if (param_types !=
       TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
               TEE_PARAM_TYPE_MEMREF_OUTPUT, TEE_PARAM_TYPE_NONE,
               TEE_PARAM_TYPE_NONE)) {
       return TEE_ERROR_BAD_PARAMETERS;
   }
 
   if (params[1].memref.size < SHA256_DIGEST_SIZE)
       return TEE_ERROR_BAD_PARAMETERS;
 
   sha256((unsigned char *)params[0].memref.buffer,
          (unsigned int)params[0].memref.size,
          (unsigned char *)params[1].memref.buffer);
 
   return TEE_SUCCESS;
}