Skip to content

Commit a4a43db

Browse files
authored
Merge pull request #691 from pq-code-package/unsigned
Use unsigned rather than unsigned int everywhere
2 parents 60a4ede + d3d1e37 commit a4a43db

26 files changed

+73
-76
lines changed

mlkem/fips202/keccakf1600.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/* End of static namespacing */
3030

3131
void KeccakF1600_StateExtractBytes(uint64_t *state, unsigned char *data,
32-
unsigned int offset, unsigned int length)
32+
unsigned offset, unsigned length)
3333
{
3434
unsigned i;
3535
#if defined(SYS_LITTLE_ENDIAN)
@@ -50,7 +50,7 @@ void KeccakF1600_StateExtractBytes(uint64_t *state, unsigned char *data,
5050
}
5151

5252
void KeccakF1600_StateXORBytes(uint64_t *state, const unsigned char *data,
53-
unsigned int offset, unsigned int length)
53+
unsigned offset, unsigned length)
5454
{
5555
unsigned i;
5656
#if defined(SYS_LITTLE_ENDIAN)
@@ -73,8 +73,8 @@ void KeccakF1600_StateXORBytes(uint64_t *state, const unsigned char *data,
7373

7474
void KeccakF1600x4_StateExtractBytes(uint64_t *state, unsigned char *data0,
7575
unsigned char *data1, unsigned char *data2,
76-
unsigned char *data3, unsigned int offset,
77-
unsigned int length)
76+
unsigned char *data3, unsigned offset,
77+
unsigned length)
7878
{
7979
KeccakF1600_StateExtractBytes(state + KECCAK_LANES * 0, data0, offset,
8080
length);
@@ -89,8 +89,8 @@ void KeccakF1600x4_StateExtractBytes(uint64_t *state, unsigned char *data0,
8989
void KeccakF1600x4_StateXORBytes(uint64_t *state, const unsigned char *data0,
9090
const unsigned char *data1,
9191
const unsigned char *data2,
92-
const unsigned char *data3,
93-
unsigned int offset, unsigned int length)
92+
const unsigned char *data3, unsigned offset,
93+
unsigned length)
9494
{
9595
KeccakF1600_StateXORBytes(state + KECCAK_LANES * 0, data0, offset, length);
9696
KeccakF1600_StateXORBytes(state + KECCAK_LANES * 1, data1, offset, length);

mlkem/fips202/keccakf1600.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define KeccakF1600_StateExtractBytes \
2020
MLKEM_NAMESPACE(KeccakF1600_StateExtractBytes)
2121
void KeccakF1600_StateExtractBytes(uint64_t *state, unsigned char *data,
22-
unsigned int offset, unsigned int length)
22+
unsigned offset, unsigned length)
2323
__contract__(
2424
requires(0 <= offset && offset <= KECCAK_LANES * sizeof(uint64_t) &&
2525
0 <= length && length <= KECCAK_LANES * sizeof(uint64_t) - offset)
@@ -30,7 +30,7 @@ __contract__(
3030

3131
#define KeccakF1600_StateXORBytes MLKEM_NAMESPACE(KeccakF1600_StateXORBytes)
3232
void KeccakF1600_StateXORBytes(uint64_t *state, const unsigned char *data,
33-
unsigned int offset, unsigned int length)
33+
unsigned offset, unsigned length)
3434
__contract__(
3535
requires(0 <= offset && offset <= KECCAK_LANES * sizeof(uint64_t) &&
3636
0 <= length && length <= KECCAK_LANES * sizeof(uint64_t) - offset)
@@ -43,8 +43,8 @@ __contract__(
4343
MLKEM_NAMESPACE(KeccakF1600x4_StateExtractBytes)
4444
void KeccakF1600x4_StateExtractBytes(uint64_t *state, unsigned char *data0,
4545
unsigned char *data1, unsigned char *data2,
46-
unsigned char *data3, unsigned int offset,
47-
unsigned int length)
46+
unsigned char *data3, unsigned offset,
47+
unsigned length)
4848
__contract__(
4949
requires(0 <= offset && offset <= KECCAK_LANES * sizeof(uint64_t) &&
5050
0 <= length && length <= KECCAK_LANES * sizeof(uint64_t) - offset)
@@ -63,8 +63,8 @@ __contract__(
6363
void KeccakF1600x4_StateXORBytes(uint64_t *state, const unsigned char *data0,
6464
const unsigned char *data1,
6565
const unsigned char *data2,
66-
const unsigned char *data3,
67-
unsigned int offset, unsigned int length)
66+
const unsigned char *data3, unsigned offset,
67+
unsigned length)
6868
__contract__(
6969
requires(0 <= offset && offset <= KECCAK_LANES * sizeof(uint64_t) &&
7070
0 <= length && length <= KECCAK_LANES * sizeof(uint64_t) - offset)

mlkem/native/aarch64/src/arith_native_aarch64.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ void intt_asm_clean(int16_t *, const int16_t *, const int16_t *);
4242
void intt_asm_opt(int16_t *, const int16_t *, const int16_t *);
4343

4444
#define rej_uniform_asm_clean MLKEM_NAMESPACE(rej_uniform_asm_clean)
45-
unsigned int rej_uniform_asm_clean(int16_t *r, const uint8_t *buf,
46-
unsigned int buflen, const uint8_t *table);
45+
unsigned rej_uniform_asm_clean(int16_t *r, const uint8_t *buf, unsigned buflen,
46+
const uint8_t *table);
4747

4848
#define poly_reduce_asm_clean MLKEM_NAMESPACE(poly_reduce_asm_clean)
4949
void poly_reduce_asm_clean(int16_t *);

mlkem/native/aarch64/src/clean_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ static INLINE void poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
6464
poly_tobytes_asm_clean(r, a);
6565
}
6666

67-
static INLINE int rej_uniform_native(int16_t *r, unsigned int len,
68-
const uint8_t *buf, unsigned int buflen)
67+
static INLINE int rej_uniform_native(int16_t *r, unsigned len,
68+
const uint8_t *buf, unsigned buflen)
6969
{
7070
if (len != MLKEM_N || buflen % 24 != 0)
7171
{

mlkem/native/aarch64/src/opt_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ static INLINE void poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES],
6565
poly_tobytes_asm_opt(r, a);
6666
}
6767

68-
static INLINE int rej_uniform_native(int16_t *r, unsigned int len,
69-
const uint8_t *buf, unsigned int buflen)
68+
static INLINE int rej_uniform_native(int16_t *r, unsigned len,
69+
const uint8_t *buf, unsigned buflen)
7070
{
7171
if (len != MLKEM_N || buflen % 24 != 0)
7272
{

mlkem/native/aarch64/src/rej_uniform_asm_clean.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* 16-bit coefficients.
1414
* - const uint8_t *buf: pointer to input buffer
1515
* (assumed to be uniform random bytes)
16-
* - unsigned int buflen: length of input buffer in bytes.
16+
* - unsigned buflen: length of input buffer in bytes.
1717
* Must be a multiple of 24.
1818
*
1919
* Returns number of sampled 16-bit integers (at most MLKEM_N).

mlkem/native/api.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,18 @@ __contract__(
314314
* uniform random integers mod q
315315
*
316316
* Arguments: - int16_t *r: pointer to output buffer
317-
* - unsigned int len: requested number of 16-bit integers
317+
* - unsigned len: requested number of 16-bit integers
318318
* (uniform mod q).
319319
* - const uint8_t *buf: pointer to input buffer
320320
* (assumed to be uniform random bytes)
321-
* - unsigned int buflen: length of input buffer in bytes.
321+
* - unsigned buflen: length of input buffer in bytes.
322322
*
323323
* Return -1 if the native implementation does not support the input lengths.
324324
* Otherwise, returns non-negative number of sampled 16-bit integers (at most
325325
* len).
326326
**************************************************/
327-
static INLINE int rej_uniform_native(int16_t *r, unsigned int len,
328-
const uint8_t *buf, unsigned int buflen)
327+
static INLINE int rej_uniform_native(int16_t *r, unsigned len,
328+
const uint8_t *buf, unsigned buflen)
329329
__contract__(
330330
requires(len <= 4096 && buflen <= 4096 && buflen % 3 == 0)
331331
requires(memory_no_alias(r, sizeof(int16_t) * len))

mlkem/native/x86_64/src/arith_native_x86_64.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(3 * 168) /* REJ_UNIFORM_AVX_BUFLEN * SHAKE128_RATE */
1717

1818
#define rej_uniform_avx2 MLKEM_NAMESPACE(rej_uniform_avx2)
19-
unsigned int rej_uniform_avx2(int16_t *r, const uint8_t *buf);
19+
unsigned rej_uniform_avx2(int16_t *r, const uint8_t *buf);
2020

2121
#define rej_uniform_table MLKEM_NAMESPACE(rej_uniform_table)
2222
extern const uint8_t rej_uniform_table[256][8];

mlkem/native/x86_64/src/default_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static INLINE void poly_permute_bitrev_to_custom(int16_t data[MLKEM_N])
3232
nttunpack_avx2((__m256i *)(data), qdata.vec);
3333
}
3434

35-
static INLINE int rej_uniform_native(int16_t *r, unsigned int len,
36-
const uint8_t *buf, unsigned int buflen)
35+
static INLINE int rej_uniform_native(int16_t *r, unsigned len,
36+
const uint8_t *buf, unsigned buflen)
3737
{
3838
/* AVX2 implementation assumes specific buffer lengths */
3939
if (len != MLKEM_N || buflen != REJ_UNIFORM_AVX_BUFLEN)

mlkem/native/x86_64/src/rej_uniform_avx2.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include "arith_native_x86_64.h"
1919
#include "consts.h"
2020

21-
unsigned int rej_uniform_avx2(int16_t *RESTRICT r, const uint8_t *buf)
21+
unsigned rej_uniform_avx2(int16_t *RESTRICT r, const uint8_t *buf)
2222
{
23-
unsigned int ctr, pos;
23+
unsigned ctr, pos;
2424
uint16_t val0, val1;
2525
uint32_t good;
2626
const __m256i bound =

mlkem/sampling.c

+11-13
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
#define load24_littleendian MLKEM_NAMESPACE(load24_littleendian)
2323
/* End of static namespacing */
2424

25-
static unsigned int rej_uniform_scalar(int16_t *r, unsigned int target,
26-
unsigned int offset, const uint8_t *buf,
27-
unsigned int buflen)
25+
static unsigned rej_uniform_scalar(int16_t *r, unsigned target, unsigned offset,
26+
const uint8_t *buf, unsigned buflen)
2827
__contract__(
2928
requires(offset <= target && target <= 4096 && buflen <= 4096 && buflen % 3 == 0)
3029
requires(memory_no_alias(r, sizeof(int16_t) * target))
@@ -35,7 +34,7 @@ __contract__(
3534
ensures(array_bound(r, 0, return_value, 0, MLKEM_Q))
3635
)
3736
{
38-
unsigned int ctr, pos;
37+
unsigned ctr, pos;
3938
uint16_t val0, val1;
4039

4140
debug_assert_bound(r, offset, 0, MLKEM_Q);
@@ -73,15 +72,15 @@ __contract__(
7372
* uniform random integers mod q
7473
*
7574
* Arguments: - int16_t *r: pointer to output buffer
76-
* - unsigned int target: requested number of 16-bit integers
75+
* - unsigned target: requested number of 16-bit integers
7776
* (uniform mod q).
7877
* Must be <= 4096.
79-
* - unsigned int offset: number of 16-bit integers that have
78+
* - unsigned offset: number of 16-bit integers that have
8079
* already been sampled.
8180
* Must be <= target.
8281
* - const uint8_t *buf: pointer to input buffer
8382
* (assumed to be uniform random bytes)
84-
* - unsigned int buflen: length of input buffer in bytes
83+
* - unsigned buflen: length of input buffer in bytes
8584
* Must be <= 4096.
8685
* Must be a multiple of 3.
8786
*
@@ -102,9 +101,8 @@ __contract__(
102101
* buffer. This avoids shifting the buffer base in the caller, which appears
103102
* tricky to reason about.
104103
*/
105-
static unsigned int rej_uniform(int16_t *r, unsigned int target,
106-
unsigned int offset, const uint8_t *buf,
107-
unsigned int buflen)
104+
static unsigned rej_uniform(int16_t *r, unsigned target, unsigned offset,
105+
const uint8_t *buf, unsigned buflen)
108106
__contract__(
109107
requires(offset <= target && target <= 4096 && buflen <= 4096 && buflen % 3 == 0)
110108
requires(memory_no_alias(r, sizeof(int16_t) * target))
@@ -146,9 +144,9 @@ void poly_rej_uniform_x4(poly *vec, uint8_t *seed[4])
146144
uint8_t buf3[MLKEM_GEN_MATRIX_NBLOCKS * XOF_RATE];
147145

148146
/* Tracks the number of coefficients we have already sampled */
149-
unsigned int ctr[KECCAK_WAY];
147+
unsigned ctr[KECCAK_WAY];
150148
xof_x4_ctx statex;
151-
unsigned int buflen;
149+
unsigned buflen;
152150

153151
/* seed is MLKEM_SYMBYTES + 2 bytes long, but padded to MLKEM_SYMBYTES + 16 */
154152
xof_x4_init(&statex);
@@ -199,7 +197,7 @@ void poly_rej_uniform(poly *entry, uint8_t seed[MLKEM_SYMBYTES + 2])
199197
{
200198
xof_ctx state;
201199
uint8_t buf[MLKEM_GEN_MATRIX_NBLOCKS * XOF_RATE];
202-
unsigned int ctr, buflen;
200+
unsigned ctr, buflen;
203201

204202
xof_init(&state);
205203
xof_absorb(&state, seed, MLKEM_SYMBYTES + 2);

proofs/cbmc/KeccakF1600_StateExtractBytes/KeccakF1600_StateExtractBytes_harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void harness(void)
88
{
99
uint64_t *state;
1010
unsigned char *data;
11-
unsigned int offset;
12-
unsigned int length;
11+
unsigned offset;
12+
unsigned length;
1313
KeccakF1600_StateExtractBytes(state, data, offset, length);
1414
}

proofs/cbmc/KeccakF1600_StateExtractBytes_BE/KeccakF1600_StateExtractBytes_be_harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void harness(void)
88
{
99
uint64_t *state;
1010
unsigned char *data;
11-
unsigned int offset;
12-
unsigned int length;
11+
unsigned offset;
12+
unsigned length;
1313
KeccakF1600_StateExtractBytes(state, data, offset, length);
1414
}

proofs/cbmc/KeccakF1600_StateXORBytes/KeccakF1600_StateXORBytes_harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void harness(void)
88
{
99
uint64_t *state;
1010
const unsigned char *data;
11-
unsigned int offset;
12-
unsigned int length;
11+
unsigned offset;
12+
unsigned length;
1313
KeccakF1600_StateXORBytes(state, data, offset, length);
1414
}

proofs/cbmc/KeccakF1600_StateXORBytes_BE/KeccakF1600_StateXORBytes_be_harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void harness(void)
88
{
99
uint64_t *state;
1010
const unsigned char *data;
11-
unsigned int offset;
12-
unsigned int length;
11+
unsigned offset;
12+
unsigned length;
1313
KeccakF1600_StateXORBytes(state, data, offset, length);
1414
}

proofs/cbmc/KeccakF1600x4_StateExtractBytes/KeccakF1600x4_StateExtractBytes_harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ void harness(void)
88
{
99
uint64_t *state;
1010
unsigned char *data0, *data1, *data2, *data3;
11-
unsigned int offset;
12-
unsigned int length;
11+
unsigned offset;
12+
unsigned length;
1313
KeccakF1600x4_StateExtractBytes(state, data0, data1, data2, data3, offset,
1414
length);
1515
}

proofs/cbmc/KeccakF1600x4_StateXORBytes/KeccakF1600x4_StateXORBytes_harness.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ void harness(void)
88
{
99
uint64_t *state;
1010
const unsigned char *data0, *data1, *data2, *data3;
11-
unsigned int offset;
12-
unsigned int length;
11+
unsigned offset;
12+
unsigned length;
1313
KeccakF1600x4_StateXORBytes(state, data0, data1, data2, data3, offset,
1414
length);
1515
}

proofs/cbmc/rej_uniform/rej_uniform_harness.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#include "cbmc.h"
77

88
#define rej_uniform MLKEM_NAMESPACE(rej_uniform)
9-
unsigned int rej_uniform(int16_t *r, unsigned int target, unsigned int offset,
10-
const uint8_t *buf, unsigned int buflen);
9+
unsigned rej_uniform(int16_t *r, unsigned target, unsigned offset,
10+
const uint8_t *buf, unsigned buflen);
1111

1212
void harness(void)
1313
{
14-
unsigned int target, offset, inlen;
14+
unsigned target, offset, inlen;
1515
int16_t *r;
1616
uint8_t *buf;
1717

proofs/cbmc/rej_uniform_native/rej_uniform_native_harness.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#include "cbmc.h"
77

88
#define rej_uniform MLKEM_NAMESPACE(rej_uniform)
9-
unsigned int rej_uniform(int16_t *r, unsigned int target, unsigned int offset,
10-
const uint8_t *buf, unsigned int buflen);
9+
unsigned rej_uniform(int16_t *r, unsigned target, unsigned offset,
10+
const uint8_t *buf, unsigned buflen);
1111

1212
void harness(void)
1313
{
14-
unsigned int target, offset, inlen;
14+
unsigned target, offset, inlen;
1515
int16_t *r;
1616
uint8_t *buf;
1717

proofs/cbmc/rej_uniform_scalar/rej_uniform_scalar_harness.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
#include "sampling.h"
66

77
#define rej_uniform_scalar MLKEM_NAMESPACE(rej_uniform_scalar)
8-
unsigned int rej_uniform_scalar(int16_t *r, unsigned int target,
9-
unsigned int offset, const uint8_t *buf,
10-
unsigned int buflen);
8+
unsigned rej_uniform_scalar(int16_t *r, unsigned target, unsigned offset,
9+
const uint8_t *buf, unsigned buflen);
1110

1211
void harness(void)
1312
{
14-
unsigned int target, offset, inlen;
13+
unsigned target, offset, inlen;
1514
int16_t *r;
1615
uint8_t *buf;
1716

test/bench_components_mlkem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int bench(void)
6262
uint8_t nonce0 = 0, nonce1 = 1, nonce2 = 2, nonce3 = 3;
6363
uint64_t cyc[NTESTS];
6464

65-
unsigned int i, j;
65+
unsigned i, j;
6666
uint64_t t0, t1;
6767

6868
BENCH("keccak-f1600-x1", KeccakF1600_StatePermute(data0))

test/bench_mlkem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int bench(void)
5555
unsigned char kg_rand[2 * CRYPTO_BYTES], enc_rand[CRYPTO_BYTES];
5656
uint64_t cycles_kg[NTESTS], cycles_enc[NTESTS], cycles_dec[NTESTS];
5757

58-
unsigned int i, j;
58+
unsigned i, j;
5959
uint64_t t0, t1;
6060

6161

test/gen_KAT.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void print_hex(const char *label, const uint8_t *data, size_t size)
2323

2424
int main(void)
2525
{
26-
unsigned int i;
26+
unsigned i;
2727
ALIGN uint8_t coins[3 * CRYPTO_SYMBYTES];
2828
ALIGN uint8_t pk[CRYPTO_PUBLICKEYBYTES];
2929
ALIGN uint8_t sk[CRYPTO_SECRETKEYBYTES];

test/hal/hal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ uint64_t get_cyclecounter(void)
167167
F(uint32_t, kpc_get_counter_count, uint32_t) \
168168
F(uint32_t, kpc_get_config_count, uint32_t) \
169169
F(int, kperf_sample_get, int *) \
170-
F(int, kpc_get_thread_counters, int, unsigned int, void *)
170+
F(int, kpc_get_thread_counters, int, unsigned, void *)
171171

172172
#define F(ret, name, ...) \
173173
typedef ret name##proc(__VA_ARGS__); \

0 commit comments

Comments
 (0)