diff --git a/contrib/pgcrypto/blf.c b/contrib/pgcrypto/blf.c
index a1af7479c24264f0d431f38b952b92e64b7d0f57..c2e83f30788adbe55fda8aecc9887cb5e9add5d2 100644
--- a/contrib/pgcrypto/blf.c
+++ b/contrib/pgcrypto/blf.c
@@ -31,6 +31,8 @@
  * 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.
+ *
+ * $PostgreSQL: pgsql/contrib/pgcrypto/blf.c,v 1.7 2005/07/11 15:07:59 tgl Exp $
  */
 
 /*
@@ -40,9 +42,9 @@
  * Bruce Schneier.
  */
 
-#include <postgres.h>
-#include "px.h"
+#include "postgres.h"
 
+#include "px.h"
 #include "blf.h"
 
 /* Function for Feistel Networks */
diff --git a/contrib/pgcrypto/crypt-md5.c b/contrib/pgcrypto/crypt-md5.c
index 7ce7a266ac02bcaf33ef6ed482ddba4f30e58460..f2acae8c7263ca85a4c76ca26b83859499814abb 100644
--- a/contrib/pgcrypto/crypt-md5.c
+++ b/contrib/pgcrypto/crypt-md5.c
@@ -8,10 +8,11 @@
  *
  * $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999/12/17 20:21:45 peter Exp $
  *
+ * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-md5.c,v 1.4 2005/07/11 15:07:59 tgl Exp $
  */
-/* $PostgreSQL: pgsql/contrib/pgcrypto/crypt-md5.c,v 1.3 2003/11/29 22:39:28 pgsql Exp $ */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include "px.h"
 #include "px-crypt.h"
 
diff --git a/contrib/pgcrypto/fortuna.c b/contrib/pgcrypto/fortuna.c
index ff02a9773e3ff0070474cb491a2ae49a82a42f44..7aa9270729f5dc063c7e2a8dcc94919185c53daf 100644
--- a/contrib/pgcrypto/fortuna.c
+++ b/contrib/pgcrypto/fortuna.c
@@ -26,16 +26,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.1 2005/07/10 13:46:27 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include <sys/time.h>
 #include <time.h>
 
 #include "rijndael.h"
 #include "sha2.h"
-
 #include "fortuna.h"
 
 
diff --git a/contrib/pgcrypto/internal.c b/contrib/pgcrypto/internal.c
index 7bbd06a606c2e9550bdf688080003ffa76b17434..4dcbb48069615f59790ad370a123992f0b017ad7 100644
--- a/contrib/pgcrypto/internal.c
+++ b/contrib/pgcrypto/internal.c
@@ -26,15 +26,14 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.19 2005/07/10 17:22:54 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.20 2005/07/11 15:07:59 tgl Exp $
  */
 
+#include "postgres.h"
 
-#include <postgres.h>
 #include <time.h>
 
 #include "px.h"
-
 #include "md5.h"
 #include "sha1.h"
 #include "sha2.h"
diff --git a/contrib/pgcrypto/mbuf.c b/contrib/pgcrypto/mbuf.c
index eb5dff9265441858976bc54a6fdb4791de4cfab7..ac59d7fc976315926f456adcc1b4b97bfa2240f7 100644
--- a/contrib/pgcrypto/mbuf.c
+++ b/contrib/pgcrypto/mbuf.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/mbuf.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/mbuf.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/md5.c b/contrib/pgcrypto/md5.c
index baf9ae00f9523d5d27deec9d8765376f150ce36c..483ea311be7b90c37dc0887bbf868f7a097d0530 100644
--- a/contrib/pgcrypto/md5.c
+++ b/contrib/pgcrypto/md5.c
@@ -1,4 +1,3 @@
-/*	$PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.12 2004/08/29 16:43:05 tgl Exp $	*/
 /*	   $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $	   */
 
 /*
@@ -28,13 +27,22 @@
  * 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.
+ *
+ * $PostgreSQL: pgsql/contrib/pgcrypto/md5.c,v 1.13 2005/07/11 15:07:59 tgl Exp $
  */
 
 #include "postgres.h"
