From 20b8bd9b454a511e25165dc285e527355be6ebb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Wed, 16 Jan 2002 20:58:41 +0100 Subject: [PATCH] (READ_UINT24, WRITE_UINT24, READ_UINT16, WRITE_UINT16): New macros. Rev: src/nettle/macros.h:1.6 --- macros.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/macros.h b/macros.h index c235600a..89400c54 100644 --- 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) \ -- GitLab