summaryrefslogtreecommitdiffstats
path: root/src/crypto
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-11-05 16:29:57 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-11-05 16:29:57 +0100
commitcb42b5b1fa81969e6d4056e0220374e8ded09651 (patch)
tree72b85d9cc8a551149467f770ec1752f540e3d3eb /src/crypto
parent4f9b5d66bc6b198dcf6e119fa05e891fce4e355f (diff)
downloadfastd-cb42b5b1fa81969e6d4056e0220374e8ded09651.tar
fastd-cb42b5b1fa81969e6d4056e0220374e8ded09651.zip
Generalize cipher/MAC key/IV lengths
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c16
-rw-r--r--src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c14
-rw-r--r--src/crypto/cipher/ciphers.c.in2
-rw-r--r--src/crypto/mac/ghash/builtin/ghash_builtin.c7
-rw-r--r--src/crypto/mac/macs.c.in2
5 files changed, 36 insertions, 5 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 f63e46f..60c8743 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
@@ -37,6 +37,10 @@ static fastd_cipher_context_t* aes128_ctr_initialize(fastd_context_t *ctx UNUSED
return NULL;
}
+static size_t aes128_ctr_key_length(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED) {
+ return 16;
+}
+
static fastd_cipher_state_t* aes128_ctr_init_state(fastd_context_t *ctx, const fastd_cipher_context_t *cctx UNUSED, const uint8_t *key) {
fastd_block128_t k;
memcpy(k.b, key, sizeof(fastd_block128_t));
@@ -49,8 +53,12 @@ static fastd_cipher_state_t* aes128_ctr_init_state(fastd_context_t *ctx, const f
return state;
}
-static bool aes128_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 fastd_block128_t *iv) {
- crypto_stream_aes128ctr_xor_afternm(out->b, in->b, len, iv->b, state->d.data);
+static size_t aes128_ctr_iv_length(fastd_context_t *ctx UNUSED, const fastd_cipher_state_t *state UNUSED) {
+ return 16;
+}
+
+static bool aes128_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) {
+ crypto_stream_aes128ctr_xor_afternm(out->b, in->b, len, iv, state->d.data);
return true;
}
@@ -68,7 +76,11 @@ const fastd_cipher_t fastd_cipher_aes128_ctr_nacl = {
.name = "nacl",
.initialize = aes128_ctr_initialize,
+
+ .key_length = aes128_ctr_key_length,
.init_state = aes128_ctr_init_state,
+
+ .iv_length = aes128_ctr_iv_length,
.crypt = aes128_ctr_crypt,
.free_state = aes128_ctr_free_state,
diff --git a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
index 04ac1f0..1d29a4c 100644
--- a/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
+++ b/src/crypto/cipher/blowfish_ctr/builtin/blowfish_ctr.c
@@ -223,6 +223,10 @@ static fastd_cipher_context_t* blowfish_ctr_initialize(fastd_context_t *ctx UNUS
return NULL;
}
+static size_t blowfish_ctr_key_length(fastd_context_t *ctx UNUSED, const fastd_cipher_context_t *cctx UNUSED) {
+ return 56;
+}
+
static inline void bf_swap(uint32_t *L, uint32_t *R) {
uint32_t tmp = *L;
*L = *R;
@@ -292,7 +296,11 @@ static fastd_cipher_state_t* blowfish_ctr_init_state(fastd_context_t *ctx UNUSED
return state;
}
-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 fastd_block128_t *iv) {
+static size_t blowfish_ctr_iv_length(fastd_context_t *ctx UNUSED, const fastd_cipher_state_t *state UNUSED) {
+ return 8;
+}
+
+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) {
uint32_t ctr[2];
fastd_block128_t block;
@@ -329,7 +337,11 @@ const fastd_cipher_t fastd_cipher_blowfish_ctr_builtin = {
.name = "builtin",
.initialize = blowfish_ctr_initialize,
+
+ .key_length = blowfish_ctr_key_length,
.init_state = blowfish_ctr_init_state,
+
+ .iv_length = blowfish_ctr_iv_length,
.crypt = blowfish_ctr_crypt,
.free_state = blowfish_ctr_free_state,
diff --git a/src/crypto/cipher/ciphers.c.in b/src/crypto/cipher/ciphers.c.in
index 5bedc75..667cfac 100644
--- a/src/crypto/cipher/ciphers.c.in
+++ b/src/crypto/cipher/ciphers.c.in
@@ -102,7 +102,7 @@ bool fastd_cipher_available(const char *name) {
return false;
}
-const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, fastd_cipher_context_t **cctx) {
+const fastd_cipher_t* fastd_cipher_get_by_name(fastd_context_t *ctx, const char *name, const fastd_cipher_context_t **cctx) {
size_t i;
for (i = 0; i < array_size(ciphers); i++) {
if (!strcmp(ciphers[i].name, name)) {
diff --git a/src/crypto/mac/ghash/builtin/ghash_builtin.c b/src/crypto/mac/ghash/builtin/ghash_builtin.c
index 2eb7fed..34e118a 100644
--- a/src/crypto/mac/ghash/builtin/ghash_builtin.c
+++ b/src/crypto/mac/ghash/builtin/ghash_builtin.c
@@ -65,6 +65,10 @@ static fastd_mac_context_t* ghash_initialize(fastd_context_t *ctx UNUSED) {
return NULL;
}
+static size_t ghash_key_length(fastd_context_t *ctx UNUSED, const fastd_mac_context_t *cctx UNUSED) {
+ return sizeof(fastd_block128_t);
+}
+
static fastd_mac_state_t* ghash_init_state(fastd_context_t *ctx UNUSED, const fastd_mac_context_t *mctx UNUSED, const uint8_t *key) {
fastd_mac_state_t *state = malloc(sizeof(fastd_mac_state_t));
@@ -132,7 +136,10 @@ const fastd_mac_t fastd_mac_ghash_builtin = {
.name = "builtin",
.initialize = ghash_initialize,
+
+ .key_length = ghash_key_length,
.init_state = ghash_init_state,
+
.hash = ghash_hash,
.free_state = ghash_free_state,
diff --git a/src/crypto/mac/macs.c.in b/src/crypto/mac/macs.c.in
index 7d8a5ff..5adca10 100644
--- a/src/crypto/mac/macs.c.in
+++ b/src/crypto/mac/macs.c.in
@@ -102,7 +102,7 @@ bool fastd_mac_available(const char *name) {
return false;
}
-const fastd_mac_t* fastd_mac_get_by_name(fastd_context_t *ctx, const char *name, fastd_mac_context_t **cctx) {
+const fastd_mac_t* fastd_mac_get_by_name(fastd_context_t *ctx, const char *name, const fastd_mac_context_t **cctx) {
size_t i;
for (i = 0; i < array_size(macs); i++) {
if (!strcmp(macs[i].name, name)) {