checking mpz_export return value properly

fixes a potential DoS attack if a DH value of zero gets processed
This commit is contained in:
Martin Willi
2008-09-17 08:10:48 +00:00
parent b33c11b6c7
commit 73f6886a50
4 changed files with 32 additions and 8 deletions
@@ -440,7 +440,11 @@ static status_t get_other_public_value(private_gmp_diffie_hellman_t *this,
return FAILED; return FAILED;
} }
value->len = this->p_len; value->len = this->p_len;
value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb); value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->yb);
if (value->ptr == NULL)
{
return FAILED;
}
return SUCCESS; return SUCCESS;
} }
@@ -451,6 +455,10 @@ static void get_my_public_value(private_gmp_diffie_hellman_t *this,chunk_t *valu
{ {
value->len = this->p_len; value->len = this->p_len;
value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->ya); value->ptr = mpz_export(NULL, NULL, 1, value->len, 1, 0, this->ya);
if (value->ptr == NULL)
{
value->len = 0;
}
} }
/** /**
@@ -463,7 +471,11 @@ static status_t get_shared_secret(private_gmp_diffie_hellman_t *this, chunk_t *s
return FAILED; return FAILED;
} }
secret->len = this->p_len; secret->len = this->p_len;
secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz); secret->ptr = mpz_export(NULL, NULL, 1, secret->len, 1, 0, this->zz);
if (secret->ptr == NULL)
{
return FAILED;
}
return SUCCESS; return SUCCESS;
} }
@@ -191,6 +191,10 @@ static chunk_t rsadp(private_gmp_rsa_private_key_t *this, chunk_t data)
decrypted.len = this->k; decrypted.len = this->k;
decrypted.ptr = mpz_export(NULL, NULL, 1, decrypted.len, 1, 0, t1); decrypted.ptr = mpz_export(NULL, NULL, 1, decrypted.len, 1, 0, t1);
if (decrypted.ptr == NULL)
{
decrypted.len = 0;
}
mpz_clear_randomized(t1); mpz_clear_randomized(t1);
mpz_clear_randomized(t2); mpz_clear_randomized(t2);
@@ -93,8 +93,12 @@ static chunk_t rsaep(private_gmp_rsa_public_key_t *this, chunk_t data)
mpz_powm(c, m, this->e, this->n); mpz_powm(c, m, this->e, this->n);
encrypted.len = this->k; encrypted.len = this->k;
encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c); encrypted.ptr = mpz_export(NULL, NULL, 1, encrypted.len, 1, 0, c);
if (encrypted.ptr == NULL)
{
encrypted.len = 0;
}
mpz_clear(c); mpz_clear(c);
mpz_clear(m); mpz_clear(m);
+4
View File
@@ -103,6 +103,10 @@ static chunk_t mpz_to_chunk(mpz_t number)
chunk.len = 1 + mpz_sizeinbase(number, 2)/BITS_PER_BYTE; chunk.len = 1 + mpz_sizeinbase(number, 2)/BITS_PER_BYTE;
chunk.ptr = mpz_export(NULL, NULL, 1, chunk.len, 1, 0, number); chunk.ptr = mpz_export(NULL, NULL, 1, chunk.len, 1, 0, number);
if (chunk.ptr == NULL)
{
chunk.len = 0;
}
return chunk; return chunk;
} }