summaryrefslogtreecommitdiffstats
path: root/src/crypto/cipher
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 05:33:12 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 05:35:49 +0100
commit61349d3d273aa23935b0c413c5885005db2669db (patch)
tree9cbc05acb31476d45b48d4a51e9edca19328b8e8 /src/crypto/cipher
parentc13fe36e4c0730037ae75d51f7f052d916486aac (diff)
downloadfastd-61349d3d273aa23935b0c413c5885005db2669db.tar
fastd-61349d3d273aa23935b0c413c5885005db2669db.zip
Compile with -std=c99 and restructure some code to ensure there is no invalid aliasing (hopefully)
Diffstat (limited to 'src/crypto/cipher')
-rw-r--r--src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c6
-rw-r--r--src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c33
2 files changed, 26 insertions, 13 deletions
diff --git a/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c b/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
index 37ed95c..6917333 100644
--- a/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
+++ b/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
@@ -41,7 +41,7 @@ static fastd_cipher_state_t* aes128_ctr_init_state(fastd_context_t *ctx UNUSED,
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
state->aes = EVP_CIPHER_CTX_new();
- EVP_EncryptInit(state->aes, EVP_aes_128_ctr(), (const void*)key, NULL);
+ EVP_EncryptInit(state->aes, EVP_aes_128_ctr(), (const unsigned char*)key, NULL);
return state;
}
@@ -52,10 +52,10 @@ static bool aes128_ctr_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_sta
if (!EVP_EncryptInit(state->aes, NULL, NULL, iv))
return false;
- if (!EVP_EncryptUpdate(state->aes, (void*)out, &clen, (const void*)in, len))
+ if (!EVP_EncryptUpdate(state->aes, (unsigned char*)out, &clen, (const unsigned char*)in, len))
return false;
- if (!EVP_EncryptFinal(state->aes, ((void*)out) + clen, &clen2))
+ if (!EVP_EncryptFinal(state->aes, ((unsigned char*)out) + clen, &clen2))
return false;
if ((size_t)(clen+clen2) != len)
diff --git a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
index 8c18203..70c4d35 100644
--- a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
+++ b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
@@ -26,6 +26,13 @@
#include "../../../../crypto.h"
+
+typedef union bf_block {
+ fastd_block128_t b;
+ uint32_t u32[4];
+} bf_block_t;
+
+
static const uint32_t Sdefault[4][256] = {
{
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
@@ -240,24 +247,30 @@ static fastd_cipher_state_t* blowfish_ctr_init_state(fastd_context_t *ctx UNUSED
}
static bool blowfish_ctr_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv) {
+ register bf_block_t block;
register uint32_t ctr[2];
- register uint32_t block[2];
-
- uint32_t *out4 = (uint32_t*)out;
- uint32_t *in4 = (uint32_t*)in;
ctr[0] = (iv[0] << 24)|(iv[1] << 16)|(iv[2] << 8)|(iv[3]);
ctr[1] = (iv[4] << 24)|(iv[5] << 16)|(iv[6] << 8)|(iv[7]);
size_t i;
- for(i = 0; i < len; i += 8) {
- block[0] = ctr[0];
- block[1] = ctr[1];
- BF_ENCRYPT(state, block[0], block[1]);
+ for(i = 0; i < len; i += 16) {
+ block.u32[0] = ctr[0];
+ block.u32[1] = ctr[1];
+ BF_ENCRYPT(state, block.u32[0], block.u32[1]);
+ ctr[1]++;
- *(out4++) = *(in4++) ^ htonl(block[0]);
- *(out4++) = *(in4++) ^ htonl(block[1]);
+ block.u32[2] = ctr[0];
+ block.u32[3] = ctr[1];
+ BF_ENCRYPT(state, block.u32[2], block.u32[3]);
ctr[1]++;
+
+ block.u32[0] = htonl(block.u32[0]);
+ block.u32[1] = htonl(block.u32[1]);
+ block.u32[2] = htonl(block.u32[2]);
+ block.u32[3] = htonl(block.u32[3]);
+
+ xor(out++, *(in++), block.b);
}
return true;