summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-09-15 19:57:18 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-09-15 19:57:18 +0200
commitf33d7756b8361ca38991bfe9d39ea5de13f86dfc (patch)
treef43a86dfebaff297ddc18778c2765a8f6c9f58d8 /src
parentb2d02587fcd86f0c3910441d58c94dd0c9fea5b5 (diff)
downloadfastd-f33d7756b8361ca38991bfe9d39ea5de13f86dfc.tar
fastd-f33d7756b8361ca38991bfe9d39ea5de13f86dfc.zip
Use inline function for alignment
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c4
-rw-r--r--src/fastd.h6
-rw-r--r--src/method_aes128_gcm.c6
-rw-r--r--src/protocol_ec25519_fhmqvc.c2
4 files changed, 10 insertions, 8 deletions
diff --git a/src/fastd.c b/src/fastd.c
index ec70c6c..1990b36 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -265,7 +265,7 @@ static size_t methods_min_encrypt_head_space(fastd_context *ctx) {
ret = s;
}
- return ALIGN(ret, 8);
+ return alignto(ret, 8);
}
static size_t methods_min_decrypt_head_space(fastd_context *ctx) {
@@ -281,7 +281,7 @@ static size_t methods_min_decrypt_head_space(fastd_context *ctx) {
ret = s;
}
- return ALIGN(ret, 8);
+ return alignto(ret, 8);
}
static size_t methods_min_encrypt_tail_space(fastd_context *ctx) {
diff --git a/src/fastd.h b/src/fastd.h
index 3981f46..d7946ea 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -283,6 +283,10 @@ static inline int fastd_rand(fastd_context *ctx, int min, int max) {
(type *)( (char *)__mptr - offsetof(type,member) );})
+static inline size_t alignto(size_t l, size_t a) {
+ return ((l+a-1)/a)*a;
+}
+
static inline fastd_buffer fastd_buffer_alloc(size_t len, size_t head_space, size_t tail_space) {
size_t base_len = head_space+len+tail_space;
uint8_t *ptr = malloc(base_len);
@@ -354,8 +358,6 @@ static inline void fastd_string_stack_free(fastd_string_stack *str) {
}
}
-#define ALIGN(l, a) (((l+a-1)/a)*a)
-
static inline bool timespec_after(const struct timespec *tp1, const struct timespec *tp2) {
return (tp1->tv_sec > tp2->tv_sec ||
(tp1->tv_sec == tp2->tv_sec && tp1->tv_nsec > tp2->tv_nsec));
diff --git a/src/method_aes128_gcm.c b/src/method_aes128_gcm.c
index ed8f026..05321fd 100644
--- a/src/method_aes128_gcm.c
+++ b/src/method_aes128_gcm.c
@@ -291,8 +291,8 @@ static bool method_encrypt(fastd_context *ctx, fastd_peer *peer, fastd_method_se
fastd_buffer_pull_head(&in, BLOCKBYTES);
memset(in.data, 0, BLOCKBYTES);
- size_t tail_len = ALIGN(in.len, BLOCKBYTES)-in.len;
- *out = fastd_buffer_alloc(in.len, ALIGN(NONCEBYTES, 8), BLOCKBYTES+tail_len);
+ size_t tail_len = alignto(in.len, BLOCKBYTES)-in.len;
+ *out = fastd_buffer_alloc(in.len, alignto(NONCEBYTES, 8), BLOCKBYTES+tail_len);
if (tail_len)
memset(in.data+in.len, 0, tail_len);
@@ -353,7 +353,7 @@ static bool method_decrypt(fastd_context *ctx, fastd_peer *peer, fastd_method_se
fastd_buffer_push_head(&in, NONCEBYTES);
- size_t tail_len = ALIGN(in.len, BLOCKBYTES)-in.len;
+ size_t tail_len = alignto(in.len, BLOCKBYTES)-in.len;
*out = fastd_buffer_alloc(in.len, 0, tail_len);
int n_blocks = (in.len+BLOCKBYTES-1)/BLOCKBYTES;
diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c
index 964c21d..02920f4 100644
--- a/src/protocol_ec25519_fhmqvc.c
+++ b/src/protocol_ec25519_fhmqvc.c
@@ -726,7 +726,7 @@ static void protocol_send(fastd_context *ctx, fastd_peer *peer, fastd_buffer buf
}
static void send_empty(fastd_context *ctx, fastd_peer *peer, protocol_session *session) {
- session_send(ctx, peer, fastd_buffer_alloc(0, ALIGN(session->method->min_encrypt_head_space(ctx), 8), session->method->min_encrypt_tail_space(ctx)), session);
+ session_send(ctx, peer, fastd_buffer_alloc(0, alignto(session->method->min_encrypt_head_space(ctx), 8), session->method->min_encrypt_tail_space(ctx)), session);
}
static void protocol_init_peer_state(fastd_context *ctx, fastd_peer *peer) {