summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorDwayne C. Litzenberger <dlitz@dlitz.net>2008-09-15 21:32:58 -0400
committerDwayne C. Litzenberger <dlitz@dlitz.net>2008-09-15 23:01:37 -0400
commitfec685ff8d63dd9dd6dd347c05c8f136f1583c3e (patch)
treeccac59512839a636e1735b33941fb92624283317 /setup.py
parent1660c692982b01741176047eefa53d794f8a81bc (diff)
downloadpycrypto-fec685ff8d63dd9dd6dd347c05c8f136f1583c3e.tar.gz
RIPEMD160: Detect endianness at build-time rather than at runtime
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/setup.py b/setup.py
index acf5184..b7038b8 100644
--- a/setup.py
+++ b/setup.py
@@ -6,6 +6,7 @@ from distutils import core
from distutils.core import Extension
from distutils.command.build_ext import build_ext
import os, sys
+import struct
if sys.version[0:1] == '1':
raise RuntimeError, ("The Python Cryptography Toolkit requires "
@@ -68,6 +69,14 @@ def find_library_file(compiler, libname, std_dirs, paths):
result = find_file(filename, std_dirs, paths)
return result
+def endianness_macro():
+ s = struct.pack("@L", 0x33221100)
+ if s == "\x00\x11\x22\x33": # little endian
+ return ('PCT_LITTLE_ENDIAN', 1)
+ elif s == "\x33\x22\x11\x00": # big endian
+ return ('PCT_BIG_ENDIAN', 1)
+ raise AssertionError("Machine is neither little-endian nor big-endian")
+
class PCTBuildExt (build_ext):
def build_extensions(self):
self.extensions += [
@@ -80,7 +89,8 @@ class PCTBuildExt (build_ext):
sources=["src/SHA256.c"]),
Extension("Crypto.Hash.RIPEMD160",
include_dirs=['src/'],
- sources=["src/RIPEMD160.c"]),
+ sources=["src/RIPEMD160.c"],
+ define_macros=[endianness_macro()]),
# Block encryption algorithms
Extension("Crypto.Cipher.AES",