Interface : Ciphers : Hashes : Utils : Examples : Structure : Installation : Copyright : History : Home | Version 0.1.1 |
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 want 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. SSLeay 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 Eric Young's fantastic SSLeay library.
The package is called CryptoWorld 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 SSLeay 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 SSLeay 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 CryptoWorld.Ciphers import RC4 from CryptoWorld.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.
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 enc.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 installed first:
Next, download the archive
(it's located on a German server), unzip it to a clean
directory on your Python path and then follow these steps
(assuming you have already installed Python):
Choosing a C++ compiler:
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.
Bug reports:
Please report any bugs or quirks, etc. directly to me.
© 1998, Copyright by Marc-André Lemburg; All
Rights Reserved. mailto: mal@lemburg.com
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee or royalty is hereby granted, provided that the above
copyright notice appear in all copies and that both the
copyright notice and this permission notice appear in
supporting documentation or portions thereof, including
modifications, that you make.
Note that your country's laws may restrict usage, copying
and distribution of software that provides interfaces to
data encryption algorithms.
THE AUTHOR MARC-ANDRE LEMBURG DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE
LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE !
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 SSLeay.
Eric Young's SSLeay (version 0.9.0):
Copyright (C) 1997 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).
Please note that MD2, MD5 and IDEA are publically available
standards that contain sample implementations, I have
re-coded them in my own way but there is nothing special
about those implementations. The DES library is another
matter :-).
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:
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.]
The reason behind this being stated in this direct manner is
past experience in code simply being copied and the
attribution removed from it and then being distributed as
part of other packages. This implementation was a
non-trivial and unpaid effort.
Things that still need to be done:
Things that changed from 0.1.0 to 0.1.1:
Version 0.1.0 was the intial release.
Package Structure
[CryptoWorld]
Doc/
[mxCrypto]
test.py
Ciphers.py
Hashes.py
Utils.py
import
.
import CryptoWorld
'
to start working.
Installation
What I'd like to hear from you...
Copyrights, Disclaimer and Credits
History & Future