aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-15 13:17:04 +0000
committerlloyd <[email protected]>2010-10-15 13:17:04 +0000
commitf7b299b7ecc684754da2959366d8895ab621d430 (patch)
treef9f7bd0ef94dbb8945e977edf252e8fcb52c7781
parent01e0b5f9e0a6572e8eea8f7e226eb96e11c0fa58 (diff)
Use size_t in ssl
-rw-r--r--src/ssl/tls_client.cpp22
-rw-r--r--src/ssl/tls_client.h4
-rw-r--r--src/ssl/tls_connection.h6
-rw-r--r--src/ssl/tls_handshake_hash.h2
-rw-r--r--src/ssl/tls_policy.h2
-rw-r--r--src/ssl/tls_reader.h64
-rw-r--r--src/ssl/tls_server.cpp22
-rw-r--r--src/ssl/tls_server.h4
-rw-r--r--src/ssl/tls_session_key.cpp12
-rw-r--r--src/ssl/tls_session_key.h4
-rw-r--r--src/ssl/tls_suites.cpp4
-rw-r--r--src/ssl/tls_suites.h4
12 files changed, 75 insertions, 75 deletions
diff --git a/src/ssl/tls_client.cpp b/src/ssl/tls_client.cpp
index d6d62d59a..18f6981e3 100644
--- a/src/ssl/tls_client.cpp
+++ b/src/ssl/tls_client.cpp
@@ -117,8 +117,8 @@ TLS_Client::TLS_Client(const TLS_Policy& pol,
TLS_Client::~TLS_Client()
{
close();
- for(u32bit j = 0; j != keys.size(); j++)
- delete keys[j];
+ for(size_t i = 0; i != keys.size(); i++)
+ delete keys[i];
delete state;
}
@@ -179,7 +179,7 @@ std::vector<X509_Certificate> TLS_Client::peer_cert_chain() const
/**
* Write to a TLS connection
*/
-void TLS_Client::write(const byte buf[], u32bit length)
+void TLS_Client::write(const byte buf[], size_t length)
{
if(!active)
throw TLS_Exception(INTERNAL_ERROR,
@@ -191,7 +191,7 @@ void TLS_Client::write(const byte buf[], u32bit length)
/**
* Read from a TLS connection
*/
-u32bit TLS_Client::read(byte out[], u32bit length)
+size_t TLS_Client::read(byte out[], size_t length)
{
if(!active)
return 0;
@@ -205,7 +205,7 @@ u32bit TLS_Client::read(byte out[], u32bit length)
break;
}
- u32bit got = std::min<size_t>(read_buf.size(), length);
+ size_t got = std::min<size_t>(read_buf.size(), length);
read_buf.read(out, got);
return got;
}
@@ -253,12 +253,12 @@ void TLS_Client::state_machine()
byte rec_type = CONNECTION_CLOSED;
SecureVector<byte> record(1024);
- u32bit bytes_needed = reader.get_record(rec_type, record);
+ size_t bytes_needed = reader.get_record(rec_type, record);
while(bytes_needed)
{
- u32bit to_get = std::min<u32bit>(record.size(), bytes_needed);
- u32bit got = peer.read(&record[0], to_get);
+ size_t to_get = std::min<size_t>(record.size(), bytes_needed);
+ size_t got = peer.read(&record[0], to_get);
if(got == 0)
{
@@ -330,7 +330,7 @@ void TLS_Client::read_handshake(byte rec_type,
byte head[4] = { 0 };
state->queue.peek(head, 4);
- const u32bit length = make_u32bit(0, head[1], head[2], head[3]);
+ const size_t length = make_u32bit(0, head[1], head[2], head[3]);
if(state->queue.size() >= length + 4)
{
@@ -384,8 +384,8 @@ void TLS_Client::process_handshake_msg(Handshake_Type type,
{
state->hash.update(static_cast<byte>(type));
const u32bit record_length = contents.size();
- for(u32bit j = 0; j != 3; j++)
- state->hash.update(get_byte(j+1, record_length));
+ for(size_t i = 0; i != 3; i++)
+ state->hash.update(get_byte(i+1, record_length));
state->hash.update(contents);
}
diff --git a/src/ssl/tls_client.h b/src/ssl/tls_client.h
index e59218892..1b9c361fe 100644
--- a/src/ssl/tls_client.h
+++ b/src/ssl/tls_client.h
@@ -25,8 +25,8 @@ namespace Botan {
class BOTAN_DLL TLS_Client : public TLS_Connection
{
public:
- u32bit read(byte buf[], u32bit buf_len);
- void write(const byte buf[], u32bit buf_len);
+ size_t read(byte buf[], size_t buf_len);
+ void write(const byte buf[], size_t buf_len);
std::vector<X509_Certificate> peer_cert_chain() const;
diff --git a/src/ssl/tls_connection.h b/src/ssl/tls_connection.h
index a6de659c4..bbefa2114 100644
--- a/src/ssl/tls_connection.h
+++ b/src/ssl/tls_connection.h
@@ -19,9 +19,9 @@ namespace Botan {
class BOTAN_DLL TLS_Connection
{
public:
- virtual u32bit read(byte[], u32bit) = 0;
- virtual void write(const byte[], u32bit) = 0;
- u32bit read(byte& in) { return read(&in, 1); }
+ virtual size_t read(byte[], size_t) = 0;
+ virtual void write(const byte[], size_t) = 0;
+ size_t read(byte& in) { return read(&in, 1); }
void write(byte out) { write(&out, 1); }
virtual std::vector<X509_Certificate> peer_cert_chain() const = 0;
diff --git a/src/ssl/tls_handshake_hash.h b/src/ssl/tls_handshake_hash.h
index 4c145c6c6..ceaa55584 100644
--- a/src/ssl/tls_handshake_hash.h
+++ b/src/ssl/tls_handshake_hash.h
@@ -20,7 +20,7 @@ using namespace Botan;
class BOTAN_DLL HandshakeHash
{
public:
- void update(const byte in[], u32bit length)
+ void update(const byte in[], size_t length)
{ data += std::make_pair(in, length); }
void update(const MemoryRegion<byte>& in)
diff --git a/src/ssl/tls_policy.h b/src/ssl/tls_policy.h
index 022eed4ec..c5944f0f7 100644
--- a/src/ssl/tls_policy.h
+++ b/src/ssl/tls_policy.h
@@ -37,7 +37,7 @@ class BOTAN_DLL TLS_Policy
virtual bool require_client_auth() const { return false; }
virtual DL_Group dh_group() const;
- virtual u32bit rsa_export_keysize() const { return 512; }
+ virtual size_t rsa_export_keysize() const { return 512; }
virtual Version_Code min_version() const { return SSL_V3; }
virtual Version_Code pref_version() const { return TLS_V11; }
diff --git a/src/ssl/tls_reader.h b/src/ssl/tls_reader.h
index 733e9bdc9..3a45235b5 100644
--- a/src/ssl/tls_reader.h
+++ b/src/ssl/tls_reader.h
@@ -22,7 +22,7 @@ class TLS_Data_Reader
TLS_Data_Reader(const MemoryRegion<byte>& buf_in) :
buf(buf_in), offset(0) {}
- u32bit remaining_bytes() const
+ size_t remaining_bytes() const
{
return buf.size() - offset;
}
@@ -32,7 +32,7 @@ class TLS_Data_Reader
return (remaining_bytes() > 0);
}
- void discard_next(u32bit bytes)
+ void discard_next(size_t bytes)
{
assert_at_least(bytes);
offset += bytes;
@@ -55,13 +55,13 @@ class TLS_Data_Reader
}
template<typename T, typename Container>
- Container get_elem(u32bit num_elems)
+ Container get_elem(size_t num_elems)
{
assert_at_least(num_elems * sizeof(T));
Container result(num_elems);
- for(u32bit i = 0; i != num_elems; ++i)
+ for(size_t i = 0; i != num_elems; ++i)
result[i] = load_be<T>(&buf[offset], i);
offset += num_elems * sizeof(T);
@@ -70,35 +70,35 @@ class TLS_Data_Reader
}
template<typename T>
- SecureVector<T> get_range(u32bit len_bytes,
- u32bit min_elems,
- u32bit max_elems)
+ SecureVector<T> get_range(size_t len_bytes,
+ size_t min_elems,
+ size_t max_elems)
{
- const u32bit num_elems =
+ const size_t num_elems =
get_num_elems(len_bytes, sizeof(T), min_elems, max_elems);
return get_elem<T, SecureVector<T> >(num_elems);
}
template<typename T>
- std::vector<T> get_range_vector(u32bit len_bytes,
- u32bit min_elems,
- u32bit max_elems)
+ std::vector<T> get_range_vector(size_t len_bytes,
+ size_t min_elems,
+ size_t max_elems)
{
- const u32bit num_elems =
+ const size_t num_elems =
get_num_elems(len_bytes, sizeof(T), min_elems, max_elems);
return get_elem<T, std::vector<T> >(num_elems);
}
template<typename T>
- SecureVector<T> get_fixed(u32bit size)
+ SecureVector<T> get_fixed(size_t size)
{
return get_elem<T, SecureVector<T> >(size);
}
private:
- u32bit get_length_field(u32bit len_bytes)
+ size_t get_length_field(size_t len_bytes)
{
assert_at_least(len_bytes);
@@ -110,17 +110,17 @@ class TLS_Data_Reader
throw Decoding_Error("TLS_Data_Reader: Bad length size");
}
- u32bit get_num_elems(u32bit len_bytes,
- u32bit T_size,
- u32bit min_elems,
- u32bit max_elems)
+ size_t get_num_elems(size_t len_bytes,
+ size_t T_size,
+ size_t min_elems,
+ size_t max_elems)
{
- const u32bit byte_length = get_length_field(len_bytes);
+ const size_t byte_length = get_length_field(len_bytes);
if(byte_length % T_size != 0)
throw Decoding_Error("TLS_Data_Reader: Size isn't multiple of T");
- const u32bit num_elems = byte_length / T_size;
+ const size_t num_elems = byte_length / T_size;
if(num_elems < min_elems || num_elems > max_elems)
throw Decoding_Error("TLS_Data_Reader: Range outside paramaters");
@@ -128,14 +128,14 @@ class TLS_Data_Reader
return num_elems;
}
- void assert_at_least(u32bit n) const
+ void assert_at_least(size_t n) const
{
if(buf.size() - offset < n)
throw Decoding_Error("TLS_Data_Reader: Corrupt packet");
}
const MemoryRegion<byte>& buf;
- u32bit offset;
+ size_t offset;
};
/**
@@ -144,11 +144,11 @@ class TLS_Data_Reader
template<typename T>
void append_tls_length_value(MemoryRegion<byte>& buf,
const T* vals,
- u32bit vals_size,
- u32bit tag_size)
+ size_t vals_size,
+ size_t tag_size)
{
- const u32bit T_size = sizeof(T);
- const u32bit val_bytes = T_size * vals_size;
+ const size_t T_size = sizeof(T);
+ const size_t val_bytes = T_size * vals_size;
if(tag_size != 1 && tag_size != 2)
throw std::invalid_argument("append_tls_length_value: invalid tag size");
@@ -157,18 +157,18 @@ void append_tls_length_value(MemoryRegion<byte>& buf,
(tag_size == 2 && val_bytes > 65535))
throw std::invalid_argument("append_tls_length_value: value too large");
- for(u32bit i = 0; i != tag_size; ++i)
- buf.push_back(get_byte(4-tag_size+i, val_bytes));
+ for(size_t i = 0; i != tag_size; ++i)
+ buf.push_back(get_byte(sizeof(val_bytes)-tag_size+i, val_bytes));
- for(u32bit i = 0; i != vals_size; ++i)
- for(u32bit j = 0; j != T_size; ++j)
+ for(size_t i = 0; i != vals_size; ++i)
+ for(size_t j = 0; j != T_size; ++j)
buf.push_back(get_byte(j, vals[i]));
}
template<typename T>
void append_tls_length_value(MemoryRegion<byte>& buf,
const MemoryRegion<T>& vals,
- u32bit tag_size)
+ size_t tag_size)
{
append_tls_length_value(buf, &vals[0], vals.size(), tag_size);
}
@@ -176,7 +176,7 @@ void append_tls_length_value(MemoryRegion<byte>& buf,
template<typename T>
void append_tls_length_value(MemoryRegion<byte>& buf,
const std::vector<T>& vals,
- u32bit tag_size)
+ size_t tag_size)
{
append_tls_length_value(buf, &vals[0], vals.size(), tag_size);
}
diff --git a/src/ssl/tls_server.cpp b/src/ssl/tls_server.cpp
index 1503912d0..8a5cefa02 100644
--- a/src/ssl/tls_server.cpp
+++ b/src/ssl/tls_server.cpp
@@ -141,7 +141,7 @@ std::vector<X509_Certificate> TLS_Server::peer_cert_chain() const
/**
* Write to a TLS connection
*/
-void TLS_Server::write(const byte buf[], u32bit length)
+void TLS_Server::write(const byte buf[], size_t length)
{
if(!active)
throw Internal_Error("TLS_Server::write called while closed");
@@ -152,7 +152,7 @@ void TLS_Server::write(const byte buf[], u32bit length)
/**
* Read from a TLS connection
*/
-u32bit TLS_Server::read(byte out[], u32bit length)
+size_t TLS_Server::read(byte out[], size_t length)
{
if(!active)
throw Internal_Error("TLS_Server::read called while closed");
@@ -166,7 +166,7 @@ u32bit TLS_Server::read(byte out[], u32bit length)
break;
}
- u32bit got = std::min<size_t>(read_buf.size(), length);
+ size_t got = std::min<size_t>(read_buf.size(), length);
read_buf.read(out, got);
return got;
}
@@ -213,12 +213,12 @@ void TLS_Server::state_machine()
byte rec_type = CONNECTION_CLOSED;
SecureVector<byte> record(1024);
- u32bit bytes_needed = reader.get_record(rec_type, record);
+ size_t bytes_needed = reader.get_record(rec_type, record);
while(bytes_needed)
{
- u32bit to_get = std::min<u32bit>(record.size(), bytes_needed);
- u32bit got = peer.read(&record[0], to_get);
+ size_t to_get = std::min<size_t>(record.size(), bytes_needed);
+ size_t got = peer.read(&record[0], to_get);
if(got == 0)
{
@@ -289,7 +289,7 @@ void TLS_Server::read_handshake(byte rec_type,
byte head[4] = { 0 };
state->queue.peek(head, 4);
- const u32bit length = make_u32bit(0, head[1], head[2], head[3]);
+ const size_t length = make_u32bit(0, head[1], head[2], head[3]);
if(state->queue.size() >= length + 4)
{
@@ -338,8 +338,8 @@ void TLS_Server::process_handshake_msg(Handshake_Type type,
{
state->hash.update(static_cast<byte>(type));
u32bit record_length = contents.size();
- for(u32bit j = 0; j != 3; j++)
- state->hash.update(get_byte(j+1, record_length));
+ for(size_t i = 0; i != 3; i++)
+ state->hash.update(get_byte(i+1, record_length));
}
state->hash.update(contents);
@@ -450,8 +450,8 @@ void TLS_Server::process_handshake_msg(Handshake_Type type,
state->hash.update(static_cast<byte>(type));
u32bit record_length = contents.size();
- for(u32bit j = 0; j != 3; j++)
- state->hash.update(get_byte(j+1, record_length));
+ for(size_t i = 0; i != 3; i++)
+ state->hash.update(get_byte(i+1, record_length));
state->hash.update(contents);
writer.send(CHANGE_CIPHER_SPEC, 1);
diff --git a/src/ssl/tls_server.h b/src/ssl/tls_server.h
index fc6adc9ce..09a1ef40b 100644
--- a/src/ssl/tls_server.h
+++ b/src/ssl/tls_server.h
@@ -23,8 +23,8 @@ namespace Botan {
class BOTAN_DLL TLS_Server : public TLS_Connection
{
public:
- u32bit read(byte buf[], u32bit buf_len);
- void write(const byte buf[], u32bit buf_len);
+ size_t read(byte buf[], size_t buf_len);
+ void write(const byte buf[], size_t buf_len);
std::vector<X509_Certificate> peer_cert_chain() const;
diff --git a/src/ssl/tls_session_key.cpp b/src/ssl/tls_session_key.cpp
index 341ce7bb0..7c75d1758 100644
--- a/src/ssl/tls_session_key.cpp
+++ b/src/ssl/tls_session_key.cpp
@@ -71,7 +71,7 @@ SecureVector<byte> SessionKeys::master_secret() const
/**
* Generate SSLv3 session keys
*/
-SymmetricKey SessionKeys::ssl3_keygen(u32bit prf_gen,
+SymmetricKey SessionKeys::ssl3_keygen(size_t prf_gen,
const MemoryRegion<byte>& pre_master,
const MemoryRegion<byte>& client_random,
const MemoryRegion<byte>& server_random)
@@ -94,7 +94,7 @@ SymmetricKey SessionKeys::ssl3_keygen(u32bit prf_gen,
/**
* Generate TLS 1.0 session keys
*/
-SymmetricKey SessionKeys::tls1_keygen(u32bit prf_gen,
+SymmetricKey SessionKeys::tls1_keygen(size_t prf_gen,
const MemoryRegion<byte>& pre_master,
const MemoryRegion<byte>& client_random,
const MemoryRegion<byte>& server_random)
@@ -134,14 +134,14 @@ SessionKeys::SessionKeys(const CipherSuite& suite, Version_Code version,
if(version != SSL_V3 && version != TLS_V10 && version != TLS_V11)
throw Invalid_Argument("SessionKeys: Unknown version code");
- const u32bit mac_keylen = output_length_of(suite.mac_algo());
- u32bit cipher_keylen = suite.cipher_keylen();
+ const size_t mac_keylen = output_length_of(suite.mac_algo());
+ const size_t cipher_keylen = suite.cipher_keylen();
- u32bit cipher_ivlen = 0;
+ size_t cipher_ivlen = 0;
if(have_block_cipher(suite.cipher_algo()))
cipher_ivlen = block_size_of(suite.cipher_algo());
- const u32bit prf_gen = 2 * (mac_keylen + cipher_keylen + cipher_ivlen);
+ const size_t prf_gen = 2 * (mac_keylen + cipher_keylen + cipher_ivlen);
SymmetricKey keyblock = (version == SSL_V3) ?
ssl3_keygen(prf_gen, pre_master_secret, c_random, s_random) :
diff --git a/src/ssl/tls_session_key.h b/src/ssl/tls_session_key.h
index 98c1b92ff..51397984b 100644
--- a/src/ssl/tls_session_key.h
+++ b/src/ssl/tls_session_key.h
@@ -35,10 +35,10 @@ class BOTAN_DLL SessionKeys
SessionKeys(const CipherSuite&, Version_Code, const MemoryRegion<byte>&,
const MemoryRegion<byte>&, const MemoryRegion<byte>&);
private:
- SymmetricKey ssl3_keygen(u32bit, const MemoryRegion<byte>&,
+ SymmetricKey ssl3_keygen(size_t, const MemoryRegion<byte>&,
const MemoryRegion<byte>&,
const MemoryRegion<byte>&);
- SymmetricKey tls1_keygen(u32bit, const MemoryRegion<byte>&,
+ SymmetricKey tls1_keygen(size_t, const MemoryRegion<byte>&,
const MemoryRegion<byte>&,
const MemoryRegion<byte>&);
diff --git a/src/ssl/tls_suites.cpp b/src/ssl/tls_suites.cpp
index 18c39edcd..07cbec608 100644
--- a/src/ssl/tls_suites.cpp
+++ b/src/ssl/tls_suites.cpp
@@ -212,7 +212,7 @@ TLS_Ciphersuite_Algos CipherSuite::lookup_ciphersuite(u16bit suite)
namespace {
-std::pair<std::string, u32bit> cipher_code_to_name(TLS_Ciphersuite_Algos algo)
+std::pair<std::string, size_t> cipher_code_to_name(TLS_Ciphersuite_Algos algo)
{
if((algo & TLS_ALGO_CIPHER_MASK) == TLS_ALGO_CIPHER_RC4_128)
return std::make_pair("ARC4", 16);
@@ -270,7 +270,7 @@ CipherSuite::CipherSuite(u16bit suite_code)
kex_algo = TLS_Ciphersuite_Algos(algos & TLS_ALGO_KEYEXCH_MASK);
- std::pair<std::string, u32bit> cipher_info = cipher_code_to_name(algos);
+ std::pair<std::string, size_t> cipher_info = cipher_code_to_name(algos);
cipher = cipher_info.first;
cipher_key_length = cipher_info.second;
diff --git a/src/ssl/tls_suites.h b/src/ssl/tls_suites.h
index 612c148e6..8d6db0e8b 100644
--- a/src/ssl/tls_suites.h
+++ b/src/ssl/tls_suites.h
@@ -25,7 +25,7 @@ class BOTAN_DLL CipherSuite
std::string cipher_algo() const { return cipher; }
std::string mac_algo() const { return mac; }
- u32bit cipher_keylen() const { return cipher_key_length; }
+ size_t cipher_keylen() const { return cipher_key_length; }
TLS_Ciphersuite_Algos kex_type() const { return kex_algo; }
TLS_Ciphersuite_Algos sig_type() const { return sig_algo; }
@@ -34,7 +34,7 @@ class BOTAN_DLL CipherSuite
private:
TLS_Ciphersuite_Algos kex_algo, sig_algo;
std::string cipher, mac;
- u32bit cipher_key_length;
+ size_t cipher_key_length;
};
}