Lines Matching refs:ctx

54 static void SipHash_Rounds(SIPHASH_CTX *ctx, int rounds)  in SipHash_Rounds()  argument
57 ctx->v[0] += ctx->v[1]; in SipHash_Rounds()
58 ctx->v[2] += ctx->v[3]; in SipHash_Rounds()
59 ctx->v[1] = rol64(ctx->v[1], 13); in SipHash_Rounds()
60 ctx->v[3] = rol64(ctx->v[3], 16); in SipHash_Rounds()
62 ctx->v[1] ^= ctx->v[0]; in SipHash_Rounds()
63 ctx->v[3] ^= ctx->v[2]; in SipHash_Rounds()
64 ctx->v[0] = rol64(ctx->v[0], 32); in SipHash_Rounds()
66 ctx->v[2] += ctx->v[1]; in SipHash_Rounds()
67 ctx->v[0] += ctx->v[3]; in SipHash_Rounds()
68 ctx->v[1] = rol64(ctx->v[1], 17); in SipHash_Rounds()
69 ctx->v[3] = rol64(ctx->v[3], 21); in SipHash_Rounds()
71 ctx->v[1] ^= ctx->v[2]; in SipHash_Rounds()
72 ctx->v[3] ^= ctx->v[0]; in SipHash_Rounds()
73 ctx->v[2] = rol64(ctx->v[2], 32); in SipHash_Rounds()
77 static void SipHash_CRounds(SIPHASH_CTX *ctx, const void *ptr, int rounds) in SipHash_CRounds() argument
81 ctx->v[3] ^= m; in SipHash_CRounds()
82 SipHash_Rounds(ctx, rounds); in SipHash_CRounds()
83 ctx->v[0] ^= m; in SipHash_CRounds()
86 void SipHash_Init(SIPHASH_CTX *ctx, const SIPHASH_KEY *key) in SipHash_Init() argument
93 ctx->v[0] = 0x736f6d6570736575ULL ^ k0; in SipHash_Init()
94 ctx->v[1] = 0x646f72616e646f6dULL ^ k1; in SipHash_Init()
95 ctx->v[2] = 0x6c7967656e657261ULL ^ k0; in SipHash_Init()
96 ctx->v[3] = 0x7465646279746573ULL ^ k1; in SipHash_Init()
98 memset(ctx->buf, 0, sizeof(ctx->buf)); in SipHash_Init()
99 ctx->bytes = 0; in SipHash_Init()
102 void SipHash_Update(SIPHASH_CTX *ctx, int rc, int rf, in SipHash_Update() argument
111 used = ctx->bytes % sizeof(ctx->buf); in SipHash_Update()
112 ctx->bytes += len; in SipHash_Update()
115 left = sizeof(ctx->buf) - used; in SipHash_Update()
118 memcpy(&ctx->buf[used], ptr, left); in SipHash_Update()
119 SipHash_CRounds(ctx, ctx->buf, rc); in SipHash_Update()
123 memcpy(&ctx->buf[used], ptr, len); in SipHash_Update()
128 while (len >= sizeof(ctx->buf)) { in SipHash_Update()
129 SipHash_CRounds(ctx, ptr, rc); in SipHash_Update()
130 len -= sizeof(ctx->buf); in SipHash_Update()
131 ptr += sizeof(ctx->buf); in SipHash_Update()
135 memcpy(&ctx->buf[used], ptr, len); in SipHash_Update()
138 void SipHash_Final(void *dst, SIPHASH_CTX *ctx, int rc, int rf) in SipHash_Final() argument
142 r = SipHash_End(ctx, rc, rf); in SipHash_Final()
147 u64 SipHash_End(SIPHASH_CTX *ctx, int rc, int rf) in SipHash_End() argument
152 used = ctx->bytes % sizeof(ctx->buf); in SipHash_End()
153 left = sizeof(ctx->buf) - used; in SipHash_End()
154 memset(&ctx->buf[used], 0, left - 1); in SipHash_End()
155 ctx->buf[7] = ctx->bytes; in SipHash_End()
157 SipHash_CRounds(ctx, ctx->buf, rc); in SipHash_End()
158 ctx->v[2] ^= 0xff; in SipHash_End()
159 SipHash_Rounds(ctx, rf); in SipHash_End()
161 r = (ctx->v[0] ^ ctx->v[1]) ^ (ctx->v[2] ^ ctx->v[3]); in SipHash_End()
162 memset(ctx, 0, sizeof(*ctx)); in SipHash_End()
168 SIPHASH_CTX ctx; in SipHash() local
170 SipHash_Init(&ctx, key); in SipHash()
171 SipHash_Update(&ctx, rc, rf, src, len); in SipHash()
172 return SipHash_End(&ctx, rc, rf); in SipHash()