aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-09-02 15:35:04 +0100
committerRichard van der Hoff <richard@matrix.org>2016-09-05 10:40:39 +0100
commit69f269ffaf88515f6d5c0b34178bf0096cf5773b (patch)
tree140b55571972ddf76c28515ec767ac01a5e21712 /src
parentf0acf6582f88ca66b3fabf7d622278da51a94c10 (diff)
Convert AES functions to plain C
Diffstat (limited to 'src')
-rw-r--r--src/cipher.cpp16
-rw-r--r--src/crypto.cpp24
-rw-r--r--src/session.cpp2
-rw-r--r--src/utility.cpp2
4 files changed, 22 insertions, 22 deletions
diff --git a/src/cipher.cpp b/src/cipher.cpp
index 8e3d7a5..6b53690 100644
--- a/src/cipher.cpp
+++ b/src/cipher.cpp
@@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "olm/cipher.h"
-#include "olm/crypto.hh"
+#include "olm/crypto.h"
#include "olm/memory.hh"
#include <cstring>
@@ -22,9 +22,9 @@ const std::size_t HMAC_KEY_LENGTH = 32;
namespace {
struct DerivedKeys {
- olm::Aes256Key aes_key;
+ _olm_aes256_key aes_key;
std::uint8_t mac_key[HMAC_KEY_LENGTH];
- olm::Aes256Iv aes_iv;
+ _olm_aes256_iv aes_iv;
};
@@ -58,7 +58,7 @@ size_t aes_sha_256_cipher_mac_length(const struct _olm_cipher *cipher) {
size_t aes_sha_256_cipher_encrypt_ciphertext_length(
const struct _olm_cipher *cipher, size_t plaintext_length
) {
- return olm::aes_encrypt_cbc_length(plaintext_length);
+ return _olm_crypto_aes_encrypt_cbc_length(plaintext_length);
}
size_t aes_sha_256_cipher_encrypt(
@@ -80,8 +80,8 @@ size_t aes_sha_256_cipher_encrypt(
derive_keys(c->kdf_info, c->kdf_info_length, key, key_length, keys);
- olm::aes_encrypt_cbc(
- keys.aes_key, keys.aes_iv, plaintext, plaintext_length, ciphertext
+ _olm_crypto_aes_encrypt_cbc(
+ &keys.aes_key, &keys.aes_iv, plaintext, plaintext_length, ciphertext
);
_olm_crypto_hmac_sha256(
@@ -126,8 +126,8 @@ size_t aes_sha_256_cipher_decrypt(
return std::size_t(-1);
}
- std::size_t plaintext_length = olm::aes_decrypt_cbc(
- keys.aes_key, keys.aes_iv, ciphertext, ciphertext_length, plaintext
+ std::size_t plaintext_length = _olm_crypto_aes_decrypt_cbc(
+ &keys.aes_key, &keys.aes_iv, ciphertext, ciphertext_length, plaintext
);
olm::unset(keys);
diff --git a/src/crypto.cpp b/src/crypto.cpp
index 89d9d72..5095c79 100644
--- a/src/crypto.cpp
+++ b/src/crypto.cpp
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "olm/crypto.hh"
+#include "olm/crypto.h"
#include "olm/memory.hh"
#include <cstring>
@@ -163,23 +163,23 @@ int _olm_crypto_ed25519_verify(
}
-std::size_t olm::aes_encrypt_cbc_length(
+std::size_t _olm_crypto_aes_encrypt_cbc_length(
std::size_t input_length
) {
return input_length + AES_BLOCK_LENGTH - input_length % AES_BLOCK_LENGTH;
}
-void olm::aes_encrypt_cbc(
- olm::Aes256Key const & key,
- olm::Aes256Iv const & iv,
+void _olm_crypto_aes_encrypt_cbc(
+ _olm_aes256_key const *key,
+ _olm_aes256_iv const *iv,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
std::uint32_t key_schedule[AES_KEY_SCHEDULE_LENGTH];
- ::aes_key_setup(key.key, key_schedule, AES_KEY_BITS);
+ ::aes_key_setup(key->key, key_schedule, AES_KEY_BITS);
std::uint8_t input_block[AES_BLOCK_LENGTH];
- std::memcpy(input_block, iv.iv, AES_BLOCK_LENGTH);
+ std::memcpy(input_block, iv->iv, AES_BLOCK_LENGTH);
while (input_length >= AES_BLOCK_LENGTH) {
xor_block<AES_BLOCK_LENGTH>(input_block, input);
::aes_encrypt(input_block, output, key_schedule, AES_KEY_BITS);
@@ -201,17 +201,17 @@ void olm::aes_encrypt_cbc(
}
-std::size_t olm::aes_decrypt_cbc(
- olm::Aes256Key const & key,
- olm::Aes256Iv const & iv,
+std::size_t _olm_crypto_aes_decrypt_cbc(
+ _olm_aes256_key const *key,
+ _olm_aes256_iv const *iv,
std::uint8_t const * input, std::size_t input_length,
std::uint8_t * output
) {
std::uint32_t key_schedule[AES_KEY_SCHEDULE_LENGTH];
- ::aes_key_setup(key.key, key_schedule, AES_KEY_BITS);
+ ::aes_key_setup(key->key, key_schedule, AES_KEY_BITS);
std::uint8_t block1[AES_BLOCK_LENGTH];
std::uint8_t block2[AES_BLOCK_LENGTH];
- std::memcpy(block1, iv.iv, 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, AES_KEY_BITS);
diff --git a/src/session.cpp b/src/session.cpp
index 72e2be8..f1bc5a7 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -14,7 +14,7 @@
*/
#include "olm/session.hh"
#include "olm/cipher.h"
-#include "olm/crypto.hh"
+#include "olm/crypto.h"
#include "olm/account.hh"
#include "olm/memory.hh"
#include "olm/message.hh"
diff --git a/src/utility.cpp b/src/utility.cpp
index 43d8e16..e9688de 100644
--- a/src/utility.cpp
+++ b/src/utility.cpp
@@ -14,7 +14,7 @@
*/
#include "olm/utility.hh"
-#include "olm/crypto.hh"
+#include "olm/crypto.h"
olm::Utility::Utility(