aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-29 10:04:06 -0400
committerJack Lloyd <[email protected]>2017-09-29 10:04:06 -0400
commit2860028d21d93bbbf33966e7e511a9e19da770ca (patch)
tree8b91259274e6df8c07afbde1e3e9ce381bd982d8 /src/lib
parent3829cf5df7522c4812d4bc33cb593503459c76b9 (diff)
Add a test of TLS CBC padding verification
See also GH #1227
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/tls/tls_cbc/tls_cbc.cpp13
-rw-r--r--src/lib/tls/tls_cbc/tls_cbc.h8
2 files changed, 12 insertions, 9 deletions
diff --git a/src/lib/tls/tls_cbc/tls_cbc.cpp b/src/lib/tls/tls_cbc/tls_cbc.cpp
index 69aa9725d..e0e631cc7 100644
--- a/src/lib/tls/tls_cbc/tls_cbc.cpp
+++ b/src/lib/tls/tls_cbc/tls_cbc.cpp
@@ -211,9 +211,6 @@ void TLS_CBC_HMAC_AEAD_Encryption::finish(secure_vector<uint8_t>& buffer, size_t
}
}
-namespace {
-
-
/*
* Checks the TLS padding. Returns 0 if the padding is invalid (we
* count the padding_length field as part of the padding size so a
@@ -225,7 +222,7 @@ namespace {
* Returning 0 in the error case should ensure the MAC check will fail.
* This approach is suggested in section 6.2.3.2 of RFC 5246.
*/
-uint16_t check_tls_padding(const uint8_t record[], size_t record_len)
+uint16_t check_tls_cbc_padding(const uint8_t record[], size_t record_len)
{
/*
* TLS v1.0 and up require all the padding bytes be the same value
@@ -246,8 +243,6 @@ uint16_t check_tls_padding(const uint8_t record[], size_t record_len)
return CT::select<uint16_t>(pad_invalid_mask, 0, pad_byte + 1);
}
-}
-
void TLS_CBC_HMAC_AEAD_Decryption::cbc_decrypt_record(uint8_t record_contents[], size_t record_len)
{
BOTAN_ASSERT(record_len % block_size() == 0,
@@ -315,7 +310,7 @@ size_t TLS_CBC_HMAC_AEAD_Decryption::output_length(size_t) const
* no compressions are performed.
*
* Note that the padding validation in Botan is always performed over
-* min(plen,256) bytes, see the function check_tls_padding. This differs
+* min(plen,256) bytes, see the function check_tls_cbc_padding. This differs
* from the countermeasure described in the paper.
*
* Note that the padding length padlen does also count the last byte
@@ -406,7 +401,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<uint8_t>& buffer, size_t
cbc_decrypt_record(record_contents, enc_size);
// 0 if padding was invalid, otherwise 1 + padding_bytes
- uint16_t pad_size = check_tls_padding(record_contents, enc_size);
+ uint16_t pad_size = check_tls_cbc_padding(record_contents, enc_size);
// No oracle here, whoever sent us this had the key since MAC check passed
if(pad_size == 0)
@@ -426,7 +421,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<uint8_t>& buffer, size_t
CT::poison(record_contents, record_len);
// 0 if padding was invalid, otherwise 1 + padding_bytes
- uint16_t pad_size = check_tls_padding(record_contents, record_len);
+ uint16_t pad_size = check_tls_cbc_padding(record_contents, record_len);
/*
This mask is zero if there is not enough room in the packet to get a valid MAC.
diff --git a/src/lib/tls/tls_cbc/tls_cbc.h b/src/lib/tls/tls_cbc/tls_cbc.h
index d0fc1fb61..f09e0ad39 100644
--- a/src/lib/tls/tls_cbc/tls_cbc.h
+++ b/src/lib/tls/tls_cbc/tls_cbc.h
@@ -166,6 +166,14 @@ class BOTAN_TEST_API TLS_CBC_HMAC_AEAD_Decryption final : public TLS_CBC_HMAC_AE
void perform_additional_compressions(size_t plen, size_t padlen);
};
+/**
+* Check the TLS padding of a record
+* @param record the record bits
+* @param record_len length of record
+* @return 0 if padding is invalid, otherwise padding_bytes + 1
+*/
+BOTAN_TEST_API uint16_t check_tls_cbc_padding(const uint8_t record[], size_t record_len);
+
}
}