Skip to content

Commit 75bb0c5

Browse files
committed
also prefix static hash functions by s_
1 parent 4fd7b50 commit 75bb0c5

File tree

17 files changed

+155
-156
lines changed

17 files changed

+155
-156
lines changed

helper.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ sub check_source {
6161
push @{$troubles->{sizeof_no_brackets}}, $lineno if $file =~ /^src\/.*\.c$/ && $l =~ /\bsizeof\s*[^\(]/;
6262
if ($file =~ m|src/.*\.c$| &&
6363
$file !~ m|src/ciphers/.*\.c$| &&
64-
$file !~ m|src/hashes/.*\.c$| &&
6564
$file !~ m|src/math/.+_desc.c$| &&
6665
$file !~ m|src/pk/ec25519/tweetnacl.c$| &&
6766
$file !~ m|src/stream/sober128/sober128_stream.c$| &&
68-
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([^s][a-zA-Z0-9_]+)\s*\(/) {
67+
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s++([^s][a-zA-Z0-9_]+)\s*\(/) {
6968
push @{$troubles->{staticfunc_name}}, "$2";
7069
}
7170
if ($file =~ m|src/.*\.[ch]$| && $l =~ /^\s*#\s*define\s+(_[A-Z_][a-zA-Z0-9_]*)\b/) {

src/hashes/blake2b.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,26 @@ static const unsigned char blake2b_sigma[12][16] =
147147
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
148148
};
149149

150-
static void blake2b_set_lastnode(hash_state *md) { md->blake2b.f[1] = CONST64(0xffffffffffffffff); }
150+
static void s_blake2b_set_lastnode(hash_state *md) { md->blake2b.f[1] = CONST64(0xffffffffffffffff); }
151151

152152
/* Some helper functions, not necessarily useful */
153-
static int blake2b_is_lastblock(const hash_state *md) { return md->blake2b.f[0] != 0; }
153+
static int s_blake2b_is_lastblock(const hash_state *md) { return md->blake2b.f[0] != 0; }
154154

155-
static void blake2b_set_lastblock(hash_state *md)
155+
static void s_blake2b_set_lastblock(hash_state *md)
156156
{
157157
if (md->blake2b.last_node) {
158-
blake2b_set_lastnode(md);
158+
s_blake2b_set_lastnode(md);
159159
}
160160
md->blake2b.f[0] = CONST64(0xffffffffffffffff);
161161
}
162162

163-
static void blake2b_increment_counter(hash_state *md, ulong64 inc)
163+
static void s_blake2b_increment_counter(hash_state *md, ulong64 inc)
164164
{
165165
md->blake2b.t[0] += inc;
166166
if (md->blake2b.t[0] < inc) md->blake2b.t[1]++;
167167
}
168168

169-
static void blake2b_init0(hash_state *md)
169+
static void s_blake2b_init0(hash_state *md)
170170
{
171171
unsigned long i;
172172
XMEMSET(&md->blake2b, 0, sizeof(md->blake2b));
@@ -177,11 +177,11 @@ static void blake2b_init0(hash_state *md)
177177
}
178178

179179
/* init xors IV with input parameter block */
180-
static int blake2b_init_param(hash_state *md, const unsigned char *P)
180+
static int s_blake2b_init_param(hash_state *md, const unsigned char *P)
181181
{
182182
unsigned long i;
183183

184-
blake2b_init0(md);
184+
s_blake2b_init0(md);
185185

186186
/* IV XOR ParamBlock */
187187
for (i = 0; i < 8; ++i) {
@@ -228,7 +228,7 @@ int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key,
228228
P[O_FANOUT] = 1;
229229
P[O_DEPTH] = 1;
230230

231-
err = blake2b_init_param(md, P);
231+
err = s_blake2b_init_param(md, P);
232232
if (err != CRYPT_OK) return err;
233233

234234
if (key) {
@@ -299,9 +299,9 @@ int blake2b_512_init(hash_state *md) { return blake2b_init(md, 64, NULL, 0); }
299299
} while (0)
300300

301301
#ifdef LTC_CLEAN_STACK
302-
static int _blake2b_compress(hash_state *md, const unsigned char *buf)
302+
static int s__blake2b_compress(hash_state *md, const unsigned char *buf)
303303
#else
304-
static int blake2b_compress(hash_state *md, const unsigned char *buf)
304+
static int s_blake2b_compress(hash_state *md, const unsigned char *buf)
305305
#endif
306306
{
307307
ulong64 m[16];
@@ -348,10 +348,10 @@ static int blake2b_compress(hash_state *md, const unsigned char *buf)
348348
#undef ROUND
349349

350350
#ifdef LTC_CLEAN_STACK
351-
static int blake2b_compress(hash_state *md, const unsigned char *buf)
351+
static int s_blake2b_compress(hash_state *md, const unsigned char *buf)
352352
{
353353
int err;
354-
err = _blake2b_compress(md, buf);
354+
err = s__blake2b_compress(md, buf);
355355
burn_stack(sizeof(ulong64) * 32 + sizeof(unsigned long));
356356
return err;
357357
}
@@ -379,13 +379,13 @@ int blake2b_process(hash_state *md, const unsigned char *in, unsigned long inlen
379379
if (inlen > fill) {
380380
md->blake2b.curlen = 0;
381381
XMEMCPY(md->blake2b.buf + (left % sizeof(md->blake2b.buf)), in, fill); /* Fill buffer */
382-
blake2b_increment_counter(md, BLAKE2B_BLOCKBYTES);
383-
blake2b_compress(md, md->blake2b.buf); /* Compress */
382+
s_blake2b_increment_counter(md, BLAKE2B_BLOCKBYTES);
383+
s_blake2b_compress(md, md->blake2b.buf); /* Compress */
384384
in += fill;
385385
inlen -= fill;
386386
while (inlen > BLAKE2B_BLOCKBYTES) {
387-
blake2b_increment_counter(md, BLAKE2B_BLOCKBYTES);
388-
blake2b_compress(md, in);
387+
s_blake2b_increment_counter(md, BLAKE2B_BLOCKBYTES);
388+
s_blake2b_compress(md, in);
389389
in += BLAKE2B_BLOCKBYTES;
390390
inlen -= BLAKE2B_BLOCKBYTES;
391391
}
@@ -412,14 +412,14 @@ int blake2b_done(hash_state *md, unsigned char *out)
412412

413413
/* if(md->blakebs.outlen != outlen) return CRYPT_INVALID_ARG; */
414414

415-
if (blake2b_is_lastblock(md)) {
415+
if (s_blake2b_is_lastblock(md)) {
416416
return CRYPT_ERROR;
417417
}
418418

419-
blake2b_increment_counter(md, md->blake2b.curlen);
420-
blake2b_set_lastblock(md);
419+
s_blake2b_increment_counter(md, md->blake2b.curlen);
420+
s_blake2b_set_lastblock(md);
421421
XMEMSET(md->blake2b.buf + md->blake2b.curlen, 0, BLAKE2B_BLOCKBYTES - md->blake2b.curlen); /* Padding */
422-
blake2b_compress(md, md->blake2b.buf);
422+
s_blake2b_compress(md, md->blake2b.buf);
423423

424424
for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
425425
STORE64L(md->blake2b.h[i], buffer + i * 8);

src/hashes/blake2s.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,26 @@ static const unsigned char blake2s_sigma[10][16] = {
139139
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
140140
};
141141

142-
static void blake2s_set_lastnode(hash_state *md) { md->blake2s.f[1] = 0xffffffffUL; }
142+
static void s_blake2s_set_lastnode(hash_state *md) { md->blake2s.f[1] = 0xffffffffUL; }
143143

144144
/* Some helper functions, not necessarily useful */
145-
static int blake2s_is_lastblock(const hash_state *md) { return md->blake2s.f[0] != 0; }
145+
static int s_blake2s_is_lastblock(const hash_state *md) { return md->blake2s.f[0] != 0; }
146146

147-
static void blake2s_set_lastblock(hash_state *md)
147+
static void s_blake2s_set_lastblock(hash_state *md)
148148
{
149149
if (md->blake2s.last_node) {
150-
blake2s_set_lastnode(md);
150+
s_blake2s_set_lastnode(md);
151151
}
152152
md->blake2s.f[0] = 0xffffffffUL;
153153
}
154154

155-
static void blake2s_increment_counter(hash_state *md, const ulong32 inc)
155+
static void s_blake2s_increment_counter(hash_state *md, const ulong32 inc)
156156
{
157157
md->blake2s.t[0] += inc;
158158
if (md->blake2s.t[0] < inc) md->blake2s.t[1]++;
159159
}
160160

161-
static int blake2s_init0(hash_state *md)
161+
static int s_blake2s_init0(hash_state *md)
162162
{
163163
int i;
164164
XMEMSET(&md->blake2s, 0, sizeof(struct blake2s_state));
@@ -171,11 +171,11 @@ static int blake2s_init0(hash_state *md)
171171
}
172172

173173
/* init2 xors IV with input parameter block */
174-
static int blake2s_init_param(hash_state *md, const unsigned char *P)
174+
static int s_blake2s_init_param(hash_state *md, const unsigned char *P)
175175
{
176176
unsigned long i;
177177

178-
blake2s_init0(md);
178+
s_blake2s_init0(md);
179179

180180
/* IV XOR ParamBlock */
181181
for (i = 0; i < 8; ++i) {
@@ -222,7 +222,7 @@ int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key,
222222
P[O_FANOUT] = 1;
223223
P[O_DEPTH] = 1;
224224

225-
err = blake2s_init_param(md, P);
225+
err = s_blake2s_init_param(md, P);
226226
if (err != CRYPT_OK) return err;
227227

228228
if (key) {
@@ -291,9 +291,9 @@ int blake2s_256_init(hash_state *md) { return blake2s_init(md, 32, NULL, 0); }
291291
} while (0)
292292

293293
#ifdef LTC_CLEAN_STACK
294-
static int _blake2s_compress(hash_state *md, const unsigned char *buf)
294+
static int s__blake2s_compress(hash_state *md, const unsigned char *buf)
295295
#else
296-
static int blake2s_compress(hash_state *md, const unsigned char *buf)
296+
static int s_blake2s_compress(hash_state *md, const unsigned char *buf)
297297
#endif
298298
{
299299
unsigned long i;
@@ -337,10 +337,10 @@ static int blake2s_compress(hash_state *md, const unsigned char *buf)
337337
#undef ROUND
338338

339339
#ifdef LTC_CLEAN_STACK
340-
static int blake2s_compress(hash_state *md, const unsigned char *buf)
340+
static int s_blake2s_compress(hash_state *md, const unsigned char *buf)
341341
{
342342
int err;
343-
err = _blake2s_compress(md, buf);
343+
err = s__blake2s_compress(md, buf);
344344
burn_stack(sizeof(ulong32) * (32) + sizeof(unsigned long));
345345
return err;
346346
}
@@ -368,13 +368,13 @@ int blake2s_process(hash_state *md, const unsigned char *in, unsigned long inlen
368368
if (inlen > fill) {
369369
md->blake2s.curlen = 0;
370370
XMEMCPY(md->blake2s.buf + (left % sizeof(md->blake2s.buf)), in, fill); /* Fill buffer */
371-
blake2s_increment_counter(md, BLAKE2S_BLOCKBYTES);
372-
blake2s_compress(md, md->blake2s.buf); /* Compress */
371+
s_blake2s_increment_counter(md, BLAKE2S_BLOCKBYTES);
372+
s_blake2s_compress(md, md->blake2s.buf); /* Compress */
373373
in += fill;
374374
inlen -= fill;
375375
while (inlen > BLAKE2S_BLOCKBYTES) {
376-
blake2s_increment_counter(md, BLAKE2S_BLOCKBYTES);
377-
blake2s_compress(md, in);
376+
s_blake2s_increment_counter(md, BLAKE2S_BLOCKBYTES);
377+
s_blake2s_compress(md, in);
378378
in += BLAKE2S_BLOCKBYTES;
379379
inlen -= BLAKE2S_BLOCKBYTES;
380380
}
@@ -401,13 +401,13 @@ int blake2s_done(hash_state *md, unsigned char *out)
401401

402402
/* if(md->blake2s.outlen != outlen) return CRYPT_INVALID_ARG; */
403403

404-
if (blake2s_is_lastblock(md)) {
404+
if (s_blake2s_is_lastblock(md)) {
405405
return CRYPT_ERROR;
406406
}
407-
blake2s_increment_counter(md, md->blake2s.curlen);
408-
blake2s_set_lastblock(md);
407+
s_blake2s_increment_counter(md, md->blake2s.curlen);
408+
s_blake2s_set_lastblock(md);
409409
XMEMSET(md->blake2s.buf + md->blake2s.curlen, 0, BLAKE2S_BLOCKBYTES - md->blake2s.curlen); /* Padding */
410-
blake2s_compress(md, md->blake2s.buf);
410+
s_blake2s_compress(md, md->blake2s.buf);
411411

412412
for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
413413
STORE32L(md->blake2s.h[i], buffer + i * 4);

src/hashes/chc/chc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int chc_init(hash_state *md)
121121
T0 <= encrypt T0
122122
state <= state xor T0 xor T1
123123
*/
124-
static int chc_compress(hash_state *md, const unsigned char *buf)
124+
static int s_chc_compress(hash_state *md, const unsigned char *buf)
125125
{
126126
unsigned char T[2][MAXBLOCKSIZE];
127127
symmetric_key *key;
@@ -154,8 +154,8 @@ static int chc_compress(hash_state *md, const unsigned char *buf)
154154
@param len The length of the data (octets)
155155
@return CRYPT_OK if successful
156156
*/
157-
static int _chc_process(hash_state * md, const unsigned char *in, unsigned long inlen);
158-
static HASH_PROCESS(_chc_process, chc_compress, chc, (unsigned long)cipher_blocksize)
157+
static int s__chc_process(hash_state * md, const unsigned char *in, unsigned long inlen);
158+
static HASH_PROCESS(s__chc_process, s_chc_compress, chc, (unsigned long)cipher_blocksize)
159159

160160
/**
161161
Process a block of memory though the hash
@@ -179,7 +179,7 @@ int chc_process(hash_state * md, const unsigned char *in, unsigned long inlen)
179179
return CRYPT_INVALID_CIPHER;
180180
}
181181

182-
return _chc_process(md, in, inlen);
182+
return s__chc_process(md, in, inlen);
183183
}
184184

185185
/**
@@ -221,7 +221,7 @@ int chc_done(hash_state *md, unsigned char *out)
221221
while (md->chc.curlen < (unsigned long)cipher_blocksize) {
222222
md->chc.buf[md->chc.curlen++] = (unsigned char)0;
223223
}
224-
chc_compress(md, md->chc.buf);
224+
s_chc_compress(md, md->chc.buf);
225225
md->chc.curlen = 0;
226226
}
227227

@@ -232,7 +232,7 @@ int chc_done(hash_state *md, unsigned char *out)
232232

233233
/* store length */
234234
STORE64L(md->chc.length, md->chc.buf+(cipher_blocksize-8));
235-
chc_compress(md, md->chc.buf);
235+
s_chc_compress(md, md->chc.buf);
236236

237237
/* copy output */
238238
XMEMCPY(out, md->chc.state, cipher_blocksize);

src/hashes/md2.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const unsigned char PI_SUBST[256] = {
4949
};
5050

5151
/* adds 16 bytes to the checksum */
52-
static void md2_update_chksum(hash_state *md)
52+
static void s_md2_update_chksum(hash_state *md)
5353
{
5454
int j;
5555
unsigned char L;
@@ -63,7 +63,7 @@ static void md2_update_chksum(hash_state *md)
6363
}
6464
}
6565

66-
static void md2_compress(hash_state *md)
66+
static void s_md2_compress(hash_state *md)
6767
{
6868
int j, k;
6969
unsigned char t;
@@ -126,8 +126,8 @@ int md2_process(hash_state *md, const unsigned char *in, unsigned long inlen)
126126

127127
/* is 16 bytes full? */
128128
if (md->md2.curlen == 16) {
129-
md2_compress(md);
130-
md2_update_chksum(md);
129+
s_md2_compress(md);
130+
s_md2_update_chksum(md);
131131
md->md2.curlen = 0;
132132
}
133133
}
@@ -159,12 +159,12 @@ int md2_done(hash_state * md, unsigned char *out)
159159
}
160160

161161
/* hash and update */
162-
md2_compress(md);
163-
md2_update_chksum(md);
162+
s_md2_compress(md);
163+
s_md2_update_chksum(md);
164164

165165
/* hash checksum */
166166
XMEMCPY(md->md2.buf, md->md2.chksum, 16);
167-
md2_compress(md);
167+
s_md2_compress(md);
168168

169169
/* output is lower 16 bytes of X */
170170
XMEMCPY(out, md->md2.X, 16);

src/hashes/md4.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ const struct ltc_hash_descriptor md4_desc =
6565
}
6666

6767
#ifdef LTC_CLEAN_STACK
68-
static int _md4_compress(hash_state *md, const unsigned char *buf)
68+
static int s__md4_compress(hash_state *md, const unsigned char *buf)
6969
#else
70-
static int md4_compress(hash_state *md, const unsigned char *buf)
70+
static int s_md4_compress(hash_state *md, const unsigned char *buf)
7171
#endif
7272
{
7373
ulong32 x[16], a, b, c, d;
@@ -149,10 +149,10 @@ static int md4_compress(hash_state *md, const unsigned char *buf)
149149
}
150150

151151
#ifdef LTC_CLEAN_STACK
152-
static int md4_compress(hash_state *md, const unsigned char *buf)
152+
static int s_md4_compress(hash_state *md, const unsigned char *buf)
153153
{
154154
int err;
155-
err = _md4_compress(md, buf);
155+
err = s__md4_compress(md, buf);
156156
burn_stack(sizeof(ulong32) * 20 + sizeof(int));
157157
return err;
158158
}
@@ -182,7 +182,7 @@ int md4_init(hash_state * md)
182182
@param inlen The length of the data (octets)
183183
@return CRYPT_OK if successful
184184
*/
185-
HASH_PROCESS(md4_process, md4_compress, md4, 64)
185+
HASH_PROCESS(md4_process, s_md4_compress, md4, 64)
186186

187187
/**
188188
Terminate the hash to get the digest
@@ -215,7 +215,7 @@ int md4_done(hash_state * md, unsigned char *out)
215215
while (md->md4.curlen < 64) {
216216
md->md4.buf[md->md4.curlen++] = (unsigned char)0;
217217
}
218-
md4_compress(md, md->md4.buf);
218+
s_md4_compress(md, md->md4.buf);
219219
md->md4.curlen = 0;
220220
}
221221

@@ -226,7 +226,7 @@ int md4_done(hash_state * md, unsigned char *out)
226226

227227
/* store length */
228228
STORE64L(md->md4.length, md->md4.buf+56);
229-
md4_compress(md, md->md4.buf);
229+
s_md4_compress(md, md->md4.buf);
230230

231231
/* copy output */
232232
for (i = 0; i < 4; i++) {

0 commit comments

Comments
 (0)