summaryrefslogtreecommitdiff
path: root/write-be32.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2010-03-26 15:26:44 +0100
committerNiels Möller <nisse@lysator.liu.se>2010-03-26 15:26:44 +0100
commite6dc6b624d86bf8686e50249007a0dd7d36fadbf (patch)
treebc744850f5cf3d3a821a1d5c5a2730f625f815e9 /write-be32.c
parentaeea048dbc3b3d0d6384117307252ee541514f03 (diff)
downloadnettle-e6dc6b624d86bf8686e50249007a0dd7d36fadbf.tar.gz
* nettle-write.h: New file.
* write-be32.c (nettle_write_be32): New file, new function. Rev: nettle/nettle-write.h:1.1 Rev: nettle/write-be32.c:1.1
Diffstat (limited to 'write-be32.c')
-rw-r--r--write-be32.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/write-be32.c b/write-be32.c
new file mode 100644
index 00000000..e52e565f
--- /dev/null
+++ b/write-be32.c
@@ -0,0 +1,68 @@
+/* write-be32.c */
+
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 2001 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., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "nettle-write.h"
+
+#include "macros.h"
+
+void
+_nettle_write_be32(unsigned length, uint8_t *dst,
+ uint32_t *src)
+{
+ unsigned i;
+ unsigned words;
+ unsigned leftover;
+
+ words = length / 4;
+ leftover = length % 4;
+
+ for (i = 0; i < words; i++, dst += 4)
+ WRITE_UINT32(dst, src[i]);
+
+ if (leftover)
+ {
+ uint32_t word;
+ unsigned j = leftover;
+
+ word = src[i];
+
+ switch (leftover)
+ {
+ default:
+ abort();
+ case 3:
+ dst[--j] = (word >> 8) & 0xff;
+ /* Fall through */
+ case 2:
+ dst[--j] = (word >> 16) & 0xff;
+ /* Fall through */
+ case 1:
+ dst[--j] = (word >> 24) & 0xff;
+ }
+ }
+}