Commit c835888e authored by Niels Möller's avatar Niels Möller

New function _nettle_write_le64.

parent 8149d146
2012-11-12 Niels Möller <nisse@lysator.liu.se>
* macros.h (LE_WRITE_UINT64): New macro.
* write-le64.c (_nettle_write_le64): New file and function.
* nettle-write.h (_nettle_write_le64): Declare. Also deleted
declaration of non-existent _nettle_write_be64.
* Makefile.in (nettle_SOURCES): Added write-le64.c.
* macros.h (ROTL64): New macro, moved from...
* sha512-compress.c (ROTL64): ... old location, deleted.
......
......@@ -95,7 +95,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
buffer.c buffer-init.c realloc.c \
nettle-meta-hashes.c nettle-meta-ciphers.c \
nettle-meta-armors.c \
write-be32.c write-le32.c
write-be32.c write-le32.c write-le64.c
hogweed_SOURCES = sexp.c sexp-format.c \
sexp-transport.c sexp-transport-format.c \
......
......@@ -87,6 +87,18 @@ do { \
} while(0)
/* And the other, little-endian, byteorder */
#define LE_WRITE_UINT64(p, i) \
do { \
(p)[7] = ((i) >> 56) & 0xff; \
(p)[6] = ((i) >> 48) & 0xff; \
(p)[5] = ((i) >> 40) & 0xff; \
(p)[4] = ((i) >> 32) & 0xff; \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while (0)
#define LE_READ_UINT32(p) \
( (((uint32_t) (p)[3]) << 24) \
| (((uint32_t) (p)[2]) << 16) \
......
......@@ -31,14 +31,17 @@
/* Write the word array at SRC to the byte array at DST, using little
endian (le) or big endian (be) byte order, and truncating the
result to LENGTH bytes. */
/* FIXME: Use a macro shortcut to memcpy for native endianness. */
void
_nettle_write_be32(unsigned length, uint8_t *dst,
uint32_t *src);
void
_nettle_write_le32(unsigned length, uint8_t *dst,
uint32_t *src);
void
_nettle_write_be64(unsigned length, uint8_t *dst,
_nettle_write_le64(unsigned length, uint8_t *dst,
uint64_t *src);
#endif /* NETTLE_WRITE_H_INCLUDED */
/* write-le64.c */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001, 2011, 2012 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
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "nettle-write.h"
#include "macros.h"
void
_nettle_write_le64(unsigned length, uint8_t *dst,
uint64_t *src)
{
unsigned i;
unsigned words;
unsigned leftover;
words = length / 8;
leftover = length % 8;
for (i = 0; i < words; i++, dst += 8)
LE_WRITE_UINT64(dst, src[i]);
if (leftover)
{
uint64_t word;
word = src[i];
do
{
*dst++ = word & 0xff;
word >>= 8;
}
while (--leftover);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment