--- /dev/null
+/*
+ * This file is part of secnet.
+ * See README for full list of copyright holders.
+ *
+ * secnet is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version d of the License, or
+ * (at your option) any later version.
+ *
+ * secnet 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with secnet; if not, see
+ * https://www.gnu.org/licenses/gpl.html.
+ */
+
+#ifndef fake_mLib_bits_h
+#define fake_mLib_bits_h
+
+/* The <mLib/bits.h> header defines a large number of types and macros for
+ * various kinds of bithacking. Notably, it has machinery for autodetecting
+ * suitable types holding (at least) various numbers of bits -- a service
+ * which C99 provides through other means.
+ *
+ * This file provides a small portion of the <mLib/bits.h> interface, just
+ * enough to make the pieces of code lifted from Catacomb feel at home.
+ */
+
+#include <stdint.h>
+#include "u64.h"
+#include "unaligned.h"
+
+typedef uint8_t octet;
+typedef uint32_t uint32;
+typedef uint64_t uint64;
+
+typedef int32_t int32;
+typedef int64_t int64;
+
+#define LOAD32_L(p) (get_uint32_le(p))
+#define LOAD32_B(p) (get_uint32(p))
+#define STORE32_L(p, x) put_uint32_le((p), (x))
+#define STORE32_B(p, x) put_uint32((p), (x))
+#define ROL32(x, n) ((n) ? ((x) << (n) | (x) >> (32 - (n))) : (x))
+
+#define MASK32 0xffffffffu
+#define U32(x) ((uint32)(x) & MASK32)
+
+typedef u64 kludge64;
+#define X64(hi, lo) u64init(0x##hi, 0x##lo)
+#define HI64(x) u64gethi(x)
+#define LO64(x) u64getlo(x)
+#define LOAD64_L_(x, p) do { \
+ const uint8_t *p_ = (const uint8_t *)(p); \
+ uint32_t lo_ = LOAD32_L(p_ + 0), hi_ = LOAD32_L(p_ + 4); \
+ (x) = u64hilo(hi_, lo_); \
+} while (0)
+#define LOAD64_B_(x, p) do { \
+ const uint8_t *p_ = (const uint8_t *)(p); \
+ uint32_t hi_ = LOAD32_B(p_ + 0), lo_ = LOAD32_B(p_ + 4); \
+ (x) = u64hilo(hi_, lo_); \
+} while (0)
+#define STORE64_L_(p, x) do { \
+ uint8_t *p_ = (uint8_t *)(p); \
+ uint32_t lo_ = LO64(x), hi_ = HI64(x); \
+ STORE32_L(p_ + 0, lo_); STORE32_L(p_ + 4, hi_); \
+} while (0)
+#define STORE64_B_(p, x) do { \
+ uint8_t *p_ = (uint8_t *)(p); \
+ uint32_t lo_ = LO64(x), hi_ = HI64(x); \
+ STORE32_B(p_ + 0, hi_); STORE32_B(p_ + 4, lo_); \
+} while (0)
+#define SET64(z, hi, lo) ((z) = u64hilo((hi), (lo)))
+#define AND64(z, x, y) ((z) = u64and((x), (y)))
+#define OR64(z, x, y) ((z) = u64or((x), (y)))
+#define XOR64(z, x, y) ((z) = u64xor((x), (y)))
+#define CPL64(z, x) ((z) = u64not((x)))
+#define ROL64_(z, x, n) ((n) ? (z) = u64rol((x), (n)) : (x))
+
+#endif /* fake_mLib_bits_h */