Lines Matching refs:ctx

101 static void poly1305_process( mbedtls_poly1305_context *ctx,  in poly1305_process()  argument
113 r0 = ctx->r[0]; in poly1305_process()
114 r1 = ctx->r[1]; in poly1305_process()
115 r2 = ctx->r[2]; in poly1305_process()
116 r3 = ctx->r[3]; in poly1305_process()
122 acc0 = ctx->acc[0]; in poly1305_process()
123 acc1 = ctx->acc[1]; in poly1305_process()
124 acc2 = ctx->acc[2]; in poly1305_process()
125 acc3 = ctx->acc[3]; in poly1305_process()
126 acc4 = ctx->acc[4]; in poly1305_process()
195 ctx->acc[0] = acc0; in poly1305_process()
196 ctx->acc[1] = acc1; in poly1305_process()
197 ctx->acc[2] = acc2; in poly1305_process()
198 ctx->acc[3] = acc3; in poly1305_process()
199 ctx->acc[4] = acc4; in poly1305_process()
209 static void poly1305_compute_mac( const mbedtls_poly1305_context *ctx, in poly1305_compute_mac() argument
218 acc0 = ctx->acc[0]; in poly1305_compute_mac()
219 acc1 = ctx->acc[1]; in poly1305_compute_mac()
220 acc2 = ctx->acc[2]; in poly1305_compute_mac()
221 acc3 = ctx->acc[3]; in poly1305_compute_mac()
222 acc4 = ctx->acc[4]; in poly1305_compute_mac()
251 d = (uint64_t) acc0 + ctx->s[0]; in poly1305_compute_mac()
253 d = (uint64_t) acc1 + ctx->s[1] + ( d >> 32U ); in poly1305_compute_mac()
255 d = (uint64_t) acc2 + ctx->s[2] + ( d >> 32U ); in poly1305_compute_mac()
257 acc3 += ctx->s[3] + (uint32_t) ( d >> 32U ); in poly1305_compute_mac()
278 void mbedtls_poly1305_init( mbedtls_poly1305_context *ctx ) in mbedtls_poly1305_init() argument
280 POLY1305_VALIDATE( ctx != NULL ); in mbedtls_poly1305_init()
282 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_poly1305_context ) ); in mbedtls_poly1305_init()
285 void mbedtls_poly1305_free( mbedtls_poly1305_context *ctx ) in mbedtls_poly1305_free() argument
287 if( ctx == NULL ) in mbedtls_poly1305_free()
290 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_poly1305_context ) ); in mbedtls_poly1305_free()
293 int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx, in mbedtls_poly1305_starts() argument
296 POLY1305_VALIDATE_RET( ctx != NULL ); in mbedtls_poly1305_starts()
300 ctx->r[0] = BYTES_TO_U32_LE( key, 0 ) & 0x0FFFFFFFU; in mbedtls_poly1305_starts()
301 ctx->r[1] = BYTES_TO_U32_LE( key, 4 ) & 0x0FFFFFFCU; in mbedtls_poly1305_starts()
302 ctx->r[2] = BYTES_TO_U32_LE( key, 8 ) & 0x0FFFFFFCU; in mbedtls_poly1305_starts()
303 ctx->r[3] = BYTES_TO_U32_LE( key, 12 ) & 0x0FFFFFFCU; in mbedtls_poly1305_starts()
305 ctx->s[0] = BYTES_TO_U32_LE( key, 16 ); in mbedtls_poly1305_starts()
306 ctx->s[1] = BYTES_TO_U32_LE( key, 20 ); in mbedtls_poly1305_starts()
307 ctx->s[2] = BYTES_TO_U32_LE( key, 24 ); in mbedtls_poly1305_starts()
308 ctx->s[3] = BYTES_TO_U32_LE( key, 28 ); in mbedtls_poly1305_starts()
311 ctx->acc[0] = 0U; in mbedtls_poly1305_starts()
312 ctx->acc[1] = 0U; in mbedtls_poly1305_starts()
313 ctx->acc[2] = 0U; in mbedtls_poly1305_starts()
314 ctx->acc[3] = 0U; in mbedtls_poly1305_starts()
315 ctx->acc[4] = 0U; in mbedtls_poly1305_starts()
318 mbedtls_platform_zeroize( ctx->queue, sizeof( ctx->queue ) ); in mbedtls_poly1305_starts()
319 ctx->queue_len = 0U; in mbedtls_poly1305_starts()
324 int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx, in mbedtls_poly1305_update() argument
332 POLY1305_VALIDATE_RET( ctx != NULL ); in mbedtls_poly1305_update()
335 if( ( remaining > 0U ) && ( ctx->queue_len > 0U ) ) in mbedtls_poly1305_update()
337 queue_free_len = ( POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len ); in mbedtls_poly1305_update()
344 memcpy( &ctx->queue[ctx->queue_len], in mbedtls_poly1305_update()
348 ctx->queue_len += ilen; in mbedtls_poly1305_update()
355 memcpy( &ctx->queue[ctx->queue_len], in mbedtls_poly1305_update()
359 ctx->queue_len = 0U; in mbedtls_poly1305_update()
361 poly1305_process( ctx, 1U, ctx->queue, 1U ); /* add padding bit */ in mbedtls_poly1305_update()
372 poly1305_process( ctx, nblocks, &input[offset], 1U ); in mbedtls_poly1305_update()
381 ctx->queue_len = remaining; in mbedtls_poly1305_update()
382 memcpy( ctx->queue, &input[offset], remaining ); in mbedtls_poly1305_update()
388 int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx, in mbedtls_poly1305_finish() argument
391 POLY1305_VALIDATE_RET( ctx != NULL ); in mbedtls_poly1305_finish()
395 if( ctx->queue_len > 0U ) in mbedtls_poly1305_finish()
398 ctx->queue[ctx->queue_len] = 1U; in mbedtls_poly1305_finish()
399 ctx->queue_len++; in mbedtls_poly1305_finish()
402 memset( &ctx->queue[ctx->queue_len], in mbedtls_poly1305_finish()
404 POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len ); in mbedtls_poly1305_finish()
406 poly1305_process( ctx, 1U, /* Process 1 block */ in mbedtls_poly1305_finish()
407 ctx->queue, 0U ); /* Already padded above */ in mbedtls_poly1305_finish()
410 poly1305_compute_mac( ctx, mac ); in mbedtls_poly1305_finish()
420 mbedtls_poly1305_context ctx; in mbedtls_poly1305_mac() local
426 mbedtls_poly1305_init( &ctx ); in mbedtls_poly1305_mac()
428 ret = mbedtls_poly1305_starts( &ctx, key ); in mbedtls_poly1305_mac()
432 ret = mbedtls_poly1305_update( &ctx, input, ilen ); in mbedtls_poly1305_mac()
436 ret = mbedtls_poly1305_finish( &ctx, mac ); in mbedtls_poly1305_mac()
439 mbedtls_poly1305_free( &ctx ); in mbedtls_poly1305_mac()