summaryrefslogtreecommitdiff
path: root/src/libtls/tls_prf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtls/tls_prf.c')
-rw-r--r--src/libtls/tls_prf.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/libtls/tls_prf.c b/src/libtls/tls_prf.c
index f181d01d3..918de1e50 100644
--- a/src/libtls/tls_prf.c
+++ b/src/libtls/tls_prf.c
@@ -33,16 +33,16 @@ struct private_tls_prf12_t {
prf_t *prf;
};
-METHOD(tls_prf_t, set_key12, void,
+METHOD(tls_prf_t, set_key12, bool,
private_tls_prf12_t *this, chunk_t key)
{
- this->prf->set_key(this->prf, key);
+ return this->prf->set_key(this->prf, key);
}
/**
* The P_hash function as in TLS 1.0/1.2
*/
-static void p_hash(prf_t *prf, char *label, chunk_t seed, size_t block_size,
+static bool p_hash(prf_t *prf, char *label, chunk_t seed, size_t block_size,
size_t bytes, char *out)
{
char buf[block_size], abuf[block_size];
@@ -56,11 +56,17 @@ static void p_hash(prf_t *prf, char *label, chunk_t seed, size_t block_size,
while (TRUE)
{
/* A(i) = HMAC_hash(secret, A(i-1)) */
- prf->get_bytes(prf, a, abuf);
+ if (!prf->get_bytes(prf, a, abuf))
+ {
+ return FALSE;
+ }
a = chunk_from_thing(abuf);
/* HMAC_hash(secret, A(i) + seed) */
- prf->get_bytes(prf, a, NULL);
- prf->get_bytes(prf, seed, buf);
+ if (!prf->get_bytes(prf, a, NULL) ||
+ !prf->get_bytes(prf, seed, buf))
+ {
+ return FALSE;
+ }
if (bytes <= block_size)
{
@@ -71,14 +77,15 @@ static void p_hash(prf_t *prf, char *label, chunk_t seed, size_t block_size,
out += block_size;
bytes -= block_size;
}
+ return TRUE;
}
-METHOD(tls_prf_t, get_bytes12, void,
+METHOD(tls_prf_t, get_bytes12, bool,
private_tls_prf12_t *this, char *label, chunk_t seed,
size_t bytes, char *out)
{
- p_hash(this->prf, label, seed, this->prf->get_block_size(this->prf),
- bytes, out);
+ return p_hash(this->prf, label, seed, this->prf->get_block_size(this->prf),
+ bytes, out);
}
METHOD(tls_prf_t, destroy12, void,
@@ -135,26 +142,31 @@ struct private_tls_prf10_t {
prf_t *sha1;
};
-METHOD(tls_prf_t, set_key10, void,
+METHOD(tls_prf_t, set_key10, bool,
private_tls_prf10_t *this, chunk_t key)
{
size_t len = key.len / 2 + key.len % 2;
- this->md5->set_key(this->md5, chunk_create(key.ptr, len));
- this->sha1->set_key(this->sha1, chunk_create(key.ptr + key.len - len, len));
+ return this->md5->set_key(this->md5, chunk_create(key.ptr, len)) &&
+ this->sha1->set_key(this->sha1, chunk_create(key.ptr + key.len - len,
+ len));
}
-METHOD(tls_prf_t, get_bytes10, void,
+METHOD(tls_prf_t, get_bytes10, bool,
private_tls_prf10_t *this, char *label, chunk_t seed,
size_t bytes, char *out)
{
char buf[bytes];
- p_hash(this->md5, label, seed, this->md5->get_block_size(this->md5),
- bytes, out);
- p_hash(this->sha1, label, seed, this->sha1->get_block_size(this->sha1),
- bytes, buf);
+ if (!p_hash(this->md5, label, seed, this->md5->get_block_size(this->md5),
+ bytes, out) ||
+ !p_hash(this->sha1, label, seed, this->sha1->get_block_size(this->sha1),
+ bytes, buf))
+ {
+ return FALSE;
+ }
memxor(out, buf, bytes);
+ return TRUE;
}
METHOD(tls_prf_t, destroy10, void,