Skip to content

Commit 2b111e0

Browse files
committed
Cleanup, add smoke test for experimental parameters.
Signed-off-by: Markku-Juhani O. Saarinen <[email protected]>
1 parent ddbf57e commit 2b111e0

24 files changed

+1467
-127
lines changed

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
.PHONY: test
55

6-
XTEST ?= xfips205
7-
CSRC = $(wildcard *.c) test/xfips205.c
6+
CSRC = $(wildcard *.c)
87
OBJS = $(CSRC:.c=.o)
9-
KATNUM ?= 1
8+
9+
XTEST ?= xfips205
10+
XTESTC ?= test/xfips205.c
1011

1112
CC = gcc
1213
CFLAGS := -Wall \
@@ -28,7 +29,7 @@ CFLAGS := -Wall \
2829
LDLIBS +=
2930

3031
$(XTEST): $(OBJS)
31-
$(CC) $(LDFLAGS) $(CFLAGS) -o $(XTEST) $(OBJS) $(LDLIBS)
32+
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(XTESTC) $(LDLIBS)
3233

3334
%.o: %.[cS]
3435
$(CC) $(CFLAGS) -c $^ -o $@

sha2_256.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
44
*/
55

6-
/* === FIPS 180-4 SHA2-256 Implementation */
6+
/* === FIPS 180-4 SHA2-256 / Portable C Implementation */
77

88
#include <string.h>
99
#include "plat_local.h"
1010
#include "sha2_api.h"
1111

12-
#ifndef SLOTH_SHA256
13-
/* ( slow / processor implementation fallback ) */
12+
#ifdef SLH_EXPERIMENTAL
13+
uint64_t sha2_256_compress_count = 0; /* instrumentation */
14+
#endif
1415

1516
/* processing step, sets "d" and "h" as a function of all 8 inputs */
1617
/* and message schedule "mi", round constant "ki" */
@@ -54,6 +55,10 @@ void sha2_256_compress(void *v)
5455
const uint32_t *mp = sp + 8;
5556
const uint32_t *kp = ck;
5657

58+
#ifdef SLH_EXPERIMENTAL
59+
sha2_256_compress_count++; /* instrumentation */
60+
#endif
61+
5762
a = sp[0] = rev8_be32(sp[0]);
5863
b = sp[1] = rev8_be32(sp[1]);
5964
c = sp[2] = rev8_be32(sp[2]);
@@ -135,8 +140,6 @@ void sha2_256_compress(void *v)
135140
sp[7] = rev8_be32(sp[7] + h);
136141
}
137142

138-
#endif
139-
140143
/* initialize */
141144

142145
static void sha2_256_init_h0(sha2_256_t *sha, const uint8_t *h0)

sha2_512.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
44
*/
55

6-
/* === FIPS 180-4 SHA2-512 Implementation */
6+
/* === FIPS 180-4 SHA2-512 / Portable C Implementation */
77

88
#include <string.h>
99
#include "plat_local.h"
1010
#include "sha2_api.h"
1111

12-
#ifndef SLOTH_SHA512
13-
/* ( slow / processor implementation fallback ) */
12+
#ifdef SLH_EXPERIMENTAL
13+
uint64_t sha2_512_compress_count = 0; /* instrumentation */
14+
#endif
1415

1516
/* processing step, sets "d" and "h" as a function of all 8 inputs */
1617
/* and message schedule "mi", round constant "ki" */
@@ -85,6 +86,10 @@ void sha2_512_compress(void *v)
8586
const uint64_t *mp = sp + 8;
8687
const uint64_t *kp = ck;
8788

89+
#ifdef SLH_EXPERIMENTAL
90+
sha2_512_compress_count++; /* instrumentation */
91+
#endif
92+
8893
/* get state */
8994
a = sp[0] = rev8_be64(sp[0]);
9095
b = sp[1] = rev8_be64(sp[1]);
@@ -168,8 +173,6 @@ void sha2_512_compress(void *v)
168173
sp[7] = rev8_be64(sp[7] + h);
169174
}
170175

171-
#endif
172-
173176
/* initialize */
174177

175178
static void sha2_512_init_h0(sha2_512_t *sha, const uint8_t *h0)
@@ -235,7 +238,6 @@ void sha2_512_256_init(sha2_512_t *sha)
235238
sha2_512_init_h0(sha, sha2_512_256_h0);
236239
}
237240

238-
239241
void sha2_512_copy(sha2_512_t *dst, const sha2_512_t *src)
240242
{
241243
dst->i = src->i;

sha3_api.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
*/
55

66
/* === FIPS 202: SHA-3 hash and SHAKE eXtensible Output Functions (XOF) */
7-
/* Hash padding mode code for testing permutation implementations. */
87

9-
#ifndef SLOTH_NO_SHA3
108
#include "sha3_api.h"
119

1210
/* These functions have not been optimized for performance. */
@@ -111,6 +109,3 @@ void shake(uint8_t *md, size_t md_sz, const void *in, size_t in_sz, size_t r_sz)
111109
sha3_update(&sha3, in, in_sz);
112110
shake_out(&sha3, md, md_sz);
113111
}
114-
115-
/* SLOTH_NO_SHA3 */
116-
#endif

sha3_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern "C"
5050
void shake_out(sha3_var_t *c, uint8_t *out, size_t out_sz);
5151

5252
/* core permutation */
53-
void keccak_f1600(void *st);
53+
void keccak_f1600(uint64_t x[25]);
5454

5555
#ifdef __cplusplus
5656
}

sha3_f1600.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55

66
/* === FIPS 202 Keccak permutation implementation for a 64-bit target. */
77

8-
#ifndef SLOTH_KECCAK
9-
108
#include "plat_local.h"
119
#include "sha3_api.h"
1210

11+
#ifdef SLH_EXPERIMENTAL
12+
uint64_t keccak_f1600_count = 0; /* instrumentation */
13+
#endif
14+
1315
/* forward permutation */
1416

15-
void keccak_f1600(void *st)
17+
void keccak_f1600(uint64_t x[25])
1618
{
1719
/* round constants */
1820
static const uint64_t keccak_rc[24] = {
@@ -30,9 +32,12 @@ void keccak_f1600(void *st)
3032
UINT64_C(0x0000000080000001), UINT64_C(0x8000000080008008)};
3133

3234
int i;
33-
uint64_t *x = (uint64_t *)st;
3435
uint64_t t, y0, y1, y2, y3, y4;
3536

37+
#ifdef SLH_EXPERIMENTAL
38+
keccak_f1600_count++; /* instrumentation */
39+
#endif
40+
3641
/* iteration */
3742

3843
for (i = 0; i < 24; i++)
@@ -148,6 +153,3 @@ void keccak_f1600(void *st)
148153
x[0] = x[0] ^ keccak_rc[i];
149154
}
150155
}
151-
152-
/* SLOTH_KECCAK */
153-
#endif

slh_adrs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
44
*/
55

6-
/* === Internal ADRS manipulation functions (Section 4.2) */
6+
/* === Internal ADRS manipulation functions (FIPS 205 Section 4.3) */
77

88
#ifndef _SLH_ADRS_H_
99
#define _SLH_ADRS_H_
@@ -156,7 +156,6 @@ static inline void adrs_set_type_and_clear_not_kp(slh_var_t *var, uint32_t y)
156156
var->adrs->u32[7] = 0;
157157
}
158158

159-
160159
/* === Compressed 22-byte address ADRSc used with SHA-2. */
161160
static inline void adrsc_22(const slh_var_t *var, uint8_t *ac)
162161
{

0 commit comments

Comments
 (0)