Skip to content

Commit

Permalink
manipulating pointer on a temp instead of void*
Browse files Browse the repository at this point in the history
  • Loading branch information
feventura committed Mar 1, 2024
1 parent 6e08171 commit 22e0fa0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions oqsprov/oqsprov_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ static OQSX_KEY *oqsx_key_op(const X509_ALGOR *palg, const unsigned char *p,
size_t publen = 0;
size_t previous_privlen = 0;
size_t previous_publen = 0;
size_t temp_pub_len, temp_priv_len;
char *temp_priv, *temp_pub;
int pqc_pub_enc = 0;
int i;

Expand Down Expand Up @@ -686,6 +688,10 @@ static OQSX_KEY *oqsx_key_op(const X509_ALGOR *palg, const unsigned char *p,
ERR_raise(ERR_LIB_USER, ERR_R_MALLOC_FAILURE);
goto err_key_op;
}
temp_priv_len = previous_privlen;
temp_pub_len = previous_publen;
temp_priv = OPENSSL_secure_zalloc(temp_priv_len);
temp_pub = OPENSSL_secure_zalloc(temp_pub_len);
previous_privlen = 0;
previous_publen = 0;
for (i = 0; i < key->numkeys; i++) {
Expand All @@ -710,6 +716,8 @@ static OQSX_KEY *oqsx_key_op(const X509_ALGOR *palg, const unsigned char *p,
OPENSSL_free(enc_len);
if (privlen > key->privkeylen_cmp[i]) {
OPENSSL_free(name);
OPENSSL_secure_clear_free(temp_priv, temp_priv_len);
OPENSSL_secure_clear_free(temp_pub, temp_pub_len);
ERR_raise(ERR_LIB_USER, OQSPROV_R_INVALID_ENCODING);
goto err_key_op;
}
Expand All @@ -723,15 +731,19 @@ static OQSX_KEY *oqsx_key_op(const X509_ALGOR *palg, const unsigned char *p,
else
publen = 0;
}
memcpy(key->privkey + previous_privlen,
memcpy(temp_priv + previous_privlen,
p + previous_privlen + previous_publen, privlen);
memcpy(key->pubkey + previous_publen,
memcpy(temp_pub + previous_publen,
p + privlen + previous_privlen + previous_publen,
publen);
previous_privlen += privlen;
previous_publen += publen;
OPENSSL_free(name);
}
memcpy(key->privkey, temp_priv, previous_privlen);
memcpy(key->privkey, temp_priv, previous_privlen);
OPENSSL_secure_clear_free(temp_priv, temp_priv_len);
OPENSSL_secure_clear_free(temp_pub, temp_pub_len);
} else {
if (key->numkeys == 2) {
DECODE_UINT32(classical_privatekey_len,
Expand Down

0 comments on commit 22e0fa0

Please sign in to comment.