summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2005-07-11 15:07:59 +0000
committerTom Lane2005-07-11 15:07:59 +0000
commit0479893bf06f8a3911d955123de742d385c4c7be (patch)
tree6a4a2e68ea3e64b281c95da53f4e010f0501ff9b
parentb52f31a8c474e4a6fa58b9e28eb65be870ccf492 (diff)
More pgcrypto fixes: avoid bogus alignment assumptions in sha2,
be more wary about having a value for BYTE_ORDER, clean up randomly- chosen ways of including Postgres core headers. Marko Kreen and Tom Lane
-rw-r--r--contrib/pgcrypto/blf.c6
-rw-r--r--contrib/pgcrypto/crypt-md5.c5
-rw-r--r--contrib/pgcrypto/fortuna.c4
-rw-r--r--contrib/pgcrypto/internal.c3
-rw-r--r--contrib/pgcrypto/mbuf.c2
-rw-r--r--contrib/pgcrypto/md5.c12
-rw-r--r--contrib/pgcrypto/openssl.c2
-rw-r--r--contrib/pgcrypto/pgp-armor.c4
-rw-r--r--contrib/pgcrypto/pgp-cfb.c3
-rw-r--r--contrib/pgcrypto/pgp-compress.c3
-rw-r--r--contrib/pgcrypto/pgp-decrypt.c2
-rw-r--r--contrib/pgcrypto/pgp-encrypt.c3
-rw-r--r--contrib/pgcrypto/pgp-info.c2
-rw-r--r--contrib/pgcrypto/pgp-mpi-internal.c2
-rw-r--r--contrib/pgcrypto/pgp-mpi-openssl.c2
-rw-r--r--contrib/pgcrypto/pgp-mpi.c2
-rw-r--r--contrib/pgcrypto/pgp-pgsql.c9
-rw-r--r--contrib/pgcrypto/pgp-pubdec.c2
-rw-r--r--contrib/pgcrypto/pgp-pubenc.c2
-rw-r--r--contrib/pgcrypto/pgp-pubkey.c2
-rw-r--r--contrib/pgcrypto/pgp-s2k.c2
-rw-r--r--contrib/pgcrypto/pgp.c2
-rw-r--r--contrib/pgcrypto/px-crypt.c3
-rw-r--r--contrib/pgcrypto/px-hmac.c3
-rw-r--r--contrib/pgcrypto/px.c2
-rw-r--r--contrib/pgcrypto/random.c4
-rw-r--r--contrib/pgcrypto/rijndael.c14
-rw-r--r--contrib/pgcrypto/sha1.c17
-rw-r--r--contrib/pgcrypto/sha2.c24
29 files changed, 76 insertions, 67 deletions
diff --git a/contrib/pgcrypto/blf.c b/contrib/pgcrypto/blf.c
index e6dde087cc..eb83f8356e 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$
*/
/*
@@ -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 32c0632ef8..49dcd0a087 100644
--- a/contrib/pgcrypto/crypt-md5.c
+++ b/contrib/pgcrypto/crypt-md5.c
@@ -8,10 +8,11 @@
*
* $FreeBSD$
*
+ * $PostgreSQL$
*/
-/* $PostgreSQL$ */
-#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 a720613539..98bb415ed7 100644
--- a/contrib/pgcrypto/fortuna.c
+++ b/contrib/pgcrypto/fortuna.c
@@ -29,13 +29,13 @@
* $PostgreSQL$
*/
-#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 e47c645349..880793e11d 100644
--- a/contrib/pgcrypto/internal.c
+++ b/contrib/pgcrypto/internal.c
@@ -29,12 +29,11 @@
* $PostgreSQL$
*/
+#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 9b03e12dcf..c7a8a632da 100644
--- a/contrib/pgcrypto/mbuf.c
+++ b/contrib/pgcrypto/mbuf.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#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 acb094e7a0..3a47a9ce17 100644
--- a/contrib/pgcrypto/md5.c
+++ b/contrib/pgcrypto/md5.c
@@ -1,4 +1,3 @@
-/* $PostgreSQL$ */
/* $KAME$ */
/*
@@ -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$
*/
#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 c729d193c1..8b27c84aea 100644
--- a/contrib/pgcrypto/openssl.c
+++ b/contrib/pgcrypto/openssl.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#include <postgres.h>
+#include "postgres.h"
#include "px.h"
diff --git a/contrib/pgcrypto/pgp-armor.c b/contrib/pgcrypto/pgp-armor.c
index 302bcd0cfa..8c6ecf836e 100644
--- a/contrib/pgcrypto/pgp-armor.c
+++ b/contrib/pgcrypto/pgp-armor.c
@@ -29,9 +29,7 @@
* $PostgreSQL$
*/
-#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 45e4400fcb..55d8557850 100644
--- a/contrib/pgcrypto/pgp-cfb.c
+++ b/contrib/pgcrypto/pgp-cfb.c
@@ -29,7 +29,8 @@
* $PostgreSQL$
*/
-#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 298564a223..5b4990863c 100644
--- a/contrib/pgcrypto/pgp-compress.c
+++ b/contrib/pgcrypto/pgp-compress.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#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 f4df5f226c..29fc0cce80 100644
--- a/contrib/pgcrypto/pgp-decrypt.c
+++ b/contrib/pgcrypto/pgp-decrypt.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#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 5e48f06ff5..e439cedfe6 100644
--- a/contrib/pgcrypto/pgp-encrypt.c
+++ b/contrib/pgcrypto/pgp-encrypt.c
@@ -29,7 +29,8 @@
* $PostgreSQL$
*/
-#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 b0e4ea5fb3..594331133d 100644
--- a/contrib/pgcrypto/pgp-info.c
+++ b/contrib/pgcrypto/pgp-info.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 a624ec8925..214bcebcae 100644
--- a/contrib/pgcrypto/pgp-mpi-internal.c
+++ b/contrib/pgcrypto/pgp-mpi-internal.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 d4b40f003a..5078bb523c 100644
--- a/contrib/pgcrypto/pgp-mpi-openssl.c
+++ b/contrib/pgcrypto/pgp-mpi-openssl.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 958e5a4d4b..0a368a6641 100644
--- a/contrib/pgcrypto/pgp-mpi.c
+++ b/contrib/pgcrypto/pgp-mpi.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 6f087ed4a2..dc64cc57e7 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -29,10 +29,11 @@
* $PostgreSQL$
*/
-#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 17af9151d4..8673c03039 100644
--- a/contrib/pgcrypto/pgp-pubdec.c
+++ b/contrib/pgcrypto/pgp-pubdec.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 03525a5ef2..05ecce55c0 100644
--- a/contrib/pgcrypto/pgp-pubenc.c
+++ b/contrib/pgcrypto/pgp-pubenc.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 1beee7f078..1ac6902144 100644
--- a/contrib/pgcrypto/pgp-pubkey.c
+++ b/contrib/pgcrypto/pgp-pubkey.c
@@ -28,7 +28,7 @@
*
* $PostgreSQL$
*/
-#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 cf640dd472..2dc7c8798c 100644
--- a/contrib/pgcrypto/pgp-s2k.c
+++ b/contrib/pgcrypto/pgp-s2k.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#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 7143dfe49c..0bd681a781 100644
--- a/contrib/pgcrypto/pgp.c
+++ b/contrib/pgcrypto/pgp.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#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 7abf3db5a6..9b35c6945f 100644
--- a/contrib/pgcrypto/px-crypt.c
+++ b/contrib/pgcrypto/px-crypt.c
@@ -29,7 +29,8 @@
* $PostgreSQL$
*/
-#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 d3954fba65..4883a008e4 100644
--- a/contrib/pgcrypto/px-hmac.c
+++ b/contrib/pgcrypto/px-hmac.c
@@ -29,8 +29,7 @@
* $PostgreSQL$
*/
-
-#include <postgres.h>
+#include "postgres.h"
#include "px.h"
diff --git a/contrib/pgcrypto/px.c b/contrib/pgcrypto/px.c
index c617f925d9..fa8ffdcfaf 100644
--- a/contrib/pgcrypto/px.c
+++ b/contrib/pgcrypto/px.c
@@ -29,7 +29,7 @@
* $PostgreSQL$
*/
-#include <postgres.h>
+#include "postgres.h"
#include "px.h"
diff --git a/contrib/pgcrypto/random.c b/contrib/pgcrypto/random.c
index bdc39965a5..1d870663f6 100644
--- a/contrib/pgcrypto/random.c
+++ b/contrib/pgcrypto/random.c
@@ -29,8 +29,7 @@
* $PostgreSQL$
*/
-
-#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 3a9c6e5fca..18e0752cf4 100644
--- a/contrib/pgcrypto/rijndael.c
+++ b/contrib/pgcrypto/rijndael.c
@@ -1,5 +1,7 @@
/* $OpenBSD$ */
+/* $PostgreSQL$ */
+
/* 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 ad303fa0fe..0025f57680 100644
--- a/contrib/pgcrypto/sha1.c
+++ b/contrib/pgcrypto/sha1.c
@@ -1,4 +1,3 @@
-/* $PostgreSQL$ */
/* $KAME$ */
/*
@@ -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$
*/
/*
* 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 82dd1229d0..97dd8d9e46 100644
--- a/contrib/pgcrypto/sha2.c
+++ b/contrib/pgcrypto/sha2.c
@@ -1,4 +1,3 @@
-/* $PostgreSQL$ */
/* $OpenBSD$ */
/*
@@ -33,9 +32,13 @@
* SUCH DAMAGE.
*
* $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
+ *
+ * $PostgreSQL$
*/
-#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 */