Skip to content

Commit f80162d

Browse files
Add lib-c functions usage option
1 parent 8ecef2f commit f80162d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/SpritzCipher.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ spritz_compare(const uint8_t *data_a, const uint8_t *data_b, uint16_t len)
254254
else {
255255
d = 1U;
256256
}
257-
# endif
258-
#endif
257+
# endif /* !defined(__GNUC__) && !defined(__clang__) */
258+
#endif /* SPRITZ_WIPE_TRACES_PARANOID */
259259

260260
return d;
261261
}
@@ -276,11 +276,15 @@ __attribute__ ((optnone))
276276
#endif
277277
spritz_memzero(uint8_t *buf, uint16_t len)
278278
{
279+
#ifdef SPRITZ_USE_LIBC
280+
memset(buf, 0, len * sizeof(uint8_t));
281+
#else
279282
uint16_t i;
280283

281284
for (i = 0; i < len; i++) {
282285
buf[i] = 0;
283286
}
287+
#endif
284288
}
285289

286290
/** spritz_state_memzero()
@@ -298,12 +302,15 @@ __attribute__ ((optnone))
298302
#endif
299303
spritz_state_memzero(spritz_ctx *ctx)
300304
{
305+
#ifdef SPRITZ_USE_LIBC
306+
memset(ctx->s, 0, SPRITZ_N);
307+
#else
301308
uint8_t i = 0;
302-
303309
/* Loop for SPRITZ_N=256 */
304310
do {
305311
ctx->s[i] = 0;
306312
} while (++i);
313+
#endif
307314

308315
ctx->i = 0;
309316
ctx->j = 0;

src/SpritzCipher.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ extern "C" {
2727
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
2828

2929

30+
/** SPRITZ_USE_LIBC
31+
* Use C standard library functions such as `memset()` to zero buffers.
32+
* It can be useful for performnce if the lib-C functions are optimized in low-level.
33+
*/
34+
#if 0
35+
# define SPRITZ_USE_LIBC
36+
# include <string.h>
37+
# if !defined(__GNUC__) && !defined(__clang__) /* Not GCC or Clang. */
38+
# warning "SPRITZ_USE_LIBC warning: Code optimization isn't off in some security functions."
39+
# endif /* Not GCC or Clang. */
40+
#endif
41+
3042
/** SPRITZ_TIMING_SAFE_CRUSH
3143
* If defined, the equal time crush() will be used.
3244
* This may NOT be useful in some compilers with optimization (except GCC and Clang).
@@ -69,7 +81,7 @@ extern "C" {
6981
/** SPRITZ_N
7082
* Present the value of N in this spritz implementation, DO NOT change SPRITZ_N value.
7183
*/
72-
#define SPRITZ_N 256
84+
#define SPRITZ_N 256U
7385

7486
/* `Semantic Versioning` of this library */
7587
#define SPRITZ_LIBRARY_VERSION_STRING "1.1.0"

0 commit comments

Comments
 (0)