]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
(READ_UINT24, WRITE_UINT24, READ_UINT16, WRITE_UINT16):
authorNiels Möller <nisse@lysator.liu.se>
Wed, 16 Jan 2002 19:58:41 +0000 (20:58 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Wed, 16 Jan 2002 19:58:41 +0000 (20:58 +0100)
New macros.

Rev: src/nettle/macros.h:1.6

macros.h

index c235600aaccd0a69b8755c9eefae3091315680dc..89400c547b6c5e5605df988f50b4bdbfa8e94e53 100644 (file)
--- a/macros.h
+++ b/macros.h
@@ -40,6 +40,29 @@ do {                                         \
   (p)[3] = (i) & 0xff;                         \
 } while(0)
 
+/* Analogous macros, for 24 and 16 bit numbers */
+#define READ_UINT24(p)                         \
+(  (((uint32_t) (p)[0]) << 16)                 \
+ | (((uint32_t) (p)[1]) << 8)                  \
+ |  ((uint32_t) (p)[2]))
+
+#define WRITE_UINT24(p, i)                     \
+do {                                           \
+  (p)[0] = ((i) >> 16) & 0xff;                 \
+  (p)[1] = ((i) >> 8) & 0xff;                  \
+  (p)[2] = (i) & 0xff;                         \
+} while(0)
+
+#define READ_UINT16(p)                         \
+(  (((uint32_t) (p)[0]) << 8)                  \
+ |  ((uint32_t) (p)[1]))
+
+#define WRITE_UINT16(p, i)                     \
+do {                                           \
+  (p)[0] = ((i) >> 8) & 0xff;                  \
+  (p)[1] = (i) & 0xff;                         \
+} while(0)
+
 /* And the other, little-endian, byteorder */
 #define LE_READ_UINT32(p)                      \
 (  (((uint32_t) (p)[3]) << 24)                 \