Lines Matching refs:ctx

73 size_t SipHash_hash_size(SIPHASH *ctx)
75 return ctx->hash_size;
85 int SipHash_set_hash_size(SIPHASH *ctx, size_t hash_size)
98 ctx->hash_size = siphash_adjust_hash_size(ctx->hash_size);
100 /* Now, adjust ctx->v1 if the old and the new size differ */
101 if ((size_t)ctx->hash_size != hash_size) {
102 ctx->v1 ^= 0xee;
103 ctx->hash_size = hash_size;
109 int SipHash_Init(SIPHASH *ctx, const unsigned char *k, int crounds, int drounds)
115 ctx->hash_size = siphash_adjust_hash_size(ctx->hash_size);
122 ctx->crounds = crounds;
123 ctx->drounds = drounds;
125 ctx->len = 0;
126 ctx->total_inlen = 0;
128 ctx->v0 = 0x736f6d6570736575ULL ^ k0;
129 ctx->v1 = 0x646f72616e646f6dULL ^ k1;
130 ctx->v2 = 0x6c7967656e657261ULL ^ k0;
131 ctx->v3 = 0x7465646279746573ULL ^ k1;
133 if (ctx->hash_size == SIPHASH_MAX_DIGEST_SIZE)
134 ctx->v1 ^= 0xee;
139 void SipHash_Update(SIPHASH *ctx, const unsigned char *in, size_t inlen)
145 uint64_t v0 = ctx->v0;
146 uint64_t v1 = ctx->v1;
147 uint64_t v2 = ctx->v2;
148 uint64_t v3 = ctx->v3;
150 ctx->total_inlen += inlen;
152 if (ctx->len) {
154 size_t available = SIPHASH_BLOCK_SIZE - ctx->len;
158 memcpy(&ctx->leavings[ctx->len], in, inlen);
159 ctx->len += inlen;
164 memcpy(&ctx->leavings[ctx->len], in, available);
169 m = U8TO64_LE(ctx->leavings);
171 for (i = 0; i < ctx->crounds; ++i)
181 for (i = 0; i < ctx->crounds; ++i)
186 /* save leavings and other ctx */
188 memcpy(ctx->leavings, end, left);
189 ctx->len = left;
191 ctx->v0 = v0;
192 ctx->v1 = v1;
193 ctx->v2 = v2;
194 ctx->v3 = v3;
197 int SipHash_Final(SIPHASH *ctx, unsigned char *out, size_t outlen)
201 uint64_t b = ctx->total_inlen << 56;
202 uint64_t v0 = ctx->v0;
203 uint64_t v1 = ctx->v1;
204 uint64_t v2 = ctx->v2;
205 uint64_t v3 = ctx->v3;
207 if (ctx->crounds == 0 || outlen == 0 || outlen != (size_t)ctx->hash_size)
210 switch (ctx->len) {
212 b |= ((uint64_t)ctx->leavings[6]) << 48;
215 b |= ((uint64_t)ctx->leavings[5]) << 40;
218 b |= ((uint64_t)ctx->leavings[4]) << 32;
221 b |= ((uint64_t)ctx->leavings[3]) << 24;
224 b |= ((uint64_t)ctx->leavings[2]) << 16;
227 b |= ((uint64_t)ctx->leavings[1]) << 8;
230 b |= ((uint64_t)ctx->leavings[0]);
236 for (i = 0; i < ctx->crounds; ++i)
239 if (ctx->hash_size == SIPHASH_MAX_DIGEST_SIZE)
243 for (i = 0; i < ctx->drounds; ++i)
247 if (ctx->hash_size == SIPHASH_MIN_DIGEST_SIZE)
250 for (i = 0; i < ctx->drounds; ++i)