summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-02-21 00:45:27 -0800
committerDwayne Litzenberger <dlitz@dlitz.net>2013-04-21 20:41:18 -0700
commit1dd8353cc490f954677285415ec01e253f84b93d (patch)
tree485b17eeaad2f25b85f5491a47d0224047ce9137
parent076560be889ef220c8fb10dd68635468939345ab (diff)
downloadpycrypto-1dd8353cc490f954677285415ec01e253f84b93d.tar.gz
Add pycrypto_common.h and clean up a bunch of miscellaneous includes & typedefs
-rw-r--r--src/AES.c8
-rw-r--r--src/ARC2.c8
-rw-r--r--src/ARC4.c2
-rw-r--r--src/Blowfish.c15
-rw-r--r--src/CAST.c6
-rw-r--r--src/DES.c2
-rw-r--r--src/MD2.c7
-rw-r--r--src/MD4.c8
-rw-r--r--src/RIPEMD160.c14
-rw-r--r--src/SHA224.c2
-rw-r--r--src/SHA256.c3
-rw-r--r--src/SHA384.c2
-rw-r--r--src/SHA512.c2
-rw-r--r--src/XOR.c2
-rw-r--r--src/_counter.c3
-rw-r--r--src/_counter.h11
-rw-r--r--src/_fastmath.c12
-rw-r--r--src/block_template.c14
-rw-r--r--src/cast5.c1
-rw-r--r--src/hash_SHA2.h12
-rw-r--r--src/hash_SHA2_template.c3
-rw-r--r--src/hash_template.c8
-rw-r--r--src/inc-msvc/config.h7
-rw-r--r--src/pycrypto_common.h41
-rw-r--r--src/stream_template.c12
-rw-r--r--src/strxor.c5
-rw-r--r--src/winrand.c3
27 files changed, 95 insertions, 118 deletions
diff --git a/src/AES.c b/src/AES.c
index 9b125e2..5da189f 100644
--- a/src/AES.c
+++ b/src/AES.c
@@ -24,7 +24,7 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#include <assert.h>
#include <stdlib.h>
@@ -36,9 +36,9 @@
#define MAXKB (256/8)
#define MAXNR 14
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
typedef struct {
u32 ek[ 4*(MAXNR+1) ];
diff --git a/src/ARC2.c b/src/ARC2.c
index a872823..255e77e 100644
--- a/src/ARC2.c
+++ b/src/ARC2.c
@@ -41,7 +41,7 @@
*
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#include <string.h>
#define MODULE_NAME _ARC2
@@ -49,9 +49,9 @@
#define KEY_SIZE 0
#define PCT_ARC2_MODULE /* Defined to get ARC2's additional keyword arguments */
-typedef unsigned int U32;
-typedef unsigned short U16;
-typedef unsigned char U8;
+typedef uint32_t U32;
+typedef uint16_t U16;
+typedef uint8_t U8;
typedef struct
{
diff --git a/src/ARC4.c b/src/ARC4.c
index 28dc4a3..a125fab 100644
--- a/src/ARC4.c
+++ b/src/ARC4.c
@@ -26,6 +26,8 @@
*
*/
+#include "pycrypto_common.h"
+
#define MODULE_NAME _ARC4
#define BLOCK_SIZE 1
#define KEY_SIZE 0
diff --git a/src/Blowfish.c b/src/Blowfish.c
index 9985728..96f8628 100644
--- a/src/Blowfish.c
+++ b/src/Blowfish.c
@@ -26,22 +26,11 @@
* http://www.schneier.com/paper-blowfish-fse.html
*/
-#include "Python.h"
-#include "config.h"
-#if HAVE_STDINT_H
-# include <stdint.h>
-#elif HAVE_INTTYPES_H
-# include <inttypes.h>
-#elif HAVE_SYS_INTTYPES_H
-# include <sys/inttypes.h>
-#else
-# error "stdint.h and inttypes.h not found"
-#endif
+#include "pycrypto_common.h"
+#include "Blowfish-tables.h"
#include <assert.h>
#include <string.h>
-#include "Blowfish-tables.h"
-
#define MODULE_NAME _Blowfish
#define BLOCK_SIZE 8 /* 64-bit block size */
#define KEY_SIZE 0 /* variable key size */
diff --git a/src/CAST.c b/src/CAST.c
index 9ff9862..ca5d0f0 100644
--- a/src/CAST.c
+++ b/src/CAST.c
@@ -42,7 +42,7 @@
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#define MODULE_NAME _CAST
#define BLOCK_SIZE 8
@@ -50,8 +50,8 @@
/* adjust these according to your compiler/platform. On some machines
uint32 will have to be a long. It's OK if uint32 is more than 32 bits. */
-typedef unsigned int uint32;
-typedef unsigned char uint8;
+typedef uint32_t uint32;
+typedef uint8_t uint8;
/* this struct probably belongs in cast.h */
typedef struct {
diff --git a/src/DES.c b/src/DES.c
index 096e309..9cbda53 100644
--- a/src/DES.c
+++ b/src/DES.c
@@ -24,7 +24,7 @@
* Country of origin: Canada
*/
-#include "Python.h"
+#include "pycrypto_common.h"
/* Setting this will cause LibTomCrypt to return CRYPT_INVALID_ARG when its
* assert-like LTC_ARGCHK macro fails. */
diff --git a/src/MD2.c b/src/MD2.c
index 043bcc8..4214ac0 100644
--- a/src/MD2.c
+++ b/src/MD2.c
@@ -27,9 +27,8 @@
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#include <string.h>
-#include "pycrypto_compat.h"
#define MODULE_NAME MD2
#define DIGEST_SIZE 16
@@ -52,8 +51,8 @@ static char MODULE__doc__[] =
"\n"
".. _RFC1319: http://tools.ietf.org/html/rfc1319\n";
-typedef unsigned char U8;
-typedef unsigned int U32;
+typedef uint8_t U8;
+typedef uint32_t U32;
typedef struct {
U8 C[16], X[48];
diff --git a/src/MD4.c b/src/MD4.c
index 7e453a8..a2be10e 100644
--- a/src/MD4.c
+++ b/src/MD4.c
@@ -25,11 +25,9 @@
* ===================================================================
*
*/
-
-#include "Python.h"
+#include "pycrypto_common.h"
#include <string.h>
-#include "pycrypto_compat.h"
#define MODULE_NAME MD4
#define DIGEST_SIZE 16
@@ -52,8 +50,8 @@ static char MODULE__doc__[] =
"\n"
".. _RFC1320: http://tools.ietf.org/html/rfc1320\n";
-typedef unsigned int U32;
-typedef unsigned char U8;
+typedef uint32_t U32;
+typedef uint8_t U8;
#define U32_MAX (U32)4294967295
typedef struct {
diff --git a/src/RIPEMD160.c b/src/RIPEMD160.c
index b12773c..67fec96 100644
--- a/src/RIPEMD160.c
+++ b/src/RIPEMD160.c
@@ -43,21 +43,9 @@
* "RIPEMD-160 is big-bit-endian, little-byte-endian, and left-justified."
*/
-#include "Python.h"
-#include "config.h"
-#if HAVE_STDINT_H
-# include <stdint.h>
-#elif HAVE_INTTYPES_H
-# include <inttypes.h>
-#elif HAVE_SYS_INTTYPES_H
-# include <sys/inttypes.h>
-#else
-# error "stdint.h and inttypes.h not found"
-#endif
-
+#include "pycrypto_common.h"
#include <assert.h>
#include <string.h>
-#include "pycrypto_compat.h"
#define RIPEMD160_DIGEST_SIZE 20
#define BLOCK_SIZE 64
diff --git a/src/SHA224.c b/src/SHA224.c
index 86591cf..e060e11 100644
--- a/src/SHA224.c
+++ b/src/SHA224.c
@@ -27,6 +27,8 @@
*
*/
+#include "pycrypto_common.h"
+
#define MODULE_NAME SHA224
#define DIGEST_SIZE (224/8)
#define BLOCK_SIZE (512/8)
diff --git a/src/SHA256.c b/src/SHA256.c
index 9473abc..b735b81 100644
--- a/src/SHA256.c
+++ b/src/SHA256.c
@@ -26,6 +26,9 @@
* ===================================================================
*
*/
+
+#include "pycrypto_common.h"
+
#define MODULE_NAME SHA256
#define DIGEST_SIZE (256/8)
#define BLOCK_SIZE (512/8)
diff --git a/src/SHA384.c b/src/SHA384.c
index eb7051e..8bc099a 100644
--- a/src/SHA384.c
+++ b/src/SHA384.c
@@ -27,6 +27,8 @@
*
*/
+#include "pycrypto_common.h"
+
#define MODULE_NAME SHA384
#define DIGEST_SIZE (384/8)
#define BLOCK_SIZE (1024/8)
diff --git a/src/SHA512.c b/src/SHA512.c
index f12755c..4b06b2f 100644
--- a/src/SHA512.c
+++ b/src/SHA512.c
@@ -27,6 +27,8 @@
*
*/
+#include "pycrypto_common.h"
+
#define MODULE_NAME SHA512
#define DIGEST_SIZE (512/8)
#define BLOCK_SIZE (1024/8)
diff --git a/src/XOR.c b/src/XOR.c
index 985e94f..d994749 100644
--- a/src/XOR.c
+++ b/src/XOR.c
@@ -24,7 +24,7 @@
* =======================================================================
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#define MODULE_NAME _XOR
#define BLOCK_SIZE 1
diff --git a/src/_counter.c b/src/_counter.c
index 6579a5f..2d6aa48 100644
--- a/src/_counter.c
+++ b/src/_counter.c
@@ -22,11 +22,10 @@
* ===================================================================
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#include <assert.h>
#include <stddef.h>
#include <string.h>
-#include "pycrypto_compat.h"
#include "_counter.h"
#ifndef IS_PY3K
diff --git a/src/_counter.h b/src/_counter.h
index 2817865..32c320b 100644
--- a/src/_counter.h
+++ b/src/_counter.h
@@ -24,16 +24,7 @@
#ifndef PCT__COUNTER_H
#define PCT__COUNTER_H
-#include "config.h"
-#if HAVE_STDINT_H
-# include <stdint.h>
-#elif HAVE_INTTYPES_H
-# include <inttypes.h>
-#elif HAVE_SYS_INTTYPES_H
-# include <sys/inttypes.h>
-#else
-# error "stdint.h and inttypes.h not found"
-#endif
+#include "pycrypto_common.h"
typedef struct {
PyObject_HEAD
diff --git a/src/_fastmath.c b/src/_fastmath.c
index bd2651d..4f2932d 100644
--- a/src/_fastmath.c
+++ b/src/_fastmath.c
@@ -26,12 +26,10 @@
* $Id$
*/
-#include "Python.h"
+#include "pycrypto_common.h"
#include <stdio.h>
#include <string.h>
-#include "pycrypto_compat.h"
#include <longintrepr.h> /* for conversions */
-#include "config.h"
#if HAVE_LIBGMP
# include <gmp.h>
#elif HAVE_LIBMPIR
@@ -53,12 +51,6 @@
#define SIEVE_BASE_SIZE (sizeof (sieve_base) / sizeof (sieve_base[0]))
-#ifdef _MSC_VER
-#define INLINE __inline
-#else
-#define INLINE inline
-#endif
-
static unsigned int sieve_base[10000];
static int rabinMillerTest (mpz_t n, int rounds, PyObject *randfunc);
@@ -1111,7 +1103,7 @@ cleanup:
-INLINE size_t size (mpz_t n)
+inline size_t size (mpz_t n)
{
return mpz_sizeinbase (n, 2);
}
diff --git a/src/block_template.c b/src/block_template.c
index 2cfee1b..8ef09ac 100644
--- a/src/block_template.c
+++ b/src/block_template.c
@@ -24,19 +24,9 @@
* ===================================================================
*/
-#include "Python.h"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef _HAVE_STDC_HEADERS
+#include "pycrypto_common.h"
+#include "modsupport.h"
#include <string.h>
-#endif
-
-#include "pycrypto_compat.h"
-#include "modsupport.h"
-
#include "_counter.h"
/* Cipher operation modes */
diff --git a/src/cast5.c b/src/cast5.c
index 0843b98..a86615e 100644
--- a/src/cast5.c
+++ b/src/cast5.c
@@ -2,6 +2,7 @@
These are the S-boxes for CAST5 as given in RFC 2144.
*/
+#include "pycrypto_common.h"
static const uint32 S1[256] = {
0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f,
diff --git a/src/hash_SHA2.h b/src/hash_SHA2.h
index caa1e84..a3b633d 100644
--- a/src/hash_SHA2.h
+++ b/src/hash_SHA2.h
@@ -26,17 +26,7 @@
#ifndef __HASH_SHA2_H
#define __HASH_SHA2_H
-#include "Python.h"
-#include "config.h"
-#if HAVE_STDINT_H
-# include <stdint.h>
-#elif HAVE_INTTYPES_H
-# include <inttypes.h>
-#elif HAVE_SYS_INTTYPES_H
-# include <sys/inttypes.h>
-#else
-# error "stdint.h and inttypes.h not found"
-#endif
+#include "pycrypto_common.h"
/* check if implementation set the correct macros */
#ifndef MODULE_NAME
diff --git a/src/hash_SHA2_template.c b/src/hash_SHA2_template.c
index 0725967..c7b8a13 100644
--- a/src/hash_SHA2_template.c
+++ b/src/hash_SHA2_template.c
@@ -30,8 +30,7 @@
*
*/
-#include "Python.h"
-#include "pycrypto_compat.h"
+#include "pycrypto_common.h"
/* compress one block */
static void sha_compress(hash_state * hs)
diff --git a/src/hash_template.c b/src/hash_template.c
index d085bb8..1e0ed70 100644
--- a/src/hash_template.c
+++ b/src/hash_template.c
@@ -24,14 +24,8 @@
/* Basic object type */
-#include "Python.h"
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#ifdef _HAVE_STDC_HEADERS
+#include "pycrypto_common.h"
#include <string.h>
-#endif
-#include "pycrypto_compat.h"
#define _STR(x) #x
#define _XSTR(x) _STR(x)
diff --git a/src/inc-msvc/config.h b/src/inc-msvc/config.h
index 2b7a626..2485df9 100644
--- a/src/inc-msvc/config.h
+++ b/src/inc-msvc/config.h
@@ -14,3 +14,10 @@
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ * calls it, or to nothing if 'inline' is not supported under any name. */
+#define inline __inline
diff --git a/src/pycrypto_common.h b/src/pycrypto_common.h
new file mode 100644
index 0000000..3182ec1
--- /dev/null
+++ b/src/pycrypto_common.h
@@ -0,0 +1,41 @@
+/*
+ * pycrypto_compat.h: Common header file for PyCrypto
+ *
+ * Written in 2013 by Dwayne C. Litzenberger <dlitz@dlitz.net>
+ *
+ * ===================================================================
+ * The contents of this file are dedicated to the public domain. To
+ * the extent that dedication to the public domain is not available,
+ * everyone is granted a worldwide, perpetual, royalty-free,
+ * non-exclusive license to exercise all rights associated with the
+ * contents of this file for any purpose whatsoever.
+ * No rights are reserved.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ * ===================================================================
+ */
+#ifndef PYCRYPTO_COMMON_H
+#define PYCRYPTO_COMMON_H
+
+#include "Python.h"
+#include "pycrypto_compat.h"
+#include "config.h"
+#if HAVE_STDINT_H
+# include <stdint.h>
+#elif HAVE_INTTYPES_H
+# include <inttypes.h>
+#elif HAVE_SYS_INTTYPES_H
+# include <sys/inttypes.h>
+#else
+# error "stdint.h and inttypes.h not found"
+#endif
+
+
+#endif /* PYCRYPTO_COMMON_H */
diff --git a/src/stream_template.c b/src/stream_template.c
index a74d18d..6384788 100644
--- a/src/stream_template.c
+++ b/src/stream_template.c
@@ -24,17 +24,7 @@
* ===================================================================
*/
-#include "Python.h"
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#ifdef _HAVE_STDC_HEADERS
-#include <string.h>
-#endif
-
-#include "pycrypto_compat.h"
+#include "pycrypto_common.h"
#include "modsupport.h"
#define _STR(x) #x
diff --git a/src/strxor.c b/src/strxor.c
index 7cbbc1c..575d3f8 100644
--- a/src/strxor.c
+++ b/src/strxor.c
@@ -21,13 +21,12 @@
* SOFTWARE.
* ===================================================================
*/
-#include "Python.h"
+
+#include "pycrypto_common.h"
#include <stddef.h>
#include <assert.h>
#include <string.h>
-#include "pycrypto_compat.h"
-
static const char rcsid[] = "$Id$";
/*
diff --git a/src/winrand.c b/src/winrand.c
index d505e54..56aa450 100644
--- a/src/winrand.c
+++ b/src/winrand.c
@@ -30,8 +30,7 @@
/* Author: Mark Moraes */
-#include "Python.h"
-#include "pycrypto_compat.h"
+#include "pycrypto_common.h"
#ifdef MS_WIN32