Lines Matching refs:ctx

68  * \param ctx               The Poly1305 context.
76 static void poly1305_process(mbedtls_poly1305_context *ctx,
88 r0 = ctx->r[0];
89 r1 = ctx->r[1];
90 r2 = ctx->r[2];
91 r3 = ctx->r[3];
97 acc0 = ctx->acc[0];
98 acc1 = ctx->acc[1];
99 acc2 = ctx->acc[2];
100 acc3 = ctx->acc[3];
101 acc4 = ctx->acc[4];
169 ctx->acc[0] = acc0;
170 ctx->acc[1] = acc1;
171 ctx->acc[2] = acc2;
172 ctx->acc[3] = acc3;
173 ctx->acc[4] = acc4;
179 * \param ctx The Poly1305 context.
183 static void poly1305_compute_mac(const mbedtls_poly1305_context *ctx,
192 acc0 = ctx->acc[0];
193 acc1 = ctx->acc[1];
194 acc2 = ctx->acc[2];
195 acc3 = ctx->acc[3];
196 acc4 = ctx->acc[4];
225 d = (uint64_t) acc0 + ctx->s[0];
227 d = (uint64_t) acc1 + ctx->s[1] + (d >> 32U);
229 d = (uint64_t) acc2 + ctx->s[2] + (d >> 32U);
231 acc3 += ctx->s[3] + (uint32_t) (d >> 32U);
240 void mbedtls_poly1305_init(mbedtls_poly1305_context *ctx)
242 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_poly1305_context));
245 void mbedtls_poly1305_free(mbedtls_poly1305_context *ctx)
247 if (ctx == NULL) {
251 mbedtls_platform_zeroize(ctx, sizeof(mbedtls_poly1305_context));
254 int mbedtls_poly1305_starts(mbedtls_poly1305_context *ctx,
258 ctx->r[0] = MBEDTLS_GET_UINT32_LE(key, 0) & 0x0FFFFFFFU;
259 ctx->r[1] = MBEDTLS_GET_UINT32_LE(key, 4) & 0x0FFFFFFCU;
260 ctx->r[2] = MBEDTLS_GET_UINT32_LE(key, 8) & 0x0FFFFFFCU;
261 ctx->r[3] = MBEDTLS_GET_UINT32_LE(key, 12) & 0x0FFFFFFCU;
263 ctx->s[0] = MBEDTLS_GET_UINT32_LE(key, 16);
264 ctx->s[1] = MBEDTLS_GET_UINT32_LE(key, 20);
265 ctx->s[2] = MBEDTLS_GET_UINT32_LE(key, 24);
266 ctx->s[3] = MBEDTLS_GET_UINT32_LE(key, 28);
269 ctx->acc[0] = 0U;
270 ctx->acc[1] = 0U;
271 ctx->acc[2] = 0U;
272 ctx->acc[3] = 0U;
273 ctx->acc[4] = 0U;
276 mbedtls_platform_zeroize(ctx->queue, sizeof(ctx->queue));
277 ctx->queue_len = 0U;
282 int mbedtls_poly1305_update(mbedtls_poly1305_context *ctx,
291 if ((remaining > 0U) && (ctx->queue_len > 0U)) {
292 queue_free_len = (POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len);
298 memcpy(&ctx->queue[ctx->queue_len],
302 ctx->queue_len += ilen;
307 memcpy(&ctx->queue[ctx->queue_len],
311 ctx->queue_len = 0U;
313 poly1305_process(ctx, 1U, ctx->queue, 1U); /* add padding bit */
323 poly1305_process(ctx, nblocks, &input[offset], 1U);
331 ctx->queue_len = remaining;
332 memcpy(ctx->queue, &input[offset], remaining);
338 int mbedtls_poly1305_finish(mbedtls_poly1305_context *ctx,
342 if (ctx->queue_len > 0U) {
344 ctx->queue[ctx->queue_len] = 1U;
345 ctx->queue_len++;
348 memset(&ctx->queue[ctx->queue_len],
350 POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len);
352 poly1305_process(ctx, 1U, /* Process 1 block */
353 ctx->queue, 0U); /* Already padded above */
356 poly1305_compute_mac(ctx, mac);
366 mbedtls_poly1305_context ctx;
369 mbedtls_poly1305_init(&ctx);
371 ret = mbedtls_poly1305_starts(&ctx, key);
376 ret = mbedtls_poly1305_update(&ctx, input, ilen);
381 ret = mbedtls_poly1305_finish(&ctx, mac);
384 mbedtls_poly1305_free(&ctx);