Interface : Ciphers : Hashes : Utils : Examples : Structure : Download & Installation : Copyright & License : History : Home | Version 0.2.0 |
A while ago I started getting interested in Andrew Kuchling's pycrypt package. This was mainly because I had some plans for implementing secure channels from a clients local server to the webserver. The connection going via HTTP through the firewalls to the server. Unfortunately, Andrew's package falls under the US ITAR export restrictions and he can only make the non-encrypting parts of the package available for export.
Since I wanted to use his package which I find very well structured, I had to find a way to fill in the blanks. Basically these three options were available:
I decided to take the third approach. OpenSSL is well supported, distributed world-wide and has a set of very fast implementations for most of the parts missing in Andrew's export version of pycrypt. So here goes: a wrapper for the ciphers and hash functions in the fantastic OpenSSL library.
The package is called mx.Crypto and includes these subpackages:
It currently does not define an interface on its own.
Note that you can also access the ciphers and hash functions through Andrew's package if you have installed the package following the instructions given below. The documentation given here is merely provided to point out minor differences between pycrypt's interface and mxCrypto's.
This subpackage wraps the cipher algorithms available in OpenSSL in a way that is nearly 100% compatible with what Andrew has implemented in his package.
All ciphers are provided as objects with a common interface:
These constructors are available in the Ciphers subpackage (DEFAULT_MODE and DEFAULT_IV are explained below):
RC2(key, mode=DEFAULT_MODE, IV=DEFAULT_IV)
RC4(key, mode=DEFAULT_MODE)
RC5(key, mode=DEFAULT_MODE, IV=DEFAULT_IV, rounds=16,
version=0x10, wordsize=32)
Blowfish(key, mode=DEFAULT_MODE, IV=DEFAULT_IV)
IDEA(key, mode=DEFAULT_MODE, IV=DEFAULT_IV)
DES(key, mode=DEFAULT_MODE, IV=DEFAULT_IV)
DES3(key, mode=DEFAULT_MODE, IV=DEFAULT_IV)
CAST(key, mode=DEFAULT_MODE, IV=DEFAULT_IV)
All cipher objects provide a similar interface. They define at least these methods:
encrypt(string)
decrypt(string)
The DES and DES3 objects also define this method:
isWeak()
Ciphers define these instance variables:
blocksize
(readonly)
keysize
(readonly)
mode
(readonly)
IV
These constants are available:
ECB, CBC, CFB
DEFAULT_MODE = ECB
DEFAULT_IV
This subpackage wraps the hash algorithms available in OpenSSL in a way that is 100% compatible with what Andrew has implemented in his package.
All hash algorithms are provided as objects with a common interface:
These constructors are available in the Hashes subpackage (DEFAULT_DATA is explained below):
MD2(string=DEFAULT_DATA)
MD4(string=DEFAULT_DATA)
MD5(string=DEFAULT_DATA)
SHA(string=DEFAULT_DATA)
RIPEMD(string=DEFAULT_DATA)
All hash objects provide a similar interface. They define at least these methods:
update(string)
digest()
hexdigest()
digest()
except that a 2-byte HEX
version of the string is returned. See
str2hex()
for details on the format.
copy()
Hashes define this instance variable:
digestsize
(readonly)digest()
on the hash object.
These constants are available:
DEFAULT_DATA = ''
This subpackage provides some handy helper functions:
str2hex(string)
hex2str(hexstring)
Here is a very simple one:
from mx.Crypto.Ciphers import RC4 from mx.Crypto.Utils import str2hex c = RC4('MyKey123') e = c.encrypt('Hello World!') print 'Less readable:',str2hex(e) c = RC4('MyKey123') print 'More readable:',c.decrypt(e)
This should the following output:
Less readable: f166e053dd40552b97a9bc23 More readable: Hello World!
For more elaborate examples of how to use the ciphers and hash functions, have a look at the Examples/ subdirectory of the package.
Small highlight: It includes a script which let's you
en/decrypt files of any size. (Use with care though: the
script is not well tested yet.) To see all options run
'python cipher.py -h'. The script shows how to deal with
blocksizes, padding and writing cipher independant code.
Entries enclosed in brackets are packages (i.e. they are
directories that include a __init__.py file). Ones
without brackets are just simple subdirectories that are not
accessible via
The package imports all symbols from the extension module
mxCrypto, so you only need to '
The package needs two other packages to be compiled and
installed first:
Next, download the archive
(located on a US server, but doesn't contain any cryptographic
code itself, only hooks to OpenSSL) and then follow these steps
(assuming you have already installed Python):
Since the wrapping code is written in C++ and uses exceptions
you may run into trouble compiling it. Be sure to use the latest
versions of your compiler (e.g. gcc 2.8.1 was reported to have
no problems; the sparcworks CC fails to handle member
constructors and gcc 2.7.2 doesn't handle exceptions). I'm using
the latest egcs
release without any difficulties. You can set the compiler by
editing the Setup file.
Some compilers fail to automatically link C++ object files with
the standard C++ lib. If you run into problems with the linker
reporting undefined symbols, edit the Setup file and
enable those libs by hand; then try to run the make
command again. If this still doesn't help, I suggest using the
latest egcs compiler
(egcs is an improved gcc compiler which solves several
problems gcc has with C++) which is what I am using.
Please report any bugs or quirks, etc. directly to me.
© 1998-2000, Copyright by Marc-André Lemburg;
All Rights Reserved. mailto: mal@lemburg.com
© 2000, Copyright by eGenix.com Software GmbH,
Langenfeld, Germany; All Rights Reserved. mailto: info@egenix.com
Note that your country's laws may restrict usage, copying
and distribution of software that provides interfaces to
data encryption algorithms.
This software is covered by the eGenix.com Public
License Agreement. The text of the license is also
included as file "LICENSE" in the package's main directory.
By downloading, copying, installing or otherwise using
the software, you agree to be bound by the terms and
conditions of the eGenix.com Public License
Agreement.
To give you a quick overview of what the copyright
conditions of the involved packages are I've copied the
notices from latest versions I could find (they may be
subject to change):
Andrew's pycrypt package (export version 1.1a2):
Distribute and use freely; there are no restrictions on
further dissemination and usage except those imposed by the
laws of your country of residence. This software is
provided "as is" without warranty of fitness for use or
suitability for any purpose, express or implied. Use at your
own risk or not at all.
Note: The package also includes software written by
third parties. See the included docs for credits and further
copyright information. AFAIK, mxCrypto replaces most (if not
all) code included in the export version that was not
written or modified by Andrew Kuchling with versions
provided by OpenSSL.
OpenSSL License:
OpenSSL uses a dual license since it inherited the code base
from Eric Young's SSLeay. Both licenses are BSD-style Open
Source licenses.
OpenSSL License:
Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
"This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
endorse or promote products derived from this software without
prior written permission. For written permission, please contact
openssl-core@openssl.org.
5. Products derived from this software may not be called "OpenSSL"
nor may "OpenSSL" appear in their names without prior written
permission of the OpenSSL Project.
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
"This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/)"
THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY 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.
====================================================================
This product includes cryptographic software written by Eric Young
(eay@cryptsoft.com). This product includes software written by Tim
Hudson (tjh@cryptsoft.com).
Original SSLeay License:
Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
All rights reserved.
This package is an SSL implementation written
by Eric Young (eay@cryptsoft.com).
The implementation was written so as to conform with Netscapes SSL.
This library is free for commercial and non-commercial use
as long as the following conditions are aheared to. The
following conditions apply to all code found in this
distribution, be it the RC4, RSA, lhash, DES, etc., code;
not just the SSL code. The SSL documentation included with
this distribution is covered by the same copyright terms
except that the holder is Tim Hudson (tjh@cryptsoft.com).
Copyright remains Eric Young's, and as such any Copyright
notices in the code are not to be removed. If this package
is used in a product, Eric Young should be given attribution
as the author of the parts of the library used. This can be
in the form of a textual message at program startup or in
documentation (online or textual) provided with the package.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of
this software must display the following acknowledgement:
"This product includes cryptographic software written by
Eric Young (eay@cryptsoft.com)" The word 'cryptographic' can
be left out if the rouines from the library being used are
not cryptographic related :-).
4. If you include any Windows specific code (or a derivative
thereof) from the apps directory (application code) you must
include an acknowledgement: "This product includes software
written by Tim Hudson (tjh@cryptsoft.com)"
THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 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.
The licence and distribution terms for any publically
available version or derivative of this code cannot be
changed. i.e. this code cannot simply be copied and put
under another distribution licence [including the GNU Public
Licence.]
Things that still need to be done:
Things that changed from 0.1.1 to 0.2.0:
Things that changed from 0.1.0 to 0.1.1:
Version 0.1.0 was the intial release.
© 1998-2000, Copyright by Marc-André Lemburg;
All Rights Reserved. mailto: mal@lemburg.com
© 2000, Copyright by eGenix.com Software GmbH;
All Rights Reserved. mailto: info@egenix.com
Package Structure
[mx.Crypto]
Doc/
[Examples]
CommandLine.py
cipher.py
[mxCrypto]
test.py
Ciphers.py
Hashes.py
Utils.py
import
.
import mx.Crypto
'
to start working.
Installation
Choosing a C++ compiler:
Getting unresolved symbols while linking mxCrypto:
Bug reports:
What I'd like to hear from you...
Copyrights, Disclaimer and Credits
History & Future