From 620a5af8d34e5e7e9fc902eb46537faa479411f4 Mon Sep 17 00:00:00 2001 From: arighi Date: Sat, 19 Feb 2011 00:06:31 +0000 Subject: [PATCH 1/1] move is_aligned() helper function into bertos/cfg/macros.h git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4718 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cfg/macros.h | 8 ++++++++ bertos/sec/util.h | 17 ++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/bertos/cfg/macros.h b/bertos/cfg/macros.h index e6706f64..17f9c676 100644 --- a/bertos/cfg/macros.h +++ b/bertos/cfg/macros.h @@ -362,6 +362,14 @@ */ typedef uint32_t id_t; +/** + * Check if a pointer is aligned to a certain power-of-2 size + */ +INLINE bool is_aligned(const void *addr, size_t size) +{ + return ((size_t)addr & (size - 1)) == 0; +} + /** \} */ //defgroup macros #endif /* MACROS_H */ diff --git a/bertos/sec/util.h b/bertos/sec/util.h index 0e62fad7..2fcf1b8f 100644 --- a/bertos/sec/util.h +++ b/bertos/sec/util.h @@ -1,6 +1,7 @@ #ifndef SEC_UTIL_H #define SEC_UTIL_H +#include #include #include #include @@ -32,12 +33,6 @@ void password2key(const char *pwd, size_t pwd_len, uint8_t *key, size_t key_len); -/* Check if a pointer is aligned to a certain power-of-2 size */ -INLINE bool __is_aligned(const void *addr, size_t size) -{ - return ((size_t)addr & (size - 1)) == 0; -} - INLINE void xor_block_8(uint8_t *out, const uint8_t *in1, const uint8_t *in2, size_t len) { @@ -83,9 +78,9 @@ INLINE void xor_block_const_32(uint32_t *out, const uint32_t *in, */ INLINE void xor_block(void *out, const void *in1, const void *in2, size_t len) { - if (__is_aligned(out, sizeof(uint32_t)) && - __is_aligned(in1, sizeof(uint32_t)) && - __is_aligned(in2, sizeof(uint32_t))) + if (is_aligned(out, sizeof(uint32_t)) && + is_aligned(in1, sizeof(uint32_t)) && + is_aligned(in2, sizeof(uint32_t))) { uint32_t *obuf = (uint32_t *)((size_t)out); const uint32_t *ibuf1 = (const uint32_t *)((size_t)in1); @@ -108,8 +103,8 @@ INLINE void xor_block(void *out, const void *in1, const void *in2, size_t len) */ INLINE void xor_block_const(uint8_t *out, const uint8_t *in, uint8_t k, size_t len) { - if (__is_aligned(out, sizeof(uint32_t)) && - __is_aligned(in, sizeof(uint32_t))) + if (is_aligned(out, sizeof(uint32_t)) && + is_aligned(in, sizeof(uint32_t))) { uint32_t *obuf = (uint32_t *)((size_t)out); const uint32_t *ibuf = (const uint32_t *)((size_t)in); -- 2.25.1