Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ supporting them.

• RSA from the Crypto++ library ; see pycryptopp.publickey.rsa ; deprecated
in favor of Ed25519
• Ecdsa from the Crypto++ library ; see pycryptopp.publickey.ecdsa ;
deprecated in favor of Ed25519
• SHA-256 from the Crypto++ library ; see pycryptopp.hash.sha256 ; deprecated
in favor of the Python Standard Library's hashlib module

Expand Down
2 changes: 1 addition & 1 deletion _doubleloadtester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static PyMethodDef _doubleloadtester_functions[] = {
};

/* from Crypto++ */
#ifdef DISABLE_EMBEDDED_CRYPTOPP
#ifdef PYCRYPTOPP_USE_SYSTEM_CRYPTOPP
#include <cryptopp/cryptlib.h>
#else
#include <src-cryptopp/cryptlib.h>
Expand Down
2 changes: 1 addition & 1 deletion pycryptopp.egg-info/stdeb.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pycryptopp]
Copyright-File: copyright
Setup-Env-Vars: PYCRYPTOPP_DISABLE_EMBEDDED_CRYPTOPP=1
Setup-Env-Vars: PYCRYPTOPP_USE_SYSTEM_CRYPTOPP_WITH_ASM=1
84 changes: 24 additions & 60 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

# Copyright © 2009-2012 Zooko Wilcox-O'Hearn
# Copyright © 2009-2013 Zooko Wilcox-O'Hearn
# Author: Zooko Wilcox-O'Hearn
#
# See README.rst for licensing information.

import os, platform, re, subprocess, sys
import os, platform, re, sys

from setuptools import Extension, setup
from setuptools import Command
Expand All @@ -18,25 +18,30 @@

import versioneer

# ECDSA=False
ECDSA=True

DEBUG=False
if "--debug" in sys.argv:
DEBUG=True
sys.argv.remove("--debug")

DISABLE_EMBEDDED_CRYPTOPP=False
if "--disable-embedded-cryptopp" in sys.argv:
DISABLE_EMBEDDED_CRYPTOPP=True
sys.argv.remove("--disable-embedded-cryptopp")
print "The --disable-embedded-cryptopp option has been removed. Use either --use-system-cryptopp-with-asm or --use-system-cryptopp-without-asm."
sys.exit(1)

# Unfortunately stdeb v0.3 doesn't seem to offer a way to pass command-line
# arguments to setup.py when building for Debian, but it does offer a way to
# pass environment variables, so we here check for that in addition to the
# command-line argument check above.
if os.environ.get('PYCRYPTOPP_DISABLE_EMBEDDED_CRYPTOPP') == "1":
DISABLE_EMBEDDED_CRYPTOPP=True
print "The PYCRYPTOPP_DISABLE_EMBEDDED_CRYPTOPP environment variable is not supported. Use either PYCRYPTOPP_USE_SYSTEM_CRYPTOPP_WITH_ASM or PYCRYPTOPP_USE_SYSTEM_CRYPTOPP_WITHOUT_ASM."
sys.exit(1)

USE_SYSTEM_CRYPTOPP=False # False, "with asm", or "without asm"
if "--use-system-cryptopp-with-asm" in sys.argv:
USE_SYSTEM_CRYPTOPP='with asm'
sys.argv.remove("--use-system-cryptopp-with-asm")
elif "--use-system-cryptopp-without-asm" in sys.argv:
USE_SYSTEM_CRYPTOPP='without asm'
sys.argv.remove("--use-system-cryptopp-without-asm")

EMBEDDED_CRYPTOPP_DIR='src-cryptopp'

Expand Down Expand Up @@ -76,8 +81,11 @@
else:
extra_compile_args.append("-w")

if DISABLE_EMBEDDED_CRYPTOPP:
define_macros.append(('DISABLE_EMBEDDED_CRYPTOPP', 1))
if USE_SYSTEM_CRYPTOPP:
define_macros.append(('PYCRYPTOPP_USE_SYSTEM_CRYPTOPP', 1))

if USE_SYSTEM_CRYPTOPP == "without asm":
define_macros.append(('CRYPTOPP_DISABLE_ASM', 1))

# Link with a Crypto++ library that is already installed on the system.

Expand Down Expand Up @@ -106,28 +114,14 @@
else:
# Build the bundled Crypto++ library which is included by source
# code in the pycryptopp tree and link against it.
define_macros.append(('CRYPTOPP_DISABLE_ASM', 1))

include_dirs.append(".")

if 'sunos' in platform.system().lower():
extra_compile_args.append('-Wa,--divide') # allow use of "/" operator

