summaryrefslogtreecommitdiffstats
path: root/src/crypto/cipher
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/cipher')
-rw-r--r--src/crypto/cipher/aes128_ctr/aes128_ctr.c7
-rw-r--r--src/crypto/cipher/aes128_ctr/nacl/cipher_aes128_ctr_nacl.c14
-rw-r--r--src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c14
-rw-r--r--src/crypto/cipher/ciphers.c.in25
-rw-r--r--src/crypto/cipher/null/memcpy/null_memcpy.c10
-rw-r--r--src/crypto/cipher/null/null.c7
-rw-r--r--src/crypto/cipher/salsa20/nacl/salsa20_nacl.c14
-rw-r--r--src/crypto/cipher/salsa20/salsa20.c7
-rw-r--r--src/crypto/cipher/salsa20/xmm/salsa20_xmm.c22
-rw-r--r--src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c14
-rw-r--r--src/crypto/cipher/salsa2012/salsa2012.c7
-rw-r--r--src/crypto/cipher/salsa2012/xmm/salsa2012_xmm.c22
12 files changed, 145 insertions, 18 deletions
diff --git a/src/crypto/cipher/aes128_ctr/aes128_ctr.c b/src/crypto/cipher/aes128_ctr/aes128_ctr.c
index 52122d9..4448dd0 100644
--- a/src/crypto/cipher/aes128_ctr/aes128_ctr.c
+++ b/src/crypto/cipher/aes128_ctr/aes128_ctr.c
@@ -23,10 +23,17 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The aes128-ctr stream cipher
+*/
+
#include "../../../crypto.h"
+/** cipher info about aes128-ctr */
const fastd_cipher_info_t fastd_cipher_info_aes128_ctr = {
.key_length = 16,
.iv_length = 16,
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 793b724..797572c 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
@@ -23,17 +23,25 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The aes128-ctr implementation from NaCl
+*/
+
#include "../../../../crypto.h"
#include <crypto_stream_aes128ctr.h>
+/** The cipher state */
struct __attribute__((aligned(16))) fastd_cipher_state {
- uint8_t d[crypto_stream_aes128ctr_BEFORENMBYTES] __attribute__((aligned(16)));
+ uint8_t d[crypto_stream_aes128ctr_BEFORENMBYTES] __attribute__((aligned(16))); /**< The unpacked AES key */
};
+/** Initializes the cipher state */
static fastd_cipher_state_t* aes128_ctr_init(const uint8_t *key) {
fastd_block128_t k;
memcpy(k.b, key, sizeof(fastd_block128_t));
@@ -47,11 +55,13 @@ static fastd_cipher_state_t* aes128_ctr_init(const uint8_t *key) {
return state;
}
+/** XORs data with the aes128-ctr cipher stream */
static bool aes128_ctr_crypt(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);
return true;
}
+/** Frees the cipher state */
static void aes128_ctr_free(fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
@@ -59,6 +69,8 @@ static void aes128_ctr_free(fastd_cipher_state_t *state) {
}
}
+
+/** The nacl aes128-ctr implementation */
const fastd_cipher_t fastd_cipher_aes128_ctr_nacl = {
.init = aes128_ctr_init,
.crypt = aes128_ctr_crypt,
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 b47be57..2e06763 100644
--- a/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
+++ b/src/crypto/cipher/aes128_ctr/openssl/aes128_ctr_openssl.c
@@ -23,17 +23,25 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The aes128-ctr implementation from OpenSSL
+*/
+
#include "../../../../crypto.h"
#include <openssl/evp.h>
+/** The cipher state containing the OpenSSL cipher context */
struct fastd_cipher_state {
- EVP_CIPHER_CTX *aes;
+ EVP_CIPHER_CTX *aes; /**< The OpenSSL cipher context */
};
+/** Initializes the cipher state */
static fastd_cipher_state_t* aes128_ctr_init(const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
@@ -43,6 +51,7 @@ static fastd_cipher_state_t* aes128_ctr_init(const uint8_t *key) {
return state;
}
+/** XORs data with the aes128-ctr cipher stream */
static bool aes128_ctr_crypt(const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv) {
int clen, clen2;
@@ -61,6 +70,7 @@ static bool aes128_ctr_crypt(const fastd_cipher_state_t *state, fastd_block128_t
return true;
}
+/** Frees the cipher state */
static void aes128_ctr_free(fastd_cipher_state_t *state) {
if (state) {
EVP_CIPHER_CTX_free(state->aes);
@@ -68,6 +78,8 @@ static void aes128_ctr_free(fastd_cipher_state_t *state) {
}
}
+
+/** The openssl aes128-ctr implementation */
const fastd_cipher_t fastd_cipher_aes128_ctr_openssl = {
.available = fastd_true,
diff --git a/src/crypto/cipher/ciphers.c.in b/src/crypto/cipher/ciphers.c.in
index 01b5a35..7816bca 100644
--- a/src/crypto/cipher/ciphers.c.in
+++ b/src/crypto/cipher/ciphers.c.in
@@ -23,6 +23,12 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ Generated lists of ciphers and their implementations
+*/
+
#include <src/crypto.h>
#include <src/fastd.h>
@@ -30,30 +36,35 @@
@CIPHER_DEFINITIONS@
+/** A cipher implementation */
typedef struct fastd_cipher_impl {
- const char *name;
- const fastd_cipher_t *impl;
+ const char *name; /**< The name of the cipher implementation */
+ const fastd_cipher_t *impl; /**< The cipher implementation */
} fastd_cipher_impl_t;
+/** A cipher */
typedef struct cipher_entry {
- const char *name;
- const fastd_cipher_info_t *info;
- const fastd_cipher_impl_t *impls;
+ const char *name; /**< The name of the cipher */
+ const fastd_cipher_info_t *info; /**< The associated cipher information */
+ const fastd_cipher_impl_t *impls; /**< NULL-terminated array of cipher implementations */
} cipher_entry_t;
@CIPHER_IMPLS@
+/** The list of supported ciphers */
static const cipher_entry_t ciphers[] = { @CIPHER_LIST@
};
+/** The list of chosen cipher implementations */
static const fastd_cipher_t *cipher_conf[array_size(ciphers)] = {};
+/** Checks if a cipher implementation is available on the runtime platform */
static inline bool cipher_available(const fastd_cipher_t *cipher) {
return (!cipher->available) || cipher->available();
}
-/** Initializes the list of ciphers */
+/** Initializes the list of cipher implementations */
void fastd_cipher_init(void) {
size_t i, j;
for (i = 0; i < array_size(ciphers); i++) {
@@ -89,6 +100,7 @@ bool fastd_cipher_config(const char *name, const char *impl) {
return false;
}
+/** Returns information about the cipher with the specified name if there is an implementation available */
const fastd_cipher_info_t* fastd_cipher_info_get_by_name(const char *name) {
size_t i;
for (i = 0; i < array_size(ciphers); i++) {
@@ -104,6 +116,7 @@ const fastd_cipher_info_t* fastd_cipher_info_get_by_name(const char *name) {
return NULL;
}
+/** Returns the chosen cipher implementation for a given cipher */
const fastd_cipher_t* fastd_cipher_get(const fastd_cipher_info_t *info) {
size_t i;
for (i = 0; i < array_size(ciphers); i++) {
diff --git a/src/crypto/cipher/null/memcpy/null_memcpy.c b/src/crypto/cipher/null/memcpy/null_memcpy.c
index a2c0df9..089817f 100644
--- a/src/crypto/cipher/null/memcpy/null_memcpy.c
+++ b/src/crypto/cipher/null/memcpy/null_memcpy.c
@@ -23,22 +23,32 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The memcpy null implementation
+*/
+
#include "../../../../crypto.h"
+/** Doesn't do anything as the null cipher doesn't use any state */
static fastd_cipher_state_t* null_init(const uint8_t *key UNUSED) {
return NULL;
}
+/** Just copies the input data to the output */
static bool null_memcpy(const fastd_cipher_state_t *state UNUSED, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv UNUSED) {
memcpy(out, in, len);
return true;
}
+/** Doesn't do anything as the null cipher doesn't use any state */
static void null_free(fastd_cipher_state_t *state UNUSED) {
}
+/** The memcpy null implementation */
const fastd_cipher_t fastd_cipher_null_memcpy = {
.init = null_init,
.crypt = null_memcpy,
diff --git a/src/crypto/cipher/null/null.c b/src/crypto/cipher/null/null.c
index d6e4cab..353090a 100644
--- a/src/crypto/cipher/null/null.c
+++ b/src/crypto/cipher/null/null.c
@@ -23,10 +23,17 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The null cipher not performing any encryption
+*/
+
#include "../../../crypto.h"
+/** cipher info about the null cipher */
const fastd_cipher_info_t fastd_cipher_info_null = {
.key_length = 0,
.iv_length = 0,
diff --git a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c
index 03ab1d9..6179bc2 100644
--- a/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c
+++ b/src/crypto/cipher/salsa20/nacl/salsa20_nacl.c
@@ -23,17 +23,25 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The Salsa20 implementation from NaCl
+*/
+
#include "../../../../crypto.h"
#include <crypto_stream_salsa20.h>
+/** The cipher state */
struct fastd_cipher_state {
- uint8_t key[crypto_stream_salsa20_KEYBYTES];
+ uint8_t key[crypto_stream_salsa20_KEYBYTES]; /**< The encryption key */
};
+/** Initializes the cipher state */
static fastd_cipher_state_t* salsa20_init(const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
memcpy(state->key, key, crypto_stream_salsa20_KEYBYTES);
@@ -41,11 +49,13 @@ static fastd_cipher_state_t* salsa20_init(const uint8_t *key) {
return state;
}
+/** XORs data with the Salsa20 cipher stream */
static bool salsa20_crypt(const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv) {
crypto_stream_salsa20_xor(out->b, in->b, len, iv, state->key);
return true;
}
+/** Frees the cipher state */
static void salsa20_free(fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
@@ -53,6 +63,8 @@ static void salsa20_free(fastd_cipher_state_t *state) {
}
}
+
+/** The nacl salsa20 implementation */
const fastd_cipher_t fastd_cipher_salsa20_nacl = {
.init = salsa20_init,
.crypt = salsa20_crypt,
diff --git a/src/crypto/cipher/salsa20/salsa20.c b/src/crypto/cipher/salsa20/salsa20.c
index f4f713f..dad6a6c 100644
--- a/src/crypto/cipher/salsa20/salsa20.c
+++ b/src/crypto/cipher/salsa20/salsa20.c
@@ -23,10 +23,17 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The Salsa20 stream cipher
+*/
+
#include "../../../crypto.h"
+/** Cipher info about Salsa20 */
const fastd_cipher_info_t fastd_cipher_info_salsa20 = {
.key_length = 32,
.iv_length = 8,
diff --git a/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c b/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c
index 52c4b6d..a85ed72 100644
--- a/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c
+++ b/src/crypto/cipher/salsa20/xmm/salsa20_xmm.c
@@ -23,15 +23,21 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- The assembly implementations were written by D. J. Bernstein and are
- Public Domain. For more information see http://cr.yp.to/snuffle.html
+/**
+ \file
+
+ The XMM Salsa20 implementation for SSE2-capable x86 systems
+
+ The assembly implementations were written by D. J. Bernstein and are
+ Public Domain. For more information see http://cr.yp.to/snuffle.html
*/
+
#include "../../../../crypto.h"
#include "../../../../cpuid.h"
+/** The length of the key used by Salsa20 */
#define KEYBYTES 32
@@ -44,18 +50,22 @@
#endif
+/** The actual Salsa20 assembly implementation */
int crypto_stream_salsa20_xor(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *k);
+/** The cipher state */
struct fastd_cipher_state {
- uint8_t key[KEYBYTES];
+ uint8_t key[KEYBYTES]; /**< The encryption key */
};
+/** Checks if the runtime platform supports SSE2 */
static bool salsa20_available(void) {
return fastd_cpuid() & CPUID_SSE2;
}
+/** Initializes the cipher state */
static fastd_cipher_state_t* salsa20_init(const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
memcpy(state->key, key, KEYBYTES);
@@ -63,11 +73,13 @@ static fastd_cipher_state_t* salsa20_init(const uint8_t *key) {
return state;
}
+/** XORs data with the Salsa20 cipher stream */
static bool salsa20_crypt(const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv) {
crypto_stream_salsa20_xor(out->b, in->b, len, iv, state->key);
return true;
}
+/** Frees the cipher state */
static void salsa20_free(fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
@@ -75,6 +87,8 @@ static void salsa20_free(fastd_cipher_state_t *state) {
}
}
+
+/** The xmm salsa20 implementation */
const fastd_cipher_t fastd_cipher_salsa20_xmm = {
.available = salsa20_available,
diff --git a/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c b/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c
index efe7089..18ec502 100644
--- a/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c
+++ b/src/crypto/cipher/salsa2012/nacl/salsa2012_nacl.c
@@ -23,17 +23,25 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The Salsa20/12 implementation from NaCl
+*/
+
#include "../../../../crypto.h"
#include <crypto_stream_salsa2012.h>
+/** The cipher state */
struct fastd_cipher_state {
- uint8_t key[crypto_stream_salsa2012_KEYBYTES];
+ uint8_t key[crypto_stream_salsa2012_KEYBYTES]; /**< The encryption key */
};
+/** Initializes the cipher state */
static fastd_cipher_state_t* salsa2012_init(const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
memcpy(state->key, key, crypto_stream_salsa2012_KEYBYTES);
@@ -41,11 +49,13 @@ static fastd_cipher_state_t* salsa2012_init(const uint8_t *key) {
return state;
}
+/** XORs data with the Salsa20/12 cipher stream */
static bool salsa2012_crypt(const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv) {
crypto_stream_salsa2012_xor(out->b, in->b, len, iv, state->key);
return true;
}
+/** Frees the cipher state */
static void salsa2012_free(fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
@@ -53,6 +63,8 @@ static void salsa2012_free(fastd_cipher_state_t *state) {
}
}
+
+/** The nacl salsa2012 implementation */
const fastd_cipher_t fastd_cipher_salsa2012_nacl = {
.init = salsa2012_init,
.crypt = salsa2012_crypt,
diff --git a/src/crypto/cipher/salsa2012/salsa2012.c b/src/crypto/cipher/salsa2012/salsa2012.c
index 8dcfc33..d10c4fb 100644
--- a/src/crypto/cipher/salsa2012/salsa2012.c
+++ b/src/crypto/cipher/salsa2012/salsa2012.c
@@ -23,10 +23,17 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ \file
+
+ The Salsa20/12 stream cipher, a reduced-round version of Salsa20
+*/
+
#include "../../../crypto.h"
+/** Cipher info about Salsa20/12 */
const fastd_cipher_info_t fastd_cipher_info_salsa2012 = {
.key_length = 32,
.iv_length = 8,
diff --git a/src/crypto/cipher/salsa2012/xmm/salsa2012_xmm.c b/src/crypto/cipher/salsa2012/xmm/salsa2012_xmm.c
index 5e5862f..7e6fe80 100644
--- a/src/crypto/cipher/salsa2012/xmm/salsa2012_xmm.c
+++ b/src/crypto/cipher/salsa2012/xmm/salsa2012_xmm.c
@@ -23,15 +23,21 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- The assembly implementations were written by D. J. Bernstein and are
- Public Domain. For more information see http://cr.yp.to/snuffle.html
+/**
+ \file
+
+ The XMM Salsa20/12 implementation for SSE2-capable x86 systems
+
+ The assembly implementations were written by D. J. Bernstein and are
+ Public Domain. For more information see http://cr.yp.to/snuffle.html
*/
+
#include "../../../../crypto.h"
#include "../../../../cpuid.h"
+/** The length of the key used by Salsa20/12 */
#define KEYBYTES 32
@@ -44,18 +50,22 @@
#endif
+/** The actual Salsa20/12 assembly implementation */
int crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m, unsigned long long mlen, const unsigned char *n, const unsigned char *k);
+/** The cipher state */
struct fastd_cipher_state {
- uint8_t key[KEYBYTES];
+ uint8_t key[KEYBYTES]; /**< The encryption key */
};
+/** Checks if the runtime platform supports SSE2 */
static bool salsa2012_available(void) {
return fastd_cpuid() & CPUID_SSE2;
}
+/** Initializes the cipher state */
static fastd_cipher_state_t* salsa2012_init(const uint8_t *key) {
fastd_cipher_state_t *state = malloc(sizeof(fastd_cipher_state_t));
memcpy(state->key, key, KEYBYTES);
@@ -63,11 +73,13 @@ static fastd_cipher_state_t* salsa2012_init(const uint8_t *key) {
return state;
}
+/** XORs data with the Salsa20/12 cipher stream */
static bool salsa2012_crypt(const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv) {
crypto_stream_salsa2012_xor(out->b, in->b, len, iv, state->key);
return true;
}
+/** Frees the cipher state */
static void salsa2012_free(fastd_cipher_state_t *state) {
if (state) {
secure_memzero(state, sizeof(*state));
@@ -75,6 +87,8 @@ static void salsa2012_free(fastd_cipher_state_t *state) {
}
}
+
+/** The xmm salsa2012 implementation */
const fastd_cipher_t fastd_cipher_salsa2012_xmm = {
.available = salsa2012_available,