Browse Source

In OSSL_PARAM_set_BN(), make sure that the data_size field is at least 1

This way, we guarantee that a zero is represented with one byte of data
that's set to zero.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20013)
Richard Levitte 1 year ago
parent
commit
c2ae891483
1 changed files with 3 additions and 0 deletions
  1. 3 0
      crypto/params.c

+ 3 - 0
crypto/params.c

@@ -1068,6 +1068,9 @@ int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val)
     /* We add 1 byte for signed numbers, to make space for a sign extension */
     if (p->data_type == OSSL_PARAM_INTEGER)
         bytes++;
+    /* 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)