Lines Matching refs:ctx

7 static int check_multipart(mbedtls_gcm_context *ctx,
28 TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
30 TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, add->x, n1_add));
31 TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, add->x + n1_add, n2_add));
38 TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, n1, output, n1, &olen));
46 TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x + n1, n2, output, n2, &olen));
53 TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
65 static void check_cipher_with_empty_ad(mbedtls_gcm_context *ctx,
80 TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
84 TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, NULL, 0));
92 TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, input->len, output, input->len, &olen));
99 TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
107 static void check_empty_cipher_with_ad(mbedtls_gcm_context *ctx,
118 TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode, iv->x, iv->len));
119 TEST_EQUAL(0, mbedtls_gcm_update_ad(ctx, add->x, add->len));
123 TEST_EQUAL(0, mbedtls_gcm_update(ctx, NULL, 0, NULL, 0, &olen));
128 TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen,
137 static void check_no_cipher_no_ad(mbedtls_gcm_context *ctx,
145 TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
148 TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
156 static void gcm_reset_ctx(mbedtls_gcm_context *ctx, const uint8_t *key,
163 mbedtls_gcm_init(ctx);
164 TEST_EQUAL(mbedtls_gcm_setkey(ctx, valid_cipher, key, key_bits), 0);
165 TEST_EQUAL(starts_ret, mbedtls_gcm_starts(ctx, mode, iv, iv_len));
186 mbedtls_gcm_context ctx;
190 mbedtls_gcm_init(&ctx);
195 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
196 TEST_ASSERT(mbedtls_gcm_crypt_and_tag(&ctx, direction, src_str->len, iv_str->x, iv_str->len,
201 mbedtls_gcm_free(&ctx);
215 mbedtls_gcm_context ctx;
221 mbedtls_gcm_init(&ctx);
227 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == init_result);
229 TEST_ASSERT(mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_ENCRYPT, src_str->len, iv_str->x,
239 if (!check_multipart(&ctx, MBEDTLS_GCM_ENCRYPT,
250 mbedtls_gcm_free(&ctx);
263 mbedtls_gcm_context ctx;
270 mbedtls_gcm_init(&ctx);
275 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == init_result);
277 ret = mbedtls_gcm_auth_decrypt(&ctx,
297 if (!check_multipart(&ctx, MBEDTLS_GCM_DECRYPT,
309 mbedtls_gcm_free(&ctx);
322 mbedtls_gcm_context ctx;
325 mbedtls_gcm_init(&ctx);
327 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
328 check_empty_cipher_with_ad(&ctx, MBEDTLS_GCM_DECRYPT,
332 mbedtls_gcm_free(&ctx);
346 mbedtls_gcm_context ctx;
349 mbedtls_gcm_init(&ctx);
351 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
352 check_cipher_with_empty_ad(&ctx, MBEDTLS_GCM_DECRYPT,
356 mbedtls_gcm_free(&ctx);
367 mbedtls_gcm_context ctx;
370 mbedtls_gcm_init(&ctx);
372 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
373 check_no_cipher_no_ad(&ctx, MBEDTLS_GCM_DECRYPT,
376 mbedtls_gcm_free(&ctx);
389 mbedtls_gcm_context ctx;
392 mbedtls_gcm_init(&ctx);
394 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
395 check_empty_cipher_with_ad(&ctx, MBEDTLS_GCM_ENCRYPT,
400 mbedtls_gcm_free(&ctx);
414 mbedtls_gcm_context ctx;
417 mbedtls_gcm_init(&ctx);
419 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
420 check_cipher_with_empty_ad(&ctx, MBEDTLS_GCM_ENCRYPT,
425 mbedtls_gcm_free(&ctx);
436 mbedtls_gcm_context ctx;
439 mbedtls_gcm_init(&ctx);
441 TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
442 check_no_cipher_no_ad(&ctx, MBEDTLS_GCM_ENCRYPT,
445 mbedtls_gcm_free(&ctx);
453 mbedtls_gcm_context ctx;
458 mbedtls_gcm_init(&ctx);
463 mbedtls_gcm_setkey(&ctx, valid_cipher, valid_buffer, invalid_bitlen));
466 mbedtls_gcm_free(&ctx);
475 mbedtls_gcm_context ctx;
481 mbedtls_gcm_init(&ctx);
482 TEST_EQUAL(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8), 0);
483 TEST_EQUAL(0, mbedtls_gcm_starts(&ctx, mode, iv->x, iv->len));
487 mbedtls_gcm_update(&ctx, input->x, input->len, output, output_len, &olen));
491 mbedtls_gcm_free(&ctx);
501 mbedtls_gcm_context ctx;
502 mbedtls_gcm_init(&ctx);
508 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, 0, MBEDTLS_ERR_GCM_BAD_INPUT);
509 mbedtls_gcm_free(&ctx);
514 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, 1ULL << 61, MBEDTLS_ERR_GCM_BAD_INPUT);
515 mbedtls_gcm_free(&ctx);
520 mbedtls_gcm_free(&ctx);
530 mbedtls_gcm_context ctx;
531 mbedtls_gcm_init(&ctx);
539 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, sizeof(b16), 0);
541 TEST_EQUAL(mbedtls_gcm_update_ad(&ctx, b16, len_max),
543 mbedtls_gcm_free(&ctx);
545 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, sizeof(b16), 0);
547 TEST_EQUAL(mbedtls_gcm_update_ad(&ctx, b16, 1), 0);
548 TEST_EQUAL(mbedtls_gcm_update_ad(&ctx, b16, len_max - 1),
550 mbedtls_gcm_free(&ctx);
552 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, sizeof(b16), 0);
554 TEST_EQUAL(mbedtls_gcm_update_ad(&ctx, b16, 1), 0);
555 TEST_EQUAL(mbedtls_gcm_update_ad(&ctx, b16, UINT64_MAX), MBEDTLS_ERR_GCM_BAD_INPUT);
558 mbedtls_gcm_free(&ctx);
569 mbedtls_gcm_context ctx;
573 mbedtls_gcm_init(&ctx);
580 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, sizeof(b16), 0);
582 TEST_EQUAL(mbedtls_gcm_update(&ctx, b16, len_max + 1, out, len_max + 1,
585 mbedtls_gcm_free(&ctx);
587 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, sizeof(b16), 0);
589 TEST_EQUAL(mbedtls_gcm_update(&ctx, b16, 1, out, 1, &out_len), 0);
590 TEST_EQUAL(mbedtls_gcm_update(&ctx, b16, len_max, out, len_max, &out_len),
592 mbedtls_gcm_free(&ctx);
594 gcm_reset_ctx(&ctx, b16, sizeof(b16) * 8, b16, sizeof(b16), 0);
596 TEST_EQUAL(mbedtls_gcm_update(&ctx, b16, 1, out, 1, &out_len), 0);
597 TEST_EQUAL(mbedtls_gcm_update(&ctx, b16, UINT64_MAX, out, UINT64_MAX,
602 mbedtls_gcm_free(&ctx);