From 9dacff2507a1e69cecc0ec888d49d296bd9c91b0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 30 Nov 2013 07:17:29 +0100 Subject: generic-poly1305: add helper functions to handle the common header --- src/methods/common.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/methods/common.h') diff --git a/src/methods/common.h b/src/methods/common.h index d3218ae..b5f7272 100644 --- a/src/methods/common.h +++ b/src/methods/common.h @@ -94,4 +94,29 @@ static inline void fastd_method_increment_nonce(fastd_method_common_t *session) } } +static inline void fastd_method_put_common_header(fastd_context_t *ctx, fastd_buffer_t *buffer, const uint8_t nonce[COMMON_NONCEBYTES], uint8_t flags) { + fastd_buffer_pull_head_from(ctx, buffer, &flags, 1); + fastd_buffer_pull_head_from(ctx, buffer, nonce, COMMON_NONCEBYTES); +} + +static inline void fastd_method_take_common_header(fastd_context_t *ctx, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags) { + fastd_buffer_push_head_to(ctx, buffer, nonce, COMMON_NONCEBYTES); + fastd_buffer_push_head_to(ctx, buffer, flags, 1); +} + +static inline bool fastd_method_handle_common_header(fastd_context_t *ctx, const fastd_method_common_t *session, fastd_buffer_t *buffer, uint8_t nonce[COMMON_NONCEBYTES], uint8_t *flags, int64_t *age) { + fastd_method_take_common_header(ctx, buffer, nonce, flags); + return fastd_method_is_nonce_valid(ctx, session, nonce, age); +} + + +static inline void fastd_method_expand_nonce(uint8_t *buf, const uint8_t nonce[COMMON_NONCEBYTES], size_t len) { + if (!len) + return; + + memset(buf, 0, len); + memcpy(buf, nonce, min_size_t(len, COMMON_NONCEBYTES)); + buf[len-1] = 1; +} + #endif /* _FASTD_METHODS_COMMON_H_ */ -- cgit v1.2.3