aboutsummaryrefslogtreecommitdiffstats
path: root/src/kdf
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-14 02:05:05 +0000
committerlloyd <[email protected]>2010-09-14 02:05:05 +0000
commit77a33b0c16880884cc0326e92c0c30d0e8444a91 (patch)
treedf2d917b312abb79c8654558399521366dbb2d14 /src/kdf
parent59a9b0ef260b010606edc3384035b6aa12dd6415 (diff)
More changes to avoid vector to pointer implicit conversions
Diffstat (limited to 'src/kdf')
-rw-r--r--src/kdf/kdf2/kdf2.cpp2
-rw-r--r--src/kdf/ssl_prf/prf_ssl3.cpp2
-rw-r--r--src/kdf/tls_prf/prf_tls.cpp19
3 files changed, 12 insertions, 11 deletions
diff --git a/src/kdf/kdf2/kdf2.cpp b/src/kdf/kdf2/kdf2.cpp
index b9e785942..8106ba07d 100644
--- a/src/kdf/kdf2/kdf2.cpp
+++ b/src/kdf/kdf2/kdf2.cpp
@@ -29,7 +29,7 @@ SecureVector<byte> KDF2::derive(u32bit out_len,
SecureVector<byte> hash_result = hash->final();
u32bit added = std::min<u32bit>(hash_result.size(), out_len);
- output.append(hash_result, added);
+ output.append(&hash_result[0], added);
out_len -= added;
++counter;
diff --git a/src/kdf/ssl_prf/prf_ssl3.cpp b/src/kdf/ssl_prf/prf_ssl3.cpp
index 2b67644d2..1d896a63c 100644
--- a/src/kdf/ssl_prf/prf_ssl3.cpp
+++ b/src/kdf/ssl_prf/prf_ssl3.cpp
@@ -39,7 +39,7 @@ OctetString next_hash(u32bit where, u32bit want,
md5.update(sha1_hash);
SecureVector<byte> md5_hash = md5.final();
- return OctetString(md5_hash, want);
+ return OctetString(&md5_hash[0], want);
}
}
diff --git a/src/kdf/tls_prf/prf_tls.cpp b/src/kdf/tls_prf/prf_tls.cpp
index 7345f11c5..fa4552474 100644
--- a/src/kdf/tls_prf/prf_tls.cpp
+++ b/src/kdf/tls_prf/prf_tls.cpp
@@ -18,7 +18,7 @@ namespace {
/*
* TLS PRF P_hash function
*/
-void P_hash(byte output[], u32bit output_len,
+void P_hash(MemoryRegion<byte>& output,
MessageAuthenticationCode* mac,
const byte secret[], u32bit secret_len,
const byte seed[], u32bit seed_len)
@@ -27,10 +27,12 @@ void P_hash(byte output[], u32bit output_len,
SecureVector<byte> A(seed, seed_len);
- while(output_len)
+ u32bit offset = 0;
+
+ while(offset != output.size())
{
const u32bit this_block_len =
- std::min(mac->OUTPUT_LENGTH, output_len);
+ std::min<u32bit>(mac->OUTPUT_LENGTH, output.size() - offset);
A = mac->process(A);
@@ -38,9 +40,8 @@ void P_hash(byte output[], u32bit output_len,
mac->update(seed, seed_len);
SecureVector<byte> block = mac->final();
- xor_buf(output, &block[0], this_block_len);
- output_len -= this_block_len;
- output += this_block_len;
+ xor_buf(&output[offset], &block[0], this_block_len);
+ offset += this_block_len;
}
}
@@ -75,8 +76,8 @@ SecureVector<byte> TLS_PRF::derive(u32bit key_len,
const byte* S1 = secret;
const byte* S2 = secret + (secret_len - S2_len);
- P_hash(output, key_len, hmac_md5, S1, S1_len, seed, seed_len);
- P_hash(output, key_len, hmac_sha1, S2, S2_len, seed, seed_len);
+ P_hash(output, hmac_md5, S1, S1_len, seed, seed_len);
+ P_hash(output, hmac_sha1, S2, S2_len, seed, seed_len);
return output;
}
@@ -100,7 +101,7 @@ SecureVector<byte> TLS_12_PRF::derive(u32bit key_len,
{
SecureVector<byte> output(key_len);
- P_hash(output, key_len, hmac, secret, secret_len, seed, seed_len);
+ P_hash(output, hmac, secret, secret_len, seed, seed_len);
return output;
}