You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/10/19 03:03:28 UTC

[GitHub] [incubator-nuttx] hartmannathan commented on a diff in pull request #6920: support /dev/crypto for nuttx

hartmannathan commented on code in PR #6920:
URL: https://github.com/apache/incubator-nuttx/pull/6920#discussion_r998894368


##########
crypto/chacha_private.h:
##########
@@ -0,0 +1,335 @@
+/****************************************************************************
+ * crypto/chacha_private.h
+ * $OpenBSD: chacha_private.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $
+ *
+ * chacha-merged.c version 20080118
+ * D. J. Bernstein
+ * Public domain.
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <string.h>
+#include <sys/types.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)
+
+#define U8V(v) ((u8)(v) & U8C(0xFF))
+#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
+
+#define ROTL32(v, n) \
+  (U32V((v) << (n)) | ((v) >> (32 - (n))))
+
+#define U8TO32_LITTLE(p) \
+  (((u32)((p)[0])) | \
+   ((u32)((p)[1]) << 8) | \
+   ((u32)((p)[2]) << 16) | \
+   ((u32)((p)[3]) << 24))
+
+#define U32TO8_LITTLE(p, v) \
+  do { \
+    (p)[0] = U8V((v)); \
+    (p)[1] = U8V((v) >> 8); \
+    (p)[2] = U8V((v) >> 16); \
+    (p)[3] = U8V((v) >> 24); \
+  } while (0)
+
+#define ROTATE(v, c) (ROTL32(v, c))
+#define XOR(v, w) ((v) ^ (w))
+#define PLUS(v, w) (U32V((v) + (w)))
+#define PLUSONE(v) (PLUS((v), 1))
+
+#define QUARTERROUND(a, b, c, d) \

Review Comment:
   Ditto. Best to wrap multiple statements with `do { ... } while (0)`, else if this macro is used like the following example:
   
   ```
   if (condition)
     QUARTERROUND(a, b, c, d);
   
   other_code();
   ```
   
   that would lead to unexpected results!
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org