]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
(READ_UINT64, WRITE_UINT64): New macros.
authorNiels Möller <nisse@lysator.liu.se>
Mon, 22 Mar 2010 21:12:27 +0000 (22:12 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 22 Mar 2010 21:12:27 +0000 (22:12 +0100)
Rev: nettle/macros.h:1.2

macros.h

index 52876976ebf52fc27add29081e8b1bb04786d3fc..2cc69cbbc9aa14d5c6ca8edd60b4f0dec557cb55 100644 (file)
--- a/macros.h
+++ b/macros.h
@@ -4,7 +4,7 @@
 
 /* nettle, low-level cryptographics library
  *
- * Copyright (C) 2001 Niels Möller
+ * Copyright (C) 2001, 2010 Niels Möller
  *  
  * The nettle library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
 #ifndef NETTLE_MACROS_H_INCLUDED
 #define NETTLE_MACROS_H_INCLUDED
 
+/* Reads a 64-bit integer, in network, big-endian, byte order */
+#define READ_UINT64(p)                         \
+(  (((uint64_t) (p)[0]) << 56)                 \
+ | (((uint64_t) (p)[1]) << 48)                 \
+ | (((uint64_t) (p)[2]) << 40)                 \
+ | (((uint64_t) (p)[3]) << 32)                 \
+ | (((uint64_t) (p)[4]) << 24)                 \
+ | (((uint64_t) (p)[5]) << 16)                 \
+ | (((uint64_t) (p)[6]) << 8)                  \
+ |  ((uint64_t) (p)[7]))
+
+#define WRITE_UINT64(p, i)                     \
+do {                                           \
+  (p)[0] = ((i) >> 56) & 0xff;                 \
+  (p)[1] = ((i) >> 48) & 0xff;                 \
+  (p)[2] = ((i) >> 40) & 0xff;                 \
+  (p)[3] = ((i) >> 32) & 0xff;                 \
+  (p)[4] = ((i) >> 24) & 0xff;                 \
+  (p)[5] = ((i) >> 16) & 0xff;                 \
+  (p)[6] = ((i) >> 8) & 0xff;                  \
+  (p)[7] = (i) & 0xff;                         \
+} while(0)
+
 /* Reads a 32-bit integer, in network, big-endian, byte order */
 #define READ_UINT32(p)                         \
 (  (((uint32_t) (p)[0]) << 24)                 \