Lines Matching refs:state

30 static inline void sipround(struct siphash *state) {
31 assert(state);
33 state->v0 += state->v1;
34 state->v1 = rotate_left(state->v1, 13);
35 state->v1 ^= state->v0;
36 state->v0 = rotate_left(state->v0, 32);
37 state->v2 += state->v3;
38 state->v3 = rotate_left(state->v3, 16);
39 state->v3 ^= state->v2;
40 state->v0 += state->v3;
41 state->v3 = rotate_left(state->v3, 21);
42 state->v3 ^= state->v0;
43 state->v2 += state->v1;
44 state->v1 = rotate_left(state->v1, 17);
45 state->v1 ^= state->v2;
46 state->v2 = rotate_left(state->v2, 32);
49 void siphash24_init(struct siphash *state, const uint8_t k[16]) {
52 assert(state);
58 *state = (struct siphash) {
69 void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
73 size_t left = state->inlen & 7;
77 assert(state);
80 state->inlen += inlen;
85 state->padding |= ((uint64_t) *in) << (left * 8);
92 printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
93 printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
94 printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
95 printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
96 printf("(%3zu) compress padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t)state->padding);
99 state->v3 ^= state->padding;
100 sipround(state);
101 sipround(state);
102 state->v0 ^= state->padding;
104 state->padding = 0;
107 end -= (state->inlen % sizeof(uint64_t));
112 printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
113 printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
114 printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
115 printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
116 printf("(%3zu) compress %08x %08x\n", state->inlen, (uint32_t) (m >> 32), (uint32_t) m);
118 state->v3 ^= m;
119 sipround(state);
120 sipround(state);
121 state->v0 ^= m;
124 left = state->inlen & 7;
127 state->padding |= ((uint64_t) in[6]) << 48;
129 state->padding |= ((uint64_t) in[5]) << 40;
131 state->padding |= ((uint64_t) in[4]) << 32;
133 state->padding |= ((uint64_t) in[3]) << 24;
135 state->padding |= ((uint64_t) in[2]) << 16;
137 state->padding |= ((uint64_t) in[1]) << 8;
139 state->padding |= ((uint64_t) in[0]);
145 uint64_t siphash24_finalize(struct siphash *state) {
148 assert(state);
150 b = state->padding | (((uint64_t) state->inlen) << 56);
153 printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
154 printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
155 printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
156 printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
157 printf("(%3zu) padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t) state->padding);
160 state->v3 ^= b;
161 sipround(state);
162 sipround(state);
163 state->v0 ^= b;
166 printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
167 printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
168 printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
169 printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
171 state->v2 ^= 0xff;
173 sipround(state);
174 sipround(state);
175 sipround(state);
176 sipround(state);
178 return state->v0 ^ state->v1 ^ state->v2 ^ state->v3;
182 struct siphash state;
187 siphash24_init(&state, k);
188 siphash24_compress(in, inlen, &state);
190 return siphash24_finalize(&state);