summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-29 23:18:21 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-30 00:42:35 +0100
commit1111dc8e5e9e78254c1a7a891d961713e1be9db0 (patch)
tree3490dad7d1c43d32a9c5d362d6f03bb17cb5408a /src/crypto
parenta09d04a02231964fa5a8f0113e9909cfb140fe4e (diff)
downloadfastd-1111dc8e5e9e78254c1a7a891d961713e1be9db0.tar
fastd-1111dc8e5e9e78254c1a7a891d961713e1be9db0.zip
Remove cipher and MAC contexts
Not a single implementation was using them...
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c17
-rw-r--r--src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c19
-rw-r--r--src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c18
-rw-r--r--src/crypto/cipher/ciphers.c.in23
-rw-r--r--src/crypto/cipher/null/memcpy/null_memcpy.c17
-rw-r--r--src/crypto/cipher/salsa20/nacl/salsa20_nacl.c17
-rw-r--r--src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c17
-rw-r--r--src/crypto/mac/ghash/builtin/ghash_builtin.c17
-rw-r--r--src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c15
-rw-r--r--src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h2
-rw-r--r--src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c2
-rw-r--r--src/crypto/mac/macs.c.in23
12 files changed, 28 insertions, 159 deletions
diff --git a/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c b/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c
index 783a9d1..f4756a3 100644
--- a/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c
+++ b/src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c
@@ -33,11 +33,7 @@ struct __attribute__((aligned(16))) fastd_cipher_state {
};
-static fastd_cipher_context_t* aes128_ctr_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static fastd_cipher_state_t* aes128_ctr_init_state(fastd_context_t *ctx, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key) {
+static fastd_cipher_state_t* aes128_ctr_init(fastd_context_t *ctx, const uint8_t *key) {
fastd_block128_t k;
memcpy(k.b, key, sizeof(fastd_block128_t));
@@ -56,24 +52,17 @@ static bool aes128_ctr_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_sta
return true;
}
-static void aes128_ctr_free_state(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
+static void aes128_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
free(state);
}
}
-static void aes128_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx UNUSED) {
-}
-
const fastd_cipher_t fastd_cipher_aes128_ctr_nacl = {
.available = fastd_true,
- .initialize = aes128_ctr_initialize,
- .init_state = aes128_ctr_init_state,
-
+ .init = aes128_ctr_init,
.crypt = aes128_ctr_crypt,
-
- .free_state = aes128_ctr_free_state,
.free = aes128_ctr_free,
};
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 6917333..b3c739c 100644
--- a/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
+++ b/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
@@ -28,16 +28,12 @@
#include <openssl/evp.h>
-struct __attribute__((aligned(16))) fastd_cipher_state {
+struct fastd_cipher_state {
EVP_CIPHER_CTX *aes;
};
-static fastd_cipher_context_t* aes128_ctr_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static fastd_cipher_state_t* aes128_ctr_init_state(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key) {
+static fastd_cipher_state_t* aes128_ctr_init(fastd_context_t *ctx UNUSED, const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
state->aes = EVP_CIPHER_CTX_new();
@@ -64,24 +60,17 @@ static bool aes128_ctr_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_sta
return true;
}
-static void aes128_ctr_free_state(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
+static void aes128_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
if (state) {
EVP_CIPHER_CTX_free(state->aes);
free(state);
}
}
-static void aes128_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx UNUSED) {
-}
-
const fastd_cipher_t fastd_cipher_aes128_ctr_openssl = {
.available = fastd_true,
- .initialize = aes128_ctr_initialize,
- .init_state = aes128_ctr_init_state,
-
+ .init = aes128_ctr_init,
.crypt = aes128_ctr_crypt,
-
- .free_state = aes128_ctr_free_state,
.free = aes128_ctr_free,
};
diff --git a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
index 70c4d35..3e82e38 100644
--- a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
+++ b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
@@ -182,11 +182,6 @@ struct fastd_cipher_state {
};
-static fastd_cipher_context_t* blowfish_ctr_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-
static inline void bf_ntohl(uint32_t *v, size_t len) {
size_t i;
for (i = 0; i < len; i++)
@@ -214,7 +209,7 @@ static inline uint32_t bf_f(const fastd_cipher_state_t *state, uint32_t x) {
BF_SWAP(L, R); \
})
-static fastd_cipher_state_t* blowfish_ctr_init_state(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key) {
+static fastd_cipher_state_t* blowfish_ctr_init(fastd_context_t *ctx UNUSED, const uint8_t *key) {
uint32_t key32[14];
memcpy(key32, key, 56);
bf_ntohl(key32, 14);
@@ -276,24 +271,17 @@ static bool blowfish_ctr_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_s
return true;
}
-static void blowfish_ctr_free_state(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
+static void blowfish_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
free(state);
}
}
-static void blowfish_ctr_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx UNUSED) {
-}
-
const fastd_cipher_t fastd_cipher_blowfish_ctr_builtin = {
.available = fastd_true,
- .initialize = blowfish_ctr_initialize,
- .init_state = blowfish_ctr_init_state,
-
+ .init = blowfish_ctr_init,
.crypt = blowfish_ctr_crypt,
-
- .free_state = blowfish_ctr_free_state,
.free = blowfish_ctr_free,
};
diff --git a/src/crypto/cipher/ciphers.c.in b/src/crypto/cipher/ciphers.c.in
index b3c6b1b..72ea3d2 100644
--- a/src/crypto/cipher/ciphers.c.in
+++ b/src/crypto/cipher/ciphers.c.in
@@ -89,24 +89,6 @@ bool fastd_cipher_config(const fastd_cipher_t **cipher_conf, const char *name, c
return false;
}
-void fastd_cipher_init(fastd_context_t *ctx) {
- ctx->cipher_contexts = calloc(array_size(ciphers), sizeof(fastd_cipher_context_t*));
-
- size_t i;
- for (i = 0; i < array_size(ciphers); i++) {
- if (ctx->conf->ciphers[i])
- ctx->cipher_contexts[i] = ctx->conf->ciphers[i]->initialize(ctx);
- }
-}
-
-void fastd_cipher_free(fastd_context_t *ctx) {
- size_t i;
- for (i = 0; i < array_size(ciphers); i++)
- ctx->conf->ciphers[i]->free(ctx, ctx->cipher_contexts[i]);
-
- free(ctx->cipher_contexts);
-}
-
const fastd_cipher_info_t* fastd_cipher_info_get_by_name(const char *name) {
size_t i, j;
for (i = 0; i < array_size(ciphers); i++) {
@@ -124,16 +106,13 @@ const fastd_cipher_info_t* fastd_cipher_info_get_by_name(const char *name) {
return NULL;
}
-const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_info_t **info, const fastd_cipher_context_t **cctx) {
+const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_info_t **info) {
size_t i;
for (i = 0; i < array_size(ciphers); i++) {
if (!strcmp(ciphers[i].name, name)) {
if (info)
*info = ciphers[i].info;
- if (cctx)
- *cctx = ctx->cipher_contexts[i];
-
return ctx->conf->ciphers[i];
}
}
diff --git a/src/crypto/cipher/null/memcpy/null_memcpy.c b/src/crypto/cipher/null/memcpy/null_memcpy.c
index 8c05b17..7f0b8b3 100644
--- a/src/crypto/cipher/null/memcpy/null_memcpy.c
+++ b/src/crypto/cipher/null/memcpy/null_memcpy.c
@@ -27,11 +27,7 @@
#include "../../../../crypto.h"
-static fastd_cipher_context_t* null_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static fastd_cipher_state_t* null_init_state(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key UNUSED) {
+static fastd_cipher_state_t* null_init(fastd_context_t *ctx UNUSED, const uint8_t *key UNUSED) {
return NULL;
}
@@ -40,20 +36,13 @@ static bool null_memcpy(fastd_context_t *ctx UNUSED, const fastd_cipher_state_t
return true;
}
-static void null_free_state(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state UNUSED) {
-}
-
-static void null_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx UNUSED) {
+static void null_free(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state UNUSED) {
}
const fastd_cipher_t fastd_cipher_null_memcpy = {
.available = fastd_true,
- .initialize = null_initialize,
- .init_state = null_init_state,
-
+ .init = null_init,
.crypt = null_memcpy,
-
- .free_state = null_free_state,
.free = null_free,
};
diff --git a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c
index 457e39c..ed14c3c 100644
--- a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c
+++ b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c
@@ -33,11 +33,7 @@ struct __attribute__((aligned(16))) fastd_cipher_state {
};
-static fastd_cipher_context_t* salsa20_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static fastd_cipher_state_t* salsa20_init_state(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key) {
+static fastd_cipher_state_t* salsa20_init(fastd_context_t *ctx UNUSED, const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
memcpy(state->key, key, crypto_stream_salsa20_KEYBYTES);
@@ -49,24 +45,17 @@ static bool salsa20_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_state_
return true;
}
-static void salsa20_free_state(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
+static void salsa20_free(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
free(state);
}
}
-static void salsa20_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx UNUSED) {
-}
-
const fastd_cipher_t fastd_cipher_salsa20_nacl = {
.available = fastd_true,
- .initialize = salsa20_initialize,
- .init_state = salsa20_init_state,
-
+ .init = salsa20_init,
.crypt = salsa20_crypt,
-
- .free_state = salsa20_free_state,
.free = salsa20_free,
};
diff --git a/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c b/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c
index 9619afe..79f01c4 100644
--- a/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c
+++ b/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c
@@ -33,11 +33,7 @@ struct __attribute__((aligned(16))) fastd_cipher_state {
};
-static fastd_cipher_context_t* salsa2012_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static fastd_cipher_state_t* salsa2012_init_state(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key) {
+static fastd_cipher_state_t* salsa2012_init(fastd_context_t *ctx UNUSED, const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
memcpy(state->key, key, crypto_stream_salsa2012_KEYBYTES);
@@ -49,24 +45,17 @@ static bool salsa2012_crypt(fastd_context_t *ctx UNUSED, const fastd_cipher_stat
return true;
}
-static void salsa2012_free_state(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
+static void salsa2012_free(fastd_context_t *ctx UNUSED, fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
free(state);
}
}
-static void salsa2012_free(fastd_context_t *ctx UNUSED, fastd_cipher_context_t *cctx UNUSED) {
-}
-
const fastd_cipher_t fastd_cipher_salsa2012_nacl = {
.available = fastd_true,
- .initialize = salsa2012_initialize,
- .init_state = salsa2012_init_state,
-
+ .init = salsa2012_init,
.crypt = salsa2012_crypt,
-
- .free_state = salsa2012_free_state,
.free = salsa2012_free,
};
diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c
index 511e844..341408f 100644
--- a/src/crypto/mac/ghash/builtin/ghash_builtin.c
+++ b/src/crypto/mac/ghash/builtin/ghash_builtin.c
@@ -61,11 +61,7 @@ static inline void mulH_a(fastd_block128_t *x, const fastd_mac_state_t *cstate)
}
-static fastd_mac_context_t* ghash_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static fastd_mac_state_t* ghash_init_state(fastd_context_t *ctx UNUSED, const fastd_mac_context_t *mctx UNUSED, const uint8_t *key) {
+static fastd_mac_state_t* ghash_init(fastd_context_t *ctx UNUSED, const uint8_t *key) {
fastd_mac_state_t *state = malloc(sizeof(fastd_mac_state_t));
fastd_block128_t Hbase[4];
@@ -121,24 +117,17 @@ static bool ghash_hash(fastd_context_t *ctx UNUSED, const fastd_mac_state_t *sta
return true;
}
-static void ghash_free_state(fastd_context_t *ctx UNUSED, fastd_mac_state_t *state) {
+static void ghash_free(fastd_context_t *ctx UNUSED, fastd_mac_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
free(state);
}
}
-static void ghash_free(fastd_context_t *ctx UNUSED, fastd_mac_context_t *mctx UNUSED) {
-}
-
const fastd_mac_t fastd_mac_ghash_builtin = {
.available = fastd_true,
- .initialize = ghash_initialize,
- .init_state = ghash_init_state,
-
+ .init = ghash_init,
.hash = ghash_hash,
-
- .free_state = ghash_free_state,
.free = ghash_free,
};
diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c
index 11073a5..8f1edb0 100644
--- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c
+++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.c
@@ -34,28 +34,17 @@ static bool ghash_available(void) {
return ((fastd_cpuid()&REQ) == REQ);
}
-static fastd_mac_context_t* ghash_initialize(fastd_context_t *ctx UNUSED) {
- return NULL;
-}
-
-static void ghash_free_state(fastd_context_t *ctx UNUSED, fastd_mac_state_t *state) {
+static void ghash_free(fastd_context_t *ctx UNUSED, fastd_mac_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
free(state);
}
}
-static void ghash_free(fastd_context_t *ctx UNUSED, fastd_mac_context_t *mctx UNUSED) {
-}
-
const fastd_mac_t fastd_mac_ghash_pclmulqdq = {
.available = ghash_available,
- .initialize = ghash_initialize,
- .init_state = fastd_ghash_pclmulqdq_init_state,
-
+ .init = fastd_ghash_pclmulqdq_init,
.hash = fastd_ghash_pclmulqdq_hash,
-
- .free_state = ghash_free_state,
.free = ghash_free,
};
diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h
index c2645f8..ccb1ecf 100644
--- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h
+++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq.h
@@ -32,5 +32,5 @@ struct fastd_mac_state {
};
-fastd_mac_state_t* fastd_ghash_pclmulqdq_init_state(fastd_context_t *ctx, const fastd_mac_context_t *mctx, const uint8_t *key);
+fastd_mac_state_t* fastd_ghash_pclmulqdq_init(fastd_context_t *ctx, const uint8_t *key);
bool fastd_ghash_pclmulqdq_hash(fastd_context_t *ctx, const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks);
diff --git a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c
index 375cf91..134d4ed 100644
--- a/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c
+++ b/src/crypto/mac/ghash/pclmulqdq/ghash_pclmulqdq_impl.c
@@ -58,7 +58,7 @@ static inline __m128i byteswap(__m128i v) {
}
-fastd_mac_state_t* fastd_ghash_pclmulqdq_init_state(fastd_context_t *ctx UNUSED, const fastd_mac_context_t *mctx UNUSED, const uint8_t *key) {
+fastd_mac_state_t* fastd_ghash_pclmulqdq_init(fastd_context_t *ctx UNUSED, const uint8_t *key) {
fastd_mac_state_t *state = malloc(sizeof(fastd_mac_state_t));
vecblock_t h;
diff --git a/src/crypto/mac/macs.c.in b/src/crypto/mac/macs.c.in
index 3587322..c70473b 100644
--- a/src/crypto/mac/macs.c.in
+++ b/src/crypto/mac/macs.c.in
@@ -89,24 +89,6 @@ bool fastd_mac_config(const fastd_mac_t **mac_conf, const char *name, const char
return false;
}
-void fastd_mac_init(fastd_context_t *ctx) {
- ctx->mac_contexts = calloc(array_size(macs), sizeof(fastd_mac_context_t*));
-
- size_t i;
- for (i = 0; i < array_size(macs); i++) {
- if (ctx->conf->macs[i])
- ctx->mac_contexts[i] = ctx->conf->macs[i]->initialize(ctx);
- }
-}
-
-void fastd_mac_free(fastd_context_t *ctx) {
- size_t i;
- for (i = 0; i < array_size(macs); i++)
- ctx->conf->macs[i]->free(ctx, ctx->mac_contexts[i]);
-
- free(ctx->mac_contexts);
-}
-
const fastd_mac_info_t* fastd_mac_info_get_by_name(const char *name) {
size_t i, j;
for (i = 0; i < array_size(macs); i++) {
@@ -124,16 +106,13 @@ const fastd_mac_info_t* fastd_mac_info_get_by_name(const char *name) {
return NULL;
}
-const fastd_mac_t* fastd_mac_get_by_name(fastd_context_t *ctx, const char *name, const fastd_mac_info_t **info, const fastd_mac_context_t **cctx) {
+const fastd_mac_t* fastd_mac_get_by_name(fastd_context_t *ctx, const char *name, const fastd_mac_info_t **info) {
size_t i;
for (i = 0; i < array_size(macs); i++) {
if (!strcmp(macs[i].name, name)) {
if (info)
*info = macs[i].info;
- if (cctx)
- *cctx = ctx->mac_contexts[i];
-
return ctx->conf->macs[i];
}
}