Lines Matching refs:ctx

55 static void	SipRounds(SIPHASH_CTX *ctx, int final);
58 SipHash_InitX(SIPHASH_CTX *ctx, int rc, int rf)
61 ctx->v[0] = 0x736f6d6570736575ull;
62 ctx->v[1] = 0x646f72616e646f6dull;
63 ctx->v[2] = 0x6c7967656e657261ull;
64 ctx->v[3] = 0x7465646279746573ull;
65 ctx->buf.b64 = 0;
66 ctx->bytes = 0;
67 ctx->buflen = 0;
68 ctx->rounds_compr = rc;
69 ctx->rounds_final = rf;
70 ctx->initialized = 1;
74 SipHash_SetKey(SIPHASH_CTX *ctx, const uint8_t key[16])
78 KASSERT(ctx->v[0] == 0x736f6d6570736575ull &&
79 ctx->initialized == 1,
80 ("%s: context %p not properly initialized", __func__, ctx));
85 ctx->v[0] ^= k[0];
86 ctx->v[1] ^= k[1];
87 ctx->v[2] ^= k[0];
88 ctx->v[3] ^= k[1];
90 ctx->initialized = 2;
94 SipBuf(SIPHASH_CTX *ctx, const uint8_t **src, size_t len, int final)
102 x = MIN(len, sizeof(ctx->buf.b64) - ctx->buflen);
103 bcopy(*src, &ctx->buf.b8[ctx->buflen], x);
104 ctx->buflen += x;
107 ctx->buf.b8[7] = (uint8_t)ctx->bytes;
109 if (ctx->buflen == 8 || final) {
110 ctx->v[3] ^= le64toh(ctx->buf.b64);
111 SipRounds(ctx, 0);
112 ctx->v[0] ^= le64toh(ctx->buf.b64);
113 ctx->buf.b64 = 0;
114 ctx->buflen = 0;
120 SipHash_Update(SIPHASH_CTX *ctx, const void *src, size_t len)
127 KASSERT(ctx->initialized == 2,
128 ("%s: context %p not properly initialized", __func__, ctx));
131 ctx->bytes += len;
138 if (ctx->buflen > 0 || len < 8)
139 len -= SipBuf(ctx, &s, len, 0);
150 ctx->v[3] ^= m;
151 SipRounds(ctx, 0);
152 ctx->v[0] ^= m;
158 ctx->v[3] ^= m;
159 SipRounds(ctx, 0);
160 ctx->v[0] ^= m;
166 (void)SipBuf(ctx, &s, rem, 0);
170 SipHash_Final(void *dst, SIPHASH_CTX *ctx)
174 KASSERT(ctx->initialized == 2,
175 ("%s: context %p not properly initialized", __func__, ctx));
177 r = SipHash_End(ctx);
182 SipHash_End(SIPHASH_CTX *ctx)
186 KASSERT(ctx->initialized == 2,
187 ("%s: context %p not properly initialized", __func__, ctx));
189 SipBuf(ctx, NULL, 0, 1);
190 ctx->v[2] ^= 0xff;
191 SipRounds(ctx, 1);
192 r = (ctx->v[0] ^ ctx->v[1]) ^ (ctx->v[2] ^ ctx->v[3]);
194 bzero(ctx, sizeof(*ctx));
199 SipHashX(SIPHASH_CTX *ctx, int rc, int rf, const uint8_t key[16],
203 SipHash_InitX(ctx, rc, rf);
204 SipHash_SetKey(ctx, key);
205 SipHash_Update(ctx, src, len);
207 return (SipHash_End(ctx));
213 SipRounds(SIPHASH_CTX *ctx, int final)
218 rounds = ctx->rounds_compr;
220 rounds = ctx->rounds_final;
223 ctx->v[0] += ctx->v[1];
224 ctx->v[2] += ctx->v[3];
225 ctx->v[1] = SIP_ROTL(ctx->v[1], 13);
226 ctx->v[3] = SIP_ROTL(ctx->v[3], 16);
228 ctx->v[1] ^= ctx->v[0];
229 ctx->v[3] ^= ctx->v[2];
230 ctx->v[0] = SIP_ROTL(ctx->v[0], 32);
232 ctx->v[2] += ctx->v[1];
233 ctx->v[0] += ctx->v[3];
234 ctx->v[1] = SIP_ROTL(ctx->v[1], 17);
235 ctx->v[3] = SIP_ROTL(ctx->v[3], 21);
237 ctx->v[1] ^= ctx->v[2];
238 ctx->v[3] ^= ctx->v[0];
239 ctx->v[2] = SIP_ROTL(ctx->v[2], 32);