Quellcode durchsuchen

added libtomcrypt-1.03

Tom St Denis vor 20 Jahren
Ursprung
Commit
3964a6523a
100 geänderte Dateien mit 1263 neuen und 335 gelöschten Zeilen
  1. 1 1
      Doxyfile
  2. 8 0
      TODO
  3. 20 0
      build.sh
  4. 60 0
      changes
  5. 377 134
      crypt.tex
  6. 4 0
      demos/encrypt.c
  7. 4 0
      demos/hashsum.c
  8. 4 0
      demos/multi.c
  9. 4 0
      demos/small.c
  10. 16 11
      demos/test.c
  11. 4 1
      demos/timing.c
  12. 4 0
      demos/tv_gen.c
  13. BIN
      doc/crypt.pdf
  14. 6 0
      doc/footer.html
  15. 6 0
      doc/header.html
  16. 4 0
      genlist.sh
  17. 66 26
      makefile
  18. 40 18
      makefile.icc
  19. 34 17
      makefile.msvc
  20. 58 30
      makefile.shared
  21. 4 0
      mess.sh
  22. 4 0
      notes/etc/saferp_optimizer.c
  23. 4 0
      notes/etc/whirlgen.c
  24. 4 0
      notes/etc/whirltest.c
  25. 18 0
      notes/tech0005.txt
  26. 4 0
      parsenames.pl
  27. 35 0
      run.sh
  28. 5 1
      src/ciphers/aes/aes.c
  29. 4 0
      src/ciphers/aes/aes_tab.c
  30. 4 0
      src/ciphers/anubis.c
  31. 4 0
      src/ciphers/blowfish.c
  32. 4 0
      src/ciphers/cast5.c
  33. 4 0
      src/ciphers/des.c
  34. 4 0
      src/ciphers/khazad.c
  35. 4 0
      src/ciphers/noekeon.c
  36. 4 0
      src/ciphers/rc2.c
  37. 4 0
      src/ciphers/rc5.c
  38. 4 0
      src/ciphers/rc6.c
  39. 4 0
      src/ciphers/safer/safer.c
  40. 4 0
      src/ciphers/safer/safer_tab.c
  41. 4 0
      src/ciphers/safer/saferp.c
  42. 4 0
      src/ciphers/skipjack.c
  43. 5 1
      src/ciphers/twofish/twofish.c
  44. 4 0
      src/ciphers/twofish/twofish_tab.c
  45. 4 0
      src/ciphers/xtea.c
  46. 4 1
      src/encauth/ccm/ccm_memory.c
  47. 4 0
      src/encauth/ccm/ccm_test.c
  48. 4 0
      src/encauth/eax/eax_addheader.c
  49. 4 0
      src/encauth/eax/eax_decrypt.c
  50. 4 0
      src/encauth/eax/eax_decrypt_verify_memory.c
  51. 4 0
      src/encauth/eax/eax_done.c
  52. 4 0
      src/encauth/eax/eax_encrypt.c
  53. 4 0
      src/encauth/eax/eax_encrypt_authenticate_memory.c
  54. 5 3
      src/encauth/eax/eax_init.c
  55. 4 0
      src/encauth/eax/eax_test.c
  56. 8 1
      src/encauth/gcm/gcm_add_aad.c
  57. 4 0
      src/encauth/gcm/gcm_add_iv.c
  58. 4 0
      src/encauth/gcm/gcm_done.c
  59. 5 0
      src/encauth/gcm/gcm_gf_mult.c
  60. 64 7
      src/encauth/gcm/gcm_init.c
  61. 4 0
      src/encauth/gcm/gcm_memory.c
  62. 4 0
      src/encauth/gcm/gcm_process.c
  63. 4 0
      src/encauth/gcm/gcm_reset.c
  64. 4 1
      src/encauth/gcm/gcm_test.c
  65. 4 0
      src/encauth/ocb/ocb_decrypt.c
  66. 4 0
      src/encauth/ocb/ocb_decrypt_verify_memory.c
  67. 4 0
      src/encauth/ocb/ocb_done_decrypt.c
  68. 4 0
      src/encauth/ocb/ocb_done_encrypt.c
  69. 4 0
      src/encauth/ocb/ocb_encrypt.c
  70. 4 0
      src/encauth/ocb/ocb_encrypt_authenticate_memory.c
  71. 4 0
      src/encauth/ocb/ocb_init.c
  72. 4 0
      src/encauth/ocb/ocb_ntz.c
  73. 4 0
      src/encauth/ocb/ocb_shift_xor.c
  74. 4 0
      src/encauth/ocb/ocb_test.c
  75. 4 0
      src/encauth/ocb/s_ocb_done.c
  76. 4 0
      src/hashes/chc/chc.c
  77. 4 0
      src/hashes/helper/hash_file.c
  78. 4 0
      src/hashes/helper/hash_filehandle.c
  79. 4 0
      src/hashes/helper/hash_memory.c
  80. 4 0
      src/hashes/helper/hash_memory_multi.c
  81. 7 5
      src/hashes/md2.c
  82. 7 3
      src/hashes/md4.c
  83. 7 5
      src/hashes/md5.c
  84. 7 3
      src/hashes/rmd128.c
  85. 7 4
      src/hashes/rmd160.c
  86. 7 4
      src/hashes/sha1.c
  87. 7 3
      src/hashes/sha2/sha224.c
  88. 7 5
      src/hashes/sha2/sha256.c
  89. 7 5
      src/hashes/sha2/sha384.c
  90. 7 5
      src/hashes/sha2/sha512.c
  91. 7 5
      src/hashes/tiger.c
  92. 7 3
      src/hashes/whirl/whirl.c
  93. 4 0
      src/hashes/whirl/whirltab.c
  94. 4 0
      src/headers/ltc_tommath.h
  95. 6 2
      src/headers/tomcrypt.h
  96. 4 0
      src/headers/tomcrypt_argchk.h
  97. 4 0
      src/headers/tomcrypt_cfg.h
  98. 14 3
      src/headers/tomcrypt_cipher.h
  99. 46 8
      src/headers/tomcrypt_custom.h
  100. 24 19
      src/headers/tomcrypt_hash.h

+ 1 - 1
Doxyfile

@@ -23,7 +23,7 @@ PROJECT_NAME           = LibTomCrypt
 # This could be handy for archiving the generated documentation or 
 # if some version control system is used.
 
-PROJECT_NUMBER         = 1.02
+PROJECT_NUMBER         = 1.03
 
 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
 # base path where the generated documentation will be put. 

+ 8 - 0
TODO

@@ -1 +1,9 @@
+Things ideal for 1.04
+
+- ASN.1 SET and UTCtime
+- Start working towards making the bignum code plugable
+- Add OID for ciphers and PRNGs to their descriptors
+- Document the ASN.1 a bit more verbosely ;-)
+- Some ASN.1 demo programs [for now read the source code!]
+- Look into other ECC point muls and consider a "precomp" interface 
 