-#include "px.h"
 
+#include <sys/param.h>
+
+#include "px.h"
 #include "md5.h"
 
+/* sanity check */
+#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
+#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
+#endif
+
 #define SHIFT(X, s) (((X) << (s)) | ((X) >> (32 - (s))))
 
 #define F(X, Y, Z) (((X) & (Y)) | ((~X) & (Z)))
diff --git a/contrib/pgcrypto/openssl.c b/contrib/pgcrypto/openssl.c
index 7381b800a4bb4ff9416f54e492b0ffbe803231bf..eb7cbbf0c602aba26c36c0ced9d73f143112676e 100644
--- a/contrib/pgcrypto/openssl.c
+++ b/contrib/pgcrypto/openssl.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.23 2005/07/11 14:38:05 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.24 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 
diff --git a/contrib/pgcrypto/pgp-armor.c b/contrib/pgcrypto/pgp-armor.c
index 20f443f22e8c476ff6380566d6d4f4294f56ec5e..b379b2538e6970e60d89363b7a4368026ef52ef1 100644
--- a/contrib/pgcrypto/pgp-armor.c
+++ b/contrib/pgcrypto/pgp-armor.c
@@ -26,12 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-armor.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-armor.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
-
-#include <string.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-cfb.c b/contrib/pgcrypto/pgp-cfb.c
index 52f37228c7de473092e926876c67c9a4d6f657fe..52e56acfc068a61c6c79e2c01142301e8717193d 100644
--- a/contrib/pgcrypto/pgp-cfb.c
+++ b/contrib/pgcrypto/pgp-cfb.c
@@ -26,10 +26,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-cfb.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-cfb.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include "mbuf.h"
 #include "px.h"
 #include "pgp.h"
diff --git a/contrib/pgcrypto/pgp-compress.c b/contrib/pgcrypto/pgp-compress.c
index 4faf0e4e1ae9207731e0e0fa40e3294947650bd1..c90887e38678928875098798a2b97528ad5d5243 100644
--- a/contrib/pgcrypto/pgp-compress.c
+++ b/contrib/pgcrypto/pgp-compress.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-compress.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-compress.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "mbuf.h"
 #include "px.h"
@@ -43,6 +43,7 @@
 #ifndef DISABLE_ZLIB
 
 #include <zlib.h>
+
 #define ZIP_OUT_BUF 8192
 #define ZIP_IN_BLOCK 8192
 
diff --git a/contrib/pgcrypto/pgp-decrypt.c b/contrib/pgcrypto/pgp-decrypt.c
index edffc6a3443459d6d29bfad301e30ac7949552c2..ad6b37577832d583a5870a51fbc96d3d8ba5811b 100644
--- a/contrib/pgcrypto/pgp-decrypt.c
+++ b/contrib/pgcrypto/pgp-decrypt.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-decrypt.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-decrypt.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-encrypt.c b/contrib/pgcrypto/pgp-encrypt.c
index 8aee9bfba2ca9d21121c2acef39a03464cebcb1a..06f46efc6209324fb47e62cd69c4b858eb818a24 100644
--- a/contrib/pgcrypto/pgp-encrypt.c
+++ b/contrib/pgcrypto/pgp-encrypt.c
@@ -26,10 +26,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-encrypt.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-encrypt.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include <time.h>
 
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-info.c b/contrib/pgcrypto/pgp-info.c
index d757e8c921e4df6d7fd561516066282ac29f3d2b..58752b7c83d6eedcd0324bd86a3b079a6b2776ca 100644
--- a/contrib/pgcrypto/pgp-info.c
+++ b/contrib/pgcrypto/pgp-info.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-info.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-info.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-mpi-internal.c b/contrib/pgcrypto/pgp-mpi-internal.c
index 12831b1af7007e357c870a08cd93c98647059c29..626700e2c9e68f7d06de2ba4cd7fdf0bfb60d204 100644
--- a/contrib/pgcrypto/pgp-mpi-internal.c
+++ b/contrib/pgcrypto/pgp-mpi-internal.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-internal.c,v 1.1 2005/07/10 13:46:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-internal.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-mpi-openssl.c b/contrib/pgcrypto/pgp-mpi-openssl.c
index c44e1935bd1a35eab7b94321479f6fb5ac09e082..61ef6f3943e364c8dab20c337f7a7536412145be 100644
--- a/contrib/pgcrypto/pgp-mpi-openssl.c
+++ b/contrib/pgcrypto/pgp-mpi-openssl.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-openssl.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-openssl.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include <openssl/bn.h>
 
