This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH 5/5] Add arc4random() etc. from OpenBSD 5.8
- From: Craig Howland <howland at LGSInnovations dot com>
- To: <newlib at sourceware dot org>
- Date: Fri, 18 Mar 2016 12:39:21 -0400
- Subject: Re: [PATCH 5/5] Add arc4random() etc. from OpenBSD 5.8
- Authentication-results: sourceware.org; auth=none
- References: <1458298168-20216-1-git-send-email-sebastian dot huber at embedded-brains dot de> <1458298168-20216-6-git-send-email-sebastian dot huber at embedded-brains dot de>
On 03/18/2016 06:49 AM, Sebastian Huber wrote:
...
diff --git a/newlib/libc/stdlib/chacha_private.h b/newlib/libc/stdlib/chacha_private.h
new file mode 100644
index 0000000..b48c981
--- /dev/null
+++ b/newlib/libc/stdlib/chacha_private.h
@@ -0,0 +1,224 @@
+/*
+...
+#include <stdint.h>
+
+typedef uint8_t u8;
+typedef uint32_t u32;
+
+typedef struct
+{
+ u32 input[16]; /* could be compressed */
+} chacha_ctx;
+
+#define U8C(v) (v##U)
+#define U32C(v) (v##U)
Not good, as may or may not match what is defined in stdint.h, and can be
inaccurate, for example if long is needed for 32 bits. However, they are only
used in the 2 lines below, so just get rid of these two defines.
(Realistically, I would expect it to still provide the correct results, but it
is definitely an error in usage.)
+
+#define U8V(v) ((u8)(v) & U8C(0xFF))
+#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
#define U8V(v) ((u8)(v) & UINT8_C(0xFF))
#define U32V(v) ((u32)(v) & UINT32_C(0xFFFFFFFF))
(For that matter, the '& mask' is not needed, as the cast does it.)