Skip to content

Commit

Permalink
add leading underscores to sober128 helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
buggywhip committed Oct 15, 2018
1 parent 646f778 commit d054762
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 40 deletions.
1 change: 0 additions & 1 deletion helper.pl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ sub check_source {
$file !~ m|src/ciphers/.*\.c$| &&
$file !~ m|src/hashes/.*\.c$| &&
$file !~ m|src/math/.+_desc.c$| &&
$file !~ m|src/stream/sober128/sober128_stream.c$| &&
$l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([^_][a-zA-Z0-9_]+)\s*\(/) {
push @{$troubles->{staticfunc_name}}, "$lineno($2)";
}
Expand Down
10 changes: 5 additions & 5 deletions src/stream/sober128/sober128_stream_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#if defined(LTC_SOBER128_STREAM_SETUP) || defined(LTC_SOBER128_STREAM_SETIV)

/* local prototypes */
static void s128_diffuse(sober128_state *st);
static void _s128_diffuse(sober128_state *st);

#endif /* LTC_SOBER128_STREAM_SETUP || LTC_SOBER128_STREAM_SETIV */

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

static void cycle(ulong32 *R)
static void _cycle(ulong32 *R)
{
ulong32 t;
int i;
Expand All @@ -67,7 +67,7 @@ static void cycle(ulong32 *R)
t = t + st->R[OFF(z,13)]; \
}

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

/* s128_diffuse() used in sober128_stream_setup() and sober128_stream_setiv() */
static void s128_diffuse(sober128_state *st)
/* _s128_diffuse() used in sober128_stream_setup() and sober128_stream_setiv() */
static void _s128_diffuse(sober128_state *st)
{
ulong32 t;
/* relies on FOLD == N == 17! */
Expand Down
14 changes: 7 additions & 7 deletions src/stream/sober128/sober128_stream_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "sober128_stream_common.h"


static void XORWORD(ulong32 w, const unsigned char *in, unsigned char *out)
static void _xorword(ulong32 w, const unsigned char *in, unsigned char *out)
{
ulong32 t;
LOAD32L(t, in);
Expand All @@ -33,7 +33,7 @@ static void XORWORD(ulong32 w, const unsigned char *in, unsigned char *out)

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

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

/* do small or odd size buffers the slow way */
while (4 <= inlen) {
cycle(st->R);
t = nltap(st);
XORWORD(t, in, out);
_cycle(st->R);
t = _nltap(st);
_xorword(t, in, out);
out += 4;
in += 4;
inlen -= 4;
}

/* handle any trailing bytes */
if (inlen != 0) {
cycle(st->R);
st->sbuf = nltap(st);
_cycle(st->R);
st->sbuf = _nltap(st);
st->nbuf = 32;
while (st->nbuf != 0 && inlen != 0) {
*out++ = *in++ ^ (unsigned char)(st->sbuf & 0xFF);
Expand Down
15 changes: 5 additions & 10 deletions src/stream/sober128/sober128_stream_setiv.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@
#include "sober128_stream_common.h"
#undef LTC_SOBER128_STREAM_SETIV

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

/* initialise to previously saved register state
*/
static void s128_reloadstate(sober128_state *st)
static void _s128_reloadstate(sober128_state *st)
{
int i;

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

/* ok we are adding an IV then... */
s128_reloadstate(st);
_s128_reloadstate(st);

/* ivlen must be multiple of 4 bytes */
if ((ivlen & 3) != 0) {
Expand All @@ -67,15 +62,15 @@ int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned
for (i = 0; i < ivlen; i += 4) {
LOAD32L(k, (unsigned char *)&iv[i]);
ADDKEY(k);
cycle(st->R);
XORNL(nltap(st));
_cycle(st->R);
XORNL(_nltap(st));
}

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

/* now diffuse */
s128_diffuse(st);
_s128_diffuse(st);
st->nbuf = 0;

return CRYPT_OK;
Expand Down
30 changes: 13 additions & 17 deletions src/stream/sober128/sober128_stream_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,28 @@
#include "sober128_stream_common.h"
#undef LTC_SOBER128_STREAM_SETUP

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


/* Save the current register state
/*
* Save the current register state
*/
static void s128_savestate(sober128_state *st)
static void _s128_savestate(sober128_state *st)
{
int i;
for (i = 0; i < N; ++i) {
st->initR[i] = st->R[i];
}
}

/* Initialise "konst"
/*
* Initialise "konst"
*/
static void s128_genkonst(sober128_state *st)
static void _s128_genkonst(sober128_state *st)
{
ulong32 newkonst;

do {
cycle(st->R);
newkonst = nltap(st);
_cycle(st->R);
newkonst = _nltap(st);
} while ((newkonst & 0xFF000000) == 0);
st->konst = newkonst;
}
Expand Down Expand Up @@ -85,17 +81,17 @@ int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned
for (i = 0; i < keylen; i += 4) {
LOAD32L(k, (unsigned char *)&key[i]);
ADDKEY(k);
cycle(st->R);
XORNL(nltap(st));
_cycle(st->R);
XORNL(_nltap(st));
}

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

/* now diffuse */
s128_diffuse(st);
s128_genkonst(st);
s128_savestate(st);
_s128_diffuse(st);
_s128_genkonst(st);
_s128_savestate(st);
st->nbuf = 0;

return CRYPT_OK;
Expand Down

0 comments on commit d054762

Please sign in to comment.