diff --git a/contrib/pgcrypto/pgp-mpi.c b/contrib/pgcrypto/pgp-mpi.c
index 6d3eff499fcc0da33934b92ebb26a0d0e8fb4391..9ae9363bfc52562e487c406d27fd403211788eb8 100644
--- a/contrib/pgcrypto/pgp-mpi.c
+++ b/contrib/pgcrypto/pgp-mpi.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c
index c17d952b39d66efb1a9c6997a2ab13d75bf41f77..5d4c0518f4c0888002ace4916eefc20018deafe9 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -26,13 +26,14 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
-#include <fmgr.h>
-#include <parser/scansup.h>
-#include <mb/pg_wchar.h>
+#include "postgres.h"
+
+#include "fmgr.h"
+#include "parser/scansup.h"
+#include "mb/pg_wchar.h"
 
 #include "mbuf.h"
 #include "px.h"
diff --git a/contrib/pgcrypto/pgp-pubdec.c b/contrib/pgcrypto/pgp-pubdec.c
index cbf2aeb44340ff7078127acbc9e4239dcc781543..32cae7f71681f200e182f82afe38ba4fc153b2d9 100644
--- a/contrib/pgcrypto/pgp-pubdec.c
+++ b/contrib/pgcrypto/pgp-pubdec.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubdec.c,v 1.2 2005/07/10 15:37:03 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubdec.c,v 1.3 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-pubenc.c b/contrib/pgcrypto/pgp-pubenc.c
index 7a0ba33409ed068366590f7feaeaa8ad2a862e0d..3585e16b0be13469aca2423fcaf6f1e163852710 100644
--- a/contrib/pgcrypto/pgp-pubenc.c
+++ b/contrib/pgcrypto/pgp-pubenc.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubenc.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubenc.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-pubkey.c b/contrib/pgcrypto/pgp-pubkey.c
index 6a00947c87be66ad28f394359af64f9f2929ee89..ec5c148b530722cbdfd536cb0464d23be67b6be8 100644
--- a/contrib/pgcrypto/pgp-pubkey.c
+++ b/contrib/pgcrypto/pgp-pubkey.c
@@ -26,9 +26,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubkey.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pubkey.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp-s2k.c b/contrib/pgcrypto/pgp-s2k.c
index 0916a0074e1b36c71e88eb571b7166fc18e538b2..2d1b92c2d443da94f255816f67f65bb62ce641ad 100644
--- a/contrib/pgcrypto/pgp-s2k.c
+++ b/contrib/pgcrypto/pgp-s2k.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-s2k.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-s2k.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/pgp.c b/contrib/pgcrypto/pgp.c
index 8c7144104dea0c24bf6eba9851c246459c58ae9b..c9bf8d7d28969a3b0f5ac44761268085d62e6fba 100644
--- a/contrib/pgcrypto/pgp.c
+++ b/contrib/pgcrypto/pgp.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.c,v 1.1 2005/07/10 13:46:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 #include "mbuf.h"
diff --git a/contrib/pgcrypto/px-crypt.c b/contrib/pgcrypto/px-crypt.c
index 5b99d1d0468c1c85fc32e220f57920fb5669fa5c..82b7deb87003c36c7c113b3c2a0c41770ff1de69 100644
--- a/contrib/pgcrypto/px-crypt.c
+++ b/contrib/pgcrypto/px-crypt.c
@@ -26,10 +26,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.11 2005/03/21 05:22:14 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/px-crypt.c,v 1.12 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include "px.h"
 #include "px-crypt.h"
 
