Skip to content

Commit e773a7d

Browse files
authored
Merge pull request #251 from aidangarske/wp-dh-privSz-fix
Fix privSz for wp_dh_get_params
2 parents 5f09701 + 575eae3 commit e773a7d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/wp_dh_kmgmt.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ static int wp_dh_get_params(wp_Dh* dh, OSSL_PARAM params[])
807807
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PRIV_KEY);
808808
if (p != NULL) {
809809
if (p->data == NULL) {
810-
p->return_size = dh->pubSz;
810+
p->return_size = dh->privSz;
811811
}
812812
else if (p->data_type == OSSL_PARAM_UNSIGNED_INTEGER) {
813813
if (p->data_size < dh->privSz) {
@@ -826,9 +826,15 @@ static int wp_dh_get_params(wp_Dh* dh, OSSL_PARAM params[])
826826
}
827827
}
828828
}
829-
if (ok && (!wp_params_set_octet_string_be(params, OSSL_PKEY_PARAM_PRIV_KEY,
830-
dh->priv, dh->privSz))) {
831-
ok = 0;
829+
if (ok) {
830+
/* Only call if we haven't already handled OSSL_PKEY_PARAM_PRIV_KEY */
831+
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PRIV_KEY);
832+
if (p == NULL || p->data != NULL) {
833+
if (!wp_params_set_octet_string_be(params, OSSL_PKEY_PARAM_PRIV_KEY,
834+
dh->priv, dh->privSz)) {
835+
ok = 0;
836+
}
837+
}
832838
}
833839
if (ok && (!wp_dh_get_params_encoded_public_key(dh, params))) {
834840
ok = 0;

test/test_dh.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ int test_dh_get_params(void *data)
508508
for (int j = 0; j < 2; j++) {
509509
if (j == 0) {
510510
mode = "Null data";
511+
paramsWolfProvider[0] = gettableParams[i];
512+
paramsWolfProvider[0].data = NULL;
513+
paramsWolfProvider[0].data_size = 0;
511514
}
512515
else {
513516
mode = "Buffer data";

0 commit comments

Comments
 (0)