summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-10-03 20:14:18 +0200
committerTom Gundersen <teg@jklm.no>2015-10-05 17:33:58 +0200
commit9e77e048d412814bb14fb13cd811973a8e6e5f56 (patch)
tree6768ac0f2682418a4c786c1fd2072a00d769494a
parent708684ef227eadafc0a2e8dff04879d6cc29d0f1 (diff)
siphash24: split out the finalization step
-rw-r--r--src/basic/siphash24.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/basic/siphash24.c b/src/basic/siphash24.c
index 66e5a6105b..e7adfe48c8 100644
--- a/src/basic/siphash24.c
+++ b/src/basic/siphash24.c
@@ -72,6 +72,16 @@ static void siphash_init(struct siphash *state, const uint8_t k[16]) {
state->v3 = 0x7465646279746573ULL ^ k1;
}
+static u64 siphash24_finalize(struct siphash *state) {
+ state->v2 ^= 0xff;
+ SIPROUND(state);
+ SIPROUND(state);
+ SIPROUND(state);
+ SIPROUND(state);
+
+ return state->v0 ^ state->v1 ^ state->v2 ^ state->v3;
+}
+
/* SipHash-2-4 */
void siphash24(uint8_t out[8], const void *_in, size_t inlen, const uint8_t k[16])
{
@@ -137,11 +147,8 @@ void siphash24(uint8_t out[8], const void *_in, size_t inlen, const uint8_t k[16
printf( "(%3d) v2 %08x %08x\n", ( int )inlen, ( u32 )( state.v2 >> 32 ), ( u32 )state.v2 );
printf( "(%3d) v3 %08x %08x\n", ( int )inlen, ( u32 )( state.v3 >> 32 ), ( u32 )state.v3 );
#endif
- state.v2 ^= 0xff;
- SIPROUND(&state);
- SIPROUND(&state);
- SIPROUND(&state);
- SIPROUND(&state);
- b = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;
+
+ b = siphash24_finalize(&state);
+
U64TO8_LE( out, b );
}