• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Tech Note 0003
2Minimizing Memory Usage
3Tom St Denis
4
5Introduction
6------------
7
8For the most part the library can get by with around 20KB of stack and about 32KB of heap even if you use the
9public key functions.  If all you plan on using are the hashes and ciphers than only about 1KB of stack is required
10and no heap.
11
12To save space all of the symmetric key scheduled keys are stored in a union called "symmetric_key".  This means the
13size of a symmetric_key is the size of the largest scheduled key.  By removing the ciphers you don't use from
14the build you can minimize the size of this structure.  For instance, by removing both Twofish and Blowfish the
15size reduces to 768 bytes from the 4,256 bytes it would have been (on a 32-bit platform).  Or if you remove
16Blowfish and use Twofish with TWOFISH_SMALL defined its still 768 bytes.  Even at its largest the structure is only
174KB which is normally not a problem for any platform.
18
19
20Cipher Name | Size of scheduled key (bytes) |
21------------+-------------------------------|
22Twofish     | 4,256                         |
23Blowfish    | 4,168                         |
243DES        | 768                           |
25SAFER+      | 532                           |
26Serpent     | 528                           |
27Rijndael    | 516                           |
28XTEA        | 256                           |
29RC2         | 256                           |
30DES         | 256                           |
31SAFER [#]   | 217                           |
32RC5         | 204                           |
33Twofish [*] | 193                           |
34RC6         | 176                           |
35CAST5       | 132                           |
36Noekeon     | 32                            |
37Skipjack    | 10                            |
38------------+-------------------------------/
39Memory used per cipher on a 32-bit platform.
40
41[*] For Twofish with TWOFISH_SMALL defined
42[#] For all 64-bit SAFER ciphers.
43
44Noekeon is a fairly fast cipher and uses very little memory.  Ideally in low-ram platforms all other ciphers should be
45left undefined and Noekeon should remain.  While Noekeon is generally considered a secure block cipher (it is insecure
46as a hash) CAST5 is perhaps a "runner-up" choice.  CAST5 has been around longer (it is also known as CAST-128) and is
47fairly fast as well.
48
49You can easily accomplish this via the "config.pl" script. Simply answer "n" to all of the ciphers except the one you want
50and then rebuild the library.  [or you can hand edit mycrypt_custom.h]
51
52
53