hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd
 */
 
#include <common.h>
#include <rockchip/crypto_v2_util.h>
 
/* ------------------------------------------------------------
 **
 * @brief This function executes a reversed words copy on a specified buffer.
 *
 *        on a 6 words buffer:
 *
 *        buff[5] <---> buff[0]
 *        buff[4] <---> buff[1]
 *        buff[3] <---> buff[2]
 *
 * @param[in] dst_ptr - The counter buffer.
 * @param[in] size    - The counter size in words.
 *
 */
void util_reverse_words_buff(u32 *buff_ptr, u32 size_words)
{
   u32 i;
   u32 temp;
   u32 *high_swap_ptr, *low_swap_ptr;
 
   /* initialize the source and the destination poision */
   high_swap_ptr = buff_ptr + size_words - 1;
   low_swap_ptr  = buff_ptr;
 
   /* execute the reverse memcpoy */
   for (i = 0; i < (size_words / 2); i++) {
       temp                = *high_swap_ptr;
       *(high_swap_ptr--)    = *low_swap_ptr;
       *(low_swap_ptr++)    = temp;
   }
} /* END OF util_reverse_words_buff */
 
/* ------------------------------------------------------------
 **
 * @brief This function executes a reversed byte copy on a specified buffer.
 *
 *        on a 6 byte buffer:
 *
 *        buff[5] <---> buff[0]
 *        buff[4] <---> buff[1]
 *        buff[3] <---> buff[2]
 *
 * @param[in] dst_ptr - The counter buffer.
 * @param[in] src_ptr - The counter size in bytes.
 *
 */
void util_reverse_buff(u8 *buff_ptr, u32 size)
{
   u32 i;
   u32 temp;
   u8 *high_swap_ptr, *low_swap_ptr;
 
   /* initialize the source and the destination poision */
   high_swap_ptr = buff_ptr + size - 1;
   low_swap_ptr  = buff_ptr;
 
   /* execute the reverse memcpoy */
   for (i = 0; i < (size / 2); i++) {
       temp            = *high_swap_ptr;
       *(high_swap_ptr--)    = *low_swap_ptr;
       *(low_swap_ptr++)    = temp;
   }
} /* END OF util_reverse_buff */
 
/* ------------------------------------------------------------
 **
 * @brief This function executes a reverse bytes copying from one buffer to
 * another buffer.
 *
 * @param[in] dst_ptr - The pointer to destination buffer.
 * @param[in] src_ptr - The pointer to source buffer.
 * @param[in] size    - The size in bytes.
 *
 */
void util_reverse_memcpy(u8 *dst_ptr, const u8 *src_ptr, u32 size)
{
   u32 i;
   u32 buff_dst_pos, buff_src_pos;
 
   /* execute the reverse copy in case of different buffers */
   /* initialize the source and the destination position */
   buff_dst_pos = size - 1;
   buff_src_pos = 0;
 
   for (i = 0; i < size; i++)
       dst_ptr[buff_dst_pos--] = src_ptr[buff_src_pos++];
} /* END OF util_reverse_memcpy */
 
/* ------------------------------------------------------------
 **
 * @brief This function executes a memory copy between 2 buffers.
 *
 * @param[in] dst_ptr - The first counter buffer.
 * @param[in] src_ptr - The second counter buffer.
 * @param[in] size    - the first counter size in words.
 *
 */
void util_word_memcpy(u32 *dst_ptr, u32 *src_ptr, u32 size)
{
   u32 i;
 
   /* execute the reverse memcpoy */
   for (i = 0; i < size; i++)
       dst_ptr[i] = src_ptr[i];
} /* END OF util_memcpy */
 
/* ------------------------------------------------------------
 **
 * @brief This function executes a reverse bytes copying from one buffer
 * to another buffer.
 *
 * @param[in] dst_ptr - The pointer to destination buffer.
 * @param[in] src_ptr - The pointer to source buffer.
 * @param[in] size    - The size in words.
 *
 */
void util_reverse_word_memcpy(u32 *dst_ptr, u32 *src_ptr, u32 size)
{
   u32 i;
   u32 buff_dst_pos, buff_src_pos;
 
   /* execute the reverse copy in case of different buffers */
   /* initialize the source and the destination position */
   buff_dst_pos = size - 1;
   buff_src_pos = 0;
 
   for (i = 0; i < size; i++)
       dst_ptr[buff_dst_pos--] = src_ptr[buff_src_pos++];
} /* END OF util_reverse_memcpy */
 
/* ------------------------------------------------------------
 **
 * @brief This function executes a memory set operation on a buffer.
 *
 * @param[in] buff_ptr - the buffer.
 * @param[in] val      - The value to set the buffer.
 * @param[in] size     - the buffers size in words.
 *
 */
void util_word_memset(u32 *buff_ptr, u32 val, u32 size)
{
   u32 i;
 
   /* execute the reverse memcpoy */
   for (i = 0; i < size; i++)
       buff_ptr[i] = val;
} /* END OF util_memcpy */