diff options
author | Jack Lloyd <[email protected]> | 2018-11-28 10:35:17 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-28 10:35:17 -0500 |
commit | 007314c530eb12d414ced07515f8cbc25a0f64f5 (patch) | |
tree | dc887f97efa0248aa5e7b8468c94145f6a1305f8 /src/lib/tls/tls_cbc/tls_cbc.cpp | |
parent | b03f38f57d4f50ace1ed8b57d83ba70eb5bc1dfb (diff) |
Add CT::Mask type
Diffstat (limited to 'src/lib/tls/tls_cbc/tls_cbc.cpp')
-rw-r--r-- | src/lib/tls/tls_cbc/tls_cbc.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/lib/tls/tls_cbc/tls_cbc.cpp b/src/lib/tls/tls_cbc/tls_cbc.cpp index 7376e655b..f3ea17d42 100644 --- a/src/lib/tls/tls_cbc/tls_cbc.cpp +++ b/src/lib/tls/tls_cbc/tls_cbc.cpp @@ -235,17 +235,17 @@ uint16_t check_tls_cbc_padding(const uint8_t record[], size_t record_len) const uint8_t pad_byte = record[record_len-1]; const uint16_t pad_bytes = 1 + pad_byte; - uint16_t pad_invalid = CT::is_less<uint16_t>(rec16, pad_bytes); + auto pad_invalid = CT::Mask<uint16_t>::is_lt(rec16, pad_byte); for(uint16_t i = rec16 - to_check; i != rec16; ++i) { const uint16_t offset = rec16 - i; - const uint16_t in_pad_range = CT::is_lte<uint16_t>(offset, pad_bytes); - pad_invalid |= (in_pad_range & (record[i] ^ pad_byte)); + const auto in_pad_range = CT::Mask<uint16_t>::is_lte(offset, pad_bytes); + const auto pad_correct = CT::Mask<uint16_t>::is_equal(record[i], pad_byte); + pad_invalid |= in_pad_range & ~pad_correct; } - const uint16_t pad_invalid_mask = CT::expand_mask<uint16_t>(pad_invalid); - return CT::select<uint16_t>(pad_invalid_mask, 0, pad_byte + 1); + return pad_invalid.if_not_set_return(pad_bytes); } void TLS_CBC_HMAC_AEAD_Decryption::cbc_decrypt_record(uint8_t record_contents[], size_t record_len) @@ -337,7 +337,7 @@ void TLS_CBC_HMAC_AEAD_Decryption::perform_additional_compressions(size_t plen, const uint16_t current_compressions = ((L2 + block_size - 1 - max_bytes_in_first_block) / block_size); // number of additional compressions we have to perform const uint16_t add_compressions = max_compresssions - current_compressions; - const uint8_t equal = CT::is_equal(max_compresssions, current_compressions) & 0x01; + const uint8_t equal = CT::Mask<uint16_t>::is_equal(max_compresssions, current_compressions).if_set_return(1); // We compute the data length we need to achieve the number of compressions. // If there are no compressions, we just add 55/111 dummy bytes so that no // compression is performed. @@ -418,8 +418,8 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<uint8_t>& buffer, size_t (sending empty records, instead of 1/(n-1) splitting) */ - const uint16_t size_ok_mask = CT::is_lte<uint16_t>(static_cast<uint16_t>(tag_size() + pad_size), static_cast<uint16_t>(record_len)); - pad_size &= size_ok_mask; + const auto size_ok_mask = CT::Mask<uint16_t>::is_lte(tag_size() + pad_size, record_len); + pad_size = size_ok_mask.if_set_return(pad_size); CT::unpoison(record_contents, record_len); @@ -442,11 +442,11 @@ void TLS_CBC_HMAC_AEAD_Decryption::finish(secure_vector<uint8_t>& buffer, size_t const bool mac_ok = constant_time_compare(&record_contents[mac_offset], mac_buf.data(), tag_size()); - const uint16_t ok_mask = size_ok_mask & CT::expand_mask<uint16_t>(mac_ok) & CT::expand_mask<uint16_t>(pad_size); + const auto ok_mask = size_ok_mask & CT::Mask<uint16_t>::expand(mac_ok) & CT::Mask<uint16_t>::expand(pad_size); CT::unpoison(ok_mask); - if(ok_mask) + if(ok_mask.is_set()) { buffer.insert(buffer.end(), plaintext_block, plaintext_block + plaintext_length); } |