Skip to content

Commit 4e292e3

Browse files
committed
Adjust to look more like ECDH
1 parent 721d935 commit 4e292e3

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

src/wh_client_crypto.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,23 +2832,20 @@ int wh_Client_Curve25519SharedSecret(whClientContext* ctx,
28322832
sizeof(*res);
28332833
/* Defensive bound: res->sz must fit within the actual
28342834
* received frame */
2835-
if (res_len < hdr_sz ||
2836-
res->sz > (res_len - hdr_sz)) {
2835+
if (res_len < hdr_sz || res->sz > (res_len - hdr_sz)) {
28372836
ret = WH_ERROR_ABORTED;
28382837
}
2839-
else if ((out != NULL) && (out_size != NULL) &&
2840-
(res->sz > *out_size)) {
2841-
/* Output buffer too small. Report required size and
2842-
* fail rather than silently truncating X25519 key
2843-
* material. */
2844-
*out_size = res->sz;
2845-
ret = WH_ERROR_BUFFER_SIZE;
2846-
}
2847-
else {
2848-
if (out_size != NULL) {
2849-
*out_size = res->sz;
2838+
if (out_size != NULL) {
2839+
if ((ret >= 0) &&
2840+
(out != NULL) && (res->sz > *out_size)) {
2841+
/* Output buffer too small. Report required size
2842+
* and fail rather than silently truncating
2843+
* X25519 key material. */
2844+
ret = WH_ERROR_BUFFER_SIZE;
28502845
}
2851-
if ((out != NULL) && (res->sz > 0)) {
2846+
/* Give caller the required size, even on failure */
2847+
*out_size = res->sz;
2848+
if ((ret >= 0) && (out != NULL) && (res->sz > 0)) {
28522849
memcpy(out, res_out, res->sz);
28532850
WH_DEBUG_VERBOSE_HEXDUMP("[client] X25519:",
28542851
res_out, res->sz);

0 commit comments

Comments
 (0)