summaryrefslogtreecommitdiff
path: root/benchmark/gc/ring.rb
diff options
context:
space:
mode:
authorgit <svn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-06-27 01:21:53 +0900
committergit <svn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-06-27 01:21:53 +0900
commitdf3c94712be83982301abaf49942052f0e6ae0fe (patch)
tree77fe50e517331744984fb9540b4de2807d640411 /benchmark/gc/ring.rb
parent72bfc52de67d774316ca872a036476aa51886ab0 (diff)
* 2019-06-27
Diffstat (limited to 'benchmark/gc/ring.rb')
0 files changed, 0 insertions, 0 deletions
le='width: 2.1%;'/> -rw-r--r--missing/crt_externs.h8
-rw-r--r--missing/crypt.c651
-rw-r--r--missing/crypt.h247
-rw-r--r--missing/des_tables.c1616
-rw-r--r--missing/dtoa.c3473
-rw-r--r--missing/dup2.c61
-rw-r--r--missing/erf.c28
-rw-r--r--missing/explicit_bzero.c91
-rw-r--r--missing/ffs.c49
-rw-r--r--missing/file.h5
-rw-r--r--missing/fileblocks.c1
-rw-r--r--missing/finite.c8
-rw-r--r--missing/flock.c37
-rw-r--r--missing/hypot.c4
-rw-r--r--missing/isinf.c72
-rw-r--r--missing/isnan.c17
-rw-r--r--missing/langinfo.c148
-rw-r--r--missing/lgamma_r.c80
-rw-r--r--missing/memcmp.c13
-rw-r--r--missing/memmove.c18
-rw-r--r--missing/mt19937.c158
-rw-r--r--missing/nan.c28
-rw-r--r--missing/nextafter.c77
-rw-r--r--missing/os2.c113
-rw-r--r--missing/procstat_vm.c85
-rw-r--r--missing/setproctitle.c176
-rw-r--r--missing/strcasecmp.c16
-rw-r--r--missing/strchr.c22
-rw-r--r--missing/strerror.c7
-rw-r--r--missing/strftime.c903
-rw-r--r--missing/strlcat.c56
-rw-r--r--missing/strlcpy.c51
-rw-r--r--missing/strncasecmp.c21
-rw-r--r--missing/strstr.c15
-rw-r--r--missing/strtod.c271
-rw-r--r--missing/strtol.c29
-rw-r--r--missing/strtoul.c184
-rw-r--r--missing/tgamma.c82
-rw-r--r--missing/vsnprintf.c1135
-rw-r--r--missing/x68.c40
-rw-r--r--missing/x86_64-chkstk.S10
45 files changed, 6934 insertions, 3289 deletions
diff --git a/missing/acosh.c b/missing/acosh.c
index ce8ace7b34..c6695b599e 100644
--- a/missing/acosh.c
+++ b/missing/acosh.c
@@ -2,8 +2,7 @@
acosh.c -
- $Author: eban $
- $Date: 2003/10/18 14:04:18 $
+ $Author$
created at: Fri Apr 12 00:34:17 JST 2002
public domain rewrite of acosh(3), asinh(3) and atanh(3)
@@ -13,6 +12,7 @@
#include <errno.h>
#include <float.h>
#include <math.h>
+#include "ruby.h"
/* DBL_MANT_DIG must be less than 4 times of bits of int */
#ifndef DBL_MANT_DIG
@@ -33,8 +33,7 @@
#ifndef HAVE_ACOSH
double
-acosh(x)
- double x;
+acosh(double x)
{
if (x < 1)
x = -1; /* NaN */
@@ -50,8 +49,7 @@ acosh(x)
#ifndef HAVE_ASINH
double
-asinh(x)
- double x;
+asinh(double x)
{
int neg = x < 0;
double z = fabs(x);
@@ -74,8 +72,7 @@ asinh(x)
#ifndef HAVE_ATANH
double
-atanh(x)
- double x;
+atanh(double x)
{
int neg = x < 0;
double z = fabs(x);
@@ -83,6 +80,14 @@ atanh(x)
if (z < SMALL_CRITERIA) return x;
z = log(z > 1 ? -1 : (1 + z) / (1 - z)) / 2;
if (neg) z = -z;
+ if (isinf(z))
+#if defined(ERANGE)
+ errno = ERANGE;
+#elif defined(EDOM)
+ errno = EDOM;
+#else
+ ;
+#endif
return z;
}
#endif
diff --git a/missing/alloca.c b/missing/alloca.c
index 39697f114a..d039dfc2cc 100644
--- a/missing/alloca.c
+++ b/missing/alloca.c
@@ -6,7 +6,7 @@
This implementation of the PWB library alloca() function,
which is used to allocate space off the run-time stack so
- that it is automatically reclaimed upon procedure exit,
+ that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
It should work under any C implementation that uses an
@@ -29,7 +29,11 @@
static char SCCSid[] = "@(#)alloca.c 1.1"; /* for the "what" utility */
#endif
-#include "config.h"
+#include "ruby/internal/config.h"
+#define X3J11 1 /* config.h should contain void if needed */
+
+#ifdef C_ALLOCA
+
#ifdef emacs
#ifdef static
/* actually, only want this if static is defined as ""
@@ -50,12 +54,12 @@ typedef void *pointer; /* generic pointer type */
typedef char *pointer; /* generic pointer type */
#endif /* X3J11 */
+#ifndef NULL
#define NULL 0 /* null pointer constant */
+#endif
-#ifdef RUBY_LIB
#define xmalloc ruby_xmalloc
#define xfree ruby_xfree
-#endif
extern void xfree();
extern pointer xmalloc();
@@ -192,3 +196,4 @@ alloca (size) /* returns pointer to storage */
}
}
+#endif
diff --git a/missing/cbrt.c b/missing/cbrt.c
new file mode 100644
index 0000000000..1bcbc63392
--- /dev/null
+++ b/missing/cbrt.c
@@ -0,0 +1,11 @@
+#include "ruby/missing.h"
+#include <math.h>
+
+double cbrt(double x)
+{
+ if (x < 0)
+ return -pow(-x, 1/3.0);
+ else
+ return pow(x, 1/3.0);
+}
+
diff --git a/missing/close.c b/missing/close.c
new file mode 100644
index 0000000000..831e75efe1
--- /dev/null
+++ b/missing/close.c
@@ -0,0 +1,72 @@
+/* Ignore ECONNRESET of FreeBSD */
+#include "ruby/missing.h"
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#undef getpeername
+int
+ruby_getpeername(int s, struct sockaddr * name,
+ socklen_t * namelen)
+{
+ int err = errno;
+ errno = 0;
+ s = getpeername(s, name, namelen);
+ if (errno == ECONNRESET) {
+ errno = 0;
+ s = 0;
+ }
+ else if (errno == 0)
+ errno = err;
+ return s;
+}
+
+#undef getsockname
+int
+ruby_getsockname(int s, struct sockaddr * name,
+ socklen_t * namelen)
+{
+ int err = errno;
+ errno = 0;
+ s = getsockname(s, name, namelen);
+ if (errno == ECONNRESET) {
+ errno = 0;
+ s = 0;
+ }
+ else if (errno == 0)
+ errno = err;
+ return s;
+}
+
+#undef shutdown
+int
+ruby_shutdown(int s, int how)
+{
+ int err = errno;
+ errno = 0;
+ s = shutdown(s, how);
+ if (errno == ECONNRESET) {
+ errno = 0;
+ s = 0;
+ }
+ else if (errno == 0)
+ errno = err;
+ return s;
+}
+
+#undef close
+int
+ruby_close(int s)
+{
+ int err = errno;
+ errno = 0;
+ s = close(s);
+ if (errno == ECONNRESET) {
+ errno = 0;
+ s = 0;
+ }
+ else if (errno == 0)
+ errno = err;
+ return s;
+}
diff --git a/missing/crt_externs.h b/missing/crt_externs.h
new file mode 100644
index 0000000000..cc96d46738
--- /dev/null
+++ b/missing/crt_externs.h
@@ -0,0 +1,8 @@
+#ifndef MISSING_CRT_EXTERNS_H
+#define MISSING_CRT_EXTERNS_H
+
+char ***_NSGetEnviron();
+#undef environ
+#define environ (*_NSGetEnviron())
+
+#endif
diff --git a/missing/crypt.c b/missing/crypt.c
index 486df5050b..f523aa51e6 100644
--- a/missing/crypt.c
+++ b/missing/crypt.c
@@ -34,6 +34,8 @@
static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include "ruby/missing.h"
+#include "crypt.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -42,10 +44,15 @@ static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93";
#include <pwd.h>
#endif
#include <stdio.h>
+#include <string.h>
#ifndef _PASSWORD_EFMT1
#define _PASSWORD_EFMT1 '_'
#endif
+#ifndef numberof
+#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
+#endif
+
/*
* UNIX password, and DES, encryption.
* By Tom Truscott, trt@rti.rti.org,
@@ -79,175 +86,22 @@ static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93";
#endif
#endif
-/*
- * define "LONG_IS_32_BITS" only if sizeof(long)==4.
- * This avoids use of bit fields (your compiler may be sloppy with them).
- */
-#if !defined(cray)
-#define LONG_IS_32_BITS
-#endif
-
-/*
- * define "B64" to be the declaration for a 64 bit integer.
- * XXX this feature is currently unused, see "endian" comment below.
- */
-#if defined(cray)
-#define B64 long
-#endif
-#if defined(convex)
-#define B64 long long
-#endif
-
-/*
- * define "LARGEDATA" to get faster permutations, by using about 72 kilobytes
- * of lookup tables. This speeds up des_setkey() and des_cipher(), but has
- * little effect on crypt().
- */
-#if defined(notdef)
-#define LARGEDATA
-#endif
-
-/* compile with "-DSTATIC=int" when profiling */
-#ifndef STATIC
-#define STATIC static
-#endif
-STATIC init_des(), init_perm(), permute();
-#ifdef DEBUG
-STATIC prtab();
-#endif
-
-/* ==================================== */
-
-/*
- * Cipher-block representation (Bob Baldwin):
- *
- * DES operates on groups of 64 bits, numbered 1..64 (sigh). One
- * representation is to store one bit per byte in an array of bytes. Bit N of
- * the NBS spec is stored as the LSB of the Nth byte (index N-1) in the array.
- * Another representation stores the 64 bits in 8 bytes, with bits 1..8 in the
- * first byte, 9..16 in the second, and so on. The DES spec apparently has
- * bit 1 in the MSB of the first byte, but that is particularly noxious so we
- * bit-reverse each byte so that bit 1 is the LSB of the first byte, bit 8 is
- * the MSB of the first byte. Specifically, the 64-bit input data and key are
- * converted to LSB format, and the output 64-bit block is converted back into
- * MSB format.
- *
- * DES operates internally on groups of 32 bits which are expanded to 48 bits
- * by permutation E and shrunk back to 32 bits by the S boxes. To speed up
- * the computation, the expansion is applied only once, the expanded
- * representation is maintained during the encryption, and a compression
- * permutation is applied only at the end. To speed up the S-box lookups,
- * the 48 bits are maintained as eight 6 bit groups, one per byte, which
- * directly feed the eight S-boxes. Within each byte, the 6 bits are the
- * most significant ones. The low two bits of each byte are zero. (Thus,
- * bit 1 of the 48 bit E expansion is stored as the "4"-valued bit of the
- * first byte in the eight byte representation, bit 2 of the 48 bit value is
- * the "8"-valued bit, and so on.) In fact, a combined "SPE"-box lookup is
- * used, in which the output is the 64 bit result of an S-box lookup which
- * has been permuted by P and expanded by E, and is ready for use in the next
- * iteration. Two 32-bit wide tables, SPE[0] and SPE[1], are used for this
- * lookup. Since each byte in the 48 bit path is a multiple of four, indexed
- * lookup of SPE[0] and SPE[1] is simple and fast. The key schedule and
- * "salt" are also converted to this 8*(6+2) format. The SPE table size is
- * 8*64*8 = 4K bytes.
- *
- * To speed up bit-parallel operations (such as XOR), the 8 byte
- * representation is "union"ed with 32 bit values "i0" and "i1", and, on
- * machines which support it, a 64 bit value "b64". This data structure,
- * "C_block", has two problems. First, alignment restrictions must be
- * honored. Second, the byte-order (e.g. little-endian or big-endian) of
- * the architecture becomes visible.
- *
- * The byte-order problem is unfortunate, since on the one hand it is good
- * to have a machine-independent C_block representation (bits 1..8 in the
- * first byte, etc.), and on the other hand it is good for the LSB of the
- * first byte to be the LSB of i0. We cannot have both these things, so we
- * currently use the "little-endian" representation and avoid any multi-byte
- * operations that depend on byte order. This largely precludes use of the
- * 64-bit datatype since the relative order of i0 and i1 are unknown. It
- * also inhibits grouping the SPE table to look up 12 bits at a time. (The
- * 12 bits can be stored in a 16-bit field with 3 low-order zeroes and 1
- * high-order zero, providing fast indexing into a 64-bit wide SPE.) On the
- * other hand, 64-bit datatypes are currently rare, and a 12-bit SPE lookup
- * requires a 128 kilobyte table, so perhaps this is not a big loss.
- *
- * Permutation representation (Jim Gillogly):
- *
- * A transformation is defined by its effect on each of the 8 bytes of the
- * 64-bit input. For each byte we give a 64-bit output that has the bits in
- * the input distributed appropriately. The transformation is then the OR
- * of the 8 sets of 64-bits. This uses 8*256*8 = 16K bytes of storage for
- * each transformation. Unless LARGEDATA is defined, however, a more compact
- * table is used which looks up 16 4-bit "chunks" rather than 8 8-bit chunks.
- * The smaller table uses 16*16*8 = 2K bytes for each transformation. This
- * is slower but tolerable, particularly for password encryption in which
- * the SPE transformation is iterated many times. The small tables total 9K
- * bytes, the large tables total 72K bytes.
- *
- * The transformations used are:
- * IE3264: MSB->LSB conversion, initial permutation, and expansion.
- * This is done by collecting the 32 even-numbered bits and applying
- * a 32->64 bit transformation, and then collecting the 32 odd-numbered
- * bits and applying the same transformation. Since there are only
- * 32 input bits, the IE3264 transformation table is half the size of
- * the usual table.
- * CF6464: Compression, final permutation, and LSB->MSB conversion.
- * This is done by two trivial 48->32 bit compressions to obtain
- * a 64-bit block (the bit numbering is given in the "CIFP" table)
- * followed by a 64->64 bit "cleanup" transformation. (It would
- * be possible to group the bits in the 64-bit block so that 2
- * identical 32->32 bit transformations could be used instead,
- * saving a factor of 4 in space and possibly 2 in time, but
- * byte-ordering and other complications rear their ugly head.
- * Similar opportunities/problems arise in the key schedule
- * transforms.)
- * PC1ROT: MSB->LSB, PC1 permutation, rotate, and PC2 permutation.
- * This admittedly baroque 64->64 bit transformation is used to
- * produce the first code (in 8*(6+2) format) of the key schedule.
- * PC2ROT[0]: Inverse PC2 permutation, rotate, and PC2 permutation.
- * It would be possible to define 15 more transformations, each
- * with a different rotation, to generate the entire key schedule.
- * To save space, however, we instead permute each code into the
- * next by using a transformation that "undoes" the PC2 permutation,
- * rotates the code, and then applies PC2. Unfortunately, PC2
- * transforms 56 bits into 48 bits, dropping 8 bits, so PC2 is not
- * invertible. We get around that problem by using a modified PC2
- * which retains the 8 otherwise-lost bits in the unused low-order
- * bits of each byte. The low-order bits are cleared when the
- * codes are stored into the key schedule.
- * PC2ROT[1]: Same as PC2ROT[0], but with two rotations.
- * This is faster than applying PC2ROT[0] twice,
- *
- * The Bell Labs "salt" (Bob Baldwin):
- *
- * The salting is a simple permutation applied to the 48-bit result of E.
- * Specifically, if bit i (1 <= i <= 24) of the salt is set then bits i and
- * i+24 of the result are swapped. The salt is thus a 24 bit number, with
- * 16777216 possible values. (The original salt was 12 bits and could not
- * swap bits 13..24 with 36..48.)
- *
- * It is possible, but ugly, to warp the SPE table to account for the salt
- * permutation. Fortunately, the conditional bit swapping requires only
- * about four machine instructions and can be done on-the-fly with about an
- * 8% performance penalty.
- */
-
-typedef union {
- unsigned char b[8];
- struct {
-#if defined(LONG_IS_32_BITS)
- /* long is often faster than a 32-bit bit field */
- long i0;
- long i1;
-#else
- long i0: 32;
- long i1: 32;
+#ifndef INIT_DES
+# if defined DUMP || defined NO_DES_TABLES
+# define INIT_DES 1
+# else
+# define INIT_DES 0
+# endif
#endif
- } b32;
-#if defined(B64)
- B64 b64;
+#if !INIT_DES
+# include "des_tables.c"
+# ifdef HAVE_DES_TABLES
+# define init_des() ((void)0)
+# else
+# undef INIT_DES
+# define INIT_DES 1
+# endif
#endif
-} C_block;
/*
* Convert twenty-four-bit long in host-order
@@ -255,59 +109,51 @@ typedef union {
*/
#define TO_SIX_BIT(rslt, src) { \
C_block cvt; \
- cvt.b[0] = src; src >>= 6; \
- cvt.b[1] = src; src >>= 6; \
- cvt.b[2] = src; src >>= 6; \
- cvt.b[3] = src; \
- rslt = (cvt.b32.i0 & 0x3f3f3f3fL) << 2; \
+ cvt.b[0] = (unsigned char)(src); (src) >>= 6; \
+ cvt.b[1] = (unsigned char)(src); (src) >>= 6; \
+ cvt.b[2] = (unsigned char)(src); (src) >>= 6; \
+ cvt.b[3] = (unsigned char)(src); \
+ (rslt) = (cvt.b32.i0 & 0x3f3f3f3fL) << 2; \
}
/*
* These macros may someday permit efficient use of 64-bit integers.
*/
-#define ZERO(d,d0,d1) d0 = 0, d1 = 0
-#define LOAD(d,d0,d1,bl) d0 = (bl).b32.i0, d1 = (bl).b32.i1
-#define LOADREG(d,d0,d1,s,s0,s1) d0 = s0, d1 = s1
-#define OR(d,d0,d1,bl) d0 |= (bl).b32.i0, d1 |= (bl).b32.i1
-#define STORE(s,s0,s1,bl) (bl).b32.i0 = s0, (bl).b32.i1 = s1
+#define ZERO(d,d0,d1) ((d0) = 0, (d1) = 0)
+#define LOAD(d,d0,d1,bl) ((d0) = (bl).b32.i0, (d1) = (bl).b32.i1)
+#define LOADREG(d,d0,d1,s,s0,s1) ((d0) = (s0), (d1) = (s1))
+#define OR(d,d0,d1,bl) ((d0) |= (bl).b32.i0, (d1) |= (bl).b32.i1)
+#define STORE(s,s0,s1,bl) ((bl).b32.i0 = (s0), (bl).b32.i1 = (s1))
#define DCL_BLOCK(d,d0,d1) long d0, d1
#if defined(LARGEDATA)
/* Waste memory like crazy. Also, do permutations in line */
-#define LGCHUNKBITS 3
-#define CHUNKBITS (1<<LGCHUNKBITS)
#define PERM6464(d,d0,d1,cpp,p) \
- LOAD(d,d0,d1,(p)[(0<<CHUNKBITS)+(cpp)[0]]); \
- OR (d,d0,d1,(p)[(1<<CHUNKBITS)+(cpp)[1]]); \
- OR (d,d0,d1,(p)[(2<<CHUNKBITS)+(cpp)[2]]); \
- OR (d,d0,d1,(p)[(3<<CHUNKBITS)+(cpp)[3]]); \
- OR (d,d0,d1,(p)[(4<<CHUNKBITS)+(cpp)[4]]); \
- OR (d,d0,d1,(p)[(5<<CHUNKBITS)+(cpp)[5]]); \
- OR (d,d0,d1,(p)[(6<<CHUNKBITS)+(cpp)[6]]); \
- OR (d,d0,d1,(p)[(7<<CHUNKBITS)+(cpp)[7]]);
+ LOAD((d),(d0),(d1),(p)[(0<<CHUNKBITS)+(cpp)[0]]); \
+ OR ((d),(d0),(d1),(p)[(1<<CHUNKBITS)+(cpp)[1]]); \
+ OR ((d),(d0),(d1),(p)[(2<<CHUNKBITS)+(cpp)[2]]); \
+ OR ((d),(d0),(d1),(p)[(3<<CHUNKBITS)+(cpp)[3]]); \
+ OR (d),(d0),(d1),(p)[(4<<CHUNKBITS)+(cpp)[4]]); \
+ OR (d),(d0),(d1),(p)[(5<<CHUNKBITS)+(cpp)[5]]); \
+ OR (d),(d0),(d1),(p)[(6<<CHUNKBITS)+(cpp)[6]]); \
+ OR (d),(d0),(d1),(p)[(7<<CHUNKBITS)+(cpp)[7]]);
#define PERM3264(d,d0,d1,cpp,p) \
- LOAD(d,d0,d1,(p)[(0<<CHUNKBITS)+(cpp)[0]]); \
- OR (d,d0,d1,(p)[(1<<CHUNKBITS)+(cpp)[1]]); \
- OR (d,d0,d1,(p)[(2<<CHUNKBITS)+(cpp)[2]]); \
- OR (d,d0,d1,(p)[(3<<CHUNKBITS)+(cpp)[3]]);
+ LOAD((d),(d0),(d1),(p)[(0<<CHUNKBITS)+(cpp)[0]]); \
+ OR ((d),(d0),(d1),(p)[(1<<CHUNKBITS)+(cpp)[1]]); \
+ OR ((d),(d0),(d1),(p)[(2<<CHUNKBITS)+(cpp)[2]]); \
+ OR ((d),(d0),(d1),(p)[(3<<CHUNKBITS)+(cpp)[3]]);
#else
/* "small data" */
-#define LGCHUNKBITS 2
-#define CHUNKBITS (1<<LGCHUNKBITS)
#define PERM6464(d,d0,d1,cpp,p) \
- { C_block tblk; permute(cpp,&tblk,p,8); LOAD (d,d0,d1,tblk); }
+ { C_block tblk; permute((cpp),&tblk,(p),8); LOAD ((d),(d0),(d1),tblk); }
#define PERM3264(d,d0,d1,cpp,p) \
- { C_block tblk; permute(cpp,&tblk,p,4); LOAD (d,d0,d1,tblk); }
-
-STATIC
-permute(cp, out, p, chars_in)
- unsigned char *cp;
- C_block *out;
- register C_block *p;
- int chars_in;
+ { C_block tblk; permute((cpp),&tblk,(p),4); LOAD ((d),(d0),(d1),tblk); }
+
+STATIC void
+permute(const unsigned char *cp, C_block *out, register const C_block *p, int chars_in)
{
register DCL_BLOCK(D,D0,D1);
- register C_block *tp;
+ register const C_block *tp;
register int t;
ZERO(D,D0,D1);
@@ -320,10 +166,14 @@ permute(cp, out, p, chars_in)
}
#endif /* LARGEDATA */
+#ifdef DEBUG
+STATIC void prtab(const char *s, const unsigned char *t, int num_rows);
+#endif
+#if INIT_DES
/* ===== (mostly) Standard DES Tables ==================== */
-static unsigned char IP[] = { /* initial permutation */
+static const unsigned char IP[] = { /* initial permutation */
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
@@ -336,7 +186,7 @@ static unsigned char IP[] = { /* initial permutation */
/* The final permutation is the inverse of IP - no table is necessary */
-static unsigned char ExpandTr[] = { /* expansion operation */
+static const unsigned char ExpandTr[] = { /* expansion operation */
32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13,
@@ -347,7 +197,7 @@ static unsigned char ExpandTr[] = { /* expansion operation */
28, 29, 30, 31, 32, 1,
};
-static unsigned char PC1[] = { /* permuted choice table 1 */
+static const unsigned char PC1[] = { /* permuted choice table 1 */
57, 49, 41, 33, 25, 17, 9,
1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27,
@@ -358,13 +208,15 @@ static unsigned char PC1[] = { /* permuted choice table 1 */
14, 6, 61, 53, 45, 37, 29,
21, 13, 5, 28, 20, 12, 4,
};
+#endif
-static unsigned char Rotates[] = { /* PC1 rotation schedule */
+static const unsigned char Rotates[] = { /* PC1 rotation schedule */
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1,
};
+#if INIT_DES
/* note: each "row" of PC2 is left-padded with bits that make it invertible */
-static unsigned char PC2[] = { /* permuted choice table 2 */
+static const unsigned char PC2[] = { /* permuted choice table 2 */
9, 18, 14, 17, 11, 24, 1, 5,
22, 25, 3, 28, 15, 6, 21, 10,
35, 38, 23, 19, 12, 4, 26, 8,
@@ -376,50 +228,66 @@ static unsigned char PC2[] = { /* permuted choice table 2 */
0, 0, 46, 42, 50, 36, 29, 32,
};
-static unsigned char S[8][64] = { /* 48->32 bit substitution tables */
+static const unsigned char S[8][64] = { /* 48->32 bit substitution tables */
+ {
/* S[1] */
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,
+ },
+ {
/* S[2] */
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
+ },
+ {
/* S[3] */
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
+ },
+ {
/* S[4] */
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
+ },
+ {
/* S[5] */
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
+ },
+ {
/* S[6] */
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
+ },
+ {
/* S[7] */
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
+ },
+ {
/* S[8] */
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11,
+ },
};
-static unsigned char P32Tr[] = { /* 32-bit permutation function */
+static const unsigned char P32Tr[] = { /* 32-bit permutation function */
16, 7, 20, 21,
29, 12, 28, 17,
1, 15, 23, 26,
@@ -430,7 +298,7 @@ static unsigned char P32Tr[] = { /* 32-bit permutation function */
22, 11, 4, 25,
};
-static unsigned char CIFP[] = { /* compressed/interleaved permutation */
+static const unsigned char CIFP[] = { /* compressed/interleaved permutation */
1, 2, 3, 4, 17, 18, 19, 20,
5, 6, 7, 8, 21, 22, 23, 24,
9, 10, 11, 12, 25, 26, 27, 28,
@@ -441,46 +309,91 @@ static unsigned char CIFP[] = { /* compressed/interleaved permutation */
41, 42, 43, 44, 57, 58, 59, 60,
45, 46, 47, 48, 61, 62, 63, 64,
};
+#endif
-static unsigned char itoa64[] = /* 0..63 => ascii-64 */
+static const unsigned char itoa64[] = /* 0..63 => ascii-64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+/* table that converts chars "./0-9A-Za-z"to integers 0-63. */
+static const unsigned char a64toi[256] = {
+#define A64TOI1(c) \
+ ((c) == '.' ? 0 : \
+ (c) == '/' ? 1 : \
+ ('0' <= (c) && (c) <= '9') ? (c) - '0' + 2 : \
+ ('A' <= (c) && (c) <= 'Z') ? (c) - 'A' + 12 : \
+ ('a' <= (c) && (c) <= 'z') ? (c) - 'a' + 38 : \
+ 0)
+#define A64TOI4(base) A64TOI1(base+0), A64TOI1(base+1), A64TOI1(base+2), A64TOI1(base+3)
+#define A64TOI16(base) A64TOI4(base+0), A64TOI4(base+4), A64TOI4(base+8), A64TOI4(base+12)
+#define A64TOI64(base) A64TOI16(base+0x00), A64TOI16(base+0x10), A64TOI16(base+0x20), A64TOI16(base+0x30)
+ A64TOI64(0x00), A64TOI64(0x40),
+ A64TOI64(0x00), A64TOI64(0x40),
+};
+#if INIT_DES
/* ===== Tables that are initialized at run time ==================== */
+typedef struct {
+ /* Initial key schedule permutation */
+ C_block PC1ROT[64/CHUNKBITS][1<<CHUNKBITS];
-static unsigned char a64toi[128]; /* ascii-64 => 0..63 */
+ /* Subsequent key schedule rotation permutations */
+ C_block PC2ROT[2][64/CHUNKBITS][1<<CHUNKBITS];
-/* Initial key schedule permutation */
-static C_block PC1ROT[64/CHUNKBITS][1<<CHUNKBITS];
+ /* Initial permutation/expansion table */
+ C_block IE3264[32/CHUNKBITS][1<<CHUNKBITS];
-/* Subsequent key schedule rotation permutations */
-static C_block PC2ROT[2][64/CHUNKBITS][1<<CHUNKBITS];
+ /* Table that combines the S, P, and E operations. */
+ unsigned long SPE[2][8][64];
-/* Initial permutation/expansion table */
-static C_block IE3264[32/CHUNKBITS][1<<CHUNKBITS];
+ /* compressed/interleaved => final permutation table */
+ C_block CF6464[64/CHUNKBITS][1<<CHUNKBITS];
-/* Table that combines the S, P, and E operations. */
-static long SPE[2][8][64];
+ int ready;
+} des_tables_t;
+static des_tables_t des_tables[1];
-/* compressed/interleaved => final permutation table */
-static C_block CF6464[64/CHUNKBITS][1<<CHUNKBITS];
+#define des_tables ((const des_tables_t *)des_tables)
+#define PC1ROT (des_tables->PC1ROT)
+#define PC2ROT (des_tables->PC2ROT)
+#define IE3264 (des_tables->IE3264)
+#define SPE (des_tables->SPE)
+#define CF6464 (des_tables->CF6464)
+STATIC void init_des(void);
+STATIC void init_perm(C_block perm[64/CHUNKBITS][1<<CHUNKBITS], unsigned char p[64], int chars_in, int chars_out);
+#endif
-/* ==================================== */
+static const C_block constdatablock = {{0}}; /* encryption constant */
+#define KS (data->KS)
+#define cryptresult (data->cryptresult)
-static C_block constdatablock; /* encryption constant */
-static char cryptresult[1+4+4+11+1]; /* encrypted result */
+static void des_setkey_r(const unsigned char *key, struct crypt_data *data);
+static void des_cipher_r(const unsigned char *in, unsigned char *out, long salt, int num_iter, struct crypt_data *data);
+#ifdef USE_NONREENTRANT_CRYPT
+static struct crypt_data default_crypt_data;
+#endif
+
+#ifdef USE_NONREENTRANT_CRYPT
/*
* Return a pointer to static data consisting of the "setting"
* followed by an encryption produced by the "key" and "setting".
*/
char *
-crypt(key, setting)
- register const char *key;
- register const char *setting;
+crypt(const char *key, const char *setting)
+{
+ return crypt_r(key, setting, &default_crypt_data);
+}
+#endif
+
+/*
+ * Return a pointer to data consisting of the "setting" followed by an
+ * encryption produced by the "key" and "setting".
+ */
+char *
+crypt_r(const char *key, const char *setting, struct crypt_data *data)
{
register char *encp;
register long i;
@@ -494,8 +407,7 @@ crypt(key, setting)
key++;
keyblock.b[i] = t;
}
- if (des_setkey((char *)keyblock.b)) /* also initializes "a64toi" */
- return (NULL);
+ des_setkey_r(keyblock.b, data); /* also initializes "a64toi" */
encp = &cryptresult[0];
switch (*setting) {
@@ -504,16 +416,13 @@ crypt(key, setting)
* Involve the rest of the password 8 characters at a time.
*/
while (*key) {
- if (des_cipher((char *)&keyblock,
- (char *)&keyblock, 0L, 1))
- return (NULL);
+ des_cipher_r(keyblock.b, keyblock.b, 0L, 1, data);
for (i = 0; i < 8; i++) {
if ((t = 2*(unsigned char)(*key)) != 0)
key++;
keyblock.b[i] ^= t;
}
- if (des_setkey((char *)keyblock.b))
- return (NULL);
+ des_setkey_r(keyblock.b, data);
}
*encp++ = *setting++;
@@ -543,9 +452,7 @@ crypt(key, setting)
salt = (salt<<6) | a64toi[t];
}
encp += salt_size;
- if (des_cipher((char *)&constdatablock, (char *)&rsltblock,
- salt, num_iter))
- return (NULL);
+ des_cipher_r(constdatablock.b, rsltblock.b, salt, num_iter, data);
/*
* Encode the 64 cipher bits as 11 ascii characters.
@@ -570,62 +477,48 @@ crypt(key, setting)
return (cryptresult);
}
-
-/*
- * The Key Schedule, filled in by des_setkey() or setkey().
- */
-#define KS_SIZE 16
-static C_block KS[KS_SIZE];
-
/*
* Set up the key schedule from the key.
*/
-des_setkey(key)
- register const char *key;
+static void
+des_setkey_r(const unsigned char *key, struct crypt_data *data)
{
register DCL_BLOCK(K, K0, K1);
- register C_block *ptabp;
+ register const C_block *ptabp;
register int i;
- static int des_ready = 0;
-
- if (!des_ready) {
- init_des();
- des_ready = 1;
+ C_block *ksp;
+
+ init_des();
+
+ PERM6464(K,K0,K1,key,PC1ROT[0]);
+ ksp = &KS[0];
+ STORE(K&~0x03030303L, K0&~0x03030303L, K1, *ksp);
+ for (i = 1; i < numberof(KS); i++) {
+ ksp++;
+ STORE(K,K0,K1,*ksp);
+ ptabp = PC2ROT[Rotates[i]-1][0];
+ PERM6464(K,K0,K1,ksp->b,ptabp);
+ STORE(K&~0x03030303L, K0&~0x03030303L, K1, *ksp);
}
-
- PERM6464(K,K0,K1,(unsigned char *)key,(C_block *)PC1ROT);
- key = (char *)&KS[0];
- STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key);
- for (i = 1; i < 16; i++) {
- key += sizeof(C_block);
- STORE(K,K0,K1,*(C_block *)key);
- ptabp = (C_block *)PC2ROT[Rotates[i]-1];
- PERM6464(K,K0,K1,(unsigned char *)key,ptabp);
- STORE(K&~0x03030303L, K0&~0x03030303L, K1, *(C_block *)key);
- }
- return (0);
}
/*
* Encrypt (or decrypt if num_iter < 0) the 8 chars at "in" with abs(num_iter)
- * iterations of DES, using the the given 24-bit salt and the pre-computed key
+ * iterations of DES, using the given 24-bit salt and the pre-computed key
* schedule, and store the resulting 8 chars at "out" (in == out is permitted).
*
* NOTE: the performance of this routine is critically dependent on your
* compiler and machine architecture.
*/
-des_cipher(in, out, salt, num_iter)
- const char *in;
- char *out;
- long salt;
- int num_iter;
+void
+des_cipher_r(const unsigned char *in, unsigned char *out, long salt, int num_iter, struct crypt_data *data)
{
/* variables that we want in registers, most important first */
#if defined(pdp11)
register int j;
#endif
- register long L0, L1, R0, R1, k;
- register C_block *kp;
+ register unsigned long L0, L1, R0, R1, k;
+ register const C_block *kp;
register int ks_inc, loop_count;
C_block B;
@@ -654,58 +547,58 @@ des_cipher(in, out, salt, num_iter)
R1 = (R1 >> 1) & 0x55555555L;
L1 = R0 | R1; /* L1 is the odd-numbered input bits */
STORE(L,L0,L1,B);
- PERM3264(L,L0,L1,B.b, (C_block *)IE3264); /* even bits */
- PERM3264(R,R0,R1,B.b+4,(C_block *)IE3264); /* odd bits */
+ PERM3264(L,L0,L1,B.b, IE3264[0]); /* even bits */
+ PERM3264(R,R0,R1,B.b+4,IE3264[0]); /* odd bits */
if (num_iter >= 0)
{ /* encryption */
kp = &KS[0];
- ks_inc = sizeof(*kp);
+ ks_inc = +1;
}
else
{ /* decryption */
num_iter = -num_iter;
kp = &KS[KS_SIZE-1];
- ks_inc = -sizeof(*kp);
+ ks_inc = -1;
}
while (--num_iter >= 0) {
loop_count = 8;
do {
-#define SPTAB(t, i) (*(long *)((unsigned char *)t + i*(sizeof(long)/4)))
+#define SPTAB(t, i) (*(const unsigned long *)((const unsigned char *)(t) + (i)*(sizeof(long)/4)))
#if defined(gould)
/* use this if B.b[i] is evaluated just once ... */
-#define DOXOR(x,y,i) x^=SPTAB(SPE[0][i],B.b[i]); y^=SPTAB(SPE[1][i],B.b[i]);
+#define DOXOR(x,y,i) (x)^=SPTAB(SPE[0][(i)],B.b[(i)]); (y)^=SPTAB(SPE[1][(i)],B.b[(i)]);
#else
#if defined(pdp11)
/* use this if your "long" int indexing is slow */
-#define DOXOR(x,y,i) j=B.b[i]; x^=SPTAB(SPE[0][i],j); y^=SPTAB(SPE[1][i],j);
+#define DOXOR(x,y,i) j=B.b[(i)]; (x)^=SPTAB(SPE[0][(i)],j); (y)^=SPTAB(SPE[1][(i)],j);
#else
/* use this if "k" is allocated to a register ... */
-#define DOXOR(x,y,i) k=B.b[i]; x^=SPTAB(SPE[0][i],k); y^=SPTAB(SPE[1][i],k);
+#define DOXOR(x,y,i) k=B.b[(i)]; (x)^=SPTAB(SPE[0][(i)],k); (y)^=SPTAB(SPE[1][(i)],k);
#endif
#endif
#define CRUNCH(p0, p1, q0, q1) \
- k = (q0 ^ q1) & SALT; \
- B.b32.i0 = k ^ q0 ^ kp->b32.i0; \
- B.b32.i1 = k ^ q1 ^ kp->b32.i1; \
- kp = (C_block *)((char *)kp+ks_inc); \
+ k = ((q0) ^ (q1)) & SALT; \
+ B.b32.i0 = k ^ (q0) ^ kp->b32.i0; \
+ B.b32.i1 = k ^ (q1) ^ kp->b32.i1; \
+ kp += ks_inc; \
\
- DOXOR(p0, p1, 0); \
- DOXOR(p0, p1, 1); \
- DOXOR(p0, p1, 2); \
- DOXOR(p0, p1, 3); \
- DOXOR(p0, p1, 4); \
- DOXOR(p0, p1, 5); \
- DOXOR(p0, p1, 6); \
- DOXOR(p0, p1, 7);
+ DOXOR((p0), (p1), 0); \
+ DOXOR((p0), (p1), 1); \
+ DOXOR((p0), (p1), 2); \
+ DOXOR((p0), (p1), 3); \
+ DOXOR((p0), (p1), 4); \
+ DOXOR((p0), (p1), 5); \
+ DOXOR((p0), (p1), 6); \
+ DOXOR((p0), (p1), 7);
CRUNCH(L0, L1, R0, R1);
CRUNCH(R0, R1, L0, L1);
} while (--loop_count != 0);
- kp = (C_block *)((char *)kp-(ks_inc*KS_SIZE));
+ kp -= (ks_inc*KS_SIZE);
/* swap L and R */
@@ -718,7 +611,7 @@ des_cipher(in, out, salt, num_iter)
L0 = ((L0 >> 3) & 0x0f0f0f0fL) | ((L1 << 1) & 0xf0f0f0f0L);
L1 = ((R0 >> 3) & 0x0f0f0f0fL) | ((R1 << 1) & 0xf0f0f0f0L);
STORE(L,L0,L1,B);
- PERM6464(L,L0,L1,B.b, (C_block *)CF6464);
+ PERM6464(L,L0,L1,B.b, CF6464[0]);
#if defined(MUST_ALIGN)
STORE(L,L0,L1,B);
out[0] = B.b[0]; out[1] = B.b[1]; out[2] = B.b[2]; out[3] = B.b[3];
@@ -726,27 +619,26 @@ des_cipher(in, out, salt, num_iter)
#else
STORE(L,L0,L1,*(C_block *)out);
#endif
- return (0);
}
+#undef des_tables
+#undef KS
+#undef cryptresult
+#if INIT_DES
/*
* Initialize various tables. This need only be done once. It could even be
* done at compile time, if the compiler were capable of that sort of thing.
*/
-STATIC
-init_des()
+STATIC void
+init_des(void)
{
register int i, j;
register long k;
register int tableno;
- static unsigned char perm[64], tmp32[32]; /* "static" for speed */
+ unsigned char perm[64], tmp32[32];
- /*
- * table that converts chars "./0-9A-Za-z"to integers 0-63.
- */
- for (i = 0; i < 64; i++)
- a64toi[itoa64[i]] = i;
+ if (des_tables->ready) return;
/*
* PC1ROT - bit reverse, then PC1, then Rotate, then PC2.
@@ -764,7 +656,7 @@ init_des()
k = (k|07) - (k&07);
k++;
}
- perm[i] = k;
+ perm[i] = (unsigned char)k;
}
#ifdef DEBUG
prtab("pc1tab", perm, 8);
@@ -811,7 +703,7 @@ init_des()
k = (k|07) - (k&07);
k++;
}
- perm[i*8+j] = k;
+ perm[i*8+j] = (unsigned char)k;
}
}
#ifdef DEBUG
@@ -857,7 +749,7 @@ init_des()
for (i = 0; i < 32; i++)
tmp32[i] = 0;
for (i = 0; i < 4; i++)
- tmp32[4 * tableno + i] = (k >> i) & 01;
+ tmp32[4 * tableno + i] = (unsigned char)(k >> i) & 01;
k = 0;
for (i = 24; --i >= 0; )
k = (k<<1) | tmp32[perm[i]-1];
@@ -868,6 +760,8 @@ init_des()
TO_SIX_BIT(SPE[1][tableno][j], k);
}
}
+
+ des_tables->ready = 1;
}
/*
@@ -878,11 +772,9 @@ init_des()
*
* "perm" must be all-zeroes on entry to this routine.
*/
-STATIC
-init_perm(perm, p, chars_in, chars_out)
- C_block perm[64/CHUNKBITS][1<<CHUNKBITS];
- unsigned char p[64];
- int chars_in, chars_out;
+STATIC void
+init_perm(C_block perm[64/CHUNKBITS][1<<CHUNKBITS],
+ unsigned char p[64], int chars_in, int chars_out)
{
register int i, j, k, l;
@@ -898,12 +790,21 @@ init_perm(perm, p, chars_in, chars_out)
}
}
}
+#endif
/*
* "setkey" routine (for backwards compatibility)
*/
-setkey(key)
- register const char *key;
+#ifdef USE_NONREENTRANT_CRYPT
+void
+setkey(const char *key)
+{
+ setkey_r(key, &default_crypt_data);
+}
+#endif
+
+void
+setkey_r(const char *key, struct crypt_data *data)
{
register int i, j, k;
C_block keyblock;
@@ -916,15 +817,22 @@ setkey(key)
}
keyblock.b[i] = k;
}
- return (des_setkey((char *)keyblock.b));
+ des_setkey_r(keyblock.b, data);
}
/*
* "encrypt" routine (for backwards compatibility)
*/
-encrypt(block, flag)
- register char *block;
- int flag;
+#ifdef USE_NONREENTRANT_CRYPT
+void
+encrypt(char *block, int flag)
+{
+ encrypt_r(block, flag, &default_crypt_data);
+}
+#endif
+
+void
+encrypt_r(char *block, int flag, struct crypt_data *data)
{
register int i, j, k;
C_block cblock;
@@ -937,8 +845,7 @@ encrypt(block, flag)
}
cblock.b[i] = k;
}
- if (des_cipher((char *)&cblock, (char *)&cblock, 0L, (flag ? -1: 1)))
- return (1);
+ des_cipher_r(cblock.b, cblock.b, 0L, (flag ? -1: 1), data);
for (i = 7; i >= 0; i--) {
k = cblock.b[i];
for (j = 7; j >= 0; j--) {
@@ -946,15 +853,11 @@ encrypt(block, flag)
k >>= 1;
}
}
- return (0);
}
#ifdef DEBUG
-STATIC
-prtab(s, t, num_rows)
- char *s;
- unsigned char *t;
- int num_rows;
+STATIC void
+prtab(const char *s, const unsigned char *t, int num_rows)
{
register int i, j;
@@ -968,3 +871,97 @@ prtab(s, t, num_rows)
(void)printf("\n");
}
#endif
+
+#ifdef DUMP
+void
+dump_block(const C_block *block)
+{
+ int i;
+ printf("{{");
+ for (i = 0; i < numberof(block->b); ++i) {
+ printf("%3d,", block->b[i]);
+ }
+ printf("}},\n");
+}
+
+int
+main(void)
+{
+ int i, j, k;
+ init_des();
+
+ printf("#ifndef HAVE_DES_TABLES\n\n");
+ printf("/* Initial key schedule permutation */\n");
+ printf("static const C_block PC1ROT[64/CHUNKBITS][1<<CHUNKBITS] = {\n");
+ for (i = 0; i < numberof(PC1ROT); ++i) {
+ printf("\t{\n");
+ for (j = 0; j < numberof(PC1ROT[0]); ++j) {
+ printf("\t\t");
+ dump_block(&PC1ROT[i][j]);
+ }
+ printf("\t},\n");
+ }
+ printf("};\n\n");
+
+ printf("/* Subsequent key schedule rotation permutations */\n");
+ printf("static const C_block PC2ROT[2][64/CHUNKBITS][1<<CHUNKBITS] = {\n");
+ for (i = 0; i < numberof(PC2ROT); ++i) {
+ printf("\t{\n");
+ for (j = 0; j < numberof(PC2ROT[0]); ++j) {
+ printf("\t\t{\n");
+ for (k = 0; k < numberof(PC2ROT[0][0]); ++k) {
+ printf("\t\t\t");
+ dump_block(&PC2ROT[i][j][k]);
+ }
+ printf("\t\t},\n");
+ }
+ printf("\t},\n");
+ }
+ printf("};\n\n");
+
+ printf("/* Initial permutation/expansion table */\n");
+ printf("static const C_block IE3264[32/CHUNKBITS][1<<CHUNKBITS] = {\n");
+ for (i = 0; i < numberof(IE3264); ++i) {
+ printf("\t{\n");
+ for (j = 0; j < numberof(IE3264[0]); ++j) {
+ printf("\t\t");
+ dump_block(&IE3264[i][j]);
+ }
+ printf("\t},\n");
+ }
+ printf("};\n\n");
+
+ printf("/* Table that combines the S, P, and E operations. */\n");
+ printf("static const unsigned long SPE[2][8][64] = {\n");
+ for (i = 0; i < numberof(SPE); ++i) {
+ printf("\t{\n");
+ for (j = 0; j < numberof(SPE[0]); ++j) {
+ int r = 0;
+ printf("\t\t{");
+ for (k = 0; k < numberof(SPE[0][0]); ++k) {
+ if (r == 0) printf("\n\t\t\t");
+ printf("%#10lx,", SPE[i][j][k]);
+ if (++r == 4) r = 0;
+ }
+ printf("\n\t\t},\n");
+ }
+ printf("\t},\n");
+ }
+ printf("};\n\n");
+
+ printf("/* compressed/interleaved => final permutation table */\n");
+ printf("static const C_block CF6464[64/CHUNKBITS][1<<CHUNKBITS] = {\n");
+ for (i = 0; i < numberof(CF6464); ++i) {
+ printf("\t{\n");
+ for (j = 0; j < numberof(CF6464[0]); ++j) {
+ printf("\t\t");
+ dump_block(&CF6464[i][j]);
+ }
+ printf("\t},\n");
+ }
+ printf("};\n\n");
+ printf("#define HAVE_DES_TABLES 1\n""#endif\n");
+
+ return 0;
+}
+#endif
diff --git a/missing/crypt.h b/missing/crypt.h
new file mode 100644
index 0000000000..ff135eee93
--- /dev/null
+++ b/missing/crypt.h
@@ -0,0 +1,247 @@
+#ifndef CRYPT_H
+#define CRYPT_H 1
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Tom Truscott.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* ===== Configuration ==================== */
+
+#ifdef CHAR_BITS
+#if CHAR_BITS != 8
+ #error C_block structure assumes 8 bit characters
+#endif
+#endif
+
+#ifndef LONG_LONG
+# if SIZEOF_LONG_LONG > 0
+# define LONG_LONG long long
+# elif SIZEOF___INT64 > 0
+# define HAVE_LONG_LONG 1
+# define LONG_LONG __int64
+# undef SIZEOF_LONG_LONG
+# define SIZEOF_LONG_LONG SIZEOF___INT64
+# endif
+#endif
+
+/*
+ * define "LONG_IS_32_BITS" only if sizeof(long)==4.
+ * This avoids use of bit fields (your compiler may be sloppy with them).
+ */
+#if SIZEOF_LONG == 4
+#define LONG_IS_32_BITS
+#endif
+
+/*
+ * define "B64" to be the declaration for a 64 bit integer.
+ * XXX this feature is currently unused, see "endian" comment below.
+ */
+#if SIZEOF_LONG == 8
+#define B64 long
+#elif SIZEOF_LONG_LONG == 8
+#define B64 LONG_LONG
+#endif
+
+/*
+ * define "LARGEDATA" to get faster permutations, by using about 72 kilobytes
+ * of lookup tables. This speeds up des_setkey() and des_cipher(), but has
+ * little effect on crypt().
+ */
+#if defined(notdef)
+#define LARGEDATA
+#endif
+
+/* compile with "-DSTATIC=int" when profiling */
+#ifndef STATIC
+#define STATIC static
+#endif
+
+/* ==================================== */
+
+/*
+ * Cipher-block representation (Bob Baldwin):
+ *
+ * DES operates on groups of 64 bits, numbered 1..64 (sigh). One
+ * representation is to store one bit per byte in an array of bytes. Bit N of
+ * the NBS spec is stored as the LSB of the Nth byte (index N-1) in the array.
+ * Another representation stores the 64 bits in 8 bytes, with bits 1..8 in the
+ * first byte, 9..16 in the second, and so on. The DES spec apparently has
+ * bit 1 in the MSB of the first byte, but that is particularly noxious so we
+ * bit-reverse each byte so that bit 1 is the LSB of the first byte, bit 8 is
+ * the MSB of the first byte. Specifically, the 64-bit input data and key are
+ * converted to LSB format, and the output 64-bit block is converted back into
+ * MSB format.
+ *
+ * DES operates internally on groups of 32 bits which are expanded to 48 bits
+ * by permutation E and shrunk back to 32 bits by the S boxes. To speed up
+ * the computation, the expansion is applied only once, the expanded
+ * representation is maintained during the encryption, and a compression
+ * permutation is applied only at the end. To speed up the S-box lookups,
+ * the 48 bits are maintained as eight 6 bit groups, one per byte, which
+ * directly feed the eight S-boxes. Within each byte, the 6 bits are the
+ * most significant ones. The low two bits of each byte are zero. (Thus,
+ * bit 1 of the 48 bit E expansion is stored as the "4"-valued bit of the
+ * first byte in the eight byte representation, bit 2 of the 48 bit value is
+ * the "8"-valued bit, and so on.) In fact, a combined "SPE"-box lookup is
+ * used, in which the output is the 64 bit result of an S-box lookup which
+ * has been permuted by P and expanded by E, and is ready for use in the next
+ * iteration. Two 32-bit wide tables, SPE[0] and SPE[1], are used for this
+ * lookup. Since each byte in the 48 bit path is a multiple of four, indexed
+ * lookup of SPE[0] and SPE[1] is simple and fast. The key schedule and
+ * "salt" are also converted to this 8*(6+2) format. The SPE table size is
+ * 8*64*8 = 4K bytes.
+ *
+ * To speed up bit-parallel operations (such as XOR), the 8 byte
+ * representation is "union"ed with 32 bit values "i0" and "i1", and, on
+ * machines which support it, a 64 bit value "b64". This data structure,
+ * "C_block", has two problems. First, alignment restrictions must be
+ * honored. Second, the byte-order (e.g. little-endian or big-endian) of
+ * the architecture becomes visible.
+ *
+ * The byte-order problem is unfortunate, since on the one hand it is good
+ * to have a machine-independent C_block representation (bits 1..8 in the
+ * first byte, etc.), and on the other hand it is good for the LSB of the
+ * first byte to be the LSB of i0. We cannot have both these things, so we
+ * currently use the "little-endian" representation and avoid any multi-byte
+ * operations that depend on byte order. This largely precludes use of the
+ * 64-bit datatype since the relative order of i0 and i1 are unknown. It
+ * also inhibits grouping the SPE table to look up 12 bits at a time. (The
+ * 12 bits can be stored in a 16-bit field with 3 low-order zeroes and 1
+ * high-order zero, providing fast indexing into a 64-bit wide SPE.) On the
+ * other hand, 64-bit datatypes are currently rare, and a 12-bit SPE lookup
+ * requires a 128 kilobyte table, so perhaps this is not a big loss.
+ *
+ * Permutation representation (Jim Gillogly):
+ *
+ * A transformation is defined by its effect on each of the 8 bytes of the
+ * 64-bit input. For each byte we give a 64-bit output that has the bits in
+ * the input distributed appropriately. The transformation is then the OR
+ * of the 8 sets of 64-bits. This uses 8*256*8 = 16K bytes of storage for
+ * each transformation. Unless LARGEDATA is defined, however, a more compact
+ * table is used which looks up 16 4-bit "chunks" rather than 8 8-bit chunks.
+ * The smaller table uses 16*16*8 = 2K bytes for each transformation. This
+ * is slower but tolerable, particularly for password encryption in which
+ * the SPE transformation is iterated many times. The small tables total 9K
+ * bytes, the large tables total 72K bytes.
+ *
+ * The transformations used are:
+ * IE3264: MSB->LSB conversion, initial permutation, and expansion.
+ * This is done by collecting the 32 even-numbered bits and applying
+ * a 32->64 bit transformation, and then collecting the 32 odd-numbered
+ * bits and applying the same transformation. Since there are only
+ * 32 input bits, the IE3264 transformation table is half the size of
+ * the usual table.
+ * CF6464: Compression, final permutation, and LSB->MSB conversion.
+ * This is done by two trivial 48->32 bit compressions to obtain
+ * a 64-bit block (the bit numbering is given in the "CIFP" table)
+ * followed by a 64->64 bit "cleanup" transformation. (It would
+ * be possible to group the bits in the 64-bit block so that 2
+ * identical 32->32 bit transformations could be used instead,
+ * saving a factor of 4 in space and possibly 2 in time, but
+ * byte-ordering and other complications rear their ugly head.
+ * Similar opportunities/problems arise in the key schedule
+ * transforms.)
+ * PC1ROT: MSB->LSB, PC1 permutation, rotate, and PC2 permutation.
+ * This admittedly baroque 64->64 bit transformation is used to
+ * produce the first code (in 8*(6+2) format) of the key schedule.
+ * PC2ROT[0]: Inverse PC2 permutation, rotate, and PC2 permutation.
+ * It would be possible to define 15 more transformations, each
+ * with a different rotation, to generate the entire key schedule.
+ * To save space, however, we instead permute each code into the
+ * next by using a transformation that "undoes" the PC2 permutation,
+ * rotates the code, and then applies PC2. Unfortunately, PC2
+ * transforms 56 bits into 48 bits, dropping 8 bits, so PC2 is not
+ * invertible. We get around that problem by using a modified PC2
+ * which retains the 8 otherwise-lost bits in the unused low-order
+ * bits of each byte. The low-order bits are cleared when the
+ * codes are stored into the key schedule.
+ * PC2ROT[1]: Same as PC2ROT[0], but with two rotations.
+ * This is faster than applying PC2ROT[0] twice,
+ *
+ * The Bell Labs "salt" (Bob Baldwin):
+ *
+ * The salting is a simple permutation applied to the 48-bit result of E.
+ * Specifically, if bit i (1 <= i <= 24) of the salt is set then bits i and
+ * i+24 of the result are swapped. The salt is thus a 24 bit number, with
+ * 16777216 possible values. (The original salt was 12 bits and could not
+ * swap bits 13..24 with 36..48.)
+ *
+ * It is possible, but ugly, to warp the SPE table to account for the salt
+ * permutation. Fortunately, the conditional bit swapping requires only
+ * about four machine instructions and can be done on-the-fly with about an
+ * 8% performance penalty.
+ */
+
+typedef union {
+ unsigned char b[8];
+ struct {
+#if defined(LONG_IS_32_BITS)
+ /* long is often faster than a 32-bit bit field */
+ long i0;
+ long i1;
+#else
+ long i0: 32;
+ long i1: 32;
+#endif
+ } b32;
+#if defined(B64)
+ B64 b64;
+#endif
+} C_block;
+
+#if defined(LARGEDATA)
+ /* Waste memory like crazy. Also, do permutations in line */
+#define LGCHUNKBITS 3
+#define CHUNKBITS (1<<LGCHUNKBITS)
+#else
+ /* "small data" */
+#define LGCHUNKBITS 2
+#define CHUNKBITS (1<<LGCHUNKBITS)
+#endif
+
+struct crypt_data {
+ /* The Key Schedule, filled in by des_setkey() or setkey(). */
+#define KS_SIZE 16
+ C_block KS[KS_SIZE];
+
+ /* ==================================== */
+
+ char cryptresult[1+4+4+11+1]; /* encrypted result */
+};
+
+char *crypt(const char *key, const char *setting);
+void setkey(const char *key);
+void encrypt(char *block, int flag);
+
+char *crypt_r(const char *key, const char *setting, struct crypt_data *data);
+void setkey_r(const char *key, struct crypt_data *data);
+void encrypt_r(char *block, int flag, struct crypt_data *data);
+
+#endif /* CRYPT_H */
diff --git a/missing/des_tables.c b/missing/des_tables.c
new file mode 100644
index 0000000000..ab6b1d1883
--- /dev/null
+++ b/missing/des_tables.c
@@ -0,0 +1,1616 @@
+#ifndef HAVE_DES_TABLES
+
+/* Initial key schedule permutation */
+static const C_block PC1ROT[64/CHUNKBITS][1<<CHUNKBITS] = {
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 1, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 1, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 1, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 1, 0, 0, 0, 0,}},
+ {{ 0, 0, 1, 1, 0, 0, 0, 0,}},
+ {{ 0, 0, 1, 1, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 0, 0, 16, 0, 0,}},
+ {{ 0, 0, 0, 0, 0, 16, 0, 0,}},
+ {{ 0, 0, 1, 0, 0, 16, 0, 0,}},
+ {{ 0, 0, 1, 0, 0, 16, 0, 0,}},
+ {{ 0, 0, 0, 1, 0, 16, 0, 0,}},
+ {{ 0, 0, 0, 1, 0, 16, 0, 0,}},
+ {{ 0, 0, 1, 1, 0, 16, 0, 0,}},
+ {{ 0, 0, 1, 1, 0, 16, 0, 0,}},
+ },
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 0,128, 0, 0, 0,}},
+ {{ 0, 0, 4, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 4, 0,128, 0, 0, 0,}},
+ {{ 0, 16, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 16, 0, 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}},
+ {{ 0, 0,128, 0, 0, 0, 0, 0,}},
+ {{ 32, 0,128, 0, 0, 0, 0, 0,}},
+ {{ 0, 0,128, 4, 0, 0, 0, 0,}},
+ {{ 32, 0,128, 4, 0, 0, 0, 0,}},
+ {{ 0, 8, 0, 0, 0, 0, 0, 0,}},
+ {{ 32, 8, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 8, 0, 4, 0, 0, 0, 0,}},
+ {{ 32, 8, 0, 4, 0, 0, 0, 0,}},
+ {{ 0, 8,128, 0, 0, 0, 0, 0,}},
+ {{ 32, 8,128, 0, 0, 0, 0, 0,}},
+ {{ 0, 8,128, 4, 0, 0, 0, 0,}},
+ {{ 32, 8,128, 4, 0, 0, 0, 0,}},
+ },
+};
+
+/* Subsequent key schedule rotation permutations */
+static const C_block PC2ROT[2][64/CHUNKBITS][1<<CHUNKBITS] = {
+ {
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 0,128, 0, 0, 0, 0, 0,}},
+ {{ 8, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 8, 0,128, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 64, 0, 0, 0, 0,}},
+ {{ 0, 0,128, 64, 0, 0, 0, 0,}},
+ {{ 8, 0, 0, 64, 0, 0, 0, 0,}},
+ {{ 8, 0,128, 64, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 4, 0, 0, 0, 0,}},
+ {{ 0, 0,128, 4, 0, 0, 0, 0,}},
+ {{ 8, 0, 0, 4, 0, 0, 0, 0,}},
+ {{ 8, 0,128, 4, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 68, 0, 0, 0, 0,}},
+ {{ 0, 0,128, 68, 0, 0, 0, 0,}},
+ {{ 8, 0, 0, 68, 0, 0, 0, 0,}},
+ {{ 8, 0,128, 68, 0, 0, 0, 0,}},
+ },
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0,128, 0, 0, 0, 0, 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
+ {{ 0, 0, 0, 0, 0, 8, 4, 0,}},
+ {{ 0, 0, 0, 0, 0, 8, 4, 0,}},
+ },
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 0, 0,128, 0, 0,}},
+ {{ 0, 0, 0, 0, 0, 0, 64, 0,}},
+ {{ 0, 0, 0, 0, 0,128, 64, 0,}},
+ {{ 0, 0, 0, 0,128, 0, 0, 0,}},
+ {{ 0, 0, 0, 0,128,128, 0, 0,}},
+ {{ 0, 0, 0, 0,128, 0, 64, 0,}},
+ {{ 0, 0, 0, 0,128,128, 64, 0,}},
+ {{ 0, 0, 0, 0, 0, 4, 0, 0,}},
+ {{ 0, 0, 0, 0, 0,132, 0, 0,}},
+ {{ 0, 0, 0, 0, 0, 4, 64, 0,}},
+ {{ 0, 0, 0, 0, 0,132, 64, 0,}},
+ {{ 0, 0, 0, 0,128, 4, 0, 0,}},
+ {{ 0, 0, 0, 0,128,132, 0, 0,}},
+ {{ 0, 0, 0, 0,128, 4, 64, 0,}},
+ {{ 0, 0, 0, 0,128,132, 64, 0,}},
+ },
+ },
+};
+
+/* Initial permutation/expansion table */
+static const C_block IE3264[32/CHUNKBITS][1<<CHUNKBITS] = {
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0, 0, 0, 0, 0, 0, 64, 4,}},
+ {{ 4, 0, 0, 0, 0, 0, 0, 64,}},
+ {{ 4, 0, 0, 0, 0, 0, 64, 68,}},
+ {{ 0, 0, 0, 0, 64, 4, 0, 0,}},
+ {{ 0, 0, 0, 0, 64, 4, 64, 4,}},
+ {{ 4, 0, 0, 0, 64, 4, 0, 64,}},
+ {{ 4, 0, 0, 0, 64, 4, 64, 68,}},
+ {{ 0, 0, 0, 0, 0, 64, 4, 0,}},
+ {{ 0, 0, 0, 0, 0, 64, 68, 4,}},
+ {{ 4, 0, 0, 0, 0, 64, 4, 64,}},
+ {{ 4, 0, 0, 0, 0, 64, 68, 68,}},
+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{{ 0, 0, 0, 0,128,136,136, 8,}},
+ {{ 0, 0, 0,128,136, 8, 0, 0,}},
+ {{ 0, 0, 0,128,136,136, 8, 0,}},
+ {{ 0, 0, 0,128,136, 8,128, 8,}},
+ {{ 0, 0, 0,128,136,136,136, 8,}},
+ },
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0, 0,}},
+ {{ 0,128, 8, 0, 0, 0, 0, 0,}},
+ {{ 0, 0,128, 8, 0, 0, 0, 0,}},
+ {{ 0,128,136, 8, 0, 0, 0, 0,}},
+ {{ 8, 0, 0, 0, 0, 0, 0,128,}},
+ {{ 8,128, 8, 0, 0, 0, 0,128,}},
+ {{ 8, 0,128, 8, 0, 0, 0,128,}},
+ {{ 8,128,136, 8, 0, 0, 0,128,}},
+ {{128, 8, 0, 0, 0, 0, 0, 0,}},
+ {{128,136, 8, 0, 0, 0, 0, 0,}},
+ {{128, 8,128, 8, 0, 0, 0, 0,}},
+ {{128,136,136, 8, 0, 0, 0, 0,}},
+ {{136, 8, 0, 0, 0, 0, 0,128,}},
+ {{136,136, 8, 0, 0, 0, 0,128,}},
+ {{136, 8,128, 8, 0, 0, 0,128,}},
+ {{136,136,136, 8, 0, 0, 0,128,}},
+ },
+};
+
+/* Table that combines the S, P, and E operations. */
+static const unsigned long SPE[2][8][64] = {
+ {
+ {
+ 0x80088000,0x80000000, 0,0x80088000,
+ 0,0x80088000,0x80000000, 0,
+ 0x80088000,0x80088000,0x80000000, 0x88000,
+ 0x88000, 0, 0,0x80000000,
+ 0x80000000, 0, 0x88000,0x80088000,
+ 0x80088000,0x80000000, 0x88000, 0x88000,
+ 0, 0x88000,0x80088000,0x80000000,
+ 0x88000, 0x88000,0x80000000, 0,
+ 0,0x80088000, 0x88000,0x80000000,
+ 0x80088000,0x80000000, 0x88000, 0x88000,
+ 0x80000000, 0x88000,0x80088000, 0,
+ 0x80088000, 0, 0,0x80000000,
+ 0x80088000,0x80088000,0x80000000, 0x88000,
+ 0, 0x88000,0x80000000, 0,
+ 0x80000000, 0, 0x88000,0x80088000,
+ 0,0x80000000, 0x88000,0x80088000,
+ },
+ {
+ 0x8800010, 0, 0x8800000, 0,
+ 0x10, 0x8800010, 0x8800000, 0x8800000,
+ 0x8800000, 0x10, 0x10, 0x8800000,
+ 0x10, 0x8800000, 0, 0x10,
+ 0, 0x8800010, 0x10, 0x8800000,
+ 0x8800010, 0, 0, 0x10,
+ 0x8800010, 0x8800010, 0x8800000, 0x10,
+ 0, 0, 0x8800010, 0x8800010,
+ 0x10, 0x8800000, 0x8800000, 0x8800010,
+ 0x8800010, 0x10, 0x10, 0,
+ 0, 0x8800010, 0, 0x10,
+ 0x8800000, 0, 0x8800010, 0x8800010,
+ 0x8800000, 0x8800000, 0, 0x10,
+ 0x10, 0x8800010, 0x8800000, 0,
+ 0x10, 0, 0x8800010, 0x8800000,
+ 0x8800010, 0x10, 0, 0x8800000,
+ },
+ {
+ 0,0x40001000, 0x1000, 0x1000,
+ 0x40000000, 0, 0x1000,0x40001000,
+ 0x1000,0x40000000,0x40000000, 0,
+ 0x40001000, 0x1000, 0,0x40000000,
+ 0,0x40000000,0x40001000, 0x1000,
+ 0x1000,0x40001000,0x40000000, 0,
+ 0x40000000, 0x1000,0x40001000,0x40000000,
+ 0x40001000, 0, 0,0x40001000,
+ 0x40001000, 0x1000, 0,0x40000000,
+ 0x1000,0x40000000,0x40000000, 0x1000,
+ 0,0x40001000,0x40001000,0x40000000,
+ 0x40000000, 0,0x40001000, 0,
+ 0x40001000, 0, 0,0x40001000,
+ 0x40000000, 0x1000, 0x1000,0x40001000,
+ 0x1000, 0,0x40000000, 0x1000,
+ 0,0x40001000, 0x1000,0x40000000,
+ },
+ {
+ 0x100008, 0x100000, 0x8, 0x100008,
+ 0, 0, 0x100008, 0x8,
+ 0x100000, 0x8, 0, 0x100008,
+ 0x8, 0x100008, 0, 0,
+ 0x8, 0x100000, 0x100000, 0x8,
+ 0x100000, 0x100008, 0, 0x100000,
+ 0x100008, 0, 0x8, 0x100000,
+ 0x100000, 0x8, 0x100008, 0,
+ 0x8, 0x100008, 0, 0x8,
+ 0x100000, 0x100000, 0x8, 0,
+ 0x100008, 0, 0x100000, 0x8,
+ 0, 0x8, 0x100000, 0x100000,
+ 0, 0x100008, 0x100008, 0,
+ 0x100008, 0x8, 0x100000, 0x100008,
+ 0x8, 0x100000, 0, 0x100008,
+ 0x100008, 0, 0x8, 0x100000,
+ },
+ {
+ 0,0x10000000, 0x44000,0x10044020,
+ 0x10000020, 0x44000,0x10044020,0x10000000,
+ 0x10000000, 0x20, 0x20,0x10044000,
+ 0x44020,0x10000020,0x10044000, 0,
+ 0x10044000, 0,0x10000020, 0x44020,
+ 0x44000,0x10044020, 0, 0x20,
+ 0x20, 0x44020,0x10044020,0x10000020,
+ 0x10000000, 0x44000, 0x44020,0x10044000,
+ 0x10044000, 0x44020,0x10000020,0x10000000,
+ 0x10000000, 0x20, 0x20, 0x44000,
+ 0,0x10044000,0x10044020, 0,
+ 0x10044020, 0, 0x44000,0x10000020,
+ 0x44020, 0x44000, 0,0x10044020,
+ 0x10000020,0x10044000, 0x44020,0x10000000,
+ 0x10044000,0x10000020, 0x44000, 0x44020,
+ 0x20,0x10044020,0x10000000, 0x20,
+ },
+ {
+ 0x440, 0x440, 0, 0x200000,
+ 0x440, 0x200000, 0x200440, 0,
+ 0x200440, 0x200440, 0x200000, 0,
+ 0x200000, 0x440, 0, 0x200440,
+ 0, 0x200440, 0x440, 0,
+ 0x200000, 0x440, 0x200000, 0x440,
+ 0x200440, 0, 0, 0x200440,
+ 0x440, 0x200000, 0x200440, 0x200000,
+ 0x200440, 0, 0x200000, 0x200440,
+ 0x200000, 0x440, 0, 0x200000,
+ 0, 0x200000, 0x440, 0,
+ 0x440, 0x200440, 0x200000, 0x440,
+ 0x200440, 0x200000, 0, 0x200440,
+ 0x440, 0, 0x200440, 0,
+ 0x200000, 0x440, 0x200440, 0x200000,
+ 0, 0x200440, 0x440, 0x440,
+ },
+ {
+ 0x4400000, 0x2000, 0x2000, 0x4,
+ 0x4402004, 0x4400004, 0x4402000, 0,
+ 0, 0x2004, 0x2004, 0x4400000,
+ 0x4, 0x4402000, 0x4400000, 0x2004,
+ 0x2004, 0x4400000, 0x4400004, 0x4402004,
+ 0, 0x2000, 0x4, 0x4402000,
+ 0x4400004, 0x4402004, 0x4402000, 0x4,
+ 0x4402004, 0x4400004, 0x2000, 0,
+ 0x4402004, 0x4400000, 0x4400004, 0x2004,
+ 0x4400000, 0x2000, 0, 0x4400004,
+ 0x2004, 0x4402004, 0x4402000, 0,
+ 0x2000, 0x4, 0x4, 0x2000,
+ 0, 0x2004, 0x2000, 0x4402000,
+ 0x2004, 0x4400000, 0x4402004, 0,
+ 0x4402000, 0x4, 0x4400004, 0x4402004,
+ 0x4, 0x4402000, 0x4400000, 0x4400004,
+ },
+ {
+ 0x880,0x20000000,0x20000880, 0,
+ 0x20000000, 0x880, 0,0x20000880,
+ 0x880, 0,0x20000000,0x20000880,
+ 0x20000880,0x20000880, 0x880, 0,
+ 0x20000000,0x20000880, 0x880,0x20000000,
+ 0x20000880, 0x880, 0,0x20000000,
+ 0, 0,0x20000880, 0x880,
+ 0,0x20000000,0x20000000, 0x880,
+ 0,0x20000000, 0x880,0x20000880,
+ 0x20000880, 0, 0,0x20000000,
+ 0x880,0x20000880,0x20000000, 0x880,
+ 0x20000000, 0x880, 0x880,0x20000000,
+ 0x20000880, 0, 0, 0x880,
+ 0x20000000,0x20000880,0x20000880, 0,
+ 0x880,0x20000000,0x20000880, 0,
+ 0, 0x880,0x20000000,0x20000880,
+ },
+ },
+ {
+ {
+ 0x2008, 0x8,0x20002000,0x20002008,
+ 0x2000,0x20000008,0x20000008,0x20002000,
+ 0x20000008, 0x2008, 0x2008,0x20000000,
+ 0x20002000, 0x2000, 0,0x20000008,
+ 0x8,0x20000000, 0x2000, 0x8,
+ 0x20002008, 0x2008,0x20000000, 0x2000,
+ 0x20000000, 0, 0x8,0x20002008,
+ 0,0x20002000,0x20002008, 0,
+ 0,0x20002008, 0x2000,0x20000008,
+ 0x2008, 0x8,0x20000000, 0x2000,
+ 0x20002008, 0, 0x8,0x20002000,
+ 0x20000008,0x20000000,0x20002000, 0x2008,
+ 0x20002008, 0x8, 0x2008,0x20002000,
+ 0x2000,0x20000000,0x20000008, 0,
+ 0x8, 0x2000,0x20002000, 0x2008,
+ 0x20000000,0x20002008, 0,0x20000008,
+ },
+ {
+ 0x4400010, 0, 0x10, 0x4400010,
+ 0x4400000, 0, 0x4400000, 0x10,
+ 0, 0x4400010, 0, 0x4400000,
+ 0x10, 0x4400010, 0x4400010, 0,
+ 0x10, 0x4400000, 0x4400010, 0,
+ 0x10, 0x4400000, 0, 0x10,
+ 0x4400000, 0x10, 0x4400010, 0x4400000,
+ 0x4400000, 0x10, 0, 0x4400010,
+ 0x10, 0x4400010, 0x4400000, 0x10,
+ 0x4400010, 0x10, 0x4400000, 0,
+ 0x4400000, 0, 0x10, 0x4400010,
+ 0, 0x4400000, 0x10, 0x4400000,
+ 0x4400010, 0, 0, 0x4400000,
+ 0, 0x4400010, 0x10, 0x4400010,
+ 0x4400010, 0x10, 0, 0x4400000,
+ 0x4400000, 0, 0x4400010, 0x10,
+ },
+ {
+ 0x10044000, 0x44004, 0,0x10044000,
+ 0x10000004, 0x44000,0x10044000, 0x4,
+ 0x44000, 0x4, 0x44004,0x10000000,
+ 0x10044004,0x10000000,0x10000000,0x10044004,
+ 0,0x10000004, 0x44004, 0,
+ 0x10000000,0x10044004, 0x4,0x10044000,
+ 0x10044004, 0x44000,0x10000004, 0x44004,
+ 0x4, 0, 0x44000,0x10000004,
+ 0x44004, 0,0x10000000, 0x4,
+ 0x10000000,0x10000004, 0x44004,0x10044000,
+ 0, 0x44004, 0x4,0x10044004,
+ 0x10000004, 0x44000,0x10044004,0x10000000,
+ 0x10000004,0x10044000, 0x44000,0x10044004,
+ 0x4, 0x44000,0x10044000, 0x4,
+ 0x44000, 0,0x10044004,0x10000000,
+ 0x10044000,0x10000004, 0, 0x44004,
+ },
+ {
+ 0x80000440, 0x100000,0x80000000,0x80100440,
+ 0, 0x100440,0x80100000,0x80000440,
+ 0x100440,0x80100000, 0x100000,0x80000000,
+ 0x80100000,0x80000440, 0x440, 0x100000,
+ 0x80100440, 0x440, 0,0x80000000,
+ 0x440,0x80100000, 0x100440, 0,
+ 0x80000000, 0,0x80000440, 0x100440,
+ 0x100000,0x80100440,0x80100440, 0x440,
+ 0x80100440,0x80000000, 0x440,0x80100000,
+ 0x440, 0x100000,0x80000000, 0x100440,
+ 0x80100000, 0, 0,0x80000440,
+ 0,0x80100440, 0x100440, 0,
+ 0x100000,0x80100440,0x80000440, 0x440,
+ 0x80100440,0x80000000, 0x100000,0x80000440,
+ 0x80000440, 0x440, 0x100440,0x80100000,
+ 0x80000000, 0x100000,0x80100000, 0x100440,
+ },
+ {
+ 0x88000, 0, 0, 0x88000,
+ 0x88000, 0x88000, 0, 0x88000,
+ 0, 0, 0x88000, 0,
+ 0x88000, 0x88000, 0x88000, 0,
+ 0, 0x88000, 0, 0,
+ 0x88000, 0, 0, 0x88000,
+ 0, 0x88000, 0x88000, 0,
+ 0x88000, 0, 0, 0x88000,
+ 0x88000, 0x88000, 0, 0x88000,
+ 0, 0, 0x88000, 0x88000,
+ 0x88000, 0, 0x88000, 0,
+ 0, 0x88000, 0, 0,
+ 0x88000, 0, 0, 0x88000,
+ 0x88000, 0x88000, 0, 0,
+ 0, 0x88000, 0x88000, 0,
+ 0, 0, 0x88000, 0x88000,
+ },
+ {
+ 0x8800000, 0x20, 0, 0x8800020,
+ 0x20, 0, 0x8800000, 0x20,
+ 0, 0x8800020, 0x20, 0x8800000,
+ 0x8800000, 0x8800000, 0x8800020, 0x20,
+ 0x20, 0x8800000, 0x8800020, 0,
+ 0, 0, 0x8800020, 0x8800020,
+ 0x8800020, 0x8800020, 0x8800000, 0,
+ 0, 0x20, 0x20, 0x8800000,
+ 0, 0x8800000, 0x8800000, 0x20,
+ 0x8800020, 0x20, 0, 0x8800000,
+ 0x8800000, 0, 0x8800020, 0x20,
+ 0x20, 0x8800020, 0x20, 0,
+ 0x8800020, 0x20, 0x20, 0x8800000,
+ 0x8800000, 0x8800020, 0x20, 0,
+ 0, 0x8800000, 0x8800000, 0x8800020,
+ 0x8800020, 0, 0, 0x8800020,
+ },
+ {
+ 0, 0, 0x1000,0x40001000,
+ 0x40001000,0x40000000, 0, 0,
+ 0x1000,0x40001000,0x40000000, 0x1000,
+ 0x40000000, 0x1000, 0x1000,0x40000000,
+ 0x40001000, 0,0x40000000,0x40001000,
+ 0, 0x1000,0x40001000, 0,
+ 0x40001000,0x40000000, 0x1000,0x40000000,
+ 0x40000000,0x40001000, 0, 0x1000,
+ 0x40000000, 0x1000,0x40001000,0x40000000,
+ 0, 0, 0x1000,0x40001000,
+ 0x40001000,0x40000000, 0, 0,
+ 0,0x40001000,0x40000000, 0x1000,
+ 0,0x40001000, 0x1000, 0,
+ 0x40000000, 0,0x40001000, 0x1000,
+ 0x1000,0x40000000,0x40000000,0x40001000,
+ 0x40001000, 0x1000, 0x1000,0x40000000,
+ },
+ {
+ 0x200880, 0x200880, 0, 0,
+ 0x200000, 0x880, 0x200880, 0x200880,
+ 0, 0x200000, 0x880, 0,
+ 0x880, 0x200000, 0x200000, 0x200880,
+ 0, 0x880, 0x880, 0x200000,
+ 0x200880, 0x200000, 0, 0x880,
+ 0x200000, 0x880, 0x200000, 0x200880,
+ 0x880, 0, 0x200880, 0,
+ 0x880, 0, 0x200000, 0x200880,
+ 0, 0x200000, 0, 0x880,
+ 0x200880, 0x200000, 0x200000, 0x880,
+ 0x200880, 0, 0x880, 0x200000,
+ 0x200880, 0x880, 0x200880, 0x200000,
+ 0x880, 0, 0x200000, 0x200880,
+ 0, 0x200880, 0x880, 0,
+ 0x200000, 0x200880, 0, 0x880,
+ },
+ },
+};
+
+/* compressed/interleaved => final permutation table */
+static const C_block CF6464[64/CHUNKBITS][1<<CHUNKBITS] = {
+ {
+ {{ 0, 0, 0, 0, 0, 0, 0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2, 2, 2, 0, 0, 0, 0,}},
+ },
+};
+
+#define HAVE_DES_TABLES 1
+#endif
diff --git a/missing/dtoa.c b/missing/dtoa.c
new file mode 100644
index 0000000000..bce2cb22a1
--- /dev/null
+++ b/missing/dtoa.c
@@ -0,0 +1,3473 @@
+/****************************************************************
+ *
+ * The author of this software is David M. Gay.
+ *
+ * Copyright (c) 1991, 2000, 2001 by Lucent Technologies.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ *
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ *
+ ***************************************************************/
+
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
+
+/* On a machine with IEEE extended-precision registers, it is
+ * necessary to specify double-precision (53-bit) rounding precision
+ * before invoking strtod or dtoa. If the machine uses (the equivalent
+ * of) Intel 80x87 arithmetic, the call
+ * _control87(PC_53, MCW_PC);
+ * does this with many compilers. Whether this or another call is
+ * appropriate depends on the compiler; for this to work, it may be
+ * necessary to #include "float.h" or another system-dependent header
+ * file.
+ */
+
+/* strtod for IEEE-, VAX-, and IBM-arithmetic machines.
+ *
+ * This strtod returns a nearest machine number to the input decimal
+ * string (or sets errno to ERANGE). With IEEE arithmetic, ties are
+ * broken by the IEEE round-even rule. Otherwise ties are broken by
+ * biased rounding (add half and chop).
+ *
+ * Inspired loosely by William D. Clinger's paper "How to Read Floating
+ * Point Numbers Accurately" [Proc. ACM SIGPLAN '90, pp. 92-101].
+ *
+ * Modifications:
+ *
+ * 1. We only require IEEE, IBM, or VAX double-precision
+ * arithmetic (not IEEE double-extended).
+ * 2. We get by with floating-point arithmetic in a case that
+ * Clinger missed -- when we're computing d * 10^n
+ * for a small integer d and the integer n is not too
+ * much larger than 22 (the maximum integer k for which
+ * we can represent 10^k exactly), we may be able to
+ * compute (d*10^k) * 10^(e-k) with just one roundoff.
+ * 3. Rather than a bit-at-a-time adjustment of the binary
+ * result in the hard case, we use floating-point
+ * arithmetic to determine the adjustment to within
+ * one bit; only in really hard cases do we need to
+ * compute a second residual.
+ * 4. Because of 3., we don't need a large table of powers of 10
+ * for ten-to-e (just some small tables, e.g. of 10^k
+ * for 0 <= k <= 22).
+ */
+
+/*
+ * #define IEEE_LITTLE_ENDIAN for IEEE-arithmetic machines where the least
+ * significant byte has the lowest address.
+ * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most
+ * significant byte has the lowest address.
+ * #define Long int on machines with 32-bit ints and 64-bit longs.
+ * #define IBM for IBM mainframe-style floating-point arithmetic.
+ * #define VAX for VAX-style floating-point arithmetic (D_floating).
+ * #define No_leftright to omit left-right logic in fast floating-point
+ * computation of dtoa.
+ * #define Honor_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
+ * and strtod and dtoa should round accordingly.
+ * #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
+ * and Honor_FLT_ROUNDS is not #defined.
+ * #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
+ * that use extended-precision instructions to compute rounded
+ * products and quotients) with IBM.
+ * #define ROUND_BIASED for IEEE-format with biased rounding.
+ * #define Inaccurate_Divide for IEEE-format with correctly rounded
+ * products but inaccurate quotients, e.g., for Intel i860.
+ * #define NO_LONG_LONG on machines that do not have a "long long"
+ * integer type (of >= 64 bits). On such machines, you can
+ * #define Just_16 to store 16 bits per 32-bit Long when doing
+ * high-precision integer arithmetic. Whether this speeds things
+ * up or slows things down depends on the machine and the number
+ * being converted. If long long is available and the name is
+ * something other than "long long", #define Llong to be the name,
+ * and if "unsigned Llong" does not work as an unsigned version of
+ * Llong, #define #ULLong to be the corresponding unsigned type.
+ * #define KR_headers for old-style C function headers.
+ * #define Bad_float_h if your system lacks a float.h or if it does not
+ * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
+ * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
+ * #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
+ * if memory is available and otherwise does something you deem
+ * appropriate. If MALLOC is undefined, malloc will be invoked
+ * directly -- and assumed always to succeed.
+ * #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
+ * memory allocations from a private pool of memory when possible.
+ * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,
+ * unless #defined to be a different length. This default length
+ * suffices to get rid of MALLOC calls except for unusual cases,
+ * such as decimal-to-binary conversion of a very long string of
+ * digits. The longest string dtoa can return is about 751 bytes
+ * long. For conversions by strtod of strings of 800 digits and
+ * all dtoa conversions in single-threaded executions with 8-byte
+ * pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte
+ * pointers, PRIVATE_MEM >= 7112 appears adequate.
+ * #define INFNAN_CHECK on IEEE systems to cause strtod to check for
+ * Infinity and NaN (case insensitively). On some systems (e.g.,
+ * some HP systems), it may be necessary to #define NAN_WORD0
+ * appropriately -- to the most significant word of a quiet NaN.
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
+ * strtod also accepts (case insensitively) strings of the form
+ * NaN(x), where x is a string of hexadecimal digits and spaces;
+ * if there is only one string of hexadecimal digits, it is taken
+ * for the 52 fraction bits of the resulting NaN; if there are two
+ * or more strings of hex digits, the first is for the high 20 bits,
+ * the second and subsequent for the low 32 bits, with intervening
+ * white space ignored; but if this results in none of the 52
+ * fraction bits being on (an IEEE Infinity symbol), then NAN_WORD0
+ * and NAN_WORD1 are used instead.
+ * #define MULTIPLE_THREADS if the system offers preemptively scheduled
+ * multiple threads. In this case, you must provide (or suitably
+ * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
+ * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
+ * in pow5mult, ensures lazy evaluation of only one copy of high
+ * powers of 5; omitting this lock would introduce a small
+ * probability of wasting memory, but would otherwise be harmless.)
+ * You must also invoke freedtoa(s) to free the value s returned by
+ * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
+ * #define NO_IEEE_Scale to disable new (Feb. 1997) logic in strtod that
+ * avoids underflows on inputs whose result does not underflow.
+ * If you #define NO_IEEE_Scale on a machine that uses IEEE-format
+ * floating-point numbers and flushes underflows to zero rather
+ * than implementing gradual underflow, then you must also #define
+ * Sudden_Underflow.
+ * #define YES_ALIAS to permit aliasing certain double values with
+ * arrays of ULongs. This leads to slightly better code with
+ * some compilers and was always used prior to 19990916, but it
+ * is not strictly legal and can cause trouble with aggressively
+ * optimizing compilers (e.g., gcc 2.95.1 under -O2).
+ * #define USE_LOCALE to use the current locale's decimal_point value.
+ * #define SET_INEXACT if IEEE arithmetic is being used and extra
+ * computation should be done to set the inexact flag when the
+ * result is inexact and avoid setting inexact when the result
+ * is exact. In this case, dtoa.c must be compiled in
+ * an environment, perhaps provided by #include "dtoa.c" in a
+ * suitable wrapper, that defines two functions,
+ * int get_inexact(void);
+ * void clear_inexact(void);
+ * such that get_inexact() returns a nonzero value if the
+ * inexact bit is already set, and clear_inexact() sets the
+ * inexact bit to 0. When SET_INEXACT is #defined, strtod
+ * also does extra computations to set the underflow and overflow
+ * flags when appropriate (i.e., when the result is tiny and
+ * inexact or when it is a numeric value rounded to +-infinity).
+ * #define NO_ERRNO if strtod should not assign errno = ERANGE when
+ * the result overflows to +-Infinity or underflows to 0.
+ */
+
+#ifdef WORDS_BIGENDIAN
+#define IEEE_BIG_ENDIAN
+#else
+#define IEEE_LITTLE_ENDIAN
+#endif
+
+#ifdef __vax__
+#define VAX
+#undef IEEE_BIG_ENDIAN
+#undef IEEE_LITTLE_ENDIAN
+#endif
+
+#if defined(__arm__) && !defined(__VFP_FP__)
+#define IEEE_BIG_ENDIAN
+#undef IEEE_LITTLE_ENDIAN
+#endif
+
+#undef Long
+#undef ULong
+
+#include <assert.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#if (INT_MAX >> 30) && !(INT_MAX >> 31)
+#define Long int
+#define ULong unsigned int
+#elif (LONG_MAX >> 30) && !(LONG_MAX >> 31)
+#define Long long int
+#define ULong unsigned long int
+#else
+#error No 32bit integer
+#endif
+
+#if defined(HAVE_LONG_LONG) && (HAVE_LONG_LONG)
+#define Llong LONG_LONG
+#else
+#define NO_LONG_LONG
+#endif
+
+#ifdef DEBUG
+#include <stdio.h>
+#define Bug(x) {fprintf(stderr, "%s\n", (x)); exit(EXIT_FAILURE);}
+#endif
+
+#ifndef ISDIGIT
+#include <ctype.h>
+#define ISDIGIT(c) isdigit(c)
+#endif
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef USE_LOCALE
+#include <locale.h>
+#endif
+
+#ifdef MALLOC
+extern void *MALLOC(size_t);
+#else
+#define MALLOC malloc
+#endif
+#ifdef FREE
+extern void FREE(void*);
+#else
+#define FREE free
+#endif
+#ifndef NO_SANITIZE
+#define NO_SANITIZE(x, y) y
+#endif
+
+#ifndef Omit_Private_Memory
+#ifndef PRIVATE_MEM
+#define PRIVATE_MEM 2304
+#endif
+#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
+static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
+#endif
+
+#undef IEEE_Arith
+#undef Avoid_Underflow
+#ifdef IEEE_BIG_ENDIAN
+#define IEEE_Arith
+#endif
+#ifdef IEEE_LITTLE_ENDIAN
+#define IEEE_Arith
+#endif
+
+#ifdef Bad_float_h
+
+#ifdef IEEE_Arith
+#define DBL_DIG 15
+#define DBL_MAX_10_EXP 308
+#define DBL_MAX_EXP 1024
+#define FLT_RADIX 2
+#endif /*IEEE_Arith*/
+
+#ifdef IBM
+#define DBL_DIG 16
+#define DBL_MAX_10_EXP 75
+#define DBL_MAX_EXP 63
+#define FLT_RADIX 16
+#define DBL_MAX 7.2370055773322621e+75
+#endif
+
+#ifdef VAX
+#define DBL_DIG 16
+#define DBL_MAX_10_EXP 38
+#define DBL_MAX_EXP 127
+#define FLT_RADIX 2
+#define DBL_MAX 1.7014118346046923e+38
+#endif
+
+#ifndef LONG_MAX
+#define LONG_MAX 2147483647
+#endif
+
+#else /* ifndef Bad_float_h */
+#include <float.h>
+#endif /* Bad_float_h */
+
+#include <math.h>
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+} /* satisfy cc-mode */
+#endif
+#endif
+
+#ifndef hexdigit
+static const char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
+#endif
+
+#if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + defined(IBM) != 1
+Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined.
+#endif
+
+typedef union { double d; ULong L[2]; } U;
+
+#ifdef YES_ALIAS
+typedef double double_u;
+# define dval(x) (x)
+# ifdef IEEE_LITTLE_ENDIAN
+# define word0(x) (((ULong *)&(x))[1])
+# define word1(x) (((ULong *)&(x))[0])
+# else
+# define word0(x) (((ULong *)&(x))[0])
+# define word1(x) (((ULong *)&(x))[1])
+# endif
+#else
+typedef U double_u;
+# ifdef IEEE_LITTLE_ENDIAN
+# define word0(x) ((x).L[1])
+# define word1(x) ((x).L[0])
+# else
+# define word0(x) ((x).L[0])
+# define word1(x) ((x).L[1])
+# endif
+# define dval(x) ((x).d)
+#endif
+
+/* The following definition of Storeinc is appropriate for MIPS processors.
+ * An alternative that might be better on some machines is
+ * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
+ */
+#if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) + defined(__arm__)
+#define Storeinc(a,b,c) (((unsigned short *)(a))[1] = (unsigned short)(b), \
+((unsigned short *)(a))[0] = (unsigned short)(c), (a)++)
+#else
+#define Storeinc(a,b,c) (((unsigned short *)(a))[0] = (unsigned short)(b), \
+((unsigned short *)(a))[1] = (unsigned short)(c), (a)++)
+#endif
+
+/* #define P DBL_MANT_DIG */
+/* Ten_pmax = floor(P*log(2)/log(5)) */
+/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
+/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
+/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
+
+#ifdef IEEE_Arith
+#define Exp_shift 20
+#define Exp_shift1 20
+#define Exp_msk1 0x100000
+#define Exp_msk11 0x100000
+#define Exp_mask 0x7ff00000
+#define P 53
+#define Bias 1023
+#define Emin (-1022)
+#define Exp_1 0x3ff00000
+#define Exp_11 0x3ff00000
+#define Ebits 11
+#define Frac_mask 0xfffff
+#define Frac_mask1 0xfffff
+#define Ten_pmax 22
+#define Bletch 0x10
+#define Bndry_mask 0xfffff
+#define Bndry_mask1 0xfffff
+#define LSB 1
+#define Sign_bit 0x80000000
+#define Log2P 1
+#define Tiny0 0
+#define Tiny1 1
+#define Quick_max 14
+#define Int_max 14
+#ifndef NO_IEEE_Scale
+#define Avoid_Underflow
+#ifdef Flush_Denorm /* debugging option */
+#undef Sudden_Underflow
+#endif
+#endif
+
+#ifndef Flt_Rounds
+#ifdef FLT_ROUNDS
+#define Flt_Rounds FLT_ROUNDS
+#else
+#define Flt_Rounds 1
+#endif
+#endif /*Flt_Rounds*/
+
+#ifdef Honor_FLT_ROUNDS
+#define Rounding rounding
+#undef Check_FLT_ROUNDS
+#define Check_FLT_ROUNDS
+#else
+#define Rounding Flt_Rounds
+#endif
+
+#else /* ifndef IEEE_Arith */
+#undef Check_FLT_ROUNDS
+#undef Honor_FLT_ROUNDS
+#undef SET_INEXACT
+#undef Sudden_Underflow
+#define Sudden_Underflow
+#ifdef IBM
+#undef Flt_Rounds
+#define Flt_Rounds 0
+#define Exp_shift 24
+#define Exp_shift1 24
+#define Exp_msk1 0x1000000
+#define Exp_msk11 0x1000000
+#define Exp_mask 0x7f000000
+#define P 14
+#define Bias 65
+#define Exp_1 0x41000000
+#define Exp_11 0x41000000
+#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
+#define Frac_mask 0xffffff
+#define Frac_mask1 0xffffff
+#define Bletch 4
+#define Ten_pmax 22
+#define Bndry_mask 0xefffff
+#define Bndry_mask1 0xffffff
+#define LSB 1
+#define Sign_bit 0x80000000
+#define Log2P 4
+#define Tiny0 0x100000
+#define Tiny1 0
+#define Quick_max 14
+#define Int_max 15
+#else /* VAX */
+#undef Flt_Rounds
+#define Flt_Rounds 1
+#define Exp_shift 23
+#define Exp_shift1 7
+#define Exp_msk1 0x80
+#define Exp_msk11 0x800000
+#define Exp_mask 0x7f80
+#define P 56
+#define Bias 129
+#define Exp_1 0x40800000
+#define Exp_11 0x4080
+#define Ebits 8
+#define Frac_mask 0x7fffff
+#define Frac_mask1 0xffff007f
+#define Ten_pmax 24
+#define Bletch 2
+#define Bndry_mask 0xffff007f
+#define Bndry_mask1 0xffff007f
+#define LSB 0x10000
+#define Sign_bit 0x8000
+#define Log2P 1
+#define Tiny0 0x80
+#define Tiny1 0
+#define Quick_max 15
+#define Int_max 15
+#endif /* IBM, VAX */
+#endif /* IEEE_Arith */
+
+#ifndef IEEE_Arith
+#define ROUND_BIASED
+#endif
+
+#ifdef RND_PRODQUOT
+#define rounded_product(a,b) ((a) = rnd_prod((a), (b)))
+#define rounded_quotient(a,b) ((a) = rnd_quot((a), (b)))
+extern double rnd_prod(double, double), rnd_quot(double, double);
+#else
+#define rounded_product(a,b) ((a) *= (b))
+#define rounded_quotient(a,b) ((a) /= (b))
+#endif
+
+#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
+#define Big1 0xffffffff
+
+#ifndef Pack_32
+#define Pack_32
+#endif
+
+#define FFFFFFFF 0xffffffffUL
+
+#ifdef NO_LONG_LONG
+#undef ULLong
+#ifdef Just_16
+#undef Pack_32
+/* When Pack_32 is not defined, we store 16 bits per 32-bit Long.
+ * This makes some inner loops simpler and sometimes saves work
+ * during multiplications, but it often seems to make things slightly
+ * slower. Hence the default is now to store 32 bits per Long.
+ */
+#endif
+#else /* long long available */
+#ifndef Llong
+#define Llong long long
+#endif
+#ifndef ULLong
+#define ULLong unsigned Llong
+#endif
+#endif /* NO_LONG_LONG */
+
+#define MULTIPLE_THREADS 1
+
+#ifndef MULTIPLE_THREADS
+#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
+#define FREE_DTOA_LOCK(n) /*nothing*/
+#else
+#define ACQUIRE_DTOA_LOCK(n) /*unused right now*/
+#define FREE_DTOA_LOCK(n) /*unused right now*/
+#endif
+
+#ifndef ATOMIC_PTR_CAS
+#define ATOMIC_PTR_CAS(var, old, new) ((var) = (new), (void *)(old))
+#endif
+#ifndef LIKELY
+#define LIKELY(x) (x)
+#endif
+#ifndef UNLIKELY
+#define UNLIKELY(x) (x)
+#endif
+#ifndef ASSUME
+#define ASSUME(x) (void)(x)
+#endif
+
+#define Kmax 15
+
+struct Bigint {
+ struct Bigint *next;
+ int k, maxwds, sign, wds;
+ ULong x[1];
+};
+
+typedef struct Bigint Bigint;
+
+static Bigint *freelist[Kmax+1];
+
+#define BLOCKING_BIGINT ((Bigint *)(-1))
+
+static Bigint *
+Balloc(int k)
+{
+ int x;
+ Bigint *rv;
+#ifndef Omit_Private_Memory
+ size_t len;
+#endif
+
+ rv = 0;
+ ACQUIRE_DTOA_LOCK(0);
+ if (k <= Kmax) {
+ rv = freelist[k];
+ while (rv) {
+ Bigint *rvn = rv;
+ rv = ATOMIC_PTR_CAS(freelist[k], rv, BLOCKING_BIGINT);
+ if (LIKELY(rv != BLOCKING_BIGINT && rvn == rv)) {
+ rvn = ATOMIC_PTR_CAS(freelist[k], BLOCKING_BIGINT, rv->next);
+ assert(rvn == BLOCKING_BIGINT);
+ ASSUME(rv);
+ break;
+ }
+ }
+ }
+ if (!rv) {
+ x = 1 << k;
+#ifdef Omit_Private_Memory
+ rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
+#else
+ len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
+ /sizeof(double);
+ if (k <= Kmax) {
+ double *pnext = pmem_next;
+ while (pnext - private_mem + len <= PRIVATE_mem) {
+ double *p = pnext;
+ pnext = ATOMIC_PTR_CAS(pmem_next, pnext, pnext + len);
+ if (LIKELY(p == pnext)) {
+ rv = (Bigint*)pnext;
+ ASSUME(rv);
+ break;
+ }
+ }
+ }
+ if (!rv)
+ rv = (Bigint*)MALLOC(len*sizeof(double));
+#endif
+ rv->k = k;
+ rv->maxwds = x;
+ }
+ FREE_DTOA_LOCK(0);
+ rv->sign = rv->wds = 0;
+ return rv;
+}
+
+static void
+Bfree(Bigint *v)
+{
+ Bigint *vn;
+ if (v) {
+ if (v->k > Kmax) {
+ FREE(v);
+ return;
+ }
+ ACQUIRE_DTOA_LOCK(0);
+ do {
+ do {
+ vn = ATOMIC_PTR_CAS(freelist[v->k], 0, 0);
+ } while (UNLIKELY(vn == BLOCKING_BIGINT));
+ v->next = vn;
+ } while (UNLIKELY(ATOMIC_PTR_CAS(freelist[v->k], vn, v) != vn));
+ FREE_DTOA_LOCK(0);
+ }
+}
+
+#define Bcopy(x,y) memcpy((char *)&(x)->sign, (char *)&(y)->sign, \
+(y)->wds*sizeof(Long) + 2*sizeof(int))
+
+static Bigint *
+multadd(Bigint *b, int m, int a) /* multiply by m and add a */
+{
+ int i, wds;
+ ULong *x;
+#ifdef ULLong
+ ULLong carry, y;
+#else
+ ULong carry, y;
+#ifdef Pack_32
+ ULong xi, z;
+#endif
+#endif
+ Bigint *b1;
+
+ wds = b->wds;
+ x = b->x;
+ i = 0;
+ carry = a;
+ do {
+#ifdef ULLong
+ y = *x * (ULLong)m + carry;
+ carry = y >> 32;
+ *x++ = (ULong)(y & FFFFFFFF);
+#else
+#ifdef Pack_32
+ xi = *x;
+ y = (xi & 0xffff) * m + carry;
+ z = (xi >> 16) * m + (y >> 16);
+ carry = z >> 16;
+ *x++ = (z << 16) + (y & 0xffff);
+#else
+ y = *x * m + carry;
+ carry = y >> 16;
+ *x++ = y & 0xffff;
+#endif
+#endif
+ } while (++i < wds);
+ if (carry) {
+ if (wds >= b->maxwds) {
+ b1 = Balloc(b->k+1);
+ Bcopy(b1, b);
+ Bfree(b);
+ b = b1;
+ }
+ b->x[wds++] = (ULong)carry;
+ b->wds = wds;
+ }
+ return b;
+}
+
+static Bigint *
+s2b(const char *s, int nd0, int nd, ULong y9)
+{
+ Bigint *b;
+ int i, k;
+ Long x, y;
+
+ x = (nd + 8) / 9;
+ for (k = 0, y = 1; x > y; y <<= 1, k++) ;
+#ifdef Pack_32
+ b = Balloc(k);
+ b->x[0] = y9;
+ b->wds = 1;
+#else
+ b = Balloc(k+1);
+ b->x[0] = y9 & 0xffff;
+ b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
+#endif
+
+ i = 9;
+ if (9 < nd0) {
+ s += 9;
+ do {
+ b = multadd(b, 10, *s++ - '0');
+ } while (++i < nd0);
+ s++;
+ }
+ else
+ s += 10;
+ for (; i < nd; i++)
+ b = multadd(b, 10, *s++ - '0');
+ return b;
+}
+
+static int
+hi0bits(register ULong x)
+{
+ register int k = 0;
+
+ if (!(x & 0xffff0000)) {
+ k = 16;
+ x <<= 16;
+ }
+ if (!(x & 0xff000000)) {
+ k += 8;
+ x <<= 8;
+ }
+ if (!(x & 0xf0000000)) {
+ k += 4;
+ x <<= 4;
+ }
+ if (!(x & 0xc0000000)) {
+ k += 2;
+ x <<= 2;
+ }
+ if (!(x & 0x80000000)) {
+ k++;
+ if (!(x & 0x40000000))
+ return 32;
+ }
+ return k;
+}
+
+static int
+lo0bits(ULong *y)
+{
+ register int k;
+ register ULong x = *y;
+
+ if (x & 7) {
+ if (x & 1)
+ return 0;
+ if (x & 2) {
+ *y = x >> 1;
+ return 1;
+ }
+ *y = x >> 2;
+ return 2;
+ }
+ k = 0;
+ if (!(x & 0xffff)) {
+ k = 16;
+ x >>= 16;
+ }
+ if (!(x & 0xff)) {
+ k += 8;
+ x >>= 8;
+ }
+ if (!(x & 0xf)) {
+ k += 4;
+ x >>= 4;
+ }
+ if (!(x & 0x3)) {
+ k += 2;
+ x >>= 2;
+ }
+ if (!(x & 1)) {
+ k++;
+ x >>= 1;
+ if (!x)
+ return 32;
+ }
+ *y = x;
+ return k;
+}
+
+static Bigint *
+i2b(int i)
+{
+ Bigint *b;
+
+ b = Balloc(1);
+ b->x[0] = i;
+ b->wds = 1;
+ return b;
+}
+
+static Bigint *
+mult(Bigint *a, Bigint *b)
+{
+ Bigint *c;
+ int k, wa, wb, wc;
+ ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
+ ULong y;
+#ifdef ULLong
+ ULLong carry, z;
+#else
+ ULong carry, z;
+#ifdef Pack_32
+ ULong z2;
+#endif
+#endif
+
+ if (a->wds < b->wds) {
+ c = a;
+ a = b;
+ b = c;
+ }
+ k = a->k;
+ wa = a->wds;
+ wb = b->wds;
+ wc = wa + wb;
+ if (wc > a->maxwds)
+ k++;
+ c = Balloc(k);
+ for (x = c->x, xa = x + wc; x < xa; x++)
+ *x = 0;
+ xa = a->x;
+ xae = xa + wa;
+ xb = b->x;
+ xbe = xb + wb;