+ 20 - 0
build.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+echo "$1 ($2, $3)..."
+make clean 1>/dev/null 2>/dev/null
+echo -n "building..."
+CFLAGS="$2 $CFLAGS" make -f $3 test tv_gen 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && exit 1)
+echo -n "testing..."
+if [ -a test ] && [ -f test ] && [ -x test ]; then
+   ((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed" && cat test_err.txt && exit 1)
+   if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then
+      for f in *_tv.txt; do if (diff $f notes/$f) then true; else (echo "tv_gen $f failed" && rm -f testok.txt && exit 1); fi; done
+   fi
+fi
+if [ -a testok.txt ] && [ -f testok.txt ]; then
+   exit 0
+fi
+exit 1
+
+# $Source: /cvs/libtom/libtomcrypt/build.sh,v $   
+# $Revision: 1.4 $   
+# $Date: 2005/05/05 14:49:27 $ 

+ 60 - 0
changes

@@ -1,3 +1,58 @@
+June 9th, 2005
+v1.03
+      -- Users may want to note that on a P4/GCC3.4 platform "-fno-regmove" greatly accelerates the ciphers/hashes.
+      --------------------------------------------------------------------------------------------------------------
+      -- Made it install the testing library in the icc/static makefiles
+      -- Found bug in ccm_memory.c which would fail to compile when LTC_CLEAN_STACK was enabled
+      -- Simon Johnson proposed I do a fully automated test suite.  Hence "testme.sh" was born
+      -- Added LTC_NO_TEST which forces test vectors off (regardless of what tomcrypt_custom.h has)
+      -- Added LTC_NO_TABLES which disables large tables (where possible, regardless of what tomcrypt_custom.h has)
+      -- New test script found a bug in twofish.c when TABLES was disabled.  Yeah testing!
+      -- Added a LTC_FAST specific test to the testing software.
+      -- Updated test driver to actually halt on errors and just print them out (useful for say... automated testing...)
+      -- Added bounds checking to Pelican MAC
+      -- Added BIT and OCTET STRING to the ASN.1 side of things.  
+      -- Pekka Riikonen pointed out that my ctr_start() function should accept the counter mode. 
+      -- Cleaned up warnings in testprof
+      -- Removed redundant mu and point mapping in ecc_verify_hash() so it should be a bit faster now
+      -- Pekka pointed out that the AES key structure was using 32 bytes more than it ought to.
+      -- Added quick defines to remove entire classes of algorithms.  This makes it easier if you want to build with just 
+         one algorithm (say AES or SHA-256).  Defines are LTC_NO_CIPHERS, LTC_NO_MODES, LTC_NO_HASHES, LTC_NO_MACS,
+         LTC_NO_PRNGS, LTC_NO_PK, LTC_NO_PKCS
+      -- As part of the move for ECC to X9.62 I've changed the signature algorithm to EC DSA.  No API changes.
+      -- Pekka helped me clean up the PKCS #1 v2.1 [OAEP/PSS] code
+      -- Wrote new DER SEQUENCE coder/decoder
+      -- RSA, DSA and ECDSA now use the DER SEQUENCE code (saves a lot of code!)
+      -- DSA output is now a DER SEQUENCE (so not compatible with previous releases).  
+      -- Added Technote #5 which shows how to build LTC on an AMD64 to have a variety of algorithms in only ~80KB of code.
+      -- Changed temp variable in LOAD/STORE macros to "ulong32" for 32-bit ops.  Makes it safer on Big endian platforms
+      -- Added INSTALL_GROUP and INSTALL_USER which you can specify on the build to override the default USER/GROUP the library 
+         is to be installed as
+      -- Removed "testprof" from the default build.  
+      -- Added IA5, NULL and Object Identifier to the list of ASN.1 DER supported types
+      -- The "no_oops" target (part of zipup) now scans for non-cvs files.  This helps prevent temp/scratch files from appearing in releases ;-)
+      -- Added DERs for missing hashes, but just the OID not the PKCS #1 v1.5 additions. 
+      -- Removed PKCS #1 v1.5 from the tree since it's taking up space and you ought to use v2.1 anyways
+      -- Kevin Kenny pointed out a few stray // comments
+      -- INTEGER code properly supports negatives and zero padding [Pekka!]
+      -- Sorted asn1/der/ directory ... less of a mess now ;-)
+      -- Added PRINTABLE STRING type
+      -- Removed ECC-160 as it wasn't a standard curve
+      -- Made ecc_shared_secret() ANSI X9.63 compliant
+      -- Changed "printf" to "fprintf(stderr, " in the testbench... ;-)
+      -- Optimized the GCM table creation.  On 1KB packets [with key switching] the new GCM is 12.7x faster than before.
+      -- Changed OID representation for hashes to be just a list of unsigned longs (so you can compare against them nicely after decoding a sequence)
+      -- ECC code now uses Montgomery reduction ... it's even faster [ECC-256 make key down from 37.4M to 4.6M cycles on an Athlon64]
+      -- Added SHORT_INTEGER so users can easily store DER encoded INTEGER types without using the bignum math library
+      -- Fixed OMAC code so that with LTC_FAST it doesn't require that LTC_FAST_TYPE divides 16 [it has to divide the block size instead]
+      -- ECC key export is now a simple [and documented] SEQUENCE, the "encrypt_key" also uses a new SEQUENCE format.
+      -- Thanks goes to the following testers
+            Michael Brown             - Solaris 10/uSPARCII
+            Richard Outerbridge       - MacOS
+            Martin Carpenter          - Solaris 8/uSPARCII [Thanks for cleaning up the scripts]
+            Greg Rose                 -  ... SunOS 5.8/SPARC [... what's with the SPARCS?]
+            Matt Johnston             - MacOS X  [Thanks for pointing out GCC 4 problems with -Os]
+
 April 19th, 2005
 v1.02
       -- Added LTC_TEST support to gcm_test()
@@ -1243,3 +1298,8 @@ v0.02  -- Changed RC5 to only allow 12 to 24 rounds
        -- Added more to the manual.
 
 v0.01  -- We will call this the first version.
+
+/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
+/* $Revision: 1.92 $ */
+/* $Date: 2005/06/09 01:06:59 $ */
+

+ 377 - 134
crypt.tex

@@ -47,7 +47,7 @@
 \def\gap{\vspace{0.5ex}}
 \makeindex
 \begin{document}
-\title{LibTomCrypt \\ Version 1.02}
+\title{LibTomCrypt \\ Version 1.03}
 \author{Tom St Denis \\
 \\
 [email protected] \\
@@ -57,7 +57,7 @@ http://libtomcrypt.org
 This text and source code library are both hereby placed in the public domain.  This book has been 
 formatted for A4 paper using the \LaTeX{} {\em book} macro package.
 
-\vspace{10cm}
+\vspace{15cm}
 
 \begin{flushright}Open Source.  Open Academia.  Open Minds.
 
@@ -771,13 +771,19 @@ other modes.
 \index{OFB Mode} \index{CFB Mode}
 The library provides simple support routines for handling CBC, CTR, CFB, OFB and ECB encoded messages.  Assuming the mode 
 you want is XXX there is a structure called ``symmetric\_XXX'' that will contain the information required to
-use that mode.  They have identical setup routines (except ECB mode for obvious reasons):
+use that mode.  They have identical setup routines (except CTR and ECB mode):
 \index{ecb\_start()} \index{cfb\_start()} \index{cbc\_start()} \index{ofb\_start()} \index{ctr\_start()}
 \begin{verbatim}
 int XXX_start(int cipher, const unsigned char *IV, 
               const unsigned char *key, int keylen, 
               int num_rounds, symmetric_XXX *XXX);
 
+int ctr_start(               int   cipher,
+              const unsigned char *IV,
+              const unsigned char *key,       int keylen,
+                             int  num_rounds, int ctr_mode,
+                   symmetric_CTR *ctr);
+
 int ecb_start(int cipher, const unsigned char *key, int keylen, 
               int num_rounds, symmetric_ECB *ecb);
 \end{verbatim}
@@ -789,7 +795,12 @@ of the cipher you choose.  It is important that the IV  be random for each uniqu
 parameters ``key'', ``keylen'' and ``num\_rounds'' are the same as in the XXX\_setup() function call.  The final parameter 
 is a pointer to the structure you want to hold the information for the mode of operation.
 
-Both routines return {\bf CRYPT\_OK} if the cipher initialized correctly, otherwise they return an error code.  
+
+In the case of CTR mode there is an additional parameter ``ctr\_mode'' which specifies the mode that the counter is to be used in.
+If \textbf{CTR\_COUNTER\_LITTLE\_ENDIAN} was specified then the counter will be treated as a little endian value.  Otherwise, if 
+\textbf{CTR\_COUNTER\_BIG\_ENDIAN} was specified the counter will be treated as a big endian value.
+
+The routines return {\bf CRYPT\_OK} if the cipher initialized correctly, otherwise they return an error code.  
 
 \subsection{Encryption and Decryption}
 To actually encrypt or decrypt the following routines are provided:
@@ -867,6 +878,7 @@ int main(void)
                            key, /* the secret key */
                             16, /* length of secret key (16 bytes, 128 bits) */
                              0, /* 0 == default # of rounds */
+     CTR_COUNTER_LITTLE_ENDIAN, /* Little endian counter */
                          &ctr)  /* where to store initialized CTR state */
       ) != CRYPT_OK) {
       printf("ctr_start error: %s\n", error_to_string(err));
@@ -1349,7 +1361,7 @@ int send_packet(const unsigned char *pt,  unsigned long ptlen,
    }
 
    /* process the plaintext */
-   if ((err = gcm_add_process(gcm, pt, ptlen, pt, GCM_ENCRYPT)) != CRYPT_OK) {
+   if ((err = gcm_process(gcm, pt, ptlen, pt, GCM_ENCRYPT)) != CRYPT_OK) {
       return err;
    }
 
@@ -1359,6 +1371,8 @@ int send_packet(const unsigned char *pt,  unsigned long ptlen,
       return err;
    }
 
+   /* ... send a header describing the lengths ... */
+
    /* depending on the protocol and how IV is generated you may have to send it too... */
    send(socket, iv, ivlen, 0);
 
@@ -2452,8 +2466,8 @@ int main(void)
 
 \section{Introduction}
 RSA wrote the PKCS \#1 specifications which detail RSA Public Key Cryptography.  In the specifications are
-padding algorithms for encryption and signatures.  The standard includes ``v1.5'' and ``v2.0'' algorithms.
-To simplify matters a little the v2.0 encryption and signature padding algorithms are called OAEP and PSS 
+padding algorithms for encryption and signatures.  The standard includes the ``v2.1'' algorithms.
+To simplify matters a little the v2.1 encryption and signature padding algorithms are called OAEP and PSS 
 respectively.  
 
 \section{PKCS \#1 Encryption}
@@ -2509,33 +2523,6 @@ If the function succeeds it decodes the OAEP encoded message into ``out'' of len
 $1$ in ``res''.  If the packet is invalid it stores $0$ in ``res'' and if the function fails for another reason
 it returns an error code.  
 
-\subsection{PKCS \#1 v1.5 Encoding}
-
-\index{pkcs\_1\_v15\_es\_encode()}
-\begin{verbatim}
-int pkcs_1_v15_es_encode(const unsigned char *msg,    unsigned long msglen,
-                               unsigned long  modulus_bitlen, 
-                               prng_state    *prng,   int           prng_idx,
-                               unsigned char *out,    unsigned long *outlen);
-\end{verbatim}
-
-This will PKCS v1.5 encode the data in ``msg'' of length ``msglen''.  Pass the length (in bits) of your
-RSA modulus in ``modulus\_bitlen''.  The encoded data will be stored in ``out'' of length ``outlen''.
-
-\subsection{PKCS \#1 v1.5 Decoding}
-\index{pkcs\_1\_v15\_es\_decode()}
-\begin{verbatim}
-int pkcs_1_v15_es_decode(const unsigned char *msg,  unsigned long msglen,
-                               unsigned long modulus_bitlen,
-                               unsigned char *out,  unsigned long outlen,
-                               int           *res);
-\end{verbatim}
-
-This will PKCS v1.5 decode the message in ``msg'' of length ``msglen''.  It will store the output in ``out''. Note
-that the length of the output ``outlen'' is a constant.  This decoder cannot determine the original message 
-length.  If the data in ``msg'' is a valid packet then a $1$ is stored in ``res'', otherwise a $0$ is 
-stored.
-
 \section{PKCS \#1 Digital Signatures}
 
 \subsection{PSS Encoding}
@@ -2577,34 +2564,6 @@ it is set to zero.  The rest of the parameters are as in the PSS encode call.
 
 It's important to use the same ``saltlen'' and hash for both encoding and decoding as otherwise the procedure will not work.
 
-\subsection{PKCS \#1 v1.5 Encoding}
-
-\index{pkcs\_1\_v15\_sa\_encode()}
-\begin{verbatim}
-int pkcs_1_v15_sa_encode(const unsigned char *msghash,  unsigned long msghashlen,
-                               int            hash_idx, unsigned long modulus_bitlen,
-                               unsigned char *out,      unsigned long *outlen);
-\end{verbatim}
-
-This will PKCS \#1 v1.5 signature encode the message hash ``msghash''  of length ``msghashlen''.  You have
-to tell this routine which hash produced the message hash in ``hash\_idx''.  The encoded hash is stored
-in ``out'' of length ``outlen''.
-
-\subsection{PKCS \#1 v1.5 Decoding}
-
-\index{pkcs\_1\_v15\_sa\_decode()}
-\begin{verbatim}
-int pkcs_1_v15_sa_decode(const unsigned char *msghash, unsigned long msghashlen,
-                         const unsigned char *sig,     unsigned long siglen,
-                               int           hash_idx, unsigned long modulus_bitlen, 
-                               int          *res);
-\end{verbatim}
-
-This will PKCS \#1 v1.5 signature decode the data in ``sig'' of length ``siglen'' and compare the extracted
-hash against ``msghash'' of length ``msghashlen''.  You have to tell this routine which hash produced the
-message digest in ``hash\_idx''.  If the packet is valid and the hashes match ``res'' is set to $1$.  Otherwise,
-it is set to $0$.
-
 \section{RSA Operations}
 \subsection{Background}
 
@@ -2698,15 +2657,14 @@ to pkcs\_1\_oaep\_encode().
 int rsa_decrypt_key(const unsigned char *in,  unsigned long inlen,
                           unsigned char *out, unsigned long *outlen, 
                     const unsigned char *lparam, unsigned long lparamlen,
-                          prng_state    *prng,   int           prng_idx,
-                          int            hash_idx, int *res,
+                          int            hash_idx, int *stat,
                           rsa_key       *key);
 \end{verbatim}
 This function will RSA decrypt ``in'' of length ``inlen'' then OAEP depad the resulting data and store it in
 ``out'' of length ``outlen''.  The ``lparam'' and ``lparamlen'' are the same parameters you would pass
 to pkcs\_1\_oaep\_decode().
 
-If the RSA decrypted data isn't a valid OAEP packet then ``res'' is set to $0$.  Otherwise, it is set to $1$.
+If the RSA decrypted data isn't a valid OAEP packet then ``stat'' is set to $0$.  Otherwise, it is set to $1$.
 
 \subsection{RSA Hash Signatures}
 Similar to RSA key encryption RSA is also used to ``digitally sign'' message digests (hashes).  To facilitate this
@@ -2729,7 +2687,6 @@ the output is stored in ``out'' of length ``outlen''.
 \begin{verbatim}
 int rsa_verify_hash(const unsigned char *sig,      unsigned long siglen,
                     const unsigned char *msghash,  unsigned long msghashlen,
-                          prng_state    *prng,     int           prng_idx,
                           int            hash_idx, unsigned long saltlen,
                           int           *stat,     rsa_key      *key);
 \end{verbatim}
@@ -2799,8 +2756,6 @@ int main(void)
                               &l2, /* plaintext length */
                         "TestApp", /* lparam for this program */
                                 7, /* lparam is 7 bytes long */
-                             NULL, /* PRNG state */
-                         prng_idx, /* prng idx */
                          hash_idx, /* hash idx */
                              &res, /* validity of data */
                              &key) /* our RSA key */ 
@@ -3060,6 +3015,34 @@ provided are very close to $p$ that is $\vert \vert \phi(\beta) \vert \vert \app
 range in order from $\approx 2^{192}$ points to $\approx 2^{521}$.  According to the source document any key size greater
 than or equal to 256-bits is sufficient for long term security.  
 
+\section{Key Format}
+LibTomCrypt uses it's own format for ECC public and private keys.  While ANSI X9.62 partially specifies key formats (it covers public keys) it does it in a less
+than ideally simple manner.  In the case of LibTomCrypt it is meant \textbf{solely} for NIST $GF(p)$ curves.  The format of the keys is as follows:
+
+\begin{small}
+\begin{verbatim}
+ECCPublicKey ::= SEQUENCE {
+    flags       BIT STRING(2), -- public/private flag (always zero), 
+                               -- compressed point
+    keySize     INTEGER,       -- Curve size (in bits) divided by eight 
+                               -- and rounded down, e.g. 521 => 65
+    pubkey.x    INTEGER,       -- The X co-ordinate of the public key point
+}
+
+ECCPrivateKey ::= SEQUENCE {
+    flags       BIT STRING(2), -- public/private flag (always one), 
+                               -- compressed point
+    keySize     INTEGER,       -- Curve size (in bits) divided by eight 
+                               -- and rounded down, e.g. 521 => 65
+    pubkey.x    INTEGER,       -- The X co-ordinate of the public key point
+    secret.k    INTEGER,       -- The secret key scalar
+}
+\end{verbatim}
+\end{small}
+
+The first flags bit denotes whether the key is public (zero) or private (one).  The compressed point bit is equal to zero if $(x^3 - 3x + b)^{(p+1)/4} \mbox{ mod }p$ is 
+congruent to the keys $y$ co-ordinate.  The bit is one if the $y$ co-ordinate is the negative of the computed square root.
+
 \section{Core Functions}
 
 Like the DH routines there is a key structure ``ecc\_key'' used by the functions.  There is a function to make a key:
@@ -3129,11 +3112,23 @@ int ecc_decrypt_key(const unsigned char *in,  unsigned long  inlen,
                           ecc_key *key);
 \end{verbatim}
 
-Where ``in'' is an input symmetric key of no more than 32 bytes.  Essentially these routines created a random public key
+Where ``in'' is an input symmetric key of no more than 64 bytes.  Essentially these routines created a random public key
 and find the hash of the shared secret.  The message digest is than XOR'ed against the symmetric key.  All of the required
 data is placed in ``out'' by ``ecc\_encrypt\_key()''.   The hash chosen must produce a message digest at least as large
 as the symmetric key you are trying to share.
 
+\subsection{Encrypt Packet Format}
+
+The packet format for the encrypted keys is the following ASN.1 SEQUENCE:
+
+\begin{verbatim}
+ECCEncrypt ::= SEQUENCE {
+   hashID        OBJECT IDENTIFIER, -- OID of hash used
+   pubkey        OCTET STRING     , -- Encapsulated ECCPublicKey (see above)
+   skey          OCTET STRING       -- xor of plaintext and "hash of shared secret"
+}
+\end{verbatim}
+
 There are also functions to sign and verify the hash of a message.
 \index{ecc\_sign\_hash()} \index{ecc\_verify\_hash()}
 \begin{verbatim}
@@ -3150,6 +3145,8 @@ The ``ecc\_sign\_hash'' function signs the message hash in ``in'' of length ``in
 The ``ecc\_verify\_hash'' function verifies the ECC signature in ``sig'' against the hash in ``hash''.  It sets ``stat''
 to non-zero if the signature passes or zero if it fails.
 
+\subsection{Signature Format}
+The signature code is an implementation of X9.62 EC-DSA and the output is comformant for GF(p) curves.
 
 \section{ECC Keysizes}
 With ECC if you try and sign a hash that is bigger than your ECC key you can run into problems.  The math will still work
@@ -3170,6 +3167,38 @@ would require at least 256 bytes where as the DSA signature would require only a
 The API for the DSA is essentially the same as the other PK algorithms.  Except in the case of DSA no encryption or
 decryption routines are provided.  
 
+\section{Key Format}
+Since no useful public standard for DSA key storage was presented to me during the course of this development I made my own ASN.1 SEQUENCE which I document
+now so that others can interoperate with this library.
+
+\begin{verbatim}
+DSAPublicKey ::= SEQUENCE {
+    publicFlags    BIT STRING(1), -- must be 0
+    g              INTEGER      , -- base generator, check that g^q mod p == 1
+                                  -- and that 1 < g < p - 1
+    p              INTEGER      , -- prime modulus 
+    q              INTEGER      , -- order of sub-group (must be prime)
+    y              INTEGER      , -- public key, specifically, g^x mod p, 
+                                  -- check that y^q mod p == 1
+                                  -- and that 1 < y < p - 1
+}
+
+DSAPrivateKey ::= SEQUENCE {
+    publicFlags    BIT STRING(1), -- must be 1
+    g              INTEGER      , -- base generator, check that g^q mod p == 1
+                                  -- and that 1 < g < p - 1
+    p              INTEGER      , -- prime modulus 
+    q              INTEGER      , -- order of sub-group (must be prime)
+    y              INTEGER      , -- public key, specifically, g^x mod p, 
+                                  -- check that y^q mod p == 1
+                                  -- and that 1 < y < p - 1
+    x              INTEGER        -- private key
+}
+\end{verbatim}
+
+The leading BIT STRING has a single bit in it which is zero for public keys and one for private keys.  This makes the structure uniquely decodable and easy
+to work with.
+
 \section{Key Generation}
 To make a DSA key you must call the following function
 \begin{verbatim}
@@ -3291,79 +3320,289 @@ This will import the DSA key from the buffer ``in'' of length ``inlen'' to the `
 will automatically free all of the heap allocated in the process (you don't have to call dsa\_free()).  
 
 \chapter{Standards Support}
-\section{DER Support}
-DER or ``Distinguished Encoding Rules'' is a subset of the ASN.1 encoding rules that is fully deterministic and
-ideal for cryptography.  In particular ASN.1 specifies an INTEGER type for storing arbitrary sized integers.  DER
-further limits the ASN.1 specifications to a deterministic encoding.
+\section{ASN.1 Formats}
+LibTomCrypt supports a variety of ASN.1 data types encoded with the Distinguished Encoding Rules (DER) suitable for various cryptographic protocols.  The data types
+are all provided with three basic functions with \textit{similar} prototypes.  One function has been dedicated to calculate the length in octets of a given
+format and two functions have been dedicated to encoding and decoding the format.  
 
-\subsection{Storing INTEGER types}
-\index{der\_encode\_integer()}
-\begin{alltt}
-int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen);
-\end{alltt}
+On top of the basic data types are the SEQUENCE and\footnote{Planned for LTC 1.04} SET data types which are collections of other ASN.1 types.  They are provided 
+in the same manner as the other data types except they use list of objects known as the \textbf{ltc\_asn1\_list} structure.  It is defined as 
 
-This will store the integer in ``num'' to the output buffer ``out'' of length ``outlen''.  It only stores
-non--negative numbers.  It stores the number of octets used back in ``outlen''.
+\index{ltc\_asn1\_list structure}
+\begin{verbatim}
+typedef struct {
+   int           type;
+   void         *data;
+   unsigned long size;
+} ltc_asn1_list;
+\end{verbatim}
 
-\subsection{Reading INTEGER types}
-\index{der\_decode\_integer()}
-\begin{alltt}
-int der_decode_integer(const unsigned char *in, unsigned long *inlen, mp_int *num);
-\end{alltt}
-This will decode the DER encoded INTEGER in ``in'' of length ``inlen'' and store the resulting integer
-in ``num''.  It will store the bytes read in ``inlen'' which is handy if you have to parse multiple
-data items out of a binary packet.
+The ``type'' field is one of the following ASN.1 field definitions.  The ``data'' pointer is a void pointer to the data to be encoded (or the destination) and the 
+``size'' field is specific to what you are encoding (e.g. number of bits in the BIT STRING data type).  To help build the lists in an orderly fashion the macro
+``LTC\_SET\_ASN1(list, index, Type, Data, Size)'' has been provided.
+
+It will assign to the ``index''th position in the ``list'' the tripplet (Type, Data, Size).  An example usage would be:
+
+\begin{small}
+\begin{verbatim}
+...
+ltc_asn1_list   sequence[3];
+unsigned long   three=3;
+
+LTC_SET_ASN1(sequence, 0, LTC_ASN1_IA5_STRING,    "hello", 5);
+LTC_SET_ASN1(sequence, 1, LTC_ASN1_SHORT_INTEGER, &three,  1);
+LTC_SET_ASN1(sequence, 2, LTC_ASN1_NULL,           NULL,   0);
+\end{verbatim}
+\end{small}
+
+The macro is relatively safe with respect to modifying variables, for instance the following code is equivalent.
+
+\begin{small}
+\begin{verbatim}
+...
+ltc_asn1_list   sequence[3];
+unsigned long   three=3;
+int             x=0;
+LTC_SET_ASN1(sequence, x++, LTC_ASN1_IA5_STRING,    "hello", 5);
+LTC_SET_ASN1(sequence, x++, LTC_ASN1_SHORT_INTEGER, &three,  1);
+LTC_SET_ASN1(sequence, x++, LTC_ASN1_NULL,           NULL,   0);
+\end{verbatim}
+\end{small}
+
+\begin{figure}[here]
+\begin{center}
+\begin{small}
+\begin{tabular}{|l|l|}
+\hline \textbf{Definition}           & \textbf{ASN.1 Type} \\
+\hline LTC\_ASN1\_EOL                & End of a ASN.1 list structure. \\
+\hline LTC\_ASN1\_INTEGER            & INTEGER (uses mp\_int) \\
+\hline LTC\_ASN1\_SHORT\_INTEGER     & INTEGER (32--bit using unsigned long) \\
+\hline LTC\_ASN1\_BIT\_STRING        & BIT STRING (one bit per char) \\
+\hline LTC\_ASN1\_OCTET\_STRING      & OCTET STRING (one octet per char) \\
+\hline LTC\_ASN1\_NULL               & NULL \\
+\hline LTC\_ASN1\_OBJECT\_IDENTIFIER & OBJECT IDENTIFIER (words are in unsigned long) \\
+\hline LTC\_ASN1\_IA5\_STRING        & IA5 STRING (one octet per char) \\
+\hline LTC\_ASN1\_PRINTABLE\_STRING  & PRINTABLE STIRNG (one octet per char) \\
+\hline LTC\_ASN1\_SEQUENCE           & SEQUENCE OF \\
+\hline
+\end{tabular}
+\caption{List of ASN.1 Supported Types}
+\end{small}
+\end{center}
+\end{figure}
+
+\subsection{SEQUENCE Type}
+The SEQUENCE data type is a collection of other ASN.1 data types encapsulated with a small header which is a useful way of sending multiple data types in one packet.
+
+\subsubsection{SEUQNECE Encoding}
+To encode a sequence a \textbf{ltc\_asn1\_list} array must be initialized with the members of the sequence and their respective pointers.  The encoding is performed
+with the following function.
+
+\index{der\_encode\_sequence()}
+\begin{verbatim}
+int der_encode_sequence(ltc_asn1_list *list, unsigned long inlen,
+                        unsigned char *out,  unsigned long *outlen);
+\end{verbatim}
+This encodes a sequence of items pointed to by ``list'' where the list has ``inlen'' items in it.  The SEQUENCE will be encoded to ``out'' and of length ``outlen''.  The
+function will terminate when it reads all the items out of the list (upto ``inlen'') or it encounters an item in the list with a type of \textbf{LTC\_ASN1\_EOL}.
 
-\subsection{INTEGER length}
+The ``data'' pointer in the list would be the same pointer you would pass to the respective ASN.1 encoder (e.g. der\_encode\_bit\_string()) and it is simply passed on
+verbatim to the dependent encoder.  The list can contain other SEQUENCE or SET types which enables you to have nested SEQUENCE and SET definitions.  In these cases
+the ``data'' pointer is simply a pointer to another \textbf{ltc\_asn1\_list}.
+
+\subsubsection{SEQUENCE Decoding}
+
+\index{der\_decode\_sequence()}
+
+Decoding a SEQUENCE is similar to encoding.  You set up an array of \textbf{ltc\_asn1\_list} where in this case the ``size'' member is the maximum size 
+(in certain cases).  For types such as IA5 STRING, BIT STRING, OCTET STRING (etc) the ``size'' field is updated after successful decoding to reflect how many
+units of the respective type has been loaded.  
+
+\begin{verbatim}
+int der_decode_sequence(const unsigned char *in,   unsigned long  inlen,
+                              ltc_asn1_list *list, unsigned long  outlen);
+\end{verbatim}
+
+This will decode upto ``outlen'' items from the input buffer ``in'' of length ``inlen'' octets.  The function will stop (gracefully) when it runs out of items to decode.
+It will fail (for among other reasons) when it runs out of input bytes to read, a data type is invalid or a heap failure occured.
+
+For the following types the ``size'' field will be updated to reflect the number of units read of the given type.
+\begin{enumerate}
+   \item BIT STRING
+   \item OCTET STRING
+   \item OBJECT IDENTIFIER
+   \item IA5 STRING
+   \item PRINTABLE STRING
+\end{enumerate}
+
+\subsubsection{SEQUENCE Length}
+
+The length of a SEQUENCE can be determined with the following function.
+
+\index{der\_length\_sequence()}
+\begin{verbatim}
+int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
+                        unsigned long *outlen);
+\end{verbatim}
+
+This will get the encoding size for the given ``list'' of length ``inlen'' and store it in ``outlen''.  
+
+\subsubsection{SEQUENCE Multiple Argument Lists}
+
+For small or simple sequences an encoding or decoding can be performed with one of the following two functions.
+
+\index{der\_encode\_sequence\_multi()}
+\index{der\_decode\_sequence\_multi()}
+
+\begin{verbatim}
+int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
+int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
+\end{verbatim}
+
+These either encode or decode (respectively) a SEQUENCE data type where the items in the sequence are specified after the length parameter.
+
+The list of items are specified as a triple of the form ``(type, size, data)''  where ``type'' is an \textbf{int}, ``size'' is a \textbf{unsigned long}
+and ``data'' is \textbf{void} pointer.  The list of items must be terminated with an item with the type \textbf{LTC\_ASN1\_EOL}.
+
+It's ideal that you cast the ``size'' values to unsigned long to ensure that the proper data type is passed to the function.  Constants such as ``1'' without
+a cast or prototype are of type \textbf{int} by default.  Appending \textit{UL} or prepending \textit{(unsigned long)} is enough to cast it to the correct type.
+
+\subsubsection{ASN.1 INTEGER}
+
+To encode or decode INTEGER data types use the following functions.
+
+\index{der\_encode\_integer()}
+\index{der\_decode\_integer()}
 \index{der\_length\_integer()}
-\begin{alltt}
+\begin{verbatim}
+int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen);
+int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int *num);
 int der_length_integer(mp_int *num, unsigned long *len);
-\end{alltt}
-This will determine the length of the DER encoding of the integer ``num'' and store it in ``len''.
+\end{verbatim}
 
-\subsection{Multiple INTEGER types}
-To simplify the DER encoding/decoding there are two functions two handle multple types at once.
+These will encode or decode a signed INTEGER data type using the ``mp\_int'' data type to store the large INTEGER.  To encode smaller values without allocating
+an mp\_int to store the value the ``short'' INTEGER functions were made available.
 
-\index{der\_put\_multi\_integer()}
-\index{der\_get\_multi\_integer()}
-\begin{alltt}
-int der_put_multi_integer(unsigned char *dst, unsigned long *outlen, mp_int *num, ...);
-int der_get_multi_integer(const unsigned char *src, unsigned long *inlen,  mp_int *num, ...);
-\end{alltt}
+\index{der\_encode\_short\_integer()}
+\index{der\_decode\_short\_integer()}
+\index{der\_length\_short\_integer()}
+\begin{verbatim}
+int der_encode_short_integer(unsigned long  num, 
+                             unsigned char *out, unsigned long *outlen);
+
+int der_decode_short_integer(const unsigned char *in,  unsigned long inlen, 
+                                   unsigned long *num);
+
+int der_length_short_integer(unsigned long num, unsigned long *outlen);
+\end{verbatim}
+
+These will encode or decode an unsigned \textbf{unsigned long} type (only reads upto 32--bits).  For values in the range $0 \dots 2^{32} - 1$ the integer 
+and short integer functions can encode and decode each others outputs.  
 
-These will handle multiple encodings/decodings at once.  They work like their single operand counterparts
-except they handle a \textbf{NULL} terminated list of operands.
+\subsubsection{ASN.1 BIT STRING}
 
+\index{der\_encode\_bit\_string()}
+\index{der\_decode\_bit\_string()}
+\index{der\_length\_bit\_string()}
 \begin{verbatim}
-#include <tomcrypt.h>
-int main(void)
-{
-   mp_int        a, b, c, d;
-   unsigned char buffer[1000];
-   unsigned long len;
-   int           err;
+int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
 
-   /* init a,b,c,d with some values ... */
+int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
 
-   /* ok we want to store them now... */
-   len = sizeof(buffer);
-   if ((err = der_put_multi_integer(buffer, &len, 
-                                    &a, &b, &c, &d, NULL)) != CRYPT_OK) {
-      // error
-   }
-   printf("I stored %lu bytes in buf\n", len);
+int der_length_bit_string(unsigned long nbits, unsigned long *outlen);
+\end{verbatim}
 
-   /* ok say we want to get them back for fun */
-   /* len set previously...otherwise set it to the size of the packet */
-   if ((err = der_get_multi_integer(buffer, &len,
-                                    &a, &b, &c, &d, NULL)) != CRYPT_OK) {
-      // error
-   }
-   printf("I read %lu bytes from buf\n", len);
-}
+These will encode or decode a BIT STRING data type.  The bits are passed in (or read out) using one \textbf{char} per bit.  A non--zero value will be interpretted
+as a one bit and a zero value a zero bit.
+
+\subsubsection{ASN.1 OCTET STRING}
+
+\index{der\_encode\_octet\_string()}
+\index{der\_decode\_octet\_string()}
+\index{der\_length\_octet\_string()}
+\begin{verbatim}
+int der_encode_octet_string(const unsigned char *in, unsigned long inlen,
+                                  unsigned char *out, unsigned long *outlen);
+
+int der_decode_octet_string(const unsigned char *in, unsigned long inlen,
+                                  unsigned char *out, unsigned long *outlen);
+
+int der_length_octet_string(unsigned long noctets, unsigned long *outlen);
+\end{verbatim}
+
+These will encode or decode an OCTET STRING data type.  The octets are stored using one \textbf{char} each.  
+
+\subsubsection{ASN.1 OBJECT IDENTIFIER}
+
+\index{der\_encode\_object\_identifier()}
+\index{der\_decode\_object\_identifier()}
+\index{der\_length\_object\_identifier()}
+\begin{verbatim}
+int der_encode_object_identifier(unsigned long *words, unsigned long  nwords,
+                                 unsigned char *out,   unsigned long *outlen);
+
+int der_decode_object_identifier(const unsigned char *in,    unsigned long  inlen,
+                                       unsigned long *words, unsigned long *outlen);
+
+int der_length_object_identifier(unsigned long *words, unsigned long nwords, 
+                                 unsigned long *outlen);
 \end{verbatim}
+
+These will encode or decode an OBJECT IDENTIFIER object.  The words of the OID are stored in individual \textbf{unsigned long} elements and must be in the range
+$0 \ldots 2^{32} - 1$.  
+
+\subsubsection{ASN.1 IA5 STRING}
+
+\index{der\_encode\_ia5\_string()}
+\index{der\_decode\_ia5\_string()}
+\index{der\_length\_ia5\_string()}
+\begin{verbatim}
+int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+
+int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+
+int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, 
+                                unsigned long *outlen);
+\end{verbatim}
+
+These will encode or decode an IA5 STRING.  The characters are read or stored in individual \textbf{char} elements.  This functions performs internal character
+to numerical conversions based on the conventions of the compiler being used.  For instance, on an x86\_32 machine 'A' == 65 but the same may not be true on 
+say a SPARC machine.  Internally these functions have a table of literal characters and their numerical ASCII values.  This provides a stable conversion provided
+that the build platform honours the runtime platforms character conventions.
+
+If you're worried try building the test suite and running it.  It has hard coded test vectors to ensure it is operating properly. 
+
+\subsubsection{ASN.1 PRINTABLE STRING}
+
+\index{der\_encode\_printable\_string()}
+\index{der\_decode\_printable\_string()}
+\index{der\_length\_printable\_string()}
+\begin{verbatim}
+int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+
+int der_decode_printable_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+
+int der_length_printable_string(const unsigned char *octets, unsigned long noctets, 
+                                unsigned long *outlen);
+\end{verbatim}
+
+These will encode or decode an PRINTABLE STRING.  The characters are read or stored in individual \textbf{char} elements.  This functions performs internal character
+to numerical conversions based on the conventions of the compiler being used.  For instance, on an x86\_32 machine 'A' == 65 but the same may not be true on 
+say a SPARC machine.  Internally these functions have a table of literal characters and their numerical ASCII values.  This provides a stable conversion provided
+that the build platform honours the runtime platforms character conventions.
+
+If you're worried try building the test suite and running it.  It has hard coded test vectors to ensure it is operating properly. 
+
+
 \section{Password Based Cryptography}
 \subsection{PKCS \#5}
+\index{PKCS \#5}
 In order to securely handle user passwords for the purposes of creating session keys and chaining IVs the PKCS \#5 was drafted.   PKCS \#5
 is made up of two algorithms, Algorithm One and Algorithm Two.  Algorithm One is the older fairly limited algorithm which has been implemented
 for completeness.  Algorithm Two is a bit more modern and more flexible to work with.
@@ -3436,7 +3675,6 @@ int main(void)
 \}
 \end{alltt}
 
-
 \chapter{Miscellaneous}
 \section{Base64 Encoding and Decoding}
 The library provides functions to encode and decode a RFC1521 base64 coding scheme.  This means that it can decode what it 
@@ -4030,8 +4268,8 @@ To initialize a cipher (for ECB mode) the function setup() was provided.  It acc
 can specify the number of rounds they want through ``num\_rounds'' where $num\_rounds = 0$ means use the default.  The destination of a scheduled key is stored
 in ``skey''.
 
-This is where things get tricky.  Currently there is no provision to allocate memory during initialization since there is no ``cipher done'' function.  So you have
-to either use an existing member of the symmetric\_key union or alias your own structure over top of it provided symmetric\_key is not smaller.
+Inside the ``symmetric\_key'' union there is a ``void *data'' which you can use to allocate data if you need a data structure that doesn't fit with the existing
+ones provided.  Just make sure in your ``done()'' function that you free the allocated memory.
 
 \subsection{Single block ECB}
 To process a single block in ECB mode the ecb\_encrypt() and ecb\_decrypt() functions were provided.  The plaintext and ciphertext buffers are allowed to overlap so you 
@@ -4062,7 +4300,8 @@ updated by the function before returning.
 \subsubsection{Accelerated CTR}
 This function is meant for accelerated CTR encryption.  It is accessible through the accel\_ctr\_encrypt pointer.
 The ``blocks'' value is the number of complete blocks to process.  The ``IV'' is the CTR counter vector.  It is an input upon calling this function and must be
-updated by the function before returning.  The ``mode'' value indicates whether the counter is big ($mode = 1$) or little ($mode = 0$) endian.
+updated by the function before returning.  The ``mode'' value indicates whether the counter is big (mode = CTR\_COUNTER\_BIG\_ENDIAN) or 
+little (mode = CTR\_COUNTER\_LITTLE\_ENDIAN) endian.
 
 This function (and the way it's called) differs from the other two since ctr\_encrypt() allows any size input plaintext.  The accelerator will only be
 called if the following conditions are met.
@@ -4101,10 +4340,10 @@ struct ltc_hash_descriptor {
     unsigned long hashsize;
     /** Input block size in octets */
     unsigned long blocksize;
-    /** ASN.1 DER identifier */
-    unsigned char DER[64];
+    /** ASN.1 OID */
+    unsigned long OID[16];
     /** Length of DER encoding */
-    unsigned long DERlen;
+    unsigned long OIDlen;
     /** Init a hash state
       @param hash   The hash to initialize
       @return CRYPT_OK if successful
@@ -4144,8 +4383,8 @@ The ``hashsize'' variable indicates the length of the output in octets.
 The `blocksize'' variable indicates the length of input (in octets) that the hash processes in a given
 invokation.
 
-\subsection{DER Identifier}
-This is the DER identifier (including the SEQUENCE header).  This is used solely for PKCS \#1 style signatures.  
+\subsection{OID Identifier}
+This is the universal ASN.1 Object Identifier for the hash.
 
 \subsection{Initialization}
 The init function initializes the hash and prepares it to process message bytes.
@@ -4251,3 +4490,7 @@ but should at least maintain the same level of state entropy.
 \input{crypt.ind}
 
 \end{document}
+
+% $Source: /cvs/libtom/libtomcrypt/crypt.tex,v $   
+% $Revision: 1.32 $   
+% $Date: 2005/06/09 00:36:17 $ 

+ 4 - 0
demos/encrypt.c

@@ -235,3 +235,7 @@ int main(int argc, char *argv[])
    }
    return 0;
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
demos/hashsum.c

@@ -113,3 +113,7 @@ void register_algs(void)
 #endif
 
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
demos/multi.c

@@ -104,3 +104,7 @@ int main(void)
    return EXIT_SUCCESS;
 }
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
demos/small.c

@@ -8,3 +8,7 @@ int main(void)
    register_hash(&sha256_desc);
    return 0;
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 16 - 11
demos/test.c

@@ -2,18 +2,23 @@
 
 int main(void)
 {
+   int x;
    reg_algs();
    printf("build == \n%s\n", crypt_build_settings);
-   printf("\ncipher_test..."); fflush(stdout); printf(cipher_hash_test() ? "failed" : "passed");
-   printf("\nmodes_test..."); fflush(stdout); printf(modes_test() ? "failed" : "passed");
-   printf("\nmac_test..."); fflush(stdout); printf(mac_test() ? "failed" : "passed");
-   printf("\npkcs_1_test..."); fflush(stdout); printf(pkcs_1_test() ? "failed" : "passed");
-   printf("\nstore_test..."); fflush(stdout); printf(store_test() ? "failed" : "passed");
-   printf("\nrsa_test..."); fflush(stdout); printf(rsa_test() ? "failed" : "passed");
-   printf("\necc_test..."); fflush(stdout); printf(ecc_tests() ? "failed" : "passed");
-   printf("\ndsa_test..."); fflush(stdout); printf(dsa_test() ? "failed" : "passed");
-   printf("\ndh_test..."); fflush(stdout); printf(dh_tests() ? "failed" : "passed");
-   printf("\nder_test..."); fflush(stdout); printf(der_tests() ? "failed" : "passed");
-
+   printf("\nstore_test...."); fflush(stdout); x = store_test();       printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\ncipher_test..."); fflush(stdout); x = cipher_hash_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\nmodes_test...."); fflush(stdout); x = modes_test();       printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\nmac_test......"); fflush(stdout); x = mac_test();         printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\nder_test......"); fflush(stdout); x = der_tests();        printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\npkcs_1_test..."); fflush(stdout); x = pkcs_1_test();      printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\nrsa_test......"); fflush(stdout); x = rsa_test();         printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\necc_test......"); fflush(stdout); x = ecc_tests();        printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\ndsa_test......"); fflush(stdout); x = dsa_test();         printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\ndh_test......."); fflush(stdout); x = dh_tests();         printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE);
+   printf("\n");
    return EXIT_SUCCESS;
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 1
demos/timing.c

@@ -17,7 +17,10 @@ time_sqr();
 time_rsa();
 time_ecc();
 time_dh();
-
 return EXIT_SUCCESS;
 
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
demos/tv_gen.c

@@ -664,3 +664,7 @@ int main(void)
       
     
    
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

BIN
doc/crypt.pdf


+ 6 - 0
doc/footer.html

@@ -2,3 +2,9 @@
 Code by <a href="http://www.libtomcrypt.org/">Tom</a><br>
 Docs using <img src="doxygen.png" alt="doxygen" align="middle" border=0>
 <a href="http://jlcooke.ca/tom/hidden_image.png">
+
+<!--
+/* $Source: /cvs/libtom/libtomcrypt/doc/footer.html,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/07 10:09:20 $ */
+-->

+ 6 - 0
doc/header.html

@@ -4,3 +4,9 @@
 <link href="doxygen.css" rel="stylesheet" type="text/css">
 </head><body>
 <!-- Generated by Doxygen 1.3.8 -->
+
+<!--
+/* $Source: /cvs/libtom/libtomcrypt/doc/header.html,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/07 10:09:20 $ */
+-->

+ 4 - 0
genlist.sh

@@ -4,3 +4,7 @@ export a=`echo -n "src/ciphers/aes/aes_enc.o *(MPIOBJECT) " ; find . -type f | s
 perl ./parsenames.pl OBJECTS "$a"
 export a=`find . -type f | grep [.]/src | grep [.]h | sed -e 'se\./ee' | xargs`
 perl ./parsenames.pl HEADERS "$a"
+
+# $Source: /cvs/libtom/libtomcrypt/genlist.sh,v $   
+# $Revision: 1.3 $   
+# $Date: 2005/05/05 14:49:27 $ 

+ 66 - 26
makefile

@@ -4,7 +4,7 @@
 # Modified by Clay Culver
 
 # The version
-VERSION=1.02
+VERSION=1.03
 
 # Compiler and Linker Names
 #CC=gcc
@@ -21,6 +21,8 @@ CFLAGS += -c -I./testprof/ -I./src/headers/ -Wall -Wsign-compare -W -Wshadow -Wn
 #CFLAGS += -Wsystem-headers -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wmissing-prototypes \
 #		  -Wmissing-declarations -Wpointer-arith 
 
+ifndef IGNORE_SPEED
+
 # optimize for SPEED
 CFLAGS += -O3 -funroll-loops
 
@@ -30,6 +32,8 @@ CFLAGS += -fomit-frame-pointer
 # optimize for SIZE
 #CFLAGS += -Os -DLTC_SMALL_CODE
 
+endif
+
 # older GCCs can't handle the "rotate with immediate" ROLc/RORc/etc macros
 # define this to help
 #CFLAGS += -DLTC_NO_ROLC
@@ -58,13 +62,24 @@ INCPATH=/usr/include
 DATAPATH=/usr/share/doc/libtomcrypt/pdf
 
 #Who do we install as?
+ifdef INSTALL_USER
+USER=$(INSTALL_USER)
+else
 USER=root
+endif
+
+ifdef INSTALL_GROUP
+GROUP=$(INSTALL_GROUP)
+else
 GROUP=wheel
+endif
 
 #List of objects to compile.
 
 #Leave MPI built-in or force developer to link against libtommath?
+ifndef IGNORE_MPI
 MPIOBJECT=src/misc/mpi/mpi.o
+endif
 
 OBJECTS=src/ciphers/aes/aes_enc.o $(MPIOBJECT) src/ciphers/aes/aes.o src/ciphers/anubis.o \
 src/ciphers/blowfish.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/khazad.o src/ciphers/noekeon.o \
@@ -115,29 +130,40 @@ src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o \
 src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
 src/modes/ecb/ecb_start.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
 src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
-src/modes/ofb/ofb_start.o src/pk/asn1/der/der_decode_integer.o src/pk/asn1/der/der_encode_integer.o \
-src/pk/asn1/der/der_get_multi_integer.o src/pk/asn1/der/der_length_integer.o \
-src/pk/asn1/der/der_put_multi_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
-src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
+src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
+src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
+src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
+src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
+src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
+src/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
+src/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
+src/pk/asn1/der/object_identifier/der_length_object_identifier.o \
+src/pk/asn1/der/octet/der_decode_octet_string.o src/pk/asn1/der/octet/der_encode_octet_string.o \
+src/pk/asn1/der/octet/der_length_octet_string.o \
+src/pk/asn1/der/printable_string/der_decode_printable_string.o \
+src/pk/asn1/der/printable_string/der_encode_printable_string.o \
+src/pk/asn1/der/printable_string/der_length_printable_string.o \
+src/pk/asn1/der/sequence/der_decode_sequence.o src/pk/asn1/der/sequence/der_decode_sequence_multi.o \
+src/pk/asn1/der/sequence/der_encode_sequence.o src/pk/asn1/der/sequence/der_encode_sequence_multi.o \
+src/pk/asn1/der/sequence/der_length_sequence.o \
+src/pk/asn1/der/short_integer/der_decode_short_integer.o \
+src/pk/asn1/der/short_integer/der_encode_short_integer.o \
+src/pk/asn1/der/short_integer/der_length_short_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o \
+src/pk/dsa/dsa_free.o src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
 src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/packet_store_header.o \
 src/pk/packet_valid_header.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mgf1.o \
 src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
-src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v15_es_decode.o \
-src/pk/pkcs1/pkcs_1_v15_es_encode.o src/pk/pkcs1/pkcs_1_v15_sa_decode.o \
-src/pk/pkcs1/pkcs_1_v15_sa_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
-src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
-src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_v15_decrypt_key.o \
-src/pk/rsa/rsa_v15_encrypt_key.o src/pk/rsa/rsa_v15_sign_hash.o src/pk/rsa/rsa_v15_verify_hash.o \
+src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/rsa/rsa_decrypt_key.o \
+src/pk/rsa/rsa_encrypt_key.o src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o \
+src/pk/rsa/rsa_import.o src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o \
 src/pk/rsa/rsa_verify_hash.o src/prngs/fortuna.o src/prngs/rc4.o src/prngs/rng_get_bytes.o \
 src/prngs/rng_make_prng.o src/prngs/sober128.o src/prngs/sprng.o src/prngs/yarrow.o 
 
-HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h \
-src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h \
-src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
-src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h \
-src/headers/tommath_class.h src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h \
-src/headers/tomcrypt_misc.h src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h \
-src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
+HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h src/headers/tomcrypt_mac.h \
+src/headers/tomcrypt_macros.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
+src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h src/headers/tommath_class.h \
+src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h src/headers/tomcrypt_misc.h \
+src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
 
 TESTOBJECTS=demos/test.o
 HASHOBJECTS=demos/hashsum.o
@@ -171,7 +197,7 @@ src/hashes/sha2/sha512.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha384.c
 src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
 
 #This rule makes the libtomcrypt library.
-library: $(LIBTEST) $(LIBNAME)
+library: $(LIBNAME)
 
 $(LIBTEST): 
 	cd testprof ; CFLAGS="$(CFLAGS)" make 
@@ -193,15 +219,15 @@ small: library $(SMALLOBJECTS)
 	$(CC) $(SMALLOBJECTS) $(LIBNAME) -o $(SMALL) $(WARN)
 	
 tv_gen: library $(TVS)
-	$(CC) $(TVS) $(LIBNAME) $(EXTRALIBS) -o $(TV)
+	$(CC) $(TVS) $(LIBNAME) -o $(TV)
 
 multi: library $(MULTIS)
 	$(CC) $(MULTIS) $(LIBNAME) -o $(MULTI)
 
-timing: library $(TIMINGS)
-	$(CC) $(TIMINGS) $(LIBTEST) $(LIBNAME) -o $(TIMING)
+timing: library $(LIBTEST) $(TIMINGS)
+	$(CC) $(TIMINGS) $(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TIMING)
 
-test: library $(TESTS)
+test: library $(LIBTEST) $(TESTS)
 	$(CC) $(TESTS) $(LIBTEST) $(LIBNAME) -o $(TEST)
 
 
@@ -216,11 +242,17 @@ install: library docs
 	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
 	install -g $(GROUP) -o $(USER) doc/crypt.pdf $(DESTDIR)$(DATAPATH)
 
-install_lib: library
+install_test: $(LIBTEST)
 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
 	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
-	install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
-	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
+	install -g $(GROUP) -o $(USER) $(LIBTEST) $(DESTDIR)$(LIBPATH)
+
+profile:
+	CFLAGS="$(CFLAGS) -fprofile-generate" make timing EXTRALIBS=-lgcov
+	./timing
+	rm -f timing `find . -type f | grep [.][ao] | xargs`
+	CFLAGS="$(CFLAGS) -fprofile-use" make timing EXTRALIBS=-lgcov
+
 
 #This rule cleans the source tree of all compiled code, not including the pdf
 #documentation.
@@ -242,6 +274,7 @@ clean:
 	rm -f $(TV) $(PROF) $(SMALL) $(CRYPT) $(HASHSUM) $(MULTI) $(TIMING) $(TEST)
 	rm -rf doc/doxygen
 	rm -f doc/*.pdf
+	rm -f *.txt
 
 #build the doxy files (requires Doxygen, tetex and patience)
 doxy:
@@ -274,6 +307,8 @@ docdvi: crypt.tex
 #zipup the project (take that!)
 no_oops: clean
 	cd .. ; cvs commit 
+	echo Scanning for scratch/dirty files
+	find . -type f | grep -v CVS | xargs -n 1 bash mess.sh
 
 zipup: no_oops docs
 	cd .. ; rm -rf crypt* libtomcrypt-$(VERSION) ; mkdir libtomcrypt-$(VERSION) ; \
@@ -283,3 +318,8 @@ zipup: no_oops docs
 	zip -9r crypt-$(VERSION).zip libtomcrypt-$(VERSION) ; \
 	gpg -b -a crypt-$(VERSION).tar.bz2 ; gpg -b -a crypt-$(VERSION).zip ; \
 	mv -fv crypt* ~ ; rm -rf libtomcrypt-$(VERSION)
+
+
+# $Source: /cvs/libtom/libtomcrypt/makefile,v $ 
+# $Revision: 1.67 $ 
+# $Date: 2005/06/09 00:39:26 $ 

+ 40 - 18
makefile.icc

@@ -22,7 +22,7 @@ CC=icc
 #ARFLAGS=r
 
 # Compilation flags. Note the += does not write over the user's CFLAGS!
-CFLAGS += -c -I./src/headers/ -DINTEL_CC
+CFLAGS += -c -Isrc/headers/ -Itestprof/ -DINTEL_CC
 
 #The default rule for make builds the libtomcrypt library.
 default:library
@@ -41,7 +41,13 @@ default:library
 #	B - Blend of P4 and PM [mobile]
 #
 # Default to just generic max opts
+ifdef LTC_SMALL
+CFLAGS += -O2 -xP -ip
+endif
+
+ifndef IGNORE_SPEED
 CFLAGS += -O3 -xP -ip 
+endif
 
 # want to see stuff?
 #CFLAGS += -opt_report
@@ -122,29 +128,40 @@ src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o \
 src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
 src/modes/ecb/ecb_start.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
 src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
-src/modes/ofb/ofb_start.o src/pk/asn1/der/der_decode_integer.o src/pk/asn1/der/der_encode_integer.o \
-src/pk/asn1/der/der_get_multi_integer.o src/pk/asn1/der/der_length_integer.o \
-src/pk/asn1/der/der_put_multi_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
-src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
+src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
+src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
+src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
+src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
+src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
+src/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
+src/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
+src/pk/asn1/der/object_identifier/der_length_object_identifier.o \
+src/pk/asn1/der/octet/der_decode_octet_string.o src/pk/asn1/der/octet/der_encode_octet_string.o \
+src/pk/asn1/der/octet/der_length_octet_string.o \
+src/pk/asn1/der/printable_string/der_decode_printable_string.o \
+src/pk/asn1/der/printable_string/der_encode_printable_string.o \
+src/pk/asn1/der/printable_string/der_length_printable_string.o \
+src/pk/asn1/der/sequence/der_decode_sequence.o src/pk/asn1/der/sequence/der_decode_sequence_multi.o \
+src/pk/asn1/der/sequence/der_encode_sequence.o src/pk/asn1/der/sequence/der_encode_sequence_multi.o \
+src/pk/asn1/der/sequence/der_length_sequence.o \
+src/pk/asn1/der/short_integer/der_decode_short_integer.o \
+src/pk/asn1/der/short_integer/der_encode_short_integer.o \
+src/pk/asn1/der/short_integer/der_length_short_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o \
+src/pk/dsa/dsa_free.o src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
 src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/packet_store_header.o \
 src/pk/packet_valid_header.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mgf1.o \
 src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
-src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v15_es_decode.o \
-src/pk/pkcs1/pkcs_1_v15_es_encode.o src/pk/pkcs1/pkcs_1_v15_sa_decode.o \
-src/pk/pkcs1/pkcs_1_v15_sa_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
-src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
-src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_v15_decrypt_key.o \
-src/pk/rsa/rsa_v15_encrypt_key.o src/pk/rsa/rsa_v15_sign_hash.o src/pk/rsa/rsa_v15_verify_hash.o \
+src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/rsa/rsa_decrypt_key.o \
+src/pk/rsa/rsa_encrypt_key.o src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o \
+src/pk/rsa/rsa_import.o src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o \
 src/pk/rsa/rsa_verify_hash.o src/prngs/fortuna.o src/prngs/rc4.o src/prngs/rng_get_bytes.o \
 src/prngs/rng_make_prng.o src/prngs/sober128.o src/prngs/sprng.o src/prngs/yarrow.o 
 
-HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h \
-src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h \
-src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
-src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h \
-src/headers/tommath_class.h src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h \
-src/headers/tomcrypt_misc.h src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h \
-src/headers/tomcrypt_prng.h  testprof/tomcrypt_test.h
+HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h src/headers/tomcrypt_mac.h \
+src/headers/tomcrypt_macros.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
+src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h src/headers/tommath_class.h \
+src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h src/headers/tomcrypt_misc.h \
+src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
 
 #ciphers come in two flavours... enc+dec and enc 
 aes_enc.o: aes.c aes_tab.c
@@ -214,4 +231,9 @@ install: library
 	install -d -g root -o root $(DESTDIR)$(LIBPATH)
 	install -d -g root -o root $(DESTDIR)$(INCPATH)
 	install -g root -o root $(LIBNAME) $(DESTDIR)$(LIBPATH)
+	install -g root -o root $(LIBTEST) $(DESTDIR)$(LIBPATH)
 	install -g root -o root $(HEADERS) $(DESTDIR)$(INCPATH)
+
+# $Source: /cvs/libtom/libtomcrypt/makefile.icc,v $   
+# $Revision: 1.32 $   
+# $Date: 2005/05/23 03:12:44 $ 

+ 34 - 17
makefile.msvc

@@ -57,29 +57,42 @@ src/modes/ctr/ctr_getiv.obj src/modes/ctr/ctr_setiv.obj src/modes/ctr/ctr_start.
 src/modes/ecb/ecb_decrypt.obj src/modes/ecb/ecb_done.obj src/modes/ecb/ecb_encrypt.obj \
 src/modes/ecb/ecb_start.obj src/modes/ofb/ofb_decrypt.obj src/modes/ofb/ofb_done.obj \
 src/modes/ofb/ofb_encrypt.obj src/modes/ofb/ofb_getiv.obj src/modes/ofb/ofb_setiv.obj \
-src/modes/ofb/ofb_start.obj src/pk/asn1/der/der_decode_integer.obj src/pk/asn1/der/der_encode_integer.obj \
-src/pk/asn1/der/der_get_multi_integer.obj src/pk/asn1/der/der_length_integer.obj \
-src/pk/asn1/der/der_put_multi_integer.obj src/pk/dh/dh.obj src/pk/dsa/dsa_export.obj src/pk/dsa/dsa_free.obj \
-src/pk/dsa/dsa_import.obj src/pk/dsa/dsa_make_key.obj src/pk/dsa/dsa_sign_hash.obj \
+src/modes/ofb/ofb_start.obj src/pk/asn1/der/bit/der_decode_bit_string.obj \
+src/pk/asn1/der/bit/der_encode_bit_string.obj src/pk/asn1/der/bit/der_length_bit_string.obj \
+src/pk/asn1/der/ia5/der_decode_ia5_string.obj src/pk/asn1/der/ia5/der_encode_ia5_string.obj \
+src/pk/asn1/der/ia5/der_length_ia5_string.obj src/pk/asn1/der/integer/der_decode_integer.obj \
+src/pk/asn1/der/integer/der_encode_integer.obj src/pk/asn1/der/integer/der_length_integer.obj \
+src/pk/asn1/der/object_identifier/der_decode_object_identifier.obj \
+src/pk/asn1/der/object_identifier/der_encode_object_identifier.obj \
+src/pk/asn1/der/object_identifier/der_length_object_identifier.obj \
+src/pk/asn1/der/octet/der_decode_octet_string.obj src/pk/asn1/der/octet/der_encode_octet_string.obj \
+src/pk/asn1/der/octet/der_length_octet_string.obj \
+src/pk/asn1/der/printable_string/der_decode_printable_string.obj \
+src/pk/asn1/der/printable_string/der_encode_printable_string.obj \
+src/pk/asn1/der/printable_string/der_length_printable_string.obj \
+src/pk/asn1/der/sequence/der_decode_sequence.obj src/pk/asn1/der/sequence/der_decode_sequence_multi.obj \
+src/pk/asn1/der/sequence/der_encode_sequence.obj src/pk/asn1/der/sequence/der_encode_sequence_multi.obj \
+src/pk/asn1/der/sequence/der_length_sequence.obj \
+src/pk/asn1/der/short_integer/der_decode_short_integer.obj \
+src/pk/asn1/der/short_integer/der_encode_short_integer.obj \
+src/pk/asn1/der/short_integer/der_length_short_integer.obj src/pk/dh/dh.obj src/pk/dsa/dsa_export.obj \
+src/pk/dsa/dsa_free.obj src/pk/dsa/dsa_import.obj src/pk/dsa/dsa_make_key.obj src/pk/dsa/dsa_sign_hash.obj \
 src/pk/dsa/dsa_verify_hash.obj src/pk/dsa/dsa_verify_key.obj src/pk/ecc/ecc.obj src/pk/packet_store_header.obj \
 src/pk/packet_valid_header.obj src/pk/pkcs1/pkcs_1_i2osp.obj src/pk/pkcs1/pkcs_1_mgf1.obj \
 src/pk/pkcs1/pkcs_1_oaep_decode.obj src/pk/pkcs1/pkcs_1_oaep_encode.obj src/pk/pkcs1/pkcs_1_os2ip.obj \
-src/pk/pkcs1/pkcs_1_pss_decode.obj src/pk/pkcs1/pkcs_1_pss_encode.obj src/pk/pkcs1/pkcs_1_v15_es_decode.obj \
-src/pk/pkcs1/pkcs_1_v15_es_encode.obj src/pk/pkcs1/pkcs_1_v15_sa_decode.obj \
-src/pk/pkcs1/pkcs_1_v15_sa_encode.obj src/pk/rsa/rsa_decrypt_key.obj src/pk/rsa/rsa_encrypt_key.obj \
-src/pk/rsa/rsa_export.obj src/pk/rsa/rsa_exptmod.obj src/pk/rsa/rsa_free.obj src/pk/rsa/rsa_import.obj \
-src/pk/rsa/rsa_make_key.obj src/pk/rsa/rsa_sign_hash.obj src/pk/rsa/rsa_v15_decrypt_key.obj \
-src/pk/rsa/rsa_v15_encrypt_key.obj src/pk/rsa/rsa_v15_sign_hash.obj src/pk/rsa/rsa_v15_verify_hash.obj \
+src/pk/pkcs1/pkcs_1_pss_decode.obj src/pk/pkcs1/pkcs_1_pss_encode.obj src/pk/rsa/rsa_decrypt_key.obj \
+src/pk/rsa/rsa_encrypt_key.obj src/pk/rsa/rsa_export.obj src/pk/rsa/rsa_exptmod.obj src/pk/rsa/rsa_free.obj \
+src/pk/rsa/rsa_import.obj src/pk/rsa/rsa_make_key.obj src/pk/rsa/rsa_sign_hash.obj \
 src/pk/rsa/rsa_verify_hash.obj src/prngs/fortuna.obj src/prngs/rc4.obj src/prngs/rng_get_bytes.obj \
 src/prngs/rng_make_prng.obj src/prngs/sober128.obj src/prngs/sprng.obj src/prngs/yarrow.obj 
 
-HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h \
-src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h \
-src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
-src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h \
-src/headers/tommath_class.h src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h \
-src/headers/tomcrypt_misc.h src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h \
-src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
+HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h src/headers/tomcrypt_mac.h \
+src/headers/tomcrypt_macros.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
+src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h src/headers/tommath_class.h \
+src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h src/headers/tomcrypt_misc.h \
+src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
+
+
 
 #ciphers come in two flavours... enc+dec and enc
 src/ciphers/aes/aes_enc.obj: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
@@ -102,3 +115,7 @@ test: demos/test.c library
 
 timing: demos/timing.c library
 	cl $(CFLAGS) demos/timing.c testprof/tomcrypt_prof.lib tomcrypt.lib advapi32.lib
+
+# $Source: /cvs/libtom/libtomcrypt/makefile.msvc,v $   
+# $Revision: 1.14 $   
+# $Date: 2005/06/08 23:37:40 $ 

+ 58 - 30
makefile.shared

@@ -6,7 +6,7 @@
 # Tom St Denis
 
 # The version
-VERSION=0:102
+VERSION=0:103
 
 # Compiler and Linker Names
 CC=libtool --mode=compile gcc
@@ -18,14 +18,18 @@ CFLAGS += -c -I./src/headers/ -Wall -Wsign-compare -W -Wshadow
 #CFLAGS += -Wsystem-headers -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wmissing-prototypes \
 #			 -Wmissing-declarations -Wpointer-arith 
 
+ifndef IGNORE_SPEED
+
 # optimize for SPEED
-CFLAGS += -O3 -funroll-all-loops
+CFLAGS += -O3 -funroll-loops
 
 # add -fomit-frame-pointer.  hinders debugging!
 CFLAGS += -fomit-frame-pointer
 
 # optimize for SIZE
-#CFLAGS += -Os
+#CFLAGS += -Os -DLTC_SMALL_CODE
+
+endif
 
 # compile for DEBUGING (required for ccmalloc checking!!!)
 #CFLAGS += -g3
@@ -45,7 +49,6 @@ TV=tv_gen
 TEST=test
 TIMING=timing
 
-
 #LIBPATH-The directory for libtomcrypt to be installed to.
 #INCPATH-The directory to install the header files for libtomcrypt.
 #DATAPATH-The directory to install the pdf docs.
@@ -55,16 +58,27 @@ INCPATH=/usr/include
 DATAPATH=/usr/share/doc/libtomcrypt/pdf
 
 #Who do we install as?
+ifdef INSTALL_USER
+USER=$(INSTALL_USER)
+else
 USER=root
-GROUP=wheel
+endif
+
+ifdef INSTALL_GROUP
+GROUP=$(INSTALL_GROUP)   
+else
+GROUP=wheel  
+endif
 
 #List of objects to compile.
 
 #Leave MPI built-in or force developer to link against libtommath?
+ifndef IGNORE_MPI
 MPIOBJECT=src/misc/mpi/mpi.o
-
+else 
 #If you don't want mpi.o then add this
-#MPISHARED=$(LIBPATH)/libtommath.la
+MPISHARED=$(LIBPATH)/libtommath.la
+endif
 
 OBJECTS=src/ciphers/aes/aes_enc.o $(MPIOBJECT) src/ciphers/aes/aes.o src/ciphers/anubis.o \
 src/ciphers/blowfish.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/khazad.o src/ciphers/noekeon.o \
@@ -115,29 +129,40 @@ src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o \
 src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \
 src/modes/ecb/ecb_start.o src/modes/ofb/ofb_decrypt.o src/modes/ofb/ofb_done.o \
 src/modes/ofb/ofb_encrypt.o src/modes/ofb/ofb_getiv.o src/modes/ofb/ofb_setiv.o \
-src/modes/ofb/ofb_start.o src/pk/asn1/der/der_decode_integer.o src/pk/asn1/der/der_encode_integer.o \
-src/pk/asn1/der/der_get_multi_integer.o src/pk/asn1/der/der_length_integer.o \
-src/pk/asn1/der/der_put_multi_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
-src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
+src/modes/ofb/ofb_start.o src/pk/asn1/der/bit/der_decode_bit_string.o \
+src/pk/asn1/der/bit/der_encode_bit_string.o src/pk/asn1/der/bit/der_length_bit_string.o \
+src/pk/asn1/der/ia5/der_decode_ia5_string.o src/pk/asn1/der/ia5/der_encode_ia5_string.o \
+src/pk/asn1/der/ia5/der_length_ia5_string.o src/pk/asn1/der/integer/der_decode_integer.o \
+src/pk/asn1/der/integer/der_encode_integer.o src/pk/asn1/der/integer/der_length_integer.o \
+src/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
+src/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
+src/pk/asn1/der/object_identifier/der_length_object_identifier.o \
+src/pk/asn1/der/octet/der_decode_octet_string.o src/pk/asn1/der/octet/der_encode_octet_string.o \
+src/pk/asn1/der/octet/der_length_octet_string.o \
+src/pk/asn1/der/printable_string/der_decode_printable_string.o \
+src/pk/asn1/der/printable_string/der_encode_printable_string.o \
+src/pk/asn1/der/printable_string/der_length_printable_string.o \
+src/pk/asn1/der/sequence/der_decode_sequence.o src/pk/asn1/der/sequence/der_decode_sequence_multi.o \
+src/pk/asn1/der/sequence/der_encode_sequence.o src/pk/asn1/der/sequence/der_encode_sequence_multi.o \
+src/pk/asn1/der/sequence/der_length_sequence.o \
+src/pk/asn1/der/short_integer/der_decode_short_integer.o \
+src/pk/asn1/der/short_integer/der_encode_short_integer.o \
+src/pk/asn1/der/short_integer/der_length_short_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o \
+src/pk/dsa/dsa_free.o src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
 src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/packet_store_header.o \
 src/pk/packet_valid_header.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mgf1.o \
 src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
-src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v15_es_decode.o \
-src/pk/pkcs1/pkcs_1_v15_es_encode.o src/pk/pkcs1/pkcs_1_v15_sa_decode.o \
-src/pk/pkcs1/pkcs_1_v15_sa_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
-src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
-src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_v15_decrypt_key.o \
-src/pk/rsa/rsa_v15_encrypt_key.o src/pk/rsa/rsa_v15_sign_hash.o src/pk/rsa/rsa_v15_verify_hash.o \
+src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/rsa/rsa_decrypt_key.o \
+src/pk/rsa/rsa_encrypt_key.o src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o \
+src/pk/rsa/rsa_import.o src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o \
 src/pk/rsa/rsa_verify_hash.o src/prngs/fortuna.o src/prngs/rc4.o src/prngs/rng_get_bytes.o \
 src/prngs/rng_make_prng.o src/prngs/sober128.o src/prngs/sprng.o src/prngs/yarrow.o 
 
-HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h \
-src/headers/tomcrypt_mac.h src/headers/tomcrypt_macros.h \
-src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
-src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h \
-src/headers/tommath_class.h src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h \
-src/headers/tomcrypt_misc.h src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h \
-src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
+HEADERS=src/headers/tommath_superclass.h src/headers/tomcrypt_cfg.h src/headers/tomcrypt_mac.h \
+src/headers/tomcrypt_macros.h src/headers/tomcrypt_custom.h src/headers/tomcrypt_argchk.h \
+src/headers/tomcrypt_cipher.h src/headers/tomcrypt_pk.h src/headers/tommath_class.h \
+src/headers/ltc_tommath.h src/headers/tomcrypt_hash.h src/headers/tomcrypt_misc.h \
+src/headers/tomcrypt.h src/headers/tomcrypt_pkcs.h src/headers/tomcrypt_prng.h testprof/tomcrypt_test.h
 
 TESTOBJECTS=demos/test.o
 HASHOBJECTS=demos/hashsum.o
@@ -164,7 +189,7 @@ src/hashes/sha2/sha512.o: src/hashes/sha2/sha512.c src/hashes/sha2/sha384.c
 src/hashes/sha2/sha256.o: src/hashes/sha2/sha256.c src/hashes/sha2/sha224.c
 
 #This rule makes the libtomcrypt library.
-library: $(LIBTEST) $(LIBNAME)
+library: $(LIBNAME)
 
 $(LIBTEST):
 	cd testprof ; CFLAGS="$(CFLAGS)" GROUP=$(GROUP) USER=$(USER) VERSION=$(VERSION) LIBPATH=$(LIBPATH) LIBNAME=$(LIBTEST) make -f makefile.shared
@@ -180,19 +205,22 @@ $(LIBNAME): $(OBJECTS)
 #This rule makes the hash program included with libtomcrypt
 hashsum: library
 	gcc $(CFLAGS) demos/hashsum.c -o hashsum.o
-	gcc -o hashsum hashsum.o -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+	gcc -o hashsum hashsum.o -ltomcrypt $(MPISHARED)
 
 #makes the crypt program
 crypt: library 
 	gcc $(CFLAGS) demos/encrypt.c -o encrypt.o
-	gcc -o crypt encrypt.o -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+	gcc -o crypt encrypt.o -ltomcrypt $(MPISHARED)
 
 tv_gen: library $(TVS)
-	gcc -o tv_gen $(TVS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+	gcc -o tv_gen $(TVS) -ltomcrypt $(MPISHARED)
 
-test: library $(TESTS)
+test: library $(LIBTEST) $(TESTS)
 	gcc -o $(TEST) $(TESTS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
 
-timing: library $(TIMINGS)
+timing: library $(LIBTEST) $(TIMINGS)
 	gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
 
+# $Source: /cvs/libtom/libtomcrypt/makefile.shared,v $   
+# $Revision: 1.16 $   
+# $Date: 2005/06/08 23:37:40 $ 

+ 4 - 0
mess.sh

@@ -0,0 +1,4 @@
+#!/bin/bash
+if cvs log $1 >/dev/null 2>/dev/null; then exit 0; else echo "$1 shouldn't be here" ; exit 1; fi
+
+

+ 4 - 0
notes/etc/saferp_optimizer.c

@@ -171,3 +171,7 @@ printf("   }\n}\n\n");
    return 0;
 }
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
notes/etc/whirlgen.c

@@ -89,3 +89,7 @@ int main(void)
 }
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
notes/etc/whirltest.c

@@ -13,3 +13,7 @@ int main(void)
    }
 }
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 18 - 0
notes/tech0005.txt

@@ -0,0 +1,18 @@
+Tech Note 0005
+Minimizing Code Space
+Tom St Denis
+
+Introduction
+------------
+
+Tweaking...
+
+You can disable whole classes of algorithms on the command line with the LTC_NO_* defines.  From there you can manually turn on what you want to enable.  
+
+The following build with GCC 3.4.3 on an AMD64 box gets you AES, CTR mode, SHA-256, HMAC, Yarrow, full RSA PKCS #1, PKCS #5, ASN.1 DER and MPI in 
+roughly 80KB of code.
+
+CFLAGS="-DSC_RSA_1 -DLTC_NO_CIPHERS -DLTC_NO_HASHES -DLTC_NO_PRNGS -DLTC_NO_MACS -DLTC_NO_MODES -DLTC_NO_PK -DRIJNDAEL -DCTR -DSHA256 \
+-DHMAC -DYARROW -DMRSA -DMPI -Os -fomit-frame-pointer" make IGNORE_SPEED=1
+
+Neato eh?

+ 4 - 0
parsenames.pl

@@ -20,3 +20,7 @@ foreach my $obj (@a) {
 if ($ARGV[0] eq "HEADERS") { print "testprof/tomcrypt_test.h"; }
 
 print "\n\n";
+
+# $Source: /cvs/libtom/libtomcrypt/parsenames.pl,v $   
+# $Revision: 1.3 $   
+# $Date: 2005/05/05 14:49:27 $ 

+ 35 - 0
run.sh

@@ -0,0 +1,35 @@
+#!/bin/bash
+bash build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1"
+if [ -a testok.txt ] && [ -f testok.txt ]; then
+   echo
+else
+	echo
+	echo "Test failed"
+	exit 1
+fi
+
+rm -f testok.txt
+bash build.sh " $1" "$2 -Os" " $3 IGNORE_SPEED=1 LTC_SMALL=1"
+if [ -a testok.txt ] && [ -f testok.txt ]; then
+   echo
+else
+	echo
+	echo "Test failed"
+	exit 1
+fi
+
+rm -f testok.txt
+bash build.sh " $1" " $2" " $3"
+if [ -a testok.txt ] && [ -f testok.txt ]; then
+   echo
+else
+	echo
+	echo "Test failed"
+	exit 1
+fi
+
+exit 0
+
+# $Source: /cvs/libtom/libtomcrypt/run.sh,v $   
+# $Revision: 1.13 $   
+# $Date: 2005/05/11 18:59:53 $ 

+ 5 - 1
src/ciphers/aes/aes.c

@@ -127,7 +127,7 @@ int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *s
 #endif    
     LTC_ARGCHK(key  != NULL);
     LTC_ARGCHK(skey != NULL);
-    
+  
     if (keylen != 16 && keylen != 24 && keylen != 32) {
        return CRYPT_INVALID_KEYSIZE;
     }
@@ -747,3 +747,7 @@ int ECB_KS(int *keysize)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/aes/aes_tab.c

@@ -1018,3 +1018,7 @@ static const ulong32 rcon[] = {
     0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL,
     0x1B000000UL, 0x36000000UL, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
 };
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/anubis.c

@@ -1548,3 +1548,7 @@ int anubis_keysize(int *keysize)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/blowfish.c

@@ -581,3 +581,7 @@ int blowfish_keysize(int *keysize)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/cast5.c

@@ -709,3 +709,7 @@ int cast5_keysize(int *keysize)
 } 
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/des.c

@@ -1888,3 +1888,7 @@ int des3_keysize(int *keysize)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/khazad.c

@@ -845,3 +845,7 @@ int khazad_keysize(int *keysize)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/noekeon.c

@@ -290,3 +290,7 @@ int noekeon_keysize(int *keysize)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/rc2.c

@@ -348,3 +348,7 @@ int rc2_keysize(int *keysize)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/rc5.c

@@ -308,3 +308,7 @@ int rc5_keysize(int *keysize)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/rc6.c

@@ -337,3 +337,7 @@ int rc6_keysize(int *keysize)
 #endif /*RC6*/
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/safer/safer.c

@@ -481,3 +481,7 @@ int safer_sk128_test(void)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/safer/safer_tab.c

@@ -62,3 +62,7 @@ const unsigned char safer_lbox[256] = {
 #endif
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/safer/saferp.c

@@ -549,3 +549,7 @@ int saferp_keysize(int *keysize)
 #endif
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/skipjack.c

@@ -329,3 +329,7 @@ int skipjack_keysize(int *keysize)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 5 - 1
src/ciphers/twofish/twofish.c

@@ -576,7 +576,7 @@ void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_k
         b = RORc(b ^ (t2 + t1 + k[3]), 1);
 
         t2 = g1_func(b, skey);
-        t1 = g_func(a, key) + t2;
+        t1 = g_func(a, skey) + t2;
         c = ROLc(c, 1) ^ (t1 + k[0]);
         d = RORc(d ^ (t2 +  t1 + k[1]), 1);
         k -= 4;
@@ -700,3 +700,7 @@ int twofish_keysize(int *keysize)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/twofish/twofish_tab.c

@@ -490,3 +490,7 @@ static const ulong32 rs_tab7[256] = {
 #endif /* TWOFISH_ALL_TABLES */
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/ciphers/xtea.c

@@ -201,3 +201,7 @@ int xtea_keysize(int *keysize)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 1
src/encauth/ccm/ccm_memory.c

@@ -293,7 +293,6 @@ int ccm_memory(int cipher,
 
 #ifdef LTC_CLEAN_STACK
    zeromem(skey,   sizeof(*skey));
-   zeromem(B,      sizeof(B));
    zeromem(PAD,    sizeof(PAD));
    zeromem(CTRPAD, sizeof(CTRPAD));
 #endif
@@ -304,3 +303,7 @@ int ccm_memory(int cipher,
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ccm/ccm_test.c

@@ -168,3 +168,7 @@ int ccm_test(void)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_addheader.c

@@ -32,3 +32,7 @@ int eax_addheader(eax_state *eax, const unsigned char *header,
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_decrypt.c

@@ -44,3 +44,7 @@ int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt,
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_decrypt_verify_memory.c

@@ -102,3 +102,7 @@ LBL_ERR:
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_done.c

@@ -88,3 +88,7 @@ LBL_ERR:
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_encrypt.c

@@ -45,3 +45,7 @@ int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct,
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_encrypt_authenticate_memory.c

@@ -76,3 +76,7 @@ LBL_ERR:
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 5 - 3
src/encauth/eax/eax_init.c

@@ -108,11 +108,9 @@ int eax_init(eax_state *eax, int cipher,
    /* note we don't finish the headeromac, this allows us to add more header later */
 
    /* setup the CTR mode */
-   if ((err = ctr_start(cipher, eax->N, key, keylen, 0, &eax->ctr)) != CRYPT_OK) {
+   if ((err = ctr_start(cipher, eax->N, key, keylen, 0, CTR_COUNTER_BIG_ENDIAN, &eax->ctr)) != CRYPT_OK) {
       goto LBL_ERR; 
    }
-   /* use big-endian counter */
-   eax->ctr.mode = 1;
 
    /* setup the OMAC for the ciphertext */
    if ((err = omac_init(&eax->ctomac, cipher, key, keylen)) != CRYPT_OK) { 
@@ -140,3 +138,7 @@ LBL_ERR:
 }
 
 #endif 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/eax/eax_test.c

@@ -276,3 +276,7 @@ int eax_test(void)
 }
 
 #endif /* EAX_MODE */
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 8 - 1
src/encauth/gcm/gcm_add_aad.c

@@ -27,8 +27,11 @@
 int gcm_add_aad(gcm_state *gcm,
                const unsigned char *adata,  unsigned long adatalen)
 {
-   unsigned long x, y;
+   unsigned long x;
    int           err;
+#ifdef LTC_FAST
+   unsigned long y;
+#endif
 
    LTC_ARGCHK(gcm    != NULL);
    if (adatalen > 0) {
@@ -115,3 +118,7 @@ int gcm_add_aad(gcm_state *gcm,
 }
 #endif
    
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/gcm/gcm_add_iv.c

@@ -88,3 +88,7 @@ int gcm_add_iv(gcm_state *gcm,
 
 #endif
    
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/gcm/gcm_done.c

@@ -75,3 +75,7 @@ int gcm_done(gcm_state *gcm,
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 5 - 0
src/encauth/gcm/gcm_gf_mult.c

@@ -31,6 +31,7 @@ static void gcm_rightshift(unsigned char *a)
 static const unsigned char mask[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
 static const unsigned char poly[] = { 0x00, 0xE1 };
 
+     
 /**
   GCM GF multiplier (internal use only) 
   @param a   First value
@@ -87,3 +88,7 @@ void gcm_mult_h(gcm_state *gcm, unsigned char *I)
 
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 64 - 7
src/encauth/gcm/gcm_init.c

@@ -17,6 +17,46 @@
 
 #ifdef GCM_MODE
 
+#ifdef GCM_TABLES
+
+/* this is x*2^128 mod p(x) ... the results are 16 bytes each stored in a packed format.  Since only the 
+ * lower 16 bits are not zero'ed I removed the upper 14 bytes */
+static const unsigned char gcm_shift_table[256*2] = {
+0x00, 0x00, 0x01, 0xc2, 0x03, 0x84, 0x02, 0x46, 0x07, 0x08, 0x06, 0xca, 0x04, 0x8c, 0x05, 0x4e,
+0x0e, 0x10, 0x0f, 0xd2, 0x0d, 0x94, 0x0c, 0x56, 0x09, 0x18, 0x08, 0xda, 0x0a, 0x9c, 0x0b, 0x5e,
+0x1c, 0x20, 0x1d, 0xe2, 0x1f, 0xa4, 0x1e, 0x66, 0x1b, 0x28, 0x1a, 0xea, 0x18, 0xac, 0x19, 0x6e,
+0x12, 0x30, 0x13, 0xf2, 0x11, 0xb4, 0x10, 0x76, 0x15, 0x38, 0x14, 0xfa, 0x16, 0xbc, 0x17, 0x7e,
+0x38, 0x40, 0x39, 0x82, 0x3b, 0xc4, 0x3a, 0x06, 0x3f, 0x48, 0x3e, 0x8a, 0x3c, 0xcc, 0x3d, 0x0e,
+0x36, 0x50, 0x37, 0x92, 0x35, 0xd4, 0x34, 0x16, 0x31, 0x58, 0x30, 0x9a, 0x32, 0xdc, 0x33, 0x1e,
+0x24, 0x60, 0x25, 0xa2, 0x27, 0xe4, 0x26, 0x26, 0x23, 0x68, 0x22, 0xaa, 0x20, 0xec, 0x21, 0x2e,
+0x2a, 0x70, 0x2b, 0xb2, 0x29, 0xf4, 0x28, 0x36, 0x2d, 0x78, 0x2c, 0xba, 0x2e, 0xfc, 0x2f, 0x3e,
+0x70, 0x80, 0x71, 0x42, 0x73, 0x04, 0x72, 0xc6, 0x77, 0x88, 0x76, 0x4a, 0x74, 0x0c, 0x75, 0xce,
+0x7e, 0x90, 0x7f, 0x52, 0x7d, 0x14, 0x7c, 0xd6, 0x79, 0x98, 0x78, 0x5a, 0x7a, 0x1c, 0x7b, 0xde,
+0x6c, 0xa0, 0x6d, 0x62, 0x6f, 0x24, 0x6e, 0xe6, 0x6b, 0xa8, 0x6a, 0x6a, 0x68, 0x2c, 0x69, 0xee,
+0x62, 0xb0, 0x63, 0x72, 0x61, 0x34, 0x60, 0xf6, 0x65, 0xb8, 0x64, 0x7a, 0x66, 0x3c, 0x67, 0xfe,
+0x48, 0xc0, 0x49, 0x02, 0x4b, 0x44, 0x4a, 0x86, 0x4f, 0xc8, 0x4e, 0x0a, 0x4c, 0x4c, 0x4d, 0x8e,
+0x46, 0xd0, 0x47, 0x12, 0x45, 0x54, 0x44, 0x96, 0x41, 0xd8, 0x40, 0x1a, 0x42, 0x5c, 0x43, 0x9e,
+0x54, 0xe0, 0x55, 0x22, 0x57, 0x64, 0x56, 0xa6, 0x53, 0xe8, 0x52, 0x2a, 0x50, 0x6c, 0x51, 0xae,
+0x5a, 0xf0, 0x5b, 0x32, 0x59, 0x74, 0x58, 0xb6, 0x5d, 0xf8, 0x5c, 0x3a, 0x5e, 0x7c, 0x5f, 0xbe,
+0xe1, 0x00, 0xe0, 0xc2, 0xe2, 0x84, 0xe3, 0x46, 0xe6, 0x08, 0xe7, 0xca, 0xe5, 0x8c, 0xe4, 0x4e,
+0xef, 0x10, 0xee, 0xd2, 0xec, 0x94, 0xed, 0x56, 0xe8, 0x18, 0xe9, 0xda, 0xeb, 0x9c, 0xea, 0x5e,
+0xfd, 0x20, 0xfc, 0xe2, 0xfe, 0xa4, 0xff, 0x66, 0xfa, 0x28, 0xfb, 0xea, 0xf9, 0xac, 0xf8, 0x6e,
+0xf3, 0x30, 0xf2, 0xf2, 0xf0, 0xb4, 0xf1, 0x76, 0xf4, 0x38, 0xf5, 0xfa, 0xf7, 0xbc, 0xf6, 0x7e,
+0xd9, 0x40, 0xd8, 0x82, 0xda, 0xc4, 0xdb, 0x06, 0xde, 0x48, 0xdf, 0x8a, 0xdd, 0xcc, 0xdc, 0x0e,
+0xd7, 0x50, 0xd6, 0x92, 0xd4, 0xd4, 0xd5, 0x16, 0xd0, 0x58, 0xd1, 0x9a, 0xd3, 0xdc, 0xd2, 0x1e,
+0xc5, 0x60, 0xc4, 0xa2, 0xc6, 0xe4, 0xc7, 0x26, 0xc2, 0x68, 0xc3, 0xaa, 0xc1, 0xec, 0xc0, 0x2e,
+0xcb, 0x70, 0xca, 0xb2, 0xc8, 0xf4, 0xc9, 0x36, 0xcc, 0x78, 0xcd, 0xba, 0xcf, 0xfc, 0xce, 0x3e,
+0x91, 0x80, 0x90, 0x42, 0x92, 0x04, 0x93, 0xc6, 0x96, 0x88, 0x97, 0x4a, 0x95, 0x0c, 0x94, 0xce,
+0x9f, 0x90, 0x9e, 0x52, 0x9c, 0x14, 0x9d, 0xd6, 0x98, 0x98, 0x99, 0x5a, 0x9b, 0x1c, 0x9a, 0xde,
+0x8d, 0xa0, 0x8c, 0x62, 0x8e, 0x24, 0x8f, 0xe6, 0x8a, 0xa8, 0x8b, 0x6a, 0x89, 0x2c, 0x88, 0xee,
+0x83, 0xb0, 0x82, 0x72, 0x80, 0x34, 0x81, 0xf6, 0x84, 0xb8, 0x85, 0x7a, 0x87, 0x3c, 0x86, 0xfe,
+0xa9, 0xc0, 0xa8, 0x02, 0xaa, 0x44, 0xab, 0x86, 0xae, 0xc8, 0xaf, 0x0a, 0xad, 0x4c, 0xac, 0x8e,
+0xa7, 0xd0, 0xa6, 0x12, 0xa4, 0x54, 0xa5, 0x96, 0xa0, 0xd8, 0xa1, 0x1a, 0xa3, 0x5c, 0xa2, 0x9e,
+0xb5, 0xe0, 0xb4, 0x22, 0xb6, 0x64, 0xb7, 0xa6, 0xb2, 0xe8, 0xb3, 0x2a, 0xb1, 0x6c, 0xb0, 0xae,
+0xbb, 0xf0, 0xba, 0x32, 0xb8, 0x74, 0xb9, 0xb6, 0xbc, 0xf8, 0xbd, 0x3a, 0xbf, 0x7c, 0xbe, 0xbe };
+
+#endif
+
 /**
   Initialize a GCM state
   @param gcm     The GCM state to initialize
@@ -31,7 +71,7 @@ int gcm_init(gcm_state *gcm, int cipher,
    int           err;
    unsigned char B[16];
 #ifdef GCM_TABLES
-   int           x, y;
+   int           x, y, z, t;
 #endif
 
    LTC_ARGCHK(gcm != NULL);
@@ -72,17 +112,34 @@ int gcm_init(gcm_state *gcm, int cipher,
 
 #ifdef GCM_TABLES
    /* setup tables */
+
+   /* generate the first table as it has no shifting (from which we make the other tables) */
    zeromem(B, 16);
-   for (x = 0; x < 16; x++) {
-       for (y = 0; y < 256; y++) {
-            B[x] = y;
-            gcm_gf_mult(gcm->H, B, &gcm->PC[x][y][0]);
-       }
-       B[x] = 0;
+   for (y = 0; y < 256; y++) {
+        B[0] = y;
+        gcm_gf_mult(gcm->H, B, &gcm->PC[0][y][0]);
    }
+
+   /* now generate the rest of the tables based the previous table */
+   for (x = 1; x < 16; x++) {
+      for (y = 0; y < 256; y++) {
+         /* now shift it right by 8 bits */
+         t = gcm->PC[x-1][y][15];
+         for (z = 15; z > 0; z--) {
+             gcm->PC[x][y][z] = gcm->PC[x-1][y][z-1];
+         }
+         gcm->PC[x][y][0] = gcm_shift_table[t<<1];
+         gcm->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1];
+     }
+  }
+
 #endif
 
    return CRYPT_OK;
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/gcm/gcm_memory.c

@@ -87,3 +87,7 @@ LTC_ERR:
 }
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/gcm/gcm_process.c

@@ -141,3 +141,7 @@ int gcm_process(gcm_state *gcm,
 
 #endif
    
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/gcm/gcm_reset.c

@@ -38,3 +38,7 @@ int gcm_reset(gcm_state *gcm)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 1
src/encauth/gcm/gcm_test.c

@@ -281,7 +281,6 @@ int gcm_test(void)
 };
    int           idx, err;
    unsigned long x, y;
-   gcm_state     gcm;
    unsigned char out[2][64], T[2][16];
 
    /* find aes */
@@ -363,3 +362,7 @@ int gcm_test(void)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_decrypt.c

@@ -71,3 +71,7 @@ int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_decrypt_verify_memory.c

@@ -80,3 +80,7 @@ LBL_ERR:
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_done_decrypt.c

@@ -74,3 +74,7 @@ LBL_ERR:
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_done_encrypt.c

@@ -40,3 +40,7 @@ int ocb_done_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned long ptle
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_encrypt.c

@@ -64,3 +64,7 @@ int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_encrypt_authenticate_memory.c

@@ -78,3 +78,7 @@ LBL_ERR:
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_init.c

@@ -127,3 +127,7 @@ int ocb_init(ocb_state *ocb, int cipher,
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_ntz.c

@@ -36,3 +36,7 @@ int ocb_ntz(unsigned long x)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_shift_xor.c

@@ -33,3 +33,7 @@ void ocb_shift_xor(ocb_state *ocb, unsigned char *Z)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/ocb_test.c

@@ -231,3 +231,7 @@ int ocb_test(void)
    -- hard to stream [you can't emit ciphertext until full block]
    -- The setup is somewhat complicated...
 */
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/encauth/ocb/s_ocb_done.c

@@ -138,3 +138,7 @@ int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/hashes/chc/chc.c

@@ -291,3 +291,7 @@ int chc_test(void)
 }
 
 #endif
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/hashes/helper/hash_file.c

@@ -51,3 +51,7 @@ int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *ou
 #endif
 }
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/hashes/helper/hash_filehandle.c

@@ -64,3 +64,7 @@ int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outle
 #endif
 }
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/hashes/helper/hash_memory.c

@@ -62,3 +62,7 @@ LBL_ERR:
 
     return err;
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/hashes/helper/hash_memory_multi.c

@@ -80,3 +80,7 @@ LBL_ERR:
     va_end(args);
     return err;
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 5
src/hashes/md2.c

@@ -24,11 +24,9 @@ const struct ltc_hash_descriptor md2_desc =
     16,
     16,
 
-    /* DER encoding */
-    { 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 
-      0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 
-      0x04, 0x10 },
-    18,
+    /* OID */
+   { 1, 2, 840, 113549, 2, 2,  },
+   6,
 
     &md2_init,
     &md2_process,
@@ -246,3 +244,7 @@ int md2_test(void)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 3
src/hashes/md4.c

@@ -24,9 +24,9 @@ const struct ltc_hash_descriptor md4_desc =
     16,
     64,
  
-    /* DER encoding (not yet supported) */
-    { 0x00 },
-    0,    
+    /* OID */
+   { 1, 2, 840, 113549, 2, 4,  },
+   6,
 
     &md4_init,
     &md4_process,
@@ -300,3 +300,7 @@ int md4_test(void)
 #endif
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 5
src/hashes/md5.c

@@ -25,11 +25,9 @@ const struct ltc_hash_descriptor md5_desc =
     16,
     64,
 
-    /* DER identifier */
-    { 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 
-      0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 
-      0x04, 0x10 },
-    18,
+    /* OID */
+   { 1, 2, 840, 113549, 2, 5,  },
+   6,
 
     &md5_init,
     &md5_process,
@@ -363,3 +361,7 @@ int  md5_test(void)
 #endif
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 3
src/hashes/rmd128.c

@@ -30,9 +30,9 @@ const struct ltc_hash_descriptor rmd128_desc =
     16,
     64,
 
-    /* DER identifier (not supported) */
-    { 0x00 },
-    0,
+    /* OID */
+   { 1, 0, 10118, 3, 0, 50 },
+   6,
 
     &rmd128_init,
     &rmd128_process,
@@ -403,3 +403,7 @@ int rmd128_test(void)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 4
src/hashes/rmd160.c

@@ -30,10 +30,9 @@ const struct ltc_hash_descriptor rmd160_desc =
     20,
     64,
 
-    /* DER identifier */
-    { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 
-      0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 },
-    15,
+    /* OID */
+   { 1, 3, 36, 3, 2, 1,  },
+   6,
 
     &rmd160_init,
     &rmd160_process,
@@ -463,3 +462,7 @@ int rmd160_test(void)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 4
src/hashes/sha1.c

@@ -25,10 +25,9 @@ const struct ltc_hash_descriptor sha1_desc =
     20,
     64,
 
-    /* DER identifier */
-    { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E, 
-      0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 },
-    15,
+    /* OID */
+   { 1, 3, 14, 3, 2, 26,  },
+   6,
 
     &sha1_init,
     &sha1_process,
@@ -282,3 +281,7 @@ int  sha1_test(void)
 #endif
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 3
src/hashes/sha2/sha224.c

@@ -20,9 +20,9 @@ const struct ltc_hash_descriptor sha224_desc =
     28,
     64,
 
-    /* DER identifier (not supported) */
-    { 0x00 },
-    0,
+    /* OID */
+   { 2, 16, 840, 1, 101, 3, 4, 2, 4,  },
+   9,
 
     &sha224_init,
     &sha256_process,
@@ -118,3 +118,7 @@ int  sha224_test(void)
  #endif
 }
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 5
src/hashes/sha2/sha256.c

@@ -24,11 +24,9 @@ const struct ltc_hash_descriptor sha256_desc =
     32,
     64,
 
-    /* DER identifier */
-    { 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 
-      0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 
-      0x00, 0x04, 0x20 },
-    19,
+    /* OID */
+   { 2, 16, 840, 1, 101, 3, 4, 2, 1,  },
+   9,
     
     &sha256_init,
     &sha256_process,
@@ -335,3 +333,7 @@ int  sha256_test(void)
 #endif
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 5
src/hashes/sha2/sha384.c

@@ -20,11 +20,9 @@ const struct ltc_hash_descriptor sha384_desc =
     48,
     128,
 
-    /* DER identifier */
-    { 0x30, 0x41, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 
-      0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 
-      0x00, 0x04, 0x30 },
-    19,
+    /* OID */
+   { 2, 16, 840, 1, 101, 3, 4, 2, 2,  },
+   9,
 
     &sha384_init,
     &sha512_process,
@@ -130,3 +128,7 @@ int  sha384_test(void)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 5
src/hashes/sha2/sha512.c

@@ -24,11 +24,9 @@ const struct ltc_hash_descriptor sha512_desc =
     64,
     128,
 
-    /* DER identifier */
-    { 0x30, 0x51, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 
-      0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 
-      0x00, 0x04, 0x40 },
-    19,
+    /* OID */
+   { 2, 16, 840, 1, 101, 3, 4, 2, 3,  },
+   9,
 
     &sha512_init,
     &sha512_process,
@@ -314,3 +312,7 @@ int  sha512_test(void)
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 5
src/hashes/tiger.c

@@ -25,11 +25,9 @@ const struct ltc_hash_descriptor tiger_desc =
     24,
     64,
 
-    /* DER identifier */
-    { 0x30, 0x29, 0x30, 0x0D, 0x06, 0x09, 0x2B, 0x06, 
-      0x01, 0x04, 0x01, 0xDA, 0x47, 0x0C, 0x02, 0x05, 
-      0x00, 0x04, 0x18 },
-    19,
+    /* OID */
+   { 1, 3, 6, 1, 4, 1, 11591, 12, 2,  },
+   9,
 
     &tiger_init,
     &tiger_process,
@@ -809,3 +807,7 @@ Hash of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFG
 
 
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 7 - 3
src/hashes/whirl/whirl.c

@@ -25,9 +25,9 @@ const struct ltc_hash_descriptor whirlpool_desc =
     64,
     64,
 
-    /* DER encoding (not yet supported) */
-    { 0x00 },
-    0,
+   /* OID */
+   { 1, 0, 10118, 3, 0, 55 },
+   6,
 
     &whirlpool_init,
     &whirlpool_process,
@@ -307,3 +307,7 @@ int  whirlpool_test(void)
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/hashes/whirl/whirltab.c

@@ -577,3 +577,7 @@ CONST64(0xca2dbf07ad5a8333),
 CONST64(0x6302aa71c81949d9),
 };
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/headers/ltc_tommath.h

@@ -575,3 +575,7 @@ extern const char *mp_s_rmap;
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 6 - 2
src/headers/tomcrypt.h

@@ -16,8 +16,8 @@ extern "C" {
 #endif
 
 /* version */
-#define CRYPT   0x0102
-#define SCRYPT  "1.02"
+#define CRYPT   0x0103
+#define SCRYPT  "1.03"
 
 /* max size of either a cipher/hash block or symmetric key [largest of the two] */
 #define MAXBLOCKSIZE  128
@@ -79,3 +79,7 @@ enum {
 
 #endif /* TOMCRYPT_H_ */
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/headers/tomcrypt_argchk.h

@@ -19,3 +19,7 @@ void crypt_argchk(char *v, char *s, int d);
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 4 - 0
src/headers/tomcrypt_cfg.h

@@ -106,3 +106,7 @@ int   XMEMCMP(const void *s1, const void *s2, size_t n);
 
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 14 - 3
src/headers/tomcrypt_cipher.h

@@ -32,7 +32,7 @@ struct saferp_key {
 
 #ifdef RIJNDAEL
 struct rijndael_key {
-   ulong32 eK[64], dK[64];
+   ulong32 eK[60], dK[60];
    int Nr;
 };
 #endif
@@ -599,8 +599,15 @@ int cbc_done(symmetric_CBC *cbc);
 #endif
 
 #ifdef CTR
-int ctr_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-              int keylen, int num_rounds, symmetric_CTR *ctr);
+
+#define CTR_COUNTER_LITTLE_ENDIAN    0
+#define CTR_COUNTER_BIG_ENDIAN       1
+
+int ctr_start(               int   cipher,
+              const unsigned char *IV,
+              const unsigned char *key,       int keylen,
+                             int  num_rounds, int ctr_mode,
+                   symmetric_CTR *ctr);
 int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);
 int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
 int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
@@ -617,3 +624,7 @@ int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
 
 int cipher_is_valid(int idx);
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 46 - 8
src/headers/tomcrypt_custom.h

@@ -1,6 +1,3 @@
-/* This header is meant to be included before mycrypt.h in projects where
- * you don't want to throw all the defines in a makefile. 
- */
 #ifndef TOMCRYPT_CUSTOM_H_
 #define TOMCRYPT_CUSTOM_H_
 
@@ -20,7 +17,9 @@
 /* #define LTC_SMALL_CODE */
 
 /* Enable self-test test vector checking */
-#define LTC_TEST
+#ifndef LTC_NO_TEST
+   #define LTC_TEST
+#endif
 
 /* clean the stack of functions which put private information on stack */
 /* #define LTC_CLEAN_STACK */
@@ -38,6 +37,8 @@
 /* #define LTC_NO_BSWAP */
 
 /* ---> Symmetric Block Ciphers <--- */
+#ifndef LTC_NO_CIPHERS
+
 #define BLOWFISH
 #define RC2
 #define RC5
@@ -48,8 +49,12 @@
 /* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
  * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
 #define TWOFISH
-#define TWOFISH_TABLES
-/* #define TWOFISH_ALL_TABLES */
+#ifndef LTC_NO_TABLES
+   #define TWOFISH_TABLES
+   /* #define TWOFISH_ALL_TABLES */
+#else
+   #define TWOFISH_SMALL
+#endif
 /* #define TWOFISH_SMALL */
 /* DES includes EDE triple-DES */
 #define DES
@@ -61,15 +66,23 @@
 #define ANUBIS
 #define ANUBIS_TWEAK
 
+#endif /* LTC_NO_CIPHERS */
+
 
 /* ---> Block Cipher Modes of Operation <--- */
+#ifndef LTC_NO_MODES
+
 #define CFB
 #define OFB
 #define ECB
 #define CBC
 #define CTR
 
+#endif /* LTC_NO_MODES */
+
 /* ---> One-Way Hash Functions <--- */
+#ifndef LTC_NO_HASHES 
+
 #define CHC_HASH
 #define WHIRLPOOL
 #define SHA512
@@ -84,7 +97,11 @@
 #define RIPEMD128
 #define RIPEMD160
 
+#endif /* LTC_NO_HASHES */
+
 /* ---> MAC functions <--- */
+#ifndef LTC_NO_MACS
+
 #define HMAC
 #define OMAC
 #define PMAC
@@ -95,6 +112,7 @@
 #endif
 
 /* ---> Encrypt + Authenticate Modes <--- */
+
 #define EAX_MODE
 #if defined(EAX_MODE) && !(defined(CTR) && defined(OMAC))
    #error EAX_MODE requires CTR and OMAC mode
@@ -104,13 +122,20 @@
 #define CCM_MODE
 
 #define GCM_MODE
+
 /* Use 64KiB tables */
-#define GCM_TABLES 
+#ifndef LTC_NO_TABLES
+   #define GCM_TABLES 
+#endif
+
+#endif /* LTC_NO_MACS */
 
 /* Various tidbits of modern neatoness */
 #define BASE64
 
 /* --> Pseudo Random Number Generators <--- */
+#ifndef LTC_NO_PRNGS
+
 /* Yarrow */
 #define YARROW
 /* which descriptor of AES to use?  */
@@ -142,7 +167,11 @@
 /* try /dev/urandom before trying /dev/random */
 #define TRY_URANDOM_FIRST
 
+#endif /* LTC_NO_PRNGS */
+
 /* ---> Public Key Crypto <--- */
+#ifndef LTC_NO_PK
+
 #define MRSA
 
 /* Digital Signature Algorithm */
@@ -168,7 +197,6 @@
 /* ECC */
 #define MECC
 /* Supported Key Sizes */
-#define ECC160
 #define ECC192
 #define ECC224
 #define ECC256
@@ -178,7 +206,11 @@
 /* Include the MPI functionality?  (required by the PK algorithms) */
 #define MPI
 
+#endif /* LTC_NO_PK */
+
 /* PKCS #1 (RSA) and #5 (Password Handling) stuff */
+#ifndef LTC_NO_PKCS
+
 #define PKCS_1
 #define PKCS_5
 
@@ -192,5 +224,11 @@
    #error RSA/DSA requires ASN.1 DER functionality, make sure LTC_DER is enabled
 #endif
 
+#endif /* LTC_NO_PKCS */
+
 #endif
 
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

+ 24 - 19
src/headers/tomcrypt_hash.h

@@ -132,10 +132,11 @@ extern  struct ltc_hash_descriptor {
     unsigned long hashsize;
     /** Input block size in octets */
     unsigned long blocksize;
-    /** ASN.1 DER identifier */
-    unsigned char DER[64];
+    /** ASN.1 OID */
+    unsigned long OID[16];
     /** Length of DER encoding */
-    unsigned long DERlen;
+    unsigned long OIDlen;
+
     /** Init a hash state
       @param hash   The hash to initialize
       @return CRYPT_OK if successful
@@ -292,29 +293,29 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
 {                                                                                           \
     unsigned long n;                                                                        \
     int           err;                                                                      \
-    LTC_ARGCHK(md != NULL);                                                                    \
-    LTC_ARGCHK(in != NULL);                                                                   \
+    LTC_ARGCHK(md != NULL);                                                                 \
+    LTC_ARGCHK(in != NULL);                                                                 \
     if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
        return CRYPT_INVALID_ARG;                                                            \
     }                                                                                       \
-    while (inlen > 0) {                                                                       \
-        if (md-> state_var .curlen == 0 && inlen >= block_size) {                             \
-           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) { \
-              return err;         \
-           }                                        \
+    while (inlen > 0) {                                                                     \
+        if (md-> state_var .curlen == 0 && inlen >= block_size) {                           \
+           if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) {               \
+              return err;                                                                   \
+           }                                                                                \
            md-> state_var .length += block_size * 8;                                        \
-           in             += block_size;                                                   \
-           inlen          -= block_size;                                                   \
+           in             += block_size;                                                    \
+           inlen          -= block_size;                                                    \
         } else {                                                                            \
-           n = MIN(inlen, (block_size - md-> state_var .curlen));                             \
-           memcpy(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);             \
+           n = MIN(inlen, (block_size - md-> state_var .curlen));                           \
+           memcpy(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n);              \
            md-> state_var .curlen += n;                                                     \
-           in             += n;                                                            \
-           inlen          -= n;                                                            \
+           in             += n;                                                             \
+           inlen          -= n;                                                             \
            if (md-> state_var .curlen == block_size) {                                      \
-              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {\
-                 return err;                                      \
-              } \
+              if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {            \
+                 return err;                                                                \
+              }                                                                             \
               md-> state_var .length += 8*block_size;                                       \
               md-> state_var .curlen = 0;                                                   \
            }                                                                                \
@@ -322,3 +323,7 @@ int func_name (hash_state * md, const unsigned char *in, unsigned long inlen)
     }                                                                                       \
     return CRYPT_OK;                                                                        \
 }
+
+/* $Source$ */
+/* $Revision$ */
+/* $Date$ */

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.