Skip to content

Commit d054762

Browse files
committed
add leading underscores to sober128 helper functions
1 parent 646f778 commit d054762

File tree

5 files changed

+30
-40
lines changed

5 files changed

+30
-40
lines changed

helper.pl

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ sub check_source {
6262
$file !~ m|src/ciphers/.*\.c$| &&
6363
$file !~ m|src/hashes/.*\.c$| &&
6464
$file !~ m|src/math/.+_desc.c$| &&
65-
$file !~ m|src/stream/sober128/sober128_stream.c$| &&
6665
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([^_][a-zA-Z0-9_]+)\s*\(/) {
6766
push @{$troubles->{staticfunc_name}}, "$lineno($2)";
6867
}

src/stream/sober128/sober128_stream_common.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#if defined(LTC_SOBER128_STREAM_SETUP) || defined(LTC_SOBER128_STREAM_SETIV)
2121

2222
/* local prototypes */
23-
static void s128_diffuse(sober128_state *st);
23+
static void _s128_diffuse(sober128_state *st);
2424

2525
#endif /* LTC_SOBER128_STREAM_SETUP || LTC_SOBER128_STREAM_SETIV */
2626

@@ -42,7 +42,7 @@ static void s128_diffuse(sober128_state *st);
4242
#define STEP(R,z) \
4343
R[OFF(z,0)] = R[OFF(z,15)] ^ R[OFF(z,4)] ^ (R[OFF(z,0)] << 8) ^ Multab[(R[OFF(z,0)] >> 24) & 0xFF];
4444

45-
static void cycle(ulong32 *R)
45+
static void _cycle(ulong32 *R)
4646
{
4747
ulong32 t;
4848
int i;
@@ -67,7 +67,7 @@ static void cycle(ulong32 *R)
6767
t = t + st->R[OFF(z,13)]; \
6868
}
6969

70-
static ulong32 nltap(const sober128_state *st)
70+
static ulong32 _nltap(const sober128_state *st)
7171
{
7272
ulong32 t;
7373
NLFUNC(st, 0);
@@ -89,8 +89,8 @@ static ulong32 nltap(const sober128_state *st)
8989
/* nonlinear diffusion of register for key */
9090
#define DROUND(z) STEP(st->R,z); NLFUNC(st,(z+1)); st->R[OFF((z+1),FOLDP)] ^= t;
9191

92-
/* s128_diffuse() used in sober128_stream_setup() and sober128_stream_setiv() */
93-
static void s128_diffuse(sober128_state *st)
92+
/* _s128_diffuse() used in sober128_stream_setup() and sober128_stream_setiv() */
93+
static void _s128_diffuse(sober128_state *st)
9494
{
9595
ulong32 t;
9696
/* relies on FOLD == N == 17! */

src/stream/sober128/sober128_stream_crypt.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "sober128_stream_common.h"
2323

2424

25-
static void XORWORD(ulong32 w, const unsigned char *in, unsigned char *out)
25+
static void _xorword(ulong32 w, const unsigned char *in, unsigned char *out)
2626
{
2727
ulong32 t;
2828
LOAD32L(t, in);
@@ -33,7 +33,7 @@ static void XORWORD(ulong32 w, const unsigned char *in, unsigned char *out)
3333

3434
/* XOR pseudo-random bytes into buffer
3535
*/
36-
#define SROUND(z) STEP(st->R,z); NLFUNC(st,(z+1)); XORWORD(t, in+(z*4), out+(z*4));
36+
#define SROUND(z) STEP(st->R,z); NLFUNC(st,(z+1)); _xorword(t, in+(z*4), out+(z*4));
3737

3838
/**
3939
Encrypt (or decrypt) bytes of ciphertext (or plaintext) with Sober128
@@ -87,18 +87,18 @@ int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned
8787

8888
/* do small or odd size buffers the slow way */
8989
while (4 <= inlen) {
90-
cycle(st->R);
91-
t = nltap(st);
92-
XORWORD(t, in, out);
90+
_cycle(st->R);
91+
t = _nltap(st);
92+
_xorword(t, in, out);
9393
out += 4;
9494
in += 4;
9595
inlen -= 4;
9696
}
9797

9898
/* handle any trailing bytes */
9999
if (inlen != 0) {
100-
cycle(st->R);
101-
st->sbuf = nltap(st);
100+
_cycle(st->R);
101+
st->sbuf = _nltap(st);
102102
st->nbuf = 32;
103103
while (st->nbuf != 0 && inlen != 0) {
104104
*out++ = *in++ ^ (unsigned char)(st->sbuf & 0xFF);

src/stream/sober128/sober128_stream_setiv.c

+5-10
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@
2323
#include "sober128_stream_common.h"
2424
#undef LTC_SOBER128_STREAM_SETIV
2525

26-
/* don't change these... */
27-
#define N 17
28-
#define INITKONST 0x6996c53a /* value of KONST to use during key loading */
29-
#define KEYP 15 /* where to insert key words */
30-
#define FOLDP 4 /* where to insert non-linear feedback */
3126

3227
/* initialise to previously saved register state
3328
*/
34-
static void s128_reloadstate(sober128_state *st)
29+
static void _s128_reloadstate(sober128_state *st)
3530
{
3631
int i;
3732

@@ -57,7 +52,7 @@ int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned
5752
LTC_ARGCHK(ivlen > 0);
5853

5954
/* ok we are adding an IV then... */
60-
s128_reloadstate(st);
55+
_s128_reloadstate(st);
6156

6257
/* ivlen must be multiple of 4 bytes */
6358
if ((ivlen & 3) != 0) {
@@ -67,15 +62,15 @@ int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned
6762
for (i = 0; i < ivlen; i += 4) {
6863
LOAD32L(k, (unsigned char *)&iv[i]);
6964
ADDKEY(k);
70-
cycle(st->R);
71-
XORNL(nltap(st));
65+
_cycle(st->R);
66+
XORNL(_nltap(st));
7267
}
7368

7469
/* also fold in the length of the key */
7570
ADDKEY(ivlen);
7671

7772
/* now diffuse */
78-
s128_diffuse(st);
73+
_s128_diffuse(st);
7974
st->nbuf = 0;
8075

8176
return CRYPT_OK;

src/stream/sober128/sober128_stream_setup.c

+13-17
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,28 @@
2323
#include "sober128_stream_common.h"
2424
#undef LTC_SOBER128_STREAM_SETUP
2525

26-
/* don't change these... */
27-
#define N 17
28-
#define INITKONST 0x6996c53a /* value of KONST to use during key loading */
29-
#define KEYP 15 /* where to insert key words */
30-
#define FOLDP 4 /* where to insert non-linear feedback */
3126

32-
33-
/* Save the current register state
27+
/*
28+
* Save the current register state
3429
*/
35-
static void s128_savestate(sober128_state *st)
30+
static void _s128_savestate(sober128_state *st)
3631
{
3732
int i;
3833
for (i = 0; i < N; ++i) {
3934
st->initR[i] = st->R[i];
4035
}
4136
}
4237

43-
/* Initialise "konst"
38+
/*
39+
* Initialise "konst"
4440
*/
45-
static void s128_genkonst(sober128_state *st)
41+
static void _s128_genkonst(sober128_state *st)
4642
{
4743
ulong32 newkonst;
4844

4945
do {
50-
cycle(st->R);
51-
newkonst = nltap(st);
46+
_cycle(st->R);
47+
newkonst = _nltap(st);
5248
} while ((newkonst & 0xFF000000) == 0);
5349
st->konst = newkonst;
5450
}
@@ -85,17 +81,17 @@ int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned
8581
for (i = 0; i < keylen; i += 4) {
8682
LOAD32L(k, (unsigned char *)&key[i]);
8783
ADDKEY(k);
88-
cycle(st->R);
89-
XORNL(nltap(st));
84+
_cycle(st->R);
85+
XORNL(_nltap(st));
9086
}
9187

9288
/* also fold in the length of the key */
9389
ADDKEY(keylen);
9490

9591
/* now diffuse */
96-
s128_diffuse(st);
97-
s128_genkonst(st);
98-
s128_savestate(st);
92+
_s128_diffuse(st);
93+
_s128_genkonst(st);
94+
_s128_savestate(st);
9995
st->nbuf = 0;
10096

10197
return CRYPT_OK;

0 commit comments

Comments
 (0)