if 'win32' in sys.platform.lower():
try:
res = subprocess.Popen(['cl'], stdin=open(os.devnull), stdout=subprocess.PIPE).communicate()
except EnvironmentError, le:
# Okay I guess we're not using the "cl.exe" compiler.
using_msvc = False
else:
using_msvc = True
else:
using_msvc = False

if using_msvc:
# We can handle out-of-line assembly.
cryptopp_src = [ os.path.join(EMBEDDED_CRYPTOPP_DIR, x) for x in os.listdir(EMBEDDED_CRYPTOPP_DIR) if x.endswith(('.cpp', '.asm')) ]
else:
# We can't handle out-of-line assembly.
cryptopp_src = [ os.path.join(EMBEDDED_CRYPTOPP_DIR, x) for x in os.listdir(EMBEDDED_CRYPTOPP_DIR) if x.endswith('.cpp') ]
cryptopp_src = [ os.path.join(EMBEDDED_CRYPTOPP_DIR, x) for x in os.listdir(EMBEDDED_CRYPTOPP_DIR) if x.endswith('.cpp') ]

# Mac OS X extended attribute files when written to a non-Mac-OS-X
# filesystem come out as "._$FNAME", for example "._rdtables.cpp",
Expand All @@ -137,34 +131,6 @@

extra_srcs.extend(cryptopp_src)

# In either case, we must provide a value for CRYPTOPP_DISABLE_ASM that
# matches the one used when Crypto++ was originally compiled. The Crypto++
# GNUmakefile tests the assembler version and only enables assembly for
# recent versions of the GNU assembler (2.10 or later). The /usr/bin/as on
# Mac OS-X 10.6 is too old.

