summaryrefslogtreecommitdiffstats
path: root/src/crypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto.h')
-rw-r--r--src/crypto.h36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/crypto.h b/src/crypto.h
index c52fd42..124d06d 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -27,7 +27,10 @@
#ifndef _FASTD_CRYPTO_H_
#define _FASTD_CRYPTO_H_
-#include "fastd.h"
+#include "types.h"
+
+#include <stdlib.h>
+#include <string.h>
struct fastd_cipher_info {
@@ -38,9 +41,9 @@ struct fastd_cipher_info {
struct fastd_cipher {
bool (*available)(void);
- fastd_cipher_state_t* (*init)(fastd_context_t *ctx, const uint8_t *key);
- bool (*crypt)(fastd_context_t *ctx, const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv);
- void (*free)(fastd_context_t *ctx, fastd_cipher_state_t *state);
+ fastd_cipher_state_t* (*init)(const uint8_t *key);
+ bool (*crypt)(const fastd_cipher_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t len, const uint8_t *iv);
+ void (*free)(fastd_cipher_state_t *state);
};
@@ -51,9 +54,9 @@ struct fastd_mac_info {
struct fastd_mac {
bool (*available)(void);
- fastd_mac_state_t* (*init)(fastd_context_t *ctx, const uint8_t *key);
- bool (*hash)(fastd_context_t *ctx, const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks);
- void (*free)(fastd_context_t *ctx, fastd_mac_state_t *state);
+ fastd_mac_state_t* (*init)(const uint8_t *key);
+ bool (*hash)(const fastd_mac_state_t *state, fastd_block128_t *out, const fastd_block128_t *in, size_t n_blocks);
+ void (*free)(fastd_mac_state_t *state);
};
@@ -71,4 +74,23 @@ bool fastd_mac_config(const fastd_mac_t **mac_conf, const char *name, const char
const fastd_mac_info_t* fastd_mac_info_get_by_name(const char *name);
const fastd_mac_t* fastd_mac_get(fastd_context_t *ctx, const fastd_mac_info_t *info);
+
+static inline void secure_memzero(void *s, size_t n) {
+ memset(s, 0, n);
+ __asm__ volatile("" : : "m"(s));
+}
+
+static inline void xor(fastd_block128_t *x, fastd_block128_t a, fastd_block128_t b) {
+ x->qw[0] = a.qw[0] ^ b.qw[0];
+ x->qw[1] = a.qw[1] ^ b.qw[1];
+}
+
+static inline void xor_a(fastd_block128_t *x, fastd_block128_t a) {
+ xor(x, *x, a);
+}
+
+static inline bool fastd_true(void) {
+ return true;
+}
+
#endif /* _FASTD_CRYPTO_H_ */