diff --git a/contrib/pgcrypto/px-hmac.c b/contrib/pgcrypto/px-hmac.c
index e79988894b4b11d0328551f2afb62cfb33637ab1..fa4233903c34804ba65d7236f3b80a91452de46f 100644
--- a/contrib/pgcrypto/px-hmac.c
+++ b/contrib/pgcrypto/px-hmac.c
@@ -26,11 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/px-hmac.c,v 1.6 2005/03/21 05:19:55 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/px-hmac.c,v 1.7 2005/07/11 15:07:59 tgl Exp $
  */
 
-
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 
diff --git a/contrib/pgcrypto/px.c b/contrib/pgcrypto/px.c
index ca271e33a822342349e5f8992d7dcad08d63f546..74b006688b545c8bb2ee9884cd1b5fb982ab71ff 100644
--- a/contrib/pgcrypto/px.c
+++ b/contrib/pgcrypto/px.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.12 2005/07/10 03:57:55 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/px.c,v 1.13 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 
diff --git a/contrib/pgcrypto/random.c b/contrib/pgcrypto/random.c
index 0aa4aa2836c15d631fa8310b8fb9dc31004dcf10..019ac3c9a3c6d15d5580f634a2dd4a0f5abf4417 100644
--- a/contrib/pgcrypto/random.c
+++ b/contrib/pgcrypto/random.c
@@ -26,11 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/random.c,v 1.11 2005/07/10 03:55:28 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/random.c,v 1.12 2005/07/11 15:07:59 tgl Exp $
  */
 
-
-#include <postgres.h>
+#include "postgres.h"
 
 #include "px.h"
 
@@ -49,7 +48,6 @@
 
 #define TRY_DEV_RANDOM
 
-#include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 
diff --git a/contrib/pgcrypto/rijndael.c b/contrib/pgcrypto/rijndael.c
index 8a68e3f166b7b23426904d71515e6cac68b160fd..fbf74cabe921c6f2f002c3c248e68bff9647a65d 100644
--- a/contrib/pgcrypto/rijndael.c
+++ b/contrib/pgcrypto/rijndael.c
@@ -1,5 +1,7 @@
 /*	$OpenBSD: rijndael.c,v 1.6 2000/12/09 18:51:34 markus Exp $ */
 
+/* $PostgreSQL: pgsql/contrib/pgcrypto/rijndael.c,v 1.11 2005/07/11 15:07:59 tgl Exp $ */
+
 /* This is an independent implementation of the encryption algorithm:	*/
 /*																		*/
 /*		   RIJNDAEL by Joan Daemen and Vincent Rijmen					*/
@@ -38,11 +40,19 @@ Mean:		   500 cycles =    51.2 mbits/sec
 
 */
 
-#include <postgres.h>
-#include "px.h"
+#include "postgres.h"
 
+#include <sys/param.h>
+
+#include "px.h"
 #include "rijndael.h"
 
+/* sanity check */
+#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
+#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
+#endif
+
+
 #define PRE_CALC_TABLES
 #define LARGE_TABLES
 
diff --git a/contrib/pgcrypto/sha1.c b/contrib/pgcrypto/sha1.c
index b1c189ab4dd10913d2445f35fa1c9663e647bd94..0944dfdabeb301a38bd6b9ea4097385393871591 100644
--- a/contrib/pgcrypto/sha1.c
+++ b/contrib/pgcrypto/sha1.c
@@ -1,4 +1,3 @@
-/*	$PostgreSQL: pgsql/contrib/pgcrypto/sha1.c,v 1.15 2005/05/25 21:40:39 momjian Exp $ */
 /*	   $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $    */
 
 /*
@@ -28,6 +27,8 @@
  * 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.
+ *
+ * $PostgreSQL: pgsql/contrib/pgcrypto/sha1.c,v 1.16 2005/07/11 15:07:59 tgl Exp $
  */
 /*
  * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
@@ -36,18 +37,16 @@
  */
 
 #include "postgres.h"
-#include "px.h"
 
+#include <sys/param.h>
+
+#include "px.h"
 #include "sha1.h"
 
 /* sanity check */
