From: Niels Möller Date: Mon, 22 Mar 2010 21:12:27 +0000 (+0100) Subject: (READ_UINT64, WRITE_UINT64): New macros. X-Git-Tag: camellia_32bit_20100720~129 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=03bdd346f59d460137c26f2f17dcecb37bd500d4;p=thirdparty%2Fnettle.git (READ_UINT64, WRITE_UINT64): New macros. Rev: nettle/macros.h:1.2 --- diff --git a/macros.h b/macros.h index 52876976..2cc69cbb 100644 --- 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 @@ -25,6 +25,29 @@ #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) \