aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/axolotl.cpp7
-rw-r--r--src/crypto.cpp13
-rw-r--r--src/ratchet.cpp6
-rw-r--r--src/session.cpp2
4 files changed, 20 insertions, 8 deletions
diff --git a/src/axolotl.cpp b/src/axolotl.cpp
index e11e2b0..e835c9b 100644
--- a/src/axolotl.cpp
+++ b/src/axolotl.cpp
@@ -67,7 +67,6 @@ std::size_t enc_output(
std::size_t length = ciphertext_length + PICKLE_CIPHER.mac_length();
std::size_t base64_length = axolotl::encode_base64_length(length);
std::uint8_t * raw_output = output + base64_length - length;
- length -= PICKLE_CIPHER.mac_length();
PICKLE_CIPHER.encrypt(
key, key_length,
raw_output, raw_length,
@@ -395,6 +394,12 @@ size_t axolotl_account_one_time_keys(
}
+size_t axolotl_create_outbound_session_random_length(
+ AxolotlSession * session
+) {
+ return from_c(session)->new_outbound_session_random_length();
+}
+
size_t axolotl_create_outbound_session(
AxolotlSession * session,
AxolotlAccount * account,
diff --git a/src/crypto.cpp b/src/crypto.cpp
index 24a8136..b287919 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -237,15 +237,18 @@ std::size_t axolotl::aes_decrypt_cbc(
) {
std::uint32_t key_schedule[60];
::aes_key_setup(key.key, key_schedule, 256);
+ std::uint8_t block1[AES_BLOCK_LENGTH];
+ std::uint8_t block2[AES_BLOCK_LENGTH];
+ std::memcpy(block1, iv.iv, AES_BLOCK_LENGTH);
for (std::size_t i = 0; i < input_length; i += AES_BLOCK_LENGTH) {
+ std::memcpy(block2, &input[i], AES_BLOCK_LENGTH);
::aes_decrypt(&input[i], &output[i], key_schedule, 256);
- if (i == 0) {
- xor_block<AES_BLOCK_LENGTH>(&output[i], iv.iv);
- } else {
- xor_block<AES_BLOCK_LENGTH>(&output[i], &input[i - AES_BLOCK_LENGTH]);
- }
+ xor_block<AES_BLOCK_LENGTH>(&output[i], block1);
+ std::memcpy(block1, block2, AES_BLOCK_LENGTH);
}
axolotl::unset(key_schedule);
+ axolotl::unset(block1);
+ axolotl::unset(block2);
std::size_t padding = output[input_length - 1];
return (padding > input_length) ? std::size_t(-1) : (input_length - padding);
}
diff --git a/src/ratchet.cpp b/src/ratchet.cpp
index 24f0ac2..37d2d4e 100644
--- a/src/ratchet.cpp
+++ b/src/ratchet.cpp
@@ -141,12 +141,12 @@ std::size_t verify_mac_and_decrypt_for_new_chain(
/* They shouldn't move to a new chain until we've sent them a message
* acknowledging the last one */
if (session.sender_chain.empty()) {
- return false;
+ return std::size_t(-1);
}
/* Limit the number of hashes we're prepared to compute */
if (reader.counter > MAX_MESSAGE_GAP) {
- return false;
+ return std::size_t(-1);
}
std::memcpy(
new_chain.ratchet_key.public_key, reader.ratchet_key, KEY_LENGTH
@@ -191,6 +191,7 @@ void axolotl::Ratchet::initialise_as_bob(
derived_secrets, sizeof(derived_secrets)
);
receiver_chains.insert();
+ receiver_chains[0].chain_key.index = 0;
std::memcpy(root_key, derived_secrets, 32);
std::memcpy(receiver_chains[0].chain_key.key, derived_secrets + 32, 32);
receiver_chains[0].ratchet_key = their_ratchet_key;
@@ -210,6 +211,7 @@ void axolotl::Ratchet::initialise_as_alice(
derived_secrets, sizeof(derived_secrets)
);
sender_chain.insert();
+ sender_chain[0].chain_key.index = 0;
std::memcpy(root_key, derived_secrets, 32);
std::memcpy(sender_chain[0].chain_key.key, derived_secrets + 32, 32);
sender_chain[0].ratchet_key = our_ratchet_key;
diff --git a/src/session.cpp b/src/session.cpp
index 0582d56..6d93326 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -332,6 +332,8 @@ std::size_t axolotl::Session::decrypt(
if (result == std::size_t(-1)) {
last_error = ratchet.last_error;
ratchet.last_error = axolotl::ErrorCode::SUCCESS;
+ } else {
+ received_message = true;
}
return result;
}