Skip to content

Commit 05cbdf5

Browse files
authored
Merge pull request #125 from ColtonWilley/wp_ed_priv_key_export_clamp_fix
Only restore ed key clamping if key was imported
2 parents 8b1c601 + 693a1a1 commit 05cbdf5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/wp_ecx_kmgmt.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ struct wp_Ecx {
168168
unsigned int hasPub:1;
169169
/** Private key available. */
170170
unsigned int hasPriv:1;
171+
/* Private key was imported and has been clamped */
172+
unsigned int clamped:1;
171173
};
172174

173175
/**
@@ -877,6 +879,7 @@ static int wp_ecx_import(wp_Ecx* ecx, int selection, const OSSL_PARAM params[])
877879
if (ok) {
878880
ecx->hasPriv = 1;
879881
ecx->hasPub = 1;
882+
ecx->clamped = 1;
880883
}
881884
}
882885
}
@@ -1020,8 +1023,10 @@ static int wp_ecx_export_keypair(wp_Ecx* ecx, OSSL_PARAM* params, int* pIdx,
10201023
outLen = ecx->data->len;
10211024
rc = (*ecx->data->exportPriv)((void*)&ecx->key, data + *idx, &outLen);
10221025
if (ok) {
1023-
data[*idx + 0 ] = ecx->unclamped[0];
1024-
data[*idx + outLen - 1] = ecx->unclamped[1];
1026+
if (ecx->clamped) {
1027+
data[*idx + 0 ] = ecx->unclamped[0];
1028+
data[*idx + outLen - 1] = ecx->unclamped[1];
1029+
}
10251030
wp_param_set_octet_string_ptr(&params[i++],
10261031
OSSL_PKEY_PARAM_PRIV_KEY, data + *idx, outLen);
10271032
}

0 commit comments

Comments
 (0)