| 1 |
------------------------------------------------- |
| 2 |
cryptgps: some symmetric cryptographic algorithms |
| 3 |
------------------------------------------------- |
| 4 |
|
| 5 |
This library implements Blowfish, DES, and Triple-DES. |
| 6 |
|
| 7 |
REQUIREMENTS |
| 8 |
|
| 9 |
The Makefile in this distribution requires that the 'findlib' package |
| 10 |
is already installed. 'findlib' is a small tool that simplifies platform- |
| 11 |
independent installation. |
| 12 |
|
| 13 |
You can get 'findlib' from: |
| 14 |
http://www.ocaml-programming.de, or |
| 15 |
http://www.npc.de/ocaml/linkdb |
| 16 |
|
| 17 |
(Or you can change the Makefile, if you like.) |
| 18 |
|
| 19 |
COMPILATION & INSTALLATION |
| 20 |
|
| 21 |
Type |
| 22 |
make all |
| 23 |
to compile a bytecode archive. |
| 24 |
|
| 25 |
make opt |
| 26 |
compiles a native archive. |
| 27 |
|
| 28 |
make install |
| 29 |
installs the bytecode, and if present, the native archive. The |
| 30 |
installation directory is determined by the 'findlib' tool. |
| 31 |
|
| 32 |
make uninstall |
| 33 |
removes the installation. |
| 34 |
|
| 35 |
USAGE |
| 36 |
|
| 37 |
The three modules Crypt_blowfish, Crypt_des, and Crypt_3des have all the |
| 38 |
following inner structure. The inner module Cryptsystem contains the core |
| 39 |
cryptographic routines, you normally need only the key preparation part. |
| 40 |
The inner module Cryptmodes implements "modes" of encryption/decryption. |
| 41 |
The core algorithms only encrypt/decrypt 64-bit blocks, and a |
| 42 |
"cryptographic mode" extends this to strings of arbitrary length. |
| 43 |
|
| 44 |
let k = Crypt_blowfish.Cryptsystem.prepare "abcdefgh" |
| 45 |
|
| 46 |
The function 'prepare' converts the key given as string to an internal |
| 47 |
format. Key preparation may be a lengthy procedure. |
| 48 |
|
| 49 |
let ivec = (0,0,0,0) |
| 50 |
|
| 51 |
The initialization vector is a non-secret random number. This means that |
| 52 |
you can transmit it with the encrypted data. A good choice is the current |
| 53 |
time (0,0,0,0 is bad...). Some modes require not to use the same ivec |
| 54 |
more than once for a given key in order to get maximum security. |
| 55 |
(The ivec is a quadruple of 16 bit numbers, from MSB to LSB.) |
| 56 |
|
| 57 |
To decrypt the message you must use the same ivec as on encryption. |
| 58 |
|
| 59 |
let ivec', i', s' = Crypt_blowfish.Cryptmodes.encrypt_cfb64 k ivec 0 s |
| 60 |
|
| 61 |
Here, "Cipher-feedback mode" with 64 bits is used. s' is the encrypted |
| 62 |
version of s. ivec' and i' are needed for cascaded invocations of cfb64. |
| 63 |
|
| 64 |
Cascading means to encrypt a large string by calling the encryption |
| 65 |
function with several smaller substrings. For example, if s = s1 ^ s2, |
| 66 |
you can do: |
| 67 |
|
| 68 |
let ivec', i', s1' = |
| 69 |
Crypt_blowfish.Cryptmodes.encrypt_cfb64 k ivec 0 s1 in |
| 70 |
let ivec'', i'', s2' = |
| 71 |
Crypt_blowfish.Cryptmodes.encrypt_cfb64 k ivec' ai' s2 |
| 72 |
|
| 73 |
Then is s' = s1' ^ s2'. Cascading is useful with slow I/O devices. |
| 74 |
|
| 75 |
SPEED |
| 76 |
|
| 77 |
Blowfish is three times faster than DES which is three times faster than |
| 78 |
Triple-DES. The algorithms have been optimized (my first DES algorithm |
| 79 |
needed 170 seconds to encrypt 1 MB, the distributed version only 15 |
| 80 |
seconds - measured on a 486/133). |
| 81 |
|
| 82 |
A Comparison with ssleay has shown that my library is approximately 8 to |
| 83 |
10 times slower (ocamlopt). As Ocaml does not have 32 bit integers, all 32 |
| 84 |
bit calculations must be performed using two 16 bit numbers; this effect |
| 85 |
explains a factor of 2. The integer representation expects a '1' in the |
| 86 |
LSB of every integer word which makes Ocaml another bit slower. ssleay |
| 87 |
uses static arrays which are often a bit faster; such a feature is not |
| 88 |
available in Ocaml. |
| 89 |
|
| 90 |
LICENSE |
| 91 |
|
| 92 |
See the file "LICENSE". |
| 93 |
|
| 94 |
CHANGES |
| 95 |
|
| 96 |
0.2: Experimental support for int32 calculations: Blowfish32 |
| 97 |
|
| 98 |
0.1.2: Updated URLs in documentation. |
| 99 |
|