diff options
Diffstat (limited to 'src/libstrongswan/crypto')
-rw-r--r-- | src/libstrongswan/crypto/crypto_tester.c | 18 | ||||
-rw-r--r-- | src/libstrongswan/crypto/prf_plus.c | 36 | ||||
-rw-r--r-- | src/libstrongswan/crypto/prfs/mac_prf.c | 3 | ||||
-rw-r--r-- | src/libstrongswan/crypto/prfs/prf.h | 5 |
4 files changed, 46 insertions, 16 deletions
diff --git a/src/libstrongswan/crypto/crypto_tester.c b/src/libstrongswan/crypto/crypto_tester.c index b97855325..469059371 100644 --- a/src/libstrongswan/crypto/crypto_tester.c +++ b/src/libstrongswan/crypto/crypto_tester.c @@ -797,8 +797,10 @@ static u_int bench_prf(private_crypto_tester_t *this, start_timing(&start); while (end_timing(&start) < this->bench_time) { - prf->get_bytes(prf, buf, bytes); - runs++; + if (prf->get_bytes(prf, buf, bytes)) + { + runs++; + } } free(buf.ptr); prf->destroy(prf); @@ -860,7 +862,10 @@ METHOD(crypto_tester_t, test_prf, bool, { prf->set_key(prf, key); } - prf->get_bytes(prf, seed, out.ptr); + if (!prf->get_bytes(prf, seed, out.ptr)) + { + failed = TRUE; + } if (!memeq(vector->out, out.ptr, out.len)) { failed = TRUE; @@ -874,8 +879,11 @@ METHOD(crypto_tester_t, test_prf, bool, prf->set_key(prf, key); } prf->allocate_bytes(prf, chunk_create(seed.ptr, 1), NULL); - prf->get_bytes(prf, chunk_create(seed.ptr + 1, 1), NULL); - prf->get_bytes(prf, chunk_skip(seed, 2), out.ptr); + if (!prf->get_bytes(prf, chunk_create(seed.ptr + 1, 1), NULL) || + !prf->get_bytes(prf, chunk_skip(seed, 2), out.ptr)) + { + failed = TRUE; + } if (!memeq(vector->out, out.ptr, out.len)) { failed = TRUE; diff --git a/src/libstrongswan/crypto/prf_plus.c b/src/libstrongswan/crypto/prf_plus.c index 2e7f87d1f..94be1d5bf 100644 --- a/src/libstrongswan/crypto/prf_plus.c +++ b/src/libstrongswan/crypto/prf_plus.c @@ -66,17 +66,27 @@ METHOD(prf_plus_t, get_bytes, bool, { if (this->buffer.len == this->used) { /* buffer used, get next round */ - this->prf->get_bytes(this->prf, this->buffer, NULL); + if (!this->prf->get_bytes(this->prf, this->buffer, NULL)) + { + return FALSE; + } if (this->counter) { - this->prf->get_bytes(this->prf, this->seed, NULL); - this->prf->get_bytes(this->prf, chunk_from_thing(this->counter), - this->buffer.ptr); + if (!this->prf->get_bytes(this->prf, this->seed, NULL) || + !this->prf->get_bytes(this->prf, + chunk_from_thing(this->counter), this->buffer.ptr)) + { + return FALSE; + } this->counter++; } else { - this->prf->get_bytes(this->prf, this->seed, this->buffer.ptr); + if (!this->prf->get_bytes(this->prf, this->seed, + this->buffer.ptr)) + { + return FALSE; + } } this->used = 0; } @@ -131,14 +141,22 @@ prf_plus_t *prf_plus_create(prf_t *prf, bool counter, chunk_t seed) if (counter) { this->counter = 0x01; - this->prf->get_bytes(this->prf, this->seed, NULL); - this->prf->get_bytes(this->prf, chunk_from_thing(this->counter), - this->buffer.ptr); + if (!this->prf->get_bytes(this->prf, this->seed, NULL) || + !this->prf->get_bytes(this->prf, chunk_from_thing(this->counter), + this->buffer.ptr)) + { + destroy(this); + return NULL; + } this->counter++; } else { - this->prf->get_bytes(this->prf, this->seed, this->buffer.ptr); + if (!this->prf->get_bytes(this->prf, this->seed, this->buffer.ptr)) + { + destroy(this); + return NULL; + } } return &this->public; diff --git a/src/libstrongswan/crypto/prfs/mac_prf.c b/src/libstrongswan/crypto/prfs/mac_prf.c index 6215a4bec..489797fb7 100644 --- a/src/libstrongswan/crypto/prfs/mac_prf.c +++ b/src/libstrongswan/crypto/prfs/mac_prf.c @@ -35,10 +35,11 @@ struct private_prf_t { mac_t *mac; }; -METHOD(prf_t, get_bytes, void, +METHOD(prf_t, get_bytes, bool, private_prf_t *this, chunk_t seed, u_int8_t *buffer) { this->mac->get_mac(this->mac, seed, buffer); + return TRUE; } METHOD(prf_t, allocate_bytes, void, diff --git a/src/libstrongswan/crypto/prfs/prf.h b/src/libstrongswan/crypto/prfs/prf.h index ad15205d3..8b98b41aa 100644 --- a/src/libstrongswan/crypto/prfs/prf.h +++ b/src/libstrongswan/crypto/prfs/prf.h @@ -71,13 +71,16 @@ extern enum_name_t *pseudo_random_function_names; * Generic interface for pseudo-random-functions. */ struct prf_t { + /** * Generates pseudo random bytes and writes them in the buffer. * * @param seed a chunk containing the seed for the next bytes * @param buffer pointer where the generated bytes will be written + * @return TRUE if bytes generated successfully */ - void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer); + __attribute__((warn_unused_result)) + bool (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer); /** * Generates pseudo random bytes and allocate space for them. |