try:
sp = subprocess.Popen(['as', '-v'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
sp.stdin.close()
sp.wait()
if re.search("GNU assembler version (0|1|2.0)", sp.stderr.read()):
define_macros.append(('CRYPTOPP_DISABLE_ASM', 1))
except EnvironmentError:
# Okay, nevermind. Maybe there isn't even an 'as' executable on this
# platform.
pass
else:
try:
# that "as -v" step creates an empty a.out, so clean it up. Modern GNU
# "as" has --version, which emits the version number without actually
# assembling anything, but older versions only have -v, which emits a
# version number and *then* assembles from stdin.
os.unlink("a.out")
except EnvironmentError:
pass

trove_classifiers=[
"Environment :: Console",
"License :: OSI Approved :: GNU General Public License (GPL)", # See README.rst for alternative licensing.
Expand All @@ -189,8 +155,6 @@
'src/pycryptopp/cipher/aesmodule.cpp',
'src/pycryptopp/cipher/xsalsa20module.cpp',
]
if ECDSA:
srcs.append('src/pycryptopp/publickey/ecdsamodule.cpp')
if BUILD_DOUBLE_LOAD_TESTER:
srcs.append('_doubleloadtester.cpp', )

Expand Down Expand Up @@ -225,7 +189,7 @@
setup_requires.append('setuptools_pyflakes >= 1.0.0')

# stdeb is required to produce Debian files with "sdist_dsc".
# http://github.com/astraw/stdeb/tree/master
# https://github.com/astraw/stdeb/tree/master
if "sdist_dsc" in sys.argv:
setup_requires.append('stdeb')

Expand Down Expand Up @@ -433,7 +397,7 @@ def _setup(longdescription):
description='Python wrappers for a few algorithms from the Crypto++ library',
long_description=longdescription,
author='Zooko Wilcox-O\'Hearn',
author_email='zooko@zooko.com',
author_email='zookog@gmail.com',
url='https://tahoe-lafs.org/trac/' + PKG,
license='GNU GPL', # see README.rst for details -- there is also an alternative licence
packages=["pycryptopp",
Expand Down
8 changes: 3 additions & 5 deletions src/pycryptopp/_pycryptoppmodule.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <Python.h>

#include "publickey/ecdsamodule.hpp"
#include "publickey/rsamodule.hpp"
#include "hash/sha256module.hpp"
#include "cipher/aesmodule.hpp"
#include "cipher/xsalsa20module.hpp"

/* from Crypto++ */
#ifdef DISABLE_EMBEDDED_CRYPTOPP
#ifdef PYCRYPTOPP_USE_SYSTEM_CRYPTOPP
#include <cryptopp/config.h>
#else
#include <src-cryptopp/config.h>
Expand All @@ -17,7 +16,7 @@ PyDoc_STRVAR(_pycryptopp__doc__,
"_pycryptopp -- Python wrappers for a few algorithms from Crypto++\n\
\n\
from pycryptopp import publickey\n\
from pycryptopp.publickey import ecdsa\n\
from pycryptopp.publickey import ed25519\n\
from pycryptopp.publickey import rsa\n\
from pycryptopp import cipher\n\
from pycryptopp.cipher import aes\n\
Expand Down Expand Up @@ -46,7 +45,7 @@ init_pycryptopp(void) {
PyObject* version;

/* a tuple of (Crypto++ version, extra-version) */
#ifndef DISABLE_EMBEDDED_CRYPTOPP
#ifndef PYCRYPTOPP_USE_SYSTEM_CRYPTOPP
/* In the version of Crypto++ which is included in pycryptopp, there is a
symbol named `cryptopp_extra_version' which is declared (external
variable) in config.h and defined in cryptlib.cpp. Of course it is
Expand All @@ -64,7 +63,6 @@ init_pycryptopp(void) {
return;


init_ecdsa(module);
init_rsa(module);
init_sha256(module);
init_aes(module);
Expand Down
10 changes: 10 additions & 0 deletions src/pycryptopp/bench/bench_algs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import bench_sigs, bench_ciphers, bench_hashes

def print_versions():
import pycryptopp
print "pycryptopp: ", pycryptopp
print "pycryptopp.__version__: ", pycryptopp.__version__,
print "pycryptopp._pycryptopp.cryptopp_version: ", pycryptopp._pycryptopp.cryptopp_version
print "pycryptopp.publickey.ed25519._version.get_versions(): ", pycryptopp.publickey.ed25519._version.get_versions()
import pkg_resources
print "pkg_resources.require('pycryptopp'): ", pkg_resources.require('pycryptopp')

def bench(MAXTIME=10.0):
print_versions()
bench_sigs.bench(MAXTIME)
bench_ciphers.bench(MAXTIME)
bench_hashes.bench(MAXTIME)
Expand Down
32 changes: 2 additions & 30 deletions src/pycryptopp/bench/bench_sigs.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
from pycryptopp.publickey import ecdsa, ed25519, rsa
from pycryptopp.publickey import ed25519, rsa

from common import insecurerandstr, rep_bench

msg = 'crypto libraries should come with benchmarks'

class ECDSA256(object):
def __init__(self):
self.seed = insecurerandstr(32)
self.signer = None

def gen(self, N):
for i in xrange(N):
ecdsa.SigningKey(self.seed)

def sign_init(self, N):
self.signer = ecdsa.SigningKey(self.seed)

def sign(self, N):
signer = self.signer
for i in xrange(N):
signer.sign(msg)

def ver_init(self, N):
signer = ecdsa.SigningKey(self.seed)
self.sig = signer.sign(msg)
self.verifier = signer.get_verifying_key()

def ver(self, N):
sig = self.sig
verifier = self.verifier
for i in xrange(N):
verifier.verify(sig, msg)

class Ed25519(object):
def __init__(self):
self.seed = insecurerandstr(32)
Expand Down Expand Up @@ -119,7 +91,7 @@ def ver(self, N):
verifier.verify(msg, sig)

def bench_sigs(MAXTIME):
for klass in [ECDSA256, Ed25519,]:
for klass in [Ed25519,]:
print klass
ob = klass()
print "generate key"
Expand Down
2 changes: 1 addition & 1 deletion src/pycryptopp/cipher/aesmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef int Py_ssize_t;


/* from Crypto++ */
#ifdef DISABLE_EMBEDDED_CRYPTOPP
#ifdef PYCRYPTOPP_USE_SYSTEM_CRYPTOPP
#include <cryptopp/modes.h>
#include <cryptopp/aes.h>
#else
Expand Down
2 changes: 1 addition & 1 deletion src/pycryptopp/cipher/xsalsa20module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef int Py_ssize_t;

#include "xsalsa20module.hpp"

#ifdef DISABLE_EMBEDDED_CRYPTOPP
#ifdef PYCRYPTOPP_USE_SYSTEM_CRYPTOPP
#include <cryptopp/salsa.h>
#else
#include <src-cryptopp/salsa.h>
Expand Down
2 changes: 1 addition & 1 deletion src/pycryptopp/hash/sha256module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef int Py_ssize_t;
#include <assert.h>

/* from Crypto++ */
#ifdef DISABLE_EMBEDDED_CRYPTOPP
#ifdef PYCRYPTOPP_USE_SYSTEM_CRYPTOPP
#include <cryptopp/sha.h>
#include <cryptopp/hex.h>
#include <cryptopp/filters.h>
Expand Down
4 changes: 2 additions & 2 deletions src/pycryptopp/publickey/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import ecdsa, rsa, ed25519
import rsa, ed25519

quiet_pyflakes=[ecdsa, rsa, ed25519]
quiet_pyflakes=[rsa, ed25519]
5 changes: 0 additions & 5 deletions src/pycryptopp/publickey/ecdsa.py

This file was deleted.

Loading