1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Crypto Component */
16 /** */
17 /** Crypto Initialization */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21 #define _NX_CRYPTO_INITIALIZE_
22
23 #include "nx_crypto.h"
24
25
26 #ifdef NX_CRYPTO_SELF_TEST
27
28 /* Include necessary system files. */
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_crypto_self_test_memcpy PORTABLE C */
36 /* 6.1.7 */
37 /* AUTHOR */
38 /* */
39 /* Timothy Stapko, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function performs memory copy function for the FIPS 140-2 */
44 /* compliance build. */
45 /* */
46 /* INPUT */
47 /* */
48 /* dest Pointer to the destination */
49 /* memory */
50 /* value value (in byte) to set to the */
51 /* memory location */
52 /* size Number of bytes to copy */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* void * Pointer to the destination */
57 /* memory */
58 /* */
59 /* CALLS */
60 /* */
61 /* None */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
71 /* 09-30-2020 Timothy Stapko Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */
74 /* renamed function, */
75 /* resulting in version 6.1.7 */
76 /* */
77 /**************************************************************************/
_nx_crypto_self_test_memcpy(void * dest,const void * src,size_t size)78 NX_CRYPTO_KEEP VOID *_nx_crypto_self_test_memcpy(void *dest, const void *src, size_t size)
79 {
80 char *from, *to;
81 unsigned int i;
82
83 from = (char*)src;
84 to = (char*)dest;
85
86 for(i = 0; i < size; i++)
87 {
88 to[i] = from[i];
89 }
90
91 return dest;
92 }
93
94 /**************************************************************************/
95 /* */
96 /* FUNCTION RELEASE */
97 /* */
98 /* _nx_crypto_self_test_memset PORTABLE C */
99 /* 6.1.7 */
100 /* AUTHOR */
101 /* */
102 /* Timothy Stapko, Microsoft Corporation */
103 /* */
104 /* DESCRIPTION */
105 /* */
106 /* This function performs memory set function for the FIPS 140-2 */
107 /* compliance build. */
108 /* */
109 /* INPUT */
110 /* */
111 /* dest Pointer to the destination */
112 /* memory */
113 /* value value (in byte) to set to the */
114 /* memory location */
115 /* size Number of bytes to set */
116 /* */
117 /* OUTPUT */
118 /* */
119 /* void * Pointer to the destination */
120 /* memory */
121 /* */
122 /* CALLS */
123 /* */
124 /* None */
125 /* */
126 /* CALLED BY */
127 /* */
128 /* */
129 /* RELEASE HISTORY */
130 /* */
131 /* DATE NAME DESCRIPTION */
132 /* */
133 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
134 /* 09-30-2020 Timothy Stapko Modified comment(s), */
135 /* resulting in version 6.1 */
136 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */
137 /* renamed function, */
138 /* resulting in version 6.1.7 */
139 /* */
140 /**************************************************************************/
_nx_crypto_self_test_memset(void * dest,int value,size_t size)141 NX_CRYPTO_KEEP VOID *_nx_crypto_self_test_memset(void *dest, int value, size_t size)
142 {
143 char *to;
144 unsigned int i;
145 char v;
146
147 to = (char*)dest;
148 v = (char)(value & 0xFF);
149 for(i = 0; i < size; i++)
150 {
151 to[i] = v;
152 }
153
154 return dest;
155 }
156
157 /**************************************************************************/
158 /* */
159 /* FUNCTION RELEASE */
160 /* */
161 /* _nx_crypto_self_test_memcmp PORTABLE C */
162 /* 6.1.7 */
163 /* AUTHOR */
164 /* */
165 /* Timothy Stapko, Microsoft Corporation */
166 /* */
167 /* DESCRIPTION */
168 /* */
169 /* This function performs memory comparison function for the */
170 /* FIPS 140-2 compliance build. */
171 /* */
172 /* INPUT */
173 /* */
174 /* str1 Pointer to the first string */
175 /* for the comparison. */
176 /* str2 Pointer to the second string */
177 /* for the comparison. */
178 /* size Number of bytes to compare. */
179 /* */
180 /* OUTPUT */
181 /* */
182 /* Result 0: str1 and str2 are the */
183 /* same. */
184 /* 0: str1 and str2 are */
185 /* different. */
186 /* */
187 /* CALLS */
188 /* */
189 /* None */
190 /* */
191 /* CALLED BY */
192 /* */
193 /* */
194 /* RELEASE HISTORY */
195 /* */
196 /* DATE NAME DESCRIPTION */
197 /* */
198 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
199 /* 09-30-2020 Timothy Stapko Modified comment(s), */
200 /* resulting in version 6.1 */
201 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */
202 /* renamed function, */
203 /* resulting in version 6.1.7 */
204 /* */
205 /**************************************************************************/
_nx_crypto_self_test_memcmp(const void * str1,const void * str2,size_t size)206 NX_CRYPTO_KEEP int _nx_crypto_self_test_memcmp(const void *str1, const void *str2, size_t size)
207 {
208 char *string1;
209 char *string2;
210 unsigned int i;
211
212 string1 = (char*)str1;
213 string2 = (char*)str2;
214 for(i = 0; i < size; i++)
215 {
216 if(*string1++ != *string2++)
217 return(1);
218 }
219
220 return(0);
221 }
222
223 /**************************************************************************/
224 /* */
225 /* FUNCTION RELEASE */
226 /* */
227 /* _nx_crypto_self_test_memmove PORTABLE C */
228 /* 6.1.7 */
229 /* AUTHOR */
230 /* */
231 /* Timothy Stapko, Microsoft Corporation */
232 /* */
233 /* DESCRIPTION */
234 /* */
235 /* This function performs memory move function for the FIPS 140-2 */
236 /* compliance build. */
237 /* */
238 /* INPUT */
239 /* */
240 /* dest Pointer to the destination */
241 /* memory */
242 /* src Pointer to the source memory */
243 /* size Number of bytes to move */
244 /* */
245 /* OUTPUT */
246 /* */
247 /* void * Pointer to the destination */
248 /* memory */
249 /* */
250 /* CALLS */
251 /* */
252 /* None */
253 /* */
254 /* CALLED BY */
255 /* */
256 /* */
257 /* RELEASE HISTORY */
258 /* */
259 /* DATE NAME DESCRIPTION */
260 /* */
261 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
262 /* 09-30-2020 Timothy Stapko Modified comment(s), */
263 /* resulting in version 6.1 */
264 /* 06-02-2021 Bhupendra Naphade Modified comment(s), */
265 /* renamed function, */
266 /* resulting in version 6.1.7 */
267 /* */
268 /**************************************************************************/
_nx_crypto_self_test_memmove(void * dest,const void * src,size_t size)269 NX_CRYPTO_KEEP void* _nx_crypto_self_test_memmove(void *dest, const void *src, size_t size)
270 {
271 char *from, *to;
272 unsigned int i;
273
274 from = (char*)src;
275 to = (char*)dest;
276
277 if((ULONG)dest < (ULONG)src)
278 {
279 for(i = 0; i < size; i++)
280 {
281 to[i] = from[i];
282 }
283 }
284 else if((ULONG)dest > (ULONG)src)
285 {
286
287 for(i = size; i != 0; i--)
288 to[i - 1] = from[i - 1];
289 }
290 return(dest);
291 }
292
293
294 /**************************************************************************/
295 /* */
296 /* FUNCTION RELEASE */
297 /* */
298 /* _nx_crypto_module_state_get PORTABLE C */
299 /* 6.1 */
300 /* AUTHOR */
301 /* */
302 /* Timothy Stapko, Microsoft Corporation */
303 /* */
304 /* DESCRIPTION */
305 /* */
306 /* This function retrieves the current crypto library state. */
307 /* */
308 /* INPUT */
309 /* */
310 /* None */
311 /* */
312 /* OUTPUT */
313 /* */
314 /* status The bitmap of the current */
315 /* status. Valid bits are: */
316 /* NX_CRYPTO_LIBRARY_STATE_UNINITIALIZED */
317 /* NX_CRYPTO_LIBRARY_STATE_POST_IN_PROGRESS */
318 /* NX_CRYPTO_LIBRARY_STATE_POST_FAILED */
319 /* NX_CRYPTO_LIBRARY_STATE_OPERATIONAL */
320 /* */
321 /* CALLS */
322 /* */
323 /* None */
324 /* */
325 /* CALLED BY */
326 /* */
327 /* */
328 /* RELEASE HISTORY */
329 /* */
330 /* DATE NAME DESCRIPTION */
331 /* */
332 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
333 /* 09-30-2020 Timothy Stapko Modified comment(s), */
334 /* resulting in version 6.1 */
335 /* */
336 /**************************************************************************/
_nx_crypto_module_state_get(VOID)337 NX_CRYPTO_KEEP UINT _nx_crypto_module_state_get(VOID)
338 {
339 return(_nx_crypto_library_state);
340
341 }
342
343 #endif
344
345
346 /**************************************************************************/
347 /* */
348 /* FUNCTION RELEASE */
349 /* */
350 /* _nx_crypto_initialize PORTABLE C */
351 /* 6.1 */
352 /* AUTHOR */
353 /* */
354 /* Timothy Stapko, Microsoft Corporation */
355 /* */
356 /* DESCRIPTION */
357 /* */
358 /* This function initializes the NetX Crypto module. */
359 /* */
360 /* INPUT */
361 /* */
362 /* None */
363 /* */
364 /* OUTPUT */
365 /* */
366 /* status */
367 /* */
368 /* CALLS */
369 /* */
370 /* None */
371 /* */
372 /* CALLED BY */
373 /* */
374 /* */
375 /* RELEASE HISTORY */
376 /* */
377 /* DATE NAME DESCRIPTION */
378 /* */
379 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
380 /* 09-30-2020 Timothy Stapko Modified comment(s), */
381 /* resulting in version 6.1 */
382 /* */
383 /**************************************************************************/
_nx_crypto_initialize(VOID)384 NX_CRYPTO_KEEP UINT _nx_crypto_initialize(VOID)
385 {
386
387
388 return(NX_CRYPTO_SUCCESS);
389
390 }
391