Lines Matching defs:ctx
55 SipHash_Init(SIPHASH_CTX *ctx, const SIPHASH_KEY *key)
62 ctx->v[0] = 0x736f6d6570736575ULL ^ k0;
63 ctx->v[1] = 0x646f72616e646f6dULL ^ k1;
64 ctx->v[2] = 0x6c7967656e657261ULL ^ k0;
65 ctx->v[3] = 0x7465646279746573ULL ^ k1;
67 memset(ctx->buf, 0, sizeof(ctx->buf));
68 ctx->bytes = 0;
72 SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, const void *src, size_t len)
80 used = ctx->bytes % sizeof(ctx->buf);
81 ctx->bytes += len;
84 left = sizeof(ctx->buf) - used;
87 memcpy(&ctx->buf[used], ptr, left);
88 SipHash_CRounds(ctx, rc);
92 memcpy(&ctx->buf[used], ptr, len);
97 while (len >= sizeof(ctx->buf)) {
98 memcpy(ctx->buf, ptr, sizeof(ctx->buf));
99 SipHash_CRounds(ctx, rc);
100 len -= sizeof(ctx->buf);
101 ptr += sizeof(ctx->buf);
105 memcpy(ctx->buf, ptr, len);
109 SipHash_Final(void *dst, SIPHASH_CTX *ctx, int rc, int rf)
113 htolem64(&r, SipHash_End(ctx, rc, rf));
118 SipHash_End(SIPHASH_CTX *ctx, int rc, int rf)
123 used = ctx->bytes % sizeof(ctx->buf);
124 left = sizeof(ctx->buf) - used;
125 memset(&ctx->buf[used], 0, left - 1);
126 ctx->buf[7] = ctx->bytes;
128 SipHash_CRounds(ctx, rc);
129 ctx->v[2] ^= 0xff;
130 SipHash_Rounds(ctx, rf);
132 r = (ctx->v[0] ^ ctx->v[1]) ^ (ctx->v[2] ^ ctx->v[3]);
133 explicit_bzero(ctx, sizeof(*ctx));
140 SIPHASH_CTX ctx;
142 SipHash_Init(&ctx, key);
143 SipHash_Update(&ctx, rc, rf, src, len);
144 return (SipHash_End(&ctx, rc, rf));
150 SipHash_Rounds(SIPHASH_CTX *ctx, int rounds)
153 ctx->v[0] += ctx->v[1];
154 ctx->v[2] += ctx->v[3];
155 ctx->v[1] = SIP_ROTL(ctx->v[1], 13);
156 ctx->v[3] = SIP_ROTL(ctx->v[3], 16);
158 ctx->v[1] ^= ctx->v[0];
159 ctx->v[3] ^= ctx->v[2];
160 ctx->v[0] = SIP_ROTL(ctx->v[0], 32);
162 ctx->v[2] += ctx->v[1];
163 ctx->v[0] += ctx->v[3];
164 ctx->v[1] = SIP_ROTL(ctx->v[1], 17);
165 ctx->v[3] = SIP_ROTL(ctx->v[3], 21);
167 ctx->v[1] ^= ctx->v[2];
168 ctx->v[3] ^= ctx->v[0];
169 ctx->v[2] = SIP_ROTL(ctx->v[2], 32);
174 SipHash_CRounds(SIPHASH_CTX *ctx, int rounds)
176 uint64_t m = lemtoh64((uint64_t *)ctx->buf);
178 ctx->v[3] ^= m;
179 SipHash_Rounds(ctx, rounds);
180 ctx->v[0] ^= m;