Lines Matching refs:ctx

94 static void poly1305_process( mbedtls_poly1305_context *ctx,  in poly1305_process()  argument
106 r0 = ctx->r[0]; in poly1305_process()
107 r1 = ctx->r[1]; in poly1305_process()
108 r2 = ctx->r[2]; in poly1305_process()
109 r3 = ctx->r[3]; in poly1305_process()
115 acc0 = ctx->acc[0]; in poly1305_process()
116 acc1 = ctx->acc[1]; in poly1305_process()
117 acc2 = ctx->acc[2]; in poly1305_process()
118 acc3 = ctx->acc[3]; in poly1305_process()
119 acc4 = ctx->acc[4]; in poly1305_process()
188 ctx->acc[0] = acc0; in poly1305_process()
189 ctx->acc[1] = acc1; in poly1305_process()
190 ctx->acc[2] = acc2; in poly1305_process()
191 ctx->acc[3] = acc3; in poly1305_process()
192 ctx->acc[4] = acc4; in poly1305_process()
202 static void poly1305_compute_mac( const mbedtls_poly1305_context *ctx, in poly1305_compute_mac() argument
211 acc0 = ctx->acc[0]; in poly1305_compute_mac()
212 acc1 = ctx->acc[1]; in poly1305_compute_mac()
213 acc2 = ctx->acc[2]; in poly1305_compute_mac()
214 acc3 = ctx->acc[3]; in poly1305_compute_mac()
215 acc4 = ctx->acc[4]; in poly1305_compute_mac()
244 d = (uint64_t) acc0 + ctx->s[0]; in poly1305_compute_mac()
246 d = (uint64_t) acc1 + ctx->s[1] + ( d >> 32U ); in poly1305_compute_mac()
248 d = (uint64_t) acc2 + ctx->s[2] + ( d >> 32U ); in poly1305_compute_mac()
250 acc3 += ctx->s[3] + (uint32_t) ( d >> 32U ); in poly1305_compute_mac()
259 void mbedtls_poly1305_init( mbedtls_poly1305_context *ctx ) in mbedtls_poly1305_init() argument
261 POLY1305_VALIDATE( ctx != NULL ); in mbedtls_poly1305_init()
263 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_poly1305_context ) ); in mbedtls_poly1305_init()
266 void mbedtls_poly1305_free( mbedtls_poly1305_context *ctx ) in mbedtls_poly1305_free() argument
268 if( ctx == NULL ) in mbedtls_poly1305_free()
271 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_poly1305_context ) ); in mbedtls_poly1305_free()
274 int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx, in mbedtls_poly1305_starts() argument
277 POLY1305_VALIDATE_RET( ctx != NULL ); in mbedtls_poly1305_starts()
281 ctx->r[0] = MBEDTLS_GET_UINT32_LE( key, 0 ) & 0x0FFFFFFFU; in mbedtls_poly1305_starts()
282 ctx->r[1] = MBEDTLS_GET_UINT32_LE( key, 4 ) & 0x0FFFFFFCU; in mbedtls_poly1305_starts()
283 ctx->r[2] = MBEDTLS_GET_UINT32_LE( key, 8 ) & 0x0FFFFFFCU; in mbedtls_poly1305_starts()
284 ctx->r[3] = MBEDTLS_GET_UINT32_LE( key, 12 ) & 0x0FFFFFFCU; in mbedtls_poly1305_starts()
286 ctx->s[0] = MBEDTLS_GET_UINT32_LE( key, 16 ); in mbedtls_poly1305_starts()
287 ctx->s[1] = MBEDTLS_GET_UINT32_LE( key, 20 ); in mbedtls_poly1305_starts()
288 ctx->s[2] = MBEDTLS_GET_UINT32_LE( key, 24 ); in mbedtls_poly1305_starts()
289 ctx->s[3] = MBEDTLS_GET_UINT32_LE( key, 28 ); in mbedtls_poly1305_starts()
292 ctx->acc[0] = 0U; in mbedtls_poly1305_starts()
293 ctx->acc[1] = 0U; in mbedtls_poly1305_starts()
294 ctx->acc[2] = 0U; in mbedtls_poly1305_starts()
295 ctx->acc[3] = 0U; in mbedtls_poly1305_starts()
296 ctx->acc[4] = 0U; in mbedtls_poly1305_starts()
299 mbedtls_platform_zeroize( ctx->queue, sizeof( ctx->queue ) ); in mbedtls_poly1305_starts()
300 ctx->queue_len = 0U; in mbedtls_poly1305_starts()
305 int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx, in mbedtls_poly1305_update() argument
313 POLY1305_VALIDATE_RET( ctx != NULL ); in mbedtls_poly1305_update()
316 if( ( remaining > 0U ) && ( ctx->queue_len > 0U ) ) in mbedtls_poly1305_update()
318 queue_free_len = ( POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len ); in mbedtls_poly1305_update()
325 memcpy( &ctx->queue[ctx->queue_len], in mbedtls_poly1305_update()
329 ctx->queue_len += ilen; in mbedtls_poly1305_update()
336 memcpy( &ctx->queue[ctx->queue_len], in mbedtls_poly1305_update()
340 ctx->queue_len = 0U; in mbedtls_poly1305_update()
342 poly1305_process( ctx, 1U, ctx->queue, 1U ); /* add padding bit */ in mbedtls_poly1305_update()
353 poly1305_process( ctx, nblocks, &input[offset], 1U ); in mbedtls_poly1305_update()
362 ctx->queue_len = remaining; in mbedtls_poly1305_update()
363 memcpy( ctx->queue, &input[offset], remaining ); in mbedtls_poly1305_update()
369 int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx, in mbedtls_poly1305_finish() argument
372 POLY1305_VALIDATE_RET( ctx != NULL ); in mbedtls_poly1305_finish()
376 if( ctx->queue_len > 0U ) in mbedtls_poly1305_finish()
379 ctx->queue[ctx->queue_len] = 1U; in mbedtls_poly1305_finish()
380 ctx->queue_len++; in mbedtls_poly1305_finish()
383 memset( &ctx->queue[ctx->queue_len], in mbedtls_poly1305_finish()
385 POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len ); in mbedtls_poly1305_finish()
387 poly1305_process( ctx, 1U, /* Process 1 block */ in mbedtls_poly1305_finish()
388 ctx->queue, 0U ); /* Already padded above */ in mbedtls_poly1305_finish()
391 poly1305_compute_mac( ctx, mac ); in mbedtls_poly1305_finish()
401 mbedtls_poly1305_context ctx; in mbedtls_poly1305_mac() local
407 mbedtls_poly1305_init( &ctx ); in mbedtls_poly1305_mac()
409 ret = mbedtls_poly1305_starts( &ctx, key ); in mbedtls_poly1305_mac()
413 ret = mbedtls_poly1305_update( &ctx, input, ilen ); in mbedtls_poly1305_mac()
417 ret = mbedtls_poly1305_finish( &ctx, mac ); in mbedtls_poly1305_mac()
420 mbedtls_poly1305_free( &ctx ); in mbedtls_poly1305_mac()