Skip to content

Commit

Permalink
In OSSL_PARAM_set_BN(), make sure that the data_size field is at least 1
Browse files Browse the repository at this point in the history
This way, we guarantee that a zero is represented with one byte of data
that's set to zero.

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#20013)

(cherry picked from commit c2ae891)
(cherry picked from commit fcc224a)
  • Loading branch information
levitte committed Jan 11, 2023
1 parent 5601648 commit f51b4eb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crypto/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,10 @@ int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val)
return 0;

bytes = (size_t)BN_num_bytes(val);
/* We make sure that at least one byte is used, so zero is properly set */
if (bytes == 0)
bytes++;

p->return_size = bytes;
if (p->data == NULL)
return 1;
Expand Down

0 comments on commit f51b4eb

Please sign in to comment.