Lines Matching refs:ctx

383 void mbedtls_lmots_public_init(mbedtls_lmots_public_t *ctx)  in mbedtls_lmots_public_init()  argument
385 memset(ctx, 0, sizeof(*ctx)); in mbedtls_lmots_public_init()
388 void mbedtls_lmots_public_free(mbedtls_lmots_public_t *ctx) in mbedtls_lmots_public_free() argument
390 if (ctx == NULL) { in mbedtls_lmots_public_free()
394 mbedtls_platform_zeroize(ctx, sizeof(*ctx)); in mbedtls_lmots_public_free()
397 int mbedtls_lmots_import_public_key(mbedtls_lmots_public_t *ctx, in mbedtls_lmots_import_public_key() argument
404 ctx->params.type = (mbedtls_lmots_algorithm_type_t) in mbedtls_lmots_import_public_key()
407 if (key_len != MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type)) { in mbedtls_lmots_import_public_key()
411 memcpy(ctx->params.I_key_identifier, in mbedtls_lmots_import_public_key()
415 memcpy(ctx->params.q_leaf_identifier, in mbedtls_lmots_import_public_key()
419 memcpy(ctx->public_key, in mbedtls_lmots_import_public_key()
421 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type)); in mbedtls_lmots_import_public_key()
423 ctx->have_public_key = 1; in mbedtls_lmots_import_public_key()
428 int mbedtls_lmots_export_public_key(const mbedtls_lmots_public_t *ctx, in mbedtls_lmots_export_public_key() argument
432 if (key_size < MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type)) { in mbedtls_lmots_export_public_key()
436 if (!ctx->have_public_key) { in mbedtls_lmots_export_public_key()
440 MBEDTLS_PUT_UINT32_BE(ctx->params.type, key, MBEDTLS_LMOTS_SIG_TYPE_OFFSET); in mbedtls_lmots_export_public_key()
443 ctx->params.I_key_identifier, in mbedtls_lmots_export_public_key()
447 ctx->params.q_leaf_identifier, in mbedtls_lmots_export_public_key()
450 memcpy(key + PUBLIC_KEY_KEY_HASH_OFFSET, ctx->public_key, in mbedtls_lmots_export_public_key()
451 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type)); in mbedtls_lmots_export_public_key()
454 *key_len = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type); in mbedtls_lmots_export_public_key()
510 int mbedtls_lmots_verify(const mbedtls_lmots_public_t *ctx, in mbedtls_lmots_verify() argument
521 if (!ctx->have_public_key) { in mbedtls_lmots_verify()
525 if (ctx->params.type != MBEDTLS_LMOTS_SHA256_N32_W8) { in mbedtls_lmots_verify()
537 ret = mbedtls_lmots_calculate_public_key_candidate(&ctx->params, in mbedtls_lmots_verify()
540 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type), in mbedtls_lmots_verify()
546 if (memcmp(&Kc_public_key_candidate, ctx->public_key, in mbedtls_lmots_verify()
547 sizeof(ctx->public_key))) { in mbedtls_lmots_verify()
556 void mbedtls_lmots_private_init(mbedtls_lmots_private_t *ctx) in mbedtls_lmots_private_init() argument
558 memset(ctx, 0, sizeof(*ctx)); in mbedtls_lmots_private_init()
561 void mbedtls_lmots_private_free(mbedtls_lmots_private_t *ctx) in mbedtls_lmots_private_free() argument
563 if (ctx == NULL) { in mbedtls_lmots_private_free()
567 mbedtls_platform_zeroize(ctx, in mbedtls_lmots_private_free()
568 sizeof(*ctx)); in mbedtls_lmots_private_free()
571 int mbedtls_lmots_generate_private_key(mbedtls_lmots_private_t *ctx, in mbedtls_lmots_generate_private_key() argument
585 if (ctx->have_private_key) { in mbedtls_lmots_generate_private_key()
593 ctx->params.type = type; in mbedtls_lmots_generate_private_key()
595 memcpy(ctx->params.I_key_identifier, in mbedtls_lmots_generate_private_key()
597 sizeof(ctx->params.I_key_identifier)); in mbedtls_lmots_generate_private_key()
599 MBEDTLS_PUT_UINT32_BE(q_leaf_identifier, ctx->params.q_leaf_identifier, 0); in mbedtls_lmots_generate_private_key()
602 i_digit_idx < MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(ctx->params.type); in mbedtls_lmots_generate_private_key()
610 ctx->params.I_key_identifier, in mbedtls_lmots_generate_private_key()
611 sizeof(ctx->params.I_key_identifier)); in mbedtls_lmots_generate_private_key()
617 ctx->params.q_leaf_identifier, in mbedtls_lmots_generate_private_key()
640 ctx->private_key[i_digit_idx], in mbedtls_lmots_generate_private_key()
641 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type), in mbedtls_lmots_generate_private_key()
650 ctx->have_private_key = 1; in mbedtls_lmots_generate_private_key()
658 int mbedtls_lmots_calculate_public_key(mbedtls_lmots_public_t *ctx, in mbedtls_lmots_calculate_public_key() argument
678 ctx->public_key); in mbedtls_lmots_calculate_public_key()
683 memcpy(&ctx->params, &priv_ctx->params, in mbedtls_lmots_calculate_public_key()
684 sizeof(ctx->params)); in mbedtls_lmots_calculate_public_key()
686 ctx->have_public_key = 1; in mbedtls_lmots_calculate_public_key()
694 int mbedtls_lmots_sign(mbedtls_lmots_private_t *ctx, in mbedtls_lmots_sign() argument
715 if (sig_size < MBEDTLS_LMOTS_SIG_LEN(ctx->params.type)) { in mbedtls_lmots_sign()
720 if (!ctx->have_private_key) { in mbedtls_lmots_sign()
725 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type)); in mbedtls_lmots_sign()
730 ret = create_digit_array_with_checksum(&ctx->params, in mbedtls_lmots_sign()
738 ret = hash_digit_array(&ctx->params, (unsigned char *) ctx->private_key, in mbedtls_lmots_sign()
744 MBEDTLS_PUT_UINT32_BE(ctx->params.type, sig, MBEDTLS_LMOTS_SIG_TYPE_OFFSET); in mbedtls_lmots_sign()
761 ctx->have_private_key = 0; in mbedtls_lmots_sign()
762 mbedtls_platform_zeroize(ctx->private_key, in mbedtls_lmots_sign()
763 sizeof(ctx->private_key)); in mbedtls_lmots_sign()
766 MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(ctx->params.type)); in mbedtls_lmots_sign()
768 memcpy(sig + MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(ctx->params.type), tmp_sig, in mbedtls_lmots_sign()
769 MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(ctx->params.type) in mbedtls_lmots_sign()
770 * MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type)); in mbedtls_lmots_sign()
773 *sig_len = MBEDTLS_LMOTS_SIG_LEN(ctx->params.type); in mbedtls_lmots_sign()