Lines Matching refs:ctx
383 void mbedtls_lmots_public_init(mbedtls_lmots_public_t *ctx)
385 memset(ctx, 0, sizeof(*ctx));
388 void mbedtls_lmots_public_free(mbedtls_lmots_public_t *ctx)
390 mbedtls_platform_zeroize(ctx, sizeof(*ctx));
393 int mbedtls_lmots_import_public_key(mbedtls_lmots_public_t *ctx,
400 ctx->params.type = (mbedtls_lmots_algorithm_type_t)
403 if (key_len != MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type)) {
407 memcpy(ctx->params.I_key_identifier,
411 memcpy(ctx->params.q_leaf_identifier,
415 memcpy(ctx->public_key,
417 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type));
419 ctx->have_public_key = 1;
424 int mbedtls_lmots_export_public_key(const mbedtls_lmots_public_t *ctx,
428 if (key_size < MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type)) {
432 if (!ctx->have_public_key) {
436 MBEDTLS_PUT_UINT32_BE(ctx->params.type, key, MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
439 ctx->params.I_key_identifier,
443 ctx->params.q_leaf_identifier,
446 memcpy(key + PUBLIC_KEY_KEY_HASH_OFFSET, ctx->public_key,
447 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type));
450 *key_len = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(ctx->params.type);
506 int mbedtls_lmots_verify(const mbedtls_lmots_public_t *ctx,
517 if (!ctx->have_public_key) {
521 if (ctx->params.type != MBEDTLS_LMOTS_SHA256_N32_W8) {
533 ret = mbedtls_lmots_calculate_public_key_candidate(&ctx->params,
536 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type),
542 if (memcmp(&Kc_public_key_candidate, ctx->public_key,
543 sizeof(ctx->public_key))) {
552 void mbedtls_lmots_private_init(mbedtls_lmots_private_t *ctx)
554 memset(ctx, 0, sizeof(*ctx));
557 void mbedtls_lmots_private_free(mbedtls_lmots_private_t *ctx)
559 mbedtls_platform_zeroize(ctx,
560 sizeof(*ctx));
563 int mbedtls_lmots_generate_private_key(mbedtls_lmots_private_t *ctx,
577 if (ctx->have_private_key) {
585 ctx->params.type = type;
587 memcpy(ctx->params.I_key_identifier,
589 sizeof(ctx->params.I_key_identifier));
591 MBEDTLS_PUT_UINT32_BE(q_leaf_identifier, ctx->params.q_leaf_identifier, 0);
594 i_digit_idx < MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(ctx->params.type);
602 ctx->params.I_key_identifier,
603 sizeof(ctx->params.I_key_identifier));
609 ctx->params.q_leaf_identifier,
632 ctx->private_key[i_digit_idx],
633 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type),
642 ctx->have_private_key = 1;
650 int mbedtls_lmots_calculate_public_key(mbedtls_lmots_public_t *ctx,
670 ctx->public_key);
675 memcpy(&ctx->params, &priv_ctx->params,
676 sizeof(ctx->params));
678 ctx->have_public_key = 1;
686 int mbedtls_lmots_sign(mbedtls_lmots_private_t *ctx,
707 if (sig_size < MBEDTLS_LMOTS_SIG_LEN(ctx->params.type)) {
712 if (!ctx->have_private_key) {
717 MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type));
722 ret = create_digit_array_with_checksum(&ctx->params,
730 ret = hash_digit_array(&ctx->params, (unsigned char *) ctx->private_key,
736 MBEDTLS_PUT_UINT32_BE(ctx->params.type, sig, MBEDTLS_LMOTS_SIG_TYPE_OFFSET);
753 ctx->have_private_key = 0;
754 mbedtls_platform_zeroize(ctx->private_key,
755 sizeof(ctx->private_key));
758 MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN(ctx->params.type));
760 memcpy(sig + MBEDTLS_LMOTS_SIG_SIGNATURE_OFFSET(ctx->params.type), tmp_sig,
761 MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT(ctx->params.type)
762 * MBEDTLS_LMOTS_N_HASH_LEN(ctx->params.type));
765 *sig_len = MBEDTLS_LMOTS_SIG_LEN(ctx->params.type);