From 5eb30fce49d8ccec303a05a42e20782286d477f4 Mon Sep 17 00:00:00 2001
From: Nicolai Stange <nstange@suse.de>
Date: Fri, 19 Nov 2021 13:59:39 +0100
Subject: [PATCH 15/18] crypto: dh - store group id in dh-generic's dh_ctx
References: jsc#SLE-21132,bsc#1191256
Patch-mainline: Submitted, linux-crypto ML
A subsequent patch will make the crypto/dh's dh_is_pubkey_valid() to
calculate the Q value from the P domain parameter for safe-prime groups,
for which by definition Q = (P - 1)/2. However, dh_is_pubkey_valid() will
need to check first whether the group in question is actually a safe-prime
group. In order to make this information available, introduce a new
->group_id member to struct dh_ctx and let dh_set_params() set it to the
value found in the struct dh as deserialized via crypto_dh_decode_key().
Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
crypto/dh.c | 3 +++
1 file changed, 3 insertions(+)
--- a/crypto/dh.c
+++ b/crypto/dh.c
@@ -14,6 +14,7 @@
#include <linux/mpi.h>
struct dh_ctx {
+ enum dh_group_id group_id;
MPI p; /* Value is guaranteed to be set. */
MPI q; /* Value is optional. */
MPI g; /* Value is guaranteed to be set. */
@@ -59,6 +60,8 @@ static int dh_set_params(struct dh_ctx *
if (dh_check_params_length(params->p_size << 3))
return -EINVAL;
+ ctx->group_id = params->group_id;
+
ctx->p = mpi_read_raw_data(params->p, params->p_size);
if (!ctx->p)
return -EINVAL;