-#if BYTE_ORDER != BIG_ENDIAN
-#if BYTE_ORDER != LITTLE_ENDIAN
-#define unsupported 1
+#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
+#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
 #endif
-#endif
-
-#ifndef unsupported
 
 /* constant table */
 static uint32 _K[] = {0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6};
@@ -346,5 +345,3 @@ sha1_result(struct sha1_ctxt * ctxt, uint8 *digest0)
 	digest[19] = ctxt->h.b8[16];
 #endif
 }
-
-#endif   /* unsupported */
diff --git a/contrib/pgcrypto/sha2.c b/contrib/pgcrypto/sha2.c
index 9c35107bdc07b1e3cdb573e7ff2052e0b87a0a47..065e8844a89c0a5af762927dbaf7a18163cd85ca 100644
--- a/contrib/pgcrypto/sha2.c
+++ b/contrib/pgcrypto/sha2.c
@@ -1,4 +1,3 @@
-/*	$PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.1 2005/07/10 13:46:29 momjian Exp $ */
 /*	$OpenBSD: sha2.c,v 1.6 2004/05/03 02:57:36 millert Exp $	*/
 
 /*
@@ -33,9 +32,13 @@
  * SUCH DAMAGE.
  *
  * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
+ *
+ * $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
+#include <sys/param.h>
 
 #include "sha2.h"
 
@@ -496,7 +499,6 @@ SHA256_Update(SHA256_CTX *context, const uint8 *data, size_t len)
 void
 SHA256_Final(uint8 digest[], SHA256_CTX *context)
 {
-	uint32	*d = (uint32 *)digest;
 	unsigned int	usedspace;
 
 	/* If no digest buffer is passed, we don't bother doing this: */
@@ -542,12 +544,10 @@ SHA256_Final(uint8 digest[], SHA256_CTX *context)
 			int	j;
 			for (j = 0; j < 8; j++) {
 				REVERSE32(context->state[j],context->state[j]);
-				*d++ = context->state[j];
 			}
 		}
-#else
-		bcopy(context->state, d, SHA256_DIGEST_LENGTH);
 #endif
+		bcopy(context->state, digest, SHA256_DIGEST_LENGTH);
 	}
 
 	/* Clean up state data: */
@@ -823,8 +823,6 @@ SHA512_Last(SHA512_CTX *context)
 void
 SHA512_Final(uint8 digest[], SHA512_CTX *context)
 {
-	uint64	*d = (uint64 *)digest;
-
 	/* If no digest buffer is passed, we don't bother doing this: */
 	if (digest != NULL) {
 		SHA512_Last(context);
@@ -836,12 +834,10 @@ SHA512_Final(uint8 digest[], SHA512_CTX *context)
 			int	j;
 			for (j = 0; j < 8; j++) {
 				REVERSE64(context->state[j],context->state[j]);
-				*d++ = context->state[j];
 			}
 		}
-#else
-		bcopy(context->state, d, SHA512_DIGEST_LENGTH);
 #endif
+		bcopy(context->state, digest, SHA512_DIGEST_LENGTH);
 	}
 
 	/* Zero out state data */
@@ -869,8 +865,6 @@ SHA384_Update(SHA384_CTX *context, const uint8 *data, size_t len)
 void
 SHA384_Final(uint8 digest[], SHA384_CTX *context)
 {
-	uint64	*d = (uint64 *)digest;
-
 	/* If no digest buffer is passed, we don't bother doing this: */
 	if (digest != NULL) {
 		SHA512_Last((SHA512_CTX *)context);
@@ -882,12 +876,10 @@ SHA384_Final(uint8 digest[], SHA384_CTX *context)
 			int	j;
 			for (j = 0; j < 6; j++) {
 				REVERSE64(context->state[j],context->state[j]);
-				*d++ = context->state[j];
 			}
 		}
-#else
-		bcopy(context->state, d, SHA384_DIGEST_LENGTH);
 #endif
+		bcopy(context->state, digest, SHA384_DIGEST_LENGTH);
 	}
 
 	/* Zero out state data */