diff --git a/contrib/pgcrypto/blf.c b/contrib/pgcrypto/blf.c
new file mode 100644
index 0000000000000000000000000000000000000000..28d44d9de9f113a08e0e110d5d25f33e41c01cc7
--- /dev/null
+++ b/contrib/pgcrypto/blf.c
@@ -0,0 +1,657 @@
+/*	$OpenBSD: blf.c,v 1.3 2000/06/17 23:36:22 provos Exp $	*/
+
+/*
+ * Blowfish block cipher for OpenBSD
+ * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
+ * All rights reserved.
+ *
+ * Implementation advice by David Mazieres <dm@lcs.mit.edu>.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Niels Provos.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+/*
+ * This code is derived from section 14.3 and the given source
+ * in section V of Applied Cryptography, second edition.
+ * Blowfish is an unpatented fast block cipher designed by
+ * Bruce Schneier.
+ */
+
+#include <postgres.h>
+#include "blf.h"
+
+#undef inline
+#ifdef __GNUC__
+#define inline __inline
+#else				/* !__GNUC__ */
+#define inline
+#endif				/* !__GNUC__ */
+
+/* Function for Feistel Networks */
+
+#define F(s, x) ((((s)[        (((x)>>24)&0xFF)]  \
+		 + (s)[0x100 + (((x)>>16)&0xFF)]) \
+		 ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \
+		 + (s)[0x300 + ( (x)     &0xFF)])
+
+#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
+
+void
+Blowfish_encipher(blf_ctx *c, uint32 *x)
+{
+	uint32 Xl;
+	uint32 Xr;
+	uint32 *s = c->S[0];
+	uint32 *p = c->P;
+
+	Xl = x[0];
+	Xr = x[1];
+
+	Xl ^= p[0];
+	BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2);
+	BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4);
+	BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6);
+	BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8);
+	BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10);
+	BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12);
+	BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14);
+	BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16);
+
+	x[0] = Xr ^ p[17];
+	x[1] = Xl;
+}
+
+void
+Blowfish_decipher(blf_ctx *c, uint32 *x)
+{
+	uint32 Xl;
+	uint32 Xr;
+	uint32 *s = c->S[0];
+	uint32 *p = c->P;
+
+	Xl = x[0];
+	Xr = x[1];
+
+	Xl ^= p[17];
+	BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15);
+	BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13);
+	BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11);
+	BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9);
+	BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7);
+	BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5);
+	BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3);
+	BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1);
+
+	x[0] = Xr ^ p[0];
+	x[1] = Xl;
+}
+
+void
+Blowfish_initstate(blf_ctx *c)
+{
+
+/* P-box and S-box tables initialized with digits of Pi */
+
+	const blf_ctx initstate =
+
+	{ {
+		{
+			0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
+			0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
+			0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+			0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
+			0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
+			0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+			0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
+			0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
+			0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+			0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
+			0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
+			0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+			0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
+			0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
+			0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+			0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
+			0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
+			0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+			0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
+			0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
+			0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+			0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
+			0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
+			0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+			0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
+			0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
+			0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+			0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
+			0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
+			0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+			0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
+			0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
+			0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+			0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
+			0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
+			0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+			0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
+			0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
+			0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+			0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
+			0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
+			0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+			0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
+			0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
+			0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+			0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
+			0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
+			0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+			0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
+			0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
+			0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+			0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
+			0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
+			0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+			0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
+			0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
+			0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+			0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
+			0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
+			0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+			0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
+			0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
+			0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+		0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a},
+		{
+			0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
+			0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
+			0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+			0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
+			0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
+			0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+			0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
+			0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
+			0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+			0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
+			0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
+			0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+			0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
+			0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
+			0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+			0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
+			0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
+			0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+			0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
+			0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
+			0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+			0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
+			0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
+			0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+			0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
+			0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
+			0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+			0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
+			0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
+			0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+			0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
+			0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
+			0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+			0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
+			0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
+			0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+			0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
+			0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
+			0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+			0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
+			0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
+			0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+			0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
+			0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
+			0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+			0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
+			0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
+			0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+			0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
+			0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
+			0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+			0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
+			0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
+			0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+			0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
+			0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
+			0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+			0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
+			0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
+			0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+			0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
+			0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
+			0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+		0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7},
+		{
+			0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
+			0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
+			0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+			0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
+			0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
+			0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+			0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
+			0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
+			0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+			0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
+			0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
+			0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+			0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
+			0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
+			0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+			0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
+			0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
+			0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+			0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
+			0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
+			0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+			0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
+			0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
+			0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+			0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
+			0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
+			0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+			0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
+			0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
+			0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+			0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
+			0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
+			0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+			0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
+			0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
+			0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+			0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
+			0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
+			0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+			0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
+			0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
+			0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+			0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
+			0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
+			0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+			0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
+			0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
+			0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+			0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
+			0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
+			0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+			0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
+			0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
+			0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+			0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
+			0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
+			0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+			0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
+			0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
+			0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+			0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
+			0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
+			0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+		0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0},
+		{
+			0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
+			0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
+			0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+			0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
+			0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
+			0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+			0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
+			0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
+			0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+			0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
+			0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
+			0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+			0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
+			0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
+			0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+			0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
+			0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
+			0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+			0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
+			0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
+			0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+			0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
+			0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
+			0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+			0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
+			0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
+			0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+			0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
+			0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
+			0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+			0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
+			0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
+			0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+			0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
+			0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
+			0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+			0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
+			0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
+			0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+			0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
+			0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
+			0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+			0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
+			0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
+			0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+			0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
+			0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
+			0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+			0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
+			0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
+			0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+			0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
+			0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
+			0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+			0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
+			0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
+			0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+			0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
+			0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
+			0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+			0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
+			0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
+			0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+		0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6}
+	},
+	{
+		0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+		0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+		0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+		0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
+		0x9216d5d9, 0x8979fb1b
+	} };
+
+	*c = initstate;
+
+}
+
+uint32
+Blowfish_stream2word(const uint8 *data, uint16 databytes, uint16 *current)
+{
+	uint8 i;
+	uint16 j;
+	uint32 temp;
+
+	temp = 0x00000000;
+	j = *current;
+
+	for (i = 0; i < 4; i++, j++) {
+		if (j >= databytes)
+			j = 0;
+		temp = (temp << 8) | data[j];
+	}
+
+	*current = j;
+	return temp;
+}
+
+void
+Blowfish_expand0state(blf_ctx *c, const uint8 *key, uint16 keybytes)
+{
+	uint16 i;
+	uint16 j;
+	uint16 k;
+	uint32 temp;
+	uint32 data[2];
+
+	j = 0;
+	for (i = 0; i < BLF_N + 2; i++) {
+		/* Extract 4 int8 to 1 int32 from keystream */
+		temp = Blowfish_stream2word(key, keybytes, &j);
+		c->P[i] = c->P[i] ^ temp;
+	}
+
+	j = 0;
+	data[0] = 0x00000000;
+	data[1] = 0x00000000;
+	for (i = 0; i < BLF_N + 2; i += 2) {
+		Blowfish_encipher(c, data);
+
+		c->P[i] = data[0];
+		c->P[i + 1] = data[1];
+	}
+
+	for (i = 0; i < 4; i++) {
+		for (k = 0; k < 256; k += 2) {
+			Blowfish_encipher(c, data);
+
+			c->S[i][k] = data[0];
+			c->S[i][k + 1] = data[1];
+		}
+	}
+}
+
+
+void
+Blowfish_expandstate(blf_ctx *c, const uint8 *data, uint16 databytes,
+		     const uint8 *key, uint16 keybytes)
+{
+	uint16 i;
+	uint16 j;
+	uint16 k;
+	uint32 temp;
+	uint32 d[2];
+
+	j = 0;
+	for (i = 0; i < BLF_N + 2; i++) {
+		/* Extract 4 int8 to 1 int32 from keystream */
+		temp = Blowfish_stream2word(key, keybytes, &j);
+		c->P[i] = c->P[i] ^ temp;
+	}
+
+	j = 0;
+	d[0] = 0x00000000;
+	d[1] = 0x00000000;
+	for (i = 0; i < BLF_N + 2; i += 2) {
+		d[0] ^= Blowfish_stream2word(data, databytes, &j);
+		d[1] ^= Blowfish_stream2word(data, databytes, &j);
+		Blowfish_encipher(c, d);
+
+		c->P[i] = d[0];
+		c->P[i + 1] = d[1];
+	}
+
+	for (i = 0; i < 4; i++) {
+		for (k = 0; k < 256; k += 2) {
+			d[0]^= Blowfish_stream2word(data, databytes, &j);
+			d[1] ^= Blowfish_stream2word(data, databytes, &j);
+			Blowfish_encipher(c, d);
+
+			c->S[i][k] = d[0];
+			c->S[i][k + 1] = d[1];
+		}
+	}
+
+}
+
+void
+blf_key(blf_ctx *c, const uint8 *k, uint16 len)
+{
+	/* Initalize S-boxes and subkeys with Pi */
+	Blowfish_initstate(c);
+
+	/* Transform S-boxes and subkeys with key */
+	Blowfish_expand0state(c, k, len);
+}
+
+void
+blf_enc(blf_ctx *c, uint32 *data, uint16 blocks)
+{
+	uint32 *d;
+	uint16 i;
+
+	d = data;
+	for (i = 0; i < blocks; i++) {
+		Blowfish_encipher(c, d);
+		d += 2;
+	}
+}
+
+void
+blf_dec(blf_ctx *c, uint32 *data, uint16 blocks)
+{
+	uint32 *d;
+	uint16 i;
+
+	d = data;
+	for (i = 0; i < blocks; i++) {
+		Blowfish_decipher(c, d);
+		d += 2;
+	}
+}
+
+void
+blf_ecb_encrypt(blf_ctx *c, uint8 *data, uint32 len)
+{
+	uint32 l, r, d[2];
+	uint32 i;
+
+	for (i = 0; i < len; i += 8) {
+		l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+		r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+		d[0] = l;
+		d[1] = r;
+		Blowfish_encipher(c, d);
+		l = d[0];
+		r = d[1];
+		data[0] = l >> 24 & 0xff;
+		data[1] = l >> 16 & 0xff;
+		data[2] = l >> 8 & 0xff;
+		data[3] = l & 0xff;
+		data[4] = r >> 24 & 0xff;
+		data[5] = r >> 16 & 0xff;
+		data[6] = r >> 8 & 0xff;
+		data[7] = r & 0xff;
+		data += 8;
+	}
+}
+
+void
+blf_ecb_decrypt(blf_ctx *c, uint8 *data, uint32 len)
+{
+	uint32 l, r, d[2];
+	uint32 i;
+
+	for (i = 0; i < len; i += 8) {
+		l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+		r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+		d[0] = l;
+		d[1] = r;
+		Blowfish_decipher(c, d);
+		l = d[0];
+		r = d[1];
+		data[0] = l >> 24 & 0xff;
+		data[1] = l >> 16 & 0xff;
+		data[2] = l >> 8 & 0xff;
+		data[3] = l & 0xff;
+		data[4] = r >> 24 & 0xff;
+		data[5] = r >> 16 & 0xff;
+		data[6] = r >> 8 & 0xff;
+		data[7] = r & 0xff;
+		data += 8;
+	}
+}
+
+void
+blf_cbc_encrypt(blf_ctx *c, uint8 *iv, uint8 *data, uint32 len)
+{
+	uint32 l, r, d[2];
+	uint32 i, j;
+
+	for (i = 0; i < len; i += 8) {
+		for (j = 0; j < 8; j++)
+			data[j] ^= iv[j];
+		l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+		r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+		d[0] = l;
+		d[1] = r;
+		Blowfish_encipher(c, d);
+		l = d[0];
+		r = d[1];
+		data[0] = l >> 24 & 0xff;
+		data[1] = l >> 16 & 0xff;
+		data[2] = l >> 8 & 0xff;
+		data[3] = l & 0xff;
+		data[4] = r >> 24 & 0xff;
+		data[5] = r >> 16 & 0xff;
+		data[6] = r >> 8 & 0xff;
+		data[7] = r & 0xff;
+		iv = data;
+		data += 8;
+	}
+}
+
+void
+blf_cbc_decrypt(blf_ctx *c, uint8 *iva, uint8 *data, uint32 len)
+{
+	uint32 l, r, d[2];
+	uint8 *iv;
+	uint32 i, j;
+
+	iv = data + len - 16;
+	data = data + len - 8;
+	for (i = len - 8; i >= 8; i -= 8) {
+		l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+		r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+		d[0] = l;
+		d[1] = r;
+		Blowfish_decipher(c, d);
+		l = d[0];
+		r = d[1];
+		data[0] = l >> 24 & 0xff;
+		data[1] = l >> 16 & 0xff;
+		data[2] = l >> 8 & 0xff;
+		data[3] = l & 0xff;
+		data[4] = r >> 24 & 0xff;
+		data[5] = r >> 16 & 0xff;
+		data[6] = r >> 8 & 0xff;
+		data[7] = r & 0xff;
+		for (j = 0; j < 8; j++)
+			data[j] ^= iv[j];
+		iv -= 8;
+		data -= 8;
+	}
+	l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+	r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+	d[0] = l;
+	d[1] = r;
+	Blowfish_decipher(c, d);
+	l = d[0];
+	r = d[1];
+	data[0] = l >> 24 & 0xff;
+	data[1] = l >> 16 & 0xff;
+	data[2] = l >> 8 & 0xff;
+	data[3] = l & 0xff;
+	data[4] = r >> 24 & 0xff;
+	data[5] = r >> 16 & 0xff;
+	data[6] = r >> 8 & 0xff;
+	data[7] = r & 0xff;
+	for (j = 0; j < 8; j++)
+		data[j] ^= iva[j];
+}
diff --git a/contrib/pgcrypto/blf.h b/contrib/pgcrypto/blf.h
new file mode 100644
index 0000000000000000000000000000000000000000..bb6b66ff27280637919fc4a10d42c2021e2ba689
--- /dev/null
+++ b/contrib/pgcrypto/blf.h
@@ -0,0 +1,82 @@
+/*	$OpenBSD: blf.h,v 1.3 2001/05/15 02:40:35 deraadt Exp $	*/
+
+/*
+ * Blowfish - a fast block cipher designed by Bruce Schneier
+ *
+ * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
+ * All rights reserved.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Niels Provos.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#ifndef _BLF_H_
+#define _BLF_H_
+
+/* Schneier states the maximum key length to be 56 bytes.
+ * The way how the subkeys are initalized by the key up
+ * to (N+2)*4 i.e. 72 bytes are utilized.
+ * Warning: For normal blowfish encryption only 56 bytes
+ * of the key affect all cipherbits.
+ */
+
+#define BLF_N	16			/* Number of Subkeys */
+#define BLF_MAXKEYLEN ((BLF_N-2)*4)	/* 448 bits */
+
+/* Blowfish context */
+typedef struct BlowfishContext {
+	uint32 S[4][256];	/* S-Boxes */
+	uint32 P[BLF_N + 2];	/* Subkeys */
+} blf_ctx;
+
+/* Raw access to customized Blowfish
+ *	blf_key is just:
+ *	Blowfish_initstate( state )
+ *	Blowfish_expand0state( state, key, keylen )
+ */
+
+void Blowfish_encipher __P((blf_ctx *, uint32 *));
+void Blowfish_decipher __P((blf_ctx *, uint32 *));
+void Blowfish_initstate __P((blf_ctx *));
+void Blowfish_expand0state __P((blf_ctx *, const uint8 *, uint16));
+void Blowfish_expandstate
+    __P((blf_ctx *, const uint8 *, uint16, const uint8 *, uint16));
+
+/* Standard Blowfish */
+
+void blf_key __P((blf_ctx *, const uint8 *, uint16));
+void blf_enc __P((blf_ctx *, uint32 *, uint16));
+void blf_dec __P((blf_ctx *, uint32 *, uint16));
+
+/* Converts uint8 to uint32 */
+uint32 Blowfish_stream2word __P((const uint8 *, uint16 ,
+				    uint16 *));
+
+void blf_ecb_encrypt __P((blf_ctx *, uint8 *, uint32));
+void blf_ecb_decrypt __P((blf_ctx *, uint8 *, uint32));
+
+void blf_cbc_encrypt __P((blf_ctx *, uint8 *, uint8 *, uint32));
+void blf_cbc_decrypt __P((blf_ctx *, uint8 *, uint8 *, uint32));
+#endif
diff --git a/contrib/pgcrypto/crypt-blowfish.c b/contrib/pgcrypto/crypt-blowfish.c
new file mode 100644
index 0000000000000000000000000000000000000000..2979a71250bad3568f028daea8277fc98f423aa0
--- /dev/null
+++ b/contrib/pgcrypto/crypt-blowfish.c
@@ -0,0 +1,732 @@
+/*
+ * This code comes from John the Ripper password cracker, with reentrant
+ * and crypt(3) interfaces added, but optimizations specific to password
+ * cracking removed.
+ *
+ * Written by Solar Designer <solar@openwall.com> in 1998-2001, and placed
+ * in the public domain.
+ *
+ * There's absolutely no warranty.
+ *
+ * It is my intent that you should be able to use this on your system,
+ * as a part of a software package, or anywhere else to improve security,
+ * ensure compatibility, or for any other purpose. I would appreciate
+ * it if you give credit where it is due and keep your modifications in
+ * the public domain as well, but I don't require that in order to let
+ * you place this code and any modifications you make under a license
+ * of your choice.
+ *
+ * This implementation is compatible with OpenBSD bcrypt.c (version 2a)
+ * by Niels Provos <provos@physnet.uni-hamburg.de>, and uses some of his
+ * ideas. The password hashing algorithm was designed by David Mazieres
+ * <dm@lcs.mit.edu>.
+ *
+ * There's a paper on the algorithm that explains its design decisions:
+ *
+ *	http://www.usenix.org/events/usenix99/provos.html
+ *
+ * Some of the tricks in BF_ROUND might be inspired by Eric Young's
+ * Blowfish library (I can't be sure if I would think of something if I
+ * hadn't seen his code).
+ */
+
+#include <postgres.h>
+#include "px-crypt.h"
+#define __set_errno(v)
+
+#ifndef __set_errno
+#define __set_errno(val) errno = (val)
+#endif
+
+#undef __CONST
+#ifdef __GNUC__
+#define __CONST __const
+#else
+#define __CONST
+#endif
+
+#ifdef __i386__
+#define BF_ASM				0	/* 1 */
+#define BF_SCALE			1
+#elif defined(__alpha__)
+#define BF_ASM				0
+#define BF_SCALE			1
+#else
+#define BF_ASM				0
+#define BF_SCALE			0
+#endif
+
+typedef unsigned int BF_word;
+
+/* Number of Blowfish rounds, this is also hardcoded into a few places */
+#define BF_N				16
+
+typedef BF_word BF_key[BF_N + 2];
+
+typedef struct {
+	BF_word S[4][0x100];
+	BF_key P;
+} BF_ctx;
+
+/*
+ * Magic IV for 64 Blowfish encryptions that we do at the end.
+ * The string is "OrpheanBeholderScryDoubt" on big-endian.
+ */
+static BF_word BF_magic_w[6] = {
+	0x4F727068, 0x65616E42, 0x65686F6C,
+	0x64657253, 0x63727944, 0x6F756274
+};
+
+/*
+ * P-box and S-box tables initialized with digits of Pi.
+ */
+static BF_ctx BF_init_state = {
+	{
+		{
+			0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
+			0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
+			0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+			0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
+			0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
+			0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+			0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
+			0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
+			0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+			0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
+			0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
+			0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+			0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
+			0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
+			0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+			0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
+			0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
+			0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+			0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
+			0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
+			0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+			0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
+			0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
+			0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+			0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
+			0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
+			0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+			0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
+			0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
+			0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+			0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
+			0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
+			0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+			0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
+			0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
+			0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+			0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
+			0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
+			0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+			0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
+			0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
+			0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+			0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
+			0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
+			0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+			0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
+			0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
+			0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+			0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
+			0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
+			0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+			0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
+			0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
+			0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+			0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
+			0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
+			0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+			0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
+			0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
+			0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+			0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
+			0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
+			0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+			0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
+		}, {
+			0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
+			0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
+			0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+			0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
+			0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
+			0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+			0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
+			0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
+			0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+			0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
+			0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
+			0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+			0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
+			0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
+			0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+			0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
+			0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
+			0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+			0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
+			0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
+			0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+			0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
+			0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
+			0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+			0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
+			0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
+			0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+			0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
+			0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
+			0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+			0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
+			0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
+			0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+			0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
+			0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
+			0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+			0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
+			0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
+			0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+			0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
+			0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
+			0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+			0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
+			0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
+			0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+			0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
+			0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
+			0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+			0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
+			0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
+			0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+			0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
+			0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
+			0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+			0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
+			0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
+			0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+			0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
+			0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
+			0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+			0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
+			0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
+			0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+			0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
+		}, {
+			0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
+			0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
+			0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+			0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
+			0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
+			0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+			0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
+			0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
+			0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+			0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
+			0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
+			0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+			0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
+			0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
+			0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+			0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
+			0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
+			0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+			0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
+			0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
+			0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+			0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
+			0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
+			0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+			0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
+			0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
+			0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+			0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
+			0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
+			0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+			0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
+			0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
+			0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+			0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
+			0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
+			0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+			0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
+			0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
+			0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+			0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
+			0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
+			0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+			0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
+			0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
+			0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+			0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
+			0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
+			0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+			0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
+			0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
+			0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+			0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
+			0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
+			0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+			0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
+			0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
+			0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+			0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
+			0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
+			0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+			0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
+			0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
+			0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+			0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
+		}, {
+			0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
+			0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
+			0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+			0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
+			0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
+			0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+			0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
+			0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
+			0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+			0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
+			0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
+			0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+			0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
+			0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
+			0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+			0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
+			0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
+			0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+			0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
+			0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
+			0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+			0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
+			0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
+			0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+			0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
+			0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
+			0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+			0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
+			0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
+			0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+			0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
+			0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
+			0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+			0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
+			0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
+			0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+			0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
+			0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
+			0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+			0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
+			0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
+			0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+			0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
+			0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
+			0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+			0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
+			0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
+			0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+			0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
+			0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
+			0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+			0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
+			0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
+			0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+			0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
+			0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
+			0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+			0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
+			0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
+			0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+			0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
+			0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
+			0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+			0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
+		}
+	}, {
+		0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+		0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+		0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+		0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
+		0x9216d5d9, 0x8979fb1b
+	}
+};
+
+static unsigned char BF_itoa64[64 + 1] =
+	"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+static unsigned char BF_atoi64[0x60] = {
+	64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1,
+	54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64,
+	64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+	17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 64, 64, 64, 64, 64,
+	64, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
+	43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 64, 64, 64, 64, 64
+};
+
+#define BF_safe_atoi64(dst, src) \
+{ \
+	tmp = (unsigned char)(src); \
+	if ((unsigned int)(tmp -= 0x20) >= 0x60) return -1; \
+	tmp = BF_atoi64[tmp]; \
+	if (tmp > 63) return -1; \
+	(dst) = tmp; \
+}
+
+static int BF_decode(BF_word *dst, __CONST char *src, int size)
+{
+	unsigned char *dptr = (unsigned char *)dst;
+	unsigned char *end = dptr + size;
+	unsigned char *sptr = (unsigned char *)src;
+	unsigned int tmp, c1, c2, c3, c4;
+
+	do {
+		BF_safe_atoi64(c1, *sptr++);
+		BF_safe_atoi64(c2, *sptr++);
+		*dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4);
+		if (dptr >= end) break;
+
+		BF_safe_atoi64(c3, *sptr++);
+		*dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2);
+		if (dptr >= end) break;
+
+		BF_safe_atoi64(c4, *sptr++);
+		*dptr++ = ((c3 & 0x03) << 6) | c4;
+	} while (dptr < end);
+
+	return 0;
+}
+
+static void BF_encode(char *dst, __CONST BF_word *src, int size)
+{
+	unsigned char *sptr = (unsigned char *)src;
+	unsigned char *end = sptr + size;
+	unsigned char *dptr = (unsigned char *)dst;
+	unsigned int c1, c2;
+
+	do {
+		c1 = *sptr++;
+		*dptr++ = BF_itoa64[c1 >> 2];
+		c1 = (c1 & 0x03) << 4;
+		if (sptr >= end) {
+			*dptr++ = BF_itoa64[c1];
+			break;
+		}
+
+		c2 = *sptr++;
+		c1 |= c2 >> 4;
+		*dptr++ = BF_itoa64[c1];
+		c1 = (c2 & 0x0f) << 2;
+		if (sptr >= end) {
+			*dptr++ = BF_itoa64[c1];
+			break;
+		}
+
+		c2 = *sptr++;
+		c1 |= c2 >> 6;
+		*dptr++ = BF_itoa64[c1];
+		*dptr++ = BF_itoa64[c2 & 0x3f];
+	} while (sptr < end);
+}
+
+static void BF_swap(BF_word *x, int count)
+{
+	static int endianness_check = 1;
+	char *is_little_endian = (char *)&endianness_check;
+	BF_word tmp;
+
+	if (*is_little_endian)
+	do {
+		tmp = *x;
+		tmp = (tmp << 16) | (tmp >> 16);
+		*x++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF);
+	} while (--count);
+}
+
+#if BF_SCALE
+/* Architectures which can shift addresses left by 2 bits with no extra cost */
+#define BF_ROUND(L, R, N) \
+	tmp1 = L & 0xFF; \
+	tmp2 = L >> 8; \
+	tmp2 &= 0xFF; \
+	tmp3 = L >> 16; \
+	tmp3 &= 0xFF; \
+	tmp4 = L >> 24; \
+	tmp1 = data.ctx.S[3][tmp1]; \
+	tmp2 = data.ctx.S[2][tmp2]; \
+	tmp3 = data.ctx.S[1][tmp3]; \
+	tmp3 += data.ctx.S[0][tmp4]; \
+	tmp3 ^= tmp2; \
+	R ^= data.ctx.P[N + 1]; \
+	tmp3 += tmp1; \
+	R ^= tmp3;
+#else
+/* Architectures with no complicated addressing modes supported */
+#define BF_INDEX(S, i) \
+	(*((BF_word *)(((unsigned char *)S) + (i))))
+#define BF_ROUND(L, R, N) \
+	tmp1 = L & 0xFF; \
+	tmp1 <<= 2; \
+	tmp2 = L >> 6; \
+	tmp2 &= 0x3FC; \
+	tmp3 = L >> 14; \
+	tmp3 &= 0x3FC; \
+	tmp4 = L >> 22; \
+	tmp4 &= 0x3FC; \
+	tmp1 = BF_INDEX(data.ctx.S[3], tmp1); \
+	tmp2 = BF_INDEX(data.ctx.S[2], tmp2); \
+	tmp3 = BF_INDEX(data.ctx.S[1], tmp3); \
+	tmp3 += BF_INDEX(data.ctx.S[0], tmp4); \
+	tmp3 ^= tmp2; \
+	R ^= data.ctx.P[N + 1]; \
+	tmp3 += tmp1; \
+	R ^= tmp3;
+#endif
+
+/*
+ * Encrypt one block, BF_N is hardcoded here.
+ */
+#define BF_ENCRYPT \
+	L ^= data.ctx.P[0]; \
+	BF_ROUND(L, R, 0); \
+	BF_ROUND(R, L, 1); \
+	BF_ROUND(L, R, 2); \
+	BF_ROUND(R, L, 3); \
+	BF_ROUND(L, R, 4); \
+	BF_ROUND(R, L, 5); \
+	BF_ROUND(L, R, 6); \
+	BF_ROUND(R, L, 7); \
+	BF_ROUND(L, R, 8); \
+	BF_ROUND(R, L, 9); \
+	BF_ROUND(L, R, 10); \
+	BF_ROUND(R, L, 11); \
+	BF_ROUND(L, R, 12); \
+	BF_ROUND(R, L, 13); \
+	BF_ROUND(L, R, 14); \
+	BF_ROUND(R, L, 15); \
+	tmp4 = R; \
+	R = L; \
+	L = tmp4 ^ data.ctx.P[BF_N + 1];
+
+#if BF_ASM
+
+extern void _BF_body_r(BF_ctx *ctx);
+#define BF_body() \
+	_BF_body_r(&data.ctx);
+
+#else
+
+#define BF_body() \
+	L = R = 0; \
+	ptr = data.ctx.P; \
+	do { \
+		ptr += 2; \
+		BF_ENCRYPT; \
+		*(ptr - 2) = L; \
+		*(ptr - 1) = R; \
+	} while (ptr < &data.ctx.P[BF_N + 2]); \
+\
+	ptr = data.ctx.S[0]; \
+	do { \
+		ptr += 2; \
+		BF_ENCRYPT; \
+		*(ptr - 2) = L; \
+		*(ptr - 1) = R; \
+	} while (ptr < &data.ctx.S[3][0xFF]);
+
+#endif
+
+static void BF_set_key(__CONST char *key, BF_key expanded, BF_key initial)
+{
+	__CONST char *ptr = key;
+	int i, j;
+	BF_word tmp;
+
+	for (i = 0; i < BF_N + 2; i++) {
+		tmp = 0;
+		for (j = 0; j < 4; j++) {
+			tmp <<= 8;
+			tmp |= *ptr;
+
+			if (!*ptr) ptr = key; else ptr++;
+		}
+
+		expanded[i] = tmp;
+		initial[i] = BF_init_state.P[i] ^ tmp;
+	}
+}
+
+char *_crypt_blowfish_rn(__CONST char *key, __CONST char *setting,
+	char *output, int size)
+{
+	struct {
+		BF_ctx ctx;
+		BF_key expanded_key;
+		union {
+			BF_word salt[4];
+			BF_word output[6];
+		} binary;
+	} data;
+	BF_word L, R;
+	BF_word tmp1, tmp2, tmp3, tmp4;
+	BF_word *ptr;
+	BF_word count;
+	int i;
+
+	if (size < 7 + 22 + 31 + 1) {
+		__set_errno(ERANGE);
+		return NULL;
+	}
+
+	if (setting[0] != '$' ||
+	    setting[1] != '2' ||
+	    setting[2] != 'a' ||
+	    setting[3] != '$' ||
+	    setting[4] < '0' || setting[4] > '3' ||
+	    setting[5] < '0' || setting[5] > '9' ||
+	    setting[6] != '$') {
+		__set_errno(EINVAL);
+		return NULL;
+	}
+
+	count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] - '0'));
+	if (count < 16 || BF_decode(data.binary.salt, &setting[7], 16)) {
+		memset(data.binary.salt, 0, sizeof(data.binary.salt));
+		__set_errno(EINVAL);
+		return NULL;
+	}
+	BF_swap(data.binary.salt, 4);
+
+	BF_set_key(key, data.expanded_key, data.ctx.P);
+
+	memcpy(data.ctx.S, BF_init_state.S, sizeof(data.ctx.S));
+
+	L = R = 0;
+	for (i = 0; i < BF_N + 2; i += 2) {
+		L ^= data.binary.salt[i & 2];
+		R ^= data.binary.salt[(i & 2) + 1];
+		BF_ENCRYPT;
+		data.ctx.P[i] = L;
+		data.ctx.P[i + 1] = R;
+	}
+
+	ptr = data.ctx.S[0];
+	do {
+		ptr += 4;
+		L ^= data.binary.salt[(BF_N + 2) & 3];
+		R ^= data.binary.salt[(BF_N + 3) & 3];
+		BF_ENCRYPT;
+		*(ptr - 4) = L;
+		*(ptr - 3) = R;
+
+		L ^= data.binary.salt[(BF_N + 4) & 3];
+		R ^= data.binary.salt[(BF_N + 5) & 3];
+		BF_ENCRYPT;
+		*(ptr - 2) = L;
+		*(ptr - 1) = R;
+	} while (ptr < &data.ctx.S[3][0xFF]);
+
+	do {
+		data.ctx.P[0] ^= data.expanded_key[0];
+		data.ctx.P[1] ^= data.expanded_key[1];
+		data.ctx.P[2] ^= data.expanded_key[2];
+		data.ctx.P[3] ^= data.expanded_key[3];
+		data.ctx.P[4] ^= data.expanded_key[4];
+		data.ctx.P[5] ^= data.expanded_key[5];
+		data.ctx.P[6] ^= data.expanded_key[6];
+		data.ctx.P[7] ^= data.expanded_key[7];
+		data.ctx.P[8] ^= data.expanded_key[8];
+		data.ctx.P[9] ^= data.expanded_key[9];
+		data.ctx.P[10] ^= data.expanded_key[10];
+		data.ctx.P[11] ^= data.expanded_key[11];
+		data.ctx.P[12] ^= data.expanded_key[12];
+		data.ctx.P[13] ^= data.expanded_key[13];
+		data.ctx.P[14] ^= data.expanded_key[14];
+		data.ctx.P[15] ^= data.expanded_key[15];
+		data.ctx.P[16] ^= data.expanded_key[16];
+		data.ctx.P[17] ^= data.expanded_key[17];
+
+		BF_body();
+
+		tmp1 = data.binary.salt[0];
+		tmp2 = data.binary.salt[1];
+		tmp3 = data.binary.salt[2];
+		tmp4 = data.binary.salt[3];
+		data.ctx.P[0] ^= tmp1;
+		data.ctx.P[1] ^= tmp2;
+		data.ctx.P[2] ^= tmp3;
+		data.ctx.P[3] ^= tmp4;
+		data.ctx.P[4] ^= tmp1;
+		data.ctx.P[5] ^= tmp2;
+		data.ctx.P[6] ^= tmp3;
+		data.ctx.P[7] ^= tmp4;
+		data.ctx.P[8] ^= tmp1;
+		data.ctx.P[9] ^= tmp2;
+		data.ctx.P[10] ^= tmp3;
+		data.ctx.P[11] ^= tmp4;
+		data.ctx.P[12] ^= tmp1;
+		data.ctx.P[13] ^= tmp2;
+		data.ctx.P[14] ^= tmp3;
+		data.ctx.P[15] ^= tmp4;
+		data.ctx.P[16] ^= tmp1;
+		data.ctx.P[17] ^= tmp2;
+
+		BF_body();
+	} while (--count);
+
+	for (i = 0; i < 6; i += 2) {
+		L = BF_magic_w[i];
+		R = BF_magic_w[i + 1];
+
+		count = 64;
+		do {
+			BF_ENCRYPT;
+		} while (--count);
+
+		data.binary.output[i] = L;
+		data.binary.output[i + 1] = R;
+	}
+
+	memcpy(output, setting, 7 + 22 - 1);
+	output[7 + 22 - 1] = BF_itoa64[(int)
+		BF_atoi64[(int)setting[7 + 22 - 1] - 0x20] & 0x30];
+
+/* This has to be bug-compatible with the original implementation, so
+ * only encode 23 of the 24 bytes. :-) */
+	BF_swap(data.binary.output, 6);
+	BF_encode(&output[7 + 22], data.binary.output, 23);
+	output[7 + 22 + 31] = '\0';
+
+/* Overwrite the most obvious sensitive data we have on the stack. Note
+ * that this does not guarantee there's no sensitive data left on the
+ * stack and/or in registers; I'm not aware of portable code that does. */
+	memset(&data, 0, sizeof(data));
+
+	return output;
+}
+
+char *_crypt_gensalt_blowfish_rn(unsigned long count,
+	__CONST char *input, int size, char *output, int output_size)
+{
+	if (size < 16 || output_size < 7 + 22 + 1 ||
+	    (count && (count < 4 || count > 31))) {
+		if (output_size > 0) output[0] = '\0';
+		__set_errno((output_size < 7 + 22 + 1) ? ERANGE : EINVAL);
+		return NULL;
+	}
+
+	if (!count) count = 5;
+
+	output[0] = '$';
+	output[1] = '2';
+	output[2] = 'a';
+	output[3] = '$';
+	output[4] = '0' + count / 10;
+	output[5] = '0' + count % 10;
+	output[6] = '$';
+
+	BF_encode(&output[7], (BF_word *)input, 16);
+	output[7 + 22] = '\0';
+
+	return output;
+}
diff --git a/contrib/pgcrypto/crypt-des.c b/contrib/pgcrypto/crypt-des.c
new file mode 100644
index 0000000000000000000000000000000000000000..d9e12127b7743e49963a486cc300a4c209f011ab
--- /dev/null
+++ b/contrib/pgcrypto/crypt-des.c
@@ -0,0 +1,761 @@
+/*
+ * FreeSec: libcrypt for NetBSD
+ *
+ * Copyright (c) 1994 David Burren
+ * All rights reserved.
+ *
+ * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet
+ *	this file should now *only* export crypt(), in order to make
+ *	binaries of libcrypt exportable from the USA
+ *
+ * Adapted for FreeBSD-4.0 by Mark R V Murray
+ *	this file should now *only* export crypt_des(), in order to make
+ *	a module that can be optionally included in libcrypt.
+ *
+ * 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 author nor the names of other contributors
+ *	  may be used to endorse or promote products derived from this software
+ *	  without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD: src/secure/lib/libcrypt/crypt-des.c,v 1.12 1999/09/20 12:39:20 markm Exp $
+ *
+ * This is an original implementation of the DES and the crypt(3) interfaces
+ * by David Burren <davidb@werj.com.au>.
+ *
+ * An excellent reference on the underlying algorithm (and related
+ * algorithms) is:
+ *
+ *	B. Schneier, Applied Cryptography: protocols, algorithms,
+ *	and source code in C, John Wiley & Sons, 1994.
+ *
+ * Note that in that book's description of DES the lookups for the initial,
+ * pbox, and final permutations are inverted (this has been brought to the
+ * attention of the author).  A list of errata for this book has been
+ * posted to the sci.crypt newsgroup by the author and is available for FTP.
+ *
+ * ARCHITECTURE ASSUMPTIONS:
+ *	It is assumed that the 8-byte arrays passed by reference can be
+ *	addressed as arrays of uint32's (ie. the CPU is not picky about
+ *	alignment).
+ */
+
+#include <postgres.h>
+#include "px-crypt.h"
+
+/* for ntohl/htonl */
+#include <netinet/in.h>
+
+
+/* We can't always assume gcc */
+#ifdef __GNUC__
+#define INLINE inline
+#endif
+
+#define _PASSWORD_EFMT1 '_'
+
+static uint8 IP[64] = {
+	58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
+	62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
+	57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
+	61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
+};
+
+static uint8 inv_key_perm[64];
+static uint8 u_key_perm[56];
+static uint8 key_perm[56] = {
+	57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
+	10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
+	63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
+	14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
+};
+
+static uint8 key_shifts[16] = {
+	1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
+};
+
+static uint8 inv_comp_perm[56];
+static uint8 comp_perm[48] = {
+	14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
+	23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
+	41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
+	44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
+};
+
+/*
+ *	No E box is used, as it's replaced by some ANDs, shifts, and ORs.
+ */
+
+static uint8 u_sbox[8][64];
+static uint8 sbox[8][64] = {
+	{
+		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
+	},
+	{
+		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
+	},
+	{
+		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
+	},
+	{
+		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
+	},
+	{
+		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
+	},
+	{
+		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
+	},
+	{
+		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
+	},
+	{
+		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 uint8 un_pbox[32];
+static uint8 pbox[32] = {
+	16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
+	2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
+};
+
+static uint32 _crypt_bits32[32] =
+{
+				0x80000000, 0x40000000, 0x20000000, 0x10000000,
+				0x08000000, 0x04000000, 0x02000000, 0x01000000,
+				0x00800000, 0x00400000, 0x00200000, 0x00100000,
+				0x00080000, 0x00040000, 0x00020000, 0x00010000,
+				0x00008000, 0x00004000, 0x00002000, 0x00001000,
+				0x00000800, 0x00000400, 0x00000200, 0x00000100,
+				0x00000080, 0x00000040, 0x00000020, 0x00000010,
+				0x00000008, 0x00000004, 0x00000002, 0x00000001
+};
+
+static uint8 _crypt_bits8[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
+
+static uint32 saltbits;
+static long old_salt;
+static uint32 *bits28,
+		   *bits24;
+static uint8 init_perm[64],
+			final_perm[64];
+static uint32 en_keysl[16],
+			en_keysr[16];
+static uint32 de_keysl[16],
+			de_keysr[16];
+static int	des_initialised = 0;
+static uint8 m_sbox[4][4096];
+static uint32 psbox[4][256];
+static uint32 ip_maskl[8][256],
+			ip_maskr[8][256];
+static uint32 fp_maskl[8][256],
+			fp_maskr[8][256];
+static uint32 key_perm_maskl[8][128],
+			key_perm_maskr[8][128];
+static uint32 comp_maskl[8][128],
+			comp_maskr[8][128];
+static uint32 old_rawkey0,
+			old_rawkey1;
+
+static INLINE int
+ascii_to_bin(char ch)
+{
+	if (ch > 'z')
+		return (0);
+	if (ch >= 'a')
+		return (ch - 'a' + 38);
+	if (ch > 'Z')
+		return (0);
+	if (ch >= 'A')
+		return (ch - 'A' + 12);
+	if (ch > '9')
+		return (0);
+	if (ch >= '.')
+		return (ch - '.');
+	return (0);
+}
+
+static void
+des_init()
+{
+	int			i,
+				j,
+				b,
+				k,
+				inbit,
+				obit;
+	uint32	   *p,
+			   *il,
+			   *ir,
+			   *fl,
+			   *fr;
+
+	old_rawkey0 = old_rawkey1 = 0L;
+	saltbits = 0L;
+	old_salt = 0L;
+	bits24 = (bits28 = _crypt_bits32 + 4) + 4;
+
+	/*
+	 * Invert the S-boxes, reordering the input bits.
+	 */
+	for (i = 0; i < 8; i++)
+		for (j = 0; j < 64; j++)
+		{
+			b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf);
+			u_sbox[i][j] = sbox[i][b];
+		}
+
+	/*
+	 * Convert the inverted S-boxes into 4 arrays of 8 bits.
+	 * Each will handle 12 bits of the S-box input.
+	 */
+	for (b = 0; b < 4; b++)
+		for (i = 0; i < 64; i++)
+			for (j = 0; j < 64; j++)
+				m_sbox[b][(i << 6) | j] =
+					(u_sbox[(b << 1)][i] << 4) |
+					u_sbox[(b << 1) + 1][j];
+
+	/*
+	 * Set up the initial & final permutations into a useful form, and
+	 * initialise the inverted key permutation.
+	 */
+	for (i = 0; i < 64; i++)
+	{
+		init_perm[final_perm[i] = IP[i] - 1] = i;
+		inv_key_perm[i] = 255;
+	}
+
+	/*
+	 * Invert the key permutation and initialise the inverted key
+	 * compression permutation.
+	 */
+	for (i = 0; i < 56; i++)
+	{
+		u_key_perm[i] = key_perm[i] - 1;
+		inv_key_perm[key_perm[i] - 1] = i;
+		inv_comp_perm[i] = 255;
+	}
+
+	/*
+	 * Invert the key compression permutation.
+	 */
+	for (i = 0; i < 48; i++)
+		inv_comp_perm[comp_perm[i] - 1] = i;
+
+	/*
+	 * Set up the OR-mask arrays for the initial and final permutations,
+	 * and for the key initial and compression permutations.
+	 */
+	for (k = 0; k < 8; k++)
+	{
+		for (i = 0; i < 256; i++)
+		{
+			*(il = &ip_maskl[k][i]) = 0L;
+			*(ir = &ip_maskr[k][i]) = 0L;
+			*(fl = &fp_maskl[k][i]) = 0L;
+			*(fr = &fp_maskr[k][i]) = 0L;
+			for (j = 0; j < 8; j++)
+			{
+				inbit = 8 * k + j;
+				if (i & _crypt_bits8[j])
+				{
+					if ((obit = init_perm[inbit]) < 32)
+						*il |= _crypt_bits32[obit];
+					else
+						*ir |= _crypt_bits32[obit - 32];
+					if ((obit = final_perm[inbit]) < 32)
+						*fl |= _crypt_bits32[obit];
+					else
+						*fr |= _crypt_bits32[obit - 32];
+				}
+			}
+		}
+		for (i = 0; i < 128; i++)
+		{
+			*(il = &key_perm_maskl[k][i]) = 0L;
+			*(ir = &key_perm_maskr[k][i]) = 0L;
+			for (j = 0; j < 7; j++)
+			{
+				inbit = 8 * k + j;
+				if (i & _crypt_bits8[j + 1])
+				{
+					if ((obit = inv_key_perm[inbit]) == 255)
+						continue;
+					if (obit < 28)
+						*il |= bits28[obit];
+					else
+						*ir |= bits28[obit - 28];
+				}
+			}
+			*(il = &comp_maskl[k][i]) = 0L;
+			*(ir = &comp_maskr[k][i]) = 0L;
+			for (j = 0; j < 7; j++)
+			{
+				inbit = 7 * k + j;
+				if (i & _crypt_bits8[j + 1])
+				{
+					if ((obit = inv_comp_perm[inbit]) == 255)
+						continue;
+					if (obit < 24)
+						*il |= bits24[obit];
+					else
+						*ir |= bits24[obit - 24];
+				}
+			}
+		}
+	}
+
+	/*
+	 * Invert the P-box permutation, and convert into OR-masks for
+	 * handling the output of the S-box arrays setup above.
+	 */
+	for (i = 0; i < 32; i++)
+		un_pbox[pbox[i] - 1] = i;
+
+	for (b = 0; b < 4; b++)
+		for (i = 0; i < 256; i++)
+		{
+			*(p = &psbox[b][i]) = 0L;
+			for (j = 0; j < 8; j++)
+			{
+				if (i & _crypt_bits8[j])
+					*p |= _crypt_bits32[un_pbox[8 * b + j]];
+			}
+		}
+
+	des_initialised = 1;
+}
+
+static void
+setup_salt(long salt)
+{
+	uint32		obit,
+				saltbit;
+	int			i;
+
+	if (salt == old_salt)
+		return;
+	old_salt = salt;
+
+	saltbits = 0L;
+	saltbit = 1;
+	obit = 0x800000;
+	for (i = 0; i < 24; i++)
+	{
+		if (salt & saltbit)
+			saltbits |= obit;
+		saltbit <<= 1;
+		obit >>= 1;
+	}
+}
+
+static int
+des_setkey(const char *key)
+{
+	uint32		k0,
+				k1,
+				rawkey0,
+				rawkey1;
+	int			shifts,
+				round;
+
+	if (!des_initialised)
+		des_init();
+
+	rawkey0 = ntohl(*(uint32 *) key);
+	rawkey1 = ntohl(*(uint32 *) (key + 4));
+
+	if ((rawkey0 | rawkey1)
+		&& rawkey0 == old_rawkey0
+		&& rawkey1 == old_rawkey1)
+	{
+		/*
+		 * Already setup for this key.
+		 * This optimisation fails on a zero key (which is weak and
+		 * has bad parity anyway) in order to simplify the starting
+		 * conditions.
+		 */
+		return (0);
+	}
+	old_rawkey0 = rawkey0;
+	old_rawkey1 = rawkey1;
+
+	/*
+	 *	Do key permutation and split into two 28-bit subkeys.
+	 */
+	k0 = key_perm_maskl[0][rawkey0 >> 25]
+		| key_perm_maskl[1][(rawkey0 >> 17) & 0x7f]
+		| key_perm_maskl[2][(rawkey0 >> 9) & 0x7f]
+		| key_perm_maskl[3][(rawkey0 >> 1) & 0x7f]
+		| key_perm_maskl[4][rawkey1 >> 25]
+		| key_perm_maskl[5][(rawkey1 >> 17) & 0x7f]
+		| key_perm_maskl[6][(rawkey1 >> 9) & 0x7f]
+		| key_perm_maskl[7][(rawkey1 >> 1) & 0x7f];
+	k1 = key_perm_maskr[0][rawkey0 >> 25]
+		| key_perm_maskr[1][(rawkey0 >> 17) & 0x7f]
+		| key_perm_maskr[2][(rawkey0 >> 9) & 0x7f]
+		| key_perm_maskr[3][(rawkey0 >> 1) & 0x7f]
+		| key_perm_maskr[4][rawkey1 >> 25]
+		| key_perm_maskr[5][(rawkey1 >> 17) & 0x7f]
+		| key_perm_maskr[6][(rawkey1 >> 9) & 0x7f]
+		| key_perm_maskr[7][(rawkey1 >> 1) & 0x7f];
+	/*
+	 *	Rotate subkeys and do compression permutation.
+	 */
+	shifts = 0;
+	for (round = 0; round < 16; round++)
+	{
+		uint32		t0,
+					t1;
+
+		shifts += key_shifts[round];
+
+		t0 = (k0 << shifts) | (k0 >> (28 - shifts));
+		t1 = (k1 << shifts) | (k1 >> (28 - shifts));
+
+		de_keysl[15 - round] =
+			en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f]
+			| comp_maskl[1][(t0 >> 14) & 0x7f]
+			| comp_maskl[2][(t0 >> 7) & 0x7f]
+			| comp_maskl[3][t0 & 0x7f]
+			| comp_maskl[4][(t1 >> 21) & 0x7f]
+			| comp_maskl[5][(t1 >> 14) & 0x7f]
+			| comp_maskl[6][(t1 >> 7) & 0x7f]
+			| comp_maskl[7][t1 & 0x7f];
+
+		de_keysr[15 - round] =
+			en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f]
+			| comp_maskr[1][(t0 >> 14) & 0x7f]
+			| comp_maskr[2][(t0 >> 7) & 0x7f]
+			| comp_maskr[3][t0 & 0x7f]
+			| comp_maskr[4][(t1 >> 21) & 0x7f]
+			| comp_maskr[5][(t1 >> 14) & 0x7f]
+			| comp_maskr[6][(t1 >> 7) & 0x7f]
+			| comp_maskr[7][t1 & 0x7f];
+	}
+	return (0);
+}
+
+static int
+do_des(uint32 l_in, uint32 r_in, uint32 * l_out, uint32 * r_out, int count)
+{
+	/*
+	 *	l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
+	 */
+	uint32		l,
+				r,
+			   *kl,
+			   *kr,
+			   *kl1,
+			   *kr1;
+	uint32		f,
+				r48l,
+				r48r;
+	int			round;
+
+	if (count == 0)
+		return (1);
+	else if (count > 0)
+	{
+		/*
+		 * Encrypting
+		 */
+		kl1 = en_keysl;
+		kr1 = en_keysr;
+	}
+	else
+	{
+		/*
+		 * Decrypting
+		 */
+		count = -count;
+		kl1 = de_keysl;
+		kr1 = de_keysr;
+	}
+
+	/*
+	 *	Do initial permutation (IP).
+	 */
+	l = ip_maskl[0][l_in >> 24]
+		| ip_maskl[1][(l_in >> 16) & 0xff]
+		| ip_maskl[2][(l_in >> 8) & 0xff]
+		| ip_maskl[3][l_in & 0xff]
+		| ip_maskl[4][r_in >> 24]
+		| ip_maskl[5][(r_in >> 16) & 0xff]
+		| ip_maskl[6][(r_in >> 8) & 0xff]
+		| ip_maskl[7][r_in & 0xff];
+	r = ip_maskr[0][l_in >> 24]
+		| ip_maskr[1][(l_in >> 16) & 0xff]
+		| ip_maskr[2][(l_in >> 8) & 0xff]
+		| ip_maskr[3][l_in & 0xff]
+		| ip_maskr[4][r_in >> 24]
+		| ip_maskr[5][(r_in >> 16) & 0xff]
+		| ip_maskr[6][(r_in >> 8) & 0xff]
+		| ip_maskr[7][r_in & 0xff];
+
+	while (count--)
+	{
+		/*
+		 * Do each round.
+		 */
+		kl = kl1;
+		kr = kr1;
+		round = 16;
+		while (round--)
+		{
+			/*
+			 * Expand R to 48 bits (simulate the E-box).
+			 */
+			r48l = ((r & 0x00000001) << 23)
+				| ((r & 0xf8000000) >> 9)
+				| ((r & 0x1f800000) >> 11)
+				| ((r & 0x01f80000) >> 13)
+				| ((r & 0x001f8000) >> 15);
+
+			r48r = ((r & 0x0001f800) << 7)
+				| ((r & 0x00001f80) << 5)
+				| ((r & 0x000001f8) << 3)
+				| ((r & 0x0000001f) << 1)
+				| ((r & 0x80000000) >> 31);
+			/*
+			 * Do salting for crypt() and friends, and
+			 * XOR with the permuted key.
+			 */
+			f = (r48l ^ r48r) & saltbits;
+			r48l ^= f ^ *kl++;
+			r48r ^= f ^ *kr++;
+			/*
+			 * Do sbox lookups (which shrink it back to 32 bits)
+			 * and do the pbox permutation at the same time.
+			 */
+			f = psbox[0][m_sbox[0][r48l >> 12]]
+				| psbox[1][m_sbox[1][r48l & 0xfff]]
+				| psbox[2][m_sbox[2][r48r >> 12]]
+				| psbox[3][m_sbox[3][r48r & 0xfff]];
+			/*
+			 * Now that we've permuted things, complete f().
+			 */
+			f ^= l;
+			l = r;
+			r = f;
+		}
+		r = l;
+		l = f;
+	}
+	/*
+	 * Do final permutation (inverse of IP).
+	 */
+	*l_out = fp_maskl[0][l >> 24]
+		| fp_maskl[1][(l >> 16) & 0xff]
+		| fp_maskl[2][(l >> 8) & 0xff]
+		| fp_maskl[3][l & 0xff]
+		| fp_maskl[4][r >> 24]
+		| fp_maskl[5][(r >> 16) & 0xff]
+		| fp_maskl[6][(r >> 8) & 0xff]
+		| fp_maskl[7][r & 0xff];
+	*r_out = fp_maskr[0][l >> 24]
+		| fp_maskr[1][(l >> 16) & 0xff]
+		| fp_maskr[2][(l >> 8) & 0xff]
+		| fp_maskr[3][l & 0xff]
+		| fp_maskr[4][r >> 24]
+		| fp_maskr[5][(r >> 16) & 0xff]
+		| fp_maskr[6][(r >> 8) & 0xff]
+		| fp_maskr[7][r & 0xff];
+	return (0);
+}
+
+static int
+des_cipher(const char *in, char *out, long salt, int count)
+{
+	uint32		l_out,
+				r_out,
+				rawl,
+				rawr;
+	int			retval;
+
+	if (!des_initialised)
+		des_init();
+
+	setup_salt(salt);
+
+	rawl = ntohl(*((uint32 *) in)++);
+	rawr = ntohl(*((uint32 *) in));
+
+	retval = do_des(rawl, rawr, &l_out, &r_out, count);
+
+	*((uint32 *) out)++ = htonl(l_out);
+	*((uint32 *) out) = htonl(r_out);
+	return (retval);
+}
+
+char *
+px_crypt_des(const char *key, const char *setting)
+{
+	int			i;
+	uint32		count,
+				salt,
+				l,
+				r0,
+				r1,
+				keybuf[2];
+	uint8	   *p,
+			   *q;
+	static uint8 output[21];
+
+	if (!des_initialised)
+		des_init();
+
+
+	/*
+	 * Copy the key, shifting each character up by one bit
+	 * and padding with zeros.
+	 */
+	q = (uint8 *) keybuf;
+	while (q - (uint8 *) keybuf - 8)
+	{
+		if ((*q++ = *key << 1))
+			key++;
+	}
+	if (des_setkey((uint8 *) keybuf))
+		return (NULL);
+
+#ifndef DISABLE_XDES
+	if (*setting == _PASSWORD_EFMT1)
+	{
+		/*
+		 * "new"-style:
+		 *	setting - underscore, 4 bytes of count, 4 bytes of salt
+		 *	key - unlimited characters
+		 */
+		for (i = 1, count = 0L; i < 5; i++)
+			count |= ascii_to_bin(setting[i]) << (i - 1) * 6;
+
+		for (i = 5, salt = 0L; i < 9; i++)
+			salt |= ascii_to_bin(setting[i]) << (i - 5) * 6;
+
+		while (*key)
+		{
+			/*
+			 * Encrypt the key with itself.
+			 */
+			if (des_cipher((uint8 *) keybuf, (uint8 *) keybuf, 0L, 1))
+				return (NULL);
+			/*
+			 * And XOR with the next 8 characters of the key.
+			 */
+			q = (uint8 *) keybuf;
+			while (q - (uint8 *) keybuf - 8 && *key)
+				*q++ ^= *key++ << 1;
+
+			if (des_setkey((uint8 *) keybuf))
+				return (NULL);
+		}
+		strncpy(output, setting, 9);
+
+		/*
+		 * Double check that we weren't given a short setting.
+		 * If we were, the above code will probably have created
+		 * wierd values for count and salt, but we don't really care.
+		 * Just make sure the output string doesn't have an extra
+		 * NUL in it.
+		 */
+		output[9] = '\0';
+		p = output + strlen(output);
+	}
+	else
+#endif	 /* !DISABLE_XDES */
+	{
+		/*
+		 * "old"-style:
+		 *	setting - 2 bytes of salt
+		 *	key - up to 8 characters
+		 */
+		count = 25;
+
+		salt = (ascii_to_bin(setting[1]) << 6)
+			| ascii_to_bin(setting[0]);
+
+		output[0] = setting[0];
+		/*
+		 * If the encrypted password that the salt was extracted from
+		 * is only 1 character long, the salt will be corrupted.  We
+		 * need to ensure that the output string doesn't have an extra
+		 * NUL in it!
+		 */
+		output[1] = setting[1] ? setting[1] : output[0];
+
+		p = output + 2;
+	}
+	setup_salt(salt);
+	/*
+	 * Do it.
+	 */
+	if (do_des(0L, 0L, &r0, &r1, count))
+		return (NULL);
+	/*
+	 * Now encode the result...
+	 */
+	l = (r0 >> 8);
+	*p++ = _crypt_a64[(l >> 18) & 0x3f];
+	*p++ = _crypt_a64[(l >> 12) & 0x3f];
+	*p++ = _crypt_a64[(l >> 6) & 0x3f];
+	*p++ = _crypt_a64[l & 0x3f];
+
+	l = (r0 << 16) | ((r1 >> 16) & 0xffff);
+	*p++ = _crypt_a64[(l >> 18) & 0x3f];
+	*p++ = _crypt_a64[(l >> 12) & 0x3f];
+	*p++ = _crypt_a64[(l >> 6) & 0x3f];
+	*p++ = _crypt_a64[l & 0x3f];
+
+	l = r1 << 2;
+	*p++ = _crypt_a64[(l >> 12) & 0x3f];
+	*p++ = _crypt_a64[(l >> 6) & 0x3f];
+	*p++ = _crypt_a64[l & 0x3f];
+	*p = 0;
+
+	return (output);
+}
diff --git a/contrib/pgcrypto/crypt-md5.c b/contrib/pgcrypto/crypt-md5.c
new file mode 100644
index 0000000000000000000000000000000000000000..02fba694965553371f84e207e42297869bbed5d3
--- /dev/null
+++ b/contrib/pgcrypto/crypt-md5.c
@@ -0,0 +1,156 @@
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@login.dknet.dk> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ * $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999/12/17 20:21:45 peter Exp $
+ *
+ */
+/* $Id: crypt-md5.c,v 1.1 2001/08/21 01:32:01 momjian Exp $ */
+
+#include <postgres.h>
+#include "px.h"
+#include "px-crypt.h"
+
+#define MD5_SIZE 16
+/*
+ * UNIX password
+ */
+
+char *
+px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)
+{
+	static char *magic = "$1$"; /*
+					 * This string is magic for
+					 * this algorithm.	Having
+					 * it this way, we can get
+					 * get better later on
+					 */
+	static char *p;
+	static const char *sp,
+			   *ep;
+	unsigned char final[MD5_SIZE];
+	int			sl,
+				pl,
+				i;
+	PX_MD	   *ctx,
+			   *ctx1;
+	int			err;
+	unsigned long l;
+
+	if (!passwd || dstlen < 120)
+		return NULL;
+	
+	/* Refine the Salt first */
+	sp = salt;
+
+	/* If it starts with the magic string, then skip that */
+	if (!strncmp(sp, magic, strlen(magic)))
+		sp += strlen(magic);
+
+	/* It stops at the first '$', max 8 chars */
+	for (ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
+		continue;
+
+	/* get the length of the true salt */
+	sl = ep - sp;
+
+	/* */
+	err = px_find_digest("md5", &ctx);
+	if (err)
+		return NULL;
+	err = px_find_digest("md5", &ctx1);
+
+	/* The password first, since that is what is most unknown */
+	px_md_update(ctx, pw, strlen(pw));
+
+	/* Then our magic string */
+	px_md_update(ctx, magic, strlen(magic));
+
+	/* Then the raw salt */
+	px_md_update(ctx, sp, sl);
+
+	/* Then just as many characters of the MD5(pw,salt,pw) */
+	px_md_update(ctx1, pw, strlen(pw));
+	px_md_update(ctx1, sp, sl);
+	px_md_update(ctx1, pw, strlen(pw));
+	px_md_finish(ctx1, final);
+	for (pl = strlen(pw); pl > 0; pl -= MD5_SIZE)
+		px_md_update(ctx, final, pl > MD5_SIZE ? MD5_SIZE : pl);
+
+	/* Don't leave anything around in vm they could use. */
+	memset(final, 0, sizeof final);
+
+	/* Then something really weird... */
+	for (i = strlen(pw); i; i >>= 1)
+		if (i & 1)
+			px_md_update(ctx, final, 1);
+		else
+			px_md_update(ctx, pw, 1);
+
+	/* Now make the output string */
+	strcpy(passwd, magic);
+	strncat(passwd, sp, sl);
+	strcat(passwd, "$");
+
+	px_md_finish(ctx, final);
+
+	/*
+	 * and now, just to make sure things don't run too fast
+	 * On a 60 Mhz Pentium this takes 34 msec, so you would
+	 * need 30 seconds to build a 1000 entry dictionary...
+	 */
+	for (i = 0; i < 1000; i++)
+	{
+		px_md_reset(ctx1);
+		if (i & 1)
+			px_md_update(ctx1, pw, strlen(pw));
+		else
+			px_md_update(ctx1, final, MD5_SIZE);
+
+		if (i % 3)
+			px_md_update(ctx1, sp, sl);
+
+		if (i % 7)
+			px_md_update(ctx1, pw, strlen(pw));
+
+		if (i & 1)
+			px_md_update(ctx1, final, MD5_SIZE);
+		else
+			px_md_update(ctx1, pw, strlen(pw));
+		px_md_finish(ctx1, final);
+	}
+
+	p = passwd + strlen(passwd);
+
+	l = (final[0] << 16) | (final[6] << 8) | final[12];
+	_crypt_to64(p, l, 4);
+	p += 4;
+	l = (final[1] << 16) | (final[7] << 8) | final[13];
+	_crypt_to64(p, l, 4);
+	p += 4;
+	l = (final[2] << 16) | (final[8] << 8) | final[14];
+	_crypt_to64(p, l, 4);
+	p += 4;
+	l = (final[3] << 16) | (final[9] << 8) | final[15];
+	_crypt_to64(p, l, 4);
+	p += 4;
+	l = (final[4] << 16) | (final[10] << 8) | final[5];
+	_crypt_to64(p, l, 4);
+	p += 4;
+	l = final[11];
+	_crypt_to64(p, l, 2);
+	p += 2;
+	*p = '\0';
+
+	/* Don't leave anything around in vm they could use. */
+	memset(final, 0, sizeof final);
+
+	px_md_free(ctx1);
+	px_md_free(ctx);
+
+	return passwd;
+}
diff --git a/contrib/pgcrypto/encode.o b/contrib/pgcrypto/encode.o
new file mode 100644
index 0000000000000000000000000000000000000000..255e82f7572aec94cd825ffdbc194f0c0e4dd7ee
Binary files /dev/null and b/contrib/pgcrypto/encode.o differ
diff --git a/contrib/pgcrypto/misc.c b/contrib/pgcrypto/misc.c
new file mode 100644
index 0000000000000000000000000000000000000000..7a3c429708545d88f73fbd3930d10fca1b262ed2
--- /dev/null
+++ b/contrib/pgcrypto/misc.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 1999
+ *		University of California.  All rights reserved.
+ *
+ * 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 author nor the names of any co-contributors
+ *	  may be used to endorse or promote products derived from this software
+ *	  without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY 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 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.
+ *
+ * $FreeBSD: src/lib/libcrypt/misc.c,v 1.1 1999/09/20 12:45:49 markm Exp $
+ *
+ */
+
+#include "px-crypt.h"
+
+char		px_crypt_a64[] =
+  "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+/* 0000000000111111111122222222223333333333444444444455555555556666 */
+/* 0123456789012345678901234567890123456789012345678901234567890123 */
+
+void
+px_crypt_to64(char *s, unsigned long v, int n)
+{
+	while (--n >= 0)
+	{
+		*s++ = px_crypt_a64[v & 0x3f];
+		v >>= 6;
+	}
+}
diff --git a/contrib/pgcrypto/px-crypt.c b/contrib/pgcrypto/px-crypt.c
new file mode 100644
index 0000000000000000000000000000000000000000..1d615a8a5a6710e33e54eed319b3cbca6265d105
--- /dev/null
+++ b/contrib/pgcrypto/px-crypt.c
@@ -0,0 +1,235 @@
+/*
+ * px-crypt.c
+ *		Wrapper for various crypt algorithms.
+ *
+ * Copyright (c) 2001 Marko Kreen
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $Id: px-crypt.c,v 1.1 2001/08/21 01:32:01 momjian Exp $
+ */
+
+#include <postgres.h>
+#include "px-crypt.h"
+
+
+#ifndef PX_SYSTEM_CRYPT
+
+static char *
+run_crypt_des(const char *psw, const char *salt,
+			 char *buf, unsigned len)
+{
+	char	   *res;
+
+	res = px_crypt_des(psw, salt);
+	if (strlen(res) > len - 1)
+		return NULL;
+	strcpy(buf, res);
+	return buf;
+}
+
+static char *
+run_crypt_md5(const char *psw, const char *salt,
+			 char *buf, unsigned len)
+{
+	char	   *res;
+	res = px_crypt_md5(psw, salt, buf, len);
+	return res;
+}
+
+static char *
+run_crypt_bf(const char *psw, const char *salt,
+			char *buf, unsigned len)
+{
+	char	   *res;
+
+	res = _crypt_blowfish_rn(psw, salt, buf, len);
+	if (!res)
+		return NULL;
+	strcpy(buf, res);
+	return buf;
+}
+
+static struct
+{
+	char		*id;
+	unsigned	id_len;
+	char	   *(*crypt) (const char *psw, const char *salt,
+									  char *buf, unsigned len);
+}			px_crypt_list[] =
+
+{
+	{ "$2a$", 4, run_crypt_bf },
+	{ "$2$", 3, NULL },							/* N/A */
+	{ "$1$", 3, run_crypt_md5 },
+	{ "_", 1, run_crypt_des },
+	{ "", 0, run_crypt_des },
+	{ NULL, 0, NULL }
+};
+
+char *
+px_crypt(const char *psw, const char *salt, char *buf, unsigned len)
+{
+	int			i;
+
+	for (i = 0; px_crypt_list[i].id; i++)
+	{
+		if (!px_crypt_list[i].id_len)
+			break;
+		if (!strncmp(salt, px_crypt_list[i].id, px_crypt_list[i].id_len))
+			break;
+	}
+
+	if (px_crypt_list[i].crypt == NULL)
+		return NULL;
+
+	return px_crypt_list[i].crypt(psw, salt, buf, len);
+}
+
+#else							/* PX_SYSTEM_CRYPT */
+
+extern char *crypt(const char *psw, const char *salt);
+
+char *
+px_crypt(const char *psw, const char *salt,
+		 char *buf, unsigned len)
+{
+	char	   *res;
+
+	res = crypt(psw, salt);
+	if (!res || strlen(res) >= len)
+		return NULL;
+	strcpy(buf, res);
+	return buf;
+}
+#endif
+
+/*
+ * salt generators
+ */
+
+static int my_rand64()
+{
+	return random() % 64;
+}
+
+static uint
+gen_des_salt(char *buf)
+{
+	buf[0] = px_crypt_a64[my_rand64()];
+	buf[1] = px_crypt_a64[my_rand64()];
+	buf[2] = 0;
+	
+	return 2;
+}
+
+static uint
+gen_xdes_salt(char *buf)
+{
+	strcpy(buf, "_12345678");
+	
+	px_crypt_to64(buf+1, (long)PX_XDES_ROUNDS, 4);
+	px_crypt_to64(buf+5, random(), 4);
+	
+	return 9;
+}
+
+static uint
+gen_md5_salt(char *buf)
+{
+	int i;
+	strcpy(buf, "$1$12345678$");
+	
+	for (i = 0; i < 8; i++)
+		buf[3 + i] = px_crypt_a64[my_rand64()];
+	
+	return 12;
+}
+
+static uint
+gen_bf_salt(char *buf)
+{
+	int i, count;
+	char *s;
+	char saltbuf[16+3];
+	unsigned slen = 16;
+	uint32 *v;
+
+	for (i = 0; i < slen; i++)
+		saltbuf[i] = random() & 255;
+	saltbuf[16] = 0;
+	saltbuf[17] = 0;
+	saltbuf[18] = 0;
+
+	strcpy(buf, "$2a$00$0123456789012345678901");
+
+	count = PX_BF_ROUNDS;
+	buf[4] = '0' + count / 10;
+	buf[5] = '0' + count % 10;
+	
+	s = buf + 7;
+	for (i = 0; i < slen; )
+	{
+		v = (uint32 *)&saltbuf[i];
+		if (i + 3 <= slen)
+			px_crypt_to64(s, *v, 4);
+		else
+			/* slen-i could be 1,2 make it 2,3 */
+			px_crypt_to64(s, *v, slen-i+1);
+		s += 4;
+		i += 3;
+	}
+		
+	s = buf;
+	/*s = _crypt_gensalt_blowfish_rn(count, saltbuf, 16, buf, PX_MAX_CRYPT);*/
+	
+	return s ? strlen(s) : 0;
+}
+
+struct generator {
+	char *name;
+	uint (*gen)(char *buf);
+};
+
+static struct generator gen_list [] = {
+	{ "des", gen_des_salt },
+	{ "md5", gen_md5_salt },
+	{ "xdes", gen_xdes_salt },
+	{ "bf", gen_bf_salt },
+	{ NULL, NULL }
+};
+
+uint
+px_gen_salt(const char *salt_type, char *buf)
+{
+	int i;
+	struct generator *g;
+	for (i = 0; gen_list[i].name; i++) {
+		g = &gen_list[i];
+		if (!strcasecmp(g->name, salt_type))
+			return g->gen(buf);
+	}
+
+	return 0;
+}
+
diff --git a/contrib/pgcrypto/px-crypt.h b/contrib/pgcrypto/px-crypt.h
new file mode 100644
index 0000000000000000000000000000000000000000..506d922e864feac4ee54beb7f6a8acc94fd261dd
--- /dev/null
+++ b/contrib/pgcrypto/px-crypt.h
@@ -0,0 +1,83 @@
+/*
+ * px-crypt.h
+ *		Header file for px_crypt().
+ *
+ * Copyright (c) 2001 Marko Kreen
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $Id: px-crypt.h,v 1.1 2001/08/21 01:32:01 momjian Exp $
+ */
+
+#ifndef _PX_CRYPT_H
+#define _PX_CRYPT_H
+
+/* max room for result */
+#define PX_MAX_CRYPT  128
+
+/* max salt returned by gen_salt() */
+#define PX_MAX_SALT_LEN     128
+
+/* rounds for xdes salt */
+/* NetBSD bin/passwd/local_passwd.c has (29 * 25)*/
+#define PX_XDES_ROUNDS		(29 * 25)
+
+/* rounds for blowfish salt */
+#define PX_BF_ROUNDS		6
+
+/*
+ * main interface
+ */
+char	   *px_crypt(const char *psw, const char *salt, char *buf, unsigned buflen);
+unsigned	px_gen_salt(const char *salt_type, char *dst);
+
+
+/* misc.c */
+extern void px_crypt_to64(char *s, unsigned long v, int n);
+extern char px_crypt_a64[];
+/* avoid conflicts with system libs */
+#define _crypt_to64 px_crypt_to64
+#define _crypt_a64 px_crypt_a64
+
+
+#ifndef PX_SYSTEM_CRYPT
+
+/* disable 'extended DES crypt' */
+/* #define DISABLE_XDES */
+
+/* crypt-blowfish.c */
+char *_crypt_gensalt_blowfish_rn(unsigned long count,
+						   const char *input, int size,
+						   char *output, int output_size);
+char *_crypt_blowfish_rn(const char *key, const char *setting,
+				   char *output, int size);
+
+/* crypt-des.c */
+char	   *px_crypt_des(const char *key, const char *setting);
+
+/* crypt-md5.c */
+char	   *px_crypt_md5(const char *pw, const char *salt,
+						char *dst, unsigned dstlen);
+
+#endif	 /* !PX_SYSTEM_CRYPT */
+#endif	 /* _PX_CRYPT_H */
diff --git a/contrib/pgcrypto/px-hmac.c b/contrib/pgcrypto/px-hmac.c
new file mode 100644
index 0000000000000000000000000000000000000000..d635aba124c78ffcfa6c48bf46f7d74872f3f800
--- /dev/null
+++ b/contrib/pgcrypto/px-hmac.c
@@ -0,0 +1,180 @@
+/*
+ * px-hmac.c
+ *		HMAC implementation.
+ *
+ * Copyright (c) 2001 Marko Kreen
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $Id: px-hmac.c,v 1.1 2001/08/21 01:32:01 momjian Exp $
+ */
+
+
+#include <postgres.h>
+
+#include "px.h"
+
+#define HMAC_IPAD 0x36
+#define HMAC_OPAD 0x5C
+
+static uint
+hmac_result_size(PX_HMAC * h)
+{
+	return px_md_result_size(h->md);
+}
+
+static uint
+hmac_block_size(PX_HMAC * h)
+{
+	return px_md_block_size(h->md);
+}
+
+static void
+hmac_init(PX_HMAC * h, const uint8 * key, uint klen)
+{
+	uint		bs,
+				hlen,
+				i;
+	uint8	   *keybuf;
+	PX_MD	   *md = h->md;
+
+	bs = px_md_block_size(md);
+	hlen = px_md_result_size(md);
+	keybuf = px_alloc(bs);
+	memset(keybuf, 0, bs);
+
+	if (klen > bs)
+	{
+		px_md_update(md, key, klen);
+		px_md_finish(md, keybuf);
+		px_md_reset(md);
+	}
+	else
+		memcpy(keybuf, key, klen);
+
+	for (i = 0; i < bs; i++)
+	{
+		h->p.ipad[i] = keybuf[i] ^ HMAC_IPAD;
+		h->p.opad[i] = keybuf[i] ^ HMAC_OPAD;
+	}
+
+	memset(keybuf, 0, bs);
+	px_free(keybuf);
+
+	px_md_update(md, h->p.ipad, bs);
+}
+
+static void
+hmac_reset(PX_HMAC * h)
+{
+	PX_MD	   *md = h->md;
+	uint		bs = px_md_block_size(md);
+
+	px_md_reset(md);
+	px_md_update(md, h->p.ipad, bs);
+}
+
+static void
+hmac_update(PX_HMAC * h, const uint8 * data, uint dlen)
+{
+	px_md_update(h->md, data, dlen);
+}
+
+static void
+hmac_finish(PX_HMAC * h, uint8 * dst)
+{
+	PX_MD	   *md = h->md;
+	uint		bs,
+				hlen;
+	uint8	   *buf;
+
+	bs = px_md_block_size(md);
+	hlen = px_md_result_size(md);
+
+	buf = px_alloc(hlen);
+
+	px_md_finish(md, buf);
+
+	px_md_reset(md);
+	px_md_update(md, h->p.opad, bs);
+	px_md_update(md, buf, hlen);
+	px_md_finish(md, dst);
+
+	memset(buf, 0, hlen);
+	px_free(buf);
+}
+
+static void
+hmac_free(PX_HMAC * h)
+{
+	uint		bs;
+
+	bs = px_md_block_size(h->md);
+	px_md_free(h->md);
+
+	memset(h->p.ipad, 0, bs);
+	memset(h->p.opad, 0, bs);
+	px_free(h->p.ipad);
+	px_free(h->p.opad);
+	px_free(h);
+}
+
+
+/* PUBLIC FUNCTIONS */
+
+int
+px_find_hmac(const char *name, PX_HMAC ** res)
+{
+	int			err;
+	PX_MD	   *md;
+	PX_HMAC    *h;
+	uint		bs;
+
+	err = px_find_digest(name, &md);
+	if (err)
+		return err;
+
+	bs = px_md_block_size(md);
+	if (bs < 2)
+	{
+		px_md_free(md);
+		return -1;
+	}
+
+	h = px_alloc(sizeof(*h));
+	h->p.ipad = px_alloc(bs);
+	h->p.opad = px_alloc(bs);
+	h->md = md;
+
+	h->result_size = hmac_result_size;
+	h->block_size = hmac_block_size;
+	h->reset = hmac_reset;
+	h->update = hmac_update;
+	h->finish = hmac_finish;
+	h->free = hmac_free;
+	h->init = hmac_init;
+
+	*res = h;
+
+	return 0;
+}
diff --git a/contrib/pgcrypto/px.c b/contrib/pgcrypto/px.c
new file mode 100644
index 0000000000000000000000000000000000000000..b3981be93ce41f25b374ab7581e82a4786463d7e
--- /dev/null
+++ b/contrib/pgcrypto/px.c
@@ -0,0 +1,299 @@
+/*
+ * px.c
+ *		Various cryptographic stuff for PostgreSQL.
+ * 
+ * Copyright (c) 2001 Marko Kreen
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $Id: px.c,v 1.1 2001/08/21 01:32:01 momjian Exp $
+ */
+
+#include <postgres.h>
+
+#include "px.h"
+
+
+const char *
+px_resolve_alias(const PX_Alias *list, const char *name)
+{
+	while (list->name) {
+		if (!strcasecmp(list->alias, name))
+			return list->name;
+		list++;
+	}
+	return name;
+}
+
+/*
+ * combo - cipher + padding (+ checksum)
+ */
+
+static uint
+combo_encrypt_len(PX_Combo *cx, uint dlen)
+{
+	return dlen + 512;
+}
+
+static uint
+combo_decrypt_len(PX_Combo *cx, uint dlen)
+{
+	return dlen;
+}
+
+static int
+combo_init(PX_Combo *cx, const uint8 *key, uint klen,
+		const uint8 *iv, uint ivlen)
+{
+	int err;
+	uint bs, ks, ivs;
+	PX_Cipher *c = cx->cipher;
+	uint8 *ivbuf = NULL;
+	uint8 *keybuf;
+
+	bs = px_cipher_block_size(c);
+	ks = px_cipher_key_size(c);
+
+	ivs = px_cipher_iv_size(c);
+	if (ivs > 0) {
+		ivbuf = px_alloc(ivs);
+		memset(ivbuf, 0, ivs);
+		if (ivlen > ivs)
+			memcpy(ivbuf, iv, ivs);
+		else
+			memcpy(ivbuf, iv, ivlen);
+	}
+
+	keybuf = px_alloc(ks);
+	memset(keybuf, 0, ks);
+	memcpy(keybuf, key, klen);
+
+	err = px_cipher_init(c, keybuf, klen, ivbuf);
+
+	if (ivbuf)
+		px_free(ivbuf);
+
+	return err;
+}
+
+static int
+combo_encrypt(PX_Combo *cx, const uint8 *data, uint dlen,
+                uint8 *res, uint *rlen)
+{
+	int err = 0;
+	uint8 *bbuf;
+	uint bs, maxlen, bpos, i, pad;
+
+	PX_Cipher *c = cx->cipher;
+
+	bbuf = NULL;
+	maxlen = *rlen;
+	bs = px_cipher_block_size(c);
+	
+	/* encrypt */
+	if (bs > 1) {
+		bbuf = px_alloc(bs * 4);
+		bpos = dlen % bs;
+		*rlen = dlen - bpos;
+		memcpy(bbuf, data + *rlen, bpos);
+
+		/* encrypt full-block data */
+		if (*rlen) {
+			err = px_cipher_encrypt(c, data, *rlen, res);
+			if (err)
+				goto out;
+		}
+		
+		/* bbuf has now bpos bytes of stuff */
+		if (cx->padding) {
+			pad = bs - (bpos % bs);
+			for (i = 0; i < pad; i++)
+				bbuf[bpos++] = pad;
+		} else if (bpos % bs) {
+			/* ERROR? */
+			pad = bs - (bpos % bs);
+			for (i = 0; i < pad; i++)
+				bbuf[bpos++] = 0;
+		}
+
+		/* encrypt the rest - pad */
+		if (bpos) {
+			err = px_cipher_encrypt(c, bbuf, bpos, res + *rlen);
+			*rlen += bpos;
+		}
+	} else {
+		/* stream cipher/mode - no pad needed */
+		err = px_cipher_encrypt(c, data, dlen, res);
+		if (err)
+			goto out;
+		*rlen = dlen;
+	}
+out:
+	if (bbuf) px_free(bbuf);
+
+	return err;
+}
+
+static int
+combo_decrypt(PX_Combo *cx, const uint8 *data, uint dlen,
+                uint8 *res, uint *rlen)
+{
+	uint bs, i, pad;
+	uint pad_ok;
+
+	PX_Cipher *c = cx->cipher;
+
+	bs = px_cipher_block_size(c);
+	if (bs > 1 && (dlen % bs) != 0) {
+		goto block_error;
+	}
+	
+	/* decrypt */
+	*rlen = dlen;
+	px_cipher_decrypt(c, data, dlen, res);
+	
+	/* unpad */
+	if (bs > 1 && cx->padding) {
+		pad = res[*rlen - 1];
+		pad_ok = 0;
+		if (pad > 0 && pad <= bs && pad <= *rlen) {
+			pad_ok = 1;
+			for (i = *rlen - pad; i < *rlen; i++)
+				if (res[i] != pad) {
+					pad_ok = 0;
+					break;
+				}
+		}
+				
+		if (pad_ok)
+			*rlen -= pad;
+	}
+
+	return 0;
+	
+	/* error reporting should be done in pgcrypto.c */
+block_error:
+	elog(NOTICE, "Data not a multiple of block size");
+	return -1;
+}
+
+static void
+combo_free(PX_Combo *cx)
+{
+	if (cx->cipher)
+		px_cipher_free(cx->cipher);
+	memset(cx, 0, sizeof(*cx));
+	px_free(cx);
+}
+
+/* PARSER */
+
+static void
+parse_cipher_name(char *full, char **cipher, char **pad)
+{
+	char *p, *p2, *q;
+	*cipher = full;
+	*pad = NULL;
+	
+	p = strchr(full, '/');
+	if (p != NULL)
+		*p++ = 0;
+	while (p != NULL) {
+		if ((q = strchr(p, '/')) != NULL)
+			*q++ = 0;
+		
+		if (!*p) {
+			p = q;
+			continue;
+		}
+		p2 = strchr(p, ':');
+		if (p2 != NULL) {
+			*p2++ = 0;
+			if (!strcmp(p, "pad")) {
+				*pad = p2;
+			} else {
+				elog(ERROR, "Unknown component: '%s'", p);
+			}
+		}
+		p = q;
+	}
+}
+
+/* provider */
+
+int
+px_find_combo(const char *name, PX_Combo **res)
+{
+	int err;
+	char *buf, *s_cipher, *s_pad;
+
+	PX_Combo *cx;
+
+	cx = px_alloc(sizeof(*cx));
+	memset(cx, 0, sizeof(*cx));
+
+	buf = px_alloc(strlen(name) + 1);
+	strcpy(buf, name);
+
+	parse_cipher_name(buf, &s_cipher, &s_pad);
+	if (s_cipher == NULL) {
+		px_free(buf);
+		px_free(cx);
+		return -1;
+	}
+
+	err = px_find_cipher(s_cipher, &cx->cipher);
+	if (err)
+		goto err1;
+	
+	if (s_pad != NULL) {
+		if (!strcmp(s_pad, "pkcs"))
+			cx->padding = 1;
+		else if (!strcmp(s_pad, "none"))
+			cx->padding = 0;
+		else
+			goto err1;
+	} else
+		cx->padding = 1;
+
+	cx->init = combo_init;
+	cx->encrypt = combo_encrypt;
+	cx->decrypt = combo_decrypt;
+	cx->encrypt_len = combo_encrypt_len;
+	cx->decrypt_len = combo_decrypt_len;
+	cx->free = combo_free;
+
+	px_free(buf);
+
+	*res = cx;
+
+	return 0;
+	
+err1:
+	if (cx->cipher)
+		px_cipher_free(cx->cipher);
+	px_free(cx);
+	px_free(buf);
+	return -1;
+}
+
diff --git a/contrib/pgcrypto/px.h b/contrib/pgcrypto/px.h
new file mode 100644
index 0000000000000000000000000000000000000000..d9ee0d1db41adfee65b43fac8db44a19221f229f
--- /dev/null
+++ b/contrib/pgcrypto/px.h
@@ -0,0 +1,177 @@
+/*
+ * px.h
+ *		Header file for pgcrypto.
+ * 
+ * Copyright (c) 2001 Marko Kreen
+ * All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ * $Id: px.h,v 1.1 2001/08/21 01:32:01 momjian Exp $
+ */
+
+#ifndef __PX_H
+#define __PX_H
+
+#if 1
+
+#define px_alloc(s) palloc(s)
+#define px_realloc(p, s) prealloc(p, s)
+#define px_free(p)  pfree(p)
+
+#else
+
+void *xalloc(size_t s);
+void *xrealloc(void *p, size_t s);
+void  xfree(void *p);
+
+#define px_alloc(s) xalloc(s)
+#define px_realloc(p, s) xrealloc(p, s)
+#define px_free(p)  xfree(p)
+
+#endif
+
+/* max len of 'type' parms */
+#define PX_MAX_NAMELEN      128
+
+/* max salt returned */
+#define PX_MAX_SALT_LEN		128
+
+
+typedef struct px_digest PX_MD;
+typedef struct px_alias PX_Alias;
+typedef struct px_hmac PX_HMAC;
+typedef struct px_cipher PX_Cipher;
+typedef struct px_combo PX_Combo;
+
+struct px_digest {
+	uint (*result_size)(PX_MD *h);
+	uint (*block_size)(PX_MD *h);
+	void (*reset)(PX_MD *h);
+	void (*update)(PX_MD *h, const uint8 *data, uint dlen);
+	void (*finish)(PX_MD *h, uint8 *dst);
+	void (*free)(PX_MD *h);
+	/* private */
+	union {
+		uint code;
+		const void *ptr;
+	} p;
+};
+
+struct px_alias {
+	char *alias;
+	char *name;
+};
+
+struct px_hmac {
+	uint (*result_size)(PX_HMAC *h);
+	uint (*block_size)(PX_HMAC *h);
+	void (*reset)(PX_HMAC *h);
+	void (*update)(PX_HMAC *h, const uint8 *data, uint dlen);
+	void (*finish)(PX_HMAC *h, uint8 *dst);
+	void (*free)(PX_HMAC *h);
+	void (*init)(PX_HMAC *h, const uint8 *key, uint klen);
+	
+	PX_MD *md;
+	/* private */
+	struct {
+		uint8 *ipad;
+		uint8 *opad;
+	} p;
+};
+
+struct px_cipher {
+	uint (*block_size)(PX_Cipher *c);
+	uint (*key_size)(PX_Cipher *c);		/* max key len */
+	uint (*iv_size)(PX_Cipher *c);
+	
+	int (*init)(PX_Cipher *c, const uint8 *key, uint klen, const uint8 *iv);
+	int (*encrypt)(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res);
+	int (*decrypt)(PX_Cipher *c, const uint8 *data, uint dlen, uint8 *res);
+	void (*free)(PX_Cipher *c);
+	/* private */
+	void *ptr;
+	int pstat; /* mcrypt uses it */
+};
+
+struct px_combo {
+	int (*init)(PX_Combo *cx, const uint8 *key, uint klen,
+			const uint8 *iv, uint ivlen);
+	int (*encrypt)(PX_Combo *cx, const uint8 *data, uint dlen,
+			uint8 *res, uint *rlen);
+	int (*decrypt)(PX_Combo *cx, const uint8 *data, uint dlen,
+			uint8 *res, uint *rlen);
+	uint (*encrypt_len)(PX_Combo *cx, uint dlen);
+	uint (*decrypt_len)(PX_Combo *cx, uint dlen);
+	void (*free)(PX_Combo *cx);
+
+	PX_Cipher *cipher;
+	uint padding;
+};
+
+int px_find_digest(const char *name, PX_MD **res);
+int px_find_hmac(const char *name, PX_HMAC **res);
+int px_find_cipher(const char *name, PX_Cipher **res);
+int px_find_combo(const char *name, PX_Combo **res);
+
+const char *px_resolve_alias(const PX_Alias *aliases, const char *name);
+
+#define px_md_result_size(md)		(md)->result_size(md)
+#define px_md_block_size(md)		(md)->block_size(md)
+#define px_md_reset(md)			(md)->reset(md)
+#define px_md_update(md, data, dlen)	(md)->update(md, data, dlen)
+#define px_md_finish(md, buf)		(md)->finish(md, buf)
+#define px_md_free(md)			(md)->free(md)
+
+#define px_hmac_result_size(hmac)	(hmac)->result_size(hmac)
+#define px_hmac_block_size(hmac)	(hmac)->block_size(hmac)
+#define px_hmac_reset(hmac)		(hmac)->reset(hmac)
+#define px_hmac_init(hmac, key, klen)	(hmac)->init(hmac, key, klen)
+#define px_hmac_update(hmac, data, dlen) (hmac)->update(hmac, data, dlen)
+#define px_hmac_finish(hmac, buf)	(hmac)->finish(hmac, buf)
+#define px_hmac_free(hmac)		(hmac)->free(hmac)
+
+
+#define px_cipher_key_size(c)		(c)->key_size(c)
+#define px_cipher_block_size(c)		(c)->block_size(c)
+#define px_cipher_iv_size(c)		(c)->iv_size(c)
+#define px_cipher_init(c, k, klen, iv)	(c)->init(c, k, klen, iv)
+#define px_cipher_encrypt(c, data, dlen, res) \
+					(c)->encrypt(c, data, dlen, res)
+#define px_cipher_decrypt(c, data, dlen, res) \
+					(c)->decrypt(c, data, dlen, res)
+#define px_cipher_free(c)		(c)->free(c)
+
+
+#define px_combo_encrypt_len(c, dlen)	(c)->encrypt_len(c, dlen)
+#define px_combo_decrypt_len(c, dlen)	(c)->decrypt_len(c, dlen)
+#define px_combo_init(c, key, klen, iv, ivlen) \
+					(c)->init(c, key, klen, iv, ivlen)
+#define px_combo_encrypt(c, data, dlen, res, rlen) \
+					(c)->encrypt(c, data, dlen, res, rlen)
+#define px_combo_decrypt(c, data, dlen, res, rlen) \
+					(c)->decrypt(c, data, dlen, res, rlen)
+#define px_combo_free(c)		(c)->free(c)
+
+
+#endif /* __PX_H */
+
diff --git a/contrib/pgcrypto/rijndael.c b/contrib/pgcrypto/rijndael.c
new file mode 100644
index 0000000000000000000000000000000000000000..e4cb6d732e1c2700204a61238b6383253bb9ad4e
--- /dev/null
+++ b/contrib/pgcrypto/rijndael.c
@@ -0,0 +1,580 @@
+/*	$OpenBSD: rijndael.c,v 1.6 2000/12/09 18:51:34 markus Exp $	*/
+
+/* This is an independent implementation of the encryption algorithm:   */
+/*                                                                      */
+/*         RIJNDAEL by Joan Daemen and Vincent Rijmen                   */
+/*                                                                      */
+/* which is a candidate algorithm in the Advanced Encryption Standard   */
+/* programme of the US National Institute of Standards and Technology.  */
+/*                                                                      */
+/* Copyright in this implementation is held by Dr B R Gladman but I     */
+/* hereby give permission for its free direct or derivative use subject */
+/* to acknowledgment of its origin and compliance with any conditions   */
+/* that the originators of the algorithm place on its exploitation.     */
+/*                                                                      */
+/* Dr Brian Gladman (gladman@seven77.demon.co.uk) 14th January 1999     */
+
+/* Timing data for Rijndael (rijndael.c)
+
+Algorithm: rijndael (rijndael.c)
+
+128 bit key:
+Key Setup:    305/1389 cycles (encrypt/decrypt)
+Encrypt:       374 cycles =    68.4 mbits/sec
+Decrypt:       352 cycles =    72.7 mbits/sec
+Mean:          363 cycles =    70.5 mbits/sec
+
+192 bit key:
+Key Setup:    277/1595 cycles (encrypt/decrypt)
+Encrypt:       439 cycles =    58.3 mbits/sec
+Decrypt:       425 cycles =    60.2 mbits/sec
+Mean:          432 cycles =    59.3 mbits/sec
+
+256 bit key:
+Key Setup:    374/1960 cycles (encrypt/decrypt)
+Encrypt:       502 cycles =    51.0 mbits/sec
+Decrypt:       498 cycles =    51.4 mbits/sec
+Mean:          500 cycles =    51.2 mbits/sec
+
+*/
+
+#include <postgres.h>
+
+#include "rijndael.h"
+
+#define PRE_CALC_TABLES
+#define LARGE_TABLES
+
+static void gen_tabs	__P((void));
+
+/* 3. Basic macros for speeding up generic operations               */
+
+/* Circular rotate of 32 bit values                                 */
+
+#define rotr(x,n)   (((x) >> ((int)(n))) | ((x) << (32 - (int)(n))))
+#define rotl(x,n)   (((x) << ((int)(n))) | ((x) >> (32 - (int)(n))))
+
+/* Invert byte order in a 32 bit variable                           */
+
+#define bswap(x)    ((rotl(x, 8) & 0x00ff00ff) | (rotr(x, 8) & 0xff00ff00))
+
+/* Extract byte from a 32 bit quantity (little endian notation)     */ 
+
+#define byte(x,n)   ((u1byte)((x) >> (8 * n)))
+
+#if BYTE_ORDER != LITTLE_ENDIAN
+#define BYTE_SWAP
+#endif
+
+#ifdef  BYTE_SWAP
+#define io_swap(x)  bswap(x)
+#else
+#define io_swap(x)  (x)
+#endif
+
+#ifdef PRINT_TABS
+#undef PRE_CALC_TABLES
+#endif
+
+#ifdef PRE_CALC_TABLES
+
+#include "rijndael.tbl"
+#define tab_gen		1
+
+#else /* !PRE_CALC_TABLES */
+
+static u1byte  pow_tab[256];
+static u1byte  log_tab[256];
+static u1byte  sbx_tab[256];
+static u1byte  isb_tab[256];
+static u4byte  rco_tab[ 10];
+static u4byte  ft_tab[4][256];
+static u4byte  it_tab[4][256];
+
+#ifdef  LARGE_TABLES
+static   u4byte  fl_tab[4][256];
+static   u4byte  il_tab[4][256];
+#endif
+
+static u4byte  tab_gen = 0;
+#endif /* !PRE_CALC_TABLES */
+
+#define ff_mult(a,b)    (a && b ? pow_tab[(log_tab[a] + log_tab[b]) % 255] : 0)
+
+#define f_rn(bo, bi, n, k)                          \
+    bo[n] =  ft_tab[0][byte(bi[n],0)] ^             \
+             ft_tab[1][byte(bi[(n + 1) & 3],1)] ^   \
+             ft_tab[2][byte(bi[(n + 2) & 3],2)] ^   \
+             ft_tab[3][byte(bi[(n + 3) & 3],3)] ^ *(k + n)
+
+#define i_rn(bo, bi, n, k)                          \
+    bo[n] =  it_tab[0][byte(bi[n],0)] ^             \
+             it_tab[1][byte(bi[(n + 3) & 3],1)] ^   \
+             it_tab[2][byte(bi[(n + 2) & 3],2)] ^   \
+             it_tab[3][byte(bi[(n + 1) & 3],3)] ^ *(k + n)
+
+#ifdef LARGE_TABLES
+
+#define ls_box(x)                \
+    ( fl_tab[0][byte(x, 0)] ^    \
+      fl_tab[1][byte(x, 1)] ^    \
+      fl_tab[2][byte(x, 2)] ^    \
+      fl_tab[3][byte(x, 3)] )
+
+#define f_rl(bo, bi, n, k)                          \
+    bo[n] =  fl_tab[0][byte(bi[n],0)] ^             \
+             fl_tab[1][byte(bi[(n + 1) & 3],1)] ^   \
+             fl_tab[2][byte(bi[(n + 2) & 3],2)] ^   \
+             fl_tab[3][byte(bi[(n + 3) & 3],3)] ^ *(k + n)
+
+#define i_rl(bo, bi, n, k)                          \
+    bo[n] =  il_tab[0][byte(bi[n],0)] ^             \
+             il_tab[1][byte(bi[(n + 3) & 3],1)] ^   \
+             il_tab[2][byte(bi[(n + 2) & 3],2)] ^   \
+             il_tab[3][byte(bi[(n + 1) & 3],3)] ^ *(k + n)
+
+#else
+
+#define ls_box(x)                            \
+    ((u4byte)sbx_tab[byte(x, 0)] <<  0) ^    \
+    ((u4byte)sbx_tab[byte(x, 1)] <<  8) ^    \
+    ((u4byte)sbx_tab[byte(x, 2)] << 16) ^    \
+    ((u4byte)sbx_tab[byte(x, 3)] << 24)
+
+#define f_rl(bo, bi, n, k)                                      \
+    bo[n] = (u4byte)sbx_tab[byte(bi[n],0)] ^                    \
+        rotl(((u4byte)sbx_tab[byte(bi[(n + 1) & 3],1)]),  8) ^  \
+        rotl(((u4byte)sbx_tab[byte(bi[(n + 2) & 3],2)]), 16) ^  \
+        rotl(((u4byte)sbx_tab[byte(bi[(n + 3) & 3],3)]), 24) ^ *(k + n)
+
+#define i_rl(bo, bi, n, k)                                      \
+    bo[n] = (u4byte)isb_tab[byte(bi[n],0)] ^                    \
+        rotl(((u4byte)isb_tab[byte(bi[(n + 3) & 3],1)]),  8) ^  \
+        rotl(((u4byte)isb_tab[byte(bi[(n + 2) & 3],2)]), 16) ^  \
+        rotl(((u4byte)isb_tab[byte(bi[(n + 1) & 3],3)]), 24) ^ *(k + n)
+
+#endif
+
+static void
+gen_tabs(void)
+{
+#ifndef PRE_CALC_TABLES
+	u4byte  i, t;
+	u1byte  p, q;
+
+	/* log and power tables for GF(2**8) finite field with  */
+	/* 0x11b as modular polynomial - the simplest prmitive  */
+	/* root is 0x11, used here to generate the tables       */
+
+	for(i = 0,p = 1; i < 256; ++i) {
+		pow_tab[i] = (u1byte)p; log_tab[p] = (u1byte)i;
+
+		p = p ^ (p << 1) ^ (p & 0x80 ? 0x01b : 0);
+	}
+
+	log_tab[1] = 0; p = 1;
+
+	for(i = 0; i < 10; ++i) {
+		rco_tab[i] = p; 
+
+		p = (p << 1) ^ (p & 0x80 ? 0x1b : 0);
+	}
+
+	/* note that the affine byte transformation matrix in   */
+	/* rijndael specification is in big endian format with  */
+	/* bit 0 as the most significant bit. In the remainder  */
+	/* of the specification the bits are numbered from the  */
+	/* least significant end of a byte.                     */
+
+	for(i = 0; i < 256; ++i) {
+		p = (i ? pow_tab[255 - log_tab[i]] : 0); q = p; 
+		q = (q >> 7) | (q << 1); p ^= q; 
+		q = (q >> 7) | (q << 1); p ^= q; 
+		q = (q >> 7) | (q << 1); p ^= q; 
+		q = (q >> 7) | (q << 1); p ^= q ^ 0x63; 
+		sbx_tab[i] = (u1byte)p; isb_tab[p] = (u1byte)i;
+	}
+
+	for(i = 0; i < 256; ++i) {
+		p = sbx_tab[i]; 
+
+#ifdef  LARGE_TABLES        
+        
+		t = p; fl_tab[0][i] = t;
+		fl_tab[1][i] = rotl(t,  8);
+		fl_tab[2][i] = rotl(t, 16);
+		fl_tab[3][i] = rotl(t, 24);
+#endif
+		t = ((u4byte)ff_mult(2, p)) |
+			((u4byte)p <<  8) |
+			((u4byte)p << 16) |
+			((u4byte)ff_mult(3, p) << 24);
+        
+		ft_tab[0][i] = t;
+		ft_tab[1][i] = rotl(t,  8);
+		ft_tab[2][i] = rotl(t, 16);
+		ft_tab[3][i] = rotl(t, 24);
+
+		p = isb_tab[i]; 
+
+#ifdef  LARGE_TABLES        
+        
+		t = p; il_tab[0][i] = t; 
+		il_tab[1][i] = rotl(t,  8); 
+		il_tab[2][i] = rotl(t, 16); 
+		il_tab[3][i] = rotl(t, 24);
+#endif 
+		t = ((u4byte)ff_mult(14, p)) |
+			((u4byte)ff_mult( 9, p) <<  8) |
+			((u4byte)ff_mult(13, p) << 16) |
+			((u4byte)ff_mult(11, p) << 24);
+        
+		it_tab[0][i] = t; 
+		it_tab[1][i] = rotl(t,  8); 
+		it_tab[2][i] = rotl(t, 16); 
+		it_tab[3][i] = rotl(t, 24); 
+	}
+
+	tab_gen = 1;
+#endif /* !PRE_CALC_TABLES */
+}
+
+
+#define star_x(x) (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
+
+#define imix_col(y,x)       \
+    u   = star_x(x);        \
+    v   = star_x(u);        \
+    w   = star_x(v);        \
+    t   = w ^ (x);          \
+   (y)  = u ^ v ^ w;        \
+   (y) ^= rotr(u ^ t,  8) ^ \
+          rotr(v ^ t, 16) ^ \
+          rotr(t,24)
+
+/* initialise the key schedule from the user supplied key   */
+
+#define loop4(i)                                    \
+{   t = ls_box(rotr(t,  8)) ^ rco_tab[i];           \
+    t ^= e_key[4 * i];     e_key[4 * i + 4] = t;    \
+    t ^= e_key[4 * i + 1]; e_key[4 * i + 5] = t;    \
+    t ^= e_key[4 * i + 2]; e_key[4 * i + 6] = t;    \
+    t ^= e_key[4 * i + 3]; e_key[4 * i + 7] = t;    \
+}
+
+#define loop6(i)                                    \
+{   t = ls_box(rotr(t,  8)) ^ rco_tab[i];           \
+    t ^= e_key[6 * i];     e_key[6 * i + 6] = t;    \
+    t ^= e_key[6 * i + 1]; e_key[6 * i + 7] = t;    \
+    t ^= e_key[6 * i + 2]; e_key[6 * i + 8] = t;    \
+    t ^= e_key[6 * i + 3]; e_key[6 * i + 9] = t;    \
+    t ^= e_key[6 * i + 4]; e_key[6 * i + 10] = t;   \
+    t ^= e_key[6 * i + 5]; e_key[6 * i + 11] = t;   \
+}
+
+#define loop8(i)                                    \
+{   t = ls_box(rotr(t,  8)) ^ rco_tab[i];           \
+    t ^= e_key[8 * i];     e_key[8 * i + 8] = t;    \
+    t ^= e_key[8 * i + 1]; e_key[8 * i + 9] = t;    \
+    t ^= e_key[8 * i + 2]; e_key[8 * i + 10] = t;   \
+    t ^= e_key[8 * i + 3]; e_key[8 * i + 11] = t;   \
+    t  = e_key[8 * i + 4] ^ ls_box(t);              \
+    e_key[8 * i + 12] = t;                          \
+    t ^= e_key[8 * i + 5]; e_key[8 * i + 13] = t;   \
+    t ^= e_key[8 * i + 6]; e_key[8 * i + 14] = t;   \
+    t ^= e_key[8 * i + 7]; e_key[8 * i + 15] = t;   \
+}
+
+rijndael_ctx *
+rijndael_set_key(rijndael_ctx *ctx, const u4byte *in_key, const u4byte key_len,
+		 int encrypt)
+{  
+	u4byte  i, t, u, v, w;
+	u4byte *e_key = ctx->e_key;
+	u4byte *d_key = ctx->d_key;
+
+	ctx->decrypt = !encrypt;
+
+	if(!tab_gen)
+		gen_tabs();
+
+	ctx->k_len = (key_len + 31) / 32;
+
+	e_key[0] = io_swap(in_key[0]); e_key[1] = io_swap(in_key[1]);
+	e_key[2] = io_swap(in_key[2]); e_key[3] = io_swap(in_key[3]);
+	
+	switch(ctx->k_len) {
+        case 4: t = e_key[3];
+                for(i = 0; i < 10; ++i) 
+			loop4(i);
+                break;
+
+        case 6: e_key[4] = io_swap(in_key[4]); t = e_key[5] = io_swap(in_key[5]);
+                for(i = 0; i < 8; ++i) 
+			loop6(i);
+                break;
+
+        case 8: e_key[4] = io_swap(in_key[4]); e_key[5] = io_swap(in_key[5]);
+                e_key[6] = io_swap(in_key[6]); t = e_key[7] = io_swap(in_key[7]);
+                for(i = 0; i < 7; ++i) 
+			loop8(i);
+                break;
+	}
+
+	if (!encrypt) {
+		d_key[0] = e_key[0]; d_key[1] = e_key[1];
+		d_key[2] = e_key[2]; d_key[3] = e_key[3];
+
+		for(i = 4; i < 4 * ctx->k_len + 24; ++i) {
+			imix_col(d_key[i], e_key[i]);
+		}
+	}
+
+	return ctx;
+}
+
+/* encrypt a block of text  */
+
+#define f_nround(bo, bi, k) \
+    f_rn(bo, bi, 0, k);     \
+    f_rn(bo, bi, 1, k);     \
+    f_rn(bo, bi, 2, k);     \
+    f_rn(bo, bi, 3, k);     \
+    k += 4
+
+#define f_lround(bo, bi, k) \
+    f_rl(bo, bi, 0, k);     \
+    f_rl(bo, bi, 1, k);     \
+    f_rl(bo, bi, 2, k);     \
+    f_rl(bo, bi, 3, k)
+
+void
+rijndael_encrypt(rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
+{   
+	u4byte k_len = ctx->k_len;
+	u4byte *e_key = ctx->e_key;
+	u4byte  b0[4], b1[4], *kp;
+
+	b0[0] = io_swap(in_blk[0]) ^ e_key[0];
+	b0[1] = io_swap(in_blk[1]) ^ e_key[1];
+	b0[2] = io_swap(in_blk[2]) ^ e_key[2];
+	b0[3] = io_swap(in_blk[3]) ^ e_key[3];
+
+	kp = e_key + 4;
+
+	if(k_len > 6) {
+		f_nround(b1, b0, kp); f_nround(b0, b1, kp);
+	}
+
+	if(k_len > 4) {
+		f_nround(b1, b0, kp); f_nround(b0, b1, kp);
+	}
+
+	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
+	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
+	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
+	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
+	f_nround(b1, b0, kp); f_lround(b0, b1, kp);
+
+	out_blk[0] = io_swap(b0[0]); out_blk[1] = io_swap(b0[1]);
+	out_blk[2] = io_swap(b0[2]); out_blk[3] = io_swap(b0[3]);
+}
+
+/* decrypt a block of text  */
+
+#define i_nround(bo, bi, k) \
+    i_rn(bo, bi, 0, k);     \
+    i_rn(bo, bi, 1, k);     \
+    i_rn(bo, bi, 2, k);     \
+    i_rn(bo, bi, 3, k);     \
+    k -= 4
+
+#define i_lround(bo, bi, k) \
+    i_rl(bo, bi, 0, k);     \
+    i_rl(bo, bi, 1, k);     \
+    i_rl(bo, bi, 2, k);     \
+    i_rl(bo, bi, 3, k)
+
+void
+rijndael_decrypt(rijndael_ctx *ctx, const u4byte *in_blk, u4byte *out_blk)
+{  
+	u4byte  b0[4], b1[4], *kp;
+	u4byte k_len = ctx->k_len;
+	u4byte *e_key = ctx->e_key;
+	u4byte *d_key = ctx->d_key;
+
+	b0[0] = io_swap(in_blk[0]) ^ e_key[4 * k_len + 24];
+	b0[1] = io_swap(in_blk[1]) ^ e_key[4 * k_len + 25];
+	b0[2] = io_swap(in_blk[2]) ^ e_key[4 * k_len + 26];
+	b0[3] = io_swap(in_blk[3]) ^ e_key[4 * k_len + 27];
+
+	kp = d_key + 4 * (k_len + 5);
+
+	if(k_len > 6) {
+		i_nround(b1, b0, kp); i_nround(b0, b1, kp);
+	}
+
+	if(k_len > 4) {
+		i_nround(b1, b0, kp); i_nround(b0, b1, kp);
+	}
+
+	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
+	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
+	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
+	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
+	i_nround(b1, b0, kp); i_lround(b0, b1, kp);
+
+	out_blk[0] = io_swap(b0[0]); out_blk[1] = io_swap(b0[1]);
+	out_blk[2] = io_swap(b0[2]); out_blk[3] = io_swap(b0[3]);
+}
+
+/*
+ * conventional interface
+ *
+ * ATM it hopes all data is 4-byte aligned - which
+ * should be true for PX.  -marko
+ */
+
+void aes_set_key(rijndael_ctx * ctx, const uint8 *key, uint keybits, int enc)
+{
+	uint32 *k;
+	k = (uint32*)key;
+	rijndael_set_key(ctx, k, keybits, enc);
+}
+
+void aes_ecb_encrypt(rijndael_ctx *ctx, uint8 *data, unsigned len)
+{
+	unsigned bs = 16;
+	uint32 *d;
+	while (len >= bs) {
+		d = (uint32*)data;
+		rijndael_encrypt(ctx, d, d);
+
+		len -= bs;
+		data += bs;
+	}
+}
+
+void aes_ecb_decrypt(rijndael_ctx *ctx, uint8 *data, unsigned len)
+{
+	unsigned bs = 16;
+	uint32 *d;
+	while (len >= bs) {
+		d = (uint32*)data;
+		rijndael_decrypt(ctx, d, d);
+
+		len -= bs;
+		data += bs;
+	}
+}
+
+void aes_cbc_encrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
+{
+	uint32 *iv = (uint32 *)iva;
+	uint32 *d = (uint32 *)data;
+	unsigned bs = 16;
+
+	while (len >= bs) {
+		d[0] ^= iv[0];  d[1] ^= iv[1];
+		d[2] ^= iv[2];  d[3] ^= iv[3];
+		
+		rijndael_encrypt(ctx, d, d);
+
+		iv = d;
+		d += bs/4;
+		len -= bs;
+	}
+}
+
+void aes_cbc_decrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len)
+{
+	uint32 *d = (uint32 *)data;
+	unsigned bs = 16;
+	uint32 buf[4], iv[4];
+
+	memcpy(iv, iva, bs);
+	while (len >= bs) {
+		buf[0] = d[0]; buf[1] = d[1];
+		buf[2] = d[2]; buf[3] = d[3];
+		
+		rijndael_decrypt(ctx, buf, d);
+		
+		d[0] ^= iv[0];  d[1] ^= iv[1];
+		d[2] ^= iv[2];  d[3] ^= iv[3];
+		
+		iv[0] = buf[0]; iv[1] = buf[1];
+		iv[2] = buf[2]; iv[3] = buf[3];
+		d += 4;
+		len -= bs;
+	}
+}
+
+/*
+ * pre-calculate tables.
+ *
+ * On i386 lifts 17k from .bss to .rodata
+ * and avoids 1k code and setup time.
+ *    -marko
+ */
+#ifdef PRINT_TABS
+
+static void show256u8(char *name, uint8 *data)
+{
+	int i;
+	printf("static const u1byte  %s[256] = {\n  ", name);
+	for (i = 0; i < 256; ) {
+		printf("%u", pow_tab[i++]);
+		if (i < 256)
+			printf(i % 16 ? ", " : ",\n  ");
+	}
+	printf("\n};\n\n");
+}
+
+
+static void show4x256u32(char *name, uint32 data[4][256])
+{
+	int i, j;
+	printf("static const u4byte  %s[4][256] = {\n{\n  ", name);
+	for (i = 0; i < 4; i++) {
+		for (j = 0; j < 256; ) {
+			printf("0x%08x", data[i][j]);
+			j++;
+			if (j < 256)
+				printf(j % 4 ? ", " : ",\n  ");
+		}
+		printf(i < 3 ? "\n}, {\n  " : "\n}\n");
+	}
+	printf("};\n\n");
+}
+
+int main()
+{
+	int i;
+	char *hdr = "/* Generated by rijndael.c */\n\n";
+	
+	gen_tabs();
+
+	printf(hdr);
+	show256u8("pow_tab", pow_tab);
+	show256u8("log_tab", log_tab);
+	show256u8("sbx_tab", sbx_tab);
+	show256u8("isb_tab", isb_tab);
+	
+	show4x256u32("ft_tab", ft_tab);
+	show4x256u32("it_tab", it_tab);
+#ifdef LARGE_TABLES
+	show4x256u32("fl_tab", fl_tab);
+	show4x256u32("il_tab", il_tab);
+#endif
+	printf("static const u4byte rco_tab[10] = {\n  ");
+	for (i = 0; i < 10; i++) {
+		printf("0x%08x", rco_tab[i]);
+		if (i < 9) printf(", ");
+		if (i == 4) printf("\n  ");
+	}
+	printf("\n};\n\n");
+	return 0;
+}
+
+#endif
+
diff --git a/contrib/pgcrypto/rijndael.h b/contrib/pgcrypto/rijndael.h
new file mode 100644
index 0000000000000000000000000000000000000000..9d9587760ca39bbde9481d5daa33cbbcedc98441
--- /dev/null
+++ b/contrib/pgcrypto/rijndael.h
@@ -0,0 +1,57 @@
+/*	$OpenBSD: rijndael.h,v 1.3 2001/05/09 23:01:32 markus Exp $	*/
+
+/* This is an independent implementation of the encryption algorithm:   */
+/*                                                                      */
+/*         RIJNDAEL by Joan Daemen and Vincent Rijmen                   */
+/*                                                                      */
+/* which is a candidate algorithm in the Advanced Encryption Standard   */
+/* programme of the US National Institute of Standards and Technology.  */
+/*                                                                      */
+/* Copyright in this implementation is held by Dr B R Gladman but I     */
+/* hereby give permission for its free direct or derivative use subject */
+/* to acknowledgment of its origin and compliance with any conditions   */
+/* that the originators of the algorithm place on its exploitation.     */
+/*                                                                      */
+/* Dr Brian Gladman (gladman@seven77.demon.co.uk) 14th January 1999     */
+
+#ifndef _RIJNDAEL_H_
+#define _RIJNDAEL_H_
+
+/* 1. Standard types for AES cryptography source code               */
+
+typedef uint8   u1byte; /* an 8 bit unsigned character type */
+typedef uint16  u2byte; /* a 16 bit unsigned integer type   */
+typedef uint32  u4byte; /* a 32 bit unsigned integer type   */
+
+typedef int8     s1byte; /* an 8 bit signed character type   */
+typedef int16    s2byte; /* a 16 bit signed integer type     */
+typedef int32    s4byte; /* a 32 bit signed integer type     */
+
+typedef struct _rijndael_ctx {
+	u4byte  k_len;
+	int decrypt;
+	u4byte  e_key[64];
+	u4byte  d_key[64];
+} rijndael_ctx;
+
+
+/* 2. Standard interface for AES cryptographic routines             */
+
+/* These are all based on 32 bit unsigned values and will therefore */
+/* require endian conversions for big-endian architectures          */
+
+rijndael_ctx *
+rijndael_set_key __P((rijndael_ctx *, const u4byte *, const u4byte, int));
+void rijndael_encrypt __P((rijndael_ctx *, const u4byte *, u4byte *));
+void rijndael_decrypt __P((rijndael_ctx *, const u4byte *, u4byte *));
+
+/* conventional interface */
+
+void aes_set_key(rijndael_ctx * ctx, const uint8 *key, uint keybits, int enc);
+void aes_ecb_encrypt(rijndael_ctx *ctx, uint8 *data, unsigned len);
+void aes_ecb_decrypt(rijndael_ctx *ctx, uint8 *data, unsigned len);
+void aes_cbc_encrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len);
+void aes_cbc_decrypt(rijndael_ctx *ctx, uint8 *iva, uint8 *data, unsigned len);
+
+
+#endif /* _RIJNDAEL_H_ */
diff --git a/contrib/pgcrypto/rijndael.tbl b/contrib/pgcrypto/rijndael.tbl
new file mode 100644
index 0000000000000000000000000000000000000000..bc0a3822ccafd9a0fcccca27ca42bfc76133fc8c
--- /dev/null
+++ b/contrib/pgcrypto/rijndael.tbl
@@ -0,0 +1,1139 @@
+/* Generated by rijndael.c */
+
+static const u1byte  pow_tab[256] = {
+  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
+  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
+  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
+  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
+  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
+  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
+  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
+  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
+  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
+  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
+  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
+  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
+  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
+  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
+  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
+  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
+};
+
+static const u1byte  log_tab[256] = {
+  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
+  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
+  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
+  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
+  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
+  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
+  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
+  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
+  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
+  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
+  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
+  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
+  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
+  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
+  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
+  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
+};
+
+static const u1byte  sbx_tab[256] = {
+  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
+  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
+  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
+  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
+  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
+  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
+  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
+  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
+  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
+  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
+  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
+  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
+  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
+  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
+  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
+  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
+};
+
+static const u1byte  isb_tab[256] = {
+  1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
+  95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
+  229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49,
+  83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205,
+  76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136,
+  131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154,
+  181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163,
+  254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160,
+  251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65,
+  195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117,
+  159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128,
+  155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84,
+  252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202,
+  69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14,
+  18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23,
+  57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
+};
+
+static const u4byte  ft_tab[4][256] = {
+{
+  0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6,
+  0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591,
+  0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56,
+  0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec,
+  0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa,
+  0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb,
+  0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45,
+  0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b,
+  0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c,
+  0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83,
+  0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9,
+  0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a,
+  0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d,
+  0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f,
+  0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df,
+  0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea,
+  0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34,
+  0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b,
+  0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d,
+  0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413,
+  0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1,
+  0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6,
+  0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972,
+  0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85,
+  0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed,
+  0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511,
+  0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe,
+  0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b,
+  0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05,
+  0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
+  0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142,
+  0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf,
+  0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3,
+  0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e,
+  0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a,
+  0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6,
+  0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3,
+  0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b,
+  0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428,
+  0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad,
+  0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14,
+  0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8,
+  0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4,
+  0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2,
+  0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda,
+  0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949,
+  0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf,
+  0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810,
+  0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c,
+  0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697,
+  0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e,
+  0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f,
+  0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc,
+  0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c,
+  0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969,
+  0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27,
+  0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122,
+  0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433,
+  0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9,
+  0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
+  0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a,
+  0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0,
+  0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e,
+  0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c
+}, {
+  0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d,
+  0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154,
+  0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d,
+  0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a,
+  0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87,
+  0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b,
+  0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea,
+  0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b,
+  0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a,
+  0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f,
+  0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908,
+  0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f,
+  0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e,
+  0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5,
+  0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d,
+  0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f,
+  0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e,
+  0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb,
+  0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce,
+  0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397,
+  0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c,
+  0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed,
+  0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b,
+  0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a,
+  0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16,
+  0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194,
+  0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81,
+  0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3,
+  0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a,
+  0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104,
+  0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263,
+  0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d,
+  0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f,
+  0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39,
+  0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47,
+  0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695,
+  0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f,
+  0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83,
+  0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c,
+  0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76,
+  0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e,
+  0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4,
+  0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6,
+  0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b,
+  0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7,
+  0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0,
+  0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25,
+  0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018,
+  0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72,
+  0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751,
+  0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21,
+  0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85,
+  0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa,
+  0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12,
+  0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0,
+  0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9,
+  0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233,
+  0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7,
+  0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920,
+  0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a,
+  0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17,
+  0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8,
+  0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11,
+  0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a
+}, {
+  0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b,
+  0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5,
+  0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b,
+  0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76,
+  0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d,
+  0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0,
+  0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf,
+  0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0,
+  0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26,
+  0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc,
+  0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1,
+  0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15,
+  0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3,
+  0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a,
+  0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2,
+  0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75,
+  0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a,
+  0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0,
+  0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3,
+  0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784,
+  0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced,
+  0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b,
+  0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39,
+  0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf,
+  0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb,
+  0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485,
+  0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f,
+  0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8,
+  0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f,
+  0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5,
+  0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321,
+  0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2,
+  0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec,
+  0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917,
+  0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d,
+  0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573,
+  0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc,
+  0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388,
+  0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14,
+  0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db,
+  0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a,
+  0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c,
+  0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662,
+  0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79,
+  0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d,
+  0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9,
+  0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea,
+  0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808,
+  0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e,
+  0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6,
+  0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f,
+  0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a,
+  0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66,
+  0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e,
+  0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9,
+  0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e,
+  0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311,
+  0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794,
+  0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9,
+  0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf,
+  0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d,
+  0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868,
+  0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f,
+  0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16
+}, {
+  0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b,
+  0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5,
+  0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b,
+  0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676,
+  0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d,
+  0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0,
+  0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf,
+  0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0,
+  0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626,
+  0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc,
+  0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1,
+  0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515,
+  0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3,
+  0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a,
+  0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2,
+  0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575,
+  0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a,
+  0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0,
+  0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3,
+  0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484,
+  0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded,
+  0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b,
+  0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939,
+  0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf,
+  0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb,
+  0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585,
+  0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f,
+  0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8,
+  0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f,
+  0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5,
+  0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121,
+  0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2,
+  0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec,
+  0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717,
+  0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d,
+  0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373,
+  0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc,
+  0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888,
+  0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414,
+  0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb,
+  0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a,
+  0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c,
+  0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262,
+  0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979,
+  0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d,
+  0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9,
+  0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea,
+  0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808,
+  0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e,
+  0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6,
+  0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f,
+  0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a,
+  0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666,
+  0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e,
+  0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9,
+  0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e,
+  0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111,
+  0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494,
+  0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9,
+  0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf,
+  0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d,
+  0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868,
+  0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f,
+  0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616
+}
+};
+
+static const u4byte  it_tab[4][256] = {
+{
+  0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a,
+  0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b,
+  0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5,
+  0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5,
+  0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d,
+  0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b,
+  0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295,
+  0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e,
+  0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927,
+  0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d,
+  0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362,
+  0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9,
+  0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52,
+  0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566,
+  0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3,
+  0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed,
+  0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e,
+  0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4,
+  0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4,
+  0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd,
+  0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d,
+  0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060,
+  0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967,
+  0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879,
+  0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000,
+  0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c,
+  0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36,
+  0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624,
+  0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b,
+  0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c,
+  0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12,
+  0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14,
+  0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3,
+  0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b,
+  0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8,
+  0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684,
+  0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7,
+  0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177,
+  0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947,
+  0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322,
+  0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498,
+  0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f,
+  0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54,
+  0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382,
+  0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf,
+  0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb,
+  0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83,
+  0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef,
+  0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029,
+  0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235,
+  0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733,
+  0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117,
+  0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4,
+  0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546,
+  0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb,
+  0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d,
+  0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb,
+  0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a,
+  0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773,
+  0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478,
+  0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2,
+  0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff,
+  0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664,
+  0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0
+}, {
+  0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96,
+  0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93,
+  0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525,
+  0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f,
+  0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1,
+  0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6,
+  0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da,
+  0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44,
+  0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd,
+  0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4,
+  0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245,
+  0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994,
+  0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7,
+  0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a,
+  0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5,
+  0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c,
+  0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1,
+  0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a,
+  0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475,
+  0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51,
+  0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46,
+  0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff,
+  0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777,
+  0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db,
+  0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000,
+  0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e,
+  0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627,
+  0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a,
+  0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e,
+  0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16,
+  0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d,
+  0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8,
+  0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd,
+  0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34,
+  0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863,
+  0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420,
+  0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d,
+  0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0,
+  0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722,
+  0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef,
+  0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836,
+  0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4,
+  0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462,
+  0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5,
+  0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3,
+  0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b,
+  0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8,
+  0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6,
+  0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6,
+  0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0,
+  0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315,
+  0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f,
+  0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df,
+  0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f,
+  0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e,
+  0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13,
+  0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89,
+  0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c,
+  0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf,
+  0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886,
+  0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f,
+  0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41,
+  0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490,
+  0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042
+}, {
+  0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e,
+  0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303,
+  0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c,
+  0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3,
+  0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0,
+  0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9,
+  0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59,
+  0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8,
+  0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71,
+  0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a,
+  0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f,
+  0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b,
+  0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8,
+  0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab,
+  0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508,
+  0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82,
+  0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2,
+  0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe,
+  0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb,
+  0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110,
+  0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd,
+  0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15,
+  0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e,
+  0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee,
+  0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000,
+  0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72,
+  0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739,
+  0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e,
+  0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91,
+  0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a,
+  0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17,
+  0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9,
+  0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60,
+  0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e,
+  0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1,
+  0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011,
+  0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1,
+  0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3,
+  0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264,
+  0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90,
+  0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b,
+  0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf,
+  0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246,
+  0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af,
+  0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312,
+  0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb,
+  0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a,
+  0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8,
+  0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c,
+  0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066,
+  0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8,
+  0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6,
+  0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04,
+  0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51,
+  0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41,
+  0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347,
+  0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c,
+  0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1,
+  0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37,
+  0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db,
+  0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40,
+  0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195,
+  0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1,
+  0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257
+}, {
+  0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27,
+  0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3,
+  0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02,
+  0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362,
+  0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe,
+  0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3,
+  0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952,
+  0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9,
+  0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9,
+  0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace,
+  0x63184adf, 0xe582311a, 0x97603351, 0x62457f53,
+  0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08,
+  0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b,
+  0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55,
+  0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837,
+  0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216,
+  0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269,
+  0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6,
+  0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6,
+  0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e,
+  0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6,
+  0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550,
+  0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9,
+  0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8,
+  0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000,
+  0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a,
+  0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d,
+  0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36,
+  0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b,
+  0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12,
+  0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b,
+  0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e,
+  0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f,
+  0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb,
+  0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4,
+  0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6,
+  0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129,
+  0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1,
+  0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9,
+  0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033,
+  0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4,
+  0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad,
+  0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e,
+  0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3,
+  0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225,
+  0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b,
+  0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f,
+  0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815,
+  0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0,
+  0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2,
+  0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7,
+  0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691,
+  0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496,
+  0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165,
+  0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b,
+  0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6,
+  0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13,
+  0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147,
+  0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7,
+  0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44,
+  0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3,
+  0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d,
+  0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156,
+  0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8
+}
+};
+
+static const u4byte  fl_tab[4][256] = {
+{
+  0x00000063, 0x0000007c, 0x00000077, 0x0000007b,
+  0x000000f2, 0x0000006b, 0x0000006f, 0x000000c5,
+  0x00000030, 0x00000001, 0x00000067, 0x0000002b,
+  0x000000fe, 0x000000d7, 0x000000ab, 0x00000076,
+  0x000000ca, 0x00000082, 0x000000c9, 0x0000007d,
+  0x000000fa, 0x00000059, 0x00000047, 0x000000f0,
+  0x000000ad, 0x000000d4, 0x000000a2, 0x000000af,
+  0x0000009c, 0x000000a4, 0x00000072, 0x000000c0,
+  0x000000b7, 0x000000fd, 0x00000093, 0x00000026,
+  0x00000036, 0x0000003f, 0x000000f7, 0x000000cc,
+  0x00000034, 0x000000a5, 0x000000e5, 0x000000f1,
+  0x00000071, 0x000000d8, 0x00000031, 0x00000015,
+  0x00000004, 0x000000c7, 0x00000023, 0x000000c3,
+  0x00000018, 0x00000096, 0x00000005, 0x0000009a,
+  0x00000007, 0x00000012, 0x00000080, 0x000000e2,
+  0x000000eb, 0x00000027, 0x000000b2, 0x00000075,
+  0x00000009, 0x00000083, 0x0000002c, 0x0000001a,
+  0x0000001b, 0x0000006e, 0x0000005a, 0x000000a0,
+  0x00000052, 0x0000003b, 0x000000d6, 0x000000b3,
+  0x00000029, 0x000000e3, 0x0000002f, 0x00000084,
+  0x00000053, 0x000000d1, 0x00000000, 0x000000ed,
+  0x00000020, 0x000000fc, 0x000000b1, 0x0000005b,
+  0x0000006a, 0x000000cb, 0x000000be, 0x00000039,
+  0x0000004a, 0x0000004c, 0x00000058, 0x000000cf,
+  0x000000d0, 0x000000ef, 0x000000aa, 0x000000fb,
+  0x00000043, 0x0000004d, 0x00000033, 0x00000085,
+  0x00000045, 0x000000f9, 0x00000002, 0x0000007f,
+  0x00000050, 0x0000003c, 0x0000009f, 0x000000a8,
+  0x00000051, 0x000000a3, 0x00000040, 0x0000008f,
+  0x00000092, 0x0000009d, 0x00000038, 0x000000f5,
+  0x000000bc, 0x000000b6, 0x000000da, 0x00000021,
+  0x00000010, 0x000000ff, 0x000000f3, 0x000000d2,
+  0x000000cd, 0x0000000c, 0x00000013, 0x000000ec,
+  0x0000005f, 0x00000097, 0x00000044, 0x00000017,
+  0x000000c4, 0x000000a7, 0x0000007e, 0x0000003d,
+  0x00000064, 0x0000005d, 0x00000019, 0x00000073,
+  0x00000060, 0x00000081, 0x0000004f, 0x000000dc,
+  0x00000022, 0x0000002a, 0x00000090, 0x00000088,
+  0x00000046, 0x000000ee, 0x000000b8, 0x00000014,
+  0x000000de, 0x0000005e, 0x0000000b, 0x000000db,
+  0x000000e0, 0x00000032, 0x0000003a, 0x0000000a,
+  0x00000049, 0x00000006, 0x00000024, 0x0000005c,
+  0x000000c2, 0x000000d3, 0x000000ac, 0x00000062,
+  0x00000091, 0x00000095, 0x000000e4, 0x00000079,
+  0x000000e7, 0x000000c8, 0x00000037, 0x0000006d,
+  0x0000008d, 0x000000d5, 0x0000004e, 0x000000a9,
+  0x0000006c, 0x00000056, 0x000000f4, 0x000000ea,
+  0x00000065, 0x0000007a, 0x000000ae, 0x00000008,
+  0x000000ba, 0x00000078, 0x00000025, 0x0000002e,
+  0x0000001c, 0x000000a6, 0x000000b4, 0x000000c6,
+  0x000000e8, 0x000000dd, 0x00000074, 0x0000001f,
+  0x0000004b, 0x000000bd, 0x0000008b, 0x0000008a,
+  0x00000070, 0x0000003e, 0x000000b5, 0x00000066,
+  0x00000048, 0x00000003, 0x000000f6, 0x0000000e,
+  0x00000061, 0x00000035, 0x00000057, 0x000000b9,
+  0x00000086, 0x000000c1, 0x0000001d, 0x0000009e,
+  0x000000e1, 0x000000f8, 0x00000098, 0x00000011,
+  0x00000069, 0x000000d9, 0x0000008e, 0x00000094,
+  0x0000009b, 0x0000001e, 0x00000087, 0x000000e9,
+  0x000000ce, 0x00000055, 0x00000028, 0x000000df,
+  0x0000008c, 0x000000a1, 0x00000089, 0x0000000d,
+  0x000000bf, 0x000000e6, 0x00000042, 0x00000068,
+  0x00000041, 0x00000099, 0x0000002d, 0x0000000f,
+  0x000000b0, 0x00000054, 0x000000bb, 0x00000016
+}, {
+  0x00006300, 0x00007c00, 0x00007700, 0x00007b00,
+  0x0000f200, 0x00006b00, 0x00006f00, 0x0000c500,
+  0x00003000, 0x00000100, 0x00006700, 0x00002b00,
+  0x0000fe00, 0x0000d700, 0x0000ab00, 0x00007600,
+  0x0000ca00, 0x00008200, 0x0000c900, 0x00007d00,
+  0x0000fa00, 0x00005900, 0x00004700, 0x0000f000,
+  0x0000ad00, 0x0000d400, 0x0000a200, 0x0000af00,
+  0x00009c00, 0x0000a400, 0x00007200, 0x0000c000,
+  0x0000b700, 0x0000fd00, 0x00009300, 0x00002600,
+  0x00003600, 0x00003f00, 0x0000f700, 0x0000cc00,
+  0x00003400, 0x0000a500, 0x0000e500, 0x0000f100,
+  0x00007100, 0x0000d800, 0x00003100, 0x00001500,
+  0x00000400, 0x0000c700, 0x00002300, 0x0000c300,
+  0x00001800, 0x00009600, 0x00000500, 0x00009a00,
+  0x00000700, 0x00001200, 0x00008000, 0x0000e200,
+  0x0000eb00, 0x00002700, 0x0000b200, 0x00007500,
+  0x00000900, 0x00008300, 0x00002c00, 0x00001a00,
+  0x00001b00, 0x00006e00, 0x00005a00, 0x0000a000,
+  0x00005200, 0x00003b00, 0x0000d600, 0x0000b300,
+  0x00002900, 0x0000e300, 0x00002f00, 0x00008400,
+  0x00005300, 0x0000d100, 0x00000000, 0x0000ed00,
+  0x00002000, 0x0000fc00, 0x0000b100, 0x00005b00,
+  0x00006a00, 0x0000cb00, 0x0000be00, 0x00003900,
+  0x00004a00, 0x00004c00, 0x00005800, 0x0000cf00,
+  0x0000d000, 0x0000ef00, 0x0000aa00, 0x0000fb00,
+  0x00004300, 0x00004d00, 0x00003300, 0x00008500,
+  0x00004500, 0x0000f900, 0x00000200, 0x00007f00,
+  0x00005000, 0x00003c00, 0x00009f00, 0x0000a800,
+  0x00005100, 0x0000a300, 0x00004000, 0x00008f00,
+  0x00009200, 0x00009d00, 0x00003800, 0x0000f500,
+  0x0000bc00, 0x0000b600, 0x0000da00, 0x00002100,
+  0x00001000, 0x0000ff00, 0x0000f300, 0x0000d200,
+  0x0000cd00, 0x00000c00, 0x00001300, 0x0000ec00,
+  0x00005f00, 0x00009700, 0x00004400, 0x00001700,
+  0x0000c400, 0x0000a700, 0x00007e00, 0x00003d00,
+  0x00006400, 0x00005d00, 0x00001900, 0x00007300,
+  0x00006000, 0x00008100, 0x00004f00, 0x0000dc00,
+  0x00002200, 0x00002a00, 0x00009000, 0x00008800,
+  0x00004600, 0x0000ee00, 0x0000b800, 0x00001400,
+  0x0000de00, 0x00005e00, 0x00000b00, 0x0000db00,
+  0x0000e000, 0x00003200, 0x00003a00, 0x00000a00,
+  0x00004900, 0x00000600, 0x00002400, 0x00005c00,
+  0x0000c200, 0x0000d300, 0x0000ac00, 0x00006200,
+  0x00009100, 0x00009500, 0x0000e400, 0x00007900,
+  0x0000e700, 0x0000c800, 0x00003700, 0x00006d00,
+  0x00008d00, 0x0000d500, 0x00004e00, 0x0000a900,
+  0x00006c00, 0x00005600, 0x0000f400, 0x0000ea00,
+  0x00006500, 0x00007a00, 0x0000ae00, 0x00000800,
+  0x0000ba00, 0x00007800, 0x00002500, 0x00002e00,
+  0x00001c00, 0x0000a600, 0x0000b400, 0x0000c600,
+  0x0000e800, 0x0000dd00, 0x00007400, 0x00001f00,
+  0x00004b00, 0x0000bd00, 0x00008b00, 0x00008a00,
+  0x00007000, 0x00003e00, 0x0000b500, 0x00006600,
+  0x00004800, 0x00000300, 0x0000f600, 0x00000e00,
+  0x00006100, 0x00003500, 0x00005700, 0x0000b900,
+  0x00008600, 0x0000c100, 0x00001d00, 0x00009e00,
+  0x0000e100, 0x0000f800, 0x00009800, 0x00001100,
+  0x00006900, 0x0000d900, 0x00008e00, 0x00009400,
+  0x00009b00, 0x00001e00, 0x00008700, 0x0000e900,
+  0x0000ce00, 0x00005500, 0x00002800, 0x0000df00,
+  0x00008c00, 0x0000a100, 0x00008900, 0x00000d00,
+  0x0000bf00, 0x0000e600, 0x00004200, 0x00006800,
+  0x00004100, 0x00009900, 0x00002d00, 0x00000f00,
+  0x0000b000, 0x00005400, 0x0000bb00, 0x00001600
+}, {
+  0x00630000, 0x007c0000, 0x00770000, 0x007b0000,
+  0x00f20000, 0x006b0000, 0x006f0000, 0x00c50000,
+  0x00300000, 0x00010000, 0x00670000, 0x002b0000,
+  0x00fe0000, 0x00d70000, 0x00ab0000, 0x00760000,
+  0x00ca0000, 0x00820000, 0x00c90000, 0x007d0000,
+  0x00fa0000, 0x00590000, 0x00470000, 0x00f00000,
+  0x00ad0000, 0x00d40000, 0x00a20000, 0x00af0000,
+  0x009c0000, 0x00a40000, 0x00720000, 0x00c00000,
+  0x00b70000, 0x00fd0000, 0x00930000, 0x00260000,
+  0x00360000, 0x003f0000, 0x00f70000, 0x00cc0000,
+  0x00340000, 0x00a50000, 0x00e50000, 0x00f10000,
+  0x00710000, 0x00d80000, 0x00310000, 0x00150000,
+  0x00040000, 0x00c70000, 0x00230000, 0x00c30000,
+  0x00180000, 0x00960000, 0x00050000, 0x009a0000,
+  0x00070000, 0x00120000, 0x00800000, 0x00e20000,
+  0x00eb0000, 0x00270000, 0x00b20000, 0x00750000,
+  0x00090000, 0x00830000, 0x002c0000, 0x001a0000,
+  0x001b0000, 0x006e0000, 0x005a0000, 0x00a00000,
+  0x00520000, 0x003b0000, 0x00d60000, 0x00b30000,
+  0x00290000, 0x00e30000, 0x002f0000, 0x00840000,
+  0x00530000, 0x00d10000, 0x00000000, 0x00ed0000,
+  0x00200000, 0x00fc0000, 0x00b10000, 0x005b0000,
+  0x006a0000, 0x00cb0000, 0x00be0000, 0x00390000,
+  0x004a0000, 0x004c0000, 0x00580000, 0x00cf0000,
+  0x00d00000, 0x00ef0000, 0x00aa0000, 0x00fb0000,
+  0x00430000, 0x004d0000, 0x00330000, 0x00850000,
+  0x00450000, 0x00f90000, 0x00020000, 0x007f0000,
+  0x00500000, 0x003c0000, 0x009f0000, 0x00a80000,
+  0x00510000, 0x00a30000, 0x00400000, 0x008f0000,
+  0x00920000, 0x009d0000, 0x00380000, 0x00f50000,
+  0x00bc0000, 0x00b60000, 0x00da0000, 0x00210000,
+  0x00100000, 0x00ff0000, 0x00f30000, 0x00d20000,
+  0x00cd0000, 0x000c0000, 0x00130000, 0x00ec0000,
+  0x005f0000, 0x00970000, 0x00440000, 0x00170000,
+  0x00c40000, 0x00a70000, 0x007e0000, 0x003d0000,
+  0x00640000, 0x005d0000, 0x00190000, 0x00730000,
+  0x00600000, 0x00810000, 0x004f0000, 0x00dc0000,
+  0x00220000, 0x002a0000, 0x00900000, 0x00880000,
+  0x00460000, 0x00ee0000, 0x00b80000, 0x00140000,
+  0x00de0000, 0x005e0000, 0x000b0000, 0x00db0000,
+  0x00e00000, 0x00320000, 0x003a0000, 0x000a0000,
+  0x00490000, 0x00060000, 0x00240000, 0x005c0000,
+  0x00c20000, 0x00d30000, 0x00ac0000, 0x00620000,
+  0x00910000, 0x00950000, 0x00e40000, 0x00790000,
+  0x00e70000, 0x00c80000, 0x00370000, 0x006d0000,
+  0x008d0000, 0x00d50000, 0x004e0000, 0x00a90000,
+  0x006c0000, 0x00560000, 0x00f40000, 0x00ea0000,
+  0x00650000, 0x007a0000, 0x00ae0000, 0x00080000,
+  0x00ba0000, 0x00780000, 0x00250000, 0x002e0000,
+  0x001c0000, 0x00a60000, 0x00b40000, 0x00c60000,
+  0x00e80000, 0x00dd0000, 0x00740000, 0x001f0000,
+  0x004b0000, 0x00bd0000, 0x008b0000, 0x008a0000,
+  0x00700000, 0x003e0000, 0x00b50000, 0x00660000,
+  0x00480000, 0x00030000, 0x00f60000, 0x000e0000,
+  0x00610000, 0x00350000, 0x00570000, 0x00b90000,
+  0x00860000, 0x00c10000, 0x001d0000, 0x009e0000,
+  0x00e10000, 0x00f80000, 0x00980000, 0x00110000,
+  0x00690000, 0x00d90000, 0x008e0000, 0x00940000,
+  0x009b0000, 0x001e0000, 0x00870000, 0x00e90000,
+  0x00ce0000, 0x00550000, 0x00280000, 0x00df0000,
+  0x008c0000, 0x00a10000, 0x00890000, 0x000d0000,
+  0x00bf0000, 0x00e60000, 0x00420000, 0x00680000,
+  0x00410000, 0x00990000, 0x002d0000, 0x000f0000,
+  0x00b00000, 0x00540000, 0x00bb0000, 0x00160000
+}, {
+  0x63000000, 0x7c000000, 0x77000000, 0x7b000000,
+  0xf2000000, 0x6b000000, 0x6f000000, 0xc5000000,
+  0x30000000, 0x01000000, 0x67000000, 0x2b000000,
+  0xfe000000, 0xd7000000, 0xab000000, 0x76000000,
+  0xca000000, 0x82000000, 0xc9000000, 0x7d000000,
+  0xfa000000, 0x59000000, 0x47000000, 0xf0000000,
+  0xad000000, 0xd4000000, 0xa2000000, 0xaf000000,
+  0x9c000000, 0xa4000000, 0x72000000, 0xc0000000,
+  0xb7000000, 0xfd000000, 0x93000000, 0x26000000,
+  0x36000000, 0x3f000000, 0xf7000000, 0xcc000000,
+  0x34000000, 0xa5000000, 0xe5000000, 0xf1000000,
+  0x71000000, 0xd8000000, 0x31000000, 0x15000000,
+  0x04000000, 0xc7000000, 0x23000000, 0xc3000000,
+  0x18000000, 0x96000000, 0x05000000, 0x9a000000,
+  0x07000000, 0x12000000, 0x80000000, 0xe2000000,
+  0xeb000000, 0x27000000, 0xb2000000, 0x75000000,
+  0x09000000, 0x83000000, 0x2c000000, 0x1a000000,
+  0x1b000000, 0x6e000000, 0x5a000000, 0xa0000000,
+  0x52000000, 0x3b000000, 0xd6000000, 0xb3000000,
+  0x29000000, 0xe3000000, 0x2f000000, 0x84000000,
+  0x53000000, 0xd1000000, 0x00000000, 0xed000000,
+  0x20000000, 0xfc000000, 0xb1000000, 0x5b000000,
+  0x6a000000, 0xcb000000, 0xbe000000, 0x39000000,
+  0x4a000000, 0x4c000000, 0x58000000, 0xcf000000,
+  0xd0000000, 0xef000000, 0xaa000000, 0xfb000000,
+  0x43000000, 0x4d000000, 0x33000000, 0x85000000,
+  0x45000000, 0xf9000000, 0x02000000, 0x7f000000,
+  0x50000000, 0x3c000000, 0x9f000000, 0xa8000000,
+  0x51000000, 0xa3000000, 0x40000000, 0x8f000000,
+  0x92000000, 0x9d000000, 0x38000000, 0xf5000000,
+  0xbc000000, 0xb6000000, 0xda000000, 0x21000000,
+  0x10000000, 0xff000000, 0xf3000000, 0xd2000000,
+  0xcd000000, 0x0c000000, 0x13000000, 0xec000000,
+  0x5f000000, 0x97000000, 0x44000000, 0x17000000,
+  0xc4000000, 0xa7000000, 0x7e000000, 0x3d000000,
+  0x64000000, 0x5d000000, 0x19000000, 0x73000000,
+  0x60000000, 0x81000000, 0x4f000000, 0xdc000000,
+  0x22000000, 0x2a000000, 0x90000000, 0x88000000,
+  0x46000000, 0xee000000, 0xb8000000, 0x14000000,
+  0xde000000, 0x5e000000, 0x0b000000, 0xdb000000,
+  0xe0000000, 0x32000000, 0x3a000000, 0x0a000000,
+  0x49000000, 0x06000000, 0x24000000, 0x5c000000,
+  0xc2000000, 0xd3000000, 0xac000000, 0x62000000,
+  0x91000000, 0x95000000, 0xe4000000, 0x79000000,
+  0xe7000000, 0xc8000000, 0x37000000, 0x6d000000,
+  0x8d000000, 0xd5000000, 0x4e000000, 0xa9000000,
+  0x6c000000, 0x56000000, 0xf4000000, 0xea000000,
+  0x65000000, 0x7a000000, 0xae000000, 0x08000000,
+  0xba000000, 0x78000000, 0x25000000, 0x2e000000,
+  0x1c000000, 0xa6000000, 0xb4000000, 0xc6000000,
+  0xe8000000, 0xdd000000, 0x74000000, 0x1f000000,
+  0x4b000000, 0xbd000000, 0x8b000000, 0x8a000000,
+  0x70000000, 0x3e000000, 0xb5000000, 0x66000000,
+  0x48000000, 0x03000000, 0xf6000000, 0x0e000000,
+  0x61000000, 0x35000000, 0x57000000, 0xb9000000,
+  0x86000000, 0xc1000000, 0x1d000000, 0x9e000000,
+  0xe1000000, 0xf8000000, 0x98000000, 0x11000000,
+  0x69000000, 0xd9000000, 0x8e000000, 0x94000000,
+  0x9b000000, 0x1e000000, 0x87000000, 0xe9000000,
+  0xce000000, 0x55000000, 0x28000000, 0xdf000000,
+  0x8c000000, 0xa1000000, 0x89000000, 0x0d000000,
+  0xbf000000, 0xe6000000, 0x42000000, 0x68000000,
+  0x41000000, 0x99000000, 0x2d000000, 0x0f000000,
+  0xb0000000, 0x54000000, 0xbb000000, 0x16000000
+}
+};
+
+static const u4byte  il_tab[4][256] = {
+{
+  0x00000052, 0x00000009, 0x0000006a, 0x000000d5,
+  0x00000030, 0x00000036, 0x000000a5, 0x00000038,
+  0x000000bf, 0x00000040, 0x000000a3, 0x0000009e,
+  0x00000081, 0x000000f3, 0x000000d7, 0x000000fb,
+  0x0000007c, 0x000000e3, 0x00000039, 0x00000082,
+  0x0000009b, 0x0000002f, 0x000000ff, 0x00000087,
+  0x00000034, 0x0000008e, 0x00000043, 0x00000044,
+  0x000000c4, 0x000000de, 0x000000e9, 0x000000cb,
+  0x00000054, 0x0000007b, 0x00000094, 0x00000032,
+  0x000000a6, 0x000000c2, 0x00000023, 0x0000003d,
+  0x000000ee, 0x0000004c, 0x00000095, 0x0000000b,
+  0x00000042, 0x000000fa, 0x000000c3, 0x0000004e,
+  0x00000008, 0x0000002e, 0x000000a1, 0x00000066,
+  0x00000028, 0x000000d9, 0x00000024, 0x000000b2,
+  0x00000076, 0x0000005b, 0x000000a2, 0x00000049,
+  0x0000006d, 0x0000008b, 0x000000d1, 0x00000025,
+  0x00000072, 0x000000f8, 0x000000f6, 0x00000064,
+  0x00000086, 0x00000068, 0x00000098, 0x00000016,
+  0x000000d4, 0x000000a4, 0x0000005c, 0x000000cc,
+  0x0000005d, 0x00000065, 0x000000b6, 0x00000092,
+  0x0000006c, 0x00000070, 0x00000048, 0x00000050,
+  0x000000fd, 0x000000ed, 0x000000b9, 0x000000da,
+  0x0000005e, 0x00000015, 0x00000046, 0x00000057,
+  0x000000a7, 0x0000008d, 0x0000009d, 0x00000084,
+  0x00000090, 0x000000d8, 0x000000ab, 0x00000000,
+  0x0000008c, 0x000000bc, 0x000000d3, 0x0000000a,
+  0x000000f7, 0x000000e4, 0x00000058, 0x00000005,
+  0x000000b8, 0x000000b3, 0x00000045, 0x00000006,
+  0x000000d0, 0x0000002c, 0x0000001e, 0x0000008f,
+  0x000000ca, 0x0000003f, 0x0000000f, 0x00000002,
+  0x000000c1, 0x000000af, 0x000000bd, 0x00000003,
+  0x00000001, 0x00000013, 0x0000008a, 0x0000006b,
+  0x0000003a, 0x00000091, 0x00000011, 0x00000041,
+  0x0000004f, 0x00000067, 0x000000dc, 0x000000ea,
+  0x00000097, 0x000000f2, 0x000000cf, 0x000000ce,
+  0x000000f0, 0x000000b4, 0x000000e6, 0x00000073,
+  0x00000096, 0x000000ac, 0x00000074, 0x00000022,
+  0x000000e7, 0x000000ad, 0x00000035, 0x00000085,
+  0x000000e2, 0x000000f9, 0x00000037, 0x000000e8,
+  0x0000001c, 0x00000075, 0x000000df, 0x0000006e,
+  0x00000047, 0x000000f1, 0x0000001a, 0x00000071,
+  0x0000001d, 0x00000029, 0x000000c5, 0x00000089,
+  0x0000006f, 0x000000b7, 0x00000062, 0x0000000e,
+  0x000000aa, 0x00000018, 0x000000be, 0x0000001b,
+  0x000000fc, 0x00000056, 0x0000003e, 0x0000004b,
+  0x000000c6, 0x000000d2, 0x00000079, 0x00000020,
+  0x0000009a, 0x000000db, 0x000000c0, 0x000000fe,
+  0x00000078, 0x000000cd, 0x0000005a, 0x000000f4,
+  0x0000001f, 0x000000dd, 0x000000a8, 0x00000033,
+  0x00000088, 0x00000007, 0x000000c7, 0x00000031,
+  0x000000b1, 0x00000012, 0x00000010, 0x00000059,
+  0x00000027, 0x00000080, 0x000000ec, 0x0000005f,
+  0x00000060, 0x00000051, 0x0000007f, 0x000000a9,
+  0x00000019, 0x000000b5, 0x0000004a, 0x0000000d,
+  0x0000002d, 0x000000e5, 0x0000007a, 0x0000009f,
+  0x00000093, 0x000000c9, 0x0000009c, 0x000000ef,
+  0x000000a0, 0x000000e0, 0x0000003b, 0x0000004d,
+  0x000000ae, 0x0000002a, 0x000000f5, 0x000000b0,
+  0x000000c8, 0x000000eb, 0x000000bb, 0x0000003c,
+  0x00000083, 0x00000053, 0x00000099, 0x00000061,
+  0x00000017, 0x0000002b, 0x00000004, 0x0000007e,
+  0x000000ba, 0x00000077, 0x000000d6, 0x00000026,
+  0x000000e1, 0x00000069, 0x00000014, 0x00000063,
+  0x00000055, 0x00000021, 0x0000000c, 0x0000007d
+}, {
+  0x00005200, 0x00000900, 0x00006a00, 0x0000d500,
+  0x00003000, 0x00003600, 0x0000a500, 0x00003800,
+  0x0000bf00, 0x00004000, 0x0000a300, 0x00009e00,
+  0x00008100, 0x0000f300, 0x0000d700, 0x0000fb00,
+  0x00007c00, 0x0000e300, 0x00003900, 0x00008200,
+  0x00009b00, 0x00002f00, 0x0000ff00, 0x00008700,
+  0x00003400, 0x00008e00, 0x00004300, 0x00004400,
+  0x0000c400, 0x0000de00, 0x0000e900, 0x0000cb00,
+  0x00005400, 0x00007b00, 0x00009400, 0x00003200,
+  0x0000a600, 0x0000c200, 0x00002300, 0x00003d00,
+  0x0000ee00, 0x00004c00, 0x00009500, 0x00000b00,
+  0x00004200, 0x0000fa00, 0x0000c300, 0x00004e00,
+  0x00000800, 0x00002e00, 0x0000a100, 0x00006600,
+  0x00002800, 0x0000d900, 0x00002400, 0x0000b200,
+  0x00007600, 0x00005b00, 0x0000a200, 0x00004900,
+  0x00006d00, 0x00008b00, 0x0000d100, 0x00002500,
+  0x00007200, 0x0000f800, 0x0000f600, 0x00006400,
+  0x00008600, 0x00006800, 0x00009800, 0x00001600,
+  0x0000d400, 0x0000a400, 0x00005c00, 0x0000cc00,
+  0x00005d00, 0x00006500, 0x0000b600, 0x00009200,
+  0x00006c00, 0x00007000, 0x00004800, 0x00005000,
+  0x0000fd00, 0x0000ed00, 0x0000b900, 0x0000da00,
+  0x00005e00, 0x00001500, 0x00004600, 0x00005700,
+  0x0000a700, 0x00008d00, 0x00009d00, 0x00008400,
+  0x00009000, 0x0000d800, 0x0000ab00, 0x00000000,
+  0x00008c00, 0x0000bc00, 0x0000d300, 0x00000a00,
+  0x0000f700, 0x0000e400, 0x00005800, 0x00000500,
+  0x0000b800, 0x0000b300, 0x00004500, 0x00000600,
+  0x0000d000, 0x00002c00, 0x00001e00, 0x00008f00,
+  0x0000ca00, 0x00003f00, 0x00000f00, 0x00000200,
+  0x0000c100, 0x0000af00, 0x0000bd00, 0x00000300,
+  0x00000100, 0x00001300, 0x00008a00, 0x00006b00,
+  0x00003a00, 0x00009100, 0x00001100, 0x00004100,
+  0x00004f00, 0x00006700, 0x0000dc00, 0x0000ea00,
+  0x00009700, 0x0000f200, 0x0000cf00, 0x0000ce00,
+  0x0000f000, 0x0000b400, 0x0000e600, 0x00007300,
+  0x00009600, 0x0000ac00, 0x00007400, 0x00002200,
+  0x0000e700, 0x0000ad00, 0x00003500, 0x00008500,
+  0x0000e200, 0x0000f900, 0x00003700, 0x0000e800,
+  0x00001c00, 0x00007500, 0x0000df00, 0x00006e00,
+  0x00004700, 0x0000f100, 0x00001a00, 0x00007100,
+  0x00001d00, 0x00002900, 0x0000c500, 0x00008900,
+  0x00006f00, 0x0000b700, 0x00006200, 0x00000e00,
+  0x0000aa00, 0x00001800, 0x0000be00, 0x00001b00,
+  0x0000fc00, 0x00005600, 0x00003e00, 0x00004b00,
+  0x0000c600, 0x0000d200, 0x00007900, 0x00002000,
+  0x00009a00, 0x0000db00, 0x0000c000, 0x0000fe00,
+  0x00007800, 0x0000cd00, 0x00005a00, 0x0000f400,
+  0x00001f00, 0x0000dd00, 0x0000a800, 0x00003300,
+  0x00008800, 0x00000700, 0x0000c700, 0x00003100,
+  0x0000b100, 0x00001200, 0x00001000, 0x00005900,
+  0x00002700, 0x00008000, 0x0000ec00, 0x00005f00,
+  0x00006000, 0x00005100, 0x00007f00, 0x0000a900,
+  0x00001900, 0x0000b500, 0x00004a00, 0x00000d00,
+  0x00002d00, 0x0000e500, 0x00007a00, 0x00009f00,
+  0x00009300, 0x0000c900, 0x00009c00, 0x0000ef00,
+  0x0000a000, 0x0000e000, 0x00003b00, 0x00004d00,
+  0x0000ae00, 0x00002a00, 0x0000f500, 0x0000b000,
+  0x0000c800, 0x0000eb00, 0x0000bb00, 0x00003c00,
+  0x00008300, 0x00005300, 0x00009900, 0x00006100,
+  0x00001700, 0x00002b00, 0x00000400, 0x00007e00,
+  0x0000ba00, 0x00007700, 0x0000d600, 0x00002600,
+  0x0000e100, 0x00006900, 0x00001400, 0x00006300,
+  0x00005500, 0x00002100, 0x00000c00, 0x00007d00
+}, {
+  0x00520000, 0x00090000, 0x006a0000, 0x00d50000,
+  0x00300000, 0x00360000, 0x00a50000, 0x00380000,
+  0x00bf0000, 0x00400000, 0x00a30000, 0x009e0000,
+  0x00810000, 0x00f30000, 0x00d70000, 0x00fb0000,
+  0x007c0000, 0x00e30000, 0x00390000, 0x00820000,
+  0x009b0000, 0x002f0000, 0x00ff0000, 0x00870000,
+  0x00340000, 0x008e0000, 0x00430000, 0x00440000,
+  0x00c40000, 0x00de0000, 0x00e90000, 0x00cb0000,
+  0x00540000, 0x007b0000, 0x00940000, 0x00320000,
+  0x00a60000, 0x00c20000, 0x00230000, 0x003d0000,
+  0x00ee0000, 0x004c0000, 0x00950000, 0x000b0000,
+  0x00420000, 0x00fa0000, 0x00c30000, 0x004e0000,
+  0x00080000, 0x002e0000, 0x00a10000, 0x00660000,
+  0x00280000, 0x00d90000, 0x00240000, 0x00b20000,
+  0x00760000, 0x005b0000, 0x00a20000, 0x00490000,
+  0x006d0000, 0x008b0000, 0x00d10000, 0x00250000,
+  0x00720000, 0x00f80000, 0x00f60000, 0x00640000,
+  0x00860000, 0x00680000, 0x00980000, 0x00160000,
+  0x00d40000, 0x00a40000, 0x005c0000, 0x00cc0000,
+  0x005d0000, 0x00650000, 0x00b60000, 0x00920000,
+  0x006c0000, 0x00700000, 0x00480000, 0x00500000,
+  0x00fd0000, 0x00ed0000, 0x00b90000, 0x00da0000,
+  0x005e0000, 0x00150000, 0x00460000, 0x00570000,
+  0x00a70000, 0x008d0000, 0x009d0000, 0x00840000,
+  0x00900000, 0x00d80000, 0x00ab0000, 0x00000000,
+  0x008c0000, 0x00bc0000, 0x00d30000, 0x000a0000,
+  0x00f70000, 0x00e40000, 0x00580000, 0x00050000,
+  0x00b80000, 0x00b30000, 0x00450000, 0x00060000,
+  0x00d00000, 0x002c0000, 0x001e0000, 0x008f0000,
+  0x00ca0000, 0x003f0000, 0x000f0000, 0x00020000,
+  0x00c10000, 0x00af0000, 0x00bd0000, 0x00030000,
+  0x00010000, 0x00130000, 0x008a0000, 0x006b0000,
+  0x003a0000, 0x00910000, 0x00110000, 0x00410000,
+  0x004f0000, 0x00670000, 0x00dc0000, 0x00ea0000,
+  0x00970000, 0x00f20000, 0x00cf0000, 0x00ce0000,
+  0x00f00000, 0x00b40000, 0x00e60000, 0x00730000,
+  0x00960000, 0x00ac0000, 0x00740000, 0x00220000,
+  0x00e70000, 0x00ad0000, 0x00350000, 0x00850000,
+  0x00e20000, 0x00f90000, 0x00370000, 0x00e80000,
+  0x001c0000, 0x00750000, 0x00df0000, 0x006e0000,
+  0x00470000, 0x00f10000, 0x001a0000, 0x00710000,
+  0x001d0000, 0x00290000, 0x00c50000, 0x00890000,
+  0x006f0000, 0x00b70000, 0x00620000, 0x000e0000,
+  0x00aa0000, 0x00180000, 0x00be0000, 0x001b0000,
+  0x00fc0000, 0x00560000, 0x003e0000, 0x004b0000,
+  0x00c60000, 0x00d20000, 0x00790000, 0x00200000,
+  0x009a0000, 0x00db0000, 0x00c00000, 0x00fe0000,
+  0x00780000, 0x00cd0000, 0x005a0000, 0x00f40000,
+  0x001f0000, 0x00dd0000, 0x00a80000, 0x00330000,
+  0x00880000, 0x00070000, 0x00c70000, 0x00310000,
+  0x00b10000, 0x00120000, 0x00100000, 0x00590000,
+  0x00270000, 0x00800000, 0x00ec0000, 0x005f0000,
+  0x00600000, 0x00510000, 0x007f0000, 0x00a90000,
+  0x00190000, 0x00b50000, 0x004a0000, 0x000d0000,
+  0x002d0000, 0x00e50000, 0x007a0000, 0x009f0000,
+  0x00930000, 0x00c90000, 0x009c0000, 0x00ef0000,
+  0x00a00000, 0x00e00000, 0x003b0000, 0x004d0000,
+  0x00ae0000, 0x002a0000, 0x00f50000, 0x00b00000,
+  0x00c80000, 0x00eb0000, 0x00bb0000, 0x003c0000,
+  0x00830000, 0x00530000, 0x00990000, 0x00610000,
+  0x00170000, 0x002b0000, 0x00040000, 0x007e0000,
+  0x00ba0000, 0x00770000, 0x00d60000, 0x00260000,
+  0x00e10000, 0x00690000, 0x00140000, 0x00630000,
+  0x00550000, 0x00210000, 0x000c0000, 0x007d0000
+}, {
+  0x52000000, 0x09000000, 0x6a000000, 0xd5000000,
+  0x30000000, 0x36000000, 0xa5000000, 0x38000000,
+  0xbf000000, 0x40000000, 0xa3000000, 0x9e000000,
+  0x81000000, 0xf3000000, 0xd7000000, 0xfb000000,
+  0x7c000000, 0xe3000000, 0x39000000, 0x82000000,
+  0x9b000000, 0x2f000000, 0xff000000, 0x87000000,
+  0x34000000, 0x8e000000, 0x43000000, 0x44000000,
+  0xc4000000, 0xde000000, 0xe9000000, 0xcb000000,
+  0x54000000, 0x7b000000, 0x94000000, 0x32000000,
+  0xa6000000, 0xc2000000, 0x23000000, 0x3d000000,
+  0xee000000, 0x4c000000, 0x95000000, 0x0b000000,
+  0x42000000, 0xfa000000, 0xc3000000, 0x4e000000,
+  0x08000000, 0x2e000000, 0xa1000000, 0x66000000,
+  0x28000000, 0xd9000000, 0x24000000, 0xb2000000,
+  0x76000000, 0x5b000000, 0xa2000000, 0x49000000,
+  0x6d000000, 0x8b000000, 0xd1000000, 0x25000000,
+  0x72000000, 0xf8000000, 0xf6000000, 0x64000000,
+  0x86000000, 0x68000000, 0x98000000, 0x16000000,
+  0xd4000000, 0xa4000000, 0x5c000000, 0xcc000000,
+  0x5d000000, 0x65000000, 0xb6000000, 0x92000000,
+  0x6c000000, 0x70000000, 0x48000000, 0x50000000,
+  0xfd000000, 0xed000000, 0xb9000000, 0xda000000,
+  0x5e000000, 0x15000000, 0x46000000, 0x57000000,
+  0xa7000000, 0x8d000000, 0x9d000000, 0x84000000,
+  0x90000000, 0xd8000000, 0xab000000, 0x00000000,
+  0x8c000000, 0xbc000000, 0xd3000000, 0x0a000000,
+  0xf7000000, 0xe4000000, 0x58000000, 0x05000000,
+  0xb8000000, 0xb3000000, 0x45000000, 0x06000000,
+  0xd0000000, 0x2c000000, 0x1e000000, 0x8f000000,
+  0xca000000, 0x3f000000, 0x0f000000, 0x02000000,
+  0xc1000000, 0xaf000000, 0xbd000000, 0x03000000,
+  0x01000000, 0x13000000, 0x8a000000, 0x6b000000,
+  0x3a000000, 0x91000000, 0x11000000, 0x41000000,
+  0x4f000000, 0x67000000, 0xdc000000, 0xea000000,
+  0x97000000, 0xf2000000, 0xcf000000, 0xce000000,
+  0xf0000000, 0xb4000000, 0xe6000000, 0x73000000,
+  0x96000000, 0xac000000, 0x74000000, 0x22000000,
+  0xe7000000, 0xad000000, 0x35000000, 0x85000000,
+  0xe2000000, 0xf9000000, 0x37000000, 0xe8000000,
+  0x1c000000, 0x75000000, 0xdf000000, 0x6e000000,
+  0x47000000, 0xf1000000, 0x1a000000, 0x71000000,
+  0x1d000000, 0x29000000, 0xc5000000, 0x89000000,
+  0x6f000000, 0xb7000000, 0x62000000, 0x0e000000,
+  0xaa000000, 0x18000000, 0xbe000000, 0x1b000000,
+  0xfc000000, 0x56000000, 0x3e000000, 0x4b000000,
+  0xc6000000, 0xd2000000, 0x79000000, 0x20000000,
+  0x9a000000, 0xdb000000, 0xc0000000, 0xfe000000,
+  0x78000000, 0xcd000000, 0x5a000000, 0xf4000000,
+  0x1f000000, 0xdd000000, 0xa8000000, 0x33000000,
+  0x88000000, 0x07000000, 0xc7000000, 0x31000000,
+  0xb1000000, 0x12000000, 0x10000000, 0x59000000,
+  0x27000000, 0x80000000, 0xec000000, 0x5f000000,
+  0x60000000, 0x51000000, 0x7f000000, 0xa9000000,
+  0x19000000, 0xb5000000, 0x4a000000, 0x0d000000,
+  0x2d000000, 0xe5000000, 0x7a000000, 0x9f000000,
+  0x93000000, 0xc9000000, 0x9c000000, 0xef000000,
+  0xa0000000, 0xe0000000, 0x3b000000, 0x4d000000,
+  0xae000000, 0x2a000000, 0xf5000000, 0xb0000000,
+  0xc8000000, 0xeb000000, 0xbb000000, 0x3c000000,
+  0x83000000, 0x53000000, 0x99000000, 0x61000000,
+  0x17000000, 0x2b000000, 0x04000000, 0x7e000000,
+  0xba000000, 0x77000000, 0xd6000000, 0x26000000,
+  0xe1000000, 0x69000000, 0x14000000, 0x63000000,
+  0x55000000, 0x21000000, 0x0c000000, 0x7d000000
+}
+};
+
+static const u4byte rco_tab[10] = {
+  0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 
+  0x00000020, 0x00000040, 0x00000080, 0x0000001b, 0x00000036
+};
+