Lines Matching refs:ctx
87 void mbedtls_gcm_init( mbedtls_gcm_context *ctx ) in mbedtls_gcm_init() argument
89 GCM_VALIDATE( ctx != NULL ); in mbedtls_gcm_init()
90 memset( ctx, 0, sizeof( mbedtls_gcm_context ) ); in mbedtls_gcm_init()
101 static int gcm_gen_table( mbedtls_gcm_context *ctx ) in gcm_gen_table() argument
110 if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 ) in gcm_gen_table()
123 ctx->HL[8] = vl; in gcm_gen_table()
124 ctx->HH[8] = vh; in gcm_gen_table()
133 ctx->HH[0] = 0; in gcm_gen_table()
134 ctx->HL[0] = 0; in gcm_gen_table()
142 ctx->HL[i] = vl; in gcm_gen_table()
143 ctx->HH[i] = vh; in gcm_gen_table()
148 uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i; in gcm_gen_table()
153 HiH[j] = vh ^ ctx->HH[j]; in gcm_gen_table()
154 HiL[j] = vl ^ ctx->HL[j]; in gcm_gen_table()
161 int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, in mbedtls_gcm_setkey() argument
169 GCM_VALIDATE_RET( ctx != NULL ); in mbedtls_gcm_setkey()
181 mbedtls_cipher_free( &ctx->cipher_ctx ); in mbedtls_gcm_setkey()
183 if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) in mbedtls_gcm_setkey()
186 if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, in mbedtls_gcm_setkey()
192 if( ( ret = gcm_gen_table( ctx ) ) != 0 ) in mbedtls_gcm_setkey()
215 static void gcm_mult( mbedtls_gcm_context *ctx, const unsigned char x[16], in gcm_mult() argument
226 PUT_UINT32_BE( ctx->HH[8] >> 32, h, 0 ); in gcm_mult()
227 PUT_UINT32_BE( ctx->HH[8], h, 4 ); in gcm_mult()
228 PUT_UINT32_BE( ctx->HL[8] >> 32, h, 8 ); in gcm_mult()
229 PUT_UINT32_BE( ctx->HL[8], h, 12 ); in gcm_mult()
238 zh = ctx->HH[lo]; in gcm_mult()
239 zl = ctx->HL[lo]; in gcm_mult()
252 zh ^= ctx->HH[lo]; in gcm_mult()
253 zl ^= ctx->HL[lo]; in gcm_mult()
261 zh ^= ctx->HH[hi]; in gcm_mult()
262 zl ^= ctx->HL[hi]; in gcm_mult()
271 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, in mbedtls_gcm_starts() argument
284 GCM_VALIDATE_RET( ctx != NULL ); in mbedtls_gcm_starts()
297 memset( ctx->y, 0x00, sizeof(ctx->y) ); in mbedtls_gcm_starts()
298 memset( ctx->buf, 0x00, sizeof(ctx->buf) ); in mbedtls_gcm_starts()
300 ctx->mode = mode; in mbedtls_gcm_starts()
301 ctx->len = 0; in mbedtls_gcm_starts()
302 ctx->add_len = 0; in mbedtls_gcm_starts()
306 memcpy( ctx->y, iv, iv_len ); in mbedtls_gcm_starts()
307 ctx->y[15] = 1; in mbedtls_gcm_starts()
320 ctx->y[i] ^= p[i]; in mbedtls_gcm_starts()
322 gcm_mult( ctx, ctx->y, ctx->y ); in mbedtls_gcm_starts()
329 ctx->y[i] ^= work_buf[i]; in mbedtls_gcm_starts()
331 gcm_mult( ctx, ctx->y, ctx->y ); in mbedtls_gcm_starts()
334 if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, in mbedtls_gcm_starts()
335 ctx->base_ectr, &olen ) ) != 0 ) in mbedtls_gcm_starts()
340 ctx->add_len = add_len; in mbedtls_gcm_starts()
347 ctx->buf[i] ^= p[i]; in mbedtls_gcm_starts()
349 gcm_mult( ctx, ctx->buf, ctx->buf ); in mbedtls_gcm_starts()
358 int mbedtls_gcm_update( mbedtls_gcm_context *ctx, in mbedtls_gcm_update() argument
370 GCM_VALIDATE_RET( ctx != NULL ); in mbedtls_gcm_update()
379 if( ctx->len + length < ctx->len || in mbedtls_gcm_update()
380 (uint64_t) ctx->len + length > 0xFFFFFFFE0ull ) in mbedtls_gcm_update()
385 ctx->len += length; in mbedtls_gcm_update()
393 if( ++ctx->y[i - 1] != 0 ) in mbedtls_gcm_update()
396 if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, ectr, in mbedtls_gcm_update()
404 if( ctx->mode == MBEDTLS_GCM_DECRYPT ) in mbedtls_gcm_update()
405 ctx->buf[i] ^= p[i]; in mbedtls_gcm_update()
407 if( ctx->mode == MBEDTLS_GCM_ENCRYPT ) in mbedtls_gcm_update()
408 ctx->buf[i] ^= out_p[i]; in mbedtls_gcm_update()
411 gcm_mult( ctx, ctx->buf, ctx->buf ); in mbedtls_gcm_update()
421 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, in mbedtls_gcm_finish() argument
430 GCM_VALIDATE_RET( ctx != NULL ); in mbedtls_gcm_finish()
433 orig_len = ctx->len * 8; in mbedtls_gcm_finish()
434 orig_add_len = ctx->add_len * 8; in mbedtls_gcm_finish()
439 memcpy( tag, ctx->base_ectr, tag_len ); in mbedtls_gcm_finish()
451 ctx->buf[i] ^= work_buf[i]; in mbedtls_gcm_finish()
453 gcm_mult( ctx, ctx->buf, ctx->buf ); in mbedtls_gcm_finish()
456 tag[i] ^= ctx->buf[i]; in mbedtls_gcm_finish()
462 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, in mbedtls_gcm_crypt_and_tag() argument
476 GCM_VALIDATE_RET( ctx != NULL ); in mbedtls_gcm_crypt_and_tag()
483 if( ( ret = mbedtls_gcm_starts( ctx, mode, iv, iv_len, add, add_len ) ) != 0 ) in mbedtls_gcm_crypt_and_tag()
486 if( ( ret = mbedtls_gcm_update( ctx, length, input, output ) ) != 0 ) in mbedtls_gcm_crypt_and_tag()
489 if( ( ret = mbedtls_gcm_finish( ctx, tag, tag_len ) ) != 0 ) in mbedtls_gcm_crypt_and_tag()
495 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, in mbedtls_gcm_auth_decrypt() argument
511 GCM_VALIDATE_RET( ctx != NULL ); in mbedtls_gcm_auth_decrypt()
518 if( ( ret = mbedtls_gcm_crypt_and_tag( ctx, MBEDTLS_GCM_DECRYPT, length, in mbedtls_gcm_auth_decrypt()
538 void mbedtls_gcm_free( mbedtls_gcm_context *ctx ) in mbedtls_gcm_free() argument
540 if( ctx == NULL ) in mbedtls_gcm_free()
542 mbedtls_cipher_free( &ctx->cipher_ctx ); in mbedtls_gcm_free()
543 mbedtls_platform_zeroize( ctx, sizeof( mbedtls_gcm_context ) ); in mbedtls_gcm_free()
778 mbedtls_gcm_context ctx; in mbedtls_gcm_self_test() local
790 mbedtls_gcm_init( &ctx ); in mbedtls_gcm_self_test()
796 ret = mbedtls_gcm_setkey( &ctx, cipher, in mbedtls_gcm_self_test()
814 ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, in mbedtls_gcm_self_test()
842 mbedtls_gcm_free( &ctx ); in mbedtls_gcm_self_test()
847 mbedtls_gcm_init( &ctx ); in mbedtls_gcm_self_test()
853 ret = mbedtls_gcm_setkey( &ctx, cipher, in mbedtls_gcm_self_test()
859 ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_DECRYPT, in mbedtls_gcm_self_test()
878 mbedtls_gcm_free( &ctx ); in mbedtls_gcm_self_test()
883 mbedtls_gcm_init( &ctx ); in mbedtls_gcm_self_test()
889 ret = mbedtls_gcm_setkey( &ctx, cipher, in mbedtls_gcm_self_test()
895 ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_ENCRYPT, in mbedtls_gcm_self_test()
906 ret = mbedtls_gcm_update( &ctx, 32, in mbedtls_gcm_self_test()
912 ret = mbedtls_gcm_update( &ctx, rest_len, in mbedtls_gcm_self_test()
920 ret = mbedtls_gcm_update( &ctx, pt_len_test_data[i], in mbedtls_gcm_self_test()
927 ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 ); in mbedtls_gcm_self_test()
939 mbedtls_gcm_free( &ctx ); in mbedtls_gcm_self_test()
944 mbedtls_gcm_init( &ctx ); in mbedtls_gcm_self_test()
950 ret = mbedtls_gcm_setkey( &ctx, cipher, in mbedtls_gcm_self_test()
956 ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_DECRYPT, in mbedtls_gcm_self_test()
967 ret = mbedtls_gcm_update( &ctx, 32, ct_test_data[j * 6 + i], in mbedtls_gcm_self_test()
972 ret = mbedtls_gcm_update( &ctx, rest_len, in mbedtls_gcm_self_test()
980 ret = mbedtls_gcm_update( &ctx, pt_len_test_data[i], in mbedtls_gcm_self_test()
987 ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 ); in mbedtls_gcm_self_test()
999 mbedtls_gcm_free( &ctx ); in mbedtls_gcm_self_test()
1016 mbedtls_gcm_free( &ctx ); in mbedtls_gcm_self_test()