Skip to content

Commit 2936545

Browse files
Performance optimization
1 parent 30f16a3 commit 2936545

File tree

2 files changed

+25
-40
lines changed

2 files changed

+25
-40
lines changed

SpritzCipher.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
SpritzCipher::SpritzCipher() { }
3434

3535

36-
static inline void
36+
static void
3737
swap(uint8_t *a, uint8_t *b)
3838
{
3939
uint8_t t = *a;
@@ -42,8 +42,8 @@ swap(uint8_t *a, uint8_t *b)
4242
}
4343

4444

45-
void
46-
SpritzCipher::stateInit(spritz_ctx *ctx)
45+
static void
46+
stateInit(spritz_ctx *ctx)
4747
{
4848
uint8_t i;
4949
ctx->i = ctx->j = ctx->k = ctx->z = ctx->a = 0;
@@ -54,17 +54,17 @@ SpritzCipher::stateInit(spritz_ctx *ctx)
5454
ctx->s[255] = 255;
5555
}
5656

57-
void
58-
SpritzCipher::update(spritz_ctx *ctx)
57+
static void
58+
update(spritz_ctx *ctx)
5959
{
6060
ctx->i = (uint8_t)(ctx->i + ctx->w);
6161
ctx->j = (uint8_t)(ctx->k + ctx->s[(uint8_t)(ctx->j + ctx->s[ctx->i])]);
6262
ctx->k = (uint8_t)(ctx->k + ctx->i + ctx->s[ctx->j]);
6363
swap(&ctx->s[ctx->i], &ctx->s[ctx->j]);
6464
}
6565

66-
void
67-
SpritzCipher::whip(spritz_ctx *ctx)
66+
static void
67+
whip(spritz_ctx *ctx)
6868
{
6969
uint8_t i;
7070
for (i = 0; i < SPRITZ_N_HALF; i++) {
@@ -76,8 +76,8 @@ SpritzCipher::whip(spritz_ctx *ctx)
7676
ctx->w = (uint8_t)(ctx->w + 2);
7777
}
7878

79-
void
80-
SpritzCipher::crush(spritz_ctx *ctx)
79+
static void
80+
crush(spritz_ctx *ctx)
8181
{
8282
uint8_t i, j;
8383
#ifdef SAFE_TIMING_CRUSH
@@ -102,8 +102,8 @@ SpritzCipher::crush(spritz_ctx *ctx)
102102
}
103103
}
104104

105-
void
106-
SpritzCipher::shuffle(spritz_ctx *ctx)
105+
static void
106+
shuffle(spritz_ctx *ctx)
107107
{
108108
whip(ctx);
109109
crush(ctx);
@@ -114,47 +114,47 @@ SpritzCipher::shuffle(spritz_ctx *ctx)
114114
}
115115

116116
/* Tip: nibble=4bit; octet=2*nibble=8bit; byte=octet in modern computers */
117-
void
118-
SpritzCipher::absorbNibble(spritz_ctx *ctx, const uint8_t nibble)
117+
static void
118+
absorbNibble(spritz_ctx *ctx, const uint8_t nibble)
119119
{
120120
if (ctx->a == SPRITZ_N_HALF) {
121121
shuffle(ctx);
122122
}
123123
swap(&ctx->s[ctx->a], &ctx->s[SPRITZ_N_HALF + nibble]);
124124
ctx->a++;
125125
}
126-
void
127-
SpritzCipher::absorb(spritz_ctx *ctx, const uint8_t octet)
126+
static void
127+
absorb(spritz_ctx *ctx, const uint8_t octet)
128128
{
129129
absorbNibble(ctx, octet % 16); /* Low */
130130
absorbNibble(ctx, octet / 16); /* High */
131131
}
132-
void
133-
SpritzCipher::absorbBytes(spritz_ctx *ctx, const uint8_t *buf, unsigned int len)
132+
static void
133+
absorbBytes(spritz_ctx *ctx, const uint8_t *buf, unsigned int len)
134134
{
135135
unsigned int i;
136136
for (i = 0; i < len; i++) {
137137
absorb(ctx, buf[i]);
138138
}
139139
}
140140

141-
void
142-
SpritzCipher::absorbStop(spritz_ctx *ctx)
141+
static void
142+
absorbStop(spritz_ctx *ctx)
143143
{
144144
if (ctx->a == SPRITZ_N_HALF) {
145145
shuffle(ctx);
146146
}
147147
ctx->a++;
148148
}
149149

150-
uint8_t
151-
SpritzCipher::output(spritz_ctx *ctx)
150+
static uint8_t
151+
output(spritz_ctx *ctx)
152152
{
153153
ctx->z = ctx->s[(uint8_t)(ctx->j + ctx->s[(uint8_t)(ctx->i + ctx->s[(uint8_t)(ctx->z + ctx->k)])])];
154154
return ctx->z;
155155
}
156-
uint8_t
157-
SpritzCipher::drip(spritz_ctx *ctx)
156+
static uint8_t
157+
drip(spritz_ctx *ctx)
158158
{
159159
if (ctx->a) {
160160
shuffle(ctx);
@@ -164,8 +164,8 @@ SpritzCipher::drip(spritz_ctx *ctx)
164164
}
165165

166166
/* squeeze() for hash() and mac() */
167-
void
168-
SpritzCipher::squeeze(spritz_ctx *ctx, uint8_t *out, uint8_t len)
167+
static void
168+
squeeze(spritz_ctx *ctx, uint8_t *out, uint8_t len)
169169
{
170170
uint8_t i;
171171
if (ctx->a) {

SpritzCipher.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,6 @@ class SpritzCipher
181181
mac(uint8_t *digest, uint8_t digestLen,
182182
const uint8_t *msg, unsigned int msgLen,
183183
const uint8_t *key, unsigned int keyLen);
184-
185-
186-
private:
187-
void stateInit(spritz_ctx *ctx);
188-
void update(spritz_ctx *ctx);
189-
void whip(spritz_ctx *ctx);
190-
void crush(spritz_ctx *ctx);
191-
void shuffle(spritz_ctx *ctx);
192-
void absorbNibble(spritz_ctx *ctx, const uint8_t nibble);
193-
void absorb(spritz_ctx *ctx, const uint8_t octet);
194-
void absorbBytes(spritz_ctx *ctx, const uint8_t *buf, unsigned int len);
195-
void absorbStop(spritz_ctx *ctx);
196-
uint8_t output(spritz_ctx *ctx);
197-
uint8_t drip(spritz_ctx *ctx);
198-
void squeeze(spritz_ctx *ctx, uint8_t *out, uint8_t len);
199184
};
200185

201186

0 commit comments

Comments
 (0)