Skip to content

Commit c4ca969

Browse files
committed
Fixes to support HAVE_PUBLIC_FFDHE not defined.
1 parent 0a42ade commit c4ca969

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/mod_etsi.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ static int NamedGroupToDhParams(EtsiKeyType keyType,
622622
int ret = 0;
623623
const DhParams* params = NULL;
624624
word32 privKeySz = 0;
625+
word32 pubKeySz = 0;
626+
#ifdef HAVE_PUBLIC_FFDHE
625627
switch (keyType) {
626628
#ifdef HAVE_FFDHE_2048
627629
case ETSI_KEY_TYPE_FFDHE_2048:
@@ -647,10 +649,17 @@ static int NamedGroupToDhParams(EtsiKeyType keyType,
647649
ret = WOLFKM_NOT_COMPILED_IN;
648650
break;
649651
}
652+
if (params)
653+
pubKeySz = params->p_len;
654+
#else
655+
privKeySz = wc_DhGetNamedKeyMinSize((int)keyType);
656+
ret = wc_DhGetNamedKeyParamSize((int)keyType, &pubKeySz, NULL, NULL);
657+
#endif
658+
650659
if (pParams)
651660
*pParams = params;
652-
if (pPubKeySz && params)
653-
*pPubKeySz = params->p_len;
661+
if (pPubKeySz)
662+
*pPubKeySz = pubKeySz;
654663
if (pPrivKeySz)
655664
*pPrivKeySz = privKeySz;
656665
return ret;
@@ -837,14 +846,15 @@ static int GenNewKeyDh(EtsiKey* key, EtsiKeyType keyType, WC_RNG* rng)
837846
int ret;
838847
DhKey dh;
839848
const DhParams* params = NULL;
840-
word32 privKeySz = 0, pubKeySz = 0;
849+
word32 privKeySz = 0, pubKeySz = 0, p_len;
841850
byte privKey[MAX_DH_PRIV_SZ];
842851
byte pubKey[MAX_DH_PUB_SZ];
843852

844853
ret = NamedGroupToDhParams(keyType, &params, &privKeySz, &pubKeySz);
845854
if (ret != 0) {
846855
return ret;
847856
}
857+
p_len = pubKeySz;
848858

849859
ret = wc_InitDhKey(&dh);
850860
if (ret != 0) {
@@ -853,20 +863,24 @@ static int GenNewKeyDh(EtsiKey* key, EtsiKeyType keyType, WC_RNG* rng)
853863
}
854864

855865
/* Set key params */
866+
#ifdef HAVE_PUBLIC_FFDHE
856867
ret = wc_DhSetKey(&dh,
857868
params->p, params->p_len,
858869
params->g, params->g_len);
870+
#else
871+
ret = wc_DhSetNamedKey(&dh, (int)keyType);
872+
#endif
859873
if (ret == 0) {
860874
/* Generate a new key pair */
861875
ret = wc_DhGenerateKeyPair(&dh, rng,
862876
privKey, &privKeySz,
863877
pubKey, &pubKeySz);
864878
}
865879
if (ret == 0) {
866-
if (params->p_len != pubKeySz) {
880+
if (p_len != pubKeySz) {
867881
/* Zero pad the front of the public key to match prime "p" size */
868-
memmove(pubKey + params->p_len - pubKeySz, pubKey, pubKeySz);
869-
memset(pubKey, 0, params->p_len - pubKeySz);
882+
memmove(pubKey + p_len - pubKeySz, pubKey, pubKeySz);
883+
memset(pubKey, 0, p_len - pubKeySz);
870884
}
871885

872886
/* load public and private key info into DkKey */

0 commit comments

Comments
 (0)