merge of 24ccd6df75086f1028c185f4ad5946f449bf2e05
     and cc138b6aed8d554f52f041a11afecb95e95ed3b8

--HG--
branch : libtomcrypt
extra : convert_revision : b699c68f607da9e448ca42b022a7891065781979
diff --git a/Doxyfile b/Doxyfile
new file mode 100644
index 0000000..a8de8a9
--- /dev/null
+++ b/Doxyfile
@@ -0,0 +1,1155 @@
+# Doxyfile 1.3.9.1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+#       TAG = value [value, ...]
+# For lists items can also be appended using:
+#       TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
+# by quotes) that should identify the project.
+
+PROJECT_NAME           = LibTomCrypt
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. 
+# This could be handy for archiving the generated documentation or 
+# if some version control system is used.
+
+PROJECT_NUMBER         = 1.05
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
+# base path where the generated documentation will be put. 
+# If a relative path is entered, it will be relative to the location 
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY       = doc/doxygen
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 
+# 4096 sub-directories (in 2 levels) under the output directory of each output 
+# format and will distribute the generated files over these directories. 
+# Enabling this option can be useful when feeding doxygen a huge amount of source 
+# files, where putting all generated files in the same directory would otherwise 
+# cause performance problems for the file system.
+
+CREATE_SUBDIRS         = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all 
+# documentation generated by doxygen is written. Doxygen will use this 
+# information to generate all constant output in the proper language. 
+# The default language is English, other supported languages are: 
+# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, 
+# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, 
+# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, 
+# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, 
+# Swedish, and Ukrainian.
+
+OUTPUT_LANGUAGE        = English
+
+# This tag can be used to specify the encoding used in the generated output. 
+# The encoding is not always determined by the language that is chosen, 
+# but also whether or not the output is meant for Windows or non-Windows users. 
+# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES 
+# forces the Windows encoding (this is the default for the Windows binary), 
+# whereas setting the tag to NO uses a Unix-style encoding (the default for 
+# all platforms other than Windows).
+
+USE_WINDOWS_ENCODING   = NO
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 
+# include brief member descriptions after the members that are listed in 
+# the file and class documentation (similar to JavaDoc). 
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC      = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 
+# the brief description of a member or function before the detailed description. 
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF           = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator 
+# that is used to form the text in various listings. Each string 
+# in this list, if found as the leading text of the brief description, will be 
+# stripped from the text and the result after processing the whole list, is used 
+# as the annotated text. Otherwise, the brief description is used as-is. If left 
+# blank, the following values are used ("$name" is automatically replaced with the 
+# name of the entity): "The $name class" "The $name widget" "The $name file" 
+# "is" "provides" "specifies" "contains" "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF       = 
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 
+# Doxygen will generate a detailed section even if there is only a brief 
+# description.
+
+ALWAYS_DETAILED_SEC    = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited 
+# members of a class in the documentation of that class as if those members were 
+# ordinary class members. Constructors, destructors and assignment operators of 
+# the base classes will not be shown.
+
+INLINE_INHERITED_MEMB  = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 
+# path before files name in the file list and in the header files. If set 
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES        = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 
+# can be used to strip a user-defined part of the path. Stripping is 
+# only done if one of the specified strings matches the left-hand part of 
+# the path. The tag can be used to show relative paths in the file list. 
+# If left blank the directory from which doxygen is run is used as the 
+# path to strip.
+
+STRIP_FROM_PATH        = src
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of 
+# the path mentioned in the documentation of a class, which tells 
+# the reader which header file to include in order to use a class. 
+# If left blank only the name of the header file containing the class 
+# definition is used. Otherwise one should specify the include paths that 
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH    = src/headers
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter 
+# (but less readable) file names. This can be useful is your file systems 
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES            = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
+# will interpret the first line (until the first dot) of a JavaDoc-style 
+# comment as the brief description. If set to NO, the JavaDoc 
+# comments will behave just like the Qt-style comments (thus requiring an 
+# explicit @brief command for a brief description.
+
+JAVADOC_AUTOBRIEF      = YES
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen 
+# treat a multi-line C++ special comment block (i.e. a block of //! or /// 
+# comments) as a brief description. This used to be the default behaviour. 
+# The new default is to treat a multi-line C++ comment block as a detailed 
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the DETAILS_AT_TOP tag is set to YES then Doxygen 
+# will output the detailed description near the top, like JavaDoc.
+# If set to NO, the detailed description appears after the member 
+# documentation.
+
+DETAILS_AT_TOP         = YES
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 
+# member inherits the documentation from any documented member that it 
+# re-implements.
+
+INHERIT_DOCS           = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 
+# tag is set to YES, then doxygen will reuse the documentation of the first 
+# member in the group (if any) for the other members of the group. By default 
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC   = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. 
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE               = 4
+
+# This tag can be used to specify a number of aliases that acts 
+# as commands in the documentation. An alias has the form "name=value". 
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to 
+# put the command \sideeffect (or @sideeffect) in the documentation, which 
+# will result in a user-defined paragraph with heading "Side Effects:". 
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES                = 
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources 
+# only. Doxygen will then generate output that is more tailored for C. 
+# For instance, some of the names that are used will be different. The list 
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C  = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources 
+# only. Doxygen will then generate output that is more tailored for Java. 
+# For instance, namespaces will be presented as packages, qualified scopes 
+# will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA   = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of 
+# the same type (for instance a group of public functions) to be put as a 
+# subgroup of that type (e.g. under the Public Functions section). Set it to 
+# NO to prevent subgrouping. Alternatively, this can be done per class using 
+# the \nosubgrouping command.
+
+SUBGROUPING            = YES
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 
+# documentation are documented, even if no documentation was available. 
+# Private class members and static file members will be hidden unless 
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL            = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
+# will be included in the documentation.
+
+EXTRACT_PRIVATE        = YES
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file 
+# will be included in the documentation.
+
+EXTRACT_STATIC         = YES
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) 
+# defined locally in source files will be included in the documentation. 
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES  = YES
+
+# This flag is only useful for Objective-C code. When set to YES local 
+# methods, which are defined in the implementation section but not in 
+# the interface are included in the documentation. 
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS  = YES
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 
+# undocumented members of documented classes, files or namespaces. 
+# If set to NO (the default) these members will be included in the 
+# various overviews, but no documentation section is generated. 
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS     = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 
+# undocumented classes that are normally visible in the class hierarchy. 
+# If set to NO (the default) these classes will be included in the various 
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES     = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all 
+# friend (class|struct|union) declarations. 
+# If set to NO (the default) these declarations will be included in the 
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS  = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any 
+# documentation blocks found inside the body of a function. 
+# If set to NO (the default) these blocks will be appended to the 
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS      = NO
+
+# The INTERNAL_DOCS tag determines if documentation 
+# that is typed after a \internal command is included. If the tag is set 
+# to NO (the default) then the documentation will be excluded. 
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS          = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 
+# file names in lower-case letters. If set to YES upper-case letters are also 
+# allowed. This is useful if you have classes or files whose names only differ 
+# in case and if your file system supports case sensitive file names. Windows 
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES       = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 
+# will show members with their full class and namespace scopes in the 
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES       = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 
+# will put a list of the files that are included by a file in the documentation 
+# of that file.
+
+SHOW_INCLUDE_FILES     = YES
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 
+# is inserted in the documentation for inline members.
+
+INLINE_INFO            = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 
+# will sort the (detailed) documentation of file and class members 
+# alphabetically by member name. If set to NO the members will appear in 
+# declaration order.
+
+SORT_MEMBER_DOCS       = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the 
+# brief documentation of file, namespace and class members alphabetically 
+# by member name. If set to NO (the default) the members will appear in 
+# declaration order.
+
+SORT_BRIEF_DOCS        = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be 
+# sorted by fully-qualified names, including namespaces. If set to 
+# NO (the default), the class list will be sorted only by class name, 
+# not including the namespace part. 
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the 
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME     = YES
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or 
+# disable (NO) the todo list. This list is created by putting \todo 
+# commands in the documentation.
+
+GENERATE_TODOLIST      = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or 
+# disable (NO) the test list. This list is created by putting \test 
+# commands in the documentation.
+
+GENERATE_TESTLIST      = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or 
+# disable (NO) the bug list. This list is created by putting \bug 
+# commands in the documentation.
+
+GENERATE_BUGLIST       = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or 
+# disable (NO) the deprecated list. This list is created by putting 
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional 
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS       = 
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines 
+# the initial value of a variable or define consists of for it to appear in 
+# the documentation. If the initializer consists of more lines than specified 
+# here it will be hidden. Use a value of 0 to hide initializers completely. 
+# The appearance of the initializer of individual variables and defines in the 
+# documentation can be controlled using \showinitializer or \hideinitializer 
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES  = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated 
+# at the bottom of the documentation of classes and structs. If set to YES the 
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES        = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated 
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET                  = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are 
+# generated by doxygen. Possible values are YES and NO. If left blank 
+# NO is used.
+
+WARNINGS               = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will 
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED   = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for 
+# potential errors in the documentation, such as not documenting some 
+# parameters in a documented function, or documenting parameters that 
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR      = YES
+
+# The WARN_FORMAT tag determines the format of the warning messages that 
+# doxygen can produce. The string should contain the $file, $line, and $text 
+# tags, which will be replaced by the file and line number from which the 
+# warning originated and the warning text.
+
+WARN_FORMAT            = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning 
+# and error messages should be written. If left blank the output is written 
+# to stderr.
+
+WARN_LOGFILE           = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain 
+# documented source files. You may enter file names like "myfile.cpp" or 
+# directories like "/usr/src/myproject". Separate the files or directories 
+# with spaces.
+
+INPUT                  = src
+
+# If the value of the INPUT tag contains directories, you can use the 
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
+# and *.h) to filter out the source-files in the directories. If left 
+# blank the following patterns are tested: 
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp 
+# *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm
+
+FILE_PATTERNS          = 
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories 
+# should be searched for input files as well. Possible values are YES and NO. 
+# If left blank NO is used.
+
+RECURSIVE              = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should 
+# excluded from the INPUT source files. This way you can easily exclude a 
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE                = 
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories 
+# that are symbolic links (a Unix filesystem feature) are excluded from the input.
+
+EXCLUDE_SYMLINKS       = NO
+
+# If the value of the INPUT tag contains directories, you can use the 
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 
+# certain files from those directories.
+
+EXCLUDE_PATTERNS       = 
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or 
+# directories that contain example code fragments that are included (see 
+# the \include command).
+
+EXAMPLE_PATH           = 
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the 
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
+# and *.h) to filter out the source-files in the directories. If left 
+# blank all files are included.
+
+EXAMPLE_PATTERNS       = 
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be 
+# searched for input files to be used with the \include or \dontinclude 
+# commands irrespective of the value of the RECURSIVE tag. 
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE      = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or 
+# directories that contain image that are included in the documentation (see 
+# the \image command).
+
+IMAGE_PATH             = 
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should 
+# invoke to filter for each input file. Doxygen will invoke the filter program 
+# by executing (via popen()) the command <filter> <input-file>, where <filter> 
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an 
+# input file. Doxygen will then use the output that the filter program writes 
+# to standard output.  If FILTER_PATTERNS is specified, this tag will be 
+# ignored.
+
+INPUT_FILTER           = 
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern 
+# basis.  Doxygen will compare the file name with each pattern and apply the 
+# filter if there is a match.  The filters are a list of the form: 
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further 
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER 
+# is applied to all files.
+
+FILTER_PATTERNS        = 
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 
+# INPUT_FILTER) will be used to filter the input files when producing source 
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will 
+# be generated. Documented entities will be cross-referenced with these sources. 
+# Note: To get rid of all source code in the generated output, make sure also 
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER         = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body 
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES         = YES
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 
+# doxygen to hide any special comment blocks from generated source code 
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS    = NO
+
+# If the REFERENCED_BY_RELATION tag is set to YES (the default) 
+# then for each documented function all documented 
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES (the default) 
+# then for each documented function all documented entities 
+# called/used by that function will be listed.
+
+REFERENCES_RELATION    = YES
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 
+# will generate a verbatim copy of the header file for each class for 
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 
+# of all compounds will be generated. Enable this if the project 
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX     = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX    = 5
+
+# In case all classes in a project start with a common prefix, all 
+# classes will be put under the same header in the alphabetical index. 
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that 
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX          = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
+# generate HTML output.
+
+GENERATE_HTML          = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT            = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for 
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank 
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION    = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for 
+# each generated HTML page. If it is left blank doxygen will generate a 
+# standard header.
+
+HTML_HEADER            = doc/header.html
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for 
+# each generated HTML page. If it is left blank doxygen will generate a 
+# standard footer.
+
+HTML_FOOTER            = doc/footer.html
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading 
+# style sheet that is used by each HTML page. It can be used to 
+# fine-tune the look of the HTML output. If the tag is left blank doxygen 
+# will generate a default style sheet. Note that doxygen will try to copy 
+# the style sheet file to the HTML output directory, so don't put your own 
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET        = 
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 
+# files or namespaces will be aligned in HTML using tables. If set to 
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS     = YES
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files 
+# will be generated that can be used as input for tools like the 
+# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) 
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP      = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can 
+# be used to specify the file name of the resulting .chm file. You 
+# can add a path in front of the file if the result should not be 
+# written to the html output directory.
+
+CHM_FILE               = 
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can 
+# be used to specify the location (absolute path including file name) of 
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run 
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION           = 
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag 
+# controls if a separate .chi index file is generated (YES) or that 
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI           = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag 
+# controls whether a binary table of contents is generated (YES) or a 
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC             = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members 
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND             = NO
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at 
+# top of each HTML page. The value NO (the default) enables the index and 
+# the value YES disables it.
+
+DISABLE_INDEX          = NO
+
+# This tag can be used to set the number of enum values (range [1..20]) 
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE   = 1
+
+# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
+# generated containing a tree-like index structure (just like the one that 
+# is generated for HTML Help). For this to work a browser that supports 
+# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, 
+# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are 
+# probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = YES
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 
+# used to set the initial width (in pixels) of the frame in which the tree 
+# is shown.
+
+TREEVIEW_WIDTH         = 250
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
+# generate Latex output.
+
+GENERATE_LATEX         = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT           = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be 
+# invoked. If left blank `latex' will be used as the default command name.
+
+LATEX_CMD_NAME         = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to 
+# generate index for LaTeX. If left blank `makeindex' will be used as the 
+# default command name.
+
+MAKEINDEX_CMD_NAME     = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 
+# LaTeX documents. This may be useful for small projects and may help to 
+# save some trees in general.
+
+COMPACT_LATEX          = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used 
+# by the printer. Possible values are: a4, a4wide, letter, legal and 
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE             = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES         = 
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for 
+# the generated latex document. The header should contain everything until 
+# the first chapter. If it is left blank doxygen will generate a 
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER           = 
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will 
+# contain links (just like the HTML output) instead of page references 
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS         = YES
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 
+# plain latex in the generated Makefile. Set this option to YES to get a 
+# higher quality PDF documentation.
+
+USE_PDFLATEX           = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 
+# command to the generated LaTeX files. This will instruct LaTeX to keep 
+# running if errors occur, instead of asking the user for help. 
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE        = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not 
+# include the index chapters (such as File Index, Compound Index, etc.) 
+# in the output.
+
+LATEX_HIDE_INDICES     = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 
+# The RTF output is optimized for Word 97 and may not look very pretty with 
+# other RTF readers or editors.
+
+GENERATE_RTF           = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT             = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact 
+# RTF documents. This may be useful for small projects and may help to 
+# save some trees in general.
+
+COMPACT_RTF            = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 
+# will contain hyperlink fields. The RTF file will 
+# contain links (just like the HTML output) instead of page references. 
+# This makes the output suitable for online browsing using WORD or other 
+# programs which support those fields. 
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS         = YES
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's 
+# config file, i.e. a series of assignments. You only have to provide 
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE    = 
+
+# Set optional variables used in the generation of an rtf document. 
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE    = 
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
+# generate man pages
+
+GENERATE_MAN           = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT             = man
+
+# The MAN_EXTENSION tag determines the extension that is added to 
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION          = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output, 
+# then it will generate one additional man file for each entity 
+# documented in the real man page(s). These additional files 
+# only source the real man page, but without them the man command 
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will 
+# generate an XML file that captures the structure of 
+# the code including all documentation.
+
+GENERATE_XML           = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. 
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT             = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema, 
+# which can be used by a validating XML parser to check the 
+# syntax of the XML files.
+
+XML_SCHEMA             = 
+
+# The XML_DTD tag can be used to specify an XML DTD, 
+# which can be used by a validating XML parser to check the 
+# syntax of the XML files.
+
+XML_DTD                = 
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will 
+# dump the program listings (including syntax highlighting 
+# and cross-referencing information) to the XML output. Note that 
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING     = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will 
+# generate an AutoGen Definitions (see autogen.sf.net) file 
+# that captures the structure of the code including all 
+# documentation. Note that this feature is still experimental 
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will 
+# generate a Perl module file that captures the structure of 
+# the code including all documentation. Note that this 
+# feature is still experimental and incomplete at the 
+# moment.
+
+GENERATE_PERLMOD       = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate 
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able 
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX          = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be 
+# nicely formatted so it can be parsed by a human reader.  This is useful 
+# if you want to understand what is going on.  On the other hand, if this 
+# tag is set to NO the size of the Perl module output will be much smaller 
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY         = YES
+
+# The names of the make variables in the generated doxyrules.make file 
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. 
+# This is useful so different doxyrules.make files included by the same 
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX = 
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor   
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 
+# evaluate all C-preprocessor directives found in the sources and include 
+# files.
+
+ENABLE_PREPROCESSING   = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 
+# names in the source code. If set to NO (the default) only conditional 
+# compilation will be performed. Macro expansion can be done in a controlled 
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION        = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 
+# then the macro expansion is limited to the macros specified with the 
+# PREDEFINED and EXPAND_AS_PREDEFINED tags.
+
+EXPAND_ONLY_PREDEF     = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES        = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that 
+# contain include files that are not input files but should be processed by 
+# the preprocessor.
+
+INCLUDE_PATH           = src/headers
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
+# patterns (like *.h and *.hpp) to filter out the header-files in the 
+# directories. If left blank, the patterns specified with FILE_PATTERNS will 
+# be used.
+
+INCLUDE_FILE_PATTERNS  = 
+
+# The PREDEFINED tag can be used to specify one or more macro names that 
+# are defined before the preprocessor is started (similar to the -D option of 
+# gcc). The argument of the tag is a list of macros of the form: name 
+# or name=definition (no spaces). If the definition and the = are 
+# omitted =1 is assumed. To prevent a macro definition from being 
+# undefined via #undef or recursively expanded use the := operator 
+# instead of the = operator.
+
+PREDEFINED             = 
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 
+# this tag can be used to specify a list of macro names that should be expanded. 
+# The macro definition that is found in the sources will be used. 
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED      = 
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then 
+# doxygen's preprocessor will remove all function-like macros that are alone 
+# on a line, have an all uppercase name, and do not end with a semicolon. Such 
+# function macros are typically used for boiler-plate code, and will confuse the 
+# parser if not removed.
+
+SKIP_FUNCTION_MACROS   = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references   
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles. 
+# Optionally an initial location of the external documentation 
+# can be added for each tagfile. The format of a tag file without 
+# this location is as follows: 
+#   TAGFILES = file1 file2 ... 
+# Adding location for the tag files is done as follows: 
+#   TAGFILES = file1=loc1 "file2 = loc2" ... 
+# where "loc1" and "loc2" can be relative or absolute paths or 
+# URLs. If a location is present for each tag, the installdox tool 
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen 
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES               = 
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create 
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE       = 
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed 
+# in the class index. If set to NO only the inherited external classes 
+# will be listed.
+
+ALLEXTERNALS           = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed 
+# in the modules index. If set to NO, only the current project's groups will 
+# be listed.
+
+EXTERNAL_GROUPS        = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script 
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH              = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool   
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base or 
+# super classes. Setting the tag to NO turns the diagrams off. Note that this 
+# option is superseded by the HAVE_DOT option below. This is only a fallback. It is 
+# recommended to install and use dot, since it yields more powerful graphs.
+
+CLASS_DIAGRAMS         = YES
+
+# If set to YES, the inheritance and collaboration graphs will hide 
+# inheritance and usage relations if the target is undocumented 
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS   = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 
+# available from the path. This tool is part of Graphviz, a graph visualization 
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section 
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT               = YES
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 
+# will generate a graph for each documented class showing the direct and 
+# indirect inheritance relations. Setting this tag to YES will force the 
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH            = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 
+# will generate a graph for each documented class showing the direct and 
+# indirect implementation dependencies (inheritance, containment, and 
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH    = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and 
+# collaboration diagrams in a style similar to the OMG's Unified Modeling 
+# Language.
+
+UML_LOOK               = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the 
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS     = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT 
+# tags are set to YES then doxygen will generate a graph for each documented 
+# file showing the direct and indirect include dependencies of the file with 
+# other documented files.
+
+INCLUDE_GRAPH          = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and 
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each 
+# documented header file showing the documented files that directly or 
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH      = YES
+
+# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will 
+# generate a call dependency graph for every global function or class method. 
+# Note that enabling this option will significantly increase the time of a run. 
+# So in most cases it will be better to enable call graphs for selected 
+# functions only using the \callgraph command.
+
+CALL_GRAPH             = YES
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY    = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images 
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT       = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be 
+# found. If left blank, it is assumed the dot tool can be found on the path.
+
+DOT_PATH               = 
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that 
+# contain dot files that are included in the documentation (see the 
+# \dotfile command).
+
+DOTFILE_DIRS           = 
+
+# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width 
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than 
+# this value, doxygen will try to truncate the graph, so that it fits within 
+# the specified constraint. Beware that most browsers cannot cope with very 
+# large images.
+
+MAX_DOT_GRAPH_WIDTH    = 1024
+
+# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height 
+# (in pixels) of the graphs generated by dot. If a graph becomes larger than 
+# this value, doxygen will try to truncate the graph, so that it fits within 
+# the specified constraint. Beware that most browsers cannot cope with very 
+# large images.
+
+MAX_DOT_GRAPH_HEIGHT   = 1024
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the 
+# graphs generated by dot. A depth value of 3 means that only nodes reachable 
+# from the root by following a path via at most 3 edges will be shown. Nodes that 
+# lay further from the root node will be omitted. Note that setting this option to 
+# 1 or 2 may greatly reduce the computation time needed for large code bases. Also 
+# note that a graph may be further truncated if the graph's image dimensions are 
+# not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH and MAX_DOT_GRAPH_HEIGHT). 
+# If 0 is used for the depth value (the default), the graph is not depth-constrained.
+
+MAX_DOT_GRAPH_DEPTH    = 0
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 
+# generate a legend page explaining the meaning of the various boxes and 
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND        = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will 
+# remove the intermediate dot files that are used to generate 
+# the various graphs.
+
+DOT_CLEANUP            = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine   
+#---------------------------------------------------------------------------
+
+# The SEARCHENGINE tag specifies whether or not a search engine should be 
+# used. If set to NO the values of all tags below this one will be ignored.
+
+SEARCHENGINE           = NO
diff --git a/LICENSE b/LICENSE
index 2e83cda..5d678c5 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,9 +1,5 @@
 LibTomCrypt is public domain.  As should all quality software be.
 
-All of the software was either written by or donated to Tom St Denis for the purposes
-of this project.  The only exception is the SAFER.C source which has no known
-license status (assumed copyrighted) which is why SAFER,C is shipped as disabled.
-
 Tom St Denis
 
 
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..ea9abbb
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,259 @@
+# MAKEFILE for linux GCC
+#
+# Tom St Denis
+# Modified by Clay Culver
+
+# The version
+VERSION=1.02
+
+VPATH=@srcdir@
+srcdir=@srcdir@
+
+# Compiler and Linker Names
+#CC=gcc
+#LD=ld
+
+# Archiver [makes .a files]
+#AR=ar
+#ARFLAGS=r
+
+# Compilation flags. Note the += does not write over the user's CFLAGS!
+# The rest of the flags come from the parent Dropbear makefile
+CFLAGS += -c -I$(srcdir)/src/headers/ -I$(srcdir)/../
+
+# additional warnings (newer GCC 3.4 and higher)
+#CFLAGS += -Wsystem-headers -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wmissing-prototypes \
+#		  -Wmissing-declarations -Wpointer-arith 
+
+# optimize for SPEED
+#CFLAGS += -O3 -funroll-loops
+
+# add -fomit-frame-pointer.  hinders debugging!
+CFLAGS += -fomit-frame-pointer
+
+# optimize for SIZE
+#CFLAGS += -Os -DLTC_SMALL_CODE
+
+# older GCCs can't handle the "rotate with immediate" ROLc/RORc/etc macros
+# define this to help
+#CFLAGS += -DLTC_NO_ROLC
+
+# compile for DEBUGING (required for ccmalloc checking!!!)
+#CFLAGS += -g3 -DLTC_NO_ASM
+
+#Output filenames for various targets.
+LIBNAME=libtomcrypt.a
+LIBTEST=testprof/libtomcrypt_prof.a
+HASH=hashsum
+CRYPT=encrypt
+SMALL=small
+PROF=x86_prof
+TV=tv_gen
+MULTI=multi
+TIMING=timing
+TEST=test
+
+#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.
+DESTDIR=
+LIBPATH=/usr/lib
+INCPATH=/usr/include
+DATAPATH=/usr/share/doc/libtomcrypt/pdf
+
+#Who do we install as?
+USER=root
+GROUP=wheel
+
+#List of objects to compile.
+
+#Leave MPI built-in or force developer to link against libtommath?
+#MPIOBJECT=src/misc/mpi/mpi.o
+#Dropbear uses libtommath
+MPIOBJECT=
+
+OBJECTS=src/ciphers/aes/aes_enc.o $(MPIOBJECT) src/ciphers/aes/aes.o \
+src/ciphers/blowfish.o src/ciphers/des.o \
+src/ciphers/twofish/twofish.o \
+src/hashes/helper/hash_memory.o src/hashes/helper/hash_memory_multi.o \
+src/hashes/md5.o src/hashes/sha1.o src/hashes/sha2/sha256.o \
+src/hashes/sha2/sha512.o src/hashes/whirl/whirl.o src/mac/hmac/hmac_done.o \
+src/mac/hmac/hmac_file.o src/mac/hmac/hmac_init.o src/mac/hmac/hmac_memory.o \
+src/mac/hmac/hmac_memory_multi.o src/mac/hmac/hmac_process.o src/mac/hmac/hmac_test.o \
+src/misc/base64/base64_decode.o \
+src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crypt/crypt.o \
+src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
+src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher.o \
+src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
+src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
+src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_prng.o \
+src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \
+src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \
+src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \
+src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \
+src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \
+src/misc/error_to_string.o src/misc/mpi/is_prime.o src/misc/mpi/mpi_to_ltc_error.o \
+src/misc/mpi/rand_prime.o src/misc/zeromem.o \
+src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \
+src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \
+src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
+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/ofb/ofb_start.o src/pk/asn1/der/der_decode_integer.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
+
+TESTOBJECTS=demos/test.o
+HASHOBJECTS=demos/hashsum.o
+CRYPTOBJECTS=demos/encrypt.o
+SMALLOBJECTS=demos/small.o
+TVS=demos/tv_gen.o
+MULTIS=demos/multi.o
+TIMINGS=demos/timing.o
+TESTS=demos/test.o
+
+#Files left over from making the crypt.pdf.
+LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind *.out
+
+#Compressed filenames
+COMPRESSED=crypt-$(VERSION).tar.bz2 crypt-$(VERSION).zip
+
+#The default rule for make builds the libtomcrypt library.
+default:library
+
+#ciphers come in two flavours... enc+dec and enc 
+src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+	$(CC) $(CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
+
+#These are the rules to make certain object files.
+src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c
+src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c
+src/pk/ecc/ecc.o: src/pk/ecc/ecc.c src/pk/ecc/ecc_sys.c
+src/pk/dh/dh.o: src/pk/dh/dh.c src/pk/dh/dh_sys.c
+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)
+# Dropbear doesn't want test programs, since it relies on yarrow etc.
+library: $(LIBNAME)
+
+$(LIBTEST): 
+	cd testprof ; CFLAGS="$(CFLAGS)" make 
+
+$(LIBNAME): $(OBJECTS)
+	$(AR) $(ARFLAGS) $@ $(OBJECTS) 
+	$(RANLIB) $(LIBNAME)
+
+#This rule makes the hash program included with libtomcrypt
+hashsum: library $(HASHOBJECTS)
+	$(CC) $(HASHOBJECTS) $(LIBNAME) -o $(HASH) $(WARN)
+
+#makes the crypt program
+crypt: library $(CRYPTOBJECTS)
+	$(CC) $(CRYPTOBJECTS) $(LIBNAME) -o $(CRYPT) $(WARN)
+
+#makes the small program
+small: library $(SMALLOBJECTS)
+	$(CC) $(SMALLOBJECTS) $(LIBNAME) -o $(SMALL) $(WARN)
+	
+tv_gen: library $(TVS)
+	$(CC) $(TVS) $(LIBNAME) $(EXTRALIBS) -o $(TV)
+
+multi: library $(MULTIS)
+	$(CC) $(MULTIS) $(LIBNAME) -o $(MULTI)
+
+timing: library $(TIMINGS)
+	$(CC) $(TIMINGS) $(LIBTEST) $(LIBNAME) -o $(TIMING)
+
+test: library $(TESTS)
+	$(CC) $(TESTS) $(LIBTEST) $(LIBNAME) -o $(TEST)
+
+
+#This rule installs the library and the header files. This must be run
+#as root in order to have a high enough permission to write to the correct
+#directories and to set the owner and group to root.
+install: library docs
+	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
+	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
+	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(DATAPATH)
+	install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
+	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
+	install -g $(GROUP) -o $(USER) doc/crypt.pdf $(DESTDIR)$(DATAPATH)
+
+install_lib: library
+	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)
+
+#This rule cleans the source tree of all compiled code, not including the pdf
+#documentation.
+clean:
+	rm -f `find . -type f | grep "[.]o" | xargs`
+	rm -f `find . -type f | grep "[.]lo"  | xargs`
+	rm -f `find . -type f | grep "[.]a" | xargs`
+	rm -f `find . -type f | grep "[.]la"  | xargs`
+	rm -f `find . -type f | grep "[.]obj" | xargs`
+	rm -f `find . -type f | grep "[.]lib" | xargs`
+	rm -f `find . -type f | grep "[.]exe" | xargs`
+	rm -f `find . -type f | grep "[.]gcda" | xargs`
+	rm -f `find . -type f | grep "[.]gcno" | xargs`
+	rm -f `find . -type f | grep "[.]il" | xargs`
+	rm -f `find . -type f | grep "[.]dyn" | xargs`
+	rm -f `find . -type f | grep "[.]dpi" | xargs`
+	rm -rf `find . -type d | grep "[.]libs" | xargs`
+	rm -f crypt.aux  crypt.dvi  crypt.idx  crypt.ilg  crypt.ind  crypt.log crypt.toc
+	rm -f $(TV) $(PROF) $(SMALL) $(CRYPT) $(HASHSUM) $(MULTI) $(TIMING) $(TEST)
+	rm -rf doc/doxygen
+	rm -f doc/*.pdf
+
+#build the doxy files (requires Doxygen, tetex and patience)
+doxy:
+	doxygen
+	cd doc/doxygen/latex ; make ; mv -f refman.pdf ../../.
+	echo The huge doxygen PDF should be available as doc/refman.pdf
+	
+#This builds the crypt.pdf file. Note that the rm -f *.pdf has been removed
+#from the clean command! This is because most people would like to keep the
+#nice pre-compiled crypt.pdf that comes with libtomcrypt! We only need to
+#delete it if we are rebuilding it.
+docs: crypt.tex
+	rm -f doc/crypt.pdf $(LEFTOVERS)
+	echo "hello" > crypt.ind
+	latex crypt > /dev/null
+	latex crypt > /dev/null
+	makeindex crypt.idx > /dev/null
+	latex crypt > /dev/null
+	dvipdf crypt
+	mv -ivf crypt.pdf doc/crypt.pdf
+	rm -f $(LEFTOVERS)
+
+docdvi: crypt.tex
+	echo hello > crypt.ind
+	latex crypt > /dev/null
+	latex crypt > /dev/null
+	makeindex crypt.idx
+	latex crypt > /dev/null
+
+#zipup the project (take that!)
+no_oops: clean
+	cd .. ; cvs commit 
+
+zipup: no_oops docs
+	cd .. ; rm -rf crypt* libtomcrypt-$(VERSION) ; mkdir libtomcrypt-$(VERSION) ; \
+	cp -R ./libtomcrypt/* ./libtomcrypt-$(VERSION)/ ; \
+	cd libtomcrypt-$(VERSION) ; rm -rf `find . -type d | grep CVS | xargs` ; cd .. ; \
+	tar -cjvf crypt-$(VERSION).tar.bz2 libtomcrypt-$(VERSION) ; \
+	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)
diff --git a/PLAN b/PLAN
deleted file mode 100644
index 71ebc1a..0000000
--- a/PLAN
+++ /dev/null
@@ -1,38 +0,0 @@
-The following functions are marked for removal and/or behavioural change by v1.00 of LibTomCrypt
-
-1.  RSA Support
-
-      rsa_pad, rsa_signpad, rsa_depad, rsa_signdepad, rsa_import, rsa_export
-
-They will be replaced with PKCS #1 compliant OAEP/PSS padding function as early as v0.96
-
-2.  DSA Support
-
-      dsa_import, dsa_export
-
-Will be replaced with suitable DSS [what is the standard?] compliant formats.  Planned for v0.96
-
-3.  Key Ring Support
-  
-      (all)
-
-The entire API will be dropped as early as v0.96.  It was just an experiment and nobody uses it anyways.
-
-4.  Test Harness
- 
-      demos/test.c
-
-The test harness is well overdue for a makeover.  Planned for as early as v0.97
-
-
-Put things in order...
-
-v0.96  -- removed keyring.c and gf.c
-       -- removed LTC RSA padding
-       -- DSS support [whatever this entails]
-       -- Bug fixes/updates to the PKCS/DSS support, should be stable in this release
-
-v0.97  -- Re-written test harness
-       -- More demos in the manual and demos/ directory
-
-... future???
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..f4f0665
--- /dev/null
+++ b/TODO
@@ -0,0 +1,10 @@
+For 1.06
+
+1. export ECC functions globally [e.g. mulmod and the sets]
+   - goal is tv_gen module and test vectors
+2. ASN.1 SET and T61String
+3. phase out DH code [RSA/ECC/DSA is enough]
+4. Some ASN.1 demo programs [for now read the source code!]
+5. Start working towards making the bignum code plugable
+6. Look into other ECC point muls and consider a "precomp" interface 
+7. Add OID for ciphers and PRNGs to their descriptors
diff --git a/ampi.c b/ampi.c
deleted file mode 100644
index 2d015ca..0000000
--- a/ampi.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* Code submitted by Svante Seleborg, cleaned up by Tom St Denis */
-
-#include "mycrypt.h"
-#include <stdarg.h>
-
-#ifdef MPI
-
-mp_err mp_init_multi(mp_int *mp, ...) 
-{
-    mp_err res = MP_OKAY;      /* Assume ok until proven otherwise */
-    int n = 0;                 /* Number of ok inits */
-    mp_int* cur_arg = mp;
-    va_list args;
-
-    va_start(args, mp);        /* init args to next argument from caller */
-    while (cur_arg != NULL) {
-        if (mp_init(cur_arg) != MP_OKAY) {
-            /* Oops - error! Back-track and mp_clear what we already
-               succeeded in init-ing, then return error.
-            */
-            va_list clean_args;
-            cur_arg = mp;
-            va_start(clean_args, mp);
-            while (n--) {
-                mp_clear(cur_arg);
-                cur_arg = va_arg(clean_args, mp_int*);
-            }
-            va_end(clean_args);
-            res = MP_MEM;
-            break;
-        }
-        n++;
-        cur_arg = va_arg(args, mp_int*);
-    }
-    va_end(args);
-    return res;                /* Assumed ok, if error flagged above. */
-}
-
-/*
-    Clear all arguments given, ended by a NULL marker.
-*/
-void mp_clear_multi(mp_int *mp, ...) 
-{
-    mp_int* next_mp = mp;
-    va_list args;
-    va_start(args, mp);
-    while (next_mp != NULL) {
-        mp_clear(next_mp);
-        next_mp = va_arg(args, mp_int*);
-    }
-    va_end(args);
-}
-
-#endif
-
diff --git a/authors b/authors
deleted file mode 100644
index ba4ea6b..0000000
--- a/authors
+++ /dev/null
@@ -1,55 +0,0 @@
-This is a list of people who have contributed [directly or indirectly] to the project
-[in no partcular order].  If you have helped and your name is not here email me at
-tomstdenis@yahoo.com.
-
-
-1) Richard.van.de.Laarschot@ict.nl
-
-   Gave help porting the lib to MSVC particularly pointed out various warnings and errors.
-
-2) Richard Heathfield
-
-   Gave a lot of help concerning valid C portable code.  
-
-3) Ajay K. Agrawal
-
-   Helped port the library to MSVC and spotted a few bugs and errors.
-
-4) Brian Gladman
-
-   Wrote the AES and Serpent code used.  Found a bug in the hash code for certain types of inputs.
-
-5) Svante Seleborg
-
-   Submitted the "ampi.c" code as well as many suggestions on improving the readability of the source code.
-
-6) Clay Culver
-
-   Submitted a fix for "rsa.c" which cleaned up some code.  Submited some other fixes too.  :-)
-   Clay has helped find bugs in various pieces of code including the registry functions, base64 routines 
-   and the make process.  He is also now the primary author of the libtomcrypt reference manual and has plan
-   at making a HTML version.
-
-7) Jason Klapste
-
-   Submitted fixes to the yarrow, hash, make process and test code as well as other subtle bug fixes.  The 
-yarrow code can now default to any cipher/hash that is left after you remove them from a build.
-
-8) Dobes Vandermeer <dobes@smartt.com>
-
-   Submitted HMAC code that worked flawlessly out of the box... good job!  Also submitted a MD4 routine.
-   Submitted some modified DES code that was merged into the code base [using the libtomcrypt API]
-
-9) Wayne Scott (wscott@bitmover.com)
-  
-   Submitted base64 that complies with the RFC standards.  Submitted some ideas to improve the RSA key generation
-   as well.
-   
-10) Sky Schulz (sky@ogn.com)
-
-   Has submitted a set of ideas to improve the library and make it more attractive for professional users.
-   
-11) Mike Frysinger 
-
-   Together with Clay came up with a more "unix friendly" makefile.  Mike Frysinger has been keeping copies of 
-   the library for the Gentoo linux distribution.
\ No newline at end of file
diff --git a/base64.c b/base64.c
deleted file mode 100644
index f2421fe..0000000
--- a/base64.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* compliant base64 code donated by Wayne Scott (wscott@bitmover.com) */
-#include "mycrypt.h"
-
-#ifdef BASE64
-
-static const char *codes = 
-"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-static const unsigned char map[256] = {
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255,  62, 255, 255, 255,  63,
- 52,  53,  54,  55,  56,  57,  58,  59,  60,  61, 255, 255,
-255, 254, 255, 255, 255,   0,   1,   2,   3,   4,   5,   6,
-  7,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,  18,
- 19,  20,  21,  22,  23,  24,  25, 255, 255, 255, 255, 255,
-255,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,
- 37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,
- 49,  50,  51, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-255, 255, 255, 255 };
-
-int base64_encode(const unsigned char *in,  unsigned long len, 
-                        unsigned char *out, unsigned long *outlen)
-{
-   unsigned long i, len2, leven;
-   unsigned char *p;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* valid output size ? */
-   len2 = 4 * ((len + 2) / 3);
-   if (*outlen < len2 + 1) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   p = out;
-   leven = 3*(len / 3);
-   for (i = 0; i < leven; i += 3) {
-       *p++ = codes[(in[0] >> 2) & 0x3F];
-       *p++ = codes[(((in[0] & 3) << 4) + (in[1] >> 4)) & 0x3F];
-       *p++ = codes[(((in[1] & 0xf) << 2) + (in[2] >> 6)) & 0x3F];
-       *p++ = codes[in[2] & 0x3F];
-       in += 3;
-   }
-   /* Pad it if necessary...  */
-   if (i < len) {
-       unsigned a = in[0];
-       unsigned b = (i+1 < len) ? in[1] : 0;
-
-       *p++ = codes[(a >> 2) & 0x3F];
-       *p++ = codes[(((a & 3) << 4) + (b >> 4)) & 0x3F];
-       *p++ = (i+1 < len) ? codes[(((b & 0xf) << 2)) & 0x3F] : '=';
-       *p++ = '=';
-   }
-
-   /* append a NULL byte */
-   *p = '\0';
-
-   /* return ok */
-   *outlen = p - out;
-   return CRYPT_OK;
-}
-
-int base64_decode(const unsigned char *in,  unsigned long len, 
-                        unsigned char *out, unsigned long *outlen)
-{
-   unsigned long t, x, y, z;
-   unsigned char c;
-   int           g;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   g = 3;
-   for (x = y = z = t = 0; x < len; x++) {
-       c = map[in[x]&0xFF];
-       if (c == 255) continue;
-       if (c == 254) { c = 0; g--; }
-       t = (t<<6)|c;
-       if (++y == 4) {
-          if (z + g > *outlen) { 
-             return CRYPT_BUFFER_OVERFLOW; 
-          }
-          out[z++] = (unsigned char)((t>>16)&255);
-          if (g > 1) out[z++] = (unsigned char)((t>>8)&255);
-          if (g > 2) out[z++] = (unsigned char)(t&255);
-          y = t = 0;
-       }
-   }
-   if (y != 0) {
-       return CRYPT_INVALID_PACKET;
-   }
-   *outlen = z;
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/base64_encode.c b/base64_encode.c
deleted file mode 100644
index c322bcc..0000000
--- a/base64_encode.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* compliant base64 code donated by Wayne Scott (wscott@bitmover.com) */
-#include "mycrypt.h"
-
-#ifdef BASE64
-
-static const char *codes = 
-"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-int base64_encode(const unsigned char *in,  unsigned long len, 
-                        unsigned char *out, unsigned long *outlen)
-{
-   unsigned long i, len2, leven;
-   unsigned char *p;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* valid output size ? */
-   len2 = 4 * ((len + 2) / 3);
-   if (*outlen < len2 + 1) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   p = out;
-   leven = 3*(len / 3);
-   for (i = 0; i < leven; i += 3) {
-       *p++ = codes[(in[0] >> 2) & 0x3F];
-       *p++ = codes[(((in[0] & 3) << 4) + (in[1] >> 4)) & 0x3F];
-       *p++ = codes[(((in[1] & 0xf) << 2) + (in[2] >> 6)) & 0x3F];
-       *p++ = codes[in[2] & 0x3F];
-       in += 3;
-   }
-   /* Pad it if necessary...  */
-   if (i < len) {
-       unsigned a = in[0];
-       unsigned b = (i+1 < len) ? in[1] : 0;
-
-       *p++ = codes[(a >> 2) & 0x3F];
-       *p++ = codes[(((a & 3) << 4) + (b >> 4)) & 0x3F];
-       *p++ = (i+1 < len) ? codes[(((b & 0xf) << 2)) & 0x3F] : '=';
-       *p++ = '=';
-   }
-
-   /* append a NULL byte */
-   *p = '\0';
-
-   /* return ok */
-   *outlen = p - out;
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/build.sh b/build.sh
new file mode 100644
index 0000000..a018aac
--- /dev/null
+++ b/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 -j3 -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.5 $   
+# $Date: 2005/06/27 13:04:05 $ 
diff --git a/burn_stack.c b/burn_stack.c
deleted file mode 100644
index 17b1391..0000000
--- a/burn_stack.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-void burn_stack(unsigned long len)
-{
-   unsigned char buf[32];
-   zeromem(buf, sizeof(buf));
-   if (len > (unsigned long)sizeof(buf))
-      burn_stack(len - sizeof(buf));
-}
-
-
diff --git a/cbc_decrypt.c b/cbc_decrypt.c
deleted file mode 100644
index 3f4958a..0000000
--- a/cbc_decrypt.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CBC
-
-int cbc_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_CBC *cbc)
-{
-   int x, err;
-   unsigned char tmp[MAXBLOCKSIZE], tmp2[MAXBLOCKSIZE];
-
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(cbc != NULL);
-
-   /* decrypt the block from ct into tmp */
-   if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
-       return err;
-   }
-   _ARGCHK(cipher_descriptor[cbc->cipher].ecb_decrypt != NULL);
-      
-   /* is blocklen valid? */
-   if (cbc->blocklen < 0 || cbc->blocklen > (int)sizeof(cbc->IV)) {
-      return CRYPT_INVALID_ARG;
-   } 
-
-   /* decrypt and xor IV against the plaintext of the previous step */
-   cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key);
-   for (x = 0; x < cbc->blocklen; x++) { 
-       /* copy CT in case ct == pt */
-       tmp2[x] = ct[x]; 
-
-       /* actually decrypt the byte */
-       pt[x] = tmp[x] ^ cbc->IV[x]; 
-   }
-
-   /* replace IV with this current ciphertext */ 
-   for (x = 0; x < cbc->blocklen; x++) {
-       cbc->IV[x] = tmp2[x];
-   }
-   #ifdef CLEAN_STACK
-      zeromem(tmp, sizeof(tmp));
-      zeromem(tmp2, sizeof(tmp2));
-   #endif
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/cbc_encrypt.c b/cbc_encrypt.c
deleted file mode 100644
index 8db5b5b..0000000
--- a/cbc_encrypt.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CBC
-
-int cbc_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_CBC *cbc)
-{
-   int x, err;
-   unsigned char tmp[MAXBLOCKSIZE];
-
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(cbc != NULL);
-
-   if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
-       return err;
-   }
-   
-   /* is blocklen valid? */
-   if (cbc->blocklen < 0 || cbc->blocklen > (int)sizeof(cbc->IV)) {
-      return CRYPT_INVALID_ARG;
-   }    
-
-   /* xor IV against plaintext */
-   for (x = 0; x < cbc->blocklen; x++) {
-       tmp[x] = pt[x] ^ cbc->IV[x];
-   }
-
-   /* encrypt */
-   cipher_descriptor[cbc->cipher].ecb_encrypt(tmp, ct, &cbc->key);
-
-   /* store IV [ciphertext] for a future block */
-   for (x = 0; x < cbc->blocklen; x++) {
-       cbc->IV[x] = ct[x];
-   }
-
-   #ifdef CLEAN_STACK
-      zeromem(tmp, sizeof(tmp));
-   #endif
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/cbc_getiv.c b/cbc_getiv.c
deleted file mode 100644
index 2443736..0000000
--- a/cbc_getiv.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef CBC
-
-int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc)
-{
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(len != NULL);
-   _ARGCHK(cbc != NULL);
-   if ((unsigned long)cbc->blocklen > *len) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   memcpy(IV, cbc->IV, cbc->blocklen);
-   *len = cbc->blocklen;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/cbc_setiv.c b/cbc_setiv.c
deleted file mode 100644
index 39e1229..0000000
--- a/cbc_setiv.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef CBC
-
-int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc)
-{
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(cbc != NULL);
-   if (len != (unsigned long)cbc->blocklen) {
-      return CRYPT_INVALID_ARG;
-   }
-   memcpy(cbc->IV, IV, len);
-   return CRYPT_OK;
-}
-
-#endif 
-
diff --git a/cbc_start.c b/cbc_start.c
deleted file mode 100644
index f0d5fb6..0000000
--- a/cbc_start.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CBC
-
-int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-              int keylen, int num_rounds, symmetric_CBC *cbc)
-{
-   int x, err;
- 
-   _ARGCHK(IV != NULL);
-   _ARGCHK(key != NULL);
-   _ARGCHK(cbc != NULL);
-
-   /* bad param? */
-   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* setup cipher */
-   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cbc->key)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* copy IV */
-   cbc->blocklen = cipher_descriptor[cipher].block_length;
-   cbc->cipher   = cipher;
-   for (x = 0; x < cbc->blocklen; x++) {
-       cbc->IV[x] = IV[x];
-   }
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/cfb_getiv.c b/cfb_getiv.c
deleted file mode 100644
index f24866f..0000000
--- a/cfb_getiv.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef CFB
-
-int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb)
-{
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(len != NULL);
-   _ARGCHK(cfb != NULL);
-   if ((unsigned long)cfb->blocklen > *len) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   memcpy(IV, cfb->IV, cfb->blocklen);
-   *len = cfb->blocklen;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/cfb_setiv.c b/cfb_setiv.c
deleted file mode 100644
index ddbbe59..0000000
--- a/cfb_setiv.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef CFB
-
-int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb)
-{
-   int err;
-   
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(cfb != NULL);
-
-   if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
-       return err;
-   }
-   
-   if (len != (unsigned long)cfb->blocklen) {
-      return CRYPT_INVALID_ARG;
-   }
-      
-   /* force next block */
-   cfb->padlen = 0;
-   cipher_descriptor[cfb->cipher].ecb_encrypt(IV, cfb->IV, &cfb->key);
-
-   return CRYPT_OK;
-}
-
-#endif 
-
diff --git a/cfb_start.c b/cfb_start.c
deleted file mode 100644
index d471412..0000000
--- a/cfb_start.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CFB
-
-int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-              int keylen, int num_rounds, symmetric_CFB *cfb)
-{
-   int x, err;
-
-   _ARGCHK(IV != NULL);
-   _ARGCHK(key != NULL);
-   _ARGCHK(cfb != NULL);
-
-   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
-      return err;
-   }
-   
-
-   /* copy data */
-   cfb->cipher = cipher;
-   cfb->blocklen = cipher_descriptor[cipher].block_length;
-   for (x = 0; x < cfb->blocklen; x++)
-       cfb->IV[x] = IV[x];
-
-   /* init the cipher */
-   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* encrypt the IV */
-   cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);
-   cfb->padlen = 0;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/changes b/changes
index 873eca9..65ccd16 100644
--- a/changes
+++ b/changes
@@ -1,10 +1,349 @@
+June 27th, 2005
+v1.05
+      -- Added Technote #6 which covers the current PK compliance.  
+      -- Fixed buffer overflow in OAEP decoder
+      -- Added CHOICE to the list of ASN.1 types
+      -- Added UTCTIME to the list of ASN.1 types
+      -- Added MUTEX locks around descriptor table functions [but not on the functions that are dependent on them]
+         All functions call *_is_valid() before using a descriptor index which means the respective table must be unlocked before 
+         it can be accessed.  However, during the operation [e.g. CCM] if the descriptor has been altered the results will be 
+         undefined.  
+      -- Minor updates to the manual to reflect recent changes
+      -- Added a catch to for an error that should never come up in rsa_exptmod().  Just being thorough.
+
+June 15th, 2005
+v1.04
+      -- Fixed off by one [bit] error in dsa_make_key() it was too high by one bit [not a security problem just inconsistent]
+      -- ECC-224 curve was wrong [it was an ok curve just not NIST, so no security flaw just interoperability].
+      -- Removed point compression since it slows down ECC ops to save a measly couple bytes.
+         This makes the ecc export format incompatible with 1.03 [it shouldn't change in the future]
+      -- Removed ECC-160 from timing and added the other curves
+
+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()
+      -- "pt/ct" can now be NULL in gcm_process() if you are processing zero bytes
+      -- Optimized GCM by removing the "double copy" handling of the plaintext/aad
+      -- Richard Outerbridge pointed out that x86_prof won't build on MACOS and that the manual 
+         erroneously refers to "mycrypt" all over the place.  Fixed.
+
+April 17th, 2005
+v1.01
+       ** Secure Science Corporation has supported this release cycle by sponsoring the development time taken.  Their 
+          continuing support of this project has helped me maintain a steady pace in order to keep LibTomCrypt up to date,
+          stable and more efficient.
+       -----------------------------------------------------------------------------------------------------
+       -- Updated base64_decode.c so if there are more than 3 '=' signs it would stop parsing
+       -- Merged in latest mpi that fixed a few bugs here and there
+       -- Updated OAEP encoder/decoder to catch when the hash output is too large
+          Cleaned up PSS code too
+       -- Andy Bontoft fixed a bug in my demos/tests/makefile.msvc ... seems "dsa_test.c" isn't an object
+          afterall.  Thanks.
+       -- Made invalid ECC key sizes (configuration) not hard fault the program (it returns an error code now)
+       -- SAFER has been re-enabled after I was pointed to http://www.ciphersbyritter.com/NEWS2/95032301.HTM
+          [Mark Kotiaho]
+       -- Added CCM mode to the encauth list (now has EAX, OCB and CCM, c'est un treo magnifique!)
+       -- Added missing ASN.1 header to the RSA keys ... oops... now the rsa_export/import are FULLY compatible
+          with other libs like OpenSSL (comment:  Test vectors would go a long way RSA...)
+       -- Manually merged in fix to the prime_random_ex() LTM function that ensures the 2nd MSB is set properly.  Now
+          When you say "I want a 1024/8 byte RSA key" the MSB bit of the modulus is set as expected.  Note I generally 
+          don't view this as a "huge issue" but it's just one less nit to worry about. [Bryan Klisch]
+       -- A new CVS has been setup on my Athlon64 box... if you want developer access send me an email (and at this point the email would have to be awesome).
+       -- Updated API for ECB and CBC shell code.  Now can process N whole blocks in one call (like $DEITY intended)
+       -- Introduced a new "hardware accel" framework that can be used to speed up cipher ECB, CBC and CTR mode
+          calls.  Later on dependent code (e.g. OMAC, CCM) will be re-written to use the generic cbc/ctr functions.  But now
+          if you [say] call ctr_encrypt() with a cipher descriptor that has hardware CTR it will automatically
+          be used (e.g. no code rewrites)
+       -- Now ships with 20% more love.
+       -- x86_prof now uses ECB shell code (hint: accelerators) and outputs cycles per BLOCK not byte.  This will make it a bit 
+          easier to compare hardware vs. software cipher implementations.  It also emits timings for CBC and CTR modes
+       -- [Peter LaDow] fixed a typo w.r.t. XREALLOC macro (spelling counts kids!)
+       -- Fixed bug with __x86_64__ where ROL64/ROR64 with LTC_NO_ROLC would be the 32-bit versions instead...
+       -- Shipping with preliminary GCM code (disabled).  It's buggy (stack overflow hidden somewhere).  If anyone can spot it let me know.
+       -- Added Pelican MAC [it's an AES based fast MAC] to the list of supported MACs
+       -- Added LTC_FAST [and you can disable by defining LTC_NO_FAST] so that CBC and CTR mode XOR whole words [e.g. 32 or 64 bits] at a time
+          instead of one byte.  On my AMD64 this reduced the overhead for AES-128-CBC from 4.56 cycles/byte to around 1 cycle/byte.  This requires
+          that you either allow unaligned read/writes [e.g. x86_32/x86_64] or align all your data.  It won't go out of it's way to ensure 
+          aligned access.  Only enabled for x86_* platforms by default since they allow unaligned read/writes.
+       -- Added LTC_FAST support to PMAC (drops the cycle/byte by about 9 cycles on my AMD64) [note: I later rewrote this prior to release]
+       -- Updated "profiled" target to work with the new directory layout
+       -- Added [demo only] optimized RC5-CTR code to x86_prof demo to show off how to make an accelerator
+          [This has been removed prior to release... It may re-appear later]
+       -- Added CCM acelerator callbacks to the list [now supports ECB, CTR, CBC and now CCM].
+       -- Added chapter to manual about accelerators (you know you want it)
+       -- Added "bswap" optimizations to x86 LOAD/STORE with big endian.  Can be disabled by defining LTC_NO_BSWAP
+       -- LTC_NO_ASM is now the official "disable all non-portable stuff" macro.  When defined it will make the code endian-neutral,
+          disable any form of ASM and disable LTC_FAST load/stores.  Essentially build the library with this defined if you're having
+          trouble building the library (old GCCs for instance dislike the ROLc macro)
+       -- Added tomcrypt_mac.h and moved MAC/encMAC functions from tomcrypt_hash.h into it
+       -- Added "done" function to ciphers and the five chaining modes [and things like omac/pmac/etc]
+       -- Changed install group to "wheel" from "root".
+       -- Replaced // comments with /**/ so it will build on older UNIX-like platforms
+       -- x86_prof builds and runs with IntelCC fine now 
+       -- Added "stest" build to intel CC to test static linked from within the dir (so you don't have to install to test)
+       -- Moved testing/benchmark into testprof directory and build it as part of the build.  Now you can link against libtomcrypt_prof.a to get 
+          testing info (hint: hardware developers ;-) )
+       -- Added CCM to tv_gen 
+       -- Added demos to MSVC makefile
+       -- Removed -funroll-all-loops from GCC makefile and replaced with -funroll-loops which is a bit more sane (P4 ain't got much cache for the IDATA)
+       -- Fixed GCM prior to release and re-enabled it.  It has not been optimized but it does conform when compiled with optimizations.
+       -- I've since optimized GCM and CCM.  They're close in speed but GCM is more flexible imho (though EAX is more flexible than both)
+       -- For kicks I optimized the ECC code to use projective points.  Gets between 3.21x (Prescott P4) to 4.53x (AMD64) times faster than before at 160-bit keys and the
+          speedup grows as the keysize grows.  Basically removing most practical reasons to "not use the ECC code".  Enjoy.
+       -- Added LTC_FAST support to OMAC/PMAC and doubled it's speed on my amd64 [faster on the P4 too I guess]
+       -- Added GCM to tv_gen
+       -- Removed "makefile.cygwin_dll" as it's not really used by anyone and not worth the effort (hell I hardly maintain the MSVC makefiles ...)
+       -- Updated a few files in the "misc" directory to have correct @file comments for doxygen
+       -- Removed "profile" target since it was slower anyways (go figure...)
+
+December 31st, 2004
+v1.00  
+       -- Added "r,s == 0" check to dsa_verify_hash()
+       -- Added "multi block" helpers for hash, hmac, pmac and omac routines so you can process multiple non-adjacent
+          blocks of data with one call (added demos/multi.c to make sure they work)
+          -- Note these are not documented but they do have doxygen comments inside them
+          -- Also I don't use them in other functions (like pkcs_5_2()) because I didn't have the time.  Job for the new LTC maintainer ;-)
+       -- Added tweaked Anubis test vectors and made it default (undefined ANUBIS_TWEAK to get original Anubis)
+       -- Merged in fix for mp_prime_random_ex() to deal with MSB and LSB "bugs"
+       -- Removed tim_exptmod() completely, updated several RSA functions (notably v15 and the decrypt/verify) so they 
+          don't require a prng now
+       -- This release brought to you by the fine tunes of Macy Gray.  We miss you.
+
+December 23rd, 2004
+v1.00rc1
+       -- Renamed "mycrypt_*" to "tomcrypt_*" to be more specific and professional
+          Now just include "tomcrypt.h" instead of "mycrypt.h" to get LTC ;-)
+       -- Cleaned up makefiles to ensure all headers are correctly installed
+       -- Added "rotate by constant" macros for portable, x86-32 and x86-64
+          You can disable this new code with LTC_NO_ROLC which is useful for older GCCs
+       -- Cleaned up detection of x86-64 so it works for ROL/ROR macros
+       -- Fixed rsa_import() so that it would detect multi-prime RSA keys and error appropriately
+       -- Sorted the source files by category and updated the makefiles appropriately
+       -- Added LTC_DER define so you can trim out DER code if not required
+       -- Fixed up RSA's decrypt functions changing "res" to "stat" to be more in sync
+          with the signature variables nomenclature. (no code change just renamed the arguments)
+       -- Removed all labels starting with __ and replaced with LBL_ to avoid namespace conflicts (Randy Howard)
+       -- Merged in LTM fix to mp_prime_random_ex() which zap'ed the most significant byte if the bit size
+          requested was a multiple of eight.
+       -- Made RSA_TIMING off by default as it's not terribly useful [and likely to be deprecated]
+       -- Renamed SMALL_CODE, CLEAN_STACK and NO_FILE to have a LTC_ prefix to avoid namespace collisions
+          with other programs.  e.g. SMALL_CODE => LTC_SMALL_CODE
+       -- Zed Shaw pointed out that on certain systems installing libs as "root" isn't possible as the super-user
+          is not root.  Now the makefiles allow this to be changed easily.
+       -- Renamed "struct _*_descriptor" to "struct ltc_*_descriptor" to avoid using a leading _
+          Also renamed _ARGCHK to LTC_ARGCHK
+       -- Zed Shaw pointed out that I still defined the prng structs in tomcrypt_prng.h even if they 
+          weren't defined.  This made undef'ing FORTUNA break the build.
+       -- Added LTC_NO_ASM to disable inline asm macros [ROL/ROR/etc]
+       -- Changed RSA decrypt functions to change the output length variable name from "keylen" to "outlen" to make 
+          it more consistent.
+       -- Added the 64-bit Khazad block cipher [NESSIE]
+       -- Added the 128-bit Anubis block cipher [with key support for 128...320 bit keys] [NESSIE]
+       -- Changes to several MAC functions to rename input arguments to more sensible names
+       -- Removed FAST_PK support from dh_sys.c
+       -- Declared deskey() from des.c as static instead of a global
+       -- Added pretty much all practical GCC warning tests to the GCC [related] makefiles.  These additional
+          warnings can easily be disabled for those with older copies of GCC [or even non GNU cc's]
+       -- Added doxygen @ tags to the code...  phew that was a hell of a lot of [repetitive] work
+       -- Also added pre-configured Doxygen script.
+       -- Cleaned up quite a few functions [ciphers, pk, etc] to make the parameters naming style consistent
+          E.g. ciphers keys are called "skey" consistently now.  The input to PK encryption is called "in", etc.
+          These changes require no code changes on the behalf of developers fortunately
+       -- Started a SAFER+ optimizer [does encrypt only] which shaves a good 30 or so cycles/byte on my AMD64
+          at an expense of huge code.  It's in notes/etc/saferp_optimizer.c
+       -- DSA sign/verify now uses DER encoded output/inputs and no LTC style headers.  
+       -- Matt Johnston found a missing semi-colon in mp_exptmod().  Fix has been merged in.  
+
+October 29th, 2004
+v0.99  -- Merged in the latest version of LTM which includes all of the recent bug fixes
+       -- Deprecated LTMSSE and removed it (to be replaced with TFM later on)
+       -- Stefan Arentz pointed out that mp_s_rmap should be extern
+       -- Kristian Gjøsteen pointed out that there are typos in the 
+          "test" makefile and minor issues in Yarrow and Sober [just cosmetics really]
+       -- Matthew P. Cashdollar pointed out that "export" is a C++ keyword 
+          so changed the PRNG api to use "pexport" and "pimport"
+       -- Updated "hashsum" demo so it builds ;-)
+       -- Added automatic support for x86-64 (will configure for 64-bit little endian automagically)
+       -- Zhi Chen pointed out a bug in rsa_exptmod which would leak memory on error. 
+       -- Made hash functions "init" return an int.  slight change to API ;-(
+       -- Added "CHC" mode which turns any cipher into a hash the other LTC functions can use
+       -- Added CHC mode stuff to demos such as tv_gen and hashsum
+       -- Added "makefile.shared" which builds and installs shared/static object copies
+          of the library.
+       -- Added DER for bignum support 
+       -- RSA is now fully joy.  rsa_export/rsa_import use PKCS #1 encodings and should be 
+          compatible with other crypto libs that use the format.
+       -- Added support for x86-64 for the ROL/ROR macros 
+       -- Changed the DLL and SO makefiles to optimize for speed, commented SMALL_CODE in
+          mycrypt_custom.h and added -DSMALL_CODE to the default makefile
+       -- Updated primality testing code so it does a minimum of 5 tests [of Miller-Rabin]
+          (AFAIK not a security fix, just warm fuzzies)
+       -- Minor updates to the OMAC code (additional __ARGCHK and removed printf from omac_test... oops!)
+       -- Update build and configuration info which was really really really out of date.  (Chapter 14)
+       ++ Minor update, switch RSA to use the PKCS style CRT
+
+August 6th, 2004
+v0.98  -- Update to hmac_init to free all allocated memory on error
+       -- Update to PRNG API to fix import/export functions of Fortuna and Yarrow
+       -- Added test functions to PRNG api, RC4 now conforms ;-) [was a minor issue]
+       -- Added the SOBER-128 PRNG based off of code donated by Greg Rose.
+       -- Added Tech Note #4 [notes/tech0004.txt] 
+       -- Changed RC4 back [due to request].  It will now XOR the output so you can use it like 
+          a stream cipher easily.
+       -- Update Fortuna's export() to emit a hash of each pool.  This means that the accumulated 
+          entropy that was spread over all the pools isn't entirely lost when you export/import.
+       -- Zhi Chen suggested a comment for rsa_encrypt_key() to let users know [easily] that it was
+          PKCS #1 v2.0 padding.  (updated other rsa_* functions)
+       -- Cleaned up Noekeon to remove unrolling [wasn't required, was messy and actually slower with GCC/ICC]
+       -- Updated RC4 so that when you feed it >256 bytes of entropy it quietly ignores additional
+          bytes.  Also removed the % from the key setup to speed it up a bit.
+       -- Added cipher/hash/prng tests to x86_prof to help catch bugs while testing
+       -- Made the PRNG "done" return int, fixed sprng_done to not require prng* to be non-null
+       -- Spruced up mycrypt_custom.h to trap more errors and also help prevent LTMSSE from being defined
+          on non-i386 platforms by accident.
+       -- Added RSA/ECC/DH speed tests to x86_prof and cleaned it up to build with zero warnings
+       -- Changed Fortuna to count only entropy [not the 2 byte header] added to pool[0] into the 
+          reseed mechanism.  
+       -- Added "export_size" member to prng_descriptor tables so you can know in advance the size of 
+          the exported state for any given PRNG.  
+       -- Ported over patch on LTM 0.30 [not ready to release LTM 0.31] that fixes bug in mp_mul()/mp_div()
+          that used to result in negative zeroes when you multiplied zero by a negative integer.  
+          (patch due to "Wolfgang Ehrhardt" <Wolfgang.Ehrhardt@munich.netsurf.de>)
+       -- Fixed rsa_*decrypt_key() and rsa_*verify_hash() to default to invalid "stat" or "res".  This way
+          if any of the higher level functions fail [before you get to the padding] the result will be in
+          a known state].  Applied to both v2 and v1.5 padding helpers.
+       -- Added MACs to x86_prof
+       -- Fixed up "warnings" in x86_prof and tv_gen
+       -- Added a "profiled" target back [for GCC 3.4 and ICC v8].  Doesn't seem to help but might be worth
+          tinkering with.
+       -- Beefed up load/store test in demos/test
+
+       ++ New note, in order to use the optimized LOAD/STORE macros your platform
+          must support unaligned 32/64 bit load/stores.  The x86s support this
+          but some [ARM for instance] do not.  If your platform cannot perform
+          unaligned operations you must use the endian neutral code which is safe for 
+          any sort of platform.
+
+July 23rd, 2004
+v0.97b -- Added PKCS #1 v1.5 RSA encrypt/sign helpers (like rsa_sign_hash, etc...)
+       -- Added missing prng check to rsa_decrypt_key() [not critical as I don't use 
+          descriptors directly in that function]
+       -- Merged in LTM-SSE, define LTMSSE before you build and you will get SSE2 optimized math ;-)
+          (roughly 3x faster on a P4 Northwood).  By default it will compile as ISO C portable
+          code (when LTMSSE is undefined).
+       -- Fixed bug in ltc_tommath.h where I had the kara/toom cutoffs not marked as ``extern''
+          Thanks to "Stefan Arentz" <stefan at organicnetwork.net>
+       -- Steven Dake <scd@broked.org> and Richard Amacker <ramacker@yahoo.com> submitted patches to 
+          fix pkcs_5_2().  It now matches the output of another crypto library.  Whoops... hehehe
+       -- Updated PRNG api.  Added Fortuna PRNG to the list of supported PRNGs
+       -- Fixed up the descriptor tables since globals are automatically zero'ed on startup.
+       -- Changed RC4 to store it's output.  If you want to encrypt with RC4
+          you'll have to do the XOR yourself.
+       -- Fixed buffer overflows/overruns in the HMAC code.  
+
+       ++ API change for the PRNGs there now is a done() function per PRNG.  You
+          should call it when you are done with a prng state.  So far it's
+          not absolutely required (won't cause problems) but is a good idea to
+          start.  
+
+
+June 23rd, 2004
+v0.97a ++ Fixed several potentially crippling bugs... [read on]
+       -- Fixed bug in OAEP decoder that would incorrectly report 
+          buffer overflows. [Zhi Chen]
+       -- Fixed headers which had various C++ missing [extern "C"]'s
+       -- Added "extern" to sha384_desc descriptor which I removed by mistake
+       -- Fixed bugs in ENDIAN_BIG macros using the wrong byte order [Matt Johnston]
+       -- Updated tiger.c and des.c to not shadow "round" which is intrinsic on
+          some C compilers.
+       -- Updated demos/test/rsa_test.c to test the RSA functionality better
+       ++ This update has been tested with GCC [v3.3.3], ICC [v8] and MSVC [v6+SP6] 
+          all on a x86 P4  [GCC/ICC tested in Gentoo Linux, MSVC in WinXP]
+       ++ Outcome: The bug Zhi Chen pointed out has been fixed.  So have the bugs
+          that Matt Johnston found.  
+
+June 19th, 2004
+v0.97  -- Removed spurious unused files [arrg!]
+       -- Patched buffer overflow in tim_exptmod()
+       -- Fixed buffer overrun bug in pkcs_1_v15_es_decode()
+       -- Reduced stack usage in PKCS #1 v2.0 padding functions (by several KBs)
+       -- Removed useless extern's that were an artifact from the project start... ;-)
+       -- Replaced memcpy/memset with XMEMCPY and XMEMSET for greater flexibility
+       -- fixed bugs in hmac_done()/hmac_init()/[various others()] where I didn't trap errors 
+       -- Reduced stack usage in OMAC/PMAC/HMAC/EAX/OCB/PKCS#5 by mallocing any significant sized
+          arrays (e.g. > 100 bytes or so).  Only in non-critical functions (e.g. eax_init())
+       -- "Zhi Chen" <zhi@massiveincorporated.com> pointed out that rsa_decrypt_key() requires
+          an incorrect output size (too large).  Fixed.
+       -- Added a "pretty" target to the GCC makefile.  Requires PERL.  It is NEAT!
+       -- Minor updates to ch1 of the manual.
+       -- Cleaned up the indentation and added comments to rsa_make_key(), rsa_exptmod() and 
+          rsa_verify_hash()
+       -- Updated makefile.icc so the "install" target would work ;-)
+       -- Removed demos/test.c [deprecated from demos/test/test.c]
+       -- Changed MAXBLOCKSIZE from 128 to 64 to reflect the true size...
+
 May 30th, 2004
 v0.96  -- Removed GF and Keyring code
        -- Extended OAEP decoder to distinguish better [and use a more uniform API]
        -- Changed PSS/OAEP API slightly to be more consistent with other PK functions (order of arguments)
        -- rsa_exptmod() now pads with leading zeroes as per I2OSP.
        -- added error checking to yarrow code
-       -- Mike Frysinger pointed out that tommath.h from this distro will overwrite tommath.h
+       --  pointed out that tommath.h from this distro will overwrite tommath.h
           from libtommath.  I changed this to ltc_tommath.h to avoid any such problems.
        -- Fixed bug in PSS encoder/decoder that didn't handle the MSB properly
        -- refactored AES, now sports an "encrypt only" descriptor which uses half as much code space.
@@ -980,3 +1319,8 @@
        -- Added more to the manual.
 
 v0.01  -- We will call this the first version.
+
+/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
+/* $Revision: 1.106 $ */
+/* $Date: 2005/06/27 12:37:06 $ */
+
diff --git a/crypt.tex b/crypt.tex
index b991721..cf1c37e 100644
--- a/crypt.tex
+++ b/crypt.tex
@@ -1,4 +1,4 @@
-\documentclass[b5paper]{book}
+\documentclass[a4paper]{book}
 \usepackage{hyperref}
 \usepackage{makeidx}
 \usepackage{amssymb}
@@ -47,22 +47,17 @@
 \def\gap{\vspace{0.5ex}}
 \makeindex
 \begin{document}
-\title{A Tiny Crypto Library, \\ LibTomCrypt \\ Version 0.96}
+\title{LibTomCrypt \\ Version 1.05}
 \author{Tom St Denis \\
 \\
-tomstdenis@iahu.ca \\
-http://libtomcrypt.org \\ \\
-Phone: 1-613-836-3160\\
-111 Banning Rd \\
-Kanata, Ontario \\
-K2L 1C3 \\
-Canada
+tomstdenis@gmail.com \\
+http://libtomcrypt.org
 }
 \maketitle
 This text and source code library are both hereby placed in the public domain.  This book has been 
-formatted for B5 [176x250] paper using the \LaTeX{} {\em book} macro package.
+formatted for A4 paper using the \LaTeX{} {\em book} macro package.
 
-\vspace{10cm}
+\vspace{15cm}
 
 \begin{flushright}Open Source.  Open Academia.  Open Minds.
 
@@ -70,62 +65,36 @@
 
 Tom St Denis,
 
-Ontario, Canada
+Phone: 1-613-836-3160
+
+111 Banning Rd 
+
+Kanata, Ontario 
+
+K2L 1C3 
+
+Canada
 \end{flushright}
 \newpage
 \tableofcontents
 \chapter{Introduction}
 \section{What is the LibTomCrypt?}
-LibTomCrypt is a portable ANSI C cryptographic library that supports symmetric ciphers, one-way hashes, 
-pseudo-random number generators, public key cryptography (via RSA,DH or ECC/DH) and a plethora of support 
-routines.  It is designed to compile out of the box with the GNU C Compiler (GCC) version 2.95.3 (and higher) 
-and with MSVC version 6 in win32.
+LibTomCrypt is a portable ISO C cryptographic library that is meant to be a toolset for cryptographers who are 
+designing a cryptosystem.  It supports symmetric ciphers, one-way hashes, pseudo-random number generators, 
+public key cryptography (via PKCS \#1 RSA, DH or ECCDH) and a plethora of support 
+routines.  
 
-The library has been successfully tested on quite a few other platforms ranging from the ARM7TDMI in a 
-Gameboy Advanced to various PowerPC processors and even the MIPS processor in the PlayStation 2.  Suffice it
-to say the code is portable.
-
-The library is designed so new ciphers/hashes/PRNGs can be added at runtime and the existing API (and helper API functions) will 
-be able to use the new designs automatically.  There exist self-check functions for each cipher and hash to ensure that
-they compile and execute to the published design specifications.  The library also performs extensive parameter error checking
-and will give verbose error messages when possible.
-
-Essentially the library saves the time of having to implement the ciphers, hashes, prngs yourself.  Typically implementing
-useful cryptography is an error prone business which means anything that can save considerable time and effort is a good
-thing.
+The library was designed such that new ciphers/hashes/PRNGs can be added at runtime and the existing API 
+(and helper API functions) are able to use the new designs automatically.  There exists self-check functions for each 
+block cipher and hash function to ensure that they compile and execute to the published design specifications.  The library 
+also performs extensive parameter error checking to prevent any number of runtime exploits or errors.
 
 \subsection{What the library IS for?}
 
-The library typically serves as a basis for other protocols and message formats.  For example, it should be possible to 
-take the RSA routines out of this library, apply the appropriate message padding and get PKCS compliant RSA routines.  
-Similarly SSL protocols could be formed on top  of the low-level symmetric cipher functions.  The goal of this package is 
-to provide these low level core functions in a robust and easy to use fashion.
-
-The library also serves well as a toolkit for applications where they don't need to be OpenPGP, PKCS, etc. compliant.
-Included are fully operational public key routines for encryption, decryption, signature generation and verification.  
-These routines are fully portable but are not conformant to any known set of standards\footnote{With the exception of 
-the RSA code which is based on the PKCS \#1 standards.}.  They are all based on established
-number theory and cryptography.  
-
-\subsection{What the library IS NOT for?}
-
-The library is not designed to be in anyway an implementation of the SSL or OpenPGP standards.  The library 
-is not designed to be compliant with any known form of API or programming hierarchy.  It is not a port of any other 
-library and it is not platform specific (like the MS CSP).  So if you're looking to drop in some buzzword 
-compliant crypto library this is not for you.  The library has been written from scratch to provide basic functions as 
-well as non-standard higher level functions.  
-
-This is not to say that the library is a ``homebrew'' project.  All of the symmetric ciphers and one-way hash functions
-conform to published test vectors.  The public key functions are derived from publicly available material and the majority
-of the code has been reviewed by a growing community of developers.
-
-\subsubsection{Why not?}
-You may be asking why I didn't choose to go all out and support standards like P1363, PKCS and the whole lot.  The reason
-is quite simple too much money gets in the way.  When I tried to access the P1363 draft documents and was denied (it 
-requires a password) I realized that they're just a business anyways.  See what happens is a company will sit down and
-invent a ``standard''.  Then they try to sell it to as many people as they can.  All of a sudden this ``standard'' is 
-everywhere.  Then the standard is updated every so often to keep people dependent.  Then you become RSA.  If people are 
-supposed to support these standards they had better make them more accessible.
+The library serves as a toolkit for developers who have to solve cryptographic problems.  Out of the box LibTomCrypt
+does not process SSL or OpenPGP messages, it doesn't read x.591 certificates or write PEM encoded data.  It does, however,
+provide all of the tools required to build such functionality.  LibTomCrypt was designed to be a flexible library that 
+was not tied to any particular cryptographic problem.  
 
 \section{Why did I write it?}
 You may be wondering, ``Tom, why did you write a crypto library.  I already have one.''.  Well the reason falls into
@@ -140,24 +109,35 @@
 
 With this library all core functions (ciphers, hashes, prngs) have the {\bf exact} same prototype definition.  They all load
 and store data in a format independent of the platform.  This means if you encrypt with Blowfish on a PPC it should decrypt
-on an x86 with zero problems.  The consistent API also means that if you learn how to use blowfish with my library you 
+on an x86 with zero problems.  The consistent API also means that if you learn how to use Blowfish with my library you 
 know how to use Safer+ or RC6 or Serpent or ... as well.  With all of the core functions there are central descriptor tables 
 that can be used to make a program automatically pick between ciphers, hashes and PRNGs at runtime.  That means your 
 application can support all ciphers/hashes/prngs without changing the source code.
 
+Not only did I strive to make a consistent and simple API to work with but I also strived to make the library
+configurable in terms of its build options.  Out of the box the library will build with any modern version of GCC
+without having to use configure scripts.  This means that the library will work with platforms where development
+tools may be limited (e.g. no autoconf).
+
+On top of making the build simple and the API approachable I've also strived for a reasonably high level of
+robustness and efficiency.  LibTomCrypt traps and returns a series of errors ranging from invalid
+arguments to buffer overflows/overruns.  It is mostly thread safe and has been clocked on various platforms
+with ``cycles per byte'' timings that are comparable (and often favourable) to other libraries such as OpenSSL and
+Crypto++.
+
 \subsection{Modular}
-The LibTomCrypt package has also been written to be very modular.  The block ciphers, one-way hashes and
-pseudo-random number generators (PRNG) are all used within the API through ``descriptor'' tables which 
+The LibTomCrypt package has also been written to be very modular.  The block ciphers, one--way hashes and
+pseudo--random number generators (PRNG) are all used within the API through ``descriptor'' tables which 
 are essentially structures with pointers to functions.  While you can still call particular functions
 directly (\textit{e.g. sha256\_process()}) this descriptor interface allows the developer to customize their
 usage of the library.
 
 For example, consider a hardware platform with a specialized RNG device.  Obviously one would like to tap
-that for the PRNG needs within the library (\textit{e.g. making a RSA key}).  All the developer has todo
+that for the PRNG needs within the library (\textit{e.g. making a RSA key}).  All the developer has to do
 is write a descriptor and the few support routines required for the device.  After that the rest of the 
-API can make use of it without change.  Similiarly imagine a few years down the road when AES2 (\textit{or whatever they call it}) is
-invented.  It can be added to the library and used within applications with zero modifications to the
-end applications provided they are written properly.
+API can make use of it without change.  Similiarly imagine a few years down the road when AES2 
+(\textit{or whatever they call it}) has been invented.  It can be added to the library and used within applications 
+with zero modifications to the end applications provided they are written properly.
 
 This flexibility within the library means it can be used with any combination of primitive algorithms and 
 unlike libraries like OpenSSL is not tied to direct routines.  For instance, in OpenSSL there are CBC block
@@ -167,7 +147,6 @@
 the key setup, ECB decrypt and encrypt and test vector routines.  After that all five chaining mode routines
 can make use of the cipher right away.
 
-
 \section{License}
 
 All of the source code except for the following files have been written by the author or donated to the project
@@ -175,14 +154,12 @@
 
 \begin{enumerate}
    \item rc2.c
-   \item safer.c
 \end{enumerate}
 
-`mpi.c'' was originally written by Michael Fromberger (sting@linguist.dartmouth.edu) but has since been replaced with my LibTomMath
-library.
+`mpi.c'' was originally written by Michael Fromberger (sting@linguist.dartmouth.edu) but has since been replaced with 
+my LibTomMath library which is public domain.
 
-``rc2.c'' is based on publicly available code that is not attributed to a person from the given source.  ``safer.c''
-was written by Richard De Moliner (demoliner@isi.ee.ethz.ch) and is public domain.
+``rc2.c'' is based on publicly available code that is not attributed to a person from the given source.  
 
 The project is hereby released as public domain.
 
@@ -190,33 +167,15 @@
 
 The author (Tom St Denis) is not a patent lawyer so this section is not to be treated as legal advice.  To the best
 of the authors knowledge the only patent related issues within the library are the RC5 and RC6 symmetric block ciphers.  
-They can be removed from a build by simply commenting out the two appropriate lines in the makefile script.  The rest
+They can be removed from a build by simply commenting out the two appropriate lines in ``tomcrypt\_custom.h''.  The rest
 of the ciphers and hashes are patent free or under patents that have since expired.
 
 The RC2 and RC4 symmetric ciphers are not under patents but are under trademark regulations.  This means you can use 
 the ciphers you just can't advertise that you are doing so.  
 
-\section{Building the library}
-
-To build the library on a GCC equipped platform simply type ``make'' at your command prompt.  It will build the library
-file ``libtomcrypt.a''.  
-
-To install the library copy all of the ``.h'' files into your ``\#include'' path and the single libtomcrypt.a file into 
-your library path.
-
-With MSVC you can build the library with ``nmake -f makefile.msvc''.  This will produce a ``tomcrypt.lib'' file which
-is the core library.  Copy the header files into your MSVC include path and the library in the lib path (typically
-under where VC98 is installed).
-
-\section{Building against the library}
-
-In the recent versions the build steps have changed.  The build options are now stored in ``mycrypt\_custom.h'' and
-no longer in the makefile.  If you change a build option in that file you must re-build the library from clean to
-ensure the build is intact.  The perl script ``config.pl'' will help setup the custom header and a custom makefile
-if you want one (the provided ``makefile'' will work with custom configs).
-
 \section{Thanks}
-I would like to give thanks to the following people (in no particular order) for helping me develop this project:
+I would like to give thanks to the following people (in no particular order) for helping me develop this project from
+early on:
 \begin{enumerate}
    \item Richard van de Laarschot
    \item Richard Heathfield
@@ -233,6 +192,9 @@
    \item Christopher Imes
 \end{enumerate}
 
+There have been quite a few other people as well.  Please check the change log to see who else has contributed from
+time to time.
+
 \chapter{The Application Programming Interface (API)}
 \section{Introduction}
 \index{CRYPT\_ERROR} \index{CRYPT\_OK}
@@ -266,24 +228,23 @@
 related issue is if you use the same symmetric cipher, hash or public key state data in multiple threads.  Normally
 that is not an issue.
 
-To include the prototypes for ``LibTomCrypt.a'' into your own program simply include ``mycrypt.h'' like so:
+To include the prototypes for ``LibTomCrypt.a'' into your own program simply include ``tomcrypt.h'' like so:
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void) {
     return 0;
 }
 \end{verbatim}
 
-The header file ``mycrypt.h'' also includes ``stdio.h'', ``string.h'', ``stdlib.h'', ``time.h'', ``ctype.h'' and ``mpi.h''
-(the bignum library routines).
+The header file ``tomcrypt.h'' also includes ``stdio.h'', ``string.h'', ``stdlib.h'', ``time.h'', ``ctype.h'' and 
+``ltc\_tommath.h'' (the bignum library routines).
 
 \section{Macros}
 
 There are a few helper macros to make the coding process a bit easier.  The first set are related to loading and storing
 32/64-bit words in little/big endian format.  The macros are:
 
-\index{STORE32L} \index{STORE64L} \index{LOAD32L} \index{LOAD64L}
-\index{STORE32H} \index{STORE64H} \index{LOAD32H} \index{LOAD64H} \index{BSWAP}
+\index{STORE32L} \index{STORE64L} \index{LOAD32L} \index{LOAD64L} \index{STORE32H} \index{STORE64H} \index{LOAD32H} \index{LOAD64H} \index{BSWAP}
 \begin{small}
 \begin{center}
 \begin{tabular}{|c|c|c|}
@@ -295,18 +256,25 @@
      \hline STORE64H(x, y) & {\bf unsigned long long} x, {\bf unsigned char} *y & $x \to y[7 \ldots 0]$ \\
      \hline LOAD32H(x, y) & {\bf unsigned long} x, {\bf unsigned char} *y & $y[3 \ldots 0] \to x$ \\
      \hline LOAD64H(x, y) & {\bf unsigned long long} x, {\bf unsigned char} *y & $y[7 \ldots 0] \to x$ \\
-     \hline BSWAP(x) & {\bf unsigned long} x & Swaps the byte order of x. \\
+     \hline BSWAP(x) & {\bf unsigned long} x & Swaps byte order (32--bits only) \\
      \hline
 \end{tabular}
 \end{center}
 \end{small}
 
-There are 32-bit cyclic rotations as well:
-\index{ROL} \index{ROR}
+There are 32 and 64-bit cyclic rotations as well:
+\index{ROL} \index{ROR} \index{ROL64} \index{ROR64} \index{ROLc} \index{RORc} \index{ROL64c} \index{ROR64c} 
 \begin{center}
 \begin{tabular}{|c|c|c|}
-     \hline ROL(x, y) & {\bf unsigned long} x, {\bf unsigned long} y & $x << y$ \\
-     \hline ROR(x, y) & {\bf unsigned long} x, {\bf unsigned long} y & $x >> y$ \\
+     \hline ROL(x, y) & {\bf unsigned long} x, {\bf unsigned long} y & $x << y, 0 \le y \le 31$ \\
+     \hline ROLc(x, y) & {\bf unsigned long} x, {\bf const unsigned long} y & $x << y, 0 \le y \le 31$ \\
+     \hline ROR(x, y) & {\bf unsigned long} x, {\bf unsigned long} y & $x >> y, 0 \le y \le 31$ \\
+     \hline RORc(x, y) & {\bf unsigned long} x, {\bf const unsigned long} y & $x >> y, 0 \le y \le 31$ \\
+     \hline && \\
+     \hline ROL64(x, y) & {\bf unsigned long} x, {\bf unsigned long} y & $x << y, 0 \le y \le 63$ \\
+     \hline ROL64c(x, y) & {\bf unsigned long} x, {\bf const unsigned long} y & $x << y, 0 \le y \le 63$ \\
+     \hline ROR64(x, y) & {\bf unsigned long} x, {\bf unsigned long} y & $x >> y, 0 \le y \le 63$ \\
+     \hline ROR64c(x, y) & {\bf unsigned long} x, {\bf const unsigned long} y & $x >> y, 0 \le y \le 63$ \\
      \hline
 \end{tabular}
 \end{center}
@@ -317,14 +285,14 @@
 the output will be stored.  For example:
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void) {
     rsa_key key;
     unsigned char buffer[1024];
     unsigned long x;
     int err;
 
-    /* ... Make up the RSA key somehow */
+    /* ... Make up the RSA key somehow ... */
 
     /* lets export the key, set x to the size of the output buffer */
     x = sizeof(buffer);
@@ -342,13 +310,17 @@
 }
 \end{verbatim}
 \end{small}
-In the above example if the size of the RSA public key was more than 1024 bytes this function would not store anything in
-either ``buffer'' or ``x'' and simply return an error code.  If the function suceeds it stores the length of the output
-back into ``x'' so that the calling application will know how many bytes used.
+In the above example if the size of the RSA public key was more than 1024 bytes this function would return an error code
+indicating a buffer overflow would have occurred.  If the function succeeds it stores the length of the output
+back into ``x'' so that the calling application will know how many bytes were used.
 
 \section{Functions that need a PRNG}
-Certain functions such as ``rsa\_make\_key()'' require a PRNG.  These functions do not setup the PRNG themselves so it is 
-the responsibility of the calling function to initialize the PRNG before calling them.
+\index{Pseudo Random Number Generator} \index{PRNG}
+Certain functions such as ``rsa\_make\_key()'' require a Pseudo Random Number Generator (PRNG).  These functions do not setup 
+the PRNG themselves so it is the responsibility of the calling function to initialize the PRNG before calling them.
+
+Certain PRNG algorithms do not require a ``prng\_state'' argument (sprng for example).  The ``prng\_state'' argument
+may be passed as \textbf{NULL} in such situations.
 
 \section{Functions that use Arrays of Octets}
 Most functions require inputs that are arrays of the data type ``unsigned char''.  Whether it is a symmetric key, IV
@@ -363,14 +335,16 @@
 \chapter{Symmetric Block Ciphers}
 \section{Core Functions}
 
-Libtomcrypt provides several block ciphers all in a plain vanilla ECB block mode.  Its important to first note that you 
+LibTomCrypt provides several block ciphers with an ECB block mode interface.  It's important to first note that you 
 should never use the ECB modes directly to encrypt data.  Instead you should use the ECB functions to make a chaining mode
 or use one of the provided chaining modes.  All of the ciphers are written as ECB interfaces since it allows the rest of
 the API to grow in a modular fashion.
 
+\subsection{Key Scheduling}
 All ciphers store their scheduled keys in a single data type called ``symmetric\_key''.  This allows all ciphers to 
-have the same prototype and store their keys as  naturally as possible.  All ciphers provide five visible functions which
-are (given that XXX is the name of the cipher):
+have the same prototype and store their keys as naturally as possible.  This also removes the need for dynamic memory
+allocation and allows you to allocate a fixed sized buffer for storing scheduled keys.  All ciphers provide five visible 
+functions which are (given that XXX is the name of the cipher):
 \index{Cipher Setup}
 \begin{verbatim}
 int XXX_setup(const unsigned char *key, int keylen, int rounds,
@@ -380,12 +354,13 @@
 The XXX\_setup() routine will setup the cipher to be used with a given number of rounds and a given key length (in bytes).
 The number of rounds can be set to zero to use the default, which is generally a good idea.
 
-If the function returns successfully the variable ``skey'' will have a scheduled key stored in it.  Its important to note
-that you should only used this scheduled key with the intended cipher.  For example, if you call 
-``blowfish\_setup()'' do not pass the scheduled key onto ``rc5\_ecb\_encrypt()''.  All setup functions do not allocate 
-memory off the heap so when you are done with a key you can simply discard it (e.g. they can be on the stack).
+If the function returns successfully the variable ``skey'' will have a scheduled key stored in it.  It's important to note
+that you should only used this scheduled key with the intended cipher.  For example, if you call ``blowfish\_setup()'' do not 
+pass the scheduled key onto ``rc5\_ecb\_encrypt()''.  All setup functions do not allocate memory off the heap so when you are 
+done with a key you can simply discard it (e.g. they can be on the stack).
 
-To encrypt or decrypt a block in ECB mode there are these two functions:
+\subsection{ECB Encryption and Decryption}
+To encrypt or decrypt a block in ECB mode there are these two function classes
 \index{Cipher Encrypt} \index{Cipher Decrypt}
 \begin{verbatim}
 void XXX_ecb_encrypt(const unsigned char *pt, unsigned char *ct,
@@ -396,13 +371,20 @@
 \end{verbatim}
 These two functions will encrypt or decrypt (respectively) a single block of text\footnote{The size of which depends on
 which cipher you are using.} and store the result where you want it.  It is possible that the input and output buffer are 
-the same buffer.  For the encrypt function ``pt''\footnote{pt stands for plaintext.} is the input and ``ct'' is the output.
-For the decryption function its the opposite.  To test a particular cipher against test vectors\footnote{As published in their design papers.} call: \index{Cipher Testing}
+the same buffer.  For the encrypt function ``pt''\footnote{pt stands for plaintext.} is the input and 
+``ct''\footnote{ct stands for ciphertext.} is the output.  For the decryption function it's the opposite.  To test a particular 
+cipher against test vectors\footnote{As published in their design papers.} call the self-test function
+ 
+\subsection{Self--Testing}
+\index{Cipher Testing}
 \begin{verbatim}
 int XXX_test(void);
 \end{verbatim}
 This function will return {\bf CRYPT\_OK} if the cipher matches the test vectors from the design publication it is 
-based upon.  Finally for each cipher there is a function which will help find a desired key size:
+based upon.  
+
+\subsection{Key Sizing}
+For each cipher there is a function which will help find a desired key size:
 \begin{verbatim}
 int XXX_keysize(int *keysize);
 \end{verbatim}
@@ -410,7 +392,7 @@
 return {\bf CRYPT\_OK} if the key size specified is acceptable.  For example:
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int keysize, err;
@@ -426,12 +408,23 @@
 }
 \end{verbatim}
 \end{small}
-This should indicate a keysize of sixteen bytes is suggested.  An example snippet that encodes a block with 
-Blowfish in ECB mode is below.
+This should indicate a keysize of sixteen bytes is suggested.  
+
+\subsection{Cipher Termination}
+When you are finished with a cipher you can de--initialize it with the done function.
+\begin{verbatim}
+void XXX_done(symmetric_key *skey);
+\end{verbatim}
+For the software based ciphers within LibTomCrypt this function will not do anything.  However, user supplied
+cipher descriptors may require calls to it for resource management.  To be compliant all functions which call a cipher
+setup function must also call the respective cipher done function when finished.
+
+\subsection{Simple Encryption Demonstration}
+An example snippet that encodes a block with Blowfish in ECB mode is below.
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 { 
    unsigned char pt[8], ct[8], key[8];
@@ -455,12 +448,19 @@
    blowfish_ecb_encrypt(pt,             /* encrypt this 8-byte array */
                         ct,             /* store encrypted data here */ 
                         &skey);         /* our previously scheduled key */
+                        
+   /* now ct holds the encrypted version of pt */                        
 
    /* decrypt the block */
    blowfish_ecb_decrypt(ct,             /* decrypt this 8-byte array */
                         pt,             /* store decrypted data here */
                         &skey);         /* our previously scheduled key */
 
+   /* now we have decrypted ct to the original plaintext in pt */                        
+
+   /* Terminate the cipher context */
+   blowfish_done(&skey);
+
    return 0;
 }
 \end{verbatim}
@@ -470,7 +470,7 @@
 \index{Symmetric Keys}
 As a general rule of thumb do not use symmetric keys under 80 bits if you can.  Only a few of the ciphers support smaller
 keys (mainly for test vectors anyways).  Ideally your application should be making at least 256 bit keys.  This is not
-because you're supposed to be paranoid.  Its because if your PRNG has a bias of any sort the more bits the better.  For
+because you're supposed to be paranoid.  It's because if your PRNG has a bias of any sort the more bits the better.  For
 example, if you have $\mbox{Pr}\left[X = 1\right] = {1 \over 2} \pm \gamma$ where $\vert \gamma \vert > 0$ then the
 total amount of entropy in N bits is $N \cdot -log_2\left ({1 \over 2} + \vert \gamma \vert \right)$.  So if $\gamma$
 were $0.25$ (a severe bias) a 256-bit string would have about 106 bits of entropy whereas a 128-bit string would have
@@ -478,31 +478,64 @@
 
 The number of rounds of most ciphers is not an option you can change.  Only RC5 allows you to change the number of
 rounds.  By passing zero as the number of rounds all ciphers will use their default number of rounds.  Generally the
-ciphers are configured such that the default number of rounds provide adequate security for the given block size.
+ciphers are configured such that the default number of rounds provide adequate security for the given block and key 
+size.
 
 \section{The Cipher Descriptors}
 \index{Cipher Descriptor}
 To facilitate automatic routines an array of cipher descriptors is provided in the array ``cipher\_descriptor''.  An element
 of this array has the following format:
 
+\begin{small}
 \begin{verbatim}
 struct _cipher_descriptor {
    char *name;
-   unsigned long min_key_length, max_key_length, 
-                 block_length, default_rounds;
-   int  (*setup)      (const unsigned char *key, int keylength, 
-                       int num_rounds, symmetric_key *skey);
-   void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, 
-                       symmetric_key *key);
-   void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt,
-                       symmetric_key *key);
-   int  (*test)       (void);
-   int  (*keysize)    (int *desired_keysize);
+   unsigned char ID;
+   int  min_key_length, 
+        max_key_length, 
+        block_length, 
+        default_rounds;
+   int  (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+   void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+   void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+   int (*test)(void);
+   void (*done)(symmetric_key *skey);      
+   int  (*keysize)(int *keysize);
+
+   void (*accel_ecb_encrypt)(const unsigned char *pt, 
+                                   unsigned char *ct, 
+                                   unsigned long blocks, symmetric_key *skey);
+   void (*accel_ecb_decrypt)(const unsigned char *ct, 
+                                   unsigned char *pt, 
+                                   unsigned long blocks, symmetric_key *skey);
+   void (*accel_cbc_encrypt)(const unsigned char *pt, 
+                                   unsigned char *ct, 
+                                   unsigned long blocks, unsigned char *IV, 
+                                   symmetric_key *skey);
+   void (*accel_cbc_decrypt)(const unsigned char *ct, 
+                                   unsigned char *pt, 
+                                   unsigned long blocks, unsigned char *IV, 
+                                   symmetric_key *skey);
+   void (*accel_ctr_encrypt)(const unsigned char *pt, 
+                                   unsigned char *ct, 
+                                   unsigned long blocks, unsigned char *IV, 
+                                   int mode, symmetric_key *skey);
+   void (*accel_ccm_memory)(
+       const unsigned char *key,    unsigned long keylen,
+       const unsigned char *nonce,  unsigned long noncelen,
+       const unsigned char *header, unsigned long headerlen,
+             unsigned char *pt,     unsigned long ptlen,
+             unsigned char *ct,
+             unsigned char *tag,    unsigned long *taglen,
+                       int  direction);
+
 };
 \end{verbatim}
+\end{small}
 
-Where ``name'' is the lower case ASCII version of the name.  The fields ``min\_key\_length'', ``max\_key\_length'' and
-``block\_length'' are all the number of bytes not bits.  As a good rule of thumb it is assumed that the cipher supports
+Where ``name'' is the lower case ASCII version of the name.  The fields ``min\_key\_length'' and ``max\_key\_length'' 
+are the minimum and maximum key sizes in bytes.  The ``block\_length'' member is the block size of the cipher
+in bytes.  As a good rule of thumb it is assumed that the cipher supports
 the min and max key lengths but not always everything in between.  The ``default\_rounds'' field is the default number
 of rounds that will be used.
 
@@ -522,10 +555,6 @@
      \hline RC5-32/12/b & rc5\_desc & 8 & 8 $\ldots$ 128 & 12 $\ldots$ 24 \\
      \hline RC6-32/20/b & rc6\_desc & 16 & 8 $\ldots$ 128 & 20 \\
      \hline SAFER+ & saferp\_desc &16 & 16, 24, 32 & 8, 12, 16 \\
-     \hline Safer K64   & safer\_k64\_desc & 8 & 8 & 6 $\ldots$ 13 \\
-     \hline Safer SK64  & safer\_sk64\_desc & 8 & 8 & 6 $\ldots$ 13 \\
-     \hline Safer K128  & safer\_k128\_desc & 8 & 16 & 6 $\ldots$ 13 \\
-     \hline Safer SK128 & safer\_sk128\_desc & 8 & 16 & 6 $\ldots$ 13 \\
      \hline AES & aes\_desc & 16 & 16, 24, 32 & 10, 12, 14 \\
                 & aes\_enc\_desc & 16 & 16, 24, 32 & 10, 12, 14 \\
      \hline Twofish & twofish\_desc & 16 & 16, 24, 32 & 16 \\
@@ -534,6 +563,8 @@
      \hline CAST5 (CAST-128) & cast5\_desc & 8 & 5 $\ldots$ 16 & 12, 16 \\
      \hline Noekeon & noekeon\_desc & 16 & 16 & 16 \\
      \hline Skipjack & skipjack\_desc & 8 & 10 & 32 \\
+     \hline Anubis & anubis\_desc & 16 & 16 $\ldots$ 40 & 12 $\ldots$ 18 \\
+     \hline Khazad & khazad\_desc & 8 & 16 & 8 \\
      \hline
 \end{tabular}
 \end{center}
@@ -556,18 +587,13 @@
 Rijndael as it makes the most sense for this cipher.
 
 \item
-For the 64-bit SAFER famliy of ciphers (e.g K64, SK64, K128, SK128) the ecb\_encrypt() and ecb\_decrypt()
-functions are the same.  So if you want to use those functions directly just call safer\_ecb\_encrypt()
-or safer\_ecb\_decrypt() respectively.
-
-\item
 Note that for ``DES'' and ``3DES'' they use 8 and 24 byte keys but only 7 and 21 [respectively] bytes of the keys are in
 fact used for the purposes of encryption.  My suggestion is just to use random 8/24 byte keys instead of trying to make a 8/24
 byte string from the real 7/21 byte key.
 
 \item
 Note that ``Twofish'' has additional configuration options that take place at build time.  These options are found in
-the file ``mycrypt\_cfg.h''.  The first option is ``TWOFISH\_SMALL'' which when defined will force the Twofish code
+the file ``tomcrypt\_cfg.h''.  The first option is ``TWOFISH\_SMALL'' which when defined will force the Twofish code
 to not pre-compute the Twofish ``$g(X)$'' function as a set of four $8 \times 32$ s-boxes.  This means that a scheduled
 key will require less ram but the resulting cipher will be slower.  The second option is ``TWOFISH\_TABLES'' which when
 defined will force the Twofish code to use pre-computed tables for the two s-boxes $q_0, q_1$ as well as the multiplication
@@ -581,9 +607,9 @@
 \begin{tabular}{|l|l|l|}
 \hline TWOFISH\_SMALL & TWOFISH\_TABLES & Speed and Memory (per key) \\
 \hline undefined & undefined & Very fast, 4.2KB of ram. \\
-\hline undefined & defined & As above, faster keysetup, larger code (1KB more). \\
+\hline undefined & defined & Faster keysetup, larger code. \\
 \hline defined & undefined & Very slow, 0.2KB of ram. \\
-\hline defined & defined & Somewhat faster, 0.2KB of ram, larger code. \\
+\hline defined & defined & Faster, 0.2KB of ram, larger code. \\
 \hline
 \end{tabular}
 \end{center}
@@ -601,7 +627,7 @@
 the location in the array where the cipher was found.  For example, to indirectly setup Blowfish you can also use:
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    unsigned char key[8];
@@ -615,7 +641,8 @@
    }
 
    /* generic call to function (assuming the key in key[] was already setup) */
-   if ((err = cipher_descriptor[find_cipher("blowfish")].setup(key, 8, 0, &skey)) != CRYPT_OK) {
+   if ((err = cipher_descriptor[find_cipher("blowfish")].setup(key, 8, 0, &skey)) != 
+       CRYPT_OK) {
       printf("Error setting up Blowfish: %s\n", error_to_string(err));
       return -1;
    }
@@ -641,7 +668,7 @@
 Which returns {\bf CRYPT\_OK} if it removes it otherwise it returns {\bf CRYPT\_ERROR}.  Consider:
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int err;
@@ -739,18 +766,24 @@
 The ECB and CBC modes process blocks of the same size as the cipher at a time.  Therefore they are less flexible than the
 other modes.
 
-\subsection{Implementation}
+\subsection{Initialization}
 \index{CBC Mode} \index{CTR Mode}
 \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}
@@ -762,30 +795,37 @@
 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.  To 
-actually encrypt or decrypt the following routines are provided:
+
+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:
 \index{ecb\_encrypt()} \index{ecb\_decrypt()} \index{cfb\_encrypt()} \index{cfb\_decrypt()} 
 \index{cbc\_encrypt()} \index{cbc\_decrypt()} \index{ofb\_encrypt()} \index{ofb\_decrypt()} \index{ctr\_encrypt()} \index{ctr\_decrypt()}
 \begin{verbatim}
 int XXX_encrypt(const unsigned char *pt, unsigned char *ct, 
-                symmetric_XXX *XXX);
-int XXX_decrypt(const unsigned char *ct, unsigned char *pt,
-                symmetric_XXX *XXX);
-
-int YYY_encrypt(const unsigned char *pt, unsigned char *ct, 
                 unsigned long len, symmetric_YYY *YYY);
-int YYY_decrypt(const unsigned char *ct, unsigned char *pt, 
+int XXX_decrypt(const unsigned char *ct, unsigned char *pt, 
                 unsigned long len, symmetric_YYY *YYY);
 \end{verbatim}
-Where ``XXX'' is one of (ecb, cbc) and ``YYY'' is one of (ctr, ofb, cfb).  In the CTR, OFB and CFB cases ``len'' is the
-size of the buffer (as number of chars) to encrypt or decrypt.  The CTR, OFB and CFB modes are order sensitive but not
+Where ``XXX'' is one of $\lbrace ecb, cbc, ctr, cfb, ofb \rbrace$.  
+
+In all cases ``len'' is the size of the buffer (as number of octets) to encrypt or decrypt.  The CTR, OFB and CFB modes are order sensitive but not
 chunk sensitive.  That is you can encrypt ``ABCDEF'' in three calls like ``AB'', ``CD'', ``EF'' or two like ``ABCDE'' and ``F''
 and end up with the same ciphertext.  However, encrypting ``ABC'' and ``DABC'' will result in different ciphertexts.  All
 five of the modes will return {\bf CRYPT\_OK} on success from the encrypt or decrypt functions.
 
+In the ECB and CBC cases ``len'' must be a multiple of the ciphers block size.  In the CBC case you must manually pad the end of your message (either with
+zeroes or with whatever your protocol requires).
+
 To decrypt in either mode you simply perform the setup like before (recall you have to fetch the IV value you used)
 and use the decrypt routine on all of the blocks.
 
+\subsection{IV Manipulation}
 To change or read the IV of a previously initialized chaining mode use the following two functions.
 
 \index{cbc\_setiv()} \index{cbc\_getiv()} \index{ofb\_setiv()} \index{ofb\_getiv()} \index{cfb\_setiv()} \index{cfb\_getiv()}
@@ -795,16 +835,28 @@
 int XXX_setiv(const unsigned char *IV, unsigned long len, symmetric_XXX *XXX);
 \end{verbatim}
 
-The XXX\_getiv function will read the IV out of the chaining mode and store it into ``IV'' along with the length of the IV 
+The XXX\_getiv() functions will read the IV out of the chaining mode and store it into ``IV'' along with the length of the IV 
 stored in ``len''.  The XXX\_setiv will initialize the chaining mode state as if the original IV were the new IV specified.  The length
 of the IV passed in must be the size of the ciphers block size.
 
-The XXX\_setiv functions are handy if you wish to change the IV without re--keying the cipher.  
+The XXX\_setiv() functions are handy if you wish to change the IV without re--keying the cipher.  
+
+\subsection{Stream Termination}
+To terminate an open stream call the done function.
+
+\index{ecb\_done()} \index{cbc\_done()}\index{cfb\_done()}\index{ofb\_done()} \index{ctr\_done()}
+\begin{verbatim}
+int XXX_done(symmetric_XXX *XXX);
+\end{verbatim}
+
+This will terminate the stream (by terminating the cipher) and return \textbf{CRYPT\_OK} if successful.
+
+\subsection{Examples}
 
 \newpage
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    unsigned char key[16], IV[16], buffer[512];
@@ -820,12 +872,14 @@
    /* somehow fill out key and IV */
 
    /* start up CTR mode */
-   if ((err = ctr_start(find_cipher("twofish"), /* index of desired cipher */
-                                            IV, /* the initial vector */
-                                           key, /* the secret key */
-                                            16, /* length of secret key (16 bytes, 128 bits) */
-                                             0, /* 0 == default # of rounds */
-                                         &ctr)  /* where to store initialized CTR state */
+   if ((err = ctr_start(
+        find_cipher("twofish"), /* index of desired cipher */
+                            IV, /* the initial vector */
+                           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));
       return -1;
@@ -861,6 +915,12 @@
       return -1;
    }
 
+   /* terminate the stream */
+   if ((err = ctr_done(&ctr)) != CRYPT_OK) {
+      printf("ctr_done error: %s\n", error_to_string(err));
+      return -1;
+   }
+
    /* clear up and return */
    zeromem(key, sizeof(key));
    zeromem(&ctr, sizeof(ctr));
@@ -953,7 +1013,7 @@
 This requires that the AES (or Rijndael) block cipher be registered with the cipher\_descriptor table first.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int           err;
@@ -1066,6 +1126,8 @@
 both functions given a single ``ocb'' state.  For bi-directional communication you will have to initialize two ``ocb''
 states (with different nonces).  Also ``pt'' and ``ct'' may point to the same location in memory.
 
+\subsubsection{State Termination}
+
 When you are finished encrypting the message you call the following function to compute the tag.
 
 \index{ocb\_done\_encrypt()}
@@ -1099,6 +1161,7 @@
 ``res'' is set to zero.  If all ``taglen'' bytes of ``tag'' can be verified then ``res'' is set to one (authenticated
 message).
 
+\subsubsection{Packet Functions}
 To make life simpler the following two functions are provided for memory bound OCB.
 
 \index{ocb\_encrypt\_authenticate\_memory()}
@@ -1128,6 +1191,240 @@
 Similarly this will OCB decrypt and compare the internally computed tag against the tag provided. ``res'' is set 
 appropriately.
 
+\subsection{CCM Mode}
+CCM is a NIST proposal for Encrypt+Authenticate that is centered around using AES (or any 16--byte cipher) as a primitive.  Unlike EAX and OCB mode
+it is only meant for ``packet'' mode where the length of the input is known in advance.  Since it is a packet mode function CCM only has one 
+function that performs the protocol.
+
+\index{ccm\_memory()}
+\begin{verbatim}
+int ccm_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+          unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen,
+                    int  direction);
+\end{verbatim}
+
+This performs the ``CCM'' operation on the data.  The ``cipher'' variable indicates which cipher in the descriptor table to use.  It must have a 
+16--byte block size for CCM.  The key is ``key'' with a length of ``keylen'' octets.  The nonce or salt is ``nonce'' of
+length ``noncelen'' octets.  The header is meta--data you want to send with the message but not have encrypted, it is stored in ``header''
+of length ``headerlen'' octets.  The header can be zero octets long (if $headerlen = 0$ then you can pass ``header'' as \textbf{NULL}).  
+
+The plaintext is stored in ``pt'' and the ciphertext in ``ct''.  The length of both are expected to be equal and is passed in as ``ptlen''.  It is
+allowable that $pt = ct$.  The ``direction'' variable indicates whether encryption (direction $=$ \textbf{CCM\_ENCRYPT}) or 
+decryption (direction $=$ \textbf{CCM\_DECRYPT}) is to be performed.
+
+As implemented this copy of CCM cannot handle a header or plaintext longer than $2^{32} - 1$ octets long.  
+
+You can test the implementation of CCM with the following function.
+
+\index{ccm\_test()}
+\begin{verbatim}
+int ccm_test(void);
+\end{verbatim}
+
+This will return \textbf{CRYPT\_OK} if the CCM routine passes known test vectors.
+
+\subsection{GCM Mode}
+Galois counter mode is an IEEE proposal for authenticated encryption.  Like EAX and OCB it can be used in a streaming capacity however, unlike EAX it cannot
+accept ``additional authentication data'' (meta--data) after plaintext has been processed.  This mode also only works with block ciphers with a sixteen
+byte block.
+
+A GCM stream is meant to be processed in three modes each one sequential serial.  First the initial vector (per session) data is processed.  This should be 
+unique to every session.  Next the the optional additional authentication data is processed and finally the plaintext.  
+
+\subsubsection{Initialization}
+To initialize the GCM context with a secret key call the following function.
+
+\index{gcm\_init()}
+\begin{verbatim}
+int gcm_init(gcm_state *gcm, int cipher,
+             const unsigned char *key, int keylen);
+\end{verbatim}
+This initializes the GCM state ``gcm'' for the given cipher indexed by ``cipher'' with a secret key ``key'' of length ``keylen'' octets.  The cipher chosen
+must have a 16--byte block size (e.g. AES).  
+
+\subsubsection{Initial Vector}
+After the state has been initialized (or reset) the next step is to add the session (or packet) initial vector.  It should be unique per packet encrypted.
+
+\index{gcm\_add\_iv()}
+\begin{verbatim}
+int gcm_add_iv(gcm_state *gcm, 
+               const unsigned char *IV,     unsigned long IVlen);
+\end{verbatim}
+
+This adds the initial vector octets from ``IV'' of length ``IVlen'' to the GCM state ``gcm''.  You can call this function as many times as required
+to process the entire IV.  
+
+Note that the GCM protocols provides a ``shortcut'' for 12--byte IVs where no preprocessing is to be done.  If you want to minimize per packet latency it's ideal
+to only use 12--byte IVs.  You can just increment it like a counter for each packet and the CTR [privacy] will be ensured.
+
+\subsubsection{Additional Authentication Data}
+After the entire IV has been processed the additional authentication data can be processed.  Unlike the IV a packet/session does not require additional
+authentication data (AAD) for security.  The AAD is meant to be used as side--channel data you want to be authenticated with the packet.  Note that once
+you begin adding AAD to the GCM state you cannot return to adding IV data until the state is reset.
+
+\index{gcm\_add\_aad()}
+\begin{verbatim}
+int gcm_add_aad(gcm_state *gcm, 
+               const unsigned char *adata,     unsigned long adatalen);
+\end{verbatim}
+This adds the additional authentication data ``adata'' of length ``adatalen'' to the GCM state ``gcm''.
+
+\subsubsection{Plaintext Processing}
+After the AAD has been processed the plaintext (or ciphertext depending on the direction) can be processed.  
+
+\index{gcm\_process()}
+\begin{verbatim}
+int gcm_process(gcm_state *gcm,
+                     unsigned char *pt,     unsigned long ptlen,
+                     unsigned char *ct,
+                     int direction);
+\end{verbatim}
+This processes message data where ``pt'' is the plaintext and ``ct'' is the ciphertext.  The length of both are equal and stored in ``ptlen''.  Depending on the 
+mode ``pt'' is the input and ``ct'' is the output (or vice versa).  When ``direction'' equals \textbf{GCM\_ENCRYPT} the plaintext is read, encrypted and stored
+in the ciphertext buffer.  When ``direction'' equals \textbf{GCM\_DECRYPT} the opposite occurs.
+
+\subsubsection{State Termination}
+To terminate a GCM state and retrieve the message authentication tag call the following function.
+
+\index{gcm\_done()}
+\begin{verbatim}
+int gcm_done(gcm_state *gcm, 
+                     unsigned char *tag,    unsigned long *taglen);
+\end{verbatim}
+This terminates the GCM state ``gcm'' and stores the tag in ``tag'' of length ``taglen'' octets.
+
+\subsubsection{State Reset}
+The call to gcm\_init() will perform considerable pre--computation (when \textbf{GCM\_TABLES} is defined) and if you're going to be dealing with a lot of packets
+it is very costly to have to call it repeatedly.  To aid in this endeavour the reset function has been provided.
+
+\index{gcm\_reset()}
+\begin{verbatim}
+int gcm_reset(gcm_state *gcm);
+\end{verbatim}
+
+This will reset the GCM state ``gcm'' to the state that gcm\_init() left it.  The user would then call gcm\_add\_iv(), gcm\_add\_aad(), etc.
+
+\subsubsection{One--Shot Packet}
+To process a single packet under any given key the following helper function can be used.
+
+\index{gcm\_memory()}
+\begin{verbatim}
+int gcm_memory(      int           cipher,
+               const unsigned char *key,    unsigned long keylen,
+               const unsigned char *IV,     unsigned long IVlen,
+               const unsigned char *adata,  unsigned long adatalen,
+                     unsigned char *pt,     unsigned long ptlen,
+                     unsigned char *ct, 
+                     unsigned char *tag,    unsigned long *taglen,
+                               int direction);
+\end{verbatim}
+
+This will initialize the GCM state with the given key, IV and AAD value then proceed to encrypt or decrypt the message text and store the final
+message tag.  The definition of the variables is the same as it is for all the manual functions.
+
+If you are processing many packets under the same key you shouldn't use this function as it invokes the pre--computation with each call.
+
+\subsubsection{Example Usage}
+The following is an example usage of how to use GCM over multiple packets with a shared secret key.
+
+\begin{small}
+\begin{verbatim}
+#include <tomcrypt.h>
+
+int send_packet(const unsigned char *pt,  unsigned long ptlen,
+                const unsigned char *iv,  unsigned long ivlen,
+                const unsigned char *aad, unsigned long aadlen,
+                      gcm_state     *gcm)
+{
+   int           err;
+   unsigned long taglen;
+   unsigned char tag[16];
+
+   /* reset the state */
+   if ((err = gcm_reset(gcm)) != CRYPT_OK) {
+      return err;
+   }
+ 
+   /* Add the IV */
+   if ((err = gcm_add_iv(gcm, iv, ivlen)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* Add the AAD (note: aad can be NULL if aadlen == 0) */
+   if ((err = gcm_add_aad(gcm, aad, aadlen)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* process the plaintext */
+   if ((err = gcm_process(gcm, pt, ptlen, pt, GCM_ENCRYPT)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* Finish up and get the MAC tag */
+   taglen = sizeof(tag);
+   if ((err = gcm_done(gcm, tag, &taglen)) != CRYPT_OK) {
+      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);
+
+   /* send the aad */
+   send(socket, aad, aadlen, 0);
+
+   /* send the ciphertext */
+   send(socket, pt, ptlen, 0);
+
+   /* send the tag */
+   send(socket, tag, taglen, 0);
+
+   return CRYPT_OK;
+}
+
+int main(void)
+{
+   gcm_state     gcm;
+   unsigned char key[16], IV[12], pt[PACKET_SIZE];
+   int           err, x;
+   unsigned long ptlen; 
+ 
+   /* somehow fill key/IV with random values */
+   
+   /* register AES */
+   register_cipher(&aes_desc);
+
+   /* init the GCM state */
+   if ((err = gcm_init(&gcm, find_cipher("aes"), key, 16)) != CRYPT_OK) {
+      whine_and_pout(err);
+   }
+
+   /* handle us some packets */
+   for (;;) {
+       ptlen = make_packet_we_want_to_send(pt);
+
+       /* use IV as counter (12 byte counter) */
+       for (x = 11; x >= 0; x--) {
+           if (++IV[x]) {
+              break;
+           }
+       }
+
+       if ((err = send_packet(pt, ptlen, iv, 12, NULL, 0, &gcm)) != CRYPT_OK) {
+           whine_and_pout(err);
+       }
+   }
+   return EXIT_SUCCESS;
+}
+\end{verbatim}
+\end{small}
+
 \chapter{One-Way Cryptographic Hash Functions}
 \section{Core Functions}
 
@@ -1141,7 +1438,7 @@
 This simply sets up the hash to the default state governed by the specifications of the hash.  To add data to the 
 message being hashed call:
 \begin{verbatim}
-int XXX_process(hash_state *md, const unsigned char *in, unsigned long len);
+int XXX_process(hash_state *md, const unsigned char *in, unsigned long inlen);
 \end{verbatim}
 
 Essentially all hash messages are virtually infinitely\footnote{Most hashes are limited to $2^{64}$ bits or 2,305,843,009,213,693,952 bytes.} long message which 
@@ -1176,7 +1473,7 @@
 example snippet that hashes a message with md5 is given below.
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
     hash_state md;
@@ -1204,9 +1501,10 @@
     char *name;
     unsigned long hashsize;    /* digest output size in bytes  */
     unsigned long blocksize;   /* the block size the hash uses */
-    void (*init)   (hash_state *);
-    int  (*process)(hash_state *, const unsigned char *, unsigned long);
-    int  (*done)   (hash_state *, unsigned char *);
+    void (*init)   (hash_state *hash);
+    int  (*process)(hash_state *hash, 
+                    const unsigned char *in, unsigned long inlen);
+    int  (*done)   (hash_state *hash, unsigned char *out);
     int  (*test)   (void);
 };
 \end{verbatim}
@@ -1219,7 +1517,7 @@
 You can use the table to indirectly call a hash function that is chosen at runtime.  For example:
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    unsigned char buffer[100], hash[MAXBLOCKSIZE];
@@ -1267,29 +1565,27 @@
 There are three helper functions as well:
 \index{hash\_memory()} \index{hash\_file()}
 \begin{verbatim}
-int hash_memory(int hash, const unsigned char *data, 
-                unsigned long len, unsigned char *dst,
-                unsigned long *outlen);
+int hash_memory(int hash, 
+                const unsigned char *in,   unsigned long inlen, 
+                      unsigned char *out,  unsigned long *outlen);
 
 int hash_file(int hash, const char *fname, 
-              unsigned char *dst,
-              unsigned long *outlen);
+              unsigned char *out, unsigned long *outlen);
 
 int hash_filehandle(int hash, FILE *in, 
-                    unsigned char *dst, unsigned long *outlen);
+                    unsigned char *out, unsigned long *outlen);
 \end{verbatim}
 
 The ``hash'' parameter is the location in the descriptor table of the hash (\textit{e.g. the return of find\_hash()}).  
-The ``*outlen'' variable is used to keep track of the output size.  You
-must set it to the size of your output buffer before calling the functions.  When they complete succesfully they store
-the length of the message digest back in it.  The functions are otherwise straightforward.  The ``hash\_filehandle'' 
-function assumes that ``in'' is an file handle opened in binary mode.  It will hash to the end of file and not reset
-the file position when finished.
+The ``*outlen'' variable is used to keep track of the output size.  You must set it to the size of your output buffer before 
+calling the functions.  When they complete succesfully they store the length of the message digest back in it.  The functions 
+are otherwise straightforward.  The ``hash\_filehandle'' function assumes that ``in'' is an file handle opened in binary mode.  
+It will hash to the end of file and not reset the file position when finished.
 
 To perform the above hash with md5 the following code could be used:
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int idx, err;
@@ -1345,7 +1641,60 @@
 int unregister_hash(const struct _hash_descriptor *hash);
 \end{verbatim}
 
-\subsection{Notice}
+\section{Cipher Hash Construction}
+\index{Cipher Hash Construction}
+An addition to the suite of hash functions is the ``Cipher Hash Construction'' or ``CHC'' mode.  In this mode
+applicable block ciphers (such as AES) can be turned into hash functions that other LTC functions can use.  In 
+particular this allows a cryptosystem to be designed using very few moving parts.
+
+In order to use the CHC system the developer will have to take a few extra steps.  First the ``chc\_desc'' hash
+descriptor must be registered with register\_hash().  At this point the CHC hash cannot be used to hash
+data.  While it is in the hash system you still have to tell the CHC code which cipher to use.  This is accomplished
+via the chc\_register() function.
+
+\index{chc\_register()}
+\begin{verbatim}
+int chc_register(int cipher);
+\end{verbatim}
+
+A cipher has to be registered with CHC (and also in the cipher descriptor tables with 
+register\_cipher()).  The chc\_register() function will bind a cipher to the CHC system.  Only one cipher can 
+be bound to the CHC hash at a time.  There are additional requirements for the system to work.
+
+\begin{enumerate}
+   \item The cipher must have a block size greater than 64--bits.  
+   \item The cipher must allow an input key the size of the block size.
+\end{enumerate}
+
+Example of using CHC with the AES block cipher.
+
+\begin{verbatim}
+#include <tomcrypt.h>
+int main(void)
+{
+   int err; 
+
+   /* register cipher and hash */
+   if (register_cipher(&aes_enc_desc) == -1) {
+      printf("Could not register cipher\n");
+      return EXIT_FAILURE;
+   }
+   if (register_hash(&chc_desc) == -1) {
+      printf("Could not register hash\n");
+      return EXIT_FAILURE;
+   }
+
+   /* start chc with AES */
+   if ((err = chc_register(find_cipher("aes"))) != CRYPT_OK) {
+      printf("Error binding AES to CHC: %s\n", error_to_string(err));
+   }
+
+   /* now you can use chc_hash in any LTC function [aside from pkcs...] */
+   /* ... */
+\end{verbatim}
+
+
+\section{Notice}
 It is highly recommended that you \textbf{not} use the MD4 or MD5 hashes for the purposes of digital signatures or authentication codes.  
 These hashes are provided for completeness and they still can be used for the purposes of password hashing or one-way accumulators
 (e.g. Yarrow).
@@ -1373,18 +1722,18 @@
 length (in octets) of the key you want to use to authenticate the message.  To send octets of a message through the HMAC system you must use the following function:
 \index{hmac\_process()}
 \begin{verbatim}
-int hmac_process(hmac_state *hmac, const unsigned char *buf,
-                  unsigned long len);
+int hmac_process(hmac_state *hmac, 
+                 const unsigned char *in, unsigned long inlen);
 \end{verbatim}
 ``hmac'' is the HMAC state you are working with. ``buf'' is the array of octets to send into the HMAC process.  ``len'' is the
 number of octets to process.  Like the hash process routines you can send the data in arbitrarly sized chunks. When you 
 are finished with the HMAC process you must call the following function to get the HMAC code:
 \index{hmac\_done()}
 \begin{verbatim}
-int hmac_done(hmac_state *hmac, unsigned char *hashOut,
-              unsigned long *outlen);
+int hmac_done(hmac_state *hmac, 
+              unsigned char *out, unsigned long *outlen);
 \end{verbatim}
-``hmac'' is the HMAC state you are working with.  ``hashOut'' is the array of octets where the HMAC code should be stored.  You must
+``hmac'' is the HMAC state you are working with.  ``out'' is the array of octets where the HMAC code should be stored.  You must
 set ``outlen'' to the size of the destination buffer before calling this function.  It is updated with the length of the HMAC code
 produced (depending on which hash was picked).  If ``outlen'' is less than the size of the message digest (and ultimately
 the HMAC code) then the HMAC code is truncated as per FIPS-198 specifications (e.g. take the first ``outlen'' bytes).
@@ -1395,22 +1744,23 @@
 
 \index{hmac\_memory()}
 \begin{verbatim}
-int hmac_memory(int hash, const unsigned char *key, unsigned long keylen,
-                const unsigned char *data, unsigned long len, 
-                unsigned char *dst, unsigned long *dstlen);
+int hmac_memory(int hash, 
+                const unsigned char *key, unsigned long  keylen,
+                const unsigned char *in,  unsigned long  inlen, 
+                      unsigned char *out, unsigned long *outlen);
 \end{verbatim}
-This will produce an HMAC code for the array of octets in ``data'' of length ``len''.  The index into the hash descriptor 
+This will produce an HMAC code for the array of octets in ``in'' of length ``inlen''.  The index into the hash descriptor 
 table must be provided in ``hash''.  It uses the key from ``key'' with a key length of ``keylen''.  
-The result is stored in the array of octets ``dst'' and the length in ``dstlen''.  The value of ``dstlen'' must be set
+The result is stored in the array of octets ``out'' and the length in ``outlen''.  The value of ``outlen'' must be set
 to the size of the destination buffer before calling this function.  Similarly for files there is the  following function:
 \index{hmac\_file()}
 \begin{verbatim}
-int hmac_file(int hash, const char *fname, const unsigned char *key,
-              unsigned long keylen, 
-              unsigned char *dst, unsigned long *dstlen);
+int hmac_file(int hash, const char *fname, 
+              const unsigned char *key, unsigned long  keylen, 
+                    unsigned char *out, unsigned long *outlen);
 \end{verbatim}
 ``hash'' is the index into the hash descriptor table of the hash you want to use.  ``fname'' is the filename to process.  
-``key'' is the array of octets to use as the key of length ``keylen''.  ``dst'' is the array of octets where the 
+``key'' is the array of octets to use as the key of length ``keylen''.  ``out'' is the array of octets where the 
 result should be stored.
 
 To test if the HMAC code is working there is the following function:
@@ -1423,7 +1773,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int idx, err;
@@ -1487,9 +1837,9 @@
 \index{omac\_process()}
 \begin{verbatim}
 int omac_process(omac_state *state, 
-                 const unsigned char *buf, unsigned long len);
+                 const unsigned char *in, unsigned long inlen);
 \end{verbatim}
-This will send ``len'' bytes from ``buf'' through the active OMAC state ``state''.  Returns \textbf{CRYPT\_OK} if the 
+This will send ``inlen'' bytes from ``in'' through the active OMAC state ``state''.  Returns \textbf{CRYPT\_OK} if the 
 function succeeds.  The function is not sensitive to the granularity of the data.  For example,
 
 \begin{verbatim}
@@ -1523,10 +1873,10 @@
 \begin{verbatim}
 int omac_memory(int cipher, 
                 const unsigned char *key, unsigned long keylen,
-                const unsigned char *msg, unsigned long msglen,
-                unsigned char *out, unsigned long *outlen);
+                const unsigned char *in,  unsigned long inlen,
+                      unsigned char *out, unsigned long *outlen);
 \end{verbatim}
-This will compute the OMAC of ``msglen'' bytes of ``msg'' using the key ``key'' of length ``keylen'' bytes and the cipher
+This will compute the OMAC of ``inlen'' bytes of ``in'' using the key ``key'' of length ``keylen'' bytes and the cipher
 specified by the ``cipher'''th entry in the cipher\_descriptor table.  It will store the MAC in ``out'' with the same
 rules as omac\_done.
 
@@ -1536,7 +1886,7 @@
 int omac_file(int cipher, 
               const unsigned char *key, unsigned long keylen,
               const char *filename, 
-              unsigned char *out, unsigned long *outlen);
+                    unsigned char *out, unsigned long *outlen);
 \end{verbatim}
 
 Which will OMAC the entire contents of the file specified by ``filename'' using the key ``key'' of length ``keylen'' bytes
@@ -1553,7 +1903,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int idx, err;
@@ -1618,9 +1968,9 @@
 \index{pmac\_process()}
 \begin{verbatim}
 int pmac_process(pmac_state *state, 
-                 const unsigned char *buf, unsigned long len);
+                 const unsigned char *in, unsigned long inlen);
 \end{verbatim}
-This will process ``len'' bytes of ``buf'' in the given ``state''.  The function is not sensitive to the granularity of the
+This will process ``inlen'' bytes of ``in'' in the given ``state''.  The function is not sensitive to the granularity of the
 data.  For example,
 
 \begin{verbatim}
@@ -1650,9 +2000,9 @@
 \index{pmac\_memory()}
 \begin{verbatim}
 int pmac_memory(int cipher, 
-                const unsigned char *key, unsigned long keylen,
-                const unsigned char *msg, unsigned long msglen,
-                unsigned char *out, unsigned long *outlen);
+                const unsigned char *key, unsigned long  keylen,
+                const unsigned char *in,  unsigned long  inlen,
+                      unsigned char *out, unsigned long *outlen);
 \end{verbatim}
 This will compute the PMAC of ``msglen'' bytes of ``msg'' using the key ``key'' of length ``keylen'' bytes and the cipher
 specified by the ``cipher'''th entry in the cipher\_descriptor table.  It will store the MAC in ``out'' with the same
@@ -1672,43 +2022,173 @@
 the same rules as omac\_done.
 
 To test if the PMAC code is working there is the following function:
+\index{pmac\_test()}
 \begin{verbatim}
 int pmac_test(void);
 \end{verbatim}
 Which returns {\bf CRYPT\_OK} if the code passes otherwise it returns an error code.
 
+\section{Pelican MAC}
+Pelican MAC is a new (experimental) MAC by the AES team that uses four rounds of AES as a ``mixing function''.  It achieves a very high 
+rate of processing and is potentially very secure.  It requires AES to be enabled to function.  You do not have to register\_cipher() AES first though
+as it calls AES directly.
+
+\index{pelican\_init()}
+\begin{verbatim}
+int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen);
+\end{verbatim}
+This will initialize the Pelican state with the given AES key.  Once this has been done you can begin processing data.
+
+\index{pelican\_process()}
+\begin{verbatim}
+int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen);
+\end{verbatim}
+This will process ``inlen'' bytes of ``in'' through the Pelican MAC.  It's best that you pass in multiples of 16 bytes as it makes the
+routine more efficient but you may pass in any length of text.  You can call this function as many times as required to process
+an entire message.
+
+\index{pelican\_done()}
+\begin{verbatim}
+int pelican_done(pelican_state *pelmac, unsigned char *out);
+\end{verbatim}
+This terminates a Pelican MAC and writes the 16--octet tag to ``out''.
+
+\subsection{Example}
+
+\begin{verbatim}
+#include <tomcrypt.h>
+int main(void)
+{
+   pelican_state pelstate;
+   unsigned char key[32], tag[16];
+   int           err;
+
+   /* somehow initialize a key */
+
+   /* initialize pelican mac */
+   if ((err = pelican_init(&pelstate,          /* the state */
+                           key,                /* user key */
+                           32                  /* key length in octets */
+                          )) != CRYPT_OK) {
+      printf("Error initializing Pelican: %s", error_to_string(err));
+      return EXIT_FAILURE;
+   }
+
+   /* MAC some data */
+   if ((err = pelican_process(&pelstate,       /* the state */
+                              "hello world",   /* data to mac */        
+                              11               /* length of data */
+                              )) != CRYPT_OK) {
+      printf("Error processing Pelican: %s", error_to_string(err));
+      return EXIT_FAILURE;
+   }
+
+   /* Terminate the MAC */
+   if ((err = pelican_done(&pelstate,       /* the state */
+                           tag              /* where to store the tag */
+                           )) != CRYPT_OK) {
+      printf("Error terminating Pelican: %s", error_to_string(err));
+      return EXIT_FAILURE;
+   }
+
+   /* tag[0..15] has the MAC output now */
+
+   return EXIT_SUCCESS;
+}
+\end{verbatim}
+
 
 \chapter{Pseudo-Random Number Generators}
 \section{Core Functions}
-
 The library provides an array of core functions for Pseudo-Random Number Generators (PRNGs) as well.  A cryptographic PRNG is
 used to expand a shorter bit string into a longer bit string.  PRNGs are used wherever random data is required such as Public Key (PK)
 key generation.  There is a universal structure called ``prng\_state''.  To initialize a PRNG call:
+\index{PRNG start}
 \begin{verbatim}
 int XXX_start(prng_state *prng);
 \end{verbatim}
 
-This will setup the PRNG for future use and not seed it.  In order 
-for the PRNG to be cryptographically useful you must give it entropy.  Ideally you'd have some OS level source to tap 
-like in UNIX (see section 5.3).  To add entropy to the PRNG call:
+This will setup the PRNG for future use and not seed it.  In order for the PRNG to be cryptographically useful you must give it 
+entropy.  Ideally you'd have some OS level source to tap like in UNIX.  To add entropy to the PRNG call:
+\index{PRNG add\_entropy}
 \begin{verbatim}
-int XXX_add_entropy(const unsigned char *in, unsigned long len, 
+int XXX_add_entropy(const unsigned char *in, unsigned long inlen, 
                     prng_state *prng);
 \end{verbatim}
 
 Which returns {\bf CRYPTO\_OK} if the entropy was accepted.  Once you think you have enough entropy you call another
 function to put the entropy into action.
+\index{PRNG ready}
 \begin{verbatim}
 int XXX_ready(prng_state *prng);
 \end{verbatim}
 
 Which returns {\bf CRYPTO\_OK} if it is ready.  Finally to actually read bytes call:
+\index{PRNG read}
 \begin{verbatim}
-unsigned long XXX_read(unsigned char *out, unsigned long len,
+unsigned long XXX_read(unsigned char *out, unsigned long outlen,
                        prng_state *prng);
 \end{verbatim}
 
-Which returns the number of bytes read from the PRNG.
+Which returns the number of bytes read from the PRNG.  When you are finished with a PRNG state you call
+the following.
+
+\index{PRNG done}
+\begin{verbatim}
+void XXX_done(prng_state *prng);
+\end{verbatim}
+
+This will terminate a PRNG state and free any memory (if any) allocated.  To export a PRNG state
+so that you can later resume the PRNG call the following.
+
+\index{PRNG export}
+\begin{verbatim}
+int XXX_export(unsigned char *out, unsigned long *outlen, 
+               prng_state    *prng);
+\end{verbatim}
+
+This will write a ``PRNG state'' to the buffer ``out'' of length ``outlen'' bytes.  The idea of 
+the export is meant to be used as a ``seed file''.  That is, when the program starts up there will not likely
+be that much entropy available.   To import a state to seed a PRNG call the following function.
+
+\index{PRNG import}
+\begin{verbatim}
+int XXX_import(const unsigned char *in, unsigned long inlen, 
+                     prng_state     *prng);
+\end{verbatim}
+
+This will call the start and add\_entropy functions of the given PRNG.  It will use the state in
+``in'' of length ``inlen'' as the initial seed.  You must pass the same seed length as was exported
+by the corresponding export function.
+
+Note that importing a state will not ``resume'' the PRNG from where it left off.  That is, if you export
+a state, emit (say) 8 bytes and then import the previously exported state the next 8 bytes will not 
+specifically equal the 8 bytes you generated previously.
+
+When a program is first executed the normal course of operation is 
+
+\begin{enumerate}
+   \item Gather entropy from your sources for a given period of time or number of events.
+   \item Start, use your entropy via add\_entropy and ready the PRNG yourself.
+\end{enumerate}
+
+When your program is finished you simply call the export function and save the state to a medium (disk,
+flash memory, etc).  The next time your application starts up you can detect the state, feed it to the 
+import function and go on your way.  It is ideal that (as soon as possible) after startup you export a
+fresh state.  This helps in the case that the program aborts or the machine is powered down without
+being given a chance to exit properly.  
+
+Note that even if you have a state to import it is important to add new entropy to the state.  However,
+there is less pressure to do so.  
+
+To test a PRNG for operational conformity call the following functions.
+
+\index{PRNG test}
+\begin{verbatim}
+int XXX_test(void);
+\end{verbatim}
+
+This will return \textbf{CRYPT\_OK} if PRNG is operating properly.
 
 \subsection{Remarks}
 
@@ -1719,11 +2199,11 @@
 
 \subsection{Example}
 
-Below is a simple snippet to read 10 bytes from yarrow.  Its important to note that this snippet is {\bf NOT} secure since
-the entropy added is not random.
+Below is a simple snippet to read 10 bytes from yarrow.  Its important to note that this snippet is 
+{\bf NOT} secure since the entropy added is not random.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    prng_state prng;
@@ -1753,10 +2233,15 @@
 \begin{verbatim}
 struct _prng_descriptor {
     char *name;
+    int  export_size;    /* size in bytes of exported state */
     int (*start)      (prng_state *);
     int (*add_entropy)(const unsigned char *, unsigned long, prng_state *);
     int (*ready)      (prng_state *);
     unsigned long (*read)(unsigned char *, unsigned long len, prng_state *);
+    void (*done)(prng_state *);
+    int (*export)(unsigned char *, unsigned long *, prng_state *);
+    int (*import)(const unsigned char *, unsigned long, prng_state *);
+    int (*test)(void);
 };
 \end{verbatim}
 
@@ -1770,19 +2255,85 @@
 int unregister_prng(const struct _prng_descriptor *prng);
 \end{verbatim}
 
-\subsubsection{PRNGs Provided}
-Currently Yarrow (yarrow\_desc), RC4 (rc4\_desc) and the secure RNG (sprng\_desc) are provided as PRNGs within the 
-library.  
+\subsection{PRNGs Provided}
+\begin{figure}[here]
+\begin{center}
+\begin{small}
+\begin{tabular}{|c|c|l|}
+\hline \textbf{Name} & \textbf{Descriptor} & \textbf{Usage} \\
+\hline Yarrow & yarrow\_desc & Fast short-term PRNG \\
+\hline Fortuna & fortuna\_desc & Fast long-term PRNG (recommended) \\
+\hline RC4 & rc4\_desc & Stream Cipher \\
+\hline SOBER-128 & sober128\_desc & Stream Cipher (also very fast PRNG) \\
+\hline
+\end{tabular}
+\end{small}
+\end{center}
+\caption{List of Provided PRNGs}
+\end{figure}
 
-RC4 is provided with a PRNG interface because it is a stream cipher and not well suited for the symmetric block cipher
-interface.  You provide the key for RC4 via the rc4\_add\_entropy() function.  By calling rc4\_ready() the key will be used
-to setup the RC4 state for encryption or decryption.  The rc4\_read() function has been modified from RC4 since it will 
-XOR the output of the RC4 keystream generator against the input buffer you provide.  The following snippet will demonstrate
-how to encrypt a buffer with RC4:
+\subsubsection{Yarrow}
+Yarrow is fast PRNG meant to collect an unspecified amount of entropy from sources 
+(keyboard, mouse, interrupts, etc) and produce an unbounded string of random bytes.  
 
+\textit{Note:} This PRNG is still secure for most taskings but is no longer recommended.  Users
+should use Fortuna instead.
+
+\subsubsection{Fortuna}
+
+Fortuna is a fast attack tolerant and more thoroughly designed PRNG suitable for long term
+usage.  It is faster than the default implementation of Yarrow\footnote{Yarrow has been implemented
+to work with most cipher and hash combos based on which you have chosen to build into the library.} while
+providing more security.  
+
+Fortuna is slightly less flexible than Yarrow in the sense that it only works with the AES block cipher 
+and SHA--256 hash function.  Technically Fortuna will work with any block cipher that accepts a 256--bit
+key and any hash that produces at least a 256--bit output.  However, to make the implementation simpler
+it has been fixed to those choices.
+
+Fortuna is more secure than Yarrow in the sense that attackers who learn parts of the entropy being 
+added to the PRNG learn far less about the state than that of Yarrow.  Without getting into to many
+details Fortuna has the ability to recover from state determination attacks where the attacker starts
+to learn information from the PRNGs output about the internal state.  Yarrow on the other hand cannot 
+recover from that problem until new entropy is added to the pool and put to use through the ready() function.
+
+\subsubsection{RC4}
+
+RC4 is an old stream cipher that can also double duty as a PRNG in a pinch.  You ``key'' it by
+calling add\_entropy() and setup the key by calling ready().  You can only add upto 256 bytes via
+add\_entropy().  
+
+When you read from RC4 the output of the RC4 algorithm is XOR'd against your buffer you provide.  In this
+manner you can use rc4\_read() as an encrypt (and decrypt) function.  
+
+You really shouldn't use RC4 anymore.  This isn't because RC4 is weak (though biases are known to exist) just
+simply that faster alternatives exist.
+
+\subsubsection{SOBER-128}
+
+SOBER-128 is a stream cipher designed by the QUALCOMM Australia team.  Like RC4 you ``key'' it by 
+calling add\_entropy().  There is no need to call ready() for this PRNG as it does not do anything.  
+
+Note that this cipher has several oddities about how it operates.  The first time you call 
+add\_entropy() that sets the cipher's key.  Every other time you call the same function it sets
+the cipher's IV variable.  The IV mechanism allows you to encrypt several messages with the same
+key and not re--use the same key material.
+
+Unlike Yarrow and Fortuna all of the entropy (and hence security) of this algorithm rests in the data
+you pass it on the first call to add\_entropy().  All buffers sent to add\_entropy() must have a length
+that is a multiple of four bytes.
+
+Like RC4 the output of SOBER--128 is XOR'ed against the buffer you provide it.  In this manner you can use
+sober128\_read() as an encrypt (and decrypt) function.
+
+Since SOBER-128 has a fixed keying scheme and is very fast (faster than RC4) the ideal usage of SOBER-128 is to 
+key it from the output of Fortuna (or Yarrow) and use it to encrypt messages.  It is also ideal for
+simulations which need a high quality (and fast) stream of bytes.  
+
+\subsubsection{Example Usage}
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    prng_state prng;
@@ -1850,7 +2401,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    ecc_key mykey;
@@ -1887,7 +2438,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    ecc_key mykey;
@@ -1909,12 +2460,14 @@
 \end{verbatim}
 \end{small}
 
+
+
 \chapter{RSA Public Key Cryptography}
 
 \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}
@@ -1970,33 +2523,6 @@
 $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}
@@ -2038,34 +2564,6 @@
 
 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}
 
@@ -2116,10 +2614,11 @@
 ``rsa\_free()'' (see below) when you are finished with the key.  If ``rsa\_make\_key()'' fails it will automatically 
 free the ram allocated itself.
 
-There are three types of RSA keys.  The types are {\bf PK\_PRIVATE\_OPTIMIZED}, {\bf PK\_PRIVATE} and {\bf PK\_PUBLIC}.  The first
-two are private keys where the ``optimized'' type uses the Chinese Remainder Theorem to speed up decryption/signatures.  By 
-default all new keys are of the ``optimized'' type.  The non-optimized private type is provided for backwards compatibility
-as well as to save space since the optimized key requires about four times as much memory.
+\index{PK\_PRIVATE} \index{PK\_PUBLIC}
+There are two types of RSA keys.  The types are {\bf PK\_PRIVATE} and {\bf PK\_PUBLIC}.  The first type is a private 
+RSA key which includes the CRT parameters\footnote{As of v0.99 the PK\_PRIVATE\_OPTIMIZED type has been deprecated
+and has been replaced by the PK\_PRIVATE type.} in the form of a RSAPrivateKey.  The second type is a public RSA key
+which only includes the modulus and public exponent.  It takes the form of a RSAPublicKey.
 
 \subsection{RSA Exponentiation}
 
@@ -2127,8 +2626,8 @@
 \index{rsa\_exptmod()}
 \begin{verbatim}
 int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
-                      unsigned char *out,  unsigned long *outlen, int which,
-                      prng_state    *prng, int           prng_idx,
+                      unsigned char *out,  unsigned long *outlen, 
+                      int which, prng_state *prng, int prng_idx,
                       rsa_key *key);
 \end{verbatim}
 This loads the bignum from ``in'' as a big endian word in the format PKCS specifies, raises it to either ``e'' or ``d'' and stores the result
@@ -2144,29 +2643,28 @@
 
 \index{rsa\_encrypt\_key()}
 \begin{verbatim}
-int rsa_encrypt_key(const unsigned char *inkey,  unsigned long inlen,
-                          unsigned char *outkey, unsigned long *outlen,
+int rsa_encrypt_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, rsa_key *key);
 \end{verbatim}
-This function will OAEP pad ``inkey'' of length inlen bytes then RSA encrypt it and store the ciphertext
-in ``outkey'' of length ``outlen''.  The ``lparam'' and ``lparamlen'' are the same parameters you would pass
+This function will OAEP pad ``in'' of length inlen bytes then RSA encrypt it and store the ciphertext
+in ``out'' of length ``outlen''.  The ``lparam'' and ``lparamlen'' are the same parameters you would pass
 to pkcs\_1\_oaep\_encode().
 
 \index{rsa\_decrypt\_key()}
 \begin{verbatim}
-int rsa_decrypt_key(const unsigned char *in,     unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
+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
-``outkey'' of length ``outlen''.  The ``lparam'' and ``lparamlen'' are the same parameters you would pass
+``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
@@ -2174,22 +2672,21 @@
 
 \index{rsa\_sign\_hash()}
 \begin{verbatim}
-int rsa_sign_hash(const unsigned char *msghash,  unsigned long  msghashlen, 
-                        unsigned char *sig,      unsigned long *siglen, 
+int rsa_sign_hash(const unsigned char *in,   unsigned long  inlen, 
+                        unsigned char *out,  unsigned long *outlen, 
                         prng_state    *prng,     int            prng_idx,
                         int            hash_idx, unsigned long  saltlen,
                         rsa_key *key);
 \end{verbatim}
 
-This will PSS encode the message hash ``msghash'' of length ``msghashlen''.  Next the PSS encoded message is
-RSA ``signed'' and the output is stored in ``sig'' of length ``siglen''.  
+This will PSS encode the message hash ``in'' of length ``inlen''.  Next the PSS encoded message will be RSA ``signed'' and 
+the output is stored in ``out'' of length ``outlen''.  
 
 
 \index{rsa\_verify\_hash()}
 \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}
@@ -2202,7 +2699,7 @@
 to $1$.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int           err, hash_idx, prng_idx, res;
@@ -2259,8 +2756,6 @@
                               &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 */ 
@@ -2272,79 +2767,6 @@
 }
 \end{verbatim}
 
-\chapter{Password Based Cryptography}
-\section{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.
-
-\section{Algorithm One}
-Algorithm One accepts as input a password, an 8--byte salt and an iteration counter.  The iteration counter is meant to act as delay for
-people trying to brute force guess the password.  The higher the iteration counter the longer the delay.  This algorithm also requires a hash 
-algorithm and produces an output no longer than the output of the hash.  
-
-\index{pkcs\_5\_alg1()}
-\begin{alltt}
-int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, 
-                const unsigned char *salt, 
-                int iteration_count,  int hash_idx,
-                unsigned char *out,   unsigned long *outlen)
-\end{alltt}
-Where ``password'' is the users password.  Since the algorithm allows binary passwords you must also specify the length in ``password\_len''.  
-The ``salt'' is a fixed size 8--byte array which should be random for each user and session.  The ``iteration\_count'' is the delay desired
-on the password.  The ``hash\_idx'' is the index of the hash you wish to use in the descriptor table.  
-
-The output of length upto ``outlen'' is stored in ``out''.  If ``outlen'' is initially larger than the size of the hash functions output
-it is set to the number of bytes stored.  If it is smaller than not all of the hash output is stored in ``out''.
-
-\section{Algorithm Two}
-
-Algorithm Two is the recommended algorithm for this task.  It allows variable length salts and can produce outputs larger than the 
-hash functions output.  As such it can easily be used to derive session keys for ciphers and MACs as well initial vectors as required
-from a single password and invokation of this algorithm.
-
-\index{pkcs\_5\_alg2()}
-\begin{alltt}
-int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, 
-                const unsigned char *salt,     unsigned long salt_len,
-                int iteration_count,           int hash_idx,
-                unsigned char *out,            unsigned long *outlen)
-\end{alltt}
-Where ``password'' is the users password.  Since the algorithm allows binary passwords you must also specify the length in ``password\_len''.  
-The ``salt'' is an array of size ``salt\_len''.  It should be random for each user and session.  The ``iteration\_count'' is the delay desired
-on the password.  The ``hash\_idx'' is the index of the hash you wish to use in the descriptor table.   The output of length upto 
-``outlen'' is stored in ``out''.
-
-\begin{alltt}
-/* demo to show how to make session state material from a password */
-#include <mycrypt.h>
-int main(void)
-\{
-    unsigned char password[100], salt[100],
-                  cipher_key[16], cipher_iv[16],
-                  mac_key[16], outbuf[48];
-    int           err, hash_idx;
-    unsigned long outlen, password_len, salt_len;
-
-    /* register hash and get it's idx .... */
-
-    /* get users password and make up a salt ... */
-
-    /* create the material (100 iterations in algorithm) */
-    outlen = sizeof(outbuf);
-    if ((err = pkcs_5_alg2(password, password_len, salt, salt_len, 
-                           100, hash_idx, outbuf, &outlen)) != CRYPT_OK) \{
-       /* error handle */
-    \}
-
-    /* now extract it */
-    memcpy(cipher_key, outbuf, 16);
-    memcpy(cipher_iv,  outbuf+16, 16);
-    memcpy(mac_key,    outbuf+32, 16);
-
-    /* use material (recall to store the salt in the output) */
-\}
-\end{alltt}
 
 \chapter{Diffie-Hellman Key Exchange}
 
@@ -2539,16 +2961,16 @@
 algorithms.  
 \index{dh\_encrypt\_key()} \index{dh\_decrypt\_key()}
 \begin{verbatim}
-int dh_encrypt_key(const unsigned char *inkey, unsigned long keylen,
+int dh_encrypt_key(const unsigned char *in,   unsigned long  inlen,
                          unsigned char *out,  unsigned long *len, 
                          prng_state *prng, int wprng, int hash, 
                          dh_key *key);
 
-int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
-                         unsigned char *outkey, unsigned long *keylen, 
+int dh_decrypt_key(const unsigned char *in,  unsigned long  inlen,
+                         unsigned char *out, unsigned long *outlen, 
                          dh_key *key);
 \end{verbatim}
-Where ``inkey'' 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 32 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 ``dh\_encrypt\_key()''.   The hash must produce a message digest at least as large
 as the symmetric key you are trying to share.
@@ -2593,6 +3015,33 @@
 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(1), -- public/private flag (always zero), 
+    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
+    pubkey.y    INTEGER,       -- The Y co-ordinate of the public key point
+}
+
+ECCPrivateKey ::= SEQUENCE {
+    flags       BIT STRING(1), -- public/private flag (always one), 
+    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
+    pubkey.y    INTEGER,       -- The Y 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).  
+
 \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:
@@ -2602,8 +3051,8 @@
                  int keysize, ecc_key *key);
 \end{verbatim}
 
-The ``keysize'' is the size of the modulus in bytes desired.  Currently directly supported values are 20, 24, 28, 32, 48 and 65 bytes which
-correspond to key sizes of 160, 192, 224, 256, 384 and 521 bits respectively.  If you pass a key size that is between any key size
+The ``keysize'' is the size of the modulus in bytes desired.  Currently directly supported values are 24, 28, 32, 48 and 65 bytes which
+correspond to key sizes of 192, 224, 256, 384 and 521 bits respectively.  If you pass a key size that is between any key size
 it will round the keysize up to the next available one.  The rest of the parameters work like they do in the ``dh\_make\_key()'' function.  
 To free the ram allocated by a key call:
 \index{ecc\_free()}
@@ -2652,21 +3101,33 @@
 
 \index{ecc\_encrypt\_key()} \index{ecc\_decrypt\_key()}
 \begin{verbatim}
-int ecc_encrypt_key(const unsigned char *inkey, unsigned long keylen,
-                          unsigned char *out,  unsigned long *len, 
+int ecc_encrypt_key(const unsigned char *in,   unsigned long  inlen,
+                          unsigned char *out,  unsigned long *outlen, 
                           prng_state *prng, int wprng, int hash, 
                           ecc_key *key);
 
-int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
+int ecc_decrypt_key(const unsigned char *in,  unsigned long  inlen,
+                          unsigned char *out, unsigned long *outlen, 
                           ecc_key *key);
 \end{verbatim}
 
-Where ``inkey'' 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}
@@ -2683,12 +3144,14 @@
 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
 and in effect the signature will still work.  With ECC keys the strength of the signature is limited by the size of
-the hash or the size of they key, whichever is smaller.  For example, if you sign with SHA256 and a ECC-160 key in effect
-you have 160-bits of security (e.g. as if you signed with SHA-1).  
+the hash or the size of they key, whichever is smaller.  For example, if you sign with SHA256 and an ECC-192 key in effect
+you have 192-bits of security.  
 
 The library will not warn you if you make this mistake so it is important to check yourself before using the 
 signatures.
@@ -2703,6 +3166,38 @@
 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}
@@ -2774,8 +3269,6 @@
 This will test ``key'' and store the result in ``stat''.  If the result is $stat = 0$ the DSA key failed one of the tests
 and should not be used at all.  If the result is $stat = 1$ the DSA key is valid (as far as valid mathematics are concerned).
 
-
-
 \section{Signatures}
 To generate a DSA signature call the following function
 
@@ -2825,6 +3318,424 @@
 This will import the DSA key from the buffer ``in'' of length ``inlen'' to the ``key''.  If the process fails the function
 will automatically free all of the heap allocated in the process (you don't have to call dsa\_free()).  
 
+\chapter{Standards Support}
+\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.  
+
+On top of the basic data types are the SEQUENCE and\footnote{Planned for LTC 1.06} 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 
+
+\index{ltc\_asn1\_list structure}
+\begin{verbatim}
+typedef struct {
+   int           type;
+   void         *data;
+   unsigned long size;
+   int           used;
+} ltc_asn1_list;
+\end{verbatim}
+
+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).  The ``used'' field is primarily for the CHOICE decoder
+and reflects if the particular member of a list was the decoded 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\_UTCTIME            & UTCTIME (see ltc\_utctime structure) \\
+\hline LTC\_ASN1\_SEQUENCE           & SEQUENCE OF \\
+\hline LTC\_ASN1\_CHOICE             & CHOICE \\
+\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}.
+
+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.
+
+\subsection{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{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{verbatim}
+
+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\_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.  
+
+\subsection{ASN.1 BIT STRING}
+
+\index{der\_encode\_bit\_string()}
+\index{der\_decode\_bit\_string()}
+\index{der\_length\_bit\_string()}
+\begin{verbatim}
+int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+
+int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+
+int der_length_bit_string(unsigned long nbits, unsigned long *outlen);
+\end{verbatim}
+
+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.
+
+\subsection{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.  
+
+\subsection{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$.  
+
+\subsection{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. 
+
+\subsection{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. 
+
+\subsection{ASN.1 UTCTIME}
+
+The UTCTIME type is to store a date and time in ASN.1 format.  It uses the following structure to organize the time.
+
+\begin{verbatim}
+typedef struct {
+   unsigned YY, /* year    00--99 */
+            MM, /* month   01--12 */
+            DD, /* day     01--31 */
+            hh, /* hour    00--23 */
+            mm, /* minute  00--59 */
+            ss, /* second  00--59 */
+            off_dir, /* timezone offset direction 0 == +, 1 == - */
+            off_hh, /* timezone offset hours */
+            off_mm; /* timezone offset minutes */
+} ltc_utctime;
+\end{verbatim}
+
+The time can be offset plus or minus a set amount of hours (off\_hh) and minutes (off\_mm).  When ``off\_dir'' is zero the time will be added otherwise it 
+will be subtracted.  
+
+For instance, the array $\lbrace 5, 6, 20, 22, 4, 00, 0, 5, 0 \rbrace$ represents the current time of 2005, June 20th, 22:04:00 with a time offset of +05h00.  
+
+\index{der\_encode\_utctime()}
+\index{der\_decode\_utctime()}
+\index{der\_length\_utctime()}
+\begin{verbatim}
+int der_encode_utctime(ltc_utctime *utctime, 
+                       unsigned char *out,   unsigned long *outlen);
+
+int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
+                             ltc_utctime   *out);
+
+int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
+\end{verbatim}
+
+The encoder will store time in one of the two ASN.1 formats, either ``YYMMDDhhmmssZ'' or ``YYMMDDhhmmss$\pm$hhmm'' and perform minimal error checking on the 
+input.  The decoder will read all valid ASN.1 formats and perform range checking on the values (not complete but rational) useful for catching packet errors.
+
+It is suggested that decoded data be further scrutinized (e.g. days of month in particular).
+
+\subsection{ASN.1 CHOICE}
+
+The CHOICE ASN.1 type represents a union of ASN.1 types all of which are stored in a ``ltc\_asn1\_list''.  There is no encoder for the CHOICE type, only a 
+decoder.  The decoder will scan through the provided list attempting to use the appropriate decoder on the input packet.  The list can contain any ASN.1 data
+type\footnote{Except it cannot have LTC\_ASN1\_INTEGER and LTC\_ASN1\_SHORT\_INTEGER simultaneously.} except for other CHOICE types.  
+
+There is no encoder for the CHOICE type as the actual DER encoding is the encoding of the chosen type.  
+
+\index{der\_decode\_choice()}
+\begin{verbatim}
+int der_decode_choice(const unsigned char *in,   unsigned long *inlen,
+                            ltc_asn1_list *list, unsigned long  outlen);
+\end{verbatim}
+
+This will decode the input in the ``in'' field of length ``inlen''.  It uses the provided ASN.1 list specified in the ``list'' field which has ``outlen'' elements.  
+The ``inlen'' field will be updated with the length of the decoded data type as well as the respective entry in the ``list'' field will have the ``used'' flag 
+set to non--zero to reflect it was the data type decoded.
+
+\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.
+
+\subsection{Algorithm One}
+Algorithm One accepts as input a password, an 8--byte salt and an iteration counter.  The iteration counter is meant to act as delay for
+people trying to brute force guess the password.  The higher the iteration counter the longer the delay.  This algorithm also requires a hash 
+algorithm and produces an output no longer than the output of the hash.  
+
+\index{pkcs\_5\_alg1()}
+\begin{alltt}
+int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, 
+                const unsigned char *salt, 
+                int iteration_count,  int hash_idx,
+                unsigned char *out,   unsigned long *outlen)
+\end{alltt}
+Where ``password'' is the users password.  Since the algorithm allows binary passwords you must also specify the length in ``password\_len''.  
+The ``salt'' is a fixed size 8--byte array which should be random for each user and session.  The ``iteration\_count'' is the delay desired
+on the password.  The ``hash\_idx'' is the index of the hash you wish to use in the descriptor table.  
+
+The output of length upto ``outlen'' is stored in ``out''.  If ``outlen'' is initially larger than the size of the hash functions output
+it is set to the number of bytes stored.  If it is smaller than not all of the hash output is stored in ``out''.
+
+\subsection{Algorithm Two}
+
+Algorithm Two is the recommended algorithm for this task.  It allows variable length salts and can produce outputs larger than the 
+hash functions output.  As such it can easily be used to derive session keys for ciphers and MACs as well initial vectors as required
+from a single password and invokation of this algorithm.
+
+\index{pkcs\_5\_alg2()}
+\begin{alltt}
+int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, 
+                const unsigned char *salt,     unsigned long salt_len,
+                int iteration_count,           int hash_idx,
+                unsigned char *out,            unsigned long *outlen)
+\end{alltt}
+Where ``password'' is the users password.  Since the algorithm allows binary passwords you must also specify the length in ``password\_len''.  
+The ``salt'' is an array of size ``salt\_len''.  It should be random for each user and session.  The ``iteration\_count'' is the delay desired
+on the password.  The ``hash\_idx'' is the index of the hash you wish to use in the descriptor table.   The output of length upto 
+``outlen'' is stored in ``out''.
+
+\begin{alltt}
+/* demo to show how to make session state material from a password */
+#include <tomcrypt.h>
+int main(void)
+\{
+    unsigned char password[100], salt[100],
+                  cipher_key[16], cipher_iv[16],
+                  mac_key[16], outbuf[48];
+    int           err, hash_idx;
+    unsigned long outlen, password_len, salt_len;
+
+    /* register hash and get it's idx .... */
+
+    /* get users password and make up a salt ... */
+
+    /* create the material (100 iterations in algorithm) */
+    outlen = sizeof(outbuf);
+    if ((err = pkcs_5_alg2(password, password_len, salt, salt_len, 
+                           100, hash_idx, outbuf, &outlen)) != CRYPT_OK) \{
+       /* error handle */
+    \}
+
+    /* now extract it */
+    memcpy(cipher_key, outbuf, 16);
+    memcpy(cipher_iv,  outbuf+16, 16);
+    memcpy(mac_key,    outbuf+32, 16);
+
+    /* use material (recall to store the salt in the output) */
+\}
+\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 
@@ -2863,7 +3774,7 @@
 At the heart of all the functions is the data type ``mp\_int'' (defined in tommath.h).  This data type is what 
 will hold all large integers.  In order to use an mp\_int one must initialize it first, for example:
 \begin{verbatim}
-#include <mycrypt.h> /* mycrypt.h includes mpi.h automatically */
+#include <tomcrypt.h> /* tomcrypt.h includes mpi.h automatically */
 int main(void)
 { 
    mp_int bignum;
@@ -3022,7 +3933,6 @@
 \begin{center}
 \begin{tabular}{|c|c|}
     \hline ECC Key Size (bits) & Work Factor ($log_2$) \\
-    \hline 160 & 80  \\
     \hline 192 & 96  \\
     \hline 224 & 112 \\
     \hline 256 & 128 \\
@@ -3058,18 +3968,67 @@
 is modular enough putting the locks in the right place should not bloat the code significantly and will solve all thread
 safety issues within the library.
 
-\chapter{Configuring the Library}
+\chapter{Configuring and Building the Library}
 \section{Introduction}
 The library is fairly flexible about how it can be built, used and generally distributed.  Additions are being made with
-each new release that will make the library even more flexible.  Most options are placed in the makefile and others
-are in ``mycrypt\_cfg.h''.  All are used when the library is built from scratch.
+each new release that will make the library even more flexible.  Each of the classes of functions can be disabled during
+the build process to make a smaller library.  This is particularly useful for shared libraries.
 
-For GCC platforms the file ``makefile'' is the makefile to be used.  On MSVC platforms ``makefile.vc'' and on PS2 platforms
-``makefile.ps2''.
+\section{Building a Static Library}
+The library can be built as a static library which is generally the simplest and most portable method of 
+building the library.  With a CC or GCC equipped platform you can issue the following
 
-\section{mycrypt\_cfg.h}
-The file ``mycrypt\_cfg.h'' is what lets you control what functionality you want to remove from the library.  By default,
-everything the library has to offer it built.  
+\begin{alltt}
+make install_lib
+\end{alltt}
+
+Which will build the library and install it in /usr/lib (as well as the headers in /usr/include).  The destination
+directory of the library and headers can be changed by editing ``makefile''.  The variable LIBNAME controls
+where the library is to be installed and INCNAME controls where the headers are to be installed.  A developer can 
+then use the library by including ``tomcrypt.h'' in their program and linking against ``libtomcrypt.a''.
+
+A static library can also be built with the Intel C Compiler  (ICC) by issuing the following
+
+\begin{alltt}
+make -f makefile.icc install
+\end{alltt}
+
+This will also build ``libtomcrypt.a'' except that it will use ICC.  Additionally Microsoft's Visual C 6.00 can be used
+by issuing
+
+\begin{alltt}
+nmake -f makefile.msvc
+\end{alltt}
+
+You will have to manually copy ``tomcrypt.lib'' and the headers to your MSVC lib/inc directories.
+
+\subsection{MPI Control}
+If you already have LibTomMath installed you can safely remove it from the build.  By commenting the line
+in the appropriate makefile which starts with 
+
+\begin{alltt}
+MPIOBJECT=mpi
+\end{alltt}
+
+Simply place a \# at the start and re-build the library.  To properly link applications you will have to also
+link in LibTomMath.  Removing MPI has the benefit of cutting down the library size as well potentially have access
+to the latest mpi.
+
+\section{Building a Shared Library}
+LibTomCrypt can also be built as a shared library (.so, .dll, etc...).  With non-Windows platforms the assumption
+of the presence of gcc and ``libtool'' has been made.  These are fairly common on Unix/Linux/BSD platforms.  To
+build a .so shared library issue 
+
+\begin{alltt}
+make -f makefile.shared
+\end{alltt}
+This will use libtool and gcc to build a shared library ``libtomcrypt.la'' as well as a static library ``libtomcrypt.a''
+and install them into /usr/lib (and the headers into /usr/include).  To link your application you should use the 
+libtool program in ``--mode=link''.
+
+\section{tomcrypt\_cfg.h}
+The file ``tomcrypt\_cfg.h'' is what lets you control various high level macros which control the behaviour 
+of the library. 
 
 \subsubsection{ARGTYPE}
 This lets you control how the \_ARGCHK macro will behave.  The macro is used to check pointers inside the functions against
@@ -3082,37 +4041,43 @@
 There are five macros related to endianess issues.  For little endian platforms define, ENDIAN\_LITTLE.  For big endian
 platforms define ENDIAN\_BIG.  Similarly when the default word size of an ``unsigned long'' is 32-bits define ENDIAN\_32BITWORD
 or define ENDIAN\_64BITWORD when its 64-bits.  If you do not define any of them the library will automatically use ENDIAN\_NEUTRAL
-which will work on all platforms.  Currently the system will automatically detect GCC or MSVC on a windows platform as well
-as GCC on a PS2 platform.
+which will work on all platforms.
+
+Currently LibTomCrypt will detect x86-32 and x86-64 running GCC as well as x86-32 running MSVC.  
 
 \section{The Configure Script}
-There are also options you can specify from the configure script or ``mycrypt\_config.h''.  
+There are also options you can specify from the configure script or ``tomcrypt\_custom.h''.  
 
-\subsubsection{X memory routines}
-The makefiles must define three macros denoted as XMALLOC, XCALLOC and XFREE which resolve to the name of the respective
-functions.  This lets you substitute in your own memory routines.  If you substitute in your own functions they must behave
-like the standard C library functions in terms of what they expect as input and output.  By default the library uses the
-standard C routines.
+\subsection{X memory routines}
+At the top of tomcrypt\_custom.h are four macros denoted as XMALLOC, XCALLOC, XREALLOC and XFREE which resolve to 
+the name of the respective functions.  This lets you substitute in your own memory routines.  If you substitute in 
+your own functions they must behave like the standard C library functions in terms of what they expect as input and 
+output.  By default the library uses the standard C routines.
 
-\subsubsection{X clock routines}
+\subsection{X clock routines}
 The rng\_get\_bytes() function can call a function that requires the clock() function.  These macros let you override
 the default clock() used with a replacement.  By default the standard C library clock() function is used.
 
-\subsubsection{NO\_FILE}
+\subsection{NO\_FILE}
 During the build if NO\_FILE is defined then any function in the library that uses file I/O will not call the file I/O 
-functions and instead simply return CRYPT\_ERROR.  This should help resolve any linker errors stemming from a lack of
+functions and instead simply return CRYPT\_NOP.  This should help resolve any linker errors stemming from a lack of
 file I/O on embedded platforms.
 
-\subsubsection{CLEAN\_STACK}
-When this functions is defined the functions that store key material on the stack will clean up afterwards.  Assumes that
-you have no memory paging with the stack.
+\subsection{CLEAN\_STACK}
+When this functions is defined the functions that store key material on the stack will clean up afterwards.  
+Assumes that you have no memory paging with the stack.
 
-\subsubsection{Symmetric Ciphers, One-way Hashes, PRNGS and Public Key Functions}
-There are a plethora of macros for the ciphers, hashes, PRNGs and public key functions which are fairly self-explanatory.  
-When they are defined the functionality is included otherwise it is not.  There are some dependency issues which are
-noted in the file.  For instance, Yarrow requires CTR chaining mode, a block cipher and a hash function.
+\subsection{LTC\_TEST}
+When this has been defined the various self--test functions (for ciphers, hashes, prngs, etc) are included in the build.
+When this has been undefined the tests are removed and if called will return CRYPT\_NOP.
 
-\subsubsection{TWOFISH\_SMALL and TWOFISH\_TABLES}
+\subsection{Symmetric Ciphers, One-way Hashes, PRNGS and Public Key Functions}
+There are a plethora of macros for the ciphers, hashes, PRNGs and public key functions which are fairly 
+self-explanatory.  When they are defined the functionality is included otherwise it is not.  There are some 
+dependency issues which are noted in the file.  For instance, Yarrow requires CTR chaining mode, a block 
+cipher and a hash function.
+
+\subsection{TWOFISH\_SMALL and TWOFISH\_TABLES}
 Twofish is a 128-bit symmetric block cipher that is provided within the library.  The cipher itself is flexible enough
 to allow some tradeoffs in the implementation.  When TWOFISH\_SMALL is defined the scheduled symmetric key for Twofish 
 requires only 200 bytes of memory.  This is achieved by not pre-computing the substitution boxes.  Having this 
@@ -3124,10 +4089,475 @@
 will increase by approximately 500 bytes.  If this is defined but TWOFISH\_SMALL is not the cipher will still work but
 it will not speed up the encryption or decryption functions.
 
-\subsubsection{SMALL\_CODE}
+\subsection{GCM\_TABLES}
+When defined GCM will use a 64KB table (per GCM state) which will greatly speed up the per--packet latency.  
+It also increases the initialization time and isn't suitable when you are going to use a key a few times only.  
+
+\subsection{SMALL\_CODE}
 When this is defined some of the code such as the Rijndael and SAFER+ ciphers are replaced with smaller code variants.
 These variants are slower but can save quite a bit of code space.
 
+\subsection{LTC\_FAST}
+This mode (autodetected with x86\_32,x86\_64 platforms with GCC or MSVC) configures various routines such as ctr\_encrypt() or 
+cbc\_encrypt() that it can safely XOR multiple octets in one step by using a larger data type.  This has the benefit of 
+cutting down the overhead of the respective functions.  
+
+This mode does have one downside.  It can cause unaligned reads from memory if you are not careful with the functions.  This is why
+it has been enabled by default only for the x86 class of processors where unaligned accesses are allowed.  Technically LTC\_FAST
+is not ``portable'' since unaligned accesses are not covered by the ISO C specifications.
+
+In practice however, you can use it on pretty much any platform (even MIPS) with care.
+
+By design the ``fast'' mode functions won't get unaligned on their own.  For instance, if you call ctr\_encrypt() right after calling
+ctr\_start() and all the inputs you gave are aligned than ctr\_encrypt() will perform aligned memory operations only.  However, if you 
+call ctr\_encrypt() with an odd amount of plaintext then call it again the CTR pad (the IV) will be partially used.  This will
+cause the ctr routine to first use up the remaining pad bytes.  Then if there are enough plaintext bytes left it will use 
+whole word XOR operations.  These operations will be unaligned.
+
+The simplest precaution is to make sure you process all data in power of two blocks and handle ``remainder'' at the end.  e.g. If you are 
+CTR'ing a long stream process it in blocks of (say) four kilobytes and handle any remaining incomplete blocks at the end of the stream.  
+
+If you do plan on using the ``LTC\_FAST'' mode you have to also define a ``LTC\_FAST\_TYPE'' macro which resolves to an optimal sized
+data type you can perform integer operations with.  Ideally it should be four or eight bytes since it must properly divide the size 
+of your block cipher (e.g. 16 bytes for AES).  This means sadly if you're on a platform with 57--bit words (or something) you can't 
+use this mode.  So sad.
+
+\subsection{LTC\_PTHREAD}
+When this is activated all of the descriptor table functions will use pthread locking to ensure thread safe updates to the tables.  Note that 
+it doesn't prevent a thread that is passively using a table from being messed up by another thread that updates the table.
+
+Generally the rule of thumb is to setup the tables once at startup and then leave them be.  This added build flag simply makes updating
+the tables safer.
+
+\section{MPI Tweaks}
+\subsection{RSA Only Tweak}
+If you plan on only using RSA with moduli in the range of 1024 to 2560 bits you can enable a series of tweaks
+to reduce the library size.  Follow these steps
+
+\begin{enumerate}
+   \item Undefine MDSA, MECC and MDH from tomcrypt\_custom.h
+   \item Undefine LTM\_ALL  from tommath\_superclass.h
+   \item Define SC\_RSA\_1 from tommath\_superclass.h
+   \item Rebuild the library.
+\end{enumerate}
+
+\chapter{Optimizations}
+\section{Introduction}
+The entire API was designed with plug and play in mind at the low level.  That is you can swap out any cipher, hash or PRNG and dependent API will not require
+updating.  This has the nice benefit that I can add ciphers not have to re--write large portions of the API.  For the most part LibTomCrypt has also been written
+to be highly portable and easy to build out of the box on pretty much any platform.  As such there are no assembler inlines throughout the code, I make no assumptions
+about the platform, etc...
+
+That works well for most cases but there are times where time is of the essence.  This API also allows optimized routines to be dropped in--place of the existing
+portable routines.  For instance, hand optimized assembler versions of AES could be provided and any existing function that uses the cipher could automatically use
+the optimized code without re--writing.  This also paves the way for hardware drivers that can access hardware accelerated cryptographic devices.
+
+At the heart of this flexibility is the ``descriptor'' system.  A descriptor is essentially just a C ``struct'' which describes the algorithm and provides pointers
+to functions that do the work.  For a given class of operation (e.g. cipher, hash, prng) the functions have identical prototypes which makes development simple.  In most
+dependent routines all a developer has to do is register\_XXX() the descriptor and they're set.
+
+\section{Ciphers}
+The ciphers in LibTomCrypt are accessed through the ltc\_cipher\_descriptor structure.
+
+\begin{small}
+\begin{verbatim}
+struct ltc_cipher_descriptor {
+   /** name of cipher */
+   char *name;
+   /** internal ID */
+   unsigned char ID;
+   /** min keysize (octets) */
+   int  min_key_length, 
+   /** max keysize (octets) */
+        max_key_length, 
+   /** block size (octets) */
+        block_length, 
+   /** default number of rounds */
+        default_rounds;
+   /** Setup the cipher 
+      @param key         The input symmetric key
+      @param keylen      The length of the input key (octets)
+      @param num_rounds  The requested number of rounds (0==default)
+      @param skey        [out] The destination of the scheduled key
+      @return CRYPT_OK if successful
+   */
+   int  (*setup)(const unsigned char *key, int keylen, 
+                 int num_rounds, symmetric_key *skey);
+   /** Encrypt a block
+      @param pt      The plaintext
+      @param ct      [out] The ciphertext
+      @param skey    The scheduled key
+   */
+   void (*ecb_encrypt)(const unsigned char *pt, 
+                             unsigned char *ct, symmetric_key *skey);
+   /** Decrypt a block
+      @param ct      The ciphertext
+      @param pt      [out] The plaintext
+      @param skey    The scheduled key
+   */
+   void (*ecb_decrypt)(const unsigned char *ct, 
+                             unsigned char *pt, symmetric_key *skey);
+   /** Test the block cipher
+       @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+   */
+   int (*test)(void);
+   /** Determine a key size
+       @param keysize    [in/out] The size of the key desired and the suggested size
+       @return CRYPT_OK if successful
+   */
+   int  (*keysize)(int *keysize);
+
+/** Accelerators **/
+   /** Accelerated ECB encryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param skey    The scheduled key context
+   */
+   void (*accel_ecb_encrypt)(const unsigned char *pt, 
+                                   unsigned char *ct, unsigned long blocks, 
+                             symmetric_key *skey);
+
+   /** Accelerated ECB decryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param skey    The scheduled key context
+   */
+   void (*accel_ecb_decrypt)(const unsigned char *ct, 
+                                   unsigned char *pt, unsigned long blocks, 
+                             symmetric_key *skey);
+
+   /** Accelerated CBC encryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param IV      The initial value (input/output)
+       @param skey    The scheduled key context
+   */
+   void (*accel_cbc_encrypt)(const unsigned char *pt, 
+                                   unsigned char *ct, unsigned long blocks, 
+                                   unsigned char *IV, symmetric_key *skey);
+
+   /** Accelerated CBC decryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param IV      The initial value (input/output)
+       @param skey    The scheduled key context
+   */
+   void (*accel_cbc_decrypt)(const unsigned char *ct, 
+                                   unsigned char *pt, unsigned long blocks, 
+                                   unsigned char *IV, symmetric_key *skey);
+
+   /** Accelerated CTR encryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param IV      The initial value (input/output)
+       @param mode    little or big endian counter (mode=0 or mode=1)
+       @param skey    The scheduled key context
+   */
+   void (*accel_ctr_encrypt)(const unsigned char *pt, 
+                                   unsigned char *ct, unsigned long blocks, 
+                                   unsigned char *IV, int mode, symmetric_key *skey);
+
+   /** Accelerated CCM packet (one-shot)
+       @param key        The secret key to use
+       @param keylen     The length of the secret key (octets)
+       @param nonce      The session nonce [use once]
+       @param noncelen   The length of the nonce
+       @param header     The header for the session
+       @param headerlen  The length of the header (octets)
+       @param pt         [out] The plaintext
+       @param ptlen      The length of the plaintext (octets)
+       @param ct         [out] The ciphertext
+       @param tag        [out] The destination tag
+       @param taglen     [in/out] The max size and resulting size of the authentication tag
+       @param direction  Encrypt or Decrypt direction (0 or 1)
+       @return CRYPT_OK if successful
+   */
+   void (*accel_ccm_memory)(
+       const unsigned char *key,    unsigned long keylen,
+       const unsigned char *nonce,  unsigned long noncelen,
+       const unsigned char *header, unsigned long headerlen,
+             unsigned char *pt,     unsigned long ptlen,
+             unsigned char *ct,
+             unsigned char *tag,    unsigned long *taglen,
+                       int  direction);
+
+   /** Accelerated GCM packet (one shot)
+       @param key               The secret key
+       @param keylen            The length of the secret key
+       @param IV                The initial vector 
+       @param IVlen             The length of the initial vector
+       @param adata             The additional authentication data (header)
+       @param adatalen          The length of the adata
+       @param pt                The plaintext
+       @param ptlen             The length of the plaintext (ciphertext length is the same)
+       @param ct                The ciphertext
+       @param tag               [out] The MAC tag
+       @param taglen            [in/out] The MAC tag length
+       @param direction         Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
+   */
+   void (*accel_gcm_memory)(
+       const unsigned char *key,    unsigned long keylen,
+       const unsigned char *IV,     unsigned long IVlen,
+       const unsigned char *adata,  unsigned long adatalen,
+             unsigned char *pt,     unsigned long ptlen,
+             unsigned char *ct, 
+             unsigned char *tag,    unsigned long *taglen,
+                       int direction);
+
+};
+\end{verbatim}
+\end{small}
+
+\subsection{Name}
+The ``name'' parameter specifies the name of the cipher.  This is what a developer would pass to find\_cipher() to find the cipher in the descriptor
+tables.
+
+\subsection{Internal ID}
+This is a single byte Internal ID you can use to distingish ciphers from each other.
+
+\subsection{Key Lengths}
+The minimum key length is ``min\_key\_length'' and is measured in octets.  Similarly the maximum key length is ``max\_key\_length''.  They can be equal
+and both must valid key sizes for the cipher.  Values in between are not assumed to be valid though they may be.
+
+\subsection{Block Length}
+The size of the ciphers plaintext or ciphertext is ``block\_length'' and is measured in octets.
+
+\subsection{Rounds}
+Some ciphers allow different number of rounds to be used.  Usually you just use the default.  The default round count is ``default\_rounds''.
+
+\subsection{Setup}
+To initialize a cipher (for ECB mode) the function setup() was provided.  It accepts an array of key octets ``key'' of length ``keylen'' octets.  The user
+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''.
+
+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 
+must make sure you do not overwrite the output before you are finished with the input.
+
+\subsection{Testing}
+The test() function is used to self--test the ``device''.  It takes no arguments and returns \textbf{CRYPT\_OK} if all is working properly.
+
+\subsection{Key Sizing}
+Occasionally a function will want to find a suitable key size to use since the input is oddly sized.  The keysize() function is for this case.  It accepts a 
+pointer to an integer which represents the desired size.  The function then has to match it to the exact or a lower key size that is valid for the cipher.  For
+example, if the input is $25$ and $24$ is valid then it stores $24$ back in the pointed to integer.  It must not round up and must return an error if the keysize
+ cannot be mapped to a valid key size for the cipher.
+
+\subsection{Acceleration}
+The next set of functions cover the accelerated functionality of the cipher descriptor.  Any combination of these functions may be set to \textbf{NULL} to indicate
+it is not supported.  In those cases the software fallbacks are used (using the single ECB block routines).
+
+\subsubsection{Accelerated ECB}
+These two functions are meant for cases where a user wants to encrypt (in ECB mode no less) an array of blocks.  These functions are accessed
+through the accel\_ecb\_encrypt and accel\_ecb\_decrypt pointers.  The ``blocks'' count is the number of complete blocks to process.
+
+\subsubsection{Accelerated CBC} 
+These two functions are meant for accelerated CBC encryption.  These functions are accessed through the accel\_cbc\_encrypt and accel\_cbc\_decrypt pointers.
+The ``blocks'' value is the number of complete blocks to process.  The ``IV'' is the CBC initial vector.  It is an input upon calling this function and must be
+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 = 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.
+
+\begin{enumerate}
+   \item The accelerator is present
+   \item The CTR pad is empty
+   \item The remaining length of the input to process is greater than or equal to the block size.
+\end{enumerate}
+
+The ``CTR pad'' is empty when a multiple (including zero) blocks of text have been processed.  That is, if you pass in seven bytes to AES--CTR mode you would have to 
+pass in a minimum of nine extra bytes before the accelerator could be called.  The CTR accelerator must increment the counter (and store it back into the 
+buffer provided) before encrypting it to create the pad.  
+
+The accelerator will only be used to encrypt whole blocks.  Partial blocks are always handled in software.
+
+\subsubsection{Accelerated CCM}
+This function is meant for accelerated CCM encryption or decryption.  It processes the entire packet in one call.  Note that the setup() function will not
+be called prior to this.  This function must handle scheduling the key provided on its own.
+
+\subsubsection{Accelerated GCM}
+This function is meant for accelerated GCM encryption or decryption.  It processes the entire packet in one call.  Note that the setup() function will not
+be called prior to this.  This function must handle scheduling the key provided on its own.
+
+\section{One--Way Hashes}
+The hash functions are accessed through the ltc\_hash\_descriptor structure.
+
+\begin{small}
+\begin{verbatim}
+struct ltc_hash_descriptor {
+    /** name of hash */
+    char *name;
+    /** internal ID */
+    unsigned char ID;
+    /** Size of digest in octets */
+    unsigned long hashsize;
+    /** Input block size in octets */
+    unsigned long blocksize;
+    /** ASN.1 OID */
+    unsigned long OID[16];
+    /** Length of DER encoding */
+    unsigned long OIDlen;
+    /** Init a hash state
+      @param hash   The hash to initialize
+      @return CRYPT_OK if successful
+    */
+    int (*init)(hash_state *hash);
+    /** Process a block of data 
+      @param hash   The hash state
+      @param in     The data to hash
+      @param inlen  The length of the data (octets)
+      @return CRYPT_OK if successful
+    */
+    int (*process)(hash_state *hash, const unsigned char *in, unsigned long inlen);
+    /** Produce the digest and store it
+      @param hash   The hash state
+      @param out    [out] The destination of the digest
+      @return CRYPT_OK if successful
+    */
+    int (*done)(hash_state *hash, unsigned char *out);
+    /** Self-test
+      @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+    */
+    int (*test)(void);
+};
+\end{verbatim}
+\end{small}
+
+\subsection{Name}
+This is the name the hash is known by and what find\_hash() will look for.
+
+\subsection{Internal ID}
+This is the internal ID byte used to distinguish the hash from other hashes.
+
+\subsection{Digest Size}
+The ``hashsize'' variable indicates the length of the output in octets.
+
+\subsection{Block Size}
+The `blocksize'' variable indicates the length of input (in octets) that the hash processes in a given
+invokation.
+
+\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.
+
+\subsection{Process}
+This processes message bytes.  The algorithm must accept any length of input that the hash would allow.  The input is not
+guaranteed to be a multiple of the block size in length.
+
+\subsection{Done}
+The done function terminates the hash and returns the message digest.
+
+\subsection{Acceleration}
+A compatible accelerator must allow processing data in any granularity which may require internal padding on the driver side.  
+
+\section{Pseudo--Random Number Generators}
+The pseudo--random number generators are accessible through the ltc\_prng\_descriptor structure.
+
+\begin{small}
+\begin{verbatim}
+struct ltc_prng_descriptor {
+    /** Name of the PRNG */
+    char *name;
+    /** size in bytes of exported state */
+    int  export_size;
+    /** Start a PRNG state
+        @param prng   [out] The state to initialize
+        @return CRYPT_OK if successful
+    */
+    int (*start)(prng_state *prng);
+    /** Add entropy to the PRNG
+        @param in         The entropy
+        @param inlen      Length of the entropy (octets)\
+        @param prng       The PRNG state
+        @return CRYPT_OK if successful
+    */
+    int (*add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng);
+    /** Ready a PRNG state to read from
+        @param prng       The PRNG state to ready
+        @return CRYPT_OK if successful
+    */
+    int (*ready)(prng_state *prng);
+    /** Read from the PRNG
+        @param out     [out] Where to store the data
+        @param outlen  Length of data desired (octets)
+        @param prng    The PRNG state to read from
+        @return Number of octets read
+    */
+    unsigned long (*read)(unsigned char *out, unsigned long outlen, prng_state *prng);
+    /** Terminate a PRNG state
+        @param prng   The PRNG state to terminate
+        @return CRYPT_OK if successful
+    */
+    int (*done)(prng_state *prng);
+    /** Export a PRNG state  
+        @param out     [out] The destination for the state
+        @param outlen  [in/out] The max size and resulting size of the PRNG state
+        @param prng    The PRNG to export
+        @return CRYPT_OK if successful
+    */
+    int (*pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng);
+    /** Import a PRNG state
+        @param in      The data to import
+        @param inlen   The length of the data to import (octets)
+        @param prng    The PRNG to initialize/import
+        @return CRYPT_OK if successful
+    */
+    int (*pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng);
+    /** Self-test the PRNG
+        @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+    */
+    int (*test)(void);
+};
+\end{verbatim}
+\end{small}
+
+\subsection{Name}
+The name by which find\_prng() will find the PRNG.
+
+\subsection{Export Size}
+When an PRNG state is to be exported for future use you specify the space required in this variable.
+
+\subsection{Start}
+Initialize the PRNG and make it ready to accept entropy.
+
+\subsection{Entropy Addition}
+Add entropy to the PRNG state.  The exact behaviour of this function depends on the particulars of the PRNG.
+
+\subsection{Ready}
+This function makes the PRNG ready to read from by processing the entropy added.  The behaviour of this function depends
+on the specific PRNG used.
+
+\subsection{Read}
+Read from the PRNG and return the number of bytes read.  This function does not have to fill the buffer but it is best 
+if it does as many protocols do not retry reads and will fail on the first try.
+
+\subsection{Done}
+Terminate a PRNG state.  The behaviour of this function depends on the particular PRNG used.
+
+\subsection{Exporting and Importing}
+An exported PRNG state is data that the PRNG can later import to resume activity.  They're not meant to resume ``the same session''
+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.39 $   
+% $Date: 2005/06/27 13:08:28 $ 
diff --git a/crypt_argchk.c b/crypt_argchk.c
deleted file mode 100644
index 3bb73a0..0000000
--- a/crypt_argchk.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-#include <signal.h>
-
-#if (ARGTYPE == 0)
-void crypt_argchk(char *v, char *s, int d)
-{
- fprintf(stderr, "_ARGCHK '%s' failure on line %d of file %s\n",
-         v, d, s);
- (void)raise(SIGABRT);
-}
-#endif
diff --git a/crypt_cipher_descriptor.c b/crypt_cipher_descriptor.c
deleted file mode 100644
index d103ea0..0000000
--- a/crypt_cipher_descriptor.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-struct _cipher_descriptor cipher_descriptor[TAB_SIZE] = {
-{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
-{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
-{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL },
-{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL } };
-
diff --git a/crypt_cipher_is_valid.c b/crypt_cipher_is_valid.c
deleted file mode 100644
index 8b0c448..0000000
--- a/crypt_cipher_is_valid.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int cipher_is_valid(int idx)
-{
-   if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
-      return CRYPT_INVALID_CIPHER;
-   }
-   return CRYPT_OK;
-}
diff --git a/crypt_find_cipher.c b/crypt_find_cipher.c
deleted file mode 100644
index 0aa88c7..0000000
--- a/crypt_find_cipher.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int find_cipher(const char *name)
-{
-   int x;
-   _ARGCHK(name != NULL);
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (cipher_descriptor[x].name != NULL && !strcmp(cipher_descriptor[x].name, name)) {
-          return x;
-       }
-   }
-   return -1;
-}
-
diff --git a/crypt_find_cipher_any.c b/crypt_find_cipher_any.c
deleted file mode 100644
index 81c33be..0000000
--- a/crypt_find_cipher_any.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* idea from Wayne Scott */
-int find_cipher_any(const char *name, int blocklen, int keylen)
-{
-   int x;
-
-   _ARGCHK(name != NULL);
-
-   x = find_cipher(name);
-   if (x != -1) return x;
-
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (cipher_descriptor[x].name == NULL) {
-          continue;
-       }
-       if (blocklen <= (int)cipher_descriptor[x].block_length && keylen <= (int)cipher_descriptor[x].max_key_length) {
-          return x;
-       }
-   }
-   return -1;
-}
diff --git a/crypt_find_cipher_id.c b/crypt_find_cipher_id.c
deleted file mode 100644
index 91b19d5..0000000
--- a/crypt_find_cipher_id.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int find_cipher_id(unsigned char ID)
-{
-   int x;
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (cipher_descriptor[x].ID == ID) {
-          return (cipher_descriptor[x].name == NULL) ? -1 : x;
-       }
-   }
-   return -1;
-}
diff --git a/crypt_find_hash.c b/crypt_find_hash.c
deleted file mode 100644
index 1422233..0000000
--- a/crypt_find_hash.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int find_hash(const char *name)
-{
-   int x;
-   _ARGCHK(name != NULL);
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (hash_descriptor[x].name != NULL && strcmp(hash_descriptor[x].name, name) == 0) {
-          return x;
-       }
-   }
-   return -1;
-}
diff --git a/crypt_find_hash_any.c b/crypt_find_hash_any.c
deleted file mode 100644
index 5b35252..0000000
--- a/crypt_find_hash_any.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* return first hash with at least [amount over] digestlen bytes of output */
-int find_hash_any(const char *name, int digestlen)
-{
-   int x, y, z;
-   _ARGCHK(name != NULL);
-
-   x = find_hash(name);
-   if (x != -1) return x;
-
-   y = MAXBLOCKSIZE+1;
-   z = -1;
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (hash_descriptor[x].name == NULL) {
-          continue;
-       }
-       if ((int)hash_descriptor[x].hashsize >= digestlen && (int)hash_descriptor[x].hashsize < y) {
-          z = x;
-          y = hash_descriptor[x].hashsize;
-       }
-   }
-   return z;
-}
diff --git a/crypt_find_hash_id.c b/crypt_find_hash_id.c
deleted file mode 100644
index ff04aea..0000000
--- a/crypt_find_hash_id.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int find_hash_id(unsigned char ID)
-{
-   int x;
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (hash_descriptor[x].ID == ID) {
-          return (hash_descriptor[x].name == NULL) ? -1 : x;
-       }
-   }
-   return -1;
-}
diff --git a/crypt_find_prng.c b/crypt_find_prng.c
deleted file mode 100644
index 7fc4e45..0000000
--- a/crypt_find_prng.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int find_prng(const char *name)
-{
-   int x;
-   _ARGCHK(name != NULL);
-   for (x = 0; x < TAB_SIZE; x++) {
-       if ((prng_descriptor[x].name != NULL) && strcmp(prng_descriptor[x].name, name) == 0) {
-          return x;
-       }
-   }
-   return -1;
-}
-
diff --git a/crypt_hash_descriptor.c b/crypt_hash_descriptor.c
deleted file mode 100644
index 697de38..0000000
--- a/crypt_hash_descriptor.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-struct _hash_descriptor hash_descriptor[TAB_SIZE] = {
-{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
-{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
-{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL },
-{ NULL, 0, 0, 0, { 0x00 }, 0, NULL, NULL, NULL, NULL } };
diff --git a/crypt_hash_is_valid.c b/crypt_hash_is_valid.c
deleted file mode 100644
index b924e59..0000000
--- a/crypt_hash_is_valid.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int hash_is_valid(int idx)
-{
-   if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
-      return CRYPT_INVALID_HASH;
-   }
-   return CRYPT_OK;
-}
diff --git a/crypt_prng_descriptor.c b/crypt_prng_descriptor.c
deleted file mode 100644
index 85f3ead..0000000
--- a/crypt_prng_descriptor.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-struct _prng_descriptor prng_descriptor[TAB_SIZE] = {
-{ NULL, NULL, NULL, NULL, NULL },
-{ NULL, NULL, NULL, NULL, NULL },
-{ NULL, NULL, NULL, NULL, NULL },
-{ NULL, NULL, NULL, NULL, NULL } };
-
diff --git a/crypt_prng_is_valid.c b/crypt_prng_is_valid.c
deleted file mode 100644
index cc66bc2..0000000
--- a/crypt_prng_is_valid.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int prng_is_valid(int idx)
-{
-   if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
-      return CRYPT_INVALID_PRNG;
-   }
-   return CRYPT_OK;
-}
diff --git a/crypt_register_cipher.c b/crypt_register_cipher.c
deleted file mode 100644
index 5fb0dcb..0000000
--- a/crypt_register_cipher.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int register_cipher(const struct _cipher_descriptor *cipher)
-{
-   int x;
-
-   _ARGCHK(cipher != NULL);
-
-   /* is it already registered? */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
-          return x;
-       }
-   }
-
-   /* find a blank spot */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (cipher_descriptor[x].name == NULL) {
-          memcpy(&cipher_descriptor[x], cipher, sizeof(struct _cipher_descriptor));
-          return x;
-       }
-   }
-
-   /* no spot */
-   return -1;
-}
diff --git a/crypt_register_hash.c b/crypt_register_hash.c
deleted file mode 100644
index 7603693..0000000
--- a/crypt_register_hash.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int register_hash(const struct _hash_descriptor *hash)
-{
-   int x;
-
-   _ARGCHK(hash != NULL);
-
-   /* is it already registered? */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (memcmp(&hash_descriptor[x], hash, sizeof(struct _hash_descriptor)) == 0) {
-          return x;
-       }
-   }
-
-   /* find a blank spot */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (hash_descriptor[x].name == NULL) {
-          memcpy(&hash_descriptor[x], hash, sizeof(struct _hash_descriptor));
-          return x;
-       }
-   }
-
-   /* no spot */
-   return -1;
-}
diff --git a/crypt_register_prng.c b/crypt_register_prng.c
deleted file mode 100644
index 1b14a33..0000000
--- a/crypt_register_prng.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int register_prng(const struct _prng_descriptor *prng)
-{
-   int x;
-
-   _ARGCHK(prng != NULL);
-
-   /* is it already registered? */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (memcmp(&prng_descriptor[x], prng, sizeof(struct _prng_descriptor)) == 0) {
-          return x;
-       }
-   }
-
-   /* find a blank spot */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (prng_descriptor[x].name == NULL) {
-          memcpy(&prng_descriptor[x], prng, sizeof(struct _prng_descriptor));
-          return x;
-       }
-   }
-
-   /* no spot */
-   return -1;
-}
diff --git a/crypt_unregister_cipher.c b/crypt_unregister_cipher.c
deleted file mode 100644
index 6321daf..0000000
--- a/crypt_unregister_cipher.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int unregister_cipher(const struct _cipher_descriptor *cipher)
-{
-   int x;
-
-   _ARGCHK(cipher != NULL);
-
-   /* is it already registered? */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (memcmp(&cipher_descriptor[x], cipher, sizeof(struct _cipher_descriptor)) == 0) {
-          cipher_descriptor[x].name = NULL;
-          cipher_descriptor[x].ID   = 255;
-          return CRYPT_OK;
-       }
-   }
-   return CRYPT_ERROR;
-}
diff --git a/crypt_unregister_hash.c b/crypt_unregister_hash.c
deleted file mode 100644
index fcdca5f..0000000
--- a/crypt_unregister_hash.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int unregister_hash(const struct _hash_descriptor *hash)
-{
-   int x;
-
-   _ARGCHK(hash != NULL);
-
-   /* is it already registered? */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (memcmp(&hash_descriptor[x], hash, sizeof(struct _hash_descriptor)) == 0) {
-          hash_descriptor[x].name = NULL;
-          return CRYPT_OK;
-       }
-   }
-   return CRYPT_ERROR;
-}
diff --git a/crypt_unregister_prng.c b/crypt_unregister_prng.c
deleted file mode 100644
index c315338..0000000
--- a/crypt_unregister_prng.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int unregister_prng(const struct _prng_descriptor *prng)
-{
-   int x;
-
-   _ARGCHK(prng != NULL);
-
-   /* is it already registered? */
-   for (x = 0; x < TAB_SIZE; x++) {
-       if (memcmp(&prng_descriptor[x], prng, sizeof(struct _prng_descriptor)) != 0) {
-          prng_descriptor[x].name = NULL;
-          return CRYPT_OK;
-       }
-   }
-   return CRYPT_ERROR;
-}
diff --git a/ctr_decrypt.c b/ctr_decrypt.c
deleted file mode 100644
index dce3a39..0000000
--- a/ctr_decrypt.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CTR
-
-int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr)
-{
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(ctr != NULL);
-
-   return ctr_encrypt(ct, pt, len, ctr);
-}
-
-#endif
-
diff --git a/ctr_encrypt.c b/ctr_encrypt.c
deleted file mode 100644
index 476de38..0000000
--- a/ctr_encrypt.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CTR
-
-int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr)
-{
-   int x, err;
-
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(ctr != NULL);
-
-   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
-       return err;
-   }
-   
-   /* is blocklen/padlen valid? */
-   if (ctr->blocklen < 0 || ctr->blocklen > (int)sizeof(ctr->ctr) ||
-       ctr->padlen   < 0 || ctr->padlen   > (int)sizeof(ctr->pad)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   while (len-- > 0) {
-      /* is the pad empty? */
-      if (ctr->padlen == ctr->blocklen) {
-         /* increment counter */
-         if (ctr->mode == 0) {
-            /* little-endian */
-            for (x = 0; x < ctr->blocklen; x++) {
-               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
-               if (ctr->ctr[x] != (unsigned char)0) {
-                  break;
-               }
-            }
-         } else {
-            /* big-endian */
-            for (x = ctr->blocklen-1; x >= 0; x--) {
-               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
-               if (ctr->ctr[x] != (unsigned char)0) {
-                  break;
-               }
-            }
-         }
-
-         /* encrypt it */
-         cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
-         ctr->padlen = 0;
-      }
-      *ct++ = *pt++ ^ ctr->pad[ctr->padlen++];
-   }
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/ctr_getiv.c b/ctr_getiv.c
deleted file mode 100644
index fb40f0b..0000000
--- a/ctr_getiv.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef CTR
-
-int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr)
-{
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(len != NULL);
-   _ARGCHK(ctr != NULL);
-   if ((unsigned long)ctr->blocklen > *len) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   memcpy(IV, ctr->ctr, ctr->blocklen);
-   *len = ctr->blocklen;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/ctr_setiv.c b/ctr_setiv.c
deleted file mode 100644
index 5aa2f2f..0000000
--- a/ctr_setiv.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef CTR
-
-int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
-{
-   int err;
-   
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(ctr != NULL);
-
-   /* bad param? */
-   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
-      return err;
-   }
-   
-   if (len != (unsigned long)ctr->blocklen) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* set IV */
-   memcpy(ctr->ctr, IV, len);
-   
-   /* force next block */
-   ctr->padlen = 0;
-   cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
-   
-   return CRYPT_OK;
-}
-
-#endif 
-
diff --git a/ctr_start.c b/ctr_start.c
deleted file mode 100644
index f752b65..0000000
--- a/ctr_start.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef CTR
-
-int ctr_start(int cipher, const unsigned char *count, const unsigned char *key, int keylen, 
-              int num_rounds, symmetric_CTR *ctr)
-{
-   int x, err;
-
-   _ARGCHK(count != NULL);
-   _ARGCHK(key != NULL);
-   _ARGCHK(ctr != NULL);
-
-   /* bad param? */
-   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* setup cipher */
-   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* copy ctr */
-   ctr->blocklen = cipher_descriptor[cipher].block_length;
-   ctr->cipher   = cipher;
-   ctr->padlen   = 0;
-   ctr->mode     = 0;
-   for (x = 0; x < ctr->blocklen; x++) {
-       ctr->ctr[x] = count[x];
-   }
-   cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/demos/encrypt.c b/demos/encrypt.c
index 5320c21..d8eb293 100644
--- a/demos/encrypt.c
+++ b/demos/encrypt.c
@@ -7,7 +7,7 @@
 /* ie: ./encrypt blowfish story.txt story.ct */
 /* ./encrypt -d blowfish story.ct story.pt */
 
-#include <mycrypt.h>
+#include <tomcrypt.h>
 
 int errno;
 
@@ -69,6 +69,12 @@
 #ifdef SKIPJACK
   register_cipher (&skipjack_desc);
 #endif
+#ifdef KHAZAD
+  register_cipher (&khazad_desc);
+#endif
+#ifdef ANUBIS
+  register_cipher (&anubis_desc);
+#endif
 
    if (register_hash(&sha256_desc) == -1) {
       printf("Error registering SHA256\n");
@@ -229,3 +235,7 @@
    }
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/encrypt.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:56 $ */
diff --git a/demos/hashsum.c b/demos/hashsum.c
index e0269b3..653b6ef 100644
--- a/demos/hashsum.c
+++ b/demos/hashsum.c
@@ -7,7 +7,7 @@
  * more functions ;)
 */
 
-#include <mycrypt_custom.h>
+#include <tomcrypt.h>
 
 int errno;
 
@@ -26,7 +26,7 @@
       printf("usage: ./hash algorithm file [file ...]\n");
       printf("Algorithms:\n");
       for (x = 0; hash_descriptor[x].name != NULL; x++) {
-         printf(" %s\n", hash_descriptor[x].name);
+         printf(" %s (%d)\n", hash_descriptor[x].name, hash_descriptor[x].ID);
       }
       exit(EXIT_SUCCESS);
    }
@@ -66,6 +66,8 @@
 
 void register_algs(void)
 {
+  int err;
+
 #ifdef TIGER
   register_hash (&tiger_desc);
 #endif
@@ -102,5 +104,16 @@
 #ifdef WHIRLPOOL
   register_hash (&whirlpool_desc);
 #endif
+#ifdef CHC_HASH
+  register_hash(&chc_desc);
+  if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) {
+     printf("chc_register error: %s\n", error_to_string(err));
+     exit(EXIT_FAILURE);
+  }
+#endif
 
 }
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/hashsum.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:56 $ */
diff --git a/demos/multi.c b/demos/multi.c
new file mode 100644
index 0000000..af4d6b6
--- /dev/null
+++ b/demos/multi.c
@@ -0,0 +1,110 @@
+/* test the multi helpers... */
+#include <tomcrypt.h>
+
+int main(void)
+{
+   unsigned char key[16], buf[2][MAXBLOCKSIZE];
+   unsigned long len, len2;
+
+
+/* register algos */
+   register_hash(&sha256_desc);
+   register_cipher(&aes_desc);
+
+/* HASH testing */
+   len = sizeof(buf[0]);
+   hash_memory(find_hash("sha256"), "hello", 5, buf[0], &len);
+   len2 = sizeof(buf[0]);
+   hash_memory_multi(find_hash("sha256"), buf[1], &len2, "hello", 5, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   hash_memory_multi(find_hash("sha256"), buf[1], &len2, "he", 2, "llo", 3, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   hash_memory_multi(find_hash("sha256"), buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+
+/* HMAC */
+   len = sizeof(buf[0]);
+   hmac_memory(find_hash("sha256"), key, 16, "hello", 5, buf[0], &len);
+   len2 = sizeof(buf[0]);
+   hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "hello", 5, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   hmac_memory_multi(find_hash("sha256"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+
+/* OMAC */
+   len = sizeof(buf[0]);
+   omac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len);
+   len2 = sizeof(buf[0]);
+   omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   omac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+
+/* PMAC */
+   len = sizeof(buf[0]);
+   pmac_memory(find_cipher("aes"), key, 16, "hello", 5, buf[0], &len);
+   len2 = sizeof(buf[0]);
+   pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "hello", 5, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "he", 2, "llo", 3, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+   len2 = sizeof(buf[0]);
+   pmac_memory_multi(find_cipher("aes"), key, 16, buf[1], &len2, "h", 1, "e", 1, "l", 1, "l", 1, "o", 1, NULL);
+   if (len != len2 || memcmp(buf[0], buf[1], len)) {
+      printf("Failed: %d %lu %lu\n", __LINE__, len, len2);
+      return EXIT_FAILURE;
+   }
+
+
+   printf("All passed\n");
+   return EXIT_SUCCESS;
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/multi.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:56 $ */
diff --git a/demos/small.c b/demos/small.c
index f5a0d43..6bdd842 100644
--- a/demos/small.c
+++ b/demos/small.c
@@ -1,6 +1,5 @@
 // small demo app that just includes a cipher/hash/prng
-
-#include <mycrypt.h>
+#include <tomcrypt.h>
 
 int main(void)
 {
@@ -9,3 +8,7 @@
    register_hash(&sha256_desc);
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/small.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:56 $ */
diff --git a/demos/test.c b/demos/test.c
index a2684fb..f6c7170 100644
--- a/demos/test.c
+++ b/demos/test.c
@@ -1,1622 +1,24 @@
-/* This is the worst code you have ever seen written on purpose.... this code is just a big hack to test
-out the functionality of the library */
+#include <tomcrypt_test.h>
 
-#ifdef SONY_PS2
-#include <eetypes.h>
-#include <eeregs.h>
-#include "timer.h"
-#endif
-
-#include <mycrypt.h>
-
-int     errnum;
-
-
-int
-null_setup (const unsigned char *key, int keylen, int num_rounds,
-        symmetric_key * skey)
+int main(void)
 {
-  return CRYPT_OK;
+   int x;
+   reg_algs();
+   printf("build == \n%s\n", crypt_build_settings);
+   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("\nder_test......"); fflush(stdout); x = der_tests();        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("\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;
 }
 
-void
-null_ecb_encrypt (const unsigned char *pt, unsigned char *ct,
-          symmetric_key * key)
-{
-  memcpy (ct, pt, 8);
-}
-
-void
-null_ecb_decrypt (const unsigned char *ct, unsigned char *pt,
-          symmetric_key * key)
-{
-  memcpy (pt, ct, 8);
-}
-
-int
-null_test (void)
-{
-  return CRYPT_OK;
-}
-
-int
-null_keysize (int *desired_keysize)
-{
-  return CRYPT_OK;
-}
-
-const struct _cipher_descriptor null_desc = {
-  "memcpy()",
-  255,
-  8, 8, 8, 1,
-  &null_setup,
-  &null_ecb_encrypt,
-  &null_ecb_decrypt,
-  &null_test,
-  &null_keysize
-};
-
-
-prng_state prng;
-
-void
-store_tests (void)
-{
-  unsigned char buf[8];
-  unsigned long L;
-  ulong64 LL;
-
-  printf ("LOAD32/STORE32 tests\n");
-  L = 0x12345678UL;
-  STORE32L (L, &buf[0]);
-  L = 0;
-  LOAD32L (L, &buf[0]);
-  if (L != 0x12345678UL) {
-    printf ("LOAD/STORE32 Little don't work\n");
-    exit (-1);
-  }
-  LL = CONST64 (0x01020304050607);
-  STORE64L (LL, &buf[0]);
-  LL = 0;
-  LOAD64L (LL, &buf[0])
-    if (LL != CONST64 (0x01020304050607)) {
-    printf ("LOAD/STORE64 Little don't work\n");
-    exit (-1);
-  }
-
-  L = 0x12345678UL;
-  STORE32H (L, &buf[0]);
-  L = 0;
-  LOAD32H (L, &buf[0]);
-  if (L != 0x12345678UL) {
-    printf ("LOAD/STORE32 High don't work, %08lx\n", L);
-    exit (-1);
-  }
-  LL = CONST64 (0x01020304050607);
-  STORE64H (LL, &buf[0]);
-  LL = 0;
-  LOAD64H (LL, &buf[0])
-    if (LL != CONST64 (0x01020304050607)) {
-    printf ("LOAD/STORE64 High don't work\n");
-    exit (-1);
-  }
-}
-
-void
-cipher_tests (void)
-{
-  int     x;
-
-  printf ("Ciphers compiled in\n");
-  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
-    printf
-      (" %12s (%2d) Key Size: %4d to %4d, Block Size: %3d, Default # of rounds: %2d\n",
-       cipher_descriptor[x].name, cipher_descriptor[x].ID,
-       cipher_descriptor[x].min_key_length * 8,
-       cipher_descriptor[x].max_key_length * 8,
-       cipher_descriptor[x].block_length * 8,
-       cipher_descriptor[x].default_rounds);
-  }
-
-}
-
-void
-ecb_tests (void)
-{
-  int     x;
-
-  printf ("ECB tests\n");
-  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
-    printf (" %12s: ", cipher_descriptor[x].name);
-    if ((errnum = cipher_descriptor[x].test ()) != CRYPT_OK) {
-      printf (" **failed** Reason: %s\n", error_to_string (errnum));
-      exit (-1);
-    } else {
-      printf ("passed\n");
-    }
-  }
-}
-
-#ifdef CBC
-void
-cbc_tests (void)
-{
-  symmetric_CBC cbc;
-  int     x, y;
-  unsigned char blk[32], ct[32], key[32], IV[32];
-  const unsigned char test[] =
-    { 0XFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
-  printf ("CBC tests\n");
-  /* ---- CBC ENCODING ---- */
-  /* make up a block and IV */
-  for (x = 0; x < 32; x++)
-    blk[x] = IV[x] = x;
-
-  /* now lets start a cbc session */
-  if ((errnum =
-       cbc_start (find_cipher ("blowfish"), IV, key, 16, 0,
-          &cbc)) != CRYPT_OK) {
-    printf ("CBC Setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets encode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = cbc_encrypt (blk + 8 * x, ct + 8 * x, &cbc)) != CRYPT_OK) {
-      printf ("CBC encrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  zeromem (blk, sizeof (blk));
-
-  /* ---- CBC DECODING ---- */
-  /* make up a IV */
-  for (x = 0; x < 32; x++)
-    IV[x] = x;
-
-  /* now lets start a cbc session */
-  if ((errnum =
-       cbc_start (find_cipher ("blowfish"), IV, key, 16, 0,
-          &cbc)) != CRYPT_OK) {
-    printf ("CBC Setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets decode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = cbc_decrypt (ct + 8 * x, blk + 8 * x, &cbc)) != CRYPT_OK) {
-      printf ("CBC decrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-
-  /* print output */
-  for (x = y = 0; x < 32; x++)
-    if (blk[x] != x)
-      y = 1;
-  printf ("  %s\n", y ? "failed" : "passed");
-
-  /* lets actually check the bytes */
-  memset (IV, 0, 8);
-  IV[0] = 0xFF;         /* IV  = FF 00 00 00 00 00 00 00 */
-  memset (blk, 0, 32);
-  blk[8] = 0xFF;        /* BLK = 00 00 00 00 00 00 00 00 FF 00 00 00 00 00 00 00 */
-  cbc_start (find_cipher ("memcpy()"), IV, key, 8, 0, &cbc);
-  cbc_encrypt (blk, ct, &cbc);  /* expect: FF 00 00 00 00 00 00 00 */
-  cbc_encrypt (blk + 8, ct + 8, &cbc);  /* expect: 00 00 00 00 00 00 00 00 */
-  if (memcmp (ct, test, 16)) {
-    printf ("CBC failed logical testing.\n");
-    for (x = 0; x < 16; x++)
-      printf ("%02x ", ct[x]);
-    printf ("\n");
-    exit (-1);
-  } else {
-    printf ("CBC passed logical testing.\n");
-  }
-}
-#else
-void
-cbc_tests (void)
-{
-  printf ("CBC not compiled in\n");
-}
-#endif
-
-#ifdef OFB
-void
-ofb_tests (void)
-{
-  symmetric_OFB ofb;
-  int     x, y;
-  unsigned char blk[32], ct[32], key[32], IV[32];
-
-  printf ("OFB tests\n");
-  /* ---- ofb ENCODING ---- */
-  /* make up a block and IV */
-  for (x = 0; x < 32; x++)
-    blk[x] = IV[x] = x;
-
-  /* now lets start a ofb session */
-  if ((errnum =
-       ofb_start (find_cipher ("cast5"), IV, key, 16, 0, &ofb)) != CRYPT_OK) {
-    printf ("OFB Setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets encode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = ofb_encrypt (blk + 8 * x, ct + 8 * x, 8, &ofb)) != CRYPT_OK) {
-      printf ("OFB encrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  zeromem (blk, sizeof (blk));
-
-  /* ---- ofb DECODING ---- */
-  /* make up a IV */
-  for (x = 0; x < 32; x++)
-    IV[x] = x;
-
-  /* now lets start a ofb session */
-  if ((errnum =
-       ofb_start (find_cipher ("cast5"), IV, key, 16, 0, &ofb)) != CRYPT_OK) {
-    printf ("OFB setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets decode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = ofb_decrypt (ct + 8 * x, blk + 8 * x, 8, &ofb)) != CRYPT_OK) {
-      printf ("OFB decrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  /* print output */
-  for (x = y = 0; x < 32; x++)
-    if (blk[x] != x)
-      y = 1;
-  printf ("  %s\n", y ? "failed" : "passed");
-  if (y)
-    exit (-1);
-}
-#else
-void
-ofb_tests (void)
-{
-  printf ("OFB not compiled in\n");
-}
-#endif
-
-#ifdef CFB
-void
-cfb_tests (void)
-{
-  symmetric_CFB cfb;
-  int     x, y;
-  unsigned char blk[32], ct[32], key[32], IV[32];
-
-  printf ("CFB tests\n");
-  /* ---- cfb ENCODING ---- */
-  /* make up a block and IV */
-  for (x = 0; x < 32; x++)
-    blk[x] = IV[x] = x;
-
-  /* now lets start a cfb session */
-  if ((errnum =
-       cfb_start (find_cipher ("blowfish"), IV, key, 16, 0,
-          &cfb)) != CRYPT_OK) {
-    printf ("CFB setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets encode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = cfb_encrypt (blk + 8 * x, ct + 8 * x, 8, &cfb)) != CRYPT_OK) {
-      printf ("CFB encrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  zeromem (blk, sizeof (blk));
-
-  /* ---- cfb DECODING ---- */
-  /* make up ahash_descriptor[prng->yarrow.hash].hashsize IV */
-  for (x = 0; x < 32; x++)
-    IV[x] = x;
-
-  /* now lets start a cfb session */
-  if ((errnum =
-       cfb_start (find_cipher ("blowfish"), IV, key, 16, 0,
-          &cfb)) != CRYPT_OK) {
-    printf ("CFB Setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets decode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = cfb_decrypt (ct + 8 * x, blk + 8 * x, 8, &cfb)) != CRYPT_OK) {
-      printf ("CFB decrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  /* print output */
-  for (x = y = 0; x < 32; x++)
-    if (blk[x] != x)
-      y = 1;
-  printf ("  %s\n", y ? "failed" : "passed");
-  if (y)
-    exit (-1);
-}
-#else
-void
-cfb_tests (void)
-{
-  printf ("CFB not compiled in\n");
-}
-#endif
-
-#ifdef CTR
-void
-ctr_tests (void)
-{
-  symmetric_CTR ctr;
-  int     x, y;
-  unsigned char blk[32], ct[32], key[32], count[32];
-  const unsigned char test[] =
-    { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0 };
-
-  printf ("CTR tests\n");
-  /* ---- CTR ENCODING ---- */
-  /* make up a block and IV */
-  for (x = 0; x < 32; x++)
-    blk[x] = count[x] = x;
-
-  /* now lets start a ctr session */
-  if ((errnum =
-       ctr_start (find_cipher ("xtea"), count, key, 16, 0,
-          &ctr)) != CRYPT_OK) {
-    printf ("CTR Setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets encode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = ctr_encrypt (blk + 8 * x, ct + 8 * x, 8, &ctr)) != CRYPT_OK) {
-      printf ("CTR encrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  zeromem (blk, sizeof (blk));
-
-  /* ---- CTR DECODING ---- */
-  /* make up a IV */
-  for (x = 0; x < 32; x++)
-    count[x] = x;
-
-  /* now lets start a cbc session */
-  if ((errnum =
-       ctr_start (find_cipher ("xtea"), count, key, 16, 0,
-          &ctr)) != CRYPT_OK) {
-    printf ("CTR Setup: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* now lets decode 32 bytes */
-  for (x = 0; x < 4; x++) {
-    if ((errnum = ctr_decrypt (ct + 8 * x, blk + 8 * x, 8, &ctr)) != CRYPT_OK) {
-      printf ("CTR decrypt: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-  }
-
-  /* print output */
-  for (x = y = 0; x < 32; x++)
-    if (blk[x] != x)
-      y = 1;
-  printf ("  %s\n", y ? "failed" : "passed");
-  if (y)
-    exit (-1);
-
-  /* lets actually check the bytes */
-  memset (count, 0, 8);
-  count[0] = 0xFF;      /* IV  = FF 00 00 00 00 00 00 00 */
-  memset (blk, 0, 32);
-  blk[9] = 2;           /* BLK = 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 */
-  ctr_start (find_cipher ("memcpy()"), count, key, 8, 0, &ctr);
-  ctr_encrypt (blk, ct, 8, &ctr);   /* expect: FF 00 00 00 00 00 00 00 */
-  ctr_encrypt (blk + 8, ct + 8, 8, &ctr);   /* expect: 00 03 00 00 00 00 00 00 */
-  if (memcmp (ct, test, 16)) {
-    printf ("CTR failed logical testing.\n");
-    for (x = 0; x < 16; x++)
-      printf ("%02x ", ct[x]);
-    printf ("\n");
-  } else {
-    printf ("CTR passed logical testing.\n");
-  }
-
-}
-#else
-void
-ctr_tests (void)
-{
-  printf ("CTR not compiled in\n");
-}
-#endif
-
-void
-hash_tests (void)
-{
-  int     x;
-  printf ("Hash tests\n");
-  for (x = 0; hash_descriptor[x].name != NULL; x++) {
-    printf (" %10s (%2d) ", hash_descriptor[x].name, hash_descriptor[x].ID);
-    if ((errnum = hash_descriptor[x].test ()) != CRYPT_OK) {
-      printf ("**failed** Reason: %s\n", error_to_string (errnum));
-      exit(-1);
-    } else {
-      printf ("passed\n");
-    }
-  }
-}
-
-#ifdef MRSA
-void
-pad_test (void)
-{
-  unsigned char in[100], out[100];
-  unsigned long x, y;
-
-  /* make a dummy message */
-  for (x = 0; x < 16; x++)
-    in[x] = (unsigned char) x;
-
-  /* pad the message so that random filler is placed before and after it */
-  y = 100;
-  if ((errnum =
-       rsa_pad (in, 16, out, &y, find_prng ("yarrow"), &prng)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* depad the message to get the original content */
-  memset (in, 0, sizeof (in));
-  x = 100;
-  if ((errnum = rsa_depad (out, y, in, &x)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* check outcome */
-  printf ("rsa_pad: ");
-  if (x != 16) {
-    printf ("Failed.  Wrong size.\n");
-    exit (-1);
-  }
-  for (x = 0; x < 16; x++)
-    if (in[x] != x) {
-      printf ("Failed.  Expected %02lx and got %02x.\n", x, in[x]);
-      exit (-1);
-    }
-  printf ("passed.\n");
-}
-void
-rsa_test (void)
-{
-  unsigned char in[520], out[520];
-  unsigned long x, y, z, limit;
-  int     stat;
-  rsa_key key;
-  clock_t t;
-
-  /* ---- SINGLE ENCRYPT ---- */
-  /* encrypt a short 8 byte string */
-  if ((errnum =
-       rsa_make_key (&prng, find_prng ("yarrow"), 1024 / 8, 65537,
-             &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  for (x = 0; x < 8; x++)
-    in[x] = (unsigned char) (x + 1);
-  y = sizeof (in);
-  if ((errnum = rsa_exptmod (in, 8, out, &y, PK_PUBLIC, &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* decrypt it */
-  zeromem (in, sizeof (in));
-  x = sizeof (out);
-  if ((errnum = rsa_exptmod (out, y, in, &x, PK_PRIVATE, &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* compare */
-  printf ("RSA    : ");
-  for (x = 0; x < 8; x++)
-    if (in[x] != (x + 1)) {
-      printf ("Failed.  x==%02lx, in[%ld]==%02x\n", x, x, in[x]);
-      exit (-1);
-    }
-  printf ("passed.\n");
-
-  /* test the rsa_encrypt_key functions */
-  for (x = 0; x < 16; x++)
-    in[x] = x;
-  y = sizeof (out);
-  if ((errnum =
-       rsa_encrypt_key (in, 16, out, &y, &prng, find_prng ("yarrow"),
-            &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  zeromem (in, sizeof (in));
-  x = sizeof (in);
-  if ((errnum = rsa_decrypt_key (out, y, in, &x, &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("RSA en/de crypt key routines: ");
-  if (x != 16) {
-    printf ("Failed (length)\n");
-    exit (-1);
-  }
-  for (x = 0; x < 16; x++)
-    if (in[x] != x) {
-      printf ("Failed (contents)\n");
-      exit (-1);
-    }
-  printf ("Passed\n");
-
-  /* test sign_hash functions */
-  for (x = 0; x < 16; x++)
-    in[x] = x;
-  x = sizeof (in);
-  if ((errnum = rsa_sign_hash (in, 16, out, &x, &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("RSA signed hash: %lu bytes\n", x);
-  if ((errnum = rsa_verify_hash (out, x, in, &stat, &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("Verify hash: %s, ", stat ? "passed" : "failed");
-  in[0] ^= 1;
-  if ((errnum = rsa_verify_hash (out, x, in, &stat, &key)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("%s\n", (!stat) ? "passed" : "failed");
-  if (stat)
-    exit (-1);
-  rsa_free (&key);
-
-  /* make a RSA key */
-#ifdef SONY_PS2_NOPE
-  limit = 1024;
-#else
-  limit = 2048;
-#endif
-
-  {
-    int     tt;
-
-    for (z = 1024; z <= limit; z += 512) {
-      t = XCLOCK ();
-      for (tt = 0; tt < 3; tt++) {
-         if ((errnum = rsa_make_key (&prng, find_prng ("yarrow"), z / 8, 65537, &key)) != CRYPT_OK) {
-            printf ("Error: %s\n", error_to_string (errnum));
-            exit (-1);
-         }
-
-         /* check modulus size */
-         if (mp_unsigned_bin_size(&key.N) != (int)(z/8)) { 
-            printf("\nRSA key supposed to be %lu bits but was %d bits\n", z, mp_count_bits(&key.N));
-            exit(EXIT_FAILURE);
-         }
-
-         if (tt < 2) {
-            rsa_free (&key);
-         }
-      }
-      t = XCLOCK () - t;
-      printf ("Took %.0f ms to make a %ld-bit RSA key.\n", 1000.0 * (((double) t / 3.0) / (double) XCLOCKS_PER_SEC), z);
-
-      /* time encryption */
-      t = XCLOCK ();
-
-      for (tt = 0; tt < 20; tt++) {
-         y = sizeof (in);
-         if ((errnum = rsa_exptmod (in, 8, out, &y, PK_PUBLIC, &key)) != CRYPT_OK) {
-            printf ("Error: %s\n", error_to_string (errnum));
-            exit (-1);
-         }
-      }
-      t = XCLOCK () - t;
-      printf ("Took %.0f ms to encrypt with a %ld-bit RSA key.\n",
-              1000.0 * (((double) t / 20.0) / (double) XCLOCKS_PER_SEC), z);
-
-      /* time decryption */
-      t = XCLOCK ();
-      for (tt = 0; tt < 20; tt++) {
-          x = sizeof (out);
-          if ((errnum = rsa_exptmod (out, y, in, &x, PK_PRIVATE, &key)) != CRYPT_OK) {
-             printf ("Error: %s\n", error_to_string (errnum));
-             exit (-1);
-          }
-      }
-      t = XCLOCK () - t;
-      printf ("Took %.0f ms to decrypt with a %ld-bit RSA key.\n",
-      1000.0 * (((double) t / 20.0) / (double) XCLOCKS_PER_SEC), z);
-      rsa_free (&key);
-    }
-  }
-}
-#else
-void
-pad_test (void)
-{
-  printf ("MRSA not compiled in\n");
-}
-
-void
-rsa_test (void)
-{
-  printf ("MRSA not compiled in\n");
-}
-#endif
-
-#ifdef BASE64
-void
-base64_test (void)
-{
-  unsigned char buf[2][100];
-  unsigned long x, y;
-
-  printf ("Base64 tests\n");
-  zeromem (buf, sizeof (buf));
-  for (x = 0; x < 16; x++)
-    buf[0][x] = (unsigned char) x;
-
-  x = 100;
-  if (base64_encode (buf[0], 16, buf[1], &x) != CRYPT_OK) {
-    printf ("  error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("  encoded 16 bytes to %ld bytes...[%s]\n", x, buf[1]);
-  memset (buf[0], 0, 100);
-  y = 100;
-  if (base64_decode (buf[1], x, buf[0], &y) != CRYPT_OK) {
-    printf ("  error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("  decoded %ld bytes to %ld bytes\n", x, y);
-  for (x = 0; x < 16; x++)
-    if (buf[0][x] != x) {
-      printf (" **failed**\n");
-      exit (-1);
-    }
-  printf ("  passed\n");
-}
-#else
-void
-base64_test (void)
-{
-  printf ("Base64 not compiled in\n");
-}
-#endif
-
-void
-time_hash (void)
-{
-  clock_t t1;
-  int     x, y;
-  unsigned long z;
-  unsigned char input[4096], out[MAXBLOCKSIZE];
-  printf ("Hash Time Trials (4KB blocks):\n");
-  for (x = 0; hash_descriptor[x].name != NULL; x++) {
-    t1 = XCLOCK ();
-    z = sizeof (out);
-    y = 0;
-    while (XCLOCK () - t1 < (5 * XCLOCKS_PER_SEC)) {
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      hash_memory (x, input, 4096, out, &z);
-      y += 32;
-    }
-    t1 = XCLOCK () - t1;
-    printf ("%-20s: Hash at %5.2f Mbit/sec\n", hash_descriptor[x].name,
-        ((8.0 * 4096.0) *
-         ((double) y / ((double) t1 / (double) XCLOCKS_PER_SEC))) /
-        1000000.0);
-  }
-}
-
-void
-time_ecb (void)
-{
-  clock_t t1, t2;
-  long    x, y1, y2;
-  unsigned char pt[32], key[32];
-  symmetric_key skey;
-  void    (*func) (const unsigned char *, unsigned char *, symmetric_key *);
-
-  printf ("ECB Time Trials for the Symmetric Ciphers:\n");
-  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
-    cipher_descriptor[x].setup (key, cipher_descriptor[x].min_key_length, 0,
-                &skey);
-
-#define DO1   func(pt,pt,&skey);
-#define DO2   DO1 DO1
-#define DO4   DO2 DO2
-#define DO8   DO4 DO4
-#define DO16  DO8 DO8
-#define DO32  DO16 DO16
-#define DO64  DO32 DO32
-#define DO128 DO64 DO64
-#define DO256 DO128 DO128
-
-    func = cipher_descriptor[x].ecb_encrypt;
-    y1 = 0;
-    t1 = XCLOCK ();
-    while (XCLOCK () - t1 < 3 * XCLOCKS_PER_SEC) {
-      DO256;
-      y1 += 256;
-    }
-    t1 = XCLOCK () - t1;
-
-    func = cipher_descriptor[x].ecb_decrypt;
-    y2 = 0;
-    t2 = XCLOCK ();
-    while (XCLOCK () - t2 < 3 * XCLOCKS_PER_SEC) {
-      DO256;
-      y2 += 256;
-    }
-    t2 = XCLOCK () - t2;
-    printf
-      ("%-20s: Encrypt at %5.2f Mbit/sec and Decrypt at %5.2f Mbit/sec\n",
-       cipher_descriptor[x].name,
-       ((8.0 * (double) cipher_descriptor[x].block_length) *
-    ((double) y1 / ((double) t1 / (double) XCLOCKS_PER_SEC))) / 1000000.0,
-       ((8.0 * (double) cipher_descriptor[x].block_length) *
-    ((double) y2 / ((double) t2 / (double) XCLOCKS_PER_SEC))) /
-       1000000.0);
-
-#undef DO256
-#undef DO128
-#undef DO64
-#undef DO32
-#undef DO16
-#undef DO8
-#undef DO4
-#undef DO2
-#undef DO1
-  }
-}
-
-#ifdef MDH
-void
-dh_tests (void)
-{
-  unsigned char buf[3][4096];
-  unsigned long x, y, z;
-  int     low, high, stat, stat2;
-  dh_key  usera, userb;
-  clock_t t1;
-
-  printf("Testing builting DH parameters...."); fflush(stdout);
-  if ((errnum = dh_test()) != CRYPT_OK) {
-     printf("DH Error: %s\n", error_to_string(errnum));
-     exit(-1);
-  }
-  printf("Passed.\n");
-
-  dh_sizes (&low, &high);
-  printf ("DH Keys from %d to %d supported.\n", low * 8, high * 8);
-
-  /* make up two keys */
-  if ((errnum =
-       dh_make_key (&prng, find_prng ("yarrow"), 96, &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  if ((errnum =
-       dh_make_key (&prng, find_prng ("yarrow"), 96, &userb)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* make the shared secret */
-  x = 4096;
-  if ((errnum = dh_shared_secret (&usera, &userb, buf[0], &x)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  y = 4096;
-  if ((errnum = dh_shared_secret (&userb, &usera, buf[1], &y)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  if (y != x) {
-    printf ("DH Shared keys are not same size.\n");
-    exit (-1);
-  }
-  if (memcmp (buf[0], buf[1], x)) {
-    printf ("DH Shared keys not same contents.\n");
-    exit (-1);
-  }
-
-  /* now export userb */
-  y = 4096;
-  if ((errnum = dh_export (buf[1], &y, PK_PUBLIC, &userb)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  dh_free (&userb);
-
-  /* import and make the shared secret again */
-  if ((errnum = dh_import (buf[1], y, &userb)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  z = 4096;
-  if ((errnum = dh_shared_secret (&usera, &userb, buf[2], &z)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  printf ("DH routines: ");
-  if (z != x) {
-    printf ("failed.  Size don't match?\n");
-    exit (-1);
-  }
-  if (memcmp (buf[0], buf[2], x)) {
-    printf ("Failed.  Content didn't match.\n");
-    exit (-1);
-  }
-  printf ("Passed\n");
-  dh_free (&usera);
-  dh_free (&userb);
-
-/* time stuff */
-  {
-    static int sizes[] = { 96, 128, 160, 192, 224, 256, 320, 384, 512 };
-    int     ii, tt;
-
-    for (ii = 0; ii < (int) (sizeof (sizes) / sizeof (sizes[0])); ii++) {
-      t1 = XCLOCK ();
-      for (tt = 0; tt < 25; tt++) {
-    dh_make_key (&prng, find_prng ("yarrow"), sizes[ii], &usera);
-    dh_free (&usera);
-      }
-      t1 = XCLOCK () - t1;
-      printf ("Make dh-%d key took %f msec\n", sizes[ii] * 8,
-          1000.0 * (((double) t1 / 25.0) / (double) XCLOCKS_PER_SEC));
-    }
-  }
-
-/* test encrypt_key */
-  dh_make_key (&prng, find_prng ("yarrow"), 128, &usera);
-  for (x = 0; x < 16; x++)
-    buf[0][x] = x;
-  y = sizeof (buf[1]);
-  if ((errnum =
-       dh_encrypt_key (buf[0], 16, buf[1], &y, &prng, find_prng ("yarrow"),
-               find_hash ("md5"), &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  zeromem (buf[0], sizeof (buf[0]));
-  x = sizeof (buf[0]);
-  if ((errnum = dh_decrypt_key (buf[1], y, buf[0], &x, &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("DH en/de crypt key routines: ");
-  if (x != 16) {
-    printf ("Failed (length)\n");
-    exit (-1);
-  }
-  for (x = 0; x < 16; x++)
-    if (buf[0][x] != x) {
-      printf ("Failed (contents)\n");
-      exit (-1);
-    }
-  printf ("Passed (size %lu)\n", y);
-
-/* test sign_hash */
-  for (x = 0; x < 16; x++)
-    buf[0][x] = x;
-  x = sizeof (buf[1]);
-  if ((errnum =
-       dh_sign_hash (buf[0], 16, buf[1], &x, &prng, find_prng ("yarrow"),
-             &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  if ((errnum = dh_verify_hash (buf[1], x, buf[0], 16, &stat, &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  buf[0][0] ^= 1;
-  if ((errnum = dh_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("dh_sign/verify_hash: %s (%d,%d), %lu\n",
-      ((stat == 1)
-       && (stat2 == 0)) ? "passed" : "failed", stat, stat2, x);
-  dh_free (&usera);
-}
-#else
-void
-dh_tests (void)
-{
-  printf ("MDH not compiled in\n");
-}
-#endif
-
-int     callback_x = 0;
-void
-callback (void)
-{
-  printf ("%c\x08", "-\\|/"[++callback_x & 3]);
-#ifndef SONY_PS2
-  fflush (stdout);
-#endif
-}
-
-void
-rng_tests (void)
-{
-  unsigned char buf[16];
-  clock_t t1;
-  int     x, y;
-
-  printf ("RNG tests\n");
-  t1 = XCLOCK ();
-  x = rng_get_bytes (buf, sizeof (buf), &callback);
-  t1 = XCLOCK () - t1;
-  printf ("  %f bytes per second...",
-      (double) x / ((double) t1 / (double) XCLOCKS_PER_SEC));
-  printf ("read %d bytes.\n  ", x);
-  for (y = 0; y < x; y++)
-    printf ("%02x ", buf[y]);
-  printf ("\n");
-
-#ifdef YARROW
-  if ((errnum =
-       rng_make_prng (128, find_prng ("yarrow"), &prng,
-              &callback)) != CRYPT_OK) {
-    printf (" starting yarrow error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-#endif
-}
-
-#ifdef MECC
-void
-ecc_tests (void)
-{
-  unsigned char buf[4][4096];
-  unsigned long x, y, z;
-  int     stat, stat2, low, high;
-  ecc_key usera, userb;
-  clock_t t1;
-
-  if ((errnum = ecc_test ()) != CRYPT_OK) {
-    printf ("ecc Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  ecc_sizes (&low, &high);
-  printf ("ecc Keys from %d to %d supported.\n", low * 8, high * 8);
-
-  /* make up two keys */
-  if ((errnum =
-       ecc_make_key (&prng, find_prng ("yarrow"), 24, &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  if ((errnum =
-       ecc_make_key (&prng, find_prng ("yarrow"), 24, &userb)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  /* make the shared secret */
-  x = 4096;
-  if ((errnum = ecc_shared_secret (&usera, &userb, buf[0], &x)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  y = 4096;
-  if ((errnum = ecc_shared_secret (&userb, &usera, buf[1], &y)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  if (y != x) {
-    printf ("ecc Shared keys are not same size.\n");
-    exit (-1);
-  }
-
-  if (memcmp (buf[0], buf[1], x)) {
-    printf ("ecc Shared keys not same contents.\n");
-    exit (-1);
-  }
-
-  /* now export userb */
-  y = 4096;
-  if ((errnum = ecc_export (buf[1], &y, PK_PUBLIC, &userb)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  ecc_free (&userb);
-  printf ("ECC-192 export took %ld bytes\n", y);
-
-  /* import and make the shared secret again */
-  if ((errnum = ecc_import (buf[1], y, &userb)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  z = 4096;
-  if ((errnum = ecc_shared_secret (&usera, &userb, buf[2], &z)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-
-  printf ("ecc routines: ");
-  if (z != x) {
-    printf ("failed.  Size don't match?\n");
-    exit (-1);
-  }
-  if (memcmp (buf[0], buf[2], x)) {
-    printf ("Failed.  Content didn't match.\n");
-    exit (-1);
-  }
-  printf ("Passed\n");
-  ecc_free (&usera);
-  ecc_free (&userb);
-
-/* time stuff */
-  {
-    static int sizes[] = { 20, 24, 28, 32, 48, 65 };
-    int     ii, tt;
-
-    for (ii = 0; ii < (int) (sizeof (sizes) / sizeof (sizes[0])); ii++) {
-      t1 = XCLOCK ();
-      for (tt = 0; tt < 10; tt++) {
-    if ((errnum =
-         ecc_make_key (&prng, find_prng ("yarrow"), sizes[ii],
-               &usera)) != CRYPT_OK) {
-      printf ("Error: %s\n", error_to_string (errnum));
-      exit (-1);
-    }
-    ecc_free (&usera);
-      }
-      t1 = XCLOCK () - t1;
-      printf ("Make ECC-%d key took %f msec\n", sizes[ii] * 8,
-          1000.0 * (((double) t1 / 10.0) / (double) XCLOCKS_PER_SEC));
-    }
-  }
-
-/* test encrypt_key */
-  ecc_make_key (&prng, find_prng ("yarrow"), 20, &usera);
-  for (x = 0; x < 32; x++)
-    buf[0][x] = x;
-  y = sizeof (buf[1]);
-  if ((errnum =
-       ecc_encrypt_key (buf[0], 32, buf[1], &y, &prng, find_prng ("yarrow"),
-            find_hash ("sha256"), &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  zeromem (buf[0], sizeof (buf[0]));
-  x = sizeof (buf[0]);
-  if ((errnum = ecc_decrypt_key (buf[1], y, buf[0], &x, &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("ECC en/de crypt key routines: ");
-  if (x != 32) {
-    printf ("Failed (length)\n");
-    exit (-1);
-  }
-  for (x = 0; x < 32; x++)
-    if (buf[0][x] != x) {
-      printf ("Failed (contents)\n");
-      exit (-1);
-    }
-  printf ("Passed (size: %lu)\n", y);
-/* test sign_hash */
-  for (x = 0; x < 16; x++)
-    buf[0][x] = x;
-  x = sizeof (buf[1]);
-  if ((errnum =
-       ecc_sign_hash (buf[0], 16, buf[1], &x, &prng, find_prng ("yarrow"),
-              &usera)) != CRYPT_OK) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf("Signature size: %lu\n", x);
-  if (ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &usera)) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  buf[0][0] ^= 1;
-  if (ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera)) {
-    printf ("Error: %s\n", error_to_string (errnum));
-    exit (-1);
-  }
-  printf ("ecc_sign/verify_hash: %s (%d,%d)\n",
-      ((stat == 1) && (stat2 == 0)) ? "passed" : "failed", stat, stat2);
-  ecc_free (&usera);
-}
-#else
-void
-ecc_tests (void)
-{
-  printf ("MECC not compiled in\n");
-}
-#endif
-
-#ifdef MPI
-void
-test_prime (void)
-{
-  char buf[1024];
-  mp_int  a;
-  int     x;
-
-  /* make a 1024 bit prime */
-  mp_init (&a);
-  rand_prime (&a, 128*8, &prng, find_prng ("yarrow"));
-
-  /* dump it */
-  mp_todecimal (&a, buf);
-  printf ("1024-bit prime:\n");
-  for (x = 0; x < (int) strlen (buf);) {
-    printf ("%c", buf[x]);
-    if (!(++x % 60))
-      printf ("\\ \n");
-  }
-  printf ("\n\n");
-
-  mp_clear (&a);
-}
-#else
-void
-test_prime (void)
-{
-  printf ("MPI not compiled in\n");
-}
-#endif
-
-void
-register_all_algs (void)
-{
-#ifdef RIJNDAEL
-  register_cipher (&aes_desc);
-#endif
-#ifdef BLOWFISH
-  register_cipher (&blowfish_desc);
-#endif
-#ifdef XTEA
-  register_cipher (&xtea_desc);
-#endif
-#ifdef RC5
-  register_cipher (&rc5_desc);
-#endif
-#ifdef RC6
-  register_cipher (&rc6_desc);
-#endif
-#ifdef SAFERP
-  register_cipher (&saferp_desc);
-#endif
-#ifdef TWOFISH
-  register_cipher (&twofish_desc);
-#endif
-#ifdef SAFER
-  register_cipher (&safer_k64_desc);
-  register_cipher (&safer_sk64_desc);
-  register_cipher (&safer_k128_desc);
-  register_cipher (&safer_sk128_desc);
-#endif
-#ifdef RC2
-  register_cipher (&rc2_desc);
-#endif
-#ifdef DES
-  register_cipher (&des_desc);
-  register_cipher (&des3_desc);
-#endif
-#ifdef CAST5
-  register_cipher (&cast5_desc);
-#endif
-#ifdef NOEKEON
-  register_cipher (&noekeon_desc);
-#endif
-#ifdef SKIPJACK
-  register_cipher (&skipjack_desc);
-#endif
-  register_cipher (&null_desc);
-
-#ifdef TIGER
-  register_hash (&tiger_desc);
-#endif
-#ifdef MD2
-  register_hash (&md2_desc);
-#endif
-#ifdef MD4
-  register_hash (&md4_desc);
-#endif
-#ifdef MD5
-  register_hash (&md5_desc);
-#endif
-#ifdef SHA1
-  register_hash (&sha1_desc);
-#endif
-#ifdef SHA256
-  register_hash (&sha256_desc);
-#endif
-#ifdef SHA224
-  register_hash (&sha224_desc);
-#endif
-#ifdef SHA384
-  register_hash (&sha384_desc);
-#endif
-#ifdef SHA512
-  register_hash (&sha512_desc);
-#endif
-#ifdef RIPEMD128
-  register_hash (&rmd128_desc);
-#endif
-#ifdef RIPEMD160
-  register_hash (&rmd160_desc);
-#endif
-#ifdef WHIRLPOOL
-  register_hash (&whirlpool_desc);
-#endif
-
-#ifdef YARROW
-  register_prng (&yarrow_desc);
-#endif
-#ifdef SPRNG
-  register_prng (&sprng_desc);
-#endif
-}
-
-void
-test_errs (void)
-{
-#define ERR(x)  printf("%25s => %s\n", #x, error_to_string(x));
-
-  ERR (CRYPT_OK);
-  ERR (CRYPT_ERROR);
-
-  ERR (CRYPT_INVALID_KEYSIZE);
-  ERR (CRYPT_INVALID_ROUNDS);
-  ERR (CRYPT_FAIL_TESTVECTOR);
-
-  ERR (CRYPT_BUFFER_OVERFLOW);
-  ERR (CRYPT_INVALID_PACKET);
-
-  ERR (CRYPT_INVALID_PRNGSIZE);
-  ERR (CRYPT_ERROR_READPRNG);
-
-  ERR (CRYPT_INVALID_CIPHER);
-  ERR (CRYPT_INVALID_HASH);
-  ERR (CRYPT_INVALID_PRNG);
-
-  ERR (CRYPT_MEM);
-
-  ERR (CRYPT_PK_TYPE_MISMATCH);
-  ERR (CRYPT_PK_NOT_PRIVATE);
-
-  ERR (CRYPT_INVALID_ARG);
-  ERR (CRYPT_FILE_NOTFOUND);
-
-  ERR (CRYPT_PK_INVALID_TYPE);
-  ERR (CRYPT_PK_INVALID_SYSTEM);
-  ERR (CRYPT_PK_DUP);
-  ERR (CRYPT_PK_NOT_FOUND);
-  ERR (CRYPT_PK_INVALID_SIZE);
-
-  ERR (CRYPT_INVALID_PRIME_SIZE);
-}
-
-
-void dsa_tests(void)
-{
-   unsigned char msg[16], out[1024], out2[1024];
-   unsigned long x, y;
-   int err, stat1, stat2;
-   dsa_key key, key2;
-
-   /* make a random key */
-   if ((err = dsa_make_key(&prng, find_prng("yarrow"), 20, 128, &key)) != CRYPT_OK) {
-      printf("Error making DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("DSA Key Made\n");
-
-   /* verify it */
-   if ((err = dsa_verify_key(&key, &stat1)) != CRYPT_OK) {
-      printf("Error verifying DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("DSA key verification: %s\n", stat1 == 1 ? "passed" : "failed");
-   if (stat1 == 0) exit(-1);     
-
-   /* sign the message */
-   x = sizeof(out);
-   if ((err = dsa_sign_hash(msg, sizeof(msg), out, &x, &prng, find_prng("yarrow"), &key)) != CRYPT_OK) {
-      printf("Error signing with DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("DSA 160/1024 signature is %lu bytes long\n", x);
-
-   /* verify it once */
-   if ((err = dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key)) != CRYPT_OK) {
-      printf("Error verifying with DSA key 1: %s\n", error_to_string(err));
-      exit(-1);
-   }
-
-   /* Modify and verify again */
-   msg[0] ^= 1;
-   if ((err = dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key)) != CRYPT_OK) {
-      printf("Error verifying with DSA key 2: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   msg[0] ^= 1;
-   printf("DSA Verification: %d, %d, %s\n", stat1, stat2, (stat1 == 1 && stat2 == 0) ? "passed" : "failed");
-   if (!(stat1 == 1 && stat2 == 0)) exit(-1);
-
-   /* test exporting it */
-   x = sizeof(out2);
-   if ((err = dsa_export(out2, &x, PK_PRIVATE, &key)) != CRYPT_OK) {
-      printf("Error export PK_PRIVATE DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("Exported PK_PRIVATE DSA key in %lu bytes\n", x);
-   if ((err = dsa_import(out2, x, &key2)) != CRYPT_OK) {
-      printf("Error importing PK_PRIVATE DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   /* verify a signature with it */
-   if ((err = dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)) != CRYPT_OK) {
-      printf("Error verifying with DSA key 3: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("PRIVATE Import Test: %s\n", stat1 == 1 ? "passed" : "failed");
-   if (stat1 == 0) exit(-1);
-   dsa_free(&key2);
-
-   /* export as public now */
-   x = sizeof(out2);
-   if ((err = dsa_export(out2, &x, PK_PUBLIC, &key)) != CRYPT_OK) {
-      printf("Error export PK_PUBLIC DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("Exported PK_PUBLIC DSA key in %lu bytes\n", x);
-   if ((err = dsa_import(out2, x, &key2)) != CRYPT_OK) {
-      printf("Error importing PK_PUBLIC DSA key: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   /* verify a signature with it */
-   if ((err = dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)) != CRYPT_OK) {
-      printf("Error verifying with DSA key 4: %s\n", error_to_string(err));
-      exit(-1);
-   }
-   printf("PUBLIC Import Test: %s\n", stat1 == 1 ? "passed" : "failed");
-   if (stat1 == 0) exit(-1);
-
-   dsa_free(&key2);
-   dsa_free(&key);
-}
-
-#ifdef PKCS_1
-void pkcs1_test(void)
-{
-   unsigned char buf[3][128];
-   int err, res1, res2, res3, prng_idx, hash_idx;
-   unsigned long x, y, l1, l2, l3, i1, i2;
-
-   /* get hash/prng  */
-   hash_idx = find_hash("sha1");
-   prng_idx = find_prng("yarrow");
-
-   /* do many tests */
-   for (x = 0; x < 10000; x++) {
-      zeromem(buf, sizeof(buf));
-
-      /* make a dummy message (of random length) */
-      l3 = (rand() & 31) + 8;
-      for (y = 0; y < l3; y++) buf[0][y] = rand() & 255;
-
-      /* encode it */
-      l1 = sizeof(buf[1]);
-      if ((err = pkcs_1_oaep_encode(buf[0], l3, NULL, 0, 1024, hash_idx, prng_idx, &prng, buf[1], &l1)) != CRYPT_OK) {
-         printf("OAEP encode: %s\n", error_to_string(err));
-         exit(-1);
-      }
-
-      /* decode it */
-      l2 = sizeof(buf[2]);
-      if ((err = pkcs_1_oaep_decode(buf[1], l1, NULL, 0, 1024, hash_idx, buf[2], &l2, &res1)) != CRYPT_OK) {
-         printf("OAEP decode: %s\n", error_to_string(err));
-         exit(-1);
-      }
-
-      if (res1 != 1 || l2 != l3 || memcmp(buf[2], buf[0], l3) != 0) {
-         printf("res == %d, Outsize == %lu, should have been %lu, msg contents follow.\n", res1, l2, l3);
-         printf("ORIGINAL:\n");
-         for (x = 0; x < l3; x++) {
-             printf("%02x ", buf[0][x]);
-         }
-         printf("\nRESULT:\n");
-         for (x = 0; x < l2; x++) {
-             printf("%02x ", buf[2][x]);
-         }
-         printf("\n\n");
-         exit(-1);
-      }
-
-      /* test PSS */
-      l1 = sizeof(buf[1]);
-      if ((err = pkcs_1_pss_encode(buf[0], l3, l3>>2, hash_idx, prng_idx, &prng, 1024, buf[1], &l1)) != CRYPT_OK) {
-         printf("PSS encode: %s\n", error_to_string(err));
-         exit(-1); 
-      }
-      
-      if ((err = pkcs_1_pss_decode(buf[0], l3, buf[1], l1, l3>>2, hash_idx, 1024, &res1)) != CRYPT_OK) {
-         printf("PSS decode1: %s\n", error_to_string(err));
-         exit(-1); 
-      }
-      
-      buf[0][i1 = abs(rand()) % l3] ^= 1;
-      if ((err = pkcs_1_pss_decode(buf[0], l3, buf[1], l1, l3>>2, hash_idx, 1024, &res2)) != CRYPT_OK) {
-         printf("PSS decode2: %s\n", error_to_string(err));
-         exit(-1); 
-      }
-
-      buf[0][i1] ^= 1;
-      buf[1][i2 = abs(rand()) % l1] ^= 1;
-      if ((err = pkcs_1_pss_decode(buf[0], l3, buf[1], l1, l3>>2, hash_idx, 1024, &res3)) != CRYPT_OK) {
-         printf("PSS decode3: %s\n", error_to_string(err));
-         exit(-1); 
-      }
-
-      if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
-         printf("PSS failed: %d, %d, %d, %lu\n", res1, res2, res3, l3);
-         exit(-1);
-      }
-   }
-   printf("PKCS #1: Passed\n");
-}
-
-#endif /* PKCS_1 */
-
-int
-main (void)
-{
-#ifdef SONY_PS2
-  TIMER_Init ();
-#endif
-  srand(time(NULL));
-
-  register_all_algs ();
-   
-  if ((errnum = yarrow_start (&prng)) != CRYPT_OK) {
-    printf ("yarrow_start: %s\n", error_to_string (errnum));
-  }
-  if ((errnum = yarrow_add_entropy ((unsigned char *)"hello", 5, &prng)) != CRYPT_OK) {
-    printf ("yarrow_add_entropy: %s\n", error_to_string (errnum));
-  }
-  if ((errnum = yarrow_ready (&prng)) != CRYPT_OK) {
-    printf ("yarrow_ready: %s\n", error_to_string (errnum));
-  }
-
-  printf (crypt_build_settings);
-  test_errs ();
-
-#ifdef HMAC
-  printf ("HMAC: %s\n", hmac_test () == CRYPT_OK ? "passed" : "failed");
-  if (hmac_test() != CRYPT_OK) exit(EXIT_FAILURE);
-#endif
-
-#ifdef OMAC
-  printf ("OMAC: %s\n", omac_test () == CRYPT_OK ? "passed" : "failed");
-  if (omac_test() != CRYPT_OK) exit(EXIT_FAILURE);
-#endif
-
-#ifdef PMAC
-  printf ("PMAC: %s\n", pmac_test () == CRYPT_OK ? "passed" : "failed");
-  if (pmac_test() != CRYPT_OK) exit(EXIT_FAILURE);
-#endif
-
-#ifdef EAX_MODE
-  printf ("EAX : %s\n", eax_test () == CRYPT_OK ? "passed" : "failed");
-  if (eax_test() != CRYPT_OK) exit(EXIT_FAILURE);
-#endif
-
-#ifdef OCB_MODE
-  printf ("OCB : %s\n", ocb_test () == CRYPT_OK ? "passed" : "failed");
-  if (ocb_test() != CRYPT_OK) exit(EXIT_FAILURE);
-#endif
-
-  store_tests ();
-  cipher_tests ();
-  hash_tests ();
-
-#ifdef PKCS_1
-  pkcs1_test();
-#endif
-
-  ecb_tests ();
-  cbc_tests ();
-  ctr_tests ();
-  ofb_tests ();
-  cfb_tests ();
-
-  rng_tests ();
-  test_prime();
-
-  dsa_tests();
-  rsa_test ();
-  pad_test ();
-  ecc_tests ();
-  dh_tests ();
-
-  base64_test ();
-
-  time_ecb ();
-  time_hash ();
-
-#ifdef SONY_PS2
-  TIMER_Shutdown ();
-#endif
-
-  return 0;
-}
+/* $Source: /cvs/libtom/libtomcrypt/demos/test.c,v $ */
+/* $Revision: 1.12 $ */
+/* $Date: 2005/06/19 12:06:58 $ */
diff --git a/demos/test/base64_test.c b/demos/test/base64_test.c
deleted file mode 100644
index b02c1a2..0000000
--- a/demos/test/base64_test.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include  "test.h"
-
-int base64_test(void)
-{
-   unsigned char in[64], out[256], tmp[64];
-   unsigned long x, l1, l2;
-   
-   for  (x = 0; x < 64; x++) {
-       yarrow_read(in, x, &test_yarrow);
-       l1 = sizeof(out);
-       DO(base64_encode(in, x, out, &l1));
-       l2 = sizeof(tmp);
-       DO(base64_decode(out, l1, tmp, &l2));
-       if (l2 != x || memcmp(tmp, in, x)) {
-           printf("base64  failed %lu %lu %lu", x, l1, l2);
-           return 1;
-       }
-   }
-   return 0;
-}
diff --git a/demos/test/cipher_hash_test.c b/demos/test/cipher_hash_test.c
deleted file mode 100644
index 52e9e65..0000000
--- a/demos/test/cipher_hash_test.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/* test the ciphers and hashes using their built-in self-tests */
-
-#include "test.h"
-
-int cipher_hash_test(void)
-{
-   int x;
-   
-   /* test ciphers */
-   for (x = 0; cipher_descriptor[x].name != NULL; x++) {
-      DO(cipher_descriptor[x].test());
-   }
-   
-   /* test hashes */
-   for (x = 0; hash_descriptor[x].name != NULL; x++) {
-      DO(hash_descriptor[x].test());
-   }
-   
-   return 0;
-}
diff --git a/demos/test/dsa_test.c b/demos/test/dsa_test.c
deleted file mode 100644
index 2076089..0000000
--- a/demos/test/dsa_test.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "test.h"
-
-int dsa_test(void)
-{
-   unsigned char msg[16], out[1024], out2[1024];
-   unsigned long x, y;
-   int err, stat1, stat2;
-   dsa_key key, key2;
-
-   /* make a random key */
-   DO(dsa_make_key(&test_yarrow, find_prng("yarrow"), 20, 128, &key));
-
-   /* verify it */
-   DO(dsa_verify_key(&key, &stat1));
-   if (stat1 == 0) { printf("dsa_verify_key "); return 1; }
-
-   /* sign the message */
-   x = sizeof(out);
-   DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &test_yarrow, find_prng("yarrow"), &key));
-
-   /* verify it once */
-   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key));
-
-   /* Modify and verify again */
-   msg[0] ^= 1;
-   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key));
-   msg[0] ^= 1;
-   if (!(stat1 == 1 && stat2 == 0)) { printf("dsa_verify %d %d", stat1, stat2); return 1; }
-
-   /* test exporting it */
-   x = sizeof(out2);
-   DO(dsa_export(out2, &x, PK_PRIVATE, &key));
-   DO(dsa_import(out2, x, &key2));
-
-   /* verify a signature with it */
-   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
-   if (stat1 == 0) { printf("dsa_verify (import private) %d ", stat1); return 1; }
-   dsa_free(&key2);
-
-   /* export as public now */
-   x = sizeof(out2);
-   DO(dsa_export(out2, &x, PK_PUBLIC, &key));
-   DO(dsa_import(out2, x, &key2));
-   /* verify a signature with it */
-   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
-   if (stat1 == 0) { printf("dsa_verify (import public) %d ", stat1); return 1; }
-   dsa_free(&key2);
-   dsa_free(&key);
-
-   return 0;
-}
diff --git a/demos/test/ecc_test.c b/demos/test/ecc_test.c
deleted file mode 100644
index 02f1f91..0000000
--- a/demos/test/ecc_test.c
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "test.h"
-
-int ecc_tests (void)
-{
-  unsigned char buf[4][4096];
-  unsigned long x, y, z;
-  int           stat, stat2;
-  ecc_key usera, userb;
-	
-  DO(ecc_test ());
-
-  /* make up two keys */
-  DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 24, &usera));
-  DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 24, &userb));
-
-  /* make the shared secret */
-  x = 4096;
-  DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
-
-  y = 4096;
-  DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
-
-  if (y != x) {
-    printf ("ecc Shared keys are not same size.");
-    return 1;
-  }
-
-  if (memcmp (buf[0], buf[1], x)) {
-    printf ("ecc Shared keys not same contents.");
-    return 1;
-  }
-
-  /* now export userb */
-  y = 4096;
-  DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb));
-  ecc_free (&userb);
-
-  /* import and make the shared secret again */
-  DO(ecc_import (buf[1], y, &userb));
-
-  z = 4096;
-  DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
-
-  if (z != x) {
-    printf ("failed.  Size don't match?");
-    return 1;
-  }
-  if (memcmp (buf[0], buf[2], x)) {
-    printf ("Failed.  Content didn't match.");
-    return 1;
-  }
-  ecc_free (&usera);
-  ecc_free (&userb);
-
-/* test encrypt_key */
-  ecc_make_key (&test_yarrow, find_prng ("yarrow"), 20, &usera);
-  for (x = 0; x < 32; x++) {
-    buf[0][x] = x;
-  }
-  y = sizeof (buf[1]);
-  DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &test_yarrow, find_prng ("yarrow"), find_hash ("sha256"), &usera));
-  zeromem (buf[0], sizeof (buf[0]));
-  x = sizeof (buf[0]);
-  DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &usera));
-  if (x != 32) {
-    printf ("Failed (length)");
-    return 1;
-  }
-  for (x = 0; x < 32; x++)
-    if (buf[0][x] != x) {
-      printf ("Failed (contents)");
-      return 1;
-    }
-/* test sign_hash */
-  for (x = 0; x < 16; x++) {
-    buf[0][x] = x;
-  }
-  x = sizeof (buf[1]);
-  DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &test_yarrow, find_prng ("yarrow"), &usera));
-  DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &usera));
-  buf[0][0] ^= 1;
-  DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera));
-  if (!(stat == 1 && stat2 == 0)) { 
-    printf("ecc_verify_hash failed");
-    return 1;
-  }
-  ecc_free (&usera);
-  return 0;
-}
diff --git a/demos/test/mac_test.c b/demos/test/mac_test.c
deleted file mode 100644
index 91c8d34..0000000
--- a/demos/test/mac_test.c
+++ /dev/null
@@ -1,12 +0,0 @@
-/* test pmac/omac/hmac */
-#include "test.h"
-
-int mac_test(void)
-{
-   DO(hmac_test());
-   DO(pmac_test());
-   DO(omac_test());
-   DO(eax_test());
-   DO(ocb_test());
-   return 0;
-}
diff --git a/demos/test/makefile b/demos/test/makefile
deleted file mode 100644
index e996767..0000000
--- a/demos/test/makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-# make test harness, it is good.
-CFLAGS += -Wall -W -Os -I../../ -I./
-
-default: test
-
-OBJECTS=test.o cipher_hash_test.o mac_test.o modes_test.o \
-pkcs_1_test.o store_test.o rsa_test.o ecc_test.o dsa_test.c dh_tests.o 
-
-test: $(OBJECTS)
-	$(CC) $(OBJECTS) -ltomcrypt -o test
-	
-clean:
-	rm -f test *.o *.obj *.exe *~	
diff --git a/demos/test/makefile.icc b/demos/test/makefile.icc
deleted file mode 100644
index 22c7154..0000000
--- a/demos/test/makefile.icc
+++ /dev/null
@@ -1,14 +0,0 @@
-# make test harness, it is good.
-CFLAGS += -O3 -xN -ip -I../../ -I./
-CC=icc
-
-default: test
-
-OBJECTS=test.o cipher_hash_test.o mac_test.o modes_test.o \
-pkcs_1_test.o store_test.o rsa_test.o ecc_test.o dsa_test.c dh_tests.o 
-
-test: $(OBJECTS)
-	$(CC) $(OBJECTS) -ltomcrypt -o test
-	
-clean:
-	rm -f test *.o *~	
diff --git a/demos/test/makefile.msvc b/demos/test/makefile.msvc
deleted file mode 100644
index c1ca8e0..0000000
--- a/demos/test/makefile.msvc
+++ /dev/null
@@ -1,14 +0,0 @@
-# make test harness, it is good.
-CFLAGS = $(CFLAGS) /W3 /Ox -I../../ -I./
-
-default: test.exe
-
-OBJECTS = test.obj cipher_hash_test.obj mac_test.obj modes_test.obj \
-pkcs_1_test.obj store_test.obj rsa_test.obj ecc_test.obj dsa_test.c dh_tests.obj 
-
-
-test.exe: $(OBJECTS)
-	cl $(OBJECTS) tomcrypt.lib advapi32.lib 
-	
-clean:
-	rm -f test.exe *.obj *~	
diff --git a/demos/test/pkcs_1_test.c b/demos/test/pkcs_1_test.c
deleted file mode 100644
index 3f1297a..0000000
--- a/demos/test/pkcs_1_test.c
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "test.h"
-
-int pkcs_1_test(void)
-{
-   unsigned char buf[3][128];
-   int res1, res2, res3, prng_idx, hash_idx;
-   unsigned long x, y, l1, l2, l3, i1, i2, lparamlen, saltlen, modlen;
-   static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
-
-   /* get hash/prng  */
-   hash_idx = find_hash("sha1");
-   prng_idx = find_prng("yarrow");
-   
-   if (hash_idx == -1 || prng_idx == -1) {
-      printf("pkcs_1 tests require sha1/yarrow");
-      return 1;
-   }   
-
-   /* do many tests */
-   for (x = 0; x < 10000; x++) {
-      zeromem(buf, sizeof(buf));
-
-      /* make a dummy message (of random length) */
-      l3 = (rand() & 31) + 8;
-      for (y = 0; y < l3; y++) buf[0][y] = rand() & 255;
-
-      /* random modulus len (v1.5 must be multiple of 8 though arbitrary sizes seem to work) */
-      modlen = 800 + 8 * (abs(rand()) % 28);
-
-      /* PKCS v1.5 testing (encryption) */
-      l1 = sizeof(buf[1]);
-      DO(pkcs_1_v15_es_encode(buf[0], l3, modlen, &test_yarrow, prng_idx, buf[1], &l1));
-      DO(pkcs_1_v15_es_decode(buf[1], l1, modlen, buf[2], l3, &res1));
-      if (res1 != 1 || memcmp(buf[0], buf[2], l3)) {
-         printf("pkcs v1.5 encrypt failed %d, %lu, %lu ", res1, l1, l3);
-         return 1;
-      }
-
-      /* PKCS v1.5 testing (signatures) */
-      l1 = sizeof(buf[1]);
-      DO(pkcs_1_v15_sa_encode(buf[0], l3, hash_idx, modlen, buf[1], &l1));
-      DO(pkcs_1_v15_sa_decode(buf[0], l3, buf[1], l1, hash_idx, modlen, &res1));
-      buf[0][i1 = abs(rand()) % l3] ^= 1;
-      DO(pkcs_1_v15_sa_decode(buf[0], l3, buf[1], l1, hash_idx, modlen, &res2));
-      buf[0][i1] ^= 1;
-      buf[1][i2 = abs(rand()) % l1] ^= 1;
-      DO(pkcs_1_v15_sa_decode(buf[0], l3, buf[1], l1, hash_idx, modlen, &res3));
-
-      if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
-         printf("pkcs v1.5 sign failed %d %d %d ", res1, res2, res3);
-         return 1;
-      }
-
-      /* pick a random lparam len [0..16] */
-      lparamlen = abs(rand()) % 17;
-
-      /* pick a random saltlen 0..16 */
-      saltlen   = abs(rand()) % 17;
-
-      /* PKCS #1 v2.0 supports modlens not multiple of 8 */
-      modlen = 800 + (abs(rand()) % 224);
-
-      /* encode it */
-      l1 = sizeof(buf[1]);
-      DO(pkcs_1_oaep_encode(buf[0], l3, lparam, lparamlen, modlen, &test_yarrow, prng_idx, hash_idx, buf[1], &l1));
-
-      /* decode it */
-      l2 = sizeof(buf[2]);
-      DO(pkcs_1_oaep_decode(buf[1], l1, lparam, lparamlen, modlen, hash_idx, buf[2], &l2, &res1));
-
-      if (res1 != 1 || l2 != l3 || memcmp(buf[2], buf[0], l3) != 0) {
-         printf("Outsize == %lu, should have been %lu, res1 = %d, lparamlen = %lu, msg contents follow.\n", l2, l3, res1, lparamlen);
-         printf("ORIGINAL:\n");
-         for (x = 0; x < l3; x++) {
-             printf("%02x ", buf[0][x]);
-         }
-         printf("\nRESULT:\n");
-         for (x = 0; x < l2; x++) {
-             printf("%02x ", buf[2][x]);
-         }
-         printf("\n\n");
-         return 1;
-      }
-
-      /* test PSS */
-      l1 = sizeof(buf[1]);
-      DO(pkcs_1_pss_encode(buf[0], l3, saltlen, &test_yarrow, prng_idx, hash_idx, modlen, buf[1], &l1));
-      DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res1));
-      
-      buf[0][i1 = abs(rand()) % l3] ^= 1;
-      DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2));
-
-      buf[0][i1] ^= 1;
-      buf[1][i2 = abs(rand()) % l1] ^= 1;
-      DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3));
-
-      if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
-         printf("PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
-         return 1;
-      }
-   }
-   return 0;
-}
diff --git a/demos/test/rsa_test.c b/demos/test/rsa_test.c
deleted file mode 100644
index 772550a..0000000
--- a/demos/test/rsa_test.c
+++ /dev/null
@@ -1,91 +0,0 @@
-#include "test.h"
-
-int rsa_test(void)
-{
-   unsigned char in[1024], out[1024], tmp[1024];
-   rsa_key       key;
-   int           hash_idx, prng_idx, stat, stat2;
-   unsigned long len, len2;
-   static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
-      
-   hash_idx = find_hash("sha1");
-   prng_idx = find_prng("yarrow");
-   if (hash_idx == -1 || prng_idx == -1) {
-      printf("rsa_test requires SHA1 and yarrow");
-      return 1;
-   }
-   
-   /* make a random key/msg */
-   yarrow_read(in, 20, &test_yarrow);
-   
-   /* make a random key */
-   DO(rsa_make_key(&test_yarrow, prng_idx, 1024/8, 65537, &key));
-   
-   /* encrypt the key (without lparam) */
-   len  = sizeof(out);
-   len2 = sizeof(tmp);
-   DO(rsa_encrypt_key(in, 20, out, &len, NULL, 0, &test_yarrow, prng_idx, hash_idx, &key));
-   /* change a byte */
-   out[0] ^= 1;
-   DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat2, &key));
-   /* change a byte back */
-   out[0] ^= 1;
-   DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat, &key));
-   if (!(stat == 1 && stat2 == 0)) {
-      printf("rsa_decrypt_key failed");
-      return 1;
-   }
-   if (len2 != 20 || memcmp(tmp, in, 20)) {
-      printf("rsa_decrypt_key mismatch len %lu", len2);
-      return 1;
-   }
-
-   /* encrypt the key (with lparam) */
-   len  = sizeof(out);
-   len2 = sizeof(tmp);
-   DO(rsa_encrypt_key(in, 20, out, &len, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &key));
-   /* change a byte */
-   out[0] ^= 1;
-   DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat2, &key));
-   /* change a byte back */
-   out[0] ^= 1;
-   DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat, &key));
-   if (!(stat == 1 && stat2 == 0)) {
-      printf("rsa_decrypt_key failed");
-      return 1;
-   }
-   if (len2 != 20 || memcmp(tmp, in, 20)) {
-      printf("rsa_decrypt_key mismatch len %lu", len2);
-      return 1;
-   }
-
-   /* sign a message (unsalted, lower cholestorol and Atkins approved) now */
-   len = sizeof(out);
-   DO(rsa_sign_hash(in, 20, out, &len, &test_yarrow, prng_idx, hash_idx, 0, &key));
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 0, &stat, &key));
-   /* change a byte */
-   in[0] ^= 1;
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 0, &stat2, &key));
-   
-   if (!(stat == 1 && stat2 == 0)) {
-      printf("rsa_verify_hash (unsalted) failed, %d, %d", stat, stat2);
-      return 1;
-   }
-
-   /* sign a message (salted) now */
-   len = sizeof(out);
-   DO(rsa_sign_hash(in, 20, out, &len, &test_yarrow, prng_idx, hash_idx, 8, &key));
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 8, &stat, &key));
-   /* change a byte */
-   in[0] ^= 1;
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 8, &stat2, &key));
-   
-   if (!(stat == 1 && stat2 == 0)) {
-      printf("rsa_verify_hash (salted) failed, %d, %d", stat, stat2);
-      return 1;
-   }
-   
-   /* free the key and return */
-   rsa_free(&key);
-   return 0;
-}
diff --git a/demos/test/store_test.c b/demos/test/store_test.c
deleted file mode 100644
index 278d52f..0000000
--- a/demos/test/store_test.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include "test.h"
-
-int store_test(void)
-{
-  unsigned char buf[8];
-  unsigned long L;
-  ulong64 LL;
-
-  L = 0x12345678UL;
-  STORE32L (L, &buf[0]);
-  L = 0;
-  LOAD32L (L, &buf[0]);
-  if (L != 0x12345678UL) {
-    printf ("LOAD/STORE32 Little don't work");
-    return 1;
-  }
-  LL = CONST64 (0x01020304050607);
-  STORE64L (LL, &buf[0]);
-  LL = 0;
-  LOAD64L (LL, &buf[0])
-    if (LL != CONST64 (0x01020304050607)) {
-    printf ("LOAD/STORE64 Little don't work");
-    return 1;
-  }
-
-  L = 0x12345678UL;
-  STORE32H (L, &buf[0]);
-  L = 0;
-  LOAD32H (L, &buf[0]);
-  if (L != 0x12345678UL) {
-    printf ("LOAD/STORE32 High don't work, %08lx", L);
-    return 1;
-  }
-  LL = CONST64 (0x01020304050607);
-  STORE64H (LL, &buf[0]);
-  LL = 0;
-  LOAD64H (LL, &buf[0])
-    if (LL != CONST64 (0x01020304050607)) {
-    printf ("LOAD/STORE64 High don't work");
-    return 1;
-  }
-  return 0;
-}
diff --git a/demos/test/test.c b/demos/test/test.c
deleted file mode 100644
index fef5900..0000000
--- a/demos/test/test.c
+++ /dev/null
@@ -1,177 +0,0 @@
-#include "test.h"
-
-test_entry tests[26];
-
-test_entry test_list[26] = { 
-
-/* test name          provides    requires             entry */
-{"store_test",             "a",         "",          store_test           },
-{"cipher_hash_test",       "b",        "a",          cipher_hash_test     },
-{"modes_test",             "c",        "b",          modes_test           },
-{"mac_test",               "d",        "c",          mac_test             },
-{"pkcs_1_test",            "e",        "b",          pkcs_1_test          },
-{"rsa_test",               "f",        "e",          rsa_test             },
-{"ecc_test",               "g",        "a",          ecc_tests            },
-{"dsa_test",               "h",        "a",          dsa_test             },
-{"dh_test",                "i",        "a",          dh_tests             },
-
-{NULL, NULL, NULL, NULL} 
-};
-
-prng_state test_yarrow;
-static int current_test;
-
-void run_cmd(int res, int line, char *file, char *cmd)
-{
-   if (res != CRYPT_OK) {
-      fprintf(stderr, "[%s]: %s (%d)\n%s:%d:%s\n", tests[current_test].name, error_to_string(res), res, file, line, cmd);
-      exit(EXIT_FAILURE);
-   }
-}
-
-void register_algs(void)
-{
-#ifdef RIJNDAEL
-  register_cipher (&aes_desc);
-#endif
-#ifdef BLOWFISH
-  register_cipher (&blowfish_desc);
-#endif
-#ifdef XTEA
-  register_cipher (&xtea_desc);
-#endif
-#ifdef RC5
-  register_cipher (&rc5_desc);
-#endif
-#ifdef RC6
-  register_cipher (&rc6_desc);
-#endif
-#ifdef SAFERP
-  register_cipher (&saferp_desc);
-#endif
-#ifdef TWOFISH
-  register_cipher (&twofish_desc);
-#endif
-#ifdef SAFER
-  register_cipher (&safer_k64_desc);
-  register_cipher (&safer_sk64_desc);
-  register_cipher (&safer_k128_desc);
-  register_cipher (&safer_sk128_desc);
-#endif
-#ifdef RC2
-  register_cipher (&rc2_desc);
-#endif
-#ifdef DES
-  register_cipher (&des_desc);
-  register_cipher (&des3_desc);
-#endif
-#ifdef CAST5
-  register_cipher (&cast5_desc);
-#endif
-#ifdef NOEKEON
-  register_cipher (&noekeon_desc);
-#endif
-#ifdef SKIPJACK
-  register_cipher (&skipjack_desc);
-#endif
-#ifdef TIGER
-  register_hash (&tiger_desc);
-#endif
-#ifdef MD2
-  register_hash (&md2_desc);
-#endif
-#ifdef MD4
-  register_hash (&md4_desc);
-#endif
-#ifdef MD5
-  register_hash (&md5_desc);
-#endif
-#ifdef SHA1
-  register_hash (&sha1_desc);
-#endif
-#ifdef SHA256
-  register_hash (&sha256_desc);
-#endif
-#ifdef SHA224
-  register_hash (&sha224_desc);
-#endif
-#ifdef SHA384
-  register_hash (&sha384_desc);
-#endif
-#ifdef SHA512
-  register_hash (&sha512_desc);
-#endif
-#ifdef RIPEMD128
-  register_hash (&rmd128_desc);
-#endif
-#ifdef RIPEMD160
-  register_hash (&rmd160_desc);
-#endif
-#ifdef WHIRLPOOL
-  register_hash (&whirlpool_desc);
-#endif
-
-   if (register_prng(&yarrow_desc) == -1) {
-      printf("Error registering yarrow PRNG\n");
-      exit(-1);
-   }
-
-   if (register_prng(&sprng_desc) == -1) {
-      printf("Error registering sprng PRNG\n");
-      exit(-1);
-   }
-}
-
-/* sort tests based on their requirement/services.  Helps make sure dependencies are tested first */
-void sort(void)
-{
-   unsigned x, y, z, a, pidx[26];
-      
-   /* find out where things are provided */
-   zeromem(pidx, sizeof(pidx));   
-   z = 0;
-   do { 
-      y = 0;
-      for (x = 0; test_list[x].name != NULL; x++) {
-        if (test_list[x].entry == NULL) continue;
-        if (strlen(test_list[x].prov) == 0) {
-           y = 1;
-           tests[z++] = test_list[x]; test_list[x].entry = NULL;
-           pidx[test_list[x].prov[0]-'a'] = 1;
-           break;
-        } else {
-           for (a = 0; a < strlen(test_list[x].req); a++) {
-               if (pidx[test_list[x].req[a]-'a'] == 0) break;
-           }
-           if (a == strlen(test_list[x].req)) {
-              y = 1;
-              tests[z++] = test_list[x]; test_list[x].entry = NULL;
-              pidx[test_list[x].prov[0]-'a'] = 1;
-              break;
-           }
-        }
-      }
-   } while (y == 1);
-}
-   
-int main(void)
-{
-   printf("Built with\n%s\n", crypt_build_settings);
-
-   srand(time(NULL));
-   sort();
-   register_algs();
-      
-   // start dummy yarrow for internal use 
-   DO(yarrow_start(&test_yarrow));
-   DO(yarrow_add_entropy("test", 4, &test_yarrow));
-   DO(yarrow_ready(&test_yarrow));
-
-   // do tests
-   for (current_test = 0; tests[current_test].name != NULL; current_test++) {
-       printf("[%-20s]: ", tests[current_test].name); fflush(stdout);
-       printf("\t%s\n", tests[current_test].entry()==0?"passed":"failed"); 
-   }
-   
-   return 0;
-}
diff --git a/demos/test/test.h b/demos/test/test.h
deleted file mode 100644
index 9f13157..0000000
--- a/demos/test/test.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __TEST_H_
-#define __TEST_H_
-
-#include "mycrypt.h"
-
-typedef struct {
-    char *name, *prov, *req;
-    int  (*entry)(void);
-} test_entry;
-
-extern prng_state test_yarrow;
-
-void run_cmd(int res, int line, char *file, char *cmd);
-#define DO(x) run_cmd((x), __LINE__, __FILE__, #x)
-
-
-
-/* TESTS */
-int cipher_hash_test(void);
-int modes_test(void);
-int mac_test(void);
-int pkcs_1_test(void);
-int store_test(void);
-int rsa_test(void);
-int ecc_tests(void);
-int dsa_test(void);
-int dh_tests(void);
-
-#endif
diff --git a/demos/timing.c b/demos/timing.c
new file mode 100644
index 0000000..368d6e4
--- /dev/null
+++ b/demos/timing.c
@@ -0,0 +1,26 @@
+#include <tomcrypt_test.h>
+
+int main(void)
+{
+init_timer();
+reg_algs();
+time_keysched();
+time_cipher();
+time_cipher2();
+time_cipher3();
+time_hash();
+time_macs();
+time_encmacs();
+time_prng();
+time_mult();
+time_sqr();
+time_rsa();
+time_ecc();
+time_dh();
+return EXIT_SUCCESS;
+
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/timing.c,v $ */
+/* $Revision: 1.17 $ */
+/* $Date: 2005/06/23 02:16:26 $ */
diff --git a/demos/tv_gen.c b/demos/tv_gen.c
index cf75d3b..edaae3e 100644
--- a/demos/tv_gen.c
+++ b/demos/tv_gen.c
@@ -1,7 +1,9 @@
-#include <mycrypt.h>
+#include <tomcrypt.h>
 
 void reg_algs(void)
 {
+  int err;
+
 #ifdef RIJNDAEL
   register_cipher (&aes_desc);
 #endif
@@ -45,6 +47,12 @@
 #ifdef SKIPJACK
   register_cipher (&skipjack_desc);
 #endif
+#ifdef ANUBIS
+  register_cipher (&anubis_desc);
+#endif
+#ifdef KHAZAD
+  register_cipher (&khazad_desc);
+#endif
 
 #ifdef TIGER
   register_hash (&tiger_desc);
@@ -82,26 +90,45 @@
 #ifdef WHIRLPOOL
   register_hash (&whirlpool_desc);
 #endif
+#ifdef CHC_HASH
+  register_hash(&chc_desc);
+  if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
+     printf("chc_register error: %s\n", error_to_string(err));
+     exit(EXIT_FAILURE);
+  }
+#endif
+
 }
 
 void hash_gen(void)
 {
-   unsigned char md[MAXBLOCKSIZE], buf[MAXBLOCKSIZE*2+2];
+   unsigned char md[MAXBLOCKSIZE], *buf;
    unsigned long outlen, x, y, z;
    FILE *out;
+   int   err;
    
    out = fopen("hash_tv.txt", "w");
+   if (out == NULL) {
+      perror("can't open hash_tv");
+   }
    
    fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n");
    for (x = 0; hash_descriptor[x].name != NULL; x++) {
+      buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1);
+      if (buf == NULL) {
+         perror("can't alloc mem");
+         exit(EXIT_FAILURE);
+      }
       fprintf(out, "Hash: %s\n", hash_descriptor[x].name);
-      
       for (y = 0; y <= (hash_descriptor[x].blocksize * 2); y++) {
          for (z = 0; z < y; z++) {
             buf[z] = (unsigned char)(z & 255);
          }
          outlen = sizeof(md);
-         hash_memory(x, buf, y, md, &outlen);
+         if ((err = hash_memory(x, buf, y, md, &outlen)) != CRYPT_OK) {
+            printf("hash_memory error: %s\n", error_to_string(err));
+            exit(EXIT_FAILURE);
+         }
          fprintf(out, "%3lu: ", y);
          for (z = 0; z < outlen; z++) {
             fprintf(out, "%02X", md[z]);
@@ -109,15 +136,16 @@
          fprintf(out, "\n");
       }
       fprintf(out, "\n");
+      XFREE(buf);
    }
    fclose(out);
 }
 
 void cipher_gen(void)
 {
-   unsigned char key[MAXBLOCKSIZE], pt[MAXBLOCKSIZE];
+   unsigned char *key, pt[MAXBLOCKSIZE];
    unsigned long x, y, z, w;
-   int kl, lastkl;
+   int err, kl, lastkl;
    FILE *out;
    symmetric_key skey;
    
@@ -138,15 +166,27 @@
             case 1: kl = (cipher_descriptor[x].min_key_length + cipher_descriptor[x].max_key_length)/2; break;
             case 2: kl = cipher_descriptor[x].max_key_length; break;
          }
-         cipher_descriptor[x].keysize(&kl);
+         if ((err = cipher_descriptor[x].keysize(&kl)) != CRYPT_OK) {
+            printf("keysize error: %s\n", error_to_string(err));
+            exit(EXIT_FAILURE);
+         }
          if (kl == lastkl) break;
          lastkl = kl;
          fprintf(out, "Key Size: %d bytes\n", kl);
 
+         key = XMALLOC(kl);
+         if (key == NULL) {
+            perror("can't malloc memory");
+            exit(EXIT_FAILURE);
+         }
+
          for (z = 0; (int)z < kl; z++) {
              key[z] = (unsigned char)z;
          }
-         cipher_descriptor[x].setup(key, kl, 0, &skey);
+         if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
+            printf("setup error: %s\n", error_to_string(err));
+            exit(EXIT_FAILURE);
+         }
          
          for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
             pt[z] = (unsigned char)z;
@@ -163,9 +203,13 @@
              for (z = 0; z < (unsigned long)kl; z++) {
                  key[z] = pt[z % cipher_descriptor[x].block_length];
              }
-             cipher_descriptor[x].setup(key, kl, 0, &skey);
+             if ((err = cipher_descriptor[x].setup(key, kl, 0, &skey)) != CRYPT_OK) {
+                printf("cipher setup2 error: %s\n", error_to_string(err));
+                exit(EXIT_FAILURE);
+             }
          }
          fprintf(out, "\n");
+         XFREE(key);
      }
      fprintf(out, "\n");
   }
@@ -174,8 +218,8 @@
 
 void hmac_gen(void)
 {
-   unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
-   int x, y, z, kl, err;
+   unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], *input;
+   int x, y, z, err;
    FILE *out;
    unsigned long len;
   
@@ -193,6 +237,12 @@
       for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) {
           key[y] = (y&255);
       }
+
+      input = XMALLOC(hash_descriptor[x].blocksize * 2 + 1);
+      if (input == NULL) {
+         perror("Can't malloc memory");
+         exit(EXIT_FAILURE);
+      }
       
       for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) {
          for (z = 0; z < y; z++) {
@@ -212,6 +262,7 @@
          /* forward the key */
          memcpy(key, output, hash_descriptor[x].hashsize);
       }
+      XFREE(input);
       fprintf(out, "\n");
    }
    fclose(out);
@@ -450,6 +501,127 @@
    fclose(out);
 }
 
+
+void ccm_gen(void)
+{
+   int err, kl, x, y1, z;
+   FILE *out;
+   unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], 
+                 plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
+   unsigned long len;
+
+   out = fopen("ccm_tv.txt", "w");
+   fprintf(out, "CCM Test Vectors.  Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key.  The outputs\n"
+                "are of the form ciphertext,tag for a given NN.  The key for step N>1 is the tag of the previous\n"
+                "step repeated sufficiently.  The nonce is fixed throughout at 13 bytes 000102...\n\n");
+
+   for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+      kl = cipher_descriptor[x].block_length;
+
+      /* skip ciphers which do not have 128 bit block sizes */
+      if (kl != 16) continue;
+
+      if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
+         kl = cipher_descriptor[x].max_key_length;
+      }
+      fprintf(out, "CCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
+
+      /* the key */
+      for (z = 0; z < kl; z++) {
+          key[z] = (z & 255);
+      }
+
+      /* fixed nonce */
+      for (z = 0; z < cipher_descriptor[x].block_length; z++) {
+          nonce[z] = z;
+      }
+      
+      for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
+         for (z = 0; z < y1; z++) {
+            plaintext[z] = (unsigned char)(z & 255);
+         }
+         len = sizeof(tag);
+         if ((err = ccm_memory(x, key, kl, nonce, 13, plaintext, y1, plaintext, y1, plaintext, tag, &len, CCM_ENCRYPT)) != CRYPT_OK) {
+            printf("Error CCM'ing: %s\n", error_to_string(err));
+            exit(EXIT_FAILURE);
+         }
+         fprintf(out, "%3d: ", y1);
+         for (z = 0; z < y1; z++) {
+            fprintf(out, "%02X", plaintext[z]);
+         }
+         fprintf(out, ", ");
+         for (z = 0; z <(int)len; z++) {
+            fprintf(out, "%02X", tag[z]);
+         }
+         fprintf(out, "\n");
+
+         /* forward the key */
+         for (z = 0; z < kl; z++) {
+             key[z] = tag[z % len];
+         }
+      }
+      fprintf(out, "\n");
+   }
+   fclose(out);
+}
+
+void gcm_gen(void)
+{
+   int err, kl, x, y1, z;
+   FILE *out;
+   unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
+   unsigned long len;
+
+   out = fopen("gcm_tv.txt", "w");
+   fprintf(out, "GCM Test Vectors.  Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key.  The outputs\n"
+                "are of the form ciphertext,tag for a given NN.  The key for step N>1 is the tag of the previous\n"
+                "step repeated sufficiently.  The nonce is fixed throughout at 13 bytes 000102...\n\n");
+
+   for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+      kl = cipher_descriptor[x].block_length;
+
+      /* skip ciphers which do not have 128 bit block sizes */
+      if (kl != 16) continue;
+
+      if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
+         kl = cipher_descriptor[x].max_key_length;
+      }
+      fprintf(out, "GCM-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
+
+      /* the key */
+      for (z = 0; z < kl; z++) {
+          key[z] = (z & 255);
+      }
+     
+      for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
+         for (z = 0; z < y1; z++) {
+            plaintext[z] = (unsigned char)(z & 255);
+         }
+         len = sizeof(tag);
+         if ((err = gcm_memory(x, key, kl, plaintext, y1, plaintext, y1, plaintext, y1, plaintext, tag, &len, GCM_ENCRYPT)) != CRYPT_OK) {
+            printf("Error GCM'ing: %s\n", error_to_string(err));
+            exit(EXIT_FAILURE);
+         }
+         fprintf(out, "%3d: ", y1);
+         for (z = 0; z < y1; z++) {
+            fprintf(out, "%02X", plaintext[z]);
+         }
+         fprintf(out, ", ");
+         for (z = 0; z <(int)len; z++) {
+            fprintf(out, "%02X", tag[z]);
+         }
+         fprintf(out, "\n");
+
+         /* forward the key */
+         for (z = 0; z < kl; z++) {
+             key[z] = tag[z % len];
+         }
+      }
+      fprintf(out, "\n");
+   }
+   fclose(out);
+}
+
 void base64_gen(void)
 {
    FILE *out;
@@ -479,6 +651,8 @@
    printf("Generating PMAC   vectors..."); fflush(stdout); pmac_gen(); printf("done\n");
    printf("Generating EAX    vectors..."); fflush(stdout); eax_gen(); printf("done\n");
    printf("Generating OCB    vectors..."); fflush(stdout); ocb_gen(); printf("done\n");
+   printf("Generating CCM    vectors..."); fflush(stdout); ccm_gen(); printf("done\n");
+   printf("Generating GCM    vectors..."); fflush(stdout); gcm_gen(); printf("done\n");
    printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
    return 0;
 }
@@ -490,3 +664,7 @@
       
     
    
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/tv_gen.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:56 $ */
diff --git a/demos/x86_prof.c b/demos/x86_prof.c
deleted file mode 100644
index e968554..0000000
--- a/demos/x86_prof.c
+++ /dev/null
@@ -1,358 +0,0 @@
-#include <mycrypt.h>
-
-#define KTIMES  25
-#define TIMES   100000
-
-struct list {
-    int id;
-    unsigned long spd1, spd2, avg;
-} results[100];
-
-int no_results;
-
-int sorter(const void *a, const void *b)
-{
-   const struct list *A, *B;
-   A = a;
-   B = b;
-   if (A->avg < B->avg) return -1;
-   if (A->avg > B->avg) return 1;
-   return 0;
-}
-
-void tally_results(int type)
-{
-   int x;
-
-   // qsort the results
-   qsort(results, no_results, sizeof(struct list), &sorter);
-
-   printf("\n");
-   if (type == 0) {
-      for (x = 0; x < no_results; x++) {
-         printf("%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1);
-      } 
-   } else if (type == 1) {
-      for (x = 0; x < no_results; x++) {
-        printf
-          ("%-20s: Encrypt at %5lu, Decrypt at %5lu\n", cipher_descriptor[results[x].id].name, results[x].spd1, results[x].spd2);
-      }
-   } else {
-      for (x = 0; x < no_results; x++) {
-        printf
-          ("%-20s: Process at %5lu\n", hash_descriptor[results[x].id].name, results[x].spd1 / 1000);
-      }
-   }
-}
-
-
-
-
-/* RDTSC from Scott Duplichan */
-static ulong64 rdtsc (void)
-   {
-   #if defined __GNUC__
-      #ifdef __i386__
-         ulong64 a;
-         __asm__ __volatile__ ("rdtsc ":"=A" (a));
-         return a;
-      #else /* gcc-IA64 version */
-         unsigned long result;
-         __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
-         while (__builtin_expect ((int) result == -1, 0))
-         __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
-         return result;
-      #endif
-
-   // Microsoft and Intel Windows compilers
-   #elif defined _M_IX86
-     __asm rdtsc
-   #elif defined _M_AMD64
-     return __rdtsc ();
-   #elif defined _M_IA64
-     #if defined __INTEL_COMPILER
-       #include <ia64intrin.h>
-     #endif
-      return __getReg (3116);
-   #else
-     #error need rdtsc function for this build
-   #endif
-   }
-
-ulong64 timer, skew = 0;
-prng_state prng;
-
-void t_start(void)
-{
-   timer = rdtsc();
-}
-
-ulong64 t_read(void)
-{
-   return rdtsc() - timer;
-}
-
-void init_timer(void)
-{
-   ulong64 c1, c2, t1, t2, t3;
-   unsigned long y1;
-
-   c1 = c2 = (ulong64)-1;
-   for (y1 = 0; y1 < TIMES*100; y1++) {
-      t_start();
-      t1 = t_read();
-      t3 = t_read();
-      t2 = t_read() - t1;
-
-      c1 = (c1 > t1) ? t1 : c1;
-      c2 = (c2 > t2) ? t2 : c2;
-   }
-   skew = c2 - c1;
-   printf("Clock Skew: %lu\n", (unsigned long)skew);
-}
-
-void reg_algs(void)
-{
-#ifdef RIJNDAEL
-  register_cipher (&aes_desc);
-#endif
-#ifdef BLOWFISH
-  register_cipher (&blowfish_desc);
-#endif
-#ifdef XTEA
-  register_cipher (&xtea_desc);
-#endif
-#ifdef RC5
-  register_cipher (&rc5_desc);
-#endif
-#ifdef RC6
-  register_cipher (&rc6_desc);
-#endif
-#ifdef SAFERP
-  register_cipher (&saferp_desc);
-#endif
-#ifdef TWOFISH
-  register_cipher (&twofish_desc);
-#endif
-#ifdef SAFER
-  register_cipher (&safer_k64_desc);
-  register_cipher (&safer_sk64_desc);
-  register_cipher (&safer_k128_desc);
-  register_cipher (&safer_sk128_desc);
-#endif
-#ifdef RC2
-  register_cipher (&rc2_desc);
-#endif
-#ifdef DES
-  register_cipher (&des_desc);
-  register_cipher (&des3_desc);
-#endif
-#ifdef CAST5
-  register_cipher (&cast5_desc);
-#endif
-#ifdef NOEKEON
-  register_cipher (&noekeon_desc);
-#endif
-#ifdef SKIPJACK
-  register_cipher (&skipjack_desc);
-#endif
-
-#ifdef TIGER
-  register_hash (&tiger_desc);
-#endif
-#ifdef MD2
-  register_hash (&md2_desc);
-#endif
-#ifdef MD4
-  register_hash (&md4_desc);
-#endif
-#ifdef MD5
-  register_hash (&md5_desc);
-#endif
-#ifdef SHA1
-  register_hash (&sha1_desc);
-#endif
-#ifdef SHA224
-  register_hash (&sha224_desc);
-#endif
-#ifdef SHA256
-  register_hash (&sha256_desc);
-#endif
-#ifdef SHA384
-  register_hash (&sha384_desc);
-#endif
-#ifdef SHA512
-  register_hash (&sha512_desc);
-#endif
-#ifdef RIPEMD128
-  register_hash (&rmd128_desc);
-#endif
-#ifdef RIPEMD160
-  register_hash (&rmd160_desc);
-#endif
-#ifdef WHIRLPOOL
-  register_hash (&whirlpool_desc);
-#endif
-
-register_prng(&yarrow_desc);
-rng_make_prng(128, find_prng("yarrow"), &prng, NULL);
-}
-
-int time_keysched(void)
-{
-  unsigned long x, i, y1;
-  ulong64 t1, c1;
-  symmetric_key skey;
-  int kl;
-  int    (*func) (const unsigned char *, int , int , symmetric_key *);
-  unsigned char key[MAXBLOCKSIZE];
-
-  printf ("\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n");
-  no_results = 0; 
- for (x = 0; cipher_descriptor[x].name != NULL; x++) {
-#define DO1(k)   func(k, kl, 0, &skey);
-
-    func = cipher_descriptor[x].setup;
-    kl   = cipher_descriptor[x].min_key_length;
-    c1 = (ulong64)-1;
-    for (y1 = 0; y1 < KTIMES; y1++) {
-       yarrow_read(key, kl, &prng);
-       t_start();
-       DO1(key);
-       t1 = t_read();
-       c1 = (t1 > c1) ? c1 : t1;
-    }
-    t1 = c1 - skew;
-    results[no_results].spd1 = results[no_results].avg = t1;
-    results[no_results++].id = x;
-    printf("."); fflush(stdout);
-
-#undef DO1
-   }
-   tally_results(0);
-
-   return 0;
-}
-
-int time_cipher(void)
-{
-  unsigned long x, y1;
-  ulong64  t1, t2, c1, c2, a1, a2;
-  symmetric_key skey;
-  void    (*func) (const unsigned char *, unsigned char *, symmetric_key *);
-  unsigned char key[MAXBLOCKSIZE], pt[MAXBLOCKSIZE];
-
-
-  printf ("\n\nECB Time Trials for the Symmetric Ciphers:\n");
-  no_results = 0;
-  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
-    cipher_descriptor[x].setup (key, cipher_descriptor[x].min_key_length, 0,
-                &skey);
-
-#define DO1   func(pt,pt,&skey);
-#define DO2   DO1 DO1
-
-    func = cipher_descriptor[x].ecb_encrypt;
-    c1 = c2 = (ulong64)-1;
-    for (y1 = 0; y1 < TIMES; y1++) {
-        t_start();
-        DO1;
-        t1 = t_read();
-        DO2;
-        t2 = t_read();
-        t2 -= t1;
-
-        c1 = (t1 > c1 ? c1 : t1);
-        c2 = (t2 > c2 ? c2 : t2);
-    }
-    a1 = c2 - c1 - skew;
-
-
-    func = cipher_descriptor[x].ecb_decrypt;
-    c1 = c2 = (ulong64)-1;
-    for (y1 = 0; y1 < TIMES; y1++) {
-        t_start();
-        DO1;
-        t1 = t_read();
-        DO2;
-        t2 = t_read();
-        t2 -= t1;
-
-        c1 = (t1 > c1 ? c1 : t1);
-        c2 = (t2 > c2 ? c2 : t2);
-    }
-    a2 = c2 - c1 - skew;
-    
-    results[no_results].id = x;
-    results[no_results].spd1 = a1/cipher_descriptor[x].block_length;
-    results[no_results].spd2 = a2/cipher_descriptor[x].block_length;;
-    results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
-    ++no_results;
-    printf("."); fflush(stdout);
-    
-#undef DO2
-#undef DO1
-   }
-   tally_results(1);
-
-   return 0;
-}
-
-int time_hash(void)
-{
-  unsigned long x, y1, len;
-  ulong64 t1, t2, c1, c2;
-  hash_state md;
-  int    (*func)(hash_state *, const unsigned char *, unsigned long);
-  unsigned char pt[MAXBLOCKSIZE];
-
-
-  printf ("\n\nHASH Time Trials for:\n");
-  no_results = 0;
-  for (x = 0; hash_descriptor[x].name != NULL; x++) {
-    hash_descriptor[x].init(&md);
-
-#define DO1   func(&md,pt,len);
-#define DO2   DO1 DO1
-
-    func = hash_descriptor[x].process;
-    len  = hash_descriptor[x].blocksize;
-
-    c1 = c2 = (ulong64)-1;
-    for (y1 = 0; y1 < TIMES; y1++) {
-       t_start();
-       DO1;
-       t1 = t_read();
-       DO2;
-       t2 = t_read() - t1;
-       c1 = (t1 > c1) ? c1 : t1;
-       c2 = (t2 > c2) ? c2 : t2;
-    }
-    t1 = c2 - c1 - skew;
-    t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
-    results[no_results].id = x;
-    results[no_results].spd1 = results[no_results].avg = t1;
-    ++no_results;
-    printf("."); fflush(stdout);
-#undef DO2
-#undef DO1
-   }
-   tally_results(2);
-
-   return 0;
-}
-
-int main(void)
-{
-  reg_algs();
-
-  printf("Timings for ciphers and hashes.  Times are listed as cycles per byte processed.\n\n");
-
-//  init_timer();
-  time_cipher();
-  time_keysched();
-  time_hash();
-
-  return EXIT_SUCCESS;
-}
-
diff --git a/doc/footer.html b/doc/footer.html
new file mode 100644
index 0000000..a1895ac
--- /dev/null
+++ b/doc/footer.html
@@ -0,0 +1,10 @@
+<hr width="80%">
+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 $ */
+-->
diff --git a/doc/header.html b/doc/header.html
new file mode 100644
index 0000000..231475d
--- /dev/null
+++ b/doc/header.html
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
+<title>LibTomCrypt: Main Page</title>
+<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 $ */
+-->
diff --git a/dsa_export.c b/dsa_export.c
deleted file mode 100644
index 995b1cf..0000000
--- a/dsa_export.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef MDSA
-
-int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key)
-{
-   unsigned long y, z;
-   int err;
-
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-
-   /* can we store the static header?  */
-   if (*outlen < (PACKET_SIZE + 1 + 2)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   
-   if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
-      return CRYPT_PK_TYPE_MISMATCH;
-   }
-
-   if (type != PK_PUBLIC && type != PK_PRIVATE) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* store header */
-   packet_store_header(out, PACKET_SECT_DSA, PACKET_SUB_KEY);
-   y = PACKET_SIZE;
-
-   /* store g, p, q, qord */
-   out[y++] = type;
-   out[y++] = (key->qord>>8)&255;
-   out[y++] = key->qord & 255;
-
-   OUTPUT_BIGNUM(&key->g,out,y,z);
-   OUTPUT_BIGNUM(&key->p,out,y,z);
-   OUTPUT_BIGNUM(&key->q,out,y,z);
-
-   /* public exponent */
-   OUTPUT_BIGNUM(&key->y,out,y,z);
-   
-   if (type == PK_PRIVATE) {
-      OUTPUT_BIGNUM(&key->x,out,y,z);
-   }
-
-   *outlen = y;
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/dsa_free.c b/dsa_free.c
deleted file mode 100644
index c451951..0000000
--- a/dsa_free.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef MDSA
-
-void dsa_free(dsa_key *key)
-{
-   _ARGCHK(key != NULL);
-   mp_clear_multi(&key->g, &key->q, &key->p, &key->x, &key->y, NULL);
-}
-
-#endif
diff --git a/dsa_import.c b/dsa_import.c
deleted file mode 100644
index 429876d..0000000
--- a/dsa_import.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef MDSA
-
-int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
-{
-   unsigned long x, y;
-   int err;
-
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
-
-   /* check length */
-   if ((1+2+PACKET_SIZE) > inlen) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* check type */
-   if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_DSA, PACKET_SUB_KEY)) != CRYPT_OK) {
-      return err;
-   }
-   y = PACKET_SIZE;
-
-   /* init key */
-   if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != MP_OKAY) {
-      return CRYPT_MEM;
-   }
-
-   /* read type/qord */
-   key->type = in[y++];
-   key->qord = ((unsigned)in[y]<<8)|((unsigned)in[y+1]);
-   y += 2;
-
-   /* input publics */
-   INPUT_BIGNUM(&key->g,in,x,y, inlen);
-   INPUT_BIGNUM(&key->p,in,x,y, inlen);
-   INPUT_BIGNUM(&key->q,in,x,y, inlen);
-   INPUT_BIGNUM(&key->y,in,x,y, inlen);
-   if (key->type == PK_PRIVATE) {
-      INPUT_BIGNUM(&key->x,in,x,y, inlen);
-   }
-
-   return CRYPT_OK;
-error: 
-   mp_clear_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL);
-   return err;
-}
-
-#endif
diff --git a/dsa_sign_hash.c b/dsa_sign_hash.c
deleted file mode 100644
index b204371..0000000
--- a/dsa_sign_hash.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef MDSA
-
-int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
-                        unsigned char *out, unsigned long *outlen,
-                        prng_state *prng, int wprng, dsa_key *key)
-{
-   mp_int k, kinv, tmp, r, s;
-   unsigned char buf[512];
-   int err, y;
-   unsigned long len;
-
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-
-   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-      return err;
-   }
-   if (key->type != PK_PRIVATE) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   /* check group order size  */
-   if (key->qord >= (int)sizeof(buf)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* Init our temps */
-   if ((err = mp_init_multi(&k, &kinv, &r, &s, &tmp, NULL)) != MP_OKAY)               { goto error; }
-
-retry:
-
-   do {
-      /* gen random k */
-      if (prng_descriptor[wprng].read(buf, key->qord, prng) != (unsigned long)key->qord) {
-         err = CRYPT_ERROR_READPRNG;
-         goto done;
-      }
-
-      /* read k */
-      if ((err = mp_read_unsigned_bin(&k, buf, key->qord)) != MP_OKAY)                { goto error; }
-
-      /* k > 1 ? */
-      if (mp_cmp_d(&k, 1) != MP_GT)                                                   { goto retry; }
-
-      /* test gcd */
-      if ((err = mp_gcd(&k, &key->q, &tmp)) != MP_OKAY)                               { goto error; }
-   } while (mp_cmp_d(&tmp, 1) != MP_EQ);
-
-   /* now find 1/k mod q */
-   if ((err = mp_invmod(&k, &key->q, &kinv)) != MP_OKAY)                              { goto error; }
-
-   /* now find r = g^k mod p mod q */
-   if ((err = mp_exptmod(&key->g, &k, &key->p, &r)) != MP_OKAY)                       { goto error; }
-   if ((err = mp_mod(&r, &key->q, &r)) != MP_OKAY)                                    { goto error; }
-
-   if (mp_iszero(&r) == MP_YES)                                                       { goto retry; }
-
-   /* now find s = (in + xr)/k mod q */
-   if ((err = mp_read_unsigned_bin(&tmp, (unsigned char *)in, inlen)) != MP_OKAY)     { goto error; }
-   if ((err = mp_mul(&key->x, &r, &s)) != MP_OKAY)                                    { goto error; }
-   if ((err = mp_add(&s, &tmp, &s)) != MP_OKAY)                                       { goto error; }
-   if ((err = mp_mulmod(&s, &kinv, &key->q, &s)) != MP_OKAY)                          { goto error; }
-
-   if (mp_iszero(&s) == MP_YES)                                                       { goto retry; }
-
-   /* now store em both */
-   
-   /* first check that we have enough room */
-   if (*outlen < (unsigned long)(PACKET_SIZE + 4 + mp_unsigned_bin_size(&s) + mp_unsigned_bin_size(&r))) {
-      err = CRYPT_BUFFER_OVERFLOW;
-      goto done;
-   }
-
-   /* packet header */
-   packet_store_header(out, PACKET_SECT_DSA, PACKET_SUB_SIGNED);
-   y = PACKET_SIZE;
-
-   /* store length of r */
-   len = mp_unsigned_bin_size(&r);
-   out[y++] = (len>>8)&255;
-   out[y++] = len&255;
-   
-   /* store r */
-   if ((err = mp_to_unsigned_bin(&r, out+y)) != MP_OKAY)                              { goto error; }
-   y += len;
-
-   /* store length of s */
-   len = mp_unsigned_bin_size(&s);
-   out[y++] = (len>>8)&255;
-   out[y++] = len&255;
-   
-   /* store s */
-   if ((err = mp_to_unsigned_bin(&s, out+y)) != MP_OKAY)                              { goto error; }
-   y += len;
-
-   /* reset size */
-   *outlen = y;
-
-   err = CRYPT_OK;
-   goto done;
-
-error : err = mpi_to_ltc_error(err);
-done  : mp_clear_multi(&k, &kinv, &r, &s, &tmp, NULL);
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return err;
-}
-
-#endif
diff --git a/dsa_verify_hash.c b/dsa_verify_hash.c
deleted file mode 100644
index 745cd7c..0000000
--- a/dsa_verify_hash.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef MDSA
-
-int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
-                    const unsigned char *hash, unsigned long inlen, 
-                    int *stat, dsa_key *key)
-{
-   mp_int r, s, w, v, u1, u2;
-   unsigned long x, y;
-   int err;
-
-   _ARGCHK(sig  != NULL);
-   _ARGCHK(hash != NULL);
-   _ARGCHK(stat != NULL);
-   _ARGCHK(key  != NULL);
-
-   /* default to invalid signature */
-   *stat = 0;
-
-   if (siglen < PACKET_SIZE+2+2) {
-      return CRYPT_INVALID_PACKET;
-   } 
-
-   /* is the message format correct? */
-   if ((err = packet_valid_header((unsigned char *)sig, PACKET_SECT_DSA, PACKET_SUB_SIGNED)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* skip over header */
-   y = PACKET_SIZE;
-
-   /* init our variables */
-   if ((err = mp_init_multi(&r, &s, &w, &v, &u1, &u2, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   /* read in r followed by s */
-   x = ((unsigned)sig[y]<<8)|((unsigned)sig[y+1]);
-   y += 2;
-   if (y + x > siglen) { 
-      err = CRYPT_INVALID_PACKET;
-      goto done;
-   }
-   if ((err = mp_read_unsigned_bin(&r, (unsigned char *)sig+y, x)) != MP_OKAY)             { goto error; }
-   y += x;
-
-   /* load s */
-   x = ((unsigned)sig[y]<<8)|((unsigned)sig[y+1]);
-   y += 2;
-   if (y + x > siglen) { 
-      err = CRYPT_INVALID_PACKET;
-      goto done;
-   }
-   if ((err = mp_read_unsigned_bin(&s, (unsigned char *)sig+y, x)) != MP_OKAY)             { goto error; }
-
-   /* w = 1/s mod q */
-   if ((err = mp_invmod(&s, &key->q, &w)) != MP_OKAY)                                      { goto error; }
-
-   /* u1 = m * w mod q */
-   if ((err = mp_read_unsigned_bin(&u1, (unsigned char *)hash, inlen)) != MP_OKAY)         { goto error; }
-   if ((err = mp_mulmod(&u1, &w, &key->q, &u1)) != MP_OKAY)                                { goto error; }
-
-   /* u2 = r*w mod q */
-   if ((err = mp_mulmod(&r, &w, &key->q, &u2)) != MP_OKAY)                                 { goto error; } 
-
-   /* v = g^u1 * y^u2 mod p mod q */
-   if ((err = mp_exptmod(&key->g, &u1, &key->p, &u1)) != MP_OKAY)                          { goto error; }
-   if ((err = mp_exptmod(&key->y, &u2, &key->p, &u2)) != MP_OKAY)                          { goto error; }
-   if ((err = mp_mulmod(&u1, &u2, &key->p, &v)) != MP_OKAY)                                { goto error; }
-   if ((err = mp_mod(&v, &key->q, &v)) != MP_OKAY)                                         { goto error; }
-
-   /* if r = v then we're set */
-   if (mp_cmp(&r, &v) == MP_EQ) {
-      *stat = 1;
-   }
-
-   err = CRYPT_OK;
-   goto done;
-
-error : err = mpi_to_ltc_error(err);
-done  : mp_clear_multi(&r, &s, &w, &v, &u1, &u2, NULL);
-   return err;
-}
-
-#endif
-
diff --git a/eax_addheader.c b/eax_addheader.c
deleted file mode 100644
index c7dfdd0..0000000
--- a/eax_addheader.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-/* add header (metadata) to the stream */
-int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length)
-{
-   _ARGCHK(eax    != NULL);
-   _ARGCHK(header != NULL);
-   return omac_process(&eax->headeromac, header, length);
-}
-
-#endif
diff --git a/eax_decrypt.c b/eax_decrypt.c
deleted file mode 100644
index de7c290..0000000
--- a/eax_decrypt.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length)
-{
-   int err;
-   
-   _ARGCHK(eax != NULL);
-   _ARGCHK(pt  != NULL);
-   _ARGCHK(ct  != NULL);
-
-   /* omac ciphertext */
-   if ((err = omac_process(&eax->ctomac, ct, length)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* decrypt  */
-   return ctr_decrypt(ct, pt, length, &eax->ctr);
-}
-
-#endif
diff --git a/eax_decrypt_verify_memory.c b/eax_decrypt_verify_memory.c
deleted file mode 100644
index 3e68efe..0000000
--- a/eax_decrypt_verify_memory.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-int eax_decrypt_verify_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  unsigned long noncelen,
-    const unsigned char *header, unsigned long headerlen,
-    const unsigned char *ct,     unsigned long ctlen,
-          unsigned char *pt,
-          unsigned char *tag,    unsigned long taglen,
-          int           *res)
-{
-   int err;
-   eax_state eax;
-   unsigned char buf[MAXBLOCKSIZE];
-   unsigned long buflen;
-
-   _ARGCHK(res != NULL);
-
-   /* default to zero */
-   *res = 0;
-
-   if ((err = eax_init(&eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
-      return err;
-   }
-
-   if ((err = eax_decrypt(&eax, ct, pt, ctlen)) != CRYPT_OK) {
-      return err;
-   }
- 
-   buflen = MIN(sizeof(buf), taglen);
-   if ((err = eax_done(&eax, buf, &buflen)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* compare tags */
-   if (buflen >= taglen && memcmp(buf, tag, taglen) == 0) {
-      *res = 1;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/eax_done.c b/eax_done.c
deleted file mode 100644
index 8bc3706..0000000
--- a/eax_done.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen)
-{
-   int           err;
-   unsigned char headermac[MAXBLOCKSIZE], ctmac[MAXBLOCKSIZE];
-   unsigned long x, len;
-
-   _ARGCHK(eax    != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(taglen != NULL);
-
-   /* finish ctomac */
-   len = sizeof(ctmac);
-   if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* finish headeromac */
-
-   /* note we specifically don't reset len so the two lens are minimal */
-
-   if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* compute N xor H xor C */
-   for (x = 0; x < len && x < *taglen; x++) {
-       tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x];
-   }
-   *taglen = x;
-
-#ifdef CLEAN_STACK
-   zeromem(ctmac, sizeof(ctmac));
-   zeromem(headermac, sizeof(headermac));
-   zeromem(eax, sizeof(*eax));
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/eax_encrypt.c b/eax_encrypt.c
deleted file mode 100644
index 1b4930e..0000000
--- a/eax_encrypt.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length)
-{
-   int err;
-   
-   _ARGCHK(eax != NULL);
-   _ARGCHK(pt  != NULL);
-   _ARGCHK(ct  != NULL);
-
-   /* encrypt */
-   if ((err = ctr_encrypt(pt, ct, length, &eax->ctr)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* omac ciphertext */
-   return omac_process(&eax->ctomac, ct, length);
-}
-
-#endif
-
diff --git a/eax_encrypt_authenticate_memory.c b/eax_encrypt_authenticate_memory.c
deleted file mode 100644
index 60e9fa7..0000000
--- a/eax_encrypt_authenticate_memory.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-int eax_encrypt_authenticate_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  unsigned long noncelen,
-    const unsigned char *header, unsigned long headerlen,
-    const unsigned char *pt,     unsigned long ptlen,
-          unsigned char *ct,
-          unsigned char *tag,    unsigned long *taglen)
-{
-   int err;
-   eax_state eax;
-
-   if ((err = eax_init(&eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
-      return err;
-   }
-
-   if ((err = eax_encrypt(&eax, pt, ct, ptlen)) != CRYPT_OK) {
-      return err;
-   }
- 
-   if ((err = eax_done(&eax, tag, taglen)) != CRYPT_OK) {
-      return err;
-   }
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/eax_init.c b/eax_init.c
deleted file mode 100644
index 1b1bbba..0000000
--- a/eax_init.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef EAX_MODE
-
-int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
-             const unsigned char *nonce, unsigned long noncelen,
-             const unsigned char *header, unsigned long headerlen)
-{
-   unsigned char buf[MAXBLOCKSIZE];
-   int           err, blklen;
-   omac_state    omac;
-   unsigned long len;
-
-
-   _ARGCHK(eax   != NULL);
-   _ARGCHK(key   != NULL);
-   _ARGCHK(nonce != NULL);
-   if (headerlen > 0) {
-      _ARGCHK(header != NULL);
-   }
-
-   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
-      return err;
-   }
-   blklen = cipher_descriptor[cipher].block_length;
-
-   /* N = OMAC_0K(nonce) */
-   zeromem(buf, sizeof(buf));
-   if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* omac the [0]_n */
-   if ((err = omac_process(&omac, buf, blklen)) != CRYPT_OK) {
-      return err;
-   }
-   /* omac the nonce */
-   if ((err = omac_process(&omac, nonce, noncelen)) != CRYPT_OK) {
-      return err;
-   }
-   /* store result */
-   len = sizeof(eax->N);
-   if ((err = omac_done(&omac, eax->N, &len)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* H = OMAC_1K(header) */
-   zeromem(buf, sizeof(buf));
-   buf[blklen - 1] = 1;
-
-   if ((err = omac_init(&eax->headeromac, cipher, key, keylen)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* omac the [1]_n */
-   if ((err = omac_process(&eax->headeromac, buf, blklen)) != CRYPT_OK) {
-      return err;
-   }
-   /* omac the header */
-   if (headerlen != 0) {
-      if ((err = omac_process(&eax->headeromac, header, headerlen)) != CRYPT_OK) {
-         return err;
-      }
-   }
-
-   /* 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) {
-      return 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) { 
-      return err;
-   }
-
-   /* omac [2]_n */
-   zeromem(buf, sizeof(buf));
-   buf[blklen-1] = 2;
-   if ((err = omac_process(&eax->ctomac, buf, blklen)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-   zeromem(&omac, sizeof(omac));
-#endif
-   return CRYPT_OK;
-}
-
-#endif 
diff --git a/ecb_decrypt.c b/ecb_decrypt.c
deleted file mode 100644
index 4f23156..0000000
--- a/ecb_decrypt.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef ECB
-
-int ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_ECB *ecb)
-{
-   int err;
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(ecb != NULL);
-
-   /* valid cipher? */
-   if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
-       return err;
-   }
-   _ARGCHK(cipher_descriptor[ecb->cipher].ecb_decrypt != NULL);
-   
-   cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key);
-   return CRYPT_OK;
-}
-
-#endif
-
-
diff --git a/ecb_encrypt.c b/ecb_encrypt.c
deleted file mode 100644
index 51b7646..0000000
--- a/ecb_encrypt.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef ECB
-
-int ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ECB *ecb)
-{
-   int err;
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(ecb != NULL);
-
-   if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
-       return err;
-   }
-   cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key);
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/ecb_start.c b/ecb_start.c
deleted file mode 100644
index 073bbe9..0000000
--- a/ecb_start.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef ECB
-
-int ecb_start(int cipher, const unsigned char *key, int keylen, int num_rounds, symmetric_ECB *ecb)
-{
-   int err;
-   _ARGCHK(key != NULL);
-   _ARGCHK(ecb != NULL);
-
-   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
-      return err;
-   }
-   ecb->cipher = cipher;
-   ecb->blocklen = cipher_descriptor[cipher].block_length;
-   return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ecb->key);
-}
-
-#endif
diff --git a/ecc.c b/ecc.c
deleted file mode 100644
index ee19681..0000000
--- a/ecc.c
+++ /dev/null
@@ -1,937 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
- *
- * All curves taken from NIST recommendation paper of July 1999
- * Available at http://csrc.nist.gov/cryptval/dss.htm
- */
-
-#include "mycrypt.h"
-
-#ifdef MECC
-
-/* This holds the key settings.  ***MUST*** be organized by size from smallest to largest. */
-static const struct {
-   int size;
-   char *name, *prime, *B, *order, *Gx, *Gy;
-} sets[] = {
-#ifdef ECC160
-{
-   20,
-   "ECC-160",
-   /* prime */
-   "G00000000000000000000000007",
-   /* B */
-   "1oUV2vOaSlWbxr6",
-   /* order */
-   "G0000000000004sCQUtDxaqDUN5",
-   /* Gx */
-   "jpqOf1BHus6Yd/pyhyVpP",
-   /* Gy */
-   "D/wykuuIFfr+vPyx7kQEPu8MixO",
-},
-#endif
-#ifdef ECC192
-{
-    24,
-   "ECC-192",
-   /* prime */
-   "/////////////////////l//////////",
-
-   /* B */
-   "P2456UMSWESFf+chSYGmIVwutkp1Hhcn",
-
-   /* order */
-   "////////////////cTxuDXHhoR6qqYWn",
-
-   /* Gx */
-   "68se3h0maFPylo3hGw680FJ/2ls2/n0I",
-
-   /* Gy */
-   "1nahbV/8sdXZ417jQoJDrNFvTw4UUKWH"
-},
-#endif
-#ifdef ECC224
-{
-   28,
-   "ECC-224",
-
-   /* prime */
-   "400000000000000000000000000000000000BV",
-
-   /* B */
-   "21HkWGL2CxJIp",
-
-   /* order */
-   "4000000000000000000Kxnixk9t8MLzMiV264/",
-
-   /* Gx */
-   "jpqOf1BHus6Yd/pyhyVpP",
-
-   /* Gy */
-   "3FCtyo2yHA5SFjkCGbYxbOvNeChwS+j6wSIwck",
-},
-#endif
-#ifdef ECC256
-{
-   32,
-   "ECC-256",
-   /* Prime */
-   "F////y000010000000000000000////////////////",
-
-   /* B */
-   "5h6DTYgEfFdi+kzLNQOXhnb7GQmp5EmzZlEF3udqc1B",
-
-   /* Order */
-   "F////y00000//////////+yvlgjfnUUXFEvoiByOoLH",
-
-   /* Gx */
-   "6iNqVBXB497+BpcvMEaGF9t0ts1BUipeFIXEKNOcCAM",
-
-   /* Gy */
-   "4/ZGkB+6d+RZkVhIdmFdXOhpZDNQp5UpiksG6Wtlr7r"
-},
-#endif
-#ifdef ECC384
-{
-   48,
-   "ECC-384",
-   /* prime */
-   "//////////////////////////////////////////x/////00000000003/"
-   "////",
-
-   /* B */
-   "ip4lf+8+v+IOZWLhu/Wj6HWTd6x+WK4I0nG8Zr0JXrh6LZcDYYxHdIg5oEtJ"
-   "x2hl",
-
-   /* Order */
-   "////////////////////////////////nsDDWVGtBTzO6WsoIB2dUkpi6MhC"
-   "nIbp",
-
-   /* Gx and Gy */
-   "geVA8hwB1JUEiSSUyo2jT6uTEsABfvkOMVT1u89KAZXL0l9TlrKfR3fKNZXo"
-   "TWgt",
-
-   "DXVUIfOcB6zTdfY/afBSAVZq7RqecXHywTen4xNmkC0AOB7E7Nw1dNf37NoG"
-   "wWvV"
-},
-#endif
-#ifdef ECC521
-{
-   65,
-   "ECC-521",
-   /* prime */
-   "V///////////////////////////////////////////////////////////"
-   "///////////////////////////",
-
-   /* B */
-   "56LFhbXZXoQ7vAQ8Q2sXK3kejfoMvcp5VEuj8cHZl49uLOPEL7iVfDx5bB0l"
-   "JknlmSrSz+8FImqyUz57zHhK3y0",
-
-   /* Order */
-   "V//////////////////////////////////////////+b66XuE/BvPhVym1I"
-   "FS9fT0xjScuYPn7hhjljnwHE6G9",
-
-   /* Gx and Gy */
-   "CQ5ZWQt10JfpPu+osOZbRH2d6I1EGK/jI7uAAzWQqqzkg5BNdVlvrae/Xt19"
-   "wB/gDupIBF1XMf2c/b+VZ72vRrc",
-
-   "HWvAMfucZl015oANxGiVHlPcFL4ILURH6WNhxqN9pvcB9VkSfbUz2P0nL2v0"
-   "J+j1s4rF726edB2G8Y+b7QVqMPG",
-},
-#endif
-{
-   0,
-   NULL, NULL, NULL, NULL, NULL, NULL
-}
-};
-
-#if 0
-
-/* you plug in a prime and B value and it finds a pseudo-random base point */
-void ecc_find_base(void)
-{
-   static char *prime = "26959946667150639794667015087019630673637144422540572481103610249951";
-   static char *order = "26959946667150639794667015087019637467111563745054605861463538557247";
-   static char *b     = "9538957348957353489587";
-   mp_int pp, p, r, B, tmp1, tmp2, tx, ty, x, y;
-   char buf[4096];
-   int i;
-
-   mp_init_multi(&tx, &ty, &x, &y, &p, &pp, &r, &B, &tmp1, &tmp2, NULL);
-   mp_read_radix(&p, prime, 10);
-   mp_read_radix(&r, order, 10);
-   mp_read_radix(&B, b, 10);
-
-   /* get (p+1)/4 */
-   mp_add_d(&p, 1, &pp);
-   mp_div_2(&pp, &pp);
-   mp_div_2(&pp, &pp);
-
-   buf[0] = 0;
-   do {
-      printf("."); fflush(stdout);
-      /* make a random value of x */
-      for (i = 0; i < 16; i++) buf[i+1] = rand() & 255;
-      mp_read_raw(&x, buf, 17);
-      mp_copy(&x, &tx);
-
-      /* now compute x^3 - 3x + b */
-      mp_expt_d(&x, 3, &tmp1);
-      mp_mul_d(&x, 3, &tmp2);
-      mp_sub(&tmp1, &tmp2, &tmp1);
-      mp_add(&tmp1, &B, &tmp1);
-      mp_mod(&tmp1, &p, &tmp1);
-
-      /* now compute sqrt via x^((p+1)/4) */
-      mp_exptmod(&tmp1, &pp, &p, &tmp2);
-      mp_copy(&tmp2, &ty);
-
-      /* now square it */
-      mp_sqrmod(&tmp2, &p, &tmp2);
-
-      /* tmp2 should equal tmp1 */
-   } while (mp_cmp(&tmp1, &tmp2));
-
-   /* now output values in way that libtomcrypt wants */
-   mp_todecimal(&p, buf);
-   printf("\n\np==%s\n", buf);
-   mp_tohex(&B, buf);
-   printf("b==%s\n", buf);
-   mp_todecimal(&r, buf);
-   printf("r==%s\n", buf);
-   mp_tohex(&tx, buf);
-   printf("Gx==%s\n", buf);
-   mp_tohex(&ty, buf);
-   printf("Gy==%s\n", buf);
-
-   mp_clear_multi(&tx, &ty, &x, &y, &p, &pp, &r, &B, &tmp1, &tmp2, NULL);
-}
- 
-#endif
-
-
-
-
-static int is_valid_idx(int n)
-{
-   int x;
-
-   for (x = 0; sets[x].size != 0; x++);
-   if ((n < 0) || (n >= x)) {
-      return 0;
-   }
-   return 1;
-}
-
-static ecc_point *new_point(void)
-{
-   ecc_point *p;
-   p = XMALLOC(sizeof(ecc_point));
-   if (p == NULL) {
-      return NULL;
-   }
-   if (mp_init_multi(&p->x, &p->y, NULL) != MP_OKAY) {
-      XFREE(p);
-      return NULL;
-   }
-   return p;
-}
-
-static void del_point(ecc_point *p)
-{
-   /* prevents free'ing null arguments */
-   if (p != NULL) {
-      mp_clear_multi(&p->x, &p->y, NULL);
-      XFREE(p);
-   }
-}
-
-/* double a point R = 2P, R can be P*/
-static int dbl_point(ecc_point *P, ecc_point *R, mp_int *modulus, mp_int *mu)
-{
-   mp_int s, tmp, tmpx;
-   int err;
-
-   if ((err = mp_init_multi(&s, &tmp, &tmpx, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   /* s = (3Xp^2 + a) / (2Yp) */
-   if ((err = mp_mul_2(&P->y, &tmp)) != MP_OKAY)                   { goto error; } /* tmp = 2*y */
-   if ((err = mp_invmod(&tmp, modulus, &tmp)) != MP_OKAY)          { goto error; } /* tmp = 1/tmp mod modulus */
-   if ((err = mp_sqr(&P->x, &s)) != MP_OKAY)                       { goto error; } /* s = x^2  */
-   if ((err = mp_reduce(&s, modulus, mu)) != MP_OKAY)              { goto error; }
-   if ((err = mp_mul_d(&s,(mp_digit)3, &s)) != MP_OKAY)            { goto error; } /* s = 3*(x^2) */
-   if ((err = mp_sub_d(&s,(mp_digit)3, &s)) != MP_OKAY)            { goto error; } /* s = 3*(x^2) - 3 */
-   if (mp_cmp_d(&s, 0) == MP_LT) {                                         /* if s < 0 add modulus */
-      if ((err = mp_add(&s, modulus, &s)) != MP_OKAY)              { goto error; }
-   }
-   if ((err = mp_mul(&s, &tmp, &s)) != MP_OKAY)                    { goto error; } /* s = tmp * s mod modulus */
-   if ((err = mp_reduce(&s, modulus, mu)) != MP_OKAY)              { goto error; }
-
-   /* Xr = s^2 - 2Xp */
-   if ((err = mp_sqr(&s,  &tmpx)) != MP_OKAY)                      { goto error; } /* tmpx = s^2  */
-   if ((err = mp_reduce(&tmpx, modulus, mu)) != MP_OKAY)           { goto error; } /* tmpx = tmpx mod modulus */
-   if ((err = mp_sub(&tmpx, &P->x, &tmpx)) != MP_OKAY)             { goto error; } /* tmpx = tmpx - x */
-   if ((err = mp_submod(&tmpx, &P->x, modulus, &tmpx)) != MP_OKAY) { goto error; } /* tmpx = tmpx - x mod modulus */
-
-   /* Yr = -Yp + s(Xp - Xr)  */
-   if ((err = mp_sub(&P->x, &tmpx, &tmp)) != MP_OKAY)              { goto error; } /* tmp = x - tmpx */
-   if ((err = mp_mul(&tmp, &s, &tmp)) != MP_OKAY)                  { goto error; } /* tmp = tmp * s */
-   if ((err = mp_submod(&tmp, &P->y, modulus, &R->y)) != MP_OKAY)  { goto error; } /* y = tmp - y mod modulus */
-   if ((err = mp_copy(&tmpx, &R->x)) != MP_OKAY)                   { goto error; } /* x = tmpx */
-
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   mp_clear_multi(&tmpx, &tmp, &s, NULL);
-   return err;
-}
-
-/* add two different points over Z/pZ, R = P + Q, note R can equal either P or Q */
-static int add_point(ecc_point *P, ecc_point *Q, ecc_point *R, mp_int *modulus, mp_int *mu)
-{
-   mp_int s, tmp, tmpx;
-   int err;
-
-   if ((err = mp_init(&tmp)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   /* is P==Q or P==-Q? */
-   if (((err = mp_neg(&Q->y, &tmp)) != MP_OKAY) || ((err = mp_mod(&tmp, modulus, &tmp)) != MP_OKAY)) {
-      mp_clear(&tmp);
-      return mpi_to_ltc_error(err);
-   }
-
-   if (mp_cmp(&P->x, &Q->x) == MP_EQ)
-      if (mp_cmp(&P->y, &Q->y) == MP_EQ || mp_cmp(&P->y, &tmp) == MP_EQ) {
-         mp_clear(&tmp);
-         return dbl_point(P, R, modulus, mu);
-      }
-
-   if ((err = mp_init_multi(&tmpx, &s, NULL)) != MP_OKAY) {
-      mp_clear(&tmp);
-      return mpi_to_ltc_error(err);
-   }
-
-   /* get s = (Yp - Yq)/(Xp-Xq) mod p */
-   if ((err = mp_sub(&P->x, &Q->x, &tmp)) != MP_OKAY)                 { goto error; } /* tmp = Px - Qx mod modulus */
-   if (mp_cmp_d(&tmp, 0) == MP_LT) {                                          /* if tmp<0 add modulus */
-      if ((err = mp_add(&tmp, modulus, &tmp)) != MP_OKAY)             { goto error; }
-   }
-   if ((err = mp_invmod(&tmp, modulus, &tmp)) != MP_OKAY)             { goto error; } /* tmp = 1/tmp mod modulus */
-   if ((err = mp_sub(&P->y, &Q->y, &s)) != MP_OKAY)                   { goto error; } /* s = Py - Qy mod modulus */
-   if (mp_cmp_d(&s, 0) == MP_LT) {                                            /* if s<0 add modulus */
-      if ((err = mp_add(&s, modulus, &s)) != MP_OKAY)                 { goto error; }
-   }
-   if ((err = mp_mul(&s, &tmp, &s)) != MP_OKAY)                       { goto error; } /* s = s * tmp mod modulus */
-   if ((err = mp_reduce(&s, modulus, mu)) != MP_OKAY)                 { goto error; }
-
-   /* Xr = s^2 - Xp - Xq */
-   if ((err = mp_sqr(&s, &tmp)) != MP_OKAY)                           { goto error; } /* tmp = s^2 mod modulus */
-   if ((err = mp_reduce(&tmp, modulus, mu)) != MP_OKAY)               { goto error; }
-   if ((err = mp_sub(&tmp, &P->x, &tmp)) != MP_OKAY)                  { goto error; } /* tmp = tmp - Px */
-   if ((err = mp_sub(&tmp, &Q->x, &tmpx)) != MP_OKAY)                 { goto error; } /* tmpx = tmp - Qx */
-
-   /* Yr = -Yp + s(Xp - Xr) */
-   if ((err = mp_sub(&P->x, &tmpx, &tmp)) != MP_OKAY)                 { goto error; } /* tmp = Px - tmpx */
-   if ((err = mp_mul(&tmp, &s, &tmp)) != MP_OKAY)                     { goto error; } /* tmp = tmp * s */
-   if ((err = mp_submod(&tmp, &P->y, modulus, &R->y)) != MP_OKAY)     { goto error; } /* Ry = tmp - Py mod modulus */
-   if ((err = mp_mod(&tmpx, modulus, &R->x)) != MP_OKAY)              { goto error; } /* Rx = tmpx mod modulus */
-
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   mp_clear_multi(&s, &tmpx, &tmp, NULL);
-   return err;
-}
-
-/* size of sliding window, don't change this! */
-#define WINSIZE 4
-
-/* perform R = kG where k == integer and G == ecc_point */
-static int ecc_mulmod(mp_int *k, ecc_point *G, ecc_point *R, mp_int *modulus)
-{
-   ecc_point *tG, *M[8];
-   int i, j, err;
-   mp_int mu;
-   mp_digit buf;
-   int     first, bitbuf, bitcpy, bitcnt, mode, digidx;
-
-  /* init barrett reduction */
-  if ((err = mp_init(&mu)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-  }
-  if ((err = mp_reduce_setup(&mu, modulus)) != MP_OKAY) {
-      mp_clear(&mu);
-      return mpi_to_ltc_error(err);
-  }
-
-  /* alloc ram for window temps */
-  for (i = 0; i < 8; i++) {
-      M[i] = new_point();
-      if (M[i] == NULL) {
-         for (j = 0; j < i; j++) {
-             del_point(M[j]);
-         }
-         mp_clear(&mu);
-         return CRYPT_MEM;
-      }
-  }
-
-   /* make a copy of G incase R==G */
-   tG = new_point();
-   if (tG == NULL)                                                            { err = CRYPT_MEM; goto done; }
-
-   /* tG = G */
-   if ((err = mp_copy(&G->x, &tG->x)) != MP_OKAY)                             { goto error; }
-   if ((err = mp_copy(&G->y, &tG->y)) != MP_OKAY)                             { goto error; }
-   
-   /* calc the M tab, which holds kG for k==8..15 */
-   /* M[0] == 8G */
-   if ((err = dbl_point(G, M[0], modulus, &mu)) != CRYPT_OK)                  { goto done; }
-   if ((err = dbl_point(M[0], M[0], modulus, &mu)) != CRYPT_OK)               { goto done; }
-   if ((err = dbl_point(M[0], M[0], modulus, &mu)) != CRYPT_OK)               { goto done; }
-
-   /* now find (8+k)G for k=1..7 */
-   for (j = 9; j < 16; j++) {
-       if ((err = add_point(M[j-9], G, M[j-8], modulus, &mu)) != CRYPT_OK)    { goto done; }
-   }
-
-   /* setup sliding window */
-   mode   = 0;
-   bitcnt = 1;
-   buf    = 0;
-   digidx = k->used - 1;
-   bitcpy = bitbuf = 0;
-   first  = 1;
-
-   /* perform ops */
-   for (;;) {
-     /* grab next digit as required */
-     if (--bitcnt == 0) {
-       if (digidx == -1) {
-          break;
-       }
-       buf = k->dp[digidx--];
-       bitcnt = (int) DIGIT_BIT;
-     }
-
-     /* grab the next msb from the multiplicand */
-     i = (buf >> (DIGIT_BIT - 1)) & 1;
-     buf <<= 1;
-
-     /* skip leading zero bits */
-     if (mode == 0 && i == 0) {
-        continue;
-     }
-
-     /* if the bit is zero and mode == 1 then we double */
-     if (mode == 1 && i == 0) {
-        if ((err = dbl_point(R, R, modulus, &mu)) != CRYPT_OK)                { goto done; }
-        continue;
-     }
-
-     /* else we add it to the window */
-     bitbuf |= (i << (WINSIZE - ++bitcpy));
-     mode = 2;
-
-     if (bitcpy == WINSIZE) {
-       /* if this is the first window we do a simple copy */
-       if (first == 1) {
-          /* R = kG [k = first window] */
-          if ((err = mp_copy(&M[bitbuf-8]->x, &R->x)) != MP_OKAY)             { goto error; }
-          if ((err = mp_copy(&M[bitbuf-8]->y, &R->y)) != MP_OKAY)             { goto error; }
-          first = 0;
-       } else {
-         /* normal window */
-         /* ok window is filled so double as required and add  */
-         /* double first */
-         for (j = 0; j < WINSIZE; j++) {
-           if ((err = dbl_point(R, R, modulus, &mu)) != CRYPT_OK)             { goto done; }
-         }
-
-         /* then add, bitbuf will be 8..15 [8..2^WINSIZE] guaranteed */
-         if ((err = add_point(R, M[bitbuf-8], R, modulus, &mu)) != CRYPT_OK)  { goto done; }
-       }
-       /* empty window and reset */
-       bitcpy = bitbuf = 0;
-       mode = 1;
-    }
-  }
-
-   /* if bits remain then double/add */
-   if (mode == 2 && bitcpy > 0) {
-     /* double then add */
-     for (j = 0; j < bitcpy; j++) {
-       /* only double if we have had at least one add first */
-       if (first == 0) {
-          if ((err = dbl_point(R, R, modulus, &mu)) != CRYPT_OK)               { goto done; }
-       }
-
-       bitbuf <<= 1;
-       if ((bitbuf & (1 << WINSIZE)) != 0) {
-         if (first == 1){
-            /* first add, so copy */
-            if ((err = mp_copy(&tG->x, &R->x)) != MP_OKAY)                     { goto error; }
-            if ((err = mp_copy(&tG->y, &R->y)) != MP_OKAY)                     { goto error; }
-            first = 0;
-         } else {
-            /* then add */
-            if ((err = add_point(R, tG, R, modulus, &mu)) != CRYPT_OK)         { goto done; }
-         }
-       }
-     }
-   }
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   del_point(tG);
-   for (i = 0; i < 8; i++) {
-       del_point(M[i]);
-   }
-   mp_clear(&mu);
-   return err;
-}
-
-#undef WINSIZE
-
-int ecc_test(void)
-{
-   mp_int     modulus, order;
-   ecc_point  *G, *GG;
-   int i, err, primality;
-
-   if ((err = mp_init_multi(&modulus, &order, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   G   = new_point();
-   GG  = new_point();
-   if (G == NULL || GG == NULL) {
-      mp_clear_multi(&modulus, &order, NULL);
-      del_point(G);
-      del_point(GG);
-      return CRYPT_MEM;
-   }
-
-   for (i = 0; sets[i].size; i++) {
-       #if 0
-          printf("Testing %d\n", sets[i].size);
-       #endif
-       if ((err = mp_read_radix(&modulus, (char *)sets[i].prime, 64)) != MP_OKAY)   { goto error; }
-       if ((err = mp_read_radix(&order, (char *)sets[i].order, 64)) != MP_OKAY)     { goto error; }
-
-       /* is prime actually prime? */
-       if ((err = is_prime(&modulus, &primality)) != CRYPT_OK)                      { goto done; }
-       if (primality == 0) {
-          err = CRYPT_FAIL_TESTVECTOR;
-          goto done;
-       }
-
-       /* is order prime ? */
-       if ((err = is_prime(&order, &primality)) != CRYPT_OK)                        { goto done; }
-       if (primality == 0) {
-          err = CRYPT_FAIL_TESTVECTOR;
-          goto done;
-       }
-
-       if ((err = mp_read_radix(&G->x, (char *)sets[i].Gx, 64)) != MP_OKAY)         { goto error; }
-       if ((err = mp_read_radix(&G->y, (char *)sets[i].Gy, 64)) != MP_OKAY)         { goto error; }
-
-       /* then we should have G == (order + 1)G */
-       if ((err = mp_add_d(&order, 1, &order)) != MP_OKAY)                          { goto error; }
-       if ((err = ecc_mulmod(&order, G, GG, &modulus)) != CRYPT_OK)                 { goto done; }
-       if (mp_cmp(&G->x, &GG->x) != 0 || mp_cmp(&G->y, &GG->y) != 0) {
-          err = CRYPT_FAIL_TESTVECTOR;
-          goto done;
-       }
-   }
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   del_point(GG);
-   del_point(G);
-   mp_clear_multi(&order, &modulus, NULL);
-   return err;
-}
-
-void ecc_sizes(int *low, int *high)
-{
- int i;
- _ARGCHK(low  != NULL);
- _ARGCHK(high != NULL);
-
- *low = INT_MAX;
- *high = 0;
- for (i = 0; sets[i].size != 0; i++) {
-     if (sets[i].size < *low)  {
-        *low  = sets[i].size;
-     }
-     if (sets[i].size > *high) {
-        *high = sets[i].size;
-     }
- }
-}
-
-int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key)
-{
-   int x, err;
-   ecc_point *base;
-   mp_int prime;
-   unsigned char buf[128];
-
-   _ARGCHK(key != NULL);
-
-   /* good prng? */
-   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* find key size */
-   for (x = 0; (keysize > sets[x].size) && (sets[x].size != 0); x++);
-   keysize = sets[x].size;
-
-   if (sets[x].size == 0) {
-      return CRYPT_INVALID_KEYSIZE;
-   }
-   key->idx = x;
-
-   /* make up random string */
-   if (prng_descriptor[wprng].read(buf, (unsigned long)keysize, prng) != (unsigned long)keysize) {
-      return CRYPT_ERROR_READPRNG;
-   }
-
-   /* setup the key variables */
-   if ((err = mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->k, &prime, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-   base = new_point();
-   if (base == NULL) {
-      mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->k, &prime, NULL);
-      return CRYPT_MEM;
-   }
-
-   /* read in the specs for this key */
-   if ((err = mp_read_radix(&prime, (char *)sets[key->idx].prime, 64)) != MP_OKAY)      { goto error; }
-   if ((err = mp_read_radix(&base->x, (char *)sets[key->idx].Gx, 64)) != MP_OKAY)       { goto error; }
-   if ((err = mp_read_radix(&base->y, (char *)sets[key->idx].Gy, 64)) != MP_OKAY)       { goto error; }
-   if ((err = mp_read_unsigned_bin(&key->k, (unsigned char *)buf, keysize)) != MP_OKAY) { goto error; }
-
-   /* make the public key */
-   if ((err = ecc_mulmod(&key->k, base, &key->pubkey, &prime)) != CRYPT_OK)             { goto done; }
-   key->type = PK_PRIVATE;
-
-   /* shrink key */
-   if ((err = mp_shrink(&key->k)) != MP_OKAY)                                           { goto error; }
-   if ((err = mp_shrink(&key->pubkey.x)) != MP_OKAY)                                    { goto error; }
-   if ((err = mp_shrink(&key->pubkey.y)) != MP_OKAY)                                    { goto error; }
-
-   /* free up ram */
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   del_point(base);
-   mp_clear(&prime);
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return err;
-}
-
-void ecc_free(ecc_key *key)
-{
-   _ARGCHK(key != NULL);
-   mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->k, NULL);
-}
-
-static int compress_y_point(ecc_point *pt, int idx, int *result)
-{
-   mp_int tmp, tmp2, p;
-   int err;
-
-   _ARGCHK(pt     != NULL);
-   _ARGCHK(result != NULL);
-
-   if ((err = mp_init_multi(&tmp, &tmp2, &p, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   /* get x^3 - 3x + b */
-   if ((err = mp_read_radix(&p, (char *)sets[idx].B, 64)) != MP_OKAY) { goto error; } /* p = B */
-   if ((err = mp_expt_d(&pt->x, 3, &tmp)) != MP_OKAY)                 { goto error; } /* tmp = pX^3  */
-   if ((err = mp_mul_d(&pt->x, 3, &tmp2)) != MP_OKAY)                 { goto error; } /* tmp2 = 3*pX^3 */
-   if ((err = mp_sub(&tmp, &tmp2, &tmp)) != MP_OKAY)                  { goto error; } /* tmp = tmp - tmp2 */
-   if ((err = mp_add(&tmp, &p, &tmp)) != MP_OKAY)                     { goto error; } /* tmp = tmp + p */
-   if ((err = mp_read_radix(&p, (char *)sets[idx].prime, 64)) != MP_OKAY)  { goto error; } /* p = prime */
-   if ((err = mp_mod(&tmp, &p, &tmp)) != MP_OKAY)                     { goto error; } /* tmp = tmp mod p */
-
-   /* now find square root */
-   if ((err = mp_add_d(&p, 1, &tmp2)) != MP_OKAY)                     { goto error; } /* tmp2 = p + 1 */
-   if ((err = mp_div_2d(&tmp2, 2, &tmp2, NULL)) != MP_OKAY)           { goto error; } /* tmp2 = (p+1)/4 */
-   if ((err = mp_exptmod(&tmp, &tmp2, &p, &tmp)) != MP_OKAY)          { goto error; } /* tmp  = (x^3 - 3x + b)^((p+1)/4) mod p */
-
-   /* if tmp equals the y point give a 0, otherwise 1 */
-   if (mp_cmp(&tmp, &pt->y) == 0) {
-      *result = 0;
-   } else {
-      *result = 1;
-   }
-
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   mp_clear_multi(&p, &tmp, &tmp2, NULL);
-   return err;
-}
-
-static int expand_y_point(ecc_point *pt, int idx, int result)
-{
-   mp_int tmp, tmp2, p;
-   int err;
-
-   _ARGCHK(pt != NULL);
-
-   if ((err = mp_init_multi(&tmp, &tmp2, &p, NULL)) != MP_OKAY) {
-      return CRYPT_MEM;
-   }
-
-   /* get x^3 - 3x + b */
-   if ((err = mp_read_radix(&p, (char *)sets[idx].B, 64)) != MP_OKAY) { goto error; } /* p = B */
-   if ((err = mp_expt_d(&pt->x, 3, &tmp)) != MP_OKAY)                 { goto error; } /* tmp = pX^3 */
-   if ((err = mp_mul_d(&pt->x, 3, &tmp2)) != MP_OKAY)                 { goto error; } /* tmp2 = 3*pX^3 */
-   if ((err = mp_sub(&tmp, &tmp2, &tmp)) != MP_OKAY)                  { goto error; } /* tmp = tmp - tmp2 */
-   if ((err = mp_add(&tmp, &p, &tmp)) != MP_OKAY)                     { goto error; } /* tmp = tmp + p */
-   if ((err = mp_read_radix(&p, (char *)sets[idx].prime, 64)) != MP_OKAY)  { goto error; } /* p = prime */
-   if ((err = mp_mod(&tmp, &p, &tmp)) != MP_OKAY)                     { goto error; } /* tmp = tmp mod p */
-
-   /* now find square root */
-   if ((err = mp_add_d(&p, 1, &tmp2)) != MP_OKAY)                     { goto error; } /* tmp2 = p + 1 */
-   if ((err = mp_div_2d(&tmp2, 2, &tmp2, NULL)) != MP_OKAY)           { goto error; } /* tmp2 = (p+1)/4 */
-   if ((err = mp_exptmod(&tmp, &tmp2, &p, &tmp)) != MP_OKAY)          { goto error; } /* tmp  = (x^3 - 3x + b)^((p+1)/4) mod p */
-
-   /* if result==0, then y==tmp, otherwise y==p-tmp */
-   if (result == 0) {
-      if ((err = mp_copy(&tmp, &pt->y) != MP_OKAY))                   { goto error; }
-   } else {
-      if ((err = mp_sub(&p, &tmp, &pt->y) != MP_OKAY))                { goto error; }
-   }
-
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   mp_clear_multi(&p, &tmp, &tmp2, NULL);
-   return err;
-}
-
-int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key)
-{
-   unsigned long y, z;
-   int cp, err;
-
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-   
-   /* can we store the static header?  */
-   if (*outlen < (PACKET_SIZE + 3)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* type valid? */
-   if (key->type != PK_PRIVATE && type == PK_PRIVATE) {
-      return CRYPT_PK_TYPE_MISMATCH;
-   }
-
-   /* output type and magic byte */
-   y = PACKET_SIZE;
-   out[y++] = (unsigned char)type;
-   out[y++] = (unsigned char)sets[key->idx].size;
-
-   /* output x coordinate */
-   OUTPUT_BIGNUM(&(key->pubkey.x), out, y, z);
-
-   /* compress y and output it  */
-   if ((err = compress_y_point(&key->pubkey, key->idx, &cp)) != CRYPT_OK) {
-      return err;
-   }
-   out[y++] = (unsigned char)cp;
-
-   if (type == PK_PRIVATE) {
-      OUTPUT_BIGNUM(&key->k, out, y, z);
-   }
-
-   /* store header */
-   packet_store_header(out, PACKET_SECT_ECC, PACKET_SUB_KEY);
-   *outlen = y;
-
-   return CRYPT_OK;
-}
-
-int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
-{
-   unsigned long x, y, s;
-   int err;
-
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
-
-   /* check length */
-   if ((3+PACKET_SIZE) > inlen) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* check type */
-   if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_ECC, PACKET_SUB_KEY)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* init key */
-   if (mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->k, NULL) != MP_OKAY) {
-      return CRYPT_MEM;
-   }
-
-   y = PACKET_SIZE;
-   key->type = (int)in[y++];
-   s = (unsigned long)in[y++];
-
-   for (x = 0; (s > (unsigned long)sets[x].size) && (sets[x].size != 0); x++);
-   if (sets[x].size == 0) {
-      err = CRYPT_INVALID_KEYSIZE;
-      goto error;
-   }
-   key->idx = (int)x;
-
-   /* type check both values */
-   if ((key->type != PK_PUBLIC) && (key->type != PK_PRIVATE))  {
-      err = CRYPT_INVALID_PACKET;
-      goto error;
-   }
-
-   /* is the key idx valid? */
-   if (is_valid_idx(key->idx) != 1) {
-      err = CRYPT_INVALID_PACKET;
-      goto error;
-   }
-
-   /* load x coordinate */
-   INPUT_BIGNUM(&key->pubkey.x, in, x, y, inlen);
-
-   /* load y */
-   x = (unsigned long)in[y++];
-   if ((err = expand_y_point(&key->pubkey, key->idx, (int)x)) != CRYPT_OK) {
-       goto error;
-   }
-
-   if (key->type == PK_PRIVATE) {
-      /* load private key */
-      INPUT_BIGNUM(&key->k, in, x, y, inlen);
-   }
-
-   /* eliminate private key if public */
-   if (key->type == PK_PUBLIC) {
-      mp_clear(&key->k);
-   }
-
-   return CRYPT_OK;
-error:
-   mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->k, NULL);
-   return err;
-}
-
-int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
-                      unsigned char *out, unsigned long *outlen)
-{
-   unsigned long x, y;
-   ecc_point *result;
-   mp_int prime;
-   int err;
-
-   _ARGCHK(private_key != NULL);
-   _ARGCHK(public_key  != NULL);
-   _ARGCHK(out         != NULL);
-   _ARGCHK(outlen      != NULL);
-
-   /* type valid? */
-   if (private_key->type != PK_PRIVATE) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   if (private_key->idx != public_key->idx) {
-      return CRYPT_PK_TYPE_MISMATCH;
-   }
-
-   /* make new point */
-   result = new_point();
-   if (result == NULL) {
-      return CRYPT_MEM;
-   }
-
-   if ((err = mp_init(&prime)) != MP_OKAY) {
-      del_point(result);
-      return mpi_to_ltc_error(err);
-   }
-
-   if ((err = mp_read_radix(&prime, (char *)sets[private_key->idx].prime, 64)) != MP_OKAY)   { goto error; }
-   if ((err = ecc_mulmod(&private_key->k, &public_key->pubkey, result, &prime)) != CRYPT_OK) { goto done1; }
-
-   x = (unsigned long)mp_unsigned_bin_size(&result->x);
-   y = (unsigned long)mp_unsigned_bin_size(&result->y);
-
-   if (*outlen < (x+y)) {
-      err = CRYPT_BUFFER_OVERFLOW;
-      goto done1;
-   }
-   *outlen = x+y;
-   if ((err = mp_to_unsigned_bin(&result->x, out))   != MP_OKAY)          { goto error; }
-   if ((err = mp_to_unsigned_bin(&result->y, out+x)) != MP_OKAY)          { goto error; }
-
-   err = CRYPT_OK;
-   goto done1;
-error:
-   err = mpi_to_ltc_error(err);
-done1:
-   mp_clear(&prime);
-   del_point(result);
-   return err;
-}
-
-int ecc_get_size(ecc_key *key)
-{
-   _ARGCHK(key != NULL);
-   if (is_valid_idx(key->idx))
-      return sets[key->idx].size;
-   else
-      return INT_MAX; /* large value known to cause it to fail when passed to ecc_make_key() */
-}
-
-#include "ecc_sys.c"
-
-#endif
-
-
diff --git a/ecc_sys.c b/ecc_sys.c
deleted file mode 100644
index 33e1311..0000000
--- a/ecc_sys.c
+++ /dev/null
@@ -1,432 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-int ecc_encrypt_key(const unsigned char *inkey, unsigned long keylen,
-                          unsigned char *out,  unsigned long *len, 
-                          prng_state *prng, int wprng, int hash, 
-                          ecc_key *key)
-{
-    unsigned char pub_expt[256], ecc_shared[256], skey[MAXBLOCKSIZE];
-    ecc_key pubkey;
-    unsigned long x, y, z, hashsize, pubkeysize;
-    int err;
-
-    _ARGCHK(inkey != NULL);
-    _ARGCHK(out   != NULL);
-    _ARGCHK(len   != NULL);
-    _ARGCHK(key   != NULL);
-
-    /* check that wprng/cipher/hash are not invalid */
-    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-       return err;
-    }
-
-    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
-       return err;
-    }
-
-    if (keylen > hash_descriptor[hash].hashsize) {
-       return CRYPT_INVALID_HASH;
-    }
-
-    /* make a random key and export the public copy */
-    if ((err = ecc_make_key(prng, wprng, ecc_get_size(key), &pubkey)) != CRYPT_OK) {
-       return err;
-    }
-
-    pubkeysize = (unsigned long)sizeof(pub_expt);
-    if ((err = ecc_export(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
-       ecc_free(&pubkey);
-       return err;
-    }
-    
-    /* now check if the out buffer is big enough */
-    if (*len < (9 + PACKET_SIZE + pubkeysize + hash_descriptor[hash].hashsize)) {
-       ecc_free(&pubkey);
-       return CRYPT_BUFFER_OVERFLOW;
-    }
-
-    /* make random key */
-    hashsize  = hash_descriptor[hash].hashsize;
-    x = (unsigned long)sizeof(ecc_shared);
-    if ((err = ecc_shared_secret(&pubkey, key, ecc_shared, &x)) != CRYPT_OK) {
-       ecc_free(&pubkey);
-       return err;
-    }
-    ecc_free(&pubkey);
-    z = (unsigned long)sizeof(skey);
-    if ((err = hash_memory(hash, ecc_shared, x, skey, &z)) != CRYPT_OK) {
-       return err;
-    }
-    
-    /* store header */
-    packet_store_header(out, PACKET_SECT_ECC, PACKET_SUB_ENC_KEY);    
-
-    /* output header */
-    y = PACKET_SIZE;
- 
-    /* size of hash name and the name itself */
-    out[y++] = hash_descriptor[hash].ID;
-
-    /* length of ECC pubkey and the key itself */
-    STORE32L(pubkeysize, out+y);
-    y += 4;
-
-    for (x = 0; x < pubkeysize; x++, y++) {
-        out[y] = pub_expt[x];
-    }
-
-    STORE32L(keylen, out+y);
-    y += 4;
-
-    /* Encrypt/Store the encrypted key */
-    for (x = 0; x < keylen; x++, y++) {
-      out[y] = skey[x] ^ inkey[x];
-    }
-    *len = y;
-
-#ifdef CLEAN_STACK
-    /* clean up */
-    zeromem(pub_expt, sizeof(pub_expt));
-    zeromem(ecc_shared, sizeof(ecc_shared));
-    zeromem(skey, sizeof(skey));
-#endif
-    return CRYPT_OK;
-}
-
-int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
-                          ecc_key *key)
-{
-   unsigned char shared_secret[256], skey[MAXBLOCKSIZE];
-   unsigned long x, y, z, hashsize, keysize;
-   int hash, err;
-   ecc_key pubkey;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(outkey != NULL);
-   _ARGCHK(keylen != NULL);
-   _ARGCHK(key    != NULL);
-
-   /* right key type? */
-   if (key->type != PK_PRIVATE) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-   
-   /* correct length ? */
-   if (inlen < PACKET_SIZE+1+4+4) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      inlen -= PACKET_SIZE+1+4+4;
-   }
-
-   /* is header correct? */
-   if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_ECC, PACKET_SUB_ENC_KEY)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* now lets get the hash name */
-   y = PACKET_SIZE;
-   hash = find_hash_id(in[y++]);
-   if (hash == -1) {
-      return CRYPT_INVALID_HASH;
-   }
-
-   /* common values */
-   hashsize  = hash_descriptor[hash].hashsize;
-
-   /* get public key */
-   LOAD32L(x, in+y);
-   if (inlen < x) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      inlen -= x;
-   }
-   y += 4;
-   if ((err = ecc_import(in+y, x, &pubkey)) != CRYPT_OK) {
-      return err;
-   }
-   y += x;
-
-   /* make shared key */
-   x = (unsigned long)sizeof(shared_secret);
-   if ((err = ecc_shared_secret(key, &pubkey, shared_secret, &x)) != CRYPT_OK) {
-      ecc_free(&pubkey);
-      return err;
-   }
-   ecc_free(&pubkey);
-
-   z = (unsigned long)sizeof(skey);
-   if ((err = hash_memory(hash, shared_secret, x, skey, &z)) != CRYPT_OK) {
-      return err;
-   }
-
-   LOAD32L(keysize, in+y);
-   if (inlen < keysize) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      inlen -= keysize;
-   }
-   y += 4;
-
-   if (*keylen < keysize) {
-       err = CRYPT_BUFFER_OVERFLOW;
-       goto done;
-   }
-
-   /* Decrypt the key */
-   for (x = 0; x < keysize; x++, y++) {
-     outkey[x] = skey[x] ^ in[y];
-   }
-
-   *keylen = keysize;
-
-   err = CRYPT_OK;
-done:
-#ifdef CLEAN_STACK
-   zeromem(shared_secret, sizeof(shared_secret));
-   zeromem(skey, sizeof(skey));
-#endif
-   return err;
-}
-
-int ecc_sign_hash(const unsigned char *in,  unsigned long inlen, 
-                        unsigned char *out, unsigned long *outlen, 
-                        prng_state *prng, int wprng, ecc_key *key)
-{
-   ecc_key pubkey;
-   mp_int b, p;
-   unsigned char epubkey[256], er[256];
-   unsigned long x, y, pubkeysize, rsize;
-   int  err;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-
-   /* is this a private key? */
-   if (key->type != PK_PRIVATE) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-   
-   /* is the IDX valid ?  */
-   if (is_valid_idx(key->idx) != 1) {
-      return CRYPT_PK_INVALID_TYPE;
-   }
-   
-   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* make up a key and export the public copy */
-   if ((err = ecc_make_key(prng, wprng, ecc_get_size(key), &pubkey)) != CRYPT_OK) {
-      return err;
-   }
-
-   pubkeysize = (unsigned long)sizeof(epubkey);
-   if ((err = ecc_export(epubkey, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
-      ecc_free(&pubkey);
-      return err;
-   }
-
-   /* get the hash and load it as a bignum into 'b' */
-   /* init the bignums */
-   if ((err = mp_init_multi(&b, &p, NULL)) != MP_OKAY) { 
-      ecc_free(&pubkey);
-      return mpi_to_ltc_error(err);
-   }
-   if ((err = mp_read_radix(&p, (char *)sets[key->idx].order, 64)) != MP_OKAY)        { goto error; }
-   if ((err = mp_read_unsigned_bin(&b, (unsigned char *)in, (int)inlen)) != MP_OKAY)  { goto error; }
-
-   /* find b = (m - x)/k */
-   if ((err = mp_invmod(&pubkey.k, &p, &pubkey.k)) != MP_OKAY)            { goto error; } /* k = 1/k */
-   if ((err = mp_submod(&b, &key->k, &p, &b)) != MP_OKAY)                 { goto error; } /* b = m - x */
-   if ((err = mp_mulmod(&b, &pubkey.k, &p, &b)) != MP_OKAY)               { goto error; } /* b = (m - x)/k */
-
-   /* export it */
-   rsize = (unsigned long)mp_unsigned_bin_size(&b);
-   if (rsize > (unsigned long)sizeof(er)) { 
-      err = CRYPT_BUFFER_OVERFLOW;
-      goto error; 
-   }
-   if ((err = mp_to_unsigned_bin(&b, er)) != MP_OKAY)                     { goto error; }
-
-   /* now lets check the outlen before we write */
-   if (*outlen < (12 + rsize + pubkeysize)) {
-      err = CRYPT_BUFFER_OVERFLOW;
-      goto done;
-   }
-
-   /* lets output */
-   y = PACKET_SIZE;
-   
-   /* size of public key */
-   STORE32L(pubkeysize, out+y);
-   y += 4;
-
-   /* copy the public key */
-   for (x = 0; x < pubkeysize; x++, y++) {
-       out[y] = epubkey[x];
-   }
-
-   /* size of 'r' */
-   STORE32L(rsize, out+y);
-   y += 4;
-
-   /* copy r */
-   for (x = 0; x < rsize; x++, y++) {
-       out[y] = er[x];
-   }
-
-   /* store header */
-   packet_store_header(out, PACKET_SECT_ECC, PACKET_SUB_SIGNED);
-
-   /* clear memory */
-   *outlen = y;
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   mp_clear_multi(&b, &p, NULL);
-   ecc_free(&pubkey);
-#ifdef CLEAN_STACK
-   zeromem(er, sizeof(er));
-   zeromem(epubkey, sizeof(epubkey));
-#endif
-   return err;   
-}
-
-/* verify that mG = (bA + Y)
- *
- * The signatures work by making up a fresh key "a" with a public key "A".  Now we want to sign so the 
- * public key Y = xG can verify it.
- *
- * b = (m - x)/k, A is the public key embedded and Y is the users public key [who signed it]
- * A = kG therefore bA == ((m-x)/k)kG == (m-x)G
- *
- * Adding Y = xG to the bA gives us (m-x)G + xG == mG
- *
- * The user given only xG, kG and b cannot determine k or x which means they can't find the private key.
- * 
- */
-int ecc_verify_hash(const unsigned char *sig, unsigned long siglen,
-                    const unsigned char *hash, unsigned long inlen, 
-                    int *stat, ecc_key *key)
-{
-   ecc_point *mG;
-   ecc_key   pubkey;
-   mp_int b, p, m, mu;
-   unsigned long x, y;
-   int err;
-
-   _ARGCHK(sig  != NULL);
-   _ARGCHK(hash != NULL);
-   _ARGCHK(stat != NULL);
-   _ARGCHK(key  != NULL);
-
-   /* default to invalid signature */
-   *stat = 0;
-
-   if (siglen < PACKET_SIZE+4+4) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      siglen -= PACKET_SIZE+4+4;
-   }
-
-   /* is the message format correct? */
-   if ((err = packet_valid_header((unsigned char *)sig, PACKET_SECT_ECC, PACKET_SUB_SIGNED)) != CRYPT_OK) {
-      return err;
-   }     
-
-   /* get hash name */
-   y = PACKET_SIZE;
-
-   /* get size of public key */
-   LOAD32L(x, sig+y);
-   if (siglen < x) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      siglen -= x;
-   }
-   y += 4;
-
-   /* load the public key */
-   if ((err = ecc_import((unsigned char*)sig+y, x, &pubkey)) != CRYPT_OK) {
-      return err;
-   }
-   y += x;
-
-   /* load size of 'b' */
-   LOAD32L(x, sig+y);
-   if (siglen < x) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      siglen -= x;
-   }
-   y += 4;
-
-   /* init values */
-   if ((err = mp_init_multi(&b, &m, &p, &mu, NULL)) != MP_OKAY) { 
-      ecc_free(&pubkey);
-      return mpi_to_ltc_error(err);
-   }
-
-   mG = new_point();
-   if (mG == NULL) { 
-      mp_clear_multi(&b, &m, &p, &mu, NULL);
-      ecc_free(&pubkey);
-      return CRYPT_MEM;
-   } 
-
-   /* load b */
-   if ((err = mp_read_unsigned_bin(&b, (unsigned char *)sig+y, (int)x)) != MP_OKAY)        { goto error; }
-   y += x;
-
-   /* get m in binary a bignum */
-   if ((err = mp_read_unsigned_bin(&m, (unsigned char *)hash, (int)inlen)) != MP_OKAY)     { goto error; }
-   
-   /* load prime */
-   if ((err = mp_read_radix(&p, (char *)sets[key->idx].prime, 64)) != MP_OKAY)             { goto error; }
-   
-   /* calculate barrett stuff */
-   mp_set(&mu, 1); 
-   mp_lshd(&mu, 2 * USED(&p));
-   if ((err = mp_div(&mu, &p, &mu, NULL)) != MP_OKAY)                                      { goto error; }
-
-   /* get bA */
-   if ((err = ecc_mulmod(&b, &pubkey.pubkey, &pubkey.pubkey, &p)) != CRYPT_OK)                  { goto done; }
-   
-   /* get bA + Y */
-   if ((err = add_point(&pubkey.pubkey, &key->pubkey, &pubkey.pubkey, &p, &mu)) != CRYPT_OK)    { goto done; }
-
-   /* get mG */
-   if ((err = mp_read_radix(&mG->x, (char *)sets[key->idx].Gx, 64)) != MP_OKAY)                 { goto error; }
-   if ((err = mp_read_radix(&mG->y, (char *)sets[key->idx].Gy, 64)) != MP_OKAY)                 { goto error; }
-   if ((err = ecc_mulmod(&m, mG, mG, &p)) != CRYPT_OK)                                          { goto done; }
-
-   /* compare mG to bA + Y */
-   if (mp_cmp(&mG->x, &pubkey.pubkey.x) == MP_EQ && mp_cmp(&mG->y, &pubkey.pubkey.y) == MP_EQ) {
-      *stat = 1;
-   }
-
-   /* clear up and return */
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   del_point(mG);
-   ecc_free(&pubkey);
-   mp_clear_multi(&p, &m, &b, &mu, NULL);
-   return err;
-}
-
diff --git a/examples/ch1-01.c b/examples/ch1-01.c
deleted file mode 100644
index 010ccd7..0000000
--- a/examples/ch1-01.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* 
- * Name      : ch1-01.c
- * Purpose   : Demonstration of a basic libtomcrypt program
- * Author    : Tom St Denis
- *
- * History   : v0.79 Initial release
- */
- 
-/* ch1-01-1  */
-/* Include the default headers and libtomcrypt headers */
-#include <mycrypt.h>
-
-int main(void)
-{
-   return 0;
-}
-/* ch1-01-1  */
-
diff --git a/examples/ch1-02.c b/examples/ch1-02.c
deleted file mode 100644
index 9d41f21..0000000
--- a/examples/ch1-02.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 
- * Name      : ch1-02.c
- * Purpose   : Demonstration of error handling
- * Author    : Tom St Denis
- *
- * History   : v0.79 Initial release
- */
- 
-/* ch1-01-1 */
-#include <mycrypt.h>
-
-int main(void)
-{
-   int errno;
-   
-   if ((errno = some_func(...)) != CRYPT_OK) {
-      printf("Error: %s\n", error_to_string(errno));
-      return EXIT_FAILURE;
-   }
-   
-   return 0;
-}
-/*ch1-01-1 */
-
-
diff --git a/examples/ch1-03.c b/examples/ch1-03.c
deleted file mode 100644
index c749aa1..0000000
--- a/examples/ch1-03.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 
- * Name      : ch1-03.c
- * Purpose   : Demonstration of variable length outputs
- * Author    : Tom St Denis
- *
- * History   : v0.79 Initial release
- */
- 
- /* ch1-01-1 */
- #include <mycrypt.h>
- 
- int main(void)
- {
-    unsigned long length;
-    unsigned char buffer[512];
-    int errno;
-    
-    length = sizeof(buffer);
-    if ((errno = some_func(..., buffer, &length)) != CRYPT_OK) {
-       printf("Error: %s\n", error_to_string(errno));
-       return EXIT_FAILURE;
-    }
-    printf("Size of output is %lu bytes\n", length);
-    return 0;
-}
-/* ch1-01-1 */
-
-
-    
\ No newline at end of file
diff --git a/examples/ch2-01.c b/examples/ch2-01.c
deleted file mode 100644
index b565479..0000000
--- a/examples/ch2-01.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* 
- * Name      : ch2-01.c
- * Purpose   : Demonstration of reading the RNG
- * Author    : Tom St Denis
- *
- * History   : v0.81 Initial release
- */
- 
- /* ch2-02-2 */
- #include <mycrypt.h>
- 
- int main(void) 
- {
-    unsigned char buf[16];
-    unsigned long len;
-    int           ix;
-    
-    /* read the RNG */
-    len = rng_get_bytes(buf, sizeof(buf), NULL);
-    
-    /* verify return */
-    if (len != sizeof(buf)) {
-       printf("Error: Only read %lu bytes.\n", len);
-    } else {
-       printf("Read %lu bytes\n", len);
-       for (ix = 0; ix < sizeof(buf); ix++) {
-           printf("%02x ", buf[ix]);
-       }
-       printf("\n");
-    }
-    
-    return EXIT_SUCCESS;
-}
-/* ch2-02-2 */
-
diff --git a/genlist.sh b/genlist.sh
new file mode 100644
index 0000000..832e8e7
--- /dev/null
+++ b/genlist.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# aes_tab.o is a pseudo object as it's made from aes.o and MPI is optional
+export a=`echo -n "src/ciphers/aes/aes_enc.o *(MPIOBJECT) " ; find . -type f | sort | grep "[.]/src" | grep "[.]c" | grep -v "sha224" | grep -v "sha384" | grep -v "aes_tab" | grep -v "twofish_tab" | grep -v "whirltab" | grep -v "dh_sys" | grep -v "ecc_sys" | grep -v "mpi[.]c" | grep -v "sober128tab" | sed -e 'sE\./EE' | sed -e 's/\.c/\.o/' | xargs`
+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 $ 
diff --git a/gf.c b/gf.c
deleted file mode 100644
index 34abb15..0000000
--- a/gf.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* polynomial basis GF(2^w) routines */
-#include "mycrypt.h"
-
-#ifdef GF
-
-#define FORLOOP for (i = 0; i < LSIZE; i++) 
-
-/* c = a + b */
-void gf_add(gf_intp a, gf_intp b, gf_intp c)
-{
-   int i;
-   FORLOOP c[i] = a[i]^b[i];
-}
-
-/* b = a */
-void gf_copy(gf_intp a, gf_intp b)
-{
-   int i;
-   FORLOOP b[i] = a[i];
-}
-
-/* a = 0 */
-void gf_zero(gf_intp a)
-{
-   int i;
-   FORLOOP a[i] = 0;
-}
-
-/* is a zero? */
-int gf_iszero(gf_intp a)
-{
-   int i;
-   FORLOOP if (a[i]) {
-      return 0;
-   }
-   return 1;
-}
-
-/* is a one? */
-int gf_isone(gf_intp a)
-{ 
-   int i;
-   for (i = 1; i < LSIZE; i++) {
-       if (a[i]) {
-          return 0;
-       }
-   }
-   return a[0] == 1;
-}
-
-/* b = a << 1*/
-void gf_shl(gf_intp a, gf_intp b)
-{
-   int i;
-   gf_int tmp;
-
-   gf_copy(a, tmp);
-   for (i = LSIZE-1; i > 0; i--) 
-       b[i] = ((tmp[i]<<1)|((tmp[i-1]&0xFFFFFFFFUL)>>31))&0xFFFFFFFFUL;
-   b[0] = (tmp[0] << 1)&0xFFFFFFFFUL;
-   gf_zero(tmp);
-}
-
-/* b = a >> 1 */
-void gf_shr(gf_intp a, gf_intp b)
-{
-   int i;
-   gf_int tmp;
-
-   gf_copy(a, tmp);
-   for (i = 0; i < LSIZE-1; i++)
-       b[i] = (((tmp[i]&0xFFFFFFFFUL)>>1)|(tmp[i+1]<<31))&0xFFFFFFFFUL;
-   b[LSIZE-1] = (tmp[LSIZE-1]&0xFFFFFFFFUL)>>1;
-   gf_zero(tmp);
-}
-
-/* returns -1 if its zero, otherwise degree of a */
-int gf_deg(gf_intp a)
-{
-   int i, ii;
-   unsigned long t;
-
-   ii = -1;
-   for (i = LSIZE-1; i >= 0; i--)
-       if (a[i]) {
-          for (t = a[i], ii = 0; t; t >>= 1, ++ii);
-          break;
-       }
-   if (i == -1) i = 0;
-   return (i<<5)+ii;
-}
-
-/* c = ab */
-void gf_mul(gf_intp a, gf_intp b, gf_intp c)
-{
-   gf_int ta, tb;
-   int i, n;
-
-   gf_copy(a, ta);
-   gf_copy(b, tb);
-   gf_zero(c);
-   n = gf_deg(ta)+1;
-   for (i = 0; i < n; i++) {
-       if (ta[i>>5]&(1<<(i&31)))
-          gf_add(c, tb, c);
-       gf_shl(tb, tb);
-   }
-   gf_zero(ta);
-   gf_zero(tb);
-}
-
-/* q = a/b, r = a%b */
-void gf_div(gf_intp a, gf_intp b, gf_intp q, gf_intp r)
-{
-   gf_int ta, tb, shifts[LSIZE*32];
-   int i, magb, mag;
-
-   mag  = gf_deg(a);
-   magb = gf_deg(b);
-
-   /* special cases */
-   if (magb > mag) {
-      gf_copy(a, r);
-      gf_zero(q);
-      return;
-   }
-   if (magb == -1) {
-      return;
-   }
-
-   /* copy locally */
-   gf_copy(a, ta);
-   gf_copy(b, tb);
-   gf_zero(q);
-
-   /* make shifted versions of "b" */
-   gf_copy(tb, shifts[0]);
-   for (i = 1; i <= (mag-magb); i++) 
-       gf_shl(shifts[i-1], shifts[i]);
-
-   while (mag >= magb) {
-       i = (mag - magb);
-       q[i>>5] |= (1<<(i&31));
-       gf_add(ta, shifts[i], ta);
-       mag = gf_deg(ta);
-   }
-   gf_copy(ta, r);
-   gf_zero(ta);
-   gf_zero(tb);
-   zeromem(shifts, sizeof(shifts));
-}
-
-/* b = a mod m */
-void gf_mod(gf_intp a, gf_intp m, gf_intp b)
-{
-   gf_int tmp;
-   gf_div(a,m,tmp,b);
-   gf_zero(tmp);
-}
-
-/* c = ab (mod m) */
-void gf_mulmod(gf_intp a, gf_intp b, gf_intp m, gf_intp c)
-{
-   gf_int tmp;
-   gf_mul(a, b, tmp);
-   gf_mod(tmp, m, c);
-   gf_zero(tmp);
-}
-
-/* B = 1/A mod M */
-void gf_invmod(gf_intp A, gf_intp M, gf_intp B)
-{
-  gf_int m, n, p0, p1, p2, r, q, tmp;
-
-  /* put all variables in known setup state */
-  gf_zero(p0);
-  gf_zero(p2);
-  gf_copy(M, m);
-  gf_copy(A, n);
-  p0[0] = 1;
-  gf_div(m, n, p1, r);
-  gf_copy(p1, q);
-
-  /* loop until r == 0 */
-  while (!gf_iszero(r)) {
-     gf_copy(n, m);
-     gf_copy(r, n);
-     gf_div(m, n, q, r);
-     gf_mul(q, p1, tmp);
-     gf_add(tmp, p0, p2);
-     gf_copy(p1, p0);
-     gf_copy(p2, p1);
-  }
-  gf_copy(p0, B);
-  gf_zero(p0);
-}
-
-/* find a square root modulo a prime.  Note the number of 
- * elements is 2^k - 1, so we must square k-2 times to get the
- * square root.. 
- */
-void gf_sqrt(gf_intp a, gf_intp M, gf_intp b)
-{
-   int k;
-   k = gf_deg(M)-2;
-   gf_copy(a, b);
-   while (k--)
-      gf_mulmod(b, b, M, b);
-}
-
-/* c = gcd(A,B) */
-void gf_gcd(gf_intp A, gf_intp B, gf_intp c)
-{
-   gf_int a, b, r;
-   int n;
-
-   gf_add(A, B, r);
-   n = gf_deg(r);
-   if (gf_deg(A) > n) {
-      gf_copy(A, a);
-      gf_copy(B, b);
-   } else {
-      gf_copy(A, b);
-      gf_copy(B, a);
-   }
-
-   do {
-      gf_mod(a, b, r);
-      gf_copy(b, a);
-      gf_copy(r, b);
-   } while (!gf_iszero(r));
-   gf_copy(a, c);
-   gf_zero(a);
-   gf_zero(b);
-}
-
-/* returns non-zero if 'a' is irreducible */
-int gf_is_prime(gf_intp a)
-{
-   gf_int u, tmp;
-   int m, n;
-
-   gf_zero(u);
-   u[0] = 2;			/* u(x) = x */
-   m = gf_deg(a);
-   for (n = 0; n < (m/2); n++) { 
-       gf_mulmod(u, u, a, u);   /* u(x) = u(x)^2 mod a(x) */
-       gf_copy(u, tmp);
-       tmp[0] ^= 2;		/* tmp(x) = u(x) - x */
-       gf_gcd(tmp, a, tmp);     /* tmp(x) = gcd(a(x), u(x) - x) */
-       if (!gf_isone(tmp)) {
-          return 0;
-       }
-   }
-   return 1;
-}  
-
-/* returns bytes required to store a gf_int */
-int gf_size(gf_intp a)
-{
-   int n;
-
-   n = gf_deg(a);
-   if (n == -1) {
-      return 4;
-   }
-   n = n + (32 - (n&31));
-   return n/8;
-}
-
-/* store a gf_int */
-void gf_toraw(gf_intp a, unsigned char *dst)
-{
-   int x, n;
-   n = gf_size(a)/4;
-   for (x = 0; x < n; x++) {
-       STORE32L(a[x], dst);
-       dst += 4;
-   }
-}
-
-/* read a gf_int (len == in bytes) */
-void gf_readraw(gf_intp a, unsigned char *str, int len)
-{
-   int x;
-   gf_zero(a);
-   for (x = 0; x < len/4; x++) {
-       LOAD32L(a[x], str);
-       str += 4;
-   }
-}
-
-#endif
-
-
diff --git a/hash_file.c b/hash_file.c
deleted file mode 100644
index 0511f2c..0000000
--- a/hash_file.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int hash_file(int hash, const char *fname, unsigned char *dst, unsigned long *outlen)
-{
-#ifdef NO_FILE
-    return CRYPT_NOP;
-#else
-    FILE *in;
-    int err;
-    _ARGCHK(fname  != NULL);
-    _ARGCHK(dst    != NULL);
-    _ARGCHK(outlen != NULL);
-
-    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
-        return err;
-    }
-
-    in = fopen(fname, "rb");
-    if (in == NULL) { 
-       return CRYPT_FILE_NOTFOUND;
-    }
-
-    err = hash_filehandle(hash, in, dst, outlen);
-    if (fclose(in) != 0) {
-       return CRYPT_ERROR;
-    }
-
-    return err;
-#endif
-}
-
diff --git a/hash_filehandle.c b/hash_filehandle.c
deleted file mode 100644
index ca6be90..0000000
--- a/hash_filehandle.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int hash_filehandle(int hash, FILE *in, unsigned char *dst, unsigned long *outlen)
-{
-#ifdef NO_FILE
-    return CRYPT_NOP;
-#else
-    hash_state md;
-    unsigned char buf[512];
-    size_t x;
-    int err;
-
-    _ARGCHK(dst    != NULL);
-    _ARGCHK(outlen != NULL);
-    _ARGCHK(in     != NULL);
-
-    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
-        return err;
-    }
-
-    if (*outlen < hash_descriptor[hash].hashsize) {
-       return CRYPT_BUFFER_OVERFLOW;
-    }
-    *outlen = hash_descriptor[hash].hashsize;
-
-    hash_descriptor[hash].init(&md);
-    do {
-        x = fread(buf, 1, sizeof(buf), in);
-        hash_descriptor[hash].process(&md, buf, x);
-    } while (x == sizeof(buf));
-    hash_descriptor[hash].done(&md, dst);
-
-#ifdef CLEAN_STACK
-    zeromem(buf, sizeof(buf));
-#endif
-    return CRYPT_OK;
-#endif
-}
-
diff --git a/hash_memory.c b/hash_memory.c
deleted file mode 100644
index 976a145..0000000
--- a/hash_memory.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen)
-{
-    hash_state md;
-    int err;
-
-    _ARGCHK(data   != NULL);
-    _ARGCHK(dst    != NULL);
-    _ARGCHK(outlen != NULL);
-
-    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
-        return err;
-    }
-
-    if (*outlen < hash_descriptor[hash].hashsize) {
-       return CRYPT_BUFFER_OVERFLOW;
-    }
-    *outlen = hash_descriptor[hash].hashsize;
-
-    hash_descriptor[hash].init(&md);
-    hash_descriptor[hash].process(&md, data, len);
-    hash_descriptor[hash].done(&md, dst);
-    return CRYPT_OK;
-}
diff --git a/hmac_done.c b/hmac_done.c
deleted file mode 100644
index 57ebbcd..0000000
--- a/hmac_done.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-/*
-    (1) append zeros to the end of K to create a B byte string
-        (e.g., if K is of length 20 bytes and B=64, then K will be
-         appended with 44 zero bytes 0x00)
-    (2) XOR (bitwise exclusive-OR) the B byte string computed in step
-        (1) with ipad (ipad = the byte 0x36 repeated B times)
-    (3) append the stream of data 'text' to the B byte string resulting
-        from step (2)
-    (4) apply H to the stream generated in step (3)
-    (5) XOR (bitwise exclusive-OR) the B byte string computed in
-        step (1) with opad (opad = the byte 0x5C repeated B times.)
-    (6) append the H result from step (4) to the B byte string
-        resulting from step (5)
-    (7) apply H to the stream generated in step (6) and output
-        the result
-*/
-
-#ifdef HMAC
-
-#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
-
-int hmac_done(hmac_state *hmac, unsigned char *hashOut, unsigned long *outlen)
-{
-    unsigned char buf[MAXBLOCKSIZE];
-    unsigned char isha[MAXBLOCKSIZE];
-    unsigned long hashsize, i;
-    int hash, err;
-
-    _ARGCHK(hmac != NULL);
-    _ARGCHK(hashOut != NULL);
-
-    hash = hmac->hash;
-    if((err = hash_is_valid(hash)) != CRYPT_OK) {
-        return err;
-    }
-
-    /* get the hash message digest size */
-    hashsize = hash_descriptor[hash].hashsize;
-
-    // Get the hash of the first HMAC vector plus the data
-    if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
-       return err;
-    }
-
-    // Create the second HMAC vector vector for step (3)
-    for(i=0; i < HMAC_BLOCKSIZE; i++) {
-        buf[i] = hmac->key[i] ^ 0x5C;
-    }
-
-    // Now calculate the "outer" hash for step (5), (6), and (7)
-    hash_descriptor[hash].init(&hmac->md);
-    hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE);
-    hash_descriptor[hash].process(&hmac->md, isha, hashsize);
-    hash_descriptor[hash].done(&hmac->md, buf);
-
-    // copy to output 
-    for (i = 0; i < hashsize && i < *outlen; i++) {
-        hashOut[i] = buf[i];
-    }
-    *outlen = i;
-
-#ifdef CLEAN_STACK
-    zeromem(isha, sizeof(buf));
-    zeromem(buf,  sizeof(isha));
-    zeromem(hmac, sizeof(*hmac));
-#endif
-    return CRYPT_OK;
-}
-
-#endif
diff --git a/hmac_file.c b/hmac_file.c
deleted file mode 100644
index 23194bd..0000000
--- a/hmac_file.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-/*
-    (1) append zeros to the end of K to create a B byte string
-        (e.g., if K is of length 20 bytes and B=64, then K will be
-         appended with 44 zero bytes 0x00)
-    (2) XOR (bitwise exclusive-OR) the B byte string computed in step
-        (1) with ipad (ipad = the byte 0x36 repeated B times)
-    (3) append the stream of data 'text' to the B byte string resulting
-        from step (2)
-    (4) apply H to the stream generated in step (3)
-    (5) XOR (bitwise exclusive-OR) the B byte string computed in
-        step (1) with opad (opad = the byte 0x5C repeated B times.)
-    (6) append the H result from step (4) to the B byte string
-        resulting from step (5)
-    (7) apply H to the stream generated in step (6) and output
-        the result
-*/
-
-#ifdef HMAC
-
-#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
-
-/* hmac_file added by Tom St Denis */
-int hmac_file(int hash, const char *fname, 
-              const unsigned char *key, unsigned long keylen, 
-                    unsigned char *dst, unsigned long *dstlen)
-{
-#ifdef NO_FILE
-    return CRYPT_NOP;
-#else
-   hmac_state hmac;
-   FILE *in;
-   unsigned char buf[512];
-   size_t x;
-   int err;
-
-   _ARGCHK(fname  != NULL);
-   _ARGCHK(key    != NULL);
-   _ARGCHK(dst    != NULL);
-   _ARGCHK(dstlen != NULL);
-   
-   if((err = hash_is_valid(hash)) != CRYPT_OK) {
-       return err;
-   }
-
-   if ((err = hmac_init(&hmac, hash, key, keylen)) != CRYPT_OK) {
-       return err;
-   }
-
-   in = fopen(fname, "rb");
-   if (in == NULL) {
-      return CRYPT_FILE_NOTFOUND;
-   }
-
-   /* process the file contents */
-   do {
-      x = fread(buf, 1, sizeof(buf), in);
-      if ((err = hmac_process(&hmac, buf, (unsigned long)x)) != CRYPT_OK) {
-         /* we don't trap this error since we're already returning an error! */
-         fclose(in);
-         return err;
-      }
-   } while (x == sizeof(buf));
-
-   if (fclose(in) != 0) {
-      return CRYPT_ERROR;
-   }
-
-   /* get final hmac */
-   if ((err = hmac_done(&hmac, dst, dstlen)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef CLEAN_STACK
-   /* clear memory */
-   zeromem(buf, sizeof(buf));
-#endif   
-   return CRYPT_OK;
-#endif
-}
-
-#endif
-
diff --git a/hmac_init.c b/hmac_init.c
deleted file mode 100644
index 7a9b801..0000000
--- a/hmac_init.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-/*
-    (1) append zeros to the end of K to create a B byte string
-        (e.g., if K is of length 20 bytes and B=64, then K will be
-         appended with 44 zero bytes 0x00)
-    (2) XOR (bitwise exclusive-OR) the B byte string computed in step
-        (1) with ipad (ipad = the byte 0x36 repeated B times)
-    (3) append the stream of data 'text' to the B byte string resulting
-        from step (2)
-    (4) apply H to the stream generated in step (3)
-    (5) XOR (bitwise exclusive-OR) the B byte string computed in
-        step (1) with opad (opad = the byte 0x5C repeated B times.)
-    (6) append the H result from step (4) to the B byte string
-        resulting from step (5)
-    (7) apply H to the stream generated in step (6) and output
-        the result
-*/
-
-#ifdef HMAC
-
-#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
-
-int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen)
-{
-    unsigned char buf[MAXBLOCKSIZE];
-    unsigned long hashsize;
-    unsigned long i, z;
-    int err;
-
-    _ARGCHK(hmac != NULL);
-    _ARGCHK(key != NULL);
-
-    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
-        return err;
-    }
-
-    /* valid key length? */
-    if (keylen == 0) {
-        return CRYPT_INVALID_KEYSIZE;
-    }
-
-    hmac->hash = hash;
-
-    // (1) make sure we have a large enough key
-    hashsize = hash_descriptor[hash].hashsize;
-    if(keylen > HMAC_BLOCKSIZE) {
-        z = (unsigned long)sizeof(hmac->key);
-        if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) {
-           return err;
-        }
-        if(hashsize < HMAC_BLOCKSIZE) {
-            zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
-        }
-        keylen = hashsize;
-    } else {
-        memcpy(hmac->key, key, (size_t)keylen);
-        if(keylen < HMAC_BLOCKSIZE) {
-            zeromem((hmac->key) + keylen, (size_t)(HMAC_BLOCKSIZE - keylen));
-        }
-    }
-
-    // Create the initial vector for step (3)
-    for(i=0; i < HMAC_BLOCKSIZE;   i++) {
-       buf[i] = hmac->key[i] ^ 0x36;
-    }
-
-    // Pre-pend that to the hash data
-    hash_descriptor[hash].init(&hmac->md);
-    hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE);
-
-    return CRYPT_OK;
-}
-
-#endif
diff --git a/hmac_memory.c b/hmac_memory.c
deleted file mode 100644
index e438a30..0000000
--- a/hmac_memory.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-/*
-    (1) append zeros to the end of K to create a B byte string
-        (e.g., if K is of length 20 bytes and B=64, then K will be
-         appended with 44 zero bytes 0x00)
-    (2) XOR (bitwise exclusive-OR) the B byte string computed in step
-        (1) with ipad (ipad = the byte 0x36 repeated B times)
-    (3) append the stream of data 'text' to the B byte string resulting
-        from step (2)
-    (4) apply H to the stream generated in step (3)
-    (5) XOR (bitwise exclusive-OR) the B byte string computed in
-        step (1) with opad (opad = the byte 0x5C repeated B times.)
-    (6) append the H result from step (4) to the B byte string
-        resulting from step (5)
-    (7) apply H to the stream generated in step (6) and output
-        the result
-*/
-
-#ifdef HMAC
-
-#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
-
-int hmac_memory(int hash, const unsigned char *key, unsigned long keylen,
-                const unsigned char *data, unsigned long len, 
-                unsigned char *dst, unsigned long *dstlen)
-{
-    hmac_state hmac;
-    int err;
-
-    _ARGCHK(key    != NULL);
-    _ARGCHK(data   != NULL);
-    _ARGCHK(dst    != NULL); 
-    _ARGCHK(dstlen != NULL);
-    
-    if((err = hash_is_valid(hash)) != CRYPT_OK) {
-        return err;
-    }
-
-    if ((err = hmac_init(&hmac, hash, key, keylen)) != CRYPT_OK) {
-        return err;
-    }
-
-    if ((err = hmac_process(&hmac, data, len)) != CRYPT_OK) {
-       return err;
-    }
-
-    if ((err = hmac_done(&hmac, dst, dstlen)) != CRYPT_OK) {
-       return err;
-    }
-    return CRYPT_OK;
-}
-
-#endif
-
diff --git a/hmac_process.c b/hmac_process.c
deleted file mode 100644
index fa4c1e6..0000000
--- a/hmac_process.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-/*
-    (1) append zeros to the end of K to create a B byte string
-        (e.g., if K is of length 20 bytes and B=64, then K will be
-         appended with 44 zero bytes 0x00)
-    (2) XOR (bitwise exclusive-OR) the B byte string computed in step
-        (1) with ipad (ipad = the byte 0x36 repeated B times)
-    (3) append the stream of data 'text' to the B byte string resulting
-        from step (2)
-    (4) apply H to the stream generated in step (3)
-    (5) XOR (bitwise exclusive-OR) the B byte string computed in
-        step (1) with opad (opad = the byte 0x5C repeated B times.)
-    (6) append the H result from step (4) to the B byte string
-        resulting from step (5)
-    (7) apply H to the stream generated in step (6) and output
-        the result
-*/
-
-#ifdef HMAC
-
-#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
-
-int hmac_process(hmac_state *hmac, const unsigned char *buf, unsigned long len)
-{
-    int err;
-    _ARGCHK(hmac != NULL);
-    _ARGCHK(buf != NULL);
-    if ((err = hash_is_valid(hmac->hash)) != CRYPT_OK) {
-        return err;
-    }
-    return hash_descriptor[hmac->hash].process(&hmac->md, buf, len);
-}
-
-#endif
-
diff --git a/keyring.c b/keyring.c
deleted file mode 100644
index 56f128d..0000000
--- a/keyring.c
+++ /dev/null
@@ -1,862 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* Provides keyring functionality for libtomcrypt, Tom St Denis */
-#include <mycrypt.h>
-
-#ifdef KR
-
-static const unsigned char key_magic[4]  = { 0x12, 0x34, 0x56, 0x78 };
-static const unsigned char file_magic[4] = { 0x9A, 0xBC, 0xDE, 0xF0 };
-static const unsigned char sign_magic[4] = { 0x87, 0x56, 0x43, 0x21 };
-static const unsigned char enc_magic[4]  = { 0x0F, 0xED, 0xCB, 0xA9 };
-
-static const unsigned long crc_table[256] = {
-  0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
-  0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
-  0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
-  0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
-  0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
-  0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
-  0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
-  0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
-  0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
-  0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
-  0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
-  0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
-  0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
-  0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
-  0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
-  0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
-  0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
-  0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
-  0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
-  0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
-  0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
-  0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
-  0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
-  0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
-  0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
-  0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
-  0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
-  0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
-  0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
-  0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
-  0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
-  0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
-  0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
-  0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
-  0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
-  0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
-  0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
-  0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
-  0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
-  0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
-  0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
-  0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
-  0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
-  0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
-  0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
-  0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
-  0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
-  0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
-  0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
-  0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
-  0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
-  0x2d02ef8dUL
-};
-
-#define DO1(buf) crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
-#define DO2(buf)  DO1(buf); DO1(buf);
-#define DO4(buf)  DO2(buf); DO2(buf);
-#define DO8(buf)  DO4(buf); DO4(buf);
-
-static unsigned long crc32 (unsigned long crc, const unsigned char *buf, unsigned long len)
-{
-  //_ARGCHK(buf != NULL  && len == 0);
-  crc = crc ^ 0xffffffffL;
-  while (len >= 8) {
-      DO8 (buf);
-      len -= 8;
-  }
-  
-  if (len > 0) {
-    do {
-	   DO1 (buf);
-    } while (--len > 0);
-  }    
-  return crc ^ 0xffffffffUL;
-}
-
-int kr_init(pk_key **pk)
-{
-   _ARGCHK(pk != NULL);
-
-   *pk = XCALLOC(1, sizeof(pk_key));
-   if (*pk == NULL) {
-      return CRYPT_MEM;
-   }
-   (*pk)->system = NON_KEY;
-   return CRYPT_OK;
-}
-
-unsigned long kr_crc(const unsigned char *name, const unsigned char *email, const unsigned char *description)
-{
-   unsigned long crc;
-   _ARGCHK(name != NULL);
-   _ARGCHK(email != NULL);
-   _ARGCHK(description != NULL);
-   crc = crc32(0UL, NULL, 0UL);
-   crc = crc32(crc, name,  (unsigned long)MIN(MAXLEN, strlen((char *)name)));
-   crc = crc32(crc, email, (unsigned long)MIN(MAXLEN, strlen((char *)email)));
-   return crc32(crc, description, (unsigned long)MIN(MAXLEN, strlen((char *)description)));
-}
-
-pk_key *kr_find(pk_key *pk, unsigned long ID)
-{
-   _ARGCHK(pk != NULL);
-
-   while (pk != NULL) {
-        if (pk->system != NON_KEY && pk->ID == ID) {
-           return pk;
-        }
-        pk = pk->next;
-   }
-   return NULL;
-}
-
-pk_key *kr_find_name(pk_key *pk, const char *name)
-{
-   _ARGCHK(pk != NULL);
-   _ARGCHK(name != NULL);
-
-   while (pk != NULL) {
-        if (pk->system != NON_KEY && strncmp((char *)pk->name, (char *)name, sizeof(pk->name)-1) == 0) {
-           return pk;
-        }
-        pk = pk->next;
-   }
-   return NULL;
-}
- 
-
-int kr_add(pk_key *pk, int key_type, int sys, const unsigned char *name, 
-           const unsigned char *email, const unsigned char *description, const _pk_key *key)
-{
-   _ARGCHK(pk != NULL);
-   _ARGCHK(name != NULL);
-   _ARGCHK(email != NULL);
-   _ARGCHK(description != NULL);
-   _ARGCHK(key != NULL);
-
-   /* check parameters */
-   if (key_type != PK_PRIVATE && key_type != PK_PRIVATE_OPTIMIZED && key_type != PK_PUBLIC) {
-      return CRYPT_PK_INVALID_TYPE;
-   }
- 
-   if (sys != RSA_KEY && sys != DH_KEY && sys != ECC_KEY) {
-      return CRYPT_PK_INVALID_SYSTEM;
-   }
-
-   /* see if its a dupe  */
-   if (kr_find(pk, kr_crc(name, email, description)) != NULL) {
-      return CRYPT_PK_DUP;
-   }
-   
-   /* find spot in key ring */
-   while (pk->system != NON_KEY) {
-         if (pk->next == NULL) {
-            return CRYPT_ERROR;
-         }
-         pk = pk->next;
-   }
-
-   /* now we have a spot make a next spot */
-   pk->next = XCALLOC(1, sizeof(pk_key));
-   if (pk->next == NULL) {
-      return CRYPT_MEM;
-   }
-   pk->next->system = NON_KEY;
-
-   /* now add this new data to this ring spot */
-   pk->key_type = key_type;
-   pk->system   = sys;
-   strncpy((char *)pk->name, (char *)name, sizeof(pk->name)-1);
-   strncpy((char *)pk->email, (char *)email, sizeof(pk->email)-1);
-   strncpy((char *)pk->description, (char *)description, sizeof(pk->description)-1);
-   pk->ID       = kr_crc(pk->name, pk->email, pk->description);
-
-   /* clear the memory area */
-   zeromem(&(pk->key), sizeof(pk->key));
-
-   /* copy the key */
-   switch (sys) {
-         case RSA_KEY:
-              memcpy(&(pk->key.rsa), &(key->rsa), sizeof(key->rsa));
-              break;
-         case DH_KEY:
-              memcpy(&(pk->key.dh), &(key->dh), sizeof(key->dh));
-              break;
-         case ECC_KEY:
-              memcpy(&(pk->key.ecc), &(key->ecc), sizeof(key->ecc));
-              break;
-   }
-   return CRYPT_OK;
-}
-
-int kr_del(pk_key **_pk, unsigned long ID)
-{
-   pk_key *ppk, *pk;
-
-   _ARGCHK(_pk != NULL);
-
-   pk  = *_pk;
-   ppk = NULL;
-   while (pk->system != NON_KEY && pk->ID != ID) {
-        ppk = pk;
-        pk  = pk->next;
-        if (pk == NULL) {
-           return CRYPT_PK_NOT_FOUND;
-        }
-   }
-
-   switch (pk->system) {
-        case RSA_KEY:
-            rsa_free(&(pk->key.rsa));
-            break;
-        case DH_KEY:
-            dh_free(&(pk->key.dh));
-            break;
-        case ECC_KEY:
-            ecc_free(&(pk->key.ecc));
-            break;
-   }
-
-   if (ppk == NULL) {       /* the first element matches the ID */
-      ppk = pk->next;       /* get the 2nd element */
-      XFREE(pk);             /* free the first */
-      *_pk = ppk;           /* make the first element the second */
-   } else {                 /* (not) first element matches the ID */
-      ppk->next = pk->next; /* make the previous'es next point to the current next */
-      XFREE(pk);             /* free the element */
-   }
-   return CRYPT_OK;
-}
-
-int kr_clear(pk_key **pk)
-{
-   int err;
-   _ARGCHK(pk != NULL);
-
-   while ((*pk)->system != NON_KEY) {
-       if ((err = kr_del(pk, (*pk)->ID)) != CRYPT_OK) { 
-          return err;
-       }
-   }       
-   XFREE(*pk);
-   *pk = NULL;
-   return CRYPT_OK;
-}
-
-static unsigned long _write(unsigned char *buf, unsigned long len, FILE *f, symmetric_CTR *ctr)
-{
-#ifdef NO_FILE
-   return 0;
-#else
-   _ARGCHK(buf != NULL);
-   _ARGCHK(f   != NULL);
-   if (ctr != NULL) {
-      if (ctr_encrypt(buf, buf, len, ctr) != CRYPT_OK) {
-         return 0;
-      }
-   }
-   return (unsigned long)fwrite(buf, 1, (size_t)len, f);
-#endif
-}
-
-static unsigned long _read(unsigned char *buf, unsigned long len, FILE *f, symmetric_CTR *ctr)
-{
-#ifdef NO_FILE
-    return 0;
-#else
-   unsigned long y;
-   _ARGCHK(buf != NULL);
-   _ARGCHK(f   != NULL);
-   y = (unsigned long)fread(buf, 1, (size_t)len, f);
-   if (ctr != NULL) {
-      if (ctr_decrypt(buf, buf, y, ctr) != CRYPT_OK) {
-         return 0;
-      }
-   }
-   return y;
-#endif
-}
-
-int kr_export(pk_key *pk, unsigned long ID, int key_type, unsigned char *out, unsigned long *outlen)
-{
-   unsigned char buf[8192], *obuf;
-   pk_key *ppk;
-   unsigned long len;
-   int err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* find the desired key */
-   ppk = kr_find(pk, ID);
-   if (ppk == NULL) {
-      return CRYPT_PK_NOT_FOUND;
-   }
-
-   if (ppk->key_type == PK_PUBLIC && key_type != PK_PUBLIC) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   /* this makes PK_PRIVATE an alias for PK_PRIVATE_OPTIMIZED type */
-   if (ppk->key_type == PK_PRIVATE_OPTIMIZED && key_type == PK_PRIVATE) {
-      key_type = PK_PRIVATE_OPTIMIZED;
-   }
-
-   /* now copy the header and various other details */
-   memcpy(buf, key_magic, 4);                              /* magic info */
-   buf[4] = key_type;                                      /* key type */
-   buf[5] = ppk->system;                                   /* system */
-   STORE32L(ppk->ID, buf+6);                               /* key ID */
-   memcpy(buf+10, ppk->name, MAXLEN);                      /* the name */
-   memcpy(buf+10+MAXLEN, ppk->email, MAXLEN);              /* the email */
-   memcpy(buf+10+MAXLEN+MAXLEN, ppk->description, MAXLEN); /* the description */
-   
-   /* export key */
-   len = sizeof(buf) - (6 + 4 + MAXLEN*3);
-   obuf = buf+6+4+MAXLEN*3;
-   switch (ppk->system) {
-       case RSA_KEY:
-           if ((err = rsa_export(obuf, &len, key_type, &(ppk->key.rsa))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-       case DH_KEY:
-           if ((err = dh_export(obuf, &len, key_type, &(ppk->key.dh))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-       case ECC_KEY:
-           if ((err = ecc_export(obuf, &len, key_type, &(ppk->key.ecc))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-   }
-
-   /* get the entire length of the packet */
-   len += 6 + 4 + 3*MAXLEN;
-
-   if (*outlen < len) {
-      #ifdef CLEAN_STACK
-          zeromem(buf, sizeof(buf));
-      #endif
-      return CRYPT_BUFFER_OVERFLOW;
-   } else {
-      *outlen = len;
-      memcpy(out, buf, len);
-      #ifdef CLEAN_STACK
-          zeromem(buf, sizeof(buf));
-      #endif
-      return CRYPT_OK;
-   }
-}
-
-int kr_import(pk_key *pk, const unsigned char *in, unsigned long inlen)
-{
-   _pk_key key;
-   int sys, key_type, err;
-   unsigned long ID;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(in != NULL);
-
-   if (inlen < 10) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   if (memcmp(in, key_magic, 4) != 0) {
-      return CRYPT_INVALID_PACKET;
-   }
-   key_type = in[4];                                 /* get type */
-   sys      = in[5];                                 /* get system */
-   LOAD32L(ID,in+6);                                 /* the ID */
-
-   if (ID != kr_crc(in+10, in+10+MAXLEN, in+10+MAXLEN+MAXLEN)) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   zeromem(&key, sizeof(key));
-   
-   /* size of remaining packet */
-   inlen -= 10 + 3*MAXLEN;
-   
-   switch (sys) {
-        case RSA_KEY:
-            if ((err = rsa_import(in+10+3*MAXLEN, inlen, &(key.rsa))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-        case DH_KEY:
-            if ((err = dh_import(in+10+3*MAXLEN, inlen, &(key.dh))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-        case ECC_KEY:
-            if ((err = ecc_import(in+10+3*MAXLEN, inlen, &(key.ecc))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-   }
-   return kr_add(pk, key_type, sys, 
-                 in+10,                           /* the name */
-                 in+10+MAXLEN,                    /* email address */
-                 in+10+MAXLEN+MAXLEN,             /* description */
-                 &key);
-}
-
-
-int kr_load(pk_key **pk, FILE *in, symmetric_CTR *ctr)
-{
-   unsigned char buf[8192], blen[4];
-   unsigned long len;
-   int res, err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(in != NULL);
-
-   /* init keyring */
-   if ((err = kr_init(pk)) != CRYPT_OK) { 
-      return err; 
-   }
-
-   /* read in magic bytes */
-   if (_read(buf, 6, in, ctr) != 6)           { goto done2; }
-
-   if (memcmp(buf, file_magic, 4) != 0) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   len = (unsigned long)buf[4] | ((unsigned long)buf[5] << 8);
-   if (len > CRYPT) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* while there are lengths to read... */
-   while (_read(blen, 4, in, ctr) == 4) {
-      /* get length */
-      LOAD32L(len, blen);
-
-      if (len > (unsigned long)sizeof(buf)) {
-         return CRYPT_INVALID_PACKET;
-      }
-
-      if (_read(buf, len, in, ctr) != len)           { goto done2; }
-      if ((err = kr_import(*pk, buf, len)) != CRYPT_OK) { 
-         return err; 
-      }
-   }
-
-   res = CRYPT_OK;
-   goto done;
-done2:
-   res = CRYPT_ERROR;
-done:
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return res;
-}
-
-int kr_save(pk_key *pk, FILE *out, symmetric_CTR *ctr)
-{
-   unsigned char buf[8192], blen[4];
-   unsigned long len;
-   int res, err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(out != NULL);
-
-   /* write out magic bytes */
-   memcpy(buf, file_magic, 4);
-   buf[4] = (unsigned char)(CRYPT&255);
-   buf[5] = (unsigned char)((CRYPT>>8)&255);
-   if (_write(buf, 6, out, ctr) != 6)           { goto done2; }
-
-   while (pk->system != NON_KEY) {
-         len = sizeof(buf);
-         if ((err = kr_export(pk, pk->ID, pk->key_type, buf, &len)) != CRYPT_OK) { 
-            return err;
-         }
-          
-         STORE32L(len, blen);
-         if (_write(blen, 4, out, ctr) != 4)    { goto done2; }
-         if (_write(buf, len, out, ctr) != len) { goto done2; }
-
-         pk = pk->next;
-   }
-         
-   res = CRYPT_OK;
-   goto done;
-done2:
-   res = CRYPT_ERROR;
-done:
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return res;
-}
-
-int kr_make_key(pk_key *pk, prng_state *prng, int wprng, 
-                int sys, int keysize, const unsigned char *name,
-                const unsigned char *email, const unsigned char *description)
-{
-   _pk_key key;
-   int key_type, err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(name != NULL);
-   _ARGCHK(email != NULL);
-   _ARGCHK(description != NULL);
-
-   /* valid PRNG? */
-   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* make the key first */
-   zeromem(&key, sizeof(key));
-   switch (sys) {
-      case RSA_KEY: 
-          if ((err = rsa_make_key(prng, wprng, keysize, 65537, &(key.rsa))) != CRYPT_OK) {
-             return err;
-          }
-          key_type = key.rsa.type;
-          break;
-      case DH_KEY: 
-          if ((err = dh_make_key(prng, wprng, keysize, &(key.dh))) != CRYPT_OK) {
-             return err;
-          }
-          key_type = key.dh.type;
-          break;
-      case ECC_KEY: 
-          if ((err = ecc_make_key(prng, wprng, keysize, &(key.ecc))) != CRYPT_OK) {
-             return err;
-          }
-          key_type = key.ecc.type;
-          break;
-      default:
-          return CRYPT_PK_INVALID_SYSTEM;
-   }
-
-   /* now add the key */
-   if ((err = kr_add(pk, key_type, sys, name, email, description, &key)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(&key, sizeof(key));
-#endif
-   return CRYPT_OK;
-}
-
-int kr_encrypt_key(pk_key *pk, unsigned long ID, 
-                   const unsigned char *in, unsigned long inlen,
-                   unsigned char *out, unsigned long *outlen,
-                   prng_state *prng, int wprng, int hash)
-{
-   unsigned char buf[8192];
-   unsigned long len;
-   pk_key *kr;
-   int err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(in != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* find the key */
-   kr = kr_find(pk, ID);
-   if (kr == NULL) {
-      return CRYPT_PK_NOT_FOUND;
-   }
-
-   /* store the header */
-   memcpy(buf, enc_magic, 4);
-
-   /* now store the ID */
-   STORE32L(kr->ID,buf+4);
-
-   /* now encrypt it */
-   len = sizeof(buf)-12;
-   switch (kr->system) {
-        case RSA_KEY:
-            if ((err = rsa_encrypt_key(in, inlen, buf+12, &len, prng, wprng, &(kr->key.rsa))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-        case DH_KEY:
-            if ((err = dh_encrypt_key(in, inlen, buf+12, &len, prng, wprng, hash, &(kr->key.dh))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-        case ECC_KEY:
-            if ((err = ecc_encrypt_key(in, inlen, buf+12, &len, prng, wprng, hash, &(kr->key.ecc))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-    }
-    STORE32L(len,buf+8);
-    len += 12;
-
-    if (len > *outlen) {
-       #ifdef CLEAN_STACK
-           zeromem(buf, sizeof(buf));
-       #endif
-       return CRYPT_BUFFER_OVERFLOW;
-    } else {
-       memcpy(out, buf, len);
-       #ifdef CLEAN_STACK
-           zeromem(buf, sizeof(buf));
-       #endif
-       *outlen = len;
-       return CRYPT_OK;
-    }
-}
-
-int kr_decrypt_key(pk_key *pk, const unsigned char *in,
-                   unsigned char *out, unsigned long *outlen)
-{
-   unsigned char buf[8192];
-   unsigned long pklen, len, ID;
-   pk_key *kr;
-   int err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(in != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* check magic header */
-   if (memcmp(in, enc_magic, 4)) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* now try to find key */
-   LOAD32L(ID,in+4);
-   kr = kr_find(pk, ID);
-   if (kr == NULL) {
-      return CRYPT_PK_NOT_FOUND;
-   }
-
-   /* is it public? */
-   if (kr->key_type == PK_PUBLIC) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   /* now try and decrypt it */
-   LOAD32L(pklen,in+8);
-   len = sizeof(buf);
-   switch (kr->system) {
-       case RSA_KEY:
-           if ((err = rsa_decrypt_key(in+12, pklen, buf, &len, &(kr->key.rsa))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-       case DH_KEY:
-           if ((err = dh_decrypt_key(in+12, pklen, buf, &len, &(kr->key.dh))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-       case ECC_KEY:
-           if ((err = ecc_decrypt_key(in+12, pklen, buf, &len, &(kr->key.ecc))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-   }
-
-    if (len > *outlen) {
-       #ifdef CLEAN_STACK
-           zeromem(buf, sizeof(buf));
-       #endif
-       return CRYPT_BUFFER_OVERFLOW;
-    } else {
-       memcpy(out, buf, len);
-       #ifdef CLEAN_STACK
-           zeromem(buf, sizeof(buf));
-       #endif
-       *outlen = len;
-       return CRYPT_OK;
-    }
-}
-
-int kr_sign_hash(pk_key *pk, unsigned long ID, 
-                 const unsigned char *in, unsigned long inlen,
-                 unsigned char *out, unsigned long *outlen,
-                 prng_state *prng, int wprng)
-{
-   unsigned char buf[8192];
-   unsigned long len;
-   pk_key *kr;
-   int err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(in != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* find the key */
-   kr = kr_find(pk, ID);
-   if (kr == NULL) {
-      return CRYPT_PK_NOT_FOUND;
-   }
-
-   /* is it public? */
-   if (kr->key_type == PK_PUBLIC) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   /* store the header */
-   memcpy(buf, sign_magic, 4);
-
-   /* now store the ID */
-   STORE32L(kr->ID,buf+4);
-
-   /* now sign it */
-   len = sizeof(buf)-16;
-   switch (kr->system) {
-        case RSA_KEY:
-            if ((err = rsa_sign_hash(in, inlen, buf+16, &len, &(kr->key.rsa))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-        case DH_KEY:
-            if ((err = dh_sign_hash(in, inlen, buf+16, &len, prng, wprng, &(kr->key.dh))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-        case ECC_KEY:
-            if ((err = ecc_sign_hash(in, inlen, buf+16, &len, prng, wprng, &(kr->key.ecc))) != CRYPT_OK) {
-               return err;
-            }
-            break;
-    }
-    STORE32L(inlen,buf+8);
-    STORE32L(len,buf+12);
-    len += 16;
-
-    if (len > *outlen) {
-       #ifdef CLEAN_STACK
-           zeromem(buf, sizeof(buf));
-       #endif
-       return CRYPT_BUFFER_OVERFLOW;
-    } else {
-       memcpy(out, buf, len);
-       #ifdef CLEAN_STACK
-           zeromem(buf, sizeof(buf));
-       #endif
-       *outlen = len;
-       return CRYPT_OK;
-    }
-}
-
-int kr_verify_hash(pk_key *pk, const unsigned char *in, const unsigned char *hash, 
-                   unsigned long hashlen, int *stat)
-{
-   unsigned long inlen, pklen, ID;
-   pk_key *kr;
-   int err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(in != NULL);
-   _ARGCHK(hash != NULL);
-   _ARGCHK(stat != NULL);
-
-   /* default to not match */
-   *stat = 0;
-
-   /* check magic header */
-   if (memcmp(in, sign_magic, 4)) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* now try to find key */
-   LOAD32L(ID,in+4);
-   kr = kr_find(pk, ID);
-   if (kr == NULL) {
-      return CRYPT_PK_NOT_FOUND;
-   }
-
-   /* now try and verify it */
-   LOAD32L(inlen,in+8);         /* this is the length of the original inlen */
-   LOAD32L(pklen,in+12);        /* size of the PK packet */
-   if (inlen != hashlen) {      /* size doesn't match means the signature is invalid */
-      return CRYPT_OK;
-   }
-
-   switch (kr->system) {
-       case RSA_KEY:
-           if ((err = rsa_verify_hash(in+16, pklen, hash, stat, &(kr->key.rsa))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-       case DH_KEY:
-           if ((err = dh_verify_hash(in+16, pklen, hash, inlen, stat, &(kr->key.dh))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-       case ECC_KEY:
-           if ((err = ecc_verify_hash(in+16, pklen, hash, inlen, stat, &(kr->key.ecc))) != CRYPT_OK) {
-              return err;
-           }
-           break;
-   }
-   return CRYPT_OK;
-}
-
-int kr_fingerprint(pk_key *pk, unsigned long ID, int hash,
-                   unsigned char *out, unsigned long *outlen)
-{
-   unsigned char buf[8192];
-   unsigned long len;
-   int err;
-
-   _ARGCHK(pk != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* valid hash? */
-   if ((err = hash_is_valid(hash)) != CRYPT_OK) {
-      return err;
-   }
-
-   len = (unsigned long)sizeof(buf);
-   if ((err = kr_export(pk, ID, PK_PUBLIC, buf, &len)) != CRYPT_OK) {
-      return err;
-   }
-   
-   /* now hash it */
-   if ((err = hash_memory(hash, buf, len, out, outlen)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return CRYPT_OK;
-}
-
-#endif
-
-
diff --git a/ltc_tommath.h b/ltc_tommath.h
deleted file mode 100644
index 0029994..0000000
--- a/ltc_tommath.h
+++ /dev/null
@@ -1,556 +0,0 @@
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#ifndef BN_H_
-#define BN_H_
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <limits.h>
-
-#undef MIN
-#define MIN(x,y) ((x)<(y)?(x):(y))
-#undef MAX
-#define MAX(x,y) ((x)>(y)?(x):(y))
-
-#ifdef __cplusplus
-extern "C" {
-
-/* C++ compilers don't like assigning void * to mp_digit * */
-#define  OPT_CAST(x)  (x *)
-
-#else
-
-/* C on the other hand doesn't care */
-#define  OPT_CAST(x)
-
-#endif
-
-/* some default configurations.
- *
- * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
- * A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
- *
- * At the very least a mp_digit must be able to hold 7 bits
- * [any size beyond that is ok provided it doesn't overflow the data type]
- */
-#ifdef MP_8BIT
-   typedef unsigned char      mp_digit;
-   typedef unsigned short     mp_word;
-#elif defined(MP_16BIT)
-   typedef unsigned short     mp_digit;
-   typedef unsigned long      mp_word;
-#elif defined(MP_64BIT)
-   /* for GCC only on supported platforms */
-#ifndef CRYPT
-   typedef unsigned long long ulong64;
-   typedef signed long long   long64;
-#endif
-
-   typedef ulong64            mp_digit;
-   typedef unsigned long      mp_word __attribute__ ((mode(TI)));
-
-   #define DIGIT_BIT          60
-#else
-   /* this is the default case, 28-bit digits */
-   
-   /* this is to make porting into LibTomCrypt easier :-) */
-#ifndef CRYPT
-   #if defined(_MSC_VER) || defined(__BORLANDC__) 
-      typedef unsigned __int64   ulong64;
-      typedef signed __int64     long64;
-   #else
-      typedef unsigned long long ulong64;
-      typedef signed long long   long64;
-   #endif
-#endif
-
-   typedef unsigned long      mp_digit;
-   typedef ulong64            mp_word;
-
-#ifdef MP_31BIT   
-   /* this is an extension that uses 31-bit digits */
-   #define DIGIT_BIT          31
-#else
-   /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
-   #define DIGIT_BIT          28
-   #define MP_28BIT
-#endif   
-#endif
-
-/* define heap macros */
-#ifndef CRYPT
-   /* default to libc stuff */
-   #ifndef XMALLOC 
-       #define XMALLOC  malloc
-       #define XFREE    free
-       #define XREALLOC realloc
-       #define XCALLOC  calloc
-   #else
-      /* prototypes for our heap functions */
-      extern void *XMALLOC(size_t n);
-      extern void *REALLOC(void *p, size_t n);
-      extern void *XCALLOC(size_t n, size_t s);
-      extern void XFREE(void *p);
-   #endif
-#endif
-
-
-/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
-#ifndef DIGIT_BIT
-   #define DIGIT_BIT     ((int)((CHAR_BIT * sizeof(mp_digit) - 1)))  /* bits per digit */
-#endif
-
-#define MP_DIGIT_BIT     DIGIT_BIT
-#define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
-#define MP_DIGIT_MAX     MP_MASK
-
-/* equalities */
-#define MP_LT        -1   /* less than */
-#define MP_EQ         0   /* equal to */
-#define MP_GT         1   /* greater than */
-
-#define MP_ZPOS       0   /* positive integer */
-#define MP_NEG        1   /* negative */
-
-#define MP_OKAY       0   /* ok result */
-#define MP_MEM        -2  /* out of mem */
-#define MP_VAL        -3  /* invalid input */
-#define MP_RANGE      MP_VAL
-
-#define MP_YES        1   /* yes response */
-#define MP_NO         0   /* no response */
-
-/* Primality generation flags */
-#define LTM_PRIME_BBS      0x0001 /* BBS style prime */
-#define LTM_PRIME_SAFE     0x0002 /* Safe prime (p-1)/2 == prime */
-#define LTM_PRIME_2MSB_OFF 0x0004 /* force 2nd MSB to 0 */
-#define LTM_PRIME_2MSB_ON  0x0008 /* force 2nd MSB to 1 */
-
-typedef int           mp_err;
-
-/* you'll have to tune these... */
-extern int KARATSUBA_MUL_CUTOFF,
-           KARATSUBA_SQR_CUTOFF,
-           TOOM_MUL_CUTOFF,
-           TOOM_SQR_CUTOFF;
-
-/* define this to use lower memory usage routines (exptmods mostly) */
-/* #define MP_LOW_MEM */
-
-/* default precision */
-#ifndef MP_PREC
-   #ifdef MP_LOW_MEM
-      #define MP_PREC                 64     /* default digits of precision */
-   #else
-      #define MP_PREC                 8      /* default digits of precision */
-   #endif   
-#endif
-
-/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
-#define MP_WARRAY               (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
-
-/* the infamous mp_int structure */
-typedef struct  {
-    int used, alloc, sign;
-    mp_digit *dp;
-} mp_int;
-
-/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
-typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
-
-
-#define USED(m)    ((m)->used)
-#define DIGIT(m,k) ((m)->dp[(k)])
-#define SIGN(m)    ((m)->sign)
-
-/* error code to char* string */
-char *mp_error_to_string(int code);
-
-/* ---> init and deinit bignum functions <--- */
-/* init a bignum */
-int mp_init(mp_int *a);
-
-/* free a bignum */
-void mp_clear(mp_int *a);
-
-/* init a null terminated series of arguments */
-int mp_init_multi(mp_int *mp, ...);
-
-/* clear a null terminated series of arguments */
-void mp_clear_multi(mp_int *mp, ...);
-
-/* exchange two ints */
-void mp_exch(mp_int *a, mp_int *b);
-
-/* shrink ram required for a bignum */
-int mp_shrink(mp_int *a);
-
-/* grow an int to a given size */
-int mp_grow(mp_int *a, int size);
-
-/* init to a given number of digits */
-int mp_init_size(mp_int *a, int size);
-
-/* ---> Basic Manipulations <--- */
-#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
-#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
-#define mp_isodd(a)  (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
-
-/* set to zero */
-void mp_zero(mp_int *a);
-
-/* set to a digit */
-void mp_set(mp_int *a, mp_digit b);
-
-/* set a 32-bit const */
-int mp_set_int(mp_int *a, unsigned long b);
-
-/* get a 32-bit value */
-unsigned long mp_get_int(mp_int * a);
-
-/* initialize and set a digit */
-int mp_init_set (mp_int * a, mp_digit b);
-
-/* initialize and set 32-bit value */
-int mp_init_set_int (mp_int * a, unsigned long b);
-
-/* copy, b = a */
-int mp_copy(mp_int *a, mp_int *b);
-
-/* inits and copies, a = b */
-int mp_init_copy(mp_int *a, mp_int *b);
-
-/* trim unused digits */
-void mp_clamp(mp_int *a);
-
-/* ---> digit manipulation <--- */
-
-/* right shift by "b" digits */
-void mp_rshd(mp_int *a, int b);
-
-/* left shift by "b" digits */
-int mp_lshd(mp_int *a, int b);
-
-/* c = a / 2**b */
-int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
-
-/* b = a/2 */
-int mp_div_2(mp_int *a, mp_int *b);
-
-/* c = a * 2**b */
-int mp_mul_2d(mp_int *a, int b, mp_int *c);
-
-/* b = a*2 */
-int mp_mul_2(mp_int *a, mp_int *b);
-
-/* c = a mod 2**d */
-int mp_mod_2d(mp_int *a, int b, mp_int *c);
-
-/* computes a = 2**b */
-int mp_2expt(mp_int *a, int b);
-
-/* Counts the number of lsbs which are zero before the first zero bit */
-int mp_cnt_lsb(mp_int *a);
-
-/* I Love Earth! */
-
-/* makes a pseudo-random int of a given size */
-int mp_rand(mp_int *a, int digits);
-
-/* ---> binary operations <--- */
-/* c = a XOR b  */
-int mp_xor(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a OR b */
-int mp_or(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a AND b */
-int mp_and(mp_int *a, mp_int *b, mp_int *c);
-
-/* ---> Basic arithmetic <--- */
-
-/* b = -a */
-int mp_neg(mp_int *a, mp_int *b);
-
-/* b = |a| */
-int mp_abs(mp_int *a, mp_int *b);
-
-/* compare a to b */
-int mp_cmp(mp_int *a, mp_int *b);
-
-/* compare |a| to |b| */
-int mp_cmp_mag(mp_int *a, mp_int *b);
-
-/* c = a + b */
-int mp_add(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a - b */
-int mp_sub(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a * b */
-int mp_mul(mp_int *a, mp_int *b, mp_int *c);
-
-/* b = a*a  */
-int mp_sqr(mp_int *a, mp_int *b);
-
-/* a/b => cb + d == a */
-int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* c = a mod b, 0 <= c < b  */
-int mp_mod(mp_int *a, mp_int *b, mp_int *c);
-
-/* ---> single digit functions <--- */
-
-/* compare against a single digit */
-int mp_cmp_d(mp_int *a, mp_digit b);
-
-/* c = a + b */
-int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* c = a - b */
-int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* c = a * b */
-int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* a/b => cb + d == a */
-int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
-
-/* a/3 => 3c + d == a */
-int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
-
-/* c = a**b */
-int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* c = a mod b, 0 <= c < b  */
-int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
-
-/* ---> number theory <--- */
-
-/* d = a + b (mod c) */
-int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* d = a - b (mod c) */
-int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* d = a * b (mod c) */
-int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* c = a * a (mod b) */
-int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = 1/a (mod b) */
-int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = (a, b) */
-int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
-
-/* produces value such that U1*a + U2*b = U3 */
-int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
-
-/* c = [a, b] or (a*b)/(a, b) */
-int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
-
-/* finds one of the b'th root of a, such that |c|**b <= |a|
- *
- * returns error if a < 0 and b is even
- */
-int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
-
-/* special sqrt algo */
-int mp_sqrt(mp_int *arg, mp_int *ret);
-
-/* is number a square? */
-int mp_is_square(mp_int *arg, int *ret);
-
-/* computes the jacobi c = (a | n) (or Legendre if b is prime)  */
-int mp_jacobi(mp_int *a, mp_int *n, int *c);
-
-/* used to setup the Barrett reduction for a given modulus b */
-int mp_reduce_setup(mp_int *a, mp_int *b);
-
-/* Barrett Reduction, computes a (mod b) with a precomputed value c
- *
- * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
- * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
- */
-int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
-
-/* setups the montgomery reduction */
-int mp_montgomery_setup(mp_int *a, mp_digit *mp);
-
-/* computes a = B**n mod b without division or multiplication useful for
- * normalizing numbers in a Montgomery system.
- */
-int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
-
-/* computes x/R == x (mod N) via Montgomery Reduction */
-int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
-
-/* returns 1 if a is a valid DR modulus */
-int mp_dr_is_modulus(mp_int *a);
-
-/* sets the value of "d" required for mp_dr_reduce */
-void mp_dr_setup(mp_int *a, mp_digit *d);
-
-/* reduces a modulo b using the Diminished Radix method */
-int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
-
-/* returns true if a can be reduced with mp_reduce_2k */
-int mp_reduce_is_2k(mp_int *a);
-
-/* determines k value for 2k reduction */
-int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
-
-/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
-int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
-
-/* d = a**b (mod c) */
-int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* ---> Primes <--- */
-
-/* number of primes */
-#ifdef MP_8BIT
-   #define PRIME_SIZE      31
-#else
-   #define PRIME_SIZE      256
-#endif
-
-/* table of first PRIME_SIZE primes */
-extern const mp_digit __prime_tab[];
-
-/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
-int mp_prime_is_divisible(mp_int *a, int *result);
-
-/* performs one Fermat test of "a" using base "b".
- * Sets result to 0 if composite or 1 if probable prime
- */
-int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
-
-/* performs one Miller-Rabin test of "a" using base "b".
- * Sets result to 0 if composite or 1 if probable prime
- */
-int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
-
-/* This gives [for a given bit size] the number of trials required
- * such that Miller-Rabin gives a prob of failure lower than 2^-96 
- */
-int mp_prime_rabin_miller_trials(int size);
-
-/* performs t rounds of Miller-Rabin on "a" using the first
- * t prime bases.  Also performs an initial sieve of trial
- * division.  Determines if "a" is prime with probability
- * of error no more than (1/4)**t.
- *
- * Sets result to 1 if probably prime, 0 otherwise
- */
-int mp_prime_is_prime(mp_int *a, int t, int *result);
-
-/* finds the next prime after the number "a" using "t" trials
- * of Miller-Rabin.
- *
- * bbs_style = 1 means the prime must be congruent to 3 mod 4
- */
-int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
-
-/* makes a truly random prime of a given size (bytes),
- * call with bbs = 1 if you want it to be congruent to 3 mod 4 
- *
- * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
- * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
- * so it can be NULL
- *
- * The prime generated will be larger than 2^(8*size).
- */
-#define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
-
-/* makes a truly random prime of a given size (bits),
- *
- * Flags are as follows:
- * 
- *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
- *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
- *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
- *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
- *
- * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
- * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
- * so it can be NULL
- *
- */
-int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
-
-/* ---> radix conversion <--- */
-int mp_count_bits(mp_int *a);
-
-int mp_unsigned_bin_size(mp_int *a);
-int mp_read_unsigned_bin(mp_int *a, unsigned char *b, int c);
-int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
-
-int mp_signed_bin_size(mp_int *a);
-int mp_read_signed_bin(mp_int *a, unsigned char *b, int c);
-int mp_to_signed_bin(mp_int *a, unsigned char *b);
-
-int mp_read_radix(mp_int *a, char *str, int radix);
-int mp_toradix(mp_int *a, char *str, int radix);
-int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
-int mp_radix_size(mp_int *a, int radix, int *size);
-
-int mp_fread(mp_int *a, int radix, FILE *stream);
-int mp_fwrite(mp_int *a, int radix, FILE *stream);
-
-#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
-#define mp_raw_size(mp)           mp_signed_bin_size(mp)
-#define mp_toraw(mp, str)         mp_to_signed_bin((mp), (str))
-#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
-#define mp_mag_size(mp)           mp_unsigned_bin_size(mp)
-#define mp_tomag(mp, str)         mp_to_unsigned_bin((mp), (str))
-
-#define mp_tobinary(M, S)  mp_toradix((M), (S), 2)
-#define mp_tooctal(M, S)   mp_toradix((M), (S), 8)
-#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
-#define mp_tohex(M, S)     mp_toradix((M), (S), 16)
-
-/* lowlevel functions, do not call! */
-int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
-int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
-#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
-int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-int fast_s_mp_sqr(mp_int *a, mp_int *b);
-int s_mp_sqr(mp_int *a, mp_int *b);
-int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
-int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
-int mp_karatsuba_sqr(mp_int *a, mp_int *b);
-int mp_toom_sqr(mp_int *a, mp_int *b);
-int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
-int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
-int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
-int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
-void bn_reverse(unsigned char *s, int len);
-
-extern const char *mp_s_rmap;
-
-#ifdef __cplusplus
-   }
-#endif
-
-#endif
-
diff --git a/makefile.cygwin_dll b/makefile.cygwin_dll
deleted file mode 100644
index 287677d..0000000
--- a/makefile.cygwin_dll
+++ /dev/null
@@ -1,90 +0,0 @@
-#makefile for Cygwin [makes a .dll]
-
-default: ltc_dll
-
-
-# Compilation flags. Note the += does not write over the user's CFLAGS!
-CFLAGS += -I./ -Wall -Wsign-compare -W -Wno-unused -Wshadow -mno-cygwin -DWIN32
-
-# optimize for SPEED
-#CFLAGS += -O3 -funroll-loops
-
-#add -fomit-frame-pointer.  v3.2 is buggy for certain platforms!
-#CFLAGS += -fomit-frame-pointer
-
-# optimize for SIZE
-CFLAGS += -Os
-
-#Leave MPI built-in or force developer to link against libtommath?
-MPIOBJECT=mpi.o
-
-OBJECTS=error_to_string.o mpi_to_ltc_error.o base64_encode.o base64_decode.o \
-\
-crypt.o                    crypt_find_cipher.o      crypt_find_hash_any.o      \
-crypt_hash_is_valid.o      crypt_register_hash.o    crypt_unregister_prng.o    \
-crypt_argchk.o             crypt_find_cipher_any.o  crypt_find_hash_id.o       \
-crypt_prng_descriptor.o    crypt_register_prng.o    crypt_cipher_descriptor.o  \
-crypt_find_cipher_id.o     crypt_find_prng.o        crypt_prng_is_valid.o      \
-crypt_unregister_cipher.o  crypt_cipher_is_valid.o  crypt_find_hash.o          \
-crypt_hash_descriptor.o    crypt_register_cipher.o  crypt_unregister_hash.o    \
-\
-sprng.o yarrow.o rc4.o rng_get_bytes.o  rng_make_prng.o \
-\
-rand_prime.o is_prime.o \
-\
-ecc.o  dh.o \
-\
-rsa_decrypt_key.o  rsa_encrypt_key.o  rsa_exptmod.o  rsa_free.o  rsa_make_key.o  \
-rsa_sign_hash.o  rsa_verify_hash.o rsa_export.o rsa_import.o tim_exptmod.o \
-\
-dsa_export.o  dsa_free.o  dsa_import.o  dsa_make_key.o  dsa_sign_hash.o  \
-dsa_verify_hash.o  dsa_verify_key.o \
-\
-aes.o aes_enc.o \
-\
-blowfish.o des.o safer_tab.o safer.o saferp.o rc2.o xtea.o \
-rc6.o rc5.o cast5.o noekeon.o twofish.o skipjack.o \
-\
-md2.o md4.o md5.o sha1.o sha256.o sha512.o tiger.o whirl.o \
-rmd128.o rmd160.o \
-\
-packet_store_header.o  packet_valid_header.o \
-\
-eax_addheader.o  eax_decrypt.o  eax_decrypt_verify_memory.o  eax_done.o  eax_encrypt.o  \
-eax_encrypt_authenticate_memory.o  eax_init.o  eax_test.o \
-\
-ocb_decrypt.o  ocb_decrypt_verify_memory.o  ocb_done_decrypt.o  ocb_done_encrypt.o  \
-ocb_encrypt.o  ocb_encrypt_authenticate_memory.o  ocb_init.o  ocb_ntz.o  \
-ocb_shift_xor.o  ocb_test.o s_ocb_done.o \
-\
-omac_done.o  omac_file.o  omac_init.o  omac_memory.o  omac_process.o  omac_test.o \
-\
-pmac_done.o  pmac_file.o  pmac_init.o  pmac_memory.o  pmac_ntz.o  pmac_process.o  \
-pmac_shift_xor.o  pmac_test.o \
-\
-cbc_start.o cbc_encrypt.o cbc_decrypt.o cbc_getiv.o cbc_setiv.o \
-cfb_start.o cfb_encrypt.o cfb_decrypt.o cfb_getiv.o cfb_setiv.o \
-ofb_start.o ofb_encrypt.o ofb_decrypt.o ofb_getiv.o ofb_setiv.o \
-ctr_start.o ctr_encrypt.o ctr_decrypt.o ctr_getiv.o ctr_setiv.o \
-ecb_start.o ecb_encrypt.o ecb_decrypt.o \
-\
-hash_file.o  hash_filehandle.o  hash_memory.o \
-\
-hmac_done.o  hmac_file.o  hmac_init.o  hmac_memory.o  hmac_process.o  hmac_test.o \
-\
-pkcs_1_mgf1.o pkcs_1_oaep_encode.o pkcs_1_oaep_decode.o  \
-pkcs_1_pss_encode.o pkcs_1_pss_decode.o pkcs_1_i2osp.o pkcs_1_os2ip.o \
-pkcs_1_v15_es_encode.o pkcs_1_v15_es_decode.o pkcs_1_v15_sa_encode.o pkcs_1_v15_sa_decode.o \
-\
-pkcs_5_1.o pkcs_5_2.o \
-\
-burn_stack.o zeromem.o \
-$(MPIOBJECT)
-
-#ciphers come in two flavours... enc+dec and enc 
-aes_enc.o: aes.c aes_tab.c
-	$(CC) $(CFLAGS) -DENCRYPT_ONLY -c aes.c -o aes_enc.o
-
-ltc_dll: $(OBJECTS) $(MPIOBJECT)
-	gcc -mno-cygwin -mdll -o libtomcrypt.dll -Wl,--out-implib=libtomcrypt.dll.a -Wl,--export-all-symbols *.o -ladvapi32
-	ranlib libtomcrypt.dll.a
diff --git a/makefile.icc b/makefile.icc
index 208a3cf..a9ab38f 100644
--- a/makefile.icc
+++ b/makefile.icc
@@ -22,7 +22,7 @@
 #ARFLAGS=r
 
 # Compilation flags. Note the += does not write over the user's CFLAGS!
-CFLAGS += -c -I./ -DINTEL_CC
+CFLAGS += -c -Isrc/headers/ -Itestprof/ -DINTEL_CC
 
 #The default rule for make builds the libtomcrypt library.
 default:library
@@ -30,18 +30,24 @@
 # optimize for SPEED
 #
 # -mcpu= can be pentium, pentiumpro (covers PII through PIII) or pentium4
-# -ax?   specifies make code specifically for ? but compatible with IA-32
-# -x?    specifies compile solely for ? [not specifically IA-32 compatible]
+# -ax?	specifies make code specifically for ? but compatible with IA-32
+# -x?	 specifies compile solely for ? [not specifically IA-32 compatible]
 #
 # where ? is 
-#   K - PIII
-#   W - first P4 [Williamette]
-#   N - P4 Northwood
-#   P - P4 Prescott
-#   B - Blend of P4 and PM [mobile]
+#	K - PIII
+#	W - first P4 [Williamette]
+#	N - P4 Northwood
+#	P - P4 Prescott
+#	B - Blend of P4 and PM [mobile]
 #
 # Default to just generic max opts
-CFLAGS += -O3 -xN -ip
+ifdef LTC_SMALL
+CFLAGS += -O2 -xP -ip
+endif
+
+ifndef IGNORE_SPEED
+CFLAGS += -O3 -xP -ip 
+endif
 
 # want to see stuff?
 #CFLAGS += -opt_report
@@ -50,11 +56,15 @@
 
 #Output filenames for various targets.
 LIBNAME=libtomcrypt.a
+LIBTEST=testprof/libtomcrypt_prof.a
 HASH=hashsum
 CRYPT=encrypt
 SMALL=small
 PROF=x86_prof
 TV=tv_gen
+MULTI=multi
+TIMING=timing
+TEST=test
 
 #LIBPATH-The directory for libtomcrypt to be installed to.
 #INCPATH-The directory to install the header files for libtomcrypt.
@@ -67,71 +77,94 @@
 #List of objects to compile.
 
 #Leave MPI built-in or force developer to link against libtommath?
-MPIOBJECT=mpi.o
+MPIOBJECT=src/misc/mpi/mpi.o
 
-OBJECTS=error_to_string.o mpi_to_ltc_error.o base64_encode.o base64_decode.o \
-\
-crypt.o                    crypt_find_cipher.o      crypt_find_hash_any.o      \
-crypt_hash_is_valid.o      crypt_register_hash.o    crypt_unregister_prng.o    \
-crypt_argchk.o             crypt_find_cipher_any.o  crypt_find_hash_id.o       \
-crypt_prng_descriptor.o    crypt_register_prng.o    crypt_cipher_descriptor.o  \
-crypt_find_cipher_id.o     crypt_find_prng.o        crypt_prng_is_valid.o      \
-crypt_unregister_cipher.o  crypt_cipher_is_valid.o  crypt_find_hash.o          \
-crypt_hash_descriptor.o    crypt_register_cipher.o  crypt_unregister_hash.o    \
-\
-sprng.o yarrow.o rc4.o rng_get_bytes.o  rng_make_prng.o \
-\
-rand_prime.o is_prime.o \
-\
-ecc.o  dh.o \
-\
-rsa_decrypt_key.o  rsa_encrypt_key.o  rsa_exptmod.o  rsa_free.o  rsa_make_key.o  \
-rsa_sign_hash.o  rsa_verify_hash.o rsa_export.o rsa_import.o tim_exptmod.o \
-\
-dsa_export.o  dsa_free.o  dsa_import.o  dsa_make_key.o  dsa_sign_hash.o  \
-dsa_verify_hash.o  dsa_verify_key.o \
-\
-aes.o aes_enc.o \
-\
-blowfish.o des.o safer_tab.o safer.o saferp.o rc2.o xtea.o \
-rc6.o rc5.o cast5.o noekeon.o twofish.o skipjack.o \
-\
-md2.o md4.o md5.o sha1.o sha256.o sha512.o tiger.o whirl.o \
-rmd128.o rmd160.o \
-\
-packet_store_header.o  packet_valid_header.o \
-\
-eax_addheader.o  eax_decrypt.o  eax_decrypt_verify_memory.o  eax_done.o  eax_encrypt.o  \
-eax_encrypt_authenticate_memory.o  eax_init.o  eax_test.o \
-\
-ocb_decrypt.o  ocb_decrypt_verify_memory.o  ocb_done_decrypt.o  ocb_done_encrypt.o  \
-ocb_encrypt.o  ocb_encrypt_authenticate_memory.o  ocb_init.o  ocb_ntz.o  \
-ocb_shift_xor.o  ocb_test.o s_ocb_done.o \
-\
-omac_done.o  omac_file.o  omac_init.o  omac_memory.o  omac_process.o  omac_test.o \
-\
-pmac_done.o  pmac_file.o  pmac_init.o  pmac_memory.o  pmac_ntz.o  pmac_process.o  \
-pmac_shift_xor.o  pmac_test.o \
-\
-cbc_start.o cbc_encrypt.o cbc_decrypt.o cbc_getiv.o cbc_setiv.o \
-cfb_start.o cfb_encrypt.o cfb_decrypt.o cfb_getiv.o cfb_setiv.o \
-ofb_start.o ofb_encrypt.o ofb_decrypt.o ofb_getiv.o ofb_setiv.o \
-ctr_start.o ctr_encrypt.o ctr_decrypt.o ctr_getiv.o ctr_setiv.o \
-ecb_start.o ecb_encrypt.o ecb_decrypt.o \
-\
-hash_file.o  hash_filehandle.o  hash_memory.o \
-\
-hmac_done.o  hmac_file.o  hmac_init.o  hmac_memory.o  hmac_process.o  hmac_test.o \
-\
-pkcs_1_mgf1.o pkcs_1_oaep_encode.o pkcs_1_oaep_decode.o  \
-pkcs_1_pss_encode.o pkcs_1_pss_decode.o pkcs_1_i2osp.o pkcs_1_os2ip.o \
-pkcs_1_v15_es_encode.o pkcs_1_v15_es_decode.o pkcs_1_v15_sa_encode.o pkcs_1_v15_sa_decode.o \
-\
-pkcs_5_1.o pkcs_5_2.o \
-\
-burn_stack.o zeromem.o \
-$(MPIOBJECT)
+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 \
+src/ciphers/rc2.o src/ciphers/rc5.o src/ciphers/rc6.o src/ciphers/safer/safer.o \
+src/ciphers/safer/safer_tab.o src/ciphers/safer/saferp.o src/ciphers/skipjack.o \
+src/ciphers/twofish/twofish.o src/ciphers/xtea.o src/encauth/ccm/ccm_memory.o \
+src/encauth/ccm/ccm_test.o src/encauth/eax/eax_addheader.o src/encauth/eax/eax_decrypt.o \
+src/encauth/eax/eax_decrypt_verify_memory.o src/encauth/eax/eax_done.o src/encauth/eax/eax_encrypt.o \
+src/encauth/eax/eax_encrypt_authenticate_memory.o src/encauth/eax/eax_init.o \
+src/encauth/eax/eax_test.o src/encauth/gcm/gcm_add_aad.o src/encauth/gcm/gcm_add_iv.o \
+src/encauth/gcm/gcm_done.o src/encauth/gcm/gcm_gf_mult.o src/encauth/gcm/gcm_init.o \
+src/encauth/gcm/gcm_memory.o src/encauth/gcm/gcm_process.o src/encauth/gcm/gcm_reset.o \
+src/encauth/gcm/gcm_test.o src/encauth/ocb/ocb_decrypt.o src/encauth/ocb/ocb_decrypt_verify_memory.o \
+src/encauth/ocb/ocb_done_decrypt.o src/encauth/ocb/ocb_done_encrypt.o src/encauth/ocb/ocb_encrypt.o \
+src/encauth/ocb/ocb_encrypt_authenticate_memory.o src/encauth/ocb/ocb_init.o src/encauth/ocb/ocb_ntz.o \
+src/encauth/ocb/ocb_shift_xor.o src/encauth/ocb/ocb_test.o src/encauth/ocb/s_ocb_done.o \
+src/hashes/chc/chc.o src/hashes/helper/hash_file.o src/hashes/helper/hash_filehandle.o \
+src/hashes/helper/hash_memory.o src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o \
+src/hashes/md5.o src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/sha1.o src/hashes/sha2/sha256.o \
+src/hashes/sha2/sha512.o src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/hmac/hmac_done.o \
+src/mac/hmac/hmac_file.o src/mac/hmac/hmac_init.o src/mac/hmac/hmac_memory.o \
+src/mac/hmac/hmac_memory_multi.o src/mac/hmac/hmac_process.o src/mac/hmac/hmac_test.o \
+src/mac/omac/omac_done.o src/mac/omac/omac_file.o src/mac/omac/omac_init.o src/mac/omac/omac_memory.o \
+src/mac/omac/omac_memory_multi.o src/mac/omac/omac_process.o src/mac/omac/omac_test.o \
+src/mac/pelican/pelican.o src/mac/pelican/pelican_memory.o src/mac/pelican/pelican_test.o \
+src/mac/pmac/pmac_done.o src/mac/pmac/pmac_file.o src/mac/pmac/pmac_init.o src/mac/pmac/pmac_memory.o \
+src/mac/pmac/pmac_memory_multi.o src/mac/pmac/pmac_ntz.o src/mac/pmac/pmac_process.o \
+src/mac/pmac/pmac_shift_xor.o src/mac/pmac/pmac_test.o src/misc/base64/base64_decode.o \
+src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crypt/crypt.o \
+src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
+src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher.o \
+src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
+src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
+src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_prng.o \
+src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \
+src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \
+src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \
+src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \
+src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \
+src/misc/error_to_string.o src/misc/mpi/is_prime.o src/misc/mpi/mpi_to_ltc_error.o \
+src/misc/mpi/rand_prime.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o src/misc/zeromem.o \
+src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \
+src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \
+src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \
+src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \
+src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
+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/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/choice/der_decode_choice.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/asn1/der/utctime/der_decode_utctime.o \
+src/pk/asn1/der/utctime/der_encode_utctime.o src/pk/asn1/der/utctime/der_length_utctime.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/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
 
 #ciphers come in two flavours... enc+dec and enc 
 aes_enc.o: aes.c aes_tab.c
@@ -140,8 +173,9 @@
 HASHOBJECTS=demos/hashsum.o
 CRYPTOBJECTS=demos/encrypt.o
 SMALLOBJECTS=demos/small.o
-PROFS=demos/x86_prof.o
 TVS=demos/tv_gen.o
+TIMINGS=demos/timing.o
+TESTS=demos/test.o
 
 #Files left over from making the crypt.pdf.
 LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind
@@ -149,25 +183,28 @@
 #Compressed filenames
 COMPRESSED=crypt.tar.bz2 crypt.zip crypt.tar.gz
 
-#Header files used by libtomcrypt.
-HEADERS=tommath.h mycrypt_cfg.h mycrypt_gf.h mycrypt_kr.h \
-mycrypt_misc.h  mycrypt_prng.h mycrypt_cipher.h  mycrypt_hash.h \
-mycrypt_macros.h  mycrypt_pk.h mycrypt.h mycrypt_argchk.h mycrypt_custom.h
+#ciphers come in two flavours... enc+dec and enc 
+src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+	$(CC) $(CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
 
 #These are the rules to make certain object files.
-rsa.o: rsa.c rsa_sys.c
-ecc.o: ecc.c ecc_sys.c
-dh.o: dh.c dh_sys.c
-aes.o: aes.c aes_tab.c
-twofish.o: twofish.c twofish_tab.c
-sha512.o: sha512.c sha384.c
-sha256.o: sha256.c sha224.c
+src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c
+src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c
+src/pk/ecc/ecc.o: src/pk/ecc/ecc.c src/pk/ecc/ecc_sys.c
+src/pk/dh/dh.o: src/pk/dh/dh.c src/pk/dh/dh_sys.c
+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: $(LIBNAME)
+library: $(LIBTEST) $(LIBNAME)
+
+$(LIBTEST):
+	cd testprof ; make -f makefile.icc
 
 $(LIBNAME): $(OBJECTS)
-	$(AR) $(ARFLAGS) $@ $(OBJECTS) 
+	$(AR) $(ARFLAGS) $@ $(OBJECTS)
+	ranlib $(LIBNAME)
 
 #This rule makes the hash program included with libtomcrypt
 hashsum: library $(HASHOBJECTS)
@@ -181,12 +218,14 @@
 small: library $(SMALLOBJECTS)
 	$(CC) $(SMALLOBJECTS) $(LIBNAME) -o $(SMALL) $(WARN)
 	
-x86_prof: library $(PROFS)
-	$(CC) $(PROFS) $(LIBNAME) -o $(PROF)
-
 tv_gen: library $(TVS)
 	$(CC) $(TVS) $(LIBNAME) -o $(TV)
 
+timing: library $(TIMINGS)
+	$(CC) $(TIMINGS) $(LIBTEST) $(LIBNAME) -o $(TIMING)
+
+test: library $(TESTS)
+	$(CC) $(TESTS) $(LIBTEST) $(LIBNAME) -o $(TEST)
   
 #This rule installs the library and the header files. This must be run
 #as root in order to have a high enough permission to write to the correct
@@ -195,11 +234,9 @@
 	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)
 
-#This rule cleans the source tree of all compiled code, not including the pdf
-#documentation.
-clean:
-	rm -f $(OBJECTS) $(TESTOBJECTS) $(HASHOBJECTS) $(CRYPTOBJECTS) $(SMALLOBJECTS) $(LEFTOVERS) $(LIBNAME)
-	rm -f $(TEST) $(HASH) $(COMPRESSED) $(PROFS) $(PROF) $(TVS) $(TV)
-	rm -f *.a *.dll *stackdump *.lib *.exe *.obj demos/*.obj demos/*.o *.bat *.txt *.il *.da demos/*.il demos/*.da *.dyn
+# $Source: /cvs/libtom/libtomcrypt/makefile.icc,v $   
+# $Revision: 1.33 $   
+# $Date: 2005/06/19 18:22:31 $ 
diff --git a/makefile.msvc b/makefile.msvc
index aa8a9bc..ae01079 100644
--- a/makefile.msvc
+++ b/makefile.msvc
@@ -1,88 +1,122 @@
 #MSVC Makefile [tested with MSVC 6.00 with SP5]
 #
 #Tom St Denis
-CFLAGS = /I. /Ox /DWIN32 /W3
+CFLAGS = /Isrc/headers/ /Itestprof/ /Ox /DWIN32 /W3 /Fo$@
 
 default: library
 
 # leave this blank and link against libtommath if you want better link resolution
-MPIOBJECT=mpi.obj
+MPIOBJECT=src/misc/mpi/mpi.obj
 
-OBJECTS=error_to_string.obj mpi_to_ltc_error.obj base64_encode.obj base64_decode.obj \
-\
-crypt.obj                    crypt_find_cipher.obj      crypt_find_hash_any.obj      \
-crypt_hash_is_valid.obj      crypt_register_hash.obj    crypt_unregister_prng.obj    \
-crypt_argchk.obj             crypt_find_cipher_any.obj  crypt_find_hash_id.obj       \
-crypt_prng_descriptor.obj    crypt_register_prng.obj    crypt_cipher_descriptor.obj  \
-crypt_find_cipher_id.obj     crypt_find_prng.obj        crypt_prng_is_valid.obj      \
-crypt_unregister_cipher.obj  crypt_cipher_is_valid.obj  crypt_find_hash.obj          \
-crypt_hash_descriptor.obj    crypt_register_cipher.obj  crypt_unregister_hash.obj    \
-\
-sprng.obj yarrow.obj rc4.obj rng_get_bytes.obj  rng_make_prng.obj \
-\
-rand_prime.obj is_prime.obj \
-\
-ecc.obj  dh.obj \
-\
-rsa_decrypt_key.obj  rsa_encrypt_key.obj  rsa_exptmod.obj  rsa_free.obj  rsa_make_key.obj  \
-rsa_sign_hash.obj  rsa_verify_hash.obj rsa_export.obj rsa_import.obj tim_exptmod.obj \
-\
-dsa_export.obj  dsa_free.obj  dsa_import.obj  dsa_make_key.obj  dsa_sign_hash.obj  \
-dsa_verify_hash.obj  dsa_verify_key.obj \
-\
-aes.obj aes_enc.obj \
-\
-blowfish.obj des.obj safer_tab.obj safer.obj saferp.obj rc2.obj xtea.obj \
-rc6.obj rc5.obj cast5.obj noekeon.obj twofish.obj skipjack.obj \
-\
-md2.obj md4.obj md5.obj sha1.obj sha256.obj sha512.obj tiger.obj whirl.obj \
-rmd128.obj rmd160.obj \
-\
-packet_store_header.obj  packet_valid_header.obj \
-\
-eax_addheader.obj  eax_decrypt.obj  eax_decrypt_verify_memory.obj  eax_done.obj  eax_encrypt.obj  \
-eax_encrypt_authenticate_memory.obj  eax_init.obj  eax_test.obj \
-\
-ocb_decrypt.obj  ocb_decrypt_verify_memory.obj  ocb_done_decrypt.obj  ocb_done_encrypt.obj  \
-ocb_encrypt.obj  ocb_encrypt_authenticate_memory.obj  ocb_init.obj  ocb_ntz.obj  \
-ocb_shift_xor.obj  ocb_test.obj s_ocb_done.obj \
-\
-omac_done.obj  omac_file.obj  omac_init.obj  omac_memory.obj  omac_process.obj  omac_test.obj \
-\
-pmac_done.obj  pmac_file.obj  pmac_init.obj  pmac_memory.obj  pmac_ntz.obj  pmac_process.obj  \
-pmac_shift_xor.obj  pmac_test.obj \
-\
-cbc_start.obj cbc_encrypt.obj cbc_decrypt.obj cbc_getiv.obj cbc_setiv.obj \
-cfb_start.obj cfb_encrypt.obj cfb_decrypt.obj cfb_getiv.obj cfb_setiv.obj \
-ofb_start.obj ofb_encrypt.obj ofb_decrypt.obj ofb_getiv.obj ofb_setiv.obj \
-ctr_start.obj ctr_encrypt.obj ctr_decrypt.obj ctr_getiv.obj ctr_setiv.obj \
-ecb_start.obj ecb_encrypt.obj ecb_decrypt.obj \
-\
-hash_file.obj  hash_filehandle.obj  hash_memory.obj \
-\
-hmac_done.obj  hmac_file.obj  hmac_init.obj  hmac_memory.obj  hmac_process.obj  hmac_test.obj \
-\
-pkcs_1_mgf1.obj pkcs_1_oaep_encode.obj pkcs_1_oaep_decode.obj  \
-pkcs_1_pss_encode.obj pkcs_1_pss_decode.obj pkcs_1_i2osp.obj pkcs_1_os2ip.obj \
-pkcs_1_v15_es_encode.obj pkcs_1_v15_es_decode.obj pkcs_1_v15_sa_encode.obj pkcs_1_v15_sa_decode.obj \
-\
-pkcs_5_1.obj pkcs_5_2.obj \
-\
-burn_stack.obj zeromem.obj \
-$(MPIOBJECT)
+OBJECTS=src/ciphers/aes/aes_enc.obj $(MPIOBJECT) src/ciphers/aes/aes.obj src/ciphers/anubis.obj \
+src/ciphers/blowfish.obj src/ciphers/cast5.obj src/ciphers/des.obj src/ciphers/khazad.obj src/ciphers/noekeon.obj \
+src/ciphers/rc2.obj src/ciphers/rc5.obj src/ciphers/rc6.obj src/ciphers/safer/safer.obj \
+src/ciphers/safer/safer_tab.obj src/ciphers/safer/saferp.obj src/ciphers/skipjack.obj \
+src/ciphers/twofish/twofish.obj src/ciphers/xtea.obj src/encauth/ccm/ccm_memory.obj \
+src/encauth/ccm/ccm_test.obj src/encauth/eax/eax_addheader.obj src/encauth/eax/eax_decrypt.obj \
+src/encauth/eax/eax_decrypt_verify_memory.obj src/encauth/eax/eax_done.obj src/encauth/eax/eax_encrypt.obj \
+src/encauth/eax/eax_encrypt_authenticate_memory.obj src/encauth/eax/eax_init.obj \
+src/encauth/eax/eax_test.obj src/encauth/gcm/gcm_add_aad.obj src/encauth/gcm/gcm_add_iv.obj \
+src/encauth/gcm/gcm_done.obj src/encauth/gcm/gcm_gf_mult.obj src/encauth/gcm/gcm_init.obj \
+src/encauth/gcm/gcm_memory.obj src/encauth/gcm/gcm_process.obj src/encauth/gcm/gcm_reset.obj \
+src/encauth/gcm/gcm_test.obj src/encauth/ocb/ocb_decrypt.obj src/encauth/ocb/ocb_decrypt_verify_memory.obj \
+src/encauth/ocb/ocb_done_decrypt.obj src/encauth/ocb/ocb_done_encrypt.obj src/encauth/ocb/ocb_encrypt.obj \
+src/encauth/ocb/ocb_encrypt_authenticate_memory.obj src/encauth/ocb/ocb_init.obj src/encauth/ocb/ocb_ntz.obj \
+src/encauth/ocb/ocb_shift_xor.obj src/encauth/ocb/ocb_test.obj src/encauth/ocb/s_ocb_done.obj \
+src/hashes/chc/chc.obj src/hashes/helper/hash_file.obj src/hashes/helper/hash_filehandle.obj \
+src/hashes/helper/hash_memory.obj src/hashes/helper/hash_memory_multi.obj src/hashes/md2.obj src/hashes/md4.obj \
+src/hashes/md5.obj src/hashes/rmd128.obj src/hashes/rmd160.obj src/hashes/sha1.obj src/hashes/sha2/sha256.obj \
+src/hashes/sha2/sha512.obj src/hashes/tiger.obj src/hashes/whirl/whirl.obj src/mac/hmac/hmac_done.obj \
+src/mac/hmac/hmac_file.obj src/mac/hmac/hmac_init.obj src/mac/hmac/hmac_memory.obj \
+src/mac/hmac/hmac_memory_multi.obj src/mac/hmac/hmac_process.obj src/mac/hmac/hmac_test.obj \
+src/mac/omac/omac_done.obj src/mac/omac/omac_file.obj src/mac/omac/omac_init.obj src/mac/omac/omac_memory.obj \
+src/mac/omac/omac_memory_multi.obj src/mac/omac/omac_process.obj src/mac/omac/omac_test.obj \
+src/mac/pelican/pelican.obj src/mac/pelican/pelican_memory.obj src/mac/pelican/pelican_test.obj \
+src/mac/pmac/pmac_done.obj src/mac/pmac/pmac_file.obj src/mac/pmac/pmac_init.obj src/mac/pmac/pmac_memory.obj \
+src/mac/pmac/pmac_memory_multi.obj src/mac/pmac/pmac_ntz.obj src/mac/pmac/pmac_process.obj \
+src/mac/pmac/pmac_shift_xor.obj src/mac/pmac/pmac_test.obj src/misc/base64/base64_decode.obj \
+src/misc/base64/base64_encode.obj src/misc/burn_stack.obj src/misc/crypt/crypt.obj \
+src/misc/crypt/crypt_argchk.obj src/misc/crypt/crypt_cipher_descriptor.obj \
+src/misc/crypt/crypt_cipher_is_valid.obj src/misc/crypt/crypt_find_cipher.obj \
+src/misc/crypt/crypt_find_cipher_any.obj src/misc/crypt/crypt_find_cipher_id.obj \
+src/misc/crypt/crypt_find_hash.obj src/misc/crypt/crypt_find_hash_any.obj \
+src/misc/crypt/crypt_find_hash_id.obj src/misc/crypt/crypt_find_prng.obj \
+src/misc/crypt/crypt_hash_descriptor.obj src/misc/crypt/crypt_hash_is_valid.obj \
+src/misc/crypt/crypt_prng_descriptor.obj src/misc/crypt/crypt_prng_is_valid.obj \
+src/misc/crypt/crypt_register_cipher.obj src/misc/crypt/crypt_register_hash.obj \
+src/misc/crypt/crypt_register_prng.obj src/misc/crypt/crypt_unregister_cipher.obj \
+src/misc/crypt/crypt_unregister_hash.obj src/misc/crypt/crypt_unregister_prng.obj \
+src/misc/error_to_string.obj src/misc/mpi/is_prime.obj src/misc/mpi/mpi_to_ltc_error.obj \
+src/misc/mpi/rand_prime.obj src/misc/pkcs5/pkcs_5_1.obj src/misc/pkcs5/pkcs_5_2.obj src/misc/zeromem.obj \
+src/modes/cbc/cbc_decrypt.obj src/modes/cbc/cbc_done.obj src/modes/cbc/cbc_encrypt.obj \
+src/modes/cbc/cbc_getiv.obj src/modes/cbc/cbc_setiv.obj src/modes/cbc/cbc_start.obj \
+src/modes/cfb/cfb_decrypt.obj src/modes/cfb/cfb_done.obj src/modes/cfb/cfb_encrypt.obj \
+src/modes/cfb/cfb_getiv.obj src/modes/cfb/cfb_setiv.obj src/modes/cfb/cfb_start.obj \
+src/modes/ctr/ctr_decrypt.obj src/modes/ctr/ctr_done.obj src/modes/ctr/ctr_encrypt.obj \
+src/modes/ctr/ctr_getiv.obj src/modes/ctr/ctr_setiv.obj src/modes/ctr/ctr_start.obj \
+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/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/choice/der_decode_choice.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/asn1/der/utctime/der_decode_utctime.obj \
+src/pk/asn1/der/utctime/der_encode_utctime.obj src/pk/asn1/der/utctime/der_length_utctime.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/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 
 
-#ciphers come in two flavours... enc+dec and enc 
-aes_enc.obj: aes.c aes_tab.c
-	$(CC) $(CFLAGS) /DENCRYPT_ONLY /c aes.c /Foaes_enc.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
+
+#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
+	$(CC) $(CFLAGS) /DENCRYPT_ONLY /c src/ciphers/aes/aes.c /Fosrc/ciphers/aes/aes_enc.obj
 
 library: $(OBJECTS)
 	lib /out:tomcrypt.lib $(OBJECTS)
+	cd testprof 
+	nmake -f makefile.msvc
+	cd ..
 	
-x86_prof: demos/x86_prof.c library
-	cl $(CFLAGS) demos/x86_prof.c tomcrypt.lib advapi32.lib 
-
 tv_gen: demos/tv_gen.c library
 	cl $(CFLAGS) demos/tv_gen.c tomcrypt.lib advapi32.lib 
 
 hashsum: demos/hashsum.c library
 	cl $(CFLAGS) demos/hashsum.c tomcrypt.lib advapi32.lib
+
+test: demos/test.c library
+	cl $(CFLAGS) demos/test.c testprof/tomcrypt_prof.lib tomcrypt.lib advapi32.lib
+
+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.15 $   
+# $Date: 2005/06/27 12:37:06 $ 
diff --git a/makefile.shared b/makefile.shared
new file mode 100644
index 0000000..62cc87b
--- /dev/null
+++ b/makefile.shared
@@ -0,0 +1,229 @@
+# MAKEFILE for linux GCC
+#
+# This makefile produces a shared object and requires libtool to be installed.
+#
+# Thanks to Zed Shaw for helping debug this on BSD/OSX.  
+# Tom St Denis
+
+# The version
+VERSION=0:105
+
+# Compiler and Linker Names
+CC=libtool --mode=compile gcc
+
+# Compilation flags. Note the += does not write over the user's CFLAGS!
+CFLAGS += -c -I./src/headers/ -Wall -Wsign-compare -W -Wshadow 
+
+# additional warnings (newer GCC 3.4 and higher)
+#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
+
+# add -fomit-frame-pointer.  hinders debugging!
+CFLAGS += -fomit-frame-pointer
+
+# optimize for SIZE
+#CFLAGS += -Os -DLTC_SMALL_CODE
+
+endif
+
+# compile for DEBUGING (required for ccmalloc checking!!!)
+#CFLAGS += -g3
+
+# older GCCs can't handle the "rotate with immediate" ROLc/RORc/etc macros
+# define this to help
+#CFLAGS += -DLTC_NO_ROLC
+
+#Output filenames for various targets.
+LIBTEST=libtomcrypt_prof.la
+LIBNAME=libtomcrypt.la
+HASH=hashsum
+CRYPT=encrypt
+SMALL=small
+PROF=x86_prof
+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.
+DESTDIR=
+LIBPATH=/usr/lib
+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
+else 
+#If you don't want mpi.o then add this
+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 \
+src/ciphers/rc2.o src/ciphers/rc5.o src/ciphers/rc6.o src/ciphers/safer/safer.o \
+src/ciphers/safer/safer_tab.o src/ciphers/safer/saferp.o src/ciphers/skipjack.o \
+src/ciphers/twofish/twofish.o src/ciphers/xtea.o src/encauth/ccm/ccm_memory.o \
+src/encauth/ccm/ccm_test.o src/encauth/eax/eax_addheader.o src/encauth/eax/eax_decrypt.o \
+src/encauth/eax/eax_decrypt_verify_memory.o src/encauth/eax/eax_done.o src/encauth/eax/eax_encrypt.o \
+src/encauth/eax/eax_encrypt_authenticate_memory.o src/encauth/eax/eax_init.o \
+src/encauth/eax/eax_test.o src/encauth/gcm/gcm_add_aad.o src/encauth/gcm/gcm_add_iv.o \
+src/encauth/gcm/gcm_done.o src/encauth/gcm/gcm_gf_mult.o src/encauth/gcm/gcm_init.o \
+src/encauth/gcm/gcm_memory.o src/encauth/gcm/gcm_process.o src/encauth/gcm/gcm_reset.o \
+src/encauth/gcm/gcm_test.o src/encauth/ocb/ocb_decrypt.o src/encauth/ocb/ocb_decrypt_verify_memory.o \
+src/encauth/ocb/ocb_done_decrypt.o src/encauth/ocb/ocb_done_encrypt.o src/encauth/ocb/ocb_encrypt.o \
+src/encauth/ocb/ocb_encrypt_authenticate_memory.o src/encauth/ocb/ocb_init.o src/encauth/ocb/ocb_ntz.o \
+src/encauth/ocb/ocb_shift_xor.o src/encauth/ocb/ocb_test.o src/encauth/ocb/s_ocb_done.o \
+src/hashes/chc/chc.o src/hashes/helper/hash_file.o src/hashes/helper/hash_filehandle.o \
+src/hashes/helper/hash_memory.o src/hashes/helper/hash_memory_multi.o src/hashes/md2.o src/hashes/md4.o \
+src/hashes/md5.o src/hashes/rmd128.o src/hashes/rmd160.o src/hashes/sha1.o src/hashes/sha2/sha256.o \
+src/hashes/sha2/sha512.o src/hashes/tiger.o src/hashes/whirl/whirl.o src/mac/hmac/hmac_done.o \
+src/mac/hmac/hmac_file.o src/mac/hmac/hmac_init.o src/mac/hmac/hmac_memory.o \
+src/mac/hmac/hmac_memory_multi.o src/mac/hmac/hmac_process.o src/mac/hmac/hmac_test.o \
+src/mac/omac/omac_done.o src/mac/omac/omac_file.o src/mac/omac/omac_init.o src/mac/omac/omac_memory.o \
+src/mac/omac/omac_memory_multi.o src/mac/omac/omac_process.o src/mac/omac/omac_test.o \
+src/mac/pelican/pelican.o src/mac/pelican/pelican_memory.o src/mac/pelican/pelican_test.o \
+src/mac/pmac/pmac_done.o src/mac/pmac/pmac_file.o src/mac/pmac/pmac_init.o src/mac/pmac/pmac_memory.o \
+src/mac/pmac/pmac_memory_multi.o src/mac/pmac/pmac_ntz.o src/mac/pmac/pmac_process.o \
+src/mac/pmac/pmac_shift_xor.o src/mac/pmac/pmac_test.o src/misc/base64/base64_decode.o \
+src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/crypt/crypt.o \
+src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
+src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher.o \
+src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
+src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
+src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_prng.o \
+src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \
+src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \
+src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \
+src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \
+src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \
+src/misc/error_to_string.o src/misc/mpi/is_prime.o src/misc/mpi/mpi_to_ltc_error.o \
+src/misc/mpi/rand_prime.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o src/misc/zeromem.o \
+src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \
+src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \
+src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \
+src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \
+src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \
+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/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/choice/der_decode_choice.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/asn1/der/utctime/der_decode_utctime.o \
+src/pk/asn1/der/utctime/der_encode_utctime.o src/pk/asn1/der/utctime/der_length_utctime.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/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
+
+TESTOBJECTS=demos/test.o
+HASHOBJECTS=demos/hashsum.o
+CRYPTOBJECTS=demos/encrypt.o
+SMALLOBJECTS=demos/small.o
+TVS=demos/tv_gen.o
+TESTS=demos/test.o
+TIMINGS=demos/timing.o
+
+#The default rule for make builds the libtomcrypt library.
+default:library
+
+#ciphers come in two flavours... enc+dec and enc 
+src/ciphers/aes/aes_enc.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+	$(CC) $(CFLAGS) -DENCRYPT_ONLY -c src/ciphers/aes/aes.c -o src/ciphers/aes/aes_enc.o
+
+#These are the rules to make certain object files.
+src/ciphers/aes/aes.o: src/ciphers/aes/aes.c src/ciphers/aes/aes_tab.c
+src/ciphers/twofish/twofish.o: src/ciphers/twofish/twofish.c src/ciphers/twofish/twofish_tab.c
+src/hashes/whirl/whirl.o: src/hashes/whirl/whirl.c src/hashes/whirl/whirltab.c
+src/pk/ecc/ecc.o: src/pk/ecc/ecc.c src/pk/ecc/ecc_sys.c
+src/pk/dh/dh.o: src/pk/dh/dh.c src/pk/dh/dh_sys.c
+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: $(LIBNAME)
+
+$(LIBTEST):
+	cd testprof ; CFLAGS="$(CFLAGS)" GROUP=$(GROUP) USER=$(USER) VERSION=$(VERSION) LIBPATH=$(LIBPATH) LIBNAME=$(LIBTEST) make -f makefile.shared
+
+$(LIBNAME): $(OBJECTS)
+	libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]lo" | grep "src/" | xargs` -o libtomcrypt.la -rpath $(LIBPATH) -version-info $(VERSION)
+	libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]o" | grep "src/" | xargs`  -o libtomcrypt.a
+	ranlib libtomcrypt.a
+	libtool --silent --mode=install install -c libtomcrypt.la $(LIBPATH)/libtomcrypt.la
+	install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
+	install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
+
+#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 $(MPISHARED)
+
+#makes the crypt program
+crypt: library 
+	gcc $(CFLAGS) demos/encrypt.c -o encrypt.o
+	gcc -o crypt encrypt.o -ltomcrypt $(MPISHARED)
+
+tv_gen: library $(TVS)
+	gcc -o tv_gen $(TVS) -ltomcrypt $(MPISHARED)
+
+test: library $(LIBTEST) $(TESTS)
+	gcc -o $(TEST) $(TESTS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+
+timing: library $(LIBTEST) $(TIMINGS)
+	gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+
+# $Source: /cvs/libtom/libtomcrypt/makefile.shared,v $   
+# $Revision: 1.19 $   
+# $Date: 2005/06/27 12:37:06 $ 
diff --git a/mess.sh b/mess.sh
new file mode 100644
index 0000000..bf639ce
--- /dev/null
+++ b/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
+
+
diff --git a/modes_test.c b/modes_test.c
deleted file mode 100644
index d2c8920..0000000
--- a/modes_test.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* test CFB/OFB/CBC modes */
-#include "test.h"
-
-int modes_test(void)
-{
-   unsigned char pt[64], ct[64], tmp[64], key[16], iv[16];
-   int x, cipher_idx;
-   symmetric_CBC cbc;
-   
-   /* make a random pt, key and iv */
-   yarrow_read(pt, 64,  &test_yarrow);
-   yarrow_read(key, 16, &test_yarrow);
-   yarrow_read(iv, 16,  &test_yarrow);
-   
-/* test CBC mode */
-   cipher_idx = find_cipher("aes");
-   if (cipher_idx == -1) {
-      printf("test requires AES");
-      return 1;
-   }
-   
-   
-   /* encode the block */
-   DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
-   for (x = 0; x < 4; x++) {
-      DO(cbc_encrypt(pt+x*16, ct+x*16, &cbc));
-   }
-   
-   /* decode the block */
-   DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
-   for (x = 0; x < 4; x++) {
-      DO(cbc_decrypt(ct+x*16, tmp+x*16, &cbc));
-   }
-   if (memcmp(tmp, pt, 64) != 0) {
-      printf("CBC failed");
-      return 1;
-   }
-   
-/*   
-   extern int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
-                     int keylen, int num_rounds, symmetric_CBC *cbc);
-extern int cbc_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_CBC *cbc);
-extern int cbc_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_CBC *cbc);
-*/
-
-}
diff --git a/mpi.c b/mpi.c
deleted file mode 100644
index 7845a27..0000000
--- a/mpi.c
+++ /dev/null
@@ -1,8416 +0,0 @@
-/* Start: bn_error.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-static const struct {
-     int code;
-     char *msg;
-} msgs[] = {
-     { MP_OKAY, "Successful" },
-     { MP_MEM,  "Out of heap" },
-     { MP_VAL,  "Value out of range" }
-};
-
-/* return a char * string for a given code */
-char *mp_error_to_string(int code)
-{
-   int x;
-
-   /* scan the lookup table for the given message */
-   for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) {
-       if (msgs[x].code == code) {
-          return msgs[x].msg;
-       }
-   }
-
-   /* generic reply for invalid code */
-   return "Invalid error code";
-}
-
-
-/* End: bn_error.c */
-
-/* Start: bn_fast_mp_invmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes the modular inverse via binary extended euclidean algorithm, 
- * that is c = 1/a mod b 
- *
- * Based on mp_invmod except this is optimized for the case where b is 
- * odd as per HAC Note 14.64 on pp. 610
- */
-int
-fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
-{
-  mp_int  x, y, u, v, B, D;
-  int     res, neg;
-
-  /* 2. [modified] b must be odd   */
-  if (mp_iseven (b) == 1) {
-    return MP_VAL;
-  }
-
-  /* init all our temps */
-  if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
-     return res;
-  }
-
-  /* x == modulus, y == value to invert */
-  if ((res = mp_copy (b, &x)) != MP_OKAY) {
-    goto __ERR;
-  }
-
-  /* we need y = |a| */
-  if ((res = mp_abs (a, &y)) != MP_OKAY) {
-    goto __ERR;
-  }
-
-  /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
-  if ((res = mp_copy (&x, &u)) != MP_OKAY) {
-    goto __ERR;
-  }
-  if ((res = mp_copy (&y, &v)) != MP_OKAY) {
-    goto __ERR;
-  }
-  mp_set (&D, 1);
-
-top:
-  /* 4.  while u is even do */
-  while (mp_iseven (&u) == 1) {
-    /* 4.1 u = u/2 */
-    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
-      goto __ERR;
-    }
-    /* 4.2 if B is odd then */
-    if (mp_isodd (&B) == 1) {
-      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
-        goto __ERR;
-      }
-    }
-    /* B = B/2 */
-    if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-
-  /* 5.  while v is even do */
-  while (mp_iseven (&v) == 1) {
-    /* 5.1 v = v/2 */
-    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
-      goto __ERR;
-    }
-    /* 5.2 if D is odd then */
-    if (mp_isodd (&D) == 1) {
-      /* D = (D-x)/2 */
-      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
-        goto __ERR;
-      }
-    }
-    /* D = D/2 */
-    if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-
-  /* 6.  if u >= v then */
-  if (mp_cmp (&u, &v) != MP_LT) {
-    /* u = u - v, B = B - D */
-    if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
-      goto __ERR;
-    }
-
-    if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
-      goto __ERR;
-    }
-  } else {
-    /* v - v - u, D = D - B */
-    if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
-      goto __ERR;
-    }
-
-    if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-
-  /* if not zero goto step 4 */
-  if (mp_iszero (&u) == 0) {
-    goto top;
-  }
-
-  /* now a = C, b = D, gcd == g*v */
-
-  /* if v != 1 then there is no inverse */
-  if (mp_cmp_d (&v, 1) != MP_EQ) {
-    res = MP_VAL;
-    goto __ERR;
-  }
-
-  /* b is now the inverse */
-  neg = a->sign;
-  while (D.sign == MP_NEG) {
-    if ((res = mp_add (&D, b, &D)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-  mp_exch (&D, c);
-  c->sign = neg;
-  res = MP_OKAY;
-
-__ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
-  return res;
-}
-
-/* End: bn_fast_mp_invmod.c */
-
-/* Start: bn_fast_mp_montgomery_reduce.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes xR**-1 == x (mod N) via Montgomery Reduction
- *
- * This is an optimized implementation of mp_montgomery_reduce
- * which uses the comba method to quickly calculate the columns of the
- * reduction.
- *
- * Based on Algorithm 14.32 on pp.601 of HAC.
-*/
-int
-fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
-{
-  int     ix, res, olduse;
-  mp_word W[MP_WARRAY];
-
-  /* get old used count */
-  olduse = x->used;
-
-  /* grow a as required */
-  if (x->alloc < n->used + 1) {
-    if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* first we have to get the digits of the input into
-   * an array of double precision words W[...]
-   */
-  {
-    register mp_word *_W;
-    register mp_digit *tmpx;
-
-    /* alias for the W[] array */
-    _W   = W;
-
-    /* alias for the digits of  x*/
-    tmpx = x->dp;
-
-    /* copy the digits of a into W[0..a->used-1] */
-    for (ix = 0; ix < x->used; ix++) {
-      *_W++ = *tmpx++;
-    }
-
-    /* zero the high words of W[a->used..m->used*2] */
-    for (; ix < n->used * 2 + 1; ix++) {
-      *_W++ = 0;
-    }
-  }
-
-  /* now we proceed to zero successive digits
-   * from the least significant upwards
-   */
-  for (ix = 0; ix < n->used; ix++) {
-    /* mu = ai * m' mod b
-     *
-     * We avoid a double precision multiplication (which isn't required)
-     * by casting the value down to a mp_digit.  Note this requires
-     * that W[ix-1] have  the carry cleared (see after the inner loop)
-     */
-    register mp_digit mu;
-    mu = (mp_digit) (((W[ix] & MP_MASK) * rho) & MP_MASK);
-
-    /* a = a + mu * m * b**i
-     *
-     * This is computed in place and on the fly.  The multiplication
-     * by b**i is handled by offseting which columns the results
-     * are added to.
-     *
-     * Note the comba method normally doesn't handle carries in the
-     * inner loop In this case we fix the carry from the previous
-     * column since the Montgomery reduction requires digits of the
-     * result (so far) [see above] to work.  This is
-     * handled by fixing up one carry after the inner loop.  The
-     * carry fixups are done in order so after these loops the
-     * first m->used words of W[] have the carries fixed
-     */
-    {
-      register int iy;
-      register mp_digit *tmpn;
-      register mp_word *_W;
-
-      /* alias for the digits of the modulus */
-      tmpn = n->dp;
-
-      /* Alias for the columns set by an offset of ix */
-      _W = W + ix;
-
-      /* inner loop */
-      for (iy = 0; iy < n->used; iy++) {
-          *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++);
-      }
-    }
-
-    /* now fix carry for next digit, W[ix+1] */
-    W[ix + 1] += W[ix] >> ((mp_word) DIGIT_BIT);
-  }
-
-  /* now we have to propagate the carries and
-   * shift the words downward [all those least
-   * significant digits we zeroed].
-   */
-  {
-    register mp_digit *tmpx;
-    register mp_word *_W, *_W1;
-
-    /* nox fix rest of carries */
-
-    /* alias for current word */
-    _W1 = W + ix;
-
-    /* alias for next word, where the carry goes */
-    _W = W + ++ix;
-
-    for (; ix <= n->used * 2 + 1; ix++) {
-      *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT);
-    }
-
-    /* copy out, A = A/b**n
-     *
-     * The result is A/b**n but instead of converting from an
-     * array of mp_word to mp_digit than calling mp_rshd
-     * we just copy them in the right order
-     */
-
-    /* alias for destination word */
-    tmpx = x->dp;
-
-    /* alias for shifted double precision result */
-    _W = W + n->used;
-
-    for (ix = 0; ix < n->used + 1; ix++) {
-      *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK));
-    }
-
-    /* zero oldused digits, if the input a was larger than
-     * m->used+1 we'll have to clear the digits
-     */
-    for (; ix < olduse; ix++) {
-      *tmpx++ = 0;
-    }
-  }
-
-  /* set the max used and clamp */
-  x->used = n->used + 1;
-  mp_clamp (x);
-
-  /* if A >= m then A = A - m */
-  if (mp_cmp_mag (x, n) != MP_LT) {
-    return s_mp_sub (x, n, x);
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_fast_mp_montgomery_reduce.c */
-
-/* Start: bn_fast_s_mp_mul_digs.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Fast (comba) multiplier
- *
- * This is the fast column-array [comba] multiplier.  It is 
- * designed to compute the columns of the product first 
- * then handle the carries afterwards.  This has the effect 
- * of making the nested loops that compute the columns very
- * simple and schedulable on super-scalar processors.
- *
- * This has been modified to produce a variable number of 
- * digits of output so if say only a half-product is required 
- * you don't have to compute the upper half (a feature 
- * required for fast Barrett reduction).
- *
- * Based on Algorithm 14.12 on pp.595 of HAC.
- *
- */
-int
-fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
-{
-  int     olduse, res, pa, ix;
-  mp_word W[MP_WARRAY];
-
-  /* grow the destination as required */
-  if (c->alloc < digs) {
-    if ((res = mp_grow (c, digs)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* clear temp buf (the columns) */
-  memset (W, 0, sizeof (mp_word) * digs);
-
-  /* calculate the columns */
-  pa = a->used;
-  for (ix = 0; ix < pa; ix++) {
-    /* this multiplier has been modified to allow you to 
-     * control how many digits of output are produced.  
-     * So at most we want to make upto "digs" digits of output.
-     *
-     * this adds products to distinct columns (at ix+iy) of W
-     * note that each step through the loop is not dependent on
-     * the previous which means the compiler can easily unroll
-     * the loop without scheduling problems
-     */
-    {
-      register mp_digit tmpx, *tmpy;
-      register mp_word *_W;
-      register int iy, pb;
-
-      /* alias for the the word on the left e.g. A[ix] * A[iy] */
-      tmpx = a->dp[ix];
-
-      /* alias for the right side */
-      tmpy = b->dp;
-
-      /* alias for the columns, each step through the loop adds a new
-         term to each column
-       */
-      _W = W + ix;
-
-      /* the number of digits is limited by their placement.  E.g.
-         we avoid multiplying digits that will end up above the # of
-         digits of precision requested
-       */
-      pb = MIN (b->used, digs - ix);
-
-      for (iy = 0; iy < pb; iy++) {
-        *_W++ += ((mp_word)tmpx) * ((mp_word)*tmpy++);
-      }
-    }
-
-  }
-
-  /* setup dest */
-  olduse  = c->used;
-  c->used = digs;
-
-  {
-    register mp_digit *tmpc;
-
-    /* At this point W[] contains the sums of each column.  To get the
-     * correct result we must take the extra bits from each column and
-     * carry them down
-     *
-     * Note that while this adds extra code to the multiplier it 
-     * saves time since the carry propagation is removed from the 
-     * above nested loop.This has the effect of reducing the work 
-     * from N*(N+N*c)==N**2 + c*N**2 to N**2 + N*c where c is the 
-     * cost of the shifting.  On very small numbers this is slower 
-     * but on most cryptographic size numbers it is faster.
-     *
-     * In this particular implementation we feed the carries from
-     * behind which means when the loop terminates we still have one
-     * last digit to copy
-     */
-    tmpc = c->dp;
-    for (ix = 1; ix < digs; ix++) {
-      /* forward the carry from the previous temp */
-      W[ix] += (W[ix - 1] >> ((mp_word) DIGIT_BIT));
-
-      /* now extract the previous digit [below the carry] */
-      *tmpc++ = (mp_digit) (W[ix - 1] & ((mp_word) MP_MASK));
-    }
-    /* fetch the last digit */
-    *tmpc++ = (mp_digit) (W[digs - 1] & ((mp_word) MP_MASK));
-
-    /* clear unused digits [that existed in the old copy of c] */
-    for (; ix < olduse; ix++) {
-      *tmpc++ = 0;
-    }
-  }
-  mp_clamp (c);
-  return MP_OKAY;
-}
-
-/* End: bn_fast_s_mp_mul_digs.c */
-
-/* Start: bn_fast_s_mp_mul_high_digs.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
- #include <ltc_tommath.h>
-
-/* this is a modified version of fast_s_mp_mul_digs that only produces
- * output digits *above* digs.  See the comments for fast_s_mp_mul_digs
- * to see how it works.
- *
- * This is used in the Barrett reduction since for one of the multiplications
- * only the higher digits were needed.  This essentially halves the work.
- *
- * Based on Algorithm 14.12 on pp.595 of HAC.
- */
-int
-fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
-{
-  int     oldused, newused, res, pa, pb, ix;
-  mp_word W[MP_WARRAY];
-
-  /* calculate size of product and allocate more space if required */
-  newused = a->used + b->used + 1;
-  if (c->alloc < newused) {
-    if ((res = mp_grow (c, newused)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* like the other comba method we compute the columns first */
-  pa = a->used;
-  pb = b->used;
-  memset (W + digs, 0, (pa + pb + 1 - digs) * sizeof (mp_word));
-  for (ix = 0; ix < pa; ix++) {
-    {
-      register mp_digit tmpx, *tmpy;
-      register int iy;
-      register mp_word *_W;
-
-      /* work todo, that is we only calculate digits that are at "digs" or above  */
-      iy = digs - ix;
-
-      /* copy of word on the left of A[ix] * B[iy] */
-      tmpx = a->dp[ix];
-
-      /* alias for right side */
-      tmpy = b->dp + iy;
-     
-      /* alias for the columns of output.  Offset to be equal to or above the 
-       * smallest digit place requested 
-       */
-      _W = W + digs;     
-      
-      /* skip cases below zero where ix > digs */
-      if (iy < 0) {
-         iy    = abs(iy);
-         tmpy += iy;
-         _W   += iy;
-         iy    = 0;
-      }
-
-      /* compute column products for digits above the minimum */
-      for (; iy < pb; iy++) {
-         *_W++ += ((mp_word) tmpx) * ((mp_word)*tmpy++);
-      }
-    }
-  }
-
-  /* setup dest */
-  oldused = c->used;
-  c->used = newused;
-
-  /* now convert the array W downto what we need
-   *
-   * See comments in bn_fast_s_mp_mul_digs.c
-   */
-  for (ix = digs + 1; ix < newused; ix++) {
-    W[ix] += (W[ix - 1] >> ((mp_word) DIGIT_BIT));
-    c->dp[ix - 1] = (mp_digit) (W[ix - 1] & ((mp_word) MP_MASK));
-  }
-  c->dp[newused - 1] = (mp_digit) (W[newused - 1] & ((mp_word) MP_MASK));
-
-  for (; ix < oldused; ix++) {
-    c->dp[ix] = 0;
-  }
-  mp_clamp (c);
-  return MP_OKAY;
-}
-
-/* End: bn_fast_s_mp_mul_high_digs.c */
-
-/* Start: bn_fast_s_mp_sqr.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* fast squaring
- *
- * This is the comba method where the columns of the product
- * are computed first then the carries are computed.  This
- * has the effect of making a very simple inner loop that
- * is executed the most
- *
- * W2 represents the outer products and W the inner.
- *
- * A further optimizations is made because the inner
- * products are of the form "A * B * 2".  The *2 part does
- * not need to be computed until the end which is good
- * because 64-bit shifts are slow!
- *
- * Based on Algorithm 14.16 on pp.597 of HAC.
- *
- */
-int fast_s_mp_sqr (mp_int * a, mp_int * b)
-{
-  int     olduse, newused, res, ix, pa;
-  mp_word W2[MP_WARRAY], W[MP_WARRAY];
-
-  /* calculate size of product and allocate as required */
-  pa = a->used;
-  newused = pa + pa + 1;
-  if (b->alloc < newused) {
-    if ((res = mp_grow (b, newused)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* zero temp buffer (columns)
-   * Note that there are two buffers.  Since squaring requires
-   * a outer and inner product and the inner product requires
-   * computing a product and doubling it (a relatively expensive
-   * op to perform n**2 times if you don't have to) the inner and
-   * outer products are computed in different buffers.  This way
-   * the inner product can be doubled using n doublings instead of
-   * n**2
-   */
-  memset (W,  0, newused * sizeof (mp_word));
-  memset (W2, 0, newused * sizeof (mp_word));
-
-  /* This computes the inner product.  To simplify the inner N**2 loop
-   * the multiplication by two is done afterwards in the N loop.
-   */
-  for (ix = 0; ix < pa; ix++) {
-    /* compute the outer product
-     *
-     * Note that every outer product is computed
-     * for a particular column only once which means that
-     * there is no need todo a double precision addition
-     * into the W2[] array.
-     */
-    W2[ix + ix] = ((mp_word)a->dp[ix]) * ((mp_word)a->dp[ix]);
-
-    {
-      register mp_digit tmpx, *tmpy;
-      register mp_word *_W;
-      register int iy;
-
-      /* copy of left side */
-      tmpx = a->dp[ix];
-
-      /* alias for right side */
-      tmpy = a->dp + (ix + 1);
-
-      /* the column to store the result in */
-      _W = W + (ix + ix + 1);
-
-      /* inner products */
-      for (iy = ix + 1; iy < pa; iy++) {
-          *_W++ += ((mp_word)tmpx) * ((mp_word)*tmpy++);
-      }
-    }
-  }
-
-  /* setup dest */
-  olduse  = b->used;
-  b->used = newused;
-
-  /* now compute digits
-   *
-   * We have to double the inner product sums, add in the
-   * outer product sums, propagate carries and convert
-   * to single precision.
-   */
-  {
-    register mp_digit *tmpb;
-
-    /* double first value, since the inner products are
-     * half of what they should be
-     */
-    W[0] += W[0] + W2[0];
-
-    tmpb = b->dp;
-    for (ix = 1; ix < newused; ix++) {
-      /* double/add next digit */
-      W[ix] += W[ix] + W2[ix];
-
-      /* propagate carry forwards [from the previous digit] */
-      W[ix] = W[ix] + (W[ix - 1] >> ((mp_word) DIGIT_BIT));
-
-      /* store the current digit now that the carry isn't
-       * needed
-       */
-      *tmpb++ = (mp_digit) (W[ix - 1] & ((mp_word) MP_MASK));
-    }
-    /* set the last value.  Note even if the carry is zero
-     * this is required since the next step will not zero
-     * it if b originally had a value at b->dp[2*a.used]
-     */
-    *tmpb++ = (mp_digit) (W[(newused) - 1] & ((mp_word) MP_MASK));
-
-    /* clear high digits of b if there were any originally */
-    for (; ix < olduse; ix++) {
-      *tmpb++ = 0;
-    }
-  }
-
-  mp_clamp (b);
-  return MP_OKAY;
-}
-
-/* End: bn_fast_s_mp_sqr.c */
-
-/* Start: bn_mp_2expt.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes a = 2**b 
- *
- * Simple algorithm which zeroes the int, grows it then just sets one bit
- * as required.
- */
-int
-mp_2expt (mp_int * a, int b)
-{
-  int     res;
-
-  /* zero a as per default */
-  mp_zero (a);
-
-  /* grow a to accomodate the single bit */
-  if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) {
-    return res;
-  }
-
-  /* set the used count of where the bit will go */
-  a->used = b / DIGIT_BIT + 1;
-
-  /* put the single bit in its place */
-  a->dp[b / DIGIT_BIT] = 1 << (b % DIGIT_BIT);
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_2expt.c */
-
-/* Start: bn_mp_abs.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* b = |a| 
- *
- * Simple function copies the input and fixes the sign to positive
- */
-int
-mp_abs (mp_int * a, mp_int * b)
-{
-  int     res;
-
-  /* copy a to b */
-  if (a != b) {
-     if ((res = mp_copy (a, b)) != MP_OKAY) {
-       return res;
-     }
-  }
-
-  /* force the sign of b to positive */
-  b->sign = MP_ZPOS;
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_abs.c */
-
-/* Start: bn_mp_add.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* high level addition (handles signs) */
-int mp_add (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     sa, sb, res;
-
-  /* get sign of both inputs */
-  sa = a->sign;
-  sb = b->sign;
-
-  /* handle two cases, not four */
-  if (sa == sb) {
-    /* both positive or both negative */
-    /* add their magnitudes, copy the sign */
-    c->sign = sa;
-    res = s_mp_add (a, b, c);
-  } else {
-    /* one positive, the other negative */
-    /* subtract the one with the greater magnitude from */
-    /* the one of the lesser magnitude.  The result gets */
-    /* the sign of the one with the greater magnitude. */
-    if (mp_cmp_mag (a, b) == MP_LT) {
-      c->sign = sb;
-      res = s_mp_sub (b, a, c);
-    } else {
-      c->sign = sa;
-      res = s_mp_sub (a, b, c);
-    }
-  }
-  return res;
-}
-
-
-/* End: bn_mp_add.c */
-
-/* Start: bn_mp_add_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* single digit addition */
-int
-mp_add_d (mp_int * a, mp_digit b, mp_int * c)
-{
-  int     res, ix, oldused;
-  mp_digit *tmpa, *tmpc, mu;
-
-  /* grow c as required */
-  if (c->alloc < a->used + 1) {
-     if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
-        return res;
-     }
-  }
-
-  /* if a is negative and |a| >= b, call c = |a| - b */
-  if (a->sign == MP_NEG && (a->used > 1 || a->dp[0] >= b)) {
-     /* temporarily fix sign of a */
-     a->sign = MP_ZPOS;
-
-     /* c = |a| - b */
-     res = mp_sub_d(a, b, c);
-
-     /* fix sign  */
-     a->sign = c->sign = MP_NEG;
-
-     return res;
-  }
-
-  /* old number of used digits in c */
-  oldused = c->used;
-
-  /* sign always positive */
-  c->sign = MP_ZPOS;
-
-  /* source alias */
-  tmpa    = a->dp;
-
-  /* destination alias */
-  tmpc    = c->dp;
-
-  /* if a is positive */
-  if (a->sign == MP_ZPOS) {
-     /* add digit, after this we're propagating
-      * the carry.
-      */
-     *tmpc   = *tmpa++ + b;
-     mu      = *tmpc >> DIGIT_BIT;
-     *tmpc++ &= MP_MASK;
-
-     /* now handle rest of the digits */
-     for (ix = 1; ix < a->used; ix++) {
-        *tmpc   = *tmpa++ + mu;
-        mu      = *tmpc >> DIGIT_BIT;
-        *tmpc++ &= MP_MASK;
-     }
-     /* set final carry */
-     ix++;
-     *tmpc++  = mu;
-
-     /* setup size */
-     c->used = a->used + 1;
-  } else {
-     /* a was negative and |a| < b */
-     c->used  = 1;
-
-     /* the result is a single digit */
-     if (a->used == 1) {
-        *tmpc++  =  b - a->dp[0];
-     } else {
-        *tmpc++  =  b;
-     }
-
-     /* setup count so the clearing of oldused
-      * can fall through correctly
-      */
-     ix       = 1;
-  }
-
-  /* now zero to oldused */
-  while (ix++ < oldused) {
-     *tmpc++ = 0;
-  }
-  mp_clamp(c);
-
-  return MP_OKAY;
-}
-
-
-/* End: bn_mp_add_d.c */
-
-/* Start: bn_mp_addmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* d = a + b (mod c) */
-int
-mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
-{
-  int     res;
-  mp_int  t;
-
-  if ((res = mp_init (&t)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_add (a, b, &t)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-  res = mp_mod (&t, c, d);
-  mp_clear (&t);
-  return res;
-}
-
-/* End: bn_mp_addmod.c */
-
-/* Start: bn_mp_and.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* AND two ints together */
-int
-mp_and (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     res, ix, px;
-  mp_int  t, *x;
-
-  if (a->used > b->used) {
-    if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-      return res;
-    }
-    px = b->used;
-    x = b;
-  } else {
-    if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
-      return res;
-    }
-    px = a->used;
-    x = a;
-  }
-
-  for (ix = 0; ix < px; ix++) {
-    t.dp[ix] &= x->dp[ix];
-  }
-
-  /* zero digits above the last from the smallest mp_int */
-  for (; ix < t.used; ix++) {
-    t.dp[ix] = 0;
-  }
-
-  mp_clamp (&t);
-  mp_exch (c, &t);
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_and.c */
-
-/* Start: bn_mp_clamp.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* trim unused digits 
- *
- * This is used to ensure that leading zero digits are
- * trimed and the leading "used" digit will be non-zero
- * Typically very fast.  Also fixes the sign if there
- * are no more leading digits
- */
-void
-mp_clamp (mp_int * a)
-{
-  /* decrease used while the most significant digit is
-   * zero.
-   */
-  while (a->used > 0 && a->dp[a->used - 1] == 0) {
-    --(a->used);
-  }
-
-  /* reset the sign flag if used == 0 */
-  if (a->used == 0) {
-    a->sign = MP_ZPOS;
-  }
-}
-
-/* End: bn_mp_clamp.c */
-
-/* Start: bn_mp_clear.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* clear one (frees)  */
-void
-mp_clear (mp_int * a)
-{
-  /* only do anything if a hasn't been freed previously */
-  if (a->dp != NULL) {
-    /* first zero the digits */
-    memset (a->dp, 0, sizeof (mp_digit) * a->used);
-
-    /* free ram */
-    XFREE(a->dp);
-
-    /* reset members to make debugging easier */
-    a->dp    = NULL;
-    a->alloc = a->used = 0;
-    a->sign  = MP_ZPOS;
-  }
-}
-
-/* End: bn_mp_clear.c */
-
-/* Start: bn_mp_clear_multi.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-#include <stdarg.h>
-
-void mp_clear_multi(mp_int *mp, ...) 
-{
-    mp_int* next_mp = mp;
-    va_list args;
-    va_start(args, mp);
-    while (next_mp != NULL) {
-        mp_clear(next_mp);
-        next_mp = va_arg(args, mp_int*);
-    }
-    va_end(args);
-}
-
-/* End: bn_mp_clear_multi.c */
-
-/* Start: bn_mp_cmp.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* compare two ints (signed)*/
-int
-mp_cmp (mp_int * a, mp_int * b)
-{
-  /* compare based on sign */
-  if (a->sign != b->sign) {
-     if (a->sign == MP_NEG) {
-        return MP_LT;
-     } else {
-        return MP_GT;
-     }
-  }
-  
-  /* compare digits */
-  if (a->sign == MP_NEG) {
-     /* if negative compare opposite direction */
-     return mp_cmp_mag(b, a);
-  } else {
-     return mp_cmp_mag(a, b);
-  }
-}
-
-/* End: bn_mp_cmp.c */
-
-/* Start: bn_mp_cmp_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* compare a digit */
-int mp_cmp_d(mp_int * a, mp_digit b)
-{
-  /* compare based on sign */
-  if (a->sign == MP_NEG) {
-    return MP_LT;
-  }
-
-  /* compare based on magnitude */
-  if (a->used > 1) {
-    return MP_GT;
-  }
-
-  /* compare the only digit of a to b */
-  if (a->dp[0] > b) {
-    return MP_GT;
-  } else if (a->dp[0] < b) {
-    return MP_LT;
-  } else {
-    return MP_EQ;
-  }
-}
-
-/* End: bn_mp_cmp_d.c */
-
-/* Start: bn_mp_cmp_mag.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* compare maginitude of two ints (unsigned) */
-int mp_cmp_mag (mp_int * a, mp_int * b)
-{
-  int     n;
-  mp_digit *tmpa, *tmpb;
-
-  /* compare based on # of non-zero digits */
-  if (a->used > b->used) {
-    return MP_GT;
-  }
-  
-  if (a->used < b->used) {
-    return MP_LT;
-  }
-
-  /* alias for a */
-  tmpa = a->dp + (a->used - 1);
-
-  /* alias for b */
-  tmpb = b->dp + (a->used - 1);
-
-  /* compare based on digits  */
-  for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
-    if (*tmpa > *tmpb) {
-      return MP_GT;
-    }
-
-    if (*tmpa < *tmpb) {
-      return MP_LT;
-    }
-  }
-  return MP_EQ;
-}
-
-/* End: bn_mp_cmp_mag.c */
-
-/* Start: bn_mp_cnt_lsb.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-static const int lnz[16] = { 
-   4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
-};
-
-/* Counts the number of lsbs which are zero before the first zero bit */
-int mp_cnt_lsb(mp_int *a)
-{
-   int x;
-   mp_digit q, qq;
-
-   /* easy out */
-   if (mp_iszero(a) == 1) {
-      return 0;
-   }
-
-   /* scan lower digits until non-zero */
-   for (x = 0; x < a->used && a->dp[x] == 0; x++);
-   q = a->dp[x];
-   x *= DIGIT_BIT;
-
-   /* now scan this digit until a 1 is found */
-   if ((q & 1) == 0) {
-      do {
-         qq  = q & 15;
-         x  += lnz[qq];
-         q >>= 4;
-      } while (qq == 0);
-   }
-   return x;
-}
-
-
-/* End: bn_mp_cnt_lsb.c */
-
-/* Start: bn_mp_copy.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* copy, b = a */
-int
-mp_copy (mp_int * a, mp_int * b)
-{
-  int     res, n;
-
-  /* if dst == src do nothing */
-  if (a == b) {
-    return MP_OKAY;
-  }
-
-  /* grow dest */
-  if (b->alloc < a->used) {
-     if ((res = mp_grow (b, a->used)) != MP_OKAY) {
-        return res;
-     }
-  }
-
-  /* zero b and copy the parameters over */
-  {
-    register mp_digit *tmpa, *tmpb;
-
-    /* pointer aliases */
-
-    /* source */
-    tmpa = a->dp;
-
-    /* destination */
-    tmpb = b->dp;
-
-    /* copy all the digits */
-    for (n = 0; n < a->used; n++) {
-      *tmpb++ = *tmpa++;
-    }
-
-    /* clear high digits */
-    for (; n < b->used; n++) {
-      *tmpb++ = 0;
-    }
-  }
-
-  /* copy used count and sign */
-  b->used = a->used;
-  b->sign = a->sign;
-  return MP_OKAY;
-}
-
-/* End: bn_mp_copy.c */
-
-/* Start: bn_mp_count_bits.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* returns the number of bits in an int */
-int
-mp_count_bits (mp_int * a)
-{
-  int     r;
-  mp_digit q;
-
-  /* shortcut */
-  if (a->used == 0) {
-    return 0;
-  }
-
-  /* get number of digits and add that */
-  r = (a->used - 1) * DIGIT_BIT;
-  
-  /* take the last digit and count the bits in it */
-  q = a->dp[a->used - 1];
-  while (q > ((mp_digit) 0)) {
-    ++r;
-    q >>= ((mp_digit) 1);
-  }
-  return r;
-}
-
-/* End: bn_mp_count_bits.c */
-
-/* Start: bn_mp_div.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* integer signed division. 
- * c*b + d == a [e.g. a/b, c=quotient, d=remainder]
- * HAC pp.598 Algorithm 14.20
- *
- * Note that the description in HAC is horribly 
- * incomplete.  For example, it doesn't consider 
- * the case where digits are removed from 'x' in 
- * the inner loop.  It also doesn't consider the 
- * case that y has fewer than three digits, etc..
- *
- * The overall algorithm is as described as 
- * 14.20 from HAC but fixed to treat these cases.
-*/
-int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
-{
-  mp_int  q, x, y, t1, t2;
-  int     res, n, t, i, norm, neg;
-
-  /* is divisor zero ? */
-  if (mp_iszero (b) == 1) {
-    return MP_VAL;
-  }
-
-  /* if a < b then q=0, r = a */
-  if (mp_cmp_mag (a, b) == MP_LT) {
-    if (d != NULL) {
-      res = mp_copy (a, d);
-    } else {
-      res = MP_OKAY;
-    }
-    if (c != NULL) {
-      mp_zero (c);
-    }
-    return res;
-  }
-
-  if ((res = mp_init_size (&q, a->used + 2)) != MP_OKAY) {
-    return res;
-  }
-  q.used = a->used + 2;
-
-  if ((res = mp_init (&t1)) != MP_OKAY) {
-    goto __Q;
-  }
-
-  if ((res = mp_init (&t2)) != MP_OKAY) {
-    goto __T1;
-  }
-
-  if ((res = mp_init_copy (&x, a)) != MP_OKAY) {
-    goto __T2;
-  }
-
-  if ((res = mp_init_copy (&y, b)) != MP_OKAY) {
-    goto __X;
-  }
-
-  /* fix the sign */
-  neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
-  x.sign = y.sign = MP_ZPOS;
-
-  /* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
-  norm = mp_count_bits(&y) % DIGIT_BIT;
-  if (norm < (int)(DIGIT_BIT-1)) {
-     norm = (DIGIT_BIT-1) - norm;
-     if ((res = mp_mul_2d (&x, norm, &x)) != MP_OKAY) {
-       goto __Y;
-     }
-     if ((res = mp_mul_2d (&y, norm, &y)) != MP_OKAY) {
-       goto __Y;
-     }
-  } else {
-     norm = 0;
-  }
-
-  /* note hac does 0 based, so if used==5 then its 0,1,2,3,4, e.g. use 4 */
-  n = x.used - 1;
-  t = y.used - 1;
-
-  /* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
-  if ((res = mp_lshd (&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
-    goto __Y;
-  }
-
-  while (mp_cmp (&x, &y) != MP_LT) {
-    ++(q.dp[n - t]);
-    if ((res = mp_sub (&x, &y, &x)) != MP_OKAY) {
-      goto __Y;
-    }
-  }
-
-  /* reset y by shifting it back down */
-  mp_rshd (&y, n - t);
-
-  /* step 3. for i from n down to (t + 1) */
-  for (i = n; i >= (t + 1); i--) {
-    if (i > x.used) {
-      continue;
-    }
-
-    /* step 3.1 if xi == yt then set q{i-t-1} to b-1, 
-     * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
-    if (x.dp[i] == y.dp[t]) {
-      q.dp[i - t - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1);
-    } else {
-      mp_word tmp;
-      tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT);
-      tmp |= ((mp_word) x.dp[i - 1]);
-      tmp /= ((mp_word) y.dp[t]);
-      if (tmp > (mp_word) MP_MASK)
-        tmp = MP_MASK;
-      q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
-    }
-
-    /* while (q{i-t-1} * (yt * b + y{t-1})) > 
-             xi * b**2 + xi-1 * b + xi-2 
-     
-       do q{i-t-1} -= 1; 
-    */
-    q.dp[i - t - 1] = (q.dp[i - t - 1] + 1) & MP_MASK;
-    do {
-      q.dp[i - t - 1] = (q.dp[i - t - 1] - 1) & MP_MASK;
-
-      /* find left hand */
-      mp_zero (&t1);
-      t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1];
-      t1.dp[1] = y.dp[t];
-      t1.used = 2;
-      if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) {
-        goto __Y;
-      }
-
-      /* find right hand */
-      t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2];
-      t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1];
-      t2.dp[2] = x.dp[i];
-      t2.used = 3;
-    } while (mp_cmp_mag(&t1, &t2) == MP_GT);
-
-    /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
-    if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) {
-      goto __Y;
-    }
-
-    if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
-      goto __Y;
-    }
-
-    if ((res = mp_sub (&x, &t1, &x)) != MP_OKAY) {
-      goto __Y;
-    }
-
-    /* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
-    if (x.sign == MP_NEG) {
-      if ((res = mp_copy (&y, &t1)) != MP_OKAY) {
-        goto __Y;
-      }
-      if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
-        goto __Y;
-      }
-      if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
-        goto __Y;
-      }
-
-      q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
-    }
-  }
-
-  /* now q is the quotient and x is the remainder 
-   * [which we have to normalize] 
-   */
-  
-  /* get sign before writing to c */
-  x.sign = a->sign;
-
-  if (c != NULL) {
-    mp_clamp (&q);
-    mp_exch (&q, c);
-    c->sign = neg;
-  }
-
-  if (d != NULL) {
-    mp_div_2d (&x, norm, &x, NULL);
-    mp_exch (&x, d);
-  }
-
-  res = MP_OKAY;
-
-__Y:mp_clear (&y);
-__X:mp_clear (&x);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
-__Q:mp_clear (&q);
-  return res;
-}
-
-/* End: bn_mp_div.c */
-
-/* Start: bn_mp_div_2.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* b = a/2 */
-int mp_div_2(mp_int * a, mp_int * b)
-{
-  int     x, res, oldused;
-
-  /* copy */
-  if (b->alloc < a->used) {
-    if ((res = mp_grow (b, a->used)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  oldused = b->used;
-  b->used = a->used;
-  {
-    register mp_digit r, rr, *tmpa, *tmpb;
-
-    /* source alias */
-    tmpa = a->dp + b->used - 1;
-
-    /* dest alias */
-    tmpb = b->dp + b->used - 1;
-
-    /* carry */
-    r = 0;
-    for (x = b->used - 1; x >= 0; x--) {
-      /* get the carry for the next iteration */
-      rr = *tmpa & 1;
-
-      /* shift the current digit, add in carry and store */
-      *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
-
-      /* forward carry to next iteration */
-      r = rr;
-    }
-
-    /* zero excess digits */
-    tmpb = b->dp + b->used;
-    for (x = b->used; x < oldused; x++) {
-      *tmpb++ = 0;
-    }
-  }
-  b->sign = a->sign;
-  mp_clamp (b);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_div_2.c */
-
-/* Start: bn_mp_div_2d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* shift right by a certain bit count (store quotient in c, optional remainder in d) */
-int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
-{
-  mp_digit D, r, rr;
-  int     x, res;
-  mp_int  t;
-
-
-  /* if the shift count is <= 0 then we do no work */
-  if (b <= 0) {
-    res = mp_copy (a, c);
-    if (d != NULL) {
-      mp_zero (d);
-    }
-    return res;
-  }
-
-  if ((res = mp_init (&t)) != MP_OKAY) {
-    return res;
-  }
-
-  /* get the remainder */
-  if (d != NULL) {
-    if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) {
-      mp_clear (&t);
-      return res;
-    }
-  }
-
-  /* copy */
-  if ((res = mp_copy (a, c)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-
-  /* shift by as many digits in the bit count */
-  if (b >= (int)DIGIT_BIT) {
-    mp_rshd (c, b / DIGIT_BIT);
-  }
-
-  /* shift any bit count < DIGIT_BIT */
-  D = (mp_digit) (b % DIGIT_BIT);
-  if (D != 0) {
-    register mp_digit *tmpc, mask, shift;
-
-    /* mask */
-    mask = (((mp_digit)1) << D) - 1;
-
-    /* shift for lsb */
-    shift = DIGIT_BIT - D;
-
-    /* alias */
-    tmpc = c->dp + (c->used - 1);
-
-    /* carry */
-    r = 0;
-    for (x = c->used - 1; x >= 0; x--) {
-      /* get the lower  bits of this word in a temp */
-      rr = *tmpc & mask;
-
-      /* shift the current word and mix in the carry bits from the previous word */
-      *tmpc = (*tmpc >> D) | (r << shift);
-      --tmpc;
-
-      /* set the carry to the carry bits of the current word found above */
-      r = rr;
-    }
-  }
-  mp_clamp (c);
-  if (d != NULL) {
-    mp_exch (&t, d);
-  }
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_div_2d.c */
-
-/* Start: bn_mp_div_3.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* divide by three (based on routine from MPI and the GMP manual) */
-int
-mp_div_3 (mp_int * a, mp_int *c, mp_digit * d)
-{
-  mp_int   q;
-  mp_word  w, t;
-  mp_digit b;
-  int      res, ix;
-  
-  /* b = 2**DIGIT_BIT / 3 */
-  b = (((mp_word)1) << ((mp_word)DIGIT_BIT)) / ((mp_word)3);
-
-  if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
-     return res;
-  }
-  
-  q.used = a->used;
-  q.sign = a->sign;
-  w = 0;
-  for (ix = a->used - 1; ix >= 0; ix--) {
-     w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]);
-
-     if (w >= 3) {
-        /* multiply w by [1/3] */
-        t = (w * ((mp_word)b)) >> ((mp_word)DIGIT_BIT);
-
-        /* now subtract 3 * [w/3] from w, to get the remainder */
-        w -= t+t+t;
-
-        /* fixup the remainder as required since
-         * the optimization is not exact.
-         */
-        while (w >= 3) {
-           t += 1;
-           w -= 3;
-        }
-      } else {
-        t = 0;
-      }
-      q.dp[ix] = (mp_digit)t;
-  }
-
-  /* [optional] store the remainder */
-  if (d != NULL) {
-     *d = (mp_digit)w;
-  }
-
-  /* [optional] store the quotient */
-  if (c != NULL) {
-     mp_clamp(&q);
-     mp_exch(&q, c);
-  }
-  mp_clear(&q);
-  
-  return res;
-}
-
-
-/* End: bn_mp_div_3.c */
-
-/* Start: bn_mp_div_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-static int s_is_power_of_two(mp_digit b, int *p)
-{
-   int x;
-
-   for (x = 1; x < DIGIT_BIT; x++) {
-      if (b == (((mp_digit)1)<<x)) {
-         *p = x;
-         return 1;
-      }
-   }
-   return 0;
-}
-
-/* single digit division (based on routine from MPI) */
-int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
-{
-  mp_int  q;
-  mp_word w;
-  mp_digit t;
-  int     res, ix;
-
-  /* cannot divide by zero */
-  if (b == 0) {
-     return MP_VAL;
-  }
-
-  /* quick outs */
-  if (b == 1 || mp_iszero(a) == 1) {
-     if (d != NULL) {
-        *d = 0;
-     }
-     if (c != NULL) {
-        return mp_copy(a, c);
-     }
-     return MP_OKAY;
-  }
-
-  /* power of two ? */
-  if (s_is_power_of_two(b, &ix) == 1) {
-     if (d != NULL) {
-        *d = a->dp[0] & ((1<<ix) - 1);
-     }
-     if (c != NULL) {
-        return mp_div_2d(a, ix, c, NULL);
-     }
-     return MP_OKAY;
-  }
-
-  /* three? */
-  if (b == 3) {
-     return mp_div_3(a, c, d);
-  }
-
-  /* no easy answer [c'est la vie].  Just division */
-  if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
-     return res;
-  }
-  
-  q.used = a->used;
-  q.sign = a->sign;
-  w = 0;
-  for (ix = a->used - 1; ix >= 0; ix--) {
-     w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]);
-     
-     if (w >= b) {
-        t = (mp_digit)(w / b);
-        w -= ((mp_word)t) * ((mp_word)b);
-      } else {
-        t = 0;
-      }
-      q.dp[ix] = (mp_digit)t;
-  }
-  
-  if (d != NULL) {
-     *d = (mp_digit)w;
-  }
-  
-  if (c != NULL) {
-     mp_clamp(&q);
-     mp_exch(&q, c);
-  }
-  mp_clear(&q);
-  
-  return res;
-}
-
-
-/* End: bn_mp_div_d.c */
-
-/* Start: bn_mp_dr_is_modulus.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* determines if a number is a valid DR modulus */
-int mp_dr_is_modulus(mp_int *a)
-{
-   int ix;
-
-   /* must be at least two digits */
-   if (a->used < 2) {
-      return 0;
-   }
-
-   /* must be of the form b**k - a [a <= b] so all
-    * but the first digit must be equal to -1 (mod b).
-    */
-   for (ix = 1; ix < a->used; ix++) {
-       if (a->dp[ix] != MP_MASK) {
-          return 0;
-       }
-   }
-   return 1;
-}
-
-
-/* End: bn_mp_dr_is_modulus.c */
-
-/* Start: bn_mp_dr_reduce.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
- *
- * Based on algorithm from the paper
- *
- * "Generating Efficient Primes for Discrete Log Cryptosystems"
- *                 Chae Hoon Lim, Pil Loong Lee,
- *          POSTECH Information Research Laboratories
- *
- * The modulus must be of a special format [see manual]
- *
- * Has been modified to use algorithm 7.10 from the LTM book instead
- *
- * Input x must be in the range 0 <= x <= (n-1)**2
- */
-int
-mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k)
-{
-  int      err, i, m;
-  mp_word  r;
-  mp_digit mu, *tmpx1, *tmpx2;
-
-  /* m = digits in modulus */
-  m = n->used;
-
-  /* ensure that "x" has at least 2m digits */
-  if (x->alloc < m + m) {
-    if ((err = mp_grow (x, m + m)) != MP_OKAY) {
-      return err;
-    }
-  }
-
-/* top of loop, this is where the code resumes if
- * another reduction pass is required.
- */
-top:
-  /* aliases for digits */
-  /* alias for lower half of x */
-  tmpx1 = x->dp;
-
-  /* alias for upper half of x, or x/B**m */
-  tmpx2 = x->dp + m;
-
-  /* set carry to zero */
-  mu = 0;
-
-  /* compute (x mod B**m) + k * [x/B**m] inline and inplace */
-  for (i = 0; i < m; i++) {
-      r         = ((mp_word)*tmpx2++) * ((mp_word)k) + *tmpx1 + mu;
-      *tmpx1++  = (mp_digit)(r & MP_MASK);
-      mu        = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
-  }
-
-  /* set final carry */
-  *tmpx1++ = mu;
-
-  /* zero words above m */
-  for (i = m + 1; i < x->used; i++) {
-      *tmpx1++ = 0;
-  }
-
-  /* clamp, sub and return */
-  mp_clamp (x);
-
-  /* if x >= n then subtract and reduce again
-   * Each successive "recursion" makes the input smaller and smaller.
-   */
-  if (mp_cmp_mag (x, n) != MP_LT) {
-    s_mp_sub(x, n, x);
-    goto top;
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_mp_dr_reduce.c */
-
-/* Start: bn_mp_dr_setup.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* determines the setup value */
-void mp_dr_setup(mp_int *a, mp_digit *d)
-{
-   /* the casts are required if DIGIT_BIT is one less than
-    * the number of bits in a mp_digit [e.g. DIGIT_BIT==31]
-    */
-   *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - 
-        ((mp_word)a->dp[0]));
-}
-
-
-/* End: bn_mp_dr_setup.c */
-
-/* Start: bn_mp_exch.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* swap the elements of two integers, for cases where you can't simply swap the 
- * mp_int pointers around
- */
-void
-mp_exch (mp_int * a, mp_int * b)
-{
-  mp_int  t;
-
-  t  = *a;
-  *a = *b;
-  *b = t;
-}
-
-/* End: bn_mp_exch.c */
-
-/* Start: bn_mp_expt_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* calculate c = a**b  using a square-multiply algorithm */
-int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
-{
-  int     res, x;
-  mp_int  g;
-
-  if ((res = mp_init_copy (&g, a)) != MP_OKAY) {
-    return res;
-  }
-
-  /* set initial result */
-  mp_set (c, 1);
-
-  for (x = 0; x < (int) DIGIT_BIT; x++) {
-    /* square */
-    if ((res = mp_sqr (c, c)) != MP_OKAY) {
-      mp_clear (&g);
-      return res;
-    }
-
-    /* if the bit is set multiply */
-    if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) {
-      if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
-         mp_clear (&g);
-         return res;
-      }
-    }
-
-    /* shift to next bit */
-    b <<= 1;
-  }
-
-  mp_clear (&g);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_expt_d.c */
-
-/* Start: bn_mp_exptmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-
-/* this is a shell function that calls either the normal or Montgomery
- * exptmod functions.  Originally the call to the montgomery code was
- * embedded in the normal function but that wasted alot of stack space
- * for nothing (since 99% of the time the Montgomery code would be called)
- */
-int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
-{
-  int dr;
-
-  /* modulus P must be positive */
-  if (P->sign == MP_NEG) {
-     return MP_VAL;
-  }
-
-  /* if exponent X is negative we have to recurse */
-  if (X->sign == MP_NEG) {
-     mp_int tmpG, tmpX;
-     int err;
-
-     /* first compute 1/G mod P */
-     if ((err = mp_init(&tmpG)) != MP_OKAY) {
-        return err;
-     }
-     if ((err = mp_invmod(G, P, &tmpG)) != MP_OKAY) {
-        mp_clear(&tmpG);
-        return err;
-     }
-
-     /* now get |X| */
-     if ((err = mp_init(&tmpX)) != MP_OKAY) {
-        mp_clear(&tmpG);
-        return err;
-     }
-     if ((err = mp_abs(X, &tmpX)) != MP_OKAY) {
-        mp_clear_multi(&tmpG, &tmpX, NULL);
-        return err;
-     }
-
-     /* and now compute (1/G)**|X| instead of G**X [X < 0] */
-     err = mp_exptmod(&tmpG, &tmpX, P, Y);
-     mp_clear_multi(&tmpG, &tmpX, NULL);
-     return err;
-  }
-
-  /* is it a DR modulus? */
-  dr = mp_dr_is_modulus(P);
-
-  /* if not, is it a uDR modulus? */
-  if (dr == 0) {
-     dr = mp_reduce_is_2k(P) << 1;
-  }
-    
-  /* if the modulus is odd or dr != 0 use the fast method */
-  if (mp_isodd (P) == 1 || dr !=  0) {
-    return mp_exptmod_fast (G, X, P, Y, dr);
-  } else {
-    /* otherwise use the generic Barrett reduction technique */
-    return s_mp_exptmod (G, X, P, Y);
-  }
-}
-
-
-/* End: bn_mp_exptmod.c */
-
-/* Start: bn_mp_exptmod_fast.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
- *
- * Uses a left-to-right k-ary sliding window to compute the modular exponentiation.
- * The value of k changes based on the size of the exponent.
- *
- * Uses Montgomery or Diminished Radix reduction [whichever appropriate]
- */
-
-#ifdef MP_LOW_MEM
-   #define TAB_SIZE 32
-#else
-   #define TAB_SIZE 256
-#endif
-
-int
-mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
-{
-  mp_int  M[TAB_SIZE], res;
-  mp_digit buf, mp;
-  int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
-
-  /* use a pointer to the reduction algorithm.  This allows us to use
-   * one of many reduction algorithms without modding the guts of
-   * the code with if statements everywhere.
-   */
-  int     (*redux)(mp_int*,mp_int*,mp_digit);
-
-  /* find window size */
-  x = mp_count_bits (X);
-  if (x <= 7) {
-    winsize = 2;
-  } else if (x <= 36) {
-    winsize = 3;
-  } else if (x <= 140) {
-    winsize = 4;
-  } else if (x <= 450) {
-    winsize = 5;
-  } else if (x <= 1303) {
-    winsize = 6;
-  } else if (x <= 3529) {
-    winsize = 7;
-  } else {
-    winsize = 8;
-  }
-
-#ifdef MP_LOW_MEM
-  if (winsize > 5) {
-     winsize = 5;
-  }
-#endif
-
-  /* init M array */
-  /* init first cell */
-  if ((err = mp_init(&M[1])) != MP_OKAY) {
-     return err;
-  }
-
-  /* now init the second half of the array */
-  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
-    if ((err = mp_init(&M[x])) != MP_OKAY) {
-      for (y = 1<<(winsize-1); y < x; y++) {
-        mp_clear (&M[y]);
-      }
-      mp_clear(&M[1]);
-      return err;
-    }
-  }
-
-  /* determine and setup reduction code */
-  if (redmode == 0) {
-     /* now setup montgomery  */
-     if ((err = mp_montgomery_setup (P, &mp)) != MP_OKAY) {
-        goto __M;
-     }
-
-     /* automatically pick the comba one if available (saves quite a few calls/ifs) */
-     if (((P->used * 2 + 1) < MP_WARRAY) &&
-          P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
-        redux = fast_mp_montgomery_reduce;
-     } else {
-        /* use slower baseline Montgomery method */
-        redux = mp_montgomery_reduce;
-     }
-  } else if (redmode == 1) {
-     /* setup DR reduction for moduli of the form B**k - b */
-     mp_dr_setup(P, &mp);
-     redux = mp_dr_reduce;
-  } else {
-     /* setup DR reduction for moduli of the form 2**k - b */
-     if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY) {
-        goto __M;
-     }
-     redux = mp_reduce_2k;
-  }
-
-  /* setup result */
-  if ((err = mp_init (&res)) != MP_OKAY) {
-    goto __M;
-  }
-
-  /* create M table
-   *
-   * The M table contains powers of the input base, e.g. M[x] = G^x mod P
-   *
-   * The first half of the table is not computed though accept for M[0] and M[1]
-   */
-
-  if (redmode == 0) {
-     /* now we need R mod m */
-     if ((err = mp_montgomery_calc_normalization (&res, P)) != MP_OKAY) {
-       goto __RES;
-     }
-
-     /* now set M[1] to G * R mod m */
-     if ((err = mp_mulmod (G, &res, P, &M[1])) != MP_OKAY) {
-       goto __RES;
-     }
-  } else {
-     mp_set(&res, 1);
-     if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
-        goto __RES;
-     }
-  }
-
-  /* compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times */
-  if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
-    goto __RES;
-  }
-
-  for (x = 0; x < (winsize - 1); x++) {
-    if ((err = mp_sqr (&M[1 << (winsize - 1)], &M[1 << (winsize - 1)])) != MP_OKAY) {
-      goto __RES;
-    }
-    if ((err = redux (&M[1 << (winsize - 1)], P, mp)) != MP_OKAY) {
-      goto __RES;
-    }
-  }
-
-  /* create upper table */
-  for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
-    if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
-      goto __RES;
-    }
-    if ((err = redux (&M[x], P, mp)) != MP_OKAY) {
-      goto __RES;
-    }
-  }
-
-  /* set initial mode and bit cnt */
-  mode   = 0;
-  bitcnt = 1;
-  buf    = 0;
-  digidx = X->used - 1;
-  bitcpy = 0;
-  bitbuf = 0;
-
-  for (;;) {
-    /* grab next digit as required */
-    if (--bitcnt == 0) {
-      /* if digidx == -1 we are out of digits so break */
-      if (digidx == -1) {
-        break;
-      }
-      /* read next digit and reset bitcnt */
-      buf    = X->dp[digidx--];
-      bitcnt = (int)DIGIT_BIT;
-    }
-
-    /* grab the next msb from the exponent */
-    y     = (mp_digit)(buf >> (DIGIT_BIT - 1)) & 1;
-    buf <<= (mp_digit)1;
-
-    /* if the bit is zero and mode == 0 then we ignore it
-     * These represent the leading zero bits before the first 1 bit
-     * in the exponent.  Technically this opt is not required but it
-     * does lower the # of trivial squaring/reductions used
-     */
-    if (mode == 0 && y == 0) {
-      continue;
-    }
-
-    /* if the bit is zero and mode == 1 then we square */
-    if (mode == 1 && y == 0) {
-      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-        goto __RES;
-      }
-      if ((err = redux (&res, P, mp)) != MP_OKAY) {
-        goto __RES;
-      }
-      continue;
-    }
-
-    /* else we add it to the window */
-    bitbuf |= (y << (winsize - ++bitcpy));
-    mode    = 2;
-
-    if (bitcpy == winsize) {
-      /* ok window is filled so square as required and multiply  */
-      /* square first */
-      for (x = 0; x < winsize; x++) {
-        if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-          goto __RES;
-        }
-        if ((err = redux (&res, P, mp)) != MP_OKAY) {
-          goto __RES;
-        }
-      }
-
-      /* then multiply */
-      if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
-        goto __RES;
-      }
-      if ((err = redux (&res, P, mp)) != MP_OKAY) {
-        goto __RES;
-      }
-
-      /* empty window and reset */
-      bitcpy = 0;
-      bitbuf = 0;
-      mode   = 1;
-    }
-  }
-
-  /* if bits remain then square/multiply */
-  if (mode == 2 && bitcpy > 0) {
-    /* square then multiply if the bit is set */
-    for (x = 0; x < bitcpy; x++) {
-      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-        goto __RES;
-      }
-      if ((err = redux (&res, P, mp)) != MP_OKAY) {
-        goto __RES;
-      }
-
-      /* get next bit of the window */
-      bitbuf <<= 1;
-      if ((bitbuf & (1 << winsize)) != 0) {
-        /* then multiply */
-        if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
-          goto __RES;
-        }
-        if ((err = redux (&res, P, mp)) != MP_OKAY) {
-          goto __RES;
-        }
-      }
-    }
-  }
-
-  if (redmode == 0) {
-     /* fixup result if Montgomery reduction is used
-      * recall that any value in a Montgomery system is
-      * actually multiplied by R mod n.  So we have
-      * to reduce one more time to cancel out the factor
-      * of R.
-      */
-     if ((err = mp_montgomery_reduce (&res, P, mp)) != MP_OKAY) {
-       goto __RES;
-     }
-  }
-
-  /* swap res with Y */
-  mp_exch (&res, Y);
-  err = MP_OKAY;
-__RES:mp_clear (&res);
-__M:
-  mp_clear(&M[1]);
-  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
-    mp_clear (&M[x]);
-  }
-  return err;
-}
-
-/* End: bn_mp_exptmod_fast.c */
-
-/* Start: bn_mp_exteuclid.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Extended euclidean algorithm of (a, b) produces 
-   a*u1 + b*u2 = u3
- */
-int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
-{
-   mp_int u1,u2,u3,v1,v2,v3,t1,t2,t3,q,tmp;
-   int err;
-
-   if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
-      return err;
-   }
-
-   /* initialize, (u1,u2,u3) = (1,0,a) */
-   mp_set(&u1, 1);
-   if ((err = mp_copy(a, &u3)) != MP_OKAY)                                        { goto _ERR; }
-
-   /* initialize, (v1,v2,v3) = (0,1,b) */
-   mp_set(&v2, 1);
-   if ((err = mp_copy(b, &v3)) != MP_OKAY)                                        { goto _ERR; }
-
-   /* loop while v3 != 0 */
-   while (mp_iszero(&v3) == MP_NO) {
-       /* q = u3/v3 */
-       if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)                         { goto _ERR; }
-
-       /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
-       if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
-       if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)                             { goto _ERR; }
-       if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
-       if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)                             { goto _ERR; }
-       if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
-       if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)                             { goto _ERR; }
-
-       /* (u1,u2,u3) = (v1,v2,v3) */
-       if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                                  { goto _ERR; }
-       if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                                  { goto _ERR; }
-       if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                                  { goto _ERR; }
-
-       /* (v1,v2,v3) = (t1,t2,t3) */
-       if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                                  { goto _ERR; }
-       if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                                  { goto _ERR; }
-       if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto _ERR; }
-   }
-
-   /* copy result out */
-   if (U1 != NULL) { mp_exch(U1, &u1); }
-   if (U2 != NULL) { mp_exch(U2, &u2); }
-   if (U3 != NULL) { mp_exch(U3, &u3); }
-
-   err = MP_OKAY;
-_ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
-   return err;
-}
-
-/* End: bn_mp_exteuclid.c */
-
-/* Start: bn_mp_fread.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* read a bigint from a file stream in ASCII */
-int mp_fread(mp_int *a, int radix, FILE *stream)
-{
-   int err, ch, neg, y;
-   
-   /* clear a */
-   mp_zero(a);
-   
-   /* if first digit is - then set negative */
-   ch = fgetc(stream);
-   if (ch == '-') {
-      neg = MP_NEG;
-      ch = fgetc(stream);
-   } else {
-      neg = MP_ZPOS;
-   }
-   
-   for (;;) {
-      /* find y in the radix map */
-      for (y = 0; y < radix; y++) {
-          if (mp_s_rmap[y] == ch) {
-             break;
-          }
-      }
-      if (y == radix) {
-         break;
-      }
-      
-      /* shift up and add */
-      if ((err = mp_mul_d(a, radix, a)) != MP_OKAY) {
-         return err;
-      }
-      if ((err = mp_add_d(a, y, a)) != MP_OKAY) {
-         return err;
-      }
-      
-      ch = fgetc(stream);
-   }
-   if (mp_cmp_d(a, 0) != MP_EQ) {
-      a->sign = neg;
-   }
-   
-   return MP_OKAY;
-}
-
-
-/* End: bn_mp_fread.c */
-
-/* Start: bn_mp_fwrite.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-int mp_fwrite(mp_int *a, int radix, FILE *stream)
-{
-   char *buf;
-   int err, len, x;
-   
-   if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
-      return err;
-   }
-
-   buf = OPT_CAST(char) XMALLOC (len);
-   if (buf == NULL) {
-      return MP_MEM;
-   }
-   
-   if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
-      XFREE (buf);
-      return err;
-   }
-   
-   for (x = 0; x < len; x++) {
-       if (fputc(buf[x], stream) == EOF) {
-          XFREE (buf);
-          return MP_VAL;
-       }
-   }
-   
-   XFREE (buf);
-   return MP_OKAY;
-}
-
-
-/* End: bn_mp_fwrite.c */
-
-/* Start: bn_mp_gcd.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Greatest Common Divisor using the binary method */
-int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
-{
-  mp_int  u, v;
-  int     k, u_lsb, v_lsb, res;
-
-  /* either zero than gcd is the largest */
-  if (mp_iszero (a) == 1 && mp_iszero (b) == 0) {
-    return mp_abs (b, c);
-  }
-  if (mp_iszero (a) == 0 && mp_iszero (b) == 1) {
-    return mp_abs (a, c);
-  }
-
-  /* optimized.  At this point if a == 0 then
-   * b must equal zero too
-   */
-  if (mp_iszero (a) == 1) {
-    mp_zero(c);
-    return MP_OKAY;
-  }
-
-  /* get copies of a and b we can modify */
-  if ((res = mp_init_copy (&u, a)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_init_copy (&v, b)) != MP_OKAY) {
-    goto __U;
-  }
-
-  /* must be positive for the remainder of the algorithm */
-  u.sign = v.sign = MP_ZPOS;
-
-  /* B1.  Find the common power of two for u and v */
-  u_lsb = mp_cnt_lsb(&u);
-  v_lsb = mp_cnt_lsb(&v);
-  k     = MIN(u_lsb, v_lsb);
-
-  if (k > 0) {
-     /* divide the power of two out */
-     if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
-        goto __V;
-     }
-
-     if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
-        goto __V;
-     }
-  }
-
-  /* divide any remaining factors of two out */
-  if (u_lsb != k) {
-     if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
-        goto __V;
-     }
-  }
-
-  if (v_lsb != k) {
-     if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
-        goto __V;
-     }
-  }
-
-  while (mp_iszero(&v) == 0) {
-     /* make sure v is the largest */
-     if (mp_cmp_mag(&u, &v) == MP_GT) {
-        /* swap u and v to make sure v is >= u */
-        mp_exch(&u, &v);
-     }
-     
-     /* subtract smallest from largest */
-     if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
-        goto __V;
-     }
-     
-     /* Divide out all factors of two */
-     if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
-        goto __V;
-     } 
-  } 
-
-  /* multiply by 2**k which we divided out at the beginning */
-  if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) {
-     goto __V;
-  }
-  c->sign = MP_ZPOS;
-  res = MP_OKAY;
-__V:mp_clear (&u);
-__U:mp_clear (&v);
-  return res;
-}
-
-/* End: bn_mp_gcd.c */
-
-/* Start: bn_mp_get_int.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* get the lower 32-bits of an mp_int */
-unsigned long mp_get_int(mp_int * a) 
-{
-  int i;
-  unsigned long res;
-
-  if (a->used == 0) {
-     return 0;
-  }
-
-  /* get number of digits of the lsb we have to read */
-  i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
-
-  /* get most significant digit of result */
-  res = DIGIT(a,i);
-   
-  while (--i >= 0) {
-    res = (res << DIGIT_BIT) | DIGIT(a,i);
-  }
-
-  /* force result to 32-bits always so it is consistent on non 32-bit platforms */
-  return res & 0xFFFFFFFFUL;
-}
-
-/* End: bn_mp_get_int.c */
-
-/* Start: bn_mp_grow.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* grow as required */
-int mp_grow (mp_int * a, int size)
-{
-  int     i;
-  mp_digit *tmp;
-
-  /* if the alloc size is smaller alloc more ram */
-  if (a->alloc < size) {
-    /* ensure there are always at least MP_PREC digits extra on top */
-    size += (MP_PREC * 2) - (size % MP_PREC);
-
-    /* reallocate the array a->dp
-     *
-     * We store the return in a temporary variable
-     * in case the operation failed we don't want
-     * to overwrite the dp member of a.
-     */
-    tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * size);
-    if (tmp == NULL) {
-      /* reallocation failed but "a" is still valid [can be freed] */
-      return MP_MEM;
-    }
-
-    /* reallocation succeeded so set a->dp */
-    a->dp = tmp;
-
-    /* zero excess digits */
-    i        = a->alloc;
-    a->alloc = size;
-    for (; i < a->alloc; i++) {
-      a->dp[i] = 0;
-    }
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_mp_grow.c */
-
-/* Start: bn_mp_init.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* init a new bigint */
-int mp_init (mp_int * a)
-{
-  /* allocate memory required and clear it */
-  a->dp = OPT_CAST(mp_digit) XCALLOC (sizeof (mp_digit), MP_PREC);
-  if (a->dp == NULL) {
-    return MP_MEM;
-  }
-
-  /* set the used to zero, allocated digits to the default precision
-   * and sign to positive */
-  a->used  = 0;
-  a->alloc = MP_PREC;
-  a->sign  = MP_ZPOS;
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_init.c */
-
-/* Start: bn_mp_init_copy.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* creates "a" then copies b into it */
-int mp_init_copy (mp_int * a, mp_int * b)
-{
-  int     res;
-
-  if ((res = mp_init (a)) != MP_OKAY) {
-    return res;
-  }
-  return mp_copy (b, a);
-}
-
-/* End: bn_mp_init_copy.c */
-
-/* Start: bn_mp_init_multi.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-#include <stdarg.h>
-
-int mp_init_multi(mp_int *mp, ...) 
-{
-    mp_err res = MP_OKAY;      /* Assume ok until proven otherwise */
-    int n = 0;                 /* Number of ok inits */
-    mp_int* cur_arg = mp;
-    va_list args;
-
-    va_start(args, mp);        /* init args to next argument from caller */
-    while (cur_arg != NULL) {
-        if (mp_init(cur_arg) != MP_OKAY) {
-            /* Oops - error! Back-track and mp_clear what we already
-               succeeded in init-ing, then return error.
-            */
-            va_list clean_args;
-            
-            /* end the current list */
-            va_end(args);
-            
-            /* now start cleaning up */            
-            cur_arg = mp;
-            va_start(clean_args, mp);
-            while (n--) {
-                mp_clear(cur_arg);
-                cur_arg = va_arg(clean_args, mp_int*);
-            }
-            va_end(clean_args);
-            res = MP_MEM;
-            break;
-        }
-        n++;
-        cur_arg = va_arg(args, mp_int*);
-    }
-    va_end(args);
-    return res;                /* Assumed ok, if error flagged above. */
-}
-
-
-/* End: bn_mp_init_multi.c */
-
-/* Start: bn_mp_init_set.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* initialize and set a digit */
-int mp_init_set (mp_int * a, mp_digit b)
-{
-  int err;
-  if ((err = mp_init(a)) != MP_OKAY) {
-     return err;
-  }
-  mp_set(a, b);
-  return err;
-}
-
-/* End: bn_mp_init_set.c */
-
-/* Start: bn_mp_init_set_int.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* initialize and set a digit */
-int mp_init_set_int (mp_int * a, unsigned long b)
-{
-  int err;
-  if ((err = mp_init(a)) != MP_OKAY) {
-     return err;
-  }
-  return mp_set_int(a, b);
-}
-
-/* End: bn_mp_init_set_int.c */
-
-/* Start: bn_mp_init_size.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* init an mp_init for a given size */
-int mp_init_size (mp_int * a, int size)
-{
-  /* pad size so there are always extra digits */
-  size += (MP_PREC * 2) - (size % MP_PREC);	
-  
-  /* alloc mem */
-  a->dp = OPT_CAST(mp_digit) XCALLOC (sizeof (mp_digit), size);
-  if (a->dp == NULL) {
-    return MP_MEM;
-  }
-  a->used  = 0;
-  a->alloc = size;
-  a->sign  = MP_ZPOS;
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_init_size.c */
-
-/* Start: bn_mp_invmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* hac 14.61, pp608 */
-int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
-{
-  mp_int  x, y, u, v, A, B, C, D;
-  int     res;
-
-  /* b cannot be negative */
-  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
-    return MP_VAL;
-  }
-
-  /* if the modulus is odd we can use a faster routine instead */
-  if (mp_isodd (b) == 1) {
-    return fast_mp_invmod (a, b, c);
-  }
-  
-  /* init temps */
-  if ((res = mp_init_multi(&x, &y, &u, &v, 
-                           &A, &B, &C, &D, NULL)) != MP_OKAY) {
-     return res;
-  }
-
-  /* x = a, y = b */
-  if ((res = mp_copy (a, &x)) != MP_OKAY) {
-    goto __ERR;
-  }
-  if ((res = mp_copy (b, &y)) != MP_OKAY) {
-    goto __ERR;
-  }
-
-  /* 2. [modified] if x,y are both even then return an error! */
-  if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
-    res = MP_VAL;
-    goto __ERR;
-  }
-
-  /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
-  if ((res = mp_copy (&x, &u)) != MP_OKAY) {
-    goto __ERR;
-  }
-  if ((res = mp_copy (&y, &v)) != MP_OKAY) {
-    goto __ERR;
-  }
-  mp_set (&A, 1);
-  mp_set (&D, 1);
-
-top:
-  /* 4.  while u is even do */
-  while (mp_iseven (&u) == 1) {
-    /* 4.1 u = u/2 */
-    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
-      goto __ERR;
-    }
-    /* 4.2 if A or B is odd then */
-    if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
-      /* A = (A+y)/2, B = (B-x)/2 */
-      if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
-         goto __ERR;
-      }
-      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
-         goto __ERR;
-      }
-    }
-    /* A = A/2, B = B/2 */
-    if ((res = mp_div_2 (&A, &A)) != MP_OKAY) {
-      goto __ERR;
-    }
-    if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-
-  /* 5.  while v is even do */
-  while (mp_iseven (&v) == 1) {
-    /* 5.1 v = v/2 */
-    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
-      goto __ERR;
-    }
-    /* 5.2 if C or D is odd then */
-    if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
-      /* C = (C+y)/2, D = (D-x)/2 */
-      if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
-         goto __ERR;
-      }
-      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
-         goto __ERR;
-      }
-    }
-    /* C = C/2, D = D/2 */
-    if ((res = mp_div_2 (&C, &C)) != MP_OKAY) {
-      goto __ERR;
-    }
-    if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-
-  /* 6.  if u >= v then */
-  if (mp_cmp (&u, &v) != MP_LT) {
-    /* u = u - v, A = A - C, B = B - D */
-    if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
-      goto __ERR;
-    }
-
-    if ((res = mp_sub (&A, &C, &A)) != MP_OKAY) {
-      goto __ERR;
-    }
-
-    if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
-      goto __ERR;
-    }
-  } else {
-    /* v - v - u, C = C - A, D = D - B */
-    if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
-      goto __ERR;
-    }
-
-    if ((res = mp_sub (&C, &A, &C)) != MP_OKAY) {
-      goto __ERR;
-    }
-
-    if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
-      goto __ERR;
-    }
-  }
-
-  /* if not zero goto step 4 */
-  if (mp_iszero (&u) == 0)
-    goto top;
-
-  /* now a = C, b = D, gcd == g*v */
-
-  /* if v != 1 then there is no inverse */
-  if (mp_cmp_d (&v, 1) != MP_EQ) {
-    res = MP_VAL;
-    goto __ERR;
-  }
-
-  /* if its too low */
-  while (mp_cmp_d(&C, 0) == MP_LT) {
-      if ((res = mp_add(&C, b, &C)) != MP_OKAY) {
-         goto __ERR;
-      }
-  }
-  
-  /* too big */
-  while (mp_cmp_mag(&C, b) != MP_LT) {
-      if ((res = mp_sub(&C, b, &C)) != MP_OKAY) {
-         goto __ERR;
-      }
-  }
-  
-  /* C is now the inverse */
-  mp_exch (&C, c);
-  res = MP_OKAY;
-__ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
-  return res;
-}
-
-/* End: bn_mp_invmod.c */
-
-/* Start: bn_mp_is_square.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Check if remainders are possible squares - fast exclude non-squares */
-static const char rem_128[128] = {
- 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
- 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1
-};
-
-static const char rem_105[105] = {
- 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
- 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1,
- 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
- 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
- 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1,
- 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1
-};
-
-/* Store non-zero to ret if arg is square, and zero if not */
-int mp_is_square(mp_int *arg,int *ret) 
-{
-  int           res;
-  mp_digit      c;
-  mp_int        t;
-  unsigned long r;
-
-  /* Default to Non-square :) */
-  *ret = MP_NO; 
-
-  if (arg->sign == MP_NEG) {
-    return MP_VAL;
-  }
-
-  /* digits used?  (TSD) */
-  if (arg->used == 0) {
-     return MP_OKAY;
-  }
-
-  /* First check mod 128 (suppose that DIGIT_BIT is at least 7) */
-  if (rem_128[127 & DIGIT(arg,0)] == 1) {
-     return MP_OKAY;
-  }
-
-  /* Next check mod 105 (3*5*7) */
-  if ((res = mp_mod_d(arg,105,&c)) != MP_OKAY) {
-     return res;
-  }
-  if (rem_105[c] == 1) {
-     return MP_OKAY;
-  }
-
-  /* product of primes less than 2^31 */
-  if ((res = mp_init_set_int(&t,11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
-     return res;
-  }
-  if ((res = mp_mod(arg,&t,&t)) != MP_OKAY) {
-     goto ERR;
-  }
-  r = mp_get_int(&t);
-  /* Check for other prime modules, note it's not an ERROR but we must
-   * free "t" so the easiest way is to goto ERR.  We know that res
-   * is already equal to MP_OKAY from the mp_mod call 
-   */ 
-  if ( (1L<<(r%11)) & 0x5C4L )             goto ERR;
-  if ( (1L<<(r%13)) & 0x9E4L )             goto ERR;
-  if ( (1L<<(r%17)) & 0x5CE8L )            goto ERR;
-  if ( (1L<<(r%19)) & 0x4F50CL )           goto ERR;
-  if ( (1L<<(r%23)) & 0x7ACCA0L )          goto ERR;
-  if ( (1L<<(r%29)) & 0xC2EDD0CL )         goto ERR;
-  if ( (1L<<(r%31)) & 0x6DE2B848L )        goto ERR;
-
-  /* Final check - is sqr(sqrt(arg)) == arg ? */
-  if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
-     goto ERR;
-  }
-  if ((res = mp_sqr(&t,&t)) != MP_OKAY) {
-     goto ERR;
-  }
-
-  *ret = (mp_cmp_mag(&t,arg) == MP_EQ) ? MP_YES : MP_NO;
-ERR:mp_clear(&t);
-  return res;
-}
-
-/* End: bn_mp_is_square.c */
-
-/* Start: bn_mp_jacobi.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes the jacobi c = (a | n) (or Legendre if n is prime)
- * HAC pp. 73 Algorithm 2.149
- */
-int mp_jacobi (mp_int * a, mp_int * p, int *c)
-{
-  mp_int  a1, p1;
-  int     k, s, r, res;
-  mp_digit residue;
-
-  /* if p <= 0 return MP_VAL */
-  if (mp_cmp_d(p, 0) != MP_GT) {
-     return MP_VAL;
-  }
-
-  /* step 1.  if a == 0, return 0 */
-  if (mp_iszero (a) == 1) {
-    *c = 0;
-    return MP_OKAY;
-  }
-
-  /* step 2.  if a == 1, return 1 */
-  if (mp_cmp_d (a, 1) == MP_EQ) {
-    *c = 1;
-    return MP_OKAY;
-  }
-
-  /* default */
-  s = 0;
-
-  /* step 3.  write a = a1 * 2**k  */
-  if ((res = mp_init_copy (&a1, a)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_init (&p1)) != MP_OKAY) {
-    goto __A1;
-  }
-
-  /* divide out larger power of two */
-  k = mp_cnt_lsb(&a1);
-  if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) {
-     goto __P1;
-  }
-
-  /* step 4.  if e is even set s=1 */
-  if ((k & 1) == 0) {
-    s = 1;
-  } else {
-    /* else set s=1 if p = 1/7 (mod 8) or s=-1 if p = 3/5 (mod 8) */
-    residue = p->dp[0] & 7;
-
-    if (residue == 1 || residue == 7) {
-      s = 1;
-    } else if (residue == 3 || residue == 5) {
-      s = -1;
-    }
-  }
-
-  /* step 5.  if p == 3 (mod 4) *and* a1 == 3 (mod 4) then s = -s */
-  if ( ((p->dp[0] & 3) == 3) && ((a1.dp[0] & 3) == 3)) {
-    s = -s;
-  }
-
-  /* if a1 == 1 we're done */
-  if (mp_cmp_d (&a1, 1) == MP_EQ) {
-    *c = s;
-  } else {
-    /* n1 = n mod a1 */
-    if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) {
-      goto __P1;
-    }
-    if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) {
-      goto __P1;
-    }
-    *c = s * r;
-  }
-
-  /* done */
-  res = MP_OKAY;
-__P1:mp_clear (&p1);
-__A1:mp_clear (&a1);
-  return res;
-}
-
-/* End: bn_mp_jacobi.c */
-
-/* Start: bn_mp_karatsuba_mul.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* c = |a| * |b| using Karatsuba Multiplication using 
- * three half size multiplications
- *
- * Let B represent the radix [e.g. 2**DIGIT_BIT] and 
- * let n represent half of the number of digits in 
- * the min(a,b)
- *
- * a = a1 * B**n + a0
- * b = b1 * B**n + b0
- *
- * Then, a * b => 
-   a1b1 * B**2n + ((a1 - a0)(b1 - b0) + a0b0 + a1b1) * B + a0b0
- *
- * Note that a1b1 and a0b0 are used twice and only need to be 
- * computed once.  So in total three half size (half # of 
- * digit) multiplications are performed, a0b0, a1b1 and 
- * (a1-b1)(a0-b0)
- *
- * Note that a multiplication of half the digits requires
- * 1/4th the number of single precision multiplications so in 
- * total after one call 25% of the single precision multiplications 
- * are saved.  Note also that the call to mp_mul can end up back 
- * in this function if the a0, a1, b0, or b1 are above the threshold.  
- * This is known as divide-and-conquer and leads to the famous 
- * O(N**lg(3)) or O(N**1.584) work which is asymptopically lower than 
- * the standard O(N**2) that the baseline/comba methods use.  
- * Generally though the overhead of this method doesn't pay off 
- * until a certain size (N ~ 80) is reached.
- */
-int mp_karatsuba_mul (mp_int * a, mp_int * b, mp_int * c)
-{
-  mp_int  x0, x1, y0, y1, t1, x0y0, x1y1;
-  int     B, err;
-
-  /* default the return code to an error */
-  err = MP_MEM;
-
-  /* min # of digits */
-  B = MIN (a->used, b->used);
-
-  /* now divide in two */
-  B = B >> 1;
-
-  /* init copy all the temps */
-  if (mp_init_size (&x0, B) != MP_OKAY)
-    goto ERR;
-  if (mp_init_size (&x1, a->used - B) != MP_OKAY)
-    goto X0;
-  if (mp_init_size (&y0, B) != MP_OKAY)
-    goto X1;
-  if (mp_init_size (&y1, b->used - B) != MP_OKAY)
-    goto Y0;
-
-  /* init temps */
-  if (mp_init_size (&t1, B * 2) != MP_OKAY)
-    goto Y1;
-  if (mp_init_size (&x0y0, B * 2) != MP_OKAY)
-    goto T1;
-  if (mp_init_size (&x1y1, B * 2) != MP_OKAY)
-    goto X0Y0;
-
-  /* now shift the digits */
-  x0.sign = x1.sign = a->sign;
-  y0.sign = y1.sign = b->sign;
-
-  x0.used = y0.used = B;
-  x1.used = a->used - B;
-  y1.used = b->used - B;
-
-  {
-    register int x;
-    register mp_digit *tmpa, *tmpb, *tmpx, *tmpy;
-
-    /* we copy the digits directly instead of using higher level functions
-     * since we also need to shift the digits
-     */
-    tmpa = a->dp;
-    tmpb = b->dp;
-
-    tmpx = x0.dp;
-    tmpy = y0.dp;
-    for (x = 0; x < B; x++) {
-      *tmpx++ = *tmpa++;
-      *tmpy++ = *tmpb++;
-    }
-
-    tmpx = x1.dp;
-    for (x = B; x < a->used; x++) {
-      *tmpx++ = *tmpa++;
-    }
-
-    tmpy = y1.dp;
-    for (x = B; x < b->used; x++) {
-      *tmpy++ = *tmpb++;
-    }
-  }
-
-  /* only need to clamp the lower words since by definition the 
-   * upper words x1/y1 must have a known number of digits
-   */
-  mp_clamp (&x0);
-  mp_clamp (&y0);
-
-  /* now calc the products x0y0 and x1y1 */
-  /* after this x0 is no longer required, free temp [x0==t2]! */
-  if (mp_mul (&x0, &y0, &x0y0) != MP_OKAY)  
-    goto X1Y1;          /* x0y0 = x0*y0 */
-  if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY)
-    goto X1Y1;          /* x1y1 = x1*y1 */
-
-  /* now calc x1-x0 and y1-y0 */
-  if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = x1 - x0 */
-  if (mp_sub (&y1, &y0, &x0) != MP_OKAY)
-    goto X1Y1;          /* t2 = y1 - y0 */
-  if (mp_mul (&t1, &x0, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = (x1 - x0) * (y1 - y0) */
-
-  /* add x0y0 */
-  if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY)
-    goto X1Y1;          /* t2 = x0y0 + x1y1 */
-  if (mp_sub (&x0, &t1, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = x0y0 + x1y1 - (x1-x0)*(y1-y0) */
-
-  /* shift by B */
-  if (mp_lshd (&t1, B) != MP_OKAY)
-    goto X1Y1;          /* t1 = (x0y0 + x1y1 - (x1-x0)*(y1-y0))<<B */
-  if (mp_lshd (&x1y1, B * 2) != MP_OKAY)
-    goto X1Y1;          /* x1y1 = x1y1 << 2*B */
-
-  if (mp_add (&x0y0, &t1, &t1) != MP_OKAY)
-    goto X1Y1;          /* t1 = x0y0 + t1 */
-  if (mp_add (&t1, &x1y1, c) != MP_OKAY)
-    goto X1Y1;          /* t1 = x0y0 + t1 + x1y1 */
-
-  /* Algorithm succeeded set the return code to MP_OKAY */
-  err = MP_OKAY;
-
-X1Y1:mp_clear (&x1y1);
-X0Y0:mp_clear (&x0y0);
-T1:mp_clear (&t1);
-Y1:mp_clear (&y1);
-Y0:mp_clear (&y0);
-X1:mp_clear (&x1);
-X0:mp_clear (&x0);
-ERR:
-  return err;
-}
-
-/* End: bn_mp_karatsuba_mul.c */
-
-/* Start: bn_mp_karatsuba_sqr.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Karatsuba squaring, computes b = a*a using three 
- * half size squarings
- *
- * See comments of mp_karatsuba_mul for details.  It 
- * is essentially the same algorithm but merely 
- * tuned to perform recursive squarings.
- */
-int mp_karatsuba_sqr (mp_int * a, mp_int * b)
-{
-  mp_int  x0, x1, t1, t2, x0x0, x1x1;
-  int     B, err;
-
-  err = MP_MEM;
-
-  /* min # of digits */
-  B = a->used;
-
-  /* now divide in two */
-  B = B >> 1;
-
-  /* init copy all the temps */
-  if (mp_init_size (&x0, B) != MP_OKAY)
-    goto ERR;
-  if (mp_init_size (&x1, a->used - B) != MP_OKAY)
-    goto X0;
-
-  /* init temps */
-  if (mp_init_size (&t1, a->used * 2) != MP_OKAY)
-    goto X1;
-  if (mp_init_size (&t2, a->used * 2) != MP_OKAY)
-    goto T1;
-  if (mp_init_size (&x0x0, B * 2) != MP_OKAY)
-    goto T2;
-  if (mp_init_size (&x1x1, (a->used - B) * 2) != MP_OKAY)
-    goto X0X0;
-
-  {
-    register int x;
-    register mp_digit *dst, *src;
-
-    src = a->dp;
-
-    /* now shift the digits */
-    dst = x0.dp;
-    for (x = 0; x < B; x++) {
-      *dst++ = *src++;
-    }
-
-    dst = x1.dp;
-    for (x = B; x < a->used; x++) {
-      *dst++ = *src++;
-    }
-  }
-
-  x0.used = B;
-  x1.used = a->used - B;
-
-  mp_clamp (&x0);
-
-  /* now calc the products x0*x0 and x1*x1 */
-  if (mp_sqr (&x0, &x0x0) != MP_OKAY)
-    goto X1X1;           /* x0x0 = x0*x0 */
-  if (mp_sqr (&x1, &x1x1) != MP_OKAY)
-    goto X1X1;           /* x1x1 = x1*x1 */
-
-  /* now calc (x1-x0)**2 */
-  if (mp_sub (&x1, &x0, &t1) != MP_OKAY)
-    goto X1X1;           /* t1 = x1 - x0 */
-  if (mp_sqr (&t1, &t1) != MP_OKAY)
-    goto X1X1;           /* t1 = (x1 - x0) * (x1 - x0) */
-
-  /* add x0y0 */
-  if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
-    goto X1X1;           /* t2 = x0x0 + x1x1 */
-  if (mp_sub (&t2, &t1, &t1) != MP_OKAY)
-    goto X1X1;           /* t1 = x0x0 + x1x1 - (x1-x0)*(x1-x0) */
-
-  /* shift by B */
-  if (mp_lshd (&t1, B) != MP_OKAY)
-    goto X1X1;           /* t1 = (x0x0 + x1x1 - (x1-x0)*(x1-x0))<<B */
-  if (mp_lshd (&x1x1, B * 2) != MP_OKAY)
-    goto X1X1;           /* x1x1 = x1x1 << 2*B */
-
-  if (mp_add (&x0x0, &t1, &t1) != MP_OKAY)
-    goto X1X1;           /* t1 = x0x0 + t1 */
-  if (mp_add (&t1, &x1x1, b) != MP_OKAY)
-    goto X1X1;           /* t1 = x0x0 + t1 + x1x1 */
-
-  err = MP_OKAY;
-
-X1X1:mp_clear (&x1x1);
-X0X0:mp_clear (&x0x0);
-T2:mp_clear (&t2);
-T1:mp_clear (&t1);
-X1:mp_clear (&x1);
-X0:mp_clear (&x0);
-ERR:
-  return err;
-}
-
-/* End: bn_mp_karatsuba_sqr.c */
-
-/* Start: bn_mp_lcm.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes least common multiple as |a*b|/(a, b) */
-int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     res;
-  mp_int  t1, t2;
-
-
-  if ((res = mp_init_multi (&t1, &t2, NULL)) != MP_OKAY) {
-    return res;
-  }
-
-  /* t1 = get the GCD of the two inputs */
-  if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) {
-    goto __T;
-  }
-
-  /* divide the smallest by the GCD */
-  if (mp_cmp_mag(a, b) == MP_LT) {
-     /* store quotient in t2 such that t2 * b is the LCM */
-     if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) {
-        goto __T;
-     }
-     res = mp_mul(b, &t2, c);
-  } else {
-     /* store quotient in t2 such that t2 * a is the LCM */
-     if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) {
-        goto __T;
-     }
-     res = mp_mul(a, &t2, c);
-  }
-
-  /* fix the sign to positive */
-  c->sign = MP_ZPOS;
-
-__T:
-  mp_clear_multi (&t1, &t2, NULL);
-  return res;
-}
-
-/* End: bn_mp_lcm.c */
-
-/* Start: bn_mp_lshd.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* shift left a certain amount of digits */
-int mp_lshd (mp_int * a, int b)
-{
-  int     x, res;
-
-  /* if its less than zero return */
-  if (b <= 0) {
-    return MP_OKAY;
-  }
-
-  /* grow to fit the new digits */
-  if (a->alloc < a->used + b) {
-     if ((res = mp_grow (a, a->used + b)) != MP_OKAY) {
-       return res;
-     }
-  }
-
-  {
-    register mp_digit *top, *bottom;
-
-    /* increment the used by the shift amount then copy upwards */
-    a->used += b;
-
-    /* top */
-    top = a->dp + a->used - 1;
-
-    /* base */
-    bottom = a->dp + a->used - 1 - b;
-
-    /* much like mp_rshd this is implemented using a sliding window
-     * except the window goes the otherway around.  Copying from
-     * the bottom to the top.  see bn_mp_rshd.c for more info.
-     */
-    for (x = a->used - 1; x >= b; x--) {
-      *top-- = *bottom--;
-    }
-
-    /* zero the lower digits */
-    top = a->dp;
-    for (x = 0; x < b; x++) {
-      *top++ = 0;
-    }
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_mp_lshd.c */
-
-/* Start: bn_mp_mod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* c = a mod b, 0 <= c < b */
-int
-mp_mod (mp_int * a, mp_int * b, mp_int * c)
-{
-  mp_int  t;
-  int     res;
-
-  if ((res = mp_init (&t)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-
-  if (t.sign != b->sign) {
-    res = mp_add (b, &t, c);
-  } else {
-    res = MP_OKAY;
-    mp_exch (&t, c);
-  }
-
-  mp_clear (&t);
-  return res;
-}
-
-/* End: bn_mp_mod.c */
-
-/* Start: bn_mp_mod_2d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* calc a value mod 2**b */
-int
-mp_mod_2d (mp_int * a, int b, mp_int * c)
-{
-  int     x, res;
-
-  /* if b is <= 0 then zero the int */
-  if (b <= 0) {
-    mp_zero (c);
-    return MP_OKAY;
-  }
-
-  /* if the modulus is larger than the value than return */
-  if (b > (int) (a->used * DIGIT_BIT)) {
-    res = mp_copy (a, c);
-    return res;
-  }
-
-  /* copy */
-  if ((res = mp_copy (a, c)) != MP_OKAY) {
-    return res;
-  }
-
-  /* zero digits above the last digit of the modulus */
-  for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) {
-    c->dp[x] = 0;
-  }
-  /* clear the digit that is not completely outside/inside the modulus */
-  c->dp[b / DIGIT_BIT] &=
-    (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1));
-  mp_clamp (c);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_mod_2d.c */
-
-/* Start: bn_mp_mod_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-int
-mp_mod_d (mp_int * a, mp_digit b, mp_digit * c)
-{
-  return mp_div_d(a, b, NULL, c);
-}
-
-/* End: bn_mp_mod_d.c */
-
-/* Start: bn_mp_montgomery_calc_normalization.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* calculates a = B^n mod b for Montgomery reduction
- * Where B is the base [e.g. 2^DIGIT_BIT].
- * B^n mod b is computed by first computing
- * A = B^(n-1) which doesn't require a reduction but a simple OR.
- * then C = A * B = B^n is computed by performing upto DIGIT_BIT
- * shifts with subtractions when the result is greater than b.
- *
- * The method is slightly modified to shift B unconditionally upto just under
- * the leading bit of b.  This saves alot of multiple precision shifting.
- */
-int
-mp_montgomery_calc_normalization (mp_int * a, mp_int * b)
-{
-  int     x, bits, res;
-
-  /* how many bits of last digit does b use */
-  bits = mp_count_bits (b) % DIGIT_BIT;
-
-  /* compute A = B^(n-1) * 2^(bits-1) */
-  if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) {
-    return res;
-  }
-
-  /* now compute C = A * B mod b */
-  for (x = bits - 1; x < (int)DIGIT_BIT; x++) {
-    if ((res = mp_mul_2 (a, a)) != MP_OKAY) {
-      return res;
-    }
-    if (mp_cmp_mag (a, b) != MP_LT) {
-      if ((res = s_mp_sub (a, b, a)) != MP_OKAY) {
-        return res;
-      }
-    }
-  }
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_montgomery_calc_normalization.c */
-
-/* Start: bn_mp_montgomery_reduce.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes xR**-1 == x (mod N) via Montgomery Reduction */
-int
-mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
-{
-  int     ix, res, digs;
-  mp_digit mu;
-
-  /* can the fast reduction [comba] method be used?
-   *
-   * Note that unlike in mp_mul you're safely allowed *less*
-   * than the available columns [255 per default] since carries
-   * are fixed up in the inner loop.
-   */
-  digs = n->used * 2 + 1;
-  if ((digs < MP_WARRAY) &&
-      n->used <
-      (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
-    return fast_mp_montgomery_reduce (x, n, rho);
-  }
-
-  /* grow the input as required */
-  if (x->alloc < digs) {
-    if ((res = mp_grow (x, digs)) != MP_OKAY) {
-      return res;
-    }
-  }
-  x->used = digs;
-
-  for (ix = 0; ix < n->used; ix++) {
-    /* mu = ai * rho mod b
-     *
-     * The value of rho must be precalculated via
-     * bn_mp_montgomery_setup() such that
-     * it equals -1/n0 mod b this allows the
-     * following inner loop to reduce the
-     * input one digit at a time
-     */
-    mu = (mp_digit) (((mp_word)x->dp[ix]) * ((mp_word)rho) & MP_MASK);
-
-    /* a = a + mu * m * b**i */
-    {
-      register int iy;
-      register mp_digit *tmpn, *tmpx, u;
-      register mp_word r;
-
-      /* alias for digits of the modulus */
-      tmpn = n->dp;
-
-      /* alias for the digits of x [the input] */
-      tmpx = x->dp + ix;
-
-      /* set the carry to zero */
-      u = 0;
-
-      /* Multiply and add in place */
-      for (iy = 0; iy < n->used; iy++) {
-        /* compute product and sum */
-        r       = ((mp_word)mu) * ((mp_word)*tmpn++) +
-                  ((mp_word) u) + ((mp_word) * tmpx);
-
-        /* get carry */
-        u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
-
-        /* fix digit */
-        *tmpx++ = (mp_digit)(r & ((mp_word) MP_MASK));
-      }
-      /* At this point the ix'th digit of x should be zero */
-
-
-      /* propagate carries upwards as required*/
-      while (u) {
-        *tmpx   += u;
-        u        = *tmpx >> DIGIT_BIT;
-        *tmpx++ &= MP_MASK;
-      }
-    }
-  }
-
-  /* at this point the n.used'th least
-   * significant digits of x are all zero
-   * which means we can shift x to the
-   * right by n.used digits and the
-   * residue is unchanged.
-   */
-
-  /* x = x/b**n.used */
-  mp_clamp(x);
-  mp_rshd (x, n->used);
-
-  /* if x >= n then x = x - n */
-  if (mp_cmp_mag (x, n) != MP_LT) {
-    return s_mp_sub (x, n, x);
-  }
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_montgomery_reduce.c */
-
-/* Start: bn_mp_montgomery_setup.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* setups the montgomery reduction stuff */
-int
-mp_montgomery_setup (mp_int * n, mp_digit * rho)
-{
-  mp_digit x, b;
-
-/* fast inversion mod 2**k
- *
- * Based on the fact that
- *
- * XA = 1 (mod 2**n)  =>  (X(2-XA)) A = 1 (mod 2**2n)
- *                    =>  2*X*A - X*X*A*A = 1
- *                    =>  2*(1) - (1)     = 1
- */
-  b = n->dp[0];
-
-  if ((b & 1) == 0) {
-    return MP_VAL;
-  }
-
-  x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
-  x *= 2 - b * x;               /* here x*a==1 mod 2**8 */
-#if !defined(MP_8BIT)
-  x *= 2 - b * x;               /* here x*a==1 mod 2**16 */
-#endif
-#if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT))
-  x *= 2 - b * x;               /* here x*a==1 mod 2**32 */
-#endif
-#ifdef MP_64BIT
-  x *= 2 - b * x;               /* here x*a==1 mod 2**64 */
-#endif
-
-  /* rho = -1/m mod b */
-  *rho = (((mp_digit) 1 << ((mp_digit) DIGIT_BIT)) - x) & MP_MASK;
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_montgomery_setup.c */
-
-/* Start: bn_mp_mul.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* high level multiplication (handles sign) */
-int mp_mul (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     res, neg;
-  neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
-
-  /* use Toom-Cook? */
-  if (MIN (a->used, b->used) >= TOOM_MUL_CUTOFF) {
-    res = mp_toom_mul(a, b, c);
-  /* use Karatsuba? */
-  } else if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) {
-    res = mp_karatsuba_mul (a, b, c);
-  } else {
-    /* can we use the fast multiplier?
-     *
-     * The fast multiplier can be used if the output will 
-     * have less than MP_WARRAY digits and the number of 
-     * digits won't affect carry propagation
-     */
-    int     digs = a->used + b->used + 1;
-
-    if ((digs < MP_WARRAY) &&
-        MIN(a->used, b->used) <= 
-        (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
-      res = fast_s_mp_mul_digs (a, b, c, digs);
-    } else {
-      res = s_mp_mul (a, b, c);
-    }
-  }
-  c->sign = neg;
-  return res;
-}
-
-/* End: bn_mp_mul.c */
-
-/* Start: bn_mp_mul_2.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* b = a*2 */
-int mp_mul_2(mp_int * a, mp_int * b)
-{
-  int     x, res, oldused;
-
-  /* grow to accomodate result */
-  if (b->alloc < a->used + 1) {
-    if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  oldused = b->used;
-  b->used = a->used;
-
-  {
-    register mp_digit r, rr, *tmpa, *tmpb;
-
-    /* alias for source */
-    tmpa = a->dp;
-    
-    /* alias for dest */
-    tmpb = b->dp;
-
-    /* carry */
-    r = 0;
-    for (x = 0; x < a->used; x++) {
-    
-      /* get what will be the *next* carry bit from the 
-       * MSB of the current digit 
-       */
-      rr = *tmpa >> ((mp_digit)(DIGIT_BIT - 1));
-      
-      /* now shift up this digit, add in the carry [from the previous] */
-      *tmpb++ = ((*tmpa++ << ((mp_digit)1)) | r) & MP_MASK;
-      
-      /* copy the carry that would be from the source 
-       * digit into the next iteration 
-       */
-      r = rr;
-    }
-
-    /* new leading digit? */
-    if (r != 0) {
-      /* add a MSB which is always 1 at this point */
-      *tmpb = 1;
-      ++(b->used);
-    }
-
-    /* now zero any excess digits on the destination 
-     * that we didn't write to 
-     */
-    tmpb = b->dp + b->used;
-    for (x = b->used; x < oldused; x++) {
-      *tmpb++ = 0;
-    }
-  }
-  b->sign = a->sign;
-  return MP_OKAY;
-}
-
-/* End: bn_mp_mul_2.c */
-
-/* Start: bn_mp_mul_2d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* shift left by a certain bit count */
-int mp_mul_2d (mp_int * a, int b, mp_int * c)
-{
-  mp_digit d;
-  int      res;
-
-  /* copy */
-  if (a != c) {
-     if ((res = mp_copy (a, c)) != MP_OKAY) {
-       return res;
-     }
-  }
-
-  if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) {
-     if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) {
-       return res;
-     }
-  }
-
-  /* shift by as many digits in the bit count */
-  if (b >= (int)DIGIT_BIT) {
-    if ((res = mp_lshd (c, b / DIGIT_BIT)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* shift any bit count < DIGIT_BIT */
-  d = (mp_digit) (b % DIGIT_BIT);
-  if (d != 0) {
-    register mp_digit *tmpc, shift, mask, r, rr;
-    register int x;
-
-    /* bitmask for carries */
-    mask = (((mp_digit)1) << d) - 1;
-
-    /* shift for msbs */
-    shift = DIGIT_BIT - d;
-
-    /* alias */
-    tmpc = c->dp;
-
-    /* carry */
-    r    = 0;
-    for (x = 0; x < c->used; x++) {
-      /* get the higher bits of the current word */
-      rr = (*tmpc >> shift) & mask;
-
-      /* shift the current word and OR in the carry */
-      *tmpc = ((*tmpc << d) | r) & MP_MASK;
-      ++tmpc;
-
-      /* set the carry to the carry bits of the current word */
-      r = rr;
-    }
-    
-    /* set final carry */
-    if (r != 0) {
-       c->dp[(c->used)++] = r;
-    }
-  }
-  mp_clamp (c);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_mul_2d.c */
-
-/* Start: bn_mp_mul_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* multiply by a digit */
-int
-mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
-{
-  mp_digit u, *tmpa, *tmpc;
-  mp_word  r;
-  int      ix, res, olduse;
-
-  /* make sure c is big enough to hold a*b */
-  if (c->alloc < a->used + 1) {
-    if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* get the original destinations used count */
-  olduse = c->used;
-
-  /* set the sign */
-  c->sign = a->sign;
-
-  /* alias for a->dp [source] */
-  tmpa = a->dp;
-
-  /* alias for c->dp [dest] */
-  tmpc = c->dp;
-
-  /* zero carry */
-  u = 0;
-
-  /* compute columns */
-  for (ix = 0; ix < a->used; ix++) {
-    /* compute product and carry sum for this term */
-    r       = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b);
-
-    /* mask off higher bits to get a single digit */
-    *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK));
-
-    /* send carry into next iteration */
-    u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
-  }
-
-  /* store final carry [if any] */
-  *tmpc++ = u;
-
-  /* now zero digits above the top */
-  while (ix++ < olduse) {
-     *tmpc++ = 0;
-  }
-
-  /* set used count */
-  c->used = a->used + 1;
-  mp_clamp(c);
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_mul_d.c */
-
-/* Start: bn_mp_mulmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* d = a * b (mod c) */
-int
-mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
-{
-  int     res;
-  mp_int  t;
-
-  if ((res = mp_init (&t)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_mul (a, b, &t)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-  res = mp_mod (&t, c, d);
-  mp_clear (&t);
-  return res;
-}
-
-/* End: bn_mp_mulmod.c */
-
-/* Start: bn_mp_n_root.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* find the n'th root of an integer 
- *
- * Result found such that (c)**b <= a and (c+1)**b > a 
- *
- * This algorithm uses Newton's approximation 
- * x[i+1] = x[i] - f(x[i])/f'(x[i]) 
- * which will find the root in log(N) time where 
- * each step involves a fair bit.  This is not meant to 
- * find huge roots [square and cube, etc].
- */
-int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
-{
-  mp_int  t1, t2, t3;
-  int     res, neg;
-
-  /* input must be positive if b is even */
-  if ((b & 1) == 0 && a->sign == MP_NEG) {
-    return MP_VAL;
-  }
-
-  if ((res = mp_init (&t1)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_init (&t2)) != MP_OKAY) {
-    goto __T1;
-  }
-
-  if ((res = mp_init (&t3)) != MP_OKAY) {
-    goto __T2;
-  }
-
-  /* if a is negative fudge the sign but keep track */
-  neg     = a->sign;
-  a->sign = MP_ZPOS;
-
-  /* t2 = 2 */
-  mp_set (&t2, 2);
-
-  do {
-    /* t1 = t2 */
-    if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
-      goto __T3;
-    }
-
-    /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
-    
-    /* t3 = t1**(b-1) */
-    if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) {   
-      goto __T3;
-    }
-
-    /* numerator */
-    /* t2 = t1**b */
-    if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {    
-      goto __T3;
-    }
-
-    /* t2 = t1**b - a */
-    if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {  
-      goto __T3;
-    }
-
-    /* denominator */
-    /* t3 = t1**(b-1) * b  */
-    if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {    
-      goto __T3;
-    }
-
-    /* t3 = (t1**b - a)/(b * t1**(b-1)) */
-    if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {  
-      goto __T3;
-    }
-
-    if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
-      goto __T3;
-    }
-  }  while (mp_cmp (&t1, &t2) != MP_EQ);
-
-  /* result can be off by a few so check */
-  for (;;) {
-    if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) {
-      goto __T3;
-    }
-
-    if (mp_cmp (&t2, a) == MP_GT) {
-      if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
-         goto __T3;
-      }
-    } else {
-      break;
-    }
-  }
-
-  /* reset the sign of a first */
-  a->sign = neg;
-
-  /* set the result */
-  mp_exch (&t1, c);
-
-  /* set the sign of the result */
-  c->sign = neg;
-
-  res = MP_OKAY;
-
-__T3:mp_clear (&t3);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
-  return res;
-}
-
-/* End: bn_mp_n_root.c */
-
-/* Start: bn_mp_neg.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* b = -a */
-int mp_neg (mp_int * a, mp_int * b)
-{
-  int     res;
-  if ((res = mp_copy (a, b)) != MP_OKAY) {
-    return res;
-  }
-  if (mp_iszero(b) != MP_YES) {
-     b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_mp_neg.c */
-
-/* Start: bn_mp_or.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* OR two ints together */
-int mp_or (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     res, ix, px;
-  mp_int  t, *x;
-
-  if (a->used > b->used) {
-    if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-      return res;
-    }
-    px = b->used;
-    x = b;
-  } else {
-    if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
-      return res;
-    }
-    px = a->used;
-    x = a;
-  }
-
-  for (ix = 0; ix < px; ix++) {
-    t.dp[ix] |= x->dp[ix];
-  }
-  mp_clamp (&t);
-  mp_exch (c, &t);
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_or.c */
-
-/* Start: bn_mp_prime_fermat.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* performs one Fermat test.
- * 
- * If "a" were prime then b**a == b (mod a) since the order of
- * the multiplicative sub-group would be phi(a) = a-1.  That means
- * it would be the same as b**(a mod (a-1)) == b**1 == b (mod a).
- *
- * Sets result to 1 if the congruence holds, or zero otherwise.
- */
-int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
-{
-  mp_int  t;
-  int     err;
-
-  /* default to composite  */
-  *result = MP_NO;
-
-  /* ensure b > 1 */
-  if (mp_cmp_d(b, 1) != MP_GT) {
-     return MP_VAL;
-  }
-
-  /* init t */
-  if ((err = mp_init (&t)) != MP_OKAY) {
-    return err;
-  }
-
-  /* compute t = b**a mod a */
-  if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
-    goto __T;
-  }
-
-  /* is it equal to b? */
-  if (mp_cmp (&t, b) == MP_EQ) {
-    *result = MP_YES;
-  }
-
-  err = MP_OKAY;
-__T:mp_clear (&t);
-  return err;
-}
-
-/* End: bn_mp_prime_fermat.c */
-
-/* Start: bn_mp_prime_is_divisible.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* determines if an integers is divisible by one 
- * of the first PRIME_SIZE primes or not
- *
- * sets result to 0 if not, 1 if yes
- */
-int mp_prime_is_divisible (mp_int * a, int *result)
-{
-  int     err, ix;
-  mp_digit res;
-
-  /* default to not */
-  *result = MP_NO;
-
-  for (ix = 0; ix < PRIME_SIZE; ix++) {
-    /* what is a mod __prime_tab[ix] */
-    if ((err = mp_mod_d (a, __prime_tab[ix], &res)) != MP_OKAY) {
-      return err;
-    }
-
-    /* is the residue zero? */
-    if (res == 0) {
-      *result = MP_YES;
-      return MP_OKAY;
-    }
-  }
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_prime_is_divisible.c */
-
-/* Start: bn_mp_prime_is_prime.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* performs a variable number of rounds of Miller-Rabin
- *
- * Probability of error after t rounds is no more than
- * (1/4)^t when 1 <= t <= PRIME_SIZE
- *
- * Sets result to 1 if probably prime, 0 otherwise
- */
-int mp_prime_is_prime (mp_int * a, int t, int *result)
-{
-  mp_int  b;
-  int     ix, err, res;
-
-  /* default to no */
-  *result = MP_NO;
-
-  /* valid value of t? */
-  if (t <= 0 || t > PRIME_SIZE) {
-    return MP_VAL;
-  }
-
-  /* is the input equal to one of the primes in the table? */
-  for (ix = 0; ix < PRIME_SIZE; ix++) {
-      if (mp_cmp_d(a, __prime_tab[ix]) == MP_EQ) {
-         *result = 1;
-         return MP_OKAY;
-      }
-  }
-
-  /* first perform trial division */
-  if ((err = mp_prime_is_divisible (a, &res)) != MP_OKAY) {
-    return err;
-  }
-
-  /* return if it was trivially divisible */
-  if (res == MP_YES) {
-    return MP_OKAY;
-  }
-
-  /* now perform the miller-rabin rounds */
-  if ((err = mp_init (&b)) != MP_OKAY) {
-    return err;
-  }
-
-  for (ix = 0; ix < t; ix++) {
-    /* set the prime */
-    mp_set (&b, __prime_tab[ix]);
-
-    if ((err = mp_prime_miller_rabin (a, &b, &res)) != MP_OKAY) {
-      goto __B;
-    }
-
-    if (res == MP_NO) {
-      goto __B;
-    }
-  }
-
-  /* passed the test */
-  *result = MP_YES;
-__B:mp_clear (&b);
-  return err;
-}
-
-/* End: bn_mp_prime_is_prime.c */
-
-/* Start: bn_mp_prime_miller_rabin.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Miller-Rabin test of "a" to the base of "b" as described in 
- * HAC pp. 139 Algorithm 4.24
- *
- * Sets result to 0 if definitely composite or 1 if probably prime.
- * Randomly the chance of error is no more than 1/4 and often 
- * very much lower.
- */
-int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
-{
-  mp_int  n1, y, r;
-  int     s, j, err;
-
-  /* default */
-  *result = MP_NO;
-
-  /* ensure b > 1 */
-  if (mp_cmp_d(b, 1) != MP_GT) {
-     return MP_VAL;
-  }     
-
-  /* get n1 = a - 1 */
-  if ((err = mp_init_copy (&n1, a)) != MP_OKAY) {
-    return err;
-  }
-  if ((err = mp_sub_d (&n1, 1, &n1)) != MP_OKAY) {
-    goto __N1;
-  }
-
-  /* set 2**s * r = n1 */
-  if ((err = mp_init_copy (&r, &n1)) != MP_OKAY) {
-    goto __N1;
-  }
-
-  /* count the number of least significant bits
-   * which are zero
-   */
-  s = mp_cnt_lsb(&r);
-
-  /* now divide n - 1 by 2**s */
-  if ((err = mp_div_2d (&r, s, &r, NULL)) != MP_OKAY) {
-    goto __R;
-  }
-
-  /* compute y = b**r mod a */
-  if ((err = mp_init (&y)) != MP_OKAY) {
-    goto __R;
-  }
-  if ((err = mp_exptmod (b, &r, a, &y)) != MP_OKAY) {
-    goto __Y;
-  }
-
-  /* if y != 1 and y != n1 do */
-  if (mp_cmp_d (&y, 1) != MP_EQ && mp_cmp (&y, &n1) != MP_EQ) {
-    j = 1;
-    /* while j <= s-1 and y != n1 */
-    while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) {
-      if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) {
-         goto __Y;
-      }
-
-      /* if y == 1 then composite */
-      if (mp_cmp_d (&y, 1) == MP_EQ) {
-         goto __Y;
-      }
-
-      ++j;
-    }
-
-    /* if y != n1 then composite */
-    if (mp_cmp (&y, &n1) != MP_EQ) {
-      goto __Y;
-    }
-  }
-
-  /* probably prime now */
-  *result = MP_YES;
-__Y:mp_clear (&y);
-__R:mp_clear (&r);
-__N1:mp_clear (&n1);
-  return err;
-}
-
-/* End: bn_mp_prime_miller_rabin.c */
-
-/* Start: bn_mp_prime_next_prime.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* finds the next prime after the number "a" using "t" trials
- * of Miller-Rabin.
- *
- * bbs_style = 1 means the prime must be congruent to 3 mod 4
- */
-int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
-{
-   int      err, res, x, y;
-   mp_digit res_tab[PRIME_SIZE], step, kstep;
-   mp_int   b;
-
-   /* ensure t is valid */
-   if (t <= 0 || t > PRIME_SIZE) {
-      return MP_VAL;
-   }
-
-   /* force positive */
-   a->sign = MP_ZPOS;
-
-   /* simple algo if a is less than the largest prime in the table */
-   if (mp_cmp_d(a, __prime_tab[PRIME_SIZE-1]) == MP_LT) {
-      /* find which prime it is bigger than */
-      for (x = PRIME_SIZE - 2; x >= 0; x--) {
-          if (mp_cmp_d(a, __prime_tab[x]) != MP_LT) {
-             if (bbs_style == 1) {
-                /* ok we found a prime smaller or
-                 * equal [so the next is larger]
-                 *
-                 * however, the prime must be
-                 * congruent to 3 mod 4
-                 */
-                if ((__prime_tab[x + 1] & 3) != 3) {
-                   /* scan upwards for a prime congruent to 3 mod 4 */
-                   for (y = x + 1; y < PRIME_SIZE; y++) {
-                       if ((__prime_tab[y] & 3) == 3) {
-                          mp_set(a, __prime_tab[y]);
-                          return MP_OKAY;
-                       }
-                   }
-                }
-             } else {
-                mp_set(a, __prime_tab[x + 1]);
-                return MP_OKAY;
-             }
-          }
-      }
-      /* at this point a maybe 1 */
-      if (mp_cmp_d(a, 1) == MP_EQ) {
-         mp_set(a, 2);
-         return MP_OKAY;
-      }
-      /* fall through to the sieve */
-   }
-
-   /* generate a prime congruent to 3 mod 4 or 1/3 mod 4? */
-   if (bbs_style == 1) {
-      kstep   = 4;
-   } else {
-      kstep   = 2;
-   }
-
-   /* at this point we will use a combination of a sieve and Miller-Rabin */
-
-   if (bbs_style == 1) {
-      /* if a mod 4 != 3 subtract the correct value to make it so */
-      if ((a->dp[0] & 3) != 3) {
-         if ((err = mp_sub_d(a, (a->dp[0] & 3) + 1, a)) != MP_OKAY) { return err; };
-      }
-   } else {
-      if (mp_iseven(a) == 1) {
-         /* force odd */
-         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
-            return err;
-         }
-      }
-   }
-
-   /* generate the restable */
-   for (x = 1; x < PRIME_SIZE; x++) {
-      if ((err = mp_mod_d(a, __prime_tab[x], res_tab + x)) != MP_OKAY) {
-         return err;
-      }
-   }
-
-   /* init temp used for Miller-Rabin Testing */
-   if ((err = mp_init(&b)) != MP_OKAY) {
-      return err;
-   }
-
-   for (;;) {
-      /* skip to the next non-trivially divisible candidate */
-      step = 0;
-      do {
-         /* y == 1 if any residue was zero [e.g. cannot be prime] */
-         y     =  0;
-
-         /* increase step to next candidate */
-         step += kstep;
-
-         /* compute the new residue without using division */
-         for (x = 1; x < PRIME_SIZE; x++) {
-             /* add the step to each residue */
-             res_tab[x] += kstep;
-
-             /* subtract the modulus [instead of using division] */
-             if (res_tab[x] >= __prime_tab[x]) {
-                res_tab[x]  -= __prime_tab[x];
-             }
-
-             /* set flag if zero */
-             if (res_tab[x] == 0) {
-                y = 1;
-             }
-         }
-      } while (y == 1 && step < ((((mp_digit)1)<<DIGIT_BIT) - kstep));
-
-      /* add the step */
-      if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
-         goto __ERR;
-      }
-
-      /* if didn't pass sieve and step == MAX then skip test */
-      if (y == 1 && step >= ((((mp_digit)1)<<DIGIT_BIT) - kstep)) {
-         continue;
-      }
-
-      /* is this prime? */
-      for (x = 0; x < t; x++) {
-          mp_set(&b, __prime_tab[t]);
-          if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
-             goto __ERR;
-          }
-          if (res == MP_NO) {
-             break;
-          }
-      }
-
-      if (res == MP_YES) {
-         break;
-      }
-   }
-
-   err = MP_OKAY;
-__ERR:
-   mp_clear(&b);
-   return err;
-}
-
-
-/* End: bn_mp_prime_next_prime.c */
-
-/* Start: bn_mp_prime_random_ex.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* makes a truly random prime of a given size (bits),
- *
- * Flags are as follows:
- * 
- *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
- *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
- *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
- *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
- *
- * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
- * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
- * so it can be NULL
- *
- */
-
-/* This is possibly the mother of all prime generation functions, muahahahahaha! */
-int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat)
-{
-   unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
-   int res, err, bsize, maskOR_msb_offset;
-
-   /* sanity check the input */
-   if (size <= 1 || t <= 0) {
-      return MP_VAL;
-   }
-
-   /* LTM_PRIME_SAFE implies LTM_PRIME_BBS */
-   if (flags & LTM_PRIME_SAFE) {
-      flags |= LTM_PRIME_BBS;
-   }
-
-   /* calc the byte size */
-   bsize = (size>>3)+(size&7?1:0);
-
-   /* we need a buffer of bsize bytes */
-   tmp = OPT_CAST(unsigned char) XMALLOC(bsize);
-   if (tmp == NULL) {
-      return MP_MEM;
-   }
-
-   /* calc the maskAND value for the MSbyte*/
-   maskAND = 0xFF >> (8 - (size & 7));
-
-   /* calc the maskOR_msb */
-   maskOR_msb        = 0;
-   maskOR_msb_offset = (size - 2) >> 3;
-   if (flags & LTM_PRIME_2MSB_ON) {
-      maskOR_msb     |= 1 << ((size - 2) & 7);
-   } else if (flags & LTM_PRIME_2MSB_OFF) {
-      maskAND        &= ~(1 << ((size - 2) & 7));
-   }
-
-   /* get the maskOR_lsb */
-   maskOR_lsb         = 0;
-   if (flags & LTM_PRIME_BBS) {
-      maskOR_lsb     |= 3;
-   }
-
-   do {
-      /* read the bytes */
-      if (cb(tmp, bsize, dat) != bsize) {
-         err = MP_VAL;
-         goto error;
-      }
- 
-      /* work over the MSbyte */
-      tmp[0]    &= maskAND;
-      tmp[0]    |= 1 << ((size - 1) & 7);
-
-      /* mix in the maskORs */
-      tmp[maskOR_msb_offset]   |= maskOR_msb;
-      tmp[bsize-1]             |= maskOR_lsb;
-
-      /* read it in */
-      if ((err = mp_read_unsigned_bin(a, tmp, bsize)) != MP_OKAY)     { goto error; }
-
-      /* is it prime? */
-      if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY)           { goto error; }
-
-      if (flags & LTM_PRIME_SAFE) {
-         /* see if (a-1)/2 is prime */
-         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY)                    { goto error; }
-         if ((err = mp_div_2(a, a)) != MP_OKAY)                       { goto error; }
- 
-         /* is it prime? */
-         if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY)        { goto error; }
-      }
-   } while (res == MP_NO);
-
-   if (flags & LTM_PRIME_SAFE) {
-      /* restore a to the original value */
-      if ((err = mp_mul_2(a, a)) != MP_OKAY)                          { goto error; }
-      if ((err = mp_add_d(a, 1, a)) != MP_OKAY)                       { goto error; }
-   }
-
-   err = MP_OKAY;
-error:
-   XFREE(tmp);
-   return err;
-}
-
-
-
-/* End: bn_mp_prime_random_ex.c */
-
-/* Start: bn_mp_radix_size.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* returns size of ASCII reprensentation */
-int mp_radix_size (mp_int * a, int radix, int *size)
-{
-  int     res, digs;
-  mp_int  t;
-  mp_digit d;
-
-  *size = 0;
-
-  /* special case for binary */
-  if (radix == 2) {
-    *size = mp_count_bits (a) + (a->sign == MP_NEG ? 1 : 0) + 1;
-    return MP_OKAY;
-  }
-
-  /* make sure the radix is in range */
-  if (radix < 2 || radix > 64) {
-    return MP_VAL;
-  }
-
-  /* init a copy of the input */
-  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-    return res;
-  }
-
-  /* digs is the digit count */
-  digs = 0;
-
-  /* if it's negative add one for the sign */
-  if (t.sign == MP_NEG) {
-    ++digs;
-    t.sign = MP_ZPOS;
-  }
-
-  /* fetch out all of the digits */
-  while (mp_iszero (&t) == 0) {
-    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
-      mp_clear (&t);
-      return res;
-    }
-    ++digs;
-  }
-  mp_clear (&t);
-
-  /* return digs + 1, the 1 is for the NULL byte that would be required. */
-  *size = digs + 1;
-  return MP_OKAY;
-}
-
-
-/* End: bn_mp_radix_size.c */
-
-/* Start: bn_mp_radix_smap.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* chars used in radix conversions */
-const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
-
-/* End: bn_mp_radix_smap.c */
-
-/* Start: bn_mp_rand.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* makes a pseudo-random int of a given size */
-int
-mp_rand (mp_int * a, int digits)
-{
-  int     res;
-  mp_digit d;
-
-  mp_zero (a);
-  if (digits <= 0) {
-    return MP_OKAY;
-  }
-
-  /* first place a random non-zero digit */
-  do {
-    d = ((mp_digit) abs (rand ()));
-  } while (d == 0);
-
-  if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
-    return res;
-  }
-
-  while (digits-- > 0) {
-    if ((res = mp_lshd (a, 1)) != MP_OKAY) {
-      return res;
-    }
-
-    if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_rand.c */
-
-/* Start: bn_mp_read_radix.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* read a string [ASCII] in a given radix */
-int mp_read_radix (mp_int * a, char *str, int radix)
-{
-  int     y, res, neg;
-  char    ch;
-
-  /* make sure the radix is ok */
-  if (radix < 2 || radix > 64) {
-    return MP_VAL;
-  }
-
-  /* if the leading digit is a 
-   * minus set the sign to negative. 
-   */
-  if (*str == '-') {
-    ++str;
-    neg = MP_NEG;
-  } else {
-    neg = MP_ZPOS;
-  }
-
-  /* set the integer to the default of zero */
-  mp_zero (a);
-  
-  /* process each digit of the string */
-  while (*str) {
-    /* if the radix < 36 the conversion is case insensitive
-     * this allows numbers like 1AB and 1ab to represent the same  value
-     * [e.g. in hex]
-     */
-    ch = (char) ((radix < 36) ? toupper (*str) : *str);
-    for (y = 0; y < 64; y++) {
-      if (ch == mp_s_rmap[y]) {
-         break;
-      }
-    }
-
-    /* if the char was found in the map 
-     * and is less than the given radix add it
-     * to the number, otherwise exit the loop. 
-     */
-    if (y < radix) {
-      if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) {
-         return res;
-      }
-      if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) {
-         return res;
-      }
-    } else {
-      break;
-    }
-    ++str;
-  }
-  
-  /* set the sign only if a != 0 */
-  if (mp_iszero(a) != 1) {
-     a->sign = neg;
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_mp_read_radix.c */
-
-/* Start: bn_mp_read_signed_bin.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* read signed bin, big endian, first byte is 0==positive or 1==negative */
-int
-mp_read_signed_bin (mp_int * a, unsigned char *b, int c)
-{
-  int     res;
-
-  /* read magnitude */
-  if ((res = mp_read_unsigned_bin (a, b + 1, c - 1)) != MP_OKAY) {
-    return res;
-  }
-
-  /* first byte is 0 for positive, non-zero for negative */
-  if (b[0] == 0) {
-     a->sign = MP_ZPOS;
-  } else {
-     a->sign = MP_NEG;
-  }
-
-  return MP_OKAY;
-}
-
-/* End: bn_mp_read_signed_bin.c */
-
-/* Start: bn_mp_read_unsigned_bin.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* reads a unsigned char array, assumes the msb is stored first [big endian] */
-int
-mp_read_unsigned_bin (mp_int * a, unsigned char *b, int c)
-{
-  int     res;
-
-  /* make sure there are at least two digits */
-  if (a->alloc < 2) {
-     if ((res = mp_grow(a, 2)) != MP_OKAY) {
-        return res;
-     }
-  }
-
-  /* zero the int */
-  mp_zero (a);
-
-  /* read the bytes in */
-  while (c-- > 0) {
-    if ((res = mp_mul_2d (a, 8, a)) != MP_OKAY) {
-      return res;
-    }
-
-#ifndef MP_8BIT
-      a->dp[0] |= *b++;
-      a->used += 1;
-#else
-      a->dp[0] = (*b & MP_MASK);
-      a->dp[1] |= ((*b++ >> 7U) & 1);
-      a->used += 2;
-#endif
-  }
-  mp_clamp (a);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_read_unsigned_bin.c */
-
-/* Start: bn_mp_reduce.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* reduces x mod m, assumes 0 < x < m**2, mu is 
- * precomputed via mp_reduce_setup.
- * From HAC pp.604 Algorithm 14.42
- */
-int
-mp_reduce (mp_int * x, mp_int * m, mp_int * mu)
-{
-  mp_int  q;
-  int     res, um = m->used;
-
-  /* q = x */
-  if ((res = mp_init_copy (&q, x)) != MP_OKAY) {
-    return res;
-  }
-
-  /* q1 = x / b**(k-1)  */
-  mp_rshd (&q, um - 1);         
-
-  /* according to HAC this optimization is ok */
-  if (((unsigned long) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
-    if ((res = mp_mul (&q, mu, &q)) != MP_OKAY) {
-      goto CLEANUP;
-    }
-  } else {
-    if ((res = s_mp_mul_high_digs (&q, mu, &q, um - 1)) != MP_OKAY) {
-      goto CLEANUP;
-    }
-  }
-
-  /* q3 = q2 / b**(k+1) */
-  mp_rshd (&q, um + 1);         
-
-  /* x = x mod b**(k+1), quick (no division) */
-  if ((res = mp_mod_2d (x, DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
-    goto CLEANUP;
-  }
-
-  /* q = q * m mod b**(k+1), quick (no division) */
-  if ((res = s_mp_mul_digs (&q, m, &q, um + 1)) != MP_OKAY) {
-    goto CLEANUP;
-  }
-
-  /* x = x - q */
-  if ((res = mp_sub (x, &q, x)) != MP_OKAY) {
-    goto CLEANUP;
-  }
-
-  /* If x < 0, add b**(k+1) to it */
-  if (mp_cmp_d (x, 0) == MP_LT) {
-    mp_set (&q, 1);
-    if ((res = mp_lshd (&q, um + 1)) != MP_OKAY)
-      goto CLEANUP;
-    if ((res = mp_add (x, &q, x)) != MP_OKAY)
-      goto CLEANUP;
-  }
-
-  /* Back off if it's too big */
-  while (mp_cmp (x, m) != MP_LT) {
-    if ((res = s_mp_sub (x, m, x)) != MP_OKAY) {
-      goto CLEANUP;
-    }
-  }
-  
-CLEANUP:
-  mp_clear (&q);
-
-  return res;
-}
-
-/* End: bn_mp_reduce.c */
-
-/* Start: bn_mp_reduce_2k.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* reduces a modulo n where n is of the form 2**p - d */
-int
-mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d)
-{
-   mp_int q;
-   int    p, res;
-   
-   if ((res = mp_init(&q)) != MP_OKAY) {
-      return res;
-   }
-   
-   p = mp_count_bits(n);    
-top:
-   /* q = a/2**p, a = a mod 2**p */
-   if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
-      goto ERR;
-   }
-   
-   if (d != 1) {
-      /* q = q * d */
-      if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { 
-         goto ERR;
-      }
-   }
-   
-   /* a = a + q */
-   if ((res = s_mp_add(a, &q, a)) != MP_OKAY) {
-      goto ERR;
-   }
-   
-   if (mp_cmp_mag(a, n) != MP_LT) {
-      s_mp_sub(a, n, a);
-      goto top;
-   }
-   
-ERR:
-   mp_clear(&q);
-   return res;
-}
-
-
-/* End: bn_mp_reduce_2k.c */
-
-/* Start: bn_mp_reduce_2k_setup.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* determines the setup value */
-int 
-mp_reduce_2k_setup(mp_int *a, mp_digit *d)
-{
-   int res, p;
-   mp_int tmp;
-   
-   if ((res = mp_init(&tmp)) != MP_OKAY) {
-      return res;
-   }
-   
-   p = mp_count_bits(a);
-   if ((res = mp_2expt(&tmp, p)) != MP_OKAY) {
-      mp_clear(&tmp);
-      return res;
-   }
-   
-   if ((res = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) {
-      mp_clear(&tmp);
-      return res;
-   }
-   
-   *d = tmp.dp[0];
-   mp_clear(&tmp);
-   return MP_OKAY;
-}
-
-/* End: bn_mp_reduce_2k_setup.c */
-
-/* Start: bn_mp_reduce_is_2k.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* determines if mp_reduce_2k can be used */
-int mp_reduce_is_2k(mp_int *a)
-{
-   int ix, iy, iz, iw;
-   
-   if (a->used == 0) {
-      return 0;
-   } else if (a->used == 1) {
-      return 1;
-   } else if (a->used > 1) {
-      iy = mp_count_bits(a);
-      iz = 1;
-      iw = 1;
-    
-      /* Test every bit from the second digit up, must be 1 */
-      for (ix = DIGIT_BIT; ix < iy; ix++) {
-          if ((a->dp[iw] & iz) == 0) {
-             return 0;
-          }
-          iz <<= 1;
-          if (iz > (int)MP_MASK) {
-             ++iw;
-             iz = 1;
-          }
-      }
-   }
-   return 1;
-}
-
-
-/* End: bn_mp_reduce_is_2k.c */
-
-/* Start: bn_mp_reduce_setup.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* pre-calculate the value required for Barrett reduction
- * For a given modulus "b" it calulates the value required in "a"
- */
-int
-mp_reduce_setup (mp_int * a, mp_int * b)
-{
-  int     res;
-  
-  if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) {
-    return res;
-  }
-  return mp_div (a, b, a, NULL);
-}
-
-/* End: bn_mp_reduce_setup.c */
-
-/* Start: bn_mp_rshd.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* shift right a certain amount of digits */
-void mp_rshd (mp_int * a, int b)
-{
-  int     x;
-
-  /* if b <= 0 then ignore it */
-  if (b <= 0) {
-    return;
-  }
-
-  /* if b > used then simply zero it and return */
-  if (a->used <= b) {
-    mp_zero (a);
-    return;
-  }
-
-  {
-    register mp_digit *bottom, *top;
-
-    /* shift the digits down */
-
-    /* bottom */
-    bottom = a->dp;
-
-    /* top [offset into digits] */
-    top = a->dp + b;
-
-    /* this is implemented as a sliding window where 
-     * the window is b-digits long and digits from 
-     * the top of the window are copied to the bottom
-     *
-     * e.g.
-
-     b-2 | b-1 | b0 | b1 | b2 | ... | bb |   ---->
-                 /\                   |      ---->
-                  \-------------------/      ---->
-     */
-    for (x = 0; x < (a->used - b); x++) {
-      *bottom++ = *top++;
-    }
-
-    /* zero the top digits */
-    for (; x < a->used; x++) {
-      *bottom++ = 0;
-    }
-  }
-  
-  /* remove excess digits */
-  a->used -= b;
-}
-
-/* End: bn_mp_rshd.c */
-
-/* Start: bn_mp_set.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* set to a digit */
-void mp_set (mp_int * a, mp_digit b)
-{
-  mp_zero (a);
-  a->dp[0] = b & MP_MASK;
-  a->used  = (a->dp[0] != 0) ? 1 : 0;
-}
-
-/* End: bn_mp_set.c */
-
-/* Start: bn_mp_set_int.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* set a 32-bit const */
-int mp_set_int (mp_int * a, unsigned long b)
-{
-  int     x, res;
-
-  mp_zero (a);
-  
-  /* set four bits at a time */
-  for (x = 0; x < 8; x++) {
-    /* shift the number up four bits */
-    if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) {
-      return res;
-    }
-
-    /* OR in the top four bits of the source */
-    a->dp[0] |= (b >> 28) & 15;
-
-    /* shift the source up to the next four bits */
-    b <<= 4;
-
-    /* ensure that digits are not clamped off */
-    a->used += 1;
-  }
-  mp_clamp (a);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_set_int.c */
-
-/* Start: bn_mp_shrink.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* shrink a bignum */
-int mp_shrink (mp_int * a)
-{
-  mp_digit *tmp;
-  if (a->alloc != a->used && a->used > 0) {
-    if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * a->used)) == NULL) {
-      return MP_MEM;
-    }
-    a->dp    = tmp;
-    a->alloc = a->used;
-  }
-  return MP_OKAY;
-}
-
-/* End: bn_mp_shrink.c */
-
-/* Start: bn_mp_signed_bin_size.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* get the size for an signed equivalent */
-int mp_signed_bin_size (mp_int * a)
-{
-  return 1 + mp_unsigned_bin_size (a);
-}
-
-/* End: bn_mp_signed_bin_size.c */
-
-/* Start: bn_mp_sqr.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* computes b = a*a */
-int
-mp_sqr (mp_int * a, mp_int * b)
-{
-  int     res;
-
-  /* use Toom-Cook? */
-  if (a->used >= TOOM_SQR_CUTOFF) {
-    res = mp_toom_sqr(a, b);
-  /* Karatsuba? */
-  } else if (a->used >= KARATSUBA_SQR_CUTOFF) {
-    res = mp_karatsuba_sqr (a, b);
-  } else {
-    /* can we use the fast comba multiplier? */
-    if ((a->used * 2 + 1) < MP_WARRAY && 
-         a->used < 
-         (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) {
-      res = fast_s_mp_sqr (a, b);
-    } else {
-      res = s_mp_sqr (a, b);
-    }
-  }
-  b->sign = MP_ZPOS;
-  return res;
-}
-
-/* End: bn_mp_sqr.c */
-
-/* Start: bn_mp_sqrmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* c = a * a (mod b) */
-int
-mp_sqrmod (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     res;
-  mp_int  t;
-
-  if ((res = mp_init (&t)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_sqr (a, &t)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-  res = mp_mod (&t, b, c);
-  mp_clear (&t);
-  return res;
-}
-
-/* End: bn_mp_sqrmod.c */
-
-/* Start: bn_mp_sqrt.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* this function is less generic than mp_n_root, simpler and faster */
-int mp_sqrt(mp_int *arg, mp_int *ret) 
-{
-  int res;
-  mp_int t1,t2;
-
-  /* must be positive */
-  if (arg->sign == MP_NEG) {
-    return MP_VAL;
-  }
-
-  /* easy out */
-  if (mp_iszero(arg) == MP_YES) {
-    mp_zero(ret);
-    return MP_OKAY;
-  }
-
-  if ((res = mp_init_copy(&t1, arg)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_init(&t2)) != MP_OKAY) {
-    goto E2;
-  }
-
-  /* First approx. (not very bad for large arg) */
-  mp_rshd (&t1,t1.used/2);
-
-  /* t1 > 0  */ 
-  if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) {
-    goto E1;
-  }
-  if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) {
-    goto E1;
-  }
-  if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) {
-    goto E1;
-  }
-  /* And now t1 > sqrt(arg) */
-  do { 
-    if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) {
-      goto E1;
-    }
-    if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) {
-      goto E1;
-    }
-    if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) {
-      goto E1;
-    }
-    /* t1 >= sqrt(arg) >= t2 at this point */
-  } while (mp_cmp_mag(&t1,&t2) == MP_GT);
-
-  mp_exch(&t1,ret);
-
-E1: mp_clear(&t2);
-E2: mp_clear(&t1);
-  return res;
-}
-
-
-/* End: bn_mp_sqrt.c */
-
-/* Start: bn_mp_sub.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* high level subtraction (handles signs) */
-int
-mp_sub (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     sa, sb, res;
-
-  sa = a->sign;
-  sb = b->sign;
-
-  if (sa != sb) {
-    /* subtract a negative from a positive, OR */
-    /* subtract a positive from a negative. */
-    /* In either case, ADD their magnitudes, */
-    /* and use the sign of the first number. */
-    c->sign = sa;
-    res = s_mp_add (a, b, c);
-  } else {
-    /* subtract a positive from a positive, OR */
-    /* subtract a negative from a negative. */
-    /* First, take the difference between their */
-    /* magnitudes, then... */
-    if (mp_cmp_mag (a, b) != MP_LT) {
-      /* Copy the sign from the first */
-      c->sign = sa;
-      /* The first has a larger or equal magnitude */
-      res = s_mp_sub (a, b, c);
-    } else {
-      /* The result has the *opposite* sign from */
-      /* the first number. */
-      c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
-      /* The second has a larger magnitude */
-      res = s_mp_sub (b, a, c);
-    }
-  }
-  return res;
-}
-
-
-/* End: bn_mp_sub.c */
-
-/* Start: bn_mp_sub_d.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* single digit subtraction */
-int
-mp_sub_d (mp_int * a, mp_digit b, mp_int * c)
-{
-  mp_digit *tmpa, *tmpc, mu;
-  int       res, ix, oldused;
-
-  /* grow c as required */
-  if (c->alloc < a->used + 1) {
-     if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
-        return res;
-     }
-  }
-
-  /* if a is negative just do an unsigned
-   * addition [with fudged signs]
-   */
-  if (a->sign == MP_NEG) {
-     a->sign = MP_ZPOS;
-     res     = mp_add_d(a, b, c);
-     a->sign = c->sign = MP_NEG;
-     return res;
-  }
-
-  /* setup regs */
-  oldused = c->used;
-  tmpa    = a->dp;
-  tmpc    = c->dp;
-
-  /* if a <= b simply fix the single digit */
-  if ((a->used == 1 && a->dp[0] <= b) || a->used == 0) {
-     if (a->used == 1) {
-        *tmpc++ = b - *tmpa;
-     } else {
-        *tmpc++ = b;
-     }
-     ix      = 1;
-
-     /* negative/1digit */
-     c->sign = MP_NEG;
-     c->used = 1;
-  } else {
-     /* positive/size */
-     c->sign = MP_ZPOS;
-     c->used = a->used;
-
-     /* subtract first digit */
-     *tmpc    = *tmpa++ - b;
-     mu       = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1);
-     *tmpc++ &= MP_MASK;
-
-     /* handle rest of the digits */
-     for (ix = 1; ix < a->used; ix++) {
-        *tmpc    = *tmpa++ - mu;
-        mu       = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1);
-        *tmpc++ &= MP_MASK;
-     }
-  }
-
-  /* zero excess digits */
-  while (ix++ < oldused) {
-     *tmpc++ = 0;
-  }
-  mp_clamp(c);
-  return MP_OKAY;
-}
-
-
-/* End: bn_mp_sub_d.c */
-
-/* Start: bn_mp_submod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* d = a - b (mod c) */
-int
-mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
-{
-  int     res;
-  mp_int  t;
-
-
-  if ((res = mp_init (&t)) != MP_OKAY) {
-    return res;
-  }
-
-  if ((res = mp_sub (a, b, &t)) != MP_OKAY) {
-    mp_clear (&t);
-    return res;
-  }
-  res = mp_mod (&t, c, d);
-  mp_clear (&t);
-  return res;
-}
-
-/* End: bn_mp_submod.c */
-
-/* Start: bn_mp_to_signed_bin.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* store in signed [big endian] format */
-int
-mp_to_signed_bin (mp_int * a, unsigned char *b)
-{
-  int     res;
-
-  if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) {
-    return res;
-  }
-  b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_to_signed_bin.c */
-
-/* Start: bn_mp_to_unsigned_bin.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* store in unsigned [big endian] format */
-int
-mp_to_unsigned_bin (mp_int * a, unsigned char *b)
-{
-  int     x, res;
-  mp_int  t;
-
-  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-    return res;
-  }
-
-  x = 0;
-  while (mp_iszero (&t) == 0) {
-#ifndef MP_8BIT
-      b[x++] = (unsigned char) (t.dp[0] & 255);
-#else
-      b[x++] = (unsigned char) (t.dp[0] | ((t.dp[1] & 0x01) << 7));
-#endif
-    if ((res = mp_div_2d (&t, 8, &t, NULL)) != MP_OKAY) {
-      mp_clear (&t);
-      return res;
-    }
-  }
-  bn_reverse (b, x);
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_to_unsigned_bin.c */
-
-/* Start: bn_mp_toom_mul.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* multiplication using the Toom-Cook 3-way algorithm */
-int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
-{
-    mp_int w0, w1, w2, w3, w4, tmp1, tmp2, a0, a1, a2, b0, b1, b2;
-    int res, B;
-        
-    /* init temps */
-    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, 
-                             &a0, &a1, &a2, &b0, &b1, 
-                             &b2, &tmp1, &tmp2, NULL)) != MP_OKAY) {
-       return res;
-    }
-    
-    /* B */
-    B = MIN(a->used, b->used) / 3;
-    
-    /* a = a2 * B**2 + a1 * B + a0 */
-    if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    if ((res = mp_copy(a, &a1)) != MP_OKAY) {
-       goto ERR;
-    }
-    mp_rshd(&a1, B);
-    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
-
-    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
-       goto ERR;
-    }
-    mp_rshd(&a2, B*2);
-    
-    /* b = b2 * B**2 + b1 * B + b0 */
-    if ((res = mp_mod_2d(b, DIGIT_BIT * B, &b0)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    if ((res = mp_copy(b, &b1)) != MP_OKAY) {
-       goto ERR;
-    }
-    mp_rshd(&b1, B);
-    mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
-
-    if ((res = mp_copy(b, &b2)) != MP_OKAY) {
-       goto ERR;
-    }
-    mp_rshd(&b2, B*2);
-    
-    /* w0 = a0*b0 */
-    if ((res = mp_mul(&a0, &b0, &w0)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    /* w4 = a2 * b2 */
-    if ((res = mp_mul(&a2, &b2, &w4)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    /* w1 = (a2 + 2(a1 + 2a0))(b2 + 2(b1 + 2b0)) */
-    if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    if ((res = mp_mul_2(&b0, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    if ((res = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    /* w3 = (a0 + 2(a1 + 2a2))(b0 + 2(b1 + 2b2)) */
-    if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    if ((res = mp_mul_2(&b2, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    if ((res = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-
-    /* w2 = (a2 + a1 + a0)(b2 + b1 + b0) */
-    if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&b2, &b1, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) {
-       goto ERR;
-    }
-    
-    /* now solve the matrix 
-    
-       0  0  0  0  1
-       1  2  4  8  16
-       1  1  1  1  1
-       16 8  4  2  1
-       1  0  0  0  0
-       
-       using 12 subtractions, 4 shifts, 
-              2 small divisions and 1 small multiplication 
-     */
-     
-     /* r1 - r4 */
-     if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r0 */
-     if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/2 */
-     if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/2 */
-     if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r2 - r0 - r4 */
-     if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - 8r0 */
-     if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - 8r4 */
-     if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* 3r2 - r1 - r3 */
-     if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/3 */
-     if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/3 */
-     if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-     
-     /* at this point shift W[n] by B*n */
-     if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
-        goto ERR;
-     }     
-     
-     if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) {
-        goto ERR;
-     }     
-     
-ERR:
-     mp_clear_multi(&w0, &w1, &w2, &w3, &w4, 
-                    &a0, &a1, &a2, &b0, &b1, 
-                    &b2, &tmp1, &tmp2, NULL);
-     return res;
-}     
-     
-
-/* End: bn_mp_toom_mul.c */
-
-/* Start: bn_mp_toom_sqr.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* squaring using Toom-Cook 3-way algorithm */
-int
-mp_toom_sqr(mp_int *a, mp_int *b)
-{
-    mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2;
-    int res, B;
-
-    /* init temps */
-    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL)) != MP_OKAY) {
-       return res;
-    }
-
-    /* B */
-    B = a->used / 3;
-
-    /* a = a2 * B**2 + a1 * B + a0 */
-    if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    if ((res = mp_copy(a, &a1)) != MP_OKAY) {
-       goto ERR;
-    }
-    mp_rshd(&a1, B);
-    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
-
-    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
-       goto ERR;
-    }
-    mp_rshd(&a2, B*2);
-
-    /* w0 = a0*a0 */
-    if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    /* w4 = a2 * a2 */
-    if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    /* w1 = (a2 + 2(a1 + 2a0))**2 */
-    if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    /* w3 = (a0 + 2(a1 + 2a2))**2 */
-    if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) {
-       goto ERR;
-    }
-
-
-    /* w2 = (a2 + a1 + a0)**2 */
-    if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
-       goto ERR;
-    }
-    if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) {
-       goto ERR;
-    }
-
-    /* now solve the matrix
-
-       0  0  0  0  1
-       1  2  4  8  16
-       1  1  1  1  1
-       16 8  4  2  1
-       1  0  0  0  0
-
-       using 12 subtractions, 4 shifts, 2 small divisions and 1 small multiplication.
-     */
-
-     /* r1 - r4 */
-     if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r0 */
-     if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/2 */
-     if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/2 */
-     if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r2 - r0 - r4 */
-     if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - 8r0 */
-     if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - 8r4 */
-     if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* 3r2 - r1 - r3 */
-     if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1 - r2 */
-     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3 - r2 */
-     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r1/3 */
-     if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-     /* r3/3 */
-     if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
-        goto ERR;
-     }
-
-     /* at this point shift W[n] by B*n */
-     if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
-        goto ERR;
-     }
-
-     if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
-        goto ERR;
-     }
-     if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) {
-        goto ERR;
-     }
-
-ERR:
-     mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL);
-     return res;
-}
-
-
-/* End: bn_mp_toom_sqr.c */
-
-/* Start: bn_mp_toradix.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* stores a bignum as a ASCII string in a given radix (2..64) */
-int mp_toradix (mp_int * a, char *str, int radix)
-{
-  int     res, digs;
-  mp_int  t;
-  mp_digit d;
-  char   *_s = str;
-
-  /* check range of the radix */
-  if (radix < 2 || radix > 64) {
-    return MP_VAL;
-  }
-
-  /* quick out if its zero */
-  if (mp_iszero(a) == 1) {
-     *str++ = '0';
-     *str = '\0';
-     return MP_OKAY;
-  }
-
-  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-    return res;
-  }
-
-  /* if it is negative output a - */
-  if (t.sign == MP_NEG) {
-    ++_s;
-    *str++ = '-';
-    t.sign = MP_ZPOS;
-  }
-
-  digs = 0;
-  while (mp_iszero (&t) == 0) {
-    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
-      mp_clear (&t);
-      return res;
-    }
-    *str++ = mp_s_rmap[d];
-    ++digs;
-  }
-
-  /* reverse the digits of the string.  In this case _s points
-   * to the first digit [exluding the sign] of the number]
-   */
-  bn_reverse ((unsigned char *)_s, digs);
-
-  /* append a NULL so the string is properly terminated */
-  *str = '\0';
-
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-
-/* End: bn_mp_toradix.c */
-
-/* Start: bn_mp_toradix_n.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* stores a bignum as a ASCII string in a given radix (2..64) 
- *
- * Stores upto maxlen-1 chars and always a NULL byte 
- */
-int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
-{
-  int     res, digs;
-  mp_int  t;
-  mp_digit d;
-  char   *_s = str;
-
-  /* check range of the maxlen, radix */
-  if (maxlen < 3 || radix < 2 || radix > 64) {
-    return MP_VAL;
-  }
-
-  /* quick out if its zero */
-  if (mp_iszero(a) == 1) {
-     *str++ = '0';
-     *str = '\0';
-     return MP_OKAY;
-  }
-
-  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-    return res;
-  }
-
-  /* if it is negative output a - */
-  if (t.sign == MP_NEG) {
-    /* we have to reverse our digits later... but not the - sign!! */
-    ++_s;
-
-    /* store the flag and mark the number as positive */
-    *str++ = '-';
-    t.sign = MP_ZPOS;
- 
-    /* subtract a char */
-    --maxlen;
-  }
-
-  digs = 0;
-  while (mp_iszero (&t) == 0) {
-    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
-      mp_clear (&t);
-      return res;
-    }
-    *str++ = mp_s_rmap[d];
-    ++digs;
-
-    if (--maxlen == 1) {
-       /* no more room */
-       break;
-    }
-  }
-
-  /* reverse the digits of the string.  In this case _s points
-   * to the first digit [exluding the sign] of the number]
-   */
-  bn_reverse ((unsigned char *)_s, digs);
-
-  /* append a NULL so the string is properly terminated */
-  *str = '\0';
-
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-
-/* End: bn_mp_toradix_n.c */
-
-/* Start: bn_mp_unsigned_bin_size.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* get the size for an unsigned equivalent */
-int
-mp_unsigned_bin_size (mp_int * a)
-{
-  int     size = mp_count_bits (a);
-  return (size / 8 + ((size & 7) != 0 ? 1 : 0));
-}
-
-/* End: bn_mp_unsigned_bin_size.c */
-
-/* Start: bn_mp_xor.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* XOR two ints together */
-int
-mp_xor (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     res, ix, px;
-  mp_int  t, *x;
-
-  if (a->used > b->used) {
-    if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-      return res;
-    }
-    px = b->used;
-    x = b;
-  } else {
-    if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
-      return res;
-    }
-    px = a->used;
-    x = a;
-  }
-
-  for (ix = 0; ix < px; ix++) {
-    t.dp[ix] ^= x->dp[ix];
-  }
-  mp_clamp (&t);
-  mp_exch (c, &t);
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_mp_xor.c */
-
-/* Start: bn_mp_zero.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* set to zero */
-void
-mp_zero (mp_int * a)
-{
-  a->sign = MP_ZPOS;
-  a->used = 0;
-  memset (a->dp, 0, sizeof (mp_digit) * a->alloc);
-}
-
-/* End: bn_mp_zero.c */
-
-/* Start: bn_prime_sizes_tab.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* this table gives the # of rabin miller trials for a prob of failure lower than 2^-96 */
-static const struct {
-   int k, t;
-} sizes[] = {
-{   128,    28 },
-{   256,    16 },
-{   384,    10 },
-{   512,     7 },
-{   640,     6 },
-{   768,     5 },
-{   896,     4 },
-{  1024,     4 },
-{  1152,     3 },
-{  1280,     3 },
-{  1408,     3 },
-{  1536,     3 },
-{  1664,     3 },
-{  1792,     2 } };
-
-/* returns # of RM trials required for a given bit size */
-int mp_prime_rabin_miller_trials(int size)
-{
-   int x;
-
-   for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
-       if (sizes[x].k == size) {
-          return sizes[x].t;
-       } else if (sizes[x].k > size) {
-          return (x == 0) ? sizes[0].t : sizes[x - 1].t;
-       }
-   }
-   return 1;
-}
-
-
-
-/* End: bn_prime_sizes_tab.c */
-
-/* Start: bn_prime_tab.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-const mp_digit __prime_tab[] = {
-  0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
-  0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
-  0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
-  0x0061, 0x0065, 0x0067, 0x006B, 0x006D, 0x0071, 0x007F,
-#ifndef MP_8BIT
-  0x0083,
-  0x0089, 0x008B, 0x0095, 0x0097, 0x009D, 0x00A3, 0x00A7, 0x00AD,
-  0x00B3, 0x00B5, 0x00BF, 0x00C1, 0x00C5, 0x00C7, 0x00D3, 0x00DF,
-  0x00E3, 0x00E5, 0x00E9, 0x00EF, 0x00F1, 0x00FB, 0x0101, 0x0107,
-  0x010D, 0x010F, 0x0115, 0x0119, 0x011B, 0x0125, 0x0133, 0x0137,
-
-  0x0139, 0x013D, 0x014B, 0x0151, 0x015B, 0x015D, 0x0161, 0x0167,
-  0x016F, 0x0175, 0x017B, 0x017F, 0x0185, 0x018D, 0x0191, 0x0199,
-  0x01A3, 0x01A5, 0x01AF, 0x01B1, 0x01B7, 0x01BB, 0x01C1, 0x01C9,
-  0x01CD, 0x01CF, 0x01D3, 0x01DF, 0x01E7, 0x01EB, 0x01F3, 0x01F7,
-  0x01FD, 0x0209, 0x020B, 0x021D, 0x0223, 0x022D, 0x0233, 0x0239,
-  0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265,
-  0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293,
-  0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF,
-
-  0x02D7, 0x02DD, 0x02E3, 0x02E7, 0x02EF, 0x02F5, 0x02F9, 0x0301,
-  0x0305, 0x0313, 0x031D, 0x0329, 0x032B, 0x0335, 0x0337, 0x033B,
-  0x033D, 0x0347, 0x0355, 0x0359, 0x035B, 0x035F, 0x036D, 0x0371,
-  0x0373, 0x0377, 0x038B, 0x038F, 0x0397, 0x03A1, 0x03A9, 0x03AD,
-  0x03B3, 0x03B9, 0x03C7, 0x03CB, 0x03D1, 0x03D7, 0x03DF, 0x03E5,
-  0x03F1, 0x03F5, 0x03FB, 0x03FD, 0x0407, 0x0409, 0x040F, 0x0419,
-  0x041B, 0x0425, 0x0427, 0x042D, 0x043F, 0x0443, 0x0445, 0x0449,
-  0x044F, 0x0455, 0x045D, 0x0463, 0x0469, 0x047F, 0x0481, 0x048B,
-
-  0x0493, 0x049D, 0x04A3, 0x04A9, 0x04B1, 0x04BD, 0x04C1, 0x04C7,
-  0x04CD, 0x04CF, 0x04D5, 0x04E1, 0x04EB, 0x04FD, 0x04FF, 0x0503,
-  0x0509, 0x050B, 0x0511, 0x0515, 0x0517, 0x051B, 0x0527, 0x0529,
-  0x052F, 0x0551, 0x0557, 0x055D, 0x0565, 0x0577, 0x0581, 0x058F,
-  0x0593, 0x0595, 0x0599, 0x059F, 0x05A7, 0x05AB, 0x05AD, 0x05B3,
-  0x05BF, 0x05C9, 0x05CB, 0x05CF, 0x05D1, 0x05D5, 0x05DB, 0x05E7,
-  0x05F3, 0x05FB, 0x0607, 0x060D, 0x0611, 0x0617, 0x061F, 0x0623,
-  0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653
-#endif
-};
-
-/* End: bn_prime_tab.c */
-
-/* Start: bn_reverse.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* reverse an array, used for radix code */
-void
-bn_reverse (unsigned char *s, int len)
-{
-  int     ix, iy;
-  unsigned char t;
-
-  ix = 0;
-  iy = len - 1;
-  while (ix < iy) {
-    t     = s[ix];
-    s[ix] = s[iy];
-    s[iy] = t;
-    ++ix;
-    --iy;
-  }
-}
-
-/* End: bn_reverse.c */
-
-/* Start: bn_s_mp_add.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* low level addition, based on HAC pp.594, Algorithm 14.7 */
-int
-s_mp_add (mp_int * a, mp_int * b, mp_int * c)
-{
-  mp_int *x;
-  int     olduse, res, min, max;
-
-  /* find sizes, we let |a| <= |b| which means we have to sort
-   * them.  "x" will point to the input with the most digits
-   */
-  if (a->used > b->used) {
-    min = b->used;
-    max = a->used;
-    x = a;
-  } else {
-    min = a->used;
-    max = b->used;
-    x = b;
-  }
-
-  /* init result */
-  if (c->alloc < max + 1) {
-    if ((res = mp_grow (c, max + 1)) != MP_OKAY) {
-      return res;
-    }
-  }
-
-  /* get old used digit count and set new one */
-  olduse = c->used;
-  c->used = max + 1;
-
-  {
-    register mp_digit u, *tmpa, *tmpb, *tmpc;
-    register int i;
-
-    /* alias for digit pointers */
-
-    /* first input */
-    tmpa = a->dp;
-
-    /* second input */
-    tmpb = b->dp;
-
-    /* destination */
-    tmpc = c->dp;
-
-    /* zero the carry */
-    u = 0;
-    for (i = 0; i < min; i++) {
-      /* Compute the sum at one digit, T[i] = A[i] + B[i] + U */
-      *tmpc = *tmpa++ + *tmpb++ + u;
-
-      /* U = carry bit of T[i] */
-      u = *tmpc >> ((mp_digit)DIGIT_BIT);
-
-      /* take away carry bit from T[i] */
-      *tmpc++ &= MP_MASK;
-    }
-
-    /* now copy higher words if any, that is in A+B 
-     * if A or B has more digits add those in 
-     */
-    if (min != max) {
-      for (; i < max; i++) {
-        /* T[i] = X[i] + U */
-        *tmpc = x->dp[i] + u;
-
-        /* U = carry bit of T[i] */
-        u = *tmpc >> ((mp_digit)DIGIT_BIT);
-
-        /* take away carry bit from T[i] */
-        *tmpc++ &= MP_MASK;
-      }
-    }
-
-    /* add carry */
-    *tmpc++ = u;
-
-    /* clear digits above oldused */
-    for (i = c->used; i < olduse; i++) {
-      *tmpc++ = 0;
-    }
-  }
-
-  mp_clamp (c);
-  return MP_OKAY;
-}
-
-/* End: bn_s_mp_add.c */
-
-/* Start: bn_s_mp_exptmod.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-#ifdef MP_LOW_MEM
-   #define TAB_SIZE 32
-#else
-   #define TAB_SIZE 256
-#endif
-
-int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
-{
-  mp_int  M[TAB_SIZE], res, mu;
-  mp_digit buf;
-  int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
-
-  /* find window size */
-  x = mp_count_bits (X);
-  if (x <= 7) {
-    winsize = 2;
-  } else if (x <= 36) {
-    winsize = 3;
-  } else if (x <= 140) {
-    winsize = 4;
-  } else if (x <= 450) {
-    winsize = 5;
-  } else if (x <= 1303) {
-    winsize = 6;
-  } else if (x <= 3529) {
-    winsize = 7;
-  } else {
-    winsize = 8;
-  }
-
-#ifdef MP_LOW_MEM
-    if (winsize > 5) {
-       winsize = 5;
-    }
-#endif
-
-  /* init M array */
-  /* init first cell */
-  if ((err = mp_init(&M[1])) != MP_OKAY) {
-     return err; 
-  }
-
-  /* now init the second half of the array */
-  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
-    if ((err = mp_init(&M[x])) != MP_OKAY) {
-      for (y = 1<<(winsize-1); y < x; y++) {
-        mp_clear (&M[y]);
-      }
-      mp_clear(&M[1]);
-      return err;
-    }
-  }
-
-  /* create mu, used for Barrett reduction */
-  if ((err = mp_init (&mu)) != MP_OKAY) {
-    goto __M;
-  }
-  if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
-    goto __MU;
-  }
-
-  /* create M table
-   *
-   * The M table contains powers of the base, 
-   * e.g. M[x] = G**x mod P
-   *
-   * The first half of the table is not 
-   * computed though accept for M[0] and M[1]
-   */
-  if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) {
-    goto __MU;
-  }
-
-  /* compute the value at M[1<<(winsize-1)] by squaring 
-   * M[1] (winsize-1) times 
-   */
-  if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
-    goto __MU;
-  }
-
-  for (x = 0; x < (winsize - 1); x++) {
-    if ((err = mp_sqr (&M[1 << (winsize - 1)], 
-                       &M[1 << (winsize - 1)])) != MP_OKAY) {
-      goto __MU;
-    }
-    if ((err = mp_reduce (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
-      goto __MU;
-    }
-  }
-
-  /* create upper table, that is M[x] = M[x-1] * M[1] (mod P)
-   * for x = (2**(winsize - 1) + 1) to (2**winsize - 1)
-   */
-  for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
-    if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
-      goto __MU;
-    }
-    if ((err = mp_reduce (&M[x], P, &mu)) != MP_OKAY) {
-      goto __MU;
-    }
-  }
-
-  /* setup result */
-  if ((err = mp_init (&res)) != MP_OKAY) {
-    goto __MU;
-  }
-  mp_set (&res, 1);
-
-  /* set initial mode and bit cnt */
-  mode   = 0;
-  bitcnt = 1;
-  buf    = 0;
-  digidx = X->used - 1;
-  bitcpy = 0;
-  bitbuf = 0;
-
-  for (;;) {
-    /* grab next digit as required */
-    if (--bitcnt == 0) {
-      /* if digidx == -1 we are out of digits */
-      if (digidx == -1) {
-        break;
-      }
-      /* read next digit and reset the bitcnt */
-      buf    = X->dp[digidx--];
-      bitcnt = (int) DIGIT_BIT;
-    }
-
-    /* grab the next msb from the exponent */
-    y     = (buf >> (mp_digit)(DIGIT_BIT - 1)) & 1;
-    buf <<= (mp_digit)1;
-
-    /* if the bit is zero and mode == 0 then we ignore it
-     * These represent the leading zero bits before the first 1 bit
-     * in the exponent.  Technically this opt is not required but it
-     * does lower the # of trivial squaring/reductions used
-     */
-    if (mode == 0 && y == 0) {
-      continue;
-    }
-
-    /* if the bit is zero and mode == 1 then we square */
-    if (mode == 1 && y == 0) {
-      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-        goto __RES;
-      }
-      if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-        goto __RES;
-      }
-      continue;
-    }
-
-    /* else we add it to the window */
-    bitbuf |= (y << (winsize - ++bitcpy));
-    mode    = 2;
-
-    if (bitcpy == winsize) {
-      /* ok window is filled so square as required and multiply  */
-      /* square first */
-      for (x = 0; x < winsize; x++) {
-        if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-          goto __RES;
-        }
-        if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-          goto __RES;
-        }
-      }
-
-      /* then multiply */
-      if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
-        goto __RES;
-      }
-      if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-        goto __RES;
-      }
-
-      /* empty window and reset */
-      bitcpy = 0;
-      bitbuf = 0;
-      mode   = 1;
-    }
-  }
-
-  /* if bits remain then square/multiply */
-  if (mode == 2 && bitcpy > 0) {
-    /* square then multiply if the bit is set */
-    for (x = 0; x < bitcpy; x++) {
-      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-        goto __RES;
-      }
-      if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-        goto __RES;
-      }
-
-      bitbuf <<= 1;
-      if ((bitbuf & (1 << winsize)) != 0) {
-        /* then multiply */
-        if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
-          goto __RES;
-        }
-        if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-          goto __RES;
-        }
-      }
-    }
-  }
-
-  mp_exch (&res, Y);
-  err = MP_OKAY;
-__RES:mp_clear (&res);
-__MU:mp_clear (&mu);
-__M:
-  mp_clear(&M[1]);
-  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
-    mp_clear (&M[x]);
-  }
-  return err;
-}
-
-/* End: bn_s_mp_exptmod.c */
-
-/* Start: bn_s_mp_mul_digs.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* multiplies |a| * |b| and only computes upto digs digits of result
- * HAC pp. 595, Algorithm 14.12  Modified so you can control how 
- * many digits of output are created.
- */
-int
-s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
-{
-  mp_int  t;
-  int     res, pa, pb, ix, iy;
-  mp_digit u;
-  mp_word r;
-  mp_digit tmpx, *tmpt, *tmpy;
-
-  /* can we use the fast multiplier? */
-  if (((digs) < MP_WARRAY) &&
-      MIN (a->used, b->used) < 
-          (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
-    return fast_s_mp_mul_digs (a, b, c, digs);
-  }
-
-  if ((res = mp_init_size (&t, digs)) != MP_OKAY) {
-    return res;
-  }
-  t.used = digs;
-
-  /* compute the digits of the product directly */
-  pa = a->used;
-  for (ix = 0; ix < pa; ix++) {
-    /* set the carry to zero */
-    u = 0;
-
-    /* limit ourselves to making digs digits of output */
-    pb = MIN (b->used, digs - ix);
-
-    /* setup some aliases */
-    /* copy of the digit from a used within the nested loop */
-    tmpx = a->dp[ix];
-    
-    /* an alias for the destination shifted ix places */
-    tmpt = t.dp + ix;
-    
-    /* an alias for the digits of b */
-    tmpy = b->dp;
-
-    /* compute the columns of the output and propagate the carry */
-    for (iy = 0; iy < pb; iy++) {
-      /* compute the column as a mp_word */
-      r       = ((mp_word)*tmpt) +
-                ((mp_word)tmpx) * ((mp_word)*tmpy++) +
-                ((mp_word) u);
-
-      /* the new column is the lower part of the result */
-      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
-
-      /* get the carry word from the result */
-      u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
-    }
-    /* set carry if it is placed below digs */
-    if (ix + iy < digs) {
-      *tmpt = u;
-    }
-  }
-
-  mp_clamp (&t);
-  mp_exch (&t, c);
-
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_s_mp_mul_digs.c */
-
-/* Start: bn_s_mp_mul_high_digs.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* multiplies |a| * |b| and does not compute the lower digs digits
- * [meant to get the higher part of the product]
- */
-int
-s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
-{
-  mp_int  t;
-  int     res, pa, pb, ix, iy;
-  mp_digit u;
-  mp_word r;
-  mp_digit tmpx, *tmpt, *tmpy;
-
-  /* can we use the fast multiplier? */
-  if (((a->used + b->used + 1) < MP_WARRAY)
-      && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
-    return fast_s_mp_mul_high_digs (a, b, c, digs);
-  }
-
-  if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) {
-    return res;
-  }
-  t.used = a->used + b->used + 1;
-
-  pa = a->used;
-  pb = b->used;
-  for (ix = 0; ix < pa; ix++) {
-    /* clear the carry */
-    u = 0;
-
-    /* left hand side of A[ix] * B[iy] */
-    tmpx = a->dp[ix];
-
-    /* alias to the address of where the digits will be stored */
-    tmpt = &(t.dp[digs]);
-
-    /* alias for where to read the right hand side from */
-    tmpy = b->dp + (digs - ix);
-
-    for (iy = digs - ix; iy < pb; iy++) {
-      /* calculate the double precision result */
-      r       = ((mp_word)*tmpt) +
-                ((mp_word)tmpx) * ((mp_word)*tmpy++) +
-                ((mp_word) u);
-
-      /* get the lower part */
-      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
-
-      /* carry the carry */
-      u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
-    }
-    *tmpt = u;
-  }
-  mp_clamp (&t);
-  mp_exch (&t, c);
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_s_mp_mul_high_digs.c */
-
-/* Start: bn_s_mp_sqr.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
-int
-s_mp_sqr (mp_int * a, mp_int * b)
-{
-  mp_int  t;
-  int     res, ix, iy, pa;
-  mp_word r;
-  mp_digit u, tmpx, *tmpt;
-
-  pa = a->used;
-  if ((res = mp_init_size (&t, 2*pa + 1)) != MP_OKAY) {
-    return res;
-  }
-
-  /* default used is maximum possible size */
-  t.used = 2*pa + 1;
-
-  for (ix = 0; ix < pa; ix++) {
-    /* first calculate the digit at 2*ix */
-    /* calculate double precision result */
-    r = ((mp_word) t.dp[2*ix]) +
-        ((mp_word)a->dp[ix])*((mp_word)a->dp[ix]);
-
-    /* store lower part in result */
-    t.dp[ix+ix] = (mp_digit) (r & ((mp_word) MP_MASK));
-
-    /* get the carry */
-    u           = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
-
-    /* left hand side of A[ix] * A[iy] */
-    tmpx        = a->dp[ix];
-
-    /* alias for where to store the results */
-    tmpt        = t.dp + (2*ix + 1);
-    
-    for (iy = ix + 1; iy < pa; iy++) {
-      /* first calculate the product */
-      r       = ((mp_word)tmpx) * ((mp_word)a->dp[iy]);
-
-      /* now calculate the double precision result, note we use
-       * addition instead of *2 since it's easier to optimize
-       */
-      r       = ((mp_word) *tmpt) + r + r + ((mp_word) u);
-
-      /* store lower part */
-      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
-
-      /* get carry */
-      u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
-    }
-    /* propagate upwards */
-    while (u != ((mp_digit) 0)) {
-      r       = ((mp_word) *tmpt) + ((mp_word) u);
-      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
-      u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
-    }
-  }
-
-  mp_clamp (&t);
-  mp_exch (&t, b);
-  mp_clear (&t);
-  return MP_OKAY;
-}
-
-/* End: bn_s_mp_sqr.c */
-
-/* Start: bn_s_mp_sub.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
-int
-s_mp_sub (mp_int * a, mp_int * b, mp_int * c)
-{
-  int     olduse, res, min, max;
-
-  /* find sizes */
-  min = b->used;
-  max = a->used;
-
-  /* init result */
-  if (c->alloc < max) {
-    if ((res = mp_grow (c, max)) != MP_OKAY) {
-      return res;
-    }
-  }
-  olduse = c->used;
-  c->used = max;
-
-  {
-    register mp_digit u, *tmpa, *tmpb, *tmpc;
-    register int i;
-
-    /* alias for digit pointers */
-    tmpa = a->dp;
-    tmpb = b->dp;
-    tmpc = c->dp;
-
-    /* set carry to zero */
-    u = 0;
-    for (i = 0; i < min; i++) {
-      /* T[i] = A[i] - B[i] - U */
-      *tmpc = *tmpa++ - *tmpb++ - u;
-
-      /* U = carry bit of T[i]
-       * Note this saves performing an AND operation since
-       * if a carry does occur it will propagate all the way to the
-       * MSB.  As a result a single shift is enough to get the carry
-       */
-      u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1));
-
-      /* Clear carry from T[i] */
-      *tmpc++ &= MP_MASK;
-    }
-
-    /* now copy higher words if any, e.g. if A has more digits than B  */
-    for (; i < max; i++) {
-      /* T[i] = A[i] - U */
-      *tmpc = *tmpa++ - u;
-
-      /* U = carry bit of T[i] */
-      u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1));
-
-      /* Clear carry from T[i] */
-      *tmpc++ &= MP_MASK;
-    }
-
-    /* clear digits above used (since we may not have grown result above) */
-    for (i = c->used; i < olduse; i++) {
-      *tmpc++ = 0;
-    }
-  }
-
-  mp_clamp (c);
-  return MP_OKAY;
-}
-
-
-/* End: bn_s_mp_sub.c */
-
-/* Start: bncore.c */
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#include <ltc_tommath.h>
-
-/* Known optimal configurations
-
- CPU                    /Compiler     /MUL CUTOFF/SQR CUTOFF
--------------------------------------------------------------
- Intel P4 Northwood     /GCC v3.3.3   /        59/        81/profiled build
- Intel P4 Northwood     /GCC v3.3.3   /        59/        80/profiled_single build
- Intel P4 Northwood     /ICC v8.0     /        57/        70/profiled build
- Intel P4 Northwood     /ICC v8.0     /        54/        76/profiled_single build
- AMD Athlon XP          /GCC v3.2     /       109/       127/
- 
-*/
-
-int     KARATSUBA_MUL_CUTOFF = 57,      /* Min. number of digits before Karatsuba multiplication is used. */
-        KARATSUBA_SQR_CUTOFF = 70,      /* Min. number of digits before Karatsuba squaring is used. */
-        
-        TOOM_MUL_CUTOFF      = 350,      /* no optimal values of these are known yet so set em high */
-        TOOM_SQR_CUTOFF      = 400; 
-
-/* End: bncore.c */
-
-
-/* EOF */
diff --git a/mpi_to_ltc_error.c b/mpi_to_ltc_error.c
deleted file mode 100644
index 015b1b2..0000000
--- a/mpi_to_ltc_error.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MPI
-static const struct {
-    int mpi_code, ltc_code;
-} mpi_to_ltc_codes[] = {
-   { MP_OKAY ,  CRYPT_OK},
-   { MP_MEM  ,  CRYPT_MEM},
-   { MP_VAL  ,  CRYPT_INVALID_ARG},
-};
-
-/* convert a MPI error to a LTC error (Possibly the most powerful function ever!  Oh wait... no) */
-int mpi_to_ltc_error(int err)
-{
-   int x;
-
-   for (x = 0; x < (int)(sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0])); x++) {
-       if (err == mpi_to_ltc_codes[x].mpi_code) { 
-          return mpi_to_ltc_codes[x].ltc_code;
-       }
-   }
-   return CRYPT_ERROR;
-}
-#endif
-
diff --git a/mycrypt_argchk.h b/mycrypt_argchk.h
deleted file mode 100644
index 8f38e54..0000000
--- a/mycrypt_argchk.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Defines the _ARGCHK macro used within the library */
-
-/* ch1-01-1 */
-/* ARGTYPE is defined in mycrypt_cfg.h */
-#if ARGTYPE == 0
-
-#include <signal.h>
-
-/* this is the default LibTomCrypt macro  */
-extern void crypt_argchk(char *v, char *s, int d);
-#define _ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); }
-
-#elif ARGTYPE == 1
-
-/* fatal type of error */
-#define _ARGCHK(x) assert((x))
-
-#elif ARGTYPE == 2
-
-#define _ARGCHK(x) 
-
-#endif
-/* ch1-01-1 */
-
diff --git a/mycrypt_cfg.h b/mycrypt_cfg.h
deleted file mode 100644
index 4d6c5db..0000000
--- a/mycrypt_cfg.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* This is the build config file.
- *
- * With this you can setup what to inlcude/exclude automatically during any build.  Just comment
- * out the line that #define's the word for the thing you want to remove.  phew!
- */
-
-#ifndef MYCRYPT_CFG_H
-#define MYCRYPT_CFG_H
-
-/* you can change how memory allocation works ... */
-extern void *XMALLOC(size_t n);
-extern void *REALLOC(void *p, size_t n);
-extern void *XCALLOC(size_t n, size_t s);
-extern void XFREE(void *p);
-
-/* change the clock function too */
-extern clock_t XCLOCK(void);
-
-/* ch1-01-1 */
-/* type of argument checking, 0=default, 1=fatal and 2=none */
-#define ARGTYPE  0
-/* ch1-01-1 */
-
-/* Controls endianess and size of registers.  Leave uncommented to get platform neutral [slower] code */
-/* detect x86-32 machines somewhat */
-#if defined(INTEL_CC) || (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))
-   #define ENDIAN_LITTLE
-   #define ENDIAN_32BITWORD
-#endif
-
-/* detects MIPS R5900 processors (PS2) */
-#if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips))
-   #define ENDIAN_LITTLE
-   #define ENDIAN_64BITWORD
-#endif
-
-/* #define ENDIAN_LITTLE */
-/* #define ENDIAN_BIG */
-
-/* #define ENDIAN_32BITWORD */
-/* #define ENDIAN_64BITWORD */
-
-#if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
-    #error You must specify a word size as well as endianess in mycrypt_cfg.h
-#endif
-
-#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
-   #define ENDIAN_NEUTRAL
-#endif
-
-#ifdef YARROW
-   #ifndef CTR
-      #error YARROW requires CTR chaining mode to be defined!
-   #endif
-#endif
-
-/* packet code */
-#if defined(MRSA) || defined(MDH) || defined(MECC)
-    #define PACKET
-
-    /* size of a packet header in bytes */
-    #define PACKET_SIZE            4
-
-    /* Section tags */
-    #define PACKET_SECT_RSA        0
-    #define PACKET_SECT_DH         1
-    #define PACKET_SECT_ECC        2
-    #define PACKET_SECT_DSA        3
-
-    /* Subsection Tags for the first three sections */
-    #define PACKET_SUB_KEY         0
-    #define PACKET_SUB_ENCRYPTED   1
-    #define PACKET_SUB_SIGNED      2
-    #define PACKET_SUB_ENC_KEY     3
-#endif
-
-#endif /* MYCRYPT_CFG_H */
-
diff --git a/mycrypt_cipher.h b/mycrypt_cipher.h
deleted file mode 100644
index ec68bbd..0000000
--- a/mycrypt_cipher.h
+++ /dev/null
@@ -1,396 +0,0 @@
-/* ---- SYMMETRIC KEY STUFF -----
- *
- * We put each of the ciphers scheduled keys in their own structs then we put all of 
- * the key formats in one union.  This makes the function prototypes easier to use.
- */
-#ifdef BLOWFISH
-struct blowfish_key {
-   ulong32 S[4][256];
-   ulong32 K[18];
-};
-#endif
-
-#ifdef RC5
-struct rc5_key {
-   int rounds;
-   ulong32 K[50];
-};
-#endif
-
-#ifdef RC6
-struct rc6_key {
-   ulong32 K[44];
-};
-#endif
-
-#ifdef SAFERP
-struct saferp_key {
-   unsigned char K[33][16];
-   long rounds;
-};
-#endif
-
-#ifdef RIJNDAEL
-struct rijndael_key {
-   ulong32 eK[64], dK[64];
-   int Nr;
-};
-#endif
-
-#ifdef XTEA
-struct xtea_key {
-   unsigned long A[32], B[32];
-};
-#endif
-
-#ifdef TWOFISH
-#ifndef TWOFISH_SMALL
-   struct twofish_key {
-      ulong32 S[4][256], K[40];
-   };
-#else
-   struct twofish_key {
-      ulong32 K[40];
-      unsigned char S[32], start;
-   };
-#endif
-#endif
-
-#ifdef SAFER
-#define SAFER_K64_DEFAULT_NOF_ROUNDS     6
-#define SAFER_K128_DEFAULT_NOF_ROUNDS   10
-#define SAFER_SK64_DEFAULT_NOF_ROUNDS    8
-#define SAFER_SK128_DEFAULT_NOF_ROUNDS  10
-#define SAFER_MAX_NOF_ROUNDS            13
-#define SAFER_BLOCK_LEN                  8
-#define SAFER_KEY_LEN     (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS))
-typedef unsigned char safer_block_t[SAFER_BLOCK_LEN];
-typedef unsigned char safer_key_t[SAFER_KEY_LEN];
-struct safer_key { safer_key_t key; };
-#endif
-
-#ifdef RC2
-struct rc2_key { unsigned xkey[64]; };
-#endif
-
-#ifdef DES
-struct des_key {
-    ulong32 ek[32], dk[32];
-};
-
-struct des3_key {
-    ulong32 ek[3][32], dk[3][32];
-};
-#endif
-
-#ifdef CAST5
-struct cast5_key {
-    ulong32 K[32], keylen;
-};
-#endif
-
-#ifdef NOEKEON
-struct noekeon_key {
-    ulong32 K[4], dK[4];
-};
-#endif
-
-#ifdef SKIPJACK 
-struct skipjack_key {
-    unsigned char key[10];
-};
-#endif
-
-typedef union Symmetric_key {
-#ifdef DES
-   struct des_key des;
-   struct des3_key des3;
-#endif
-#ifdef RC2
-   struct rc2_key rc2;
-#endif
-#ifdef SAFER
-   struct safer_key safer;
-#endif
-#ifdef TWOFISH
-   struct twofish_key  twofish;
-#endif
-#ifdef BLOWFISH
-   struct blowfish_key blowfish;
-#endif
-#ifdef RC5
-   struct rc5_key      rc5;
-#endif
-#ifdef RC6
-   struct rc6_key      rc6;
-#endif
-#ifdef SAFERP
-   struct saferp_key   saferp;
-#endif
-#ifdef RIJNDAEL
-   struct rijndael_key rijndael;
-#endif
-#ifdef XTEA
-   struct xtea_key     xtea;
-#endif
-#ifdef CAST5
-   struct cast5_key    cast5;
-#endif
-#ifdef NOEKEON
-   struct noekeon_key  noekeon;
-#endif   
-#ifdef SKIPJACK
-   struct skipjack_key skipjack;
-#endif
-} symmetric_key;
-
-/* A block cipher ECB structure */
-typedef struct {
-   int                 cipher, blocklen;
-   symmetric_key       key;
-} symmetric_ECB;
-
-/* A block cipher CFB structure */
-typedef struct {
-   int                 cipher, blocklen, padlen;
-   unsigned char       IV[MAXBLOCKSIZE], pad[MAXBLOCKSIZE];
-   symmetric_key       key;
-} symmetric_CFB;
-
-/* A block cipher OFB structure */
-typedef struct {
-   int                 cipher, blocklen, padlen;
-   unsigned char       IV[MAXBLOCKSIZE];
-   symmetric_key       key;
-} symmetric_OFB;
-
-/* A block cipher CBC structure */
-typedef struct Symmetric_CBC {
-   int                 cipher, blocklen;
-   unsigned char       IV[MAXBLOCKSIZE];
-   symmetric_key       key;
-} symmetric_CBC;
-
-/* A block cipher CTR structure */
-typedef struct Symmetric_CTR {
-   int                 cipher, blocklen, padlen, mode;
-   unsigned char       ctr[MAXBLOCKSIZE], pad[MAXBLOCKSIZE];
-   symmetric_key       key;
-} symmetric_CTR;
-
-/* cipher descriptor table, last entry has "name == NULL" to mark the end of table */
-extern  struct _cipher_descriptor {
-   char *name;
-   unsigned char ID;
-   int  min_key_length, max_key_length, block_length, default_rounds;
-   int  (*setup)(const unsigned char *key, int keylength, int num_rounds, symmetric_key *skey);
-   void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-   void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-   int (*test)(void);
-   int  (*keysize)(int *desired_keysize);
-} cipher_descriptor[];
-
-#ifdef BLOWFISH
-extern int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int blowfish_test(void);
-extern int blowfish_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor blowfish_desc;
-#endif
-
-#ifdef RC5
-extern int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int rc5_test(void);
-extern int rc5_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor rc5_desc;
-#endif
-
-#ifdef RC6
-extern int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int rc6_test(void);
-extern int rc6_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor rc6_desc;
-#endif
-
-#ifdef RC2
-extern int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int rc2_test(void);
-extern int rc2_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor rc2_desc;
-#endif
-
-#ifdef SAFERP
-extern int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int saferp_test(void);
-extern int saferp_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor saferp_desc;
-#endif
-
-#ifdef SAFER
-extern int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-
-extern int safer_k64_test(void);
-extern int safer_sk64_test(void);
-extern int safer_sk128_test(void);
-
-extern int safer_64_keysize(int *desired_keysize);
-extern int safer_128_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc;
-#endif
-
-#ifdef RIJNDAEL
-
-/* make aes an alias */
-#define aes_setup           rijndael_setup
-#define aes_ecb_encrypt     rijndael_ecb_encrypt
-#define aes_ecb_decrypt     rijndael_ecb_decrypt
-#define aes_test            rijndael_test
-#define aes_keysize         rijndael_keysize
-
-#define aes_enc_setup           rijndael_enc_setup
-#define aes_enc_ecb_encrypt     rijndael_enc_ecb_encrypt
-#define aes_enc_keysize         rijndael_enc_keysize
-
-extern int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int rijndael_test(void);
-extern int rijndael_keysize(int *desired_keysize);
-
-extern int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern int rijndael_enc_keysize(int *desired_keysize);
-
-extern const struct _cipher_descriptor rijndael_desc, aes_desc;
-extern const struct _cipher_descriptor rijndael_enc_desc, aes_enc_desc;
-#endif
-
-#ifdef XTEA
-extern int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int xtea_test(void);
-extern int xtea_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor xtea_desc;
-#endif
-
-#ifdef TWOFISH
-extern int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int twofish_test(void);
-extern int twofish_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor twofish_desc;
-#endif
-
-#ifdef DES
-extern int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int des_test(void);
-extern int des_keysize(int *desired_keysize);
-
-extern int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int des3_test(void);
-extern int des3_keysize(int *desired_keysize);
-
-extern const struct _cipher_descriptor des_desc, des3_desc;
-#endif
-
-#ifdef CAST5
-extern int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int cast5_test(void);
-extern int cast5_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor cast5_desc;
-#endif
-
-#ifdef NOEKEON
-extern int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int noekeon_test(void);
-extern int noekeon_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor noekeon_desc;
-#endif
-
-#ifdef SKIPJACK
-extern int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-extern void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
-extern void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
-extern int skipjack_test(void);
-extern int skipjack_keysize(int *desired_keysize);
-extern const struct _cipher_descriptor skipjack_desc;
-#endif
-
-#ifdef ECB
-extern int ecb_start(int cipher, const unsigned char *key, 
-                     int keylen, int num_rounds, symmetric_ECB *ecb);
-extern int ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ECB *ecb);
-extern int ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_ECB *ecb);
-#endif
-
-#ifdef CFB
-extern int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-                     int keylen, int num_rounds, symmetric_CFB *cfb);
-extern int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
-extern int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
-extern int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
-extern int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
-#endif
-
-#ifdef OFB
-extern int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-                     int keylen, int num_rounds, symmetric_OFB *ofb);
-extern int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
-extern int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
-extern int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
-extern int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
-#endif
-
-#ifdef CBC
-extern int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
-                     int keylen, int num_rounds, symmetric_CBC *cbc);
-extern int cbc_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_CBC *cbc);
-extern int cbc_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_CBC *cbc);
-extern int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
-extern int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
-#endif
-
-#ifdef CTR
-extern int ctr_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-                     int keylen, int num_rounds, symmetric_CTR *ctr);
-extern int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr);
-extern int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr);
-extern int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr);
-extern int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
-#endif
-
-
-    
-extern int find_cipher(const char *name);
-extern int find_cipher_any(const char *name, int blocklen, int keylen);
-extern int find_cipher_id(unsigned char ID);
-
-extern int register_cipher(const struct _cipher_descriptor *cipher);
-extern int unregister_cipher(const struct _cipher_descriptor *cipher);
-
-extern int cipher_is_valid(int idx);
-
diff --git a/mycrypt_custom.h b/mycrypt_custom.h
deleted file mode 100644
index 2a2856e..0000000
--- a/mycrypt_custom.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* 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 MYCRYPT_CUSTOM_H_
-#define MYCRYPT_CUSTOM_H_
-
-/* this will sort out which stuff based on the user-config in options.h */
-#include "../options.h"
-
-#ifdef CRYPT
-	#error mycrypt_custom.h should be included before mycrypt.h
-#endif
-
-/* macros for various libc functions */
-#define XMALLOC malloc
-#define XREALLOC realloc
-#define XCALLOC calloc
-#define XFREE free
-#define XCLOCK clock
-#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
-
-#ifdef DROPBEAR_SMALL_CODE
-#define SMALL_CODE
-#endif
-
-/* #define LTC_TEST */
-#define CLEAN_STACK
-#define NO_FILE
-
-#ifdef DROPBEAR_BLOWFISH_CBC
-#define BLOWFISH
-#endif
-
-#ifdef DROPBEAR_AES128_CBC
-#define RIJNDAEL
-#endif
-
-#ifdef DROPBEAR_TWOFISH128_CBC
-#define TWOFISH
-
-/* enabling just TWOFISH_SMALL will make the binary ~1kB smaller, turning on
- * TWOFISH_TABLES will make it a few kB bigger, but perhaps reduces runtime
- * memory usage? */
-#define TWOFISH_SMALL
-/*#define TWOFISH_TABLES*/
-#endif
-
-#ifdef DROPBEAR_3DES_CBC
-#define DES
-#endif
-
-#define CBC
-
-#if defined(DROPBEAR_DSS) && defined(DSS_PROTOK)
-#define SHA512
-#endif
-
-#define SHA1
-
-#ifdef DROPBEAR_MD5_HMAC
-#define MD5
-#endif
-
-#define HMAC
-#define BASE64
-
-#include <mycrypt.h>
-
-#endif
-
diff --git a/mycrypt_gf.h b/mycrypt_gf.h
deleted file mode 100644
index 331065d..0000000
--- a/mycrypt_gf.h
+++ /dev/null
@@ -1,32 +0,0 @@
-
-/* ---- GF(2^w) polynomial basis ---- */
-#ifdef GF
-#define   LSIZE    32   /* handle upto 1024-bit GF numbers */
-
-typedef unsigned long gf_int[LSIZE];
-typedef unsigned long *gf_intp;
-
-extern void gf_copy(gf_intp a, gf_intp b);
-extern void gf_zero(gf_intp a);
-extern int gf_iszero(gf_intp a);
-extern int gf_isone(gf_intp a);
-extern int gf_deg(gf_intp a);
-
-extern void gf_shl(gf_intp a, gf_intp b);
-extern void gf_shr(gf_intp a, gf_intp b);
-extern void gf_add(gf_intp a, gf_intp b, gf_intp c);
-extern void gf_mul(gf_intp a, gf_intp b, gf_intp c);
-extern void gf_div(gf_intp a, gf_intp b, gf_intp q, gf_intp r);
-
-extern void gf_mod(gf_intp a, gf_intp m, gf_intp b);
-extern void gf_mulmod(gf_intp a, gf_intp b, gf_intp m, gf_intp c);
-extern void gf_invmod(gf_intp A, gf_intp M, gf_intp B);
-extern void gf_sqrt(gf_intp a, gf_intp M, gf_intp b);
-extern void gf_gcd(gf_intp A, gf_intp B, gf_intp c);
-extern int gf_is_prime(gf_intp a);
-
-extern int gf_size(gf_intp a);
-extern void gf_toraw(gf_intp a, unsigned char *dst);
-extern void gf_readraw(gf_intp a, unsigned char *str, int len);
-
-#endif
diff --git a/mycrypt_hash.h b/mycrypt_hash.h
deleted file mode 100644
index 93df9e9..0000000
--- a/mycrypt_hash.h
+++ /dev/null
@@ -1,449 +0,0 @@
-/* ---- HASH FUNCTIONS ---- */
-#ifdef SHA512
-struct sha512_state {
-    ulong64  length, state[8];
-    unsigned long curlen;
-    unsigned char buf[128];
-};
-#endif
-
-#ifdef SHA256
-struct sha256_state {
-    ulong64 length;
-    ulong32 state[8], curlen;
-    unsigned char buf[64];
-};
-#endif
-
-#ifdef SHA1
-struct sha1_state {
-    ulong64 length;
-    ulong32 state[5], curlen;
-    unsigned char buf[64];
-};
-#endif
-
-#ifdef MD5
-struct md5_state {
-    ulong64 length;
-    ulong32 state[4], curlen;
-    unsigned char buf[64];
-};
-#endif
-
-#ifdef MD4
-struct md4_state {
-    ulong64 length;
-    ulong32 state[4], curlen;
-    unsigned char buf[64];
-};
-#endif
-
-#ifdef TIGER
-struct tiger_state {
-    ulong64 state[3], length;
-    unsigned long curlen;
-    unsigned char buf[64];
-};
-#endif
-
-#ifdef MD2
-struct md2_state {
-    unsigned char chksum[16], X[48], buf[16];
-    unsigned long curlen;
-};
-#endif
-
-#ifdef RIPEMD128
-struct rmd128_state {
-    ulong64 length;
-    unsigned char buf[64];
-    ulong32 curlen, state[4];
-};
-#endif
-
-#ifdef RIPEMD160
-struct rmd160_state {
-    ulong64 length;
-    unsigned char buf[64];
-    ulong32 curlen, state[5];
-};
-#endif
-
-#ifdef WHIRLPOOL
-struct whirlpool_state {
-    ulong64 length, state[8];
-    unsigned char buf[64];
-    ulong32 curlen;
-};
-#endif
-
-typedef union Hash_state {
-#ifdef WHIRLPOOL
-    struct whirlpool_state whirlpool;
-#endif
-#ifdef SHA512
-    struct sha512_state sha512;
-#endif
-#ifdef SHA256
-    struct sha256_state sha256;
-#endif
-#ifdef SHA1
-    struct sha1_state   sha1;
-#endif
-#ifdef MD5
-    struct md5_state    md5;
-#endif
-#ifdef MD4
-    struct md4_state    md4;
-#endif
-#ifdef MD2
-    struct md2_state    md2;
-#endif
-#ifdef TIGER
-    struct tiger_state  tiger;
-#endif
-#ifdef RIPEMD128
-    struct rmd128_state rmd128;
-#endif
-#ifdef RIPEMD160
-    struct rmd160_state rmd160;
-#endif
-} hash_state;
-
-extern struct _hash_descriptor {
-    char *name;
-    unsigned char ID;
-    unsigned long hashsize;       /* digest output size in bytes  */
-    unsigned long blocksize;      /* the block size the hash uses */
-    unsigned char DER[64];        /* DER encoded identifier */
-    unsigned long DERlen;         /* length of DER encoding */
-    void (*init)(hash_state *);
-    int (*process)(hash_state *, const unsigned char *, unsigned long);
-    int (*done)(hash_state *, unsigned char *);
-    int  (*test)(void);
-} hash_descriptor[];
-
-
-#ifdef WHIRLPOOL
-extern void whirlpool_init(hash_state * md);
-extern int whirlpool_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int whirlpool_done(hash_state * md, unsigned char *hash);
-extern int  whirlpool_test(void);
-extern const struct _hash_descriptor whirlpool_desc;
-#endif
-
-#ifdef SHA512
-extern void sha512_init(hash_state * md);
-extern int sha512_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int sha512_done(hash_state * md, unsigned char *hash);
-extern int  sha512_test(void);
-extern const struct _hash_descriptor sha512_desc;
-#endif
-
-#ifdef SHA384
-#ifndef SHA512
-   #error SHA512 is required for SHA384
-#endif
-extern void sha384_init(hash_state * md);
-#define sha384_process sha512_process
-extern int sha384_done(hash_state * md, unsigned char *hash);
-extern int  sha384_test(void);
-extern const struct _hash_descriptor sha384_desc;
-#endif
-
-#ifdef SHA256
-extern void sha256_init(hash_state * md);
-extern int sha256_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int sha256_done(hash_state * md, unsigned char *hash);
-extern int  sha256_test(void);
-extern const struct _hash_descriptor sha256_desc;
-
-#ifdef SHA224
-#ifndef SHA256
-   #error SHA256 is required for SHA224
-#endif
-extern void sha224_init(hash_state * md);
-#define sha224_process sha256_process
-extern int sha224_done(hash_state * md, unsigned char *hash);
-extern int  sha224_test(void);
-extern const struct _hash_descriptor sha224_desc;
-#endif
-#endif
-
-#ifdef SHA1
-extern void sha1_init(hash_state * md);
-extern int sha1_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int sha1_done(hash_state * md, unsigned char *hash);
-extern int  sha1_test(void);
-extern const struct _hash_descriptor sha1_desc;
-#endif
-
-#ifdef MD5
-extern void md5_init(hash_state * md);
-extern int md5_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int md5_done(hash_state * md, unsigned char *hash);
-extern int  md5_test(void);
-extern const struct _hash_descriptor md5_desc;
-#endif
-
-#ifdef MD4
-extern void md4_init(hash_state * md);
-extern int md4_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int md4_done(hash_state * md, unsigned char *hash);
-extern int  md4_test(void);
-extern const struct _hash_descriptor md4_desc;
-#endif
-
-#ifdef MD2
-extern void md2_init(hash_state * md);
-extern int md2_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int md2_done(hash_state * md, unsigned char *hash);
-extern int  md2_test(void);
-extern const struct _hash_descriptor md2_desc;
-#endif
-
-#ifdef TIGER
-extern void tiger_init(hash_state * md);
-extern int tiger_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int tiger_done(hash_state * md, unsigned char *hash);
-extern int  tiger_test(void);
-extern const struct _hash_descriptor tiger_desc;
-#endif
-
-#ifdef RIPEMD128
-extern void rmd128_init(hash_state * md);
-extern int rmd128_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int rmd128_done(hash_state * md, unsigned char *hash);
-extern int  rmd128_test(void);
-extern const struct _hash_descriptor rmd128_desc;
-#endif
-
-#ifdef RIPEMD160
-extern void rmd160_init(hash_state * md);
-extern int rmd160_process(hash_state * md, const unsigned char *buf, unsigned long len);
-extern int rmd160_done(hash_state * md, unsigned char *hash);
-extern int  rmd160_test(void);
-extern const struct _hash_descriptor rmd160_desc;
-#endif
-
-
-extern int find_hash(const char *name);
-extern int find_hash_id(unsigned char ID);
-extern int find_hash_any(const char *name, int digestlen);
-extern int register_hash(const struct _hash_descriptor *hash);
-extern int unregister_hash(const struct _hash_descriptor *hash);
-extern int hash_is_valid(int idx);
-
-extern int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen);
-extern int hash_filehandle(int hash, FILE *in, unsigned char *dst, unsigned long *outlen);
-extern int hash_file(int hash, const char *fname, unsigned char *dst, unsigned long *outlen);
-
-/* a simple macro for making hash "process" functions */
-#define HASH_PROCESS(func_name, compress_name, state_var, block_size)                       \
-int func_name (hash_state * md, const unsigned char *buf, unsigned long len)               \
-{                                                                                           \
-    unsigned long n;                                                                        \
-    _ARGCHK(md != NULL);                                                                    \
-    _ARGCHK(buf != NULL);                                                                   \
-    if (md-> state_var .curlen > sizeof(md-> state_var .buf)) {                             \
-       return CRYPT_INVALID_ARG;                                                            \
-    }                                                                                       \
-    while (len > 0) {                                                                       \
-        if (md-> state_var .curlen == 0 && len >= block_size) {                             \
-           compress_name (md, (unsigned char *)buf);                                        \
-           md-> state_var .length += block_size * 8;                                        \
-           buf             += block_size;                                                   \
-           len             -= block_size;                                                   \
-        } else {                                                                            \
-           n = MIN(len, (block_size - md-> state_var .curlen));                             \
-           memcpy(md-> state_var .buf + md-> state_var.curlen, buf, (size_t)n);             \
-           md-> state_var .curlen += n;                                                     \
-           buf             += n;                                                            \
-           len             -= n;                                                            \
-           if (md-> state_var .curlen == block_size) {                                      \
-              compress_name (md, md-> state_var .buf);                                      \
-              md-> state_var .length += 8*block_size;                                       \
-              md-> state_var .curlen = 0;                                                   \
-           }                                                                                \
-       }                                                                                    \
-    }                                                                                       \
-    return CRYPT_OK;                                                                        \
-}
-
-#ifdef HMAC
-typedef struct Hmac_state {
-     hash_state     md;
-     int            hash;
-     hash_state     hashstate;
-     unsigned char  key[MAXBLOCKSIZE];
-} hmac_state;
-
-extern int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
-extern int hmac_process(hmac_state *hmac, const unsigned char *buf, unsigned long len);
-extern int hmac_done(hmac_state *hmac, unsigned char *hashOut, unsigned long *outlen);
-extern int hmac_test(void);
-extern int hmac_memory(int hash, const unsigned char *key, unsigned long keylen,
-                       const unsigned char *data, unsigned long len, 
-                       unsigned char *dst, unsigned long *dstlen);
-extern int hmac_file(int hash, const char *fname, const unsigned char *key,
-                     unsigned long keylen, 
-                     unsigned char *dst, unsigned long *dstlen);
-#endif
-
-#ifdef OMAC
-
-typedef struct {
-   int             cipher_idx, 
-                   buflen,
-                   blklen;
-   unsigned char   block[MAXBLOCKSIZE],
-                   prev[MAXBLOCKSIZE],
-                   Lu[2][MAXBLOCKSIZE];
-   symmetric_key   key;
-} omac_state;
-
-extern int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
-extern int omac_process(omac_state *state, const unsigned char *buf, unsigned long len);
-extern int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen);
-extern int omac_memory(int cipher, const unsigned char *key, unsigned long keylen,
-                const unsigned char *msg, unsigned long msglen,
-                unsigned char *out, unsigned long *outlen);
-extern int omac_file(int cipher, const unsigned char *key, unsigned long keylen,
-              const char *filename, unsigned char *out, unsigned long *outlen);
-extern int omac_test(void);
-#endif /* OMAC */
-
-#ifdef PMAC
-
-typedef struct {
-   unsigned char     Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
-                     Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
-                     Lr[MAXBLOCKSIZE],        /* L * x^-1 */
-                     block[MAXBLOCKSIZE],     /* currently accumulated block */
-                     checksum[MAXBLOCKSIZE];  /* current checksum */
-
-   symmetric_key     key;                     /* scheduled key for cipher */
-   unsigned long     block_index;             /* index # for current block */
-   int               cipher_idx,              /* cipher idx */
-                     block_len,               /* length of block */
-                     buflen;                  /* number of bytes in the buffer */
-} pmac_state;
-
-extern int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
-extern int pmac_process(pmac_state *state, const unsigned char *buf, unsigned long len);
-extern int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen);
-
-extern int pmac_memory(int cipher, const unsigned char *key, unsigned long keylen,
-                const unsigned char *msg, unsigned long msglen,
-                unsigned char *out, unsigned long *outlen);
-
-extern int pmac_file(int cipher, const unsigned char *key, unsigned long keylen,
-              const char *filename, unsigned char *out, unsigned long *outlen);
-
-extern int pmac_test(void);
-
-/* internal functions */
-extern int pmac_ntz(unsigned long x);
-extern void pmac_shift_xor(pmac_state *pmac);
-
-#endif /* PMAC */
-
-#ifdef EAX_MODE
-
-#if !(defined(OMAC) && defined(CTR))
-   #error EAX_MODE requires OMAC and CTR
-#endif
-
-typedef struct {
-   unsigned char N[MAXBLOCKSIZE];
-   symmetric_CTR ctr;
-   omac_state    headeromac, ctomac;
-} eax_state;
-
-extern int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
-                    const unsigned char *nonce, unsigned long noncelen,
-                    const unsigned char *header, unsigned long headerlen);
-
-extern int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
-extern int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
-extern int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
-extern int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
-
-extern int eax_encrypt_authenticate_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  unsigned long noncelen,
-    const unsigned char *header, unsigned long headerlen,
-    const unsigned char *pt,     unsigned long ptlen,
-          unsigned char *ct,
-          unsigned char *tag,    unsigned long *taglen);
-
-extern int eax_decrypt_verify_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  unsigned long noncelen,
-    const unsigned char *header, unsigned long headerlen,
-    const unsigned char *ct,     unsigned long ctlen,
-          unsigned char *pt,
-          unsigned char *tag,    unsigned long taglen,
-          int           *res);
-
-extern int eax_test(void);
-#endif /* EAX MODE */
-
-#ifdef OCB_MODE
-typedef struct {
-   unsigned char     L[MAXBLOCKSIZE],         /* L value */
-                     Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
-                     Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
-                     Lr[MAXBLOCKSIZE],        /* L * x^-1 */
-                     R[MAXBLOCKSIZE],         /* R value */
-                     checksum[MAXBLOCKSIZE];  /* current checksum */
-
-   symmetric_key     key;                     /* scheduled key for cipher */
-   unsigned long     block_index;             /* index # for current block */
-   int               cipher,                  /* cipher idx */
-                     block_len;               /* length of block */
-} ocb_state;
-
-extern int ocb_init(ocb_state *ocb, int cipher, 
-             const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
-
-extern int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
-extern int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
-
-extern int ocb_done_encrypt(ocb_state *ocb, 
-                     const unsigned char *pt,  unsigned long ptlen,
-                           unsigned char *ct, 
-                           unsigned char *tag, unsigned long *taglen);
-
-extern int ocb_done_decrypt(ocb_state *ocb, 
-                     const unsigned char *ct,  unsigned long ctlen,
-                           unsigned char *pt, 
-                     const unsigned char *tag, unsigned long taglen, int *res);
-
-extern int ocb_encrypt_authenticate_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  
-    const unsigned char *pt,     unsigned long ptlen,
-          unsigned char *ct,
-          unsigned char *tag,    unsigned long *taglen);
-
-extern int ocb_decrypt_verify_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  
-    const unsigned char *ct,     unsigned long ctlen,
-          unsigned char *pt,
-    const unsigned char *tag,    unsigned long taglen,
-          int           *res);
-
-extern int ocb_test(void);
-
-/* internal functions */
-extern void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
-extern int ocb_ntz(unsigned long x);
-extern int __ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
-                     unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
-
-#endif /* OCB_MODE */
-
-
diff --git a/mycrypt_kr.h b/mycrypt_kr.h
deleted file mode 100644
index 6dc16cd..0000000
--- a/mycrypt_kr.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifdef KR
-
-#if !defined(MRSA) || !defined(MDH) || !defined(MECC)
-    #error "Keyring code requires all three public key algorithms."
-#endif
-
-#define MAXLEN    256
-
-enum {
-   NON_KEY=0,
-   RSA_KEY,
-   DH_KEY,
-   ECC_KEY
-};
-
-typedef union {
-    rsa_key rsa;
-    dh_key  dh;
-    ecc_key ecc;
-} _pk_key;
-
-typedef struct Pk_key {
-    int     key_type,             /* PUBLIC, PRIVATE, PRIVATE_OPTIMIZED */
-            system;               /* RSA, ECC or DH ?   */
-
-    unsigned char 
-            name[MAXLEN],         /* various info's about this key */
-            email[MAXLEN],
-            description[MAXLEN];
-
-    unsigned long ID;             /* CRC32 of the name/email/description together */
-
-    _pk_key key;
-
-    struct Pk_key  *next;         /* linked list chain */
-} pk_key;
-
-extern int kr_init(pk_key **pk);
-
-extern unsigned long kr_crc(const unsigned char *name, const unsigned char *email, const unsigned char *description);
-
-extern pk_key *kr_find(pk_key *pk, unsigned long ID);
-extern pk_key *kr_find_name(pk_key *pk, const char *name);
-
-extern int kr_add(pk_key *pk, int key_type, int sys, const unsigned char *name, 
-                  const unsigned char *email, const unsigned char *description, const _pk_key *key);
-                  
-extern int kr_del(pk_key **_pk, unsigned long ID);
-extern int kr_clear(pk_key **pk);
-extern int kr_make_key(pk_key *pk, prng_state *prng, int wprng, 
-                       int sys, int keysize, const unsigned char *name,
-                       const unsigned char *email, const unsigned char *description);
-
-extern int kr_export(pk_key *pk, unsigned long ID, int key_type, unsigned char *out, unsigned long *outlen);
-extern int kr_import(pk_key *pk, const unsigned char *in, unsigned long inlen);
-
-extern int kr_load(pk_key **pk, FILE *in, symmetric_CTR *ctr);
-extern int kr_save(pk_key *pk, FILE *out, symmetric_CTR *ctr);
-
-extern int kr_encrypt_key(pk_key *pk, unsigned long ID, 
-                          const unsigned char *in, unsigned long inlen,
-                          unsigned char *out, unsigned long *outlen,
-                          prng_state *prng, int wprng, int hash);
-
-extern int kr_decrypt_key(pk_key *pk, const unsigned char *in,
-                          unsigned char *out, unsigned long *outlen);
-
-extern int kr_sign_hash(pk_key *pk, unsigned long ID, 
-                        const unsigned char *in, unsigned long inlen,
-                        unsigned char *out, unsigned long *outlen,
-                        prng_state *prng, int wprng);
-
-extern int kr_verify_hash(pk_key *pk, const unsigned char *in, 
-                          const unsigned char *hash, unsigned long hashlen,
-                          int *stat);
-
-extern int kr_fingerprint(pk_key *pk, unsigned long ID, int hash,
-                          unsigned char *out, unsigned long *outlen);
-
-#endif
-
diff --git a/mycrypt_misc.h b/mycrypt_misc.h
deleted file mode 100644
index 7524c9d..0000000
--- a/mycrypt_misc.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ---- BASE64 Routines ---- */
-#ifdef BASE64
-extern int base64_encode(const unsigned char *in,  unsigned long len, 
-                               unsigned char *out, unsigned long *outlen);
-
-extern int base64_decode(const unsigned char *in,  unsigned long len, 
-                               unsigned char *out, unsigned long *outlen);
-#endif
-
-/* ---- MEM routines ---- */
-extern void zeromem(void *dst, size_t len);
-extern void burn_stack(unsigned long len);
-
-extern const char *error_to_string(int err);
-extern int mpi_to_ltc_error(int err);
-
-#if 0
-/* Takes up space we don\'t need for Dropbear */
-extern const char *crypt_build_settings;
-#endif
diff --git a/mycrypt_pk.h b/mycrypt_pk.h
deleted file mode 100644
index 9b7e5ec..0000000
--- a/mycrypt_pk.h
+++ /dev/null
@@ -1,253 +0,0 @@
-/* ---- NUMBER THEORY ---- */
-#ifdef MPI
-
-#include "ltc_tommath.h"
-
-/* in/out macros */
-#define OUTPUT_BIGNUM(num, out, y, z)                                                             \
-{                                                                                                 \
-      if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; }                                    \
-      z = (unsigned long)mp_unsigned_bin_size(num);                                               \
-      STORE32L(z, out+y);                                                                         \
-      y += 4;                                                                                     \
-      if ((y + z) > *outlen) { return CRYPT_BUFFER_OVERFLOW; }                                    \
-      if ((err = mp_to_unsigned_bin(num, out+y)) != MP_OKAY) { return mpi_to_ltc_error(err); }    \
-      y += z;                                                                                     \
-}
-
-
-#define INPUT_BIGNUM(num, in, x, y, inlen)                       \
-{                                                                \
-     /* load value */                                            \
-     if ((y + 4) > inlen) {                                      \
-        err = CRYPT_INVALID_PACKET;                              \
-        goto error;                                              \
-     }                                                           \
-     LOAD32L(x, in+y);                                           \
-     y += 4;                                                     \
-                                                                 \
-     /* sanity check... */                                       \
-     if ((x+y) > inlen) {                                        \
-        err = CRYPT_INVALID_PACKET;                              \
-        goto error;                                              \
-     }                                                           \
-                                                                 \
-     /* load it */                                               \
-     if ((err = mp_read_unsigned_bin(num, (unsigned char *)in+y, (int)x)) != MP_OKAY) {\
-        err = mpi_to_ltc_error(err);                             \
-        goto error;                                              \
-     }                                                           \
-     y += x;                                                     \
-     if ((err = mp_shrink(num)) != MP_OKAY) {                    \
-        err = mpi_to_ltc_error(err);                             \
-        goto error;                                              \
-     }                                                           \
-}
-
-extern int is_prime(mp_int *, int *);
-extern int rand_prime(mp_int *N, long len, prng_state *prng, int wprng);
-
-#else
-   #ifdef MRSA
-      #error RSA requires the big int library 
-   #endif
-   #ifdef MECC
-      #error ECC requires the big int library 
-   #endif
-   #ifdef MDH
-      #error DH requires the big int library 
-   #endif
-   #ifdef MDSA
-      #error DSA requires the big int library 
-   #endif
-#endif /* MPI */
-
-
-/* ---- PUBLIC KEY CRYPTO ---- */
-
-#define PK_PRIVATE            0        /* PK private keys */
-#define PK_PUBLIC             1        /* PK public keys */
-#define PK_PRIVATE_OPTIMIZED  2        /* PK private key [rsa optimized] */
-
-/* ---- PACKET ---- */
-#ifdef PACKET
-
-extern void packet_store_header(unsigned char *dst, int section, int subsection);
-extern int packet_valid_header(unsigned char *src, int section, int subsection);
-
-#endif
-
-
-/* ---- RSA ---- */
-#ifdef MRSA
-
-/* Min and Max RSA key sizes (in bits) */
-#define MIN_RSA_SIZE 1024
-#define MAX_RSA_SIZE 4096
-
-/* Stack required for temps (plus padding) */
-// #define RSA_STACK    (8 + (MAX_RSA_SIZE/8))
-
-typedef struct Rsa_key {
-    int type;
-    mp_int e, d, N, qP, pQ, dP, dQ, p, q;
-} rsa_key;
-
-extern int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
-
-extern int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
-                      unsigned char *out,  unsigned long *outlen, int which,
-                      prng_state    *prng, int           prng_idx,
-                      rsa_key *key);
-
-#ifdef RSA_TIMING
-
-extern int tim_exptmod(prng_state *prng, int prng_idx, 
-                       mp_int *c, mp_int *e, mp_int *d, mp_int *n, mp_int *m);
-
-#else
-
-#define tim_exptmod(prng, prng_idx, c, e, d, n, m) mpi_to_ltc_error(mp_exptmod(c, d, n, m))
-
-#endif
-
-extern void rsa_free(rsa_key *key);
-
-int rsa_encrypt_key(const unsigned char *inkey,  unsigned long inlen,
-                          unsigned char *outkey, unsigned long *outlen,
-                    const unsigned char *lparam, unsigned long lparamlen,
-                    prng_state *prng, int prng_idx, int hash_idx, rsa_key *key);
-                                        
-int rsa_decrypt_key(const unsigned char *in,     unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
-                    const unsigned char *lparam, unsigned long lparamlen,
-                          prng_state    *prng,   int           prng_idx,
-                          int            hash_idx, int *res,
-                          rsa_key       *key);
-
-int rsa_sign_hash(const unsigned char *msghash,  unsigned long  msghashlen, 
-                        unsigned char *sig,      unsigned long *siglen, 
-                        prng_state    *prng,     int            prng_idx,
-                        int            hash_idx, unsigned long  saltlen,
-                        rsa_key *key);
-
-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);
-
-int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
-int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
-                        
-#endif
-
-/* ---- DH Routines ---- */
-#ifdef MDH 
-
-typedef struct Dh_key {
-    int idx, type;
-    mp_int x, y;
-} dh_key;
-
-extern int dh_test(void);
-extern void dh_sizes(int *low, int *high);
-extern int dh_get_size(dh_key *key);
-
-extern int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key);
-extern void dh_free(dh_key *key);
-
-extern int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
-extern int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
-
-extern int dh_shared_secret(dh_key *private_key, dh_key *public_key,
-                            unsigned char *out, unsigned long *outlen);
-
-extern int dh_encrypt_key(const unsigned char *inkey, unsigned long keylen,
-                                unsigned char *out,  unsigned long *len, 
-                                prng_state *prng, int wprng, int hash, 
-                                dh_key *key);
-
-extern int dh_decrypt_key(const unsigned char *in,  unsigned long inlen, 
-                                unsigned char *outkey, unsigned long *keylen, 
-                                dh_key *key);
-
-extern int dh_sign_hash(const unsigned char *in,  unsigned long inlen,
-                              unsigned char *out, unsigned long *outlen,
-                              prng_state *prng, int wprng, dh_key *key);
-
-extern int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
-                          const unsigned char *hash, unsigned long hashlen, 
-                                int *stat, dh_key *key);
-
-
-#endif
-
-/* ---- ECC Routines ---- */
-#ifdef MECC
-typedef struct {
-    mp_int x, y;
-} ecc_point;
-
-typedef struct {
-    int type, idx;
-    ecc_point pubkey;
-    mp_int k;
-} ecc_key;
-
-extern int ecc_test(void);
-extern void ecc_sizes(int *low, int *high);
-extern int ecc_get_size(ecc_key *key);
-
-extern int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
-extern void ecc_free(ecc_key *key);
-
-extern int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key);
-extern int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
-
-extern int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key, 
-                             unsigned char *out, unsigned long *outlen);
-
-extern int ecc_encrypt_key(const unsigned char *inkey, unsigned long keylen,
-                                 unsigned char *out,  unsigned long *len, 
-                                 prng_state *prng, int wprng, int hash, 
-                                 ecc_key *key);
-
-extern int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
-                                 unsigned char *outkey, unsigned long *keylen, 
-                                 ecc_key *key);
-
-extern int ecc_sign_hash(const unsigned char *in,  unsigned long inlen,
-                               unsigned char *out, unsigned long *outlen,
-                               prng_state *prng, int wprng, ecc_key *key);
-
-extern int ecc_verify_hash(const unsigned char *sig,  unsigned long siglen,
-                           const unsigned char *hash, unsigned long hashlen, 
-                                 int *stat, ecc_key *key);
-#endif
-
-#ifdef MDSA
-
-typedef struct {
-   int type, qord;
-   mp_int g, q, p, x, y;
-} dsa_key;
-
-extern int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
-extern void dsa_free(dsa_key *key);
-
-extern int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
-                        unsigned char *out, unsigned long *outlen,
-                        prng_state *prng, int wprng, dsa_key *key);
-
-extern int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
-                           const unsigned char *hash, unsigned long inlen, 
-                           int *stat, dsa_key *key);
-
-extern int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
-
-extern int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
-
-extern int dsa_verify_key(dsa_key *key, int *stat);
-
-#endif
diff --git a/mycrypt_prng.h b/mycrypt_prng.h
deleted file mode 100644
index b96fa43..0000000
--- a/mycrypt_prng.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* ---- PRNG Stuff ---- */
-struct yarrow_prng {
-    int                   cipher, hash;
-    unsigned char         pool[MAXBLOCKSIZE];
-    symmetric_CTR         ctr;
-};
-
-struct rc4_prng {
-    int x, y;
-    unsigned char buf[256];
-};
-
-typedef union Prng_state {
-    struct yarrow_prng    yarrow;
-    struct rc4_prng       rc4;
-} prng_state;
-
-extern struct _prng_descriptor {
-    char *name;
-    int (*start)(prng_state *);
-    int (*add_entropy)(const unsigned char *, unsigned long, prng_state *);
-    int (*ready)(prng_state *);
-    unsigned long (*read)(unsigned char *, unsigned long len, prng_state *);
-} prng_descriptor[];
-
-#ifdef YARROW
-extern int yarrow_start(prng_state *prng);
-extern int yarrow_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
-extern int yarrow_ready(prng_state *prng);
-extern unsigned long yarrow_read(unsigned char *buf, unsigned long len, prng_state *prng);
-extern const struct _prng_descriptor yarrow_desc;
-#endif
-
-#ifdef RC4
-extern int rc4_start(prng_state *prng);
-extern int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
-extern int rc4_ready(prng_state *prng);
-extern unsigned long rc4_read(unsigned char *buf, unsigned long len, prng_state *prng);
-extern const struct _prng_descriptor rc4_desc;
-#endif
-
-#ifdef SPRNG
-extern int sprng_start(prng_state *prng);
-extern int sprng_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
-extern int sprng_ready(prng_state *prng);
-extern unsigned long sprng_read(unsigned char *buf, unsigned long len, prng_state *prng);
-extern const struct _prng_descriptor sprng_desc;
-#endif
-
-extern int find_prng(const char *name);
-extern int register_prng(const struct _prng_descriptor *prng);
-extern int unregister_prng(const struct _prng_descriptor *prng);
-extern int prng_is_valid(int idx);
-
-
-/* Slow RNG you **might** be able to use to seed a PRNG with.  Be careful as this
- * might not work on all platforms as planned
- */
-/* ch2-02-1 */ 
-extern unsigned long rng_get_bytes(unsigned char *buf, 
-                                   unsigned long len, 
-                                   void (*callback)(void));
-/* ch2-02-1 */
-
-extern int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
-
diff --git a/notes/ccm_tv.txt b/notes/ccm_tv.txt
new file mode 100644
index 0000000..3ff4b77
--- /dev/null
+++ b/notes/ccm_tv.txt
@@ -0,0 +1,214 @@
+CCM Test Vectors.  Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key.  The outputs
+are of the form ciphertext,tag for a given NN.  The key for step N>1 is the tag of the previous
+step repeated sufficiently.  The nonce is fixed throughout at 13 bytes 000102...
+
+CCM-aes (16 byte key)
+  0: , 54C92FE45510D6B3B0D46EAC2FEE8E63
+  1: DA, 7A8984228DCF944903936CA9D7709ACF
+  2: B95E, 1056DE0CBBEEA760ED2053FFEB554EA6
+  3: 58FF3B, A42DE1A812D29BBC6C1C5AC808565437
+  4: 9D6E6FB6, 5E8E0422792999381ED669CE17601D34
+  5: 40D49E851D, B076B4ED79BF0155B39A743550593944
+  6: 015356B9A6E1, 8D62CEFC451CAE4A21C1C579C6CAA128
+  7: A2CF0A77AE0DE2, 97B9D201740FA59E863513EDACC59FFB
+  8: A44C68E52F95B48B, A461B79D4D9B8ADF6C6618E6ECDC059A
+  9: F56B8AD68AA31F22B9, C5C7D2E6FE34D94CE72B86DA55679080
+ 10: 5C17EEBF4E348CBE3278, 29FAE7B470CB652C501343FE23B25894
+ 11: 1EE960BFAE360302D834E3, 8F8F475EB9BAB29CE14A9CF42C30B148
+ 12: EFF6BA1F2B1389237C6C045E, C895302DD8E75096951EF5CA63BFDD67
+ 13: 5A1179A4047334CCD9162F36EB, 110987D37F45422625DEA402BD7580EB
+ 14: F26E2C27E7D287B182FA42879978, 530FDE90C13A01EBCA86449073A3B035
+ 15: 77BFE79B4BC87116EC5232606E890F, 280994EB0E16C7CF10F31BB60DBF52C8
+ 16: 9926A4CE1AD70B89CC0050A58B958742, A635B4272EBFA1F83DAE270452D877E7
+ 17: BAAF99CAE4753E3304D6F8F9C0CD366C68, A6F606AACD0B87923B43C3EB61AC3965
+ 18: F72453C6765352A31494FA02B388E407B1FB, 0A446D28B7C5845C3621B4D3A0FA98DB
+ 19: A7372589A86B2E137F124A96618095EB5E1435, 3C59A6A858947FEBFD32441E37309F1A
+ 20: 5683E13A4E82A1AB8B3DC2051B6DBF2E1F2BB417, 459D1B0D2CF2C30B5ED5C237D07DFC19
+ 21: 33594C4B84536C23DA5AB2117E9267258CCE5DEC3B, 6E4BB70A72343E142AC4E31CE0FE6A77
+ 22: 332EDC9A3BDB90DBCCF317AC55BE5855CA9BCA2A73C4, 9FB310E5FFF5C754EE1E5FFF865F1656
+ 23: 734618677055469335FFD574B008F2C68B78633F79010E, FAD31386E42BB4EA76A643A9004A8CB4
+ 24: BA6F6ABA2AF35895F7F966D71F4E91A0BDD1DD551826F861, 25A3EC1C91C26283BAA5975390285AB2
+ 25: FF519213E858E36AC8D92450F81CA46C8CA8AB129A997EBB36, 0D4AB2B7A5EB02242C01A81CEBF5D84E
+ 26: B1F80058C3B4316EA86E9A898CD0B9C0366DFCB2AEC0799312D5, 0F4FF2759EDDF6349F4E23F284FAAD2E
+ 27: 00BDC15012F8183112D5C3A135DC60DC9C764A04BD39A8E041F1D9, 0C68BC9E6A6BF1B01743F3183C9B7C80
+ 28: 3022FD12969D925365C553D98D59E5D1EC494540909D1FA794F41E18, 05E61844943E78DB9BD417DDDE9C98B2
+ 29: 4F4A4554BFED6BAA09E3D8843C4EA3807B8762799C1D21289A46575389, 3A59A6DC9230020FE061466A92BBCAFD
+ 30: 6AE735EB15D9B39C8AD0E54F45307AAD97DB9F8A2A66BDC9BABCCFBD54A3, 0BDB365E493A9E160EEFD7DE24101870
+ 31: 4AF19F00EAE55FED2304B94FBCA29383042F2BE711041323C1D9F14BA63383, 94561581E496553D068052BA698683D2
+ 32: C2438BC46A92A465E0DB41E638CC6C8E0029C4DA842CA4140D73F90985EABA9C, 0F5A69F52AA8D8508D09E642511E54E5
+
+CCM-rc6 (16 byte key)
+  0: , D01FACF2BB577BFA6194800E53FB4A00
+  1: 65, 92E48F7300FA2697E9E0FF80DD187237
+  2: AF5C, 332863BC515649D5BCAB6A2FE5F5250D
+  3: E7C89D, 49A641F027C65A15100009D99E79CF3F
+  4: ACB36D46, 53DE328A8B4B14CAD363BED53DACE8A1
+  5: C3ADAE6CCF, F713F5079BD77046F95D8685CDF522DC
+  6: 5A8CABC912DA, FB97B059D2BE1273497FA8D2739A1505
+  7: 27F101DD6D0894, 266ACEF34476A0E64410D209219335D0
+  8: 66164DA09BE2F46D, EFC64C01890A5B562AF39ADFC48E1CA9
+  9: 1B0018895394753995, FA894E1C882D96E35A4C238708931F3D
+ 10: D346062826187BAEFC3B, A036AE1D3C02E2AD23541DE095AC7B84
+ 11: EFB375BA1138339FA1B504, CDD4232FF4664D59D5AC6BE32CBE1B35
+ 12: AFCF494078D7D7E6D9803FD5, 07E06ED923F76150BE82C1DDCB62C4DD
+ 13: 75DF2EC91379408DA426A444E4, 440ACDF2A6567FA3A5009DDFE502A1A1
+ 14: 3B36B62B01E324E702694305DD29, 4093598607DCD9993845D1837D211FE2
+ 15: 7DF6595C9711B164C99CB246B4D57E, F364993B2C187058F466B62D11E0F94D
+ 16: D317EE9EE1746D1B89A4CC52D88F0819, 41856B0B229D38344FA718E04CA57A8B
+ 17: 85252277A97CA7553007995BD5A0DCD372, BDEEAB636BD1ACC8D5A23F658150FA30
+ 18: 36FF305AC6EF662C155A1C15A6C195D3EC88, 9AC48EF07A510E308E06E79C0C80C3A0
+ 19: 51645A614313E978F6DCE7BBDDEDC33E3284AB, E9F7723E763AD50161C0671C4034FD0A
+ 20: 3CB9E6D0730FE05F903D338708AD8E34BFBB3285, 8A12185DAD518049F0FAC945A8FB305A
+ 21: 276E37D246C40ABF32DC83007B95390EE801CDA6E3, 73FA1D310D031E0A0A3A1421661B4697
+ 22: 4444BB070EDFBD1AC59D0BF70D66F48F0830069F3562, 9DCB6A99CBCCE3C8AEF29F06AF5057FB
+ 23: D16BA084CF82EDD2E43349311140BF3A2E37DE40544BF3, CB93C5AD60C700D4EA653136101AACCC
+ 24: 3FBAEBB36E2B74014043BA7D72F899B0D8DED883F592D778, 54DEA31D7EEA863A06A16D6C9B25DC13
+ 25: 3614B5428B790793F31E23670A38A070B65DB8E51C61FEA9C9, A91B750FD7ABFF18376C982DFA0C8872
+ 26: AC15FD90A4C254BA1406BE7DBA5694BB2625F634C69F45CCCD04, E6F97BCC8526BE3C04BA139EB50E65DF
+ 27: B506E83557E48553BD8557411D2C17D64005E734BA5A5FF1CF98B1, 6FA001758A19F783A71C97AF1AA61F94
+ 28: F07721663400838947EA1B9404D9683556F2D911429A9F59E3F5AD31, 376A1165A30C919E96C3706A4AB5DB37
+ 29: 98B5EB8FE0005E515A585D8F44D838FA590054EA5201CD444366B6F71E, D8C58448F601F2C05F24ED2CC349C78B
+ 30: E36E2FC225767CC1E2C388BEBC2C81C340FEF5B504575D5FA49682E1C214, CFED56F38CA4F84E6E1E16CEF50A6154
+ 31: 7A9FDD8E481B822B3D282AAF726944101ED61DAE73782DE055D7D305E36B27, 328B10841E977041CBD13C39CD70F03F
+ 32: 48AE8B5FA027930A7BCEC27468D795D0D8E6099C5F0558361B3AD20C1ECFF89F, B180AA9353E9EB6A22710A4DE872FACB
+
+CCM-safer+ (16 byte key)
+  0: , E106F41D61402E532662213EBA471BFF
+  1: 05, 1749600C7045647DCB3293C0724E7A21
+  2: 2355, 80DD597665723F4AEFFF760C5C6C5EE2
+  3: 5F4CD8, 59AE54E63A8CF4DBAD050B42CE922013
+  4: 75F63A43, C31B6BD3125C036C99507DDEE0197201
+  5: 51D4D87B8D, 0F3872088CDEB0E958C35F343677AC24
+  6: 8CF6D81A274C, C8E688954E72A052B5F8D1CA46FB44B0
+  7: 5EB8283B299AB1, 5977CB96C8D439DE3A86AE0452A2EE34
+  8: 829B1A4EA8643EAA, 1E892D3DFB73A469035CA81DD7F937D1
+  9: 0FEEF9504CF0F4E282, EDCBED7C61E8E2D24392B4145218F0AB
+ 10: DEF7679D3073D461A94C, D7ABAE561901CBB30FD7D9467C088B3B
+ 11: 625FD679C7354A74D62893, 450E3954857640DDF4C7A95A6E202A1E
+ 12: 3C9E76E4E2D4D95FEABD5C90, CD4467F695B7ED8973AEED5A822B347A
+ 13: B1B6294ECEAE6AEE4853731CA9, 6042302DAE598822BE8554BE038119CF
+ 14: 204BF480582D4BA408BAD23CEB52, 4D6B87334E1BFB9BA2D42B89B24165B2
+ 15: 277591770E3E2DB97A3011D9616991, 75D0A4B9937748EAE7794056F7A8A7FE
+ 16: 5669F75D0C908BFF7B82095231B86DAA, 3E816776A73FB89276534A3646C0F8FB
+ 17: 37E621EF5A043A83FC98A65329891BC031, 159A823EA61B3A47B42EFCF12F304725
+ 18: 18AC6ECF3F478A0797BF813C871235A9D309, 9B415B1B3A933B22C9027E2D72764956
+ 19: 671484C7587DAAB885C7F2FAF030081B452CC6, 574A63D113A5ECEC877D5A368A3160AA
+ 20: D7AB0F7D46B7ED976C8F6E7D0C6AABE3CAAA5A6E, 266C7A025C4EDF657DD42EB82BB6616A
+ 21: D60E4CFC6500E237276A69F35AE4BBAE17371392EF, 6ED2A1673F8B4DB795547D9D93D76D8B
+ 22: FAC6E21979D8D9896C790CB883C29F84D6820AE4FD4B, 1C7B6D73200E3C2DC5C701152F38EE8E
+ 23: 39240DC2B544CA8BEBBB4EA499FD48A5EE707198AE8AC8, E7FFD169552665ADE7B9C0DFFDD04EBD
+ 24: 6BE2C24172CAA192D55CC3E640E34675DD7F441CE5DB0FC0, 760CA976355281F76E49A2856A4EC7A0
+ 25: 0E20427218D6447D6E23FA4832CB8D2A172B23FDC542B41524, 27D0F37E109252FF5E6F6F703CA784F5
+ 26: 0AF75BD89028A5691B8B7993B9CE4FD24334A312DE28212C8B2C, AFE4C6B193B0F1796FC9E6C23292C060
+ 27: 6830D8E2E6DEC1476796DA44C982D36409E268F966283A66E801ED, 9E2C92D5B30EB0943E17869ED4C789EC
+ 28: 75ED280BEECD7768F7E032071F0E06D9D6BF1C9FF8E5DEB536DCD4BA, BF0DD11D633DBA5DCD25F4172765570B
+ 29: DF1FAECC1DB24718236B18B90B354F405FD5DE1257EC43F811F4A43DCD, 48D182E572E794350BBDA91FD76B86BC
+ 30: 176681E38ACACCD3C625F554C1F7A2D7C2C474C9444EAC8929B8C36EC05E, 080E109FFC5D247F1007217DD642BBA3
+ 31: 8A8172C21D88A1FDD43089C545C308507617F7BDB02C47CF2719F1484407E2, 1A0D10B0AF5BE21BF19D570D3FDA5BCE
+ 32: 0A93CAE2B95517773A4009FD3438231A207B9D46AABAE83FC4E1057EA4E2D6B4, 717AEF2F55DC8669F7E2D0298F8A7BE9
+
+CCM-twofish (16 byte key)
+  0: , 33B3DF1B59C84DD3C15E4FEB66173303
+  1: BF, 92DCEBF1C11DD0B028DEC944A555E4C6
+  2: 8A4F, A859C7F76291326D821BB3C7519657C0
+  3: BAE755, 14D7C2EFBCA1063460FEFCEBAE3AD79A
+  4: 25695BC6, 9358BC434B14B59ED17F9C0D3F51DCB1
+  5: 1D9FC70ECE, 2A86578FA3A8C702E2E6723DB9A9893F
+  6: AC39F1DF3661, 3F9C71EE0506FD2BAFFEE7200D22CD92
+  7: D330A915EED9D0, 22DC25EDF5ACDEF8358BE2A3082112BC
+  8: EF913ADAE6380507, E87D72BB6395EEEF2AD4F546B4033DE8
+  9: 5EC16994E762BCE467, D7700F7BF4FE026A2076F161C3383A0A
+ 10: 7EEB4910B7C2B540B490, 40C88A977E1DCDDABD749ABC9A0C60F8
+ 11: E5DD32FF54D39451CC2AF8, 541B1558B5AFF6E9EFBEE496D60AD65C
+ 12: 242C2900F859966B6627FF5C, 1CED148098350F3A5D1B5634180817A3
+ 13: EEF025B9E4EB867B127EBD19D4, AD0179A07AD1418C25F40E123C2BEF47
+ 14: C5E812B0AE37098686E2C4452C12, 02FC88AAA62E34742BB8577A651E922B
+ 15: 7BCAB32D1A871A62F9C781AFCAC60C, 2CD1C11EE197D9E130359F76E7F49251
+ 16: 1E82D8B8EED9A730D1670F0DCFF17B60, B7730261560EA6CF715FF7006D5FEFE2
+ 17: 0E1966992E360DC81312B28ECA6865B811, 10C40ACD169CB0F2A6FFC99F9A5516EA
+ 18: 5F5418C1322BF7EB828CF27C1F72086515BE, 90F8ED0447171A10476DED39F7518075
+ 19: 6C552506FA167FB8AA12E9F416930031487D4E, C992009F83F31A7BF922BFAE68C4134B
+ 20: 38429D966676406B17638DB7F9F7205250408BB2, 3385A50E9789D2C63835A80EFE9CFAE4
+ 21: 56EF426315EF96BE4C60B49F41C9BDDE2E0CDB3C22, 2D51D5B4F5B04BEF3BC1A7CF1AEA70E9
+ 22: 314B075C097EE531ECCE6AD7CEF22A72AAFCEFB02029, FB7A7D84D23FF524D060871D90FAC106
+ 23: 61CCCF7E2A9B3E46CD0A94D7F4A7617BB0DBA2D989907A, B3F4D46094732F3EDD81E0755F0C52EB
+ 24: 7A812A3BCED4E0A72FB81218BD5A4E33D69CA18834FFAE61, 487F80588B41F4E1198124708987667D
+ 25: DBFAB77EF07AA4C9ED2B05500BDFA00FE3F19F15F97A74880A, 84504D9EECBC6CE11B18BD105DE55E2C
+ 26: E676D4739B01B5101E36BF8D9F4FAE8F767C028E83A6D5B39664, 3141A05669807BCA30F0934F599FD077
+ 27: D8FEBD069D87C1EE504CB8F72ADFF2166B14BA40B17B4DAA439668, 1D99A301943041C2F7A71432DA736FE0
+ 28: D98E2A1CFFAB28341F92C41971A21AD0FDDE733EA25F2607967CD0C3, 42E05A53BF4F1A6C5B7F84742ECE031B
+ 29: 13FA412B484945C1FE8291A7EB8F8FB78D2DC2C72C5132386EA82BF4A6, A1A8E8B026DD116B0F9C73EB14C1C7CD
+ 30: 10ABD2DC25C8BA594FBFA9312E69C1A2DBF326475AF2080E55E3611FBC0E, 49DF8A5171DAC3FB684BA2CF7FBB3D3B
+ 31: F401D2123619B81F54F307B783362CC40FB4FB2433CF51F5543A147BCD1FE5, ACBB670CB3722059B4B9FBEE67703E98
+ 32: 839A9BFA1D3CA37924BC6648DED2291FC61736A3638906D9C5DA28A66AA684AC, CD07B83C8E0C3E6FB4115A149BDF6FDA
+
+CCM-noekeon (16 byte key)
+  0: , FF73C6775C61DB36D9B5EEC812091FF7
+  1: 5F, 7D2AEA62A5202E3C4FBE05F33EBE4CC5
+  2: 0EA5, 312ED15FDDAB6EEEAC6AF9BE9CE698FA
+  3: 968F95, FA1AD58B85B93B5A4B5096C881F773C3
+  4: 9A8F4069, 8911063ADDF79E27D9DCEFF3F440E6D7
+  5: A5C0376E27, 9553F44B0BA8039527F8E05CD70AD8B0
+  6: 5B097736F3DA, 405B7EC685FC94903B36AC8E700558B8
+  7: 616810AE303B2C, 64C95A2DF5263F7BE6D1F9F3CF88EADE
+  8: C8D69A2E1170532C, 073A7E426266237FD73D8109F55AE5D3
+  9: 3E42CDB7DA4A72F2E0, 48675EA4302CA6BFE5992DE96CE43BB3
+ 10: 88532CC1F3E321F66D64, 528B3516C6D9A4B5390DD32C2A2E6C19
+ 11: 9216A8FC9A961E7F602F7D, B03047186B783844F5B6757057576B38
+ 12: 89B0858D4FDE6795EDE19CCC, F4530A2DCA823307AEDE5AF34E5C4191
+ 13: A676E20BB0A5E84FD0B9149BF7, 11B823B315DA93B0E15780851526D4BD
+ 14: 903AD5C108C43A80436FE2117EF0, EB1C79C7DF20CE2967A99783EA8D6EF8
+ 15: 81774C36F46F67159B7FFC24C080D7, 2E9E4812D9A92977EC34922782B6420D
+ 16: 63FD1C3F692D64B2DA3982FCD474A5D4, 04171AE84857713A9BABBD4564875D33
+ 17: B1BF6AD99F83C9173C6C021ACA74C5431C, 38D17D4F6AA3C24B8F3B465EAACE0A1E
+ 18: 0948D1ED59F07DE44A96A76E05B0B6F7C309, 1848D886FCFF35E85B0DC3CBE5BEE7FA
+ 19: 3458E5911222F9C555A1054C7D9748876DA39A, 584AFAE72FB6065A74BE016CF39D2E86
+ 20: 641F3867185D0605E9D666AB605187E75A1299EF, 6F9332E6FB5EA0CE811E3345593CD163
+ 21: 0676622D07733EF31A765AAB1E713FCE329277FB16, 88547474050FFC986930CC04BA8A03F0
+ 22: 79861EC2FD2BCC5C12B69F30A1575FC66AC1405281BB, FC68EEAC8F39ED69D312AEABF8000084
+ 23: CB2731835A576F7F8F2C2786D786FB6186E2F85D89DA3B, 3ED9E95BC51CF6368E6EF63667B35BD8
+ 24: 3CB1C02FADB6DD5483BC5D3C03D944102CFCEDF82B913402, 1C3F60C989A6FBF41A7AF4F29115C334
+ 25: E69FAEA5E3D0B76EF9E70F99C5918D934D0E9836F248DB9EEE, 7F1916B2CF7C9A5E3F5581D365ADBD31
+ 26: 36779AD755A9DF2DC3C5824DC2F7DD4FFE038628A4E1A1C33AE7, 2BDED3703468D267F8AB7EC0AF8F1E65
+ 27: E9D325646A41EE5AA7DABCDE98DE83440A7DC02714BA0AEE017E22, 972F4D7832F3371C60DCD04A6DEDEA15
+ 28: 0FAAE3F6028A28A80BBFE71FA7AA9042E538B41A0D514D6EB4EE6029, F7B3925495E260249ACC6E1CBE956BC5
+ 29: A9CC39EFFEE354C0E0579256AA85CBAA7B10E670DD3828A7A05DA0F49D, 28D9D20187AFE70AD9DD16759F0EFEB5
+ 30: 032F4BBB4EBF2E65758C541FDAFF2107DDBED399739849F8EBB41AF9711F, A3436981ED637CE5EEE01B380C46ACAD
+ 31: 7B321ED831CE96A603668E3E74BBC7453749A03D04A1B38E95966E6CC488F0, 88D1DADF2C1EE0BA579D0A8A90C1E62A
+ 32: D862B0BD0E2178AE05AEFB14F34C791547C5956F1F3B5BD525926578DE383A94, BF32CFE059F27222DC55D3E7CE7C5F10
+
+CCM-anubis (16 byte key)
+  0: , C85F41475E06F25682F855C3D45A6523
+  1: 25, 437BD73ECB8CFFAD9B2876F08D4BDA36
+  2: 5ADC, 5C762058A5EF71278B69F567F18CBE51
+  3: 95E541, DF099E8218AEDE8087791B38298334E9
+  4: 2DAA84E4, 7437094198E4AD2647C2618248769A26
+  5: B9641C5855, 91B02EC44D22460BFF22BB40C799E20C
+  6: 102012BCEFA5, E60488DA65D683182F0EFDF9DA52A78C
+  7: 8F14972CA4F8EA, C26B51F20ACDEC7DCA911500CF1241ED
+  8: ED2714B652972256, 8BA29459D5D370FC608EE362B55B7633
+  9: BF58A269A4F59CE0A4, D69080820F836E5B5CA8F393E61ED009
+ 10: 44AF1F715ADAF26C6EF0, FEFBC7DB75ECDDBA4A13CBF9A57873D8
+ 11: 77CDE1B951F0803893642D, FBF8B80B061703504D8D3A7718366B6E
+ 12: DE599BAAC9D3EFD9FCD47E44, F636EC35D172D661F01746FF86688B95
+ 13: A792B8359050C4866572977415, AE67D4EED92E63A14003FBC936EEF43E
+ 14: 62D5A7A4DFB78A175831627987CB, 25F7B440DBE9902C28B28E50BF02C516
+ 15: B6F289459F924C76586F4EEA0C1CAA, 54266B4424C3AF6E81F6CC4F2437F54E
+ 16: 884B7DF3395F063DCA26BDF9F2FEF4EA, E3C2BFA1964EFDF78FDB9559C8031C50
+ 17: 774962377B8731F2F301B930487518801F, F35B54264711D843D23636BA6CFA3E4C
+ 18: E9C8D1164F2B196C7305406179B232E45F1F, 2A13E034A136EBC0ED3361737EAD214C
+ 19: D3DCD242C952C5589E00B65CD826CA87691B8F, 9D624D482042798DB896B55D801EAD98
+ 20: 57065B2655D4799C0478FE7E8463A2215E758875, C8FB052F14F9DF6731A9C8B566E71D53
+ 21: FF736FDBD23593D9BC9A0D8CA7D819F550EF969322, 5CC3023029790BFD43204B27D52D7D7E
+ 22: C562B7387B8F1D3DBA22DD1636C9C4AB443F2FF15F70, 195C928EAF88BB4ACBA8A01B4EBAEE6E
+ 23: D0AC6EA8A804DC261304D4821E6AD7FCC2F0DC1A299B9A, 34FE2034CCF09A98DD50581DA8BCBE39
+ 24: B65933A7D7C8EF19C1BDEAABE2B4CE5E821459D953565EF8, 42B20EF142EB228803D6AF47C6482BEB
+ 25: F1F4FCE842EFEF563F6F047956E6706DC9B178D00D82776D74, 3ECE3050D8C80319821D5F57A7CA7066
+ 26: 4A3F10F4E34210A5CA1B81AD4269CBC3FD68AC662BF0E9DC9935, 0BC0724AA9A194D8C75EE6FC8E7F28F1
+ 27: 077F3C055303FD669BC1A370B18AA7F31D3C8CBFF5A69381404FBB, 872C7946401BE70E677B79EA13FB0F58
+ 28: FD39D32B27FE5BB8E6512C642D490E0AD0866E386580AE115C85ED2B, EE81712EA57DD54DDEE98EAB3285E6EE
+ 29: B45ED179290A6064188AFF6B722B37F8C3E984EC37AB5F47B353229B12, 186B3AD0C9F60D57E84992CBB2B0F71B
+ 30: 83FF1FD179D518A414148C15BE566BE4CC3DBE9FF5319A651E862811F152, 4B2942C66565EB9139A83C2EFD549D55
+ 31: B8176469E6A0D5797ED6421A871FEECDE48ACF011E394981C43AC917E8FFD5, E9B01383DB1A32E6126BD802A6C6F47E
+ 32: AB6A0AA29B687D05735167D78DB697BA2478BD14ECD059AE9D1239E7F2AB48FD, A560A30FD87CF28BA66F5B2638567E4B
+
diff --git a/notes/cipher_tv.txt b/notes/cipher_tv.txt
index f144fae..c649d26 100644
--- a/notes/cipher_tv.txt
+++ b/notes/cipher_tv.txt
@@ -1005,6 +1005,222 @@
 49: F8B974A4BC134F39BE9B27BD8B2F1129
 
 
+Cipher: safer-k64
+Key Size: 8 bytes
+ 0: 533F0CD7CCC6DDF6
+ 1: C3CD66BB1E5E5C17
+ 2: 079DFD68F6AF9A79
+ 3: 84EB4922264A1204
+ 4: 31F3A7D739C7E42C
+ 5: 381F88FB46E1DCA2
+ 6: CAF4AC443E50EF47
+ 7: 2914E255DA9BDDBB
+ 8: A160A24120E4FECC
+ 9: F748C6009FFBC465
+10: 8B3CB5784846D2B0
+11: 4F98C1621473399B
+12: B486B0BC365ABEE9
+13: 314EAB2B4E9F7840
+14: 613FE3637968A8FE
+15: 28935352361E1239
+16: 0DCB090233B8EB3C
+17: CF0BC7F307586C8B
+18: 64DF354F96CB0781
+19: D2B73C6BAACA7FB1
+20: 638FCEEF49A29743
+21: 204C4E0E0C0A8B63
+22: F041EF6BE046D8AA
+23: 76954D822F5E2C32
+24: 6700C60971A73C9E
+25: 80019293AA929DF2
+26: 8EF4DE13F054ED98
+27: 41DDF9845ABA2B7A
+28: B91834079643850C
+29: 8F44EC823D5D70DC
+30: EC2FF8DE726C84CE
+31: 25DF59DC2EA22CB5
+32: FC1130B511794ABB
+33: ED3259359D2E68D4
+34: D7773C04804033F6
+35: C1A32C114589251C
+36: 51647E61EE32542E
+37: B95A8037457C8425
+38: 4F84B3D483F239EE
+39: 458401C3787BCA5E
+40: F59B5A93FD066F8A
+41: 1450E10189CC4000
+42: 0F758B71804B3AB3
+43: 51B744B271554626
+44: B55ADA1ED1B29F0D
+45: 585DF794461FEBDA
+46: 3790CC4DCA437505
+47: 7F7D46616FF05DFA
+48: 6AE981921DFCFB13
+49: FE89299D55465BC6
+
+
+Cipher: safer-sk64
+Key Size: 8 bytes
+ 0: 14A391FCE1DECD95
+ 1: 16A5418C990D77F4
+ 2: EE33161465F7E2DD
+ 3: AB85A34464D58EC4
+ 4: 3D247C84C1B98737
+ 5: D88D275545132F17
+ 6: 00B45A81780E3441
+ 7: 6830FAE6C4A6D0D3
+ 8: 93DF6918E1975723
+ 9: 15AB9036D02AA290
+10: 0933666F0BA4486E
+11: 93F42DEE726D949C
+12: 756E7BA3A6D4DE2E
+13: 4922DCE8EED38CFD
+14: 8EC07AFBD42DF21C
+15: E82BEBCFB1D7C6B4
+16: B3EDB4CB62B8A9BA
+17: 5521307CA52DD2F3
+18: 54B5D75512E1F8F3
+19: 1A736293F2D460A8
+20: 778C71384545F710
+21: CBC041D3BF742253
+22: 9C47FC0FDA1FE8D9
+23: B84E290D4BF6EE66
+24: FC3E514CE66BB9E3
+25: E8742C92E3640AA8
+26: 4DA275A571BDE1F0
+27: C5698E3F6AC5ED9D
+28: AC3E758DBC7425EA
+29: B1D316FC0C5A59FD
+30: 2861C78CA59069B9
+31: E742B9B6525201CF
+32: 2072746EDF9B32A6
+33: 41EF55A26D66FEBC
+34: EC57905E4EED5AC9
+35: 5854E6D1C2FB2B88
+36: 492D7E4A699EA6D6
+37: D3E6B9298813982C
+38: 65071A860261288B
+39: 401EEF4839AC3C2E
+40: 1025CA9BD9109F1D
+41: 0C28B570A1AE84EA
+42: BFBE239720E4B3C5
+43: 09FB0339ACCEC228
+44: DFF2E0E2631B556D
+45: ECE375020575B084
+46: 1C4C14890D44EB42
+47: EA9062A14D4E1F7F
+48: 82773D9EEFCAB1AB
+49: 516C78FF770B6A2F
+
+
+Cipher: safer-k128
+Key Size: 16 bytes
+ 0: 4D791DB28D724E55
+ 1: 53788205114E1200
+ 2: 4472BCCAF3DDEF59
+ 3: FE9B3640ED11589C
+ 4: 4DDD7859819857D7
+ 5: 6BF901C4B46CC9DB
+ 6: 930DBFC0DE0F5007
+ 7: E89F702158A00D82
+ 8: BEB661953BF46D50
+ 9: 6F0DA64C0FD101F9
+10: 4EBBCE4E5A37BED8
+11: 996EAA0AF92A09AC
+12: AED6BB9522E0B00F
+13: DF9C643624A271B4
+14: 2E5C789DD44EF0CF
+15: 86A5BA1060177330
+16: 2385DBA4DEBEB4A3
+17: 82E2FC765722094D
+18: B3CA2161757695EF
+19: F8A4C6081F3ABC06
+20: 6422316E1BEFFAC8
+21: C178511BFBFF380E
+22: 049B8CBEDE5942A9
+23: 0E181292C1B1DEFC
+24: C347BA0632A49E55
+25: 32FDA46669714F99
+26: 0523743E30C16788
+27: 782BE96A93769ED0
+28: 9F99C9E8BD4A69D8
+29: 104C094F120C926D
+30: 1F7EA3C4654D59E6
+31: 90C263629BC81D53
+32: 1803469BE59FED9E
+33: 1478C7C176B86336
+34: 362FE111601411FF
+35: 6428417432ECC3C8
+36: D74C42FCC6946FC5
+37: 1A8F3A82C78C2BE6
+38: EE22C641DC096375
+39: 59D34A0187C5C021
+40: F68CC96F09686A30
+41: CF8C608BDCC4A7FC
+42: D2896AB16C284A85
+43: 8375C5B139D93189
+44: 0F0462F9D8EBAED0
+45: C3359B7CF78B3963
+46: E4F7233D6F05DCC9
+47: 8533D1062397119B
+48: 4B300915F320DFCE
+49: A050956A4F705DB9
+
+
+Cipher: safer-sk128
+Key Size: 16 bytes
+ 0: 511E4D5D8D70B37E
+ 1: 3C688F629490B796
+ 2: 41CB15571FE700C6
+ 3: F1CBFE79F0AD23C8
+ 4: 0A0DC4AA14C2E8AA
+ 5: 05740CF7CD1CA039
+ 6: 24E886AD6E0C0A67
+ 7: EEF14D7B967066BC
+ 8: 6ABDF6D8AF85EAA0
+ 9: 0EB947521357ED27
+10: BDD2C15957F9EC95
+11: 0989B87A74A2D454
+12: 04C793BA2FAB7462
+13: 3DAD2FACDDFA3C45
+14: D1194935CC4E1BD7
+15: BAC0A2C8248FF782
+16: 7DD5894A82298C64
+17: A59F552A4377C08B
+18: 8DDDE41AB4586151
+19: 7CC4261B38FFA833
+20: E99204D6584158EC
+21: AACC8ED0803CB5C4
+22: C105CA72A7688E79
+23: 3D662FDC35B88C09
+24: A4BCEDC0AE99E30E
+25: EAECF9B6024D353C
+26: 214651A3D34AFF40
+27: 807099325F9D73C2
+28: 45EC21AEB6B90A24
+29: DCED39526687F219
+30: 2CC248E301D3101D
+31: C7F37AB8570BA13C
+32: BB9B31A34A39641B
+33: 5314570844948CAC
+34: 4581F837C02CD4F4
+35: 4E036B1B62303BF3
+36: 7B3B88DE1F5492A4
+37: CEF2865C14875035
+38: 14DE8BEE09A155DE
+39: 3AA284C74867161B
+40: 3616B4607369D597
+41: 07512F57E75EDEF7
+42: 710D1641FCE64DC2
+43: DB2A089E87C867A2
+44: A192D7B392AA2E2F
+45: 8D797A62FBFE6C81
+46: E52CE898E19BF110
+47: 72695C25158CB870
+48: 29F945B733FB498F
+49: 27057037E976F3FB
+
+
 Cipher: rc2
 Key Size: 8 bytes
  0: 83B189DE87161805
@@ -1537,3 +1753,215 @@
 49: 0AAB29DF65861F4C
 
 
+Cipher: anubis
+Key Size: 16 bytes
+ 0: 30FF064629BF7EF5B010830BF3D4E1E9
+ 1: DD7A8E87CFD352AF9F63EA24ADA7E353
+ 2: 0D0BE8F05510EBD6A3EC842E5BD9FC2A
+ 3: 330F09581FDC897B3FE6EC1A5056A410
+ 4: 30349D965F43C295B9484C389C4D942C
+ 5: 9225343F0056BC355060C0282C638D02
+ 6: E3A85D41B5337533C4D87730948A9D4E
+ 7: 09DA0DDB65FF431081CAB08A28010B76
+ 8: 6C0D0BD6CEAFB9783B31023FD455DAC6
+ 9: FBE6F26B7CA322A45312856D586DE2EE
+10: 1F269EC072D0FBA72E87CA77F8B983FB
+11: CFFAE9ADE3006BD511ED172D42F16D05
+12: 73F0E9DE89F4C7541506F052D181BAC2
+13: FCFA3E2E89FF769834295C77431EF7CE
+14: 0452360383D56F827C81263F6B0855BC
+15: 40744E07299D6A2A210BE5598835221B
+16: 2F0FC61148C36F4C7B42DF274AD0DDE0
+17: 2EA0E9BE9E4E4DF85488FE6E7CFCD6E3
+18: 0AD1254FA64C3996BBD485D41A3687A0
+19: 5B55988652DF200348A114F802FD3C03
+20: C32906AF76934C1436CA60BAD58A0C66
+21: 59D87987DE9DD485C4537F3A95A164A0
+22: 0A706ADF488D84632C96F4BEC43D9FA8
+23: 0B74E0CDD14D984B37491E2D9FA63CAE
+24: 47CB1827D151A60473E67BD5D233102F
+25: F455B4B665D3D0AFB25FDE4A3312AFF6
+26: F9A0649421D45DF604206854F681DBDB
+27: 21477F5546339E4B6D8215368EE9F884
+28: 577640F23CA73345701B0906DFABA4B7
+29: 89F8D08A6E173759020DD7301E0FE361
+30: 44EF7AF7043FD4B8112345CEE42BC969
+31: D7CF0CE04A57253F4C63CABC4A5CB034
+32: AF73D3F4CED32593B315E27079131D22
+33: F6E603E3455359FE43A3B83AAF3AF0C5
+34: DCC3FB557F2C301B631DEF499097E4FD
+35: 8285A25CF6F7E701644708E12081C62C
+36: EC702DD0293F4C646B1C9C2606762816
+37: 289491E5A65DCA605B78E88DA8A9F8AB
+38: D82FBC14452BE34C5840DAD81FC2A65E
+39: B88A340EB1BF8D5ADE6A4E6C16104FC8
+40: C9FC3D70D2BA26C4059BD3D34134264C
+41: 18CE3D2920E3BDEFA91C369E9DE57BF4
+42: 50917AE58278E15A18A47B284D8027A3
+43: BDA6F9DE33704302CE056412143B4F82
+44: C287898C1451774675EB7A964C004E0D
+45: 3BDE73E0D357319AB06D3675F1D3E28D
+46: 30FF4326C89C0FFE4D31D2E92CC0BF9B
+47: F69816F304ED892232F220F290320A8D
+48: 1368153F1A54EFF8D61F93A2D6AF21E3
+49: 06DD274894B6EDF3159A1403F47F09C7
+
+Key Size: 28 bytes
+ 0: 7828B1997D3D050201DC6EE45C8521B5
+ 1: 0D77F896F9CEF16DAAFCF962C2257AAE
+ 2: 89C27B0623F5EECCA38BAE1AD86AE156
+ 3: 44EC09834052009CC3CD66E1BA11AF01
+ 4: F922BFDB03FB186A069C1E7B48222E3D
+ 5: 277F7971955D8984AAECF287C32B8211
+ 6: E77ED0144A3ED827B71453B91562FE25
+ 7: 1760EFD04477AE527BC37F72C8BBBCAE
+ 8: 26259425ACD58207AE328B3F1A217AC1
+ 9: 0876C4DC51D22657C4121E9067C2C3BA
+10: 0214981592C9CEDD4D654F84AF1793A5
+11: 3E11FA027BC4F15048D27B187062259A
+12: 24E7D61BB21EA90B5282B43AAFB0DBDC
+13: 688F56ECB45B7C242000653460F04A23
+14: DFA587501A875ACDE8687A04AE404861
+15: 4C21CC3FBB768CC9AF2242FA206FE406
+16: 5CA0B03FA7751DEBBE70CB21AA61765A
+17: 4879B3AC26270C422645B9CA29CAD8BB
+18: 24F941E1B9AF84C18D03885EAACE16E3
+19: 05E163A0150123C2664131A81B20AFC1
+20: D606CAA85362E23598E5B8BD60C60506
+21: 33BD0AE751019BB751C151AE47BD5811
+22: 75DA523F5F793F90034144A3599DC5E6
+23: CD4709B56521EA306F5AD95CCA878183
+24: 6A4EC2EDDEBBBFEB62C1F13F7A59BF20
+25: 2A36272DC4EFDFC03F4DCF049ED2ADFF
+26: FD4F3904E8E37E7C31508E5829482965
+27: BA64BAE1C2ABB8599A31B245DBAD1153
+28: 757E0151783A50FC92AE55861DCD797D
+29: 5E63BDA3217ECB544972CA14A9074DA5
+30: E52F1195921767FA2410BA095EA5C328
+31: 6D7E42D67E329D669299B5A590017E8D
+32: 0516F6F7D99ADE5DC42E635BB5832E80
+33: 57FB4E6B82ED2A3091248DCEF9C27F14
+34: 25231D0E9B96534977D2F2AF93DD10AB
+35: 847C4C524A586568D19EFA3ECA343F1C
+36: 52448814064E0F33A4EA89368C2E1ACC
+37: 461275466FAA7BC16ABAD9EC459BD67A
+38: 16C8324A383A00DA06DBEC419B69C551
+39: 5F26F7CF715FF2649DCC3C71EB6B92DF
+40: 575363411FB07C067CD4357A1CD1D695
+41: AB70F08BAB51C5F57139A107EE858A12
+42: 887F62AE3D700EC5323EDA231C6B4C48
+43: 7B9851B01DC9083293F3B226690A54F4
+44: 36E03DF51C574E35EF2077DB7A49548E
+45: E238A564246B163F97EDD733A235EDEB
+46: 30679CE080915DC3BFA91D0DAFF5E82E
+47: 7C2E8145D803D4FE18EE32995AAC16B0
+48: 24D6F61ECC87206804885D33BFA7B2CA
+49: 1F4F81751CB3FAFDC9F9C27E639F370B
+
+Key Size: 40 bytes
+ 0: 31C3221C218E4CA1762B0DE77B964528
+ 1: 0B6E4BD937773597647FFE0A3859BB12
+ 2: 67A116E5F762619DE72F99AD1562A943
+ 3: B6A841663FB466ACAF89C8DA5BA080F0
+ 4: 0442708BF804642B9B1C69F5D905817E
+ 5: BC77391EAB530B96CA35319E510DB306
+ 6: AED37991A50AECB70C1B99137D5B38F2
+ 7: 8735F7AF0BF6C5C7E3C98021E83A31EE
+ 8: A614243B1B871D80BDCE4A23AD00F9FA
+ 9: 16AC67B139A92AD777871C990D3DA571
+10: B1774A2A12A8CAB25D28A575B67CEF5D
+11: 4C9B1A120BC6A33C62AF903FEEC3AF5F
+12: 7B128F00480E497C5754EE333457EE5E
+13: AB56D578229492B95ED309C0EC566658
+14: 42FAF577855FEDB3446D40B4B6677445
+15: 84E0C19B4A4512001F663E22D3184F0A
+16: 8B01680D049F5A9421BA9BED100CC272
+17: 2B1D70B92A5DF12CE0FA6A7AA43E4CEE
+18: C7F61340D1B2321A1884E54D74576657
+19: 153C07C56B32530866722C4DEAC86A50
+20: 2EACBEFC4A29D1250EEAFD12A1D4AE77
+21: FCCB40B0997E47512295066F1A0344DD
+22: C149A543345E2A1B8249F71CB9F903A4
+23: 3FD0688A8D0BE5F06F157C234C29BF9A
+24: 6A3F813F396D77C7F4641ECC3E0BF3AA
+25: E2888B9D2A6D819367F61C5792866A8F
+26: 1A8A000F91AF4E600DDD88E098BD938B
+27: 2283E758C04548EF8C37FA9F5700A7AD
+28: 4FD6D8E1678D2B85520B96C038C582BF
+29: D13C0B228F792EF88F09ED192C571029
+30: 1A2A06B1987BE0DADA4B558AE5E6A128
+31: 097B0460C47F1801986F5706A69EB01C
+32: DD17BAC0737515C6386ECA6A6D6C02B6
+33: 5989BD1D46FD6EC14D4C55D5D6D17F99
+34: 431002E0224BD34B0B93988356C19E7C
+35: 37DB7570296DCCE45ABDDE36EBE4731D
+36: 4731DE78EEBAA1D02568EEEA2E04A2F5
+37: 1F879753A7964AF44C84FD5765D8E080
+38: 54F120726F68EA4B0501365CD2A84759
+39: 366E43BB744C615999E896D01A0D1D0E
+40: 18747BD79F1D0529D09CAC70F4D08948
+41: 4F9854BAE0834A0C5FD12381225958F2
+42: 7C14ADF94A0B61828996D902E4CCFF3E
+43: 242F0E9CE96E4E208A9E0C5D76F8E698
+44: 27EE179E2A9301B521B2C94ED3D36A77
+45: 892C84A5E77E88A67F5F00F3597F4C04
+46: FC7880D7860E90DE17E935700FC8C030
+47: BC49373F775BF9CD6BDC22C87F71E192
+48: 365646D0DE092AF42EC8F12A19840342
+49: 62D0E9C210A20ECD2FF191AD3495DE6F
+
+
+Cipher: khazad
+Key Size: 16 bytes
+ 0: 9C4C292A989175FC
+ 1: F49E366AF89BD6B7
+ 2: 9E859C8F323666F9
+ 3: 349EC57A02451059
+ 4: 59E34CF03134A662
+ 5: 436C16BAB80E3E2D
+ 6: 81C35012B08A194C
+ 7: 056CCC9991C1F087
+ 8: 0A59F24C4715B303
+ 9: 3C2CFF98AE8500FD
+10: 9136C3FCC332D974
+11: FA3FA726E6BEBA65
+12: DD84E4F9F39FB7EE
+13: A3F397CC9FB771F5
+14: E2D6ECC1F40A51C7
+15: 6704A1A705163A02
+16: BD820F5AF7DEEB04
+17: E21E37CC122027FF
+18: E319085D8E2C1F4F
+19: 0DDFE55B199A49A9
+20: B70F39CCCB2BA9A6
+21: 3F2F25723AED2E29
+22: 751FACD5F517AB2F
+23: D32CE55FBF217CE9
+24: 91393018EA847012
+25: D50F1C54BABE7081
+26: C73350FBC5B3A82B
+27: E9A054F709FD5C57
+28: 94BD5121B25746D4
+29: EE19F88B28BEB4B7
+30: CE6845FD13A3B78A
+31: 566729D0183496BC
+32: DC0E1D38CB5E03A8
+33: 251AD2B2842C75E3
+34: D344AC41190F3594
+35: 579B956A36ADA3A8
+36: 5F83D3AFEE9A6F25
+37: 2D3FF8708A03C600
+38: 32A732C7BEEBB693
+39: F437276FAA05BB39
+40: 58DDD4CD0281C5FD
+41: ECC2C84BD8C0A4DC
+42: BAB24C2CEFE23531
+43: 5244BFA3E2821E7D
+44: A4B273E960946B2C
+45: 039376D02A8D6788
+46: D3EB7074E3B05206
+47: 89C18FFA26ED0836
+48: 1F05A2D2D78927D9
+49: 0133E1745856C44C
+
+
diff --git a/notes/eax_tv.txt b/notes/eax_tv.txt
index bf4a52a..95cd7c1 100644
--- a/notes/eax_tv.txt
+++ b/notes/eax_tv.txt
@@ -199,6 +199,82 @@
  31: 2DC26D449379997D110309B2A0DC2760FCE8CADB4B14ED580F86C70F69C9BA, EFCB60EB2B25737E256BC76700B198EF
  32: 2B1890EB9FC0B8293E45D42D2126F4072754AA54E220C853C5F20FBA86BE0795, 1A1B15BBC287372FB9AF035FB124B6A1
 
+EAX-safer-k64 (8 byte key)
+  0: , 9065118C8F6F7842
+  1: A1, 1926B3F5112C33BA
+  2: 2E9A, 5FA6078A0AA7B7C8
+  3: 56FCE2, 984E385F9441FEC8
+  4: C33ACE8A, 24AC1CBBCCD0D00A
+  5: 24307E196B, DD2D52EFCA571B68
+  6: 31471EAA5155, EB41C2B36FAAA774
+  7: 03D397F6CFFF62, 7DFBC8485C8B169B
+  8: 8FA39E282C21B5B2, 2C7EC769966B36D7
+  9: FEA5402D9A8BE34946, A058E165B5FFB556
+ 10: 6CDEF76554CA845193F0, FED516001FFE039A
+ 11: DC50D19E98463543D94820, 8F9CCF32394498A1
+ 12: 42D8DC34F1974FB4EB2535D7, 77F648526BCBB5AF
+ 13: B75F1299EF6211A6318F6A8EAA, C5086AEA1BE7640B
+ 14: 1E28D68373330829DD1FFC5D083E, 33EDA06A7B5929A2
+ 15: 85529CF87C4706751B0D47CC89CEA6, D031905D6141CBED
+ 16: FE5CB61BAF93B30ED3C296EE85F51864, CC484888F0ABD922
+
+EAX-safer-sk64 (8 byte key)
+  0: , 5254AB3079CDCB78
+  1: 75, 798DCF14FEF8F4D1
+  2: 0300, D5FCA75DAC97849C
+  3: 520F98, 10E357957CE20898
+  4: 80E2764D, 5C7F46656C6A46EA
+  5: C48960CDAA, 3CCF44BD41F01CA8
+  6: E0E60BD9AA2C, EBB493983FCEE79D
+  7: D13D8804906A1B, 6EDDCA919978F0B6
+  8: B7AE14C37A343BFB, 2369E38A9B686747
+  9: 5DE326BBCC7D0D35E9, 041E5EE8568E941C
+ 10: 13494F5B0635BA3D6E53, EAEEA8AFA55141DD
+ 11: A9BB35B14C831FDA0D83F7, 4002A696F1363987
+ 12: E242043A1C355409819FABFC, 63A085B8886C5FDC
+ 13: 204598B889272C6FE694BDBB4D, 194A1530138EFECE
+ 14: EE3F39E0823A82615679C664DEBF, 1EFF8134C8BEFB3A
+ 15: 8579D87FD3B5E2780BC229665F1D1B, A832CD3E1C1C2289
+ 16: 74D7290D72DA67C4A9EAD434AE3A0A85, 96BAA615A5253CB5
+
+EAX-safer-k128 (16 byte key)
+  0: , 7E32E3F943777EE7
+  1: D1, BA00336F561731A7
+  2: F6D7, 8E3862846CD1F482
+  3: 5323B5, BD1B8C27B061969B
+  4: A3EC3416, 170BBB9CE17D1D62
+  5: 0C74D66716, 7BD024B890C5CE01
+  6: 6158A630EB37, B5C5BD0652ACB712
+  7: 17F2D0E019947D, F9FF81E2638EC21C
+  8: 68E135CC154509C8, AA9EAEF8426886AA
+  9: EDB1ABE0B486749C21, 355C99E4651C0400
+ 10: DB0C30E9367A72E8F5B2, 631B5671B8A1DB9A
+ 11: D4E5453D9A4C9DB5170FCE, 75A2DF0042E14D82
+ 12: 3F429CC9A550CBDA44107AA7, 2C2977EA13FEBD45
+ 13: A7CA22A97C2361171B415E7083, BFE81185F31727A8
+ 14: 170F79D8B0E3F77299C44208C5B1, D5ED9F9459DF9C22
+ 15: 2E24312D2AE5D5F09D5410900A4BBA, 2FC865CA96EA5A7E
+ 16: 8F3C49A316BA27067FF2C6D99EC8C846, 9D840F40CDB62E4B
+
+EAX-safer-sk128 (16 byte key)
+  0: , 22D90A75BBA5F298
+  1: 3F, 98C31AB2DE61DE82
+  2: 584D, F4701D4A1A09928C
+  3: B9DEAD, 6E221A98505153DA
+  4: 06D4A6EB, 0E57C51B96BA13B6
+  5: 7B58B441CA, E28CCF271F5D0A29
+  6: 7950E0D1EC24, 2ACDDE6E38180C07
+  7: 65A4F4E098D7C6, 7DC1C9E9602BACF2
+  8: FEBE4E72BAA0848F, C4607EA3F138BAD9
+  9: 9B7BD6D6D655985AA3, 8B2C58A9530EA6AC
+ 10: 60C92F925D1478470203, 51E6F5F6DC996F84
+ 11: 7B40769370E651F64AA654, 74F1F8A8D3F4B9AF
+ 12: 7215832C2FB9C54DF7A9C686, 9BF9AEF14F9151D1
+ 13: AD0F9C79008572AB8AE2466EFF, F375D0583D921B69
+ 14: C05076E2C330A0D25D7CEC80597F, 843C12F84B00A8E0
+ 15: D18F0563AB0278140B0CD9A9B07B34, 262B1688E16A171E
+ 16: 650747091F5C532EE37D2D78EE1EC605, 1BAC36144F9A0E8D
+
 EAX-rc2 (8 byte key)
   0: , D6CC8632EEE0F46B
   1: 4C, EA19572CB8970CB4
@@ -329,3 +405,57 @@
  15: 07AF486D1C458AAB2DBF13C3243FAD, 87288E41A9E64089
  16: 84059283DF9A2A8563E7AF69235F26DF, 351652A0DBCE9D6E
 
+EAX-anubis (16 byte key)
+  0: , 8E20F19D9BA22ABA09FB86FDE6B9EF38
+  1: 3B, F4201E546A9160F989191942EC8FD1D3
+  2: 9F38, 4E3CEAE3E1CB954E021A10E814B71732
+  3: 4F4769, 3E8F35A6A5B11200E9F1AA38590066CD
+  4: AB41F5FC, EC4C97A8892AAF5433106D4AC8A49843
+  5: 414F95D61B, BF831E34D1E3FECB973A8C730ECA2E6D
+  6: 4798322F06D1, 005BBC30BFEDBE6463536C4F80D1A071
+  7: F256B6CD1BF4F5, 468A28F0661884B846B191B530C8D064
+  8: 90906F27A633ADDE, 6D9200A37A7F6A456CB103673184C2E5
+  9: 16CD3C17C9B4EAB135, 6D716E23D7B35109F55B036EDFA7742E
+ 10: 7AD1C22F1F06298DFB25, B076990F8193543C8F3185D3792BCE56
+ 11: 0476F2ABCD057FE6FEE39D, BB2876DB18C00038FADBBD9B264ACC3C
+ 12: B69EDE336407DBC2EE735857, AB63E5906116A8BE22C52B5DA31B1839
+ 13: C3864C1354065A56470669E602, C72BFD3A0BC73BFF051C9AB2F0DFED93
+ 14: 296D8F183A59020D33890420DD7B, C9D90B9EB42C32EDCF6223587D1598A6
+ 15: 256ED8E9D982616680559979BDF2E9, 179FE4E7BA7E966050D35900317E9916
+ 16: D4ED8F30FF9C0470D75B3B16750A3AE4, 5D50F05BB270A292DFF9F67A3BA84675
+ 17: 40CDEB6388274143CA3C4F6020BD9A4875, B27C7DFB1BFBB3FCCEE0171852C7924E
+ 18: 54EF262EC1801D505C7629D038654EBA0594, 9D2060FCD0A2C577511C7752ADE60BBE
+ 19: F39EE54A37F16DD38B624D7AB8F0D9CBD4B981, BC056C7D2C09D813703CDD63C1C69F44
+ 20: F4E7AD474FCA153ABD670E43081ED09EB2C4CC1A, F244BD4D630272F0D98FCA04226C04F1
+ 21: 039ECC36A0A16273E7246CA1FF19D213AC87B53F29, 3056DB6916C925DF220B6C9980EE141A
+ 22: 7DE1DCDEF01447CA2FE83375A48DD84E4A7CB7C01992, 79AFEA4816EAF8DAC8A5E93960F1594F
+ 23: A886C4B914BF0983003272F226F9B2197EF2DC05ACDDE0, B59D85A0FDA5FA4422F7203C055B97A9
+ 24: 00B3E1E91448E250AAFB695C0643A6577AB453EFECFABF53, 4A7EFF1CBC1AB535122A017203616D85
+ 25: 85E972E774D66D0531E40B8FE9E264A77B50FA883AB0943080, B18E164BF89B7E7AB0DC256DFEC7C72F
+ 26: 004849E39334969B392CB0CF3FDEFB3D792DCBBC15F8328C7EDC, 3C51295711F5F878DE8F0B2B5A26A227
+ 27: A0BAD6C2264AB1578993BA49E59D4598822FFED20A57D88F756FF1, 2EB9D525697A419A10DB2A84AEEA5FBC
+ 28: C34DD806EAB5AD823D78BCA78A7709A705FC94ECC521A367D76C9588, 3C57580C7903039D645C06DBAF07B477
+ 29: C447EC77512938CF7862388C32AF22ACE6B5E4CBAA998BE4F5CBC4D215, 43425D09B7ACFD90371C08953946A955
+ 30: 2C16993AAE624CBA4CDAF34FE3D368559E6BE548292B281439866375013B, 3B7360C3FA8FB1C15D19F567153CB46C
+ 31: 538E5DFAF14854A786851E4165F2E01CDDA963E318FCE4FB58E31A6B5CFC33, 2F8EA13B7A6873FE556CA535ABA0968B
+ 32: 5E29CDB7D9695A110043E9C260104BDF020A3A2A139D4112E918AB584BDD7EDA, 9133213AA7BCF062D2BD37F866683D3F
+
+EAX-khazad (16 byte key)
+  0: , 75968E54452F6781
+  1: 95, ADAF5949F09B5A22
+  2: 6B8F, A06B201947424A11
+  3: 5BE668, 3251416625DF347A
+  4: 5A92E82B, 33E25772427D9786
+  5: 62F9F2ABCC, DE714F5F5D17D6D0
+  6: 0E3CD825BD8D, A7991C8CB8975ED9
+  7: 4AD0D999503AAD, 53A827D7886F7227
+  8: BB08E6FAED1DAEE8, 91A118749B7AB9F3
+  9: 16E30CB12E20D18495, F8F8B8C1280158F9
+ 10: 616DBCC6346959D89E4A, 506BF35A70297D53
+ 11: F86B022D4B28FDB1F0B7D3, EA42220C805FD759
+ 12: 9B8A3D9CDBADD9BBCCCD2B28, BB478D3CE9A229C9
+ 13: CDC4AB4EF2D5B46E87827241F0, 658EDB9497A91823
+ 14: 1A113D96B21B4AEBDB13E34C381A, 63AD0C4084AC84B0
+ 15: 14DA751E5AF7E01F35B3CE74EE1ACF, 3C76AB64E1724DCE
+ 16: A13BBC7E408D2C550634CBC64690B8FE, 3D4BBC0C76536730
+
diff --git a/notes/etc/saferp_optimizer.c b/notes/etc/saferp_optimizer.c
new file mode 100644
index 0000000..32de878
--- /dev/null
+++ b/notes/etc/saferp_optimizer.c
@@ -0,0 +1,177 @@
+/* emits an optimized version of SAFER+ ... only does encrypt so far... */
+
+#include <stdio.h>
+#include <string.h>
+
+/* This is the "Armenian" Shuffle.  It takes the input from b and stores it in b2 */
+#define SHUF\
+    b2[0] = b[8]; b2[1] = b[11]; b2[2] = b[12]; b2[3] = b[15];   \
+    b2[4] = b[2]; b2[5] = b[1]; b2[6] = b[6]; b2[7] = b[5];      \
+    b2[8] = b[10]; b2[9] = b[9]; b2[10] = b[14]; b2[11] = b[13]; \
+    b2[12] = b[0]; b2[13] = b[7]; b2[14] = b[4]; b2[15] = b[3]; memcpy(b, b2, sizeof(b));
+
+/* This is the inverse shuffle.  It takes from b and gives to b2 */
+#define iSHUF(b, b2)                                               \
+    b2[0] = b[12]; b2[1] = b[5]; b2[2] = b[4]; b2[3] = b[15];      \
+    b2[4] = b[14]; b2[5] = b[7]; b2[6] = b[6]; b2[7] = b[13];      \
+    b2[8] = b[0]; b2[9] = b[9]; b2[10] = b[8]; b2[11] = b[1];      \
+    b2[12] = b[2]; b2[13] = b[11]; b2[14] = b[10]; b2[15] = b[3]; memcpy(b, b2, sizeof(b));
+    
+#define ROUND(b, i)                                                                        \
+    b[0]  = (safer_ebox[(b[0] ^ skey->saferp.K[i][0]) & 255] + skey->saferp.K[i+1][0]) & 255;    \
+    b[1]  = safer_lbox[(b[1] + skey->saferp.K[i][1]) & 255] ^ skey->saferp.K[i+1][1];            \
+    b[2]  = safer_lbox[(b[2] + skey->saferp.K[i][2]) & 255] ^ skey->saferp.K[i+1][2];            \
+    b[3]  = (safer_ebox[(b[3] ^ skey->saferp.K[i][3]) & 255] + skey->saferp.K[i+1][3]) & 255;    \
+    b[4]  = (safer_ebox[(b[4] ^ skey->saferp.K[i][4]) & 255] + skey->saferp.K[i+1][4]) & 255;    \
+    b[5]  = safer_lbox[(b[5] + skey->saferp.K[i][5]) & 255] ^ skey->saferp.K[i+1][5];            \
+    b[6]  = safer_lbox[(b[6] + skey->saferp.K[i][6]) & 255] ^ skey->saferp.K[i+1][6];            \
+    b[7]  = (safer_ebox[(b[7] ^ skey->saferp.K[i][7]) & 255] + skey->saferp.K[i+1][7]) & 255;    \
+    b[8]  = (safer_ebox[(b[8] ^ skey->saferp.K[i][8]) & 255] + skey->saferp.K[i+1][8]) & 255;    \
+    b[9]  = safer_lbox[(b[9] + skey->saferp.K[i][9]) & 255] ^ skey->saferp.K[i+1][9];            \
+    b[10] = safer_lbox[(b[10] + skey->saferp.K[i][10]) & 255] ^ skey->saferp.K[i+1][10];         \
+    b[11] = (safer_ebox[(b[11] ^ skey->saferp.K[i][11]) & 255] + skey->saferp.K[i+1][11]) & 255; \
+    b[12] = (safer_ebox[(b[12] ^ skey->saferp.K[i][12]) & 255] + skey->saferp.K[i+1][12]) & 255; \
+    b[13] = safer_lbox[(b[13] + skey->saferp.K[i][13]) & 255] ^ skey->saferp.K[i+1][13];         \
+    b[14] = safer_lbox[(b[14] + skey->saferp.K[i][14]) & 255] ^ skey->saferp.K[i+1][14];         \
+    b[15] = (safer_ebox[(b[15] ^ skey->saferp.K[i][15]) & 255] + skey->saferp.K[i+1][15]) & 255;        
+
+int main(void)
+{
+   int b[16], b2[16], x, y, z;
+   
+/* -- ENCRYPT ---  */
+   for (x = 0; x < 16; x++) b[x] = x;
+   /* emit encrypt preabmle  */
+printf(
+"void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)\n"
+"{\n"
+"   int x;\n"
+"   unsigned char b[16];\n"
+"\n"
+"   LTC_ARGCHK(pt   != NULL);\n"
+"   LTC_ARGCHK(ct   != NULL);\n"
+"   LTC_ARGCHK(skey != NULL);\n"
+"\n"
+"   /* do eight rounds */\n"
+"   for (x = 0; x < 16; x++) {\n"
+"       b[x] = pt[x];\n"
+"   }\n");   
+
+   /* do 8 rounds of ROUND; LT; */
+   for (x = 0; x < 8; x++) {
+       /* ROUND(..., x*2) */
+       for (y = 0; y < 16; y++) {
+printf("b[%d] = (safer_%cbox[(b[%d] %c skey->saferp.K[%d][%d]) & 255] %c skey->saferp.K[%d][%d]) & 255;\n",
+          b[y], "elle"[y&3], b[y], "^++^"[y&3],      x*2, y, "+^^+"[y&3], x*2+1, y);
+       }
+       
+       /* LT */
+       for (y = 0; y < 4; y++) {
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[0], b[0], b[1], b[0], b[1]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[2], b[2], b[3], b[3], b[2]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[4], b[4], b[5], b[5], b[4]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[6], b[6], b[7], b[7], b[6]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[8], b[8], b[9], b[9], b[8]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[10], b[10], b[11], b[11], b[10]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[12], b[12], b[13], b[13], b[12]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[14], b[14], b[15], b[15], b[14]);
+      if (y < 3) {
+         SHUF;
+      }         
+      }   
+  }
+  
+printf(
+"   if (skey->saferp.rounds <= 8) {\n");
+/* finish */
+   for (x = 0; x < 16; x++) {
+   printf(
+"      ct[%d] = (b[%d] %c skey->saferp.K[skey->saferp.rounds*2][%d]) & 255;\n",
+       x, b[x], "^++^"[x&3], x);
+   }   
+   printf("      return;\n   }\n");
+  
+  /* 192-bit keys */
+printf(  
+"   /* 192-bit key? */\n"
+"   if (skey->saferp.rounds > 8) {\n");
+  
+   /* do 4 rounds of ROUND; LT; */
+   for (x = 8; x < 12; x++) {
+       /* ROUND(..., x*2) */
+       for (y = 0; y < 16; y++) {
+printf("b[%d] = (safer_%cbox[(b[%d] %c skey->saferp.K[%d][%d]) & 255] %c skey->saferp.K[%d][%d]) & 255;\n",
+          b[y], "elle"[y&3], b[y], "^++^"[y&3],      x*2, y, "+^^+"[y&3], x*2+1, y);
+       }
+       
+       /* LT */
+       for (y = 0; y < 4; y++) {
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[0], b[0], b[1], b[0], b[1]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[2], b[2], b[3], b[3], b[2]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[4], b[4], b[5], b[5], b[4]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[6], b[6], b[7], b[7], b[6]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[8], b[8], b[9], b[9], b[8]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[10], b[10], b[11], b[11], b[10]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[12], b[12], b[13], b[13], b[12]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[14], b[14], b[15], b[15], b[14]);
+      if (y < 3) {
+         SHUF;
+      }         
+      }   
+  }
+printf("}\n");
+  
+printf(
+"   if (skey->saferp.rounds <= 12) {\n");
+/* finish */
+   for (x = 0; x < 16; x++) {
+   printf(
+"      ct[%d] = (b[%d] %c skey->saferp.K[skey->saferp.rounds*2][%d]) & 255;\n",
+       x, b[x], "^++^"[x&3], x);
+   }   
+   printf("      return;\n   }\n");
+
+  /* 256-bit keys */
+printf(  
+"   /* 256-bit key? */\n"
+"   if (skey->saferp.rounds > 12) {\n");
+  
+   /* do 4 rounds of ROUND; LT; */
+   for (x = 12; x < 16; x++) {
+       /* ROUND(..., x*2) */
+       for (y = 0; y < 16; y++) {
+printf("b[%d] = (safer_%cbox[(b[%d] %c skey->saferp.K[%d][%d]) & 255] %c skey->saferp.K[%d][%d]) & 255;\n",
+          b[y], "elle"[y&3], b[y], "^++^"[y&3],      x*2, y, "+^^+"[y&3], x*2+1, y);
+       }
+       
+       /* LT */
+       for (y = 0; y < 4; y++) {
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[0], b[0], b[1], b[0], b[1]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[2], b[2], b[3], b[3], b[2]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[4], b[4], b[5], b[5], b[4]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[6], b[6], b[7], b[7], b[6]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[8], b[8], b[9], b[9], b[8]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[10], b[10], b[11], b[11], b[10]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[12], b[12], b[13], b[13], b[12]);
+printf("   b[%d]  = (b[%d] + (b[%d] = (b[%d] + b[%d]) & 255)) & 255;\n", b[14], b[14], b[15], b[15], b[14]);
+      if (y < 3) {
+         SHUF;
+      }         
+      }   
+  }
+/* finish */
+   for (x = 0; x < 16; x++) {
+   printf(
+"      ct[%d] = (b[%d] %c skey->saferp.K[skey->saferp.rounds*2][%d]) & 255;\n",
+       x, b[x], "^++^"[x&3], x);
+   }   
+   printf("   return;\n");
+printf("   }\n}\n\n");
+
+   return 0;
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/notes/etc/saferp_optimizer.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/notes/etc/whirlgen.c b/notes/etc/whirlgen.c
index 2880d3f..c06687e 100644
--- a/notes/etc/whirlgen.c
+++ b/notes/etc/whirlgen.c
@@ -89,3 +89,7 @@
 }
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/notes/etc/whirlgen.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/notes/etc/whirltest.c b/notes/etc/whirltest.c
index 9184f77..226e012 100644
--- a/notes/etc/whirltest.c
+++ b/notes/etc/whirltest.c
@@ -13,3 +13,7 @@
    }
 }
 
+
+/* $Source: /cvs/libtom/libtomcrypt/notes/etc/whirltest.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/notes/gcm_tv.txt b/notes/gcm_tv.txt
new file mode 100644
index 0000000..79d3b8d
--- /dev/null
+++ b/notes/gcm_tv.txt
@@ -0,0 +1,214 @@
+GCM Test Vectors.  Uses the 00010203...NN-1 pattern for nonce/header/plaintext/key.  The outputs
+are of the form ciphertext,tag for a given NN.  The key for step N>1 is the tag of the previous
+step repeated sufficiently.  The nonce is fixed throughout at 13 bytes 000102...
+
+GCM-aes (16 byte key)
+  0: , C6A13B37878F5B826F4F8162A1C8D879
+  1: F1, 397F649A20F3F89A00F45BF230F26B61
+  2: D6B8, 1653F67C9C716D0FC59F3B14154DECBF
+  3: 673456, E82EFC79B30CA5235E2DC8BE4C14265D
+  4: 26DD7C26, B8D1F4DB845F7D7079DEB8920949C14D
+  5: DA62AD1487, 828A42329320764E5FB74D44A6108F4B
+  6: FB79F7D51742, 865415BD049E86F3DA2E0B6E25E1A50C
+  7: 9D96D1034166BF, 50669247A5B338E183DE5139831CD6A4
+  8: B466050E1330B20A, CB264FA7853A1FFE86E1A07CFA7C7319
+  9: CF16F0B3D9FC6183DF, 647DD6E1F40F385E1DFE6676FB036242
+ 10: 14D90928C7236050096F, 930CAAA5536406218885475CA823A973
+ 11: 4F2322D66A7079BD7DF519, 3B3931D47413042FAF1313F1041509A3
+ 12: F1497906F1D8F4F9E47E4BE9, 469FB0D62828427C2E9BA04041A1424F
+ 13: 2FAFA2A3EEA4C000702E58D1D4, C9A484FC4ED8644A06060DAE2C3D1568
+ 14: 5D707F8ACF319413D220AA2FC2B2, 0EE9AAF5B1CF622ECF6C4F5E5FF4656A
+ 15: 2C19DBF966D24B2713F82B69934060, 8676246A2F7795ABD435B3C6B4EA6E7A
+ 16: B3FED6C2315CE6D98729DBE69270A11E, B8AC739AD154744A33E906C34D91BD4B
+ 17: B2BC44CE088BC3F654B9703D9C691F17B3, BAD8314A171BC0119942136C5876AACC
+ 18: C6E958E3E9AC836C9626BD66478974D26B0C, 4E6D61833E9DB839117B665A96DC686C
+ 19: D40FADD078B474EBCE130FB44DDB4824077988, F43E3CD978A6E328AF039CC70E291E1C
+ 20: E177B3DF83A117E55F255A6C2CD78AFDAFDA307F, EEF1ABAAB9CBE0EE317CC79E7E5E24B8
+ 21: DBB4569B3E305E4525F1F7B3D2AFEF226F397E661D, 65ACFB70132EEE1D47319A550A506DB5
+ 22: AC2CAF77718DE59131A6B745DE9F3A9897B17580EC71, D8DB9006A9597F640F2594340D69E551
+ 23: 8F62022F72A0D769D2D095A55E28832950870B2B44B0BE, A7E196F869071B7BB713E8A2D15627E9
+ 24: 37F5640F820384B35F13F8C8C7DC31BDE1E4F29DCFBDA321, D5765C39DBCA72AC89100CCB8864E1DB
+ 25: 25059BFC302D0F8DD41BB22CF2391D456630C06F1DAF4DFA86, DC2FFD153C788C28D251B78AB8B7388C
+ 26: 151F158CC4BA9393FDB153C4C72911C120BAB519FAF64719133D, C61915006038BF15DED603832FD179DE
+ 27: F5DCF4231482F72D02F8B9BE0A41113D35AEA1CD85021CEC978D9C, 9CBD02C557180FBD0868C87A0BEA25AE
+ 28: 5D88B5554A2ED73054226473676FAA7159CE12B5357D635DDED35B5A, 5AD11CD6B14C59E64B5B26DFBD00FB5C
+ 29: 5696C7066EA09A30FC8BCBAD96D48A5E5FBCC8756B770F0A89B8711911, B9EA5F3BEF0599D385A9ACEBE4064498
+ 30: 1240FED47B305AC1883F8CF137D58E79052B4E686DCA1423A6A2BECBD5F5, 036A5EA5F4F2D0BF397E8896EB7AB03D
+ 31: AD9517BF392C1EB56D78EDE1C41F3C73B72304DA47F400C390C86B37A50C2A, EB3E026D518EED47F6C927525746AC54
+ 32: 2AE1CEED83C6490A7E5752E91532406EAC6FF4B11AA770EFFF1B255FDB77C528, 74BFBC7F120B58FA2B5E988A41EAF7AC
+
+GCM-rc6 (16 byte key)
+  0: , D595FEDAB06C62D8C5290E76ED84601D
+  1: 4D, 47A6EDEF8286F9C144B7B51C9BCCCACF
+  2: 0085, 9788DDF89843EC51120B132EB0D0F833
+  3: 463701, 673CB8D248E6BECD5A6A7B0B08465EF6
+  4: F5B3222C, 1C424282D7FB427E55285E20FC2ABFF9
+  5: 3A4A8361B2, BD40E631B054F280C7973E5AB3F06B42
+  6: A475866BF2C5, 2067F42FAAA6274270CF9E65D833FDED
+  7: 689D0D407172C8, 3BCCFFC64E56D5B753352E1DDD5CCAA3
+  8: D9CE4B051202A1D3, 79B0CCDA3D0B9C9BCF640BC9E6D9CE0D
+  9: 0317D68BE098D276B7, AF35043DB6213DC5D4F3DFB8E29EE537
+ 10: 154CEF0C6F37AA0A73C4, 61E598A8C6D17B639F9E27AF55DD00F3
+ 11: C3DB1B2B6CCC9170B9C05F, 966871DDD6E110711FB9DD733B6B2B3A
+ 12: E4F22383C75BC0FB0E59C5E8, 971536AF878F4EED68F59046C928EAC8
+ 13: 2FBFB99AABC6209FB8664916DD, 68D0BF2144AD1ADECC4074DAE58540C2
+ 14: 5FEEDFD09BF89719A34CDCCD2AAA, 64DEB7D5E6891103AA54C0EB366715D0
+ 15: E063A076E0C770FB010D26C3AC3EB5, 0CA321B2A7448FEEF84D4E0AD5BA2DA4
+ 16: AFB0DB9959F0906BD346C2D81DC5412C, 425627895E2C4C9546D3227975585459
+ 17: 79179C0D4D6C5E0741DD4CA1E8CF28C75C, D0188A344A1CEE52272FE6368DB0FB75
+ 18: 8A75521139B0DE3C08C9EAEB77D8018A39FE, 47FCC200D8A384320D2F1A5E803A9991
+ 19: 0399381D0A975AE3980A9FB75B991C055AF367, 034915370AF94B96A8A4E50FF9B134CC
+ 20: 8C189094DB13FBE62EA5C4A53C29A428ED587BA2, 99C58F838423033298897841ED526347
+ 21: D91F5144B525AF5D47EF4D5F0AF9915447A55927F9, F6750BF7E089515D35B47BC1C65E2E3A
+ 22: A4E26B554AA277057A5FE3FA08A6138CEEC6D69BB1D8, 7BBEBF52D8251108C7AA1025E213EC44
+ 23: 5C1A8C3A46FCA90D73675706313CADFBB90A535A4B3D5A, E35244A2633478BBDAFCC81161F28B80
+ 24: D69F7264FC594057B89181B83582D799AE54E9EE4FE8AD48, D4B29E5C25F9477D9345526DBDE9372A
+ 25: AFD322D0AC4AF38D5B9CBE0DFE85618C001A7A77CD8FFFCB3E, AD06BB9C59D23D258D6A2AEDD946AA20
+ 26: 179CA8395CD8E75B4E5EA07D25C8036AF08B1A1C330492523D36, E3704C4341A834C087500E332B7DEAE9
+ 27: B9178EF7774684F43F1FCE99A4319B5A4D167B0A848551F562CD7C, 5D5082FB02B9B494D5883DF49DB3B84B
+ 28: 830FCD15A09EC61245D7DA258E308E76D3B542F2345DBFC11AE983A3, F50C3332F8D91911BDACCFE228565E5C
+ 29: 179619B8C7EE9B3121405BBED2AC102A027E6C97EAEDB5ECFEB13792EF, 859EBA3BADCE6E5AB271A261B26DE28C
+ 30: 14264C7E0A154119BF24B7FCF434E81440D42D54738F0BAE55836849AB85, 0B6C9B9CADB1B6EC71CEA090C8C72834
+ 31: 0D7A316F8B873F62CF26CFC569179AB11CBF09D3467936A85ADC265B2C9A8F, 866AE7C51EC2D9DEB32748A1C8B61143
+ 32: F8FD1F967CD3632805AD7FA8ECB40F530927DD5C49D31FDBAE49738E2315905D, 9CB1CB84A727C9F42555EB566E0A1DEE
+
+GCM-safer+ (16 byte key)
+  0: , F769B436C7FB7C0C822E24BB2B2555D3
+  1: CA, B156298625F5634FA012B23044437807
+  2: 4960, A64C73E890F3D77B2C3B3C76C2D913C6
+  3: DBBB8D, 686651A017F89A22F9FE96533C85C52C
+  4: 150AD99A, 177F7DE9E897DACCAB7EACEE3CDE7601
+  5: 077055065F, 48B4309C76CAC37BDF11842311BA6CD3
+  6: B2F8CE062C06, ED04DF96C06959524956E8AC5C338457
+  7: DCE718211410D8, 3F8D8180BDEAC2F018EA81615177CC8F
+  8: 0F71E2772402AC83, 2130481B2CA7B4B4C8F3EE73B3B3C28F
+  9: B69030734E5ADF753C, 8CC4B62BFBC3EA56CCDBF0ED318C784D
+ 10: 6B8A91ABC1BF2F2D0176, 86EAAD80D148A48086987A40A5631DEF
+ 11: 44AD00799EC8E62E34D6A1, 016830D58F06F75E54531B45D9E785F9
+ 12: 0C4B9381D78E0F0A78B3CEAA, 4A79C58DAB131A22F172F9177DC4158B
+ 13: 2C56D4625876524B4D8D5F079B, 7B407F704225B25F1F136C984E564147
+ 14: 36424D69BACC56407D345B3D7B4D, EB126C255A2DCFD32F69DD5CB61876C7
+ 15: FDD3E091C0420D1A4D4A848757FCC2, D319C5C07134D67BA42A4BF312CD874D
+ 16: EFAF6F117EA9A4B4B83052BBF5A07DB9, BB09D473FE82257146E7ABC2EFF6F631
+ 17: 19B71383C414BAC3EF252FFF09F5ACD777, 526DC9AE6895ED33A34A9A4ADB07E1B6
+ 18: 9AB6DFDB930D26E00B3D98DD5AD014E08756, D70B95B20C106A5A03F9B803D2CAC3A0
+ 19: EEB3C236C3031DE4C3F94BD746677AE84B271D, 9483BBCBBFDBA1CC5F6392DABA2ACC19
+ 20: 3A0EBC7536F8717E8FDAFEDAC39E8F1F43C0627A, 3DA7DC2475466CEDF01EB543870A74FA
+ 21: 79D28D2F149E1D97E910342DF383FCEECF5AFD4C6A, 2364F33BCF6F07E381F7E26DAF802D83
+ 22: F1D7C319BAFB740332CA19AB0C9B71728D3AE69BFAC2, 3D4AEE9780A5C98CBC69606CDDDB31F8
+ 23: 1A0D80381A186673FB7B52C40AB6C46A11AB0889333C20, AF5C17E3D0D9724EDC1FC438A16B4EBB
+ 24: 5E503440B22DD6AE6401BA4355C8791BACC598C9E0F1412E, 156D8221BD61F5C108FC18FB2F50D159
+ 25: 7784EFDC6F0FC56FCADAFF17BB52DEB35B64FA19C3F391BDFD, A291E8238EF158A2379692077F70E8D0
+ 26: 184B6E18032D1A70CE5027912E447C357C72EEF7B20EF0FB256C, 0FA0138FB9480E0C4C237BF5D6099777
+ 27: 7AC8FCB64F35B71C5ED0CCD776B1FF76CE352EB57244085ED34FE8, D995B3C1350CC777878108640C1CADAE
+ 28: 86C7A01FB2262A8E37FF38CC99BF3EFAEB8B36166D24913BDD3B91DA, 25EC6D9F69168C5FA32C39631B606B55
+ 29: 91F5D3E3FE0B1976E2915B8DA3E785F4D55768FD727AEF19FA1552F506, AF902DED55E386F0FC4210C97DB9446E
+ 30: 7ABF5BD9CB2EFF8382C6D2B28C1B0B25540E434123AC252046BDDA74DA32, 713259EDDA9B1B63EB68E0283D0259DB
+ 31: 5634B23ACEF2874BE0591BE3268C4538698FF2D93D59B39BC86D0137DACBAD, C4054796AFD335B43C60E7E634122BAF
+ 32: F26C68C36B1E56449595EA4E162391E0C6A306592949F69797B6C2327E533ADB, 7B392AF776A94983078814B6B8428BFE
+
+GCM-twofish (16 byte key)
+  0: , 6275E8CA35B36C108AD6D5F84F0CC5A3
+  1: 38, A714210792F9ED12A28F25CAE3B3BC5E
+  2: 8E2F, 6357C1F125723F2244DAF344CDFCD47B
+  3: 900A4C, ED4E0B318346D5B9B646441E946204E9
+  4: 087EAFF8, B871ED95C873F1EFA24EF8B6915F447D
+  5: 63FC9EFBD4, 650D0ED98CBECA07040AB97B97129360
+  6: B6081E94AA19, 6A3BDA8030C5A79B6B9087555A1DA67B
+  7: E10A7B9CBB20C2, 59EB55DFD0A37C55A869834E597373AF
+  8: 94E947FEE05780EE, 354918527F855264E37DB6892E868050
+  9: 9A80C567AA50220862, 814EE57CC9D51D7D900AB4840C4B072F
+ 10: A8741BE1E42BE207C416, 2B28AFD8ABE20664D8BAD7535F82F11A
+ 11: 6AB7E3C68B6682023E8190, 5E48B67541FE83969952394F84D29E93
+ 12: 4F66FB634EB258CEE2955D84, F2632C2135B6E1144673B0EF73499818
+ 13: B29042F3877C2F5E694953C5F6, 03268A30499D57A06AA873EF00160C3C
+ 14: DCC7B5D9F58C88F54A9611389B8D, 5515426FF7CF2EEA91BE2B3752371CE0
+ 15: B665488BCD75FC02A0DF7994B7CF98, B721531E2A317C254FA2ED306ADCF96C
+ 16: 9535DC8A72645E34F948B71A5159AA9B, 5CEED93DE128044F0471C65AA8F21D29
+ 17: 5CBFC61A23D28562FCA929375E5B585327, 3AA842B21631968D1B58B72FEE090EE1
+ 18: 2AC3F780B956A933C0B8565EE527173B8CC8, 16EC4B6D8E2CF3CD0D16E7A5F401C78E
+ 19: 5067FD65870A4EBF6C7FA811A15270E7F8F17D, 9A7563BEDADFA6B6E48F5C13FCEAED6E
+ 20: E3A65A188077E5DC171CFF30BE8B27F10F015166, BD5B3D84D0C1DD51A3909F849141B57F
+ 21: 88D0A65C105823E68BE3987CB205AE0C1A27588FCD, B280221AD0BD83E1D6B37F331F326AB5
+ 22: 7C56D987FEF6807EEFAFD4C7EB9D72AA0E037979D91E, 686E1268A8DC9CD0192A383EA6C2D975
+ 23: B23CCD0A076CB122750B634B9E6551E0585EDEA18C3245, 6DF30A7F0728E2D549AA411AE375E569
+ 24: 767BC3AF206E67C9E27A4D7E814F3B3A65D27BB70BA9DD4D, AB2B16C031FB2C8E85B3B2B38A5CBA4E
+ 25: 9ABF34ABD43705D62F377449461C5DC239A2A86E5A98AFB159, 3DEDEDA85E6BFB53C6F18726CD561604
+ 26: FE756344C05CB12AA0673F1C2069A86556E583FF4B7313A0D395, 21CB0E0BABC3C7E547F5CB207295C0EE
+ 27: B70F16AD19A6B0AF6D8DBF4E98D7D5ADB944D91BD889D9390C3E21, 2AE67812A22C1C785D3BFC184A1C74EA
+ 28: A6389032AA9D08BDBAAA5E230E5130665FB4F0CB868F3F20C4C5438B, ECA054EFA3F39400A587839C4F0605C7
+ 29: A55A41315EAF3A67A0FD0E14C6E04D03A5E38D0F756719F4A0800B290A, 7A5277809D4B65E663603099B4DFFBD8
+ 30: E739633579AA6201A024B9873F28412BB08B08B8616D611BC9D07979BD3A, 390038A93AFD326C5CC1525A24CA91AD
+ 31: ED3266F8B0DAA7C3DB7814427E8139831CFC0EDE668F0DA83FF7090154410D, DE440EC2C6080048BFF3C5455E1BB33F
+ 32: 4D0F751B55DA3A2E0B28DE59E9680669FCB5984E9C0DB942DBAACDDEF0879731, 62F96CFE31D3D6AAA0B9F5130ED1B21B
+
+GCM-noekeon (16 byte key)
+  0: , EB5A8E30D5C16311864E2D8D32859ACB
+  1: 88, EAB88DE1EB7BC784A706B2D7946798D7
+  2: BA1F, DC3CEC6AA324AC7D053EFF7A99AD3069
+  3: 9A1457, 4AB65831DE378DFF71C20249C7BEC05E
+  4: 2F9496D6, 800745CF95EAE3A698EDF9EC949D92B7
+  5: 84153177A2, F6A05B654435ABDF5F696C0E0588CB5C
+  6: F80B7865C766, 2334D0061FD488D15A6AC8E44EA1F4B9
+  7: 872EA486B4EA9D, 3A49671DE347F675AD7904DDF4255F3D
+  8: A4EE5750507FC831, 956D09F7C5FE812C6FB982E1DDBE864A
+  9: B5874AC964FBFC1A97, 90FBC75F45BFF58B3A1100393955D0C2
+ 10: 92FF5FCF1EC675E02E71, 983C96A7BD4A0DB5D3B877911CE8A6B3
+ 11: F7BCA69A9C7033D84A2BA0, D4ECE5BB9FFCBB331A646D9CE8078634
+ 12: 5E1041B4554C8CDD14AAF16D, 1EF777F307CB96788B9120FFF8A8BC2F
+ 13: 7BB7289FCAD209D7992EB7AEDC, E8AEFB830DBAED2B4A790FFEF940A20B
+ 14: 12776A7C937A648F0A8628AD8C5C, F070283852AC030819EA67BF82C719AA
+ 15: 7293476D9E935EAE9DEB66F697F662, D6322603671153A1EC1453CDA5978E15
+ 16: DC12A86C85E7358919BABB15A3BF5FD7, BBBFA467EBA8124DFEC82DB0137D56B9
+ 17: 0CC1DAD00A987F9C57E3660D9417F226E5, BB8AF5A0B5BC79BD11C5D41CA80CDE2C
+ 18: D0049115D6EB5495FB391CDC494022AEAA48, 682FF357B2BC059765C29AE6CA668D0C
+ 19: 48FC54A401B4C06CE8567AD298B672191C7E84, 493A4AF4C2A8828FED8442C4EFF877F6
+ 20: 90779795821CB1B7DBD97028E29DC1CE7D0CFAE0, E126F485F73B6F7B3894B4CF7E1C5DDE
+ 21: 8CA5C246C8B7C04BD7171CAE2D1A892D66302433F8, 5D73149A3635A86B3C34DEA5B95CCBCB
+ 22: DF082B665F7A952B2604C04554B81393FCC7C0B816C8, D3569ED7D431176B286EF22414E4CBA8
+ 23: 761908530C9069E189649ED24B6A68A89B067C31E9868C, A258BCD83D3FBC7AE2AEF7516025AB36
+ 24: 717048F5A31F3C89D3704F90069AC5D5174118770C65BDA1, 067EBF18F7E3DF4EA13F9ABAC682C2A2
+ 25: 08C6FCC5D3099347C3FEBA3858A6C22C51298CB591DDB77827, B57BFBA40BE99DF5031918A1A4E2CA80
+ 26: 2CC53EF7EB954234E64CD4D60FB1D7157A489ABABC10900FFCDB, 236E769611D16EB7F463B7578770F886
+ 27: 2556B46F2E831223D632F2691329A874F517687AF81B8322AC55D7, E213A90DBC31DC261A45A9AE41CFEEC3
+ 28: 71241792728594D69791B80AD6DBC6417D1D14D222DF5E6F834B82C8, 601F97617708B1945BCDA8A82496EFB1
+ 29: 5003DC2EAAA23F9E2221CCBB9E20116692CCC99B3CFBD0DDD3A8491E7C, 3743155B792012845550205C8949B73E
+ 30: D0589675357E850333F854FBA160688F06D122DEC00CC2620DA0B2770765, 20E085752FC4D37791C22501ED1DB6AD
+ 31: 645B46D2D114EE7329F14AC1D94E6817EB385EB80C61F014F90530749079EC, 8A18DE86F9555A1070D0BFEDAC15B14F
+ 32: 068389206D37BF5A41C58075FC98901C3B42E6F2F13C09F4E92524021BB1C1C8, 370B86914D63CFEE8303D538A6BEA0E7
+
+GCM-anubis (16 byte key)
+  0: , A0061C2F3B2295BFA33BC74C037EA8DA
+  1: ED, 9E5648DCE40DE37B56C557D26CB18D83
+  2: 6719, A6605253C59A101FF85C5102CE92BE45
+  3: B8873D, 13F3E3ED3646BB296EE4ED5D6379A21B
+  4: 5AA6E2CB, 1812E8385D15B5BAE043E4E860BEF490
+  5: 4F6F4CD8E9, 8A80BC5E08929C42A5A74C5D9ACC0C6D
+  6: 2F0D8B483CE4, 316F588F78FC6A9196C97CE59B9B63B6
+  7: 82D885FDE1F948, 7160BF556614511F53738A92B5277056
+  8: E4931462AD41B6DC, 7CE24C4D6B499975FCB72B5E2275ED56
+  9: 503AA70BE698BC5B41, 10EA0C61FDBA8FF7B4E9927BCCEFD911
+ 10: 6B2D213D14B5D25EBE36, DC3222AED12EE26D3D14E2E733EDB2A7
+ 11: 7D8B0BC1B7443E7267371E, FCACFC73E391865BE86E041F51C45E81
+ 12: 9EF3BF8609E133BEB10565AF, D84326D4CAC9D5B74FCFD8CBAFE79E77
+ 13: 59AE7B1FDE1178CEE7F63C4894, E1BCFCDCA86CAB9C684F7D21962D580D
+ 14: 564E7B8BAC5582A3BF1178916569, 54804D8DF4D7577EF65C15487695F840
+ 15: 758A6DC437C8821274B0F16F911BAA, 19DD27500915F425F34F67CC2374DC36
+ 16: 0468C94A88A27AEEE2B3A973065E53CC, C743996C6F49363B2F4613F24703EF7E
+ 17: 3B0CABA5EEE44B7BFF0D726ECED54763FF, 14D9D09815BCD91DCCE2F5AE1A9929CF
+ 18: 5B945D83B98C43B0248F9BC0479E332869AB, 67A275F0313D4245B1965411CFCC8F17
+ 19: 97332441CA96DE8553A3C6D898FC6D90C86DBF, 73150EC3D6327E3FC8015A6192652D3B
+ 20: B9A1778FAF9767160D0D87816ECE1B99AA727087, 0C173D3C4078392CE377313C48D2BAE8
+ 21: 5882B73911C7D26EFDCCA3AED2EDC8A8BFFE75B1F8, 8F8C535639A0B59537E590C7FC9D2E53
+ 22: 70AEBED8CCFFF6E5CF06F3E841D12387EF8D6C7B4BDE, 4B00C27FCA9BEB82331CC8EB13DCC580
+ 23: 345CCB52BC20DC5F1BF5EEDF5D72A6C48F402557FFD342, 1A790A39573B853DBB8E2E73B7331014
+ 24: 0637C78A817E91D63CE18CEAF8D65C6107283A90C5A97842, 52786CB81724E12C76A0D23D4680E36B
+ 25: 59526D1E86A473DFB720FF25E97D6571077845F73C5E8322F1, 369FBA7823FC83D727FFD25D10130987
+ 26: 2933BB4E7603C313B62332827601F8189E14C1F08EA547E15AB5, 204520E365DAFF6551B01562A4CEFDFB
+ 27: A4098CF2A48A1DC2BCCE65CCE8DF825AF51E7E5F94B6186FF85D77, 9833EBB9A1D5CD0356E023E2C3761C2B
+ 28: 26557B942FD6913D806672EB01526DBD5D6F532F78AB6759DE3415C5, EDAACDD101BC40EE6530D8B5DC031F31
+ 29: DB92C3D77DF0C8F4C98845AA9AD43FB800192E57A53E083862B7E3FAF0, 628DEB1E345303A40700289052080FF8
+ 30: FC57BFAC2C77781723C2B721886D44ED67A52D9AD827874BC4EEC0A97281, 9A222DBC47B4AB4E520D3CC5850D4DEF
+ 31: 72DFB9E91A78EAFE758B4542206A4A957B4523A58428398C11BCF2AEAE1938, 307D0B876130E82804C1167E03B69B2F
+ 32: 7275C6EBDC2680DFCB73326A987D2FBCE83E40A9AEFE6351CFDA7251A6FE10A6, 895E6EEAA9BD88594903325A063CA45F
+
diff --git a/notes/hash_tv.txt b/notes/hash_tv.txt
index 7fd9062..4f2714d 100644
--- a/notes/hash_tv.txt
+++ b/notes/hash_tv.txt
@@ -1734,3 +1734,38 @@
 127: 3C9A7F387B7104DF19CF264B0B5821B2E46E44ADC79262546E98FFA113EB3D45799EAC78CCA4643C937FCC3C1D249A212FACB34C63D45EEC81069095D7CDCE7B
 128: 803A3B37C89E84FBBEC75BEE3D00DD728FFC4246B5A5E989DC8DC2CD0F7937966AB78C79E1D4648EE6EB40F3D70491CB46B8AB42E155672E2AB8374FCF70DD79
 
+Hash: chc_hash
+  0: 4047929F1F572643B55F829EB3291D11
+  1: 8898FD04F810507740E7A8DBF44C18E8
+  2: 1445928BB912A6D3C5111923B6C5D48D
+  3: D85B2E8854D16A440CF32DDDA741DA52
+  4: 5F3082124472598098B03649EA409CDC
+  5: 604A19622A06D0486D559A07C95B297A
+  6: A16F89E4DACA6C8174C9D66AA23B15AF
+  7: FC6893F79A2D28315FBBEFCAF0280793
+  8: 6A80F04CB93B1CFB947DED28141E877A
+  9: D036D0B4DEF1FA138C3181367143D1A9
+ 10: F031A2DC2A196B268046F73728EE7831
+ 11: 2E05C9B5A43CFB01AD026ABA8AE8201F
+ 12: 8B49EF0BC936792F905E61AE621E63C3
+ 13: 485CF5E83BC66843D446D9922547E43B
+ 14: 704767A75D1FD6639CE72291AE1F6CD8
+ 15: 19F6228C2531747CB20F644F9EC65691
+ 16: B78FEC0628D7F47B042A3C15C57750FB
+ 17: 3EF9AFAAFAE9C80D09CD078E1CC0BD8A
+ 18: 5E4501C8DD0D49589F4FFA20F278D316
+ 19: 00D2D0FDD0E0476C9D40DE5A04508849
+ 20: CC7382E78D8DF07F0BAB66203F191745
+ 21: 85B841BCCCB4AD2420BCABCFD06A0757
+ 22: 7159E38F4D7E4CEBEBF86A65A984BA2A
+ 23: C8949A9D92601726F77E1AEF0E5F1E0F
+ 24: 8CE35EF6EC7DDA294134077420159F68
+ 25: A0F4E4522832676B49E7CD393E6D9761
+ 26: F55C27D180948585819833322D7BC4CA
+ 27: 0A3975A0113E1FE6A66F8C7D529715B5
+ 28: F77135C5D04096181305C0906BAEE789
+ 29: 31FF81B49B9003D73F878F810D49C851
+ 30: BE1E12BF021D0DB2FC5CE7D5348A1DE7
+ 31: CB4AF60D7340EC6849574DF1E5BAA24E
+ 32: 7C5ABDBA19396D7BE48C2A84F8CC747B
+
diff --git a/notes/hmac_tv.txt b/notes/hmac_tv.txt
index 3003490..18edd70 100644
--- a/notes/hmac_tv.txt
+++ b/notes/hmac_tv.txt
@@ -1734,3 +1734,38 @@
 127: 1D8B2525E519A3FF8BDAAF31E80EE695F5914B78E7DAB801729B5D84C3A7A2B36A33803F5E0723981CF8A9586EC1BEABC58154EFD919AFF08935FBD756327AAB
 128: 4AABF1C3F24C20FFAA61D6106E32EF1BB7CDEB607354BD4B6251893941730054244E198EECD4943C77082CC9B406A2E12271BCA455DF15D3613336615C36B22E
 
+HMAC-chc_hash
+  0: 0607F24D43AA98A86FCC45B53DA04F9D
+  1: BE4FB5E0BC4BD8132DB14BCBD7E4CD10
+  2: A3246C609FE39D7C9F7CFCF16185FB48
+  3: 3C7EA951205937240F0756BC0F2F4D1B
+  4: 7F69A5DD411DFE6BB99D1B8391B31272
+  5: DCB4D4D7F3B9AF6F51F30DCF733068CC
+  6: 1363B27E6B28BCD8AE3DCD0F55B387D7
+  7: BB525342845B1253CFE98F00237A85F3
+  8: 89FB247A36A9926FDA10F2013119151B
+  9: 54EB023EF9CE37EDC986373E23A9ED16
+ 10: 2358D8884471CB1D9E233107C7A7A4A0
+ 11: 94BAB092B00574C5FBEB1D7E54B684C4
+ 12: DF1819707621B8A66D9709397E92DC2F
+ 13: 3044DFFC7947787FDB12F62141B9E4FB
+ 14: 9EA9943FC2635AD852D1C5699234915D
+ 15: 1CC75C985BE6EDD3AD5907ED72ECE05E
+ 16: 1A826C4817FF59E686A59B0B96C9A619
+ 17: 44DB2A64264B125DE535A182CB7B2B2C
+ 18: 4741D46F73F2A860F95751E7E14CC244
+ 19: 13FDD4463084FEEB24F713DD9858E7F4
+ 20: D3308382E65E588D576D970A792BAC61
+ 21: 38E04BD5885FEA9E140F065F37DD09FC
+ 22: 5C309499657F24C1812FD8B926A419E2
+ 23: D1FDB9E8AC245737DA836D68FA507736
+ 24: F6924085988770FCC3BC9EEA8F72604E
+ 25: C72B261A79411F74D707C6B6F45823BD
+ 26: 2ED2333EBAC77F291FC6E844F2A7E42D
+ 27: CE0D3EF674917CEA5171F1A52EA62AAE
+ 28: 55EDEAC9F935ABEAF2956C8E83F3E447
+ 29: 820B799CB66DC9763FFD9AB634D971EC
+ 30: E14B18AB25025BF5DF2C1A73C235AD8B
+ 31: DE9F394575B9F525A734F302F0DB0A42
+ 32: 625ED3B09144ADFF57B6659BB2044FBE
+
diff --git a/notes/ocb_tv.txt b/notes/ocb_tv.txt
index aefd8fd..6429228 100644
--- a/notes/ocb_tv.txt
+++ b/notes/ocb_tv.txt
@@ -199,6 +199,82 @@
  31: F175230606040ADACEBAFE4D58BBD140B2D45E8BF7E5C904510B58E4B53D3F, DAF579E1A12481D39F4DCFB7C28794B1
  32: 261388D491EF1CB92C261FD9B91CAD5B95440DE0A747144EB8697699F600801D, 749056EBEAF4F20CD8746AA8C8846C47
 
+OCB-safer-k64 (8 byte key)
+  0: , 0EDD2A1AB692AA7A
+  1: 3E, 306F814F3C2C109E
+  2: 0593, 063D19B734C34715
+  3: CA72C6, DF6DAAFAD91BE697
+  4: 08924AEE, 15095FA49E789483
+  5: 359908A6CD, 16CB7F0741BA4091
+  6: 97F3BD820CF4, A59DB15B67B95EE8
+  7: 0A267201AC039E, B4FFC31DBCD8284A
+  8: 9F6ACD9705C9ECC5, 6B41A938F0B1CAEB
+  9: F355D5A937DD1582C2, 9D1F932E521CB955
+ 10: ED39758CAF89E7932E48, 398EF517015F118F
+ 11: D8ACF19363A0E0ADC9321B, F98B2A30217766AA
+ 12: F8F54A8202B0F281ED610F33, 36EF7FA4A20E04B7
+ 13: 0F8677DF64B5982DB6E2299140, 4DED2DA806834C81
+ 14: 0C357A9DC321C93B3872881503B0, 7814D1C0C6A8900A
+ 15: 10B6B1A261C3015A18110AD200A7B6, 9A814D6D2BAD850C
+ 16: AA9EA9D1BA7818C0D2EBF23781A5467D, 236A24FC98826702
+
+OCB-safer-sk64 (8 byte key)
+  0: , 76F16BDCE55B3E23
+  1: 63, F34B0B471F6F8F75
+  2: 8651, D7EFE17943D35193
+  3: D45504, 263224E50E7E9E75
+  4: 57B414C3, A553D6CABCA0F285
+  5: 4976E3B303, AC5E9969F739EBD9
+  6: F10AB8EB94E0, 8301FFE68848D46D
+  7: 6E954593AC427D, C1CF93BBC0F92644
+  8: F48F44441B898C0F, 698FFAED1A95E8E4
+  9: 1DC60156D62782E3D0, 6AFF0DCC65D4C933
+ 10: 71920ADC8997CB8B3A72, 1C101C6A27CFBBBD
+ 11: 890ED7492ED914AC20391B, F66DCD6205D945C6
+ 12: 1B9FAB84A8748BAC187C7393, B450757FCAFAAD52
+ 13: B4C89E1BB280DBC265E43ACE15, AE6BB3D2E6A371FF
+ 14: 24B0C28944BDF22048E2E86644F5, 84E93E2191CEF17A
+ 15: 8F2D5694D55EE235168AAA735943AF, 514252AEF2F2A2D9
+ 16: 568B7E31FFDA726718E40397CFC8DCC6, 3C80BA7FCA9E419E
+
+OCB-safer-k128 (16 byte key)
+  0: , 4919F68F6BC44ABC
+  1: 65, C6785F7BE4DE54D3
+  2: E1B0, C197C93B63F58355
+  3: BB7247, DFE092EF8184443B
+  4: 38C2D022, 943FD999227C5596
+  5: D71E4FD0ED, 51040FE9A01EA901
+  6: C4B211EADC2A, 329429BE3366F22F
+  7: 426DEB3FC3A4BC, CF1C976F6A19CE88
+  8: A6F813C09CE84800, 98D9FF427B3BD571
+  9: 4D1A9948FD157814B4, 5A389FAEEB85B8C6
+ 10: EC3EA142C3F07F5A9EEB, 31E26E13F032A48F
+ 11: A75FB14365D1533CD3FBE7, 8EF01ACC568C0591
+ 12: 891582B5853DD546FF3EA071, E013CFFE43219C21
+ 13: 54CA848C49DCDEE076780F21F4, 298EFC7B4D6B6CFE
+ 14: EA7611C69A60F1A2EF71D6A7762D, 7D9AA51CFCEC8101
+ 15: B2D1A211BC524B965A084BB4B21710, 7B2AC0EEB5216892
+ 16: 5E81F1BFA270E804A488C9BFAB75811D, A67F627CE1E37851
+
+OCB-safer-sk128 (16 byte key)
+  0: , E523C6DBB3CA178D
+  1: 5E, B1CB7EBE5780DF98
+  2: F4D8, 8036235F2BE7A817
+  3: 4FE268, 123320394EAC24F6
+  4: A5BA02B4, B8276B5E027D45DA
+  5: 1571859CCC, 29406C5F2DF2CFC4
+  6: CA1E47447B95, 5D4FAF8FD5341791
+  7: 8710DB37022D96, E10040FEA9AEA9C2
+  8: 205990DC9A34DA3C, AE25CB49AA7A697B
+  9: 757AFCB3191DC811C3, AA8CADA8638D6118
+ 10: 6994F8C153522361BB92, 1BCEE09E928EB18B
+ 11: A86FA0CDD051BB60AF5AA8, 50A38F8E9889354D
+ 12: 8D3FD3EB7FF2269AACFD24BA, CB51CF84CEFC45F0
+ 13: 03D2A313925D9490FC5547F95F, A1FF9D72E11C420B
+ 14: D77C0F0F600FE92F14F479FA457C, 1EBE1B4B9685EDFA
+ 15: 0CAF0A8BEB864E26058C7DF8EBA0EB, 1B153DDAE807561F
+ 16: 113D12716DFE0596A2F30C875EC6BA0E, C61F5AC0245154A6
+
 OCB-rc2 (8 byte key)
   0: , 1A073F25FF5690BE
   1: F4, 3D3221E92E40F634
@@ -329,3 +405,57 @@
  15: 1D5A7AD556FF3078284BB21A536DAA, 01FAE2F4936ED9D2
  16: 4B8B71396924880CB33EA6EC6593F969, A0F4B1BE3B9B4CCE
 
+OCB-anubis (16 byte key)
+  0: , D22ACF880B297DB0513DFAF0D2DF57D9
+  1: 59, 210A179469D6568AB9470C760415574E
+  2: AFA5, 1223F9CD160ABE2F257164C6E5533C87
+  3: 969BEC, A57EC767543CA2ADBA4F5A7423ECA78A
+  4: CF8B31F1, 13B5BF9CD87CE15CE696F3AF1B082650
+  5: 9B22DF3852, 4937FDDA0AFDDA04CCD53CCBB0A82745
+  6: E11719B2F0F8, 6847931DBF0223F5CEF66AE3F4DFCF9B
+  7: 5A85E0F6DD2266, A1A0AF45A68A681CC396615FE1E1DFB5
+  8: 7F2DFCC65ED86976, 13614A3C6E0E08611D8DF8EE5B7D788F
+  9: 1DAF10DFA3F1D53E50, 673632B6DD553BAE90E9E6CC8CDE0FA5
+ 10: AF74FD9671F9C0A9879C, B8B4DD448FE967207227B84E42126D90
+ 11: 49421CED1167A882E26297, 21C8951A1761E4BD13BC85CBD14D30BD
+ 12: BC0BC779B83F07D30CB340DA, FAABD25E14FFD8D468AD6616021F604C
+ 13: 843D7E00F94E61AE950B9AA191, 08933ED5FBDCAF72F788393CD5422D0F
+ 14: 296F15C383C511C36258F528E331, 8BFFADF5655C1864057D69A6706D1739
+ 15: E31D2E80B2DBA4FBFAF52DB0513838, C4CD36821EC631CCBF1F258EE9931288
+ 16: 87F319FE9A48E2D087EDF95563896EE5, 517960488E5A118D150A1573E76C290A
+ 17: 9632B7DC1740BBE0A7AEEFD0F535B5AE8A, 0C24D0950873621D319A928862D3A6AC
+ 18: 359431ED4B3AC537238CAC2F86126972D403, 4A0CED2F4BFA3355C17D6C5DF9FABFAA
+ 19: E15B50172EE8DA9C552D448A5A48BEEAA2F11D, 8166B2A2D3A0745D1055F9F503FD6C03
+ 20: 75842DDC0D5E3BD80225E4BFBD1298421244D7EF, BB957BB2582B67B63978BCFD7A949EDD
+ 21: 3DD69162716D5F3E096E614991CAD7ED8E01F926B8, 40A954F31F5B0A2C5DD220ACED8D2B3E
+ 22: 8A49AC14F59593D5399A10F9346E2FD36F47F64ED419, 4324D408CE7F86370495AF14FBD1A859
+ 23: 6AA8FA353BCAAB4262211D75F13D27BE173526B8BC3CFC, BA3A27D79EC8ECBC5A78CB9FD095B766
+ 24: B918192BB72CFEF980298EEE570460356A4BA1755576FEAA, EB341ECE0A070E769F498600EE4EBF77
+ 25: BEFAE0B77E42A2FD18958D9E43202E8A338562AFF8317461B0, 444C1D6BDC026A01012BB2CEEAD89C2C
+ 26: 07E86D49CFFE6FB08FDF44584033AF321447003D8AD3862C00C9, DA9355A79B224EF662DA65F19BE494A7
+ 27: 911BB223AC6F6E54082FBFEDEC300D73FCAF715CCA35949212B372, 3496160A46A21DCDB5A4C179F159D860
+ 28: ABB563FC803715F59AA35460E98470E2E94E4270455ACEBF4297641B, 899CFE1946A060DE620879B8A7464718
+ 29: 47D98E83B5849CDE19B14ABCF9EA6CA9684AB49A3AB36BD14F328D808C, 6D76CD5EFF6D4AD3B67A56DF1EB42E05
+ 30: C8BF0B71A95884FFB93D64C57E327A4754EC5A1EE26632CF8E0B6B26CBDE, 2B3BE785263B1A400E5893273AFD09AE
+ 31: 9804D668CF2D75CA58C9671F65630E33909269B9511AF9119BE88EBB35F00C, 3DDA028B1A2339CA817DC8D9371E0FF8
+ 32: F6E038A82A09BCD20BAAC7926B2296B78F9CBA9DD12C497C47EA08DBCD8CEA3A, A203FC1E68E21A52E72224891AC10EE2
+
+OCB-khazad (16 byte key)
+  0: , BDEDFF7AA0070063
+  1: 00, 67E951582D66ED93
+  2: 5FED, 09DC8AEAD70673DE
+  3: 26A7CC, CE1436CE1E37D4B0
+  4: 3D2BD063, 574C24395F31511A
+  5: 597F1AFCB1, 6FBBE820C6F26CDB
+  6: 202DAE442DF6, 58CA6E5706C9852D
+  7: 7C20EDA18E9444, AABF0DA252A1BAAD
+  8: DEC02BF76DFD5B77, A0A97446B80EACB6
+  9: 5D7A42F73843F9200E, A1DD603372D124CB
+ 10: 0D4710E454C19B68369E, CC78E9D7EAA6A39F
+ 11: 126694191BF09A29DCF40E, 76C9B84FA3E8913F
+ 12: A94EBB86BD325B4FA1942FA5, 613DE312DB1666F7
+ 13: 4F9462386469EA0EFDC1BFAFE9, 5247244FD4BBAA6F
+ 14: 4EB794DFCF3823BDC38FA5EF3B23, 0C12017B5E058398
+ 15: D870479780CC5B3B13A7A39029A56F, 003D3FCD31D497B5
+ 16: A47BF1218AC86A60F6002CE004AF5E50, B4EC27091D5DCD58
+
diff --git a/notes/omac_tv.txt b/notes/omac_tv.txt
index e74f76f..56d8da6 100644
--- a/notes/omac_tv.txt
+++ b/notes/omac_tv.txt
@@ -199,6 +199,82 @@
  31: C24FCA5DD4AE0DF2BFF17364D17D6743
  32: DC6738080478AF9AF7CA833295031E06
 
+OMAC-safer-k64 (8 byte key)
+  0: 726FE2DD40A43924
+  1: 2A138B65EB352621
+  2: 9588A1B53E29616C
+  3: C025DEFDE1A59850
+  4: 73D062F1B6D8E003
+  5: 944598A2FC8A2D76
+  6: B176C25D8CAFFC98
+  7: 14F05014DE6A090A
+  8: A7B9847B2CE22D0F
+  9: FCD71310CBAA3A62
+ 10: BFF00CE5D4A20331
+ 11: BEE12A2171333ED5
+ 12: 333FD849BEB4A64A
+ 13: D048EC7E93B90435
+ 14: F04960356689CFEF
+ 15: 9E63D9744BF1B61A
+ 16: 7C744982F32F8889
+
+OMAC-safer-sk64 (8 byte key)
+  0: E96711BA37D53743
+  1: 7DCFF26A03509FE1
+  2: 0A20EF19C8EE9BF2
+  3: FE2883748A6963CF
+  4: 557060195B820A18
+  5: 771A7931FBBE5C0F
+  6: 6BDBCE5F96CF91D8
+  7: F3B924CCE8724595
+  8: EC7191286D83C2C3
+  9: 94F55B19BB7A8AC1
+ 10: 2189F4F2B06A8CA4
+ 11: 99853DAEBCA33A46
+ 12: 66EAC37A033802D7
+ 13: 845D7AA866F8A8AD
+ 14: 33A874DFECAC22AC
+ 15: 63DD9F7A7F3683DF
+ 16: EAC277D951676C44
+
+OMAC-safer-k128 (16 byte key)
+  0: 8037B89AF193F129
+  1: FF2314E87BA6AFE1
+  2: C3243DF896B61D85
+  3: 0F61C715CE821AB8
+  4: EBFDC6A9CFD2F5A4
+  5: AB6497D7AF2C7FFF
+  6: C920CEEB7C1819C2
+  7: 3E186951B545A7E5
+  8: 5EA36A93C94AF4AC
+  9: 6A2C59FAE33709BE
+ 10: BF1BAFAF9FC39C19
+ 11: 69EB6EF046677B7C
+ 12: CDDCEE6B20453094
+ 13: A3833BD3FED6895C
+ 14: B6C05E51F01E049B
+ 15: 90A2D0EAB739D39B
+ 16: 07BF607A161D0A66
+
+OMAC-safer-sk128 (16 byte key)
+  0: 5E8B137A3946A557
+  1: 0228FA66B13F3C7E
+  2: A6F9BBAFF050DCDD
+  3: F75880F684A796CE
+  4: E0AEFB8E32040EBD
+  5: 9F65D658B86D310F
+  6: 3FA52804FB46CCAA
+  7: 2F6D12D199FCD2FB
+  8: CB56AF60AFB4D2BB
+  9: 8E6F0FF6FDD262FD
+ 10: 490245BE3CCCEDE2
+ 11: EFD319AE46C73005
+ 12: 43E00E545C848995
+ 13: 10444B41ECA15EBE
+ 14: 521775C389D5BE71
+ 15: 9B683EF8B097FEBA
+ 16: 3C5D746EED09530A
+
 OMAC-rc2 (8 byte key)
   0: F001FE9BBC3A97B0
   1: 8F8DC9C952897FBD
@@ -329,3 +405,57 @@
  15: ED91F98DA98F42C4
  16: D8D0FA5CE96B08BF
 
+OMAC-anubis (16 byte key)
+  0: E672617CAA1E641C0E7B4B4CC4787455
+  1: C0C16E8FD63907C08A8ABBB7B73376D3
+  2: 23F97CED54939361830396224A7BDD91
+  3: 7FD87DEA9F05E07212DDF61292D9E13D
+  4: 929A11A4D0991A6446B1051926A6048D
+  5: 4EB74F1CC0150D86126BC6FE1FC8253D
+  6: 33C2C3C072D05BB6D54F87579C23B116
+  7: DE350181C9E90A79879813A609BE77E2
+  8: DB519EB9EF0E154D9D248734FD3D3724
+  9: 4F7F2E6D3FC72BA94FE24EC0ABBF4E66
+ 10: D646389DBCEEDD59EBB6E8F09C422930
+ 11: 8547658AE1CE6A8B8D010A1E1FEA7AF4
+ 12: C9BE2B7F3630EFDFBD3AEA6A108C86EA
+ 13: 290417C57096B8B9A1BA3C20FD91285B
+ 14: 9AF60E99692C5F911CBF969A6E11DC14
+ 15: CDA433BE58C98E49EBA8A7108E50DE2B
+ 16: 7430D0EE631A4659351B8A4489A78D46
+ 17: DCC74C0FD0415768FE00225CA14B7DC2
+ 18: 0CF2432B1B465F2A8C5FACAAF2FEF619
+ 19: DA020680C64E93AE5FCA3D71466D01C1
+ 20: B9C33A86E6ED9FCCDCD973382DD1B6A3
+ 21: 6631236B9F2F810DD4D97E6046F41AF2
+ 22: 0312C322F4D634CF4FBC0C2624E3E9F2
+ 23: 111E3E9F8FBDC1E4364622723F1CB524
+ 24: 6D2608D7AAF243D5219E14513895BFF6
+ 25: 683BD01B43CBC0430A007ACBAB357DC9
+ 26: 01B8FC65C56B0F1A5BFEBEDCCF6748D9
+ 27: 4D6298D63A80D55491697A6DD8E3694C
+ 28: 6F0205E4E083CAB00747D723300510DF
+ 29: 5183BAEEF05E9402A935EB9AFF0AA2A9
+ 30: 1E673BFAD4944643A740C59D96A5925C
+ 31: 940FB4000E34EEE78E8DB402E4A76502
+ 32: 87B0C48F3D155AD85D0502D94A4572DE
+
+OMAC-khazad (16 byte key)
+  0: 4EBEFA460499424F
+  1: 97AEEAD51E541D16
+  2: 29A35212910C9595
+  3: ABD1577D622074EA
+  4: 70A537DE14DD765C
+  5: 240A19016DE99C51
+  6: 4D42C10A9F803177
+  7: F464BC3E0DB5A909
+  8: 1C65A01A7C08DAC7
+  9: E49A1428C230C209
+ 10: 16DD0FEB7A6505B8
+ 11: 2DDDB3E35A05C220
+ 12: EC88910C799AC6CC
+ 13: B2A65C9EF39BEC8A
+ 14: F0D2366BA91DFFD5
+ 15: BCAB623CAB7AAA23
+ 16: 9BCEAB857596E478
+
diff --git a/notes/pmac_tv.txt b/notes/pmac_tv.txt
index 6a920cb..e0a1900 100644
--- a/notes/pmac_tv.txt
+++ b/notes/pmac_tv.txt
@@ -199,6 +199,82 @@
  31: 0D06F2FAEC5AA404A4087AAEBC4DBB36
  32: 0F396FE9E3D9D74D17EB7A0BF603AB51
 
+PMAC-safer-k64 (8 byte key)
+  0: 2E49792C78C1DA52
+  1: 7A5136F4FE617C57
+  2: 6FC8575F6F3D78EC
+  3: 7C0373CAEAAA640B
+  4: 9D469E7FF6C35D31
+  5: 7755D62DD7D88112
+  6: ADD9E7855A958C9F
+  7: 752D29BA8150F18E
+  8: 0954649A99596104
+  9: 05D4D75A9FAE233D
+ 10: 1AADAFD7B4B250DA
+ 11: E7A8F31ED74DA32B
+ 12: 1A74DF61BDB9DF94
+ 13: C38A67B1955C4E0D
+ 14: EBADAA44746ADF16
+ 15: C0BFBB092CE81D8E
+ 16: 984975657F3FF2B0
+
+PMAC-safer-sk64 (8 byte key)
+  0: E8917E1629E7403E
+  1: AE8061A5E412A647
+  2: C969771CE5A9B0C6
+  3: 78159C01D0A3A5CB
+  4: 1DD4382A8FC81921
+  5: 4086880FD863C048
+  6: A520B45600A3FA1D
+  7: 0F0AB5118D7506C4
+  8: 22E315F2DD03BCC6
+  9: 5ECB5561EE372016
+ 10: 446A9B2BCB367AD6
+ 11: B2107FE2EB411AE9
+ 12: 5A539B62FB5893DF
+ 13: F44EE1EB3278C2BA
+ 14: 293FEA56D1F6EA81
+ 15: F38F614D2B5F81C4
+ 16: AB23F7F8F4C12A7E
+
+PMAC-safer-k128 (16 byte key)
+  0: 7E0BDE11EC82FDE6
+  1: 8942FB017A135520
+  2: 0B073E6D0F037A02
+  3: DBF88439D671ED4F
+  4: B89427ED1121069A
+  5: AA8573DAC66D2315
+  6: 12DA3144BEF13FF2
+  7: EF80413CBA281B3A
+  8: DFA7114D8505EEBD
+  9: AE53607F3E6F4A54
+ 10: 3F2C9395CFB9F78F
+ 11: 67EB7C5F02760AED
+ 12: 3EF4CBB4AB5B8D1F
+ 13: 83B63AFA78795A92
+ 14: 5DE400951766992A
+ 15: AA8791A45237CF83
+ 16: 7743B18704B037CF
+
+PMAC-safer-sk128 (16 byte key)
+  0: 8F1597FFCF6FB7C1
+  1: AFF8BD8FF9F3888A
+  2: 65F89D82869D8B42
+  3: CBE1F06476B2D5BD
+  4: 4878D47FDFECE23E
+  5: 4751A9E6D61AB2A2
+  6: 003AC162AED4DED8
+  7: 1F617A5555092C22
+  8: 088EE0C35B607153
+  9: F840B485086F9908
+ 10: BA99E0FB5D7D0976
+ 11: F04AF6DC4BAF6887
+ 12: 5DBBE40AF2F67E4E
+ 13: 7F52A93E87E29C9D
+ 14: 7B26A14A4BD5B709
+ 15: C34F26E08C64F26B
+ 16: 291A41D479EC1D2A
+
 PMAC-rc2 (8 byte key)
   0: E5AF80FAC4580444
   1: 6A15D6211EB4FF99
@@ -329,3 +405,57 @@
  15: 2C5BD475AAC44C77
  16: FEB892DA66D31A84
 
+PMAC-anubis (16 byte key)
+  0: DF33EE541FFEE6A97FE3A1F72F7A38FC
+  1: 0AB28675AC3923C6DD9F5A8E1E2928D0
+  2: 2DABF75D6403E1E1CFAB3E6869FB1088
+  3: 95835D49E09740180B79E394FC2AA744
+  4: F364D6DC2C2078A519E5BAEFE858AFCA
+  5: DA4C66A4805FC91FABAECC0D3AEAD850
+  6: 487660FADCAC7B326C492AA051A1DF49
+  7: BF07835AA1A548FA7312509AF35CE3F3
+  8: 3CE8A8B1F324A700923AC0B830D53D99
+  9: 3C54D99AACFAB26E34FC1B0B6BB9EB22
+ 10: 0A559F9D107ED76FD19227FDD0752B8A
+ 11: BFD9E74ADC40B9C7446FDD09558FA584
+ 12: F1130F663BC0FA3B1066129E0D1910E9
+ 13: 535EAD786F0D211DE7AA78F3CB480803
+ 14: CDF5855F00A4C310D95B26751B01A28B
+ 15: EF6686E999D5A9C35A96D25BB9DBBF57
+ 16: E795733AA0AAF16D8F7AB1A8E9C55E54
+ 17: E03CA85727D5CF06F56BB6465BB3E5C5
+ 18: 6EDDDB6D2292EFF584E382E1BACD1A49
+ 19: 7B7FE0D8821836C1AA95578071FF2FD2
+ 20: 5F8CC568338400746B61A9286B7CF262
+ 21: 32DEE5A11E9EDB04BDF911837CE0FA4D
+ 22: F1A99914F13B17ABF383F36157FEB170
+ 23: 99F541647F382390043CAE5332E3114D
+ 24: 34C5EBB85693A1979F8CFDF8B431A5BB
+ 25: 1BA7266568F1E7B4A77A869D3021AC0F
+ 26: 0FC675C99C24E859F8CE714E86BF5289
+ 27: CBFAB21F5ABC47356A43BED806D873C0
+ 28: 9659AB1A4D334B622629721F98EECE3A
+ 29: 644C8BEE41F03BDE7652B03CAEA31E37
+ 30: 5B3447AFAD934B4D1E4910A8DFD588E7
+ 31: BFF403342E8D50D0447627AEA2F56B23
+ 32: 19F468F0FB05184D00FABD40A18DB7B2
+
+PMAC-khazad (16 byte key)
+  0: F40CEF2E392BEAEB
+  1: C6E086BD1CFA0992
+  2: 513F2851583AD69A
+  3: 07279D57695D78FF
+  4: 051E94FE4CC847B6
+  5: 5E9AAA5989D5C951
+  6: 310D5D740143369A
+  7: 9BB1EA8ECD4AF34B
+  8: CF886800AF0526C8
+  9: 0B03E2C94729E643
+ 10: 42815B308A900EC7
+ 11: 9A38A58C438D26DD
+ 12: 044BFF68FD2BFF76
+ 13: 7F5ABBDC29852729
+ 14: F81A7D6F7B788A5D
+ 15: 93098DA8A180AA35
+ 16: BACE2F4DA8A89E32
+
diff --git a/notes/tech0004.txt b/notes/tech0004.txt
new file mode 100644
index 0000000..2acd378
--- /dev/null
+++ b/notes/tech0004.txt
@@ -0,0 +1,91 @@
+Tech Note 0004
+Using Yarrow, Fortuna and SOBER-128
+Tom St Denis
+
+Introduction
+------------
+
+This tech note explains how to use three of the more useful pseudo random number generators and their 
+own little "issues".  While all of the PRNGs have the same API and are roughly used in the same 
+manner their effectiveness really depends on the user knowing how they work.
+
+
+Yarrow
+------
+
+Yarrow is by far the simplest of the PRNGs.  It gathers bits of entropy by hashing the pool state
+plus the additional bits storing the message digest back in the pool.  E.g.
+
+pool = hash(pool || newbits)
+
+Simply dump bits into the PRNG via yarrow_add_entropy() and call yarrow_ready() when you want to 
+put them to use.  This PRNG while simple is not entirely safe.  An attacker who learns the state
+of the pool and can control future events can control the PRNG.  This requires an active attacker but 
+isn't entire impossible.
+
+The pool is then used as a key for a cipher that is used in CTR mode.  
+
+Yarrow is mostly meant for short-term programs [e.g. like file utils].  This particular implementation
+is not meant for long-term usage.
+
+Fortuna
+-------
+
+Fortuna was designed by Niels Fergusson and Bruce Schneier [Bruce is also the guy who invented Yarrow].  It
+operates on a more defensive level than Yarrow.  Instead of 1 entropy pool it has 32 and the new entropy 
+is spread [round robin] in all of the pools. 
+
+That is, each call to fortuna_add_entropy() puts the bits in the next [in the sequenece] pool of entropy.  
+Effective bits are added to the pool by sending them through a hash [but not terminating the hash].  
+
+Here's the main catch though.  When the PRNG must be reseeded [so that you can extract bits from it] only
+certain pools are used.  More precisely the i'th pool is used every 2**i'th reseeding.  For example, pool[0]
+is always used.  pool[1] is used every second reseeding, pool[2] every fourth.
+
+The pools are hashed together along with the current key and the result is the new key for a cipher which
+operates in CTR mode [more about that in a sec].
+
+Now this may seem odd at first however there is a good reason behind it.  An attacker who learns pool[0] won't
+strictly know the other pools.  So the recovery rate of is not 0.  In fact pool[0] can be completely 
+compromised and the PRNG will still eventually recover.  The value FORTUNA_WD is the "WatchDog" counter.
+Every FORTUNA_WD calls to fortuna_read will invoke the reseed operation.  By default this is set to 10 which 
+means after 10 calls the PRNG will reseed itself.  
+
+The pools are combined with the running cipher key [256 bits] so that a cipher in CTR mode can produce 
+the stream.  Unlike Yarrow the cipher is re-keyed after every call to fortuna_read() [so one big call 
+would be faster than many smaller calls].  This prevents too much data being encrypted under the same
+key [and mitigates a flaw in CTR mode that the same block can't be emitted twice under the same key].
+
+Fortuna is really meant for a kernel-level PRNG.  The more sources [and often] you feed into it the 
+healthier it will be.  It's also meant to be used for long term purposes.  Since it can recover from
+compromises it is harder to control it.  
+
+SOBER-128
+------
+
+SOBER-128 is actually a stream cipher but like most ciphers can easily be modelled in the context of a PRNG.
+This PRNG is extremely fast [4 cycles/byte on a P4] and was designed by a well known cryptographer [Greg Rose].
+
+SOBER-128 doesn't really "act" like the other two PRNGs.  It's meant to be seeded once and then read as 
+required.  In such a sense it isn't a "system PRNG" but useful short term purposes.  In particular
+the sober128_read() function actually XORs against the input buffer you specify.  This allows the 
+read() function to be used as an "encrypt" function as well.  
+
+You can only key SOBER-128 once [by calling sober128_add_entropy()].  Once it it is keyed subsequent
+calls to add_entropy() will be considered a "re-IV" operation.  Changing the IV allows you to use same
+initial key and not produce the same output stream.  It also lets you differentiate packets.  E.g. each
+packet has it's own IV.
+
+All inputs to sober128_add_entropy() must have a length that is a multiple of four.
+
+Overall
+-------
+
+Since SOBER-128 is *much* faster than the other two PRNGs a good setup would be to use Fortuna as your 
+system-wide PRNG and use SOBER-128 [key'ed from Fortuna] for encrypting streams or as a PRNG for 
+simulations.
+
+Yarrow is still a good candidate but only for "short lived" programs.  However, since Fortuna is faster
+[by about 10 cycles/byte on a P4] I'd use Fortuna anyways...
+
+Tom
\ No newline at end of file
diff --git a/notes/tech0005.txt b/notes/tech0005.txt
new file mode 100644
index 0000000..8f393d5
--- /dev/null
+++ b/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?
diff --git a/notes/tech0006.txt b/notes/tech0006.txt
new file mode 100644
index 0000000..ecbe8b0
--- /dev/null
+++ b/notes/tech0006.txt
@@ -0,0 +1,91 @@
+Tech Note 0006
+PK Standards Compliance
+Tom St Denis
+
+RSA
+----
+
+PKCS #1 compliance.
+
+Key Format:  RSAPublicKey and RSAPrivateKey as per PKCS #1 v2.1
+Encryption:  OAEP as per PKCS #1
+Signature :  PSS  as per PKCS #1
+
+DSA
+----
+
+The NIST DSA algorithm
+
+Key Format:  HomeBrew [see below]
+Signature :  ANSI X9.62 format [see below].
+
+Keys are stored as 
+
+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
+}
+
+Signatures are stored as 
+
+DSASignature ::= SEQUENCE {
+    r, s           INTEGER        -- signature parameters
+}
+
+ECC
+----
+
+The ANSI X9.62 and X9.63 algorithms [partial].  Supports all NIST GF(p) curves.
+
+Key Format   :  Homebrew [see below, only GF(p) NIST curves supported]
+Signature    :  X9.62 compliant
+Encryption   :  Homebrew [based on X9.63, differs in that the public point is stored as an ECCPublicKey]
+Shared Secret:  X9.63 compliant
+
+ECCPublicKey ::= SEQUENCE {
+    flags       BIT STRING(1), -- public/private flag (always zero), 
+    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
+    pubkey.y    INTEGER,       -- The Y co-ordinate of the public key point
+}
+
+ECCPrivateKey ::= SEQUENCE {
+    flags       BIT STRING(1), -- public/private flag (always one), 
+    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
+    pubkey.y    INTEGER,       -- The Y co-ordinate of the public key point
+    secret.k    INTEGER,       -- The secret key scalar
+}
+
+The encryption works by finding the X9.63 shared secret and hashing it.  The hash is then simply XOR'ed against the message [which must be at most the size
+of the hash digest].  The format of the encrypted text is as follows
+
+ECCEncrypted ::= SEQUENCE {
+    hashOID     OBJECT IDENTIFIER,   -- The OID of the hash used
+    pubkey      OCTET STRING     ,   -- Encapsulation of a random ECCPublicKey
+    skey        OCTET STRING         -- The encrypted text (which the hash was XOR'ed against)
+}
+
+% $Source: /cvs/libtom/libtomcrypt/notes/tech0006.txt,v $   
+% $Revision: 1.2 $   
+% $Date: 2005/06/18 02:26:27 $ 
diff --git a/ocb_decrypt_verify_memory.c b/ocb_decrypt_verify_memory.c
deleted file mode 100644
index f0e29fa..0000000
--- a/ocb_decrypt_verify_memory.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-int ocb_decrypt_verify_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  
-    const unsigned char *ct,     unsigned long ctlen,
-          unsigned char *pt,
-    const unsigned char *tag,    unsigned long taglen,
-          int           *res)
-{
-   int err;
-   ocb_state ocb;
-
-
-   _ARGCHK(key    != NULL);
-   _ARGCHK(nonce  != NULL);
-   _ARGCHK(pt     != NULL);
-   _ARGCHK(ct     != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(res    != NULL);
-
-   if ((err = ocb_init(&ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
-      return err;
-   }
-
-   while (ctlen > (unsigned long)ocb.block_len) {
-        if ((err = ocb_decrypt(&ocb, ct, pt)) != CRYPT_OK) {
-           return err;
-        }
-        ctlen   -= ocb.block_len;
-        pt      += ocb.block_len;
-        ct      += ocb.block_len;
-   }
-
-   return ocb_done_decrypt(&ocb, ct, ctlen, pt, tag, taglen, res);
-}
-
-#endif
diff --git a/ocb_done_decrypt.c b/ocb_done_decrypt.c
deleted file mode 100644
index 97ba393..0000000
--- a/ocb_done_decrypt.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-int ocb_done_decrypt(ocb_state *ocb, 
-                     const unsigned char *ct,  unsigned long ctlen,
-                           unsigned char *pt, 
-                     const unsigned char *tag, unsigned long taglen, int *res)
-{
-   int err;
-   unsigned char tagbuf[MAXBLOCKSIZE];
-   unsigned long tagbuflen;
-
-   _ARGCHK(ocb != NULL);
-   _ARGCHK(pt  != NULL);
-   _ARGCHK(ct  != NULL);
-   _ARGCHK(tag != NULL);
-   _ARGCHK(res != NULL);
-
-   *res = 0;
-
-   tagbuflen = sizeof(tagbuf);
-   if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
-      return err;
-   }
-
-   if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) {
-      *res = 1;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(tagbuf, sizeof(tagbuf));
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/ocb_done_encrypt.c b/ocb_done_encrypt.c
deleted file mode 100644
index 209892e..0000000
--- a/ocb_done_encrypt.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-int ocb_done_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
-                     unsigned char *ct, unsigned char *tag, unsigned long *taglen)
-{
-   _ARGCHK(ocb    != NULL);
-   _ARGCHK(pt     != NULL);
-   _ARGCHK(ct     != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(taglen != NULL);
-   return __ocb_done(ocb, pt, ptlen, ct, tag, taglen, 0);
-}
-
-#endif
-
diff --git a/ocb_encrypt_authenticate_memory.c b/ocb_encrypt_authenticate_memory.c
deleted file mode 100644
index 839da02..0000000
--- a/ocb_encrypt_authenticate_memory.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-int ocb_encrypt_authenticate_memory(int cipher,
-    const unsigned char *key,    unsigned long keylen,
-    const unsigned char *nonce,  
-    const unsigned char *pt,     unsigned long ptlen,
-          unsigned char *ct,
-          unsigned char *tag,    unsigned long *taglen)
-{
-   int err;
-   ocb_state ocb;
-
-   _ARGCHK(key    != NULL);
-   _ARGCHK(nonce  != NULL);
-   _ARGCHK(pt     != NULL);
-   _ARGCHK(ct     != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(taglen != NULL);
-
-   if ((err = ocb_init(&ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
-      return err;
-   }
-
-   while (ptlen > (unsigned long)ocb.block_len) {
-        if ((err = ocb_encrypt(&ocb, pt, ct)) != CRYPT_OK) {
-           return err;
-        }
-        ptlen   -= ocb.block_len;
-        pt      += ocb.block_len;
-        ct      += ocb.block_len;
-   }
-
-   return ocb_done_encrypt(&ocb, pt, ptlen, ct, tag, taglen);
-}
-
-#endif
diff --git a/ocb_ntz.c b/ocb_ntz.c
deleted file mode 100644
index fbf6bb6..0000000
--- a/ocb_ntz.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-int ocb_ntz(unsigned long x)
-{
-   int c;
-   x &= 0xFFFFFFFFUL;
-   c = 0;
-   while ((x & 1) == 0) {
-      ++c;
-      x >>= 1;
-   }
-   return c;
-}
-
-#endif
diff --git a/ocb_shift_xor.c b/ocb_shift_xor.c
deleted file mode 100644
index ce93138..0000000
--- a/ocb_shift_xor.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-void ocb_shift_xor(ocb_state *ocb, unsigned char *Z)
-{
-   int x, y;
-   y = ocb_ntz(ocb->block_index++);
-   for (x = 0; x < ocb->block_len; x++) {
-       ocb->Li[x] ^= ocb->Ls[y][x];
-       Z[x]        = ocb->Li[x] ^ ocb->R[x];
-   }
-}
-
-#endif
diff --git a/ofb_decrypt.c b/ofb_decrypt.c
deleted file mode 100644
index 9531969..0000000
--- a/ofb_decrypt.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef OFB
-
-int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb)
-{
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(ofb != NULL);
-   return ofb_encrypt(ct, pt, len, ofb);
-}
-
-
-#endif
-
- 
diff --git a/ofb_getiv.c b/ofb_getiv.c
deleted file mode 100644
index 864de02..0000000
--- a/ofb_getiv.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef OFB
-
-int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb)
-{
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(len != NULL);
-   _ARGCHK(ofb != NULL);
-   if ((unsigned long)ofb->blocklen > *len) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   memcpy(IV, ofb->IV, ofb->blocklen);
-   *len = ofb->blocklen;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/ofb_setiv.c b/ofb_setiv.c
deleted file mode 100644
index 6683bc7..0000000
--- a/ofb_setiv.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef OFB
-
-int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb)
-{
-   int err;
-
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(ofb != NULL);
-
-   if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
-       return err;
-   }
-
-   if (len != (unsigned long)ofb->blocklen) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* force next block */
-   ofb->padlen = 0;
-   cipher_descriptor[ofb->cipher].ecb_encrypt(IV, ofb->IV, &ofb->key);
-   return CRYPT_OK;
-}
-
-#endif 
-
diff --git a/ofb_start.c b/ofb_start.c
deleted file mode 100644
index 45fcc70..0000000
--- a/ofb_start.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef OFB
-
-int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-              int keylen, int num_rounds, symmetric_OFB *ofb)
-{
-   int x, err;
-
-   _ARGCHK(IV != NULL);
-   _ARGCHK(key != NULL);
-   _ARGCHK(ofb != NULL);
-
-   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* copy details */
-   ofb->cipher = cipher;
-   ofb->blocklen = cipher_descriptor[cipher].block_length;
-   for (x = 0; x < ofb->blocklen; x++) {
-       ofb->IV[x] = IV[x];
-   }
-
-   /* init the cipher */
-   ofb->padlen = ofb->blocklen;
-   return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ofb->key);
-}
-
-#endif
diff --git a/omac_done.c b/omac_done.c
deleted file mode 100644
index f065a1d..0000000
--- a/omac_done.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
-#include "mycrypt.h"
-
-#ifdef OMAC
-
-int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen)
-{
-   int err, mode, x;
-
-   _ARGCHK(state != NULL);
-   _ARGCHK(out   != NULL);
-   if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
-       (state->blklen > (int)sizeof(state->block)) || (state->buflen > state->blklen)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* figure out mode */
-   if (state->buflen != state->blklen) {
-      /* add the 0x80 byte */
-      state->block[state->buflen++] = 0x80;
-
-      /* pad with 0x00 */
-      while (state->buflen < state->blklen) {
-         state->block[state->buflen++] = 0x00;
-      }
-      mode = 1;
-   } else {
-      mode = 0;
-   }
-
-   /* now xor prev + Lu[mode] */
-   for (x = 0; x < state->blklen; x++) {
-       state->block[x] ^= state->prev[x] ^ state->Lu[mode][x];
-   }
-
-   /* encrypt it */
-   cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->block, &state->key);
- 
-   /* output it */
-   for (x = 0; x < state->blklen && (unsigned long)x < *outlen; x++) {
-       out[x] = state->block[x];
-   }
-   *outlen = x;
-
-#ifdef CLEAN_STACK
-   zeromem(state, sizeof(*state));
-#endif
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/omac_file.c b/omac_file.c
deleted file mode 100644
index 09d2d4b..0000000
--- a/omac_file.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
-#include "mycrypt.h"
-
-#ifdef OMAC
-
-int omac_file(int cipher, 
-              const unsigned char *key, unsigned long keylen,
-              const char *filename, 
-                    unsigned char *out, unsigned long *outlen)
-{
-#ifdef NO_FILE
-   return CRYPT_NOP;
-#else
-   int err, x;
-   omac_state omac;
-   FILE *in;
-   unsigned char buf[512];
-
-   _ARGCHK(key      != NULL);
-   _ARGCHK(filename != NULL);
-   _ARGCHK(out      != NULL);
-   _ARGCHK(outlen   != NULL);
-
-   in = fopen(filename, "rb");
-   if (in == NULL) {
-      return CRYPT_FILE_NOTFOUND;
-   }
-
-   if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
-      fclose(in);
-      return err;
-   }
-
-   do {
-      x = fread(buf, 1, sizeof(buf), in);
-      if ((err = omac_process(&omac, buf, x)) != CRYPT_OK) {
-         fclose(in);
-         return err;
-      }
-   } while (x == sizeof(buf));
-   fclose(in);
-
-   if ((err = omac_done(&omac, out, outlen)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-
-   return CRYPT_OK;
-#endif
-}
-
-#endif
diff --git a/omac_memory.c b/omac_memory.c
deleted file mode 100644
index 1cca891..0000000
--- a/omac_memory.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
-#include "mycrypt.h"
-
-#ifdef OMAC
-
-int omac_memory(int cipher, 
-                const unsigned char *key, unsigned long keylen,
-                const unsigned char *msg, unsigned long msglen,
-                      unsigned char *out, unsigned long *outlen)
-{
-   int err;
-   omac_state omac;
-
-   _ARGCHK(key != NULL);
-   _ARGCHK(msg != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(outlen != NULL);
-
-   if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = omac_process(&omac, msg, msglen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = omac_done(&omac, out, outlen)) != CRYPT_OK) {
-      return err;
-   }
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/omac_process.c b/omac_process.c
deleted file mode 100644
index 8da1527..0000000
--- a/omac_process.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
-#include "mycrypt.h"
-
-#ifdef OMAC
-
-int omac_process(omac_state *state, const unsigned char *buf, unsigned long len)
-{
-   int err, n, x;
-
-   _ARGCHK(state != NULL);
-   _ARGCHK(buf   != NULL);
-   if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
-       (state->blklen > (int)sizeof(state->block)) || (state->buflen > state->blklen)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   while (len != 0) { 
-       /* ok if the block is full we xor in prev, encrypt and replace prev */
-       if (state->buflen == state->blklen) {
-          for (x = 0; x < state->blklen; x++) {
-              state->block[x] ^= state->prev[x];
-          }
-          cipher_descriptor[state->cipher_idx].ecb_encrypt(state->block, state->prev, &state->key);
-          state->buflen = 0;
-       }
-
-       /* add bytes */
-       n = MIN(len, (unsigned long)(state->blklen - state->buflen));
-       memcpy(state->block + state->buflen, buf, n);
-       state->buflen += n;
-       len           -= n;
-       buf           += n;
-   }
-
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/parsenames.pl b/parsenames.pl
new file mode 100644
index 0000000..761f036
--- /dev/null
+++ b/parsenames.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+#
+# Splits the list of files and outputs for makefile type files 
+# wrapped at 80 chars 
+# 
+# Tom St Denis
+@a = split(" ", $ARGV[1]);
+$b = "$ARGV[0]=";
+$len = length($b);
+print $b;
+foreach my $obj (@a) {
+   $len = $len + length($obj);
+   $obj =~ s/\*/\$/;
+   if ($len > 100) {
+      printf "\\\n";
+      $len = length($obj);
+   }
+   print "$obj ";
+}
+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 $ 
diff --git a/pkcs_1_mgf1.c b/pkcs_1_mgf1.c
deleted file mode 100644
index b21d928..0000000
--- a/pkcs_1_mgf1.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* The Mask Generation Function (MGF1) for PKCS #1 -- Tom St Denis */
-
-#ifdef PKCS_1
-
-int pkcs_1_mgf1(const unsigned char *seed, unsigned long seedlen,
-                      int            hash_idx,
-                      unsigned char *mask, unsigned long masklen)
-{
-   unsigned long hLen, counter, x;
-   int           err;
-   hash_state    md;
-   unsigned char buf[MAXBLOCKSIZE];
- 
-   _ARGCHK(seed != NULL);
-   _ARGCHK(mask != NULL);
-
-   /* ensure valid hash */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
-      return err;
-   }
-
-   /* get hash output size */
-   hLen = hash_descriptor[hash_idx].hashsize;
-
-   /* start counter */
-   counter = 0;
-
-   while (masklen > 0) {
-       /* handle counter */
-       STORE32H(counter, buf);
-       ++counter;
-
-       /* get hash of seed || counter */
-       hash_descriptor[hash_idx].init(&md);
-       if ((err = hash_descriptor[hash_idx].process(&md, seed, seedlen)) != CRYPT_OK) {
-          return err;
-       }
-       if ((err = hash_descriptor[hash_idx].process(&md, buf, 4)) != CRYPT_OK) {
-          return err;
-       }
-       if ((err = hash_descriptor[hash_idx].done(&md, buf)) != CRYPT_OK) {
-          return err;
-       }
-
-       /* store it */
-       for (x = 0; x < hLen && masklen > 0; x++, masklen--) {
-          *mask++ = buf[x];
-       }
-   }
-
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
diff --git a/pkcs_1_oaep_decode.c b/pkcs_1_oaep_decode.c
deleted file mode 100644
index 55f2e1d..0000000
--- a/pkcs_1_oaep_decode.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* OAEP Padding for PKCS #1 -- Tom St Denis */
-
-#ifdef PKCS_1
-
-int pkcs_1_oaep_decode(const unsigned char *msg,    unsigned long msglen,
-                       const unsigned char *lparam, unsigned long lparamlen,
-                             unsigned long modulus_bitlen, int hash_idx,
-                             unsigned char *out,    unsigned long *outlen,
-                             int           *res)
-{
-   unsigned char DB[1024], seed[MAXBLOCKSIZE], mask[sizeof(DB)];
-   unsigned long hLen, x, y, modulus_len;
-   int           err;
-
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(res    != NULL);
-
-   /* default to invalid packet */
-   *res = 0;
-   
-   /* test valid hash */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
-      return err;
-   }
-   hLen        = hash_descriptor[hash_idx].hashsize;
-   modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
-
-   /* test message size */
-   if (modulus_len >= sizeof(DB) || msglen != modulus_len) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-
-   /* ok so it's now in the form
-  
-      0x00  || maskedseed || maskedDB 
-  
-       1    ||   hLen     ||  modulus_len - hLen - 1
-   
-    */
-
-   /* must have leading 0x00 byte */
-   if (msg[0] != 0x00) {
-      return CRYPT_OK;
-   }
-
-   /* now read the masked seed */
-   for (x = 1, y = 0; y < hLen; y++) {
-      seed[y] = msg[x++];
-   }
-
-   /* now read the masked DB */
-   for (y = 0; y < modulus_len - hLen - 1; y++) {
-      DB[y] = msg[x++];
-   }
-
-   /* compute MGF1 of maskedDB (hLen) */ 
-   if ((err = pkcs_1_mgf1(DB, modulus_len - hLen - 1, hash_idx, mask, hLen)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* XOR against seed */
-   for (y = 0; y < hLen; y++) {
-      seed[y] ^= mask[y];
-   }
-
-   /* compute MGF1 of seed (k - hlen - 1) */
-   if ((err = pkcs_1_mgf1(seed, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* xor against DB */
-   for (y = 0; y < (modulus_len - hLen - 1); y++) {
-       DB[y] ^= mask[y]; 
-   }
-
-   /* now DB == lhash || PS || 0x01 || M, PS == k - mlen - 2hlen - 2 zeroes */
-
-   /* compute lhash and store it in seed [reuse temps!] */
-   x = sizeof(seed);
-   if (lparam != NULL) {
-      if ((err = hash_memory(hash_idx, lparam, lparamlen, seed, &x)) != CRYPT_OK) {
-         return err;
-      }
-   } else {
-      /* can't pass hash_memory a NULL so use DB with zero length */
-      if ((err = hash_memory(hash_idx, DB, 0, seed, &x)) != CRYPT_OK) {
-         return err;
-      }
-   }
-
-   /* compare the lhash'es */
-   if (memcmp(seed, DB, hLen) != 0) {
-      return CRYPT_OK;
-   }
-
-   /* now zeroes before a 0x01 */
-   for (x = hLen; x < (modulus_len - hLen - 1) && DB[x] == 0x00; x++) {
-      /* step... */
-   }
-
-   /* error out if wasn't 0x01 */
-   if (x == (modulus_len - hLen - 1) || DB[x] != 0x01) {
-      return CRYPT_OK;
-   }
-
-   /* rest is the message (and skip 0x01) */
-   if (msglen - ++x > *outlen) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* copy message */
-   *outlen = (modulus_len - hLen - 1) - x;
-   for (y = 0; x != (modulus_len - hLen - 1); ) {
-       out[y++] = DB[x++];
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(DB,   sizeof(DB));
-   zeromem(seed, sizeof(seed));
-   zeromem(mask, sizeof(mask));
-#endif
-
-   /* valid packet */
-   *res = 1;
-
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
diff --git a/pkcs_1_oaep_encode.c b/pkcs_1_oaep_encode.c
deleted file mode 100644
index 0cc76f4..0000000
--- a/pkcs_1_oaep_encode.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* OAEP Padding for PKCS #1 -- Tom St Denis */
-
-#ifdef PKCS_1
-
-int pkcs_1_oaep_encode(const unsigned char *msg,    unsigned long msglen,
-                       const unsigned char *lparam, unsigned long lparamlen,
-                             unsigned long modulus_bitlen, prng_state *prng,
-                             int           prng_idx,         int  hash_idx,
-                             unsigned char *out,    unsigned long *outlen)
-{
-   unsigned char DB[1024], seed[MAXBLOCKSIZE], mask[sizeof(DB)];
-   unsigned long hLen, x, y, modulus_len;
-   int           err;
-
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* test valid hash */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
-      return err;
-   }
-
-   /* valid prng */
-   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   hLen        = hash_descriptor[hash_idx].hashsize;
-   modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
-
-   /* test message size */
-   if (modulus_len >= sizeof(DB) || msglen > (modulus_len - 2*hLen - 2)) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-
-   /* get lhash */
-// DB == lhash || PS || 0x01 || M, PS == k - mlen - 2hlen - 2 zeroes
-   x = sizeof(DB);
-   if (lparam != NULL) {
-      if ((err = hash_memory(hash_idx, lparam, lparamlen, DB, &x)) != CRYPT_OK) {
-         return err;
-      }
-   } else {
-      /* can't pass hash_memory a NULL so use DB with zero length */
-      if ((err = hash_memory(hash_idx, DB, 0, DB, &x)) != CRYPT_OK) {
-         return err;
-      }
-   }
-
-   /* append PS then 0x01 (to lhash)  */
-   x = hLen;
-   y = modulus_len - msglen - 2*hLen - 2;
-   while (y--) {
-      DB[x++] = 0x00;
-   }
-   DB[x++] = 0x01;
-
-   /* message */
-   y = msglen;
-   while (y--) {
-     DB[x++] = *msg++;
-   }
-
-   /* now choose a random seed */
-   if (prng_descriptor[prng_idx].read(seed, hLen, prng) != hLen) {
-      return CRYPT_ERROR_READPRNG;
-   }
-
-   /* compute MGF1 of seed (k - hlen - 1) */
-   if ((err = pkcs_1_mgf1(seed, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* xor against DB */
-   for (y = 0; y < (modulus_len - hLen - 1); y++) {
-       DB[y] ^= mask[y]; 
-   }
-
-   /* compute MGF1 of maskedDB (hLen) */ 
-   if ((err = pkcs_1_mgf1(DB, modulus_len - hLen - 1, hash_idx, mask, hLen)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* XOR against seed */
-   for (y = 0; y < hLen; y++) {
-      seed[y] ^= mask[y];
-   }
-
-   /* create string of length modulus_len */
-   if (*outlen < modulus_len) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* start output which is 0x00 || maskedSeed || maskedDB */
-   x = 0;
-   out[x++] = 0x00;
-   for (y = 0; y < hLen; y++) {
-      out[x++] = seed[y];
-   }
-   for (y = 0; y < modulus_len - hLen - 1; y++) {
-      out[x++] = DB[y];
-   }
-   *outlen = x;
-
-#ifdef CLEAN_STACK
-   zeromem(DB,   sizeof(DB));
-   zeromem(seed, sizeof(seed));
-   zeromem(mask, sizeof(mask));
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
-
diff --git a/pkcs_1_os2ip.c b/pkcs_1_os2ip.c
deleted file mode 100644
index cff881e..0000000
--- a/pkcs_1_os2ip.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/*  Octet to Integer OS2IP -- Tom St Denis */
-#ifdef PKCS_1
-
-int pkcs_1_os2ip(mp_int *n, unsigned char *in, unsigned long inlen)
-{
-   int err;
-   /* read it */
-   if ((err = mp_read_unsigned_bin(n, in, inlen)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
-
diff --git a/pkcs_1_pss_decode.c b/pkcs_1_pss_decode.c
deleted file mode 100644
index a6de65f..0000000
--- a/pkcs_1_pss_decode.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* PKCS #1 PSS Signature Padding -- Tom St Denis */
-
-#ifdef PKCS_1
-
-int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
-                      const unsigned char *sig,     unsigned long siglen,
-                            unsigned long saltlen,  int           hash_idx,
-                            unsigned long modulus_bitlen, int    *res)
-{
-   unsigned char DB[1024], mask[sizeof(DB)], salt[sizeof(DB)], hash[sizeof(DB)];
-   unsigned long x, y, hLen, modulus_len;
-   int           err;
-   hash_state    md;
-
-   _ARGCHK(msghash != NULL);
-   _ARGCHK(res     != NULL);
-
-   /* default to invalid */
-   *res = 0;
-
-   /* ensure hash is valid */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   hLen        = hash_descriptor[hash_idx].hashsize;
-   modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
-
-   /* check sizes */
-   if ((saltlen > sizeof(salt)) || (modulus_len > sizeof(DB)) || 
-       (modulus_len < hLen + saltlen + 2) || (siglen != modulus_len)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* ensure the 0xBC byte */
-   if (sig[siglen-1] != 0xBC) {
-      return CRYPT_OK;
-   }
-
-   /* copy out the DB */
-   for (x = 0; x < modulus_len - hLen - 1; x++) {
-      DB[x] = sig[x];
-   }
-
-   /* copy out the hash */
-   for (y = 0; y < hLen; y++) {
-      hash[y] = sig[x++];
-   }
-
-   /* check the MSB */
-   if ((sig[0] & ~(0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)))) != 0) {
-      return CRYPT_OK;
-   }
-
-   /* generate mask of length modulus_len - hLen - 1 from hash */
-   if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* xor against DB */
-   for (y = 0; y < (modulus_len - hLen - 1); y++) {
-      DB[y] ^= mask[y];
-   }
-   
-   /* now clear the first byte [make sure smaller than modulus] */
-   DB[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1));
-
-   /* DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */
-
-   /* check for zeroes and 0x01 */
-   for (x = 0; x < modulus_len - saltlen - hLen - 2; x++) {
-       if (DB[x] != 0x00) {
-          return CRYPT_OK;
-       }
-   }
-
-   if (DB[x++] != 0x01) {
-      return CRYPT_OK;
-   }
-
-   /* M = (eight) 0x00 || msghash || salt, mask = H(M) */
-   hash_descriptor[hash_idx].init(&md);
-   zeromem(mask, 8);
-   if ((err = hash_descriptor[hash_idx].process(&md, mask, 8)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = hash_descriptor[hash_idx].process(&md, DB+x, saltlen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = hash_descriptor[hash_idx].done(&md, mask)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* mask == hash means valid signature */
-   if (memcmp(mask, hash, hLen) == 0) {
-      *res = 1;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(DB,   sizeof(DB));   
-   zeromem(mask, sizeof(mask));   
-   zeromem(salt, sizeof(salt));   
-   zeromem(hash, sizeof(hash));   
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
diff --git a/pkcs_1_pss_encode.c b/pkcs_1_pss_encode.c
deleted file mode 100644
index d902892..0000000
--- a/pkcs_1_pss_encode.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* PKCS #1 PSS Signature Padding -- Tom St Denis */
-
-#ifdef PKCS_1
-
-int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
-                            unsigned long saltlen,  prng_state   *prng,     
-                            int           prng_idx, int           hash_idx,
-                            unsigned long modulus_bitlen,
-                            unsigned char *out,     unsigned long *outlen)
-{
-   unsigned char DB[1024], mask[sizeof(DB)], salt[sizeof(DB)], hash[sizeof(DB)];
-   unsigned long x, y, hLen, modulus_len;
-   int           err;
-   hash_state    md;
-
-   _ARGCHK(msghash != NULL);
-   _ARGCHK(out     != NULL);
-   _ARGCHK(outlen  != NULL);
-
-   /* ensure hash and PRNG are valid */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   hLen        = hash_descriptor[hash_idx].hashsize;
-   modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
-
-   /* check sizes */
-   if ((saltlen > sizeof(salt)) || (modulus_len > sizeof(DB)) || (modulus_len < hLen + saltlen + 2)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* generate random salt */
-   if (saltlen > 0) {
-      if (prng_descriptor[prng_idx].read(salt, saltlen, prng) != saltlen) {
-         return CRYPT_ERROR_READPRNG;
-      }
-   }
-
-   /* M = (eight) 0x00 || msghash || salt, hash = H(M) */
-   hash_descriptor[hash_idx].init(&md);
-   zeromem(DB, 8);
-   if ((err = hash_descriptor[hash_idx].process(&md, DB, 8)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = hash_descriptor[hash_idx].process(&md, salt, saltlen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */
-   for (x = 0; x < (modulus_len - saltlen - hLen - 2); x++) {
-       DB[x] = 0x00;
-   }
-   DB[x++] = 0x01;
-   for (y = 0; y < saltlen; y++) {
-      DB[x++] = salt[y];
-   }
-
-   /* generate mask of length modulus_len - hLen - 1 from hash */
-   if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* xor against DB */
-   for (y = 0; y < (modulus_len - hLen - 1); y++) {
-      DB[y] ^= mask[y];
-   }
-
-   /* output is DB || hash || 0xBC */
-   if (*outlen < modulus_len) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* DB */
-   for (y = x = 0; x < modulus_len - hLen - 1; x++) {
-       out[y++] = DB[x];
-   }
-   /* hash */
-   for (x = 0; x < hLen; x++) {
-       out[y++] = hash[x];
-   }
-   /* 0xBC */
-   out[y] = 0xBC;
-
-   /* now clear the 8*modulus_len - modulus_bitlen most significant bits */
-   out[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1));
-
-   /* store output size */
-   *outlen = modulus_len;
-
-#ifdef CLEAN_STACK
-   zeromem(DB,   sizeof(DB));   
-   zeromem(mask, sizeof(mask));   
-   zeromem(salt, sizeof(salt));   
-   zeromem(hash, sizeof(hash));   
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
diff --git a/pkcs_1_v15_es_decode.c b/pkcs_1_v15_es_decode.c
deleted file mode 100644
index 98ae554..0000000
--- a/pkcs_1_v15_es_decode.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* PKCS #1 v1.5 Encryption Padding -- Tom St Denis */
-
-#ifdef PKCS_1
-
-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)
-{
-   unsigned long x, modulus_bytelen;
-
-   _ARGCHK(msg != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(res != NULL);
-   
-   /* default to failed */
-   *res = 0;
-
-   /* must be at least 12 bytes long */
-   if (msglen < 12) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   modulus_bytelen = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
-
-   /* should start with 0x00 0x02 */
-   if (msg[0] != 0x00 || msg[1] != 0x02) {
-      return CRYPT_OK;
-   }
-   
-   /* skip over PS */
-   x = 2 + (modulus_bytelen - outlen - 3);
-
-   /* should be 0x00 */
-   if (msg[x++] != 0x00) {
-      return CRYPT_OK;
-   }
-
-   /* the message is left */
-   if (x + outlen > modulus_bytelen) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-   memcpy(out, msg + x, outlen);
-   *res = 1;
-   return CRYPT_OK;
-}
-
-#endif 
-
diff --git a/pkcs_1_v15_es_encode.c b/pkcs_1_v15_es_encode.c
deleted file mode 100644
index 1fd0aaa..0000000
--- a/pkcs_1_v15_es_encode.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* v1.5 Encryption Padding for PKCS #1 -- Tom St Denis */
-
-#ifdef PKCS_1
-
-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)
-{ 
-   unsigned long modulus_bytelen, x, y;
-
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* get modulus len */
-   modulus_bytelen = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
-   if (modulus_bytelen < 12) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* verify length */
-   if (msglen > (modulus_bytelen - 11) || *outlen < modulus_bytelen) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-
-   /* 0x00 0x02 PS 0x00 M */
-   x = 0;
-   out[x++] = 0x00;
-   out[x++] = 0x02;
-   y = modulus_bytelen - msglen - 3;
-   if (prng_descriptor[prng_idx].read(out+x, y, prng) != y) {
-      return CRYPT_ERROR_READPRNG;
-   }
-   x += y;
-   out[x++] = 0x00;
-   memcpy(out+x, msg, msglen);
-   *outlen = modulus_bytelen;
-
-   return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
diff --git a/pkcs_1_v15_sa_decode.c b/pkcs_1_v15_sa_decode.c
deleted file mode 100644
index 1b5307c..0000000
--- a/pkcs_1_v15_sa_decode.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* PKCS #1 v1.5 Signature Padding -- Tom St Denis */
-
-#ifdef PKCS_1
-
-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)
-{
-   unsigned long x, y, modulus_bytelen, derlen;
-   int err;
-   
-   _ARGCHK(msghash != NULL);
-   _ARGCHK(sig     != NULL);
-   _ARGCHK(res     != NULL);
-
-   /* default to invalid */
-   *res = 0;
-
-   /* valid hash ? */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* get derlen */
-   derlen = hash_descriptor[hash_idx].DERlen;
-
-   /* get modulus len */
-   modulus_bytelen = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
-
-   /* valid sizes? */
-   if ((msghashlen + 3 + derlen > modulus_bytelen) || (siglen != modulus_bytelen)) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-
-   /* packet is 0x00 0x01 PS 0x00 T, where PS == 0xFF repeated modulus_bytelen - 3 - derlen - msghashlen times, T == DER || hash */
-   x = 0;
-   if (sig[x++] != 0x00 || sig[x++] != 0x01) {
-      return CRYPT_OK;
-   }
-
-   /* now follows (modulus_bytelen - 3 - derlen - msghashlen) 0xFF bytes */
-   for (y = 0; y < (modulus_bytelen - 3 - derlen - msghashlen); y++) {
-     if (sig[x++] != 0xFF) {
-        return CRYPT_OK;
-     }
-   }
-
-   if (sig[x++] != 0x00) {
-      return CRYPT_OK;
-   }
-
-   for (y = 0; y < derlen; y++) {
-      if (sig[x++] != hash_descriptor[hash_idx].DER[y]) {
-         return CRYPT_OK;
-      }
-   }
-
-   if (memcmp(msghash, sig+x, msghashlen) == 0) {
-      *res = 1;
-   }
-   return CRYPT_OK;
-}
-
-#endif 
diff --git a/pkcs_1_v15_sa_encode.c b/pkcs_1_v15_sa_encode.c
deleted file mode 100644
index f0f258a..0000000
--- a/pkcs_1_v15_sa_encode.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-/* PKCS #1 v1.5 Signature Padding -- Tom St Denis */
-
-#ifdef PKCS_1
-
-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)
-{
-  unsigned long derlen, modulus_bytelen, x, y;
-  int err;
-
-  _ARGCHK(msghash != NULL)
-  _ARGCHK(out     != NULL);
-  _ARGCHK(outlen  != NULL);
-
-  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-     return err;
-  }
-
-  /* hack, to detect any hash without a DER OID */
-  if (hash_descriptor[hash_idx].DERlen == 0) {
-     return CRYPT_INVALID_ARG; 
-  }
-
-  /* get modulus len */
-  modulus_bytelen = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
-
-  /* get der len ok?  Forgive my lame German accent.... */
-  derlen = hash_descriptor[hash_idx].DERlen;
-
-  /* valid sizes? */
-  if (msghashlen + 3 + derlen > modulus_bytelen) {
-     return CRYPT_PK_INVALID_SIZE;
-  }
-
-  if (*outlen < modulus_bytelen) {
-     return CRYPT_BUFFER_OVERFLOW;
-  }
-
-  /* packet is 0x00 0x01 PS 0x00 T, where PS == 0xFF repeated modulus_bytelen - 3 - derlen - msghashlen times, T == DER || hash */
-  x = 0;
-  out[x++] = 0x00;
-  out[x++] = 0x01;
-  for (y = 0; y < (modulus_bytelen - 3 - derlen - msghashlen); y++) {
-     out[x++] = 0xFF;
-  }
-  out[x++] = 0x00;
-  for (y = 0; y < derlen; y++) {
-     out[x++] = hash_descriptor[hash_idx].DER[y];
-  }
-  for (y = 0; y < msghashlen; y++) {
-     out[x++] = msghash[y];
-  }
-
-  *outlen = modulus_bytelen;
-  return CRYPT_OK;
-}
-
-#endif /* PKCS_1 */
diff --git a/pkcs_5_1.c b/pkcs_5_1.c
deleted file mode 100644
index d7ae0e1..0000000
--- a/pkcs_5_1.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include <mycrypt.h>
-
-/* PKCS #5, Algorithm #1 */
-#ifdef PKCS_5
-
-int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, 
-                const unsigned char *salt, 
-                int iteration_count,  int hash_idx,
-                unsigned char *out,   unsigned long *outlen)
-{
-   int err;
-   unsigned long x;
-   hash_state md;
-   unsigned char buf[MAXBLOCKSIZE];
-
-   _ARGCHK(password != NULL);
-   _ARGCHK(salt     != NULL);
-   _ARGCHK(out      != NULL);
-   _ARGCHK(outlen   != NULL);
-
-   /* test hash IDX */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* hash initial password + salt */
-   hash_descriptor[hash_idx].init(&md);
-   hash_descriptor[hash_idx].process(&md, password, password_len);
-   hash_descriptor[hash_idx].process(&md, salt, 8);
-   hash_descriptor[hash_idx].done(&md, buf);
-
-   while (--iteration_count) {
-      // code goes here.
-      x = sizeof(buf);
-      if ((err = hash_memory(hash_idx, buf, hash_descriptor[hash_idx].hashsize, buf, &x)) != CRYPT_OK) {
-         return err;
-      }
-   }
-
-   /* copy upto outlen bytes */
-   for (x = 0; x < hash_descriptor[hash_idx].hashsize && x < *outlen; x++) {
-       out[x] = buf[x];
-   }
-   *outlen = x;
-
-#ifdef CLEAN_STACK 
-   zeromem(buf, sizeof(buf));
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/pkcs_5_2.c b/pkcs_5_2.c
deleted file mode 100644
index 46bf75b..0000000
--- a/pkcs_5_2.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include <mycrypt.h>
-
-/* PKCS #5, Algorithm #2 */
-#ifdef PKCS_5
-
-int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, 
-                const unsigned char *salt,     unsigned long salt_len,
-                int iteration_count,           int hash_idx,
-                unsigned char *out,            unsigned long *outlen)
-{
-   int err, itts;
-   unsigned long stored, left, x, y, blkno;
-   unsigned char buf[2][MAXBLOCKSIZE];
-   hmac_state    hmac;
-
-   _ARGCHK(password != NULL);
-   _ARGCHK(salt     != NULL);
-   _ARGCHK(out      != NULL);
-   _ARGCHK(outlen   != NULL);
-
-   /* test hash IDX */
-   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   left   = *outlen;
-   blkno  = 1;
-   stored = 0;
-   while (left != 0) {
-       /* process block number blkno */
-       zeromem(buf, sizeof(buf));
-       
-       /* store current block number and increment for next pass */
-       STORE32H(blkno, buf[1]);
-       ++blkno;
-
-       /* get PRF(P, S||int(blkno)) */
-       if ((err = hmac_init(&hmac, hash_idx, password, password_len)) != CRYPT_OK) { 
-          return err; 
-       }
-       if ((err = hmac_process(&hmac, salt, salt_len)) != CRYPT_OK) {
-          return err;
-       }
-       if ((err = hmac_process(&hmac, buf[1], 4)) != CRYPT_OK) {
-          return err;
-       }
-       x = sizeof(buf[0]);
-       if ((err = hmac_done(&hmac, buf[0], &x)) != CRYPT_OK) {
-          return err;
-       }
-
-       /* now compute repeated and XOR it in buf[1] */
-       memcpy(buf[1], buf[0], x);
-       for (itts = 2; itts < iteration_count; ++itts) {
-           if ((err = hmac_memory(hash_idx, password, password_len, buf[0], x, buf[0], &x)) != CRYPT_OK) {
-              return err;
-           }
-           for (y = 0; y < x; y++) {
-               buf[1][y] ^= buf[0][y];
-           }
-       }
-
-       /* now emit upto x bytes of buf[1] to output */
-       for (y = 0; y < x && left != 0; ++y) {
-           out[stored++] = buf[1][y];
-           --left;
-       }
-   }
-   *outlen = stored;
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/pmac_file.c b/pmac_file.c
deleted file mode 100644
index c664a09..0000000
--- a/pmac_file.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef PMAC
-
-int pmac_file(int cipher, 
-              const unsigned char *key, unsigned long keylen,
-              const char *filename, 
-                    unsigned char *out, unsigned long *outlen)
-{
-#ifdef NO_FILE
-   return CRYPT_NOP;
-#else
-   int err, x;
-   pmac_state pmac;
-   FILE *in;
-   unsigned char buf[512];
-
-
-   _ARGCHK(key      != NULL);
-   _ARGCHK(filename != NULL);
-   _ARGCHK(out      != NULL);
-   _ARGCHK(outlen   != NULL);
-
-   in = fopen(filename, "rb");
-   if (in == NULL) {
-      return CRYPT_FILE_NOTFOUND;
-   }
-
-   if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) {
-      fclose(in);
-      return err;
-   }
-
-   do {
-      x = fread(buf, 1, sizeof(buf), in);
-      if ((err = pmac_process(&pmac, buf, x)) != CRYPT_OK) {
-         fclose(in);
-         return err;
-      }
-   } while (x == sizeof(buf));
-   fclose(in);
-
-   if ((err = pmac_done(&pmac, out, outlen)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-
-   return CRYPT_OK;
-#endif
-}
-
-#endif
diff --git a/pmac_memory.c b/pmac_memory.c
deleted file mode 100644
index c279d71..0000000
--- a/pmac_memory.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef PMAC
-
-int pmac_memory(int cipher, 
-                const unsigned char *key, unsigned long keylen,
-                const unsigned char *msg, unsigned long msglen,
-                      unsigned char *out, unsigned long *outlen)
-{
-   int err;
-   pmac_state pmac;
-
-   _ARGCHK(key    != NULL);
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-
-   if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = pmac_process(&pmac, msg, msglen)) != CRYPT_OK) {
-      return err;
-   }
-   if ((err = pmac_done(&pmac, out, outlen)) != CRYPT_OK) {
-      return err;
-   }
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/pmac_ntz.c b/pmac_ntz.c
deleted file mode 100644
index 98ec430..0000000
--- a/pmac_ntz.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef PMAC
-
-int pmac_ntz(unsigned long x)
-{
-   int c;
-   x &= 0xFFFFFFFFUL;
-   c = 0;
-   while ((x & 1) == 0) {
-      ++c;
-      x >>= 1;
-   }
-   return c;
-}
-
-#endif
diff --git a/pmac_process.c b/pmac_process.c
deleted file mode 100644
index ff2c3fe..0000000
--- a/pmac_process.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef PMAC
-
-int pmac_process(pmac_state *state, const unsigned char *buf, unsigned long len)
-{
-   int err, n, x;
-   unsigned char Z[MAXBLOCKSIZE];
-
-   _ARGCHK(state != NULL);
-   _ARGCHK(buf   != NULL);
-   if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
-       (state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   while (len != 0) { 
-       /* ok if the block is full we xor in prev, encrypt and replace prev */
-       if (state->buflen == state->block_len) {
-          pmac_shift_xor(state);
-          for (x = 0; x < state->block_len; x++) {
-              Z[x] = state->Li[x] ^ state->block[x];
-          }
-          cipher_descriptor[state->cipher_idx].ecb_encrypt(Z, Z, &state->key);
-          for (x = 0; x < state->block_len; x++) {
-              state->checksum[x] ^= Z[x];
-          }
-          state->buflen = 0;
-       }
-
-       /* add bytes */
-       n = MIN(len, (unsigned long)(state->block_len - state->buflen));
-       memcpy(state->block + state->buflen, buf, n);
-       state->buflen += n;
-       len           -= n;
-       buf           += n;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(Z, sizeof(Z));
-#endif
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/pmac_shift_xor.c b/pmac_shift_xor.c
deleted file mode 100644
index 46159fb..0000000
--- a/pmac_shift_xor.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef PMAC
-
-void pmac_shift_xor(pmac_state *pmac)
-{
-   int x, y;
-   y = pmac_ntz(pmac->block_index++);
-   for (x = 0; x < pmac->block_len; x++) {
-       pmac->Li[x] ^= pmac->Ls[y][x];
-   }
-}
-
-#endif
diff --git a/rc4.c b/rc4.c
deleted file mode 100644
index 9d2f6b7..0000000
--- a/rc4.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-#ifdef RC4
-
-const struct _prng_descriptor rc4_desc = 
-{
-   "rc4",
-    &rc4_start,
-    &rc4_add_entropy,
-    &rc4_ready,
-    &rc4_read
-};
-
-int rc4_start(prng_state *prng)
-{
-    _ARGCHK(prng != NULL);
-
-    /* set keysize to zero */
-    prng->rc4.x = 0;
-    
-    return CRYPT_OK;
-}
-
-int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
-{
-    _ARGCHK(buf != NULL);
-    _ARGCHK(prng != NULL);
-
-    if (prng->rc4.x + len > 256) {
-       return CRYPT_INVALID_KEYSIZE;
-    }
-
-    while (len--) {
-       prng->rc4.buf[prng->rc4.x++] = *buf++;
-    }
-
-    return CRYPT_OK;
-    
-}
-
-int rc4_ready(prng_state *prng)
-{
-    unsigned char key[256], tmp;
-    int keylen, x, y;
-
-    _ARGCHK(prng != NULL);
-
-    /* extract the key */
-    memcpy(key, prng->rc4.buf, 256);
-    keylen = prng->rc4.x;
-
-    /* make RC4 perm and shuffle */
-    for (x = 0; x < 256; x++) {
-        prng->rc4.buf[x] = x;
-    }
-
-    for (x = y = 0; x < 256; x++) {
-        y = (y + prng->rc4.buf[x] + key[x % keylen]) & 255;
-        tmp = prng->rc4.buf[x]; prng->rc4.buf[x] = prng->rc4.buf[y]; prng->rc4.buf[y] = tmp;
-    }
-    prng->rc4.x = x;
-    prng->rc4.y = y;
-
-#ifdef CLEAN_STACK
-    zeromem(key, sizeof(key));
-#endif
-
-    return CRYPT_OK;
-}
-
-unsigned long rc4_read(unsigned char *buf, unsigned long len, prng_state *prng)
-{
-   int x, y; 
-   unsigned char *s, tmp;
-   unsigned long n;
-
-   _ARGCHK(buf != NULL);
-   _ARGCHK(prng != NULL);
-
-   n = len;
-   x = prng->rc4.x;
-   y = prng->rc4.y;
-   s = prng->rc4.buf;
-   while (len--) {
-      x = (x + 1) & 255;
-      y = (y + s[x]) & 255;
-      tmp = s[x]; s[x] = s[y]; s[y] = tmp;
-      tmp = (s[x] + s[y]) & 255;
-      *buf++ ^= s[tmp];
-   }
-   prng->rc4.x = x;
-   prng->rc4.y = y;
-   return n;
-}
-
-#endif
-
diff --git a/rsa.c b/rsa.c
deleted file mode 100644
index 05190fd..0000000
--- a/rsa.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* RSA Code by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-int rsa_signpad(const unsigned char *in,  unsigned long inlen,
-                      unsigned char *out, unsigned long *outlen)
-{
-   unsigned long x, y;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   if (*outlen < (3 * inlen)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* check inlen */
-   if (inlen > MAX_RSA_SIZE/8) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-
-   for (y = x = 0; x < inlen; x++)
-       out[y++] = (unsigned char)0xFF;
-   for (x = 0; x < inlen; x++)
-       out[y++] = in[x];
-   for (x = 0; x < inlen; x++)
-       out[y++] = (unsigned char)0xFF;
-   *outlen = 3 * inlen;
-   return CRYPT_OK;
-}
-
-int rsa_pad(const unsigned char *in,  unsigned long inlen,
-                  unsigned char *out, unsigned long *outlen,
-                  int wprng, prng_state *prng)
-{
-   unsigned char buf[3*(MAX_RSA_SIZE/8)];
-   unsigned long x;
-   int err;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* is output big enough? */
-   if (*outlen < (3 * inlen)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* get random padding required */
-   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* check inlen */
-   if (inlen > (MAX_RSA_SIZE/8)) {
-      return CRYPT_PK_INVALID_SIZE;
-   }
-
-   if (prng_descriptor[wprng].read(buf, inlen*2-2, prng) != (inlen*2 - 2))  {
-       return CRYPT_ERROR_READPRNG;
-   }
-
-   /* pad it like a sandwhich
-    *
-    * Looks like 0xFF R1 M R2 0xFF
-    *
-    * Where R1/R2 are random and exactly equal to the length of M minus one byte.
-    */
-   for (x = 0; x < inlen-1; x++) {
-       out[x+1] = buf[x];
-   }
-
-   for (x = 0; x < inlen; x++) {
-       out[x+inlen] = in[x];
-   }
-
-   for (x = 0; x < inlen-1; x++) {
-       out[x+inlen+inlen] = buf[x+inlen-1];
-   }
-
-   /* last and first bytes are 0xFF */
-   out[0] = out[inlen+inlen+inlen-1] = (unsigned char)0xFF;
-
-   /* clear up and return */
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
-#endif
-   *outlen = inlen*3;
-   return CRYPT_OK;
-}
-
-int rsa_signdepad(const unsigned char *in,  unsigned long inlen,
-                        unsigned char *out, unsigned long *outlen)
-{
-   unsigned long x;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   if (*outlen < inlen/3) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* check padding bytes */
-   for (x = 0; x < inlen/3; x++) {
-       if (in[x] != (unsigned char)0xFF || in[x+(inlen/3)+(inlen/3)] != (unsigned char)0xFF) {
-          return CRYPT_INVALID_PACKET;
-       }
-   }
-   for (x = 0; x < inlen/3; x++) {
-       out[x] = in[x+(inlen/3)];
-   }
-   *outlen = inlen/3;
-   return CRYPT_OK;
-}
-
-int rsa_depad(const unsigned char *in,  unsigned long inlen,
-                    unsigned char *out, unsigned long *outlen)
-{
-   unsigned long x;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   if (*outlen < inlen/3) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-   for (x = 0; x < inlen/3; x++) {
-       out[x] = in[x+(inlen/3)];
-   }
-   *outlen = inlen/3;
-   return CRYPT_OK;
-}
-
-int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
-{
-   unsigned long y, z; 
-   int err;
-
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-   
-   /* can we store the static header?  */
-   if (*outlen < (PACKET_SIZE + 1)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }   
-
-   /* type valid? */
-   if (!(key->type == PK_PRIVATE || key->type == PK_PRIVATE_OPTIMIZED) &&
-        (type == PK_PRIVATE || type == PK_PRIVATE_OPTIMIZED)) {
-      return CRYPT_PK_INVALID_TYPE;
-   }
-
-   /* start at offset y=PACKET_SIZE */
-   y = PACKET_SIZE;
-
-   /* output key type */
-   out[y++] = type;
-
-   /* output modulus */
-   OUTPUT_BIGNUM(&key->N, out, y, z);
-
-   /* output public key */
-   OUTPUT_BIGNUM(&key->e, out, y, z);
-
-   if (type == PK_PRIVATE || type == PK_PRIVATE_OPTIMIZED) {
-      OUTPUT_BIGNUM(&key->d, out, y, z);
-   }
-
-   if (type == PK_PRIVATE_OPTIMIZED) {
-      OUTPUT_BIGNUM(&key->dQ, out, y, z);
-      OUTPUT_BIGNUM(&key->dP, out, y, z);
-      OUTPUT_BIGNUM(&key->pQ, out, y, z);
-      OUTPUT_BIGNUM(&key->qP, out, y, z);
-      OUTPUT_BIGNUM(&key->p, out, y, z);
-      OUTPUT_BIGNUM(&key->q, out, y, z);
-   }
-
-   /* store packet header */
-   packet_store_header(out, PACKET_SECT_RSA, PACKET_SUB_KEY);
-
-   /* copy to the user buffer */
-   *outlen = y;
-
-   /* clear stack and return */
-   return CRYPT_OK;
-}
-
-int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key)
-{
-   unsigned long x, y;
-   int err;
-
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
-
-   /* check length */
-   if (inlen < (1+PACKET_SIZE)) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* test packet header */
-   if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_RSA, PACKET_SUB_KEY)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* init key */
-   if ((err = mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP, &key->qP,
-                     &key->pQ, &key->p, &key->q, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   /* get key type */
-   y = PACKET_SIZE;
-   key->type = (int)in[y++];
-
-   /* load the modulus  */
-   INPUT_BIGNUM(&key->N, in, x, y, inlen);
-
-   /* load public exponent */
-   INPUT_BIGNUM(&key->e, in, x, y, inlen);
-
-   /* get private exponent */
-   if (key->type == PK_PRIVATE || key->type == PK_PRIVATE_OPTIMIZED) {
-      INPUT_BIGNUM(&key->d, in, x, y, inlen);
-   }
-
-   /* get CRT private data if required */
-   if (key->type == PK_PRIVATE_OPTIMIZED) {
-      INPUT_BIGNUM(&key->dQ, in, x, y, inlen);
-      INPUT_BIGNUM(&key->dP, in, x, y, inlen);
-      INPUT_BIGNUM(&key->pQ, in, x, y, inlen);
-      INPUT_BIGNUM(&key->qP, in, x, y, inlen);
-      INPUT_BIGNUM(&key->p, in, x, y, inlen);
-      INPUT_BIGNUM(&key->q, in, x, y, inlen);
-   }
-
-   /* free up ram not required */
-   if (key->type != PK_PRIVATE_OPTIMIZED) {
-      mp_clear_multi(&key->dQ, &key->dP, &key->pQ, &key->qP, &key->p, &key->q, NULL);
-   }
-   if (key->type != PK_PRIVATE && key->type != PK_PRIVATE_OPTIMIZED) {
-      mp_clear(&key->d);
-   }
-
-   return CRYPT_OK;
-error:
-   mp_clear_multi(&key->d, &key->e, &key->N, &key->dQ, &key->dP,
-                  &key->pQ, &key->qP, &key->p, &key->q, NULL);
-   return err;
-}
-
-#include "rsa_sys.c"
-
-#endif /* RSA */
-
-
diff --git a/rsa_decrypt_key.c b/rsa_decrypt_key.c
deleted file mode 100644
index 8d63d46..0000000
--- a/rsa_decrypt_key.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-/* decrypt then OAEP depad  */
-int rsa_decrypt_key(const unsigned char *in,     unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
-                    const unsigned char *lparam, unsigned long lparamlen,
-                          prng_state    *prng,   int           prng_idx,
-                          int            hash_idx, int *res,
-                          rsa_key       *key)
-{
-  unsigned long modulus_bitlen, modulus_bytelen, x;
-  int           err;
-  
-  _ARGCHK(outkey != NULL);
-  _ARGCHK(keylen != NULL);
-  _ARGCHK(key    != NULL);
-  _ARGCHK(res    != NULL);
-  
-  /* valid hash ? */
-  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-     return err;
-  }
-  
-  /* get modulus len in bits */
-  modulus_bitlen = mp_count_bits(&(key->N));
-
-  /* outlen must be at least the size of the modulus */
-  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
-  if (modulus_bytelen != inlen) {
-     return CRYPT_INVALID_PACKET;
-  }
-
-  /* rsa decode the packet */
-  x = *keylen;
-  if ((err = rsa_exptmod(in, inlen, outkey, &x, PK_PRIVATE, prng, prng_idx, key)) != CRYPT_OK) {
-     return err;
-  }
-
-  /* now OAEP decode the packet */
-  return pkcs_1_oaep_decode(outkey, x, lparam, lparamlen, modulus_bitlen, hash_idx,
-                            outkey, keylen, res);
-}
-
-#endif /* MRSA */
-
-
-
-
diff --git a/rsa_encrypt_key.c b/rsa_encrypt_key.c
deleted file mode 100644
index fc5076b..0000000
--- a/rsa_encrypt_key.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-/* OAEP pad then encrypt */
-int rsa_encrypt_key(const unsigned char *inkey,  unsigned long inlen,
-                          unsigned char *outkey, unsigned long *outlen,
-                    const unsigned char *lparam, unsigned long lparamlen,
-                    prng_state *prng, int prng_idx, int hash_idx, rsa_key *key)
-{
-  unsigned long modulus_bitlen, modulus_bytelen, x;
-  int           err;
-  
-  _ARGCHK(inkey  != NULL);
-  _ARGCHK(outkey != NULL);
-  _ARGCHK(outlen != NULL);
-  _ARGCHK(key    != NULL);
-  
-  /* valid prng and hash ? */
-  if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-     return err;
-  }
-  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-     return err;
-  }
-  
-  /* get modulus len in bits */
-  modulus_bitlen = mp_count_bits(&(key->N));
-
-  /* outlen must be at least the size of the modulus */
-  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
-  if (modulus_bytelen > *outlen) {
-     return CRYPT_BUFFER_OVERFLOW;
-  }
-      
-  /* OAEP pad the key */
-  x = *outlen;
-  if ((err = pkcs_1_oaep_encode(inkey, inlen, lparam, 
-                                lparamlen, modulus_bitlen, prng, prng_idx, hash_idx, 
-                                outkey, &x)) != CRYPT_OK) {
-     return err;
-  }                                
-
-  /* rsa exptmod the OAEP pad */
-  return rsa_exptmod(outkey, x, outkey, outlen, PK_PUBLIC, prng, prng_idx, key);
-}
-
-#endif /* MRSA */
diff --git a/rsa_export.c b/rsa_export.c
deleted file mode 100644
index cedd26d..0000000
--- a/rsa_export.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
-{
-   unsigned long y, z; 
-   int err;
-
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-   
-   /* can we store the static header?  */
-   if (*outlen < (PACKET_SIZE + 1)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }   
-
-   /* type valid? */
-   if (!(key->type == PK_PRIVATE || key->type == PK_PRIVATE_OPTIMIZED) &&
-        (type == PK_PRIVATE || type == PK_PRIVATE_OPTIMIZED)) {
-      return CRYPT_PK_INVALID_TYPE;
-   }
-
-   /* start at offset y=PACKET_SIZE */
-   y = PACKET_SIZE;
-
-   /* output key type */
-   out[y++] = type;
-
-   /* output modulus */
-   OUTPUT_BIGNUM(&key->N, out, y, z);
-
-   /* output public key */
-   OUTPUT_BIGNUM(&key->e, out, y, z);
-
-   if (type == PK_PRIVATE || type == PK_PRIVATE_OPTIMIZED) {
-      OUTPUT_BIGNUM(&key->d, out, y, z);
-   }
-
-   if (type == PK_PRIVATE_OPTIMIZED) {
-      OUTPUT_BIGNUM(&key->dQ, out, y, z);
-      OUTPUT_BIGNUM(&key->dP, out, y, z);
-      OUTPUT_BIGNUM(&key->pQ, out, y, z);
-      OUTPUT_BIGNUM(&key->qP, out, y, z);
-      OUTPUT_BIGNUM(&key->p, out, y, z);
-      OUTPUT_BIGNUM(&key->q, out, y, z);
-   }
-
-   /* store packet header */
-   packet_store_header(out, PACKET_SECT_RSA, PACKET_SUB_KEY);
-
-   /* copy to the user buffer */
-   *outlen = y;
-
-   /* clear stack and return */
-   return CRYPT_OK;
-}
-
-#endif /* MRSA */
-
diff --git a/rsa_exptmod.c b/rsa_exptmod.c
deleted file mode 100644
index fbf49d4..0000000
--- a/rsa_exptmod.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* RSA Code by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
-                      unsigned char *out,  unsigned long *outlen, int which,
-                      prng_state    *prng, int           prng_idx,
-                      rsa_key *key)
-{
-   mp_int        tmp, tmpa, tmpb;
-   unsigned long x;
-   int           err;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-   
-   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   if (which == PK_PRIVATE && (key->type != PK_PRIVATE && key->type != PK_PRIVATE_OPTIMIZED)) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   /* must be a private or public operation */
-   if (which != PK_PRIVATE && which != PK_PUBLIC) {
-      return CRYPT_PK_INVALID_TYPE;
-   }
-
-   /* init and copy into tmp */
-   if ((err = mp_init_multi(&tmp, &tmpa, &tmpb, NULL)) != MP_OKAY)                     { goto error; }
-   if ((err = mp_read_unsigned_bin(&tmp, (unsigned char *)in, (int)inlen)) != MP_OKAY) { goto error; }
-
-   /* sanity check on the input */
-   if (mp_cmp(&key->N, &tmp) == MP_LT) {
-      err = CRYPT_PK_INVALID_SIZE;
-      goto done;
-   }
-
-   /* are we using the private exponent and is the key optimized? */
-   if (which == PK_PRIVATE && key->type == PK_PRIVATE_OPTIMIZED) {
-      /* tmpa = tmp^dP mod p */
-      if ((err = tim_exptmod(prng, prng_idx, &tmp, &key->e, &key->dP, &key->p, &tmpa)) != MP_OKAY)    { goto error; }
-
-      /* tmpb = tmp^dQ mod q */
-      if ((err = tim_exptmod(prng, prng_idx, &tmp, &key->e,  &key->dQ, &key->q, &tmpb)) != MP_OKAY)    { goto error; }
-
-      /* tmp = tmpa*qP + tmpb*pQ mod N */
-      if ((err = mp_mul(&tmpa, &key->qP, &tmpa)) != MP_OKAY)                { goto error; }
-      if ((err = mp_mul(&tmpb, &key->pQ, &tmpb)) != MP_OKAY)                { goto error; }
-      if ((err = mp_addmod(&tmpa, &tmpb, &key->N, &tmp)) != MP_OKAY)        { goto error; }
-   } else {
-      /* exptmod it */
-      if (which == PK_PRIVATE) {
-         if ((err = tim_exptmod(prng, prng_idx, &tmp, &key->e, &key->d, &key->N, &tmp)) != MP_OKAY) { goto error; }
-      } else {
-         if ((err = mp_exptmod(&tmp, &key->e, &key->N, &tmp)) != MP_OKAY) { goto error; }
-      }
-   }
-
-   /* read it back */
-   x = (unsigned long)mp_unsigned_bin_size(&key->N);
-   if (x > *outlen) {
-      err = CRYPT_BUFFER_OVERFLOW;
-      goto done;
-   }
-   *outlen = x;
-
-   /* convert it */
-   zeromem(out, x);
-   if ((err = mp_to_unsigned_bin(&tmp, out+(x-mp_unsigned_bin_size(&tmp)))) != MP_OKAY) { goto error; }
-
-   /* clean up and return */
-   err = CRYPT_OK;
-   goto done;
-error:
-   err = mpi_to_ltc_error(err);
-done:
-   mp_clear_multi(&tmp, &tmpa, &tmpb, NULL);
-   return err;
-}
-
-#endif
diff --git a/rsa_free.c b/rsa_free.c
deleted file mode 100644
index c97242b..0000000
--- a/rsa_free.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* RSA Code by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-void rsa_free(rsa_key *key)
-{
-   _ARGCHK(key != NULL);
-   mp_clear_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP,
-                  &key->qP, &key->pQ, &key->p, &key->q, NULL);
-}
-
-#endif
diff --git a/rsa_import.c b/rsa_import.c
deleted file mode 100644
index deffc38..0000000
--- a/rsa_import.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key)
-{
-   unsigned long x, y;
-   int err;
-
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
-
-   /* check length */
-   if (inlen < (1+PACKET_SIZE)) {
-      return CRYPT_INVALID_PACKET;
-   }
-
-   /* test packet header */
-   if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_RSA, PACKET_SUB_KEY)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* init key */
-   if ((err = mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP, &key->qP,
-                     &key->pQ, &key->p, &key->q, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
-   }
-
-   /* get key type */
-   y = PACKET_SIZE;
-   key->type = (int)in[y++];
-
-   /* load the modulus  */
-   INPUT_BIGNUM(&key->N, in, x, y, inlen);
-
-   /* load public exponent */
-   INPUT_BIGNUM(&key->e, in, x, y, inlen);
-
-   /* get private exponent */
-   if (key->type == PK_PRIVATE || key->type == PK_PRIVATE_OPTIMIZED) {
-      INPUT_BIGNUM(&key->d, in, x, y, inlen);
-   }
-
-   /* get CRT private data if required */
-   if (key->type == PK_PRIVATE_OPTIMIZED) {
-      INPUT_BIGNUM(&key->dQ, in, x, y, inlen);
-      INPUT_BIGNUM(&key->dP, in, x, y, inlen);
-      INPUT_BIGNUM(&key->pQ, in, x, y, inlen);
-      INPUT_BIGNUM(&key->qP, in, x, y, inlen);
-      INPUT_BIGNUM(&key->p, in, x, y, inlen);
-      INPUT_BIGNUM(&key->q, in, x, y, inlen);
-   }
-
-   /* free up ram not required */
-   if (key->type != PK_PRIVATE_OPTIMIZED) {
-      mp_clear_multi(&key->dQ, &key->dP, &key->pQ, &key->qP, &key->p, &key->q, NULL);
-   }
-   if (key->type != PK_PRIVATE && key->type != PK_PRIVATE_OPTIMIZED) {
-      mp_clear(&key->d);
-   }
-
-   return CRYPT_OK;
-error:
-   mp_clear_multi(&key->d, &key->e, &key->N, &key->dQ, &key->dP,
-                  &key->pQ, &key->qP, &key->p, &key->q, NULL);
-   return err;
-}
-
-#endif /* MRSA */
-
diff --git a/rsa_sign_hash.c b/rsa_sign_hash.c
deleted file mode 100644
index decac6c..0000000
--- a/rsa_sign_hash.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-/* PSS pad then sign */
-int rsa_sign_hash(const unsigned char *msghash,  unsigned long  msghashlen, 
-                        unsigned char *sig,      unsigned long *siglen, 
-                        prng_state    *prng,     int            prng_idx,
-                        int            hash_idx, unsigned long  saltlen,
-                        rsa_key *key)
-{
-   unsigned long modulus_bitlen, modulus_bytelen, x;
-   int           err;
-   
-  _ARGCHK(msghash  != NULL);
-  _ARGCHK(sig      != NULL);
-  _ARGCHK(siglen   != NULL);
-  _ARGCHK(key      != NULL);
-  
-  /* valid prng and hash ? */
-  if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-     return err;
-  }
-  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-     return err;
-  }
-  
-  /* get modulus len in bits */
-  modulus_bitlen = mp_count_bits(&(key->N));
-
-  /* outlen must be at least the size of the modulus */
-  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
-  if (modulus_bytelen > *siglen) {
-     return CRYPT_BUFFER_OVERFLOW;
-  }
-      
-  /* PSS pad the key */
-  x = *siglen;
-  if ((err = pkcs_1_pss_encode(msghash, msghashlen, saltlen, prng, prng_idx,
-                               hash_idx, modulus_bitlen, sig, &x)) != CRYPT_OK) {
-     return err;
-  }
-
-  /* RSA encode it */
-  return rsa_exptmod(sig, x, sig, siglen, PK_PRIVATE, prng, prng_idx, key);
-}
-
-#endif /* MRSA */
diff --git a/rsa_sys.c b/rsa_sys.c
deleted file mode 100644
index fd3aa0a..0000000
--- a/rsa_sys.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* these are smaller routines written by Clay Culver.  They do the same function as the rsa_encrypt/decrypt 
- * except that they are used to RSA encrypt/decrypt a single value and not a packet.
- */
-int rsa_encrypt_key(const unsigned char *inkey, unsigned long inlen,
-                    unsigned char *outkey, unsigned long *outlen,
-                    prng_state *prng, int wprng, rsa_key *key)
-{
-   unsigned char rsa_in[RSA_STACK], rsa_out[RSA_STACK];
-   unsigned long x, y, rsa_size;
-   int err;
-
-   _ARGCHK(inkey  != NULL);
-   _ARGCHK(outkey != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-   
-   /* only allow keys from 64 to 256 bits */
-   if (inlen < 8 || inlen > 32) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* are the parameters valid? */
-   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
-      return err; 
-   }
-
-   /* rsa_pad the symmetric key */
-   y = (unsigned long)sizeof(rsa_in); 
-   if ((err = rsa_pad(inkey, inlen, rsa_in, &y, wprng, prng)) != CRYPT_OK) {
-      return CRYPT_ERROR;
-   }
-   
-   /* rsa encrypt it */
-   rsa_size = (unsigned long)sizeof(rsa_out);
-   if ((err = rsa_exptmod(rsa_in, y, rsa_out, &rsa_size, PK_PUBLIC, key)) != CRYPT_OK) {
-      return CRYPT_ERROR;
-   }
-
-   /* check size */
-   if (*outlen < (PACKET_SIZE+4+rsa_size)) { 
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* store header */
-   packet_store_header(outkey, PACKET_SECT_RSA, PACKET_SUB_ENC_KEY);
-
-   /* now lets make the header */
-   y = PACKET_SIZE;
-   
-   /* store the size of the RSA value */
-   STORE32L(rsa_size, (outkey+y));
-   y += 4;
-
-   /* store the rsa value */
-   for (x = 0; x < rsa_size; x++, y++) {
-       outkey[y] = rsa_out[x];
-   }
-
-   *outlen = y;
-#ifdef CLEAN_STACK
-   /* clean up */
-   zeromem(rsa_in, sizeof(rsa_in));
-   zeromem(rsa_out, sizeof(rsa_out));
-#endif
-
-   return CRYPT_OK;
-}
-
-int rsa_decrypt_key(const unsigned char *in, unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
-                          rsa_key *key)
-{
-   unsigned char sym_key[MAXBLOCKSIZE], rsa_out[RSA_STACK];
-   unsigned long x, y, z, i, rsa_size;
-   int err;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(outkey != NULL);
-   _ARGCHK(keylen != NULL);
-   _ARGCHK(key    != NULL);
-
-   /* right key type? */
-   if (key->type != PK_PRIVATE && key->type != PK_PRIVATE_OPTIMIZED) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   if (inlen < PACKET_SIZE+4) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      inlen -= PACKET_SIZE+4;
-   }
-
-   /* check the header */
-   if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_RSA, PACKET_SUB_ENC_KEY)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* grab length of the rsa key */
-   y = PACKET_SIZE;
-   LOAD32L(rsa_size, (in+y));
-   if (inlen < rsa_size) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      inlen -= rsa_size;
-   }
-   y += 4;
-
-   /* decrypt it */
-   x = (unsigned long)sizeof(rsa_out);
-   if ((err = rsa_exptmod(in+y, rsa_size, rsa_out, &x, PK_PRIVATE, key)) != CRYPT_OK) {
-      return err;
-   }
-   y += rsa_size;
-
-   /* depad it */
-   z = (unsigned long)sizeof(sym_key);
-   if ((err = rsa_depad(rsa_out, x, sym_key, &z)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* check size */
-   if (*keylen < z) { 
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   for (i = 0; i < z; i++) {
-     outkey[i] = sym_key[i];
-   }
-   
-#ifdef CLEAN_STACK
-   /* clean up */
-   zeromem(sym_key, sizeof(sym_key));
-   zeromem(rsa_out, sizeof(rsa_out));
-#endif
-   *keylen = z;
-   return CRYPT_OK;
-}
-
-int rsa_sign_hash(const unsigned char *in,  unsigned long inlen, 
-                        unsigned char *out, unsigned long *outlen, 
-                        rsa_key *key)
-{
-   unsigned long rsa_size, x, y;
-   unsigned char rsa_in[RSA_STACK], rsa_out[RSA_STACK];
-   int err;
-
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-   
-   /* reject nonsense sizes */
-   if (inlen > (512/3) || inlen < 16) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* type of key? */
-   if (key->type != PK_PRIVATE && key->type != PK_PRIVATE_OPTIMIZED) {
-      return CRYPT_PK_NOT_PRIVATE;
-   }
-
-   /* pad it */
-   x = (unsigned long)sizeof(rsa_out);
-   if ((err = rsa_signpad(in, inlen, rsa_out, &x)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* sign it */
-   rsa_size = (unsigned long)sizeof(rsa_in);
-   if ((err = rsa_exptmod(rsa_out, x, rsa_in, &rsa_size, PK_PRIVATE, key)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* check size */
-   if (*outlen < (PACKET_SIZE+4+rsa_size)) {
-      return CRYPT_BUFFER_OVERFLOW;
-   }
-
-   /* now lets output the message */
-   y = PACKET_SIZE;
-
-   /* output the len */
-   STORE32L(rsa_size, (out+y));
-   y += 4;
-
-   /* store the signature */
-   for (x = 0; x < rsa_size; x++, y++) {
-       out[y] = rsa_in[x];
-   }
-
-   /* store header */
-   packet_store_header(out, PACKET_SECT_RSA, PACKET_SUB_SIGNED);
-
-#ifdef CLEAN_STACK
-   /* clean up */
-   zeromem(rsa_in, sizeof(rsa_in));
-   zeromem(rsa_out, sizeof(rsa_out));
-#endif
-   *outlen = y;
-   return CRYPT_OK;
-}
-
-int rsa_verify_hash(const unsigned char *sig, unsigned long siglen,
-                    const unsigned char *md, int *stat, rsa_key *key)
-{
-   unsigned long rsa_size, x, y, z;
-   unsigned char rsa_in[RSA_STACK], rsa_out[RSA_STACK];
-   int err;
-
-   _ARGCHK(sig  != NULL);
-   _ARGCHK(md   != NULL);
-   _ARGCHK(stat != NULL);
-   _ARGCHK(key  != NULL);
-
-   /* always be incorrect by default */
-   *stat = 0;
-   
-   if (siglen < PACKET_SIZE+4) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      siglen -= PACKET_SIZE+4;
-   }
-
-   /* verify header */
-   if ((err = packet_valid_header((unsigned char *)sig, PACKET_SECT_RSA, PACKET_SUB_SIGNED)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* get the len */
-   y = PACKET_SIZE;
-   LOAD32L(rsa_size, (sig+y));
-   if (siglen < rsa_size) {
-      return CRYPT_INVALID_PACKET;
-   } else {
-      siglen -= rsa_size;
-   }
-   y += 4;
-
-   /* exptmod it */
-   x = (unsigned long)sizeof(rsa_out);
-   if ((err = rsa_exptmod(sig+y, rsa_size, rsa_out, &x, PK_PUBLIC, key)) != CRYPT_OK) {
-      return err;
-   }
-   y += rsa_size;
-
-   /* depad it */
-   z = (unsigned long)sizeof(rsa_in);
-   if ((err = rsa_signdepad(rsa_out, x, rsa_in, &z)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* check? */
-   if (memcmp(rsa_in, md, (size_t)z) == 0) {
-      *stat = 1;
-   }
-
-#ifdef CLEAN_STACK
-   zeromem(rsa_in, sizeof(rsa_in));
-   zeromem(rsa_out, sizeof(rsa_out));
-#endif
-   return CRYPT_OK;
-}
-
diff --git a/rsa_verify_hash.c b/rsa_verify_hash.c
deleted file mode 100644
index 223ccda..0000000
--- a/rsa_verify_hash.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-/* design then PSS depad */
-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)
-{
-   unsigned long modulus_bitlen, modulus_bytelen, x;
-   int           err;
-   unsigned char *tmpbuf;
-   
-  _ARGCHK(msghash  != NULL);
-  _ARGCHK(sig      != NULL);
-  _ARGCHK(stat     != NULL);
-  _ARGCHK(key      != NULL);
-  
-  /* valid hash ? */
-  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
-     return err;
-  }
-
-  if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-     return err;
-  }
-  
-  /* get modulus len in bits */
-  modulus_bitlen = mp_count_bits(&(key->N));
-
-  /* outlen must be at least the size of the modulus */
-  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
-  if (modulus_bytelen != siglen) {
-     return CRYPT_INVALID_PACKET;
-  }
-  
-  /* allocate temp buffer for decoded sig */
-  tmpbuf = XCALLOC(1, modulus_bytelen + 1);
-  if (tmpbuf == NULL) {
-     return CRYPT_MEM;
-  }
-      
-  /* RSA decode it  */
-  x = siglen;
-  if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, prng, prng_idx, key)) != CRYPT_OK) {
-     XFREE(tmpbuf);
-     return err;
-  }
-  
-  /* PSS decode it */
-  err = pkcs_1_pss_decode(msghash, msghashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);
-  XFREE(tmpbuf);
-  return err;
-}
-
-#endif /* MRSA */
diff --git a/run.sh b/run.sh
new file mode 100644
index 0000000..b652110
--- /dev/null
+++ b/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 $ 
diff --git a/s_ocb_done.c b/s_ocb_done.c
deleted file mode 100644
index 90ed65c..0000000
--- a/s_ocb_done.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef OCB_MODE
-
-/* Since the last block is encrypted in CTR mode the same code can
- * be used to finish a decrypt or encrypt stream.  The only difference
- * is we XOR the final ciphertext into the checksum so we have to xor it
- * before we CTR [decrypt] or after [encrypt]
- *
- * the names pt/ptlen/ct really just mean in/inlen/out but this is the way I wrote it... 
- */
-int __ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
-                     unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode)
-
-{
-   unsigned char Z[MAXBLOCKSIZE], Y[MAXBLOCKSIZE], X[MAXBLOCKSIZE];
-   int err, x;
-
-   _ARGCHK(ocb    != NULL);
-   _ARGCHK(pt     != NULL);
-   _ARGCHK(ct     != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(taglen != NULL);
-   if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
-      return err;
-   }
-   if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length ||
-       (int)ptlen > ocb->block_len || (int)ptlen < 0) {
-      return CRYPT_INVALID_ARG;
-   }
-
-   /* compute X[m] = len(pt[m]) XOR Lr XOR Z[m] */
-   ocb_shift_xor(ocb, X); 
-   memcpy(Z, X, ocb->block_len);
-
-   X[ocb->block_len-1] ^= (ptlen*8)&255;
-   X[ocb->block_len-2] ^= ((ptlen*8)>>8)&255;
-   for (x = 0; x < ocb->block_len; x++) {
-       X[x] ^= ocb->Lr[x]; 
-   }
-
-   /* Y[m] = E(X[m])) */
-   cipher_descriptor[ocb->cipher].ecb_encrypt(X, Y, &ocb->key);
-
-   if (mode == 1) {
-      /* decrypt mode, so let's xor it first */
-      /* xor C[m] into checksum */
-      for (x = 0; x < (int)ptlen; x++) {
-         ocb->checksum[x] ^= ct[x];
-      }  
-   }
-
-   /* C[m] = P[m] xor Y[m] */
-   for (x = 0; x < (int)ptlen; x++) {
-       ct[x] = pt[x] ^ Y[x];
-   }
-
-   if (mode == 0) {
-      /* encrypt mode */    
-      /* xor C[m] into checksum */
-      for (x = 0; x < (int)ptlen; x++) {
-          ocb->checksum[x] ^= ct[x];
-      }
-   }
-
-   /* xor Y[m] and Z[m] into checksum */
-   for (x = 0; x < ocb->block_len; x++) {
-       ocb->checksum[x] ^= Y[x] ^ Z[x];
-   }
-   
-   /* encrypt checksum, er... tag!! */
-   cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->checksum, X, &ocb->key);
-
-   /* now store it */
-   for (x = 0; x < ocb->block_len && x < (int)*taglen; x++) {
-       tag[x] = X[x];
-   }
-   *taglen = x;
-
-#ifdef CLEAN_STACK
-   zeromem(X, sizeof(X));
-   zeromem(Y, sizeof(Y));
-   zeromem(Z, sizeof(Z));
-   zeromem(ocb, sizeof(*ocb));
-#endif
-   return CRYPT_OK;
-}
-
-#endif
-
diff --git a/serpent.c b/serpent.c
deleted file mode 100644
index 235ea11..0000000
--- a/serpent.c
+++ /dev/null
@@ -1,698 +0,0 @@
-#include "mycrypt.h"
-
-#ifdef SERPENT
-
-const struct _cipher_descriptor serpent_desc =
-{
-    "serpent",
-    5,
-    16, 32, 16, 32,
-    &serpent_setup,
-    &serpent_ecb_encrypt,
-    &serpent_ecb_decrypt,
-    &serpent_test,
-    &serpent_keysize
-};
-
-/* These defines are derived from Brian Gladman's work.  Contact him at gladman@seven77.demon.co.uk 
- *
- * Available on the web at http://fp.gladman.plus.com/cryptography_technology/aes/index.htm
- */
-#define sb0(a,b,c,d,e,f,g,h)    \
-    t1 = a ^ d;     \
-    t2 = a & d;     \
-    t3 = c ^ t1;    \
-    t6 = b & t1;    \
-    t4 = b ^ t3;    \
-    t10 = ~t3;      \
-    h = t2 ^ t4;    \
-    t7 = a ^ t6;    \
-    t14 = ~t7;      \
-    t8 = c | t7;    \
-    t11 = t3 ^ t7;  \
-    g = t4 ^ t8;    \
-    t12 = h & t11;  \
-    f = t10 ^ t12;  \
-    e = t12 ^ t14
-
-/* 15 terms */
-
-#define ib0(a,b,c,d,e,f,g,h)    \
-    t1 = ~a;        \
-    t2 = a ^ b;     \
-    t3 = t1 | t2;   \
-    t4 = d ^ t3;    \
-    t7 = d & t2;    \
-    t5 = c ^ t4;    \
-    t8 = t1 ^ t7;   \
-    g = t2 ^ t5;    \
-    t11 = a & t4;   \
-    t9 = g & t8;    \
-    t14 = t5 ^ t8;  \
-    f = t4 ^ t9;    \
-    t12 = t5 | f;   \
-    h = t11 ^ t12;  \
-    e = h ^ t14
-
-/* 14 terms!  */
-
-#define sb1(a,b,c,d,e,f,g,h)    \
-    t1 = ~a;        \
-    t2 = b ^ t1;    \
-    t3 = a | t2;    \
-    t4 = d | t2;    \
-    t5 = c ^ t3;    \
-    g = d ^ t5;     \
-    t7 = b ^ t4;    \
-    t8 = t2 ^ g;    \
-    t9 = t5 & t7;   \
-    h = t8 ^ t9;    \
-    t11 = t5 ^ t7;  \
-    f = h ^ t11;    \
-    t13 = t8 & t11; \
-    e = t5 ^ t13
-
-/* 17 terms */
-
-#define ib1(a,b,c,d,e,f,g,h)    \
-    t1 = a ^ d;     \
-    t2 = a & b;     \
-    t3 = b ^ c;     \
-    t4 = a ^ t3;    \
-    t5 = b | d;     \
-    t7 = c | t1;    \
-    h = t4 ^ t5;    \
-    t8 = b ^ t7;    \
-    t11 = ~t2;      \
-    t9 = t4 & t8;   \
-    f = t1 ^ t9;    \
-    t13 = t9 ^ t11; \
-    t12 = h & f;    \
-    g = t12 ^ t13;  \
-    t15 = a & d;    \
-    t16 = c ^ t13;  \
-    e = t15 ^ t16
-
-/* 16 terms */
-
-#define sb2(a,b,c,d,e,f,g,h)    \
-    t1 = ~a;        \
-    t2 = b ^ d;     \
-    t3 = c & t1;    \
-    t13 = d | t1;   \
-    e = t2 ^ t3;    \
-    t5 = c ^ t1;    \
-    t6 = c ^ e;     \
-    t7 = b & t6;    \
-    t10 = e | t5;   \
-    h = t5 ^ t7;    \
-    t9 = d | t7;    \
-    t11 = t9 & t10; \
-    t14 = t2 ^ h;   \
-    g = a ^ t11;    \
-    t15 = g ^ t13;  \
-    f = t14 ^ t15
-
-/* 16 terms */
-
-#define ib2(a,b,c,d,e,f,g,h)    \
-    t1 = b ^ d;     \
-    t2 = ~t1;       \
-    t3 = a ^ c;     \
-    t4 = c ^ t1;    \
-    t7 = a | t2;    \
-    t5 = b & t4;    \
-    t8 = d ^ t7;    \
-    t11 = ~t4;      \
-    e = t3 ^ t5;    \
-    t9 = t3 | t8;   \
-    t14 = d & t11;  \
-    h = t1 ^ t9;    \
-    t12 = e | h;    \
-    f = t11 ^ t12;  \
-    t15 = t3 ^ t12; \
-    g = t14 ^ t15
-
-/* 17 terms */
-
-#define sb3(a,b,c,d,e,f,g,h)    \
-    t1 = a ^ c;     \
-    t2 = d ^ t1;    \
-    t3 = a & t2;    \
-    t4 = d ^ t3;    \
-    t5 = b & t4;    \
-    g = t2 ^ t5;    \
-    t7 = a | g;     \
-    t8 = b | d;     \
-    t11 = a | d;    \
-    t9 = t4 & t7;   \
-    f = t8 ^ t9;    \
-    t12 = b ^ t11;  \
-    t13 = g ^ t9;   \
-    t15 = t3 ^ t8;  \
-    h = t12 ^ t13;  \
-    t16 = c & t15;  \
-    e = t12 ^ t16
-
-/* 16 term solution that performs less well than 17 term one
-   in my environment (PPro/PII)                                  
-
-#define sb3(a,b,c,d,e,f,g,h)    \
-    t1 = a ^ b;     \
-    t2 = a & c;     \
-    t3 = a | d;     \
-    t4 = c ^ d;     \
-    t5 = t1 & t3;   \
-    t6 = t2 | t5;   \
-    g = t4 ^ t6;    \
-    t8 = b ^ t3;    \
-    t9 = t6 ^ t8;   \
-    t10 = t4 & t9;  \
-    e = t1 ^ t10;   \
-    t12 = g & e;    \
-    f = t9 ^ t12;   \
-    t14 = b | d;    \
-    t15 = t4 ^ t12; \
-    h = t14 ^ t15
-*/
-
-/* 17 terms */
-
-#define ib3(a,b,c,d,e,f,g,h)    \
-    t1 = b ^ c;     \
-    t2 = b | c;     \
-    t3 = a ^ c;     \
-    t7 = a ^ d;     \
-    t4 = t2 ^ t3;   \
-    t5 = d | t4;    \
-    t9 = t2 ^ t7;   \
-    e = t1 ^ t5;    \
-    t8 = t1 | t5;   \
-    t11 = a & t4;   \
-    g = t8 ^ t9;    \
-    t12 = e | t9;   \
-    f = t11 ^ t12;  \
-    t14 = a & g;    \
-    t15 = t2 ^ t14; \
-    t16 = e & t15;  \
-    h = t4 ^ t16
-
-/* 15 terms */
-
-#define sb4(a,b,c,d,e,f,g,h)    \
-    t1 = a ^ d;     \
-    t2 = d & t1;    \
-    t3 = c ^ t2;    \
-    t4 = b | t3;    \
-    h = t1 ^ t4;    \
-    t6 = ~b;        \
-    t7 = t1 | t6;   \
-    e = t3 ^ t7;    \
-    t9 = a & e;     \
-    t10 = t1 ^ t6;  \
-    t11 = t4 & t10; \
-    g = t9 ^ t11;   \
-    t13 = a ^ t3;   \
-    t14 = t10 & g;  \
-    f = t13 ^ t14
-
-/* 17 terms */
-
-#define ib4(a,b,c,d,e,f,g,h)    \
-    t1 = c ^ d;     \
-    t2 = c | d;     \
-    t3 = b ^ t2;    \
-    t4 = a & t3;    \
-    f = t1 ^ t4;    \
-    t6 = a ^ d;     \
-    t7 = b | d;     \
-    t8 = t6 & t7;   \
-    h = t3 ^ t8;    \
-    t10 = ~a;       \
-    t11 = c ^ h;    \
-    t12 = t10 | t11;\
-    e = t3 ^ t12;   \
-    t14 = c | t4;   \
-    t15 = t7 ^ t14; \
-    t16 = h | t10;  \
-    g = t15 ^ t16
-
-/* 16 terms */
-
-#define sb5(a,b,c,d,e,f,g,h)    \
-    t1 = ~a;        \
-    t2 = a ^ b;     \
-    t3 = a ^ d;     \
-    t4 = c ^ t1;    \
-    t5 = t2 | t3;   \
-    e = t4 ^ t5;    \
-    t7 = d & e;     \
-    t8 = t2 ^ e;    \
-    t10 = t1 | e;   \
-    f = t7 ^ t8;    \
-    t11 = t2 | t7;  \
-    t12 = t3 ^ t10; \
-    t14 = b ^ t7;   \
-    g = t11 ^ t12;  \
-    t15 = f & t12;  \
-    h = t14 ^ t15
-
-/* 16 terms */
-
-#define ib5(a,b,c,d,e,f,g,h)    \
-    t1 = ~c;        \
-    t2 = b & t1;    \
-    t3 = d ^ t2;    \
-    t4 = a & t3;    \
-    t5 = b ^ t1;    \
-    h = t4 ^ t5;    \
-    t7 = b | h;     \
-    t8 = a & t7;    \
-    f = t3 ^ t8;    \
-    t10 = a | d;    \
-    t11 = t1 ^ t7;  \
-    e = t10 ^ t11;  \
-    t13 = a ^ c;    \
-    t14 = b & t10;  \
-    t15 = t4 | t13; \
-    g = t14 ^ t15
-
-/* 15 terms */
-
-#define sb6(a,b,c,d,e,f,g,h)    \
-    t1 = ~a;        \
-    t2 = a ^ d;     \
-    t3 = b ^ t2;    \
-    t4 = t1 | t2;   \
-    t5 = c ^ t4;    \
-    f = b ^ t5;     \
-    t13 = ~t5;      \
-    t7 = t2 | f;    \
-    t8 = d ^ t7;    \
-    t9 = t5 & t8;   \
-    g = t3 ^ t9;    \
-    t11 = t5 ^ t8;  \
-    e = g ^ t11;    \
-    t14 = t3 & t11; \
-    h = t13 ^ t14
-
-/* 15 terms */
-
-#define ib6(a,b,c,d,e,f,g,h)    \
-    t1 = ~a;        \
-    t2 = a ^ b;     \
-    t3 = c ^ t2;    \
-    t4 = c | t1;    \
-    t5 = d ^ t4;    \
-    t13 = d & t1;   \
-    f = t3 ^ t5;    \
-    t7 = t3 & t5;   \
-    t8 = t2 ^ t7;   \
-    t9 = b | t8;    \
-    h = t5 ^ t9;    \
-    t11 = b | h;    \
-    e = t8 ^ t11;   \
-    t14 = t3 ^ t11; \
-    g = t13 ^ t14
-
-/* 17 terms */
-
-#define sb7(a,b,c,d,e,f,g,h)    \
-    t1 = ~c;        \
-    t2 = b ^ c;     \
-    t3 = b | t1;    \
-    t4 = d ^ t3;    \
-    t5 = a & t4;    \
-    t7 = a ^ d;     \
-    h = t2 ^ t5;    \
-    t8 = b ^ t5;    \
-    t9 = t2 | t8;   \
-    t11 = d & t3;   \
-    f = t7 ^ t9;    \
-    t12 = t5 ^ f;   \
-    t15 = t1 | t4;  \
-    t13 = h & t12;  \
-    g = t11 ^ t13;  \
-    t16 = t12 ^ g;  \
-    e = t15 ^ t16
-
-/* 17 terms */
-
-#define ib7(a,b,c,d,e,f,g,h)    \
-    t1 = a & b;     \
-    t2 = a | b;     \
-    t3 = c | t1;    \
-    t4 = d & t2;    \
-    h = t3 ^ t4;    \
-    t6 = ~d;        \
-    t7 = b ^ t4;    \
-    t8 = h ^ t6;    \
-    t11 = c ^ t7;   \
-    t9 = t7 | t8;   \
-    f = a ^ t9;     \
-    t12 = d | f;    \
-    e = t11 ^ t12;  \
-    t14 = a & h;    \
-    t15 = t3 ^ f;   \
-    t16 = e ^ t14;  \
-    g = t15 ^ t16
-
-#define k_xor(r,a,b,c,d)             \
-    a ^= skey->serpent.K[4 * (r) + 0]; \
-    b ^= skey->serpent.K[4 * (r) + 1]; \
-    c ^= skey->serpent.K[4 * (r) + 2]; \
-    d ^= skey->serpent.K[4 * (r) + 3]
-
-#define k_set(r,a,b,c,d)   \
-    a = lkey[4 * (r) +  8];  \
-    b = lkey[4 * (r) +  9];  \
-    c = lkey[4 * (r) + 10];  \
-    d = lkey[4 * (r) + 11]
-
-#define k_get(r,a,b,c,d)            \
-    skey->serpent.K[4 * (r) + 0] = a; \
-    skey->serpent.K[4 * (r) + 1] = b; \
-    skey->serpent.K[4 * (r) + 2] = c; \
-    skey->serpent.K[4 * (r) + 3] = d
-
-/* the linear transformation and its inverse    */
-
-#define rot(a,b,c,d)    \
-    a = ROL(a, 13);    \
-    c = ROL(c, 3);     \
-    d ^= c ^ (a << 3);  \
-    b ^= a ^ c;         \
-    d = ROL(d, 7);     \
-    b = ROL(b, 1);     \
-    a ^= b ^ d;         \
-    c ^= d ^ (b << 7);  \
-    a = ROL(a, 5);     \
-    c = ROL(c, 22)
-
-#define irot(a,b,c,d)   \
-    c = ROR(c, 22);    \
-    a = ROR(a, 5);     \
-    c ^= d ^ (b << 7);  \
-    a ^= b ^ d;         \
-    d = ROR(d, 7);     \
-    b = ROR(b, 1);     \
-    d ^= c ^ (a << 3);  \
-    b ^= a ^ c;         \
-    c = ROR(c, 3);     \
-    a = ROR(a, 13)
-    
-#ifdef CLEAN_STACK
-static int _serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
-#else
-int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
-#endif
-{
-    unsigned long lkey[140], t, a, b, c, d, e, f, g, h, x;
-    unsigned long t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
-    unsigned char buf[32];
-
-    _ARGCHK(key != NULL);
-    _ARGCHK(skey != NULL);
-
-    /* check rounds */
-    if (num_rounds != 0 && num_rounds != 32) {
-       return CRYPT_INVALID_ROUNDS;
-    }
-
-    /* check keylen */
-    if (keylen < 16 || keylen > 32) {
-       return CRYPT_INVALID_KEYSIZE;
-    }
-
-    /* copy key and expand to 32bytes as required */
-    for (x = 0; x < (unsigned long)keylen; x++) {
-        buf[x] = key[x];
-    }
-
-    if (x < 32) {
-       buf[x++] = (unsigned char)0x01;
-       while (x < 32) {
-           buf[x++] = (unsigned char)0;
-       }
-    }
-
-    /* copy key into 32-bit words */
-    for (x = 0; x < 8; x++) {
-        LOAD32L(lkey[x], &buf[x*4]);
-    }
-
-    /* expand using the LFSR to 140 words */
-    for (x = 0; x < 132; x++) {
-        t = lkey[x] ^ lkey[x+3] ^ lkey[x+5] ^ lkey[x+7] ^ x ^ 0x9E3779B9UL;
-        lkey[x + 8] = ROL(t, 11);
-    }
-
-    /* perform the substituions */
-    for (x = 0; x < 32; ) {
-       k_set( x,a,b,c,d);sb3(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb2(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb1(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb0(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb7(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb6(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb5(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-       k_set( x,a,b,c,d);sb4(a,b,c,d,e,f,g,h);k_get( x,e,f,g,h); ++x;
-    }
-    k_set(32,a,b,c,d);sb3(a,b,c,d,e,f,g,h);k_get(32,e,f,g,h);
-    return CRYPT_OK;
-}
-
-#ifdef CLEAN_STACK
-int serpent_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
-{
-   int x;
-   x = _serpent_setup(key, keylen, num_rounds, skey);
-   burn_stack(sizeof(unsigned long)*166 + sizeof(unsigned char)*32);
-   return x;
-}
-#endif
-
-#ifdef CLEAN_STACK
-static void _serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
-#else
-void serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
-#endif
-{
-    unsigned long a,b,c,d,e,f,g,h;
-    unsigned long t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
-
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(skey != NULL);
-
-    LOAD32L(a, &pt[0]);LOAD32L(b, &pt[4]);LOAD32L(c, &pt[8]);LOAD32L(d, &pt[12]);
-    k_xor( 0,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor( 1,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor( 2,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor( 3,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor( 4,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor( 5,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor( 6,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor( 7,e,f,g,h); sb7(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor( 8,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor( 9,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d); 
-    k_xor(10,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(11,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(12,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(13,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(14,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(15,e,f,g,h); sb7(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(16,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(17,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(18,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(19,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(20,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(21,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(22,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(23,e,f,g,h); sb7(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(24,a,b,c,d); sb0(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(25,e,f,g,h); sb1(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(26,a,b,c,d); sb2(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(27,e,f,g,h); sb3(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(28,a,b,c,d); sb4(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(29,e,f,g,h); sb5(e,f,g,h,a,b,c,d); rot(a,b,c,d);
-    k_xor(30,a,b,c,d); sb6(a,b,c,d,e,f,g,h); rot(e,f,g,h);
-    k_xor(31,e,f,g,h); sb7(e,f,g,h,a,b,c,d); k_xor(32,a,b,c,d);
-    STORE32L(a, &ct[0]);STORE32L(b, &ct[4]);STORE32L(c, &ct[8]);STORE32L(d, &ct[12]);
-}
-
-#ifdef CLEAN_STACK
-void serpent_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
-{
-   _serpent_ecb_encrypt(pt, ct, skey);
-   burn_stack(sizeof(unsigned long)*24);
-}
-#endif
-
-#ifdef CLEAN_STACK
-static void _serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
-#else
-void serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
-#endif
-{
-    unsigned long a,b,c,d,e,f,g,h;
-    unsigned long t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;
-
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(skey != NULL);
-
-    LOAD32L(a, &ct[0]);LOAD32L(b, &ct[4]);LOAD32L(c, &ct[8]);LOAD32L(d, &ct[12]);
-    k_xor(32,a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor(31,e,f,g,h);
-    irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor(30,a,b,c,d);
-    irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor(29,e,f,g,h);
-    irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor(28,a,b,c,d);
-    irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor(27,e,f,g,h);
-    irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor(26,a,b,c,d);
-    irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor(25,e,f,g,h);
-    irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor(24,a,b,c,d);
-    irot(a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor(23,e,f,g,h);
-    irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor(22,a,b,c,d);
-    irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor(21,e,f,g,h);
-    irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor(20,a,b,c,d);
-    irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor(19,e,f,g,h);
-    irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor(18,a,b,c,d);
-    irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor(17,e,f,g,h);
-    irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor(16,a,b,c,d);
-    irot(a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor(15,e,f,g,h);
-    irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor(14,a,b,c,d);
-    irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor(13,e,f,g,h);
-    irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor(12,a,b,c,d);
-    irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor(11,e,f,g,h);
-    irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor(10,a,b,c,d);
-    irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor( 9,e,f,g,h);
-    irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor( 8,a,b,c,d);
-    irot(a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor( 7,e,f,g,h);
-    irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor( 6,a,b,c,d);
-    irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor( 5,e,f,g,h);
-    irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor( 4,a,b,c,d);
-    irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor( 3,e,f,g,h);
-    irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor( 2,a,b,c,d);
-    irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor( 1,e,f,g,h);
-    irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor( 0,a,b,c,d);
-    STORE32L(a, &pt[0]);STORE32L(b, &pt[4]);STORE32L(c, &pt[8]);STORE32L(d, &pt[12]);
-}
-
-#ifdef CLEAN_STACK
-void serpent_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
-{
-   _serpent_ecb_decrypt(ct, pt, skey);
-   burn_stack(sizeof(unsigned long)*24);
-}
-#endif
-
-int serpent_test(void)
-{
-   static const struct {
-       int keylen;
-       unsigned char key[32], pt[16], ct[16];
-   } tests[] = {
-   {
-      16,
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0xdd, 0xd2, 0x6b, 0x98, 0xa5, 0xff, 0xd8, 0x2c,
-        0x05, 0x34, 0x5a, 0x9d, 0xad, 0xbf, 0xaf, 0x49 }
-   },
-   {
-      16,
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 },
-      { 0x4a, 0xe9, 0xa2, 0x0b, 0x2b, 0x14, 0xa1, 0x02,
-        0x90, 0xcb, 0xb8, 0x20, 0xb7, 0xff, 0xb5, 0x10 }
-   },
-   {
-      24,
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 },
-      { 0xe1, 0x1b, 0x01, 0x52, 0x4e, 0xa1, 0xf4, 0x65, 
-        0xa2, 0xa2, 0x00, 0x43, 0xeb, 0x9f, 0x7e, 0x8a }
-   },
-   {
-      32,
-      { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0xe0, 0x88, 0x5d, 0x44, 0x60, 0x37, 0x34, 0x69,
-        0xd1, 0xfa, 0x6c, 0x36, 0xa6, 0xe1, 0xc5, 0x2f }
-   },
-   {
-      32,
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x17, 0xc6, 0x25, 0x8e, 0x60, 0x09, 0xe2, 0x82,
-        0x66, 0x18, 0x69, 0xd5, 0x25, 0xf7, 0xd2, 0x04 }
-   },
-   {
-      32,
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
-      { 0x9f, 0xe1, 0x43, 0x25, 0x0d, 0x00, 0xe2, 0x56, 
-        0x96, 0xb0, 0x1e, 0x0a, 0x2e, 0xd0, 0x5d, 0xb3 }
-   }
-   };
-
-   unsigned char buf[2][16];
-   int x, err;
-   symmetric_key key;
-
-   for (x = 0; x < (int)(sizeof(tests) / sizeof(tests[0])); x++) {
-      /* setup key */
-      if ((err = serpent_setup(tests[x].key, tests[x].keylen, 0, &key))!= CRYPT_OK) {
-         return err;
-      }
-
-      /* encrypt and decrypt */
-      serpent_ecb_encrypt(tests[x].pt, buf[0], &key);
-      serpent_ecb_decrypt(buf[0], buf[1], &key);
-
-      /* compare */
-      if (memcmp(buf[0], tests[x].ct, 16) != 0 || memcmp(buf[1], tests[x].pt, 16) != 0) {
-         return CRYPT_FAIL_TESTVECTOR;
-      }
-   }
-   return CRYPT_OK;
-}
-
-int serpent_keysize(int *desired_keysize)
-{
-   _ARGCHK(desired_keysize != NULL);
-
-   if (*desired_keysize < 16)
-      return CRYPT_INVALID_KEYSIZE;
-   if (*desired_keysize > 32)
-      *desired_keysize = 32;
-   return CRYPT_OK;
-}
-
-#endif
-
-
diff --git a/sprng.c b/sprng.c
deleted file mode 100644
index db6e338..0000000
--- a/sprng.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* A secure PRNG using the RNG functions.  Basically this is a
- * wrapper that allows you to use a secure RNG as a PRNG
- * in the various other functions.
- */
-#include "mycrypt.h"
-
-#ifdef SPRNG
-
-const struct _prng_descriptor sprng_desc =
-{
-    "sprng",
-    &sprng_start,
-    &sprng_add_entropy,
-    &sprng_ready,
-    &sprng_read
-};
-
-int sprng_start(prng_state *prng)
-{
-   return CRYPT_OK;  
-}
-
-int sprng_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
-{
-   return CRYPT_OK;
-}
-
-int sprng_ready(prng_state *prng)
-{
-   return CRYPT_OK;
-}
-
-unsigned long sprng_read(unsigned char *buf, unsigned long len, prng_state *prng)
-{
-   _ARGCHK(buf != NULL);
-   return rng_get_bytes(buf, len, NULL);
-}
-
-#endif
-
-
- 
diff --git a/aes.c b/src/ciphers/aes/aes.c
similarity index 84%
rename from aes.c
rename to src/ciphers/aes/aes.c
index e0e4c96..0e4933f 100644
--- a/aes.c
+++ b/src/ciphers/aes/aes.c
@@ -6,7 +6,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
 /* AES implementation by Tom St Denis
@@ -25,8 +25,12 @@
   * @author Paulo Barreto <paulo.barreto@terra.com.br>
 ---
  */
+/**
+  @file aes.c
+  Implementation of AES
+*/   
 
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
 #ifdef RIJNDAEL
 
@@ -35,23 +39,28 @@
 #define SETUP    rijndael_setup
 #define ECB_ENC  rijndael_ecb_encrypt
 #define ECB_DEC  rijndael_ecb_decrypt
+#define ECB_DONE rijndael_done
 #define ECB_TEST rijndael_test
 #define ECB_KS   rijndael_keysize
 
-const struct _cipher_descriptor rijndael_desc =
+#if 0
+const struct ltc_cipher_descriptor rijndael_desc =
 {
     "rijndael",
     6,
     16, 32, 16, 10,
-    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_KS
+    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
+#endif
 
-const struct _cipher_descriptor aes_desc =
+const struct ltc_cipher_descriptor aes_desc =
 {
     "aes",
     6,
     16, 32, 16, 10,
-    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_KS
+    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 #else
@@ -59,21 +68,24 @@
 #define SETUP    rijndael_enc_setup
 #define ECB_ENC  rijndael_enc_ecb_encrypt
 #define ECB_KS   rijndael_enc_keysize
+#define ECB_DONE rijndael_enc_done
 
-const struct _cipher_descriptor rijndael_enc_desc =
+const struct ltc_cipher_descriptor rijndael_enc_desc =
 {
     "rijndael",
     6,
     16, 32, 16, 10,
-    SETUP, ECB_ENC, NULL, NULL, ECB_KS
+    SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
-const struct _cipher_descriptor aes_enc_desc =
+const struct ltc_cipher_descriptor aes_enc_desc =
 {
     "aes",
     6,
     16, 32, 16, 10,
-    SETUP, ECB_ENC, NULL, NULL, ECB_KS
+    SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 #endif
@@ -89,7 +101,7 @@
 }
 
 #ifndef ENCRYPT_ONLY
-
+#ifdef LTC_SMALL_CODE
 static ulong32 setup_mix2(ulong32 temp)
 {
    return Td0(255 & Te4[byte(temp, 3)]) ^
@@ -97,24 +109,32 @@
           Td2(255 & Te4[byte(temp, 1)]) ^
           Td3(255 & Te4[byte(temp, 0)]);
 }
-
+#endif
 #endif
 
-int SETUP(const unsigned char *key, int keylen, int rounds, symmetric_key *skey)
+ /**
+    Initialize the AES (Rijndael) block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+int SETUP(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
     int i, j;
     ulong32 temp, *rk;
 #ifndef ENCRYPT_ONLY
     ulong32 *rrk;
 #endif    
-    _ARGCHK(key  != NULL);
-    _ARGCHK(skey != NULL);
-    
+    LTC_ARGCHK(key  != NULL);
+    LTC_ARGCHK(skey != NULL);
+  
     if (keylen != 16 && keylen != 24 && keylen != 32) {
        return CRYPT_INVALID_KEYSIZE;
     }
     
-    if (rounds != 0 && rounds != (10 + ((keylen/8)-2)*2)) {
+    if (num_rounds != 0 && num_rounds != (10 + ((keylen/8)-2)*2)) {
        return CRYPT_INVALID_ROUNDS;
     }
     
@@ -181,7 +201,7 @@
                 break;
             }
             temp = rk[11];
-            rk[12] = rk[ 4] ^ setup_mix(ROR(temp, 8));
+            rk[12] = rk[ 4] ^ setup_mix(RORc(temp, 8));
             rk[13] = rk[ 5] ^ rk[12];
             rk[14] = rk[ 6] ^ rk[13];
             rk[15] = rk[ 7] ^ rk[14];
@@ -189,7 +209,7 @@
         }
     } else {
        /* this can't happen */
-       j = 4;
+       return CRYPT_ERROR;
     }
 
 #ifndef ENCRYPT_ONLY    
@@ -208,7 +228,7 @@
     for (i = 1; i < skey->rijndael.Nr; i++) {
         rrk -= 4;
         rk  += 4;
-    #ifdef SMALL_CODE        
+    #ifdef LTC_SMALL_CODE        
         temp = rrk[0];
         rk[0] = setup_mix2(temp);
         temp = rrk[1];
@@ -258,7 +278,13 @@
     return CRYPT_OK;   
 }
 
-#ifdef CLEAN_STACK
+/**
+  Encrypts a block of text with AES
+  @param pt The input plaintext (16 bytes)
+  @param ct The output ciphertext (16 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
 static void _rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) 
 #else
 void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
@@ -267,9 +293,9 @@
     ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
     int Nr, r;
    
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(pt != NULL);
+    LTC_ARGCHK(ct != NULL);
+    LTC_ARGCHK(skey != NULL);
     
     Nr = skey->rijndael.Nr;
     rk = skey->rijndael.eK;
@@ -284,7 +310,7 @@
     LOAD32H(s3, pt  + 12); s3 ^= rk[3];
 
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
 
     for (r = 0; ; r++) {
         rk += 4;
@@ -418,7 +444,7 @@
     STORE32H(s3, ct+12);
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) 
 {
    _rijndael_ecb_encrypt(pt, ct, skey);
@@ -428,7 +454,13 @@
 
 #ifndef ENCRYPT_ONLY 
 
-#ifdef CLEAN_STACK
+/**
+  Decrypts a block of text with AES
+  @param ct The input ciphertext (16 bytes)
+  @param pt The output plaintext (16 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
 static void _rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 
 #else
 void ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
@@ -437,9 +469,9 @@
     ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
     int Nr, r;
 
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(pt != NULL);
+    LTC_ARGCHK(ct != NULL);
+    LTC_ARGCHK(skey != NULL);
     
     Nr = skey->rijndael.Nr;
     rk = skey->rijndael.dK;
@@ -453,7 +485,7 @@
     LOAD32H(s2, ct  +  8); s2 ^= rk[2];
     LOAD32H(s3, ct  + 12); s3 ^= rk[3];
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     for (r = 0; ; r++) {
         rk += 4;
         t0 =
@@ -588,7 +620,7 @@
 }
 
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 void ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 
 {
    _rijndael_ecb_decrypt(ct, pt, skey);
@@ -596,6 +628,10 @@
 }
 #endif
 
+/**
+  Performs a self-test of the AES block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int ECB_TEST(void)
 {
  #ifndef LTC_TEST
@@ -679,23 +715,41 @@
 
 #endif /* ENCRYPT_ONLY */
 
-int ECB_KS(int *desired_keysize)
-{
-   _ARGCHK(desired_keysize != NULL);
 
-   if (*desired_keysize < 16)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void ECB_DONE(symmetric_key *skey)
+{
+}
+
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int ECB_KS(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+
+   if (*keysize < 16)
       return CRYPT_INVALID_KEYSIZE;
-   if (*desired_keysize < 24) {
-      *desired_keysize = 16;
+   if (*keysize < 24) {
+      *keysize = 16;
       return CRYPT_OK;
-   } else if (*desired_keysize < 32) {
-      *desired_keysize = 24;
+   } else if (*keysize < 32) {
+      *keysize = 24;
       return CRYPT_OK;
    } else {
-      *desired_keysize = 32;
+      *keysize = 32;
       return CRYPT_OK;
    }
 }
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/aes/aes.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/aes_tab.c b/src/ciphers/aes/aes_tab.c
similarity index 98%
rename from aes_tab.c
rename to src/ciphers/aes/aes_tab.c
index cb450a7..31d276e 100644
--- a/aes_tab.c
+++ b/src/ciphers/aes/aes_tab.c
@@ -6,7 +6,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 /* The precomputed tables for AES */
 /*
@@ -23,6 +23,10 @@
 Td4[x] = Si[x].[01, 01, 01, 01];
 */
 
+/**
+  @file aes_tab.c
+  AES tables
+*/  
 static const ulong32 TE0[256] = {
     0xc66363a5UL, 0xf87c7c84UL, 0xee777799UL, 0xf67b7b8dUL,
     0xfff2f20dUL, 0xd66b6bbdUL, 0xde6f6fb1UL, 0x91c5c554UL,
@@ -295,17 +299,17 @@
 
 #endif /* ENCRYPT_ONLY */
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
 
 #define Te0(x) TE0[x]
-#define Te1(x) ROR(TE0[x], 8)
-#define Te2(x) ROR(TE0[x], 16)
-#define Te3(x) ROR(TE0[x], 24)
+#define Te1(x) RORc(TE0[x], 8)
+#define Te2(x) RORc(TE0[x], 16)
+#define Te3(x) RORc(TE0[x], 24)
 
 #define Td0(x) TD0[x]
-#define Td1(x) ROR(TD0[x], 8)
-#define Td2(x) ROR(TD0[x], 16)
-#define Td3(x) ROR(TD0[x], 24)
+#define Td1(x) RORc(TD0[x], 8)
+#define Td2(x) RORc(TD0[x], 16)
+#define Td3(x) RORc(TD0[x], 24)
 
 #define Te4_0 0x000000FF & Te4
 #define Te4_1 0x0000FF00 & Te4
@@ -1014,3 +1018,7 @@
     0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL,
     0x1B000000UL, 0x36000000UL, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
 };
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/aes/aes_tab.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/ciphers/anubis.c b/src/ciphers/anubis.c
new file mode 100644
index 0000000..511eac2
--- /dev/null
+++ b/src/ciphers/anubis.c
@@ -0,0 +1,1554 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis

+ *

+ * LibTomCrypt is a library that provides various cryptographic

+ * algorithms in a highly modular and flexible manner.

+ *

+ * The library is free for all purposes without any express

+ * guarantee it works.

+ *

+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org

+ */

+

+/**

+  @file anubis.c

+  Anubis implementation derived from public domain source

+  Authors: Paulo S.L.M. Barreto and Vincent Rijmen.

+*/

+

+#include "tomcrypt.h"

+

+#ifdef ANUBIS

+

+const struct ltc_cipher_descriptor anubis_desc = {

+   "anubis",

+   19,

+   16, 40, 16, 12,

+   &anubis_setup,

+   &anubis_ecb_encrypt,

+   &anubis_ecb_decrypt,

+   &anubis_test,

+   &anubis_done,

+   &anubis_keysize,

+   NULL, NULL, NULL, NULL, NULL, NULL, NULL

+};

+

+#define MIN_N           4 

+#define MAX_N           10 

+#define MIN_ROUNDS      (8 + MIN_N) 

+#define MAX_ROUNDS      (8 + MAX_N) 

+#define MIN_KEYSIZEB    (4*MIN_N) 

+#define MAX_KEYSIZEB    (4*MAX_N) 

+#define BLOCKSIZE       128 

+#define BLOCKSIZEB      (BLOCKSIZE/8) 

+

+

+/*

+ * Though Anubis is endianness-neutral, the encryption tables are listed

+ * in BIG-ENDIAN format, which is adopted throughout this implementation

+ * (but little-endian notation would be equally suitable if consistently

+ * employed).

+ */

+#if defined(ANUBIS_TWEAK)

+

+static const ulong32 T0[256] = {

+    0xba69d2bbU, 0x54a84de5U, 0x2f5ebce2U, 0x74e8cd25U,

+    0x53a651f7U, 0xd3bb6bd0U, 0xd2b96fd6U, 0x4d9a29b3U,

+    0x50a05dfdU, 0xac458acfU, 0x8d070e09U, 0xbf63c6a5U,

+    0x70e0dd3dU, 0x52a455f1U, 0x9a29527bU, 0x4c982db5U,

+    0xeac98f46U, 0xd5b773c4U, 0x97336655U, 0xd1bf63dcU,

+    0x3366ccaaU, 0x51a259fbU, 0x5bb671c7U, 0xa651a2f3U,

+    0xdea15ffeU, 0x48903dadU, 0xa84d9ad7U, 0x992f5e71U,

+    0xdbab4be0U, 0x3264c8acU, 0xb773e695U, 0xfce5d732U,

+    0xe3dbab70U, 0x9e214263U, 0x913f7e41U, 0x9b2b567dU,

+    0xe2d9af76U, 0xbb6bd6bdU, 0x4182199bU, 0x6edca579U,

+    0xa557aef9U, 0xcb8b0b80U, 0x6bd6b167U, 0x95376e59U,

+    0xa15fbee1U, 0xf3fbeb10U, 0xb17ffe81U, 0x0204080cU,

+    0xcc851792U, 0xc49537a2U, 0x1d3a744eU, 0x14285078U,

+    0xc39b2bb0U, 0x63c69157U, 0xdaa94fe6U, 0x5dba69d3U,

+    0x5fbe61dfU, 0xdca557f2U, 0x7dfae913U, 0xcd871394U,

+    0x7ffee11fU, 0x5ab475c1U, 0x6cd8ad75U, 0x5cb86dd5U,

+    0xf7f3fb08U, 0x264c98d4U, 0xffe3db38U, 0xedc79354U,

+    0xe8cd874aU, 0x9d274e69U, 0x6fdea17fU, 0x8e010203U,

+    0x19326456U, 0xa05dbae7U, 0xf0fde71aU, 0x890f1e11U,

+    0x0f1e3c22U, 0x070e1c12U, 0xaf4386c5U, 0xfbebcb20U,

+    0x08102030U, 0x152a547eU, 0x0d1a342eU, 0x04081018U,

+    0x01020406U, 0x64c88d45U, 0xdfa35bf8U, 0x76ecc529U,

+    0x79f2f90bU, 0xdda753f4U, 0x3d7af48eU, 0x162c5874U,

+    0x3f7efc82U, 0x376edcb2U, 0x6ddaa973U, 0x3870e090U,

+    0xb96fdeb1U, 0x73e6d137U, 0xe9cf834cU, 0x356ad4beU,

+    0x55aa49e3U, 0x71e2d93bU, 0x7bf6f107U, 0x8c050a0fU,

+    0x72e4d531U, 0x880d1a17U, 0xf6f1ff0eU, 0x2a54a8fcU,

+    0x3e7cf884U, 0x5ebc65d9U, 0x274e9cd2U, 0x468c0589U,

+    0x0c183028U, 0x65ca8943U, 0x68d0bd6dU, 0x61c2995bU,

+    0x03060c0aU, 0xc19f23bcU, 0x57ae41efU, 0xd6b17fceU,

+    0xd9af43ecU, 0x58b07dcdU, 0xd8ad47eaU, 0x66cc8549U,

+    0xd7b37bc8U, 0x3a74e89cU, 0xc88d078aU, 0x3c78f088U,

+    0xfae9cf26U, 0x96316253U, 0xa753a6f5U, 0x982d5a77U,

+    0xecc59752U, 0xb86ddab7U, 0xc7933ba8U, 0xae4182c3U,

+    0x69d2b96bU, 0x4b9631a7U, 0xab4b96ddU, 0xa94f9ed1U,

+    0x67ce814fU, 0x0a14283cU, 0x478e018fU, 0xf2f9ef16U,

+    0xb577ee99U, 0x224488ccU, 0xe5d7b364U, 0xeec19f5eU,

+    0xbe61c2a3U, 0x2b56acfaU, 0x811f3e21U, 0x1224486cU,

+    0x831b362dU, 0x1b366c5aU, 0x0e1c3824U, 0x23468ccaU,

+    0xf5f7f304U, 0x458a0983U, 0x214284c6U, 0xce811f9eU,

+    0x499239abU, 0x2c58b0e8U, 0xf9efc32cU, 0xe6d1bf6eU,

+    0xb671e293U, 0x2850a0f0U, 0x172e5c72U, 0x8219322bU,

+    0x1a34685cU, 0x8b0b161dU, 0xfee1df3eU, 0x8a09121bU,

+    0x09122436U, 0xc98f038cU, 0x87132635U, 0x4e9c25b9U,

+    0xe1dfa37cU, 0x2e5cb8e4U, 0xe4d5b762U, 0xe0dda77aU,

+    0xebcb8b40U, 0x903d7a47U, 0xa455aaffU, 0x1e3c7844U,

+    0x85172e39U, 0x60c09d5dU, 0x00000000U, 0x254a94deU,

+    0xf4f5f702U, 0xf1ffe31cU, 0x94356a5fU, 0x0b162c3aU,

+    0xe7d3bb68U, 0x75eac923U, 0xefc39b58U, 0x3468d0b8U,

+    0x3162c4a6U, 0xd4b577c2U, 0xd0bd67daU, 0x86112233U,

+    0x7efce519U, 0xad478ec9U, 0xfde7d334U, 0x2952a4f6U,

+    0x3060c0a0U, 0x3b76ec9aU, 0x9f234665U, 0xf8edc72aU,

+    0xc6913faeU, 0x13264c6aU, 0x060c1814U, 0x050a141eU,

+    0xc59733a4U, 0x11224466U, 0x77eec12fU, 0x7cf8ed15U,

+    0x7af4f501U, 0x78f0fd0dU, 0x366cd8b4U, 0x1c387048U,

+    0x3972e496U, 0x59b279cbU, 0x18306050U, 0x56ac45e9U,

+    0xb37bf68dU, 0xb07dfa87U, 0x244890d8U, 0x204080c0U,

+    0xb279f28bU, 0x9239724bU, 0xa35bb6edU, 0xc09d27baU,

+    0x44880d85U, 0x62c49551U, 0x10204060U, 0xb475ea9fU,

+    0x84152a3fU, 0x43861197U, 0x933b764dU, 0xc2992fb6U,

+    0x4a9435a1U, 0xbd67cea9U, 0x8f030605U, 0x2d5ab4eeU,

+    0xbc65caafU, 0x9c254a6fU, 0x6ad4b561U, 0x40801d9dU,

+    0xcf831b98U, 0xa259b2ebU, 0x801d3a27U, 0x4f9e21bfU,

+    0x1f3e7c42U, 0xca890f86U, 0xaa4992dbU, 0x42841591U,

+};

+

+static const ulong32 T1[256] = {

+    0x69babbd2U, 0xa854e54dU, 0x5e2fe2bcU, 0xe87425cdU,

+    0xa653f751U, 0xbbd3d06bU, 0xb9d2d66fU, 0x9a4db329U,

+    0xa050fd5dU, 0x45accf8aU, 0x078d090eU, 0x63bfa5c6U,

+    0xe0703dddU, 0xa452f155U, 0x299a7b52U, 0x984cb52dU,

+    0xc9ea468fU, 0xb7d5c473U, 0x33975566U, 0xbfd1dc63U,

+    0x6633aaccU, 0xa251fb59U, 0xb65bc771U, 0x51a6f3a2U,

+    0xa1defe5fU, 0x9048ad3dU, 0x4da8d79aU, 0x2f99715eU,

+    0xabdbe04bU, 0x6432acc8U, 0x73b795e6U, 0xe5fc32d7U,

+    0xdbe370abU, 0x219e6342U, 0x3f91417eU, 0x2b9b7d56U,

+    0xd9e276afU, 0x6bbbbdd6U, 0x82419b19U, 0xdc6e79a5U,

+    0x57a5f9aeU, 0x8bcb800bU, 0xd66b67b1U, 0x3795596eU,

+    0x5fa1e1beU, 0xfbf310ebU, 0x7fb181feU, 0x04020c08U,

+    0x85cc9217U, 0x95c4a237U, 0x3a1d4e74U, 0x28147850U,

+    0x9bc3b02bU, 0xc6635791U, 0xa9dae64fU, 0xba5dd369U,

+    0xbe5fdf61U, 0xa5dcf257U, 0xfa7d13e9U, 0x87cd9413U,

+    0xfe7f1fe1U, 0xb45ac175U, 0xd86c75adU, 0xb85cd56dU,

+    0xf3f708fbU, 0x4c26d498U, 0xe3ff38dbU, 0xc7ed5493U,

+    0xcde84a87U, 0x279d694eU, 0xde6f7fa1U, 0x018e0302U,

+    0x32195664U, 0x5da0e7baU, 0xfdf01ae7U, 0x0f89111eU,

+    0x1e0f223cU, 0x0e07121cU, 0x43afc586U, 0xebfb20cbU,

+    0x10083020U, 0x2a157e54U, 0x1a0d2e34U, 0x08041810U,

+    0x02010604U, 0xc864458dU, 0xa3dff85bU, 0xec7629c5U,

+    0xf2790bf9U, 0xa7ddf453U, 0x7a3d8ef4U, 0x2c167458U,

+    0x7e3f82fcU, 0x6e37b2dcU, 0xda6d73a9U, 0x703890e0U,

+    0x6fb9b1deU, 0xe67337d1U, 0xcfe94c83U, 0x6a35bed4U,

+    0xaa55e349U, 0xe2713bd9U, 0xf67b07f1U, 0x058c0f0aU,

+    0xe47231d5U, 0x0d88171aU, 0xf1f60effU, 0x542afca8U,

+    0x7c3e84f8U, 0xbc5ed965U, 0x4e27d29cU, 0x8c468905U,

+    0x180c2830U, 0xca654389U, 0xd0686dbdU, 0xc2615b99U,

+    0x06030a0cU, 0x9fc1bc23U, 0xae57ef41U, 0xb1d6ce7fU,

+    0xafd9ec43U, 0xb058cd7dU, 0xadd8ea47U, 0xcc664985U,

+    0xb3d7c87bU, 0x743a9ce8U, 0x8dc88a07U, 0x783c88f0U,

+    0xe9fa26cfU, 0x31965362U, 0x53a7f5a6U, 0x2d98775aU,

+    0xc5ec5297U, 0x6db8b7daU, 0x93c7a83bU, 0x41aec382U,

+    0xd2696bb9U, 0x964ba731U, 0x4babdd96U, 0x4fa9d19eU,

+    0xce674f81U, 0x140a3c28U, 0x8e478f01U, 0xf9f216efU,

+    0x77b599eeU, 0x4422cc88U, 0xd7e564b3U, 0xc1ee5e9fU,

+    0x61bea3c2U, 0x562bfaacU, 0x1f81213eU, 0x24126c48U,

+    0x1b832d36U, 0x361b5a6cU, 0x1c0e2438U, 0x4623ca8cU,

+    0xf7f504f3U, 0x8a458309U, 0x4221c684U, 0x81ce9e1fU,

+    0x9249ab39U, 0x582ce8b0U, 0xeff92cc3U, 0xd1e66ebfU,

+    0x71b693e2U, 0x5028f0a0U, 0x2e17725cU, 0x19822b32U,

+    0x341a5c68U, 0x0b8b1d16U, 0xe1fe3edfU, 0x098a1b12U,

+    0x12093624U, 0x8fc98c03U, 0x13873526U, 0x9c4eb925U,

+    0xdfe17ca3U, 0x5c2ee4b8U, 0xd5e462b7U, 0xdde07aa7U,

+    0xcbeb408bU, 0x3d90477aU, 0x55a4ffaaU, 0x3c1e4478U,

+    0x1785392eU, 0xc0605d9dU, 0x00000000U, 0x4a25de94U,

+    0xf5f402f7U, 0xfff11ce3U, 0x35945f6aU, 0x160b3a2cU,

+    0xd3e768bbU, 0xea7523c9U, 0xc3ef589bU, 0x6834b8d0U,

+    0x6231a6c4U, 0xb5d4c277U, 0xbdd0da67U, 0x11863322U,

+    0xfc7e19e5U, 0x47adc98eU, 0xe7fd34d3U, 0x5229f6a4U,

+    0x6030a0c0U, 0x763b9aecU, 0x239f6546U, 0xedf82ac7U,

+    0x91c6ae3fU, 0x26136a4cU, 0x0c061418U, 0x0a051e14U,

+    0x97c5a433U, 0x22116644U, 0xee772fc1U, 0xf87c15edU,

+    0xf47a01f5U, 0xf0780dfdU, 0x6c36b4d8U, 0x381c4870U,

+    0x723996e4U, 0xb259cb79U, 0x30185060U, 0xac56e945U,

+    0x7bb38df6U, 0x7db087faU, 0x4824d890U, 0x4020c080U,

+    0x79b28bf2U, 0x39924b72U, 0x5ba3edb6U, 0x9dc0ba27U,

+    0x8844850dU, 0xc4625195U, 0x20106040U, 0x75b49feaU,

+    0x15843f2aU, 0x86439711U, 0x3b934d76U, 0x99c2b62fU,

+    0x944aa135U, 0x67bda9ceU, 0x038f0506U, 0x5a2deeb4U,

+    0x65bcafcaU, 0x259c6f4aU, 0xd46a61b5U, 0x80409d1dU,

+    0x83cf981bU, 0x59a2ebb2U, 0x1d80273aU, 0x9e4fbf21U,

+    0x3e1f427cU, 0x89ca860fU, 0x49aadb92U, 0x84429115U,

+};

+

+static const ulong32 T2[256] = {

+    0xd2bbba69U, 0x4de554a8U, 0xbce22f5eU, 0xcd2574e8U,

+    0x51f753a6U, 0x6bd0d3bbU, 0x6fd6d2b9U, 0x29b34d9aU,

+    0x5dfd50a0U, 0x8acfac45U, 0x0e098d07U, 0xc6a5bf63U,

+    0xdd3d70e0U, 0x55f152a4U, 0x527b9a29U, 0x2db54c98U,

+    0x8f46eac9U, 0x73c4d5b7U, 0x66559733U, 0x63dcd1bfU,

+    0xccaa3366U, 0x59fb51a2U, 0x71c75bb6U, 0xa2f3a651U,

+    0x5ffedea1U, 0x3dad4890U, 0x9ad7a84dU, 0x5e71992fU,

+    0x4be0dbabU, 0xc8ac3264U, 0xe695b773U, 0xd732fce5U,

+    0xab70e3dbU, 0x42639e21U, 0x7e41913fU, 0x567d9b2bU,

+    0xaf76e2d9U, 0xd6bdbb6bU, 0x199b4182U, 0xa5796edcU,

+    0xaef9a557U, 0x0b80cb8bU, 0xb1676bd6U, 0x6e599537U,

+    0xbee1a15fU, 0xeb10f3fbU, 0xfe81b17fU, 0x080c0204U,

+    0x1792cc85U, 0x37a2c495U, 0x744e1d3aU, 0x50781428U,

+    0x2bb0c39bU, 0x915763c6U, 0x4fe6daa9U, 0x69d35dbaU,

+    0x61df5fbeU, 0x57f2dca5U, 0xe9137dfaU, 0x1394cd87U,

+    0xe11f7ffeU, 0x75c15ab4U, 0xad756cd8U, 0x6dd55cb8U,

+    0xfb08f7f3U, 0x98d4264cU, 0xdb38ffe3U, 0x9354edc7U,

+    0x874ae8cdU, 0x4e699d27U, 0xa17f6fdeU, 0x02038e01U,

+    0x64561932U, 0xbae7a05dU, 0xe71af0fdU, 0x1e11890fU,

+    0x3c220f1eU, 0x1c12070eU, 0x86c5af43U, 0xcb20fbebU,

+    0x20300810U, 0x547e152aU, 0x342e0d1aU, 0x10180408U,

+    0x04060102U, 0x8d4564c8U, 0x5bf8dfa3U, 0xc52976ecU,

+    0xf90b79f2U, 0x53f4dda7U, 0xf48e3d7aU, 0x5874162cU,

+    0xfc823f7eU, 0xdcb2376eU, 0xa9736ddaU, 0xe0903870U,

+    0xdeb1b96fU, 0xd13773e6U, 0x834ce9cfU, 0xd4be356aU,

+    0x49e355aaU, 0xd93b71e2U, 0xf1077bf6U, 0x0a0f8c05U,

+    0xd53172e4U, 0x1a17880dU, 0xff0ef6f1U, 0xa8fc2a54U,

+    0xf8843e7cU, 0x65d95ebcU, 0x9cd2274eU, 0x0589468cU,

+    0x30280c18U, 0x894365caU, 0xbd6d68d0U, 0x995b61c2U,

+    0x0c0a0306U, 0x23bcc19fU, 0x41ef57aeU, 0x7fced6b1U,

+    0x43ecd9afU, 0x7dcd58b0U, 0x47ead8adU, 0x854966ccU,

+    0x7bc8d7b3U, 0xe89c3a74U, 0x078ac88dU, 0xf0883c78U,

+    0xcf26fae9U, 0x62539631U, 0xa6f5a753U, 0x5a77982dU,

+    0x9752ecc5U, 0xdab7b86dU, 0x3ba8c793U, 0x82c3ae41U,

+    0xb96b69d2U, 0x31a74b96U, 0x96ddab4bU, 0x9ed1a94fU,

+    0x814f67ceU, 0x283c0a14U, 0x018f478eU, 0xef16f2f9U,

+    0xee99b577U, 0x88cc2244U, 0xb364e5d7U, 0x9f5eeec1U,

+    0xc2a3be61U, 0xacfa2b56U, 0x3e21811fU, 0x486c1224U,

+    0x362d831bU, 0x6c5a1b36U, 0x38240e1cU, 0x8cca2346U,

+    0xf304f5f7U, 0x0983458aU, 0x84c62142U, 0x1f9ece81U,

+    0x39ab4992U, 0xb0e82c58U, 0xc32cf9efU, 0xbf6ee6d1U,

+    0xe293b671U, 0xa0f02850U, 0x5c72172eU, 0x322b8219U,

+    0x685c1a34U, 0x161d8b0bU, 0xdf3efee1U, 0x121b8a09U,

+    0x24360912U, 0x038cc98fU, 0x26358713U, 0x25b94e9cU,

+    0xa37ce1dfU, 0xb8e42e5cU, 0xb762e4d5U, 0xa77ae0ddU,

+    0x8b40ebcbU, 0x7a47903dU, 0xaaffa455U, 0x78441e3cU,

+    0x2e398517U, 0x9d5d60c0U, 0x00000000U, 0x94de254aU,

+    0xf702f4f5U, 0xe31cf1ffU, 0x6a5f9435U, 0x2c3a0b16U,

+    0xbb68e7d3U, 0xc92375eaU, 0x9b58efc3U, 0xd0b83468U,

+    0xc4a63162U, 0x77c2d4b5U, 0x67dad0bdU, 0x22338611U,

+    0xe5197efcU, 0x8ec9ad47U, 0xd334fde7U, 0xa4f62952U,

+    0xc0a03060U, 0xec9a3b76U, 0x46659f23U, 0xc72af8edU,

+    0x3faec691U, 0x4c6a1326U, 0x1814060cU, 0x141e050aU,

+    0x33a4c597U, 0x44661122U, 0xc12f77eeU, 0xed157cf8U,

+    0xf5017af4U, 0xfd0d78f0U, 0xd8b4366cU, 0x70481c38U,

+    0xe4963972U, 0x79cb59b2U, 0x60501830U, 0x45e956acU,

+    0xf68db37bU, 0xfa87b07dU, 0x90d82448U, 0x80c02040U,

+    0xf28bb279U, 0x724b9239U, 0xb6eda35bU, 0x27bac09dU,

+    0x0d854488U, 0x955162c4U, 0x40601020U, 0xea9fb475U,

+    0x2a3f8415U, 0x11974386U, 0x764d933bU, 0x2fb6c299U,

+    0x35a14a94U, 0xcea9bd67U, 0x06058f03U, 0xb4ee2d5aU,

+    0xcaafbc65U, 0x4a6f9c25U, 0xb5616ad4U, 0x1d9d4080U,

+    0x1b98cf83U, 0xb2eba259U, 0x3a27801dU, 0x21bf4f9eU,

+    0x7c421f3eU, 0x0f86ca89U, 0x92dbaa49U, 0x15914284U,

+};

+

+static const ulong32 T3[256] = {

+    0xbbd269baU, 0xe54da854U, 0xe2bc5e2fU, 0x25cde874U,

+    0xf751a653U, 0xd06bbbd3U, 0xd66fb9d2U, 0xb3299a4dU,

+    0xfd5da050U, 0xcf8a45acU, 0x090e078dU, 0xa5c663bfU,

+    0x3ddde070U, 0xf155a452U, 0x7b52299aU, 0xb52d984cU,

+    0x468fc9eaU, 0xc473b7d5U, 0x55663397U, 0xdc63bfd1U,

+    0xaacc6633U, 0xfb59a251U, 0xc771b65bU, 0xf3a251a6U,

+    0xfe5fa1deU, 0xad3d9048U, 0xd79a4da8U, 0x715e2f99U,

+    0xe04babdbU, 0xacc86432U, 0x95e673b7U, 0x32d7e5fcU,

+    0x70abdbe3U, 0x6342219eU, 0x417e3f91U, 0x7d562b9bU,

+    0x76afd9e2U, 0xbdd66bbbU, 0x9b198241U, 0x79a5dc6eU,

+    0xf9ae57a5U, 0x800b8bcbU, 0x67b1d66bU, 0x596e3795U,

+    0xe1be5fa1U, 0x10ebfbf3U, 0x81fe7fb1U, 0x0c080402U,

+    0x921785ccU, 0xa23795c4U, 0x4e743a1dU, 0x78502814U,

+    0xb02b9bc3U, 0x5791c663U, 0xe64fa9daU, 0xd369ba5dU,

+    0xdf61be5fU, 0xf257a5dcU, 0x13e9fa7dU, 0x941387cdU,

+    0x1fe1fe7fU, 0xc175b45aU, 0x75add86cU, 0xd56db85cU,

+    0x08fbf3f7U, 0xd4984c26U, 0x38dbe3ffU, 0x5493c7edU,

+    0x4a87cde8U, 0x694e279dU, 0x7fa1de6fU, 0x0302018eU,

+    0x56643219U, 0xe7ba5da0U, 0x1ae7fdf0U, 0x111e0f89U,

+    0x223c1e0fU, 0x121c0e07U, 0xc58643afU, 0x20cbebfbU,

+    0x30201008U, 0x7e542a15U, 0x2e341a0dU, 0x18100804U,

+    0x06040201U, 0x458dc864U, 0xf85ba3dfU, 0x29c5ec76U,

+    0x0bf9f279U, 0xf453a7ddU, 0x8ef47a3dU, 0x74582c16U,

+    0x82fc7e3fU, 0xb2dc6e37U, 0x73a9da6dU, 0x90e07038U,

+    0xb1de6fb9U, 0x37d1e673U, 0x4c83cfe9U, 0xbed46a35U,

+    0xe349aa55U, 0x3bd9e271U, 0x07f1f67bU, 0x0f0a058cU,

+    0x31d5e472U, 0x171a0d88U, 0x0efff1f6U, 0xfca8542aU,

+    0x84f87c3eU, 0xd965bc5eU, 0xd29c4e27U, 0x89058c46U,

+    0x2830180cU, 0x4389ca65U, 0x6dbdd068U, 0x5b99c261U,

+    0x0a0c0603U, 0xbc239fc1U, 0xef41ae57U, 0xce7fb1d6U,

+    0xec43afd9U, 0xcd7db058U, 0xea47add8U, 0x4985cc66U,

+    0xc87bb3d7U, 0x9ce8743aU, 0x8a078dc8U, 0x88f0783cU,

+    0x26cfe9faU, 0x53623196U, 0xf5a653a7U, 0x775a2d98U,

+    0x5297c5ecU, 0xb7da6db8U, 0xa83b93c7U, 0xc38241aeU,

+    0x6bb9d269U, 0xa731964bU, 0xdd964babU, 0xd19e4fa9U,

+    0x4f81ce67U, 0x3c28140aU, 0x8f018e47U, 0x16eff9f2U,

+    0x99ee77b5U, 0xcc884422U, 0x64b3d7e5U, 0x5e9fc1eeU,

+    0xa3c261beU, 0xfaac562bU, 0x213e1f81U, 0x6c482412U,

+    0x2d361b83U, 0x5a6c361bU, 0x24381c0eU, 0xca8c4623U,

+    0x04f3f7f5U, 0x83098a45U, 0xc6844221U, 0x9e1f81ceU,

+    0xab399249U, 0xe8b0582cU, 0x2cc3eff9U, 0x6ebfd1e6U,

+    0x93e271b6U, 0xf0a05028U, 0x725c2e17U, 0x2b321982U,

+    0x5c68341aU, 0x1d160b8bU, 0x3edfe1feU, 0x1b12098aU,

+    0x36241209U, 0x8c038fc9U, 0x35261387U, 0xb9259c4eU,

+    0x7ca3dfe1U, 0xe4b85c2eU, 0x62b7d5e4U, 0x7aa7dde0U,

+    0x408bcbebU, 0x477a3d90U, 0xffaa55a4U, 0x44783c1eU,

+    0x392e1785U, 0x5d9dc060U, 0x00000000U, 0xde944a25U,

+    0x02f7f5f4U, 0x1ce3fff1U, 0x5f6a3594U, 0x3a2c160bU,

+    0x68bbd3e7U, 0x23c9ea75U, 0x589bc3efU, 0xb8d06834U,

+    0xa6c46231U, 0xc277b5d4U, 0xda67bdd0U, 0x33221186U,

+    0x19e5fc7eU, 0xc98e47adU, 0x34d3e7fdU, 0xf6a45229U,

+    0xa0c06030U, 0x9aec763bU, 0x6546239fU, 0x2ac7edf8U,

+    0xae3f91c6U, 0x6a4c2613U, 0x14180c06U, 0x1e140a05U,

+    0xa43397c5U, 0x66442211U, 0x2fc1ee77U, 0x15edf87cU,

+    0x01f5f47aU, 0x0dfdf078U, 0xb4d86c36U, 0x4870381cU,

+    0x96e47239U, 0xcb79b259U, 0x50603018U, 0xe945ac56U,

+    0x8df67bb3U, 0x87fa7db0U, 0xd8904824U, 0xc0804020U,

+    0x8bf279b2U, 0x4b723992U, 0xedb65ba3U, 0xba279dc0U,

+    0x850d8844U, 0x5195c462U, 0x60402010U, 0x9fea75b4U,

+    0x3f2a1584U, 0x97118643U, 0x4d763b93U, 0xb62f99c2U,

+    0xa135944aU, 0xa9ce67bdU, 0x0506038fU, 0xeeb45a2dU,

+    0xafca65bcU, 0x6f4a259cU, 0x61b5d46aU, 0x9d1d8040U,

+    0x981b83cfU, 0xebb259a2U, 0x273a1d80U, 0xbf219e4fU,

+    0x427c3e1fU, 0x860f89caU, 0xdb9249aaU, 0x91158442U,

+};

+

+static const ulong32 T4[256] = {

+    0xbabababaU, 0x54545454U, 0x2f2f2f2fU, 0x74747474U,

+    0x53535353U, 0xd3d3d3d3U, 0xd2d2d2d2U, 0x4d4d4d4dU,

+    0x50505050U, 0xacacacacU, 0x8d8d8d8dU, 0xbfbfbfbfU,

+    0x70707070U, 0x52525252U, 0x9a9a9a9aU, 0x4c4c4c4cU,

+    0xeaeaeaeaU, 0xd5d5d5d5U, 0x97979797U, 0xd1d1d1d1U,

+    0x33333333U, 0x51515151U, 0x5b5b5b5bU, 0xa6a6a6a6U,

+    0xdedededeU, 0x48484848U, 0xa8a8a8a8U, 0x99999999U,

+    0xdbdbdbdbU, 0x32323232U, 0xb7b7b7b7U, 0xfcfcfcfcU,

+    0xe3e3e3e3U, 0x9e9e9e9eU, 0x91919191U, 0x9b9b9b9bU,

+    0xe2e2e2e2U, 0xbbbbbbbbU, 0x41414141U, 0x6e6e6e6eU,

+    0xa5a5a5a5U, 0xcbcbcbcbU, 0x6b6b6b6bU, 0x95959595U,

+    0xa1a1a1a1U, 0xf3f3f3f3U, 0xb1b1b1b1U, 0x02020202U,

+    0xccccccccU, 0xc4c4c4c4U, 0x1d1d1d1dU, 0x14141414U,

+    0xc3c3c3c3U, 0x63636363U, 0xdadadadaU, 0x5d5d5d5dU,

+    0x5f5f5f5fU, 0xdcdcdcdcU, 0x7d7d7d7dU, 0xcdcdcdcdU,

+    0x7f7f7f7fU, 0x5a5a5a5aU, 0x6c6c6c6cU, 0x5c5c5c5cU,

+    0xf7f7f7f7U, 0x26262626U, 0xffffffffU, 0xededededU,

+    0xe8e8e8e8U, 0x9d9d9d9dU, 0x6f6f6f6fU, 0x8e8e8e8eU,

+    0x19191919U, 0xa0a0a0a0U, 0xf0f0f0f0U, 0x89898989U,

+    0x0f0f0f0fU, 0x07070707U, 0xafafafafU, 0xfbfbfbfbU,

+    0x08080808U, 0x15151515U, 0x0d0d0d0dU, 0x04040404U,

+    0x01010101U, 0x64646464U, 0xdfdfdfdfU, 0x76767676U,

+    0x79797979U, 0xddddddddU, 0x3d3d3d3dU, 0x16161616U,

+    0x3f3f3f3fU, 0x37373737U, 0x6d6d6d6dU, 0x38383838U,

+    0xb9b9b9b9U, 0x73737373U, 0xe9e9e9e9U, 0x35353535U,

+    0x55555555U, 0x71717171U, 0x7b7b7b7bU, 0x8c8c8c8cU,

+    0x72727272U, 0x88888888U, 0xf6f6f6f6U, 0x2a2a2a2aU,

+    0x3e3e3e3eU, 0x5e5e5e5eU, 0x27272727U, 0x46464646U,

+    0x0c0c0c0cU, 0x65656565U, 0x68686868U, 0x61616161U,

+    0x03030303U, 0xc1c1c1c1U, 0x57575757U, 0xd6d6d6d6U,

+    0xd9d9d9d9U, 0x58585858U, 0xd8d8d8d8U, 0x66666666U,

+    0xd7d7d7d7U, 0x3a3a3a3aU, 0xc8c8c8c8U, 0x3c3c3c3cU,

+    0xfafafafaU, 0x96969696U, 0xa7a7a7a7U, 0x98989898U,

+    0xececececU, 0xb8b8b8b8U, 0xc7c7c7c7U, 0xaeaeaeaeU,

+    0x69696969U, 0x4b4b4b4bU, 0xababababU, 0xa9a9a9a9U,

+    0x67676767U, 0x0a0a0a0aU, 0x47474747U, 0xf2f2f2f2U,

+    0xb5b5b5b5U, 0x22222222U, 0xe5e5e5e5U, 0xeeeeeeeeU,

+    0xbebebebeU, 0x2b2b2b2bU, 0x81818181U, 0x12121212U,

+    0x83838383U, 0x1b1b1b1bU, 0x0e0e0e0eU, 0x23232323U,

+    0xf5f5f5f5U, 0x45454545U, 0x21212121U, 0xcecececeU,

+    0x49494949U, 0x2c2c2c2cU, 0xf9f9f9f9U, 0xe6e6e6e6U,

+    0xb6b6b6b6U, 0x28282828U, 0x17171717U, 0x82828282U,

+    0x1a1a1a1aU, 0x8b8b8b8bU, 0xfefefefeU, 0x8a8a8a8aU,

+    0x09090909U, 0xc9c9c9c9U, 0x87878787U, 0x4e4e4e4eU,

+    0xe1e1e1e1U, 0x2e2e2e2eU, 0xe4e4e4e4U, 0xe0e0e0e0U,

+    0xebebebebU, 0x90909090U, 0xa4a4a4a4U, 0x1e1e1e1eU,

+    0x85858585U, 0x60606060U, 0x00000000U, 0x25252525U,

+    0xf4f4f4f4U, 0xf1f1f1f1U, 0x94949494U, 0x0b0b0b0bU,

+    0xe7e7e7e7U, 0x75757575U, 0xefefefefU, 0x34343434U,

+    0x31313131U, 0xd4d4d4d4U, 0xd0d0d0d0U, 0x86868686U,

+    0x7e7e7e7eU, 0xadadadadU, 0xfdfdfdfdU, 0x29292929U,

+    0x30303030U, 0x3b3b3b3bU, 0x9f9f9f9fU, 0xf8f8f8f8U,

+    0xc6c6c6c6U, 0x13131313U, 0x06060606U, 0x05050505U,

+    0xc5c5c5c5U, 0x11111111U, 0x77777777U, 0x7c7c7c7cU,

+    0x7a7a7a7aU, 0x78787878U, 0x36363636U, 0x1c1c1c1cU,

+    0x39393939U, 0x59595959U, 0x18181818U, 0x56565656U,

+    0xb3b3b3b3U, 0xb0b0b0b0U, 0x24242424U, 0x20202020U,

+    0xb2b2b2b2U, 0x92929292U, 0xa3a3a3a3U, 0xc0c0c0c0U,

+    0x44444444U, 0x62626262U, 0x10101010U, 0xb4b4b4b4U,

+    0x84848484U, 0x43434343U, 0x93939393U, 0xc2c2c2c2U,

+    0x4a4a4a4aU, 0xbdbdbdbdU, 0x8f8f8f8fU, 0x2d2d2d2dU,

+    0xbcbcbcbcU, 0x9c9c9c9cU, 0x6a6a6a6aU, 0x40404040U,

+    0xcfcfcfcfU, 0xa2a2a2a2U, 0x80808080U, 0x4f4f4f4fU,

+    0x1f1f1f1fU, 0xcacacacaU, 0xaaaaaaaaU, 0x42424242U,

+};

+

+static const ulong32 T5[256] = {

+    0x00000000U, 0x01020608U, 0x02040c10U, 0x03060a18U,

+    0x04081820U, 0x050a1e28U, 0x060c1430U, 0x070e1238U,

+    0x08103040U, 0x09123648U, 0x0a143c50U, 0x0b163a58U,

+    0x0c182860U, 0x0d1a2e68U, 0x0e1c2470U, 0x0f1e2278U,

+    0x10206080U, 0x11226688U, 0x12246c90U, 0x13266a98U,

+    0x142878a0U, 0x152a7ea8U, 0x162c74b0U, 0x172e72b8U,

+    0x183050c0U, 0x193256c8U, 0x1a345cd0U, 0x1b365ad8U,

+    0x1c3848e0U, 0x1d3a4ee8U, 0x1e3c44f0U, 0x1f3e42f8U,

+    0x2040c01dU, 0x2142c615U, 0x2244cc0dU, 0x2346ca05U,

+    0x2448d83dU, 0x254ade35U, 0x264cd42dU, 0x274ed225U,

+    0x2850f05dU, 0x2952f655U, 0x2a54fc4dU, 0x2b56fa45U,

+    0x2c58e87dU, 0x2d5aee75U, 0x2e5ce46dU, 0x2f5ee265U,

+    0x3060a09dU, 0x3162a695U, 0x3264ac8dU, 0x3366aa85U,

+    0x3468b8bdU, 0x356abeb5U, 0x366cb4adU, 0x376eb2a5U,

+    0x387090ddU, 0x397296d5U, 0x3a749ccdU, 0x3b769ac5U,

+    0x3c7888fdU, 0x3d7a8ef5U, 0x3e7c84edU, 0x3f7e82e5U,

+    0x40809d3aU, 0x41829b32U, 0x4284912aU, 0x43869722U,

+    0x4488851aU, 0x458a8312U, 0x468c890aU, 0x478e8f02U,

+    0x4890ad7aU, 0x4992ab72U, 0x4a94a16aU, 0x4b96a762U,

+    0x4c98b55aU, 0x4d9ab352U, 0x4e9cb94aU, 0x4f9ebf42U,

+    0x50a0fdbaU, 0x51a2fbb2U, 0x52a4f1aaU, 0x53a6f7a2U,

+    0x54a8e59aU, 0x55aae392U, 0x56ace98aU, 0x57aeef82U,

+    0x58b0cdfaU, 0x59b2cbf2U, 0x5ab4c1eaU, 0x5bb6c7e2U,

+    0x5cb8d5daU, 0x5dbad3d2U, 0x5ebcd9caU, 0x5fbedfc2U,

+    0x60c05d27U, 0x61c25b2fU, 0x62c45137U, 0x63c6573fU,

+    0x64c84507U, 0x65ca430fU, 0x66cc4917U, 0x67ce4f1fU,

+    0x68d06d67U, 0x69d26b6fU, 0x6ad46177U, 0x6bd6677fU,

+    0x6cd87547U, 0x6dda734fU, 0x6edc7957U, 0x6fde7f5fU,

+    0x70e03da7U, 0x71e23bafU, 0x72e431b7U, 0x73e637bfU,

+    0x74e82587U, 0x75ea238fU, 0x76ec2997U, 0x77ee2f9fU,

+    0x78f00de7U, 0x79f20befU, 0x7af401f7U, 0x7bf607ffU,

+    0x7cf815c7U, 0x7dfa13cfU, 0x7efc19d7U, 0x7ffe1fdfU,

+    0x801d2774U, 0x811f217cU, 0x82192b64U, 0x831b2d6cU,

+    0x84153f54U, 0x8517395cU, 0x86113344U, 0x8713354cU,

+    0x880d1734U, 0x890f113cU, 0x8a091b24U, 0x8b0b1d2cU,

+    0x8c050f14U, 0x8d07091cU, 0x8e010304U, 0x8f03050cU,

+    0x903d47f4U, 0x913f41fcU, 0x92394be4U, 0x933b4decU,

+    0x94355fd4U, 0x953759dcU, 0x963153c4U, 0x973355ccU,

+    0x982d77b4U, 0x992f71bcU, 0x9a297ba4U, 0x9b2b7dacU,

+    0x9c256f94U, 0x9d27699cU, 0x9e216384U, 0x9f23658cU,

+    0xa05de769U, 0xa15fe161U, 0xa259eb79U, 0xa35bed71U,

+    0xa455ff49U, 0xa557f941U, 0xa651f359U, 0xa753f551U,

+    0xa84dd729U, 0xa94fd121U, 0xaa49db39U, 0xab4bdd31U,

+    0xac45cf09U, 0xad47c901U, 0xae41c319U, 0xaf43c511U,

+    0xb07d87e9U, 0xb17f81e1U, 0xb2798bf9U, 0xb37b8df1U,

+    0xb4759fc9U, 0xb57799c1U, 0xb67193d9U, 0xb77395d1U,

+    0xb86db7a9U, 0xb96fb1a1U, 0xba69bbb9U, 0xbb6bbdb1U,

+    0xbc65af89U, 0xbd67a981U, 0xbe61a399U, 0xbf63a591U,

+    0xc09dba4eU, 0xc19fbc46U, 0xc299b65eU, 0xc39bb056U,

+    0xc495a26eU, 0xc597a466U, 0xc691ae7eU, 0xc793a876U,

+    0xc88d8a0eU, 0xc98f8c06U, 0xca89861eU, 0xcb8b8016U,

+    0xcc85922eU, 0xcd879426U, 0xce819e3eU, 0xcf839836U,

+    0xd0bddaceU, 0xd1bfdcc6U, 0xd2b9d6deU, 0xd3bbd0d6U,

+    0xd4b5c2eeU, 0xd5b7c4e6U, 0xd6b1cefeU, 0xd7b3c8f6U,

+    0xd8adea8eU, 0xd9afec86U, 0xdaa9e69eU, 0xdbabe096U,

+    0xdca5f2aeU, 0xdda7f4a6U, 0xdea1febeU, 0xdfa3f8b6U,

+    0xe0dd7a53U, 0xe1df7c5bU, 0xe2d97643U, 0xe3db704bU,

+    0xe4d56273U, 0xe5d7647bU, 0xe6d16e63U, 0xe7d3686bU,

+    0xe8cd4a13U, 0xe9cf4c1bU, 0xeac94603U, 0xebcb400bU,

+    0xecc55233U, 0xedc7543bU, 0xeec15e23U, 0xefc3582bU,

+    0xf0fd1ad3U, 0xf1ff1cdbU, 0xf2f916c3U, 0xf3fb10cbU,

+    0xf4f502f3U, 0xf5f704fbU, 0xf6f10ee3U, 0xf7f308ebU,

+    0xf8ed2a93U, 0xf9ef2c9bU, 0xfae92683U, 0xfbeb208bU,

+    0xfce532b3U, 0xfde734bbU, 0xfee13ea3U, 0xffe338abU,

+};

+

+/**

+ * The round constants.

+ */

+static const ulong32 rc[] = {

+    0xba542f74U, 0x53d3d24dU, 0x50ac8dbfU, 0x70529a4cU,

+    0xead597d1U, 0x33515ba6U, 0xde48a899U, 0xdb32b7fcU,

+    0xe39e919bU, 0xe2bb416eU, 0xa5cb6b95U, 0xa1f3b102U,

+    0xccc41d14U, 0xc363da5dU, 0x5fdc7dcdU, 0x7f5a6c5cU,

+    0xf726ffedU, 0xe89d6f8eU, 0x19a0f089U,

+};

+

+

+

+#else

+

+

+static const ulong32 T0[256] = {

+    0xa753a6f5U, 0xd3bb6bd0U, 0xe6d1bf6eU, 0x71e2d93bU,

+    0xd0bd67daU, 0xac458acfU, 0x4d9a29b3U, 0x79f2f90bU,

+    0x3a74e89cU, 0xc98f038cU, 0x913f7e41U, 0xfce5d732U,

+    0x1e3c7844U, 0x478e018fU, 0x54a84de5U, 0xbd67cea9U,

+    0x8c050a0fU, 0xa557aef9U, 0x7af4f501U, 0xfbebcb20U,

+    0x63c69157U, 0xb86ddab7U, 0xdda753f4U, 0xd4b577c2U,

+    0xe5d7b364U, 0xb37bf68dU, 0xc59733a4U, 0xbe61c2a3U,

+    0xa94f9ed1U, 0x880d1a17U, 0x0c183028U, 0xa259b2ebU,

+    0x3972e496U, 0xdfa35bf8U, 0x2952a4f6U, 0xdaa94fe6U,

+    0x2b56acfaU, 0xa84d9ad7U, 0xcb8b0b80U, 0x4c982db5U,

+    0x4b9631a7U, 0x224488ccU, 0xaa4992dbU, 0x244890d8U,

+    0x4182199bU, 0x70e0dd3dU, 0xa651a2f3U, 0xf9efc32cU,

+    0x5ab475c1U, 0xe2d9af76U, 0xb07dfa87U, 0x366cd8b4U,

+    0x7dfae913U, 0xe4d5b762U, 0x3366ccaaU, 0xffe3db38U,

+    0x60c09d5dU, 0x204080c0U, 0x08102030U, 0x8b0b161dU,

+    0x5ebc65d9U, 0xab4b96ddU, 0x7ffee11fU, 0x78f0fd0dU,

+    0x7cf8ed15U, 0x2c58b0e8U, 0x57ae41efU, 0xd2b96fd6U,

+    0xdca557f2U, 0x6ddaa973U, 0x7efce519U, 0x0d1a342eU,

+    0x53a651f7U, 0x94356a5fU, 0xc39b2bb0U, 0x2850a0f0U,

+    0x274e9cd2U, 0x060c1814U, 0x5fbe61dfU, 0xad478ec9U,

+    0x67ce814fU, 0x5cb86dd5U, 0x55aa49e3U, 0x48903dadU,

+    0x0e1c3824U, 0x52a455f1U, 0xeac98f46U, 0x42841591U,

+    0x5bb671c7U, 0x5dba69d3U, 0x3060c0a0U, 0x58b07dcdU,

+    0x51a259fbU, 0x59b279cbU, 0x3c78f088U, 0x4e9c25b9U,

+    0x3870e090U, 0x8a09121bU, 0x72e4d531U, 0x14285078U,

+    0xe7d3bb68U, 0xc6913faeU, 0xdea15ffeU, 0x50a05dfdU,

+    0x8e010203U, 0x9239724bU, 0xd1bf63dcU, 0x77eec12fU,

+    0x933b764dU, 0x458a0983U, 0x9a29527bU, 0xce811f9eU,

+    0x2d5ab4eeU, 0x03060c0aU, 0x62c49551U, 0xb671e293U,

+    0xb96fdeb1U, 0xbf63c6a5U, 0x96316253U, 0x6bd6b167U,

+    0x3f7efc82U, 0x070e1c12U, 0x1224486cU, 0xae4182c3U,

+    0x40801d9dU, 0x3468d0b8U, 0x468c0589U, 0x3e7cf884U,

+    0xdbab4be0U, 0xcf831b98U, 0xecc59752U, 0xcc851792U,

+    0xc19f23bcU, 0xa15fbee1U, 0xc09d27baU, 0xd6b17fceU,

+    0x1d3a744eU, 0xf4f5f702U, 0x61c2995bU, 0x3b76ec9aU,

+    0x10204060U, 0xd8ad47eaU, 0x68d0bd6dU, 0xa05dbae7U,

+    0xb17ffe81U, 0x0a14283cU, 0x69d2b96bU, 0x6cd8ad75U,

+    0x499239abU, 0xfae9cf26U, 0x76ecc529U, 0xc49537a2U,

+    0x9e214263U, 0x9b2b567dU, 0x6edca579U, 0x992f5e71U,

+    0xc2992fb6U, 0xb773e695U, 0x982d5a77U, 0xbc65caafU,

+    0x8f030605U, 0x85172e39U, 0x1f3e7c42U, 0xb475ea9fU,

+    0xf8edc72aU, 0x11224466U, 0x2e5cb8e4U, 0x00000000U,

+    0x254a94deU, 0x1c387048U, 0x2a54a8fcU, 0x3d7af48eU,

+    0x050a141eU, 0x4f9e21bfU, 0x7bf6f107U, 0xb279f28bU,

+    0x3264c8acU, 0x903d7a47U, 0xaf4386c5U, 0x19326456U,

+    0xa35bb6edU, 0xf7f3fb08U, 0x73e6d137U, 0x9d274e69U,

+    0x152a547eU, 0x74e8cd25U, 0xeec19f5eU, 0xca890f86U,

+    0x9f234665U, 0x0f1e3c22U, 0x1b366c5aU, 0x75eac923U,

+    0x86112233U, 0x84152a3fU, 0x9c254a6fU, 0x4a9435a1U,

+    0x97336655U, 0x1a34685cU, 0x65ca8943U, 0xf6f1ff0eU,

+    0xedc79354U, 0x09122436U, 0xbb6bd6bdU, 0x264c98d4U,

+    0x831b362dU, 0xebcb8b40U, 0x6fdea17fU, 0x811f3e21U,

+    0x04081018U, 0x6ad4b561U, 0x43861197U, 0x01020406U,

+    0x172e5c72U, 0xe1dfa37cU, 0x87132635U, 0xf5f7f304U,

+    0x8d070e09U, 0xe3dbab70U, 0x23468ccaU, 0x801d3a27U,

+    0x44880d85U, 0x162c5874U, 0x66cc8549U, 0x214284c6U,

+    0xfee1df3eU, 0xd5b773c4U, 0x3162c4a6U, 0xd9af43ecU,

+    0x356ad4beU, 0x18306050U, 0x0204080cU, 0x64c88d45U,

+    0xf2f9ef16U, 0xf1ffe31cU, 0x56ac45e9U, 0xcd871394U,

+    0x8219322bU, 0xc88d078aU, 0xba69d2bbU, 0xf0fde71aU,

+    0xefc39b58U, 0xe9cf834cU, 0xe8cd874aU, 0xfde7d334U,

+    0x890f1e11U, 0xd7b37bc8U, 0xc7933ba8U, 0xb577ee99U,

+    0xa455aaffU, 0x2f5ebce2U, 0x95376e59U, 0x13264c6aU,

+    0x0b162c3aU, 0xf3fbeb10U, 0xe0dda77aU, 0x376edcb2U,

+};

+

+static const ulong32 T1[256] = {

+    0x53a7f5a6U, 0xbbd3d06bU, 0xd1e66ebfU, 0xe2713bd9U,

+    0xbdd0da67U, 0x45accf8aU, 0x9a4db329U, 0xf2790bf9U,

+    0x743a9ce8U, 0x8fc98c03U, 0x3f91417eU, 0xe5fc32d7U,

+    0x3c1e4478U, 0x8e478f01U, 0xa854e54dU, 0x67bda9ceU,

+    0x058c0f0aU, 0x57a5f9aeU, 0xf47a01f5U, 0xebfb20cbU,

+    0xc6635791U, 0x6db8b7daU, 0xa7ddf453U, 0xb5d4c277U,

+    0xd7e564b3U, 0x7bb38df6U, 0x97c5a433U, 0x61bea3c2U,

+    0x4fa9d19eU, 0x0d88171aU, 0x180c2830U, 0x59a2ebb2U,

+    0x723996e4U, 0xa3dff85bU, 0x5229f6a4U, 0xa9dae64fU,

+    0x562bfaacU, 0x4da8d79aU, 0x8bcb800bU, 0x984cb52dU,

+    0x964ba731U, 0x4422cc88U, 0x49aadb92U, 0x4824d890U,

+    0x82419b19U, 0xe0703dddU, 0x51a6f3a2U, 0xeff92cc3U,

+    0xb45ac175U, 0xd9e276afU, 0x7db087faU, 0x6c36b4d8U,

+    0xfa7d13e9U, 0xd5e462b7U, 0x6633aaccU, 0xe3ff38dbU,

+    0xc0605d9dU, 0x4020c080U, 0x10083020U, 0x0b8b1d16U,

+    0xbc5ed965U, 0x4babdd96U, 0xfe7f1fe1U, 0xf0780dfdU,

+    0xf87c15edU, 0x582ce8b0U, 0xae57ef41U, 0xb9d2d66fU,

+    0xa5dcf257U, 0xda6d73a9U, 0xfc7e19e5U, 0x1a0d2e34U,

+    0xa653f751U, 0x35945f6aU, 0x9bc3b02bU, 0x5028f0a0U,

+    0x4e27d29cU, 0x0c061418U, 0xbe5fdf61U, 0x47adc98eU,

+    0xce674f81U, 0xb85cd56dU, 0xaa55e349U, 0x9048ad3dU,

+    0x1c0e2438U, 0xa452f155U, 0xc9ea468fU, 0x84429115U,

+    0xb65bc771U, 0xba5dd369U, 0x6030a0c0U, 0xb058cd7dU,

+    0xa251fb59U, 0xb259cb79U, 0x783c88f0U, 0x9c4eb925U,

+    0x703890e0U, 0x098a1b12U, 0xe47231d5U, 0x28147850U,

+    0xd3e768bbU, 0x91c6ae3fU, 0xa1defe5fU, 0xa050fd5dU,

+    0x018e0302U, 0x39924b72U, 0xbfd1dc63U, 0xee772fc1U,

+    0x3b934d76U, 0x8a458309U, 0x299a7b52U, 0x81ce9e1fU,

+    0x5a2deeb4U, 0x06030a0cU, 0xc4625195U, 0x71b693e2U,

+    0x6fb9b1deU, 0x63bfa5c6U, 0x31965362U, 0xd66b67b1U,

+    0x7e3f82fcU, 0x0e07121cU, 0x24126c48U, 0x41aec382U,

+    0x80409d1dU, 0x6834b8d0U, 0x8c468905U, 0x7c3e84f8U,

+    0xabdbe04bU, 0x83cf981bU, 0xc5ec5297U, 0x85cc9217U,

+    0x9fc1bc23U, 0x5fa1e1beU, 0x9dc0ba27U, 0xb1d6ce7fU,

+    0x3a1d4e74U, 0xf5f402f7U, 0xc2615b99U, 0x763b9aecU,

+    0x20106040U, 0xadd8ea47U, 0xd0686dbdU, 0x5da0e7baU,

+    0x7fb181feU, 0x140a3c28U, 0xd2696bb9U, 0xd86c75adU,

+    0x9249ab39U, 0xe9fa26cfU, 0xec7629c5U, 0x95c4a237U,

+    0x219e6342U, 0x2b9b7d56U, 0xdc6e79a5U, 0x2f99715eU,

+    0x99c2b62fU, 0x73b795e6U, 0x2d98775aU, 0x65bcafcaU,

+    0x038f0506U, 0x1785392eU, 0x3e1f427cU, 0x75b49feaU,

+    0xedf82ac7U, 0x22116644U, 0x5c2ee4b8U, 0x00000000U,

+    0x4a25de94U, 0x381c4870U, 0x542afca8U, 0x7a3d8ef4U,

+    0x0a051e14U, 0x9e4fbf21U, 0xf67b07f1U, 0x79b28bf2U,

+    0x6432acc8U, 0x3d90477aU, 0x43afc586U, 0x32195664U,

+    0x5ba3edb6U, 0xf3f708fbU, 0xe67337d1U, 0x279d694eU,

+    0x2a157e54U, 0xe87425cdU, 0xc1ee5e9fU, 0x89ca860fU,

+    0x239f6546U, 0x1e0f223cU, 0x361b5a6cU, 0xea7523c9U,

+    0x11863322U, 0x15843f2aU, 0x259c6f4aU, 0x944aa135U,

+    0x33975566U, 0x341a5c68U, 0xca654389U, 0xf1f60effU,

+    0xc7ed5493U, 0x12093624U, 0x6bbbbdd6U, 0x4c26d498U,

+    0x1b832d36U, 0xcbeb408bU, 0xde6f7fa1U, 0x1f81213eU,

+    0x08041810U, 0xd46a61b5U, 0x86439711U, 0x02010604U,

+    0x2e17725cU, 0xdfe17ca3U, 0x13873526U, 0xf7f504f3U,

+    0x078d090eU, 0xdbe370abU, 0x4623ca8cU, 0x1d80273aU,

+    0x8844850dU, 0x2c167458U, 0xcc664985U, 0x4221c684U,

+    0xe1fe3edfU, 0xb7d5c473U, 0x6231a6c4U, 0xafd9ec43U,

+    0x6a35bed4U, 0x30185060U, 0x04020c08U, 0xc864458dU,

+    0xf9f216efU, 0xfff11ce3U, 0xac56e945U, 0x87cd9413U,

+    0x19822b32U, 0x8dc88a07U, 0x69babbd2U, 0xfdf01ae7U,

+    0xc3ef589bU, 0xcfe94c83U, 0xcde84a87U, 0xe7fd34d3U,

+    0x0f89111eU, 0xb3d7c87bU, 0x93c7a83bU, 0x77b599eeU,

+    0x55a4ffaaU, 0x5e2fe2bcU, 0x3795596eU, 0x26136a4cU,

+    0x160b3a2cU, 0xfbf310ebU, 0xdde07aa7U, 0x6e37b2dcU,

+};

+

+static const ulong32 T2[256] = {

+    0xa6f5a753U, 0x6bd0d3bbU, 0xbf6ee6d1U, 0xd93b71e2U,

+    0x67dad0bdU, 0x8acfac45U, 0x29b34d9aU, 0xf90b79f2U,

+    0xe89c3a74U, 0x038cc98fU, 0x7e41913fU, 0xd732fce5U,

+    0x78441e3cU, 0x018f478eU, 0x4de554a8U, 0xcea9bd67U,

+    0x0a0f8c05U, 0xaef9a557U, 0xf5017af4U, 0xcb20fbebU,

+    0x915763c6U, 0xdab7b86dU, 0x53f4dda7U, 0x77c2d4b5U,

+    0xb364e5d7U, 0xf68db37bU, 0x33a4c597U, 0xc2a3be61U,

+    0x9ed1a94fU, 0x1a17880dU, 0x30280c18U, 0xb2eba259U,

+    0xe4963972U, 0x5bf8dfa3U, 0xa4f62952U, 0x4fe6daa9U,

+    0xacfa2b56U, 0x9ad7a84dU, 0x0b80cb8bU, 0x2db54c98U,

+    0x31a74b96U, 0x88cc2244U, 0x92dbaa49U, 0x90d82448U,

+    0x199b4182U, 0xdd3d70e0U, 0xa2f3a651U, 0xc32cf9efU,

+    0x75c15ab4U, 0xaf76e2d9U, 0xfa87b07dU, 0xd8b4366cU,

+    0xe9137dfaU, 0xb762e4d5U, 0xccaa3366U, 0xdb38ffe3U,

+    0x9d5d60c0U, 0x80c02040U, 0x20300810U, 0x161d8b0bU,

+    0x65d95ebcU, 0x96ddab4bU, 0xe11f7ffeU, 0xfd0d78f0U,

+    0xed157cf8U, 0xb0e82c58U, 0x41ef57aeU, 0x6fd6d2b9U,

+    0x57f2dca5U, 0xa9736ddaU, 0xe5197efcU, 0x342e0d1aU,

+    0x51f753a6U, 0x6a5f9435U, 0x2bb0c39bU, 0xa0f02850U,

+    0x9cd2274eU, 0x1814060cU, 0x61df5fbeU, 0x8ec9ad47U,

+    0x814f67ceU, 0x6dd55cb8U, 0x49e355aaU, 0x3dad4890U,

+    0x38240e1cU, 0x55f152a4U, 0x8f46eac9U, 0x15914284U,

+    0x71c75bb6U, 0x69d35dbaU, 0xc0a03060U, 0x7dcd58b0U,

+    0x59fb51a2U, 0x79cb59b2U, 0xf0883c78U, 0x25b94e9cU,

+    0xe0903870U, 0x121b8a09U, 0xd53172e4U, 0x50781428U,

+    0xbb68e7d3U, 0x3faec691U, 0x5ffedea1U, 0x5dfd50a0U,

+    0x02038e01U, 0x724b9239U, 0x63dcd1bfU, 0xc12f77eeU,

+    0x764d933bU, 0x0983458aU, 0x527b9a29U, 0x1f9ece81U,

+    0xb4ee2d5aU, 0x0c0a0306U, 0x955162c4U, 0xe293b671U,

+    0xdeb1b96fU, 0xc6a5bf63U, 0x62539631U, 0xb1676bd6U,

+    0xfc823f7eU, 0x1c12070eU, 0x486c1224U, 0x82c3ae41U,

+    0x1d9d4080U, 0xd0b83468U, 0x0589468cU, 0xf8843e7cU,

+    0x4be0dbabU, 0x1b98cf83U, 0x9752ecc5U, 0x1792cc85U,

+    0x23bcc19fU, 0xbee1a15fU, 0x27bac09dU, 0x7fced6b1U,

+    0x744e1d3aU, 0xf702f4f5U, 0x995b61c2U, 0xec9a3b76U,

+    0x40601020U, 0x47ead8adU, 0xbd6d68d0U, 0xbae7a05dU,

+    0xfe81b17fU, 0x283c0a14U, 0xb96b69d2U, 0xad756cd8U,

+    0x39ab4992U, 0xcf26fae9U, 0xc52976ecU, 0x37a2c495U,

+    0x42639e21U, 0x567d9b2bU, 0xa5796edcU, 0x5e71992fU,

+    0x2fb6c299U, 0xe695b773U, 0x5a77982dU, 0xcaafbc65U,

+    0x06058f03U, 0x2e398517U, 0x7c421f3eU, 0xea9fb475U,

+    0xc72af8edU, 0x44661122U, 0xb8e42e5cU, 0x00000000U,

+    0x94de254aU, 0x70481c38U, 0xa8fc2a54U, 0xf48e3d7aU,

+    0x141e050aU, 0x21bf4f9eU, 0xf1077bf6U, 0xf28bb279U,

+    0xc8ac3264U, 0x7a47903dU, 0x86c5af43U, 0x64561932U,

+    0xb6eda35bU, 0xfb08f7f3U, 0xd13773e6U, 0x4e699d27U,

+    0x547e152aU, 0xcd2574e8U, 0x9f5eeec1U, 0x0f86ca89U,

+    0x46659f23U, 0x3c220f1eU, 0x6c5a1b36U, 0xc92375eaU,

+    0x22338611U, 0x2a3f8415U, 0x4a6f9c25U, 0x35a14a94U,

+    0x66559733U, 0x685c1a34U, 0x894365caU, 0xff0ef6f1U,

+    0x9354edc7U, 0x24360912U, 0xd6bdbb6bU, 0x98d4264cU,

+    0x362d831bU, 0x8b40ebcbU, 0xa17f6fdeU, 0x3e21811fU,

+    0x10180408U, 0xb5616ad4U, 0x11974386U, 0x04060102U,

+    0x5c72172eU, 0xa37ce1dfU, 0x26358713U, 0xf304f5f7U,

+    0x0e098d07U, 0xab70e3dbU, 0x8cca2346U, 0x3a27801dU,

+    0x0d854488U, 0x5874162cU, 0x854966ccU, 0x84c62142U,

+    0xdf3efee1U, 0x73c4d5b7U, 0xc4a63162U, 0x43ecd9afU,

+    0xd4be356aU, 0x60501830U, 0x080c0204U, 0x8d4564c8U,

+    0xef16f2f9U, 0xe31cf1ffU, 0x45e956acU, 0x1394cd87U,

+    0x322b8219U, 0x078ac88dU, 0xd2bbba69U, 0xe71af0fdU,

+    0x9b58efc3U, 0x834ce9cfU, 0x874ae8cdU, 0xd334fde7U,

+    0x1e11890fU, 0x7bc8d7b3U, 0x3ba8c793U, 0xee99b577U,

+    0xaaffa455U, 0xbce22f5eU, 0x6e599537U, 0x4c6a1326U,

+    0x2c3a0b16U, 0xeb10f3fbU, 0xa77ae0ddU, 0xdcb2376eU,

+};

+

+static const ulong32 T3[256] = {

+    0xf5a653a7U, 0xd06bbbd3U, 0x6ebfd1e6U, 0x3bd9e271U,

+    0xda67bdd0U, 0xcf8a45acU, 0xb3299a4dU, 0x0bf9f279U,

+    0x9ce8743aU, 0x8c038fc9U, 0x417e3f91U, 0x32d7e5fcU,

+    0x44783c1eU, 0x8f018e47U, 0xe54da854U, 0xa9ce67bdU,

+    0x0f0a058cU, 0xf9ae57a5U, 0x01f5f47aU, 0x20cbebfbU,

+    0x5791c663U, 0xb7da6db8U, 0xf453a7ddU, 0xc277b5d4U,

+    0x64b3d7e5U, 0x8df67bb3U, 0xa43397c5U, 0xa3c261beU,

+    0xd19e4fa9U, 0x171a0d88U, 0x2830180cU, 0xebb259a2U,

+    0x96e47239U, 0xf85ba3dfU, 0xf6a45229U, 0xe64fa9daU,

+    0xfaac562bU, 0xd79a4da8U, 0x800b8bcbU, 0xb52d984cU,

+    0xa731964bU, 0xcc884422U, 0xdb9249aaU, 0xd8904824U,

+    0x9b198241U, 0x3ddde070U, 0xf3a251a6U, 0x2cc3eff9U,

+    0xc175b45aU, 0x76afd9e2U, 0x87fa7db0U, 0xb4d86c36U,

+    0x13e9fa7dU, 0x62b7d5e4U, 0xaacc6633U, 0x38dbe3ffU,

+    0x5d9dc060U, 0xc0804020U, 0x30201008U, 0x1d160b8bU,

+    0xd965bc5eU, 0xdd964babU, 0x1fe1fe7fU, 0x0dfdf078U,

+    0x15edf87cU, 0xe8b0582cU, 0xef41ae57U, 0xd66fb9d2U,

+    0xf257a5dcU, 0x73a9da6dU, 0x19e5fc7eU, 0x2e341a0dU,

+    0xf751a653U, 0x5f6a3594U, 0xb02b9bc3U, 0xf0a05028U,

+    0xd29c4e27U, 0x14180c06U, 0xdf61be5fU, 0xc98e47adU,

+    0x4f81ce67U, 0xd56db85cU, 0xe349aa55U, 0xad3d9048U,

+    0x24381c0eU, 0xf155a452U, 0x468fc9eaU, 0x91158442U,

+    0xc771b65bU, 0xd369ba5dU, 0xa0c06030U, 0xcd7db058U,

+    0xfb59a251U, 0xcb79b259U, 0x88f0783cU, 0xb9259c4eU,

+    0x90e07038U, 0x1b12098aU, 0x31d5e472U, 0x78502814U,

+    0x68bbd3e7U, 0xae3f91c6U, 0xfe5fa1deU, 0xfd5da050U,

+    0x0302018eU, 0x4b723992U, 0xdc63bfd1U, 0x2fc1ee77U,

+    0x4d763b93U, 0x83098a45U, 0x7b52299aU, 0x9e1f81ceU,

+    0xeeb45a2dU, 0x0a0c0603U, 0x5195c462U, 0x93e271b6U,

+    0xb1de6fb9U, 0xa5c663bfU, 0x53623196U, 0x67b1d66bU,

+    0x82fc7e3fU, 0x121c0e07U, 0x6c482412U, 0xc38241aeU,

+    0x9d1d8040U, 0xb8d06834U, 0x89058c46U, 0x84f87c3eU,

+    0xe04babdbU, 0x981b83cfU, 0x5297c5ecU, 0x921785ccU,

+    0xbc239fc1U, 0xe1be5fa1U, 0xba279dc0U, 0xce7fb1d6U,

+    0x4e743a1dU, 0x02f7f5f4U, 0x5b99c261U, 0x9aec763bU,

+    0x60402010U, 0xea47add8U, 0x6dbdd068U, 0xe7ba5da0U,

+    0x81fe7fb1U, 0x3c28140aU, 0x6bb9d269U, 0x75add86cU,

+    0xab399249U, 0x26cfe9faU, 0x29c5ec76U, 0xa23795c4U,

+    0x6342219eU, 0x7d562b9bU, 0x79a5dc6eU, 0x715e2f99U,

+    0xb62f99c2U, 0x95e673b7U, 0x775a2d98U, 0xafca65bcU,

+    0x0506038fU, 0x392e1785U, 0x427c3e1fU, 0x9fea75b4U,

+    0x2ac7edf8U, 0x66442211U, 0xe4b85c2eU, 0x00000000U,

+    0xde944a25U, 0x4870381cU, 0xfca8542aU, 0x8ef47a3dU,

+    0x1e140a05U, 0xbf219e4fU, 0x07f1f67bU, 0x8bf279b2U,

+    0xacc86432U, 0x477a3d90U, 0xc58643afU, 0x56643219U,

+    0xedb65ba3U, 0x08fbf3f7U, 0x37d1e673U, 0x694e279dU,

+    0x7e542a15U, 0x25cde874U, 0x5e9fc1eeU, 0x860f89caU,

+    0x6546239fU, 0x223c1e0fU, 0x5a6c361bU, 0x23c9ea75U,

+    0x33221186U, 0x3f2a1584U, 0x6f4a259cU, 0xa135944aU,

+    0x55663397U, 0x5c68341aU, 0x4389ca65U, 0x0efff1f6U,

+    0x5493c7edU, 0x36241209U, 0xbdd66bbbU, 0xd4984c26U,

+    0x2d361b83U, 0x408bcbebU, 0x7fa1de6fU, 0x213e1f81U,

+    0x18100804U, 0x61b5d46aU, 0x97118643U, 0x06040201U,

+    0x725c2e17U, 0x7ca3dfe1U, 0x35261387U, 0x04f3f7f5U,

+    0x090e078dU, 0x70abdbe3U, 0xca8c4623U, 0x273a1d80U,

+    0x850d8844U, 0x74582c16U, 0x4985cc66U, 0xc6844221U,

+    0x3edfe1feU, 0xc473b7d5U, 0xa6c46231U, 0xec43afd9U,

+    0xbed46a35U, 0x50603018U, 0x0c080402U, 0x458dc864U,

+    0x16eff9f2U, 0x1ce3fff1U, 0xe945ac56U, 0x941387cdU,

+    0x2b321982U, 0x8a078dc8U, 0xbbd269baU, 0x1ae7fdf0U,

+    0x589bc3efU, 0x4c83cfe9U, 0x4a87cde8U, 0x34d3e7fdU,

+    0x111e0f89U, 0xc87bb3d7U, 0xa83b93c7U, 0x99ee77b5U,

+    0xffaa55a4U, 0xe2bc5e2fU, 0x596e3795U, 0x6a4c2613U,

+    0x3a2c160bU, 0x10ebfbf3U, 0x7aa7dde0U, 0xb2dc6e37U,

+};

+

+static const ulong32 T4[256] = {

+    0xa7a7a7a7U, 0xd3d3d3d3U, 0xe6e6e6e6U, 0x71717171U,

+    0xd0d0d0d0U, 0xacacacacU, 0x4d4d4d4dU, 0x79797979U,

+    0x3a3a3a3aU, 0xc9c9c9c9U, 0x91919191U, 0xfcfcfcfcU,

+    0x1e1e1e1eU, 0x47474747U, 0x54545454U, 0xbdbdbdbdU,

+    0x8c8c8c8cU, 0xa5a5a5a5U, 0x7a7a7a7aU, 0xfbfbfbfbU,

+    0x63636363U, 0xb8b8b8b8U, 0xddddddddU, 0xd4d4d4d4U,

+    0xe5e5e5e5U, 0xb3b3b3b3U, 0xc5c5c5c5U, 0xbebebebeU,

+    0xa9a9a9a9U, 0x88888888U, 0x0c0c0c0cU, 0xa2a2a2a2U,

+    0x39393939U, 0xdfdfdfdfU, 0x29292929U, 0xdadadadaU,

+    0x2b2b2b2bU, 0xa8a8a8a8U, 0xcbcbcbcbU, 0x4c4c4c4cU,

+    0x4b4b4b4bU, 0x22222222U, 0xaaaaaaaaU, 0x24242424U,

+    0x41414141U, 0x70707070U, 0xa6a6a6a6U, 0xf9f9f9f9U,

+    0x5a5a5a5aU, 0xe2e2e2e2U, 0xb0b0b0b0U, 0x36363636U,

+    0x7d7d7d7dU, 0xe4e4e4e4U, 0x33333333U, 0xffffffffU,

+    0x60606060U, 0x20202020U, 0x08080808U, 0x8b8b8b8bU,

+    0x5e5e5e5eU, 0xababababU, 0x7f7f7f7fU, 0x78787878U,

+    0x7c7c7c7cU, 0x2c2c2c2cU, 0x57575757U, 0xd2d2d2d2U,

+    0xdcdcdcdcU, 0x6d6d6d6dU, 0x7e7e7e7eU, 0x0d0d0d0dU,

+    0x53535353U, 0x94949494U, 0xc3c3c3c3U, 0x28282828U,

+    0x27272727U, 0x06060606U, 0x5f5f5f5fU, 0xadadadadU,

+    0x67676767U, 0x5c5c5c5cU, 0x55555555U, 0x48484848U,

+    0x0e0e0e0eU, 0x52525252U, 0xeaeaeaeaU, 0x42424242U,

+    0x5b5b5b5bU, 0x5d5d5d5dU, 0x30303030U, 0x58585858U,

+    0x51515151U, 0x59595959U, 0x3c3c3c3cU, 0x4e4e4e4eU,

+    0x38383838U, 0x8a8a8a8aU, 0x72727272U, 0x14141414U,

+    0xe7e7e7e7U, 0xc6c6c6c6U, 0xdedededeU, 0x50505050U,

+    0x8e8e8e8eU, 0x92929292U, 0xd1d1d1d1U, 0x77777777U,

+    0x93939393U, 0x45454545U, 0x9a9a9a9aU, 0xcecececeU,

+    0x2d2d2d2dU, 0x03030303U, 0x62626262U, 0xb6b6b6b6U,

+    0xb9b9b9b9U, 0xbfbfbfbfU, 0x96969696U, 0x6b6b6b6bU,

+    0x3f3f3f3fU, 0x07070707U, 0x12121212U, 0xaeaeaeaeU,

+    0x40404040U, 0x34343434U, 0x46464646U, 0x3e3e3e3eU,

+    0xdbdbdbdbU, 0xcfcfcfcfU, 0xececececU, 0xccccccccU,

+    0xc1c1c1c1U, 0xa1a1a1a1U, 0xc0c0c0c0U, 0xd6d6d6d6U,

+    0x1d1d1d1dU, 0xf4f4f4f4U, 0x61616161U, 0x3b3b3b3bU,

+    0x10101010U, 0xd8d8d8d8U, 0x68686868U, 0xa0a0a0a0U,

+    0xb1b1b1b1U, 0x0a0a0a0aU, 0x69696969U, 0x6c6c6c6cU,

+    0x49494949U, 0xfafafafaU, 0x76767676U, 0xc4c4c4c4U,

+    0x9e9e9e9eU, 0x9b9b9b9bU, 0x6e6e6e6eU, 0x99999999U,

+    0xc2c2c2c2U, 0xb7b7b7b7U, 0x98989898U, 0xbcbcbcbcU,

+    0x8f8f8f8fU, 0x85858585U, 0x1f1f1f1fU, 0xb4b4b4b4U,

+    0xf8f8f8f8U, 0x11111111U, 0x2e2e2e2eU, 0x00000000U,

+    0x25252525U, 0x1c1c1c1cU, 0x2a2a2a2aU, 0x3d3d3d3dU,

+    0x05050505U, 0x4f4f4f4fU, 0x7b7b7b7bU, 0xb2b2b2b2U,

+    0x32323232U, 0x90909090U, 0xafafafafU, 0x19191919U,

+    0xa3a3a3a3U, 0xf7f7f7f7U, 0x73737373U, 0x9d9d9d9dU,

+    0x15151515U, 0x74747474U, 0xeeeeeeeeU, 0xcacacacaU,

+    0x9f9f9f9fU, 0x0f0f0f0fU, 0x1b1b1b1bU, 0x75757575U,

+    0x86868686U, 0x84848484U, 0x9c9c9c9cU, 0x4a4a4a4aU,

+    0x97979797U, 0x1a1a1a1aU, 0x65656565U, 0xf6f6f6f6U,

+    0xededededU, 0x09090909U, 0xbbbbbbbbU, 0x26262626U,

+    0x83838383U, 0xebebebebU, 0x6f6f6f6fU, 0x81818181U,

+    0x04040404U, 0x6a6a6a6aU, 0x43434343U, 0x01010101U,

+    0x17171717U, 0xe1e1e1e1U, 0x87878787U, 0xf5f5f5f5U,

+    0x8d8d8d8dU, 0xe3e3e3e3U, 0x23232323U, 0x80808080U,

+    0x44444444U, 0x16161616U, 0x66666666U, 0x21212121U,

+    0xfefefefeU, 0xd5d5d5d5U, 0x31313131U, 0xd9d9d9d9U,

+    0x35353535U, 0x18181818U, 0x02020202U, 0x64646464U,

+    0xf2f2f2f2U, 0xf1f1f1f1U, 0x56565656U, 0xcdcdcdcdU,

+    0x82828282U, 0xc8c8c8c8U, 0xbabababaU, 0xf0f0f0f0U,

+    0xefefefefU, 0xe9e9e9e9U, 0xe8e8e8e8U, 0xfdfdfdfdU,

+    0x89898989U, 0xd7d7d7d7U, 0xc7c7c7c7U, 0xb5b5b5b5U,

+    0xa4a4a4a4U, 0x2f2f2f2fU, 0x95959595U, 0x13131313U,

+    0x0b0b0b0bU, 0xf3f3f3f3U, 0xe0e0e0e0U, 0x37373737U,

+};

+

+static const ulong32 T5[256] = {

+    0x00000000U, 0x01020608U, 0x02040c10U, 0x03060a18U,

+    0x04081820U, 0x050a1e28U, 0x060c1430U, 0x070e1238U,

+    0x08103040U, 0x09123648U, 0x0a143c50U, 0x0b163a58U,

+    0x0c182860U, 0x0d1a2e68U, 0x0e1c2470U, 0x0f1e2278U,

+    0x10206080U, 0x11226688U, 0x12246c90U, 0x13266a98U,

+    0x142878a0U, 0x152a7ea8U, 0x162c74b0U, 0x172e72b8U,

+    0x183050c0U, 0x193256c8U, 0x1a345cd0U, 0x1b365ad8U,

+    0x1c3848e0U, 0x1d3a4ee8U, 0x1e3c44f0U, 0x1f3e42f8U,

+    0x2040c01dU, 0x2142c615U, 0x2244cc0dU, 0x2346ca05U,

+    0x2448d83dU, 0x254ade35U, 0x264cd42dU, 0x274ed225U,

+    0x2850f05dU, 0x2952f655U, 0x2a54fc4dU, 0x2b56fa45U,

+    0x2c58e87dU, 0x2d5aee75U, 0x2e5ce46dU, 0x2f5ee265U,

+    0x3060a09dU, 0x3162a695U, 0x3264ac8dU, 0x3366aa85U,

+    0x3468b8bdU, 0x356abeb5U, 0x366cb4adU, 0x376eb2a5U,

+    0x387090ddU, 0x397296d5U, 0x3a749ccdU, 0x3b769ac5U,

+    0x3c7888fdU, 0x3d7a8ef5U, 0x3e7c84edU, 0x3f7e82e5U,

+    0x40809d3aU, 0x41829b32U, 0x4284912aU, 0x43869722U,

+    0x4488851aU, 0x458a8312U, 0x468c890aU, 0x478e8f02U,

+    0x4890ad7aU, 0x4992ab72U, 0x4a94a16aU, 0x4b96a762U,

+    0x4c98b55aU, 0x4d9ab352U, 0x4e9cb94aU, 0x4f9ebf42U,

+    0x50a0fdbaU, 0x51a2fbb2U, 0x52a4f1aaU, 0x53a6f7a2U,

+    0x54a8e59aU, 0x55aae392U, 0x56ace98aU, 0x57aeef82U,

+    0x58b0cdfaU, 0x59b2cbf2U, 0x5ab4c1eaU, 0x5bb6c7e2U,

+    0x5cb8d5daU, 0x5dbad3d2U, 0x5ebcd9caU, 0x5fbedfc2U,

+    0x60c05d27U, 0x61c25b2fU, 0x62c45137U, 0x63c6573fU,

+    0x64c84507U, 0x65ca430fU, 0x66cc4917U, 0x67ce4f1fU,

+    0x68d06d67U, 0x69d26b6fU, 0x6ad46177U, 0x6bd6677fU,

+    0x6cd87547U, 0x6dda734fU, 0x6edc7957U, 0x6fde7f5fU,

+    0x70e03da7U, 0x71e23bafU, 0x72e431b7U, 0x73e637bfU,

+    0x74e82587U, 0x75ea238fU, 0x76ec2997U, 0x77ee2f9fU,

+    0x78f00de7U, 0x79f20befU, 0x7af401f7U, 0x7bf607ffU,

+    0x7cf815c7U, 0x7dfa13cfU, 0x7efc19d7U, 0x7ffe1fdfU,

+    0x801d2774U, 0x811f217cU, 0x82192b64U, 0x831b2d6cU,

+    0x84153f54U, 0x8517395cU, 0x86113344U, 0x8713354cU,

+    0x880d1734U, 0x890f113cU, 0x8a091b24U, 0x8b0b1d2cU,

+    0x8c050f14U, 0x8d07091cU, 0x8e010304U, 0x8f03050cU,

+    0x903d47f4U, 0x913f41fcU, 0x92394be4U, 0x933b4decU,

+    0x94355fd4U, 0x953759dcU, 0x963153c4U, 0x973355ccU,

+    0x982d77b4U, 0x992f71bcU, 0x9a297ba4U, 0x9b2b7dacU,

+    0x9c256f94U, 0x9d27699cU, 0x9e216384U, 0x9f23658cU,

+    0xa05de769U, 0xa15fe161U, 0xa259eb79U, 0xa35bed71U,

+    0xa455ff49U, 0xa557f941U, 0xa651f359U, 0xa753f551U,

+    0xa84dd729U, 0xa94fd121U, 0xaa49db39U, 0xab4bdd31U,

+    0xac45cf09U, 0xad47c901U, 0xae41c319U, 0xaf43c511U,

+    0xb07d87e9U, 0xb17f81e1U, 0xb2798bf9U, 0xb37b8df1U,

+    0xb4759fc9U, 0xb57799c1U, 0xb67193d9U, 0xb77395d1U,

+    0xb86db7a9U, 0xb96fb1a1U, 0xba69bbb9U, 0xbb6bbdb1U,

+    0xbc65af89U, 0xbd67a981U, 0xbe61a399U, 0xbf63a591U,

+    0xc09dba4eU, 0xc19fbc46U, 0xc299b65eU, 0xc39bb056U,

+    0xc495a26eU, 0xc597a466U, 0xc691ae7eU, 0xc793a876U,

+    0xc88d8a0eU, 0xc98f8c06U, 0xca89861eU, 0xcb8b8016U,

+    0xcc85922eU, 0xcd879426U, 0xce819e3eU, 0xcf839836U,

+    0xd0bddaceU, 0xd1bfdcc6U, 0xd2b9d6deU, 0xd3bbd0d6U,

+    0xd4b5c2eeU, 0xd5b7c4e6U, 0xd6b1cefeU, 0xd7b3c8f6U,

+    0xd8adea8eU, 0xd9afec86U, 0xdaa9e69eU, 0xdbabe096U,

+    0xdca5f2aeU, 0xdda7f4a6U, 0xdea1febeU, 0xdfa3f8b6U,

+    0xe0dd7a53U, 0xe1df7c5bU, 0xe2d97643U, 0xe3db704bU,

+    0xe4d56273U, 0xe5d7647bU, 0xe6d16e63U, 0xe7d3686bU,

+    0xe8cd4a13U, 0xe9cf4c1bU, 0xeac94603U, 0xebcb400bU,

+    0xecc55233U, 0xedc7543bU, 0xeec15e23U, 0xefc3582bU,

+    0xf0fd1ad3U, 0xf1ff1cdbU, 0xf2f916c3U, 0xf3fb10cbU,

+    0xf4f502f3U, 0xf5f704fbU, 0xf6f10ee3U, 0xf7f308ebU,

+    0xf8ed2a93U, 0xf9ef2c9bU, 0xfae92683U, 0xfbeb208bU,

+    0xfce532b3U, 0xfde734bbU, 0xfee13ea3U, 0xffe338abU,

+};

+

+/**

+ * The round constants.

+ */

+static const ulong32 rc[] = {

+   0xa7d3e671U, 0xd0ac4d79U, 0x3ac991fcU, 0x1e4754bdU,

+   0x8ca57afbU, 0x63b8ddd4U, 0xe5b3c5beU, 0xa9880ca2U,

+   0x39df29daU, 0x2ba8cb4cU, 0x4b22aa24U, 0x4170a6f9U,

+   0x5ae2b036U, 0x7de433ffU, 0x6020088bU, 0x5eab7f78U,

+   0x7c2c57d2U, 0xdc6d7e0dU, 0x5394c328U,

+};

+

+#endif

+

+ /**

+    Initialize the Anubis block cipher

+    @param key The symmetric key you wish to pass

+    @param keylen The key length in bytes

+    @param num_rounds The number of rounds desired (0 for default)

+    @param skey The key in as scheduled by this function.

+    @return CRYPT_OK if successful

+ */

+#ifdef CLEAN_STACK

+static int _anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)

+#else

+int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)

+#endif

+{

+   int N, R, i, pos, r;

+   ulong32 kappa[MAX_N];

+   ulong32 inter[MAX_N];

+   ulong32 v, K0, K1, K2, K3;

+

+   LTC_ARGCHK(key  != NULL);

+   LTC_ARGCHK(skey != NULL);

+

+   /* Valid sizes (in bytes) are 16, 20, 24, 28, 32, 36, and 40. */

+   if ((keylen & 3) || (keylen < 16) || (keylen > 40)) {

+      return CRYPT_INVALID_KEYSIZE;

+   }

+   skey->anubis.keyBits = keylen*8;

+

+   /*

+    * determine the N length parameter:

+    * (N.B. it is assumed that the key length is valid!)

+    */

+   N = skey->anubis.keyBits >> 5;

+

+   /*

+    * determine number of rounds from key size:

+    */

+   skey->anubis.R = R = 8 + N;

+

+   if (num_rounds != 0 && num_rounds != skey->anubis.R) {

+      return CRYPT_INVALID_ROUNDS;

+   }

+

+    /*

+    * map cipher key to initial key state (mu):

+    */

+    for (i = 0, pos = 0; i < N; i++, pos += 4) {

+      kappa[i] =

+         (key[pos    ] << 24) ^

+         (key[pos + 1] << 16) ^

+         (key[pos + 2] <<  8) ^

+         (key[pos + 3]      );

+    }

+

+   /*

+    * generate R + 1 round keys:

+    */

+   for (r = 0; r <= R; r++) {

+      /*

+       * generate r-th round key K^r:

+       */

+      K0 = T4[(kappa[N - 1] >> 24)       ];

+      K1 = T4[(kappa[N - 1] >> 16) & 0xff];

+      K2 = T4[(kappa[N - 1] >>  8) & 0xff];

+      K3 = T4[(kappa[N - 1]      ) & 0xff];

+      for (i = N - 2; i >= 0; i--) {

+         K0 = T4[(kappa[i] >> 24)       ] ^

+            (T5[(K0 >> 24)       ] & 0xff000000U) ^

+            (T5[(K0 >> 16) & 0xff] & 0x00ff0000U) ^

+            (T5[(K0 >>  8) & 0xff] & 0x0000ff00U) ^

+            (T5[(K0      ) & 0xff] & 0x000000ffU);

+         K1 = T4[(kappa[i] >> 16) & 0xff] ^

+            (T5[(K1 >> 24)       ] & 0xff000000U) ^

+            (T5[(K1 >> 16) & 0xff] & 0x00ff0000U) ^

+            (T5[(K1 >>  8) & 0xff] & 0x0000ff00U) ^

+            (T5[(K1      ) & 0xff] & 0x000000ffU);

+         K2 = T4[(kappa[i] >>  8) & 0xff] ^

+            (T5[(K2 >> 24)       ] & 0xff000000U) ^

+            (T5[(K2 >> 16) & 0xff] & 0x00ff0000U) ^

+            (T5[(K2 >>  8) & 0xff] & 0x0000ff00U) ^

+            (T5[(K2      ) & 0xff] & 0x000000ffU);

+         K3 = T4[(kappa[i]      ) & 0xff] ^

+            (T5[(K3 >> 24)       ] & 0xff000000U) ^

+            (T5[(K3 >> 16) & 0xff] & 0x00ff0000U) ^

+            (T5[(K3 >>  8) & 0xff] & 0x0000ff00U) ^

+            (T5[(K3      ) & 0xff] & 0x000000ffU);

+      }

+      /*

+      -- this is the code to use with the large U tables:

+      K0 = K1 = K2 = K3 = 0;

+      for (i = 0; i < N; i++) {

+         K0 ^= U[i][(kappa[i] >> 24)       ];

+         K1 ^= U[i][(kappa[i] >> 16) & 0xff];

+         K2 ^= U[i][(kappa[i] >>  8) & 0xff];

+         K3 ^= U[i][(kappa[i]      ) & 0xff];

+      }

+      */

+      skey->anubis.roundKeyEnc[r][0] = K0;

+      skey->anubis.roundKeyEnc[r][1] = K1;

+      skey->anubis.roundKeyEnc[r][2] = K2;

+      skey->anubis.roundKeyEnc[r][3] = K3;

+

+      /*

+       * compute kappa^{r+1} from kappa^r:

+       */

+      if (r == R) {

+         break;

+      }

+      for (i = 0; i < N; i++) {

+         int j = i;

+         inter[i]  = T0[(kappa[j--] >> 24)       ]; if (j < 0) j = N - 1;

+         inter[i] ^= T1[(kappa[j--] >> 16) & 0xff]; if (j < 0) j = N - 1;

+         inter[i] ^= T2[(kappa[j--] >>  8) & 0xff]; if (j < 0) j = N - 1;

+         inter[i] ^= T3[(kappa[j  ]      ) & 0xff];

+      }

+      kappa[0] = inter[0] ^ rc[r];

+      for (i = 1; i < N; i++) {

+         kappa[i] = inter[i];

+      }

+   }

+

+   /*

+    * generate inverse key schedule: K'^0 = K^R, K'^R = K^0, K'^r = theta(K^{R-r}):

+    */

+   for (i = 0; i < 4; i++) {

+      skey->anubis.roundKeyDec[0][i] = skey->anubis.roundKeyEnc[R][i];

+      skey->anubis.roundKeyDec[R][i] = skey->anubis.roundKeyEnc[0][i];

+   }

+   for (r = 1; r < R; r++) {

+      for (i = 0; i < 4; i++) {

+         v = skey->anubis.roundKeyEnc[R - r][i];

+         skey->anubis.roundKeyDec[r][i] =

+            T0[T4[(v >> 24)       ] & 0xff] ^

+            T1[T4[(v >> 16) & 0xff] & 0xff] ^

+            T2[T4[(v >>  8) & 0xff] & 0xff] ^

+            T3[T4[(v      ) & 0xff] & 0xff];

+      }

+   }

+

+   return CRYPT_OK;

+}

+

+#ifdef CLEAN_STACK

+int  anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)

+{

+  int err;

+  err = _anubis_setup(key, keylen, num_rounds, skey);

+  burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5));

+  return err;

+}

+#endif

+  

+

+static void anubis_crypt(const unsigned char *plaintext, unsigned char *ciphertext,

+                         ulong32 roundKey[18 + 1][4], int R) {

+   int i, pos, r;

+   ulong32 state[4];

+   ulong32 inter[4];

+

+    /*

+    * map plaintext block to cipher state (mu)

+    * and add initial round key (sigma[K^0]):

+    */

+    for (i = 0, pos = 0; i < 4; i++, pos += 4) {

+      state[i] =

+         (plaintext[pos    ] << 24) ^

+         (plaintext[pos + 1] << 16) ^

+         (plaintext[pos + 2] <<  8) ^

+         (plaintext[pos + 3]      ) ^

+         roundKey[0][i];

+    }

+

+    /*

+     * R - 1 full rounds:

+     */

+    for (r = 1; r < R; r++) {

+      inter[0] =

+         T0[(state[0] >> 24)       ] ^

+         T1[(state[1] >> 24)       ] ^

+         T2[(state[2] >> 24)       ] ^

+         T3[(state[3] >> 24)       ] ^

+         roundKey[r][0];

+      inter[1] =

+         T0[(state[0] >> 16) & 0xff] ^

+         T1[(state[1] >> 16) & 0xff] ^

+         T2[(state[2] >> 16) & 0xff] ^

+         T3[(state[3] >> 16) & 0xff] ^

+         roundKey[r][1];

+      inter[2] =

+         T0[(state[0] >>  8) & 0xff] ^

+         T1[(state[1] >>  8) & 0xff] ^

+         T2[(state[2] >>  8) & 0xff] ^

+         T3[(state[3] >>  8) & 0xff] ^

+         roundKey[r][2];

+      inter[3] =

+         T0[(state[0]      ) & 0xff] ^

+         T1[(state[1]      ) & 0xff] ^

+         T2[(state[2]      ) & 0xff] ^

+         T3[(state[3]      ) & 0xff] ^

+         roundKey[r][3];

+      state[0] = inter[0];

+      state[1] = inter[1];

+      state[2] = inter[2];

+      state[3] = inter[3];

+    }

+

+    /*

+    * last round:

+    */

+   inter[0] =

+      (T0[(state[0] >> 24)       ] & 0xff000000U) ^

+      (T1[(state[1] >> 24)       ] & 0x00ff0000U) ^

+      (T2[(state[2] >> 24)       ] & 0x0000ff00U) ^

+      (T3[(state[3] >> 24)       ] & 0x000000ffU) ^

+      roundKey[R][0];

+   inter[1] =

+      (T0[(state[0] >> 16) & 0xff] & 0xff000000U) ^

+      (T1[(state[1] >> 16) & 0xff] & 0x00ff0000U) ^

+      (T2[(state[2] >> 16) & 0xff] & 0x0000ff00U) ^

+      (T3[(state[3] >> 16) & 0xff] & 0x000000ffU) ^

+      roundKey[R][1];

+   inter[2] =

+      (T0[(state[0] >>  8) & 0xff] & 0xff000000U) ^

+      (T1[(state[1] >>  8) & 0xff] & 0x00ff0000U) ^

+      (T2[(state[2] >>  8) & 0xff] & 0x0000ff00U) ^

+      (T3[(state[3] >>  8) & 0xff] & 0x000000ffU) ^

+      roundKey[R][2];

+   inter[3] =

+      (T0[(state[0]      ) & 0xff] & 0xff000000U) ^

+      (T1[(state[1]      ) & 0xff] & 0x00ff0000U) ^

+      (T2[(state[2]      ) & 0xff] & 0x0000ff00U) ^

+      (T3[(state[3]      ) & 0xff] & 0x000000ffU) ^

+      roundKey[R][3];

+

+   /*

+    * map cipher state to ciphertext block (mu^{-1}):

+    */

+    for (i = 0, pos = 0; i < 4; i++, pos += 4) {

+        ulong32 w = inter[i];

+        ciphertext[pos    ] = (unsigned char)(w >> 24);

+        ciphertext[pos + 1] = (unsigned char)(w >> 16);

+        ciphertext[pos + 2] = (unsigned char)(w >>  8);

+        ciphertext[pos + 3] = (unsigned char)(w      );

+    }

+}

+

+/**

+  Encrypts a block of text with Anubis

+  @param pt The input plaintext (16 bytes)

+  @param ct The output ciphertext (16 bytes)

+  @param skey The key as scheduled

+*/

+void anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)

+{

+   LTC_ARGCHK(pt   != NULL);

+   LTC_ARGCHK(ct   != NULL);

+   LTC_ARGCHK(skey != NULL);

+   anubis_crypt(pt, ct, skey->anubis.roundKeyEnc, skey->anubis.R);

+}

+

+/**

+  Decrypts a block of text with Anubis

+  @param ct The input ciphertext (16 bytes)

+  @param pt The output plaintext (16 bytes)

+  @param skey The key as scheduled 

+*/

+void anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)

+{

+   LTC_ARGCHK(pt   != NULL);

+   LTC_ARGCHK(ct   != NULL);

+   LTC_ARGCHK(skey != NULL);

+   anubis_crypt(ct, pt, skey->anubis.roundKeyDec, skey->anubis.R);

+}

+

+/**

+  Performs a self-test of the Anubis block cipher

+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled

+*/

+int anubis_test(void)

+{

+#if !defined(LTC_TEST)

+  return CRYPT_NOP;

+#else

+  static const struct test {

+     int keylen;

+     unsigned char pt[16], ct[16], key[40];

+  } tests[] = {

+#ifndef ANUBIS_TWEAK

+  /**** ORIGINAL ANUBIS ****/

+  /* 128 bit keys */

+{

+   16,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xF0, 0x68, 0x60, 0xFC, 0x67, 0x30, 0xE8, 0x18, 

+     0xF1, 0x32, 0xC7, 0x8A, 0xF4, 0x13, 0x2A, 0xFE },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   16,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xA8, 0x66, 0x84, 0x80, 0x07, 0x74, 0x5C, 0x89, 

+     0xFC, 0x5E, 0xB5, 0xBA, 0xD4, 0xFE, 0x32, 0x6D },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+},

+

+   /* 160-bit keys */

+{

+   20,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xBD, 0x5E, 0x32, 0xBE, 0x51, 0x67, 0xA8, 0xE2,

+     0x72, 0xD7, 0x95, 0x0F, 0x83, 0xC6, 0x8C, 0x31 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00 }

+}, {

+   20,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x4C, 0x1F, 0x86, 0x2E, 0x11, 0xEB, 0xCE, 0xEB,

+     0xFE, 0xB9, 0x73, 0xC9, 0xDF, 0xEF, 0x7A, 0xDB },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 192-bit keys */

+{

+   24,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x17, 0xAC, 0x57, 0x44, 0x9D, 0x59, 0x61, 0x66, 

+     0xD0, 0xC7, 0x9E, 0x04, 0x7C, 0xC7, 0x58, 0xF0 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   24,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x71, 0x52, 0xB4, 0xEB, 0x1D, 0xAA, 0x36, 0xFD, 

+     0x57, 0x14, 0x5F, 0x57, 0x04, 0x9F, 0x70, 0x74 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 224-bit keys */

+{

+   28,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xA2, 0xF0, 0xA6, 0xB9, 0x17, 0x93, 0x2A, 0x3B, 

+     0xEF, 0x08, 0xE8, 0x7A, 0x58, 0xD6, 0xF8, 0x53 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00 }

+}, {

+   28,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xF0, 0xCA, 0xFC, 0x78, 0x8B, 0x4B, 0x4E, 0x53, 

+     0x8B, 0xC4, 0x32, 0x6A, 0xF5, 0xB9, 0x1B, 0x5F },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 256-bit keys */

+{

+   32,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xE0, 0x86, 0xAC, 0x45, 0x6B, 0x3C, 0xE5, 0x13, 

+     0xED, 0xF5, 0xDF, 0xDD, 0xD6, 0x3B, 0x71, 0x93 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   32,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x50, 0x01, 0xB9, 0xF5, 0x21, 0xC1, 0xC1, 0x29, 

+     0x00, 0xD5, 0xEC, 0x98, 0x2B, 0x9E, 0xE8, 0x21 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 288-bit keys */

+{

+   36,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xE8, 0xF4, 0xAF, 0x2B, 0x21, 0xA0, 0x87, 0x9B, 

+     0x41, 0x95, 0xB9, 0x71, 0x75, 0x79, 0x04, 0x7C },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00 }

+}, {

+   36,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xE6, 0xA6, 0xA5, 0xBC, 0x8B, 0x63, 0x6F, 0xE2, 

+     0xBD, 0xA7, 0xA7, 0x53, 0xAB, 0x40, 0x22, 0xE0 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 320-bit keys */

+{

+   40,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x17, 0x04, 0xD7, 0x2C, 0xC6, 0x85, 0x76, 0x02, 

+     0x4B, 0xCC, 0x39, 0x80, 0xD8, 0x22, 0xEA, 0xA4 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   40,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x7A, 0x41, 0xE6, 0x7D, 0x4F, 0xD8, 0x64, 0xF0, 

+     0x44, 0xA8, 0x3C, 0x73, 0x81, 0x7E, 0x53, 0xD8 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+}

+#else

+  /**** Tweaked ANUBIS ****/

+  /* 128 bit keys */

+{

+   16,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xB8, 0x35, 0xBD, 0xC3, 0x34, 0x82, 0x9D, 0x83,

+     0x71, 0xBF, 0xA3, 0x71, 0xE4, 0xB3, 0xC4, 0xFD },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   16,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xE6, 0x14, 0x1E, 0xAF, 0xEB, 0xE0, 0x59, 0x3C,

+     0x48, 0xE1, 0xCD, 0xF2, 0x1B, 0xBA, 0xA1, 0x89 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+},

+

+   /* 160-bit keys */

+{

+   20,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x97, 0x59, 0x79, 0x4B, 0x5C, 0xA0, 0x70, 0x73,

+     0x24, 0xEF, 0xB3, 0x58, 0x67, 0xCA, 0xD4, 0xB3 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00 }

+}, {

+   20,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xB8, 0x0D, 0xFB, 0x9B, 0xE4, 0xA1, 0x58, 0x87,

+     0xB3, 0x76, 0xD5, 0x02, 0x18, 0x95, 0xC1, 0x2E },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 192-bit keys */

+{

+   24,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x7D, 0x62, 0x3B, 0x52, 0xC7, 0x4C, 0x64, 0xD8,

+     0xEB, 0xC7, 0x2D, 0x57, 0x97, 0x85, 0x43, 0x8F },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   24,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xB1, 0x0A, 0x59, 0xDD, 0x5D, 0x5D, 0x8D, 0x67,

+     0xEC, 0xEE, 0x4A, 0xC4, 0xBE, 0x4F, 0xA8, 0x4F },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 224-bit keys */

+{

+   28,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x68, 0x9E, 0x05, 0x94, 0x6A, 0x94, 0x43, 0x8F,

+     0xE7, 0x8E, 0x37, 0x3D, 0x24, 0x97, 0x92, 0xF5 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00 }

+}, {

+   28,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xDD, 0xB7, 0xB0, 0xB4, 0xE9, 0xB4, 0x9B, 0x9C,

+     0x38, 0x20, 0x25, 0x0B, 0x47, 0xC2, 0x1F, 0x89 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 256-bit keys */

+{

+   32,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x96, 0x00, 0xF0, 0x76, 0x91, 0x69, 0x29, 0x87,

+     0xF5, 0xE5, 0x97, 0xDB, 0xDB, 0xAF, 0x1B, 0x0A },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   32,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x69, 0x9C, 0xAF, 0xDD, 0x94, 0xC7, 0xBC, 0x60,

+     0x44, 0xFE, 0x02, 0x05, 0x8A, 0x6E, 0xEF, 0xBD },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 288-bit keys */

+{

+   36,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x0F, 0xC7, 0xA2, 0xC0, 0x11, 0x17, 0xAC, 0x43,

+     0x52, 0x5E, 0xDF, 0x6C, 0xF3, 0x96, 0x33, 0x6C },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00 }

+}, {

+   36,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xAD, 0x08, 0x4F, 0xED, 0x55, 0xA6, 0x94, 0x3E,

+     0x7E, 0x5E, 0xED, 0x05, 0xA1, 0x9D, 0x41, 0xB4 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x01 }

+},

+

+  /* 320-bit keys */

+{

+   40,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0xFE, 0xE2, 0x0E, 0x2A, 0x9D, 0xC5, 0x83, 0xBA,

+     0xA3, 0xA6, 0xD6, 0xA6, 0xF2, 0xE8, 0x06, 0xA5 },

+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

+}, {

+   40,

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },

+   { 0x86, 0x3D, 0xCC, 0x4A, 0x60, 0x34, 0x9C, 0x28,

+     0xA7, 0xDA, 0xA4, 0x3B, 0x0A, 0xD7, 0xFD, 0xC7 },

+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }

+}

+#endif

+};

+   int x, y;

+   unsigned char buf[2][16];

+   symmetric_key skey;

+

+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {

+       anubis_setup(tests[x].key, tests[x].keylen, 0, &skey);

+       anubis_ecb_encrypt(tests[x].pt, buf[0], &skey);

+       anubis_ecb_decrypt(buf[0], buf[1], &skey);

+       if (memcmp(buf[0], tests[x].ct, 16) || memcmp(buf[1], tests[x].pt, 16)) {

+          return CRYPT_FAIL_TESTVECTOR;

+       }

+

+       for (y = 0; y < 1000; y++) anubis_ecb_encrypt(buf[0], buf[0], &skey);

+       for (y = 0; y < 1000; y++) anubis_ecb_decrypt(buf[0], buf[0], &skey);

+       if (memcmp(buf[0], tests[x].ct, 16)) {

+          return CRYPT_FAIL_TESTVECTOR;

+       }

+

+   }

+   return CRYPT_OK;

+#endif

+}

+

+/** Terminate the context 

+   @param skey    The scheduled key

+*/

+void anubis_done(symmetric_key *skey)

+{

+}

+

+/**

+  Gets suitable key size

+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.

+  @return CRYPT_OK if the input key size is acceptable.

+*/

+int anubis_keysize(int *keysize)

+{

+   LTC_ARGCHK(keysize != NULL);

+   if (*keysize >= 40) {

+      *keysize = 40;

+   } else if (*keysize >= 36) {

+      *keysize = 36;

+   } else if (*keysize >= 32) {

+      *keysize = 32;

+   } else if (*keysize >= 28) {

+      *keysize = 28;

+   } else if (*keysize >= 24) {

+      *keysize = 24;

+   } else if (*keysize >= 20) {

+      *keysize = 20;

+   } else if (*keysize >= 16) {

+      *keysize = 16;

+   } else {

+      return CRYPT_INVALID_KEYSIZE;

+   }

+   return CRYPT_OK;

+}

+

+#endif

+

+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/anubis.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/blowfish.c b/src/ciphers/blowfish.c
similarity index 86%
rename from blowfish.c
rename to src/ciphers/blowfish.c
index 229ba88..3502983 100644
--- a/blowfish.c
+++ b/src/ciphers/blowfish.c
@@ -6,13 +6,17 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+/**
+  @file blowfish.c
+  Implementation of the Blowfish block cipher, Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef BLOWFISH
 
-const struct _cipher_descriptor blowfish_desc =
+const struct ltc_cipher_descriptor blowfish_desc =
 {
     "blowfish",
     0,
@@ -21,7 +25,9 @@
     &blowfish_ecb_encrypt,
     &blowfish_ecb_decrypt,
     &blowfish_test,
-    &blowfish_keysize
+    &blowfish_done,
+    &blowfish_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 ORIG_P[16 + 2] = {
@@ -291,14 +297,22 @@
         0xB74E6132UL, 0xCE77E25BUL, 0x578FDFE3UL, 0x3AC372E6UL  }
 };
 
+ /**
+    Initialize the Blowfish block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
                    symmetric_key *skey)
 {
    ulong32 x, y, z, A;
    unsigned char B[8];
 
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* check key length */
    if (keylen < 8 || keylen > 56) {
@@ -353,7 +367,7 @@
        }
    }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(B, sizeof(B));
 #endif
 
@@ -363,13 +377,19 @@
 #ifndef __GNUC__
 #define F(x) ((S1[byte(x,3)] + S2[byte(x,2)]) ^ S3[byte(x,1)]) + S4[byte(x,0)]
 #else
-#define F(x) ((key->blowfish.S[0][byte(x,3)] + key->blowfish.S[1][byte(x,2)]) ^ key->blowfish.S[2][byte(x,1)]) + key->blowfish.S[3][byte(x,0)]
+#define F(x) ((skey->blowfish.S[0][byte(x,3)] + skey->blowfish.S[1][byte(x,2)]) ^ skey->blowfish.S[2][byte(x,1)]) + skey->blowfish.S[3][byte(x,0)]
 #endif
 
-#ifdef CLEAN_STACK
-static void _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with Blowfish
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
    ulong32 L, R;
@@ -378,15 +398,15 @@
    ulong32 *S1, *S2, *S3, *S4;
 #endif
 
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
 
 #ifndef __GNUC__
-    S1 = key->blowfish.S[0];
-    S2 = key->blowfish.S[1];
-    S3 = key->blowfish.S[2];
-    S4 = key->blowfish.S[3];
+    S1 = skey->blowfish.S[0];
+    S2 = skey->blowfish.S[1];
+    S3 = skey->blowfish.S[2];
+    S4 = skey->blowfish.S[3];
 #endif
 
    /* load it */
@@ -395,33 +415,39 @@
 
    /* do 16 rounds */
    for (r = 0; r < 16; ) {
-      L ^= key->blowfish.K[r++];  R ^= F(L);
-      R ^= key->blowfish.K[r++];  L ^= F(R);
-      L ^= key->blowfish.K[r++];  R ^= F(L);
-      R ^= key->blowfish.K[r++];  L ^= F(R);
+      L ^= skey->blowfish.K[r++];  R ^= F(L);
+      R ^= skey->blowfish.K[r++];  L ^= F(R);
+      L ^= skey->blowfish.K[r++];  R ^= F(L);
+      R ^= skey->blowfish.K[r++];  L ^= F(R);
    }
 
    /* last keying */
-   R ^= key->blowfish.K[17];
-   L ^= key->blowfish.K[16];
+   R ^= skey->blowfish.K[17];
+   L ^= skey->blowfish.K[16];
 
    /* store */
    STORE32H(R, &ct[0]);
    STORE32H(L, &ct[4]);
 }
 
-#ifdef CLEAN_STACK
-void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-    _blowfish_ecb_encrypt(pt, ct, key);
+    _blowfish_ecb_encrypt(pt, ct, skey);
     burn_stack(sizeof(ulong32) * 2 + sizeof(int));
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with Blowfish
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
    ulong32 L, R;
@@ -430,15 +456,15 @@
    ulong32 *S1, *S2, *S3, *S4;
 #endif
 
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     
 #ifndef __GNUC__
-    S1 = key->blowfish.S[0];
-    S2 = key->blowfish.S[1];
-    S3 = key->blowfish.S[2];
-    S4 = key->blowfish.S[3];
+    S1 = skey->blowfish.S[0];
+    S2 = skey->blowfish.S[1];
+    S3 = skey->blowfish.S[2];
+    S4 = skey->blowfish.S[3];
 #endif
 
    /* load it */
@@ -446,15 +472,15 @@
    LOAD32H(L, &ct[4]);
 
    /* undo last keying */
-   R ^= key->blowfish.K[17];
-   L ^= key->blowfish.K[16];
+   R ^= skey->blowfish.K[17];
+   L ^= skey->blowfish.K[16];
 
    /* do 16 rounds */
    for (r = 15; r > 0; ) {
-      L ^= F(R); R ^= key->blowfish.K[r--];
-      R ^= F(L); L ^= key->blowfish.K[r--];
-      L ^= F(R); R ^= key->blowfish.K[r--];
-      R ^= F(L); L ^= key->blowfish.K[r--];
+      L ^= F(R); R ^= skey->blowfish.K[r--];
+      R ^= F(L); L ^= skey->blowfish.K[r--];
+      L ^= F(R); R ^= skey->blowfish.K[r--];
+      R ^= F(L); L ^= skey->blowfish.K[r--];
    }
 
    /* store */
@@ -462,15 +488,19 @@
    STORE32H(R, &pt[4]);
 }
 
-#ifdef CLEAN_STACK
-void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-    _blowfish_ecb_decrypt(ct, pt, key);
+    _blowfish_ecb_decrypt(ct, pt, skey);
     burn_stack(sizeof(ulong32) * 2 + sizeof(int));
 }
 #endif
 
 
+/**
+  Performs a self-test of the Blowfish block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int blowfish_test(void)
 {
  #ifndef LTC_TEST
@@ -525,17 +555,33 @@
  #endif
 }
 
-int blowfish_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void blowfish_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
+}
 
-   if (*desired_keysize < 8) {
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int blowfish_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+
+   if (*keysize < 8) {
       return CRYPT_INVALID_KEYSIZE;
-   } else if (*desired_keysize > 56) {
-      *desired_keysize = 56;
+   } else if (*keysize > 56) {
+      *keysize = 56;
    }
    return CRYPT_OK;
 }
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/blowfish.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/cast5.c b/src/ciphers/cast5.c
similarity index 89%
rename from cast5.c
rename to src/ciphers/cast5.c
index 45a8433..f4b045c 100644
--- a/cast5.c
+++ b/src/ciphers/cast5.c
@@ -6,14 +6,18 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* Implementation of CAST5 (RFC 2144) by Tom St Denis */
-#include "mycrypt.h"
+ 
+ /** 
+   @file cast5.c
+   Implementation of CAST5 (RFC 2144) by Tom St Denis 
+ */
+#include "tomcrypt.h"
 
 #ifdef CAST5
 
-const struct _cipher_descriptor cast5_desc = {
+const struct ltc_cipher_descriptor cast5_desc = {
    "cast5",
    15,
    5, 16, 8, 16,
@@ -21,7 +25,9 @@
    &cast5_ecb_encrypt,
    &cast5_ecb_decrypt,
    &cast5_test,
-   &cast5_keysize
+   &cast5_done,
+   &cast5_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 S1[256] = {
@@ -391,7 +397,15 @@
    #define GB(x, i) (((x[(15-i)>>2])>>(unsigned)(8*((15-i)&3)))&255)
 #endif   
 
-#ifdef CLEAN_STACK
+ /**
+    Initialize the CAST5 block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+#ifdef LTC_CLEAN_STACK
 static int _cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
@@ -401,8 +415,8 @@
    unsigned char buf[16];
    int y, i;
 
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (num_rounds != 12 && num_rounds != 16 && num_rounds != 0) {
       return CRYPT_INVALID_ROUNDS; 
@@ -418,7 +432,7 @@
 
    /* extend the key as required */
    zeromem(buf, sizeof(buf));
-   memcpy(buf, key, (size_t)keylen);
+   XMEMCPY(buf, key, (size_t)keylen);
 
    /* load and start the awful looking network */
    for (y = 0; y < 4; y++) {
@@ -466,7 +480,7 @@
 
    skey->cast5.keylen = keylen;
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, sizeof(buf));
    zeromem(x, sizeof(x));
    zeromem(z, sizeof(z));
@@ -475,7 +489,7 @@
    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    int z;
@@ -515,95 +529,111 @@
    return ((S1[byte(I, 3)] + S2[byte(I,2)]) ^ S3[byte(I,1)]) - S4[byte(I,0)];
 }
 
-#ifdef CLEAN_STACK
-static void _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with CAST5
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
    ulong32 R, L;
 
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    LOAD32H(L,&pt[0]); 
    LOAD32H(R,&pt[4]);
-   L ^= FI(R, key->cast5.K[0], key->cast5.K[16]);
-   R ^= FII(L, key->cast5.K[1], key->cast5.K[17]);
-   L ^= FIII(R, key->cast5.K[2], key->cast5.K[18]);
-   R ^= FI(L, key->cast5.K[3], key->cast5.K[19]);
-   L ^= FII(R, key->cast5.K[4], key->cast5.K[20]);
-   R ^= FIII(L, key->cast5.K[5], key->cast5.K[21]);
-   L ^= FI(R, key->cast5.K[6], key->cast5.K[22]);
-   R ^= FII(L, key->cast5.K[7], key->cast5.K[23]);
-   L ^= FIII(R, key->cast5.K[8], key->cast5.K[24]);
-   R ^= FI(L, key->cast5.K[9], key->cast5.K[25]);
-   L ^= FII(R, key->cast5.K[10], key->cast5.K[26]);
-   R ^= FIII(L, key->cast5.K[11], key->cast5.K[27]);
-   if (key->cast5.keylen > 10) {
-      L ^= FI(R, key->cast5.K[12], key->cast5.K[28]);
-      R ^= FII(L, key->cast5.K[13], key->cast5.K[29]);
-      L ^= FIII(R, key->cast5.K[14], key->cast5.K[30]);
-      R ^= FI(L, key->cast5.K[15], key->cast5.K[31]);
+   L ^= FI(R, skey->cast5.K[0], skey->cast5.K[16]);
+   R ^= FII(L, skey->cast5.K[1], skey->cast5.K[17]);
+   L ^= FIII(R, skey->cast5.K[2], skey->cast5.K[18]);
+   R ^= FI(L, skey->cast5.K[3], skey->cast5.K[19]);
+   L ^= FII(R, skey->cast5.K[4], skey->cast5.K[20]);
+   R ^= FIII(L, skey->cast5.K[5], skey->cast5.K[21]);
+   L ^= FI(R, skey->cast5.K[6], skey->cast5.K[22]);
+   R ^= FII(L, skey->cast5.K[7], skey->cast5.K[23]);
+   L ^= FIII(R, skey->cast5.K[8], skey->cast5.K[24]);
+   R ^= FI(L, skey->cast5.K[9], skey->cast5.K[25]);
+   L ^= FII(R, skey->cast5.K[10], skey->cast5.K[26]);
+   R ^= FIII(L, skey->cast5.K[11], skey->cast5.K[27]);
+   if (skey->cast5.keylen > 10) {
+      L ^= FI(R, skey->cast5.K[12], skey->cast5.K[28]);
+      R ^= FII(L, skey->cast5.K[13], skey->cast5.K[29]);
+      L ^= FIII(R, skey->cast5.K[14], skey->cast5.K[30]);
+      R ^= FI(L, skey->cast5.K[15], skey->cast5.K[31]);
    }
    STORE32H(R,&ct[0]);
    STORE32H(L,&ct[4]);
 }
 
 
-#ifdef CLEAN_STACK
-void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-   _cast5_ecb_encrypt(pt,ct,key);
+   _cast5_ecb_encrypt(pt,ct,skey);
    burn_stack(sizeof(ulong32)*3);
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with CAST5
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
    ulong32 R, L;
 
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    LOAD32H(R,&ct[0]); 
    LOAD32H(L,&ct[4]);
-   if (key->cast5.keylen > 10) {
-      R ^= FI(L, key->cast5.K[15], key->cast5.K[31]);
-      L ^= FIII(R, key->cast5.K[14], key->cast5.K[30]);
-      R ^= FII(L, key->cast5.K[13], key->cast5.K[29]);
-      L ^= FI(R, key->cast5.K[12], key->cast5.K[28]);
+   if (skey->cast5.keylen > 10) {
+      R ^= FI(L, skey->cast5.K[15], skey->cast5.K[31]);
+      L ^= FIII(R, skey->cast5.K[14], skey->cast5.K[30]);
+      R ^= FII(L, skey->cast5.K[13], skey->cast5.K[29]);
+      L ^= FI(R, skey->cast5.K[12], skey->cast5.K[28]);
    }
-   R ^= FIII(L, key->cast5.K[11], key->cast5.K[27]);
-   L ^= FII(R, key->cast5.K[10], key->cast5.K[26]);
-   R ^= FI(L, key->cast5.K[9], key->cast5.K[25]);
-   L ^= FIII(R, key->cast5.K[8], key->cast5.K[24]);
-   R ^= FII(L, key->cast5.K[7], key->cast5.K[23]);
-   L ^= FI(R, key->cast5.K[6], key->cast5.K[22]);
-   R ^= FIII(L, key->cast5.K[5], key->cast5.K[21]);
-   L ^= FII(R, key->cast5.K[4], key->cast5.K[20]);
-   R ^= FI(L, key->cast5.K[3], key->cast5.K[19]);
-   L ^= FIII(R, key->cast5.K[2], key->cast5.K[18]);
-   R ^= FII(L, key->cast5.K[1], key->cast5.K[17]);
-   L ^= FI(R, key->cast5.K[0], key->cast5.K[16]);
+   R ^= FIII(L, skey->cast5.K[11], skey->cast5.K[27]);
+   L ^= FII(R, skey->cast5.K[10], skey->cast5.K[26]);
+   R ^= FI(L, skey->cast5.K[9], skey->cast5.K[25]);
+   L ^= FIII(R, skey->cast5.K[8], skey->cast5.K[24]);
+   R ^= FII(L, skey->cast5.K[7], skey->cast5.K[23]);
+   L ^= FI(R, skey->cast5.K[6], skey->cast5.K[22]);
+   R ^= FIII(L, skey->cast5.K[5], skey->cast5.K[21]);
+   L ^= FII(R, skey->cast5.K[4], skey->cast5.K[20]);
+   R ^= FI(L, skey->cast5.K[3], skey->cast5.K[19]);
+   L ^= FIII(R, skey->cast5.K[2], skey->cast5.K[18]);
+   R ^= FII(L, skey->cast5.K[1], skey->cast5.K[17]);
+   L ^= FI(R, skey->cast5.K[0], skey->cast5.K[16]);
    STORE32H(L,&pt[0]);
    STORE32H(R,&pt[4]);
 }
 
-#ifdef CLEAN_STACK
-void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-   _cast5_ecb_decrypt(ct,pt,key);
+   _cast5_ecb_decrypt(ct,pt,skey);
    burn_stack(sizeof(ulong32)*3);
 }
 #endif
 
+/**
+  Performs a self-test of the CAST5 block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int cast5_test(void)
 {
  #ifndef LTC_TEST
@@ -655,15 +685,31 @@
  #endif
 }
 
-int cast5_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void cast5_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
-   if (*desired_keysize < 5) {
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int cast5_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 5) {
       return CRYPT_INVALID_KEYSIZE;
-   } else if (*desired_keysize > 16) {
-      *desired_keysize = 16;
+   } else if (*keysize > 16) {
+      *keysize = 16;
    }
    return CRYPT_OK;
 } 
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/cast5.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/des.c b/src/ciphers/des.c
similarity index 96%
rename from des.c
rename to src/ciphers/des.c
index 090c594..84258d0 100644
--- a/des.c
+++ b/src/ciphers/des.c
@@ -6,17 +6,22 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* DES code submitted by Dobes Vandermeer */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/** 
+  @file des.c
+  DES code submitted by Dobes Vandermeer 
+*/
 
 #ifdef DES
 
 #define EN0 0 
 #define DE1 1
 
-const struct _cipher_descriptor des_desc =
+#if 0
+const struct ltc_cipher_descriptor des_desc =
 {
     "des",
     13,
@@ -25,10 +30,13 @@
     &des_ecb_encrypt,
     &des_ecb_decrypt,
     &des_test,
-    &des_keysize
+    &des_done,
+    &des_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
+#endif
 
-const struct _cipher_descriptor des3_desc =
+const struct ltc_cipher_descriptor des3_desc =
 {
     "3des",
     14,
@@ -37,7 +45,9 @@
     &des3_ecb_encrypt,
     &des3_ecb_decrypt,
     &des3_test,
-    &des3_keysize
+    &des3_done,
+    &des3_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 bytebit[8] =
@@ -239,7 +249,7 @@
     0x00001040UL, 0x00040040UL, 0x10000000UL, 0x10041000UL
 };
 
-#ifndef SMALL_CODE
+#ifndef LTC_SMALL_CODE
 
 static const ulong64 des_ip[8][256] = {
 
@@ -1292,10 +1302,10 @@
 
 static void cookey(const ulong32 *raw1, ulong32 *keyout);
 
-#ifdef CLEAN_STACK
-void _deskey(const unsigned char *key, short edf, ulong32 *keyout)
+#ifdef LTC_CLEAN_STACK
+static void _deskey(const unsigned char *key, short edf, ulong32 *keyout)
 #else
-void deskey(const unsigned char *key, short edf, ulong32 *keyout)
+static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 #endif
 {
     ulong32 i, j, l, m, n, kn[32];
@@ -1344,15 +1354,15 @@
     cookey(kn, keyout);
 }
 
-#ifdef CLEAN_STACK
-void deskey(const unsigned char *key, short edf, ulong32 *keyout)
+#ifdef LTC_CLEAN_STACK
+static void deskey(const unsigned char *key, short edf, ulong32 *keyout)
 {
    _deskey(key, edf, keyout);
    burn_stack(sizeof(int)*5 + sizeof(ulong32)*32 + sizeof(unsigned char)*112);
 }
 #endif
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void _cookey(const ulong32 *raw1, ulong32 *keyout)
 #else
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
@@ -1377,10 +1387,10 @@
         *cook++ |= (*raw1 & 0x0000003fL);
     }
 
-    memcpy(keyout, dough, sizeof dough);
+    XMEMCPY(keyout, dough, sizeof dough);
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
 {
    _cookey(raw1, keyout);
@@ -1388,19 +1398,19 @@
 }
 #endif
 
-#ifndef CLEAN_STACK
+#ifndef LTC_CLEAN_STACK
 static void desfunc(ulong32 *block, const ulong32 *keys)
 #else
 static void _desfunc(ulong32 *block, const ulong32 *keys)
 #endif
 {
     ulong32 work, right, leftt;
-    int round;
+    int cur_round;
 
     leftt = block[0];
     right = block[1];
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     work = ((leftt >> 4)  ^ right) & 0x0f0f0f0fL;
     right ^= work;
     leftt ^= (work << 4);
@@ -1417,12 +1427,12 @@
     leftt ^= work;
     right ^= (work << 8);
 
-    right = ROL(right, 1);
+    right = ROLc(right, 1);
     work = (leftt ^ right) & 0xaaaaaaaaL;
     
     leftt ^= work;
     right ^= work;
-    leftt = ROL(leftt, 1);
+    leftt = ROLc(leftt, 1);
 #else 
    {
       ulong64 tmp;
@@ -1439,8 +1449,8 @@
    }
 #endif
 
-    for (round = 0; round < 8; round++) {
-        work  = ROR(right, 4) ^ *keys++;
+    for (cur_round = 0; cur_round < 8; cur_round++) {
+        work  = RORc(right, 4) ^ *keys++;
         leftt ^= SP7[work        & 0x3fL]
               ^ SP5[(work >>  8) & 0x3fL]
               ^ SP3[(work >> 16) & 0x3fL]
@@ -1451,7 +1461,7 @@
               ^  SP4[(work >> 16) & 0x3fL]
               ^  SP2[(work >> 24) & 0x3fL];
 
-        work = ROR(leftt, 4) ^ *keys++;
+        work = RORc(leftt, 4) ^ *keys++;
         right ^= SP7[ work        & 0x3fL]
               ^  SP5[(work >>  8) & 0x3fL]
               ^  SP3[(work >> 16) & 0x3fL]
@@ -1463,16 +1473,16 @@
               ^  SP2[(work >> 24) & 0x3fL];
     }
 
-#ifdef SMALL_CODE    
-    right = ROR(right, 1);
+#ifdef LTC_SMALL_CODE    
+    right = RORc(right, 1);
     work = (leftt ^ right) & 0xaaaaaaaaL;
     leftt ^= work;
     right ^= work;
-    leftt = ROR(leftt, 1);
+    leftt = RORc(leftt, 1);
     work = ((leftt >> 8) ^ right) & 0x00ff00ffL;
     right ^= work;
     leftt ^= (work << 8);
-    // --
+    /* -- */
     work = ((leftt >> 2) ^ right) & 0x33333333L;
     right ^= work;
     leftt ^= (work << 2);
@@ -1502,7 +1512,7 @@
     block[1] = leftt;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void desfunc(ulong32 *block, const ulong32 *keys)
 {
    _desfunc(block, keys);
@@ -1510,10 +1520,19 @@
 }
 #endif
 
+#if 0
+ /**
+    Initialize the DES block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
 int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
-    _ARGCHK(key != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(key != NULL);
+    LTC_ARGCHK(skey != NULL);
 
     if (num_rounds != 0 && num_rounds != 16) {
         return CRYPT_INVALID_ROUNDS;
@@ -1528,13 +1547,22 @@
 
     return CRYPT_OK;
 }
+#endif
 
+ /**
+    Initialize the 3DES-EDE block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
 int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
-    _ARGCHK(key != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(key != NULL);
+    LTC_ARGCHK(skey != NULL);
 
-    if( num_rounds != 0 && num_rounds != 16) {
+    if(num_rounds != 0 && num_rounds != 16) {
         return CRYPT_INVALID_ROUNDS;
     }
 
@@ -1553,63 +1581,94 @@
     return CRYPT_OK;
 }
 
-void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#if 0
+/**
+  Encrypts a block of text with DES
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
     ulong32 work[2];
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     LOAD32H(work[0], pt+0);
     LOAD32H(work[1], pt+4);
-    desfunc(work, key->des.ek);
+    desfunc(work, skey->des.ek);
     STORE32H(work[0],ct+0);
     STORE32H(work[1],ct+4);
 }
 
-void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with DES
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
     ulong32 work[2];
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     LOAD32H(work[0], ct+0);
     LOAD32H(work[1], ct+4);
-    desfunc(work, key->des.dk);
+    desfunc(work, skey->des.dk);
     STORE32H(work[0],pt+0);
     STORE32H(work[1],pt+4);
 }
+#endif
 
-void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with 3DES-EDE
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
     ulong32 work[2];
     
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     LOAD32H(work[0], pt+0);
     LOAD32H(work[1], pt+4);
-    desfunc(work, key->des3.ek[0]);
-    desfunc(work, key->des3.ek[1]);
-    desfunc(work, key->des3.ek[2]);
+    desfunc(work, skey->des3.ek[0]);
+    desfunc(work, skey->des3.ek[1]);
+    desfunc(work, skey->des3.ek[2]);
     STORE32H(work[0],ct+0);
     STORE32H(work[1],ct+4);
 }
 
-void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with 3DES-EDE
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
     ulong32 work[2];
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     LOAD32H(work[0], ct+0);
     LOAD32H(work[1], ct+4);
-    desfunc(work, key->des3.dk[0]);
-    desfunc(work, key->des3.dk[1]);
-    desfunc(work, key->des3.dk[2]);
+    desfunc(work, skey->des3.dk[0]);
+    desfunc(work, skey->des3.dk[1]);
+    desfunc(work, skey->des3.dk[2]);
     STORE32H(work[0],pt+0);
     STORE32H(work[1],pt+4);
 }
 
+#if 0
+/**
+  Performs a self-test of the DES block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int des_test(void)
 {
  #ifndef LTC_TEST
@@ -1617,7 +1676,7 @@
  #else    
     int err;
     static const struct des_test_case {
-        int num, mode; // mode 1 = encrypt
+        int num, mode; /* mode 1 = encrypt */
         unsigned char key[8], txt[8], out[8];
     } cases[] = {
         { 1, 1,     { 0x10, 0x31, 0x6E, 0x02, 0x8C, 0x8F, 0x3B, 0x4A },
@@ -1752,6 +1811,7 @@
     return CRYPT_OK;
   #endif
 }
+#endif
 
 int des3_test(void)
 {
@@ -1789,25 +1849,58 @@
  #endif
 }
 
-int des_keysize(int *desired_keysize)
+#if 0
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void des_done(symmetric_key *skey)
 {
-    _ARGCHK(desired_keysize != NULL);
-    if(*desired_keysize < 8) {
-        return CRYPT_INVALID_KEYSIZE;
-    }
-    *desired_keysize = 8;
-    return CRYPT_OK;
+}
+#endif
+
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void des3_done(symmetric_key *skey)
+{
 }
 
-int des3_keysize(int *desired_keysize)
+
+#if 0
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int des_keysize(int *keysize)
 {
-    _ARGCHK(desired_keysize != NULL);
-    if(*desired_keysize < 24) {
+    LTC_ARGCHK(keysize != NULL);
+    if(*keysize < 8) {
         return CRYPT_INVALID_KEYSIZE;
     }
-    *desired_keysize = 24;
+    *keysize = 8;
+    return CRYPT_OK;
+}
+#endif
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int des3_keysize(int *keysize)
+{
+    LTC_ARGCHK(keysize != NULL);
+    if(*keysize < 24) {
+        return CRYPT_INVALID_KEYSIZE;
+    }
+    *keysize = 24;
     return CRYPT_OK;
 }
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/des.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/ciphers/khazad.c b/src/ciphers/khazad.c
new file mode 100644
index 0000000..d07134c
--- /dev/null
+++ b/src/ciphers/khazad.c
@@ -0,0 +1,851 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file khazad.c
+  Khazad implementation derived from public domain source
+  Authors: Paulo S.L.M. Barreto and Vincent Rijmen.
+*/
+
+#ifdef KHAZAD
+
+const struct ltc_cipher_descriptor khazad_desc = {
+   "khazad",
+   18,
+   16, 16, 8, 8,
+   &khazad_setup,
+   &khazad_ecb_encrypt,
+   &khazad_ecb_decrypt,
+   &khazad_test,
+   &khazad_done,
+   &khazad_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+#define R      8 
+#define KEYSIZE      128 
+#define KEYSIZEB   (KEYSIZE/8) 
+#define BLOCKSIZE   64 
+#define BLOCKSIZEB   (BLOCKSIZE/8) 
+
+static const ulong64 T0[256] = {
+    CONST64(0xbad3d268bbb96a01), CONST64(0x54fc4d19e59a66b1), CONST64(0x2f71bc93e26514cd), CONST64(0x749ccdb925871b51),
+    CONST64(0x53f55102f7a257a4), CONST64(0xd3686bb8d0d6be03), CONST64(0xd26b6fbdd6deb504), CONST64(0x4dd72964b35285fe),
+    CONST64(0x50f05d0dfdba4aad), CONST64(0xace98a26cf09e063), CONST64(0x8d8a0e83091c9684), CONST64(0xbfdcc679a5914d1a),
+    CONST64(0x7090ddad3da7374d), CONST64(0x52f65507f1aa5ca3), CONST64(0x9ab352c87ba417e1), CONST64(0x4cd42d61b55a8ef9),
+    CONST64(0xea238f65460320ac), CONST64(0xd56273a6c4e68411), CONST64(0x97a466f155cc68c2), CONST64(0xd16e63b2dcc6a80d),
+    CONST64(0x3355ccffaa85d099), CONST64(0x51f35908fbb241aa), CONST64(0x5bed712ac7e20f9c), CONST64(0xa6f7a204f359ae55),
+    CONST64(0xde7f5f81febec120), CONST64(0x48d83d75ad7aa2e5), CONST64(0xa8e59a32d729cc7f), CONST64(0x99b65ec771bc0ae8),
+    CONST64(0xdb704b90e096e63b), CONST64(0x3256c8faac8ddb9e), CONST64(0xb7c4e65195d11522), CONST64(0xfc19d72b32b3aace),
+    CONST64(0xe338ab48704b7393), CONST64(0x9ebf42dc63843bfd), CONST64(0x91ae7eef41fc52d0), CONST64(0x9bb056cd7dac1ce6),
+    CONST64(0xe23baf4d76437894), CONST64(0xbbd0d66dbdb16106), CONST64(0x41c319589b32f1da), CONST64(0x6eb2a5cb7957e517),
+    CONST64(0xa5f2ae0bf941b35c), CONST64(0xcb400bc08016564b), CONST64(0x6bbdb1da677fc20c), CONST64(0x95a26efb59dc7ecc),
+    CONST64(0xa1febe1fe1619f40), CONST64(0xf308eb1810cbc3e3), CONST64(0xb1cefe4f81e12f30), CONST64(0x0206080a0c10160e),
+    CONST64(0xcc4917db922e675e), CONST64(0xc45137f3a26e3f66), CONST64(0x1d2774694ee8cf53), CONST64(0x143c504478a09c6c),
+    CONST64(0xc3582be8b0560e73), CONST64(0x63a591f2573f9a34), CONST64(0xda734f95e69eed3c), CONST64(0x5de76934d3d2358e),
+    CONST64(0x5fe1613edfc22380), CONST64(0xdc79578bf2aed72e), CONST64(0x7d87e99413cf486e), CONST64(0xcd4a13de94266c59),
+    CONST64(0x7f81e19e1fdf5e60), CONST64(0x5aee752fc1ea049b), CONST64(0x6cb4adc17547f319), CONST64(0x5ce46d31d5da3e89),
+    CONST64(0xf704fb0c08ebefff), CONST64(0x266a98bed42d47f2), CONST64(0xff1cdb2438abb7c7), CONST64(0xed2a937e543b11b9),
+    CONST64(0xe825876f4a1336a2), CONST64(0x9dba4ed3699c26f4), CONST64(0x6fb1a1ce7f5fee10), CONST64(0x8e8f028c03048b8d),
+    CONST64(0x192b647d56c8e34f), CONST64(0xa0fdba1ae7699447), CONST64(0xf00de7171ad3deea), CONST64(0x89861e97113cba98),
+    CONST64(0x0f113c332278692d), CONST64(0x07091c1b12383115), CONST64(0xafec8629c511fd6a), CONST64(0xfb10cb30208b9bdb),
+    CONST64(0x0818202830405838), CONST64(0x153f54417ea8976b), CONST64(0x0d1734392e687f23), CONST64(0x040c101418202c1c),
+    CONST64(0x0103040506080b07), CONST64(0x64ac8de94507ab21), CONST64(0xdf7c5b84f8b6ca27), CONST64(0x769ac5b329970d5f),
+    CONST64(0x798bf9800bef6472), CONST64(0xdd7a538ef4a6dc29), CONST64(0x3d47f4c98ef5b2b3), CONST64(0x163a584e74b08a62),
+    CONST64(0x3f41fcc382e5a4bd), CONST64(0x3759dcebb2a5fc85), CONST64(0x6db7a9c4734ff81e), CONST64(0x3848e0d890dd95a8),
+    CONST64(0xb9d6de67b1a17708), CONST64(0x7395d1a237bf2a44), CONST64(0xe926836a4c1b3da5), CONST64(0x355fd4e1beb5ea8b),
+    CONST64(0x55ff491ce3926db6), CONST64(0x7193d9a83baf3c4a), CONST64(0x7b8df18a07ff727c), CONST64(0x8c890a860f149d83),
+    CONST64(0x7296d5a731b72143), CONST64(0x88851a921734b19f), CONST64(0xf607ff090ee3e4f8), CONST64(0x2a7ea882fc4d33d6),
+    CONST64(0x3e42f8c684edafba), CONST64(0x5ee2653bd9ca2887), CONST64(0x27699cbbd2254cf5), CONST64(0x46ca0543890ac0cf),
+    CONST64(0x0c14303c28607424), CONST64(0x65af89ec430fa026), CONST64(0x68b8bdd56d67df05), CONST64(0x61a399f85b2f8c3a),
+    CONST64(0x03050c0f0a181d09), CONST64(0xc15e23e2bc46187d), CONST64(0x57f94116ef827bb8), CONST64(0xd6677fa9cefe9918),
+    CONST64(0xd976439aec86f035), CONST64(0x58e87d25cdfa1295), CONST64(0xd875479fea8efb32), CONST64(0x66aa85e34917bd2f),
+    CONST64(0xd7647bacc8f6921f), CONST64(0x3a4ee8d29ccd83a6), CONST64(0xc84507cf8a0e4b42), CONST64(0x3c44f0cc88fdb9b4),
+    CONST64(0xfa13cf35268390dc), CONST64(0x96a762f453c463c5), CONST64(0xa7f4a601f551a552), CONST64(0x98b55ac277b401ef),
+    CONST64(0xec29977b52331abe), CONST64(0xb8d5da62b7a97c0f), CONST64(0xc7543bfca876226f), CONST64(0xaeef822cc319f66d),
+    CONST64(0x69bbb9d06b6fd402), CONST64(0x4bdd317aa762bfec), CONST64(0xabe0963ddd31d176), CONST64(0xa9e69e37d121c778),
+    CONST64(0x67a981e64f1fb628), CONST64(0x0a1e28223c504e36), CONST64(0x47c901468f02cbc8), CONST64(0xf20bef1d16c3c8e4),
+    CONST64(0xb5c2ee5b99c1032c), CONST64(0x226688aacc0d6bee), CONST64(0xe532b356647b4981), CONST64(0xee2f9f715e230cb0),
+    CONST64(0xbedfc27ca399461d), CONST64(0x2b7dac87fa4538d1), CONST64(0x819e3ebf217ce2a0), CONST64(0x1236485a6c90a67e),
+    CONST64(0x839836b52d6cf4ae), CONST64(0x1b2d6c775ad8f541), CONST64(0x0e1238362470622a), CONST64(0x23658cafca0560e9),
+    CONST64(0xf502f30604fbf9f1), CONST64(0x45cf094c8312ddc6), CONST64(0x216384a5c61576e7), CONST64(0xce4f1fd19e3e7150),
+    CONST64(0x49db3970ab72a9e2), CONST64(0x2c74b09ce87d09c4), CONST64(0xf916c33a2c9b8dd5), CONST64(0xe637bf596e635488),
+    CONST64(0xb6c7e25493d91e25), CONST64(0x2878a088f05d25d8), CONST64(0x17395c4b72b88165), CONST64(0x829b32b02b64ffa9),
+    CONST64(0x1a2e68725cd0fe46), CONST64(0x8b80169d1d2cac96), CONST64(0xfe1fdf213ea3bcc0), CONST64(0x8a8312981b24a791),
+    CONST64(0x091b242d3648533f), CONST64(0xc94603ca8c064045), CONST64(0x879426a1354cd8b2), CONST64(0x4ed2256bb94a98f7),
+    CONST64(0xe13ea3427c5b659d), CONST64(0x2e72b896e46d1fca), CONST64(0xe431b75362734286), CONST64(0xe03da7477a536e9a),
+    CONST64(0xeb208b60400b2bab), CONST64(0x90ad7aea47f459d7), CONST64(0xa4f1aa0eff49b85b), CONST64(0x1e22786644f0d25a),
+    CONST64(0x85922eab395ccebc), CONST64(0x60a09dfd5d27873d), CONST64(0x0000000000000000), CONST64(0x256f94b1de355afb),
+    CONST64(0xf401f70302f3f2f6), CONST64(0xf10ee3121cdbd5ed), CONST64(0x94a16afe5fd475cb), CONST64(0x0b1d2c273a584531),
+    CONST64(0xe734bb5c686b5f8f), CONST64(0x759fc9bc238f1056), CONST64(0xef2c9b74582b07b7), CONST64(0x345cd0e4b8bde18c),
+    CONST64(0x3153c4f5a695c697), CONST64(0xd46177a3c2ee8f16), CONST64(0xd06d67b7dacea30a), CONST64(0x869722a43344d3b5),
+    CONST64(0x7e82e59b19d75567), CONST64(0xadea8e23c901eb64), CONST64(0xfd1ad32e34bba1c9), CONST64(0x297ba48df6552edf),
+    CONST64(0x3050c0f0a09dcd90), CONST64(0x3b4decd79ac588a1), CONST64(0x9fbc46d9658c30fa), CONST64(0xf815c73f2a9386d2),
+    CONST64(0xc6573ff9ae7e2968), CONST64(0x13354c5f6a98ad79), CONST64(0x060a181e14303a12), CONST64(0x050f14111e28271b),
+    CONST64(0xc55233f6a4663461), CONST64(0x113344556688bb77), CONST64(0x7799c1b62f9f0658), CONST64(0x7c84ed9115c74369),
+    CONST64(0x7a8ef58f01f7797b), CONST64(0x7888fd850de76f75), CONST64(0x365ad8eeb4adf782), CONST64(0x1c24706c48e0c454),
+    CONST64(0x394be4dd96d59eaf), CONST64(0x59eb7920cbf21992), CONST64(0x1828607850c0e848), CONST64(0x56fa4513e98a70bf),
+    CONST64(0xb3c8f6458df1393e), CONST64(0xb0cdfa4a87e92437), CONST64(0x246c90b4d83d51fc), CONST64(0x206080a0c01d7de0),
+    CONST64(0xb2cbf2408bf93239), CONST64(0x92ab72e04be44fd9), CONST64(0xa3f8b615ed71894e), CONST64(0xc05d27e7ba4e137a),
+    CONST64(0x44cc0d49851ad6c1), CONST64(0x62a695f751379133), CONST64(0x103040506080b070), CONST64(0xb4c1ea5e9fc9082b),
+    CONST64(0x84912aae3f54c5bb), CONST64(0x43c511529722e7d4), CONST64(0x93a876e54dec44de), CONST64(0xc25b2fedb65e0574),
+    CONST64(0x4ade357fa16ab4eb), CONST64(0xbddace73a9815b14), CONST64(0x8f8c0689050c808a), CONST64(0x2d77b499ee7502c3),
+    CONST64(0xbcd9ca76af895013), CONST64(0x9cb94ad66f942df3), CONST64(0x6abeb5df6177c90b), CONST64(0x40c01d5d9d3afadd),
+    CONST64(0xcf4c1bd498367a57), CONST64(0xa2fbb210eb798249), CONST64(0x809d3aba2774e9a7), CONST64(0x4fd1216ebf4293f0),
+    CONST64(0x1f217c6342f8d95d), CONST64(0xca430fc5861e5d4c), CONST64(0xaae39238db39da71), CONST64(0x42c61557912aecd3),
+};
+
+static const ulong64 T1[256] = {
+    CONST64(0xd3ba68d2b9bb016a), CONST64(0xfc54194d9ae5b166), CONST64(0x712f93bc65e2cd14), CONST64(0x9c74b9cd8725511b),
+    CONST64(0xf5530251a2f7a457), CONST64(0x68d3b86bd6d003be), CONST64(0x6bd2bd6fded604b5), CONST64(0xd74d642952b3fe85),
+    CONST64(0xf0500d5dbafdad4a), CONST64(0xe9ac268a09cf63e0), CONST64(0x8a8d830e1c098496), CONST64(0xdcbf79c691a51a4d),
+    CONST64(0x9070addda73d4d37), CONST64(0xf6520755aaf1a35c), CONST64(0xb39ac852a47be117), CONST64(0xd44c612d5ab5f98e),
+    CONST64(0x23ea658f0346ac20), CONST64(0x62d5a673e6c41184), CONST64(0xa497f166cc55c268), CONST64(0x6ed1b263c6dc0da8),
+    CONST64(0x5533ffcc85aa99d0), CONST64(0xf3510859b2fbaa41), CONST64(0xed5b2a71e2c79c0f), CONST64(0xf7a604a259f355ae),
+    CONST64(0x7fde815fbefe20c1), CONST64(0xd848753d7aade5a2), CONST64(0xe5a8329a29d77fcc), CONST64(0xb699c75ebc71e80a),
+    CONST64(0x70db904b96e03be6), CONST64(0x5632fac88dac9edb), CONST64(0xc4b751e6d1952215), CONST64(0x19fc2bd7b332ceaa),
+    CONST64(0x38e348ab4b709373), CONST64(0xbf9edc428463fd3b), CONST64(0xae91ef7efc41d052), CONST64(0xb09bcd56ac7de61c),
+    CONST64(0x3be24daf43769478), CONST64(0xd0bb6dd6b1bd0661), CONST64(0xc3415819329bdaf1), CONST64(0xb26ecba5577917e5),
+    CONST64(0xf2a50bae41f95cb3), CONST64(0x40cbc00b16804b56), CONST64(0xbd6bdab17f670cc2), CONST64(0xa295fb6edc59cc7e),
+    CONST64(0xfea11fbe61e1409f), CONST64(0x08f318ebcb10e3c3), CONST64(0xceb14ffee181302f), CONST64(0x06020a08100c0e16),
+    CONST64(0x49ccdb172e925e67), CONST64(0x51c4f3376ea2663f), CONST64(0x271d6974e84e53cf), CONST64(0x3c144450a0786c9c),
+    CONST64(0x58c3e82b56b0730e), CONST64(0xa563f2913f57349a), CONST64(0x73da954f9ee63ced), CONST64(0xe75d3469d2d38e35),
+    CONST64(0xe15f3e61c2df8023), CONST64(0x79dc8b57aef22ed7), CONST64(0x877d94e9cf136e48), CONST64(0x4acdde132694596c),
+    CONST64(0x817f9ee1df1f605e), CONST64(0xee5a2f75eac19b04), CONST64(0xb46cc1ad477519f3), CONST64(0xe45c316ddad5893e),
+    CONST64(0x04f70cfbeb08ffef), CONST64(0x6a26be982dd4f247), CONST64(0x1cff24dbab38c7b7), CONST64(0x2aed7e933b54b911),
+    CONST64(0x25e86f87134aa236), CONST64(0xba9dd34e9c69f426), CONST64(0xb16fcea15f7f10ee), CONST64(0x8f8e8c0204038d8b),
+    CONST64(0x2b197d64c8564fe3), CONST64(0xfda01aba69e74794), CONST64(0x0df017e7d31aeade), CONST64(0x8689971e3c1198ba),
+    CONST64(0x110f333c78222d69), CONST64(0x09071b1c38121531), CONST64(0xecaf298611c56afd), CONST64(0x10fb30cb8b20db9b),
+    CONST64(0x1808282040303858), CONST64(0x3f154154a87e6b97), CONST64(0x170d3934682e237f), CONST64(0x0c04141020181c2c),
+    CONST64(0x030105040806070b), CONST64(0xac64e98d074521ab), CONST64(0x7cdf845bb6f827ca), CONST64(0x9a76b3c597295f0d),
+    CONST64(0x8b7980f9ef0b7264), CONST64(0x7add8e53a6f429dc), CONST64(0x473dc9f4f58eb3b2), CONST64(0x3a164e58b074628a),
+    CONST64(0x413fc3fce582bda4), CONST64(0x5937ebdca5b285fc), CONST64(0xb76dc4a94f731ef8), CONST64(0x4838d8e0dd90a895),
+    CONST64(0xd6b967dea1b10877), CONST64(0x9573a2d1bf37442a), CONST64(0x26e96a831b4ca53d), CONST64(0x5f35e1d4b5be8bea),
+    CONST64(0xff551c4992e3b66d), CONST64(0x9371a8d9af3b4a3c), CONST64(0x8d7b8af1ff077c72), CONST64(0x898c860a140f839d),
+    CONST64(0x9672a7d5b7314321), CONST64(0x8588921a34179fb1), CONST64(0x07f609ffe30ef8e4), CONST64(0x7e2a82a84dfcd633),
+    CONST64(0x423ec6f8ed84baaf), CONST64(0xe25e3b65cad98728), CONST64(0x6927bb9c25d2f54c), CONST64(0xca4643050a89cfc0),
+    CONST64(0x140c3c3060282474), CONST64(0xaf65ec890f4326a0), CONST64(0xb868d5bd676d05df), CONST64(0xa361f8992f5b3a8c),
+    CONST64(0x05030f0c180a091d), CONST64(0x5ec1e22346bc7d18), CONST64(0xf957164182efb87b), CONST64(0x67d6a97ffece1899),
+    CONST64(0x76d99a4386ec35f0), CONST64(0xe858257dfacd9512), CONST64(0x75d89f478eea32fb), CONST64(0xaa66e38517492fbd),
+    CONST64(0x64d7ac7bf6c81f92), CONST64(0x4e3ad2e8cd9ca683), CONST64(0x45c8cf070e8a424b), CONST64(0x443cccf0fd88b4b9),
+    CONST64(0x13fa35cf8326dc90), CONST64(0xa796f462c453c563), CONST64(0xf4a701a651f552a5), CONST64(0xb598c25ab477ef01),
+    CONST64(0x29ec7b973352be1a), CONST64(0xd5b862daa9b70f7c), CONST64(0x54c7fc3b76a86f22), CONST64(0xefae2c8219c36df6),
+    CONST64(0xbb69d0b96f6b02d4), CONST64(0xdd4b7a3162a7ecbf), CONST64(0xe0ab3d9631dd76d1), CONST64(0xe6a9379e21d178c7),
+    CONST64(0xa967e6811f4f28b6), CONST64(0x1e0a2228503c364e), CONST64(0xc9474601028fc8cb), CONST64(0x0bf21defc316e4c8),
+    CONST64(0xc2b55beec1992c03), CONST64(0x6622aa880dccee6b), CONST64(0x32e556b37b648149), CONST64(0x2fee719f235eb00c),
+    CONST64(0xdfbe7cc299a31d46), CONST64(0x7d2b87ac45fad138), CONST64(0x9e81bf3e7c21a0e2), CONST64(0x36125a48906c7ea6),
+    CONST64(0x9883b5366c2daef4), CONST64(0x2d1b776cd85a41f5), CONST64(0x120e363870242a62), CONST64(0x6523af8c05cae960),
+    CONST64(0x02f506f3fb04f1f9), CONST64(0xcf454c091283c6dd), CONST64(0x6321a58415c6e776), CONST64(0x4fced11f3e9e5071),
+    CONST64(0xdb49703972abe2a9), CONST64(0x742c9cb07de8c409), CONST64(0x16f93ac39b2cd58d), CONST64(0x37e659bf636e8854),
+    CONST64(0xc7b654e2d993251e), CONST64(0x782888a05df0d825), CONST64(0x39174b5cb8726581), CONST64(0x9b82b032642ba9ff),
+    CONST64(0x2e1a7268d05c46fe), CONST64(0x808b9d162c1d96ac), CONST64(0x1ffe21dfa33ec0bc), CONST64(0x838a9812241b91a7),
+    CONST64(0x1b092d2448363f53), CONST64(0x46c9ca03068c4540), CONST64(0x9487a1264c35b2d8), CONST64(0xd24e6b254ab9f798),
+    CONST64(0x3ee142a35b7c9d65), CONST64(0x722e96b86de4ca1f), CONST64(0x31e453b773628642), CONST64(0x3de047a7537a9a6e),
+    CONST64(0x20eb608b0b40ab2b), CONST64(0xad90ea7af447d759), CONST64(0xf1a40eaa49ff5bb8), CONST64(0x221e6678f0445ad2),
+    CONST64(0x9285ab2e5c39bcce), CONST64(0xa060fd9d275d3d87), CONST64(0x0000000000000000), CONST64(0x6f25b19435defb5a),
+    CONST64(0x01f403f7f302f6f2), CONST64(0x0ef112e3db1cedd5), CONST64(0xa194fe6ad45fcb75), CONST64(0x1d0b272c583a3145),
+    CONST64(0x34e75cbb6b688f5f), CONST64(0x9f75bcc98f235610), CONST64(0x2cef749b2b58b707), CONST64(0x5c34e4d0bdb88ce1),
+    CONST64(0x5331f5c495a697c6), CONST64(0x61d4a377eec2168f), CONST64(0x6dd0b767ceda0aa3), CONST64(0x9786a4224433b5d3),
+    CONST64(0x827e9be5d7196755), CONST64(0xeaad238e01c964eb), CONST64(0x1afd2ed3bb34c9a1), CONST64(0x7b298da455f6df2e),
+    CONST64(0x5030f0c09da090cd), CONST64(0x4d3bd7ecc59aa188), CONST64(0xbc9fd9468c65fa30), CONST64(0x15f83fc7932ad286),
+    CONST64(0x57c6f93f7eae6829), CONST64(0x35135f4c986a79ad), CONST64(0x0a061e183014123a), CONST64(0x0f051114281e1b27),
+    CONST64(0x52c5f63366a46134), CONST64(0x33115544886677bb), CONST64(0x9977b6c19f2f5806), CONST64(0x847c91edc7156943),
+    CONST64(0x8e7a8ff5f7017b79), CONST64(0x887885fde70d756f), CONST64(0x5a36eed8adb482f7), CONST64(0x241c6c70e04854c4),
+    CONST64(0x4b39dde4d596af9e), CONST64(0xeb592079f2cb9219), CONST64(0x28187860c05048e8), CONST64(0xfa5613458ae9bf70),
+    CONST64(0xc8b345f6f18d3e39), CONST64(0xcdb04afae9873724), CONST64(0x6c24b4903dd8fc51), CONST64(0x6020a0801dc0e07d),
+    CONST64(0xcbb240f2f98b3932), CONST64(0xab92e072e44bd94f), CONST64(0xf8a315b671ed4e89), CONST64(0x5dc0e7274eba7a13),
+    CONST64(0xcc44490d1a85c1d6), CONST64(0xa662f79537513391), CONST64(0x30105040806070b0), CONST64(0xc1b45eeac99f2b08),
+    CONST64(0x9184ae2a543fbbc5), CONST64(0xc54352112297d4e7), CONST64(0xa893e576ec4dde44), CONST64(0x5bc2ed2f5eb67405),
+    CONST64(0xde4a7f356aa1ebb4), CONST64(0xdabd73ce81a9145b), CONST64(0x8c8f89060c058a80), CONST64(0x772d99b475eec302),
+    CONST64(0xd9bc76ca89af1350), CONST64(0xb99cd64a946ff32d), CONST64(0xbe6adfb577610bc9), CONST64(0xc0405d1d3a9dddfa),
+    CONST64(0x4ccfd41b3698577a), CONST64(0xfba210b279eb4982), CONST64(0x9d80ba3a7427a7e9), CONST64(0xd14f6e2142bff093),
+    CONST64(0x211f637cf8425dd9), CONST64(0x43cac50f1e864c5d), CONST64(0xe3aa389239db71da), CONST64(0xc64257152a91d3ec),
+};
+
+static const ulong64 T2[256] = {
+    CONST64(0xd268bad36a01bbb9), CONST64(0x4d1954fc66b1e59a), CONST64(0xbc932f7114cde265), CONST64(0xcdb9749c1b512587),
+    CONST64(0x510253f557a4f7a2), CONST64(0x6bb8d368be03d0d6), CONST64(0x6fbdd26bb504d6de), CONST64(0x29644dd785feb352),
+    CONST64(0x5d0d50f04aadfdba), CONST64(0x8a26ace9e063cf09), CONST64(0x0e838d8a9684091c), CONST64(0xc679bfdc4d1aa591),
+    CONST64(0xddad7090374d3da7), CONST64(0x550752f65ca3f1aa), CONST64(0x52c89ab317e17ba4), CONST64(0x2d614cd48ef9b55a),
+    CONST64(0x8f65ea2320ac4603), CONST64(0x73a6d5628411c4e6), CONST64(0x66f197a468c255cc), CONST64(0x63b2d16ea80ddcc6),
+    CONST64(0xccff3355d099aa85), CONST64(0x590851f341aafbb2), CONST64(0x712a5bed0f9cc7e2), CONST64(0xa204a6f7ae55f359),
+    CONST64(0x5f81de7fc120febe), CONST64(0x3d7548d8a2e5ad7a), CONST64(0x9a32a8e5cc7fd729), CONST64(0x5ec799b60ae871bc),
+    CONST64(0x4b90db70e63be096), CONST64(0xc8fa3256db9eac8d), CONST64(0xe651b7c4152295d1), CONST64(0xd72bfc19aace32b3),
+    CONST64(0xab48e3387393704b), CONST64(0x42dc9ebf3bfd6384), CONST64(0x7eef91ae52d041fc), CONST64(0x56cd9bb01ce67dac),
+    CONST64(0xaf4de23b78947643), CONST64(0xd66dbbd06106bdb1), CONST64(0x195841c3f1da9b32), CONST64(0xa5cb6eb2e5177957),
+    CONST64(0xae0ba5f2b35cf941), CONST64(0x0bc0cb40564b8016), CONST64(0xb1da6bbdc20c677f), CONST64(0x6efb95a27ecc59dc),
+    CONST64(0xbe1fa1fe9f40e161), CONST64(0xeb18f308c3e310cb), CONST64(0xfe4fb1ce2f3081e1), CONST64(0x080a0206160e0c10),
+    CONST64(0x17dbcc49675e922e), CONST64(0x37f3c4513f66a26e), CONST64(0x74691d27cf534ee8), CONST64(0x5044143c9c6c78a0),
+    CONST64(0x2be8c3580e73b056), CONST64(0x91f263a59a34573f), CONST64(0x4f95da73ed3ce69e), CONST64(0x69345de7358ed3d2),
+    CONST64(0x613e5fe12380dfc2), CONST64(0x578bdc79d72ef2ae), CONST64(0xe9947d87486e13cf), CONST64(0x13decd4a6c599426),
+    CONST64(0xe19e7f815e601fdf), CONST64(0x752f5aee049bc1ea), CONST64(0xadc16cb4f3197547), CONST64(0x6d315ce43e89d5da),
+    CONST64(0xfb0cf704efff08eb), CONST64(0x98be266a47f2d42d), CONST64(0xdb24ff1cb7c738ab), CONST64(0x937eed2a11b9543b),
+    CONST64(0x876fe82536a24a13), CONST64(0x4ed39dba26f4699c), CONST64(0xa1ce6fb1ee107f5f), CONST64(0x028c8e8f8b8d0304),
+    CONST64(0x647d192be34f56c8), CONST64(0xba1aa0fd9447e769), CONST64(0xe717f00ddeea1ad3), CONST64(0x1e978986ba98113c),
+    CONST64(0x3c330f11692d2278), CONST64(0x1c1b070931151238), CONST64(0x8629afecfd6ac511), CONST64(0xcb30fb109bdb208b),
+    CONST64(0x2028081858383040), CONST64(0x5441153f976b7ea8), CONST64(0x34390d177f232e68), CONST64(0x1014040c2c1c1820),
+    CONST64(0x040501030b070608), CONST64(0x8de964acab214507), CONST64(0x5b84df7cca27f8b6), CONST64(0xc5b3769a0d5f2997),
+    CONST64(0xf980798b64720bef), CONST64(0x538edd7adc29f4a6), CONST64(0xf4c93d47b2b38ef5), CONST64(0x584e163a8a6274b0),
+    CONST64(0xfcc33f41a4bd82e5), CONST64(0xdceb3759fc85b2a5), CONST64(0xa9c46db7f81e734f), CONST64(0xe0d8384895a890dd),
+    CONST64(0xde67b9d67708b1a1), CONST64(0xd1a273952a4437bf), CONST64(0x836ae9263da54c1b), CONST64(0xd4e1355fea8bbeb5),
+    CONST64(0x491c55ff6db6e392), CONST64(0xd9a871933c4a3baf), CONST64(0xf18a7b8d727c07ff), CONST64(0x0a868c899d830f14),
+    CONST64(0xd5a77296214331b7), CONST64(0x1a928885b19f1734), CONST64(0xff09f607e4f80ee3), CONST64(0xa8822a7e33d6fc4d),
+    CONST64(0xf8c63e42afba84ed), CONST64(0x653b5ee22887d9ca), CONST64(0x9cbb27694cf5d225), CONST64(0x054346cac0cf890a),
+    CONST64(0x303c0c1474242860), CONST64(0x89ec65afa026430f), CONST64(0xbdd568b8df056d67), CONST64(0x99f861a38c3a5b2f),
+    CONST64(0x0c0f03051d090a18), CONST64(0x23e2c15e187dbc46), CONST64(0x411657f97bb8ef82), CONST64(0x7fa9d6679918cefe),
+    CONST64(0x439ad976f035ec86), CONST64(0x7d2558e81295cdfa), CONST64(0x479fd875fb32ea8e), CONST64(0x85e366aabd2f4917),
+    CONST64(0x7bacd764921fc8f6), CONST64(0xe8d23a4e83a69ccd), CONST64(0x07cfc8454b428a0e), CONST64(0xf0cc3c44b9b488fd),
+    CONST64(0xcf35fa1390dc2683), CONST64(0x62f496a763c553c4), CONST64(0xa601a7f4a552f551), CONST64(0x5ac298b501ef77b4),
+    CONST64(0x977bec291abe5233), CONST64(0xda62b8d57c0fb7a9), CONST64(0x3bfcc754226fa876), CONST64(0x822caeeff66dc319),
+    CONST64(0xb9d069bbd4026b6f), CONST64(0x317a4bddbfeca762), CONST64(0x963dabe0d176dd31), CONST64(0x9e37a9e6c778d121),
+    CONST64(0x81e667a9b6284f1f), CONST64(0x28220a1e4e363c50), CONST64(0x014647c9cbc88f02), CONST64(0xef1df20bc8e416c3),
+    CONST64(0xee5bb5c2032c99c1), CONST64(0x88aa22666beecc0d), CONST64(0xb356e5324981647b), CONST64(0x9f71ee2f0cb05e23),
+    CONST64(0xc27cbedf461da399), CONST64(0xac872b7d38d1fa45), CONST64(0x3ebf819ee2a0217c), CONST64(0x485a1236a67e6c90),
+    CONST64(0x36b58398f4ae2d6c), CONST64(0x6c771b2df5415ad8), CONST64(0x38360e12622a2470), CONST64(0x8caf236560e9ca05),
+    CONST64(0xf306f502f9f104fb), CONST64(0x094c45cfddc68312), CONST64(0x84a5216376e7c615), CONST64(0x1fd1ce4f71509e3e),
+    CONST64(0x397049dba9e2ab72), CONST64(0xb09c2c7409c4e87d), CONST64(0xc33af9168dd52c9b), CONST64(0xbf59e63754886e63),
+    CONST64(0xe254b6c71e2593d9), CONST64(0xa088287825d8f05d), CONST64(0x5c4b1739816572b8), CONST64(0x32b0829bffa92b64),
+    CONST64(0x68721a2efe465cd0), CONST64(0x169d8b80ac961d2c), CONST64(0xdf21fe1fbcc03ea3), CONST64(0x12988a83a7911b24),
+    CONST64(0x242d091b533f3648), CONST64(0x03cac94640458c06), CONST64(0x26a18794d8b2354c), CONST64(0x256b4ed298f7b94a),
+    CONST64(0xa342e13e659d7c5b), CONST64(0xb8962e721fcae46d), CONST64(0xb753e43142866273), CONST64(0xa747e03d6e9a7a53),
+    CONST64(0x8b60eb202bab400b), CONST64(0x7aea90ad59d747f4), CONST64(0xaa0ea4f1b85bff49), CONST64(0x78661e22d25a44f0),
+    CONST64(0x2eab8592cebc395c), CONST64(0x9dfd60a0873d5d27), CONST64(0x0000000000000000), CONST64(0x94b1256f5afbde35),
+    CONST64(0xf703f401f2f602f3), CONST64(0xe312f10ed5ed1cdb), CONST64(0x6afe94a175cb5fd4), CONST64(0x2c270b1d45313a58),
+    CONST64(0xbb5ce7345f8f686b), CONST64(0xc9bc759f1056238f), CONST64(0x9b74ef2c07b7582b), CONST64(0xd0e4345ce18cb8bd),
+    CONST64(0xc4f53153c697a695), CONST64(0x77a3d4618f16c2ee), CONST64(0x67b7d06da30adace), CONST64(0x22a48697d3b53344),
+    CONST64(0xe59b7e82556719d7), CONST64(0x8e23adeaeb64c901), CONST64(0xd32efd1aa1c934bb), CONST64(0xa48d297b2edff655),
+    CONST64(0xc0f03050cd90a09d), CONST64(0xecd73b4d88a19ac5), CONST64(0x46d99fbc30fa658c), CONST64(0xc73ff81586d22a93),
+    CONST64(0x3ff9c6572968ae7e), CONST64(0x4c5f1335ad796a98), CONST64(0x181e060a3a121430), CONST64(0x1411050f271b1e28),
+    CONST64(0x33f6c5523461a466), CONST64(0x44551133bb776688), CONST64(0xc1b6779906582f9f), CONST64(0xed917c84436915c7),
+    CONST64(0xf58f7a8e797b01f7), CONST64(0xfd8578886f750de7), CONST64(0xd8ee365af782b4ad), CONST64(0x706c1c24c45448e0),
+    CONST64(0xe4dd394b9eaf96d5), CONST64(0x792059eb1992cbf2), CONST64(0x60781828e84850c0), CONST64(0x451356fa70bfe98a),
+    CONST64(0xf645b3c8393e8df1), CONST64(0xfa4ab0cd243787e9), CONST64(0x90b4246c51fcd83d), CONST64(0x80a020607de0c01d),
+    CONST64(0xf240b2cb32398bf9), CONST64(0x72e092ab4fd94be4), CONST64(0xb615a3f8894eed71), CONST64(0x27e7c05d137aba4e),
+    CONST64(0x0d4944ccd6c1851a), CONST64(0x95f762a691335137), CONST64(0x40501030b0706080), CONST64(0xea5eb4c1082b9fc9),
+    CONST64(0x2aae8491c5bb3f54), CONST64(0x115243c5e7d49722), CONST64(0x76e593a844de4dec), CONST64(0x2fedc25b0574b65e),
+    CONST64(0x357f4adeb4eba16a), CONST64(0xce73bdda5b14a981), CONST64(0x06898f8c808a050c), CONST64(0xb4992d7702c3ee75),
+    CONST64(0xca76bcd95013af89), CONST64(0x4ad69cb92df36f94), CONST64(0xb5df6abec90b6177), CONST64(0x1d5d40c0fadd9d3a),
+    CONST64(0x1bd4cf4c7a579836), CONST64(0xb210a2fb8249eb79), CONST64(0x3aba809de9a72774), CONST64(0x216e4fd193f0bf42),
+    CONST64(0x7c631f21d95d42f8), CONST64(0x0fc5ca435d4c861e), CONST64(0x9238aae3da71db39), CONST64(0x155742c6ecd3912a),
+};
+
+static const ulong64 T3[256] = {
+    CONST64(0x68d2d3ba016ab9bb), CONST64(0x194dfc54b1669ae5), CONST64(0x93bc712fcd1465e2), CONST64(0xb9cd9c74511b8725),
+    CONST64(0x0251f553a457a2f7), CONST64(0xb86b68d303bed6d0), CONST64(0xbd6f6bd204b5ded6), CONST64(0x6429d74dfe8552b3),
+    CONST64(0x0d5df050ad4abafd), CONST64(0x268ae9ac63e009cf), CONST64(0x830e8a8d84961c09), CONST64(0x79c6dcbf1a4d91a5),
+    CONST64(0xaddd90704d37a73d), CONST64(0x0755f652a35caaf1), CONST64(0xc852b39ae117a47b), CONST64(0x612dd44cf98e5ab5),
+    CONST64(0x658f23eaac200346), CONST64(0xa67362d51184e6c4), CONST64(0xf166a497c268cc55), CONST64(0xb2636ed10da8c6dc),
+    CONST64(0xffcc553399d085aa), CONST64(0x0859f351aa41b2fb), CONST64(0x2a71ed5b9c0fe2c7), CONST64(0x04a2f7a655ae59f3),
+    CONST64(0x815f7fde20c1befe), CONST64(0x753dd848e5a27aad), CONST64(0x329ae5a87fcc29d7), CONST64(0xc75eb699e80abc71),
+    CONST64(0x904b70db3be696e0), CONST64(0xfac856329edb8dac), CONST64(0x51e6c4b72215d195), CONST64(0x2bd719fcceaab332),
+    CONST64(0x48ab38e393734b70), CONST64(0xdc42bf9efd3b8463), CONST64(0xef7eae91d052fc41), CONST64(0xcd56b09be61cac7d),
+    CONST64(0x4daf3be294784376), CONST64(0x6dd6d0bb0661b1bd), CONST64(0x5819c341daf1329b), CONST64(0xcba5b26e17e55779),
+    CONST64(0x0baef2a55cb341f9), CONST64(0xc00b40cb4b561680), CONST64(0xdab1bd6b0cc27f67), CONST64(0xfb6ea295cc7edc59),
+    CONST64(0x1fbefea1409f61e1), CONST64(0x18eb08f3e3c3cb10), CONST64(0x4ffeceb1302fe181), CONST64(0x0a0806020e16100c),
+    CONST64(0xdb1749cc5e672e92), CONST64(0xf33751c4663f6ea2), CONST64(0x6974271d53cfe84e), CONST64(0x44503c146c9ca078),
+    CONST64(0xe82b58c3730e56b0), CONST64(0xf291a563349a3f57), CONST64(0x954f73da3ced9ee6), CONST64(0x3469e75d8e35d2d3),
+    CONST64(0x3e61e15f8023c2df), CONST64(0x8b5779dc2ed7aef2), CONST64(0x94e9877d6e48cf13), CONST64(0xde134acd596c2694),
+    CONST64(0x9ee1817f605edf1f), CONST64(0x2f75ee5a9b04eac1), CONST64(0xc1adb46c19f34775), CONST64(0x316de45c893edad5),
+    CONST64(0x0cfb04f7ffefeb08), CONST64(0xbe986a26f2472dd4), CONST64(0x24db1cffc7b7ab38), CONST64(0x7e932aedb9113b54),
+    CONST64(0x6f8725e8a236134a), CONST64(0xd34eba9df4269c69), CONST64(0xcea1b16f10ee5f7f), CONST64(0x8c028f8e8d8b0403),
+    CONST64(0x7d642b194fe3c856), CONST64(0x1abafda0479469e7), CONST64(0x17e70df0eaded31a), CONST64(0x971e868998ba3c11),
+    CONST64(0x333c110f2d697822), CONST64(0x1b1c090715313812), CONST64(0x2986ecaf6afd11c5), CONST64(0x30cb10fbdb9b8b20),
+    CONST64(0x2820180838584030), CONST64(0x41543f156b97a87e), CONST64(0x3934170d237f682e), CONST64(0x14100c041c2c2018),
+    CONST64(0x05040301070b0806), CONST64(0xe98dac6421ab0745), CONST64(0x845b7cdf27cab6f8), CONST64(0xb3c59a765f0d9729),
+    CONST64(0x80f98b797264ef0b), CONST64(0x8e537add29dca6f4), CONST64(0xc9f4473db3b2f58e), CONST64(0x4e583a16628ab074),
+    CONST64(0xc3fc413fbda4e582), CONST64(0xebdc593785fca5b2), CONST64(0xc4a9b76d1ef84f73), CONST64(0xd8e04838a895dd90),
+    CONST64(0x67ded6b90877a1b1), CONST64(0xa2d19573442abf37), CONST64(0x6a8326e9a53d1b4c), CONST64(0xe1d45f358beab5be),
+    CONST64(0x1c49ff55b66d92e3), CONST64(0xa8d993714a3caf3b), CONST64(0x8af18d7b7c72ff07), CONST64(0x860a898c839d140f),
+    CONST64(0xa7d596724321b731), CONST64(0x921a85889fb13417), CONST64(0x09ff07f6f8e4e30e), CONST64(0x82a87e2ad6334dfc),
+    CONST64(0xc6f8423ebaafed84), CONST64(0x3b65e25e8728cad9), CONST64(0xbb9c6927f54c25d2), CONST64(0x4305ca46cfc00a89),
+    CONST64(0x3c30140c24746028), CONST64(0xec89af6526a00f43), CONST64(0xd5bdb86805df676d), CONST64(0xf899a3613a8c2f5b),
+    CONST64(0x0f0c0503091d180a), CONST64(0xe2235ec17d1846bc), CONST64(0x1641f957b87b82ef), CONST64(0xa97f67d61899fece),
+    CONST64(0x9a4376d935f086ec), CONST64(0x257de8589512facd), CONST64(0x9f4775d832fb8eea), CONST64(0xe385aa662fbd1749),
+    CONST64(0xac7b64d71f92f6c8), CONST64(0xd2e84e3aa683cd9c), CONST64(0xcf0745c8424b0e8a), CONST64(0xccf0443cb4b9fd88),
+    CONST64(0x35cf13fadc908326), CONST64(0xf462a796c563c453), CONST64(0x01a6f4a752a551f5), CONST64(0xc25ab598ef01b477),
+    CONST64(0x7b9729ecbe1a3352), CONST64(0x62dad5b80f7ca9b7), CONST64(0xfc3b54c76f2276a8), CONST64(0x2c82efae6df619c3),
+    CONST64(0xd0b9bb6902d46f6b), CONST64(0x7a31dd4becbf62a7), CONST64(0x3d96e0ab76d131dd), CONST64(0x379ee6a978c721d1),
+    CONST64(0xe681a96728b61f4f), CONST64(0x22281e0a364e503c), CONST64(0x4601c947c8cb028f), CONST64(0x1def0bf2e4c8c316),
+    CONST64(0x5beec2b52c03c199), CONST64(0xaa886622ee6b0dcc), CONST64(0x56b332e581497b64), CONST64(0x719f2feeb00c235e),
+    CONST64(0x7cc2dfbe1d4699a3), CONST64(0x87ac7d2bd13845fa), CONST64(0xbf3e9e81a0e27c21), CONST64(0x5a4836127ea6906c),
+    CONST64(0xb5369883aef46c2d), CONST64(0x776c2d1b41f5d85a), CONST64(0x3638120e2a627024), CONST64(0xaf8c6523e96005ca),
+    CONST64(0x06f302f5f1f9fb04), CONST64(0x4c09cf45c6dd1283), CONST64(0xa5846321e77615c6), CONST64(0xd11f4fce50713e9e),
+    CONST64(0x7039db49e2a972ab), CONST64(0x9cb0742cc4097de8), CONST64(0x3ac316f9d58d9b2c), CONST64(0x59bf37e68854636e),
+    CONST64(0x54e2c7b6251ed993), CONST64(0x88a07828d8255df0), CONST64(0x4b5c39176581b872), CONST64(0xb0329b82a9ff642b),
+    CONST64(0x72682e1a46fed05c), CONST64(0x9d16808b96ac2c1d), CONST64(0x21df1ffec0bca33e), CONST64(0x9812838a91a7241b),
+    CONST64(0x2d241b093f534836), CONST64(0xca0346c94540068c), CONST64(0xa1269487b2d84c35), CONST64(0x6b25d24ef7984ab9),
+    CONST64(0x42a33ee19d655b7c), CONST64(0x96b8722eca1f6de4), CONST64(0x53b731e486427362), CONST64(0x47a73de09a6e537a),
+    CONST64(0x608b20ebab2b0b40), CONST64(0xea7aad90d759f447), CONST64(0x0eaaf1a45bb849ff), CONST64(0x6678221e5ad2f044),
+    CONST64(0xab2e9285bcce5c39), CONST64(0xfd9da0603d87275d), CONST64(0x0000000000000000), CONST64(0xb1946f25fb5a35de),
+    CONST64(0x03f701f4f6f2f302), CONST64(0x12e30ef1edd5db1c), CONST64(0xfe6aa194cb75d45f), CONST64(0x272c1d0b3145583a),
+    CONST64(0x5cbb34e78f5f6b68), CONST64(0xbcc99f7556108f23), CONST64(0x749b2cefb7072b58), CONST64(0xe4d05c348ce1bdb8),
+    CONST64(0xf5c4533197c695a6), CONST64(0xa37761d4168feec2), CONST64(0xb7676dd00aa3ceda), CONST64(0xa4229786b5d34433),
+    CONST64(0x9be5827e6755d719), CONST64(0x238eeaad64eb01c9), CONST64(0x2ed31afdc9a1bb34), CONST64(0x8da47b29df2e55f6),
+    CONST64(0xf0c0503090cd9da0), CONST64(0xd7ec4d3ba188c59a), CONST64(0xd946bc9ffa308c65), CONST64(0x3fc715f8d286932a),
+    CONST64(0xf93f57c668297eae), CONST64(0x5f4c351379ad986a), CONST64(0x1e180a06123a3014), CONST64(0x11140f051b27281e),
+    CONST64(0xf63352c5613466a4), CONST64(0x5544331177bb8866), CONST64(0xb6c1997758069f2f), CONST64(0x91ed847c6943c715),
+    CONST64(0x8ff58e7a7b79f701), CONST64(0x85fd8878756fe70d), CONST64(0xeed85a3682f7adb4), CONST64(0x6c70241c54c4e048),
+    CONST64(0xdde44b39af9ed596), CONST64(0x2079eb599219f2cb), CONST64(0x7860281848e8c050), CONST64(0x1345fa56bf708ae9),
+    CONST64(0x45f6c8b33e39f18d), CONST64(0x4afacdb03724e987), CONST64(0xb4906c24fc513dd8), CONST64(0xa0806020e07d1dc0),
+    CONST64(0x40f2cbb23932f98b), CONST64(0xe072ab92d94fe44b), CONST64(0x15b6f8a34e8971ed), CONST64(0xe7275dc07a134eba),
+    CONST64(0x490dcc44c1d61a85), CONST64(0xf795a66233913751), CONST64(0x5040301070b08060), CONST64(0x5eeac1b42b08c99f),
+    CONST64(0xae2a9184bbc5543f), CONST64(0x5211c543d4e72297), CONST64(0xe576a893de44ec4d), CONST64(0xed2f5bc274055eb6),
+    CONST64(0x7f35de4aebb46aa1), CONST64(0x73cedabd145b81a9), CONST64(0x89068c8f8a800c05), CONST64(0x99b4772dc30275ee),
+    CONST64(0x76cad9bc135089af), CONST64(0xd64ab99cf32d946f), CONST64(0xdfb5be6a0bc97761), CONST64(0x5d1dc040ddfa3a9d),
+    CONST64(0xd41b4ccf577a3698), CONST64(0x10b2fba2498279eb), CONST64(0xba3a9d80a7e97427), CONST64(0x6e21d14ff09342bf),
+    CONST64(0x637c211f5dd9f842), CONST64(0xc50f43ca4c5d1e86), CONST64(0x3892e3aa71da39db), CONST64(0x5715c642d3ec2a91),
+};
+
+static const ulong64 T4[256] = {
+    CONST64(0xbbb96a01bad3d268), CONST64(0xe59a66b154fc4d19), CONST64(0xe26514cd2f71bc93), CONST64(0x25871b51749ccdb9),
+    CONST64(0xf7a257a453f55102), CONST64(0xd0d6be03d3686bb8), CONST64(0xd6deb504d26b6fbd), CONST64(0xb35285fe4dd72964),
+    CONST64(0xfdba4aad50f05d0d), CONST64(0xcf09e063ace98a26), CONST64(0x091c96848d8a0e83), CONST64(0xa5914d1abfdcc679),
+    CONST64(0x3da7374d7090ddad), CONST64(0xf1aa5ca352f65507), CONST64(0x7ba417e19ab352c8), CONST64(0xb55a8ef94cd42d61),
+    CONST64(0x460320acea238f65), CONST64(0xc4e68411d56273a6), CONST64(0x55cc68c297a466f1), CONST64(0xdcc6a80dd16e63b2),
+    CONST64(0xaa85d0993355ccff), CONST64(0xfbb241aa51f35908), CONST64(0xc7e20f9c5bed712a), CONST64(0xf359ae55a6f7a204),
+    CONST64(0xfebec120de7f5f81), CONST64(0xad7aa2e548d83d75), CONST64(0xd729cc7fa8e59a32), CONST64(0x71bc0ae899b65ec7),
+    CONST64(0xe096e63bdb704b90), CONST64(0xac8ddb9e3256c8fa), CONST64(0x95d11522b7c4e651), CONST64(0x32b3aacefc19d72b),
+    CONST64(0x704b7393e338ab48), CONST64(0x63843bfd9ebf42dc), CONST64(0x41fc52d091ae7eef), CONST64(0x7dac1ce69bb056cd),
+    CONST64(0x76437894e23baf4d), CONST64(0xbdb16106bbd0d66d), CONST64(0x9b32f1da41c31958), CONST64(0x7957e5176eb2a5cb),
+    CONST64(0xf941b35ca5f2ae0b), CONST64(0x8016564bcb400bc0), CONST64(0x677fc20c6bbdb1da), CONST64(0x59dc7ecc95a26efb),
+    CONST64(0xe1619f40a1febe1f), CONST64(0x10cbc3e3f308eb18), CONST64(0x81e12f30b1cefe4f), CONST64(0x0c10160e0206080a),
+    CONST64(0x922e675ecc4917db), CONST64(0xa26e3f66c45137f3), CONST64(0x4ee8cf531d277469), CONST64(0x78a09c6c143c5044),
+    CONST64(0xb0560e73c3582be8), CONST64(0x573f9a3463a591f2), CONST64(0xe69eed3cda734f95), CONST64(0xd3d2358e5de76934),
+    CONST64(0xdfc223805fe1613e), CONST64(0xf2aed72edc79578b), CONST64(0x13cf486e7d87e994), CONST64(0x94266c59cd4a13de),
+    CONST64(0x1fdf5e607f81e19e), CONST64(0xc1ea049b5aee752f), CONST64(0x7547f3196cb4adc1), CONST64(0xd5da3e895ce46d31),
+    CONST64(0x08ebeffff704fb0c), CONST64(0xd42d47f2266a98be), CONST64(0x38abb7c7ff1cdb24), CONST64(0x543b11b9ed2a937e),
+    CONST64(0x4a1336a2e825876f), CONST64(0x699c26f49dba4ed3), CONST64(0x7f5fee106fb1a1ce), CONST64(0x03048b8d8e8f028c),
+    CONST64(0x56c8e34f192b647d), CONST64(0xe7699447a0fdba1a), CONST64(0x1ad3deeaf00de717), CONST64(0x113cba9889861e97),
+    CONST64(0x2278692d0f113c33), CONST64(0x1238311507091c1b), CONST64(0xc511fd6aafec8629), CONST64(0x208b9bdbfb10cb30),
+    CONST64(0x3040583808182028), CONST64(0x7ea8976b153f5441), CONST64(0x2e687f230d173439), CONST64(0x18202c1c040c1014),
+    CONST64(0x06080b0701030405), CONST64(0x4507ab2164ac8de9), CONST64(0xf8b6ca27df7c5b84), CONST64(0x29970d5f769ac5b3),
+    CONST64(0x0bef6472798bf980), CONST64(0xf4a6dc29dd7a538e), CONST64(0x8ef5b2b33d47f4c9), CONST64(0x74b08a62163a584e),
+    CONST64(0x82e5a4bd3f41fcc3), CONST64(0xb2a5fc853759dceb), CONST64(0x734ff81e6db7a9c4), CONST64(0x90dd95a83848e0d8),
+    CONST64(0xb1a17708b9d6de67), CONST64(0x37bf2a447395d1a2), CONST64(0x4c1b3da5e926836a), CONST64(0xbeb5ea8b355fd4e1),
+    CONST64(0xe3926db655ff491c), CONST64(0x3baf3c4a7193d9a8), CONST64(0x07ff727c7b8df18a), CONST64(0x0f149d838c890a86),
+    CONST64(0x31b721437296d5a7), CONST64(0x1734b19f88851a92), CONST64(0x0ee3e4f8f607ff09), CONST64(0xfc4d33d62a7ea882),
+    CONST64(0x84edafba3e42f8c6), CONST64(0xd9ca28875ee2653b), CONST64(0xd2254cf527699cbb), CONST64(0x890ac0cf46ca0543),
+    CONST64(0x286074240c14303c), CONST64(0x430fa02665af89ec), CONST64(0x6d67df0568b8bdd5), CONST64(0x5b2f8c3a61a399f8),
+    CONST64(0x0a181d0903050c0f), CONST64(0xbc46187dc15e23e2), CONST64(0xef827bb857f94116), CONST64(0xcefe9918d6677fa9),
+    CONST64(0xec86f035d976439a), CONST64(0xcdfa129558e87d25), CONST64(0xea8efb32d875479f), CONST64(0x4917bd2f66aa85e3),
+    CONST64(0xc8f6921fd7647bac), CONST64(0x9ccd83a63a4ee8d2), CONST64(0x8a0e4b42c84507cf), CONST64(0x88fdb9b43c44f0cc),
+    CONST64(0x268390dcfa13cf35), CONST64(0x53c463c596a762f4), CONST64(0xf551a552a7f4a601), CONST64(0x77b401ef98b55ac2),
+    CONST64(0x52331abeec29977b), CONST64(0xb7a97c0fb8d5da62), CONST64(0xa876226fc7543bfc), CONST64(0xc319f66daeef822c),
+    CONST64(0x6b6fd40269bbb9d0), CONST64(0xa762bfec4bdd317a), CONST64(0xdd31d176abe0963d), CONST64(0xd121c778a9e69e37),
+    CONST64(0x4f1fb62867a981e6), CONST64(0x3c504e360a1e2822), CONST64(0x8f02cbc847c90146), CONST64(0x16c3c8e4f20bef1d),
+    CONST64(0x99c1032cb5c2ee5b), CONST64(0xcc0d6bee226688aa), CONST64(0x647b4981e532b356), CONST64(0x5e230cb0ee2f9f71),
+    CONST64(0xa399461dbedfc27c), CONST64(0xfa4538d12b7dac87), CONST64(0x217ce2a0819e3ebf), CONST64(0x6c90a67e1236485a),
+    CONST64(0x2d6cf4ae839836b5), CONST64(0x5ad8f5411b2d6c77), CONST64(0x2470622a0e123836), CONST64(0xca0560e923658caf),
+    CONST64(0x04fbf9f1f502f306), CONST64(0x8312ddc645cf094c), CONST64(0xc61576e7216384a5), CONST64(0x9e3e7150ce4f1fd1),
+    CONST64(0xab72a9e249db3970), CONST64(0xe87d09c42c74b09c), CONST64(0x2c9b8dd5f916c33a), CONST64(0x6e635488e637bf59),
+    CONST64(0x93d91e25b6c7e254), CONST64(0xf05d25d82878a088), CONST64(0x72b8816517395c4b), CONST64(0x2b64ffa9829b32b0),
+    CONST64(0x5cd0fe461a2e6872), CONST64(0x1d2cac968b80169d), CONST64(0x3ea3bcc0fe1fdf21), CONST64(0x1b24a7918a831298),
+    CONST64(0x3648533f091b242d), CONST64(0x8c064045c94603ca), CONST64(0x354cd8b2879426a1), CONST64(0xb94a98f74ed2256b),
+    CONST64(0x7c5b659de13ea342), CONST64(0xe46d1fca2e72b896), CONST64(0x62734286e431b753), CONST64(0x7a536e9ae03da747),
+    CONST64(0x400b2babeb208b60), CONST64(0x47f459d790ad7aea), CONST64(0xff49b85ba4f1aa0e), CONST64(0x44f0d25a1e227866),
+    CONST64(0x395ccebc85922eab), CONST64(0x5d27873d60a09dfd), CONST64(0x0000000000000000), CONST64(0xde355afb256f94b1),
+    CONST64(0x02f3f2f6f401f703), CONST64(0x1cdbd5edf10ee312), CONST64(0x5fd475cb94a16afe), CONST64(0x3a5845310b1d2c27),
+    CONST64(0x686b5f8fe734bb5c), CONST64(0x238f1056759fc9bc), CONST64(0x582b07b7ef2c9b74), CONST64(0xb8bde18c345cd0e4),
+    CONST64(0xa695c6973153c4f5), CONST64(0xc2ee8f16d46177a3), CONST64(0xdacea30ad06d67b7), CONST64(0x3344d3b5869722a4),
+    CONST64(0x19d755677e82e59b), CONST64(0xc901eb64adea8e23), CONST64(0x34bba1c9fd1ad32e), CONST64(0xf6552edf297ba48d),
+    CONST64(0xa09dcd903050c0f0), CONST64(0x9ac588a13b4decd7), CONST64(0x658c30fa9fbc46d9), CONST64(0x2a9386d2f815c73f),
+    CONST64(0xae7e2968c6573ff9), CONST64(0x6a98ad7913354c5f), CONST64(0x14303a12060a181e), CONST64(0x1e28271b050f1411),
+    CONST64(0xa4663461c55233f6), CONST64(0x6688bb7711334455), CONST64(0x2f9f06587799c1b6), CONST64(0x15c743697c84ed91),
+    CONST64(0x01f7797b7a8ef58f), CONST64(0x0de76f757888fd85), CONST64(0xb4adf782365ad8ee), CONST64(0x48e0c4541c24706c),
+    CONST64(0x96d59eaf394be4dd), CONST64(0xcbf2199259eb7920), CONST64(0x50c0e84818286078), CONST64(0xe98a70bf56fa4513),
+    CONST64(0x8df1393eb3c8f645), CONST64(0x87e92437b0cdfa4a), CONST64(0xd83d51fc246c90b4), CONST64(0xc01d7de0206080a0),
+    CONST64(0x8bf93239b2cbf240), CONST64(0x4be44fd992ab72e0), CONST64(0xed71894ea3f8b615), CONST64(0xba4e137ac05d27e7),
+    CONST64(0x851ad6c144cc0d49), CONST64(0x5137913362a695f7), CONST64(0x6080b07010304050), CONST64(0x9fc9082bb4c1ea5e),
+    CONST64(0x3f54c5bb84912aae), CONST64(0x9722e7d443c51152), CONST64(0x4dec44de93a876e5), CONST64(0xb65e0574c25b2fed),
+    CONST64(0xa16ab4eb4ade357f), CONST64(0xa9815b14bddace73), CONST64(0x050c808a8f8c0689), CONST64(0xee7502c32d77b499),
+    CONST64(0xaf895013bcd9ca76), CONST64(0x6f942df39cb94ad6), CONST64(0x6177c90b6abeb5df), CONST64(0x9d3afadd40c01d5d),
+    CONST64(0x98367a57cf4c1bd4), CONST64(0xeb798249a2fbb210), CONST64(0x2774e9a7809d3aba), CONST64(0xbf4293f04fd1216e),
+    CONST64(0x42f8d95d1f217c63), CONST64(0x861e5d4cca430fc5), CONST64(0xdb39da71aae39238), CONST64(0x912aecd342c61557),
+};
+
+static const ulong64 T5[256] = {
+    CONST64(0xb9bb016ad3ba68d2), CONST64(0x9ae5b166fc54194d), CONST64(0x65e2cd14712f93bc), CONST64(0x8725511b9c74b9cd),
+    CONST64(0xa2f7a457f5530251), CONST64(0xd6d003be68d3b86b), CONST64(0xded604b56bd2bd6f), CONST64(0x52b3fe85d74d6429),
+    CONST64(0xbafdad4af0500d5d), CONST64(0x09cf63e0e9ac268a), CONST64(0x1c0984968a8d830e), CONST64(0x91a51a4ddcbf79c6),
+    CONST64(0xa73d4d379070addd), CONST64(0xaaf1a35cf6520755), CONST64(0xa47be117b39ac852), CONST64(0x5ab5f98ed44c612d),
+    CONST64(0x0346ac2023ea658f), CONST64(0xe6c4118462d5a673), CONST64(0xcc55c268a497f166), CONST64(0xc6dc0da86ed1b263),
+    CONST64(0x85aa99d05533ffcc), CONST64(0xb2fbaa41f3510859), CONST64(0xe2c79c0fed5b2a71), CONST64(0x59f355aef7a604a2),
+    CONST64(0xbefe20c17fde815f), CONST64(0x7aade5a2d848753d), CONST64(0x29d77fcce5a8329a), CONST64(0xbc71e80ab699c75e),
+    CONST64(0x96e03be670db904b), CONST64(0x8dac9edb5632fac8), CONST64(0xd1952215c4b751e6), CONST64(0xb332ceaa19fc2bd7),
+    CONST64(0x4b70937338e348ab), CONST64(0x8463fd3bbf9edc42), CONST64(0xfc41d052ae91ef7e), CONST64(0xac7de61cb09bcd56),
+    CONST64(0x437694783be24daf), CONST64(0xb1bd0661d0bb6dd6), CONST64(0x329bdaf1c3415819), CONST64(0x577917e5b26ecba5),
+    CONST64(0x41f95cb3f2a50bae), CONST64(0x16804b5640cbc00b), CONST64(0x7f670cc2bd6bdab1), CONST64(0xdc59cc7ea295fb6e),
+    CONST64(0x61e1409ffea11fbe), CONST64(0xcb10e3c308f318eb), CONST64(0xe181302fceb14ffe), CONST64(0x100c0e1606020a08),
+    CONST64(0x2e925e6749ccdb17), CONST64(0x6ea2663f51c4f337), CONST64(0xe84e53cf271d6974), CONST64(0xa0786c9c3c144450),
+    CONST64(0x56b0730e58c3e82b), CONST64(0x3f57349aa563f291), CONST64(0x9ee63ced73da954f), CONST64(0xd2d38e35e75d3469),
+    CONST64(0xc2df8023e15f3e61), CONST64(0xaef22ed779dc8b57), CONST64(0xcf136e48877d94e9), CONST64(0x2694596c4acdde13),
+    CONST64(0xdf1f605e817f9ee1), CONST64(0xeac19b04ee5a2f75), CONST64(0x477519f3b46cc1ad), CONST64(0xdad5893ee45c316d),
+    CONST64(0xeb08ffef04f70cfb), CONST64(0x2dd4f2476a26be98), CONST64(0xab38c7b71cff24db), CONST64(0x3b54b9112aed7e93),
+    CONST64(0x134aa23625e86f87), CONST64(0x9c69f426ba9dd34e), CONST64(0x5f7f10eeb16fcea1), CONST64(0x04038d8b8f8e8c02),
+    CONST64(0xc8564fe32b197d64), CONST64(0x69e74794fda01aba), CONST64(0xd31aeade0df017e7), CONST64(0x3c1198ba8689971e),
+    CONST64(0x78222d69110f333c), CONST64(0x3812153109071b1c), CONST64(0x11c56afdecaf2986), CONST64(0x8b20db9b10fb30cb),
+    CONST64(0x4030385818082820), CONST64(0xa87e6b973f154154), CONST64(0x682e237f170d3934), CONST64(0x20181c2c0c041410),
+    CONST64(0x0806070b03010504), CONST64(0x074521abac64e98d), CONST64(0xb6f827ca7cdf845b), CONST64(0x97295f0d9a76b3c5),
+    CONST64(0xef0b72648b7980f9), CONST64(0xa6f429dc7add8e53), CONST64(0xf58eb3b2473dc9f4), CONST64(0xb074628a3a164e58),
+    CONST64(0xe582bda4413fc3fc), CONST64(0xa5b285fc5937ebdc), CONST64(0x4f731ef8b76dc4a9), CONST64(0xdd90a8954838d8e0),
+    CONST64(0xa1b10877d6b967de), CONST64(0xbf37442a9573a2d1), CONST64(0x1b4ca53d26e96a83), CONST64(0xb5be8bea5f35e1d4),
+    CONST64(0x92e3b66dff551c49), CONST64(0xaf3b4a3c9371a8d9), CONST64(0xff077c728d7b8af1), CONST64(0x140f839d898c860a),
+    CONST64(0xb73143219672a7d5), CONST64(0x34179fb18588921a), CONST64(0xe30ef8e407f609ff), CONST64(0x4dfcd6337e2a82a8),
+    CONST64(0xed84baaf423ec6f8), CONST64(0xcad98728e25e3b65), CONST64(0x25d2f54c6927bb9c), CONST64(0x0a89cfc0ca464305),
+    CONST64(0x60282474140c3c30), CONST64(0x0f4326a0af65ec89), CONST64(0x676d05dfb868d5bd), CONST64(0x2f5b3a8ca361f899),
+    CONST64(0x180a091d05030f0c), CONST64(0x46bc7d185ec1e223), CONST64(0x82efb87bf9571641), CONST64(0xfece189967d6a97f),
+    CONST64(0x86ec35f076d99a43), CONST64(0xfacd9512e858257d), CONST64(0x8eea32fb75d89f47), CONST64(0x17492fbdaa66e385),
+    CONST64(0xf6c81f9264d7ac7b), CONST64(0xcd9ca6834e3ad2e8), CONST64(0x0e8a424b45c8cf07), CONST64(0xfd88b4b9443cccf0),
+    CONST64(0x8326dc9013fa35cf), CONST64(0xc453c563a796f462), CONST64(0x51f552a5f4a701a6), CONST64(0xb477ef01b598c25a),
+    CONST64(0x3352be1a29ec7b97), CONST64(0xa9b70f7cd5b862da), CONST64(0x76a86f2254c7fc3b), CONST64(0x19c36df6efae2c82),
+    CONST64(0x6f6b02d4bb69d0b9), CONST64(0x62a7ecbfdd4b7a31), CONST64(0x31dd76d1e0ab3d96), CONST64(0x21d178c7e6a9379e),
+    CONST64(0x1f4f28b6a967e681), CONST64(0x503c364e1e0a2228), CONST64(0x028fc8cbc9474601), CONST64(0xc316e4c80bf21def),
+    CONST64(0xc1992c03c2b55bee), CONST64(0x0dccee6b6622aa88), CONST64(0x7b64814932e556b3), CONST64(0x235eb00c2fee719f),
+    CONST64(0x99a31d46dfbe7cc2), CONST64(0x45fad1387d2b87ac), CONST64(0x7c21a0e29e81bf3e), CONST64(0x906c7ea636125a48),
+    CONST64(0x6c2daef49883b536), CONST64(0xd85a41f52d1b776c), CONST64(0x70242a62120e3638), CONST64(0x05cae9606523af8c),
+    CONST64(0xfb04f1f902f506f3), CONST64(0x1283c6ddcf454c09), CONST64(0x15c6e7766321a584), CONST64(0x3e9e50714fced11f),
+    CONST64(0x72abe2a9db497039), CONST64(0x7de8c409742c9cb0), CONST64(0x9b2cd58d16f93ac3), CONST64(0x636e885437e659bf),
+    CONST64(0xd993251ec7b654e2), CONST64(0x5df0d825782888a0), CONST64(0xb872658139174b5c), CONST64(0x642ba9ff9b82b032),
+    CONST64(0xd05c46fe2e1a7268), CONST64(0x2c1d96ac808b9d16), CONST64(0xa33ec0bc1ffe21df), CONST64(0x241b91a7838a9812),
+    CONST64(0x48363f531b092d24), CONST64(0x068c454046c9ca03), CONST64(0x4c35b2d89487a126), CONST64(0x4ab9f798d24e6b25),
+    CONST64(0x5b7c9d653ee142a3), CONST64(0x6de4ca1f722e96b8), CONST64(0x7362864231e453b7), CONST64(0x537a9a6e3de047a7),
+    CONST64(0x0b40ab2b20eb608b), CONST64(0xf447d759ad90ea7a), CONST64(0x49ff5bb8f1a40eaa), CONST64(0xf0445ad2221e6678),
+    CONST64(0x5c39bcce9285ab2e), CONST64(0x275d3d87a060fd9d), CONST64(0x0000000000000000), CONST64(0x35defb5a6f25b194),
+    CONST64(0xf302f6f201f403f7), CONST64(0xdb1cedd50ef112e3), CONST64(0xd45fcb75a194fe6a), CONST64(0x583a31451d0b272c),
+    CONST64(0x6b688f5f34e75cbb), CONST64(0x8f2356109f75bcc9), CONST64(0x2b58b7072cef749b), CONST64(0xbdb88ce15c34e4d0),
+    CONST64(0x95a697c65331f5c4), CONST64(0xeec2168f61d4a377), CONST64(0xceda0aa36dd0b767), CONST64(0x4433b5d39786a422),
+    CONST64(0xd7196755827e9be5), CONST64(0x01c964ebeaad238e), CONST64(0xbb34c9a11afd2ed3), CONST64(0x55f6df2e7b298da4),
+    CONST64(0x9da090cd5030f0c0), CONST64(0xc59aa1884d3bd7ec), CONST64(0x8c65fa30bc9fd946), CONST64(0x932ad28615f83fc7),
+    CONST64(0x7eae682957c6f93f), CONST64(0x986a79ad35135f4c), CONST64(0x3014123a0a061e18), CONST64(0x281e1b270f051114),
+    CONST64(0x66a4613452c5f633), CONST64(0x886677bb33115544), CONST64(0x9f2f58069977b6c1), CONST64(0xc7156943847c91ed),
+    CONST64(0xf7017b798e7a8ff5), CONST64(0xe70d756f887885fd), CONST64(0xadb482f75a36eed8), CONST64(0xe04854c4241c6c70),
+    CONST64(0xd596af9e4b39dde4), CONST64(0xf2cb9219eb592079), CONST64(0xc05048e828187860), CONST64(0x8ae9bf70fa561345),
+    CONST64(0xf18d3e39c8b345f6), CONST64(0xe9873724cdb04afa), CONST64(0x3dd8fc516c24b490), CONST64(0x1dc0e07d6020a080),
+    CONST64(0xf98b3932cbb240f2), CONST64(0xe44bd94fab92e072), CONST64(0x71ed4e89f8a315b6), CONST64(0x4eba7a135dc0e727),
+    CONST64(0x1a85c1d6cc44490d), CONST64(0x37513391a662f795), CONST64(0x806070b030105040), CONST64(0xc99f2b08c1b45eea),
+    CONST64(0x543fbbc59184ae2a), CONST64(0x2297d4e7c5435211), CONST64(0xec4dde44a893e576), CONST64(0x5eb674055bc2ed2f),
+    CONST64(0x6aa1ebb4de4a7f35), CONST64(0x81a9145bdabd73ce), CONST64(0x0c058a808c8f8906), CONST64(0x75eec302772d99b4),
+    CONST64(0x89af1350d9bc76ca), CONST64(0x946ff32db99cd64a), CONST64(0x77610bc9be6adfb5), CONST64(0x3a9dddfac0405d1d),
+    CONST64(0x3698577a4ccfd41b), CONST64(0x79eb4982fba210b2), CONST64(0x7427a7e99d80ba3a), CONST64(0x42bff093d14f6e21),
+    CONST64(0xf8425dd9211f637c), CONST64(0x1e864c5d43cac50f), CONST64(0x39db71dae3aa3892), CONST64(0x2a91d3ecc6425715),
+};
+
+static const ulong64 T6[256] = {
+    CONST64(0x6a01bbb9d268bad3), CONST64(0x66b1e59a4d1954fc), CONST64(0x14cde265bc932f71), CONST64(0x1b512587cdb9749c),
+    CONST64(0x57a4f7a2510253f5), CONST64(0xbe03d0d66bb8d368), CONST64(0xb504d6de6fbdd26b), CONST64(0x85feb35229644dd7),
+    CONST64(0x4aadfdba5d0d50f0), CONST64(0xe063cf098a26ace9), CONST64(0x9684091c0e838d8a), CONST64(0x4d1aa591c679bfdc),
+    CONST64(0x374d3da7ddad7090), CONST64(0x5ca3f1aa550752f6), CONST64(0x17e17ba452c89ab3), CONST64(0x8ef9b55a2d614cd4),
+    CONST64(0x20ac46038f65ea23), CONST64(0x8411c4e673a6d562), CONST64(0x68c255cc66f197a4), CONST64(0xa80ddcc663b2d16e),
+    CONST64(0xd099aa85ccff3355), CONST64(0x41aafbb2590851f3), CONST64(0x0f9cc7e2712a5bed), CONST64(0xae55f359a204a6f7),
+    CONST64(0xc120febe5f81de7f), CONST64(0xa2e5ad7a3d7548d8), CONST64(0xcc7fd7299a32a8e5), CONST64(0x0ae871bc5ec799b6),
+    CONST64(0xe63be0964b90db70), CONST64(0xdb9eac8dc8fa3256), CONST64(0x152295d1e651b7c4), CONST64(0xaace32b3d72bfc19),
+    CONST64(0x7393704bab48e338), CONST64(0x3bfd638442dc9ebf), CONST64(0x52d041fc7eef91ae), CONST64(0x1ce67dac56cd9bb0),
+    CONST64(0x78947643af4de23b), CONST64(0x6106bdb1d66dbbd0), CONST64(0xf1da9b32195841c3), CONST64(0xe5177957a5cb6eb2),
+    CONST64(0xb35cf941ae0ba5f2), CONST64(0x564b80160bc0cb40), CONST64(0xc20c677fb1da6bbd), CONST64(0x7ecc59dc6efb95a2),
+    CONST64(0x9f40e161be1fa1fe), CONST64(0xc3e310cbeb18f308), CONST64(0x2f3081e1fe4fb1ce), CONST64(0x160e0c10080a0206),
+    CONST64(0x675e922e17dbcc49), CONST64(0x3f66a26e37f3c451), CONST64(0xcf534ee874691d27), CONST64(0x9c6c78a05044143c),
+    CONST64(0x0e73b0562be8c358), CONST64(0x9a34573f91f263a5), CONST64(0xed3ce69e4f95da73), CONST64(0x358ed3d269345de7),
+    CONST64(0x2380dfc2613e5fe1), CONST64(0xd72ef2ae578bdc79), CONST64(0x486e13cfe9947d87), CONST64(0x6c59942613decd4a),
+    CONST64(0x5e601fdfe19e7f81), CONST64(0x049bc1ea752f5aee), CONST64(0xf3197547adc16cb4), CONST64(0x3e89d5da6d315ce4),
+    CONST64(0xefff08ebfb0cf704), CONST64(0x47f2d42d98be266a), CONST64(0xb7c738abdb24ff1c), CONST64(0x11b9543b937eed2a),
+    CONST64(0x36a24a13876fe825), CONST64(0x26f4699c4ed39dba), CONST64(0xee107f5fa1ce6fb1), CONST64(0x8b8d0304028c8e8f),
+    CONST64(0xe34f56c8647d192b), CONST64(0x9447e769ba1aa0fd), CONST64(0xdeea1ad3e717f00d), CONST64(0xba98113c1e978986),
+    CONST64(0x692d22783c330f11), CONST64(0x311512381c1b0709), CONST64(0xfd6ac5118629afec), CONST64(0x9bdb208bcb30fb10),
+    CONST64(0x5838304020280818), CONST64(0x976b7ea85441153f), CONST64(0x7f232e6834390d17), CONST64(0x2c1c18201014040c),
+    CONST64(0x0b07060804050103), CONST64(0xab2145078de964ac), CONST64(0xca27f8b65b84df7c), CONST64(0x0d5f2997c5b3769a),
+    CONST64(0x64720beff980798b), CONST64(0xdc29f4a6538edd7a), CONST64(0xb2b38ef5f4c93d47), CONST64(0x8a6274b0584e163a),
+    CONST64(0xa4bd82e5fcc33f41), CONST64(0xfc85b2a5dceb3759), CONST64(0xf81e734fa9c46db7), CONST64(0x95a890dde0d83848),
+    CONST64(0x7708b1a1de67b9d6), CONST64(0x2a4437bfd1a27395), CONST64(0x3da54c1b836ae926), CONST64(0xea8bbeb5d4e1355f),
+    CONST64(0x6db6e392491c55ff), CONST64(0x3c4a3bafd9a87193), CONST64(0x727c07fff18a7b8d), CONST64(0x9d830f140a868c89),
+    CONST64(0x214331b7d5a77296), CONST64(0xb19f17341a928885), CONST64(0xe4f80ee3ff09f607), CONST64(0x33d6fc4da8822a7e),
+    CONST64(0xafba84edf8c63e42), CONST64(0x2887d9ca653b5ee2), CONST64(0x4cf5d2259cbb2769), CONST64(0xc0cf890a054346ca),
+    CONST64(0x74242860303c0c14), CONST64(0xa026430f89ec65af), CONST64(0xdf056d67bdd568b8), CONST64(0x8c3a5b2f99f861a3),
+    CONST64(0x1d090a180c0f0305), CONST64(0x187dbc4623e2c15e), CONST64(0x7bb8ef82411657f9), CONST64(0x9918cefe7fa9d667),
+    CONST64(0xf035ec86439ad976), CONST64(0x1295cdfa7d2558e8), CONST64(0xfb32ea8e479fd875), CONST64(0xbd2f491785e366aa),
+    CONST64(0x921fc8f67bacd764), CONST64(0x83a69ccde8d23a4e), CONST64(0x4b428a0e07cfc845), CONST64(0xb9b488fdf0cc3c44),
+    CONST64(0x90dc2683cf35fa13), CONST64(0x63c553c462f496a7), CONST64(0xa552f551a601a7f4), CONST64(0x01ef77b45ac298b5),
+    CONST64(0x1abe5233977bec29), CONST64(0x7c0fb7a9da62b8d5), CONST64(0x226fa8763bfcc754), CONST64(0xf66dc319822caeef),
+    CONST64(0xd4026b6fb9d069bb), CONST64(0xbfeca762317a4bdd), CONST64(0xd176dd31963dabe0), CONST64(0xc778d1219e37a9e6),
+    CONST64(0xb6284f1f81e667a9), CONST64(0x4e363c5028220a1e), CONST64(0xcbc88f02014647c9), CONST64(0xc8e416c3ef1df20b),
+    CONST64(0x032c99c1ee5bb5c2), CONST64(0x6beecc0d88aa2266), CONST64(0x4981647bb356e532), CONST64(0x0cb05e239f71ee2f),
+    CONST64(0x461da399c27cbedf), CONST64(0x38d1fa45ac872b7d), CONST64(0xe2a0217c3ebf819e), CONST64(0xa67e6c90485a1236),
+    CONST64(0xf4ae2d6c36b58398), CONST64(0xf5415ad86c771b2d), CONST64(0x622a247038360e12), CONST64(0x60e9ca058caf2365),
+    CONST64(0xf9f104fbf306f502), CONST64(0xddc68312094c45cf), CONST64(0x76e7c61584a52163), CONST64(0x71509e3e1fd1ce4f),
+    CONST64(0xa9e2ab72397049db), CONST64(0x09c4e87db09c2c74), CONST64(0x8dd52c9bc33af916), CONST64(0x54886e63bf59e637),
+    CONST64(0x1e2593d9e254b6c7), CONST64(0x25d8f05da0882878), CONST64(0x816572b85c4b1739), CONST64(0xffa92b6432b0829b),
+    CONST64(0xfe465cd068721a2e), CONST64(0xac961d2c169d8b80), CONST64(0xbcc03ea3df21fe1f), CONST64(0xa7911b2412988a83),
+    CONST64(0x533f3648242d091b), CONST64(0x40458c0603cac946), CONST64(0xd8b2354c26a18794), CONST64(0x98f7b94a256b4ed2),
+    CONST64(0x659d7c5ba342e13e), CONST64(0x1fcae46db8962e72), CONST64(0x42866273b753e431), CONST64(0x6e9a7a53a747e03d),
+    CONST64(0x2bab400b8b60eb20), CONST64(0x59d747f47aea90ad), CONST64(0xb85bff49aa0ea4f1), CONST64(0xd25a44f078661e22),
+    CONST64(0xcebc395c2eab8592), CONST64(0x873d5d279dfd60a0), CONST64(0x0000000000000000), CONST64(0x5afbde3594b1256f),
+    CONST64(0xf2f602f3f703f401), CONST64(0xd5ed1cdbe312f10e), CONST64(0x75cb5fd46afe94a1), CONST64(0x45313a582c270b1d),
+    CONST64(0x5f8f686bbb5ce734), CONST64(0x1056238fc9bc759f), CONST64(0x07b7582b9b74ef2c), CONST64(0xe18cb8bdd0e4345c),
+    CONST64(0xc697a695c4f53153), CONST64(0x8f16c2ee77a3d461), CONST64(0xa30adace67b7d06d), CONST64(0xd3b5334422a48697),
+    CONST64(0x556719d7e59b7e82), CONST64(0xeb64c9018e23adea), CONST64(0xa1c934bbd32efd1a), CONST64(0x2edff655a48d297b),
+    CONST64(0xcd90a09dc0f03050), CONST64(0x88a19ac5ecd73b4d), CONST64(0x30fa658c46d99fbc), CONST64(0x86d22a93c73ff815),
+    CONST64(0x2968ae7e3ff9c657), CONST64(0xad796a984c5f1335), CONST64(0x3a121430181e060a), CONST64(0x271b1e281411050f),
+    CONST64(0x3461a46633f6c552), CONST64(0xbb77668844551133), CONST64(0x06582f9fc1b67799), CONST64(0x436915c7ed917c84),
+    CONST64(0x797b01f7f58f7a8e), CONST64(0x6f750de7fd857888), CONST64(0xf782b4add8ee365a), CONST64(0xc45448e0706c1c24),
+    CONST64(0x9eaf96d5e4dd394b), CONST64(0x1992cbf2792059eb), CONST64(0xe84850c060781828), CONST64(0x70bfe98a451356fa),
+    CONST64(0x393e8df1f645b3c8), CONST64(0x243787e9fa4ab0cd), CONST64(0x51fcd83d90b4246c), CONST64(0x7de0c01d80a02060),
+    CONST64(0x32398bf9f240b2cb), CONST64(0x4fd94be472e092ab), CONST64(0x894eed71b615a3f8), CONST64(0x137aba4e27e7c05d),
+    CONST64(0xd6c1851a0d4944cc), CONST64(0x9133513795f762a6), CONST64(0xb070608040501030), CONST64(0x082b9fc9ea5eb4c1),
+    CONST64(0xc5bb3f542aae8491), CONST64(0xe7d49722115243c5), CONST64(0x44de4dec76e593a8), CONST64(0x0574b65e2fedc25b),
+    CONST64(0xb4eba16a357f4ade), CONST64(0x5b14a981ce73bdda), CONST64(0x808a050c06898f8c), CONST64(0x02c3ee75b4992d77),
+    CONST64(0x5013af89ca76bcd9), CONST64(0x2df36f944ad69cb9), CONST64(0xc90b6177b5df6abe), CONST64(0xfadd9d3a1d5d40c0),
+    CONST64(0x7a5798361bd4cf4c), CONST64(0x8249eb79b210a2fb), CONST64(0xe9a727743aba809d), CONST64(0x93f0bf42216e4fd1),
+    CONST64(0xd95d42f87c631f21), CONST64(0x5d4c861e0fc5ca43), CONST64(0xda71db399238aae3), CONST64(0xecd3912a155742c6),
+};
+
+static const ulong64 T7[256] = {
+    CONST64(0x016ab9bb68d2d3ba), CONST64(0xb1669ae5194dfc54), CONST64(0xcd1465e293bc712f), CONST64(0x511b8725b9cd9c74),
+    CONST64(0xa457a2f70251f553), CONST64(0x03bed6d0b86b68d3), CONST64(0x04b5ded6bd6f6bd2), CONST64(0xfe8552b36429d74d),
+    CONST64(0xad4abafd0d5df050), CONST64(0x63e009cf268ae9ac), CONST64(0x84961c09830e8a8d), CONST64(0x1a4d91a579c6dcbf),
+    CONST64(0x4d37a73daddd9070), CONST64(0xa35caaf10755f652), CONST64(0xe117a47bc852b39a), CONST64(0xf98e5ab5612dd44c),
+    CONST64(0xac200346658f23ea), CONST64(0x1184e6c4a67362d5), CONST64(0xc268cc55f166a497), CONST64(0x0da8c6dcb2636ed1),
+    CONST64(0x99d085aaffcc5533), CONST64(0xaa41b2fb0859f351), CONST64(0x9c0fe2c72a71ed5b), CONST64(0x55ae59f304a2f7a6),
+    CONST64(0x20c1befe815f7fde), CONST64(0xe5a27aad753dd848), CONST64(0x7fcc29d7329ae5a8), CONST64(0xe80abc71c75eb699),
+    CONST64(0x3be696e0904b70db), CONST64(0x9edb8dacfac85632), CONST64(0x2215d19551e6c4b7), CONST64(0xceaab3322bd719fc),
+    CONST64(0x93734b7048ab38e3), CONST64(0xfd3b8463dc42bf9e), CONST64(0xd052fc41ef7eae91), CONST64(0xe61cac7dcd56b09b),
+    CONST64(0x947843764daf3be2), CONST64(0x0661b1bd6dd6d0bb), CONST64(0xdaf1329b5819c341), CONST64(0x17e55779cba5b26e),
+    CONST64(0x5cb341f90baef2a5), CONST64(0x4b561680c00b40cb), CONST64(0x0cc27f67dab1bd6b), CONST64(0xcc7edc59fb6ea295),
+    CONST64(0x409f61e11fbefea1), CONST64(0xe3c3cb1018eb08f3), CONST64(0x302fe1814ffeceb1), CONST64(0x0e16100c0a080602),
+    CONST64(0x5e672e92db1749cc), CONST64(0x663f6ea2f33751c4), CONST64(0x53cfe84e6974271d), CONST64(0x6c9ca07844503c14),
+    CONST64(0x730e56b0e82b58c3), CONST64(0x349a3f57f291a563), CONST64(0x3ced9ee6954f73da), CONST64(0x8e35d2d33469e75d),
+    CONST64(0x8023c2df3e61e15f), CONST64(0x2ed7aef28b5779dc), CONST64(0x6e48cf1394e9877d), CONST64(0x596c2694de134acd),
+    CONST64(0x605edf1f9ee1817f), CONST64(0x9b04eac12f75ee5a), CONST64(0x19f34775c1adb46c), CONST64(0x893edad5316de45c),
+    CONST64(0xffefeb080cfb04f7), CONST64(0xf2472dd4be986a26), CONST64(0xc7b7ab3824db1cff), CONST64(0xb9113b547e932aed),
+    CONST64(0xa236134a6f8725e8), CONST64(0xf4269c69d34eba9d), CONST64(0x10ee5f7fcea1b16f), CONST64(0x8d8b04038c028f8e),
+    CONST64(0x4fe3c8567d642b19), CONST64(0x479469e71abafda0), CONST64(0xeaded31a17e70df0), CONST64(0x98ba3c11971e8689),
+    CONST64(0x2d697822333c110f), CONST64(0x153138121b1c0907), CONST64(0x6afd11c52986ecaf), CONST64(0xdb9b8b2030cb10fb),
+    CONST64(0x3858403028201808), CONST64(0x6b97a87e41543f15), CONST64(0x237f682e3934170d), CONST64(0x1c2c201814100c04),
+    CONST64(0x070b080605040301), CONST64(0x21ab0745e98dac64), CONST64(0x27cab6f8845b7cdf), CONST64(0x5f0d9729b3c59a76),
+    CONST64(0x7264ef0b80f98b79), CONST64(0x29dca6f48e537add), CONST64(0xb3b2f58ec9f4473d), CONST64(0x628ab0744e583a16),
+    CONST64(0xbda4e582c3fc413f), CONST64(0x85fca5b2ebdc5937), CONST64(0x1ef84f73c4a9b76d), CONST64(0xa895dd90d8e04838),
+    CONST64(0x0877a1b167ded6b9), CONST64(0x442abf37a2d19573), CONST64(0xa53d1b4c6a8326e9), CONST64(0x8beab5bee1d45f35),
+    CONST64(0xb66d92e31c49ff55), CONST64(0x4a3caf3ba8d99371), CONST64(0x7c72ff078af18d7b), CONST64(0x839d140f860a898c),
+    CONST64(0x4321b731a7d59672), CONST64(0x9fb13417921a8588), CONST64(0xf8e4e30e09ff07f6), CONST64(0xd6334dfc82a87e2a),
+    CONST64(0xbaafed84c6f8423e), CONST64(0x8728cad93b65e25e), CONST64(0xf54c25d2bb9c6927), CONST64(0xcfc00a894305ca46),
+    CONST64(0x247460283c30140c), CONST64(0x26a00f43ec89af65), CONST64(0x05df676dd5bdb868), CONST64(0x3a8c2f5bf899a361),
+    CONST64(0x091d180a0f0c0503), CONST64(0x7d1846bce2235ec1), CONST64(0xb87b82ef1641f957), CONST64(0x1899fecea97f67d6),
+    CONST64(0x35f086ec9a4376d9), CONST64(0x9512facd257de858), CONST64(0x32fb8eea9f4775d8), CONST64(0x2fbd1749e385aa66),
+    CONST64(0x1f92f6c8ac7b64d7), CONST64(0xa683cd9cd2e84e3a), CONST64(0x424b0e8acf0745c8), CONST64(0xb4b9fd88ccf0443c),
+    CONST64(0xdc90832635cf13fa), CONST64(0xc563c453f462a796), CONST64(0x52a551f501a6f4a7), CONST64(0xef01b477c25ab598),
+    CONST64(0xbe1a33527b9729ec), CONST64(0x0f7ca9b762dad5b8), CONST64(0x6f2276a8fc3b54c7), CONST64(0x6df619c32c82efae),
+    CONST64(0x02d46f6bd0b9bb69), CONST64(0xecbf62a77a31dd4b), CONST64(0x76d131dd3d96e0ab), CONST64(0x78c721d1379ee6a9),
+    CONST64(0x28b61f4fe681a967), CONST64(0x364e503c22281e0a), CONST64(0xc8cb028f4601c947), CONST64(0xe4c8c3161def0bf2),
+    CONST64(0x2c03c1995beec2b5), CONST64(0xee6b0dccaa886622), CONST64(0x81497b6456b332e5), CONST64(0xb00c235e719f2fee),
+    CONST64(0x1d4699a37cc2dfbe), CONST64(0xd13845fa87ac7d2b), CONST64(0xa0e27c21bf3e9e81), CONST64(0x7ea6906c5a483612),
+    CONST64(0xaef46c2db5369883), CONST64(0x41f5d85a776c2d1b), CONST64(0x2a6270243638120e), CONST64(0xe96005caaf8c6523),
+    CONST64(0xf1f9fb0406f302f5), CONST64(0xc6dd12834c09cf45), CONST64(0xe77615c6a5846321), CONST64(0x50713e9ed11f4fce),
+    CONST64(0xe2a972ab7039db49), CONST64(0xc4097de89cb0742c), CONST64(0xd58d9b2c3ac316f9), CONST64(0x8854636e59bf37e6),
+    CONST64(0x251ed99354e2c7b6), CONST64(0xd8255df088a07828), CONST64(0x6581b8724b5c3917), CONST64(0xa9ff642bb0329b82),
+    CONST64(0x46fed05c72682e1a), CONST64(0x96ac2c1d9d16808b), CONST64(0xc0bca33e21df1ffe), CONST64(0x91a7241b9812838a),
+    CONST64(0x3f5348362d241b09), CONST64(0x4540068cca0346c9), CONST64(0xb2d84c35a1269487), CONST64(0xf7984ab96b25d24e),
+    CONST64(0x9d655b7c42a33ee1), CONST64(0xca1f6de496b8722e), CONST64(0x8642736253b731e4), CONST64(0x9a6e537a47a73de0),
+    CONST64(0xab2b0b40608b20eb), CONST64(0xd759f447ea7aad90), CONST64(0x5bb849ff0eaaf1a4), CONST64(0x5ad2f0446678221e),
+    CONST64(0xbcce5c39ab2e9285), CONST64(0x3d87275dfd9da060), CONST64(0x0000000000000000), CONST64(0xfb5a35deb1946f25),
+    CONST64(0xf6f2f30203f701f4), CONST64(0xedd5db1c12e30ef1), CONST64(0xcb75d45ffe6aa194), CONST64(0x3145583a272c1d0b),
+    CONST64(0x8f5f6b685cbb34e7), CONST64(0x56108f23bcc99f75), CONST64(0xb7072b58749b2cef), CONST64(0x8ce1bdb8e4d05c34),
+    CONST64(0x97c695a6f5c45331), CONST64(0x168feec2a37761d4), CONST64(0x0aa3cedab7676dd0), CONST64(0xb5d34433a4229786),
+    CONST64(0x6755d7199be5827e), CONST64(0x64eb01c9238eeaad), CONST64(0xc9a1bb342ed31afd), CONST64(0xdf2e55f68da47b29),
+    CONST64(0x90cd9da0f0c05030), CONST64(0xa188c59ad7ec4d3b), CONST64(0xfa308c65d946bc9f), CONST64(0xd286932a3fc715f8),
+    CONST64(0x68297eaef93f57c6), CONST64(0x79ad986a5f4c3513), CONST64(0x123a30141e180a06), CONST64(0x1b27281e11140f05),
+    CONST64(0x613466a4f63352c5), CONST64(0x77bb886655443311), CONST64(0x58069f2fb6c19977), CONST64(0x6943c71591ed847c),
+    CONST64(0x7b79f7018ff58e7a), CONST64(0x756fe70d85fd8878), CONST64(0x82f7adb4eed85a36), CONST64(0x54c4e0486c70241c),
+    CONST64(0xaf9ed596dde44b39), CONST64(0x9219f2cb2079eb59), CONST64(0x48e8c05078602818), CONST64(0xbf708ae91345fa56),
+    CONST64(0x3e39f18d45f6c8b3), CONST64(0x3724e9874afacdb0), CONST64(0xfc513dd8b4906c24), CONST64(0xe07d1dc0a0806020),
+    CONST64(0x3932f98b40f2cbb2), CONST64(0xd94fe44be072ab92), CONST64(0x4e8971ed15b6f8a3), CONST64(0x7a134ebae7275dc0),
+    CONST64(0xc1d61a85490dcc44), CONST64(0x33913751f795a662), CONST64(0x70b0806050403010), CONST64(0x2b08c99f5eeac1b4),
+    CONST64(0xbbc5543fae2a9184), CONST64(0xd4e722975211c543), CONST64(0xde44ec4de576a893), CONST64(0x74055eb6ed2f5bc2),
+    CONST64(0xebb46aa17f35de4a), CONST64(0x145b81a973cedabd), CONST64(0x8a800c0589068c8f), CONST64(0xc30275ee99b4772d),
+    CONST64(0x135089af76cad9bc), CONST64(0xf32d946fd64ab99c), CONST64(0x0bc97761dfb5be6a), CONST64(0xddfa3a9d5d1dc040),
+    CONST64(0x577a3698d41b4ccf), CONST64(0x498279eb10b2fba2), CONST64(0xa7e97427ba3a9d80), CONST64(0xf09342bf6e21d14f),
+    CONST64(0x5dd9f842637c211f), CONST64(0x4c5d1e86c50f43ca), CONST64(0x71da39db3892e3aa), CONST64(0xd3ec2a915715c642),
+};
+
+static const ulong64 c[R + 1] = {
+    CONST64(0xba542f7453d3d24d),
+    CONST64(0x50ac8dbf70529a4c),
+    CONST64(0xead597d133515ba6),
+    CONST64(0xde48a899db32b7fc),
+    CONST64(0xe39e919be2bb416e),
+    CONST64(0xa5cb6b95a1f3b102),
+    CONST64(0xccc41d14c363da5d),
+    CONST64(0x5fdc7dcd7f5a6c5c),
+    CONST64(0xf726ffede89d6f8e),
+};
+
+ /**
+    Initialize the Khazad block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+{
+   int               r;
+   const ulong64    *S;
+   ulong64           K2, K1;
+
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(skey != NULL);
+   if (keylen != 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+   if (num_rounds != 8 && num_rounds != 0) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
+   /* use 7th table */
+   S = T7;
+
+    /*
+    * map unsigned char array cipher key to initial key state (mu):
+    */
+   K2 =
+      ((ulong64)key[ 0] << 56) ^
+      ((ulong64)key[ 1] << 48) ^
+      ((ulong64)key[ 2] << 40) ^
+      ((ulong64)key[ 3] << 32) ^
+      ((ulong64)key[ 4] << 24) ^
+      ((ulong64)key[ 5] << 16) ^
+      ((ulong64)key[ 6] <<  8) ^
+      ((ulong64)key[ 7]      );
+   K1 =
+      ((ulong64)key[ 8] << 56) ^
+      ((ulong64)key[ 9] << 48) ^
+      ((ulong64)key[10] << 40) ^
+      ((ulong64)key[11] << 32) ^
+      ((ulong64)key[12] << 24) ^
+      ((ulong64)key[13] << 16) ^
+      ((ulong64)key[14] <<  8) ^
+      ((ulong64)key[15]      );
+
+   /*
+    * compute the round keys:
+    */
+   for (r = 0; r <= R; r++) {
+      /*
+       * K[r] = rho(c[r], K1) ^ K2;
+       */
+      skey->khazad.roundKeyEnc[r] =
+         T0[(int)(K1 >> 56)       ] ^
+         T1[(int)(K1 >> 48) & 0xff] ^
+         T2[(int)(K1 >> 40) & 0xff] ^
+         T3[(int)(K1 >> 32) & 0xff] ^
+         T4[(int)(K1 >> 24) & 0xff] ^
+         T5[(int)(K1 >> 16) & 0xff] ^
+         T6[(int)(K1 >>  8) & 0xff] ^
+         T7[(int)(K1      ) & 0xff] ^
+         c[r] ^ K2;
+      K2 = K1; K1 = skey->khazad.roundKeyEnc[r];
+   }
+   /*
+    * compute the inverse key schedule:
+    * K'^0 = K^R, K'^R = K^0, K'^r = theta(K^{R-r})
+    */
+   skey->khazad.roundKeyDec[0] = skey->khazad.roundKeyEnc[R];
+   for (r = 1; r < R; r++) {
+      K1 = skey->khazad.roundKeyEnc[R - r];
+      skey->khazad.roundKeyDec[r] =
+         T0[(int)S[(int)(K1 >> 56)       ] & 0xff] ^
+         T1[(int)S[(int)(K1 >> 48) & 0xff] & 0xff] ^
+         T2[(int)S[(int)(K1 >> 40) & 0xff] & 0xff] ^
+         T3[(int)S[(int)(K1 >> 32) & 0xff] & 0xff] ^
+         T4[(int)S[(int)(K1 >> 24) & 0xff] & 0xff] ^
+         T5[(int)S[(int)(K1 >> 16) & 0xff] & 0xff] ^
+         T6[(int)S[(int)(K1 >>  8) & 0xff] & 0xff] ^
+         T7[(int)S[(int)(K1      ) & 0xff] & 0xff];
+   }
+   skey->khazad.roundKeyDec[R] = skey->khazad.roundKeyEnc[0];
+
+   return CRYPT_OK;
+}
+
+static void khazad_crypt(const unsigned char *plaintext, unsigned char *ciphertext,
+                         const ulong64       *roundKey) {
+   int     r;
+   ulong64 state;
+    /*
+    * map plaintext block to cipher state (mu)
+    * and add initial round key (sigma[K^0]):
+    */
+   state =
+      ((ulong64)plaintext[0] << 56) ^
+      ((ulong64)plaintext[1] << 48) ^
+      ((ulong64)plaintext[2] << 40) ^
+      ((ulong64)plaintext[3] << 32) ^
+      ((ulong64)plaintext[4] << 24) ^
+      ((ulong64)plaintext[5] << 16) ^
+      ((ulong64)plaintext[6] <<  8) ^
+      ((ulong64)plaintext[7]      ) ^
+      roundKey[0];
+
+    /*
+    * R - 1 full rounds:
+    */
+    for (r = 1; r < R; r++) {
+      state =
+         T0[(int)(state >> 56)       ] ^
+         T1[(int)(state >> 48) & 0xff] ^
+         T2[(int)(state >> 40) & 0xff] ^
+         T3[(int)(state >> 32) & 0xff] ^
+         T4[(int)(state >> 24) & 0xff] ^
+         T5[(int)(state >> 16) & 0xff] ^
+         T6[(int)(state >>  8) & 0xff] ^
+         T7[(int)(state      ) & 0xff] ^
+         roundKey[r];
+    }
+
+    /*
+    * last round:
+    */
+   state =
+      (T0[(int)(state >> 56)       ] & CONST64(0xff00000000000000)) ^
+      (T1[(int)(state >> 48) & 0xff] & CONST64(0x00ff000000000000)) ^
+      (T2[(int)(state >> 40) & 0xff] & CONST64(0x0000ff0000000000)) ^
+      (T3[(int)(state >> 32) & 0xff] & CONST64(0x000000ff00000000)) ^
+      (T4[(int)(state >> 24) & 0xff] & CONST64(0x00000000ff000000)) ^
+      (T5[(int)(state >> 16) & 0xff] & CONST64(0x0000000000ff0000)) ^
+      (T6[(int)(state >>  8) & 0xff] & CONST64(0x000000000000ff00)) ^
+      (T7[(int)(state      ) & 0xff] & CONST64(0x00000000000000ff)) ^
+      roundKey[R];
+
+   /*
+    * map cipher state to ciphertext block (mu^{-1}):
+    */
+   ciphertext[0] = (unsigned char)(state >> 56);
+   ciphertext[1] = (unsigned char)(state >> 48);
+   ciphertext[2] = (unsigned char)(state >> 40);
+   ciphertext[3] = (unsigned char)(state >> 32);
+   ciphertext[4] = (unsigned char)(state >> 24);
+   ciphertext[5] = (unsigned char)(state >> 16);
+   ciphertext[6] = (unsigned char)(state >>  8);
+   ciphertext[7] = (unsigned char)(state      );
+}
+
+/**
+  Encrypts a block of text with Khazad
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+void khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
+{
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
+   khazad_crypt(pt, ct, skey->khazad.roundKeyEnc);
+}
+
+/**
+  Decrypts a block of text with Khazad
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+void khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
+{
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
+   khazad_crypt(ct, pt, skey->khazad.roundKeyDec);
+}
+
+/**
+  Performs a self-test of the Khazad block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
+int khazad_test(void)
+{
+#ifndef LTC_TEST
+  return CRYPT_NOP;
+#else
+  static const struct test {
+     unsigned char pt[8], ct[8], key[16];
+  } tests[] = {
+{
+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+   { 0x49, 0xA4, 0xCE, 0x32, 0xAC, 0x19, 0x0E, 0x3F },
+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+}, {
+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+   { 0x64, 0x5D, 0x77, 0x3E, 0x40, 0xAB, 0xDD, 0x53 },
+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }
+}, {
+   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+   { 0x9E, 0x39, 0x98, 0x64, 0xF7, 0x8E, 0xCA, 0x02 },
+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+}, {
+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
+   { 0xA9, 0xDF, 0x3D, 0x2C, 0x64, 0xD3, 0xEA, 0x28 },
+   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+}
+};
+   int x, y;
+   unsigned char buf[2][8];
+   symmetric_key skey;
+
+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+       khazad_setup(tests[x].key, 16, 0, &skey);
+       khazad_ecb_encrypt(tests[x].pt, buf[0], &skey);
+       khazad_ecb_decrypt(buf[0], buf[1], &skey);
+       if (memcmp(buf[0], tests[x].ct, 8) || memcmp(buf[1], tests[x].pt, 8)) {
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+       for (y = 0; y < 1000; y++) khazad_ecb_encrypt(buf[0], buf[0], &skey);
+       for (y = 0; y < 1000; y++) khazad_ecb_decrypt(buf[0], buf[0], &skey);
+       if (memcmp(buf[0], tests[x].ct, 8)) {
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+   }
+   return CRYPT_OK;
+#endif
+}
+
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void khazad_done(symmetric_key *skey)
+{
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int khazad_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize >= 16) {
+      *keysize = 16;
+      return CRYPT_OK;
+   } else {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/khazad.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/noekeon.c b/src/ciphers/noekeon.c
similarity index 65%
rename from noekeon.c
rename to src/ciphers/noekeon.c
index 7c6e87f..e502dfe 100644
--- a/noekeon.c
+++ b/src/ciphers/noekeon.c
@@ -6,14 +6,17 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* Implementation of the Noekeon block cipher by Tom St Denis */
-#include "mycrypt.h"
+/**
+   @file noekeon.c
+   Implementation of the Noekeon block cipher by Tom St Denis 
+*/
+#include "tomcrypt.h"
 
 #ifdef NOEKEON
 
-const struct _cipher_descriptor noekeon_desc =
+const struct ltc_cipher_descriptor noekeon_desc =
 {
     "noekeon",
     16,
@@ -22,7 +25,9 @@
     &noekeon_ecb_encrypt,
     &noekeon_ecb_decrypt,
     &noekeon_test,
-    &noekeon_keysize
+    &noekeon_done,
+    &noekeon_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 RC[] = {
@@ -33,17 +38,16 @@
    0x000000d4UL 
 };
 
-
 #define kTHETA(a, b, c, d)                                 \
-    temp = a^c; temp = temp ^ ROL(temp, 8) ^ ROR(temp, 8); \
+    temp = a^c; temp = temp ^ ROLc(temp, 8) ^ RORc(temp, 8); \
     b ^= temp; d ^= temp;                                  \
-    temp = b^d; temp = temp ^ ROL(temp, 8) ^ ROR(temp, 8); \
+    temp = b^d; temp = temp ^ ROLc(temp, 8) ^ RORc(temp, 8); \
     a ^= temp; c ^= temp;
 
 #define THETA(k, a, b, c, d)                               \
-    temp = a^c; temp = temp ^ ROL(temp, 8) ^ ROR(temp, 8); \
+    temp = a^c; temp = temp ^ ROLc(temp, 8) ^ RORc(temp, 8); \
     b ^= temp ^ k[1]; d ^= temp ^ k[3];                    \
-    temp = b^d; temp = temp ^ ROL(temp, 8) ^ ROR(temp, 8); \
+    temp = b^d; temp = temp ^ ROLc(temp, 8) ^ RORc(temp, 8); \
     a ^= temp ^ k[0]; c ^= temp ^ k[2];
     
 #define GAMMA(a, b, c, d)     \
@@ -55,17 +59,25 @@
     a ^= c&b;
     
 #define PI1(a, b, c, d) \
-    a = ROL(a, 1); c = ROL(c, 5); d = ROL(d, 2);
+    a = ROLc(a, 1); c = ROLc(c, 5); d = ROLc(d, 2);
     
 #define PI2(a, b, c, d) \
-    a = ROR(a, 1); c = ROR(c, 5); d = ROR(d, 2);
+    a = RORc(a, 1); c = RORc(c, 5); d = RORc(d, 2);
     
+ /**
+    Initialize the Noekeon block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
 int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    ulong32 temp;
    
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
    
    if (keylen != 16) {
       return CRYPT_INVALID_KEYSIZE;
@@ -90,112 +102,110 @@
    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with Noekeon
+  @param pt The input plaintext (16 bytes)
+  @param ct The output ciphertext (16 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
    ulong32 a,b,c,d,temp;
-#ifdef SMALL_CODE
    int r;
-#endif
 
-   _ARGCHK(key != NULL);
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
    
    LOAD32H(a,&pt[0]); LOAD32H(b,&pt[4]);
    LOAD32H(c,&pt[8]); LOAD32H(d,&pt[12]);
    
 #define ROUND(i) \
        a ^= RC[i]; \
-       THETA(key->noekeon.K, a,b,c,d); \
+       THETA(skey->noekeon.K, a,b,c,d); \
        PI1(a,b,c,d); \
        GAMMA(a,b,c,d); \
        PI2(a,b,c,d);
 
-#ifdef SMALL_CODE
    for (r = 0; r < 16; ++r) {
        ROUND(r);
    }
-#else 
-   ROUND( 0); ROUND( 1); ROUND( 2); ROUND( 3);
-   ROUND( 4); ROUND( 5); ROUND( 6); ROUND( 7);
-   ROUND( 8); ROUND( 9); ROUND(10); ROUND(11);
-   ROUND(12); ROUND(13); ROUND(14); ROUND(15);
-#endif
 
 #undef ROUND
 
    a ^= RC[16];
-   THETA(key->noekeon.K, a, b, c, d);
+   THETA(skey->noekeon.K, a, b, c, d);
    
    STORE32H(a,&ct[0]); STORE32H(b,&ct[4]);
    STORE32H(c,&ct[8]); STORE32H(d,&ct[12]);
 }
 
-#ifdef CLEAN_STACK
-void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-   _noekeon_ecb_encrypt(pt, ct, key);
+   _noekeon_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with Noekeon
+  @param ct The input ciphertext (16 bytes)
+  @param pt The output plaintext (16 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
    ulong32 a,b,c,d, temp;
-#ifdef SMALL_CODE
    int r;
-#endif
 
-   _ARGCHK(key != NULL);
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
    
    LOAD32H(a,&ct[0]); LOAD32H(b,&ct[4]);
    LOAD32H(c,&ct[8]); LOAD32H(d,&ct[12]);
    
 
 #define ROUND(i) \
-       THETA(key->noekeon.dK, a,b,c,d); \
+       THETA(skey->noekeon.dK, a,b,c,d); \
        a ^= RC[i]; \
        PI1(a,b,c,d); \
        GAMMA(a,b,c,d); \
        PI2(a,b,c,d); 
 
-#ifdef SMALL_CODE
    for (r = 16; r > 0; --r) {
        ROUND(r);
    }
-#else
-   ROUND(16); ROUND(15); ROUND(14); ROUND(13);
-   ROUND(12); ROUND(11); ROUND(10); ROUND( 9);
-   ROUND( 8); ROUND( 7); ROUND( 6); ROUND( 5);
-   ROUND( 4); ROUND( 3); ROUND( 2); ROUND( 1);
-#endif
-   
+
 #undef ROUND
 
-   THETA(key->noekeon.dK, a,b,c,d);
+   THETA(skey->noekeon.dK, a,b,c,d);
    a ^= RC[0];
    STORE32H(a,&pt[0]); STORE32H(b, &pt[4]);
    STORE32H(c,&pt[8]); STORE32H(d, &pt[12]);
 }
 
-#ifdef CLEAN_STACK
-void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-   _noekeon_ecb_decrypt(ct, pt, key);
+   _noekeon_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 5 + sizeof(int));
 }
 #endif
 
+/**
+  Performs a self-test of the Noekeon block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int noekeon_test(void)
 {
  #ifndef LTC_TEST
@@ -255,16 +265,32 @@
  #endif
 }
 
-int noekeon_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void noekeon_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
-   if (*desired_keysize < 16) {
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int noekeon_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 16) {
       return CRYPT_INVALID_KEYSIZE;
    } else {
-      *desired_keysize = 16;
+      *keysize = 16;
       return CRYPT_OK;
    }
 }
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/noekeon.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/rc2.c b/src/ciphers/rc2.c
similarity index 62%
rename from rc2.c
rename to src/ciphers/rc2.c
index a8f1d2d..e91f83a 100644
--- a/rc2.c
+++ b/src/ciphers/rc2.c
@@ -6,7 +6,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 /**********************************************************************\
 * To commemorate the 1996 RSA Data Security Conference, the following  *
@@ -18,32 +18,29 @@
 * Thanks to CodeView, SoftIce, and D86 for helping bring this code to  *
 * the public.                                                          *
 \**********************************************************************/
+#include <tomcrypt.h>
 
-#include <mycrypt.h>
+/**
+  @file rc2.c
+  Implementation of RC2
+*/  
 
 #ifdef RC2
 
-const struct _cipher_descriptor rc2_desc = {
+const struct ltc_cipher_descriptor rc2_desc = {
    "rc2",
    12, 8, 128, 8, 16,
    &rc2_setup,
    &rc2_ecb_encrypt,
    &rc2_ecb_decrypt,
    &rc2_test,
-   &rc2_keysize
+   &rc2_done,
+   &rc2_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
-
-/**********************************************************************\
-* Expand a variable-length user key (between 1 and 128 bytes) to a     *
-* 64-short working rc2 key, of at most "bits" effective key bits.      *
-* The effective key bits parameter looks like an export control hack.  *
-* For normal use, it should always be set to 1024.  For convenience,   *
-* zero is accepted as an alias for 1024.                               *
-\**********************************************************************/
-
-   /* 256-entry permutation table, probably derived somehow from pi */
-    static const unsigned char permute[256] = {
+/* 256-entry permutation table, probably derived somehow from pi */
+static const unsigned char permute[256] = {
         217,120,249,196, 25,221,181,237, 40,233,253,121, 74,160,216,157,
         198,126, 55,131, 43,118, 83,142, 98, 76,100,136, 68,139,251,162,
          23,154, 89,245,135,179, 79, 19, 97, 69,109,141,  9,129,125, 50,
@@ -60,23 +57,31 @@
         211,  0,230,207,225,158,168, 44, 99, 22,  1, 63, 88,226,137,169,
          13, 56, 52, 27,171, 51,255,176,187, 72, 12, 95,185,177,205, 46,
         197,243,219, 71,229,165,156,119, 10,166, 32,104,254,127,193,173
-    };
+};
 
-int rc2_setup(const unsigned char *key, int keylen, int rounds, symmetric_key *skey)
+ /**
+    Initialize the RC2 block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    unsigned *xkey = skey->rc2.xkey;
    unsigned char tmp[128];
    unsigned T8, TM;
    int i, bits;
 
-   _ARGCHK(key  != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (keylen < 8 || keylen > 128) {
       return CRYPT_INVALID_KEYSIZE;
    }
 
-   if (rounds != 0 && rounds != 16) {
+   if (num_rounds != 0 && num_rounds != 16) {
       return CRYPT_INVALID_ROUNDS;
    }
 
@@ -87,26 +92,25 @@
     /* Phase 1: Expand input key to 128 bytes */
     if (keylen < 128) {
         for (i = keylen; i < 128; i++) {
-            tmp[i] = permute[(int)((tmp[i - 1] + tmp[i - keylen]) & 255)];
+            tmp[i] = permute[(tmp[i - 1] + tmp[i - keylen]) & 255];
         }
     }
     
     /* Phase 2 - reduce effective key size to "bits" */
-    bits = keylen*8;
+    bits = keylen<<3;
     T8   = (unsigned)(bits+7)>>3;
     TM   = (255 >> (unsigned)(7 & -bits));
-    tmp[128 - T8] = permute[(int)(tmp[128 - T8] & TM)];
+    tmp[128 - T8] = permute[tmp[128 - T8] & TM];
     for (i = 127 - T8; i >= 0; i--) {
-        tmp[i] = permute[(int)(tmp[i + 1] ^ tmp[i + T8])];
+        tmp[i] = permute[tmp[i + 1] ^ tmp[i + T8]];
     }
 
     /* Phase 3 - copy to xkey in little-endian order */
-    i = 63;
-    do {
+    for (i = 0; i < 64; i++) {
         xkey[i] =  (unsigned)tmp[2*i] + ((unsigned)tmp[2*i+1] << 8);
-    } while (i-- > 0);
+    }        
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(tmp, sizeof(tmp));
 #endif
     
@@ -116,42 +120,48 @@
 /**********************************************************************\
 * Encrypt an 8-byte block of plaintext using the given key.            *
 \**********************************************************************/
-#ifdef CLEAN_STACK
-static void _rc2_ecb_encrypt( const unsigned char *plain,
-                            unsigned char *cipher,
+/**
+  Encrypts a block of text with RC2
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _rc2_ecb_encrypt( const unsigned char *pt,
+                            unsigned char *ct,
                             symmetric_key *skey)
 #else
-void rc2_ecb_encrypt( const unsigned char *plain,
-                            unsigned char *cipher,
+void rc2_ecb_encrypt( const unsigned char *pt,
+                            unsigned char *ct,
                             symmetric_key *skey)
 #endif
 {
     unsigned *xkey;
     unsigned x76, x54, x32, x10, i;
 
-    _ARGCHK(plain != NULL);
-    _ARGCHK(cipher != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(pt  != NULL);
+    LTC_ARGCHK(ct != NULL);
+    LTC_ARGCHK(skey   != NULL);
 
     xkey = skey->rc2.xkey;
 
-    x76 = ((unsigned)plain[7] << 8) + (unsigned)plain[6];
-    x54 = ((unsigned)plain[5] << 8) + (unsigned)plain[4];
-    x32 = ((unsigned)plain[3] << 8) + (unsigned)plain[2];
-    x10 = ((unsigned)plain[1] << 8) + (unsigned)plain[0];
+    x76 = ((unsigned)pt[7] << 8) + (unsigned)pt[6];
+    x54 = ((unsigned)pt[5] << 8) + (unsigned)pt[4];
+    x32 = ((unsigned)pt[3] << 8) + (unsigned)pt[2];
+    x10 = ((unsigned)pt[1] << 8) + (unsigned)pt[0];
 
     for (i = 0; i < 16; i++) {
         x10 = (x10 + (x32 & ~x76) + (x54 & x76) + xkey[4*i+0]) & 0xFFFF;
-        x10 = ((x10 << 1) | (x10 >> 15)) & 0xFFFF;
+        x10 = ((x10 << 1) | (x10 >> 15));
 
         x32 = (x32 + (x54 & ~x10) + (x76 & x10) + xkey[4*i+1]) & 0xFFFF;
-        x32 = ((x32 << 2) | (x32 >> 14)) & 0xFFFF;
+        x32 = ((x32 << 2) | (x32 >> 14));
 
         x54 = (x54 + (x76 & ~x32) + (x10 & x32) + xkey[4*i+2]) & 0xFFFF;
-        x54 = ((x54 << 3) | (x54 >> 13)) & 0xFFFF;
+        x54 = ((x54 << 3) | (x54 >> 13));
 
         x76 = (x76 + (x10 & ~x54) + (x32 & x54) + xkey[4*i+3]) & 0xFFFF;
-        x76 = ((x76 << 5) | (x76 >> 11)) & 0xFFFF;
+        x76 = ((x76 << 5) | (x76 >> 11));
 
         if (i == 4 || i == 10) {
             x10 = (x10 + xkey[x76 & 63]) & 0xFFFF;
@@ -161,22 +171,22 @@
         }
     }
 
-    cipher[0] = (unsigned char)x10;
-    cipher[1] = (unsigned char)(x10 >> 8);
-    cipher[2] = (unsigned char)x32;
-    cipher[3] = (unsigned char)(x32 >> 8);
-    cipher[4] = (unsigned char)x54;
-    cipher[5] = (unsigned char)(x54 >> 8);
-    cipher[6] = (unsigned char)x76;
-    cipher[7] = (unsigned char)(x76 >> 8);
+    ct[0] = (unsigned char)x10;
+    ct[1] = (unsigned char)(x10 >> 8);
+    ct[2] = (unsigned char)x32;
+    ct[3] = (unsigned char)(x32 >> 8);
+    ct[4] = (unsigned char)x54;
+    ct[5] = (unsigned char)(x54 >> 8);
+    ct[6] = (unsigned char)x76;
+    ct[7] = (unsigned char)(x76 >> 8);
 }
 
-#ifdef CLEAN_STACK
-void rc2_ecb_encrypt( const unsigned char *plain,
-                            unsigned char *cipher,
+#ifdef LTC_CLEAN_STACK
+void rc2_ecb_encrypt( const unsigned char *pt,
+                            unsigned char *ct,
                             symmetric_key *skey)
 {
-    _rc2_ecb_encrypt(plain, cipher, skey);
+    _rc2_ecb_encrypt(pt, ct, skey);
     burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 5);
 }
 #endif
@@ -184,14 +194,19 @@
 /**********************************************************************\
 * Decrypt an 8-byte block of ciphertext using the given key.           *
 \**********************************************************************/
-
-#ifdef CLEAN_STACK
-static void _rc2_ecb_decrypt( const unsigned char *cipher,
-                            unsigned char *plain,
+/**
+  Decrypts a block of text with RC2
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _rc2_ecb_decrypt( const unsigned char *ct,
+                            unsigned char *pt,
                             symmetric_key *skey)
 #else
-void rc2_ecb_decrypt( const unsigned char *cipher,
-                            unsigned char *plain,
+void rc2_ecb_decrypt( const unsigned char *ct,
+                            unsigned char *pt,
                             symmetric_key *skey)
 #endif
 {
@@ -199,16 +214,16 @@
     unsigned *xkey;
     int i;
 
-    _ARGCHK(plain != NULL);
-    _ARGCHK(cipher != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(pt  != NULL);
+    LTC_ARGCHK(ct != NULL);
+    LTC_ARGCHK(skey   != NULL);
 
     xkey = skey->rc2.xkey;
 
-    x76 = ((unsigned)cipher[7] << 8) + (unsigned)cipher[6];
-    x54 = ((unsigned)cipher[5] << 8) + (unsigned)cipher[4];
-    x32 = ((unsigned)cipher[3] << 8) + (unsigned)cipher[2];
-    x10 = ((unsigned)cipher[1] << 8) + (unsigned)cipher[0];
+    x76 = ((unsigned)ct[7] << 8) + (unsigned)ct[6];
+    x54 = ((unsigned)ct[5] << 8) + (unsigned)ct[4];
+    x32 = ((unsigned)ct[3] << 8) + (unsigned)ct[2];
+    x10 = ((unsigned)ct[1] << 8) + (unsigned)ct[0];
 
     for (i = 15; i >= 0; i--) {
         if (i == 4 || i == 10) {
@@ -218,39 +233,43 @@
             x10 = (x10 - xkey[x76 & 63]) & 0xFFFF;
         }
 
-        x76 = ((x76 << 11) | (x76 >> 5)) & 0xFFFF;
+        x76 = ((x76 << 11) | (x76 >> 5));
         x76 = (x76 - ((x10 & ~x54) + (x32 & x54) + xkey[4*i+3])) & 0xFFFF;
 
-        x54 = ((x54 << 13) | (x54 >> 3)) & 0xFFFF;
+        x54 = ((x54 << 13) | (x54 >> 3));
         x54 = (x54 - ((x76 & ~x32) + (x10 & x32) + xkey[4*i+2])) & 0xFFFF;
 
-        x32 = ((x32 << 14) | (x32 >> 2)) & 0xFFFF;
+        x32 = ((x32 << 14) | (x32 >> 2));
         x32 = (x32 - ((x54 & ~x10) + (x76 & x10) + xkey[4*i+1])) & 0xFFFF;
 
-        x10 = ((x10 << 15) | (x10 >> 1)) & 0xFFFF;
+        x10 = ((x10 << 15) | (x10 >> 1));
         x10 = (x10 - ((x32 & ~x76) + (x54 & x76) + xkey[4*i+0])) & 0xFFFF;
     }
 
-    plain[0] = (unsigned char)x10;
-    plain[1] = (unsigned char)(x10 >> 8);
-    plain[2] = (unsigned char)x32;
-    plain[3] = (unsigned char)(x32 >> 8);
-    plain[4] = (unsigned char)x54;
-    plain[5] = (unsigned char)(x54 >> 8);
-    plain[6] = (unsigned char)x76;
-    plain[7] = (unsigned char)(x76 >> 8);
+    pt[0] = (unsigned char)x10;
+    pt[1] = (unsigned char)(x10 >> 8);
+    pt[2] = (unsigned char)x32;
+    pt[3] = (unsigned char)(x32 >> 8);
+    pt[4] = (unsigned char)x54;
+    pt[5] = (unsigned char)(x54 >> 8);
+    pt[6] = (unsigned char)x76;
+    pt[7] = (unsigned char)(x76 >> 8);
 }
 
-#ifdef CLEAN_STACK
-void rc2_ecb_decrypt( const unsigned char *cipher,
-                            unsigned char *plain,
+#ifdef LTC_CLEAN_STACK
+void rc2_ecb_decrypt( const unsigned char *ct,
+                            unsigned char *pt,
                             symmetric_key *skey)
 {
-    _rc2_ecb_decrypt(cipher, plain, skey);
+    _rc2_ecb_decrypt(ct, pt, skey);
     burn_stack(sizeof(unsigned *) + sizeof(unsigned) * 4 + sizeof(int));
 }
 #endif
 
+/**
+  Performs a self-test of the RC2 block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int rc2_test(void)
 {
  #ifndef LTC_TEST
@@ -302,9 +321,21 @@
    #endif
 }
 
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void rc2_done(symmetric_key *skey)
+{
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
 int rc2_keysize(int *keysize)
 {
-   _ARGCHK(keysize != NULL);
+   LTC_ARGCHK(keysize != NULL);
    if (*keysize < 8) {
        return CRYPT_INVALID_KEYSIZE;
    } else if (*keysize > 128) {
@@ -317,3 +348,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/rc2.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/rc5.c b/src/ciphers/rc5.c
similarity index 68%
rename from rc5.c
rename to src/ciphers/rc5.c
index ab79535..9465ac8 100644
--- a/rc5.c
+++ b/src/ciphers/rc5.c
@@ -6,16 +6,19 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* RC5 code by Tom St Denis */
+/**
+   @file rc5.c
+   RC5 code by Tom St Denis 
+*/
 
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
 #ifdef RC5
 
-const struct _cipher_descriptor rc5_desc =
+const struct ltc_cipher_descriptor rc5_desc =
 {
     "rc5",
     2,
@@ -24,7 +27,9 @@
     &rc5_ecb_encrypt,
     &rc5_ecb_decrypt,
     &rc5_test,
-    &rc5_keysize
+    &rc5_done,
+    &rc5_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 stab[50] = {
@@ -37,7 +42,15 @@
 0x62482413UL, 0x007f9dccUL
 };
 
-#ifdef CLEAN_STACK
+ /**
+    Initialize the RC5 block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+#ifdef LTC_CLEAN_STACK
 static int _rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
@@ -45,8 +58,8 @@
 {
     ulong32 L[64], *S, A, B, i, j, v, s, t, l;
 
-    _ARGCHK(skey != NULL);
-    _ARGCHK(key  != NULL);
+    LTC_ARGCHK(skey != NULL);
+    LTC_ARGCHK(key  != NULL);
     
     /* test parameters */
     if (num_rounds == 0) { 
@@ -81,13 +94,13 @@
 
     /* setup the S array */
     t = (ulong32)(2 * (num_rounds + 1));
-    memcpy(S, stab, t * sizeof(*S));
+    XMEMCPY(S, stab, t * sizeof(*S));
 
     /* mix buffer */
     s = 3 * MAX(t, j);
     l = j;
     for (A = B = i = j = v = 0; v < s; v++) { 
-        A = S[i] = ROL(S[i] + A + B, 3);
+        A = S[i] = ROLc(S[i] + A + B, 3);
         B = L[j] = ROL(L[j] + A + B, (A+B));
         if (++i == t) { i = 0; }
         if (++j == l) { j = 0; }
@@ -95,7 +108,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    int x;
@@ -105,26 +118,32 @@
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with RC5
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
    ulong32 A, B, *K;
    int r;
-   _ARGCHK(key != NULL);
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
 
    LOAD32L(A, &pt[0]);
    LOAD32L(B, &pt[4]);
-   A += key->rc5.K[0];
-   B += key->rc5.K[1];
-   K  = key->rc5.K + 2;
+   A += skey->rc5.K[0];
+   B += skey->rc5.K[1];
+   K  = skey->rc5.K + 2;
    
-   if ((key->rc5.rounds & 1) == 0) {
-      for (r = 0; r < key->rc5.rounds; r += 2) {
+   if ((skey->rc5.rounds & 1) == 0) {
+      for (r = 0; r < skey->rc5.rounds; r += 2) {
           A = ROL(A ^ B, B) + K[0];
           B = ROL(B ^ A, A) + K[1];
           A = ROL(A ^ B, B) + K[2];
@@ -132,7 +151,7 @@
           K += 4;
       }
    } else {
-      for (r = 0; r < key->rc5.rounds; r++) {
+      for (r = 0; r < skey->rc5.rounds; r++) {
           A = ROL(A ^ B, B) + K[0];
           B = ROL(B ^ A, A) + K[1];
           K += 2;
@@ -142,33 +161,39 @@
    STORE32L(B, &ct[4]);
 }
 
-#ifdef CLEAN_STACK
-void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-   _rc5_ecb_encrypt(pt, ct, key);
+   _rc5_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 2 + sizeof(int));
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with RC5
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
    ulong32 A, B, *K;
    int r;
-   _ARGCHK(key != NULL);
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
 
    LOAD32L(A, &ct[0]);
    LOAD32L(B, &ct[4]);
-   K = key->rc5.K + (key->rc5.rounds << 1);
+   K = skey->rc5.K + (skey->rc5.rounds << 1);
    
-   if ((key->rc5.rounds & 1) == 0) {
+   if ((skey->rc5.rounds & 1) == 0) {
        K -= 2;
-       for (r = key->rc5.rounds - 1; r >= 0; r -= 2) {
+       for (r = skey->rc5.rounds - 1; r >= 0; r -= 2) {
           B = ROR(B - K[3], A) ^ A;
           A = ROR(A - K[2], B) ^ B;
           B = ROR(B - K[1], A) ^ A;
@@ -176,26 +201,30 @@
           K -= 4;
         }
    } else {
-      for (r = key->rc5.rounds - 1; r >= 0; r--) {
+      for (r = skey->rc5.rounds - 1; r >= 0; r--) {
           B = ROR(B - K[1], A) ^ A;
           A = ROR(A - K[0], B) ^ B;
           K -= 2;
       }
    }
-   A -= key->rc5.K[0];
-   B -= key->rc5.K[1];
+   A -= skey->rc5.K[0];
+   B -= skey->rc5.K[1];
    STORE32L(A, &pt[0]);
    STORE32L(B, &pt[4]);
 }
 
-#ifdef CLEAN_STACK
-void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-   _rc5_ecb_decrypt(ct, pt, key);
+   _rc5_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 2 + sizeof(int));
 }
 #endif
 
+/**
+  Performs a self-test of the RC5 block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int rc5_test(void)
 {
  #ifndef LTC_TEST
@@ -252,13 +281,25 @@
   #endif
 }
 
-int rc5_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void rc5_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
-   if (*desired_keysize < 8) {
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int rc5_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 8) {
       return CRYPT_INVALID_KEYSIZE;
-   } else if (*desired_keysize > 128) {
-      *desired_keysize = 128;
+   } else if (*keysize > 128) {
+      *keysize = 128;
    }
    return CRYPT_OK;
 }
@@ -267,3 +308,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/rc5.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/rc6.c b/src/ciphers/rc6.c
similarity index 72%
rename from rc6.c
rename to src/ciphers/rc6.c
index 8cc165c..ae6f114 100644
--- a/rc6.c
+++ b/src/ciphers/rc6.c
@@ -6,15 +6,18 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* RC6 code by Tom St Denis */
-#include "mycrypt.h"
+/**
+   @file rc6.c
+   RC6 code by Tom St Denis 
+*/
+#include "tomcrypt.h"
 
 #ifdef RC6
 
-const struct _cipher_descriptor rc6_desc =
+const struct ltc_cipher_descriptor rc6_desc =
 {
     "rc6",
     3,
@@ -23,7 +26,9 @@
     &rc6_ecb_encrypt,
     &rc6_ecb_decrypt,
     &rc6_test,
-    &rc6_keysize
+    &rc6_done,
+    &rc6_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 stab[44] = {
@@ -34,7 +39,15 @@
 0x7ed08883UL, 0x1d08023cUL, 0xbb3f7bf5UL, 0x5976f5aeUL, 0xf7ae6f67UL, 0x95e5e920UL, 0x341d62d9UL, 0xd254dc92UL,
 0x708c564bUL, 0x0ec3d004UL, 0xacfb49bdUL, 0x4b32c376UL };
 
-#ifdef CLEAN_STACK
+ /**
+    Initialize the RC6 block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+#ifdef LTC_CLEAN_STACK
 static int _rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
@@ -42,8 +55,8 @@
 {
     ulong32 L[64], S[50], A, B, i, j, v, s, l;
 
-    _ARGCHK(key != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(key != NULL);
+    LTC_ARGCHK(skey != NULL);
 
     /* test parameters */
     if (num_rounds != 0 && num_rounds != 20) { 
@@ -71,13 +84,13 @@
     }
 
     /* setup the S array */
-    memcpy(S, stab, 44 * sizeof(stab[0]));
+    XMEMCPY(S, stab, 44 * sizeof(stab[0]));
 
     /* mix buffer */
     s = 3 * MAX(44, j);
     l = j;
     for (A = B = i = j = v = 0; v < s; v++) { 
-        A = S[i] = ROL(S[i] + A + B, 3);
+        A = S[i] = ROLc(S[i] + A + B, 3);
         B = L[j] = ROL(L[j] + A + B, (A+B));
         if (++i == 44) { i = 0; }
         if (++j == l)  { j = 0; }
@@ -90,7 +103,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    int x;
@@ -100,30 +113,36 @@
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with RC6
+  @param pt The input plaintext (16 bytes)
+  @param ct The output ciphertext (16 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
    ulong32 a,b,c,d,t,u, *K;
    int r;
    
-   _ARGCHK(key != NULL);
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
    LOAD32L(a,&pt[0]);LOAD32L(b,&pt[4]);LOAD32L(c,&pt[8]);LOAD32L(d,&pt[12]);
 
-   b += key->rc6.K[0];
-   d += key->rc6.K[1];
+   b += skey->rc6.K[0];
+   d += skey->rc6.K[1];
 
 #define RND(a,b,c,d) \
-       t = (b * (b + b + 1)); t = ROL(t, 5); \
-       u = (d * (d + d + 1)); u = ROL(u, 5); \
+       t = (b * (b + b + 1)); t = ROLc(t, 5); \
+       u = (d * (d + d + 1)); u = ROLc(u, 5); \
        a = ROL(a^t,u) + K[0];                \
        c = ROL(c^u,t) + K[1]; K += 2;   
     
-   K = key->rc6.K + 2;
+   K = skey->rc6.K + 2;
    for (r = 0; r < 20; r += 4) {
        RND(a,b,c,d);
        RND(b,c,d,a);
@@ -133,43 +152,49 @@
    
 #undef RND
 
-   a += key->rc6.K[42];
-   c += key->rc6.K[43];
+   a += skey->rc6.K[42];
+   c += skey->rc6.K[43];
    STORE32L(a,&ct[0]);STORE32L(b,&ct[4]);STORE32L(c,&ct[8]);STORE32L(d,&ct[12]);
 }
 
-#ifdef CLEAN_STACK
-void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-   _rc6_ecb_encrypt(pt, ct, key);
+   _rc6_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 6 + sizeof(int));
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with RC6
+  @param ct The input ciphertext (16 bytes)
+  @param pt The output plaintext (16 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
    ulong32 a,b,c,d,t,u, *K;
    int r;
 
-   _ARGCHK(key != NULL);
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
+   LTC_ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
    
    LOAD32L(a,&ct[0]);LOAD32L(b,&ct[4]);LOAD32L(c,&ct[8]);LOAD32L(d,&ct[12]);
-   a -= key->rc6.K[42];
-   c -= key->rc6.K[43];
+   a -= skey->rc6.K[42];
+   c -= skey->rc6.K[43];
    
 #define RND(a,b,c,d) \
-       t = (b * (b + b + 1)); t = ROL(t, 5); \
-       u = (d * (d + d + 1)); u = ROL(u, 5); \
+       t = (b * (b + b + 1)); t = ROLc(t, 5); \
+       u = (d * (d + d + 1)); u = ROLc(u, 5); \
        c = ROR(c - K[1], t) ^ u; \
        a = ROR(a - K[0], u) ^ t; K -= 2;
    
-   K = key->rc6.K + 40;
+   K = skey->rc6.K + 40;
    
    for (r = 0; r < 20; r += 4) {
        RND(d,a,b,c);
@@ -180,19 +205,23 @@
    
 #undef RND
 
-   b -= key->rc6.K[0];
-   d -= key->rc6.K[1];
+   b -= skey->rc6.K[0];
+   d -= skey->rc6.K[1];
    STORE32L(a,&pt[0]);STORE32L(b,&pt[4]);STORE32L(c,&pt[8]);STORE32L(d,&pt[12]);
 }
 
-#ifdef CLEAN_STACK
-void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-   _rc6_ecb_decrypt(ct, pt, key);
+   _rc6_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 6 + sizeof(int));
 }
 #endif
 
+/**
+  Performs a self-test of the RC6 block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int rc6_test(void)
 {
  #ifndef LTC_TEST
@@ -282,13 +311,25 @@
   #endif
 }
 
-int rc6_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void rc6_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
-   if (*desired_keysize < 8) {
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int rc6_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 8) {
       return CRYPT_INVALID_KEYSIZE;
-   } else if (*desired_keysize > 128) {
-      *desired_keysize = 128;
+   } else if (*keysize > 128) {
+      *keysize = 128;
    }
    return CRYPT_OK;
 }
@@ -296,3 +337,7 @@
 #endif /*RC6*/
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/rc6.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/safer.c b/src/ciphers/safer/safer.c
similarity index 90%
rename from safer.c
rename to src/ciphers/safer/safer.c
index 580872a..bad00a0 100644
--- a/safer.c
+++ b/src/ciphers/safer/safer.c
@@ -6,7 +6,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
 /*******************************************************************************
@@ -28,11 +28,11 @@
 *
 *******************************************************************************/
 
-#include <mycrypt.h>
+#include <tomcrypt.h>
 
 #ifdef SAFER
 
-const struct _cipher_descriptor 
+const struct ltc_cipher_descriptor 
    safer_k64_desc = {
    "safer-k64", 
    8, 8, 8, 8, SAFER_K64_DEFAULT_NOF_ROUNDS,
@@ -40,7 +40,9 @@
    &safer_ecb_encrypt,
    &safer_ecb_decrypt,
    &safer_k64_test,
-   &safer_64_keysize
+   &safer_done,
+   &safer_64_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
    },
 
    safer_sk64_desc = {
@@ -50,7 +52,9 @@
    &safer_ecb_encrypt,
    &safer_ecb_decrypt,
    &safer_sk64_test,
-   &safer_64_keysize
+   &safer_done,
+   &safer_64_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
    },
 
    safer_k128_desc = {
@@ -60,7 +64,9 @@
    &safer_ecb_encrypt,
    &safer_ecb_decrypt,
    &safer_sk128_test,
-   &safer_128_keysize
+   &safer_done,
+   &safer_128_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
    },
 
    safer_sk128_desc = {
@@ -70,11 +76,13 @@
    &safer_ecb_encrypt,
    &safer_ecb_decrypt,
    &safer_sk128_test,
-   &safer_128_keysize
+   &safer_done,
+   &safer_128_keysize,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL
    };
 
 /******************* Constants ************************************************/
-// #define TAB_LEN      256
+/* #define TAB_LEN      256  */
 
 /******************* Assertions ***********************************************/
 
@@ -89,7 +97,7 @@
 /******************* Types ****************************************************/
 extern const unsigned char safer_ebox[], safer_lbox[];
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void _Safer_Expand_Userkey(const unsigned char *userkey_1,
                                  const unsigned char *userkey_2,
                                  unsigned int nof_rounds,
@@ -151,13 +159,13 @@
         }
     }
     
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(ka, sizeof(ka));
     zeromem(kb, sizeof(kb));
 #endif
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void Safer_Expand_Userkey(const unsigned char *userkey_1,
                                  const unsigned char *userkey_2,
                                  unsigned int nof_rounds,
@@ -171,8 +179,8 @@
 
 int safer_k64_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
 {
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (numrounds != 0 && (numrounds < 6 || numrounds > SAFER_MAX_NOF_ROUNDS)) {
       return CRYPT_INVALID_ROUNDS;
@@ -188,8 +196,8 @@
    
 int safer_sk64_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
 {
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (numrounds != 0 && (numrounds < 6 || numrounds > SAFER_MAX_NOF_ROUNDS)) {
       return CRYPT_INVALID_ROUNDS;
@@ -205,8 +213,8 @@
 
 int safer_k128_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
 {
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (numrounds != 0 && (numrounds < 6 || numrounds > SAFER_MAX_NOF_ROUNDS)) {
       return CRYPT_INVALID_ROUNDS;
@@ -222,8 +230,8 @@
 
 int safer_sk128_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
 {
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (numrounds != 0 && (numrounds < 6 || numrounds > SAFER_MAX_NOF_ROUNDS)) {
       return CRYPT_INVALID_ROUNDS;
@@ -237,7 +245,7 @@
    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void _safer_ecb_encrypt(const unsigned char *block_in,
                              unsigned char *block_out,
                              symmetric_key *skey)
@@ -250,9 +258,9 @@
     unsigned int round;
     unsigned char *key;
 
-    _ARGCHK(block_in != NULL);
-    _ARGCHK(block_out != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(block_in != NULL);
+    LTC_ARGCHK(block_out != NULL);
+    LTC_ARGCHK(skey != NULL);
 
     key = skey->safer.key;
     a = block_in[0]; b = block_in[1]; c = block_in[2]; d = block_in[3];
@@ -279,7 +287,7 @@
     block_out[6] = g & 0xFF; block_out[7] = h & 0xFF;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 void safer_ecb_encrypt(const unsigned char *block_in,
                              unsigned char *block_out,
                              symmetric_key *skey)
@@ -289,7 +297,7 @@
 }
 #endif
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void _safer_ecb_decrypt(const unsigned char *block_in,
                              unsigned char *block_out,
                              symmetric_key *skey)
@@ -302,9 +310,9 @@
     unsigned int round;
     unsigned char *key;
 
-    _ARGCHK(block_in != NULL);
-    _ARGCHK(block_out != NULL);
-    _ARGCHK(skey != NULL);
+    LTC_ARGCHK(block_in != NULL);
+    LTC_ARGCHK(block_out != NULL);
+    LTC_ARGCHK(skey != NULL);
 
     key = skey->safer.key;
     a = block_in[0]; b = block_in[1]; c = block_in[2]; d = block_in[3];
@@ -332,7 +340,7 @@
     block_out[6] = g & 0xFF; block_out[7] = h & 0xFF;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 void safer_ecb_decrypt(const unsigned char *block_in,
                              unsigned char *block_out,
                              symmetric_key *skey)
@@ -344,7 +352,7 @@
 
 int safer_64_keysize(int *keysize)
 {
-   _ARGCHK(keysize != NULL);
+   LTC_ARGCHK(keysize != NULL);
    if (*keysize < 8) {
       return CRYPT_INVALID_KEYSIZE;
    } else {
@@ -355,7 +363,7 @@
 
 int safer_128_keysize(int *keysize)
 {
-   _ARGCHK(keysize != NULL);
+   LTC_ARGCHK(keysize != NULL);
    if (*keysize < 16) {
       return CRYPT_INVALID_KEYSIZE;
    } else {
@@ -428,6 +436,13 @@
   #endif
 }
 
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void safer_done(symmetric_key *skey)
+{
+}
+
 int safer_sk128_test(void)
 {
  #ifndef LTC_TEST
@@ -466,3 +481,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/safer/safer.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/safer_tab.c b/src/ciphers/safer/safer_tab.c
similarity index 91%
rename from safer_tab.c
rename to src/ciphers/safer/safer_tab.c
index 06859db..47fbd1c 100644
--- a/safer_tab.c
+++ b/src/ciphers/safer/safer_tab.c
@@ -6,10 +6,15 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-#include "mycrypt.h"
+/**
+  @file safer_tab.c
+  Tables for SAFER block ciphers
+*/ 
+ 
+#include "tomcrypt.h"
 
 #if defined(SAFERP) || defined(SAFER)
 
@@ -57,3 +62,7 @@
 #endif
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/safer/safer_tab.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/saferp.c b/src/ciphers/safer/saferp.c
similarity index 89%
rename from saferp.c
rename to src/ciphers/safer/saferp.c
index 8415deb..6d0d589 100644
--- a/saferp.c
+++ b/src/ciphers/safer/saferp.c
@@ -6,15 +6,18 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* SAFER+ Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file saferp.c
+   SAFER+ Implementation by Tom St Denis 
+*/
+#include "tomcrypt.h"
 
 #ifdef SAFERP
 
-const struct _cipher_descriptor saferp_desc =
+const struct ltc_cipher_descriptor saferp_desc =
 {
     "safer+",
     4,
@@ -23,7 +26,9 @@
     &saferp_ecb_encrypt,
     &saferp_ecb_decrypt,
     &saferp_test,
-    &saferp_keysize
+    &saferp_done,
+    &saferp_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 /* ROUND(b,i) 
@@ -129,7 +134,7 @@
     iSHUF(b2, b); iPHT(b);    \
     iSHUF(b, b2); iPHT(b2);
     
-#ifdef SMALL_CODE    
+#ifdef LTC_SMALL_CODE    
 
 static void _round(unsigned char *b, int i, symmetric_key *skey) 
 {
@@ -200,14 +205,22 @@
 {  53,  72, 156,  81,  47,  59,  85, 227, 192, 159, 216, 211, 243, 141, 177, 255},
 {  62, 220, 134, 119, 215, 166,  17, 251, 244, 186, 146, 145, 100, 131, 241,  51}};
 
+ /**
+    Initialize the SAFER+ block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
 int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    unsigned x, y, z;
    unsigned char t[33];
    static const int rounds[3] = { 8, 12, 16 };
 
-   _ARGCHK(key  != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* check arguments */
    if (keylen != 16 && keylen != 24 && keylen != 32) {
@@ -305,20 +318,26 @@
        }
        skey->saferp.rounds = 16;
    }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(t, sizeof(t));
 #endif
    return CRYPT_OK;
 }
 
+/**
+  Encrypts a block of text with SAFER+
+  @param pt The input plaintext (16 bytes)
+  @param ct The output ciphertext (16 bytes)
+  @param skey The key as scheduled
+*/
 void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
    unsigned char b[16];
    int x;
 
-   _ARGCHK(pt   != NULL);
-   _ARGCHK(ct   != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* do eight rounds */
    for (x = 0; x < 16; x++) {
@@ -362,19 +381,25 @@
    ct[13] = (b[13] + skey->saferp.K[skey->saferp.rounds*2][13]) & 255;
    ct[14] = (b[14] + skey->saferp.K[skey->saferp.rounds*2][14]) & 255;
    ct[15] = b[15] ^ skey->saferp.K[skey->saferp.rounds*2][15];
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(b, sizeof(b));
 #endif
 }
 
+/**
+  Decrypts a block of text with SAFER+
+  @param ct The input ciphertext (16 bytes)
+  @param pt The output plaintext (16 bytes)
+  @param skey The key as scheduled 
+*/
 void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
    unsigned char b[16];
    int x;
 
-   _ARGCHK(pt   != NULL);
-   _ARGCHK(ct   != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* do eight rounds */
    b[0] = ct[0] ^ skey->saferp.K[skey->saferp.rounds*2][0];
@@ -418,11 +443,15 @@
    for (x = 0; x < 16; x++) {
        pt[x] = b[x];
    }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(b, sizeof(b));
 #endif
 }
 
+/**
+  Performs a self-test of the SAFER+ block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int saferp_test(void)
 {
  #ifndef LTC_TEST
@@ -489,18 +518,30 @@
  #endif
 }
 
-int saferp_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void saferp_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int saferp_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
    
-   if (*desired_keysize < 16)
+   if (*keysize < 16)
       return CRYPT_INVALID_KEYSIZE;
-   if (*desired_keysize < 24) {
-      *desired_keysize = 16;
-   } else if (*desired_keysize < 32) {
-      *desired_keysize = 24;
+   if (*keysize < 24) {
+      *keysize = 16;
+   } else if (*keysize < 32) {
+      *keysize = 24;
    } else {
-      *desired_keysize = 32;
+      *keysize = 32;
    }
    return CRYPT_OK;
 }
@@ -508,3 +549,7 @@
 #endif
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/safer/saferp.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/skipjack.c b/src/ciphers/skipjack.c
similarity index 74%
rename from skipjack.c
rename to src/ciphers/skipjack.c
index a66efa1..4cb3bf2 100644
--- a/skipjack.c
+++ b/src/ciphers/skipjack.c
@@ -6,15 +6,18 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* Skipjack Implementation by Tom St Denis */
-#include "mycrypt.h"
+/**
+  @file skipjack.c
+  Skipjack Implementation by Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef SKIPJACK
 
-const struct _cipher_descriptor skipjack_desc =
+const struct ltc_cipher_descriptor skipjack_desc =
 {
     "skipjack",
     17,
@@ -23,7 +26,9 @@
     &skipjack_ecb_encrypt,
     &skipjack_ecb_decrypt,
     &skipjack_test,
-    &skipjack_keysize
+    &skipjack_done,
+    &skipjack_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const unsigned char sbox[256] = {
@@ -51,12 +56,20 @@
 /* simple x - 1 (mod 10) in one step */
 static const int ikeystep[] = { 9, 0, 1, 2, 3, 4, 5, 6, 7, 8 };
 
+ /**
+    Initialize the Skipjack block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
 int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    int x;
 
-   _ARGCHK(key  != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    if (keylen != 10) {
       return CRYPT_INVALID_KEYSIZE;
@@ -75,24 +88,24 @@
 }
 
 #define RULE_A \
-   tmp = g_func(w1, &kp, key->skipjack.key);      \
+   tmp = g_func(w1, &kp, skey->skipjack.key);      \
    w1  = tmp ^ w4 ^ x;                            \
    w4  = w3; w3 = w2;                             \
    w2  = tmp;
 
 #define RULE_B \
-   tmp  = g_func(w1, &kp, key->skipjack.key);     \
+   tmp  = g_func(w1, &kp, skey->skipjack.key);     \
    tmp1 = w4; w4  = w3;                           \
    w3   = w1 ^ w2 ^ x;                            \
    w1   = tmp1; w2 = tmp;
 
 #define RULE_A1 \
    tmp = w1 ^ w2 ^ x;                             \
-   w1  = ig_func(w2, &kp, key->skipjack.key);     \
+   w1  = ig_func(w2, &kp, skey->skipjack.key);     \
    w2  = w3; w3 = w4; w4 = tmp;
 
 #define RULE_B1 \
-   tmp = ig_func(w2, &kp, key->skipjack.key);     \
+   tmp = ig_func(w2, &kp, skey->skipjack.key);     \
    w2  = tmp ^ w3 ^ x;                            \
    w3  = w4; w4 = w1; w1 = tmp;
 
@@ -120,18 +133,24 @@
    return ((unsigned)g1<<8)|(unsigned)g2;
 }
 
-#ifdef CLEAN_STACK
-static void _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with Skipjack
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
    unsigned w1,w2,w3,w4,tmp,tmp1;
    int x, kp;
 
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* load block */
    w1 = ((unsigned)pt[0]<<8)|pt[1];
@@ -166,26 +185,32 @@
    ct[6] = (w4>>8)&255; ct[7] = w4&255;
 }
 
-#ifdef CLEAN_STACK
-void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-   _skipjack_ecb_encrypt(pt, ct, key);
+   _skipjack_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(unsigned) * 8 + sizeof(int) * 2);
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with Skipjack
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
    unsigned w1,w2,w3,w4,tmp;
    int x, kp;
 
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* load block */
    w1 = ((unsigned)ct[0]<<8)|ct[1];
@@ -224,14 +249,18 @@
    pt[6] = (w4>>8)&255; pt[7] = w4&255;
 }
 
-#ifdef CLEAN_STACK
-void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-   _skipjack_ecb_decrypt(ct, pt, key);
+   _skipjack_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(unsigned) * 7 + sizeof(int) * 2);
 }
 #endif
 
+/**
+  Performs a self-test of the Skipjack block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int skipjack_test(void)
 {
  #ifndef LTC_TEST
@@ -276,15 +305,31 @@
   #endif
 }
 
-int skipjack_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void skipjack_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize != NULL);
-   if (*desired_keysize < 10) {
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int skipjack_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 10) {
       return CRYPT_INVALID_KEYSIZE;
-   } else if (*desired_keysize > 10) {
-      *desired_keysize = 10;
+   } else if (*keysize > 10) {
+      *keysize = 10;
    }
    return CRYPT_OK;
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/skipjack.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/twofish.c b/src/ciphers/twofish/twofish.c
similarity index 79%
rename from twofish.c
rename to src/ciphers/twofish/twofish.c
index b618b98..f147bab 100644
--- a/twofish.c
+++ b/src/ciphers/twofish/twofish.c
@@ -6,11 +6,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* Implementation of Twofish by Tom St Denis */
-#include "mycrypt.h"
+ /** 
+   @file twofish.c
+   Implementation of Twofish by Tom St Denis 
+ */
+#include "tomcrypt.h"
 
 #ifdef TWOFISH
 
@@ -21,7 +24,7 @@
 #endif
 #endif
 
-const struct _cipher_descriptor twofish_desc =
+const struct ltc_cipher_descriptor twofish_desc =
 {
     "twofish",
     7,
@@ -30,7 +33,9 @@
     &twofish_ecb_encrypt,
     &twofish_ecb_decrypt,
     &twofish_test,
-    &twofish_keysize
+    &twofish_done,
+    &twofish_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 /* the two polynomials */
@@ -38,12 +43,14 @@
 #define RS_POLY           0x14D
 
 /* The 4x4 MDS Linear Transform */
+#if 0
 static const unsigned char MDS[4][4] = {
     { 0x01, 0xEF, 0x5B, 0x5B },
     { 0x5B, 0xEF, 0xEF, 0x01 },
     { 0xEF, 0x5B, 0x01, 0xEF },
     { 0xEF, 0x01, 0xEF, 0x5B }
 };
+#endif
 
 /* The 4x8 RS Linear Transform */
 static const unsigned char RS[4][8] = {
@@ -86,7 +93,7 @@
 };
 
 /* computes S_i[x] */
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static ulong32 _sbox(int i, ulong32 x)
 #else
 static ulong32 sbox(int i, ulong32 x)
@@ -125,7 +132,7 @@
    return (ulong32)y;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static ulong32 sbox(int i, ulong32 x)
 {
    ulong32 y;
@@ -133,7 +140,7 @@
    burn_stack(sizeof(unsigned char) * 11);
    return y;
 }
-#endif /* CLEAN_STACK */
+#endif /* LTC_CLEAN_STACK */
 
 #endif /* TWOFISH_TABLES */
 
@@ -270,10 +277,10 @@
 
 /* for GCC we don't use pointer aliases */
 #if defined(__GNUC__)
-    #define S1 key->twofish.S[0]
-    #define S2 key->twofish.S[1]
-    #define S3 key->twofish.S[2]
-    #define S4 key->twofish.S[3]
+    #define S1 skey->twofish.S[0]
+    #define S2 skey->twofish.S[1]
+    #define S3 skey->twofish.S[2]
+    #define S4 skey->twofish.S[3]
 #endif
 
 /* the G function */
@@ -282,7 +289,7 @@
 
 #else
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static ulong32 _g_func(ulong32 x, symmetric_key *key)
 #else
 static ulong32 g_func(ulong32 x, symmetric_key *key)
@@ -313,9 +320,9 @@
    return res;
 }
 
-#define g1_func(x, key) g_func(ROL(x, 8), key)
+#define g1_func(x, key) g_func(ROLc(x, 8), key)
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static ulong32 g_func(ulong32 x, symmetric_key *key)
 {
     ulong32 y;
@@ -323,11 +330,19 @@
     burn_stack(sizeof(unsigned char) * 4 + sizeof(ulong32));
     return y;
 }
-#endif /* CLEAN_STACK */
+#endif /* LTC_CLEAN_STACK */
 
 #endif /* TWOFISH_SMALL */
 
-#ifdef CLEAN_STACK
+ /**
+    Initialize the Twofish block cipher
+    @param key The symmetric key you wish to pass
+    @param keylen The key length in bytes
+    @param num_rounds The number of rounds desired (0 for default)
+    @param skey The key in as scheduled by this function.
+    @return CRYPT_OK if successful
+ */
+#ifdef LTC_CLEAN_STACK
 static int _twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 #else
 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
@@ -340,8 +355,8 @@
    unsigned char tmp[4], tmp2[4], M[8*4];
    ulong32 A, B;
 
-   _ARGCHK(key  != NULL);
-   _ARGCHK(skey != NULL);
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(skey != NULL);
 
    /* invalid arguments? */
    if (num_rounds != 16 && num_rounds != 0) {
@@ -386,13 +401,13 @@
        }
        h_func(tmp, tmp2, M, k, 1);
        LOAD32L(B, tmp2);
-       B = ROL(B, 8);
+       B = ROLc(B, 8);
 
        /* K[2i]   = A + B */
        skey->twofish.K[x+x] = (A + B) & 0xFFFFFFFFUL;
 
        /* K[2i+1] = (A + 2B) <<< 9 */
-       skey->twofish.K[x+x+1] = ROL(B + B + A, 9);
+       skey->twofish.K[x+x+1] = ROLc(B + B + A, 9);
    }
 
 #ifndef TWOFISH_SMALL
@@ -437,7 +452,7 @@
    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
    int x;
@@ -447,10 +462,16 @@
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  Encrypts a block of text with Twofish
+  @param pt The input plaintext (16 bytes)
+  @param ct The output ciphertext (16 bytes)
+  @param skey The key as scheduled
+*/
+#ifdef LTC_CLEAN_STACK
+static void _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #else
-void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 #endif
 {
     ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
@@ -459,61 +480,67 @@
     ulong32 *S1, *S2, *S3, *S4;
 #endif    
 
-    _ARGCHK(pt  != NULL);
-    _ARGCHK(ct  != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     
 #if !defined(TWOFISH_SMALL) && !defined(__GNUC__)
-    S1 = key->twofish.S[0];
-    S2 = key->twofish.S[1];
-    S3 = key->twofish.S[2];
-    S4 = key->twofish.S[3];
+    S1 = skey->twofish.S[0];
+    S2 = skey->twofish.S[1];
+    S3 = skey->twofish.S[2];
+    S4 = skey->twofish.S[3];
 #endif    
 
     LOAD32L(a,&pt[0]); LOAD32L(b,&pt[4]);
     LOAD32L(c,&pt[8]); LOAD32L(d,&pt[12]);
-    a ^= key->twofish.K[0];
-    b ^= key->twofish.K[1];
-    c ^= key->twofish.K[2];
-    d ^= key->twofish.K[3];
+    a ^= skey->twofish.K[0];
+    b ^= skey->twofish.K[1];
+    c ^= skey->twofish.K[2];
+    d ^= skey->twofish.K[3];
     
-    k  = key->twofish.K + 8;
+    k  = skey->twofish.K + 8;
     for (r = 8; r != 0; --r) {
-        t2 = g1_func(b, key);
-        t1 = g_func(a, key) + t2;
-        c  = ROR(c ^ (t1 + k[0]), 1);
-        d  = ROL(d, 1) ^ (t2 + t1 + k[1]);
+        t2 = g1_func(b, skey);
+        t1 = g_func(a, skey) + t2;
+        c  = RORc(c ^ (t1 + k[0]), 1);
+        d  = ROLc(d, 1) ^ (t2 + t1 + k[1]);
         
-        t2 = g1_func(d, key);
-        t1 = g_func(c, key) + t2;
-        a  = ROR(a ^ (t1 + k[2]), 1);
-        b  = ROL(b, 1) ^ (t2 + t1 + k[3]);
+        t2 = g1_func(d, skey);
+        t1 = g_func(c, skey) + t2;
+        a  = RORc(a ^ (t1 + k[2]), 1);
+        b  = ROLc(b, 1) ^ (t2 + t1 + k[3]);
         k += 4;
    }
 
     /* output with "undo last swap" */
-    ta = c ^ key->twofish.K[4];
-    tb = d ^ key->twofish.K[5];
-    tc = a ^ key->twofish.K[6];
-    td = b ^ key->twofish.K[7];
+    ta = c ^ skey->twofish.K[4];
+    tb = d ^ skey->twofish.K[5];
+    tc = a ^ skey->twofish.K[6];
+    td = b ^ skey->twofish.K[7];
 
     /* store output */
     STORE32L(ta,&ct[0]); STORE32L(tb,&ct[4]);
     STORE32L(tc,&ct[8]); STORE32L(td,&ct[12]);
 }
 
-#ifdef CLEAN_STACK
-void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 {
-   _twofish_ecb_encrypt(pt, ct, key);
+   _twofish_ecb_encrypt(pt, ct, skey);
    burn_stack(sizeof(ulong32) * 10 + sizeof(int));
 }
 #endif
 
-#ifdef CLEAN_STACK
-static void _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+/**
+  Decrypts a block of text with Twofish
+  @param ct The input ciphertext (16 bytes)
+  @param pt The output plaintext (16 bytes)
+  @param skey The key as scheduled 
+*/
+#ifdef LTC_CLEAN_STACK
+static void _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #else
-void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 #endif
 {
     ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
@@ -522,15 +549,15 @@
     ulong32 *S1, *S2, *S3, *S4;
 #endif    
 
-    _ARGCHK(pt != NULL);
-    _ARGCHK(ct != NULL);
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(pt   != NULL);
+    LTC_ARGCHK(ct   != NULL);
+    LTC_ARGCHK(skey != NULL);
     
 #if !defined(TWOFISH_SMALL) && !defined(__GNUC__)
-    S1 = key->twofish.S[0];
-    S2 = key->twofish.S[1];
-    S3 = key->twofish.S[2];
-    S4 = key->twofish.S[3];
+    S1 = skey->twofish.S[0];
+    S2 = skey->twofish.S[1];
+    S3 = skey->twofish.S[2];
+    S4 = skey->twofish.S[3];
 #endif    
 
     /* load input */
@@ -538,44 +565,48 @@
     LOAD32L(tc,&ct[8]); LOAD32L(td,&ct[12]);
 
     /* undo undo final swap */
-    a = tc ^ key->twofish.K[6];
-    b = td ^ key->twofish.K[7];
-    c = ta ^ key->twofish.K[4];
-    d = tb ^ key->twofish.K[5];
+    a = tc ^ skey->twofish.K[6];
+    b = td ^ skey->twofish.K[7];
+    c = ta ^ skey->twofish.K[4];
+    d = tb ^ skey->twofish.K[5];
 
-    k = key->twofish.K + 36;
+    k = skey->twofish.K + 36;
     for (r = 8; r != 0; --r) {
-        t2 = g1_func(d, key);
-        t1 = g_func(c, key) + t2;
-        a = ROL(a, 1) ^ (t1 + k[2]);
-        b = ROR(b ^ (t2 + t1 + k[3]), 1);
+        t2 = g1_func(d, skey);
+        t1 = g_func(c, skey) + t2;
+        a = ROLc(a, 1) ^ (t1 + k[2]);
+        b = RORc(b ^ (t2 + t1 + k[3]), 1);
 
-        t2 = g1_func(b, key);
-        t1 = g_func(a, key) + t2;
-        c = ROL(c, 1) ^ (t1 + k[0]);
-        d = ROR(d ^ (t2 +  t1 + k[1]), 1);
+        t2 = g1_func(b, skey);
+        t1 = g_func(a, skey) + t2;
+        c = ROLc(c, 1) ^ (t1 + k[0]);
+        d = RORc(d ^ (t2 +  t1 + k[1]), 1);
         k -= 4;
     }
 
     /* pre-white */
-    a ^= key->twofish.K[0];
-    b ^= key->twofish.K[1];
-    c ^= key->twofish.K[2];
-    d ^= key->twofish.K[3];
+    a ^= skey->twofish.K[0];
+    b ^= skey->twofish.K[1];
+    c ^= skey->twofish.K[2];
+    d ^= skey->twofish.K[3];
     
     /* store */
     STORE32L(a, &pt[0]); STORE32L(b, &pt[4]);
     STORE32L(c, &pt[8]); STORE32L(d, &pt[12]);
 }
 
-#ifdef CLEAN_STACK
-void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
+#ifdef LTC_CLEAN_STACK
+void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 {
-   _twofish_ecb_decrypt(ct, pt, key);
+   _twofish_ecb_decrypt(ct, pt, skey);
    burn_stack(sizeof(ulong32) * 10 + sizeof(int));
 }
 #endif
 
+/**
+  Performs a self-test of the Twofish block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
 int twofish_test(void)
 {
  #ifndef LTC_TEST
@@ -638,19 +669,31 @@
 #endif 
 }
 
-int twofish_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void twofish_done(symmetric_key *skey)
 {
-   _ARGCHK(desired_keysize);
-   if (*desired_keysize < 16)
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int twofish_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize);
+   if (*keysize < 16)
       return CRYPT_INVALID_KEYSIZE;
-   if (*desired_keysize < 24) {
-      *desired_keysize = 16;
+   if (*keysize < 24) {
+      *keysize = 16;
       return CRYPT_OK;
-   } else if (*desired_keysize < 32) {
-      *desired_keysize = 24;
+   } else if (*keysize < 32) {
+      *keysize = 24;
       return CRYPT_OK;
    } else {
-      *desired_keysize = 32;
+      *keysize = 32;
       return CRYPT_OK;
    }
 }
@@ -659,3 +702,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/twofish/twofish.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/twofish_tab.c b/src/ciphers/twofish/twofish_tab.c
similarity index 98%
rename from twofish_tab.c
rename to src/ciphers/twofish/twofish_tab.c
index 5a2bb5b..47d4717 100644
--- a/twofish_tab.c
+++ b/src/ciphers/twofish/twofish_tab.c
@@ -6,9 +6,13 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
+ /**
+    @file twofish_tab.c
+    Twofish tables, Tom St Denis
+ */
 #ifdef TWOFISH_TABLES
 
 /* pre generated 8x8 tables from the four 4x4s */
@@ -486,3 +490,7 @@
 #endif /* TWOFISH_ALL_TABLES */
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/twofish/twofish_tab.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/ciphers/xtea.c b/src/ciphers/xtea.c
new file mode 100644
index 0000000..a45a13a
--- /dev/null
+++ b/src/ciphers/xtea.c
@@ -0,0 +1,207 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+  @file xtea.c
+  Implementation of XTEA, Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef XTEA
+
+const struct ltc_cipher_descriptor xtea_desc =
+{
+    "xtea",
+    1,
+    16, 16, 8, 32,
+    &xtea_setup,
+    &xtea_ecb_encrypt,
+    &xtea_ecb_decrypt,
+    &xtea_test,
+    &xtea_done,
+    &xtea_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
+{
+   unsigned long x, sum, K[4];
+   
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   /* check arguments */
+   if (keylen != 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+
+   if (num_rounds != 0 && num_rounds != 32) {
+      return CRYPT_INVALID_ROUNDS;
+   }
+
+   /* load key */
+   LOAD32L(K[0], key+0);
+   LOAD32L(K[1], key+4);
+   LOAD32L(K[2], key+8);
+   LOAD32L(K[3], key+12);
+   
+   for (x = sum = 0; x < 32; x++) {
+       skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL;
+       sum = (sum + 0x9E3779B9UL) & 0xFFFFFFFFUL;
+       skey->xtea.B[x] = (sum + K[(sum>>11)&3]) & 0xFFFFFFFFUL;
+   }
+   
+#ifdef LTC_CLEAN_STACK
+   zeromem(&K, sizeof(K));
+#endif   
+   
+   return CRYPT_OK;
+}
+
+/**
+  Encrypts a block of text with XTEA
+  @param pt The input plaintext (8 bytes)
+  @param ct The output ciphertext (8 bytes)
+  @param skey The key as scheduled
+*/
+void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
+{
+   unsigned long y, z;
+   int r;
+
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   LOAD32L(y, &pt[0]);
+   LOAD32L(z, &pt[4]);
+   for (r = 0; r < 32; r += 4) {
+       y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
+       z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
+
+       y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r+1])) & 0xFFFFFFFFUL;
+       z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r+1])) & 0xFFFFFFFFUL;
+
+       y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r+2])) & 0xFFFFFFFFUL;
+       z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r+2])) & 0xFFFFFFFFUL;
+
+       y = (y + ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r+3])) & 0xFFFFFFFFUL;
+       z = (z + ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r+3])) & 0xFFFFFFFFUL;
+   }
+   STORE32L(y, &ct[0]);
+   STORE32L(z, &ct[4]);
+}
+
+/**
+  Decrypts a block of text with XTEA
+  @param ct The input ciphertext (8 bytes)
+  @param pt The output plaintext (8 bytes)
+  @param skey The key as scheduled 
+*/
+void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
+{
+   unsigned long y, z;
+   int r;
+
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(skey != NULL);
+
+   LOAD32L(y, &ct[0]);
+   LOAD32L(z, &ct[4]);
+   for (r = 31; r >= 0; r -= 4) {
+       z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r])) & 0xFFFFFFFFUL;
+       y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r])) & 0xFFFFFFFFUL;
+
+       z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r-1])) & 0xFFFFFFFFUL;
+       y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r-1])) & 0xFFFFFFFFUL;
+
+       z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r-2])) & 0xFFFFFFFFUL;
+       y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r-2])) & 0xFFFFFFFFUL;
+
+       z = (z - ((((y<<4)^(y>>5)) + y) ^ skey->xtea.B[r-3])) & 0xFFFFFFFFUL;
+       y = (y - ((((z<<4)^(z>>5)) + z) ^ skey->xtea.A[r-3])) & 0xFFFFFFFFUL;
+   }
+   STORE32L(y, &pt[0]);
+   STORE32L(z, &pt[4]);
+}
+
+/**
+  Performs a self-test of the XTEA block cipher
+  @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled
+*/
+int xtea_test(void)
+{
+ #ifndef LTC_TEST
+    return CRYPT_NOP;
+ #else    
+   static const unsigned char key[16] = 
+      { 0x78, 0x56, 0x34, 0x12, 0xf0, 0xcd, 0xcb, 0x9a,
+        0x48, 0x37, 0x26, 0x15, 0xc0, 0xbf, 0xae, 0x9d };
+   static const unsigned char pt[8] = 
+      { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
+   static const unsigned char ct[8] = 
+      { 0x75, 0xd7, 0xc5, 0xbf, 0xcf, 0x58, 0xc9, 0x3f };
+   unsigned char tmp[2][8];
+   symmetric_key skey;
+   int err, y;
+
+   if ((err = xtea_setup(key, 16, 0, &skey)) != CRYPT_OK)  {
+      return err;
+   }
+   xtea_ecb_encrypt(pt, tmp[0], &skey);
+   xtea_ecb_decrypt(tmp[0], tmp[1], &skey);
+
+   if (memcmp(tmp[0], ct, 8) != 0 || memcmp(tmp[1], pt, 8) != 0) { 
+      return CRYPT_FAIL_TESTVECTOR;
+   }
+
+      /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
+      for (y = 0; y < 8; y++) tmp[0][y] = 0;
+      for (y = 0; y < 1000; y++) xtea_ecb_encrypt(tmp[0], tmp[0], &skey);
+      for (y = 0; y < 1000; y++) xtea_ecb_decrypt(tmp[0], tmp[0], &skey);
+      for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
+
+   return CRYPT_OK;
+ #endif
+}
+
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void xtea_done(symmetric_key *skey)
+{
+}
+
+/**
+  Gets suitable key size
+  @param keysize [in/out] The length of the recommended key (in bytes).  This function will store the suitable size back in this variable.
+  @return CRYPT_OK if the input key size is acceptable.
+*/
+int xtea_keysize(int *keysize)
+{
+   LTC_ARGCHK(keysize != NULL);
+   if (*keysize < 16) {
+      return CRYPT_INVALID_KEYSIZE; 
+   }
+   *keysize = 16;
+   return CRYPT_OK;
+}
+
+
+#endif
+
+
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/xtea.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ccm/ccm_memory.c b/src/encauth/ccm/ccm_memory.c
new file mode 100644
index 0000000..48dc4b7
--- /dev/null
+++ b/src/encauth/ccm/ccm_memory.c
@@ -0,0 +1,309 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ccm_memory.c
+  CCM support, process a block of memory, Tom St Denis
+*/
+
+#ifdef CCM_MODE
+
+/**
+   CCM encrypt/decrypt and produce an authentication tag
+   @param cipher     The index of the cipher desired
+   @param key        The secret key to use
+   @param keylen     The length of the secret key (octets)
+   @param nonce      The session nonce [use once]
+   @param noncelen   The length of the nonce
+   @param header     The header for the session
+   @param headerlen  The length of the header (octets)
+   @param pt         [out] The plaintext
+   @param ptlen      The length of the plaintext (octets)
+   @param ct         [out] The ciphertext
+   @param tag        [out] The destination tag
+   @param taglen     [in/out] The max size and resulting size of the authentication tag
+   @param direction  Encrypt or Decrypt direction (0 or 1)
+   @return CRYPT_OK if successful
+*/
+int ccm_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+          unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen,
+                    int  direction)
+{
+   unsigned char  PAD[16], ctr[16], CTRPAD[16], b;
+   symmetric_key *skey;
+   int            err;
+   unsigned long  len, L, x, y, z, CTRlen;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(nonce  != NULL);
+   if (headerlen > 0) {
+      LTC_ARGCHK(header != NULL);
+   }
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+
+#ifdef LTC_FAST
+   if (16 % sizeof(LTC_FAST_TYPE)) {
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+
+   /* check cipher input */
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   if (cipher_descriptor[cipher].block_length != 16) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   /* make sure the taglen is even and <= 16 */
+   *taglen &= ~1;
+   if (*taglen > 16) {
+      *taglen = 16;
+   }
+
+   /* can't use < 4 */
+   if (*taglen < 4) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* is there an accelerator? */
+   if (cipher_descriptor[cipher].accel_ccm_memory != NULL) {
+       cipher_descriptor[cipher].accel_ccm_memory(
+           key,    keylen,
+           nonce,  noncelen,
+           header, headerlen,
+           pt,     ptlen,
+           ct, 
+           tag,    taglen,
+           direction);
+      return CRYPT_OK;
+   }
+
+   /* let's get the L value */
+   len = ptlen;
+   L   = 0;
+   while (len) {
+      ++L;
+      len >>= 8;
+   }
+   if (L <= 1) {
+      L = 2;
+   }
+
+   /* increase L to match the nonce len */
+   noncelen = (noncelen > 13) ? 13 : noncelen;
+   if ((15 - noncelen) > L) {
+      L = 15 - noncelen;
+   }
+
+   /* allocate mem for the symmetric key */
+   skey = XMALLOC(sizeof(*skey));
+   if (skey == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* initialize the cipher */
+   if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, skey)) != CRYPT_OK) {
+      XFREE(skey);
+      return err;
+   }
+
+   /* form B_0 == flags | Nonce N | l(m) */
+   x = 0;
+   PAD[x++] = ((headerlen > 0) ? (1<<6) : 0) |
+            (((*taglen - 2)>>1)<<3)        |
+            (L-1);
+
+   /* nonce */
+   for (y = 0; y < (16 - (L + 1)); y++) {
+       PAD[x++] = nonce[y];
+   }
+
+   /* store len */
+   len = ptlen;
+
+   /* shift len so the upper bytes of len are the contents of the length */
+   for (y = L; y < 4; y++) {
+       len <<= 8;
+   }
+
+   /* store l(m) (only store 32-bits) */
+   for (y = 0; L > 4 && (L-y)>4; y++) {
+       PAD[x++] = 0;
+   }
+   for (; y < L; y++) {
+       PAD[x++] = (len >> 24) & 255;
+       len <<= 8;
+   }
+
+   /* encrypt PAD */
+   cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+
+   /* handle header */
+   if (headerlen > 0) {
+      x = 0;
+      
+      /* store length */
+      if (headerlen < ((1UL<<16) - (1UL<<8))) {
+         PAD[x++] ^= (headerlen>>8) & 255;
+         PAD[x++] ^= headerlen & 255;
+      } else {
+         PAD[x++] ^= 0xFF;
+         PAD[x++] ^= 0xFE;
+         PAD[x++] ^= (headerlen>>24) & 255;
+         PAD[x++] ^= (headerlen>>16) & 255;
+         PAD[x++] ^= (headerlen>>8) & 255;
+         PAD[x++] ^= headerlen & 255;
+      }
+
+      /* now add the data */
+      for (y = 0; y < headerlen; y++) {
+          if (x == 16) {
+             /* full block so let's encrypt it */
+             cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+             x = 0;
+          }
+          PAD[x++] ^= header[y];
+      }
+
+      /* remainder? */
+      if (x != 0) {
+         cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+      }
+   }
+
+   /* setup the ctr counter */
+   x = 0;
+
+   /* flags */
+   ctr[x++] = L-1;
+ 
+   /* nonce */
+   for (y = 0; y < (16 - (L+1)); ++y) {
+      ctr[x++] = nonce[y];
+   }
+   /* offset */
+   while (x < 16) {
+      ctr[x++] = 0;
+   }
+
+   x      = 0;
+   CTRlen = 16;
+
+   /* now handle the PT */
+   if (ptlen > 0) {
+      y = 0;
+#ifdef LTC_FAST
+      if (ptlen & ~15)  {
+          if (direction == CCM_ENCRYPT) {
+             for (; y < (ptlen & ~15); y += 16) {
+                /* increment the ctr? */
+                for (z = 15; z > 15-L; z--) {
+                    ctr[z] = (ctr[z] + 1) & 255;
+                    if (ctr[z]) break;
+                }
+                cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
+
+                /* xor the PT against the pad first */
+                for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
+                    *((LTC_FAST_TYPE*)(&PAD[z]))  ^= *((LTC_FAST_TYPE*)(&pt[y+z]));
+                    *((LTC_FAST_TYPE*)(&ct[y+z])) = *((LTC_FAST_TYPE*)(&pt[y+z])) ^ *((LTC_FAST_TYPE*)(&CTRPAD[z]));
+                }
+                cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+             }
+         } else {
+             for (; y < (ptlen & ~15); y += 16) {
+                /* increment the ctr? */
+                for (z = 15; z > 15-L; z--) {
+                    ctr[z] = (ctr[z] + 1) & 255;
+                    if (ctr[z]) break;
+                }
+                cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
+
+                /* xor the PT against the pad last */
+                for (z = 0; z < 16; z += sizeof(LTC_FAST_TYPE)) {
+                    *((LTC_FAST_TYPE*)(&pt[y+z])) = *((LTC_FAST_TYPE*)(&ct[y+z])) ^ *((LTC_FAST_TYPE*)(&CTRPAD[z]));
+                    *((LTC_FAST_TYPE*)(&PAD[z]))  ^= *((LTC_FAST_TYPE*)(&pt[y+z]));
+                }
+                cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+             }
+         }
+     }
+#endif
+
+      for (; y < ptlen; y++) {
+          /* increment the ctr? */
+          if (CTRlen == 16) {
+             for (z = 15; z > 15-L; z--) {
+                 ctr[z] = (ctr[z] + 1) & 255;
+                 if (ctr[z]) break;
+             }
+             cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
+             CTRlen = 0;
+          }
+
+          /* if we encrypt we add the bytes to the MAC first */
+          if (direction == CCM_ENCRYPT) {
+             b     = pt[y];
+             ct[y] = b ^ CTRPAD[CTRlen++];
+          } else {
+             b     = ct[y] ^ CTRPAD[CTRlen++];
+             pt[y] = b;
+          }
+
+          if (x == 16) {
+             cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+             x = 0;
+          }
+          PAD[x++] ^= b;
+      }
+             
+      if (x != 0) {
+         cipher_descriptor[cipher].ecb_encrypt(PAD, PAD, skey);
+      }
+   }
+
+   /* setup CTR for the TAG */
+   ctr[14] = ctr[15] = 0x00;
+   cipher_descriptor[cipher].ecb_encrypt(ctr, CTRPAD, skey);
+   cipher_descriptor[cipher].done(skey);
+
+   /* store the TAG */
+   for (x = 0; x < 16 && x < *taglen; x++) {
+       tag[x] = PAD[x] ^ CTRPAD[x];
+   }
+   *taglen = x;
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(skey,   sizeof(*skey));
+   zeromem(PAD,    sizeof(PAD));
+   zeromem(CTRPAD, sizeof(CTRPAD));
+#endif
+
+   XFREE(skey);
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_memory.c,v $ */
+/* $Revision: 1.9 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ccm/ccm_test.c b/src/encauth/ccm/ccm_test.c
new file mode 100644
index 0000000..c33502a
--- /dev/null
+++ b/src/encauth/ccm/ccm_test.c
@@ -0,0 +1,174 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ccm_test.c
+  CCM support, process a block of memory, Tom St Denis
+*/
+
+#ifdef CCM_MODE
+
+int ccm_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   static const struct {
+       unsigned char key[16];
+       unsigned char nonce[16];
+       int           noncelen;
+       unsigned char header[64];
+       int           headerlen;
+       unsigned char pt[64];
+       int           ptlen;
+       unsigned char ct[64];
+       unsigned char tag[16];
+       int           taglen;
+   } tests[] = {
+
+/* 13 byte nonce, 8 byte auth, 23 byte pt */
+{
+   { 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 
+     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF },
+   { 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xA0, 
+     0xA1, 0xA2, 0xA3, 0xA4, 0xA5 },
+   13,
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
+   8,
+   { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+     0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E },
+   23,
+   { 0x58, 0x8C, 0x97, 0x9A, 0x61, 0xC6, 0x63, 0xD2,
+     0xF0, 0x66, 0xD0, 0xC2, 0xC0, 0xF9, 0x89, 0x80,
+     0x6D, 0x5F, 0x6B, 0x61, 0xDA, 0xC3, 0x84 },
+   { 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0 },
+   8
+},
+
+/* 13 byte nonce, 12 byte header, 19 byte pt */
+{
+   { 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 
+     0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF },
+   { 0x00, 0x00, 0x00, 0x06, 0x05, 0x04, 0x03, 0xA0, 
+     0xA1, 0xA2, 0xA3, 0xA4, 0xA5 },
+   13,
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B },
+   12,
+   { 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 
+     0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 
+     0x1C, 0x1D, 0x1E },
+   19,
+   { 0xA2, 0x8C, 0x68, 0x65, 0x93, 0x9A, 0x9A, 0x79, 
+     0xFA, 0xAA, 0x5C, 0x4C, 0x2A, 0x9D, 0x4A, 0x91, 
+     0xCD, 0xAC, 0x8C },
+   { 0x96, 0xC8, 0x61, 0xB9, 0xC9, 0xE6, 0x1E, 0xF1 },
+   8
+},
+
+/* supplied by Brian Gladman */
+{
+   { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 
+     0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f },
+   { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16  },
+   7,
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
+   8,
+   { 0x20, 0x21, 0x22, 0x23 },
+   4,
+   { 0x71, 0x62, 0x01, 0x5b },
+   { 0x4d, 0xac, 0x25, 0x5d },
+   4
+},
+
+{
+   { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, 
+     0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f },
+   { 0x00, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0xb5, 
+     0x03, 0x97, 0x76, 0xe7, 0x0c },
+   13,
+   { 0x08, 0x40, 0x0f, 0xd2, 0xe1, 0x28, 0xa5, 0x7c, 
+     0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0xab, 0xae, 
+     0xa5, 0xb8, 0xfc, 0xba, 0x00, 0x00 },
+   22,
+   { 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae, 
+     0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb, 
+     0x7e, 0x78, 0xa0, 0x50 },
+   20,
+   { 0xf3, 0xd0, 0xa2, 0xfe, 0x9a, 0x3d, 0xbf, 0x23, 
+     0x42, 0xa6, 0x43, 0xe4, 0x32, 0x46, 0xe8, 0x0c, 
+     0x3c, 0x04, 0xd0, 0x19 },
+   { 0x78, 0x45, 0xce, 0x0b, 0x16, 0xf9, 0x76, 0x23 },
+   8
+},
+
+};
+  unsigned long taglen, x;
+  unsigned char buf[64], buf2[64], tag2[16], tag[16];
+  int           err, idx;
+
+  idx = find_cipher("aes");
+  if (idx == -1) {
+     idx = find_cipher("rijndael");
+     if (idx == -1) {
+        return CRYPT_NOP;
+     }
+  }
+
+  for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) {
+      taglen = tests[x].taglen;
+      if ((err = ccm_memory(idx,
+                            tests[x].key, 16,
+                            tests[x].nonce, tests[x].noncelen,
+                            tests[x].header, tests[x].headerlen,
+                            (unsigned char*)tests[x].pt, tests[x].ptlen,
+                            buf,
+                            tag, &taglen, 0)) != CRYPT_OK) {
+         return err;
+      }
+
+      if (memcmp(buf, tests[x].ct, tests[x].ptlen)) {
+         return CRYPT_FAIL_TESTVECTOR;
+      }
+      if (memcmp(tag, tests[x].tag, tests[x].taglen)) {
+         return CRYPT_FAIL_TESTVECTOR;
+      }
+
+      if ((err = ccm_memory(idx,
+                            tests[x].key, 16,
+                            tests[x].nonce, tests[x].noncelen,
+                            tests[x].header, tests[x].headerlen,
+                            buf2, tests[x].ptlen,
+                            buf,
+                            tag2, &taglen, 1	)) != CRYPT_OK) {
+         return err;
+      }
+
+     if (memcmp(buf2, tests[x].pt, tests[x].ptlen)) {
+         return CRYPT_FAIL_TESTVECTOR;
+      }
+     if (memcmp(tag2, tests[x].tag, tests[x].taglen)) {
+         return CRYPT_FAIL_TESTVECTOR;
+     }
+ 
+
+  }
+  return CRYPT_OK;
+#endif
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_test.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_addheader.c b/src/encauth/eax/eax_addheader.c
new file mode 100644
index 0000000..cfb325d
--- /dev/null
+++ b/src/encauth/eax/eax_addheader.c
@@ -0,0 +1,38 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+/** 
+    @file eax_addheader.c
+    EAX implementation, add meta-data, by Tom St Denis 
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/** 
+    add header (metadata) to the stream 
+    @param eax    The current EAX state
+    @param header The header (meta-data) data you wish to add to the state
+    @param length The length of the header data
+    @return CRYPT_OK if successful
+*/
+int eax_addheader(eax_state *eax, const unsigned char *header, 
+                  unsigned long length)
+{
+   LTC_ARGCHK(eax    != NULL);
+   LTC_ARGCHK(header != NULL);
+   return omac_process(&eax->headeromac, header, length);
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_addheader.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_decrypt.c b/src/encauth/eax/eax_decrypt.c
new file mode 100644
index 0000000..13e23cc
--- /dev/null
+++ b/src/encauth/eax/eax_decrypt.c
@@ -0,0 +1,50 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+    @file eax_decrypt.c
+    EAX implementation, decrypt block, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/**  
+   Decrypt data with the EAX protocol
+   @param eax     The EAX state
+   @param ct      The ciphertext
+   @param pt      [out] The plaintext
+   @param length  The length (octets) of the ciphertext
+   @return CRYPT_OK if successful
+*/
+int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, 
+                unsigned long length)
+{
+   int err;
+   
+   LTC_ARGCHK(eax != NULL);
+   LTC_ARGCHK(pt  != NULL);
+   LTC_ARGCHK(ct  != NULL);
+
+   /* omac ciphertext */
+   if ((err = omac_process(&eax->ctomac, ct, length)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* decrypt  */
+   return ctr_decrypt(ct, pt, length, &eax->ctr);
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_decrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_decrypt_verify_memory.c b/src/encauth/eax/eax_decrypt_verify_memory.c
new file mode 100644
index 0000000..d6d72ab
--- /dev/null
+++ b/src/encauth/eax/eax_decrypt_verify_memory.c
@@ -0,0 +1,108 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+    @file eax_decrypt_verify_memory.c
+    EAX implementation, decrypt block of memory, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/**
+   Decrypt a block of memory and verify the provided MAC tag with EAX
+   @param cipher     The index of the cipher desired
+   @param key        The secret key
+   @param keylen     The length of the key (octets)
+   @param nonce      The nonce data (use once) for the session
+   @param noncelen   The length of the nonce data.
+   @param header     The session header data
+   @param headerlen  The length of the header (octets)
+   @param ct         The ciphertext
+   @param ctlen      The length of the ciphertext (octets)
+   @param pt         [out] The plaintext
+   @param tag        The authentication tag provided by the encoder
+   @param taglen     [in/out] The length of the tag (octets)
+   @param stat       [out] The result of the decryption (1==valid tag, 0==invalid)
+   @return CRYPT_OK if successful regardless of the resulting tag comparison
+*/
+int eax_decrypt_verify_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+    const unsigned char *ct,     unsigned long ctlen,
+          unsigned char *pt,
+          unsigned char *tag,    unsigned long taglen,
+          int           *stat)
+{
+   int            err;
+   eax_state     *eax;
+   unsigned char *buf;
+   unsigned long  buflen;
+
+   LTC_ARGCHK(stat != NULL);
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(tag  != NULL);
+
+   /* default to zero */
+   *stat = 0;
+
+   /* allocate ram */
+   buf = XMALLOC(taglen);
+   eax = XMALLOC(sizeof(*eax));
+   if (eax == NULL || buf == NULL) {
+      if (eax != NULL) {
+         XFREE(eax);
+      }
+      if (buf != NULL) {
+         XFREE(buf);
+      }
+      return CRYPT_MEM;
+   }
+
+   if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   if ((err = eax_decrypt(eax, ct, pt, ctlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+ 
+   buflen = taglen;
+   if ((err = eax_done(eax, buf, &buflen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* compare tags */
+   if (buflen >= taglen && memcmp(buf, tag, taglen) == 0) {
+      *stat = 1;
+   }
+   
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, taglen);
+   zeromem(eax, sizeof(*eax));
+#endif
+
+   XFREE(eax);
+   XFREE(buf);
+
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_decrypt_verify_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_done.c b/src/encauth/eax/eax_done.c
new file mode 100644
index 0000000..10e2c23
--- /dev/null
+++ b/src/encauth/eax/eax_done.c
@@ -0,0 +1,94 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file eax_done.c
+   EAX implementation, terminate session, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/**
+   Terminate an EAX session and get the tag.
+   @param eax       The EAX state
+   @param tag       [out] The destination of the authentication tag
+   @param taglen    [in/out] The max length and resulting length of the authentication tag
+   @return CRYPT_OK if successful
+*/
+int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen)
+{
+   int           err;
+   unsigned char *headermac, *ctmac;
+   unsigned long x, len;
+
+   LTC_ARGCHK(eax    != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+
+   /* allocate ram */
+   headermac = XMALLOC(MAXBLOCKSIZE);
+   ctmac     = XMALLOC(MAXBLOCKSIZE);
+
+   if (headermac == NULL || ctmac == NULL) {
+      if (headermac != NULL) {
+         XFREE(headermac);
+      }
+      if (ctmac != NULL) {
+         XFREE(ctmac);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* finish ctomac */
+   len = MAXBLOCKSIZE;
+   if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   /* finish headeromac */
+
+   /* note we specifically don't reset len so the two lens are minimal */
+
+   if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   /* terminate the CTR chain */
+   if ((err = ctr_done(&eax->ctr)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* compute N xor H xor C */
+   for (x = 0; x < len && x < *taglen; x++) {
+       tag[x] = eax->N[x] ^ headermac[x] ^ ctmac[x];
+   }
+   *taglen = x;
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(ctmac,     MAXBLOCKSIZE);
+   zeromem(headermac, MAXBLOCKSIZE);
+   zeromem(eax,       sizeof(*eax));
+#endif
+
+   XFREE(ctmac);
+   XFREE(headermac);
+
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_encrypt.c b/src/encauth/eax/eax_encrypt.c
new file mode 100644
index 0000000..a646588
--- /dev/null
+++ b/src/encauth/eax/eax_encrypt.c
@@ -0,0 +1,51 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file eax_encrypt.c
+   EAX implementation, encrypt block by Tom St Denis 
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/**
+   Encrypt with EAX a block of data.
+   @param eax        The EAX state
+   @param pt         The plaintext to encrypt
+   @param ct         [out] The ciphertext as encrypted
+   @param length     The length of the plaintext (octets)
+   @return CRYPT_OK if successful
+*/
+int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, 
+                unsigned long length)
+{
+   int err;
+   
+   LTC_ARGCHK(eax != NULL);
+   LTC_ARGCHK(pt  != NULL);
+   LTC_ARGCHK(ct  != NULL);
+
+   /* encrypt */
+   if ((err = ctr_encrypt(pt, ct, length, &eax->ctr)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* omac ciphertext */
+   return omac_process(&eax->ctomac, ct, length);
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_encrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_encrypt_authenticate_memory.c b/src/encauth/eax/eax_encrypt_authenticate_memory.c
new file mode 100644
index 0000000..9760616
--- /dev/null
+++ b/src/encauth/eax/eax_encrypt_authenticate_memory.c
@@ -0,0 +1,82 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+  @file eax_encrypt_authenticate_memory.c
+  EAX implementation, encrypt a block of memory, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/**
+   EAX encrypt and produce an authentication tag
+   @param cipher     The index of the cipher desired
+   @param key        The secret key to use
+   @param keylen     The length of the secret key (octets)
+   @param nonce      The session nonce [use once]
+   @param noncelen   The length of the nonce
+   @param header     The header for the session
+   @param headerlen  The length of the header (octets)
+   @param pt         The plaintext
+   @param ptlen      The length of the plaintext (octets)
+   @param ct         [out] The ciphertext
+   @param tag        [out] The destination tag
+   @param taglen     [in/out] The max size and resulting size of the authentication tag
+   @return CRYPT_OK if successful
+*/
+int eax_encrypt_authenticate_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+    const unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen)
+{
+   int err;
+   eax_state *eax;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+
+   eax = XMALLOC(sizeof(*eax));
+
+   if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+ 
+   if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(eax, sizeof(*eax));
+#endif
+
+   XFREE(eax);
+
+   return err;   
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_encrypt_authenticate_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/eax/eax_init.c b/src/encauth/eax/eax_init.c
new file mode 100644
index 0000000..942b25f
--- /dev/null
+++ b/src/encauth/eax/eax_init.c
@@ -0,0 +1,144 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+   @file eax_init.c
+   EAX implementation, initialized EAX state, by Tom St Denis 
+*/
+#include "tomcrypt.h"
+
+#ifdef EAX_MODE
+
+/** 
+   Initialized an EAX state
+   @param eax       [out] The EAX state to initialize
+   @param cipher    The index of the desired cipher
+   @param key       The secret key
+   @param keylen    The length of the secret key (octets)
+   @param nonce     The use-once nonce for the session
+   @param noncelen  The length of the nonce (octets)
+   @param header    The header for the EAX state
+   @param headerlen The header length (octets)
+   @return CRYPT_OK if successful
+*/
+int eax_init(eax_state *eax, int cipher, 
+             const unsigned char *key,    unsigned long keylen,
+             const unsigned char *nonce,  unsigned long noncelen,
+             const unsigned char *header, unsigned long headerlen)
+{
+   unsigned char *buf;
+   int           err, blklen;
+   omac_state    *omac;
+   unsigned long len;
+
+
+   LTC_ARGCHK(eax   != NULL);
+   LTC_ARGCHK(key   != NULL);
+   LTC_ARGCHK(nonce != NULL);
+   if (headerlen > 0) {
+      LTC_ARGCHK(header != NULL);
+   }
+
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   blklen = cipher_descriptor[cipher].block_length;
+
+   /* allocate ram */
+   buf  = XMALLOC(MAXBLOCKSIZE);
+   omac = XMALLOC(sizeof(*omac));
+
+   if (buf == NULL || omac == NULL) {
+      if (buf != NULL) {
+         XFREE(buf);
+      }
+      if (omac != NULL) {
+         XFREE(omac);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* N = OMAC_0K(nonce) */
+   zeromem(buf, MAXBLOCKSIZE);
+   if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   /* omac the [0]_n */
+   if ((err = omac_process(omac, buf, blklen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+   /* omac the nonce */
+   if ((err = omac_process(omac, nonce, noncelen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+   /* store result */
+   len = sizeof(eax->N);
+   if ((err = omac_done(omac, eax->N, &len)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   /* H = OMAC_1K(header) */
+   zeromem(buf, MAXBLOCKSIZE);
+   buf[blklen - 1] = 1;
+
+   if ((err = omac_init(&eax->headeromac, cipher, key, keylen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   /* omac the [1]_n */
+   if ((err = omac_process(&eax->headeromac, buf, blklen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+   /* omac the header */
+   if (headerlen != 0) {
+      if ((err = omac_process(&eax->headeromac, header, headerlen)) != CRYPT_OK) {
+          goto LBL_ERR; 
+      }
+   }
+
+   /* 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, CTR_COUNTER_BIG_ENDIAN, &eax->ctr)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   /* setup the OMAC for the ciphertext */
+   if ((err = omac_init(&eax->ctomac, cipher, key, keylen)) != CRYPT_OK) { 
+      goto LBL_ERR; 
+   }
+
+   /* omac [2]_n */
+   zeromem(buf, MAXBLOCKSIZE);
+   buf[blklen-1] = 2;
+   if ((err = omac_process(&eax->ctomac, buf, blklen)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf,  MAXBLOCKSIZE);
+   zeromem(omac, sizeof(*omac));
+#endif
+
+   XFREE(omac);
+   XFREE(buf);
+
+   return err;
+}
+
+#endif 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_init.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/eax_test.c b/src/encauth/eax/eax_test.c
similarity index 94%
rename from eax_test.c
rename to src/encauth/eax/eax_test.c
index 93774b0..b08f5ab 100644
--- a/eax_test.c
+++ b/src/encauth/eax/eax_test.c
@@ -6,14 +6,21 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+    @file eax_test.c
+    EAX implementation, self-test, by Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef EAX_MODE
 
+/**
+   Test the EAX implementation
+   @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+*/
 int eax_test(void)
 {
 #ifndef LTC_TEST
@@ -269,3 +276,7 @@
 }
 
 #endif /* EAX_MODE */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/eax/eax_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_add_aad.c b/src/encauth/gcm/gcm_add_aad.c
new file mode 100644
index 0000000..03cb279
--- /dev/null
+++ b/src/encauth/gcm/gcm_add_aad.c
@@ -0,0 +1,124 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_add_aad.c
+   GCM implementation, Add AAD data to the stream, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/**
+  Add AAD to the GCM state
+  @param gcm       The GCM state
+  @param adata     The additional authentication data to add to the GCM state
+  @param adatalen  The length of the AAD data.
+  @return CRYPT_OK on success
+ */
+int gcm_add_aad(gcm_state *gcm,
+               const unsigned char *adata,  unsigned long adatalen)
+{
+   unsigned long x;
+   int           err;
+#ifdef LTC_FAST
+   unsigned long y;
+#endif
+
+   LTC_ARGCHK(gcm    != NULL);
+   if (adatalen > 0) {
+      LTC_ARGCHK(adata  != NULL);
+   }
+
+   if (gcm->buflen > 16 || gcm->buflen < 0) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* in IV mode? */
+   if (gcm->mode == GCM_MODE_IV) {
+      /* let's process the IV */
+      if (gcm->ivmode || gcm->buflen != 12) {
+         for (x = 0; x < (unsigned long)gcm->buflen; x++) {
+             gcm->X[x] ^= gcm->buf[x];
+         }
+         if (gcm->buflen) {
+            gcm->totlen += gcm->buflen * CONST64(8);
+            gcm_mult_h(gcm, gcm->X);
+         }
+ 
+         /* mix in the length */
+         zeromem(gcm->buf, 8);
+         STORE64H(gcm->totlen, gcm->buf+8);
+         for (x = 0; x < 16; x++) {
+             gcm->X[x] ^= gcm->buf[x];
+         }
+         gcm_mult_h(gcm, gcm->X);
+
+         /* copy counter out */ 
+         XMEMCPY(gcm->Y, gcm->X, 16);
+         zeromem(gcm->X, 16);
+      } else {
+         XMEMCPY(gcm->Y, gcm->buf, 12);
+         gcm->Y[12] = 0;
+         gcm->Y[13] = 0;
+         gcm->Y[14] = 0;
+         gcm->Y[15] = 1;
+      }
+      XMEMCPY(gcm->Y_0, gcm->Y, 16);
+      zeromem(gcm->buf, 16);
+      gcm->buflen = 0;
+      gcm->totlen = 0;
+      gcm->mode   = GCM_MODE_AAD;
+   }
+
+   if (gcm->mode != GCM_MODE_AAD || gcm->buflen >= 16) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   x = 0;
+#ifdef LTC_FAST
+   if (gcm->buflen == 0) {
+      for (x = 0; x < (adatalen & ~15); x += 16) {
+          for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+              *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&adata[x + y]));
+          }
+          gcm_mult_h(gcm, gcm->X);
+          gcm->totlen += 128;
+      }
+      adata += x;
+   }
+#endif
+
+
+   /* start adding AAD data to the state */
+   for (; x < adatalen; x++) {
+       gcm->X[gcm->buflen++] ^= *adata++;
+
+       if (gcm->buflen == 16) {
+         /* GF mult it */
+         gcm_mult_h(gcm, gcm->X);
+         gcm->buflen = 0;
+         gcm->totlen += 128;
+      }
+   }
+
+   return CRYPT_OK;
+}
+#endif
+   
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_add_aad.c,v $ */
+/* $Revision: 1.14 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_add_iv.c b/src/encauth/gcm/gcm_add_iv.c
new file mode 100644
index 0000000..107cf35
--- /dev/null
+++ b/src/encauth/gcm/gcm_add_iv.c
@@ -0,0 +1,94 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_add_iv.c
+   GCM implementation, add IV data to the state, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/**
+  Add IV data to the GCM state
+  @param gcm    The GCM state
+  @param IV     The initial value data to add
+  @param IVlen  The length of the IV
+  @return CRYPT_OK on success
+ */
+int gcm_add_iv(gcm_state *gcm, 
+               const unsigned char *IV,     unsigned long IVlen)
+{
+   unsigned long x, y;
+   int           err;
+
+   LTC_ARGCHK(gcm != NULL);
+   if (IVlen > 0) {
+      LTC_ARGCHK(IV  != NULL);
+   }
+
+   /* must be in IV mode */
+   if (gcm->mode != GCM_MODE_IV) {
+      return CRYPT_INVALID_ARG;
+   }
+ 
+   if (gcm->buflen >= 16 || gcm->buflen < 0) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+
+   /* trip the ivmode flag */
+   if (IVlen + gcm->buflen > 12) {
+      gcm->ivmode |= 1;
+   }
+
+   x = 0;
+#ifdef LTC_FAST
+   if (gcm->buflen == 0) {
+      for (x = 0; x < (IVlen & ~15); x += 16) {
+          for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+              *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&IV[x + y]));
+          }
+          gcm_mult_h(gcm, gcm->X);
+          gcm->totlen += 128;
+      }
+      IV += x;
+   }
+#endif
+
+   /* start adding IV data to the state */
+   for (; x < IVlen; x++) {
+       gcm->buf[gcm->buflen++] = *IV++;
+
+       if (gcm->buflen == 16) {
+         /* GF mult it */
+         for (y = 0; y < 16; y++) {
+             gcm->X[y] ^= gcm->buf[y];
+         }
+         gcm_mult_h(gcm, gcm->X);
+         gcm->buflen = 0;
+         gcm->totlen += 128;
+      }
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+   
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_add_iv.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_done.c b/src/encauth/gcm/gcm_done.c
new file mode 100644
index 0000000..96ef7f3
--- /dev/null
+++ b/src/encauth/gcm/gcm_done.c
@@ -0,0 +1,81 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_done.c
+   GCM implementation, Terminate the stream, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/**
+  Terminate a GCM stream
+  @param gcm     The GCM state
+  @param tag     [out] The destination for the MAC tag
+  @param taglen  [in/out]  The length of the MAC tag
+  @return CRYPT_OK on success
+ */
+int gcm_done(gcm_state *gcm, 
+                     unsigned char *tag,    unsigned long *taglen)
+{
+   unsigned long x;
+   int err;
+
+   LTC_ARGCHK(gcm     != NULL);
+   LTC_ARGCHK(tag     != NULL);
+   LTC_ARGCHK(taglen  != NULL);
+
+   if (gcm->buflen > 16 || gcm->buflen < 0) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+
+   if (gcm->mode != GCM_MODE_TEXT) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* handle remaining ciphertext */
+   if (gcm->buflen) {
+      gcm->pttotlen += gcm->buflen * CONST64(8);
+      gcm_mult_h(gcm, gcm->X);
+   }
+
+   /* length */
+   STORE64H(gcm->totlen, gcm->buf);
+   STORE64H(gcm->pttotlen, gcm->buf+8);
+   for (x = 0; x < 16; x++) {
+       gcm->X[x] ^= gcm->buf[x];
+   }
+   gcm_mult_h(gcm, gcm->X);
+
+   /* encrypt original counter */
+   cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y_0, gcm->buf, &gcm->K);
+   for (x = 0; x < 16 && x < *taglen; x++) {
+       tag[x] = gcm->buf[x] ^ gcm->X[x];
+   }
+   *taglen = x;
+
+   cipher_descriptor[gcm->cipher].done(&gcm->K);
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_done.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_gf_mult.c b/src/encauth/gcm/gcm_gf_mult.c
new file mode 100644
index 0000000..06db22b
--- /dev/null
+++ b/src/encauth/gcm/gcm_gf_mult.c
@@ -0,0 +1,94 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_gf_mult.c
+   GCM implementation, initialize state, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/* right shift */
+static void gcm_rightshift(unsigned char *a)
+{
+   int x;
+   for (x = 15; x > 0; x--) {
+       a[x] = (a[x]>>1) | ((a[x-1]<<7)&0x80);
+   }
+   a[0] >>= 1;
+}
+
+/* c = b*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
+  @param b   Second value
+  @param c   Destination for a * b
+ */  
+void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c)
+{
+   unsigned char Z[16], V[16];
+   unsigned x, y, z;
+
+   zeromem(Z, 16);
+   XMEMCPY(V, a, 16);
+   for (x = 0; x < 128; x++) {
+       if (b[x>>3] & mask[x&7]) {
+          for (y = 0; y < 16; y++) {
+              Z[y] ^= V[y]; 
+          }
+       }
+       z     = V[15] & 0x01;
+       gcm_rightshift(V);
+       V[0] ^= poly[z];
+   }
+   XMEMCPY(c, Z, 16);
+}
+
+/**
+  GCM multiply by H
+  @param gcm   The GCM state which holds the H value
+  @param I     The value to multiply H by
+ */
+void gcm_mult_h(gcm_state *gcm, unsigned char *I)
+{
+   unsigned char T[16];
+#ifdef GCM_TABLES
+   int x, y;
+   XMEMCPY(T, &gcm->PC[0][I[0]][0], 16);
+   for (x = 1; x < 16; x++) {
+#ifdef LTC_FAST
+       for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+           *((LTC_FAST_TYPE *)(T + y)) ^= *((LTC_FAST_TYPE *)(&gcm->PC[x][I[x]][y]));
+       }
+#else
+       for (y = 0; y < 16; y++) {
+           T[y] ^= gcm->PC[x][I[x]][y];
+       }
+#endif
+   }
+#else     
+   gcm_gf_mult(gcm->H, I, T); 
+#endif
+   XMEMCPY(I, T, 16);
+}
+
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_gf_mult.c,v $ */
+/* $Revision: 1.16 $ */
+/* $Date: 2005/05/21 14:33:42 $ */
diff --git a/src/encauth/gcm/gcm_init.c b/src/encauth/gcm/gcm_init.c
new file mode 100644
index 0000000..249b61d
--- /dev/null
+++ b/src/encauth/gcm/gcm_init.c
@@ -0,0 +1,145 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_init.c
+   GCM implementation, initialize state, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#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
+  @param cipher  The index of the cipher to use
+  @param key     The secret key
+  @param keylen  The length of the secret key
+  @return CRYPT_OK on success
+ */
+int gcm_init(gcm_state *gcm, int cipher, 
+             const unsigned char *key,  int keylen)
+{
+   int           err;
+   unsigned char B[16];
+#ifdef GCM_TABLES
+   int           x, y, z, t;
+#endif
+
+   LTC_ARGCHK(gcm != NULL);
+   LTC_ARGCHK(key != NULL);
+
+#ifdef LTC_FAST
+   if (16 % sizeof(LTC_FAST_TYPE)) {
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+
+   /* is cipher valid? */
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   if (cipher_descriptor[cipher].block_length != 16) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   /* schedule key */
+   if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &gcm->K)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* H = E(0) */
+   zeromem(B, 16);
+   cipher_descriptor[cipher].ecb_encrypt(B, gcm->H, &gcm->K);
+
+   /* setup state */
+   zeromem(gcm->buf, sizeof(gcm->buf));
+   zeromem(gcm->X,   sizeof(gcm->X));
+   gcm->cipher   = cipher;
+   gcm->mode     = GCM_MODE_IV;
+   gcm->ivmode   = 0;
+   gcm->buflen   = 0;
+   gcm->totlen   = 0;
+   gcm->pttotlen = 0;
+
+#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 (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: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_init.c,v $ */
+/* $Revision: 1.15 $ */
+/* $Date: 2005/05/21 15:05:19 $ */
diff --git a/src/encauth/gcm/gcm_memory.c b/src/encauth/gcm/gcm_memory.c
new file mode 100644
index 0000000..ee10d3f
--- /dev/null
+++ b/src/encauth/gcm/gcm_memory.c
@@ -0,0 +1,93 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_memory.c
+   GCM implementation, process a packet, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/**
+  Process an entire GCM packet in one call.
+  @param cipher            Index of cipher to use
+  @param key               The secret key
+  @param keylen            The length of the secret key
+  @param IV                The initial vector 
+  @param IVlen             The length of the initial vector
+  @param adata             The additional authentication data (header)
+  @param adatalen          The length of the adata
+  @param pt                The plaintext
+  @param ptlen             The length of the plaintext (ciphertext length is the same)
+  @param ct                The ciphertext
+  @param tag               [out] The MAC tag
+  @param taglen            [in/out] The MAC tag length
+  @param direction         Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
+  @return CRYPT_OK on success
+ */
+int gcm_memory(      int           cipher,
+               const unsigned char *key,    unsigned long keylen,
+               const unsigned char *IV,     unsigned long IVlen,
+               const unsigned char *adata,  unsigned long adatalen,
+                     unsigned char *pt,     unsigned long ptlen,
+                     unsigned char *ct, 
+                     unsigned char *tag,    unsigned long *taglen,
+                               int direction)
+{
+    gcm_state *gcm;
+    int        err;
+
+    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+       return err;
+    }
+ 
+    if (cipher_descriptor[cipher].accel_gcm_memory != NULL) {
+       cipher_descriptor[cipher].accel_gcm_memory
+                                          (key,   keylen,
+                                           IV,    IVlen,
+                                           adata, adatalen,
+                                           pt,    ptlen,
+                                           ct,
+                                           tag,   taglen,
+                                           direction);
+       return CRYPT_OK;
+    }
+
+
+    gcm = XMALLOC(sizeof(*gcm));
+    if (gcm == NULL) {
+        return CRYPT_MEM;
+    }
+
+    if ((err = gcm_init(gcm, cipher, key, keylen)) != CRYPT_OK) {
+       goto LTC_ERR;
+    }
+    if ((err = gcm_add_iv(gcm, IV, IVlen)) != CRYPT_OK) {
+       goto LTC_ERR;
+    }
+    if ((err = gcm_add_aad(gcm, adata, adatalen)) != CRYPT_OK) {
+       goto LTC_ERR;
+    }
+    if ((err = gcm_process(gcm, pt, ptlen, ct, direction)) != CRYPT_OK) {
+       goto LTC_ERR;
+    }
+    err = gcm_done(gcm, tag, taglen);
+LTC_ERR:
+    XFREE(gcm);
+    return err;
+}
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_memory.c,v $ */
+/* $Revision: 1.19 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_process.c b/src/encauth/gcm/gcm_process.c
new file mode 100644
index 0000000..f512e28
--- /dev/null
+++ b/src/encauth/gcm/gcm_process.c
@@ -0,0 +1,147 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_process.c
+   GCM implementation, process message data, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/** 
+  Process plaintext/ciphertext through GCM
+  @param gcm       The GCM state 
+  @param pt        The plaintext
+  @param ptlen     The plaintext length (ciphertext length is the same)
+  @param ct        The ciphertext
+  @param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
+  @return CRYPT_OK on success
+ */
+int gcm_process(gcm_state *gcm,
+                     unsigned char *pt,     unsigned long ptlen,
+                     unsigned char *ct,
+                     int direction)
+{
+   unsigned long x, y;
+   unsigned char b;
+   int           err;
+
+   LTC_ARGCHK(gcm != NULL);
+   if (ptlen > 0) {
+      LTC_ARGCHK(pt  != NULL);
+      LTC_ARGCHK(ct  != NULL);
+   }
+
+   if (gcm->buflen > 16 || gcm->buflen < 0) {
+      return CRYPT_INVALID_ARG;
+   }
+ 
+   if ((err = cipher_is_valid(gcm->cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* in AAD mode? */
+   if (gcm->mode == GCM_MODE_AAD) {
+      /* let's process the AAD */
+      if (gcm->buflen) {
+         gcm->totlen += gcm->buflen * CONST64(8);
+         gcm_mult_h(gcm, gcm->X);
+      }
+
+      /* increment counter */
+      for (y = 15; y >= 12; y--) {
+          if (++gcm->Y[y]) { break; }
+      }
+      /* encrypt the counter */
+      cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);     
+
+      gcm->buflen = 0;
+      gcm->mode   = GCM_MODE_TEXT;
+   }
+
+   if (gcm->mode != GCM_MODE_TEXT) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   x = 0;
+#ifdef LTC_FAST
+   if (gcm->buflen == 0) {
+      if (direction == GCM_ENCRYPT) { 
+         for (x = 0; x < (ptlen & ~15); x += 16) {
+             /* ctr encrypt */
+             for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+                 *((LTC_FAST_TYPE*)(&ct[x + y])) = *((LTC_FAST_TYPE*)(&pt[x+y])) ^ *((LTC_FAST_TYPE*)(&gcm->buf[y]));
+                 *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&ct[x+y]));
+             }
+             /* GMAC it */
+             gcm->pttotlen += 128;
+             gcm_mult_h(gcm, gcm->X);
+             /* increment counter */
+             for (y = 15; y >= 12; y--) {
+                 if (++gcm->Y[y]) { break; }
+             }
+             cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
+         }
+      } else {
+         for (x = 0; x < (ptlen & ~15); x += 16) {
+             /* ctr encrypt */
+             for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+                 *((LTC_FAST_TYPE*)(&gcm->X[y])) ^= *((LTC_FAST_TYPE*)(&ct[x+y]));
+                 *((LTC_FAST_TYPE*)(&pt[x + y])) = *((LTC_FAST_TYPE*)(&ct[x+y])) ^ *((LTC_FAST_TYPE*)(&gcm->buf[y]));
+             }
+             /* GMAC it */
+             gcm->pttotlen += 128;
+             gcm_mult_h(gcm, gcm->X);
+             /* increment counter */
+             for (y = 15; y >= 12; y--) {
+                 if (++gcm->Y[y]) { break; }
+             }
+             cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
+         }
+     }
+   }
+#endif        
+
+   /* process text */
+   for (; x < ptlen; x++) {
+       if (gcm->buflen == 16) {
+          gcm->pttotlen += 128;
+          gcm_mult_h(gcm, gcm->X);
+          
+          /* increment counter */
+          for (y = 15; y >= 12; y--) {
+              if (++gcm->Y[y]) { break; }
+          }
+          cipher_descriptor[gcm->cipher].ecb_encrypt(gcm->Y, gcm->buf, &gcm->K);
+          gcm->buflen = 0;
+       }
+
+       if (direction == GCM_ENCRYPT) {
+          b = ct[x] = pt[x] ^ gcm->buf[gcm->buflen]; 
+       } else {
+          b = ct[x];
+          pt[x] = ct[x] ^ gcm->buf[gcm->buflen];
+       }
+       gcm->X[gcm->buflen++] ^= b;          
+   }
+
+   return CRYPT_OK;
+}
+
+
+
+#endif
+   
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_process.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_reset.c b/src/encauth/gcm/gcm_reset.c
new file mode 100644
index 0000000..b336a92
--- /dev/null
+++ b/src/encauth/gcm/gcm_reset.c
@@ -0,0 +1,44 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_reset.c
+   GCM implementation, reset a used state so it can accept IV data, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/**
+  Reset a GCM state to as if you just called gcm_init().  This saves the initialization time.
+  @param gcm   The GCM state to reset
+  @return CRYPT_OK on success
+*/
+int gcm_reset(gcm_state *gcm)
+{
+   LTC_ARGCHK(gcm != NULL);
+
+   zeromem(gcm->buf, sizeof(gcm->buf));
+   zeromem(gcm->X,   sizeof(gcm->X));
+   gcm->mode     = GCM_MODE_IV;
+   gcm->ivmode   = 0;
+   gcm->buflen   = 0;
+   gcm->totlen   = 0;
+   gcm->pttotlen = 0;
+  
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_reset.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/gcm/gcm_test.c b/src/encauth/gcm/gcm_test.c
new file mode 100644
index 0000000..7106188
--- /dev/null
+++ b/src/encauth/gcm/gcm_test.c
@@ -0,0 +1,368 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file gcm_test.c
+   GCM implementation, testing, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef GCM_MODE
+
+/** 
+  Test the GCM code
+  @return CRYPT_OK on success
+ */
+int gcm_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   static const struct {
+       unsigned char K[32];
+       int           keylen;
+       unsigned char P[64];
+       unsigned long ptlen;
+		 unsigned char A[64];
+       unsigned long alen;
+       unsigned char IV[64];
+       unsigned long IVlen;
+       unsigned char C[64];
+       unsigned char T[16];
+   } tests[] = {
+
+/* test case #1 */
+{
+  /* key */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+  16,
+
+  /* plaintext */
+  { 0 },
+  0,
+
+  /* AAD data */
+  { 0 },
+  0,
+
+  /* IV */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00 },
+  12,
+
+  /* ciphertext  */
+  { 0 },
+
+  /* tag */
+  { 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
+    0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a }
+},
+
+/* test case #2 */
+{
+  /* key */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+  16,
+
+  /* PT */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+  16,
+
+  /* ADATA */
+  { 0 },
+  0,
+
+  /* IV */
+  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00 },
+  12,
+
+  /* CT */
+  { 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
+    0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78 },
+
+  /* TAG */
+  { 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
+    0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf }
+},
+
+/* test case #3 */
+{
+   /* key */
+   { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 
+     0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, },
+   16,
+
+   /* PT */
+   { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 
+     0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 
+     0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, 
+     0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 
+     0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 
+     0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, 
+     0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 
+     0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, },
+  64,
+
+  /* ADATA */
+  { 0 },
+  0,
+
+  /* IV */
+  { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, 
+    0xde, 0xca, 0xf8, 0x88,  },
+  12,
+ 
+  /* CT */
+  { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 
+    0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 
+    0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, 
+    0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 
+    0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 
+    0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, 
+    0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 
+    0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85, },
+
+  /* TAG */
+  { 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, 
+    0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4, }
+},
+
+/* test case #4 */
+{
+   /* key */
+   { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 
+     0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, },
+   16,
+
+   /* PT */
+   { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 
+     0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 
+     0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, 
+     0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 
+     0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 
+     0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, 
+     0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 
+     0xba, 0x63, 0x7b, 0x39,  },
+   60,
+
+   /* ADATA */
+   { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 
+     0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 
+     0xab, 0xad, 0xda, 0xd2,  },
+   20,
+
+   /* IV */
+   { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, 
+     0xde, 0xca, 0xf8, 0x88,  },
+   12,
+
+   /* CT */
+   { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 
+     0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 
+     0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, 
+     0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 
+     0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 
+     0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, 
+     0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 
+     0x3d, 0x58, 0xe0, 0x91,  },
+
+   /* TAG */
+   { 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, 
+     0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47, }
+
+},
+
+/* test case #5 */
+{
+   /* key */
+   { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 
+     0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, },
+   16,
+
+   /* PT */
+   { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 
+     0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 
+     0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, 
+     0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 
+     0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 
+     0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, 
+     0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 
+     0xba, 0x63, 0x7b, 0x39,  },
+   60,
+
+   /* ADATA */
+   { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 
+     0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 
+     0xab, 0xad, 0xda, 0xd2,  },
+   20,
+
+   /* IV */
+   { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, },
+   8,
+
+   /* CT */
+   { 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, 
+     0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, 
+     0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8, 
+     0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, 
+     0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, 
+     0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, 
+     0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, 
+     0xc2, 0x3f, 0x45, 0x98,  },
+
+   /* TAG */
+   { 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, 
+     0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb, }
+},
+
+/* test case #6 */
+{
+   /* key */
+   { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 
+     0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, },
+   16,
+
+   /* PT */
+   { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 
+     0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 
+     0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, 
+     0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 
+     0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 
+     0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, 
+     0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 
+     0xba, 0x63, 0x7b, 0x39,  },
+   60,
+
+   /* ADATA */
+   { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 
+     0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 
+     0xab, 0xad, 0xda, 0xd2,  },
+   20,
+
+   /* IV */
+   { 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, 
+     0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, 
+     0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, 
+     0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, 
+     0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, 
+     0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, 
+     0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, 
+     0xa6, 0x37, 0xb3, 0x9b,  },
+   60,
+
+   /* CT */
+   { 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, 
+     0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, 
+     0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8, 
+     0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, 
+     0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, 
+     0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, 
+     0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, 
+     0x4c, 0x34, 0xae, 0xe5,  },
+
+   /* TAG */
+   { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, 
+     0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, }
+}
+
+/* rest of test cases are the same except AES key size changes... ignored... */
+};
+   int           idx, err;
+   unsigned long x, y;
+   unsigned char out[2][64], T[2][16];
+
+   /* find aes */
+   idx = find_cipher("aes");
+   if (idx == -1) {
+      idx = find_cipher("rijndael");
+      if (idx == -1) {
+         return CRYPT_NOP;
+      }
+   }
+
+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+       y = sizeof(T[0]);
+       if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen,
+                             tests[x].IV, tests[x].IVlen,
+                             tests[x].A, tests[x].alen,
+                             (unsigned char*)tests[x].P, tests[x].ptlen,
+                             out[0], T[0], &y, GCM_ENCRYPT)) != CRYPT_OK) {
+          return err;
+       }
+
+       if (memcmp(out[0], tests[x].C, tests[x].ptlen)) {
+#if 0
+          printf("\nCiphertext wrong %lu\n", x);
+          for (y = 0; y < tests[x].ptlen; y++) {
+              printf("%02x", out[0][y] & 255);
+          }
+          printf("\n");
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+       if (memcmp(T[0], tests[x].T, 16)) {
+#if 0
+          printf("\nTag on plaintext wrong %lu\n", x);
+          for (y = 0; y < 16; y++) {
+              printf("%02x", T[0][y] & 255);
+          }
+          printf("\n");
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+       y = sizeof(T[1]);
+       if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen,
+                             tests[x].IV, tests[x].IVlen,
+                             tests[x].A, tests[x].alen,
+                             out[1], tests[x].ptlen,
+                             out[0], T[1], &y, GCM_DECRYPT)) != CRYPT_OK) {
+          return err;
+       }
+
+       if (memcmp(out[1], tests[x].P, tests[x].ptlen)) {
+#if 0
+          printf("\nplaintext wrong %lu\n", x);
+          for (y = 0; y < tests[x].ptlen; y++) {
+              printf("%02x", out[0][y] & 255);
+          }
+          printf("\n");
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+       if (memcmp(T[1], tests[x].T, 16)) {
+#if 0
+          printf("\nTag on ciphertext wrong %lu\n", x);
+          for (y = 0; y < 16; y++) {
+              printf("%02x", T[1][y] & 255);
+          }
+          printf("\n");
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+
+   }
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/gcm/gcm_test.c,v $ */
+/* $Revision: 1.15 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/ocb_decrypt.c b/src/encauth/ocb/ocb_decrypt.c
similarity index 62%
rename from ocb_decrypt.c
rename to src/encauth/ocb/ocb_decrypt.c
index b7c785b..a0f2754 100644
--- a/ocb_decrypt.c
+++ b/src/encauth/ocb/ocb_decrypt.c
@@ -6,28 +6,38 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
+/**
+   @file ocb_decrypt.c
+   OCB implementation, decrypt data, by Tom St Denis 
+*/
+#include "tomcrypt.h"
 
 #ifdef OCB_MODE
 
+/**
+  Decrypt a block with OCB.
+  @param ocb    The OCB state
+  @param ct     The ciphertext (length of the block size of the block cipher)
+  @param pt     [out] The plaintext (length of ct)
+  @return CRYPT_OK if successful
+*/
 int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt)
 {
    unsigned char Z[MAXBLOCKSIZE], tmp[MAXBLOCKSIZE];
    int err, x;
 
-   _ARGCHK(ocb != NULL);
-   _ARGCHK(pt  != NULL);
-   _ARGCHK(ct  != NULL);
+   LTC_ARGCHK(ocb != NULL);
+   LTC_ARGCHK(pt  != NULL);
+   LTC_ARGCHK(ct  != NULL);
 
    /* check if valid cipher */
    if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
       return err;
    }
-   _ARGCHK(cipher_descriptor[ocb->cipher].ecb_decrypt != NULL);
+   LTC_ARGCHK(cipher_descriptor[ocb->cipher].ecb_decrypt != NULL);
    
    /* check length */
    if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length) {
@@ -52,7 +62,7 @@
    }
 
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(Z, sizeof(Z));
    zeromem(tmp, sizeof(tmp));
 #endif
@@ -61,3 +71,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_decrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/ocb_decrypt_verify_memory.c b/src/encauth/ocb/ocb_decrypt_verify_memory.c
new file mode 100644
index 0000000..0173eff
--- /dev/null
+++ b/src/encauth/ocb/ocb_decrypt_verify_memory.c
@@ -0,0 +1,86 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+  @file ocb_decrypt_verify_memory.c
+  OCB implementation, helper to decrypt block of memory, by Tom St Denis 
+*/
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/**
+   Decrypt and compare the tag with OCB.
+   @param cipher     The index of the cipher desired
+   @param key        The secret key
+   @param keylen     The length of the secret key (octets)
+   @param nonce      The session nonce (length of the block size of the block cipher)
+   @param ct         The ciphertext
+   @param ctlen      The length of the ciphertext (octets)
+   @param pt         [out] The plaintext
+   @param tag        The tag to compare against
+   @param taglen     The length of the tag (octets)
+   @param stat       [out] The result of the tag comparison (1==valid, 0==invalid)
+   @return CRYPT_OK if successful regardless of the tag comparison
+*/
+int ocb_decrypt_verify_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  
+    const unsigned char *ct,     unsigned long ctlen,
+          unsigned char *pt,
+    const unsigned char *tag,    unsigned long taglen,
+          int           *stat)
+{
+   int err;
+   ocb_state *ocb;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(nonce  != NULL);
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(stat    != NULL);
+
+   /* allocate memory */
+   ocb = XMALLOC(sizeof(ocb_state));
+   if (ocb == NULL) {
+      return CRYPT_MEM;
+   }
+
+   if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
+      goto LBL_ERR; 
+   }
+
+   while (ctlen > (unsigned long)ocb->block_len) {
+        if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) {
+            goto LBL_ERR; 
+        }
+        ctlen   -= ocb->block_len;
+        pt      += ocb->block_len;
+        ct      += ocb->block_len;
+   }
+
+   err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, stat);
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(ocb, sizeof(ocb_state));
+#endif
+ 
+   XFREE(ocb);
+
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_decrypt_verify_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/ocb_done_decrypt.c b/src/encauth/ocb/ocb_done_decrypt.c
new file mode 100644
index 0000000..fb149bd
--- /dev/null
+++ b/src/encauth/ocb/ocb_done_decrypt.c
@@ -0,0 +1,80 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+   @file ocb_done_decrypt.c
+   OCB implementation, terminate decryption, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/**
+   Terminate a decrypting OCB state
+   @param ocb    The OCB state
+   @param ct     The ciphertext (if any)
+   @param ctlen  The length of the ciphertext (octets)
+   @param pt     [out] The plaintext
+   @param tag    The authentication tag (to compare against)
+   @param taglen The length of the authentication tag provided
+   @param stat    [out] The result of the tag comparison
+   @return CRYPT_OK if the process was successful regardless if the tag is valid
+*/
+int ocb_done_decrypt(ocb_state *ocb, 
+                     const unsigned char *ct,  unsigned long ctlen,
+                           unsigned char *pt, 
+                     const unsigned char *tag, unsigned long taglen, int *stat)
+{
+   int err;
+   unsigned char *tagbuf;
+   unsigned long tagbuflen;
+
+   LTC_ARGCHK(ocb  != NULL);
+   LTC_ARGCHK(pt   != NULL);
+   LTC_ARGCHK(ct   != NULL);
+   LTC_ARGCHK(tag  != NULL);
+   LTC_ARGCHK(stat != NULL);
+
+   /* default to failed */
+   *stat = 0;
+
+   /* allocate memory */
+   tagbuf = XMALLOC(MAXBLOCKSIZE);
+   if (tagbuf == NULL) {
+      return CRYPT_MEM;
+   }
+
+   tagbuflen = MAXBLOCKSIZE;
+   if ((err = s_ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) {
+      *stat = 1;
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(tagbuf, MAXBLOCKSIZE);
+#endif
+
+   XFREE(tagbuf);
+
+   return err;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_done_decrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/ocb_done_encrypt.c b/src/encauth/ocb/ocb_done_encrypt.c
new file mode 100644
index 0000000..27126e7
--- /dev/null
+++ b/src/encauth/ocb/ocb_done_encrypt.c
@@ -0,0 +1,46 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+   @file ocb_done_encrypt.c
+   OCB implementation, terminate encryption, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/** 
+   Terminate an encryption OCB state
+   @param ocb       The OCB state
+   @param pt        Remaining plaintext (if any)
+   @param ptlen     The length of the plaintext (octets)
+   @param ct        [out] The ciphertext (if any)
+   @param tag       [out] The tag for the OCB stream
+   @param taglen    [in/out] The max size and resulting size of the tag
+   @return CRYPT_OK if successful
+*/
+int ocb_done_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
+                     unsigned char *ct, unsigned char *tag, unsigned long *taglen)
+{
+   LTC_ARGCHK(ocb    != NULL);
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+   return s_ocb_done(ocb, pt, ptlen, ct, tag, taglen, 0);
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_done_encrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/ocb_encrypt.c b/src/encauth/ocb/ocb_encrypt.c
similarity index 63%
rename from ocb_encrypt.c
rename to src/encauth/ocb/ocb_encrypt.c
index d951933..2a48551 100644
--- a/ocb_encrypt.c
+++ b/src/encauth/ocb/ocb_encrypt.c
@@ -6,22 +6,32 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file ocb_encrypt.c
+   OCB implementation, encrypt data, by Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef OCB_MODE
 
+/**
+   Encrypt a block of data with OCB.
+   @param ocb     The OCB state
+   @param pt      The plaintext (length of the block size of the block cipher)
+   @param ct      [out] The ciphertext (same size as the pt)
+   @return CRYPT_OK if successful
+*/
 int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct)
 {
    unsigned char Z[MAXBLOCKSIZE], tmp[MAXBLOCKSIZE];
    int err, x;
 
-   _ARGCHK(ocb != NULL);
-   _ARGCHK(pt  != NULL);
-   _ARGCHK(ct  != NULL);
+   LTC_ARGCHK(ocb != NULL);
+   LTC_ARGCHK(pt  != NULL);
+   LTC_ARGCHK(ct  != NULL);
    if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
       return err;
    }
@@ -46,7 +56,7 @@
        ct[x] ^= Z[x];
    }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(Z, sizeof(Z));
    zeromem(tmp, sizeof(tmp));
 #endif
@@ -54,3 +64,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_encrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/ocb_encrypt_authenticate_memory.c b/src/encauth/ocb/ocb_encrypt_authenticate_memory.c
new file mode 100644
index 0000000..beb72c8
--- /dev/null
+++ b/src/encauth/ocb/ocb_encrypt_authenticate_memory.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+  @file ocb_encrypt_authenticate_memory.c
+  OCB implementation, encrypt block of memory, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/**
+   Encrypt and generate an authentication code for a buffer of memory
+   @param cipher     The index of the cipher desired
+   @param key        The secret key
+   @param keylen     The length of the secret key (octets)
+   @param nonce      The session nonce (length of the block ciphers block size)
+   @param pt         The plaintext
+   @param ptlen      The length of the plaintext (octets)
+   @param ct         [out] The ciphertext
+   @param tag        [out] The authentication tag
+   @param taglen     [in/out] The max size and resulting size of the authentication tag
+   @return CRYPT_OK if successful
+*/
+int ocb_encrypt_authenticate_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  
+    const unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen)
+{
+   int err;
+   ocb_state *ocb;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(nonce  != NULL);
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+
+   /* allocate ram */
+   ocb = XMALLOC(sizeof(ocb_state));
+   if (ocb == NULL) {
+      return CRYPT_MEM;
+   }
+
+   if ((err = ocb_init(ocb, cipher, key, keylen, nonce)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   while (ptlen > (unsigned long)ocb->block_len) {
+        if ((err = ocb_encrypt(ocb, pt, ct)) != CRYPT_OK) {
+           goto LBL_ERR;
+        }
+        ptlen   -= ocb->block_len;
+        pt      += ocb->block_len;
+        ct      += ocb->block_len;
+   }
+
+   err = ocb_done_encrypt(ocb, pt, ptlen, ct, tag, taglen);
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(ocb, sizeof(ocb_state));
+#endif
+
+   XFREE(ocb);
+
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_encrypt_authenticate_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/ocb_init.c b/src/encauth/ocb/ocb_init.c
similarity index 77%
rename from ocb_init.c
rename to src/encauth/ocb/ocb_init.c
index bfb5a87..9266d5c 100644
--- a/ocb_init.c
+++ b/src/encauth/ocb/ocb_init.c
@@ -6,11 +6,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
+/**
+   @file ocb_init.c
+   OCB implementation, initialize state, by Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef OCB_MODE
 
@@ -32,14 +35,23 @@
 }
 };
 
+/**
+  Initialize an OCB context.
+  @param ocb     [out] The destination of the OCB state
+  @param cipher  The index of the desired cipher
+  @param key     The secret key
+  @param keylen  The length of the secret key (octets)
+  @param nonce   The session nonce (length of the block size of the cipher)
+  @return CRYPT_OK if successful
+*/
 int ocb_init(ocb_state *ocb, int cipher, 
              const unsigned char *key, unsigned long keylen, const unsigned char *nonce)
 {
    int poly, x, y, m, err;
 
-   _ARGCHK(ocb   != NULL);
-   _ARGCHK(key   != NULL);
-   _ARGCHK(nonce != NULL);
+   LTC_ARGCHK(ocb   != NULL);
+   LTC_ARGCHK(key   != NULL);
+   LTC_ARGCHK(nonce != NULL);
 
    /* valid cipher? */
    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
@@ -73,7 +85,7 @@
    cipher_descriptor[cipher].ecb_encrypt(ocb->R, ocb->R, &ocb->key);
 
    /* find Ls[i] = L << i for i == 0..31 */
-   memcpy(ocb->Ls[0], ocb->L, ocb->block_len);
+   XMEMCPY(ocb->Ls[0], ocb->L, ocb->block_len);
    for (x = 1; x < 32; x++) {
        m = ocb->Ls[x-1][0] >> 7;
        for (y = 0; y < ocb->block_len-1; y++) {
@@ -104,7 +116,7 @@
     }
 
     /* set Li, checksum */
-    zeromem(ocb->Li, ocb->block_len);
+    zeromem(ocb->Li,       ocb->block_len);
     zeromem(ocb->checksum, ocb->block_len);
 
     /* set other params */
@@ -115,3 +127,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_init.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/ocb_ntz.c b/src/encauth/ocb/ocb_ntz.c
new file mode 100644
index 0000000..9b83c53
--- /dev/null
+++ b/src/encauth/ocb/ocb_ntz.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+   @file ocb_ntz.c
+   OCB implementation, internal function, by Tom St Denis
+*/
+
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/**
+   Returns the number of leading zero bits [from lsb up]
+   @param x  The 32-bit value to observe
+   @return   The number of bits [from the lsb up] that are zero
+*/
+int ocb_ntz(unsigned long x)
+{
+   int c;
+   x &= 0xFFFFFFFFUL;
+   c = 0;
+   while ((x & 1) == 0) {
+      ++c;
+      x >>= 1;
+   }
+   return c;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_ntz.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/ocb_shift_xor.c b/src/encauth/ocb/ocb_shift_xor.c
new file mode 100644
index 0000000..b03de4b
--- /dev/null
+++ b/src/encauth/ocb/ocb_shift_xor.c
@@ -0,0 +1,39 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+   @file ocb_shift_xor.c
+   OCB implementation, internal function, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/**
+   Compute the shift/xor for OCB (internal function)
+   @param ocb  The OCB state 
+   @param Z    The destination of the shift
+*/
+void ocb_shift_xor(ocb_state *ocb, unsigned char *Z)
+{
+   int x, y;
+   y = ocb_ntz(ocb->block_index++);
+   for (x = 0; x < ocb->block_len; x++) {
+       ocb->Li[x] ^= ocb->Ls[y][x];
+       Z[x]        = ocb->Li[x] ^ ocb->R[x];
+   }
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_shift_xor.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/ocb_test.c b/src/encauth/ocb/ocb_test.c
similarity index 94%
rename from ocb_test.c
rename to src/encauth/ocb/ocb_test.c
index 0b5dafd..7a7fc77 100644
--- a/ocb_test.c
+++ b/src/encauth/ocb/ocb_test.c
@@ -6,14 +6,21 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file ocb_test.c
+   OCB implementation, self-test by Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef OCB_MODE
 
+/** 
+  Test the OCB protocol
+  @return   CRYPT_OK if successful
+*/
 int ocb_test(void)
 {
 #ifndef LTC_TEST
@@ -224,3 +231,7 @@
    -- hard to stream [you can't emit ciphertext until full block]
    -- The setup is somewhat complicated...
 */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/ocb_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/encauth/ocb/s_ocb_done.c b/src/encauth/ocb/s_ocb_done.c
new file mode 100644
index 0000000..7399b54
--- /dev/null
+++ b/src/encauth/ocb/s_ocb_done.c
@@ -0,0 +1,144 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/** 
+   @file s_ocb_done.c
+   OCB implementation, internal helper, by Tom St Denis
+*/
+#include "tomcrypt.h"
+
+#ifdef OCB_MODE
+
+/* Since the last block is encrypted in CTR mode the same code can
+ * be used to finish a decrypt or encrypt stream.  The only difference
+ * is we XOR the final ciphertext into the checksum so we have to xor it
+ * before we CTR [decrypt] or after [encrypt]
+ *
+ * the names pt/ptlen/ct really just mean in/inlen/out but this is the way I wrote it... 
+ */
+
+/**
+   Shared code to finish an OCB stream
+   @param ocb    The OCB state
+   @param pt     The remaining plaintext [or input]
+   @param ptlen  The length of the input (octets)
+   @param ct     [out] The output buffer
+   @param tag    [out] The destination for the authentication tag
+   @param taglen [in/out] The max size and resulting size of the authentication tag
+   @param mode   The mode we are terminating, 0==encrypt, 1==decrypt
+   @return       CRYPT_OK if successful
+*/
+int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
+               unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode)
+
+{
+   unsigned char *Z, *Y, *X;
+   int err, x;
+
+   LTC_ARGCHK(ocb    != NULL);
+   LTC_ARGCHK(pt     != NULL);
+   LTC_ARGCHK(ct     != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
+   if ((err = cipher_is_valid(ocb->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   if (ocb->block_len != cipher_descriptor[ocb->cipher].block_length ||
+       (int)ptlen > ocb->block_len || (int)ptlen < 0) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* allocate ram */
+   Z = XMALLOC(MAXBLOCKSIZE);
+   Y = XMALLOC(MAXBLOCKSIZE);
+   X = XMALLOC(MAXBLOCKSIZE);
+   if (X == NULL || Y == NULL || Z == NULL) {
+      if (X != NULL) {
+         XFREE(X);
+      }
+      if (Y != NULL) {
+         XFREE(Y);
+      }
+      if (Z != NULL) {
+         XFREE(Z);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* compute X[m] = len(pt[m]) XOR Lr XOR Z[m] */
+   ocb_shift_xor(ocb, X); 
+   XMEMCPY(Z, X, ocb->block_len);
+
+   X[ocb->block_len-1] ^= (ptlen*8)&255;
+   X[ocb->block_len-2] ^= ((ptlen*8)>>8)&255;
+   for (x = 0; x < ocb->block_len; x++) {
+       X[x] ^= ocb->Lr[x]; 
+   }
+
+   /* Y[m] = E(X[m])) */
+   cipher_descriptor[ocb->cipher].ecb_encrypt(X, Y, &ocb->key);
+
+   if (mode == 1) {
+      /* decrypt mode, so let's xor it first */
+      /* xor C[m] into checksum */
+      for (x = 0; x < (int)ptlen; x++) {
+         ocb->checksum[x] ^= ct[x];
+      }  
+   }
+
+   /* C[m] = P[m] xor Y[m] */
+   for (x = 0; x < (int)ptlen; x++) {
+       ct[x] = pt[x] ^ Y[x];
+   }
+
+   if (mode == 0) {
+      /* encrypt mode */    
+      /* xor C[m] into checksum */
+      for (x = 0; x < (int)ptlen; x++) {
+          ocb->checksum[x] ^= ct[x];
+      }
+   }
+
+   /* xor Y[m] and Z[m] into checksum */
+   for (x = 0; x < ocb->block_len; x++) {
+       ocb->checksum[x] ^= Y[x] ^ Z[x];
+   }
+   
+   /* encrypt checksum, er... tag!! */
+   cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->checksum, X, &ocb->key);
+   cipher_descriptor[ocb->cipher].done(&ocb->key);
+
+   /* now store it */
+   for (x = 0; x < ocb->block_len && x < (int)*taglen; x++) {
+       tag[x] = X[x];
+   }
+   *taglen = x;
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(X, MAXBLOCKSIZE);
+   zeromem(Y, MAXBLOCKSIZE);
+   zeromem(Z, MAXBLOCKSIZE);
+   zeromem(ocb, sizeof(*ocb));
+#endif
+   
+   XFREE(X);
+   XFREE(Y);
+   XFREE(Z);
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/encauth/ocb/s_ocb_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/hashes/chc/chc.c b/src/hashes/chc/chc.c
new file mode 100644
index 0000000..4ff39f0
--- /dev/null
+++ b/src/hashes/chc/chc.c
@@ -0,0 +1,297 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+#include "tomcrypt.h"
+
+/**
+  @file chc.c
+  CHC support. (Tom St Denis)
+*/
+
+#ifdef CHC_HASH
+
+#define UNDEFED_HASH  -17
+
+/* chc settings */
+static int            cipher_idx=UNDEFED_HASH,        /* which cipher */
+                      cipher_blocksize;               /* blocksize of cipher */
+
+
+const struct ltc_hash_descriptor chc_desc = {
+   "chc_hash", 12, 0, 0, { 0 }, 0,
+   &chc_init,
+   &chc_process,
+   &chc_done,
+   &chc_test
+};
+
+/**
+  Initialize the CHC state with a given cipher 
+  @param cipher  The index of the cipher you wish to bind 
+  @return CRYPT_OK if successful
+*/
+int chc_register(int cipher)
+{
+   int err, kl, idx;
+
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* will it be valid? */
+   kl = cipher_descriptor[cipher].block_length;
+
+   /* must be >64 bit block */
+   if (kl <= 8) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   /* can we use the ideal keysize? */
+   if ((err = cipher_descriptor[cipher].keysize(&kl)) != CRYPT_OK) {
+      return err;
+   }
+   /* we require that key size == block size be a valid choice */
+   if (kl != cipher_descriptor[cipher].block_length) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   /* determine if chc_hash has been register_hash'ed already */
+   if ((err = hash_is_valid(idx = find_hash("chc_hash"))) != CRYPT_OK) {
+      return err;
+   }
+
+   /* store into descriptor */
+   hash_descriptor[idx].hashsize  = 
+   hash_descriptor[idx].blocksize = cipher_descriptor[cipher].block_length;
+
+   /* store the idx and block size */
+   cipher_idx       = cipher;
+   cipher_blocksize = cipher_descriptor[cipher].block_length;
+   return CRYPT_OK;
+}
+
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int chc_init(hash_state *md)
+{
+   symmetric_key *key;
+   unsigned char  buf[MAXBLOCKSIZE];
+   int            err;
+ 
+   LTC_ARGCHK(md != NULL);
+
+   /* is the cipher valid? */
+   if ((err = cipher_is_valid(cipher_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   if (cipher_blocksize != cipher_descriptor[cipher_idx].block_length) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   if ((key = XMALLOC(sizeof(*key))) == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* zero key and what not */   
+   zeromem(buf, cipher_blocksize);
+   if ((err = cipher_descriptor[cipher_idx].setup(buf, cipher_blocksize, 0, key)) != CRYPT_OK) {
+      XFREE(key);
+      return err;
+   }
+
+   /* encrypt zero block */
+   cipher_descriptor[cipher_idx].ecb_encrypt(buf, md->chc.state, key);
+
+   /* zero other members */
+   md->chc.length = 0;
+   md->chc.curlen = 0;
+   zeromem(md->chc.buf, sizeof(md->chc.buf));
+   XFREE(key);
+   return CRYPT_OK;
+}
+
+/* 
+   key    <= state
+   T0,T1  <= block
+   T0     <= encrypt T0
+   state  <= state xor T0 xor T1
+*/
+static int chc_compress(hash_state *md, unsigned char *buf)
+{
+   unsigned char  T[2][MAXBLOCKSIZE];
+   symmetric_key *key;
+   int            err, x;
+
+   if ((key = XMALLOC(sizeof(*key))) == NULL) {
+      return CRYPT_MEM;
+   }
+   if ((err = cipher_descriptor[cipher_idx].setup(md->chc.state, cipher_blocksize, 0, key)) != CRYPT_OK) {
+      XFREE(key);
+      return err;
+   }
+   memcpy(T[1], buf, cipher_blocksize);
+   cipher_descriptor[cipher_idx].ecb_encrypt(buf, T[0], key);
+   for (x = 0; x < cipher_blocksize; x++) {
+       md->chc.state[x] ^= T[0][x] ^ T[1][x];
+   }
+   XFREE(key);
+#ifdef LTC_CLEAN_STACK
+   zeromem(T, sizeof(T));
+   zeromem(&key, sizeof(key));
+#endif
+   return CRYPT_OK;
+}
+
+/* function for processing blocks */
+int _chc_process(hash_state * md, const unsigned char *buf, unsigned long len);
+HASH_PROCESS(_chc_process, chc_compress, chc, (unsigned long)cipher_blocksize)
+
+/**
+   Process a block of memory though the hash
+   @param md   The hash state
+   @param in   The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
+int chc_process(hash_state * md, const unsigned char *in, unsigned long inlen)
+{
+   int err;
+
+   LTC_ARGCHK(md   != NULL);
+   LTC_ARGCHK(in  != NULL);
+
+   /* is the cipher valid? */
+   if ((err = cipher_is_valid(cipher_idx)) != CRYPT_OK) {
+      return err;
+   }
+   if (cipher_blocksize != cipher_descriptor[cipher_idx].block_length) {
+      return CRYPT_INVALID_CIPHER;
+   }
+
+   return _chc_process(md, in, inlen);
+}
+
+/**
+   Terminate the hash to get the digest
+   @param md   The hash state
+   @param out [out] The destination of the hash (length of the block size of the block cipher)
+   @return CRYPT_OK if successful
+*/
+int chc_done(hash_state *md, unsigned char *out)
+{
+    int err;
+
+    LTC_ARGCHK(md   != NULL);
+    LTC_ARGCHK(out  != NULL);
+
+    /* is the cipher valid? */
+    if ((err = cipher_is_valid(cipher_idx)) != CRYPT_OK) {
+       return err;
+    }
+    if (cipher_blocksize != cipher_descriptor[cipher_idx].block_length) {
+       return CRYPT_INVALID_CIPHER;
+    }
+
+    if (md->chc.curlen >= sizeof(md->chc.buf)) {
+       return CRYPT_INVALID_ARG;
+    }
+
+    /* increase the length of the message */
+    md->chc.length += md->chc.curlen * 8;
+
+    /* append the '1' bit */
+    md->chc.buf[md->chc.curlen++] = (unsigned char)0x80;
+
+    /* if the length is currently above l-8 bytes we append zeros
+     * then compress.  Then we can fall back to padding zeros and length
+     * encoding like normal.
+     */
+    if (md->chc.curlen > (unsigned long)(cipher_blocksize - 8)) {
+        while (md->chc.curlen < (unsigned long)cipher_blocksize) {
+            md->chc.buf[md->chc.curlen++] = (unsigned char)0;
+        }
+        chc_compress(md, md->chc.buf);
+        md->chc.curlen = 0;
+    }
+
+    /* pad upto l-8 bytes of zeroes */
+    while (md->chc.curlen < (unsigned long)(cipher_blocksize - 8)) {
+        md->chc.buf[md->chc.curlen++] = (unsigned char)0;
+    }
+
+    /* store length */
+    STORE64L(md->chc.length, md->chc.buf+(cipher_blocksize-8));
+    chc_compress(md, md->chc.buf);
+
+    /* copy output */
+    XMEMCPY(out, md->chc.state, cipher_blocksize);
+
+#ifdef LTC_CLEAN_STACK
+    zeromem(md, sizeof(hash_state));
+#endif
+    return CRYPT_OK;
+}
+
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
+int chc_test(void)
+{
+   static const struct {
+      unsigned char *msg,
+                     md[MAXBLOCKSIZE];
+      int            len;
+   } tests[] = {
+{
+   (unsigned char *)"hello world",
+   { 0xcf, 0x57, 0x9d, 0xc3, 0x0a, 0x0e, 0xea, 0x61, 
+     0x0d, 0x54, 0x47, 0xc4, 0x3c, 0x06, 0xf5, 0x4e },
+   16
+}
+};
+   int x, oldhashidx, idx;
+   unsigned char out[MAXBLOCKSIZE];
+   hash_state md;
+
+   /* AES can be under rijndael or aes... try to find it */
+   if ((idx = find_cipher("aes")) == -1) {
+      if ((idx = find_cipher("rijndael")) == -1) {
+         return CRYPT_NOP;
+      }
+   }
+   oldhashidx = cipher_idx;
+   chc_register(idx);
+
+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+       chc_init(&md);
+       chc_process(&md, tests[x].msg, strlen((char *)tests[x].msg));
+       chc_done(&md, out);
+       if (memcmp(out, tests[x].md, tests[x].len)) {
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+   }
+   if (oldhashidx != UNDEFED_HASH) {
+      chc_register(oldhashidx);
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/chc/chc.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/hashes/helper/hash_file.c b/src/hashes/helper/hash_file.c
new file mode 100644
index 0000000..50f726a
--- /dev/null
+++ b/src/hashes/helper/hash_file.c
@@ -0,0 +1,57 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file hash_file.c
+  Hash a file, Tom St Denis
+*/
+
+/**
+  @param hash   The index of the hash desired
+  @param fname  The name of the file you wish to hash
+  @param out    [out] The destination of the digest
+  @param outlen [in/out] The max size and resulting size of the message digest
+  @result CRYPT_OK if successful
+*/
+int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *outlen)
+{
+#ifdef LTC_NO_FILE
+    return CRYPT_NOP;
+#else
+    FILE *in;
+    int err;
+    LTC_ARGCHK(fname  != NULL);
+    LTC_ARGCHK(out    != NULL);
+    LTC_ARGCHK(outlen != NULL);
+
+    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+        return err;
+    }
+
+    in = fopen(fname, "rb");
+    if (in == NULL) { 
+       return CRYPT_FILE_NOTFOUND;
+    }
+
+    err = hash_filehandle(hash, in, out, outlen);
+    if (fclose(in) != 0) {
+       return CRYPT_ERROR;
+    }
+
+    return err;
+#endif
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_file.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/hashes/helper/hash_filehandle.c b/src/hashes/helper/hash_filehandle.c
new file mode 100644
index 0000000..201ef83
--- /dev/null
+++ b/src/hashes/helper/hash_filehandle.c
@@ -0,0 +1,70 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file hash_filehandle.c
+   Hash open files, Tom St Denis
+*/
+
+/** 
+  Hash data from an open file handle.  
+  @param hash   The index of the hash you want to use
+  @param in     The FILE* handle of the file you want to hash
+  @param out    [out] The destination of the digest
+  @param outlen [in/out] The max size and resulting size of the digest
+  @result CRYPT_OK if successful   
+*/
+int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen)
+{
+#ifdef LTC_NO_FILE
+    return CRYPT_NOP;
+#else
+    hash_state md;
+    unsigned char buf[512];
+    size_t x;
+    int err;
+
+    LTC_ARGCHK(out    != NULL);
+    LTC_ARGCHK(outlen != NULL);
+    LTC_ARGCHK(in     != NULL);
+
+    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+        return err;
+    }
+
+    if (*outlen < hash_descriptor[hash].hashsize) {
+       return CRYPT_BUFFER_OVERFLOW;
+    }
+    if ((err = hash_descriptor[hash].init(&md)) != CRYPT_OK) {
+       return err;
+    }
+
+    *outlen = hash_descriptor[hash].hashsize;
+    do {
+        x = fread(buf, 1, sizeof(buf), in);
+        if ((err = hash_descriptor[hash].process(&md, buf, x)) != CRYPT_OK) {
+           return err;
+        }
+    } while (x == sizeof(buf));
+    err = hash_descriptor[hash].done(&md, out);
+
+#ifdef LTC_CLEAN_STACK
+    zeromem(buf, sizeof(buf));
+#endif
+    return err;
+#endif
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_filehandle.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/hashes/helper/hash_memory.c b/src/hashes/helper/hash_memory.c
new file mode 100644
index 0000000..7e849b4
--- /dev/null
+++ b/src/hashes/helper/hash_memory.c
@@ -0,0 +1,68 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file hash_memory.c
+  Hash memory helper, Tom St Denis
+*/
+
+/**
+  Hash a block of memory and store the digest.
+  @param hash   The index of the hash you wish to use
+  @param in     The data you wish to hash
+  @param inlen  The length of the data to hash (octets)
+  @param out    [out] Where to store the digest
+  @param outlen [in/out] Max size and resulting size of the digest
+  @return CRYPT_OK if successful
+*/
+int hash_memory(int hash, const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen)
+{
+    hash_state *md;
+    int err;
+
+    LTC_ARGCHK(in     != NULL);
+    LTC_ARGCHK(out    != NULL);
+    LTC_ARGCHK(outlen != NULL);
+
+    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+        return err;
+    }
+
+    if (*outlen < hash_descriptor[hash].hashsize) {
+       return CRYPT_BUFFER_OVERFLOW;
+    }
+
+    md = XMALLOC(sizeof(hash_state));
+    if (md == NULL) {
+       return CRYPT_MEM;
+    }
+
+    if ((err = hash_descriptor[hash].init(md)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    if ((err = hash_descriptor[hash].process(md, in, inlen)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    err = hash_descriptor[hash].done(md, out);
+    *outlen = hash_descriptor[hash].hashsize;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+    zeromem(md, sizeof(hash_state));
+#endif
+    XFREE(md);
+
+    return err;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/hashes/helper/hash_memory_multi.c b/src/hashes/helper/hash_memory_multi.c
new file mode 100644
index 0000000..8fcb8e9
--- /dev/null
+++ b/src/hashes/helper/hash_memory_multi.c
@@ -0,0 +1,86 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+/**
+  @file hash_memory_multi.c
+  Hash (multiple buffers) memory helper, Tom St Denis
+*/
+
+/**
+  Hash multiple (non-adjacent) blocks of memory at once.  
+  @param hash   The index of the hash you wish to use
+  @param out    [out] Where to store the digest
+  @param outlen [in/out] Max size and resulting size of the digest
+  @param in     The data you wish to hash
+  @param inlen  The length of the data to hash (octets)
+  @param ...    tuples of (data,len) pairs to hash, terminated with a (NULL,x) (x=don't care)
+  @return CRYPT_OK if successful
+*/  
+int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
+                      const unsigned char *in, unsigned long inlen, ...)
+{
+    hash_state          *md;
+    int                  err;
+    va_list              args;
+    const unsigned char *curptr;
+    unsigned long        curlen;
+
+    LTC_ARGCHK(in     != NULL);
+    LTC_ARGCHK(out    != NULL);
+    LTC_ARGCHK(outlen != NULL);
+
+    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+        return err;
+    }
+
+    if (*outlen < hash_descriptor[hash].hashsize) {
+       return CRYPT_BUFFER_OVERFLOW;
+    }
+
+    md = XMALLOC(sizeof(hash_state));
+    if (md == NULL) {
+       return CRYPT_MEM;
+    }
+
+    if ((err = hash_descriptor[hash].init(md)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    va_start(args, inlen);
+    curptr = in; 
+    curlen = inlen;
+    for (;;) {
+       /* process buf */
+       if ((err = hash_descriptor[hash].process(md, curptr, curlen)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       /* step to next */
+       curptr = va_arg(args, const unsigned char*);
+       if (curptr == NULL) {
+          break;
+       }
+       curlen = va_arg(args, unsigned long);
+    }
+    err = hash_descriptor[hash].done(md, out);
+    *outlen = hash_descriptor[hash].hashsize;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+    zeromem(md, sizeof(hash_state));
+#endif
+    XFREE(md);
+    va_end(args);
+    return err;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/helper/hash_memory_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/md2.c b/src/hashes/md2.c
similarity index 76%
rename from md2.c
rename to src/hashes/md2.c
index e60b995..db60fbd 100644
--- a/md2.c
+++ b/src/hashes/md2.c
@@ -6,25 +6,27 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* MD2 (RFC 1319) hash function implementation by Tom St Denis */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+   @param md2.c
+   MD2 (RFC 1319) hash function implementation by Tom St Denis 
+*/
 
 #ifdef MD2
 
-const struct _hash_descriptor md2_desc =
+const struct ltc_hash_descriptor md2_desc =
 {
     "md2",
     7,
     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,
@@ -90,31 +92,44 @@
    }
 }
 
-void md2_init(hash_state *md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int md2_init(hash_state *md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
 
    /* MD2 uses a zero'ed state... */
    zeromem(md->md2.X, sizeof(md->md2.X));
    zeromem(md->md2.chksum, sizeof(md->md2.chksum));
    zeromem(md->md2.buf, sizeof(md->md2.buf));
    md->md2.curlen = 0;
+   return CRYPT_OK;
 }
 
-int md2_process(hash_state *md, const unsigned char *buf, unsigned long len)
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
+int md2_process(hash_state *md, const unsigned char *in, unsigned long inlen)
 {
     unsigned long n;
-    _ARGCHK(md != NULL);
-    _ARGCHK(buf != NULL);
+    LTC_ARGCHK(md != NULL);
+    LTC_ARGCHK(in != NULL);
     if (md-> md2 .curlen > sizeof(md-> md2 .buf)) {                            
        return CRYPT_INVALID_ARG;                                                           
     }                                                                                       
-    while (len > 0) {
-        n = MIN(len, (16 - md->md2.curlen));
-        memcpy(md->md2.buf + md->md2.curlen, buf, (size_t)n);
+    while (inlen > 0) {
+        n = MIN(inlen, (16 - md->md2.curlen));
+        XMEMCPY(md->md2.buf + md->md2.curlen, in, (size_t)n);
         md->md2.curlen += n;
-        buf            += n;
-        len            -= n;
+        in             += n;
+        inlen          -= n;
 
         /* is 16 bytes full? */
         if (md->md2.curlen == 16) {
@@ -126,12 +141,18 @@
     return CRYPT_OK;
 }
 
-int md2_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (16 bytes)
+   @return CRYPT_OK if successful
+*/
+int md2_done(hash_state * md, unsigned char *out)
 {
     unsigned long i, k;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->md2.curlen >= sizeof(md->md2.buf)) {
        return CRYPT_INVALID_ARG;
@@ -149,18 +170,22 @@
     md2_update_chksum(md);
 
     /* hash checksum */
-    memcpy(md->md2.buf, md->md2.chksum, 16);
+    XMEMCPY(md->md2.buf, md->md2.chksum, 16);
     md2_compress(md);
 
     /* output is lower 16 bytes of X */
-    memcpy(hash, md->md2.X, 16);
+    XMEMCPY(out, md->md2.X, 16);
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int md2_test(void)
 {
  #ifndef LTC_TEST
@@ -219,3 +244,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/md2.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/md4.c b/src/hashes/md4.c
similarity index 81%
rename from md4.c
rename to src/hashes/md4.c
index 5c2ea11..17ef35e 100644
--- a/md4.c
+++ b/src/hashes/md4.c
@@ -6,23 +6,27 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* Submitted by Dobes Vandermeer  (dobes@smartt.com) */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+   @param md4.c
+   Submitted by Dobes Vandermeer  (dobes@smartt.com) 
+*/
 
 #ifdef MD4
 
-const struct _hash_descriptor md4_desc =
+const struct ltc_hash_descriptor md4_desc =
 {
     "md4",
     6,
     16,
     64,
  
-    /* DER encoding (not yet supported) */
-    { 0x00 },
-    0,    
+    /* OID */
+   { 1, 2, 840, 113549, 2, 4,  },
+   6,
 
     &md4_init,
     &md4_process,
@@ -49,7 +53,7 @@
 #define H(x, y, z) ((x) ^ (y) ^ (z))
 
 /* ROTATE_LEFT rotates x left n bits. */
-#define ROTATE_LEFT(x, n) ROL(x, n)
+#define ROTATE_LEFT(x, n) ROLc(x, n)
 
 /* FF, GG and HH are transformations for rounds 1, 2 and 3 */ 
 /* Rotation is separate from addition to prevent recomputation */ 
@@ -67,10 +71,10 @@
     (a) = ROTATE_LEFT ((a), (s)); \
   }
 
-#ifdef CLEAN_STACK
-static void _md4_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _md4_compress(hash_state *md, unsigned char *buf)
 #else
-static void md4_compress(hash_state *md, unsigned char *buf)
+static int  md4_compress(hash_state *md, unsigned char *buf)
 #endif
 {
     ulong32 x[16], a, b, c, d;
@@ -147,35 +151,58 @@
     md->md4.state[1] = md->md4.state[1] + b;
     md->md4.state[2] = md->md4.state[2] + c;
     md->md4.state[3] = md->md4.state[3] + d;
+
+    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void md4_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int md4_compress(hash_state *md, unsigned char *buf)
 {
-   _md4_compress(md, buf);
+   int err;
+   err = _md4_compress(md, buf);
    burn_stack(sizeof(ulong32) * 20 + sizeof(int));
+   return err;
 }
 #endif
 
-void md4_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int md4_init(hash_state * md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
    md->md4.state[0] = 0x67452301UL;
    md->md4.state[1] = 0xefcdab89UL;
    md->md4.state[2] = 0x98badcfeUL;
    md->md4.state[3] = 0x10325476UL;
    md->md4.length  = 0;
    md->md4.curlen  = 0;
+   return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(md4_process, md4_compress, md4, 64)
 
-int md4_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (16 bytes)
+   @return CRYPT_OK if successful
+*/
+int md4_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->md4.curlen >= sizeof(md->md4.buf)) {
        return CRYPT_INVALID_ARG;
@@ -210,14 +237,18 @@
 
     /* copy output */
     for (i = 0; i < 4; i++) {
-        STORE32L(md->md4.state[i], hash+(4*i));
+        STORE32L(md->md4.state[i], out+(4*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif 
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int md4_test(void)
 {
  #ifndef LTC_TEST
@@ -269,3 +300,7 @@
 #endif
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/md4.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/md5.c b/src/hashes/md5.c
similarity index 81%
rename from md5.c
rename to src/hashes/md5.c
index 8f6e1ea..fb8ff31 100644
--- a/md5.c
+++ b/src/hashes/md5.c
@@ -6,27 +6,28 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* MD5 hash function by Tom St Denis */
 
-#include "mycrypt.h"
+/**
+  @file md5.c
+  MD5 hash function by Tom St Denis 
+*/
 
 #ifdef MD5
 
-const struct _hash_descriptor md5_desc =
+const struct ltc_hash_descriptor md5_desc =
 {
     "md5",
     3,
     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,
@@ -39,6 +40,8 @@
 #define H(x,y,z)  (x^y^z)
 #define I(x,y,z)  (y^(x|(~z)))
 
+#ifdef LTC_SMALL_CODE
+
 #define FF(a,b,c,d,M,s,t) \
     a = (a + F(b,c,d) + M + t); a = ROL(a, s) + b;
 
@@ -51,8 +54,6 @@
 #define II(a,b,c,d,M,s,t) \
     a = (a + I(b,c,d) + M + t); a = ROL(a, s) + b;
 
-#ifdef SMALL_CODE
-
 static const unsigned char Worder[64] = {
    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
    1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,
@@ -78,16 +79,31 @@
 0x6fa87e4fUL, 0xfe2ce6e0UL, 0xa3014314UL, 0x4e0811a1UL, 0xf7537e82UL, 0xbd3af235UL, 0x2ad7d2bbUL, 0xeb86d391UL
 };
 
+#else
+
+#define FF(a,b,c,d,M,s,t) \
+    a = (a + F(b,c,d) + M + t); a = ROLc(a, s) + b;
+
+#define GG(a,b,c,d,M,s,t) \
+    a = (a + G(b,c,d) + M + t); a = ROLc(a, s) + b;
+
+#define HH(a,b,c,d,M,s,t) \
+    a = (a + H(b,c,d) + M + t); a = ROLc(a, s) + b;
+
+#define II(a,b,c,d,M,s,t) \
+    a = (a + I(b,c,d) + M + t); a = ROLc(a, s) + b;
+
+
 #endif   
 
-#ifdef CLEAN_STACK
-static void _md5_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _md5_compress(hash_state *md, unsigned char *buf)
 #else
-static void md5_compress(hash_state *md, unsigned char *buf)
+static int  md5_compress(hash_state *md, unsigned char *buf)
 #endif
 {
     ulong32 i, W[16], a, b, c, d;
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     ulong32 t;
 #endif
 
@@ -102,7 +118,7 @@
     c = md->md5.state[2];
     d = md->md5.state[3];
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     for (i = 0; i < 16; ++i) {
         FF(a,b,c,d,W[Worder[i]],Rorder[i],Korder[i]);
         t = d; d = c; c = b; b = a; a = t;
@@ -194,35 +210,58 @@
     md->md5.state[1] = md->md5.state[1] + b;
     md->md5.state[2] = md->md5.state[2] + c;
     md->md5.state[3] = md->md5.state[3] + d;
+
+    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void md5_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int md5_compress(hash_state *md, unsigned char *buf)
 {
-   _md5_compress(md, buf);
+   int err;
+   err = _md5_compress(md, buf);
    burn_stack(sizeof(ulong32) * 21);
+   return err;
 }
 #endif
 
-void md5_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int md5_init(hash_state * md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
    md->md5.state[0] = 0x67452301UL;
    md->md5.state[1] = 0xefcdab89UL;
    md->md5.state[2] = 0x98badcfeUL;
    md->md5.state[3] = 0x10325476UL;
    md->md5.curlen = 0;
    md->md5.length = 0;
+   return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(md5_process, md5_compress, md5, 64)
 
-int md5_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (16 bytes)
+   @return CRYPT_OK if successful
+*/
+int md5_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->md5.curlen >= sizeof(md->md5.buf)) {
        return CRYPT_INVALID_ARG;
@@ -258,14 +297,18 @@
 
     /* copy output */
     for (i = 0; i < 4; i++) {
-        STORE32L(md->md5.state[i], hash+(4*i));
+        STORE32L(md->md5.state[i], out+(4*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  md5_test(void)
 {
  #ifndef LTC_TEST
@@ -318,3 +361,7 @@
 #endif
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/md5.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/rmd128.c b/src/hashes/rmd128.c
similarity index 84%
rename from rmd128.c
rename to src/hashes/rmd128.c
index 13a3135..1c663e4 100644
--- a/rmd128.c
+++ b/src/hashes/rmd128.c
@@ -6,28 +6,33 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
+
+/**
+   @param rmd128.c
+   RMD128 Hash function
+*/   
 
 /* Implementation of RIPEMD-128 based on the source by Antoon Bosselaers, ESAT-COSIC
  *
  * This source has been radically overhauled to be portable and work within
  * the LibTomCrypt API by Tom St Denis
  */
-#include "mycrypt.h"
 
 #ifdef RIPEMD128
 
-const struct _hash_descriptor rmd128_desc =
+const struct ltc_hash_descriptor rmd128_desc =
 {
     "rmd128",
     8,
     16,
     64,
 
-    /* DER identifier (not supported) */
-    { 0x00 },
-    0,
+    /* OID */
+   { 1, 0, 10118, 3, 0, 50 },
+   6,
 
     &rmd128_init,
     &rmd128_process,
@@ -44,40 +49,40 @@
 /* the eight basic operations FF() through III() */
 #define FF(a, b, c, d, x, s)        \
       (a) += F((b), (c), (d)) + (x);\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define GG(a, b, c, d, x, s)        \
       (a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define HH(a, b, c, d, x, s)        \
       (a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define II(a, b, c, d, x, s)        \
       (a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define FFF(a, b, c, d, x, s)        \
       (a) += F((b), (c), (d)) + (x);\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define GGG(a, b, c, d, x, s)        \
       (a) += G((b), (c), (d)) + (x) + 0x6d703ef3UL;\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define HHH(a, b, c, d, x, s)        \
       (a) += H((b), (c), (d)) + (x) + 0x5c4dd124UL;\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
 #define III(a, b, c, d, x, s)        \
       (a) += I((b), (c), (d)) + (x) + 0x50a28be6UL;\
-      (a) = ROL((a), (s));
+      (a) = ROLc((a), (s));
 
-#ifdef CLEAN_STACK
-static void _rmd128_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _rmd128_compress(hash_state *md, unsigned char *buf)
 #else
-static void rmd128_compress(hash_state *md, unsigned char *buf)
+static int  rmd128_compress(hash_state *md, unsigned char *buf)
 #endif
 {
    ulong32 aa,bb,cc,dd,aaa,bbb,ccc,ddd,X[16];
@@ -244,35 +249,58 @@
    md->rmd128.state[2] = md->rmd128.state[3] + aa + bbb;
    md->rmd128.state[3] = md->rmd128.state[0] + bb + ccc;
    md->rmd128.state[0] = ddd;
+
+   return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void rmd128_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int rmd128_compress(hash_state *md, unsigned char *buf)
 {
-   _rmd128_compress(md, buf);
+   int err;
+   err = _rmd128_compress(md, buf);
    burn_stack(sizeof(ulong32) * 24 + sizeof(int));
+   return err;
 }
 #endif
 
-void rmd128_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int rmd128_init(hash_state * md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
    md->rmd128.state[0] = 0x67452301UL;
    md->rmd128.state[1] = 0xefcdab89UL;
    md->rmd128.state[2] = 0x98badcfeUL;
    md->rmd128.state[3] = 0x10325476UL;
    md->rmd128.curlen   = 0;
    md->rmd128.length   = 0;
+   return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(rmd128_process, rmd128_compress, rmd128, 64)
 
-int rmd128_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (16 bytes)
+   @return CRYPT_OK if successful
+*/
+int rmd128_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->rmd128.curlen >= sizeof(md->rmd128.buf)) {
        return CRYPT_INVALID_ARG;
@@ -308,14 +336,18 @@
 
     /* copy output */
     for (i = 0; i < 4; i++) {
-        STORE32L(md->rmd128.state[i], hash+(4*i));
+        STORE32L(md->rmd128.state[i], out+(4*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
    return CRYPT_OK;  
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int rmd128_test(void)
 {
 #ifndef LTC_TEST
@@ -371,3 +403,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/rmd128.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/rmd160.c b/src/hashes/rmd160.c
similarity index 84%
rename from rmd160.c
rename to src/hashes/rmd160.c
index 6b49076..6124f59 100644
--- a/rmd160.c
+++ b/src/hashes/rmd160.c
@@ -6,29 +6,33 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
+
+/**
+   @file rmd160.c
+   RMD160 hash function
+*/   
 
 /* Implementation of RIPEMD-160 based on the source by Antoon Bosselaers, ESAT-COSIC
  *
  * This source has been radically overhauled to be portable and work within
  * the LibTomCrypt API by Tom St Denis
  */
-#include "mycrypt.h"
 
 #ifdef RIPEMD160
 
-const struct _hash_descriptor rmd160_desc =
+const struct ltc_hash_descriptor rmd160_desc =
 {
     "rmd160",
     9,
     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,
@@ -46,59 +50,59 @@
 /* the ten basic operations FF() through III() */
 #define FF(a, b, c, d, e, x, s)        \
       (a) += F((b), (c), (d)) + (x);\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define GG(a, b, c, d, e, x, s)        \
       (a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define HH(a, b, c, d, e, x, s)        \
       (a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define II(a, b, c, d, e, x, s)        \
       (a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define JJ(a, b, c, d, e, x, s)        \
       (a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define FFF(a, b, c, d, e, x, s)        \
       (a) += F((b), (c), (d)) + (x);\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define GGG(a, b, c, d, e, x, s)        \
       (a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define HHH(a, b, c, d, e, x, s)        \
       (a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define III(a, b, c, d, e, x, s)        \
       (a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 #define JJJ(a, b, c, d, e, x, s)        \
       (a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\
-      (a) = ROL((a), (s)) + (e);\
-      (c) = ROL((c), 10);
+      (a) = ROLc((a), (s)) + (e);\
+      (c) = ROLc((c), 10);
 
 
-#ifdef CLEAN_STACK
-static void _rmd160_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _rmd160_compress(hash_state *md, unsigned char *buf)
 #else
-static void rmd160_compress(hash_state *md, unsigned char *buf)
+static int  rmd160_compress(hash_state *md, unsigned char *buf)
 #endif
 {
    ulong32 aa,bb,cc,dd,ee,aaa,bbb,ccc,ddd,eee,X[16];
@@ -303,19 +307,28 @@
    md->rmd160.state[3] = md->rmd160.state[4] + aa + bbb;
    md->rmd160.state[4] = md->rmd160.state[0] + bb + ccc;
    md->rmd160.state[0] = ddd;
+
+   return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void rmd160_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int rmd160_compress(hash_state *md, unsigned char *buf)
 {
-   _rmd160_compress(md, buf);
+   int err;
+   err = _rmd160_compress(md, buf);
    burn_stack(sizeof(ulong32) * 26 + sizeof(int));
+   return err;
 }
 #endif
 
-void rmd160_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int rmd160_init(hash_state * md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
    md->rmd160.state[0] = 0x67452301UL;
    md->rmd160.state[1] = 0xefcdab89UL;
    md->rmd160.state[2] = 0x98badcfeUL;
@@ -323,16 +336,30 @@
    md->rmd160.state[4] = 0xc3d2e1f0UL;
    md->rmd160.curlen   = 0;
    md->rmd160.length   = 0;
+   return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(rmd160_process, rmd160_compress, rmd160, 64)
 
-int rmd160_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (20 bytes)
+   @return CRYPT_OK if successful
+*/
+int rmd160_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->rmd160.curlen >= sizeof(md->rmd160.buf)) {
        return CRYPT_INVALID_ARG;
@@ -368,14 +395,18 @@
 
     /* copy output */
     for (i = 0; i < 5; i++) {
-        STORE32L(md->rmd160.state[i], hash+(4*i));
+        STORE32L(md->rmd160.state[i], out+(4*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int rmd160_test(void)
 {
 #ifndef LTC_TEST
@@ -431,3 +462,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/rmd160.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/sha1.c b/src/hashes/sha1.c
similarity index 70%
rename from sha1.c
rename to src/hashes/sha1.c
index 77700f6..a75d04d 100644
--- a/sha1.c
+++ b/src/hashes/sha1.c
@@ -6,25 +6,28 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* SHA1 code by Tom St Denis */
-#include "mycrypt.h"
+/**
+  @file sha1.c
+  SHA1 code by Tom St Denis 
+*/
+
 
 #ifdef SHA1
 
-const struct _hash_descriptor sha1_desc =
+const struct ltc_hash_descriptor sha1_desc =
 {
     "sha1",
     2,
     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,
@@ -37,14 +40,14 @@
 #define F2(x,y,z)  ((x & y) | (z & (x | y)))
 #define F3(x,y,z)  (x ^ y ^ z)
 
-#ifdef CLEAN_STACK
-static void _sha1_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _sha1_compress(hash_state *md, unsigned char *buf)
 #else
-static void sha1_compress(hash_state *md, unsigned char *buf)
+static int  sha1_compress(hash_state *md, unsigned char *buf)
 #endif
 {
     ulong32 a,b,c,d,e,W[80],i;
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     ulong32 t;
 #endif
 
@@ -67,12 +70,12 @@
 
     /* compress */
     /* round one */
-    #define FF0(a,b,c,d,e,i) e = (ROL(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROL(b, 30);
-    #define FF1(a,b,c,d,e,i) e = (ROL(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROL(b, 30);
-    #define FF2(a,b,c,d,e,i) e = (ROL(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROL(b, 30);
-    #define FF3(a,b,c,d,e,i) e = (ROL(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROL(b, 30);
+    #define FF0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
+    #define FF1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
+    #define FF2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
+    #define FF3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
  
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
  
     for (i = 0; i < 20; ) {
        FF0(a,b,c,d,e,i++); t = e; e = d; d = c; c = b; b = a; a = t;
@@ -139,19 +142,28 @@
     md->sha1.state[2] = md->sha1.state[2] + c;
     md->sha1.state[3] = md->sha1.state[3] + d;
     md->sha1.state[4] = md->sha1.state[4] + e;
+
+    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void sha1_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int sha1_compress(hash_state *md, unsigned char *buf)
 {
-   _sha1_compress(md, buf);
+   int err;
+   err = _sha1_compress(md, buf);
    burn_stack(sizeof(ulong32) * 87);
+   return err;
 }
 #endif
 
-void sha1_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int sha1_init(hash_state * md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
    md->sha1.state[0] = 0x67452301UL;
    md->sha1.state[1] = 0xefcdab89UL;
    md->sha1.state[2] = 0x98badcfeUL;
@@ -159,16 +171,30 @@
    md->sha1.state[4] = 0xc3d2e1f0UL;
    md->sha1.curlen = 0;
    md->sha1.length = 0;
+   return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(sha1_process, sha1_compress, sha1, 64)
 
-int sha1_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (20 bytes)
+   @return CRYPT_OK if successful
+*/
+int sha1_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->sha1.curlen >= sizeof(md->sha1.buf)) {
        return CRYPT_INVALID_ARG;
@@ -203,14 +229,18 @@
 
     /* copy output */
     for (i = 0; i < 5; i++) {
-        STORE32H(md->sha1.state[i], hash+(4*i));
+        STORE32H(md->sha1.state[i], out+(4*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  sha1_test(void)
 {
  #ifndef LTC_TEST
@@ -251,3 +281,7 @@
 #endif
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha1.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/sha224.c b/src/hashes/sha2/sha224.c
similarity index 65%
rename from sha224.c
rename to src/hashes/sha2/sha224.c
index d013551..bff2fdf 100644
--- a/sha224.c
+++ b/src/hashes/sha2/sha224.c
@@ -6,20 +6,23 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+/**
+   @param sha224.c
+   SHA-224 new NIST standard based off of SHA-256 truncated to 224 bits (Tom St Denis)
+*/
 
-/* SHA-224 new NIST standard based off of SHA-256 truncated to 224 bits */
-const struct _hash_descriptor sha224_desc =
+const struct ltc_hash_descriptor sha224_desc =
 {
     "sha224",
     10,
     28,
     64,
 
-    /* DER identifier (not supported) */
-    { 0x00 },
-    0,
+    /* OID */
+   { 2, 16, 840, 1, 101, 3, 4, 2, 4,  },
+   9,
 
     &sha224_init,
     &sha256_process,
@@ -28,9 +31,14 @@
 };
 
 /* init the sha256 er... sha224 state ;-) */
-void sha224_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int sha224_init(hash_state * md)
 {
-    _ARGCHK(md != NULL);
+    LTC_ARGCHK(md != NULL);
 
     md->sha256.curlen = 0;
     md->sha256.length = 0;
@@ -42,21 +50,35 @@
     md->sha256.state[5] = 0x68581511UL;
     md->sha256.state[6] = 0x64f98fa7UL;
     md->sha256.state[7] = 0xbefa4fa4UL;
+    return CRYPT_OK;
 }
 
-int sha224_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (28 bytes)
+   @return CRYPT_OK if successful
+*/
+int sha224_done(hash_state * md, unsigned char *out)
 {
     unsigned char buf[32];
     int err;
 
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
+
     err = sha256_done(md, buf);
-    memcpy(hash, buf, 28);
-#ifdef CLEAN_STACK
+    XMEMCPY(out, buf, 28);
+#ifdef LTC_CLEAN_STACK
     zeromem(buf, sizeof(buf));
 #endif 
     return err;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  sha224_test(void)
 {
  #ifndef LTC_TEST
@@ -96,3 +118,7 @@
  #endif
 }
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha224.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/sha256.c b/src/hashes/sha2/sha256.c
similarity index 85%
rename from sha256.c
rename to src/hashes/sha2/sha256.c
index ef2ae5e..c48c0f6 100644
--- a/sha256.c
+++ b/src/hashes/sha2/sha256.c
@@ -6,28 +6,27 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-
-/* SHA256 by Tom St Denis */
-
-#include "mycrypt.h"
+/**
+  @file sha256.c
+  SHA256 by Tom St Denis 
+*/
 
 #ifdef SHA256 
 
-const struct _hash_descriptor sha256_desc =
+const struct ltc_hash_descriptor sha256_desc =
 {
     "sha256",
     0,
     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,
@@ -35,7 +34,7 @@
     &sha256_test
 };
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
 /* the K array */
 static const unsigned long K[64] = {
     0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
@@ -57,7 +56,7 @@
 /* Various logical functions */
 #define Ch(x,y,z)       (z ^ (x & (y ^ z)))
 #define Maj(x,y,z)      (((x | y) & z) | (x & y)) 
-#define S(x, n)         ROR((x),(n))
+#define S(x, n)         RORc((x),(n))
 #define R(x, n)         (((x)&0xFFFFFFFFUL)>>(n))
 #define Sigma0(x)       (S(x, 2) ^ S(x, 13) ^ S(x, 22))
 #define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
@@ -65,14 +64,14 @@
 #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
 
 /* compress 512-bits */
-#ifdef CLEAN_STACK
-static void _sha256_compress(hash_state * md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _sha256_compress(hash_state * md, unsigned char *buf)
 #else
-static void sha256_compress(hash_state * md, unsigned char *buf)
+static int  sha256_compress(hash_state * md, unsigned char *buf)
 #endif
 {
     ulong32 S[8], W[64], t0, t1;
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     ulong32 t;
 #endif
     int i;
@@ -93,7 +92,7 @@
     }        
 
     /* Compress */
-#ifdef SMALL_CODE   
+#ifdef LTC_SMALL_CODE   
 #define RND(a,b,c,d,e,f,g,h,i)                         \
      t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];   \
      t1 = Sigma0(a) + Maj(a, b, c);                    \
@@ -104,7 +103,7 @@
          RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],i);
          t = S[7]; S[7] = S[6]; S[6] = S[5]; S[5] = S[4]; 
          S[4] = S[3]; S[3] = S[2]; S[2] = S[1]; S[1] = S[0]; S[0] = t;
-	  }  
+     }  
 #else 
 #define RND(a,b,c,d,e,f,g,h,i,ki)                    \
      t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i];   \
@@ -185,21 +184,27 @@
     for (i = 0; i < 8; i++) {
         md->sha256.state[i] = md->sha256.state[i] + S[i];
     }
-
+    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void sha256_compress(hash_state * md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int sha256_compress(hash_state * md, unsigned char *buf)
 {
-    _sha256_compress(md, buf);
+    int err;
+    err = _sha256_compress(md, buf);
     burn_stack(sizeof(ulong32) * 74);
+    return err;
 }
 #endif
 
-/* init the sha256 state */
-void sha256_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int sha256_init(hash_state * md)
 {
-    _ARGCHK(md != NULL);
+    LTC_ARGCHK(md != NULL);
 
     md->sha256.curlen = 0;
     md->sha256.length = 0;
@@ -211,16 +216,30 @@
     md->sha256.state[5] = 0x9B05688CUL;
     md->sha256.state[6] = 0x1F83D9ABUL;
     md->sha256.state[7] = 0x5BE0CD19UL;
+    return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(sha256_process, sha256_compress, sha256, 64)
 
-int sha256_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (32 bytes)
+   @return CRYPT_OK if successful
+*/
+int sha256_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->sha256.curlen >= sizeof(md->sha256.buf)) {
        return CRYPT_INVALID_ARG;
@@ -256,14 +275,18 @@
 
     /* copy output */
     for (i = 0; i < 8; i++) {
-        STORE32H(md->sha256.state[i], hash+(4*i));
+        STORE32H(md->sha256.state[i], out+(4*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  sha256_test(void)
 {
  #ifndef LTC_TEST
@@ -310,3 +333,7 @@
 #endif
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha256.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/sha384.c b/src/hashes/sha2/sha384.c
similarity index 70%
rename from sha384.c
rename to src/hashes/sha2/sha384.c
index 120289a..43f8fb6 100644
--- a/sha384.c
+++ b/src/hashes/sha2/sha384.c
@@ -6,23 +6,23 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+/** 
+   @param sha384.c
+   SHA384 hash included in sha512.c, Tom St Denis
+*/
 
-/* included in sha512.c */
-
-const struct _hash_descriptor sha384_desc =
+const struct ltc_hash_descriptor sha384_desc =
 {
     "sha384",
     4,
     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,
@@ -30,9 +30,14 @@
     &sha384_test
 };
 
-void sha384_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int sha384_init(hash_state * md)
 {
-    _ARGCHK(md != NULL);
+    LTC_ARGCHK(md != NULL);
 
     md->sha512.curlen = 0;
     md->sha512.length = 0;
@@ -44,27 +49,38 @@
     md->sha512.state[5] = CONST64(0x8eb44a8768581511);
     md->sha512.state[6] = CONST64(0xdb0c2e0d64f98fa7);
     md->sha512.state[7] = CONST64(0x47b5481dbefa4fa4);
+    return CRYPT_OK;
 }
 
-int sha384_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (48 bytes)
+   @return CRYPT_OK if successful
+*/
+int sha384_done(hash_state * md, unsigned char *out)
 {
    unsigned char buf[64];
 
-   _ARGCHK(md != NULL);
-   _ARGCHK(hash != NULL);
+   LTC_ARGCHK(md  != NULL);
+   LTC_ARGCHK(out != NULL);
 
     if (md->sha512.curlen >= sizeof(md->sha512.buf)) {
        return CRYPT_INVALID_ARG;
     }
 
    sha512_done(md, buf);
-   memcpy(hash, buf, 48);
-#ifdef CLEAN_STACK
+   XMEMCPY(out, buf, 48);
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, sizeof(buf));
 #endif
    return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  sha384_test(void)
 {
  #ifndef LTC_TEST
@@ -112,3 +128,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha384.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/sha512.c b/src/hashes/sha2/sha512.c
similarity index 83%
rename from sha512.c
rename to src/hashes/sha2/sha512.c
index 9b5ddad..7b6805b 100644
--- a/sha512.c
+++ b/src/hashes/sha2/sha512.c
@@ -6,27 +6,27 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* SHA512 by Tom St Denis */
-
-#include "mycrypt.h"
+/**
+   @param sha512.c
+   SHA512 by Tom St Denis 
+*/
 
 #ifdef SHA512
 
-const struct _hash_descriptor sha512_desc =
+const struct ltc_hash_descriptor sha512_desc =
 {
     "sha512",
     5,
     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,
@@ -81,7 +81,7 @@
 /* Various logical functions */
 #define Ch(x,y,z)       (z ^ (x & (y ^ z)))
 #define Maj(x,y,z)      (((x | y) & z) | (x & y)) 
-#define S(x, n)         ROR64((x),(n))
+#define S(x, n)         ROR64c(x, n)
 #define R(x, n)         (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)n))
 #define Sigma0(x)       (S(x, 28) ^ S(x, 34) ^ S(x, 39))
 #define Sigma1(x)       (S(x, 14) ^ S(x, 18) ^ S(x, 41))
@@ -89,10 +89,10 @@
 #define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
 
 /* compress 1024-bits */
-#ifdef CLEAN_STACK
-static void _sha512_compress(hash_state * md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _sha512_compress(hash_state * md, unsigned char *buf)
 #else
-static void sha512_compress(hash_state * md, unsigned char *buf)
+static int  sha512_compress(hash_state * md, unsigned char *buf)
 #endif
 {
     ulong64 S[8], W[80], t0, t1;
@@ -114,7 +114,7 @@
     }        
 
     /* Compress */
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
     for (i = 0; i < 80; i++) {
         t0 = S[7] + Sigma1(S[4]) + Ch(S[4], S[5], S[6]) + K[i] + W[i];
         t1 = Sigma0(S[0]) + Maj(S[0], S[1], S[2]);
@@ -151,22 +151,29 @@
     for (i = 0; i < 8; i++) {
         md->sha512.state[i] = md->sha512.state[i] + S[i];
     }
+
+    return CRYPT_OK;
 }
 
 /* compress 1024-bits */
-#ifdef CLEAN_STACK
-static void sha512_compress(hash_state * md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int sha512_compress(hash_state * md, unsigned char *buf)
 {
-    _sha512_compress(md, buf);
+    int err;
+    err = _sha512_compress(md, buf);
     burn_stack(sizeof(ulong64) * 90 + sizeof(int));
+    return err;
 }
 #endif
 
-/* init the sha512 state */
-void sha512_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int sha512_init(hash_state * md)
 {
-    _ARGCHK(md != NULL);
-
+    LTC_ARGCHK(md != NULL);
     md->sha512.curlen = 0;
     md->sha512.length = 0;
     md->sha512.state[0] = CONST64(0x6a09e667f3bcc908);
@@ -177,16 +184,30 @@
     md->sha512.state[5] = CONST64(0x9b05688c2b3e6c1f);
     md->sha512.state[6] = CONST64(0x1f83d9abfb41bd6b);
     md->sha512.state[7] = CONST64(0x5be0cd19137e2179);
+    return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(sha512_process, sha512_compress, sha512, 128)
 
-int sha512_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (64 bytes)
+   @return CRYPT_OK if successful
+*/
+int sha512_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->sha512.curlen >= sizeof(md->sha512.buf)) {
        return CRYPT_INVALID_ARG;
@@ -224,14 +245,18 @@
 
     /* copy output */
     for (i = 0; i < 8; i++) {
-        STORE64H(md->sha512.state[i], hash+(8*i));
+        STORE64H(md->sha512.state[i], out+(8*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  sha512_test(void)
 {
  #ifndef LTC_TEST
@@ -287,3 +312,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/sha2/sha512.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/tiger.c b/src/hashes/tiger.c
similarity index 95%
rename from tiger.c
rename to src/hashes/tiger.c
index 09ba9b3..250c186 100644
--- a/tiger.c
+++ b/src/hashes/tiger.c
@@ -6,25 +6,28 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+   @file tiger.c
+   Tiger hash function, Tom St Denis
+*/
 
 #ifdef TIGER
 
-const struct _hash_descriptor tiger_desc =
+const struct ltc_hash_descriptor tiger_desc =
 {
     "tiger",
     1,
     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,
@@ -558,7 +561,7 @@
 #endif   
 
 /* one round of the hash function */
-INLINE static void round(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 x, int mul)
+INLINE static void tiger_round(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 x, int mul)
 {
     ulong64 tmp;
     tmp = (*c ^= x); 
@@ -574,14 +577,14 @@
 /* one complete pass */
 static void pass(ulong64 *a, ulong64 *b, ulong64 *c, ulong64 *x, int mul)
 {
-   round(a,b,c,x[0],mul); 
-   round(b,c,a,x[1],mul); 
-   round(c,a,b,x[2],mul); 
-   round(a,b,c,x[3],mul); 
-   round(b,c,a,x[4],mul); 
-   round(c,a,b,x[5],mul); 
-   round(a,b,c,x[6],mul); 
-   round(b,c,a,x[7],mul);          
+   tiger_round(a,b,c,x[0],mul); 
+   tiger_round(b,c,a,x[1],mul); 
+   tiger_round(c,a,b,x[2],mul); 
+   tiger_round(a,b,c,x[3],mul); 
+   tiger_round(b,c,a,x[4],mul); 
+   tiger_round(c,a,b,x[5],mul); 
+   tiger_round(a,b,c,x[6],mul); 
+   tiger_round(b,c,a,x[7],mul);          
 }   
 
 /* The key mixing schedule */
@@ -605,10 +608,10 @@
     x[7] -= x[6] ^ CONST64(0x0123456789ABCDEF);
 }    
 
-#ifdef CLEAN_STACK
-static void _tiger_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _tiger_compress(hash_state *md, unsigned char *buf)
 #else
-static void tiger_compress(hash_state *md, unsigned char *buf)
+static int  tiger_compress(hash_state *md, unsigned char *buf)
 #endif
 {
     ulong64 a, b, c, x[8];
@@ -632,32 +635,55 @@
     md->tiger.state[0] = a ^ md->tiger.state[0];
     md->tiger.state[1] = b - md->tiger.state[1];
     md->tiger.state[2] = c + md->tiger.state[2];
+
+    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
-static void tiger_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int tiger_compress(hash_state *md, unsigned char *buf)
 {
-   _tiger_compress(md, buf);
+   int err;
+   err = _tiger_compress(md, buf);
    burn_stack(sizeof(ulong64) * 11 + sizeof(unsigned long));
+   return err;
 }
 #endif
 
-void tiger_init(hash_state *md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int tiger_init(hash_state *md)
 {
-    _ARGCHK(md != NULL);
+    LTC_ARGCHK(md != NULL);
     md->tiger.state[0] = CONST64(0x0123456789ABCDEF);
     md->tiger.state[1] = CONST64(0xFEDCBA9876543210);
     md->tiger.state[2] = CONST64(0xF096A5B4C3B2E187);
     md->tiger.curlen = 0;
     md->tiger.length = 0;
+    return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(tiger_process, tiger_compress, tiger, 64)
 
-int tiger_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (24 bytes)
+   @return CRYPT_OK if successful
+*/
+int tiger_done(hash_state * md, unsigned char *out)
 {
-    _ARGCHK(md   != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->tiger.curlen >= sizeof(md->tiger.buf)) {
        return CRYPT_INVALID_ARG;
@@ -690,16 +716,20 @@
     tiger_compress(md, md->tiger.buf);
 
     /* copy output */
-    STORE64L(md->tiger.state[0], &hash[0]);
-    STORE64L(md->tiger.state[1], &hash[8]);
-    STORE64L(md->tiger.state[2], &hash[16]);
-#ifdef CLEAN_STACK
+    STORE64L(md->tiger.state[0], &out[0]);
+    STORE64L(md->tiger.state[1], &out[8]);
+    STORE64L(md->tiger.state[2], &out[16]);
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
 
     return CRYPT_OK;
 }
 
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  tiger_test(void)
 {
  #ifndef LTC_TEST
@@ -777,3 +807,7 @@
 
 
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/tiger.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/whirl.c b/src/hashes/whirl/whirl.c
similarity index 82%
rename from whirl.c
rename to src/hashes/whirl/whirl.c
index 5233c47..1bd7983 100644
--- a/whirl.c
+++ b/src/hashes/whirl/whirl.c
@@ -6,25 +6,28 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-/* WHIRLPOOL (using their new sbox) hash function by Tom St Denis */
+/** 
+   @file whirl.c
+   WHIRLPOOL (using their new sbox) hash function by Tom St Denis 
+*/
 
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
 #ifdef WHIRLPOOL
 
-const struct _hash_descriptor whirlpool_desc =
+const struct ltc_hash_descriptor whirlpool_desc =
 {
     "whirlpool",
     11,
     64,
     64,
 
-    /* DER encoding (not yet supported) */
-    { 0x00 },
-    0,
+   /* OID */
+   { 1, 0, 10118, 3, 0, 55 },
+   6,
 
     &whirlpool_init,
     &whirlpool_process,
@@ -49,10 +52,10 @@
     SB6(GB(a, i-6, 1)) ^                 \
     SB7(GB(a, i-7, 0))
 
-#ifdef CLEAN_STACK
-static void _whirlpool_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int _whirlpool_compress(hash_state *md, unsigned char *buf)
 #else
-static void whirlpool_compress(hash_state *md, unsigned char *buf)
+static int whirlpool_compress(hash_state *md, unsigned char *buf)
 #endif
 {
    ulong64 K[2][8], T[3][8];
@@ -90,7 +93,7 @@
        /* xor the constant */
        K[0][0] ^= cont[x+1];
        
-       /* apply main transform to T[0] into T[1] */
+       /* apply main transform to T[1] into T[0] */
        for (y = 0; y < 8; y++) {
            T[0][y] = theta_pi_gamma(T[1], y) ^ K[0][y];
        }
@@ -100,32 +103,55 @@
    for (x = 0; x < 8; x++) {
       md->whirlpool.state[x] ^= T[0][x] ^ T[2][x];
    }
+
+   return CRYPT_OK;
 }
 
 
-#ifdef CLEAN_STACK
-static void whirlpool_compress(hash_state *md, unsigned char *buf)
+#ifdef LTC_CLEAN_STACK
+static int whirlpool_compress(hash_state *md, unsigned char *buf)
 {
-   _whirlpool_compress(md, buf);
+   int err;
+   err = _whirlpool_compress(md, buf);
    burn_stack((5 * 8 * sizeof(ulong64)) + (2 * sizeof(int)));
+   return err;
 }
 #endif
 
 
-void whirlpool_init(hash_state * md)
+/**
+   Initialize the hash state
+   @param md   The hash state you wish to initialize
+   @return CRYPT_OK if successful
+*/
+int whirlpool_init(hash_state * md)
 {
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
    zeromem(&md->whirlpool, sizeof(md->whirlpool));
+   return CRYPT_OK;
 }
 
+/**
+   Process a block of memory though the hash
+   @param md     The hash state
+   @param in     The data to hash
+   @param inlen  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
 HASH_PROCESS(whirlpool_process, whirlpool_compress, whirlpool, 64)
 
-int whirlpool_done(hash_state * md, unsigned char *hash)
+/**
+   Terminate the hash to get the digest
+   @param md  The hash state
+   @param out [out] The destination of the hash (64 bytes)
+   @return CRYPT_OK if successful
+*/
+int whirlpool_done(hash_state * md, unsigned char *out)
 {
     int i;
 
-    _ARGCHK(md   != NULL);
-    _ARGCHK(hash != NULL);
+    LTC_ARGCHK(md  != NULL);
+    LTC_ARGCHK(out != NULL);
 
     if (md->whirlpool.curlen >= sizeof(md->whirlpool.buf)) {
        return CRYPT_INVALID_ARG;
@@ -160,15 +186,18 @@
 
     /* copy output */
     for (i = 0; i < 8; i++) {
-        STORE64H(md->whirlpool.state[i], hash+(8*i));
+        STORE64H(md->whirlpool.state[i], out+(8*i));
     }
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(*md));
 #endif
     return CRYPT_OK;
 }
 
-
+/**
+  Self-test the hash
+  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+*/  
 int  whirlpool_test(void)
 {
  #ifndef LTC_TEST
@@ -278,3 +307,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/whirl/whirl.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/23 02:42:07 $ */
diff --git a/whirltab.c b/src/hashes/whirl/whirltab.c
similarity index 98%
rename from whirltab.c
rename to src/hashes/whirl/whirltab.c
index 031c643..c83d0b2 100644
--- a/whirltab.c
+++ b/src/hashes/whirl/whirltab.c
@@ -1,3 +1,7 @@
+/**
+   @file whirltab.c
+   WHIRLPOOL tables, Tom St Denis
+*/   
 static const ulong64 sbox0[] = {
 CONST64(0x18186018c07830d8), CONST64(0x23238c2305af4626), CONST64(0xc6c63fc67ef991b8), CONST64(0xe8e887e8136fcdfb), 
 CONST64(0x878726874ca113cb), CONST64(0xb8b8dab8a9626d11), CONST64(0x0101040108050209), CONST64(0x4f4f214f426e9e0d), 
@@ -65,16 +69,16 @@
 CONST64(0x2828a0285d885075), CONST64(0x5c5c6d5cda31b886), CONST64(0xf8f8c7f8933fed6b), CONST64(0x8686228644a411c2)
 };
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
 
 #define SB0(x) sbox0[x]
-#define SB1(x) ROR64(sbox0[x], 8)
-#define SB2(x) ROR64(sbox0[x], 16)
-#define SB3(x) ROR64(sbox0[x], 24)
-#define SB4(x) ROR64(sbox0[x], 32)
-#define SB5(x) ROR64(sbox0[x], 40)
-#define SB6(x) ROR64(sbox0[x], 48)
-#define SB7(x) ROR64(sbox0[x], 56)
+#define SB1(x) ROR64c(sbox0[x], 8)
+#define SB2(x) ROR64c(sbox0[x], 16)
+#define SB3(x) ROR64c(sbox0[x], 24)
+#define SB4(x) ROR64c(sbox0[x], 32)
+#define SB5(x) ROR64c(sbox0[x], 40)
+#define SB6(x) ROR64c(sbox0[x], 48)
+#define SB7(x) ROR64c(sbox0[x], 56)
 
 #else
 
@@ -573,3 +577,7 @@
 CONST64(0x6302aa71c81949d9),
 };
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/hashes/whirl/whirltab.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/tommath.h b/src/headers/ltc_tommath.h
similarity index 92%
rename from tommath.h
rename to src/headers/ltc_tommath.h
index bc50ce9..2d62b4e 100644
--- a/tommath.h
+++ b/src/headers/ltc_tommath.h
@@ -21,7 +21,7 @@
 #include <ctype.h>
 #include <limits.h>
 
-#define NO_LTM_TOOM 1
+#include <tommath_class.h>
 
 #undef MIN
 #define MIN(x,y) ((x)<(y)?(x):(y))
@@ -41,6 +41,14 @@
 
 #endif
 
+
+/* detect 64-bit mode if possible */
+#if defined(__x86_64__) 
+   #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
+      #define MP_64BIT
+   #endif
+#endif
+
 /* some default configurations.
  *
  * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
@@ -62,7 +70,7 @@
    typedef signed long long   long64;
 #endif
 
-   typedef ulong64            mp_digit;
+   typedef unsigned long      mp_digit;
    typedef unsigned long      mp_word __attribute__ ((mode(TI)));
 
    #define DIGIT_BIT          60
@@ -104,7 +112,7 @@
    #else
       /* prototypes for our heap functions */
       extern void *XMALLOC(size_t n);
-      extern void *REALLOC(void *p, size_t n);
+      extern void *XREALLOC(void *p, size_t n);
       extern void *XCALLOC(size_t n, size_t s);
       extern void XFREE(void *p);
    #endif
@@ -139,7 +147,6 @@
 /* Primality generation flags */
 #define LTM_PRIME_BBS      0x0001 /* BBS style prime */
 #define LTM_PRIME_SAFE     0x0002 /* Safe prime (p-1)/2 == prime */
-#define LTM_PRIME_2MSB_OFF 0x0004 /* force 2nd MSB to 0 */
 #define LTM_PRIME_2MSB_ON  0x0008 /* force 2nd MSB to 1 */
 
 typedef int           mp_err;
@@ -155,7 +162,7 @@
 
 /* default precision */
 #ifndef MP_PREC
-   #ifdef MP_LOW_MEM
+   #ifndef MP_LOW_MEM
       #define MP_PREC                 64     /* default digits of precision */
    #else
       #define MP_PREC                 8      /* default digits of precision */
@@ -421,6 +428,15 @@
 /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
 
+/* returns true if a can be reduced with mp_reduce_2k_l */
+int mp_reduce_is_2k_l(mp_int *a);
+
+/* determines k value for 2k reduction */
+int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
+
+/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
+int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
+
 /* d = a**b (mod c) */
 int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
 
@@ -434,7 +450,7 @@
 #endif
 
 /* table of first PRIME_SIZE primes */
-extern const mp_digit __prime_tab[];
+extern const mp_digit ltm_prime_tab[];
 
 /* result=1 if a is divisible by one of the first PRIME_SIZE primes */
 int mp_prime_is_divisible(mp_int *a, int *result);
@@ -501,14 +517,16 @@
 int mp_count_bits(mp_int *a);
 
 int mp_unsigned_bin_size(mp_int *a);
-int mp_read_unsigned_bin(mp_int *a, unsigned char *b, int c);
+int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
 int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
+int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
 
 int mp_signed_bin_size(mp_int *a);
-int mp_read_signed_bin(mp_int *a, unsigned char *b, int c);
-int mp_to_signed_bin(mp_int *a, unsigned char *b);
+int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
+int mp_to_signed_bin(mp_int *a,  unsigned char *b);
+int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
 
-int mp_read_radix(mp_int *a, char *str, int radix);
+int mp_read_radix(mp_int *a, const char *str, int radix);
 int mp_toradix(mp_int *a, char *str, int radix);
 int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
 int mp_radix_size(mp_int *a, int radix, int *size);
@@ -543,9 +561,10 @@
 int mp_karatsuba_sqr(mp_int *a, mp_int *b);
 int mp_toom_sqr(mp_int *a, mp_int *b);
 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
+int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
 int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
-int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
+int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
 void bn_reverse(unsigned char *s, int len);
 
 extern const char *mp_s_rmap;
@@ -556,3 +575,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/ltc_tommath.h,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/mycrypt.h b/src/headers/tomcrypt.h
similarity index 76%
rename from mycrypt.h
rename to src/headers/tomcrypt.h
index 93ed492..4804194 100644
--- a/mycrypt.h
+++ b/src/headers/tomcrypt.h
@@ -1,5 +1,5 @@
-#ifndef CRYPT_H_
-#define CRYPT_H_
+#ifndef TOMCRYPT_H_
+#define TOMCRYPT_H_
 #include <assert.h>
 #include <stdio.h>
 #include <string.h>
@@ -8,19 +8,19 @@
 #include <ctype.h>
 #include <limits.h>
 
-/* if there is a custom definition header file use it */
-#include <mycrypt_custom.h>
+/* use configuration data */
+#include <tomcrypt_custom.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* version */
-#define CRYPT   0x0096
-#define SCRYPT  "0.96"
+#define CRYPT   0x0105
+#define SCRYPT  "1.05"
 
 /* max size of either a cipher/hash block or symmetric key [largest of the two] */
-#define MAXBLOCKSIZE           128
+#define MAXBLOCKSIZE  128
 
 /* descriptor table size */
 /* Dropbear change - this should be smaller, saves some size */
@@ -63,19 +63,24 @@
    CRYPT_INVALID_PRIME_SIZE/* Invalid size of prime requested */
 };
 
-#include <mycrypt_cfg.h>
-#include <mycrypt_macros.h>
-#include <mycrypt_cipher.h>
-#include <mycrypt_hash.h>
-#include <mycrypt_prng.h>
-#include <mycrypt_pk.h>
-#include <mycrypt_misc.h>
-#include <mycrypt_argchk.h>
-#include <mycrypt_pkcs.h>
+#include <tomcrypt_cfg.h>
+#include <tomcrypt_macros.h>
+#include <tomcrypt_cipher.h>
+#include <tomcrypt_hash.h>
+#include <tomcrypt_mac.h>
+#include <tomcrypt_prng.h>
+#include <tomcrypt_pk.h>
+#include <tomcrypt_misc.h>
+#include <tomcrypt_argchk.h>
+#include <tomcrypt_pkcs.h>
 
 #ifdef __cplusplus
    }
 #endif
 
-#endif /* CRYPT_H_ */
+#endif /* TOMCRYPT_H_ */
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt.h,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/06/19 18:03:25 $ */
diff --git a/src/headers/tomcrypt_argchk.h b/src/headers/tomcrypt_argchk.h
new file mode 100644
index 0000000..ef344ee
--- /dev/null
+++ b/src/headers/tomcrypt_argchk.h
@@ -0,0 +1,25 @@
+/* Defines the LTC_ARGCHK macro used within the library */
+/* ARGTYPE is defined in mycrypt_cfg.h */
+#if ARGTYPE == 0
+
+#include <signal.h>
+
+/* this is the default LibTomCrypt macro  */
+void crypt_argchk(char *v, char *s, int d);
+#define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); }
+
+#elif ARGTYPE == 1
+
+/* fatal type of error */
+#define LTC_ARGCHK(x) assert((x))
+
+#elif ARGTYPE == 2
+
+#define LTC_ARGCHK(x) 
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_argchk.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h
new file mode 100644
index 0000000..1d5bc6c
--- /dev/null
+++ b/src/headers/tomcrypt_cfg.h
@@ -0,0 +1,112 @@
+/* This is the build config file.
+ *
+ * With this you can setup what to inlcude/exclude automatically during any build.  Just comment
+ * out the line that #define's the word for the thing you want to remove.  phew!
+ */
+
+#ifndef TOMCRYPT_CFG_H
+#define TOMCRYPT_CFG_H
+
+/* you can change how memory allocation works ... */
+void *XMALLOC(size_t n);
+void *XREALLOC(void *p, size_t n);
+void *XCALLOC(size_t n, size_t s);
+void XFREE(void *p);
+
+/* change the clock function too */
+ clock_t XCLOCK(void);
+
+/* various other functions */
+void *XMEMCPY(void *dest, const void *src, size_t n);
+int   XMEMCMP(const void *s1, const void *s2, size_t n);
+
+/* type of argument checking, 0=default, 1=fatal and 2=none */
+#define ARGTYPE  0
+
+/* Controls endianess and size of registers.  Leave uncommented to get platform neutral [slower] code 
+ * 
+ * Note: in order to use the optimized macros your platform must support unaligned 32 and 64 bit read/writes.
+ * The x86 platforms allow this but some others [ARM for instance] do not.  On those platforms you **MUST**
+ * use the portable [slower] macros.
+ */
+
+/* detect x86-32 machines somewhat */
+#if defined(INTEL_CC) || (defined(_MSC_VER) && defined(WIN32)) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__)))
+   #define ENDIAN_LITTLE
+   #define ENDIAN_32BITWORD
+   #define LTC_FAST
+   #define LTC_FAST_TYPE    unsigned long
+#endif
+
+/* detects MIPS R5900 processors (PS2) */
+#if (defined(__R5900) || defined(R5900) || defined(__R5900__)) && (defined(_mips) || defined(__mips__) || defined(mips))
+   #define ENDIAN_LITTLE
+   #define ENDIAN_64BITWORD
+#endif
+
+/* detect amd64 */
+#if defined(__x86_64__)
+   #define ENDIAN_LITTLE
+   #define ENDIAN_64BITWORD
+   #define LTC_FAST
+   #define LTC_FAST_TYPE    unsigned long
+#endif
+
+#ifdef LTC_NO_FAST
+   #ifdef LTC_FAST
+      #undef LTC_FAST
+   #endif
+#endif
+
+/* No asm is a quick way to disable anything "not portable" */
+#ifdef LTC_NO_ASM
+   #undef ENDIAN_LITTLE
+   #undef ENDIAN_BIG
+   #undef ENDIAN_32BITWORD
+   #undef ENDIAN_64BITWORD
+   #undef LTC_FAST
+   #undef LTC_FAST_TYPE
+   #define LTC_NO_ROLC
+	#define LTC_NO_BSWAP
+#endif
+
+/* #define ENDIAN_LITTLE */
+/* #define ENDIAN_BIG */
+
+/* #define ENDIAN_32BITWORD */
+/* #define ENDIAN_64BITWORD */
+
+#if (defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE)) && !(defined(ENDIAN_32BITWORD) || defined(ENDIAN_64BITWORD))
+    #error You must specify a word size as well as endianess in mycrypt_cfg.h
+#endif
+
+#if !(defined(ENDIAN_BIG) || defined(ENDIAN_LITTLE))
+   #define ENDIAN_NEUTRAL
+#endif
+
+/* packet code */
+#if defined(MRSA) || defined(MDH) || defined(MECC)
+    #define PACKET
+
+    /* size of a packet header in bytes */
+    #define PACKET_SIZE            4
+
+    /* Section tags */
+    #define PACKET_SECT_RSA        0
+    #define PACKET_SECT_DH         1
+    #define PACKET_SECT_ECC        2
+    #define PACKET_SECT_DSA        3
+
+    /* Subsection Tags for the first three sections */
+    #define PACKET_SUB_KEY         0
+    #define PACKET_SUB_ENCRYPTED   1
+    #define PACKET_SUB_SIGNED      2
+    #define PACKET_SUB_ENC_KEY     3
+#endif
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cfg.h,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/headers/tomcrypt_cipher.h b/src/headers/tomcrypt_cipher.h
new file mode 100644
index 0000000..4f00302
--- /dev/null
+++ b/src/headers/tomcrypt_cipher.h
@@ -0,0 +1,629 @@
+/* ---- SYMMETRIC KEY STUFF -----
+ *
+ * We put each of the ciphers scheduled keys in their own structs then we put all of 
+ * the key formats in one union.  This makes the function prototypes easier to use.
+ */
+#ifdef BLOWFISH
+struct blowfish_key {
+   ulong32 S[4][256];
+   ulong32 K[18];
+};
+#endif
+
+#ifdef RC5
+struct rc5_key {
+   int rounds;
+   ulong32 K[50];
+};
+#endif
+
+#ifdef RC6
+struct rc6_key {
+   ulong32 K[44];
+};
+#endif
+
+#ifdef SAFERP
+struct saferp_key {
+   unsigned char K[33][16];
+   long rounds;
+};
+#endif
+
+#ifdef RIJNDAEL
+struct rijndael_key {
+   ulong32 eK[60], dK[60];
+   int Nr;
+};
+#endif
+
+#ifdef XTEA
+struct xtea_key {
+   unsigned long A[32], B[32];
+};
+#endif
+
+#ifdef TWOFISH
+#ifndef TWOFISH_SMALL
+   struct twofish_key {
+      ulong32 S[4][256], K[40];
+   };
+#else
+   struct twofish_key {
+      ulong32 K[40];
+      unsigned char S[32], start;
+   };
+#endif
+#endif
+
+#ifdef SAFER
+#define SAFER_K64_DEFAULT_NOF_ROUNDS     6
+#define SAFER_K128_DEFAULT_NOF_ROUNDS   10
+#define SAFER_SK64_DEFAULT_NOF_ROUNDS    8
+#define SAFER_SK128_DEFAULT_NOF_ROUNDS  10
+#define SAFER_MAX_NOF_ROUNDS            13
+#define SAFER_BLOCK_LEN                  8
+#define SAFER_KEY_LEN     (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS))
+typedef unsigned char safer_block_t[SAFER_BLOCK_LEN];
+typedef unsigned char safer_key_t[SAFER_KEY_LEN];
+struct safer_key { safer_key_t key; };
+#endif
+
+#ifdef RC2
+struct rc2_key { unsigned xkey[64]; };
+#endif
+
+#ifdef DES
+struct des_key {
+    ulong32 ek[32], dk[32];
+};
+
+struct des3_key {
+    ulong32 ek[3][32], dk[3][32];
+};
+#endif
+
+#ifdef CAST5
+struct cast5_key {
+    ulong32 K[32], keylen;
+};
+#endif
+
+#ifdef NOEKEON
+struct noekeon_key {
+    ulong32 K[4], dK[4];
+};
+#endif
+
+#ifdef SKIPJACK 
+struct skipjack_key {
+    unsigned char key[10];
+};
+#endif
+
+#ifdef KHAZAD
+struct khazad_key {
+   ulong64 roundKeyEnc[8 + 1]; 
+   ulong64 roundKeyDec[8 + 1]; 
+};
+#endif
+
+#ifdef ANUBIS
+struct anubis_key { 
+   int keyBits; 
+   int R; 
+   ulong32 roundKeyEnc[18 + 1][4]; 
+   ulong32 roundKeyDec[18 + 1][4]; 
+}; 
+#endif
+
+typedef union Symmetric_key {
+#ifdef DES
+   struct des_key des;
+   struct des3_key des3;
+#endif
+#ifdef RC2
+   struct rc2_key rc2;
+#endif
+#ifdef SAFER
+   struct safer_key safer;
+#endif
+#ifdef TWOFISH
+   struct twofish_key  twofish;
+#endif
+#ifdef BLOWFISH
+   struct blowfish_key blowfish;
+#endif
+#ifdef RC5
+   struct rc5_key      rc5;
+#endif
+#ifdef RC6
+   struct rc6_key      rc6;
+#endif
+#ifdef SAFERP
+   struct saferp_key   saferp;
+#endif
+#ifdef RIJNDAEL
+   struct rijndael_key rijndael;
+#endif
+#ifdef XTEA
+   struct xtea_key     xtea;
+#endif
+#ifdef CAST5
+   struct cast5_key    cast5;
+#endif
+#ifdef NOEKEON
+   struct noekeon_key  noekeon;
+#endif   
+#ifdef SKIPJACK
+   struct skipjack_key skipjack;
+#endif
+#ifdef KHAZAD
+   struct khazad_key   khazad;
+#endif
+#ifdef ANUBIS
+   struct anubis_key   anubis;
+#endif
+   void   *data;
+} symmetric_key;
+
+/* A block cipher ECB structure */
+typedef struct {
+   /** The index of the cipher chosen */
+   int                 cipher, 
+   /** The block size of the given cipher */
+                       blocklen;
+   /** The scheduled key */                       
+   symmetric_key       key;
+} symmetric_ECB;
+
+/* A block cipher CFB structure */
+typedef struct {
+   /** The index of the cipher chosen */
+   int                 cipher, 
+   /** The block size of the given cipher */                        
+                       blocklen, 
+   /** The padding offset */
+                       padlen;
+   /** The current IV */
+   unsigned char       IV[MAXBLOCKSIZE], 
+   /** The pad used to encrypt/decrypt */ 
+                       pad[MAXBLOCKSIZE];
+   /** The scheduled key */
+   symmetric_key       key;
+} symmetric_CFB;
+
+/* A block cipher OFB structure */
+typedef struct {
+   /** The index of the cipher chosen */
+   int                 cipher, 
+   /** The block size of the given cipher */                        
+                       blocklen, 
+   /** The padding offset */
+                       padlen;
+   /** The current IV */
+   unsigned char       IV[MAXBLOCKSIZE];
+   /** The scheduled key */
+   symmetric_key       key;
+} symmetric_OFB;
+
+/* A block cipher CBC structure */
+typedef struct {
+   /** The index of the cipher chosen */
+   int                 cipher, 
+   /** The block size of the given cipher */                        
+                       blocklen;
+   /** The current IV */
+   unsigned char       IV[MAXBLOCKSIZE];
+   /** The scheduled key */
+   symmetric_key       key;
+} symmetric_CBC;
+
+/* A block cipher CTR structure */
+typedef struct {
+   /** The index of the cipher chosen */
+   int                 cipher,
+   /** The block size of the given cipher */                        
+                       blocklen, 
+   /** The padding offset */
+                       padlen, 
+   /** The mode (endianess) of the CTR, 0==little, 1==big */                       
+                       mode;
+   /** The counter */                       
+   unsigned char       ctr[MAXBLOCKSIZE], 
+   /** The pad used to encrypt/decrypt */                       
+                       pad[MAXBLOCKSIZE];
+   /** The scheduled key */
+   symmetric_key       key;
+} symmetric_CTR;
+
+/* cipher descriptor table, last entry has "name == NULL" to mark the end of table */
+extern struct ltc_cipher_descriptor {
+   /** name of cipher */
+   char *name;
+   /** internal ID */
+   unsigned char ID;
+   /** min keysize (octets) */
+   int  min_key_length, 
+   /** max keysize (octets) */
+        max_key_length, 
+   /** block size (octets) */
+        block_length, 
+   /** default number of rounds */
+        default_rounds;
+   /** Setup the cipher 
+      @param key         The input symmetric key
+      @param keylen      The length of the input key (octets)
+      @param num_rounds  The requested number of rounds (0==default)
+      @param skey        [out] The destination of the scheduled key
+      @return CRYPT_OK if successful
+   */
+   int  (*setup)(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+   /** Encrypt a block
+      @param pt      The plaintext
+      @param ct      [out] The ciphertext
+      @param skey    The scheduled key
+   */
+   void (*ecb_encrypt)(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+   /** Decrypt a block
+      @param ct      The ciphertext
+      @param pt      [out] The plaintext
+      @param skey    The scheduled key
+   */
+   void (*ecb_decrypt)(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+   /** Test the block cipher
+       @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+   */
+   int (*test)(void);
+
+   /** Terminate the context 
+      @param skey    The scheduled key
+   */
+   void (*done)(symmetric_key *skey);      
+
+   /** Determine a key size
+       @param keysize    [in/out] The size of the key desired and the suggested size
+       @return CRYPT_OK if successful
+   */
+   int  (*keysize)(int *keysize);
+
+/** Accelerators **/
+   /** Accelerated ECB encryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param skey    The scheduled key context
+   */
+   void (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey);
+
+   /** Accelerated ECB decryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param skey    The scheduled key context
+   */
+   void (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey);
+
+   /** Accelerated CBC encryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param IV      The initial value (input/output)
+       @param skey    The scheduled key context
+   */
+   void (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
+
+   /** Accelerated CBC decryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param IV      The initial value (input/output)
+       @param skey    The scheduled key context
+   */
+   void (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey);
+
+   /** Accelerated CTR encryption 
+       @param pt      Plaintext
+       @param ct      Ciphertext
+       @param blocks  The number of complete blocks to process
+       @param IV      The initial value (input/output)
+       @param mode    little or big endian counter (mode=0 or mode=1)
+       @param skey    The scheduled key context
+   */
+   void (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey);
+
+   /** Accelerated CCM packet (one-shot)
+       @param key        The secret key to use
+       @param keylen     The length of the secret key (octets)
+       @param nonce      The session nonce [use once]
+       @param noncelen   The length of the nonce
+       @param header     The header for the session
+       @param headerlen  The length of the header (octets)
+       @param pt         [out] The plaintext
+       @param ptlen      The length of the plaintext (octets)
+       @param ct         [out] The ciphertext
+       @param tag        [out] The destination tag
+       @param taglen     [in/out] The max size and resulting size of the authentication tag
+       @param direction  Encrypt or Decrypt direction (0 or 1)
+       @return CRYPT_OK if successful
+   */
+   void (*accel_ccm_memory)(
+       const unsigned char *key,    unsigned long keylen,
+       const unsigned char *nonce,  unsigned long noncelen,
+       const unsigned char *header, unsigned long headerlen,
+             unsigned char *pt,     unsigned long ptlen,
+             unsigned char *ct,
+             unsigned char *tag,    unsigned long *taglen,
+                       int  direction);
+
+   /** Accelerated GCM packet (one shot)
+       @param key               The secret key
+       @param keylen            The length of the secret key
+       @param IV                The initial vector 
+       @param IVlen             The length of the initial vector
+       @param adata             The additional authentication data (header)
+       @param adatalen          The length of the adata
+       @param pt                The plaintext
+       @param ptlen             The length of the plaintext (ciphertext length is the same)
+       @param ct                The ciphertext
+       @param tag               [out] The MAC tag
+       @param taglen            [in/out] The MAC tag length
+       @param direction         Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
+   */
+   void (*accel_gcm_memory)(
+       const unsigned char *key,    unsigned long keylen,
+       const unsigned char *IV,     unsigned long IVlen,
+       const unsigned char *adata,  unsigned long adatalen,
+             unsigned char *pt,     unsigned long ptlen,
+             unsigned char *ct, 
+             unsigned char *tag,    unsigned long *taglen,
+                       int direction);
+} cipher_descriptor[];
+
+#ifdef BLOWFISH
+int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int blowfish_test(void);
+void blowfish_done(symmetric_key *skey);
+int blowfish_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor blowfish_desc;
+#endif
+
+#ifdef RC5
+int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int rc5_test(void);
+void rc5_done(symmetric_key *skey);
+int rc5_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor rc5_desc;
+#endif
+
+#ifdef RC6
+int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int rc6_test(void);
+void rc6_done(symmetric_key *skey);
+int rc6_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor rc6_desc;
+#endif
+
+#ifdef RC2
+int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int rc2_test(void);
+void rc2_done(symmetric_key *skey);
+int rc2_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor rc2_desc;
+#endif
+
+#ifdef SAFERP
+int saferp_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void saferp_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int saferp_test(void);
+void saferp_done(symmetric_key *skey);
+int saferp_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor saferp_desc;
+#endif
+
+#ifdef SAFER
+int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key);
+void safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
+int safer_k64_test(void);
+int safer_sk64_test(void);
+int safer_sk128_test(void);
+void safer_done(symmetric_key *skey);
+int safer_64_keysize(int *keysize);
+int safer_128_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer_sk64_desc, safer_sk128_desc;
+#endif
+
+#ifdef RIJNDAEL
+
+/* make aes an alias */
+#define aes_setup           rijndael_setup
+#define aes_ecb_encrypt     rijndael_ecb_encrypt
+#define aes_ecb_decrypt     rijndael_ecb_decrypt
+#define aes_test            rijndael_test
+#define aes_done            rijndael_done
+#define aes_keysize         rijndael_keysize
+
+#define aes_enc_setup           rijndael_enc_setup
+#define aes_enc_ecb_encrypt     rijndael_enc_ecb_encrypt
+#define aes_enc_keysize         rijndael_enc_keysize
+
+int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int rijndael_test(void);
+void rijndael_done(symmetric_key *skey);
+int rijndael_keysize(int *keysize);
+int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void rijndael_enc_done(symmetric_key *skey);
+int rijndael_enc_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
+extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
+#endif
+
+#ifdef XTEA
+int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int xtea_test(void);
+void xtea_done(symmetric_key *skey);
+int xtea_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor xtea_desc;
+#endif
+
+#ifdef TWOFISH
+int twofish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int twofish_test(void);
+void twofish_done(symmetric_key *skey);
+int twofish_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor twofish_desc;
+#endif
+
+#ifdef DES
+int des_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int des_test(void);
+void des_done(symmetric_key *skey);
+int des_keysize(int *keysize);
+int des3_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int des3_test(void);
+void des3_done(symmetric_key *skey);
+int des3_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor des_desc, des3_desc;
+#endif
+
+#ifdef CAST5
+int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void cast5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int cast5_test(void);
+void cast5_done(symmetric_key *skey);
+int cast5_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor cast5_desc;
+#endif
+
+#ifdef NOEKEON
+int noekeon_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int noekeon_test(void);
+void noekeon_done(symmetric_key *skey);
+int noekeon_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor noekeon_desc;
+#endif
+
+#ifdef SKIPJACK
+int skipjack_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void skipjack_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int skipjack_test(void);
+void skipjack_done(symmetric_key *skey);
+int skipjack_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor skipjack_desc;
+#endif
+
+#ifdef KHAZAD
+int khazad_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void khazad_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void khazad_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int khazad_test(void);
+void khazad_done(symmetric_key *skey);
+int khazad_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor khazad_desc;
+#endif
+
+#ifdef ANUBIS
+int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
+void anubis_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey);
+void anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey);
+int anubis_test(void);
+void anubis_done(symmetric_key *skey);
+int anubis_keysize(int *keysize);
+extern const struct ltc_cipher_descriptor anubis_desc;
+#endif
+
+#ifdef ECB
+int ecb_start(int cipher, const unsigned char *key, 
+              int keylen, int num_rounds, symmetric_ECB *ecb);
+int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb);
+int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb);
+int ecb_done(symmetric_ECB *ecb);
+#endif
+
+#ifdef CFB
+int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+              int keylen, int num_rounds, symmetric_CFB *cfb);
+int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb);
+int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb);
+int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb);
+int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb);
+int cfb_done(symmetric_CFB *cfb);
+#endif
+
+#ifdef OFB
+int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+              int keylen, int num_rounds, symmetric_OFB *ofb);
+int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb);
+int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb);
+int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb);
+int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb);
+int ofb_done(symmetric_OFB *ofb);
+#endif
+
+#ifdef CBC
+int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
+               int keylen, int num_rounds, symmetric_CBC *cbc);
+int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc);
+int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc);
+int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc);
+int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc);
+int cbc_done(symmetric_CBC *cbc);
+#endif
+
+#ifdef 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);
+int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr);
+int ctr_done(symmetric_CTR *ctr);
+#endif
+    
+int find_cipher(const char *name);
+int find_cipher_any(const char *name, int blocklen, int keylen);
+int find_cipher_id(unsigned char ID);
+int register_cipher(const struct ltc_cipher_descriptor *cipher);
+int unregister_cipher(const struct ltc_cipher_descriptor *cipher);
+int cipher_is_valid(int idx);
+
+LTC_MUTEX_PROTO(ltc_cipher_mutex);
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_cipher.h,v $ */
+/* $Revision: 1.16 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/headers/tomcrypt_custom.h b/src/headers/tomcrypt_custom.h
new file mode 100644
index 0000000..eaa8edd
--- /dev/null
+++ b/src/headers/tomcrypt_custom.h
@@ -0,0 +1,93 @@
+#ifndef TOMCRYPT_CUSTOM_H_
+#define TOMCRYPT_CUSTOM_H_
+
+/* this will sort out which stuff based on the user-config in options.h */
+#include "../options.h"
+
+/* macros for various libc functions you can change for embedded targets */
+#define XMALLOC  malloc
+#define XREALLOC realloc
+#define XCALLOC  calloc
+#define XFREE    free
+
+#define XMEMSET  memset
+#define XMEMCPY  memcpy
+
+#define XCLOCK   clock
+#define XCLOCKS_PER_SEC CLOCKS_PER_SEC
+
+#ifdef DROPBEAR_SMALL_CODE
+#define LTC_SMALL_CODE
+#endif
+
+/* Enable self-test test vector checking */
+/* Not for dropbear */
+//#define LTC_TEST
+
+/* clean the stack of functions which put private information on stack */
+/* #define LTC_CLEAN_STACK */
+
+/* disable all file related functions */
+/* #define LTC_NO_FILE */
+
+/* disable all forms of ASM */
+/* #define LTC_NO_ASM */
+
+/* disable FAST mode */
+/* #define LTC_NO_FAST */
+
+/* disable BSWAP on x86 */
+/* #define LTC_NO_BSWAP */
+
+
+#ifdef DROPBEAR_BLOWFISH_CBC
+#define BLOWFISH
+#endif
+
+#ifdef DROPBEAR_AES128_CBC
+#define RIJNDAEL
+#endif
+
+#ifdef DROPBEAR_TWOFISH128_CBC
+#define TWOFISH
+
+/* enabling just TWOFISH_SMALL will make the binary ~1kB smaller, turning on
+ * TWOFISH_TABLES will make it a few kB bigger, but perhaps reduces runtime
+ * memory usage? */
+#define TWOFISH_SMALL
+/*#define TWOFISH_TABLES*/
+#endif
+
+#ifdef DROPBEAR_3DES_CBC
+#define DES
+#endif
+#define CBC
+
+#if defined(DROPBEAR_DSS) && defined(DSS_PROTOK)
+#define SHA512
+#endif
+
+#define SHA1
+
+#ifdef DROPBEAR_MD5_HMAC
+#define MD5
+#endif
+
+#define HMAC
+
+/* Various tidbits of modern neatoness */
+#define BASE64
+
+/* default no functions */
+#define LTC_MUTEX_GLOBAL(x)
+#define LTC_MUTEX_PROTO(x)
+#define LTC_MUTEX_LOCK(x)
+#define LTC_MUTEX_UNLOCK(x)
+#define FORTUNA_POOLS 0
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_custom.h,v $ */
+/* $Revision: 1.17 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/headers/tomcrypt_hash.h b/src/headers/tomcrypt_hash.h
new file mode 100644
index 0000000..a0534f9
--- /dev/null
+++ b/src/headers/tomcrypt_hash.h
@@ -0,0 +1,331 @@
+/* ---- HASH FUNCTIONS ---- */
+#ifdef SHA512
+struct sha512_state {
+    ulong64  length, state[8];
+    unsigned long curlen;
+    unsigned char buf[128];
+};
+#endif
+
+#ifdef SHA256
+struct sha256_state {
+    ulong64 length;
+    ulong32 state[8], curlen;
+    unsigned char buf[64];
+};
+#endif
+
+#ifdef SHA1
+struct sha1_state {
+    ulong64 length;
+    ulong32 state[5], curlen;
+    unsigned char buf[64];
+};
+#endif
+
+#ifdef MD5
+struct md5_state {
+    ulong64 length;
+    ulong32 state[4], curlen;
+    unsigned char buf[64];
+};
+#endif
+
+#ifdef MD4
+struct md4_state {
+    ulong64 length;
+    ulong32 state[4], curlen;
+    unsigned char buf[64];
+};
+#endif
+
+#ifdef TIGER
+struct tiger_state {
+    ulong64 state[3], length;
+    unsigned long curlen;
+    unsigned char buf[64];
+};
+#endif
+
+#ifdef MD2
+struct md2_state {
+    unsigned char chksum[16], X[48], buf[16];
+    unsigned long curlen;
+};
+#endif
+
+#ifdef RIPEMD128
+struct rmd128_state {
+    ulong64 length;
+    unsigned char buf[64];
+    ulong32 curlen, state[4];
+};
+#endif
+
+#ifdef RIPEMD160
+struct rmd160_state {
+    ulong64 length;
+    unsigned char buf[64];
+    ulong32 curlen, state[5];
+};
+#endif
+
+#ifdef WHIRLPOOL
+struct whirlpool_state {
+    ulong64 length, state[8];
+    unsigned char buf[64];
+    ulong32 curlen;
+};
+#endif
+
+#ifdef CHC_HASH
+struct chc_state {
+    ulong64 length;
+    unsigned char state[MAXBLOCKSIZE], buf[MAXBLOCKSIZE];
+    ulong32 curlen;
+};
+#endif
+
+typedef union Hash_state {
+#ifdef CHC_HASH
+    struct chc_state chc;
+#endif
+#ifdef WHIRLPOOL
+    struct whirlpool_state whirlpool;
+#endif
+#ifdef SHA512
+    struct sha512_state sha512;
+#endif
+#ifdef SHA256
+    struct sha256_state sha256;
+#endif
+#ifdef SHA1
+    struct sha1_state   sha1;
+#endif
+#ifdef MD5
+    struct md5_state    md5;
+#endif
+#ifdef MD4
+    struct md4_state    md4;
+#endif
+#ifdef MD2
+    struct md2_state    md2;
+#endif
+#ifdef TIGER
+    struct tiger_state  tiger;
+#endif
+#ifdef RIPEMD128
+    struct rmd128_state rmd128;
+#endif
+#ifdef RIPEMD160
+    struct rmd160_state rmd160;
+#endif
+    void *data;
+} hash_state;
+
+extern  struct ltc_hash_descriptor {
+    /** name of hash */
+    char *name;
+    /** internal ID */
+    unsigned char ID;
+    /** Size of digest in octets */
+    unsigned long hashsize;
+    /** Input block size in octets */
+    unsigned long blocksize;
+    /** ASN.1 OID */
+    unsigned long OID[16];
+    /** Length of DER encoding */
+    unsigned long OIDlen;
+
+    /** Init a hash state
+      @param hash   The hash to initialize
+      @return CRYPT_OK if successful
+    */
+    int (*init)(hash_state *hash);
+    /** Process a block of data 
+      @param hash   The hash state
+      @param in     The data to hash
+      @param inlen  The length of the data (octets)
+      @return CRYPT_OK if successful
+    */
+    int (*process)(hash_state *hash, const unsigned char *in, unsigned long inlen);
+    /** Produce the digest and store it
+      @param hash   The hash state
+      @param out    [out] The destination of the digest
+      @return CRYPT_OK if successful
+    */
+    int (*done)(hash_state *hash, unsigned char *out);
+    /** Self-test
+      @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
+    */
+    int (*test)(void);
+} hash_descriptor[];
+
+#ifdef CHC_HASH
+int chc_register(int cipher);
+int chc_init(hash_state * md);
+int chc_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int chc_done(hash_state * md, unsigned char *hash);
+int chc_test(void);
+extern const struct ltc_hash_descriptor chc_desc;
+#endif
+
+#ifdef WHIRLPOOL
+int whirlpool_init(hash_state * md);
+int whirlpool_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int whirlpool_done(hash_state * md, unsigned char *hash);
+int whirlpool_test(void);
+extern const struct ltc_hash_descriptor whirlpool_desc;
+#endif
+
+#ifdef SHA512
+int sha512_init(hash_state * md);
+int sha512_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int sha512_done(hash_state * md, unsigned char *hash);
+int sha512_test(void);
+extern const struct ltc_hash_descriptor sha512_desc;
+#endif
+
+#ifdef SHA384
+#ifndef SHA512
+   #error SHA512 is required for SHA384
+#endif
+int sha384_init(hash_state * md);
+#define sha384_process sha512_process
+int sha384_done(hash_state * md, unsigned char *hash);
+int sha384_test(void);
+extern const struct ltc_hash_descriptor sha384_desc;
+#endif
+
+#ifdef SHA256
+int sha256_init(hash_state * md);
+int sha256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int sha256_done(hash_state * md, unsigned char *hash);
+int sha256_test(void);
+extern const struct ltc_hash_descriptor sha256_desc;
+
+#ifdef SHA224
+#ifndef SHA256
+   #error SHA256 is required for SHA224
+#endif
+int sha224_init(hash_state * md);
+#define sha224_process sha256_process
+int sha224_done(hash_state * md, unsigned char *hash);
+int sha224_test(void);
+extern const struct ltc_hash_descriptor sha224_desc;
+#endif
+#endif
+
+#ifdef SHA1
+int sha1_init(hash_state * md);
+int sha1_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int sha1_done(hash_state * md, unsigned char *hash);
+int sha1_test(void);
+extern const struct ltc_hash_descriptor sha1_desc;
+#endif
+
+#ifdef MD5
+int md5_init(hash_state * md);
+int md5_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int md5_done(hash_state * md, unsigned char *hash);
+int md5_test(void);
+extern const struct ltc_hash_descriptor md5_desc;
+#endif
+
+#ifdef MD4
+int md4_init(hash_state * md);
+int md4_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int md4_done(hash_state * md, unsigned char *hash);
+int md4_test(void);
+extern const struct ltc_hash_descriptor md4_desc;
+#endif
+
+#ifdef MD2
+int md2_init(hash_state * md);
+int md2_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int md2_done(hash_state * md, unsigned char *hash);
+int md2_test(void);
+extern const struct ltc_hash_descriptor md2_desc;
+#endif
+
+#ifdef TIGER
+int tiger_init(hash_state * md);
+int tiger_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int tiger_done(hash_state * md, unsigned char *hash);
+int tiger_test(void);
+extern const struct ltc_hash_descriptor tiger_desc;
+#endif
+
+#ifdef RIPEMD128
+int rmd128_init(hash_state * md);
+int rmd128_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int rmd128_done(hash_state * md, unsigned char *hash);
+int rmd128_test(void);
+extern const struct ltc_hash_descriptor rmd128_desc;
+#endif
+
+#ifdef RIPEMD160
+int rmd160_init(hash_state * md);
+int rmd160_process(hash_state * md, const unsigned char *in, unsigned long inlen);
+int rmd160_done(hash_state * md, unsigned char *hash);
+int rmd160_test(void);
+extern const struct ltc_hash_descriptor rmd160_desc;
+#endif
+
+int find_hash(const char *name);
+int find_hash_id(unsigned char ID);
+int find_hash_any(const char *name, int digestlen);
+int register_hash(const struct ltc_hash_descriptor *hash);
+int unregister_hash(const struct ltc_hash_descriptor *hash);
+int hash_is_valid(int idx);
+
+LTC_MUTEX_PROTO(ltc_hash_mutex);
+
+int hash_memory(int hash, 
+                const unsigned char *in,  unsigned long inlen, 
+                      unsigned char *out, unsigned long *outlen);
+int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
+                      const unsigned char *in, unsigned long inlen, ...);
+int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen);
+int hash_file(int hash, const char *fname, unsigned char *out, unsigned long *outlen);
+
+/* a simple macro for making hash "process" functions */
+#define HASH_PROCESS(func_name, compress_name, state_var, block_size)                       \
+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);                                                                 \
+    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;                                                                   \
+           }                                                                                \
+           md-> state_var .length += block_size * 8;                                        \
+           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);              \
+           md-> state_var .curlen += 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;                                                                \
+              }                                                                             \
+              md-> state_var .length += 8*block_size;                                       \
+              md-> state_var .curlen = 0;                                                   \
+           }                                                                                \
+       }                                                                                    \
+    }                                                                                       \
+    return CRYPT_OK;                                                                        \
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_hash.h,v $ */
+/* $Revision: 1.12 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/headers/tomcrypt_mac.h b/src/headers/tomcrypt_mac.h
new file mode 100644
index 0000000..411b1bc
--- /dev/null
+++ b/src/headers/tomcrypt_mac.h
@@ -0,0 +1,301 @@
+#ifdef HMAC
+typedef struct Hmac_state {
+     hash_state     md;
+     int            hash;
+     hash_state     hashstate;
+     unsigned char  *key;
+} hmac_state;
+
+int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
+int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen);
+int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen);
+int hmac_test(void);
+int hmac_memory(int hash, 
+                const unsigned char *key, unsigned long keylen,
+                const unsigned char *in,  unsigned long inlen, 
+                      unsigned char *out, unsigned long *outlen);
+int hmac_memory_multi(int hash, 
+                const unsigned char *key,  unsigned long keylen,
+                      unsigned char *out,  unsigned long *outlen,
+                const unsigned char *in,   unsigned long inlen, ...);
+int hmac_file(int hash, const char *fname, const unsigned char *key,
+              unsigned long keylen, 
+              unsigned char *dst, unsigned long *dstlen);
+#endif
+
+#ifdef OMAC
+
+typedef struct {
+   int             cipher_idx, 
+                   buflen,
+                   blklen;
+   unsigned char   block[MAXBLOCKSIZE],
+                   prev[MAXBLOCKSIZE],
+                   Lu[2][MAXBLOCKSIZE];
+   symmetric_key   key;
+} omac_state;
+
+int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen);
+int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen);
+int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen);
+int omac_memory(int cipher, 
+               const unsigned char *key, unsigned long keylen,
+               const unsigned char *in,  unsigned long inlen,
+                     unsigned char *out, unsigned long *outlen);
+int omac_memory_multi(int cipher, 
+                const unsigned char *key, unsigned long keylen,
+                      unsigned char *out, unsigned long *outlen,
+                const unsigned char *in,  unsigned long inlen, ...);
+int omac_file(int cipher, 
+              const unsigned char *key, unsigned long keylen,
+              const          char *filename, 
+                    unsigned char *out, unsigned long *outlen);
+int omac_test(void);
+#endif /* OMAC */
+
+#ifdef PMAC
+
+typedef struct {
+   unsigned char     Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
+                     Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
+                     Lr[MAXBLOCKSIZE],        /* L * x^-1 */
+                     block[MAXBLOCKSIZE],     /* currently accumulated block */
+                     checksum[MAXBLOCKSIZE];  /* current checksum */
+
+   symmetric_key     key;                     /* scheduled key for cipher */
+   unsigned long     block_index;             /* index # for current block */
+   int               cipher_idx,              /* cipher idx */
+                     block_len,               /* length of block */
+                     buflen;                  /* number of bytes in the buffer */
+} pmac_state;
+
+int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen);
+int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen);
+int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
+
+int pmac_memory(int cipher, 
+               const unsigned char *key, unsigned long keylen,
+               const unsigned char *msg, unsigned long msglen,
+                     unsigned char *out, unsigned long *outlen);
+
+int pmac_memory_multi(int cipher, 
+                const unsigned char *key, unsigned long keylen,
+                      unsigned char *out, unsigned long *outlen,
+                const unsigned char *in, unsigned long inlen, ...);
+
+int pmac_file(int cipher, 
+             const unsigned char *key, unsigned long keylen,
+             const          char *filename, 
+                   unsigned char *out, unsigned long *outlen);
+
+int pmac_test(void);
+
+/* internal functions */
+int pmac_ntz(unsigned long x);
+void pmac_shift_xor(pmac_state *pmac);
+
+#endif /* PMAC */
+
+#ifdef EAX_MODE
+
+#if !(defined(OMAC) && defined(CTR))
+   #error EAX_MODE requires OMAC and CTR
+#endif
+
+typedef struct {
+   unsigned char N[MAXBLOCKSIZE];
+   symmetric_CTR ctr;
+   omac_state    headeromac, ctomac;
+} eax_state;
+
+int eax_init(eax_state *eax, int cipher, const unsigned char *key, unsigned long keylen,
+             const unsigned char *nonce, unsigned long noncelen,
+             const unsigned char *header, unsigned long headerlen);
+
+int eax_encrypt(eax_state *eax, const unsigned char *pt, unsigned char *ct, unsigned long length);
+int eax_decrypt(eax_state *eax, const unsigned char *ct, unsigned char *pt, unsigned long length);
+int eax_addheader(eax_state *eax, const unsigned char *header, unsigned long length);
+int eax_done(eax_state *eax, unsigned char *tag, unsigned long *taglen);
+
+int eax_encrypt_authenticate_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+    const unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen);
+
+int eax_decrypt_verify_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+    const unsigned char *ct,     unsigned long ctlen,
+          unsigned char *pt,
+          unsigned char *tag,    unsigned long taglen,
+          int           *stat);
+
+ int eax_test(void);
+#endif /* EAX MODE */
+
+#ifdef OCB_MODE
+typedef struct {
+   unsigned char     L[MAXBLOCKSIZE],         /* L value */
+                     Ls[32][MAXBLOCKSIZE],    /* L shifted by i bits to the left */
+                     Li[MAXBLOCKSIZE],        /* value of Li [current value, we calc from previous recall] */
+                     Lr[MAXBLOCKSIZE],        /* L * x^-1 */
+                     R[MAXBLOCKSIZE],         /* R value */
+                     checksum[MAXBLOCKSIZE];  /* current checksum */
+
+   symmetric_key     key;                     /* scheduled key for cipher */
+   unsigned long     block_index;             /* index # for current block */
+   int               cipher,                  /* cipher idx */
+                     block_len;               /* length of block */
+} ocb_state;
+
+int ocb_init(ocb_state *ocb, int cipher, 
+             const unsigned char *key, unsigned long keylen, const unsigned char *nonce);
+
+int ocb_encrypt(ocb_state *ocb, const unsigned char *pt, unsigned char *ct);
+int ocb_decrypt(ocb_state *ocb, const unsigned char *ct, unsigned char *pt);
+
+int ocb_done_encrypt(ocb_state *ocb, 
+                     const unsigned char *pt,  unsigned long ptlen,
+                           unsigned char *ct, 
+                           unsigned char *tag, unsigned long *taglen);
+
+int ocb_done_decrypt(ocb_state *ocb, 
+                     const unsigned char *ct,  unsigned long ctlen,
+                           unsigned char *pt, 
+                     const unsigned char *tag, unsigned long taglen, int *stat);
+
+int ocb_encrypt_authenticate_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  
+    const unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen);
+
+int ocb_decrypt_verify_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  
+    const unsigned char *ct,     unsigned long ctlen,
+          unsigned char *pt,
+    const unsigned char *tag,    unsigned long taglen,
+          int           *stat);
+
+int ocb_test(void);
+
+/* internal functions */
+void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
+int ocb_ntz(unsigned long x);
+int s_ocb_done(ocb_state *ocb, const unsigned char *pt, unsigned long ptlen,
+               unsigned char *ct, unsigned char *tag, unsigned long *taglen, int mode);
+
+#endif /* OCB_MODE */
+
+#ifdef CCM_MODE
+
+#define CCM_ENCRYPT 0
+#define CCM_DECRYPT 1
+
+int ccm_memory(int cipher,
+    const unsigned char *key,    unsigned long keylen,
+    const unsigned char *nonce,  unsigned long noncelen,
+    const unsigned char *header, unsigned long headerlen,
+          unsigned char *pt,     unsigned long ptlen,
+          unsigned char *ct,
+          unsigned char *tag,    unsigned long *taglen,
+                    int  direction);
+
+int ccm_test(void);
+
+#endif /* CCM_MODE */
+
+#ifdef GCM_MODE
+
+#define GCM_ENCRYPT 0
+#define GCM_DECRYPT 1
+
+#define GCM_MODE_IV    0
+#define GCM_MODE_AAD   1
+#define GCM_MODE_TEXT  2
+
+typedef struct { 
+   symmetric_key       K;
+   unsigned char       H[16],        /* multiplier */
+                       X[16],        /* accumulator */
+                       Y[16],        /* counter */
+                       Y_0[16],      /* initial counter */
+                       buf[16];      /* buffer for stuff */
+
+   int                 cipher,       /* which cipher */
+                       ivmode,       /* Which mode is the IV in? */
+                       mode,         /* mode the GCM code is in */
+                       buflen;       /* length of data in buf */
+
+   ulong64             totlen,       /* 64-bit counter used for IV and AAD */
+                       pttotlen;     /* 64-bit counter for the PT */
+
+#ifdef GCM_TABLES
+   unsigned char       PC[16][256][16];  /* 16 tables of 8x128 */
+#endif  
+
+} gcm_state;
+
+void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *c);
+void gcm_mult_h(gcm_state *gcm, unsigned char *I);
+
+int gcm_init(gcm_state *gcm, int cipher,
+             const unsigned char *key, int keylen);
+
+int gcm_reset(gcm_state *gcm);
+
+int gcm_add_iv(gcm_state *gcm, 
+               const unsigned char *IV,     unsigned long IVlen);
+
+int gcm_add_aad(gcm_state *gcm,
+               const unsigned char *adata,  unsigned long adatalen);
+
+int gcm_process(gcm_state *gcm,
+                     unsigned char *pt,     unsigned long ptlen,
+                     unsigned char *ct,
+                     int direction);
+
+int gcm_done(gcm_state *gcm, 
+                     unsigned char *tag,    unsigned long *taglen);
+
+int gcm_memory(      int           cipher,
+               const unsigned char *key,    unsigned long keylen,
+               const unsigned char *IV,     unsigned long IVlen,
+               const unsigned char *adata,  unsigned long adatalen,
+                     unsigned char *pt,     unsigned long ptlen,
+                     unsigned char *ct, 
+                     unsigned char *tag,    unsigned long *taglen,
+                               int direction);
+int gcm_test(void);
+
+#endif /* GCM_MODE */
+
+#ifdef PELICAN
+
+typedef struct pelican_state
+{
+    symmetric_key K;
+    unsigned char state[16];
+    int           buflen;
+} pelican_state;
+
+int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen);
+int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen);
+int pelican_done(pelican_state *pelmac, unsigned char *out);
+int pelican_test(void);
+
+int pelican_memory(const unsigned char *key, unsigned long keylen,
+                   const unsigned char *in, unsigned long inlen,
+                         unsigned char *out);
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_mac.h,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/mycrypt_macros.h b/src/headers/tomcrypt_macros.h
similarity index 64%
rename from mycrypt_macros.h
rename to src/headers/tomcrypt_macros.h
index 969a961..488931f 100644
--- a/mycrypt_macros.h
+++ b/src/headers/tomcrypt_macros.h
@@ -10,7 +10,11 @@
 /* this is the "32-bit at least" data type 
  * Re-define it to suit your platform but it must be at least 32-bits 
  */
-typedef unsigned long ulong32;
+#if defined(__x86_64__)
+   typedef unsigned ulong32;
+#else
+   typedef unsigned long ulong32;
+#endif
 
 /* ---- HELPER MACROS ---- */
 #ifdef ENDIAN_NEUTRAL
@@ -63,6 +67,23 @@
 
 #ifdef ENDIAN_LITTLE
 
+#if !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
+
+#define STORE32H(x, y)           \
+asm __volatile__ (               \
+   "bswapl %0     \n\t"          \
+   "movl   %0,(%2)\n\t"          \
+   "bswapl %0     \n\t"          \
+      :"=r"(x):"0"(x), "r"(y));
+
+#define LOAD32H(x, y)          \
+asm __volatile__ (             \
+   "movl (%2),%0\n\t"          \
+   "bswapl %0\n\t"             \
+   :"=r"(x): "0"(x), "r"(y));
+
+#else
+
 #define STORE32H(x, y)                                                                     \
      { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255);   \
        (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
@@ -73,6 +94,27 @@
            ((unsigned long)((y)[2] & 255)<<8)  | \
            ((unsigned long)((y)[3] & 255)); }
 
+#endif
+
+
+/* x86_64 processor */
+#if !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__))
+
+#define STORE64H(x, y)           \
+asm __volatile__ (               \
+   "bswapq %0     \n\t"          \
+   "movq   %0,(%2)\n\t"          \
+   "bswapq %0     \n\t"          \
+      :"=r"(x):"0"(x), "r"(y):"0");
+
+#define LOAD64H(x, y)          \
+asm __volatile__ (             \
+   "movq (%2),%0\n\t"          \
+   "bswapq %0\n\t"             \
+   :"=r"(x): "0"(x), "r"(y));
+
+#else
+
 #define STORE64H(x, y)                                                                     \
    { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255);     \
      (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255);     \
@@ -85,10 +127,12 @@
          (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
          (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
 
+#endif
+
 #ifdef ENDIAN_32BITWORD 
 
 #define STORE32L(x, y)        \
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
+     { ulong32  __t = (x); memcpy(y, &__t, 4); }
 
 #define LOAD32L(x, y)         \
      memcpy(&(x), y, 4);
@@ -108,7 +152,7 @@
 #else /* 64-bit words then  */
 
 #define STORE32L(x, y)        \
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
+     { ulong32 __t = (x); memcpy(y, &__t, 4); }
 
 #define LOAD32L(x, y)         \
      { memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
@@ -135,41 +179,41 @@
            ((unsigned long)((y)[0] & 255)); }
 
 #define STORE64L(x, y)                                                                     \
-     { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255);   \
-       (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255);   \
-       (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);   \
-       (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
+   { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255);     \
+     (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255);     \
+     (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255);     \
+     (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
 
-#define LOAD64L(x, y)                                                       \
-     { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
-           (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
-           (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
-           (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
+#define LOAD64L(x, y)                                                      \
+   { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
+         (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
+         (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
+         (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
 
 #ifdef ENDIAN_32BITWORD 
 
 #define STORE32H(x, y)        \
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
+     { ulong32 __t = (x); memcpy(y, &__t, 4); }
 
 #define LOAD32H(x, y)         \
      memcpy(&(x), y, 4);
 
 #define STORE64H(x, y)                                                                     \
-   { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255);     \
-     (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255);     \
-     (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255);     \
-     (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
+     { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255);   \
+       (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255);   \
+       (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255);   \
+       (y)[6] = (unsigned char)(((x)>>8)&255);  (y)[7] = (unsigned char)((x)&255); }
 
-#define LOAD64H(x, y)                                                      \
-   { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
-         (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
-         (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
-         (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
+#define LOAD64H(x, y)                                                       \
+     { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
+           (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
+           (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
+           (((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); }
 
 #else /* 64-bit words then  */
 
 #define STORE32H(x, y)        \
-     { unsigned long __t = (x); memcpy(y, &__t, 4); }
+     { ulong32 __t = (x); memcpy(y, &__t, 4); }
 
 #define LOAD32H(x, y)         \
      { memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
@@ -186,40 +230,118 @@
 #define BSWAP(x)  ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL)  | \
                     ((x>>8)&0x0000FF00UL)  | ((x<<8)&0x00FF0000UL) )
 
-#ifdef _MSC_VER
+
+/* 32-bit Rotates */
+#if defined(_MSC_VER)
 
 /* instrinsic rotate */
 #include <stdlib.h>
 #pragma intrinsic(_lrotr,_lrotl)
 #define ROR(x,n) _lrotr(x,n)
 #define ROL(x,n) _lrotl(x,n)
+#define RORc(x,n) _lrotr(x,n)
+#define ROLc(x,n) _lrotl(x,n)
 
-#elif defined(__GNUC__) && defined(__i386__) && !defined(INTEL_CC)
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
 
-static inline unsigned long ROL(unsigned long word, int i)
+static inline unsigned ROL(unsigned word, int i)
 {
-   __asm__("roll %%cl,%0"
+   asm ("roll %%cl,%0"
       :"=r" (word)
       :"0" (word),"c" (i));
    return word;
 }
 
-static inline unsigned long ROR(unsigned long word, int i)
+static inline unsigned ROR(unsigned word, int i)
 {
-   __asm__("rorl %%cl,%0"
+   asm ("rorl %%cl,%0"
       :"=r" (word)
       :"0" (word),"c" (i));
    return word;
 }
 
+#ifndef LTC_NO_ROLC
+
+static inline unsigned ROLc(unsigned word, const int i)
+{
+   asm ("roll %2,%0"
+      :"=r" (word)
+      :"0" (word),"I" (i));
+   return word;
+}
+
+static inline unsigned RORc(unsigned word, const int i)
+{
+   asm ("rorl %2,%0"
+      :"=r" (word)
+      :"0" (word),"I" (i));
+   return word;
+}
+
+#else
+
+#define ROLc ROL
+#define RORc ROR
+
+#endif
+
 #else
 
 /* rotates the hard way */
 #define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
 #define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
+#define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
+#define RORc(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
 
 #endif
 
+
+/* 64-bit Rotates */
+#if defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM)
+
+static inline unsigned long ROL64(unsigned long word, int i)
+{
+   asm("rolq %%cl,%0"
+      :"=r" (word)
+      :"0" (word),"c" (i));
+   return word;
+}
+
+static inline unsigned long ROR64(unsigned long word, int i)
+{
+   asm("rorq %%cl,%0"
+      :"=r" (word)
+      :"0" (word),"c" (i));
+   return word;
+}
+
+#ifndef LTC_NO_ROLC
+
+static inline unsigned long ROL64c(unsigned long word, const int i)
+{
+   asm("rolq %2,%0"
+      :"=r" (word)
+      :"0" (word),"J" (i));
+   return word;
+}
+
+static inline unsigned long ROR64c(unsigned long word, const int i)
+{
+   asm("rorq %2,%0"
+      :"=r" (word)
+      :"0" (word),"J" (i));
+   return word;
+}
+
+#else /* LTC_NO_ROLC */
+
+#define ROL64c ROL64
+#define ROR64c ROR64
+
+#endif
+
+#else /* Not x86_64  */
+
 #define ROL64(x, y) \
     ( (((x)<<((ulong64)(y)&63)) | \
       (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
@@ -228,6 +350,16 @@
     ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
       ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
 
+#define ROL64c(x, y) \
+    ( (((x)<<((ulong64)(y)&63)) | \
+      (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
+
+#define ROR64c(x, y) \
+    ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
+      ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
+
+#endif
+
 #undef MAX
 #undef MIN
 #define MAX(x, y) ( ((x)>(y))?(x):(y) )
@@ -239,3 +371,7 @@
 #else
    #define byte(x, n) (((x) >> (8 * (n))) & 255)
 #endif   
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_macros.h,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/headers/tomcrypt_misc.h b/src/headers/tomcrypt_misc.h
new file mode 100644
index 0000000..3b44795
--- /dev/null
+++ b/src/headers/tomcrypt_misc.h
@@ -0,0 +1,21 @@
+/* ---- BASE64 Routines ---- */
+#ifdef BASE64
+int base64_encode(const unsigned char *in,  unsigned long len, 
+                        unsigned char *out, unsigned long *outlen);
+
+int base64_decode(const unsigned char *in,  unsigned long len, 
+                        unsigned char *out, unsigned long *outlen);
+#endif
+
+/* ---- MEM routines ---- */
+void zeromem(void *dst, size_t len);
+void burn_stack(unsigned long len);
+
+const char *error_to_string(int err);
+int mpi_to_ltc_error(int err);
+
+extern const char *crypt_build_settings;
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_misc.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/headers/tomcrypt_pk.h b/src/headers/tomcrypt_pk.h
new file mode 100644
index 0000000..4f047de
--- /dev/null
+++ b/src/headers/tomcrypt_pk.h
@@ -0,0 +1,381 @@
+/* ---- NUMBER THEORY ---- */
+#ifdef MPI
+
+#include "ltc_tommath.h"
+
+/* in/out macros */
+#define OUTPUT_BIGNUM(num, out, y, z)                                                             \
+{                                                                                                 \
+      if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; }                                    \
+      z = (unsigned long)mp_unsigned_bin_size(num);                                               \
+      STORE32L(z, out+y);                                                                         \
+      y += 4;                                                                                     \
+      if ((y + z) > *outlen) { return CRYPT_BUFFER_OVERFLOW; }                                    \
+      if ((err = mp_to_unsigned_bin(num, out+y)) != MP_OKAY) { return mpi_to_ltc_error(err); }    \
+      y += z;                                                                                     \
+}
+
+
+#define INPUT_BIGNUM(num, in, x, y, inlen)                       \
+{                                                                \
+     /* load value */                                            \
+     if ((y + 4) > inlen) {                                      \
+        err = CRYPT_INVALID_PACKET;                              \
+        goto error;                                              \
+     }                                                           \
+     LOAD32L(x, in+y);                                           \
+     y += 4;                                                     \
+                                                                 \
+     /* sanity check... */                                       \
+     if ((x+y) > inlen) {                                        \
+        err = CRYPT_INVALID_PACKET;                              \
+        goto error;                                              \
+     }                                                           \
+                                                                 \
+     /* load it */                                               \
+     if ((err = mp_read_unsigned_bin(num, (unsigned char *)in+y, (int)x)) != MP_OKAY) {\
+        err = mpi_to_ltc_error(err);                             \
+        goto error;                                              \
+     }                                                           \
+     y += x;                                                     \
+     if ((err = mp_shrink(num)) != MP_OKAY) {                    \
+        err = mpi_to_ltc_error(err);                             \
+        goto error;                                              \
+     }                                                           \
+}
+
+ int is_prime(mp_int *, int *);
+ int rand_prime(mp_int *N, long len, prng_state *prng, int wprng);
+
+#else
+   #ifdef MRSA
+      #error RSA requires the big int library 
+   #endif
+   #ifdef MECC
+      #error ECC requires the big int library 
+   #endif
+   #ifdef MDH
+      #error DH requires the big int library 
+   #endif
+   #ifdef MDSA
+      #error DSA requires the big int library 
+   #endif
+#endif /* MPI */
+
+
+/* ---- PUBLIC KEY CRYPTO ---- */
+
+#define PK_PRIVATE            0        /* PK private keys */
+#define PK_PUBLIC             1        /* PK public keys */
+
+/* ---- PACKET ---- */
+#ifdef PACKET
+
+void packet_store_header(unsigned char *dst, int section, int subsection);
+int packet_valid_header(unsigned char *src, int section, int subsection);
+
+#endif
+
+
+/* ---- RSA ---- */
+#ifdef MRSA
+
+/* Min and Max RSA key sizes (in bits) */
+#define MIN_RSA_SIZE 1024
+#define MAX_RSA_SIZE 4096
+
+typedef struct Rsa_key {
+    int type;
+    mp_int e, d, N, p, q, qP, dP, dQ;
+} rsa_key;
+
+int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);
+
+int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
+                      unsigned char *out,  unsigned long *outlen, int which,
+                      rsa_key *key);
+
+void rsa_free(rsa_key *key);
+
+/* These use PKCS #1 v2.0 padding */
+int rsa_encrypt_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, rsa_key *key);
+                                        
+int rsa_decrypt_key(const unsigned char *in,       unsigned long inlen,
+                          unsigned char *out,      unsigned long *outlen, 
+                    const unsigned char *lparam,   unsigned long lparamlen,
+                          int            hash_idx, int *stat,
+                          rsa_key       *key);
+
+int rsa_sign_hash(const unsigned char *in,     unsigned long  inlen, 
+                        unsigned char *out,    unsigned long *outlen, 
+                        prng_state    *prng,     int            prng_idx,
+                        int            hash_idx, unsigned long  saltlen,
+                        rsa_key *key);
+
+int rsa_verify_hash(const unsigned char *sig,      unsigned long siglen,
+                    const unsigned char *hash,     unsigned long hashlen,
+                          int            hash_idx, unsigned long saltlen,
+                          int           *stat,     rsa_key      *key);
+
+/* PKCS #1 import/export */
+int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);
+int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);
+                        
+#endif
+
+/* ---- DH Routines ---- */
+#ifdef MDH 
+
+typedef struct Dh_key {
+    int idx, type;
+    mp_int x, y;
+} dh_key;
+
+int dh_test(void);
+void dh_sizes(int *low, int *high);
+int dh_get_size(dh_key *key);
+
+int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key);
+void dh_free(dh_key *key);
+
+int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);
+int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);
+
+int dh_shared_secret(dh_key        *private_key, dh_key        *public_key,
+                     unsigned char *out,         unsigned long *outlen);
+
+int dh_encrypt_key(const unsigned char *in,    unsigned long  keylen,
+                         unsigned char *out,   unsigned long *outlen, 
+                         prng_state    *prng,  int wprng, int hash, 
+                         dh_key        *key);
+
+int dh_decrypt_key(const unsigned char *in,  unsigned long  inlen, 
+                         unsigned char *out, unsigned long *outlen, 
+                         dh_key *key);
+
+int dh_sign_hash(const unsigned char *in,   unsigned long inlen,
+                       unsigned char *out,  unsigned long *outlen,
+                       prng_state    *prng, int wprng, dh_key *key);
+
+int dh_verify_hash(const unsigned char *sig,  unsigned long siglen,
+                   const unsigned char *hash, unsigned long hashlen, 
+                   int *stat, dh_key *key);
+
+
+#endif
+
+/* ---- ECC Routines ---- */
+#ifdef MECC
+typedef struct {
+    mp_int x, y, z;
+} ecc_point;
+
+typedef struct {
+    int type, idx;
+    ecc_point pubkey;
+    mp_int k;
+} ecc_key;
+
+int ecc_test(void);
+void ecc_sizes(int *low, int *high);
+int ecc_get_size(ecc_key *key);
+
+int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);
+void ecc_free(ecc_key *key);
+
+int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key);
+int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key);
+
+int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key, 
+                      unsigned char *out, unsigned long *outlen);
+
+int ecc_encrypt_key(const unsigned char *in,   unsigned long inlen,
+                          unsigned char *out,  unsigned long *outlen, 
+                          prng_state *prng, int wprng, int hash, 
+                          ecc_key *key);
+
+int ecc_decrypt_key(const unsigned char *in,  unsigned long  inlen,
+                          unsigned char *out, unsigned long *outlen, 
+                          ecc_key *key);
+
+int ecc_sign_hash(const unsigned char *in,  unsigned long inlen, 
+                        unsigned char *out, unsigned long *outlen, 
+                        prng_state *prng, int wprng, ecc_key *key);
+
+int ecc_verify_hash(const unsigned char *sig,  unsigned long siglen,
+                    const unsigned char *hash, unsigned long hashlen, 
+                    int *stat, ecc_key *key);
+
+#endif
+
+#ifdef MDSA
+
+typedef struct {
+   int type, qord;
+   mp_int g, q, p, x, y;
+} dsa_key;
+
+int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key);
+void dsa_free(dsa_key *key);
+
+
+int dsa_sign_hash_raw(const unsigned char *in,  unsigned long inlen,
+                                   mp_int *r,   mp_int *s,
+                               prng_state *prng, int wprng, dsa_key *key);
+
+int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
+                        unsigned char *out, unsigned long *outlen,
+                        prng_state *prng, int wprng, dsa_key *key);
+
+int dsa_verify_hash_raw(         mp_int *r,          mp_int *s,
+                    const unsigned char *hash, unsigned long hashlen, 
+                                    int *stat,      dsa_key *key);
+
+int dsa_verify_hash(const unsigned char *sig,  unsigned long siglen,
+                    const unsigned char *hash, unsigned long hashlen, 
+                          int           *stat, dsa_key       *key);
+
+int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key);
+
+int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
+
+int dsa_verify_key(dsa_key *key, int *stat);
+
+#endif
+
+#ifdef LTC_DER
+/* DER handling */
+
+enum {
+ LTC_ASN1_EOL,
+ LTC_ASN1_INTEGER,
+ LTC_ASN1_SHORT_INTEGER,
+ LTC_ASN1_BIT_STRING,
+ LTC_ASN1_OCTET_STRING,
+ LTC_ASN1_NULL,
+ LTC_ASN1_OBJECT_IDENTIFIER,
+ LTC_ASN1_IA5_STRING,
+ LTC_ASN1_PRINTABLE_STRING,
+ LTC_ASN1_UTCTIME,
+
+ LTC_ASN1_CHOICE,
+ LTC_ASN1_SEQUENCE
+};
+
+typedef struct {
+   int           type;
+   void         *data;
+   unsigned long size;
+   int           used;
+} ltc_asn1_list;
+
+#define LTC_SET_ASN1(list, index, Type, Data, Size)  \
+   do {                                              \
+      int LTC_MACRO_temp            = (index);       \
+      ltc_asn1_list *LTC_MACRO_list = (list);        \
+      LTC_MACRO_list[LTC_MACRO_temp].type = (Type);  \
+      LTC_MACRO_list[LTC_MACRO_temp].data = (Data);  \
+      LTC_MACRO_list[LTC_MACRO_temp].size = (Size);  \
+      LTC_MACRO_list[LTC_MACRO_temp].used = 0;       \
+   } while (0);
+
+/* SEQUENCE */
+int der_encode_sequence(ltc_asn1_list *list, unsigned long inlen,
+                        unsigned char *out,  unsigned long *outlen);
+
+int der_decode_sequence(const unsigned char *in,   unsigned long  inlen,
+                              ltc_asn1_list *list, unsigned long  outlen);
+
+int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
+                        unsigned long *outlen);
+
+/* VA list handy helpers */
+int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...);
+int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...);
+
+/* INTEGER */
+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);
+
+/* INTEGER -- handy for 0..2^32-1 values */
+int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num);
+int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen);
+int der_length_short_integer(unsigned long num, unsigned long *outlen);
+
+/* BIT STRING */
+int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+int der_decode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen);
+int der_length_bit_string(unsigned long nbits, unsigned long *outlen);
+
+/* OCTET STRING */
+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);
+
+/* OBJECT IDENTIFIER */
+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);
+unsigned long der_object_identifier_bits(unsigned long x);
+
+/* IA5 STRING */
+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);
+
+int der_ia5_char_encode(int c);
+int der_ia5_value_decode(int v);
+
+/* Printable STRING */
+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);
+
+int der_printable_char_encode(int c);
+int der_printable_value_decode(int v);
+
+/* CHOICE */
+int der_decode_choice(const unsigned char *in,   unsigned long *inlen,
+                            ltc_asn1_list *list, unsigned long  outlen);
+
+/* UTCTime */
+typedef struct {
+   unsigned YY, /* year */
+            MM, /* month */
+            DD, /* day */
+            hh, /* hour */
+            mm, /* minute */
+            ss, /* second */
+            off_dir, /* timezone offset direction 0 == +, 1 == - */
+            off_hh, /* timezone offset hours */
+            off_mm; /* timezone offset minutes */
+} ltc_utctime;
+
+int der_encode_utctime(ltc_utctime *utctime, 
+                       unsigned char *out,   unsigned long *outlen);
+
+int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
+                             ltc_utctime   *out);
+
+int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen);
+
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pk.h,v $ */
+/* $Revision: 1.30 $ */
+/* $Date: 2005/06/19 11:23:03 $ */
diff --git a/mycrypt_pkcs.h b/src/headers/tomcrypt_pkcs.h
similarity index 64%
rename from mycrypt_pkcs.h
rename to src/headers/tomcrypt_pkcs.h
index 9fd0581..8d850de 100644
--- a/mycrypt_pkcs.h
+++ b/src/headers/tomcrypt_pkcs.h
@@ -10,7 +10,7 @@
 int pkcs_1_i2osp(mp_int *n, unsigned long modulus_len, unsigned char *out);
 int pkcs_1_os2ip(mp_int *n, unsigned char *in, unsigned long inlen);
 
-/* *** v2.0 padding */
+/* *** v2.1 padding */
 int pkcs_1_oaep_encode(const unsigned char *msg,    unsigned long msglen,
                        const unsigned char *lparam, unsigned long lparamlen,
                              unsigned long modulus_bitlen, prng_state *prng,
@@ -34,32 +34,6 @@
                             unsigned long saltlen,  int           hash_idx,
                             unsigned long modulus_bitlen, int    *res);
 
-/* *** v1.5 padding */
-/* encryption padding */
-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);
-
-/* note "outlen" is fixed, you have to tell this decoder how big
- * the original message was.  Unlike the OAEP decoder it cannot auto-detect it.
- */
-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);
-
-/* signature padding */
-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);
-
-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);
-
-
 #endif /* PKCS_1 */
 
 /* ===> PKCS #5 -- Password Based Cryptography <=== */
@@ -78,3 +52,7 @@
                 unsigned char *out,            unsigned long *outlen);
 
 #endif  /* PKCS_5 */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_pkcs.h,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/14 11:46:08 $ */
diff --git a/src/headers/tomcrypt_prng.h b/src/headers/tomcrypt_prng.h
new file mode 100644
index 0000000..f96d408
--- /dev/null
+++ b/src/headers/tomcrypt_prng.h
@@ -0,0 +1,195 @@
+/* ---- PRNG Stuff ---- */
+#ifdef YARROW
+struct yarrow_prng {
+    int                   cipher, hash;
+    unsigned char         pool[MAXBLOCKSIZE];
+    symmetric_CTR         ctr;
+};
+#endif
+
+#ifdef RC4
+struct rc4_prng {
+    int x, y;
+    unsigned char buf[256];
+};
+#endif
+
+#ifdef FORTUNA
+struct fortuna_prng {
+    hash_state pool[FORTUNA_POOLS];     /* the  pools */
+
+    symmetric_key skey;
+
+    unsigned char K[32],      /* the current key */
+                  IV[16];     /* IV for CTR mode */
+    
+    unsigned long pool_idx,   /* current pool we will add to */
+                  pool0_len,  /* length of 0'th pool */
+                  wd;            
+
+    ulong64       reset_cnt;  /* number of times we have reset */
+};
+#endif
+
+#ifdef SOBER128
+struct sober128_prng {
+    ulong32      R[17],          /* Working storage for the shift register */
+                 initR[17],      /* saved register contents */ 
+                 konst,          /* key dependent constant */
+                 sbuf;           /* partial word encryption buffer */
+
+    int          nbuf,           /* number of part-word stream bits buffered */
+                 flag,           /* first add_entropy call or not? */
+                 set;            /* did we call add_entropy to set key? */
+    
+};
+#endif
+
+typedef union Prng_state {
+#ifdef YARROW
+    struct yarrow_prng    yarrow;
+#endif
+#ifdef RC4
+    struct rc4_prng       rc4;
+#endif
+#ifdef FORTUNA
+    struct fortuna_prng   fortuna;
+#endif
+#ifdef SOBER128
+    struct sober128_prng  sober128;
+#endif
+} prng_state;
+
+extern struct ltc_prng_descriptor {
+    /** Name of the PRNG */
+    char *name;
+    /** size in bytes of exported state */
+    int  export_size;
+    /** Start a PRNG state
+        @param prng   [out] The state to initialize
+        @return CRYPT_OK if successful
+    */
+    int (*start)(prng_state *prng);
+    /** Add entropy to the PRNG
+        @param in         The entropy
+        @param inlen      Length of the entropy (octets)\
+        @param prng       The PRNG state
+        @return CRYPT_OK if successful
+    */
+    int (*add_entropy)(const unsigned char *in, unsigned long inlen, prng_state *prng);
+    /** Ready a PRNG state to read from
+        @param prng       The PRNG state to ready
+        @return CRYPT_OK if successful
+    */
+    int (*ready)(prng_state *prng);
+    /** Read from the PRNG
+        @param out     [out] Where to store the data
+        @param outlen  Length of data desired (octets)
+        @param prng    The PRNG state to read from
+        @return Number of octets read
+    */
+    unsigned long (*read)(unsigned char *out, unsigned long outlen, prng_state *prng);
+    /** Terminate a PRNG state
+        @param prng   The PRNG state to terminate
+        @return CRYPT_OK if successful
+    */
+    int (*done)(prng_state *prng);
+    /** Export a PRNG state  
+        @param out     [out] The destination for the state
+        @param outlen  [in/out] The max size and resulting size of the PRNG state
+        @param prng    The PRNG to export
+        @return CRYPT_OK if successful
+    */
+    int (*pexport)(unsigned char *out, unsigned long *outlen, prng_state *prng);
+    /** Import a PRNG state
+        @param in      The data to import
+        @param inlen   The length of the data to import (octets)
+        @param prng    The PRNG to initialize/import
+        @return CRYPT_OK if successful
+    */
+    int (*pimport)(const unsigned char *in, unsigned long inlen, prng_state *prng);
+    /** Self-test the PRNG
+        @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+    */
+    int (*test)(void);
+} prng_descriptor[];
+
+#ifdef YARROW
+int yarrow_start(prng_state *prng);
+int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int yarrow_ready(prng_state *prng);
+unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng);
+int yarrow_done(prng_state *prng);
+int  yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
+int  yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int  yarrow_test(void);
+extern const struct ltc_prng_descriptor yarrow_desc;
+#endif
+
+#ifdef FORTUNA
+int fortuna_start(prng_state *prng);
+int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int fortuna_ready(prng_state *prng);
+unsigned long fortuna_read(unsigned char *out, unsigned long outlen, prng_state *prng);
+int fortuna_done(prng_state *prng);
+int  fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
+int  fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int  fortuna_test(void);
+extern const struct ltc_prng_descriptor fortuna_desc;
+#endif
+
+#ifdef RC4
+int rc4_start(prng_state *prng);
+int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int rc4_ready(prng_state *prng);
+unsigned long rc4_read(unsigned char *out, unsigned long outlen, prng_state *prng);
+int  rc4_done(prng_state *prng);
+int  rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
+int  rc4_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int  rc4_test(void);
+extern const struct ltc_prng_descriptor rc4_desc;
+#endif
+
+#ifdef SPRNG
+int sprng_start(prng_state *prng);
+int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int sprng_ready(prng_state *prng);
+unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng);
+int sprng_done(prng_state *prng);
+int  sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
+int  sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int  sprng_test(void);
+extern const struct ltc_prng_descriptor sprng_desc;
+#endif
+
+#ifdef SOBER128
+int sober128_start(prng_state *prng);
+int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int sober128_ready(prng_state *prng);
+unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state *prng);
+int sober128_done(prng_state *prng);
+int  sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
+int  sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
+int  sober128_test(void);
+extern const struct ltc_prng_descriptor sober128_desc;
+#endif
+
+int find_prng(const char *name);
+int register_prng(const struct ltc_prng_descriptor *prng);
+int unregister_prng(const struct ltc_prng_descriptor *prng);
+int prng_is_valid(int idx);
+LTC_MUTEX_PROTO(ltc_prng_mutex);
+
+/* Slow RNG you **might** be able to use to seed a PRNG with.  Be careful as this
+ * might not work on all platforms as planned
+ */
+unsigned long rng_get_bytes(unsigned char *out, 
+                            unsigned long outlen, 
+                            void (*callback)(void));
+
+int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_prng.h,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/headers/tommath_class.h b/src/headers/tommath_class.h
new file mode 100644
index 0000000..02dd7cf
--- /dev/null
+++ b/src/headers/tommath_class.h
@@ -0,0 +1,998 @@
+#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
+#if defined(LTM2)
+#define LTM3
+#endif
+#if defined(LTM1)
+#define LTM2
+#endif
+#define LTM1
+
+#if defined(LTM_ALL)
+#define BN_ERROR_C
+#define BN_FAST_MP_INVMOD_C
+#define BN_FAST_MP_MONTGOMERY_REDUCE_C
+#define BN_FAST_S_MP_MUL_DIGS_C
+#define BN_FAST_S_MP_MUL_HIGH_DIGS_C
+#define BN_FAST_S_MP_SQR_C
+#define BN_MP_2EXPT_C
+#define BN_MP_ABS_C
+#define BN_MP_ADD_C
+#define BN_MP_ADD_D_C
+#define BN_MP_ADDMOD_C
+#define BN_MP_AND_C
+#define BN_MP_CLAMP_C
+#define BN_MP_CLEAR_C
+#define BN_MP_CLEAR_MULTI_C
+#define BN_MP_CMP_C
+#define BN_MP_CMP_D_C
+#define BN_MP_CMP_MAG_C
+#define BN_MP_CNT_LSB_C
+#define BN_MP_COPY_C
+#define BN_MP_COUNT_BITS_C
+#define BN_MP_DIV_C
+#define BN_MP_DIV_2_C
+#define BN_MP_DIV_2D_C
+#define BN_MP_DIV_3_C
+#define BN_MP_DIV_D_C
+#define BN_MP_DR_IS_MODULUS_C
+#define BN_MP_DR_REDUCE_C
+#define BN_MP_DR_SETUP_C
+#define BN_MP_EXCH_C
+#define BN_MP_EXPT_D_C
+#define BN_MP_EXPTMOD_C
+#define BN_MP_EXPTMOD_FAST_C
+#define BN_MP_EXTEUCLID_C
+#define BN_MP_FREAD_C
+#define BN_MP_FWRITE_C
+#define BN_MP_GCD_C
+#define BN_MP_GET_INT_C
+#define BN_MP_GROW_C
+#define BN_MP_INIT_C
+#define BN_MP_INIT_COPY_C
+#define BN_MP_INIT_MULTI_C
+#define BN_MP_INIT_SET_C
+#define BN_MP_INIT_SET_INT_C
+#define BN_MP_INIT_SIZE_C
+#define BN_MP_INVMOD_C
+#define BN_MP_INVMOD_SLOW_C
+#define BN_MP_IS_SQUARE_C
+#define BN_MP_JACOBI_C
+#define BN_MP_KARATSUBA_MUL_C
+#define BN_MP_KARATSUBA_SQR_C
+#define BN_MP_LCM_C
+#define BN_MP_LSHD_C
+#define BN_MP_MOD_C
+#define BN_MP_MOD_2D_C
+#define BN_MP_MOD_D_C
+#define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
+#define BN_MP_MONTGOMERY_REDUCE_C
+#define BN_MP_MONTGOMERY_SETUP_C
+#define BN_MP_MUL_C
+#define BN_MP_MUL_2_C
+#define BN_MP_MUL_2D_C
+#define BN_MP_MUL_D_C
+#define BN_MP_MULMOD_C
+#define BN_MP_N_ROOT_C
+#define BN_MP_NEG_C
+#define BN_MP_OR_C
+#define BN_MP_PRIME_FERMAT_C
+#define BN_MP_PRIME_IS_DIVISIBLE_C
+#define BN_MP_PRIME_IS_PRIME_C
+#define BN_MP_PRIME_MILLER_RABIN_C
+#define BN_MP_PRIME_NEXT_PRIME_C
+#define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
+#define BN_MP_PRIME_RANDOM_EX_C
+#define BN_MP_RADIX_SIZE_C
+#define BN_MP_RADIX_SMAP_C
+#define BN_MP_RAND_C
+#define BN_MP_READ_RADIX_C
+#define BN_MP_READ_SIGNED_BIN_C
+#define BN_MP_READ_UNSIGNED_BIN_C
+#define BN_MP_REDUCE_C
+#define BN_MP_REDUCE_2K_C
+#define BN_MP_REDUCE_2K_L_C
+#define BN_MP_REDUCE_2K_SETUP_C
+#define BN_MP_REDUCE_2K_SETUP_L_C
+#define BN_MP_REDUCE_IS_2K_C
+#define BN_MP_REDUCE_IS_2K_L_C
+#define BN_MP_REDUCE_SETUP_C
+#define BN_MP_RSHD_C
+#define BN_MP_SET_C
+#define BN_MP_SET_INT_C
+#define BN_MP_SHRINK_C
+#define BN_MP_SIGNED_BIN_SIZE_C
+#define BN_MP_SQR_C
+#define BN_MP_SQRMOD_C
+#define BN_MP_SQRT_C
+#define BN_MP_SUB_C
+#define BN_MP_SUB_D_C
+#define BN_MP_SUBMOD_C
+#define BN_MP_TO_SIGNED_BIN_C
+#define BN_MP_TO_SIGNED_BIN_N_C
+#define BN_MP_TO_UNSIGNED_BIN_C
+#define BN_MP_TO_UNSIGNED_BIN_N_C
+#define BN_MP_TOOM_MUL_C
+#define BN_MP_TOOM_SQR_C
+#define BN_MP_TORADIX_C
+#define BN_MP_TORADIX_N_C
+#define BN_MP_UNSIGNED_BIN_SIZE_C
+#define BN_MP_XOR_C
+#define BN_MP_ZERO_C
+#define BN_PRIME_TAB_C
+#define BN_REVERSE_C
+#define BN_S_MP_ADD_C
+#define BN_S_MP_EXPTMOD_C
+#define BN_S_MP_MUL_DIGS_C
+#define BN_S_MP_MUL_HIGH_DIGS_C
+#define BN_S_MP_SQR_C
+#define BN_S_MP_SUB_C
+#define BNCORE_C
+#endif
+
+#if defined(BN_ERROR_C)
+   #define BN_MP_ERROR_TO_STRING_C
+#endif
+
+#if defined(BN_FAST_MP_INVMOD_C)
+   #define BN_MP_ISEVEN_C
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_COPY_C
+   #define BN_MP_MOD_C
+   #define BN_MP_SET_C
+   #define BN_MP_DIV_2_C
+   #define BN_MP_ISODD_C
+   #define BN_MP_SUB_C
+   #define BN_MP_CMP_C
+   #define BN_MP_ISZERO_C
+   #define BN_MP_CMP_D_C
+   #define BN_MP_ADD_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_MULTI_C
+#endif
+
+#if defined(BN_FAST_MP_MONTGOMERY_REDUCE_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_FAST_S_MP_MUL_DIGS_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_FAST_S_MP_MUL_HIGH_DIGS_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_FAST_S_MP_SQR_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_2EXPT_C)
+   #define BN_MP_ZERO_C
+   #define BN_MP_GROW_C
+#endif
+
+#if defined(BN_MP_ABS_C)
+   #define BN_MP_COPY_C
+#endif
+
+#if defined(BN_MP_ADD_C)
+   #define BN_S_MP_ADD_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_MP_ADD_D_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_SUB_D_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_ADDMOD_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_ADD_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_MOD_C
+#endif
+
+#if defined(BN_MP_AND_C)
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_CLAMP_C)
+#endif
+
+#if defined(BN_MP_CLEAR_C)
+#endif
+
+#if defined(BN_MP_CLEAR_MULTI_C)
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_CMP_C)
+   #define BN_MP_CMP_MAG_C
+#endif
+
+#if defined(BN_MP_CMP_D_C)
+#endif
+
+#if defined(BN_MP_CMP_MAG_C)
+#endif
+
+#if defined(BN_MP_CNT_LSB_C)
+   #define BN_MP_ISZERO_C
+#endif
+
+#if defined(BN_MP_COPY_C)
+   #define BN_MP_GROW_C
+#endif
+
+#if defined(BN_MP_COUNT_BITS_C)
+#endif
+
+#if defined(BN_MP_DIV_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_MP_COPY_C
+   #define BN_MP_ZERO_C
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_SET_C
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_ABS_C
+   #define BN_MP_MUL_2D_C
+   #define BN_MP_CMP_C
+   #define BN_MP_SUB_C
+   #define BN_MP_ADD_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_MULTI_C
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_INIT_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_MUL_D_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_DIV_2_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_DIV_2D_C)
+   #define BN_MP_COPY_C
+   #define BN_MP_ZERO_C
+   #define BN_MP_INIT_C
+   #define BN_MP_MOD_2D_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+#endif
+
+#if defined(BN_MP_DIV_3_C)
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_DIV_D_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_COPY_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_DIV_3_C
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_DR_IS_MODULUS_C)
+#endif
+
+#if defined(BN_MP_DR_REDUCE_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_MP_DR_SETUP_C)
+#endif
+
+#if defined(BN_MP_EXCH_C)
+#endif
+
+#if defined(BN_MP_EXPT_D_C)
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_SET_C
+   #define BN_MP_SQR_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_MUL_C
+#endif
+
+#if defined(BN_MP_EXPTMOD_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_INVMOD_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_ABS_C
+   #define BN_MP_CLEAR_MULTI_C
+   #define BN_MP_REDUCE_IS_2K_L_C
+   #define BN_S_MP_EXPTMOD_C
+   #define BN_MP_DR_IS_MODULUS_C
+   #define BN_MP_REDUCE_IS_2K_C
+   #define BN_MP_ISODD_C
+   #define BN_MP_EXPTMOD_FAST_C
+#endif
+
+#if defined(BN_MP_EXPTMOD_FAST_C)
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_INIT_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_MONTGOMERY_SETUP_C
+   #define BN_FAST_MP_MONTGOMERY_REDUCE_C
+   #define BN_MP_MONTGOMERY_REDUCE_C
+   #define BN_MP_DR_SETUP_C
+   #define BN_MP_DR_REDUCE_C
+   #define BN_MP_REDUCE_2K_SETUP_C
+   #define BN_MP_REDUCE_2K_C
+   #define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
+   #define BN_MP_MULMOD_C
+   #define BN_MP_SET_C
+   #define BN_MP_MOD_C
+   #define BN_MP_COPY_C
+   #define BN_MP_SQR_C
+   #define BN_MP_MUL_C
+   #define BN_MP_EXCH_C
+#endif
+
+#if defined(BN_MP_EXTEUCLID_C)
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_SET_C
+   #define BN_MP_COPY_C
+   #define BN_MP_ISZERO_C
+   #define BN_MP_DIV_C
+   #define BN_MP_MUL_C
+   #define BN_MP_SUB_C
+   #define BN_MP_NEG_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_MULTI_C
+#endif
+
+#if defined(BN_MP_FREAD_C)
+   #define BN_MP_ZERO_C
+   #define BN_MP_S_RMAP_C
+   #define BN_MP_MUL_D_C
+   #define BN_MP_ADD_D_C
+   #define BN_MP_CMP_D_C
+#endif
+
+#if defined(BN_MP_FWRITE_C)
+   #define BN_MP_RADIX_SIZE_C
+   #define BN_MP_TORADIX_C
+#endif
+
+#if defined(BN_MP_GCD_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_ABS_C
+   #define BN_MP_ZERO_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_CNT_LSB_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_MP_EXCH_C
+   #define BN_S_MP_SUB_C
+   #define BN_MP_MUL_2D_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_GET_INT_C)
+#endif
+
+#if defined(BN_MP_GROW_C)
+#endif
+
+#if defined(BN_MP_INIT_C)
+#endif
+
+#if defined(BN_MP_INIT_COPY_C)
+   #define BN_MP_COPY_C
+#endif
+
+#if defined(BN_MP_INIT_MULTI_C)
+   #define BN_MP_ERR_C
+   #define BN_MP_INIT_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_INIT_SET_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_SET_C
+#endif
+
+#if defined(BN_MP_INIT_SET_INT_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_SET_INT_C
+#endif
+
+#if defined(BN_MP_INIT_SIZE_C)
+   #define BN_MP_INIT_C
+#endif
+
+#if defined(BN_MP_INVMOD_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_ISODD_C
+   #define BN_FAST_MP_INVMOD_C
+   #define BN_MP_INVMOD_SLOW_C
+#endif
+
+#if defined(BN_MP_INVMOD_SLOW_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_MOD_C
+   #define BN_MP_COPY_C
+   #define BN_MP_ISEVEN_C
+   #define BN_MP_SET_C
+   #define BN_MP_DIV_2_C
+   #define BN_MP_ISODD_C
+   #define BN_MP_ADD_C
+   #define BN_MP_SUB_C
+   #define BN_MP_CMP_C
+   #define BN_MP_CMP_D_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_MULTI_C
+#endif
+
+#if defined(BN_MP_IS_SQUARE_C)
+   #define BN_MP_MOD_D_C
+   #define BN_MP_INIT_SET_INT_C
+   #define BN_MP_MOD_C
+   #define BN_MP_GET_INT_C
+   #define BN_MP_SQRT_C
+   #define BN_MP_SQR_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_JACOBI_C)
+   #define BN_MP_CMP_D_C
+   #define BN_MP_ISZERO_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_CNT_LSB_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_MOD_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_KARATSUBA_MUL_C)
+   #define BN_MP_MUL_C
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_SUB_C
+   #define BN_MP_ADD_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_KARATSUBA_SQR_C)
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_SQR_C
+   #define BN_MP_SUB_C
+   #define BN_S_MP_ADD_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_ADD_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_LCM_C)
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_GCD_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_MP_DIV_C
+   #define BN_MP_MUL_C
+   #define BN_MP_CLEAR_MULTI_C
+#endif
+
+#if defined(BN_MP_LSHD_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_RSHD_C
+#endif
+
+#if defined(BN_MP_MOD_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_DIV_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_ADD_C
+   #define BN_MP_EXCH_C
+#endif
+
+#if defined(BN_MP_MOD_2D_C)
+   #define BN_MP_ZERO_C
+   #define BN_MP_COPY_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_MOD_D_C)
+   #define BN_MP_DIV_D_C
+#endif
+
+#if defined(BN_MP_MONTGOMERY_CALC_NORMALIZATION_C)
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_2EXPT_C
+   #define BN_MP_SET_C
+   #define BN_MP_MUL_2_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_MP_MONTGOMERY_REDUCE_C)
+   #define BN_FAST_MP_MONTGOMERY_REDUCE_C
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_MP_MONTGOMERY_SETUP_C)
+#endif
+
+#if defined(BN_MP_MUL_C)
+   #define BN_MP_TOOM_MUL_C
+   #define BN_MP_KARATSUBA_MUL_C
+   #define BN_FAST_S_MP_MUL_DIGS_C
+   #define BN_S_MP_MUL_C
+   #define BN_S_MP_MUL_DIGS_C
+#endif
+
+#if defined(BN_MP_MUL_2_C)
+   #define BN_MP_GROW_C
+#endif
+
+#if defined(BN_MP_MUL_2D_C)
+   #define BN_MP_COPY_C
+   #define BN_MP_GROW_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_MUL_D_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_MULMOD_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_MUL_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_MOD_C
+#endif
+
+#if defined(BN_MP_N_ROOT_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_SET_C
+   #define BN_MP_COPY_C
+   #define BN_MP_EXPT_D_C
+   #define BN_MP_MUL_C
+   #define BN_MP_SUB_C
+   #define BN_MP_MUL_D_C
+   #define BN_MP_DIV_C
+   #define BN_MP_CMP_C
+   #define BN_MP_SUB_D_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_NEG_C)
+   #define BN_MP_COPY_C
+   #define BN_MP_ISZERO_C
+#endif
+
+#if defined(BN_MP_OR_C)
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_PRIME_FERMAT_C)
+   #define BN_MP_CMP_D_C
+   #define BN_MP_INIT_C
+   #define BN_MP_EXPTMOD_C
+   #define BN_MP_CMP_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_PRIME_IS_DIVISIBLE_C)
+   #define BN_MP_MOD_D_C
+#endif
+
+#if defined(BN_MP_PRIME_IS_PRIME_C)
+   #define BN_MP_CMP_D_C
+   #define BN_MP_PRIME_IS_DIVISIBLE_C
+   #define BN_MP_INIT_C
+   #define BN_MP_SET_C
+   #define BN_MP_PRIME_MILLER_RABIN_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_PRIME_MILLER_RABIN_C)
+   #define BN_MP_CMP_D_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_SUB_D_C
+   #define BN_MP_CNT_LSB_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_EXPTMOD_C
+   #define BN_MP_CMP_C
+   #define BN_MP_SQRMOD_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_PRIME_NEXT_PRIME_C)
+   #define BN_MP_CMP_D_C
+   #define BN_MP_SET_C
+   #define BN_MP_SUB_D_C
+   #define BN_MP_ISEVEN_C
+   #define BN_MP_MOD_D_C
+   #define BN_MP_INIT_C
+   #define BN_MP_ADD_D_C
+   #define BN_MP_PRIME_MILLER_RABIN_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_PRIME_RABIN_MILLER_TRIALS_C)
+#endif
+
+#if defined(BN_MP_PRIME_RANDOM_EX_C)
+   #define BN_MP_READ_UNSIGNED_BIN_C
+   #define BN_MP_PRIME_IS_PRIME_C
+   #define BN_MP_SUB_D_C
+   #define BN_MP_DIV_2_C
+   #define BN_MP_MUL_2_C
+   #define BN_MP_ADD_D_C
+#endif
+
+#if defined(BN_MP_RADIX_SIZE_C)
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_ISZERO_C
+   #define BN_MP_DIV_D_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_RADIX_SMAP_C)
+   #define BN_MP_S_RMAP_C
+#endif
+
+#if defined(BN_MP_RAND_C)
+   #define BN_MP_ZERO_C
+   #define BN_MP_ADD_D_C
+   #define BN_MP_LSHD_C
+#endif
+
+#if defined(BN_MP_READ_RADIX_C)
+   #define BN_MP_ZERO_C
+   #define BN_MP_S_RMAP_C
+   #define BN_MP_MUL_D_C
+   #define BN_MP_ADD_D_C
+   #define BN_MP_ISZERO_C
+#endif
+
+#if defined(BN_MP_READ_SIGNED_BIN_C)
+   #define BN_MP_READ_UNSIGNED_BIN_C
+#endif
+
+#if defined(BN_MP_READ_UNSIGNED_BIN_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_ZERO_C
+   #define BN_MP_MUL_2D_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_REDUCE_C)
+   #define BN_MP_REDUCE_SETUP_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_MUL_C
+   #define BN_S_MP_MUL_HIGH_DIGS_C
+   #define BN_FAST_S_MP_MUL_HIGH_DIGS_C
+   #define BN_MP_MOD_2D_C
+   #define BN_S_MP_MUL_DIGS_C
+   #define BN_MP_SUB_C
+   #define BN_MP_CMP_D_C
+   #define BN_MP_SET_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_ADD_C
+   #define BN_MP_CMP_C
+   #define BN_S_MP_SUB_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_REDUCE_2K_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_MUL_D_C
+   #define BN_S_MP_ADD_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_REDUCE_2K_L_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_MUL_C
+   #define BN_S_MP_ADD_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_REDUCE_2K_SETUP_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_2EXPT_C
+   #define BN_MP_CLEAR_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_MP_REDUCE_2K_SETUP_L_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_2EXPT_C
+   #define BN_MP_COUNT_BITS_C
+   #define BN_S_MP_SUB_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_REDUCE_IS_2K_C)
+   #define BN_MP_REDUCE_2K_C
+   #define BN_MP_COUNT_BITS_C
+#endif
+
+#if defined(BN_MP_REDUCE_IS_2K_L_C)
+#endif
+
+#if defined(BN_MP_REDUCE_SETUP_C)
+   #define BN_MP_2EXPT_C
+   #define BN_MP_DIV_C
+#endif
+
+#if defined(BN_MP_RSHD_C)
+   #define BN_MP_ZERO_C
+#endif
+
+#if defined(BN_MP_SET_C)
+   #define BN_MP_ZERO_C
+#endif
+
+#if defined(BN_MP_SET_INT_C)
+   #define BN_MP_ZERO_C
+   #define BN_MP_MUL_2D_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_SHRINK_C)
+#endif
+
+#if defined(BN_MP_SIGNED_BIN_SIZE_C)
+   #define BN_MP_UNSIGNED_BIN_SIZE_C
+#endif
+
+#if defined(BN_MP_SQR_C)
+   #define BN_MP_TOOM_SQR_C
+   #define BN_MP_KARATSUBA_SQR_C
+   #define BN_FAST_S_MP_SQR_C
+   #define BN_S_MP_SQR_C
+#endif
+
+#if defined(BN_MP_SQRMOD_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_SQR_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_MOD_C
+#endif
+
+#if defined(BN_MP_SQRT_C)
+   #define BN_MP_N_ROOT_C
+   #define BN_MP_ISZERO_C
+   #define BN_MP_ZERO_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_DIV_C
+   #define BN_MP_ADD_C
+   #define BN_MP_DIV_2_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_SUB_C)
+   #define BN_S_MP_ADD_C
+   #define BN_MP_CMP_MAG_C
+   #define BN_S_MP_SUB_C
+#endif
+
+#if defined(BN_MP_SUB_D_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_ADD_D_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_MP_SUBMOD_C)
+   #define BN_MP_INIT_C
+   #define BN_MP_SUB_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_MOD_C
+#endif
+
+#if defined(BN_MP_TO_SIGNED_BIN_C)
+   #define BN_MP_TO_UNSIGNED_BIN_C
+#endif
+
+#if defined(BN_MP_TO_SIGNED_BIN_N_C)
+   #define BN_MP_SIGNED_BIN_SIZE_C
+   #define BN_MP_TO_SIGNED_BIN_C
+#endif
+
+#if defined(BN_MP_TO_UNSIGNED_BIN_C)
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_ISZERO_C
+   #define BN_MP_DIV_2D_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_TO_UNSIGNED_BIN_N_C)
+   #define BN_MP_UNSIGNED_BIN_SIZE_C
+   #define BN_MP_TO_UNSIGNED_BIN_C
+#endif
+
+#if defined(BN_MP_TOOM_MUL_C)
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_MOD_2D_C
+   #define BN_MP_COPY_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_MUL_C
+   #define BN_MP_MUL_2_C
+   #define BN_MP_ADD_C
+   #define BN_MP_SUB_C
+   #define BN_MP_DIV_2_C
+   #define BN_MP_MUL_2D_C
+   #define BN_MP_MUL_D_C
+   #define BN_MP_DIV_3_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_CLEAR_MULTI_C
+#endif
+
+#if defined(BN_MP_TOOM_SQR_C)
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_MOD_2D_C
+   #define BN_MP_COPY_C
+   #define BN_MP_RSHD_C
+   #define BN_MP_SQR_C
+   #define BN_MP_MUL_2_C
+   #define BN_MP_ADD_C
+   #define BN_MP_SUB_C
+   #define BN_MP_DIV_2_C
+   #define BN_MP_MUL_2D_C
+   #define BN_MP_MUL_D_C
+   #define BN_MP_DIV_3_C
+   #define BN_MP_LSHD_C
+   #define BN_MP_CLEAR_MULTI_C
+#endif
+
+#if defined(BN_MP_TORADIX_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_DIV_D_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_S_RMAP_C
+#endif
+
+#if defined(BN_MP_TORADIX_N_C)
+   #define BN_MP_ISZERO_C
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_DIV_D_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_S_RMAP_C
+#endif
+
+#if defined(BN_MP_UNSIGNED_BIN_SIZE_C)
+   #define BN_MP_COUNT_BITS_C
+#endif
+
+#if defined(BN_MP_XOR_C)
+   #define BN_MP_INIT_COPY_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_MP_ZERO_C)
+#endif
+
+#if defined(BN_PRIME_TAB_C)
+#endif
+
+#if defined(BN_REVERSE_C)
+#endif
+
+#if defined(BN_S_MP_ADD_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BN_S_MP_EXPTMOD_C)
+   #define BN_MP_COUNT_BITS_C
+   #define BN_MP_INIT_C
+   #define BN_MP_CLEAR_C
+   #define BN_MP_REDUCE_SETUP_C
+   #define BN_MP_REDUCE_C
+   #define BN_MP_REDUCE_2K_SETUP_L_C
+   #define BN_MP_REDUCE_2K_L_C
+   #define BN_MP_MOD_C
+   #define BN_MP_COPY_C
+   #define BN_MP_SQR_C
+   #define BN_MP_MUL_C
+   #define BN_MP_SET_C
+   #define BN_MP_EXCH_C
+#endif
+
+#if defined(BN_S_MP_MUL_DIGS_C)
+   #define BN_FAST_S_MP_MUL_DIGS_C
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_S_MP_MUL_HIGH_DIGS_C)
+   #define BN_FAST_S_MP_MUL_HIGH_DIGS_C
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_S_MP_SQR_C)
+   #define BN_MP_INIT_SIZE_C
+   #define BN_MP_CLAMP_C
+   #define BN_MP_EXCH_C
+   #define BN_MP_CLEAR_C
+#endif
+
+#if defined(BN_S_MP_SUB_C)
+   #define BN_MP_GROW_C
+   #define BN_MP_CLAMP_C
+#endif
+
+#if defined(BNCORE_C)
+#endif
+
+#ifdef LTM3
+#define LTM_LAST
+#endif
+#include <tommath_superclass.h>
+#include <tommath_class.h>
+#else
+#define LTM_LAST
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tommath_class.h,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/headers/tommath_superclass.h b/src/headers/tommath_superclass.h
new file mode 100644
index 0000000..89f3f57
--- /dev/null
+++ b/src/headers/tommath_superclass.h
@@ -0,0 +1,80 @@
+/* super class file for PK algos */
+
+/* default ... include all MPI */
+#ifndef SC_RSA_1
+
+#define LTM_ALL
+
+#endif
+
+/* RSA only (does not support DH/DSA/ECC) */
+/* #define SC_RSA_1 */
+
+/* For reference.... On an Athlon64 optimizing for speed...
+
+   LTM's mpi.o with all functions [striped] is 142KiB in size.
+
+*/
+
+/* Works for RSA only, mpi.o is 68KiB */
+#ifdef SC_RSA_1
+   #define BN_MP_SHRINK_C
+   #define BN_MP_LCM_C
+   #define BN_MP_PRIME_RANDOM_EX_C
+   #define BN_MP_INVMOD_C
+   #define BN_MP_GCD_C
+   #define BN_MP_MOD_C
+   #define BN_MP_MULMOD_C
+   #define BN_MP_ADDMOD_C
+   #define BN_MP_EXPTMOD_C
+   #define BN_MP_SET_INT_C
+   #define BN_MP_INIT_MULTI_C
+   #define BN_MP_CLEAR_MULTI_C
+   #define BN_MP_UNSIGNED_BIN_SIZE_C
+   #define BN_MP_TO_UNSIGNED_BIN_C
+   #define BN_MP_MOD_D_C
+   #define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
+   #define BN_REVERSE_C
+   #define BN_PRIME_TAB_C
+
+   /* other modifiers */
+   #define BN_MP_DIV_SMALL                    /* Slower division, not critical */
+
+   /* here we are on the last pass so we turn things off.  The functions classes are still there
+    * but we remove them specifically from the build.  This also invokes tweaks in functions
+    * like removing support for even moduli, etc...
+    */
+#ifdef LTM_LAST
+   #undef  BN_MP_TOOM_MUL_C
+   #undef  BN_MP_TOOM_SQR_C
+   #undef  BN_MP_KARATSUBA_MUL_C
+   #undef  BN_MP_KARATSUBA_SQR_C
+   #undef  BN_MP_REDUCE_C
+   #undef  BN_MP_REDUCE_SETUP_C
+   #undef  BN_MP_DR_IS_MODULUS_C
+   #undef  BN_MP_DR_SETUP_C
+   #undef  BN_MP_DR_REDUCE_C
+   #undef  BN_MP_REDUCE_IS_2K_C
+   #undef  BN_MP_REDUCE_2K_SETUP_C
+   #undef  BN_MP_REDUCE_2K_C
+   #undef  BN_S_MP_EXPTMOD_C
+   #undef  BN_MP_DIV_3_C
+   #undef  BN_S_MP_MUL_HIGH_DIGS_C
+   #undef  BN_FAST_S_MP_MUL_HIGH_DIGS_C
+   #undef  BN_FAST_MP_INVMOD_C
+
+   /* To safely undefine these you have to make sure your RSA key won't exceed the Comba threshold
+    * which is roughly 255 digits [7140 bits for 32-bit machines, 15300 bits for 64-bit machines] 
+    * which means roughly speaking you can handle upto 2536-bit RSA keys with these defined without
+    * trouble.  
+    */
+   #undef  BN_S_MP_MUL_DIGS_C
+   #undef  BN_S_MP_SQR_C
+   #undef  BN_MP_MONTGOMERY_REDUCE_C
+#endif
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/headers/tommath_superclass.h,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/14 13:27:20 $ */
diff --git a/src/mac/hmac/hmac_done.c b/src/mac/hmac/hmac_done.c
new file mode 100644
index 0000000..f64d044
--- /dev/null
+++ b/src/mac/hmac/hmac_done.c
@@ -0,0 +1,109 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file hmac_done.c
+  HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
+*/
+
+#ifdef HMAC
+
+#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
+
+/**
+   Terminate an HMAC session
+   @param hmac    The HMAC state
+   @param out     [out] The destination of the HMAC authentication tag
+   @param outlen  [in/out]  The max size and resulting size of the HMAC authentication tag
+   @return CRYPT_OK if successful
+*/
+int hmac_done(hmac_state *hmac, unsigned char *out, unsigned long *outlen)
+{
+    unsigned char *buf, *isha;
+    unsigned long hashsize, i;
+    int hash, err;
+
+    LTC_ARGCHK(hmac  != NULL);
+    LTC_ARGCHK(out   != NULL);
+
+    /* test hash */
+    hash = hmac->hash;
+    if((err = hash_is_valid(hash)) != CRYPT_OK) {
+        return err;
+    }
+
+    /* get the hash message digest size */
+    hashsize = hash_descriptor[hash].hashsize;
+
+    /* allocate buffers */
+    buf  = XMALLOC(HMAC_BLOCKSIZE);
+    isha = XMALLOC(hashsize);
+    if (buf == NULL || isha == NULL) { 
+       if (buf != NULL) {
+          XFREE(buf);
+       } 
+       if (isha != NULL) {
+          XFREE(isha);
+       }  
+       return CRYPT_MEM;
+    }
+
+    /* Get the hash of the first HMAC vector plus the data */
+    if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    /* Create the second HMAC vector vector for step (3) */
+    for(i=0; i < HMAC_BLOCKSIZE; i++) {
+        buf[i] = hmac->key[i] ^ 0x5C;
+    }
+
+    /* Now calculate the "outer" hash for step (5), (6), and (7) */
+    if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    if ((err = hash_descriptor[hash].done(&hmac->md, buf)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    /* copy to output  */
+    for (i = 0; i < hashsize && i < *outlen; i++) {
+        out[i] = buf[i];
+    }
+    *outlen = i;
+
+    err = CRYPT_OK;
+LBL_ERR:
+    XFREE(hmac->key);
+#ifdef LTC_CLEAN_STACK
+    zeromem(isha, hashsize);
+    zeromem(buf,  hashsize);
+    zeromem(hmac, sizeof(*hmac));
+#endif
+
+    XFREE(isha);
+    XFREE(buf);
+
+    return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_done.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/hmac/hmac_file.c b/src/mac/hmac/hmac_file.c
new file mode 100644
index 0000000..f88d692
--- /dev/null
+++ b/src/mac/hmac/hmac_file.c
@@ -0,0 +1,93 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file hmac_file.c
+  HMAC support, process a file, Tom St Denis/Dobes Vandermeer
+*/
+
+#ifdef HMAC
+
+/**
+  HMAC a file
+  @param hash     The index of the hash you wish to use
+  @param fname    The name of the file you wish to HMAC
+  @param key      The secret key
+  @param keylen   The length of the secret key
+  @param out      [out] The HMAC authentication tag
+  @param outlen   [in/out]  The max size and resulting size of the authentication tag
+  @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
+*/
+int hmac_file(int hash, const char *fname, 
+              const unsigned char *key, unsigned long keylen, 
+                    unsigned char *out, unsigned long *outlen)
+{
+#ifdef LTC_NO_FILE
+    return CRYPT_NOP;
+#else
+   hmac_state hmac;
+   FILE *in;
+   unsigned char buf[512];
+   size_t x;
+   int err;
+
+   LTC_ARGCHK(fname  != NULL);
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   
+   if((err = hash_is_valid(hash)) != CRYPT_OK) {
+       return err;
+   }
+
+   if ((err = hmac_init(&hmac, hash, key, keylen)) != CRYPT_OK) {
+       return err;
+   }
+
+   in = fopen(fname, "rb");
+   if (in == NULL) {
+      return CRYPT_FILE_NOTFOUND;
+   }
+
+   /* process the file contents */
+   do {
+      x = fread(buf, 1, sizeof(buf), in);
+      if ((err = hmac_process(&hmac, buf, (unsigned long)x)) != CRYPT_OK) {
+         /* we don't trap this error since we're already returning an error! */
+         fclose(in);
+         return err;
+      }
+   } while (x == sizeof(buf));
+
+   if (fclose(in) != 0) {
+      return CRYPT_ERROR;
+   }
+
+   /* get final hmac */
+   if ((err = hmac_done(&hmac, out, outlen)) != CRYPT_OK) {
+      return err;
+   }
+
+#ifdef LTC_CLEAN_STACK
+   /* clear memory */
+   zeromem(buf, sizeof(buf));
+#endif   
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_file.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/hmac/hmac_init.c b/src/mac/hmac/hmac_init.c
new file mode 100644
index 0000000..e64d47f
--- /dev/null
+++ b/src/mac/hmac/hmac_init.c
@@ -0,0 +1,112 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file hmac_init.c
+  HMAC support, initialize state, Tom St Denis/Dobes Vandermeer 
+*/
+
+#ifdef HMAC
+
+#define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
+
+/**
+   Initialize an HMAC context.
+   @param hmac     The HMAC state 
+   @param hash     The index of the hash you want to use 
+   @param key      The secret key
+   @param keylen   The length of the secret key (octets)
+   @return CRYPT_OK if successful
+*/
+int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen)
+{
+    unsigned char *buf;
+    unsigned long hashsize;
+    unsigned long i, z;
+    int err;
+
+    LTC_ARGCHK(hmac != NULL);
+    LTC_ARGCHK(key  != NULL);
+
+    /* valid hash? */
+    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+        return err;
+    }
+    hmac->hash = hash;
+    hashsize   = hash_descriptor[hash].hashsize;
+
+    /* valid key length? */
+    if (keylen == 0) {
+        return CRYPT_INVALID_KEYSIZE;
+    }
+
+    /* allocate ram for buf */
+    buf = XMALLOC(HMAC_BLOCKSIZE);
+    if (buf == NULL) {
+       return CRYPT_MEM;
+    }
+
+    /* allocate memory for key */
+    hmac->key = XMALLOC(HMAC_BLOCKSIZE);
+    if (hmac->key == NULL) {
+       XFREE(buf);
+       return CRYPT_MEM;
+    }
+
+    /* (1) make sure we have a large enough key */
+    if(keylen > HMAC_BLOCKSIZE) {
+        z = HMAC_BLOCKSIZE;
+        if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) {
+           goto LBL_ERR;
+        }
+        if(hashsize < HMAC_BLOCKSIZE) {
+            zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
+        }
+        keylen = hashsize;
+    } else {
+        XMEMCPY(hmac->key, key, (size_t)keylen);
+        if(keylen < HMAC_BLOCKSIZE) {
+            zeromem((hmac->key) + keylen, (size_t)(HMAC_BLOCKSIZE - keylen));
+        }
+    }
+
+    /* Create the initial vector for step (3) */
+    for(i=0; i < HMAC_BLOCKSIZE;   i++) {
+       buf[i] = hmac->key[i] ^ 0x36;
+    }
+
+    /* Pre-pend that to the hash data */
+    if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    goto done;
+LBL_ERR:
+    /* free the key since we failed */
+    XFREE(hmac->key);
+done:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, HMAC_BLOCKSIZE);
+#endif
+ 
+   XFREE(buf);
+   return err;    
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_init.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/hmac/hmac_memory.c b/src/mac/hmac/hmac_memory.c
new file mode 100644
index 0000000..99959f4
--- /dev/null
+++ b/src/mac/hmac/hmac_memory.c
@@ -0,0 +1,77 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file hmac_memory.c
+  HMAC support, process a block of memory, Tom St Denis/Dobes Vandermeer
+*/
+
+#ifdef HMAC
+
+/**
+   HMAC a block of memory to produce the authentication tag
+   @param hash      The index of the hash to use 
+   @param key       The secret key 
+   @param keylen    The length of the secret key (octets)
+   @param in        The data to HMAC
+   @param inlen     The length of the data to HMAC (octets)
+   @param out       [out] Destination of the authentication tag
+   @param outlen    [in/out] Max size and resulting size of authentication tag
+   @return CRYPT_OK if successful
+*/
+int hmac_memory(int hash, 
+                const unsigned char *key,  unsigned long keylen,
+                const unsigned char *in,   unsigned long inlen, 
+                      unsigned char *out,  unsigned long *outlen)
+{
+    hmac_state *hmac;
+    int err;
+
+    LTC_ARGCHK(key    != NULL);
+    LTC_ARGCHK(in   != NULL);
+    LTC_ARGCHK(out    != NULL); 
+    LTC_ARGCHK(outlen != NULL);
+
+    /* allocate ram for hmac state */
+    hmac = XMALLOC(sizeof(hmac_state));
+    if (hmac == NULL) {
+       return CRYPT_MEM;
+    }
+
+    if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    if ((err = hmac_process(hmac, in, inlen)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    if ((err = hmac_done(hmac, out, outlen)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(hmac, sizeof(hmac_state));
+#endif
+
+   XFREE(hmac);
+   return err;   
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/hmac/hmac_memory_multi.c b/src/mac/hmac/hmac_memory_multi.c
new file mode 100644
index 0000000..b7a6d96
--- /dev/null
+++ b/src/mac/hmac/hmac_memory_multi.c
@@ -0,0 +1,92 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+/**
+  @file hmac_memory_multi.c
+  HMAC support, process multiple blocks of memory, Tom St Denis/Dobes Vandermeer
+*/
+
+#ifdef HMAC
+
+/**
+   HMAC multiple blocks of memory to produce the authentication tag
+   @param hash      The index of the hash to use 
+   @param key       The secret key 
+   @param keylen    The length of the secret key (octets)
+   @param out       [out] Destination of the authentication tag
+   @param outlen    [in/out] Max size and resulting size of authentication tag
+   @param in        The data to HMAC
+   @param inlen     The length of the data to HMAC (octets)
+   @param ...       tuples of (data,len) pairs to HMAC, terminated with a (NULL,x) (x=don't care)
+   @return CRYPT_OK if successful
+*/
+int hmac_memory_multi(int hash, 
+                const unsigned char *key,  unsigned long keylen,
+                      unsigned char *out,  unsigned long *outlen,
+                const unsigned char *in,   unsigned long inlen, ...)
+
+{
+    hmac_state          *hmac;
+    int                  err;
+    va_list              args;
+    const unsigned char *curptr;
+    unsigned long        curlen;
+
+    LTC_ARGCHK(key    != NULL);
+    LTC_ARGCHK(in     != NULL);
+    LTC_ARGCHK(out    != NULL); 
+    LTC_ARGCHK(outlen != NULL);
+
+    /* allocate ram for hmac state */
+    hmac = XMALLOC(sizeof(hmac_state));
+    if (hmac == NULL) {
+       return CRYPT_MEM;
+    }
+
+    if ((err = hmac_init(hmac, hash, key, keylen)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+
+    va_start(args, inlen);
+    curptr = in; 
+    curlen = inlen;
+    for (;;) {
+       /* process buf */
+       if ((err = hmac_process(hmac, curptr, curlen)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       /* step to next */
+       curptr = va_arg(args, const unsigned char*);
+       if (curptr == NULL) {
+          break;
+       }
+       curlen = va_arg(args, unsigned long);
+    }
+    if ((err = hmac_done(hmac, out, outlen)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(hmac, sizeof(hmac_state));
+#endif
+   XFREE(hmac);
+   va_end(args);
+   return err;   
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_memory_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/hmac/hmac_process.c b/src/mac/hmac/hmac_process.c
new file mode 100644
index 0000000..2919282
--- /dev/null
+++ b/src/mac/hmac/hmac_process.c
@@ -0,0 +1,43 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file hmac_process.c
+  HMAC support, process data, Tom St Denis/Dobes Vandermeer
+*/
+
+#ifdef HMAC
+
+/** 
+  Process data through HMAC
+  @param hmac    The hmac state
+  @param in      The data to send through HMAC
+  @param inlen   The length of the data to HMAC (octets)
+  @return CRYPT_OK if successful
+*/
+int hmac_process(hmac_state *hmac, const unsigned char *in, unsigned long inlen)
+{
+    int err;
+    LTC_ARGCHK(hmac != NULL);
+    LTC_ARGCHK(in != NULL);
+    if ((err = hash_is_valid(hmac->hash)) != CRYPT_OK) {
+        return err;
+    }
+    return hash_descriptor[hmac->hash].process(&hmac->md, in, inlen);
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_process.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/hmac_test.c b/src/mac/hmac/hmac_test.c
similarity index 91%
rename from hmac_test.c
rename to src/mac/hmac/hmac_test.c
index 4ec7d94..87758f5 100644
--- a/hmac_test.c
+++ b/src/mac/hmac/hmac_test.c
@@ -6,27 +6,13 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
+#include "tomcrypt.h"
 
-#include "mycrypt.h"
-
-/*
-    (1) append zeros to the end of K to create a B byte string
-        (e.g., if K is of length 20 bytes and B=64, then K will be
-         appended with 44 zero bytes 0x00)
-    (2) XOR (bitwise exclusive-OR) the B byte string computed in step
-        (1) with ipad (ipad = the byte 0x36 repeated B times)
-    (3) append the stream of data 'text' to the B byte string resulting
-        from step (2)
-    (4) apply H to the stream generated in step (3)
-    (5) XOR (bitwise exclusive-OR) the B byte string computed in
-        step (1) with opad (opad = the byte 0x5C repeated B times.)
-    (6) append the H result from step (4) to the B byte string
-        resulting from step (5)
-    (7) apply H to the stream generated in step (6) and output
-        the result
+/**
+  @file hmac_test.c
+  HMAC support, self-test, Tom St Denis/Dobes Vandermeer
 */
 
 #ifdef HMAC
@@ -34,7 +20,6 @@
 #define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
 
 /*
-
     TEST CASES SOURCE:
 
 Network Working Group                                          P. Cheng
@@ -42,11 +27,13 @@
 Category: Informational                                        R. Glenn
                                                                    NIST
                                                          September 1997
-
                  Test Cases for HMAC-MD5 and HMAC-SHA-1
 */
 
-
+/**
+  HMAC self-test
+  @return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled.
+*/
 int hmac_test(void)
 {
  #ifndef LTC_TEST
@@ -285,12 +272,13 @@
         outlen = sizeof(digest);
         if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) {
 #if 0
-            printf("HMAC-%s test #%d\n", cases[i].algo, cases[i].num);
+            printf("HMAC-%s test #%d, %s\n", cases[i].algo, cases[i].num, error_to_string(err));
 #endif
             return err;
         }
 
         if(memcmp(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0)  {
+            failed++;
 #if 0
             unsigned int j;
             printf("\nHMAC-%s test #%d:\n", cases[i].algo, cases[i].num);
@@ -303,9 +291,8 @@
                printf("%2x ", cases[i].digest[j]);
             }
             printf("\n");
+            return CRYPT_ERROR;
 #endif
-            failed++;
-            //return CRYPT_ERROR;
         } else {
             /* printf("HMAC-%s test #%d: Passed\n", cases[i].algo, cases[i].num); */
         }
@@ -323,3 +310,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/hmac/hmac_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/omac/omac_done.c b/src/mac/omac/omac_done.c
new file mode 100644
index 0000000..37292d5
--- /dev/null
+++ b/src/mac/omac/omac_done.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file omac_done.c
+  OMAC1 support, terminate a stream, Tom St Denis
+*/
+
+#ifdef OMAC
+
+/**
+  Terminate an OMAC stream
+  @param omac   The OMAC state
+  @param out    [out] Destination for the authentication tag
+  @param outlen [in/out]  The max size and resulting size of the authentication tag
+  @return CRYPT_OK if successful
+*/
+int omac_done(omac_state *omac, unsigned char *out, unsigned long *outlen)
+{
+   int       err, mode;
+   unsigned  x;
+
+   LTC_ARGCHK(omac   != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   if ((omac->buflen > (int)sizeof(omac->block)) || (omac->buflen < 0) ||
+       (omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* figure out mode */
+   if (omac->buflen != omac->blklen) {
+      /* add the 0x80 byte */
+      omac->block[omac->buflen++] = 0x80;
+
+      /* pad with 0x00 */
+      while (omac->buflen < omac->blklen) {
+         omac->block[omac->buflen++] = 0x00;
+      }
+      mode = 1;
+   } else {
+      mode = 0;
+   }
+
+   /* now xor prev + Lu[mode] */
+   for (x = 0; x < (unsigned)omac->blklen; x++) {
+       omac->block[x] ^= omac->prev[x] ^ omac->Lu[mode][x];
+   }
+
+   /* encrypt it */
+   cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->block, &omac->key);
+   cipher_descriptor[omac->cipher_idx].done(&omac->key);
+ 
+   /* output it */
+   for (x = 0; x < (unsigned)omac->blklen && x < *outlen; x++) {
+       out[x] = omac->block[x];
+   }
+   *outlen = x;
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(omac, sizeof(*omac));
+#endif
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/omac/omac_file.c b/src/mac/omac/omac_file.c
new file mode 100644
index 0000000..63784b0
--- /dev/null
+++ b/src/mac/omac/omac_file.c
@@ -0,0 +1,83 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file omac_file.c
+  OMAC1 support, process a file, Tom St Denis
+*/
+
+#ifdef OMAC
+
+/**
+   OMAC a file
+   @param cipher   The index of the cipher desired
+   @param key      The secret key
+   @param keylen   The length of the secret key (octets)
+   @param filename The name of the file you wish to OMAC
+   @param out      [out] Where the authentication tag is to be stored
+   @param outlen   [in/out] The max size and resulting size of the authentication tag
+   @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
+*/
+int omac_file(int cipher, 
+              const unsigned char *key, unsigned long keylen,
+              const char *filename, 
+                    unsigned char *out, unsigned long *outlen)
+{
+#ifdef LTC_NO_FILE
+   return CRYPT_NOP;
+#else
+   int err, x;
+   omac_state omac;
+   FILE *in;
+   unsigned char buf[512];
+
+   LTC_ARGCHK(key      != NULL);
+   LTC_ARGCHK(filename != NULL);
+   LTC_ARGCHK(out      != NULL);
+   LTC_ARGCHK(outlen   != NULL);
+
+   in = fopen(filename, "rb");
+   if (in == NULL) {
+      return CRYPT_FILE_NOTFOUND;
+   }
+
+   if ((err = omac_init(&omac, cipher, key, keylen)) != CRYPT_OK) {
+      fclose(in);
+      return err;
+   }
+
+   do {
+      x = fread(buf, 1, sizeof(buf), in);
+      if ((err = omac_process(&omac, buf, x)) != CRYPT_OK) {
+         fclose(in);
+         return err;
+      }
+   } while (x == sizeof(buf));
+   fclose(in);
+
+   if ((err = omac_done(&omac, out, outlen)) != CRYPT_OK) {
+      return err;
+   }
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, sizeof(buf));
+#endif
+
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_file.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/omac_init.c b/src/mac/omac/omac_init.c
similarity index 70%
rename from omac_init.c
rename to src/mac/omac/omac_init.c
index 3945630..8866772 100644
--- a/omac_init.c
+++ b/src/mac/omac/omac_init.c
@@ -6,25 +6,44 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/** 
+  @file omac_init.c
+  OMAC1 support, initialize state, by Tom St Denis
+*/
+
 
 #ifdef OMAC
 
+/**
+   Initialize an OMAC state
+   @param omac    The OMAC state to initialize
+   @param cipher  The index of the desired cipher
+   @param key     The secret key
+   @param keylen  The length of the secret key (octets)
+   @return CRYPT_OK if successful
+*/
 int omac_init(omac_state *omac, int cipher, const unsigned char *key, unsigned long keylen)
 {
    int err, x, y, mask, msb, len;
 
-   _ARGCHK(omac != NULL);
-   _ARGCHK(key  != NULL);
+   LTC_ARGCHK(omac != NULL);
+   LTC_ARGCHK(key  != NULL);
 
    /* schedule the key */
    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
       return err;
    }
 
+#ifdef LTC_FAST
+   if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
+       return CRYPT_INVALID_ARG;
+   }
+#endif
+
    /* now setup the system */
    switch (cipher_descriptor[cipher].block_length) {
        case 8:  mask = 0x1B;
@@ -59,7 +78,7 @@
  
        /* copy up as require */
        if (x == 0) {
-          memcpy(omac->Lu[1], omac->Lu[0], sizeof(omac->Lu[0]));
+          XMEMCPY(omac->Lu[1], omac->Lu[0], sizeof(omac->Lu[0]));
        }
    }
 
@@ -74,3 +93,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_init.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/06/06 10:22:44 $ */
diff --git a/src/mac/omac/omac_memory.c b/src/mac/omac/omac_memory.c
new file mode 100644
index 0000000..3b1521c
--- /dev/null
+++ b/src/mac/omac/omac_memory.c
@@ -0,0 +1,75 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file omac_memory.c
+  OMAC1 support, process a block of memory, Tom St Denis
+*/
+
+#ifdef OMAC
+
+/**
+   OMAC a block of memory 
+   @param cipher    The index of the desired cipher
+   @param key       The secret key
+   @param keylen    The length of the secret key (octets)
+   @param in        The data to send through OMAC
+   @param inlen     The length of the data to send through OMAC (octets)
+   @param out       [out] The destination of the authentication tag
+   @param outlen    [in/out]  The max size and resulting size of the authentication tag (octets)
+   @return CRYPT_OK if successful
+*/
+int omac_memory(int cipher, 
+                const unsigned char *key, unsigned long keylen,
+                const unsigned char *in,  unsigned long inlen,
+                      unsigned char *out, unsigned long *outlen)
+{
+   int err;
+   omac_state *omac;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* allocate ram for omac state */
+   omac = XMALLOC(sizeof(omac_state));
+   if (omac == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* omac process the message */
+   if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = omac_process(omac, in, inlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(omac, sizeof(omac_state));
+#endif
+
+   XFREE(omac);
+   return err;   
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/omac/omac_memory_multi.c b/src/mac/omac/omac_memory_multi.c
new file mode 100644
index 0000000..52f7323
--- /dev/null
+++ b/src/mac/omac/omac_memory_multi.c
@@ -0,0 +1,90 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+/** 
+  @file omac_memory_multi.c
+  OMAC1 support, process multiple blocks of memory, Tom St Denis
+*/
+
+#ifdef OMAC
+
+/**
+   OMAC multiple blocks of memory 
+   @param cipher    The index of the desired cipher
+   @param key       The secret key
+   @param keylen    The length of the secret key (octets)
+   @param out       [out] The destination of the authentication tag
+   @param outlen    [in/out]  The max size and resulting size of the authentication tag (octets)
+   @param in        The data to send through OMAC
+   @param inlen     The length of the data to send through OMAC (octets)
+   @param ...       tuples of (data,len) pairs to OMAC, terminated with a (NULL,x) (x=don't care)
+   @return CRYPT_OK if successful
+*/
+int omac_memory_multi(int cipher, 
+                const unsigned char *key, unsigned long keylen,
+                      unsigned char *out, unsigned long *outlen,
+                const unsigned char *in,  unsigned long inlen, ...)
+{
+   int                  err;
+   omac_state          *omac;
+   va_list              args;
+   const unsigned char *curptr;
+   unsigned long        curlen;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* allocate ram for omac state */
+   omac = XMALLOC(sizeof(omac_state));
+   if (omac == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* omac process the message */
+   if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   va_start(args, inlen);
+   curptr = in; 
+   curlen = inlen;
+   for (;;) {
+      /* process buf */
+      if ((err = omac_process(omac, curptr, curlen)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+      /* step to next */
+      curptr = va_arg(args, const unsigned char*);
+      if (curptr == NULL) {
+         break;
+      }
+      curlen = va_arg(args, unsigned long);
+   }
+   if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(omac, sizeof(omac_state));
+#endif
+   XFREE(omac);
+   va_end(args);
+   return err;   
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_memory_multi.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/src/mac/omac/omac_process.c b/src/mac/omac/omac_process.c
new file mode 100644
index 0000000..ca3ec6b
--- /dev/null
+++ b/src/mac/omac/omac_process.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file omac_process.c
+  OMAC1 support, process data, Tom St Denis
+*/
+
+
+#ifdef OMAC
+
+/** 
+   Process data through OMAC
+   @param omac     The OMAC state
+   @param in       The input data to send through OMAC
+   @param inlen    The length of the input (octets)
+   @return CRYPT_OK if successful
+*/
+int omac_process(omac_state *omac, const unsigned char *in, unsigned long inlen)
+{
+   unsigned long n, x;
+   int           err;
+
+   LTC_ARGCHK(omac  != NULL);
+   LTC_ARGCHK(in    != NULL);
+   if ((err = cipher_is_valid(omac->cipher_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   if ((omac->buflen > (int)sizeof(omac->block)) || (omac->buflen < 0) ||
+       (omac->blklen > (int)sizeof(omac->block)) || (omac->buflen > omac->blklen)) {
+      return CRYPT_INVALID_ARG;
+   }
+
+#ifdef LTC_FAST
+   if (omac->buflen == 0 && inlen > 16) {
+      int y;
+      for (x = 0; x < (inlen - 16); x += 16) {
+          for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+              *((LTC_FAST_TYPE*)(&omac->prev[y])) ^= *((LTC_FAST_TYPE*)(&in[y]));
+          }
+          in += 16;
+          cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->prev, omac->prev, &omac->key);
+      }
+      inlen -= x;
+    }
+#endif
+
+   while (inlen != 0) { 
+       /* ok if the block is full we xor in prev, encrypt and replace prev */
+       if (omac->buflen == omac->blklen) {
+          for (x = 0; x < (unsigned long)omac->blklen; x++) {
+              omac->block[x] ^= omac->prev[x];
+          }
+          cipher_descriptor[omac->cipher_idx].ecb_encrypt(omac->block, omac->prev, &omac->key);
+          omac->buflen = 0;
+       }
+
+       /* add bytes */
+       n = MIN(inlen, (unsigned long)(omac->blklen - omac->buflen));
+       XMEMCPY(omac->block + omac->buflen, in, n);
+       omac->buflen  += n;
+       inlen         -= n;
+       in            += n;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_process.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/05 14:35:58 $ */
diff --git a/omac_test.c b/src/mac/omac/omac_test.c
similarity index 87%
rename from omac_test.c
rename to src/mac/omac/omac_test.c
index 2d50d9a..1bc9ead 100644
--- a/omac_test.c
+++ b/src/mac/omac/omac_test.c
@@ -6,13 +6,21 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* OMAC1 Support by Tom St Denis (for 64 and 128 bit block ciphers only) */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/** 
+  @file omac_test.c
+  OMAC1 support, self-test, by Tom St Denis
+*/
 
 #ifdef OMAC
 
+/**
+  Test the OMAC setup
+  @return CRYPT_OK if successful, CRYPT_NOP if tests have been disabled
+*/
 int omac_test(void)
 {
 #if !defined(LTC_TEST)
@@ -65,7 +73,7 @@
 
     };
     unsigned char out[16];
-    int x, y, err, idx;
+    int x, err, idx;
     unsigned long len;
 
 
@@ -83,8 +91,11 @@
        }
 
        if (memcmp(out, tests[x].tag, 16) != 0) {
+#if 0
+          int y;
           printf("\n\nTag: ");
           for (y = 0; y < 16; y++) printf("%02x", out[y]); printf("\n\n");
+#endif
           return CRYPT_FAIL_TESTVECTOR;
        }
     }
@@ -93,3 +104,7 @@
 }   
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/omac/omac_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pelican/pelican.c b/src/mac/pelican/pelican.c
new file mode 100644
index 0000000..85bf9ee
--- /dev/null
+++ b/src/mac/pelican/pelican.c
@@ -0,0 +1,165 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pelican.c
+   Pelican MAC, initialize state, by Tom St Denis 
+*/
+
+#ifdef PELICAN
+
+#define ENCRYPT_ONLY
+#include "../../ciphers/aes/aes_tab.c"
+
+
+/**
+   Initialize a Pelican state
+   @param pelmac    The Pelican state to initialize
+   @param key       The secret key 
+   @param keylen    The length of the secret key (octets)
+   @return CRYPT_OK if successful
+*/
+int pelican_init(pelican_state *pelmac, const unsigned char *key, unsigned long keylen)
+{
+    int err;
+    
+    LTC_ARGCHK(pelmac != NULL);
+    LTC_ARGCHK(key    != NULL);
+
+#ifdef LTC_FAST
+    if (16 % sizeof(LTC_FAST_TYPE)) {
+        return CRYPT_INVALID_ARG;
+    }
+#endif
+
+    if ((err = aes_setup(key, keylen, 0, &pelmac->K)) != CRYPT_OK) {
+       return err;
+    }
+
+    zeromem(pelmac->state, 16);
+    aes_ecb_encrypt(pelmac->state, pelmac->state, &pelmac->K);
+    pelmac->buflen = 0;
+
+    return CRYPT_OK;    
+}
+
+static void four_rounds(pelican_state *pelmac)
+{
+    ulong32 s0, s1, s2, s3, t0, t1, t2, t3;
+    int r;
+
+    LOAD32H(s0, pelmac->state      );
+    LOAD32H(s1, pelmac->state  +  4);
+    LOAD32H(s2, pelmac->state  +  8);
+    LOAD32H(s3, pelmac->state  + 12);
+    for (r = 0; r < 4; r++) {
+        t0 =
+            Te0(byte(s0, 3)) ^
+            Te1(byte(s1, 2)) ^
+            Te2(byte(s2, 1)) ^
+            Te3(byte(s3, 0));
+        t1 =
+            Te0(byte(s1, 3)) ^
+            Te1(byte(s2, 2)) ^
+            Te2(byte(s3, 1)) ^
+            Te3(byte(s0, 0));
+        t2 =
+            Te0(byte(s2, 3)) ^
+            Te1(byte(s3, 2)) ^
+            Te2(byte(s0, 1)) ^
+            Te3(byte(s1, 0));
+        t3 =
+            Te0(byte(s3, 3)) ^
+            Te1(byte(s0, 2)) ^
+            Te2(byte(s1, 1)) ^
+            Te3(byte(s2, 0));
+        s0 = t0; s1 = t1; s2 = t2; s3 = t3;
+    }
+    STORE32H(s0, pelmac->state      );
+    STORE32H(s1, pelmac->state  +  4);
+    STORE32H(s2, pelmac->state  +  8);
+    STORE32H(s3, pelmac->state  + 12);
+}
+
+/** 
+  Process a block of text through Pelican
+  @param pelmac       The Pelican MAC state
+  @param in           The input
+  @param inlen        The length input (octets)
+  @return CRYPT_OK on success
+  */
+int pelican_process(pelican_state *pelmac, const unsigned char *in, unsigned long inlen)
+{
+
+   LTC_ARGCHK(pelmac != NULL);
+   LTC_ARGCHK(in     != NULL);
+
+   /* check range */
+   if (pelmac->buflen < 0 || pelmac->buflen > 15) {
+      return CRYPT_INVALID_ARG;
+   }
+
+#ifdef LTC_FAST
+   if (pelmac->buflen == 0) {
+      while (inlen & ~15) {
+         int x;
+         for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
+            *((LTC_FAST_TYPE*)((unsigned char *)pelmac->state + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)in + x));
+         }
+         four_rounds(pelmac);
+         in    += 16;
+         inlen -= 16;
+      }
+   }
+#endif
+
+   while (inlen--) {
+       pelmac->state[pelmac->buflen++] ^= *in++;
+       if (pelmac->buflen == 16) {
+          four_rounds(pelmac);
+          pelmac->buflen = 0;
+       }
+   }
+   return CRYPT_OK;
+}
+
+/**
+  Terminate Pelican MAC
+  @param pelmac      The Pelican MAC state
+  @param out         [out] The TAG
+  @return CRYPT_OK on sucess
+*/
+int pelican_done(pelican_state *pelmac, unsigned char *out)
+{
+   LTC_ARGCHK(pelmac  != NULL);
+   LTC_ARGCHK(out     != NULL);
+
+   /* check range */
+   if (pelmac->buflen < 0 || pelmac->buflen > 16) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if  (pelmac->buflen == 16) {
+       four_rounds(pelmac);
+       pelmac->buflen = 0;
+   }
+   pelmac->state[pelmac->buflen++] ^= 0x80;
+   aes_ecb_encrypt(pelmac->state, out, &pelmac->K);
+   aes_done(&pelmac->K);
+   return CRYPT_OK;
+}                        
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pelican/pelican.c,v $ */
+/* $Revision: 1.16 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pelican/pelican_memory.c b/src/mac/pelican/pelican_memory.c
new file mode 100644
index 0000000..093340d
--- /dev/null
+++ b/src/mac/pelican/pelican_memory.c
@@ -0,0 +1,59 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pelican_memory.c
+   Pelican MAC, MAC a block of memory, by Tom St Denis 
+*/
+
+#ifdef PELICAN
+
+/**
+  Pelican block of memory
+  @param key      The key for the MAC
+  @param keylen   The length of the key (octets)
+  @param in       The input to MAC
+  @param inlen    The length of the input (octets)
+  @param out      [out] The output TAG 
+  @return CRYPT_OK on success
+*/
+int pelican_memory(const unsigned char *key, unsigned long keylen,
+                   const unsigned char *in,  unsigned long inlen,
+                         unsigned char *out)
+{
+   pelican_state *pel;
+   int err;
+
+   pel = XMALLOC(sizeof(*pel));
+   if (pel == NULL) { 
+      return CRYPT_MEM;
+   }
+
+   if ((err = pelican_init(pel, key, keylen)) != CRYPT_OK) {
+      XFREE(pel);
+      return err;
+   }
+   if ((err = pelican_process(pel, in ,inlen)) != CRYPT_OK) {
+      XFREE(pel);
+      return err;
+   }
+   err = pelican_done(pel, out);
+   XFREE(pel); 
+   return err;
+}
+
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pelican/pelican_memory.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pelican/pelican_test.c b/src/mac/pelican/pelican_test.c
new file mode 100644
index 0000000..06ec3f0
--- /dev/null
+++ b/src/mac/pelican/pelican_test.c
@@ -0,0 +1,120 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pelican_test.c
+   Pelican MAC, test, by Tom St Denis 
+*/
+
+#ifdef PELICAN
+
+int pelican_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   static const struct {
+        unsigned char K[32], MSG[64], T[16];
+	int keylen, ptlen;
+   } tests[] = {
+/* K=16, M=0 */
+{
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+   { 0 },
+   { 0xeb, 0x58, 0x37, 0x15, 0xf8, 0x34, 0xde, 0xe5, 
+     0xa4, 0xd1, 0x6e, 0xe4, 0xb9, 0xd7, 0x76, 0x0e, },
+   16, 0
+},
+
+/* K=16, M=3 */
+{
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+   { 0x00, 0x01, 0x02 },
+   { 0x1c, 0x97, 0x40, 0x60, 0x6c, 0x58, 0x17, 0x2d, 
+     0x03, 0x94, 0x19, 0x70, 0x81, 0xc4, 0x38, 0x54, },
+   16, 3
+},
+
+/* K=16, M=16 */
+{
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+   { 0x03, 0xcc, 0x46, 0xb8, 0xac, 0xa7, 0x9c, 0x36, 
+     0x1e, 0x8c, 0x6e, 0xa6, 0x7b, 0x89, 0x32, 0x49, },
+   16, 16
+},
+
+/* K=16, M=32 */
+{
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+     0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
+   { 0x89, 0xcc, 0x36, 0x58, 0x1b, 0xdd, 0x4d, 0xb5, 
+     0x78, 0xbb, 0xac, 0xf0, 0xff, 0x8b, 0x08, 0x15, },
+   16, 32
+},
+
+/* K=16, M=35 */
+{
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
+   { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+     0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+     0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+     0x20, 0x21, 0x23 },
+   { 0x4a, 0x7d, 0x45, 0x4d, 0xcd, 0xb5, 0xda, 0x8d, 
+     0x48, 0x78, 0x16, 0x48, 0x5d, 0x45, 0x95, 0x99, },
+   16, 35
+},
+};
+   int x, err;
+   unsigned char out[16];
+   pelican_state pel;
+   
+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { 
+       if ((err = pelican_init(&pel, tests[x].K, tests[x].keylen)) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = pelican_process(&pel, tests[x].MSG, tests[x].ptlen)) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = pelican_done(&pel, out)) != CRYPT_OK) {
+          return err;
+       }
+
+       if (memcmp(out, tests[x].T, 16)) {
+#if 0
+           int y;
+           printf("\nFailed test %d\n", x);
+           printf("{ "); for (y = 0; y < 16; ) { printf("0x%02x, ", out[y]); if (!(++y & 7)) printf("\n"); } printf(" }\n");
+#endif
+           return CRYPT_FAIL_TESTVECTOR;
+       }
+   }
+   return CRYPT_OK;
+#endif
+}
+
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pelican/pelican_test.c,v $ */
+/* $Revision: 1.9 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/pmac_done.c b/src/mac/pmac/pmac_done.c
similarity index 76%
rename from pmac_done.c
rename to src/mac/pmac/pmac_done.c
index 8051da7..09c430c 100644
--- a/pmac_done.c
+++ b/src/mac/pmac/pmac_done.c
@@ -6,11 +6,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+  @file pmac_done.c
+  PMAC implementation, terminate a session, by Tom St Denis 
+*/
 
 #ifdef PMAC
 
@@ -18,8 +21,8 @@
 {
    int err, x;
 
-   _ARGCHK(state != NULL);
-   _ARGCHK(out   != NULL);
+   LTC_ARGCHK(state != NULL);
+   LTC_ARGCHK(out   != NULL);
    if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
       return err;
    }
@@ -47,6 +50,7 @@
 
    /* encrypt it */
    cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key);
+   cipher_descriptor[state->cipher_idx].done(&state->key);
 
    /* store it */
    for (x = 0; x < state->block_len && x <= (int)*outlen; x++) {
@@ -54,7 +58,7 @@
    }
    *outlen = x;
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(state, sizeof(*state));
 #endif
    return CRYPT_OK;
@@ -62,3 +66,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pmac/pmac_file.c b/src/mac/pmac/pmac_file.c
new file mode 100644
index 0000000..1034c6f
--- /dev/null
+++ b/src/mac/pmac/pmac_file.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pmac_file.c
+   PMAC implementation, process a file, by Tom St Denis 
+*/
+
+#ifdef PMAC
+
+/**
+   PMAC a file 
+   @param cipher       The index of the cipher desired
+   @param key          The secret key
+   @param keylen       The length of the secret key (octets)
+   @param filename     The name of the file to send through PMAC
+   @param out          [out] Destination for the authentication tag
+   @param outlen       [in/out] Max size and resulting size of the authentication tag
+   @return CRYPT_OK if successful, CRYPT_NOP if file support has been disabled
+*/
+int pmac_file(int cipher, 
+              const unsigned char *key, unsigned long keylen,
+              const char *filename, 
+                    unsigned char *out, unsigned long *outlen)
+{
+#ifdef LTC_NO_FILE
+   return CRYPT_NOP;
+#else
+   int err, x;
+   pmac_state pmac;
+   FILE *in;
+   unsigned char buf[512];
+
+
+   LTC_ARGCHK(key      != NULL);
+   LTC_ARGCHK(filename != NULL);
+   LTC_ARGCHK(out      != NULL);
+   LTC_ARGCHK(outlen   != NULL);
+
+   in = fopen(filename, "rb");
+   if (in == NULL) {
+      return CRYPT_FILE_NOTFOUND;
+   }
+
+   if ((err = pmac_init(&pmac, cipher, key, keylen)) != CRYPT_OK) {
+      fclose(in);
+      return err;
+   }
+
+   do {
+      x = fread(buf, 1, sizeof(buf), in);
+      if ((err = pmac_process(&pmac, buf, x)) != CRYPT_OK) {
+         fclose(in);
+         return err;
+      }
+   } while (x == sizeof(buf));
+   fclose(in);
+
+   if ((err = pmac_done(&pmac, out, outlen)) != CRYPT_OK) {
+      return err;
+   }
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, sizeof(buf));
+#endif
+
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_file.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/pmac_init.c b/src/mac/pmac/pmac_init.c
similarity index 73%
rename from pmac_init.c
rename to src/mac/pmac/pmac_init.c
index b4ef111..5bd94a0 100644
--- a/pmac_init.c
+++ b/src/mac/pmac/pmac_init.c
@@ -6,11 +6,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file pmac_init.c
+   PMAC implementation, initialize state, by Tom St Denis 
+*/
 
 #ifdef PMAC
 
@@ -32,13 +35,21 @@
 }
 };
 
+/**
+   Initialize a PMAC state
+   @param pmac      The PMAC state to initialize
+   @param cipher    The index of the desired cipher
+   @param key       The secret key 
+   @param keylen    The length of the secret key (octets)
+   @return CRYPT_OK if successful
+*/
 int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned long keylen)
 {
    int poly, x, y, m, err;
-   unsigned char L[MAXBLOCKSIZE];
+   unsigned char *L;
 
-   _ARGCHK(pmac  != NULL);
-   _ARGCHK(key   != NULL);
+   LTC_ARGCHK(pmac  != NULL);
+   LTC_ARGCHK(key   != NULL);
 
    /* valid cipher? */
    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
@@ -54,19 +65,32 @@
    }
    if (polys[poly].len != pmac->block_len) {
       return CRYPT_INVALID_ARG;
-   }   
+   }
+
+#ifdef LTC_FAST
+   if (pmac->block_len % sizeof(LTC_FAST_TYPE)) {
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+
 
    /* schedule the key */
    if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &pmac->key)) != CRYPT_OK) {
       return err;
    }
  
+   /* allocate L */
+   L = XMALLOC(pmac->block_len);
+   if (L == NULL) {
+      return CRYPT_MEM;
+   }
+
    /* find L = E[0] */
    zeromem(L, pmac->block_len);
    cipher_descriptor[cipher].ecb_encrypt(L, L, &pmac->key);
 
    /* find Ls[i] = L << i for i == 0..31 */
-   memcpy(pmac->Ls[0], L, pmac->block_len);
+   XMEMCPY(pmac->Ls[0], L, pmac->block_len);
    for (x = 1; x < 32; x++) {
        m = pmac->Ls[x-1][0] >> 7;
        for (y = 0; y < pmac->block_len-1; y++) {
@@ -104,11 +128,17 @@
     zeromem(pmac->Li,       sizeof(pmac->Li));
     zeromem(pmac->checksum, sizeof(pmac->checksum));
 
-#ifdef CLEAN_STACK
-    zeromem(L, sizeof(L));
+#ifdef LTC_CLEAN_STACK
+    zeromem(L, pmac->block_len);
 #endif
 
+    XFREE(L);
+
     return CRYPT_OK;
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_init.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pmac/pmac_memory.c b/src/mac/pmac/pmac_memory.c
new file mode 100644
index 0000000..fcdef99
--- /dev/null
+++ b/src/mac/pmac/pmac_memory.c
@@ -0,0 +1,74 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pmac_memory.c
+   PMAC implementation, process a block of memory, by Tom St Denis 
+*/
+
+#ifdef PMAC
+
+/**
+   PMAC a block of memory
+   @param cipher   The index of the cipher desired
+   @param key      The secret key
+   @param keylen   The length of the secret key (octets)
+   @param in       The data you wish to send through PMAC
+   @param inlen    The length of data you wish to send through PMAC (octets)
+   @param out      [out] Destination for the authentication tag
+   @param outlen   [in/out] The max size and resulting size of the authentication tag
+   @return CRYPT_OK if successful
+*/
+int pmac_memory(int cipher, 
+                const unsigned char *key, unsigned long keylen,
+                const unsigned char *in, unsigned long inlen,
+                      unsigned char *out, unsigned long *outlen)
+{
+   int err;
+   pmac_state *pmac;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(in    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* allocate ram for pmac state */
+   pmac = XMALLOC(sizeof(pmac_state));
+   if (pmac == NULL) {
+      return CRYPT_MEM;
+   }
+   
+   if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = pmac_process(pmac, in, inlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(pmac, sizeof(pmac_state));
+#endif
+
+   XFREE(pmac);
+   return err;   
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_memory.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pmac/pmac_memory_multi.c b/src/mac/pmac/pmac_memory_multi.c
new file mode 100644
index 0000000..2cc8572
--- /dev/null
+++ b/src/mac/pmac/pmac_memory_multi.c
@@ -0,0 +1,89 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+/** 
+   @file pmac_memory_multi.c
+   PMAC implementation, process multiple blocks of memory, by Tom St Denis 
+*/
+
+#ifdef PMAC
+
+/**
+   PMAC multiple blocks of memory
+   @param cipher   The index of the cipher desired
+   @param key      The secret key
+   @param keylen   The length of the secret key (octets)
+   @param out      [out] Destination for the authentication tag
+   @param outlen   [in/out] The max size and resulting size of the authentication tag
+   @param in       The data you wish to send through PMAC
+   @param inlen    The length of data you wish to send through PMAC (octets)
+   @param ...      tuples of (data,len) pairs to PMAC, terminated with a (NULL,x) (x=don't care)
+   @return CRYPT_OK if successful
+*/
+int pmac_memory_multi(int cipher, 
+                const unsigned char *key, unsigned long  keylen,
+                      unsigned char *out, unsigned long *outlen,
+                const unsigned char *in,  unsigned long  inlen, ...)
+{
+   int                  err;
+   pmac_state          *pmac;
+   va_list              args;
+   const unsigned char *curptr;
+   unsigned long        curlen;
+
+   LTC_ARGCHK(key    != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* allocate ram for pmac state */
+   pmac = XMALLOC(sizeof(pmac_state));
+   if (pmac == NULL) {
+      return CRYPT_MEM;
+   }
+   
+   if ((err = pmac_init(pmac, cipher, key, keylen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   va_start(args, inlen);
+   curptr = in; 
+   curlen = inlen;
+   for (;;) {
+      /* process buf */
+      if ((err = pmac_process(pmac, curptr, curlen)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+      /* step to next */
+      curptr = va_arg(args, const unsigned char*);
+      if (curptr == NULL) {
+         break;
+      }
+      curlen = va_arg(args, unsigned long);
+   }
+   if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(pmac, sizeof(pmac_state));
+#endif
+   XFREE(pmac);
+   va_end(args);
+   return err;   
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_memory_multi.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pmac/pmac_ntz.c b/src/mac/pmac/pmac_ntz.c
new file mode 100644
index 0000000..7ec4550
--- /dev/null
+++ b/src/mac/pmac/pmac_ntz.c
@@ -0,0 +1,39 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pmac_ntz.c
+   PMAC implementation, internal function, by Tom St Denis 
+*/
+
+#ifdef PMAC
+
+/**
+  Internal PMAC function
+*/
+int pmac_ntz(unsigned long x)
+{
+   int c;
+   x &= 0xFFFFFFFFUL;
+   c = 0;
+   while ((x & 1) == 0) {
+      ++c;
+      x >>= 1;
+   }
+   return c;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_ntz.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pmac/pmac_process.c b/src/mac/pmac/pmac_process.c
new file mode 100644
index 0000000..9ebd44e
--- /dev/null
+++ b/src/mac/pmac/pmac_process.c
@@ -0,0 +1,96 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pmac_process.c
+   PMAC implementation, process data, by Tom St Denis 
+*/
+
+
+#ifdef PMAC
+
+/**
+  Process data in a PMAC stream
+  @param pmac     The PMAC state
+  @param in       The data to send through PMAC
+  @param inlen    The length of the data to send through PMAC
+  @return CRYPT_OK if successful
+*/
+int pmac_process(pmac_state *pmac, const unsigned char *in, unsigned long inlen)
+{
+   int err, n;
+   unsigned long x;
+   unsigned char Z[MAXBLOCKSIZE];
+
+   LTC_ARGCHK(pmac != NULL);
+   LTC_ARGCHK(in   != NULL);
+   if ((err = cipher_is_valid(pmac->cipher_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   if ((pmac->buflen > (int)sizeof(pmac->block)) || (pmac->buflen < 0) ||
+       (pmac->block_len > (int)sizeof(pmac->block)) || (pmac->buflen > pmac->block_len)) {
+      return CRYPT_INVALID_ARG;
+   }
+
+#ifdef LTC_FAST
+   if (pmac->buflen == 0 && inlen > 16) {
+      unsigned long y;
+      for (x = 0; x < (inlen - 16); x += 16) {
+          pmac_shift_xor(pmac);
+          for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+              *((LTC_FAST_TYPE*)(&Z[y])) = *((LTC_FAST_TYPE*)(&in[y])) ^ *((LTC_FAST_TYPE*)(&pmac->Li[y]));
+          }
+          cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key);
+          for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
+              *((LTC_FAST_TYPE*)(&pmac->checksum[y])) ^= *((LTC_FAST_TYPE*)(&Z[y]));
+          }
+          in += 16;
+      }
+      inlen -= x;
+   }
+#endif
+
+   while (inlen != 0) { 
+       /* ok if the block is full we xor in prev, encrypt and replace prev */
+       if (pmac->buflen == pmac->block_len) {
+          pmac_shift_xor(pmac);
+          for (x = 0; x < (unsigned long)pmac->block_len; x++) {
+               Z[x] = pmac->Li[x] ^ pmac->block[x];
+          }
+          cipher_descriptor[pmac->cipher_idx].ecb_encrypt(Z, Z, &pmac->key);
+          for (x = 0; x < (unsigned long)pmac->block_len; x++) {
+              pmac->checksum[x] ^= Z[x];
+          }
+          pmac->buflen = 0;
+       }
+
+       /* add bytes */
+       n = MIN(inlen, (unsigned long)(pmac->block_len - pmac->buflen));
+       XMEMCPY(pmac->block + pmac->buflen, in, n);
+       pmac->buflen  += n;
+       inlen         -= n;
+       in            += n;
+   }
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(Z, sizeof(Z));
+#endif
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_process.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/mac/pmac/pmac_shift_xor.c b/src/mac/pmac/pmac_shift_xor.c
new file mode 100644
index 0000000..f24c22b
--- /dev/null
+++ b/src/mac/pmac/pmac_shift_xor.c
@@ -0,0 +1,44 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+   @file pmac_shift_xor.c
+   PMAC implementation, internal function, by Tom St Denis 
+*/
+
+#ifdef PMAC
+
+/**
+  Internal function.  Performs the state update (adding correct multiple)
+  @param pmac   The PMAC state.
+*/
+void pmac_shift_xor(pmac_state *pmac)
+{
+   int x, y;
+   y = pmac_ntz(pmac->block_index++);
+#ifdef LTC_FAST
+   for (x = 0; x < pmac->block_len; x += sizeof(LTC_FAST_TYPE)) {
+       *((LTC_FAST_TYPE*)((unsigned char *)pmac->Li + x)) ^=
+       *((LTC_FAST_TYPE*)((unsigned char *)pmac->Ls[y] + x));
+   }
+#else
+   for (x = 0; x < pmac->block_len; x++) {
+       pmac->Li[x] ^= pmac->Ls[y][x];
+   }
+#endif
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_shift_xor.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/pmac_test.c b/src/mac/pmac/pmac_test.c
similarity index 90%
rename from pmac_test.c
rename to src/mac/pmac/pmac_test.c
index e813eb5..6d88703 100644
--- a/pmac_test.c
+++ b/src/mac/pmac/pmac_test.c
@@ -6,14 +6,22 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file pmac_test.c
+   PMAC implementation, self-test, by Tom St Denis 
+*/
+
 
 #ifdef PMAC
 
+/** 
+   Test the OMAC implementation
+   @return CRYPT_OK if successful, CRYPT_NOP if testing has been disabled
+*/
 int pmac_test(void)
 {
 #if !defined(LTC_TEST)
@@ -151,3 +159,7 @@
 
 
  
+
+/* $Source: /cvs/libtom/libtomcrypt/src/mac/pmac/pmac_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/base64_decode.c b/src/misc/base64/base64_decode.c
similarity index 64%
rename from base64_decode.c
rename to src/misc/base64/base64_decode.c
index 6729480..551add1 100644
--- a/base64_decode.c
+++ b/src/misc/base64/base64_decode.c
@@ -6,11 +6,15 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* compliant base64 code donated by Wayne Scott (wscott@bitmover.com) */
-#include "mycrypt.h"
+/**
+  @file base64_decode.c
+  Compliant base64 code donated by Wayne Scott (wscott@bitmover.com)
+*/
+
 
 #ifdef BASE64
 
@@ -38,23 +42,43 @@
 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 255, 255, 255, 255 };
 
-int base64_decode(const unsigned char *in,  unsigned long len, 
+/**
+   base64 decode a block of memory
+   @param in       The base64 data to decode
+   @param inlen    The length of the base64 data
+   @param out      [out] The destination of the binary decoded data
+   @param outlen   [in/out] The max size and resulting size of the decoded data
+   @return CRYPT_OK if successful
+*/
+int base64_decode(const unsigned char *in,  unsigned long inlen, 
                         unsigned char *out, unsigned long *outlen)
 {
    unsigned long t, x, y, z;
    unsigned char c;
    int           g;
 
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
 
    g = 3;
-   for (x = y = z = t = 0; x < len; x++) {
+   for (x = y = z = t = 0; x < inlen; x++) {
        c = map[in[x]&0xFF];
        if (c == 255) continue;
-       if (c == 254) { c = 0; g--; }
+       /* the final = symbols are read and used to trim the remaining bytes */
+       if (c == 254) { 
+          c = 0; 
+          /* prevent g < 0 which would potentially allow an overflow later */
+          if (--g < 0) {
+             return CRYPT_INVALID_PACKET;
+          }
+       } else if (g != 3) {
+          /* we only allow = to be at the end */
+          return CRYPT_INVALID_PACKET;
+       }
+
        t = (t<<6)|c;
+
        if (++y == 4) {
           if (z + g > *outlen) { 
              return CRYPT_BUFFER_OVERFLOW; 
@@ -74,3 +98,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/base64/base64_decode.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/base64/base64_encode.c b/src/misc/base64/base64_encode.c
new file mode 100644
index 0000000..5978643
--- /dev/null
+++ b/src/misc/base64/base64_encode.c
@@ -0,0 +1,80 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file base64_encode.c
+  Compliant base64 encoder donated by Wayne Scott (wscott@bitmover.com)
+*/
+
+
+#ifdef BASE64
+
+static const char *codes = 
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+/**
+   base64 Encode a buffer (NUL terminated)
+   @param in      The input buffer to encode
+   @param inlen   The length of the input buffer
+   @param out     [out] The destination of the base64 encoded data
+   @param outlen  [in/out] The max size and resulting size
+   @return CRYPT_OK if successful
+*/
+int base64_encode(const unsigned char *in,  unsigned long inlen, 
+                        unsigned char *out, unsigned long *outlen)
+{
+   unsigned long i, len2, leven;
+   unsigned char *p;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* valid output size ? */
+   len2 = 4 * ((inlen + 2) / 3);
+   if (*outlen < len2 + 1) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+   p = out;
+   leven = 3*(inlen / 3);
+   for (i = 0; i < leven; i += 3) {
+       *p++ = codes[(in[0] >> 2) & 0x3F];
+       *p++ = codes[(((in[0] & 3) << 4) + (in[1] >> 4)) & 0x3F];
+       *p++ = codes[(((in[1] & 0xf) << 2) + (in[2] >> 6)) & 0x3F];
+       *p++ = codes[in[2] & 0x3F];
+       in += 3;
+   }
+   /* Pad it if necessary...  */
+   if (i < inlen) {
+       unsigned a = in[0];
+       unsigned b = (i+1 < inlen) ? in[1] : 0;
+
+       *p++ = codes[(a >> 2) & 0x3F];
+       *p++ = codes[(((a & 3) << 4) + (b >> 4)) & 0x3F];
+       *p++ = (i+1 < inlen) ? codes[(((b & 0xf) << 2)) & 0x3F] : '=';
+       *p++ = '=';
+   }
+
+   /* append a NULL byte */
+   *p = '\0';
+
+   /* return ok */
+   *outlen = p - out;
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/base64/base64_encode.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/burn_stack.c b/src/misc/burn_stack.c
new file mode 100644
index 0000000..7ac6518
--- /dev/null
+++ b/src/misc/burn_stack.c
@@ -0,0 +1,34 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file burn_stack.c
+   Burn stack, Tom St Denis
+*/
+
+/**
+   Burn some stack memory
+   @param len amount of stack to burn in bytes
+*/
+void burn_stack(unsigned long len)
+{
+   unsigned char buf[32];
+   zeromem(buf, sizeof(buf));
+   if (len > (unsigned long)sizeof(buf))
+      burn_stack(len - sizeof(buf));
+}
+
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/burn_stack.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/crypt.c b/src/misc/crypt/crypt.c
similarity index 61%
rename from crypt.c
rename to src/misc/crypt/crypt.c
index 68615c2..eb75b8d 100644
--- a/crypt.c
+++ b/src/misc/crypt/crypt.c
@@ -6,14 +6,20 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
-/* Dropbear doesn't need these 
+/**
+  @file crypt.c
+  Build strings, Tom St Denis
+*/  
 
+/*
 const char *crypt_build_settings =
-   "LibTomCrypt " SCRYPT "\n\n"
+   "LibTomCrypt " SCRYPT " (Tom St Denis, tomstdenis@gmail.com)\n"
+   "LibTomCrypt is public domain software.\n"
+   "Built on " __DATE__ " at " __TIME__ "\n\n\n"
    "Endianess: "
 #if defined(ENDIAN_NEUTRAL)
    "neutral\n"
@@ -33,7 +39,7 @@
    #endif
 #endif
    "Clean stack: "
-#if defined(CLEAN_STACK)
+#if defined(LTC_CLEAN_STACK)
    "enabled\n"
 #else
    "disabled\n"
@@ -65,12 +71,20 @@
 #endif
 #if defined(TWOFISH)
    "   Twofish "
-   #if defined(TWOFISH_SMALL) && defined(TWOFISH_TABLES)
+   #if defined(TWOFISH_SMALL) && defined(TWOFISH_TABLES) && defined(TWOFISH_ALL_TABLES)
+       "(small, tables, all_tables)\n"
+   #elif defined(TWOFISH_SMALL) && defined(TWOFISH_TABLES)
        "(small, tables)\n"
+   #elif defined(TWOFISH_SMALL) && defined(TWOFISH_ALL_TABLES)
+       "(small, all_tables)\n"
+   #elif defined(TWOFISH_TABLES) && defined(TWOFISH_ALL_TABLES)
+       "(tables, all_tables)\n"
    #elif defined(TWOFISH_SMALL)
        "(small)\n"
    #elif defined(TWOFISH_TABLES)
        "(tables)\n"
+   #elif defined(TWOFISH_ALL_TABLES)
+       "(all_tables)\n"
    #else
        "\n"
    #endif
@@ -87,6 +101,16 @@
 #if defined(SKIPJACK)
    "   Skipjack\n"
 #endif
+#if defined(KHAZAD)
+   "   Khazad\n"
+#endif
+#if defined(ANUBIS)
+   "   Anubis "
+#endif
+#if defined(ANUBIS_TWEAK)
+   " (tweaked)"
+#endif
+   "\n"
 
     "\nHashes built-in:\n"
 #if defined(SHA512)
@@ -125,6 +149,9 @@
 #if defined(WHIRLPOOL)
    "   WHIRLPOOL\n"
 #endif
+#if defined(CHC_HASH)
+   "   CHC_HASH \n"
+#endif
 
     "\nBlock Chaining Modes:\n"
 #if defined(CFB)
@@ -143,6 +170,39 @@
     "   CTR\n"
 #endif
 
+    "\nMACs:\n"
+#if defined(HMAC)
+    "   HMAC\n"
+#endif
+#if defined(OMAC)
+    "   OMAC\n"
+#endif
+#if defined(PMAC)
+    "   PMAC\n"
+#endif
+#if defined(PELICAN)
+    "   PELICAN\n"
+#endif
+
+    "\nENC + AUTH modes:\n"
+#if defined(EAX_MODE)
+    "   EAX_MODE\n"
+#endif
+#if defined(OCB_MODE)
+    "   OCB_MODE\n"
+#endif
+#if defined(CCM_MODE)
+    "   CCM_MODE\n"
+#endif
+#if defined(GCM_MODE)
+    "   GCM_MODE "
+#endif
+#if defined(GCM_TABLES)
+    " (GCM_TABLES) "
+#endif
+   "\n"
+
+
     "\nPRNG:\n"
 #if defined(YARROW)
     "   Yarrow\n"
@@ -153,14 +213,16 @@
 #if defined(RC4)
     "   RC4\n"
 #endif
+#if defined(FORTUNA)
+    "   Fortuna\n"
+#endif
+#if defined(SOBER128)
+    "   SOBER128\n"
+#endif
 
     "\nPK Algs:\n"
 #if defined(MRSA)
-    "   RSA"
-#if defined(RSA_TIMING)
-    " + RSA_TIMING "
-#endif
-    "\n"
+    "   RSA \n"
 #endif
 #if defined(MDH)
     "   DH\n"
@@ -176,10 +238,10 @@
 #if defined(WIN32)
     "   WIN32 platform detected.\n"
 #endif
-#if defined(__CYGWIN__)
+#if defined(LBL_CYGWIN__)
     "   CYGWIN Detected.\n"
 #endif
-#if defined(__DJGPP__)
+#if defined(LBL_DJGPP__)
     "   DJGPP Detected.\n"
 #endif
 #if defined(_MSC_VER)
@@ -191,6 +253,9 @@
 #if defined(INTEL_CC)
     "   Intel C Compiler detected.\n"
 #endif
+#if defined(LBL_x86_64__)
+    "   x86-64 detected.\n"
+#endif
 
     "\nVarious others: "
 #if defined(BASE64)
@@ -199,21 +264,6 @@
 #if defined(MPI)
     " MPI "
 #endif
-#if defined(HMAC)
-    " HMAC "
-#endif
-#if defined(OMAC)
-    " OMAC "
-#endif
-#if defined(PMAC)
-    " PMAC "
-#endif
-#if defined(EAX_MODE)
-    " EAX_MODE "
-#endif
-#if defined(OCB_MODE)
-    " OCB_MODE "
-#endif
 #if defined(TRY_UNRANDOM_FIRST)
     " TRY_UNRANDOM_FIRST "
 #endif
@@ -226,17 +276,42 @@
 #if defined(PKCS_5)
     " PKCS#5 "
 #endif
-#if defined(SMALL_CODE)
-    " SMALL_CODE "
+#if defined(LTC_SMALL_CODE)
+    " LTC_SMALL_CODE "
 #endif
-#if defined(NO_FILE)
-    " NO_FILE "
+#if defined(LTC_NO_FILE)
+    " LTC_NO_FILE "
 #endif
-#if defined(LTC_TEST)
-    " LTC_TEST "
+#if defined(LTC_DER)
+    " LTC_DER "
+#endif
+#if defined(LTC_FAST)
+    " LTC_FAST "
+#endif
+#if defined(LTC_NO_FAST)
+    " LTC_NO_FAST "
+#endif
+#if defined(LTC_NO_BSWAP)
+    " LTC_NO_BSWAP "
+#endif
+#if defined(LTC_NO_ASM)
+    " LTC_NO_ASM "
+#endif
+#if defined(LTC_NO_TEST)
+    " LTC_NO_TEST "
+#endif
+#if defined(LTC_NO_TABLES)
+    " LTC_NO_TABLES "
+#endif
+#if defined(LTC_PTHREAD)
+    " LTC_PTHREAD "
 #endif
     "\n"
     "\n\n\n"
     ;
 	*/
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt.c,v $ */
+/* $Revision: 1.11 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_argchk.c b/src/misc/crypt/crypt_argchk.c
new file mode 100644
index 0000000..699c6cf
--- /dev/null
+++ b/src/misc/crypt/crypt_argchk.c
@@ -0,0 +1,30 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <signal.h>
+
+/**
+  @file crypt_argchk.c
+  Perform argument checking, Tom St Denis
+*/  
+
+#if (ARGTYPE == 0)
+void crypt_argchk(char *v, char *s, int d)
+{
+ fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n",
+         v, d, s);
+ (void)raise(SIGABRT);
+}
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_argchk.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/crypt/crypt_cipher_descriptor.c b/src/misc/crypt/crypt_cipher_descriptor.c
new file mode 100644
index 0000000..127e85c
--- /dev/null
+++ b/src/misc/crypt/crypt_cipher_descriptor.c
@@ -0,0 +1,27 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_cipher_descriptor.c
+  Stores the cipher descriptor table, Tom St Denis
+*/
+
+struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = {
+{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+ };
+
+LTC_MUTEX_GLOBAL(ltc_cipher_mutex);
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_cipher_descriptor.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_cipher_is_valid.c b/src/misc/crypt/crypt_cipher_is_valid.c
new file mode 100644
index 0000000..7830303
--- /dev/null
+++ b/src/misc/crypt/crypt_cipher_is_valid.c
@@ -0,0 +1,36 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_cipher_is_valid.c
+  Determine if cipher is valid, Tom St Denis
+*/
+
+/*
+   Test if a cipher index is valid
+   @param idx   The index of the cipher to search for
+   @return CRYPT_OK if valid
+*/
+int cipher_is_valid(int idx)
+{
+   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
+   if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
+      LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+      return CRYPT_INVALID_CIPHER;
+   }
+   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+   return CRYPT_OK;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_cipher_is_valid.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_find_cipher.c b/src/misc/crypt/crypt_find_cipher.c
new file mode 100644
index 0000000..e7fba73
--- /dev/null
+++ b/src/misc/crypt/crypt_find_cipher.c
@@ -0,0 +1,41 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_cipher.c
+  Find a cipher in the descriptor tables, Tom St Denis
+*/
+
+/**
+   Find a registered cipher by name
+   @param name   The name of the cipher to look for
+   @return >= 0 if found, -1 if not present
+*/
+int find_cipher(const char *name)
+{
+   int x;
+   LTC_ARGCHK(name != NULL);
+   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (cipher_descriptor[x].name != NULL && !strcmp(cipher_descriptor[x].name, name)) {
+          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+          return x;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+   return -1;
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_cipher.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_find_cipher_any.c b/src/misc/crypt/crypt_find_cipher_any.c
new file mode 100644
index 0000000..6dd0e6d
--- /dev/null
+++ b/src/misc/crypt/crypt_find_cipher_any.c
@@ -0,0 +1,50 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_cipher_any.c
+  Find a cipher in the descriptor tables, Tom St Denis
+*/
+
+/**
+   Find a cipher flexibly.  First by name then if not present by block and key size 
+   @param name        The name of the cipher desired
+   @param blocklen    The minimum length of the block cipher desired (octets)
+   @param keylen      The minimum length of the key size desired (octets)
+   @return >= 0 if found, -1 if not present
+*/
+int find_cipher_any(const char *name, int blocklen, int keylen)
+{
+   int x;
+
+   LTC_ARGCHK(name != NULL);
+
+   x = find_cipher(name);
+   if (x != -1) return x;
+
+   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (cipher_descriptor[x].name == NULL) {
+          continue;
+       }
+       if (blocklen <= (int)cipher_descriptor[x].block_length && keylen <= (int)cipher_descriptor[x].max_key_length) {
+          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+          return x;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_cipher_any.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_find_cipher_id.c b/src/misc/crypt/crypt_find_cipher_id.c
new file mode 100644
index 0000000..5f5f874
--- /dev/null
+++ b/src/misc/crypt/crypt_find_cipher_id.c
@@ -0,0 +1,40 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_cipher_id.c
+  Find cipher by ID, Tom St Denis
+*/
+
+/**
+   Find a cipher by ID number
+   @param ID    The ID (not same as index) of the cipher to find
+   @return >= 0 if found, -1 if not present
+*/
+int find_cipher_id(unsigned char ID)
+{
+   int x;
+   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (cipher_descriptor[x].ID == ID) {
+          x = (cipher_descriptor[x].name == NULL) ? -1 : x;
+          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+          return x;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_cipher_id.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_find_hash.c b/src/misc/crypt/crypt_find_hash.c
new file mode 100644
index 0000000..d02a449
--- /dev/null
+++ b/src/misc/crypt/crypt_find_hash.c
@@ -0,0 +1,40 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_hash.c
+  Find a hash, Tom St Denis
+*/
+
+/**
+   Find a registered hash by name
+   @param name   The name of the hash to look for
+   @return >= 0 if found, -1 if not present
+*/
+int find_hash(const char *name)
+{
+   int x;
+   LTC_ARGCHK(name != NULL);
+   LTC_MUTEX_LOCK(&ltc_hash_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (hash_descriptor[x].name != NULL && strcmp(hash_descriptor[x].name, name) == 0) {
+          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+          return x;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_find_hash_any.c b/src/misc/crypt/crypt_find_hash_any.c
new file mode 100644
index 0000000..1172f22
--- /dev/null
+++ b/src/misc/crypt/crypt_find_hash_any.c
@@ -0,0 +1,49 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_hash_any.c
+  Find a hash, Tom St Denis
+*/
+
+/**
+   Find a hash flexibly.  First by name then if not present by digest size 
+   @param name        The name of the hash desired
+   @param digestlen   The minimum length of the digest size (octets)
+   @return >= 0 if found, -1 if not present
+*/int find_hash_any(const char *name, int digestlen)
+{
+   int x, y, z;
+   LTC_ARGCHK(name != NULL);
+
+   x = find_hash(name);
+   if (x != -1) return x;
+
+   LTC_MUTEX_LOCK(&ltc_hash_mutex);
+   y = MAXBLOCKSIZE+1;
+   z = -1;
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (hash_descriptor[x].name == NULL) {
+          continue;
+       }
+       if ((int)hash_descriptor[x].hashsize >= digestlen && (int)hash_descriptor[x].hashsize < y) {
+          z = x;
+          y = hash_descriptor[x].hashsize;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+   return z;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash_any.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_find_hash_id.c b/src/misc/crypt/crypt_find_hash_id.c
new file mode 100644
index 0000000..8cd0d38
--- /dev/null
+++ b/src/misc/crypt/crypt_find_hash_id.c
@@ -0,0 +1,40 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_hash_id.c
+  Find hash by ID, Tom St Denis
+*/
+
+/**
+   Find a hash by ID number
+   @param ID    The ID (not same as index) of the hash to find
+   @return >= 0 if found, -1 if not present
+*/
+int find_hash_id(unsigned char ID)
+{
+   int x;
+   LTC_MUTEX_LOCK(&ltc_hash_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+      if (hash_descriptor[x].ID == ID) {
+          x = (hash_descriptor[x].name == NULL) ? -1 : x;
+          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+          return x;
+      }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash_id.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/06/19 18:03:25 $ */
diff --git a/src/misc/crypt/crypt_find_prng.c b/src/misc/crypt/crypt_find_prng.c
new file mode 100644
index 0000000..503813d
--- /dev/null
+++ b/src/misc/crypt/crypt_find_prng.c
@@ -0,0 +1,41 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_find_prng.c
+  Find a PRNG, Tom St Denis
+*/
+
+/**
+   Find a registered PRNG by name
+   @param name   The name of the PRNG to look for
+   @return >= 0 if found, -1 if not present
+*/
+int find_prng(const char *name)
+{
+   int x;
+   LTC_ARGCHK(name != NULL);
+   LTC_MUTEX_LOCK(&ltc_prng_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if ((prng_descriptor[x].name != NULL) && strcmp(prng_descriptor[x].name, name) == 0) {
+          LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+          return x;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+   return -1;
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_prng.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_hash_descriptor.c b/src/misc/crypt/crypt_hash_descriptor.c
new file mode 100644
index 0000000..f8583d8
--- /dev/null
+++ b/src/misc/crypt/crypt_hash_descriptor.c
@@ -0,0 +1,27 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_hash_descriptor.c
+  Stores the hash descriptor table, Tom St Denis  
+*/
+
+struct ltc_hash_descriptor hash_descriptor[TAB_SIZE] = {
+{ NULL, 0, 0, 0, { 0 }, 0, NULL, NULL, NULL, NULL }
+};
+
+LTC_MUTEX_GLOBAL(ltc_hash_mutex);
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_descriptor.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_hash_is_valid.c b/src/misc/crypt/crypt_hash_is_valid.c
new file mode 100644
index 0000000..a8130d4
--- /dev/null
+++ b/src/misc/crypt/crypt_hash_is_valid.c
@@ -0,0 +1,36 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_hash_is_valid.c
+  Determine if hash is valid, Tom St Denis
+*/  
+
+/*
+   Test if a hash index is valid
+   @param idx   The index of the hash to search for
+   @return CRYPT_OK if valid
+*/
+int hash_is_valid(int idx)
+{
+   LTC_MUTEX_LOCK(&ltc_hash_mutex);
+   if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
+      LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+      return CRYPT_INVALID_HASH;
+   }
+   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+   return CRYPT_OK;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_prng_descriptor.c b/src/misc/crypt/crypt_prng_descriptor.c
new file mode 100644
index 0000000..7335f5d
--- /dev/null
+++ b/src/misc/crypt/crypt_prng_descriptor.c
@@ -0,0 +1,26 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_prng_descriptor.c
+  Stores the PRNG descriptors, Tom St Denis
+*/  
+struct ltc_prng_descriptor prng_descriptor[TAB_SIZE] = {
+{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+};
+
+LTC_MUTEX_GLOBAL(ltc_prng_mutex);
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_prng_descriptor.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_prng_is_valid.c b/src/misc/crypt/crypt_prng_is_valid.c
new file mode 100644
index 0000000..a7a7ed6
--- /dev/null
+++ b/src/misc/crypt/crypt_prng_is_valid.c
@@ -0,0 +1,36 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_prng_is_valid.c
+  Determine if PRNG is valid, Tom St Denis
+*/
+
+/*
+   Test if a PRNG index is valid
+   @param idx   The index of the PRNG to search for
+   @return CRYPT_OK if valid
+*/
+int prng_is_valid(int idx)
+{
+   LTC_MUTEX_LOCK(&ltc_prng_mutex);
+   if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
+      LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+      return CRYPT_INVALID_PRNG;
+   }
+   LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+   return CRYPT_OK;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_prng_is_valid.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_register_cipher.c b/src/misc/crypt/crypt_register_cipher.c
new file mode 100644
index 0000000..c55d7c0
--- /dev/null
+++ b/src/misc/crypt/crypt_register_cipher.c
@@ -0,0 +1,54 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_register_cipher.c
+  Register a cipher, Tom St Denis
+*/
+
+/**
+   Register a cipher with the descriptor table
+   @param cipher   The cipher you wish to register
+   @return value >= 0 if successfully added (or already present), -1 if unsuccessful
+*/
+int register_cipher(const struct ltc_cipher_descriptor *cipher)
+{
+   int x;
+
+   LTC_ARGCHK(cipher != NULL);
+
+   /* is it already registered? */
+   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
+          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+          return x;
+       }
+   }
+
+   /* find a blank spot */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (cipher_descriptor[x].name == NULL) {
+          XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor));
+          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+          return x;
+       }
+   }
+
+   /* no spot */
+   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_register_cipher.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_register_hash.c b/src/misc/crypt/crypt_register_hash.c
new file mode 100644
index 0000000..0ff521f
--- /dev/null
+++ b/src/misc/crypt/crypt_register_hash.c
@@ -0,0 +1,54 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_register_hash.c
+  Register a HASH, Tom St Denis
+*/
+
+/**
+   Register a hash with the descriptor table
+   @param hash   The hash you wish to register
+   @return value >= 0 if successfully added (or already present), -1 if unsuccessful
+*/
+int register_hash(const struct ltc_hash_descriptor *hash)
+{
+   int x;
+
+   LTC_ARGCHK(hash != NULL);
+
+   /* is it already registered? */
+   LTC_MUTEX_LOCK(&ltc_hash_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
+          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+          return x;
+       }
+   }
+
+   /* find a blank spot */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (hash_descriptor[x].name == NULL) {
+          XMEMCPY(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor));
+          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+          return x;
+       }
+   }
+
+   /* no spot */
+   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_register_hash.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_register_prng.c b/src/misc/crypt/crypt_register_prng.c
new file mode 100644
index 0000000..5ab4a49
--- /dev/null
+++ b/src/misc/crypt/crypt_register_prng.c
@@ -0,0 +1,54 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_register_prng.c
+  Register a PRNG, Tom St Denis
+*/
+  
+/**
+   Register a PRNG with the descriptor table
+   @param prng   The PRNG you wish to register
+   @return value >= 0 if successfully added (or already present), -1 if unsuccessful
+*/
+int register_prng(const struct ltc_prng_descriptor *prng)
+{
+   int x;
+
+   LTC_ARGCHK(prng != NULL);
+
+   /* is it already registered? */
+   LTC_MUTEX_LOCK(&ltc_prng_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {
+          LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+          return x;
+       }
+   }
+
+   /* find a blank spot */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (prng_descriptor[x].name == NULL) {
+          XMEMCPY(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor));
+          LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+          return x;
+       }
+   }
+
+   /* no spot */
+   LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+   return -1;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_register_prng.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_unregister_cipher.c b/src/misc/crypt/crypt_unregister_cipher.c
new file mode 100644
index 0000000..4081ca8
--- /dev/null
+++ b/src/misc/crypt/crypt_unregister_cipher.c
@@ -0,0 +1,45 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_unregister_cipher.c
+  Unregister a cipher, Tom St Denis
+*/
+
+/**
+  Unregister a cipher from the descriptor table
+  @param cipher   The cipher descriptor to remove
+  @return CRYPT_OK on success
+*/
+int unregister_cipher(const struct ltc_cipher_descriptor *cipher)
+{
+   int x;
+
+   LTC_ARGCHK(cipher != NULL);
+
+   /* is it already registered? */
+   LTC_MUTEX_LOCK(&ltc_cipher_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor)) == 0) {
+          cipher_descriptor[x].name = NULL;
+          cipher_descriptor[x].ID   = 255;
+          LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+          return CRYPT_OK;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
+   return CRYPT_ERROR;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_unregister_cipher.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_unregister_hash.c b/src/misc/crypt/crypt_unregister_hash.c
new file mode 100644
index 0000000..fdd25b2
--- /dev/null
+++ b/src/misc/crypt/crypt_unregister_hash.c
@@ -0,0 +1,44 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_unregister_hash.c
+  Unregister a hash, Tom St Denis
+*/
+
+/**
+  Unregister a hash from the descriptor table
+  @param hash   The hash descriptor to remove
+  @return CRYPT_OK on success
+*/
+int unregister_hash(const struct ltc_hash_descriptor *hash)
+{
+   int x;
+
+   LTC_ARGCHK(hash != NULL);
+
+   /* is it already registered? */
+   LTC_MUTEX_LOCK(&ltc_hash_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
+          hash_descriptor[x].name = NULL;
+          LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+          return CRYPT_OK;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_hash_mutex);
+   return CRYPT_ERROR;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_unregister_hash.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/src/misc/crypt/crypt_unregister_prng.c b/src/misc/crypt/crypt_unregister_prng.c
new file mode 100644
index 0000000..4aff6de
--- /dev/null
+++ b/src/misc/crypt/crypt_unregister_prng.c
@@ -0,0 +1,44 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file crypt_unregister_prng.c
+  Unregister a PRNG, Tom St Denis
+*/
+
+/**
+  Unregister a PRNG from the descriptor table
+  @param prng   The PRNG descriptor to remove
+  @return CRYPT_OK on success
+*/
+int unregister_prng(const struct ltc_prng_descriptor *prng)
+{
+   int x;
+
+   LTC_ARGCHK(prng != NULL);
+ 
+   /* is it already registered? */
+   LTC_MUTEX_LOCK(&ltc_prng_mutex);
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) != 0) {
+          prng_descriptor[x].name = NULL;
+          LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+          return CRYPT_OK;
+       }
+   }
+   LTC_MUTEX_UNLOCK(&ltc_prng_mutex);
+   return CRYPT_ERROR;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_unregister_prng.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 18:00:28 $ */
diff --git a/error_to_string.c b/src/misc/error_to_string.c
similarity index 71%
rename from error_to_string.c
rename to src/misc/error_to_string.c
index 9c388fa..6167a70 100644
--- a/error_to_string.c
+++ b/src/misc/error_to_string.c
@@ -6,10 +6,15 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
 
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file error_to_string.c
+  Convert error codes to ASCII strings, Tom St Denis
+*/
 
 static const char *err_2_str[] =
 {
@@ -49,6 +54,11 @@
 
 };
 
+/**
+   Convert an LTC error code to ASCII
+   @param err    The error code
+   @return A pointer to the ASCII NUL terminated string for the error or "Invalid error code." if the err code was not valid.
+*/
 const char *error_to_string(int err)
 {
    if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) {
@@ -58,3 +68,7 @@
    }   
 }
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/error_to_string.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/is_prime.c b/src/misc/mpi/is_prime.c
similarity index 61%
rename from is_prime.c
rename to src/misc/mpi/is_prime.c
index d6fc84e..9ee4ed2 100644
--- a/is_prime.c
+++ b/src/misc/mpi/is_prime.c
@@ -6,9 +6,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file is_prime.c
+  Determines if integer is prime for LTC, Tom St Denis
+*/  
 
 #ifdef MPI
 
@@ -16,8 +21,8 @@
 int is_prime(mp_int *N, int *result)
 {
    int err;
-   _ARGCHK(N != NULL);
-   _ARGCHK(result != NULL);
+   LTC_ARGCHK(N != NULL);
+   LTC_ARGCHK(result != NULL);
    if ((err = mp_prime_is_prime(N, mp_prime_rabin_miller_trials(mp_count_bits(N)), result)) != MP_OKAY) {
       return mpi_to_ltc_error(err);
    }
@@ -25,3 +30,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/mpi/is_prime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/mpi/mpi_to_ltc_error.c b/src/misc/mpi/mpi_to_ltc_error.c
new file mode 100644
index 0000000..bc39ea1
--- /dev/null
+++ b/src/misc/mpi/mpi_to_ltc_error.c
@@ -0,0 +1,48 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file mpi_to_ltc_error.c
+  Convert MPI errors to LTC, Tom St Denis
+*/  
+
+#ifdef MPI
+static const struct {
+    int mpi_code, ltc_code;
+} mpi_to_ltc_codes[] = {
+   { MP_OKAY ,  CRYPT_OK},
+   { MP_MEM  ,  CRYPT_MEM},
+   { MP_VAL  ,  CRYPT_INVALID_ARG},
+};
+
+/**
+   Convert a MPI error to a LTC error (Possibly the most powerful function ever!  Oh wait... no) 
+   @param err    The error to convert
+   @return The equivalent LTC error code or CRYPT_ERROR if none found
+*/
+int mpi_to_ltc_error(int err)
+{
+   int x;
+
+   for (x = 0; x < (int)(sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0])); x++) {
+       if (err == mpi_to_ltc_codes[x].mpi_code) { 
+          return mpi_to_ltc_codes[x].ltc_code;
+       }
+   }
+   return CRYPT_ERROR;
+}
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/mpi/mpi_to_ltc_error.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/rand_prime.c b/src/misc/mpi/rand_prime.c
similarity index 80%
rename from rand_prime.c
rename to src/misc/mpi/rand_prime.c
index 4e9cdbd..9c5921a 100644
--- a/rand_prime.c
+++ b/src/misc/mpi/rand_prime.c
@@ -6,10 +6,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
+/**
+  @file rand_prime.c
+  Generate a random prime, Tom St Denis
+*/  
 #ifdef MPI
 
 struct rng_data {
@@ -27,7 +31,7 @@
    struct rng_data rng;
    int             type, err;
 
-   _ARGCHK(N != NULL);
+   LTC_ARGCHK(N != NULL);
 
    /* allow sizes between 2 and 256 bytes for a prime size */
    if (len < 16 || len > 4096) { 
@@ -50,6 +54,7 @@
    } else {
       type = 0;
    }
+  type |= LTM_PRIME_2MSB_ON;
 
    /* New prime generation makes the code even more cryptoish-insane.  Do you know what this means!!!
       -- Gir:  Yeah, oh wait, er, no.
@@ -59,3 +64,7 @@
       
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/mpi/rand_prime.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/pkcs5/pkcs_5_1.c b/src/misc/pkcs5/pkcs_5_1.c
new file mode 100644
index 0000000..90411b7
--- /dev/null
+++ b/src/misc/pkcs5/pkcs_5_1.c
@@ -0,0 +1,106 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include <tomcrypt.h>
+
+/** 
+   @file pkcs_5_1.c
+   PKCS #5, Algorithm #1, Tom St Denis
+*/
+#ifdef PKCS_5
+/**
+   Execute PKCS #5 v1
+   @param password         The password (or key)
+   @param password_len     The length of the password (octet)
+   @param salt             The salt (or nonce) which is 8 octets long
+   @param iteration_count  The PKCS #5 v1 iteration count
+   @param hash_idx         The index of the hash desired
+   @param out              [out] The destination for this algorithm
+   @param outlen           [in/out] The max size and resulting size of the algorithm output
+   @return CRYPT_OK if successful
+*/
+int pkcs_5_alg1(const unsigned char *password, unsigned long password_len, 
+                const unsigned char *salt, 
+                int iteration_count,  int hash_idx,
+                unsigned char *out,   unsigned long *outlen)
+{
+   int err;
+   unsigned long x;
+   hash_state    *md;
+   unsigned char *buf;
+
+   LTC_ARGCHK(password != NULL);
+   LTC_ARGCHK(salt     != NULL);
+   LTC_ARGCHK(out      != NULL);
+   LTC_ARGCHK(outlen   != NULL);
+
+   /* test hash IDX */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* allocate memory */
+   md  = XMALLOC(sizeof(hash_state));
+   buf = XMALLOC(MAXBLOCKSIZE);
+   if (md == NULL || buf == NULL) {
+      if (md != NULL) {
+         XFREE(md);
+      }
+      if (buf != NULL) { 
+         XFREE(buf);
+      }
+      return CRYPT_MEM;
+   }        
+
+   /* hash initial password + salt */
+   if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
+       goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].process(md, password, password_len)) != CRYPT_OK) {
+       goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].process(md, salt, 8)) != CRYPT_OK) {
+       goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
+       goto LBL_ERR;
+   }
+
+   while (--iteration_count) {
+      /* code goes here. */
+      x = MAXBLOCKSIZE;
+      if ((err = hash_memory(hash_idx, buf, hash_descriptor[hash_idx].hashsize, buf, &x)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+   }
+
+   /* copy upto outlen bytes */
+   for (x = 0; x < hash_descriptor[hash_idx].hashsize && x < *outlen; x++) {
+       out[x] = buf[x];
+   }
+   *outlen = x;
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK 
+   zeromem(buf, MAXBLOCKSIZE);
+   zeromem(md, sizeof(hash_state));
+#endif
+
+   XFREE(buf);
+   XFREE(md);
+
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/pkcs5/pkcs_5_1.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/pkcs5/pkcs_5_2.c b/src/misc/pkcs5/pkcs_5_2.c
new file mode 100644
index 0000000..08d8a18
--- /dev/null
+++ b/src/misc/pkcs5/pkcs_5_2.c
@@ -0,0 +1,129 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include <tomcrypt.h>
+
+/** 
+   @file pkcs_5_2.c
+   PKCS #5, Algorithm #2, Tom St Denis
+*/
+#ifdef PKCS_5
+
+/**
+   Execute PKCS #5 v2
+   @param password          The input password (or key)
+   @param password_len      The length of the password (octets)
+   @param salt              The salt (or nonce)
+   @param salt_len          The length of the salt (octets)
+   @param iteration_count   # of iterations desired for PKCS #5 v2 [read specs for more]
+   @param hash_idx          The index of the hash desired
+   @param out               [out] The destination for this algorithm
+   @param outlen            [in/out] The max size and resulting size of the algorithm output
+   @return CRYPT_OK if successful
+*/
+int pkcs_5_alg2(const unsigned char *password, unsigned long password_len, 
+                const unsigned char *salt,     unsigned long salt_len,
+                int iteration_count,           int hash_idx,
+                unsigned char *out,            unsigned long *outlen)
+{
+   int err, itts;
+   ulong32  blkno;
+   unsigned long stored, left, x, y;
+   unsigned char *buf[2];
+   hmac_state    *hmac;
+
+   LTC_ARGCHK(password != NULL);
+   LTC_ARGCHK(salt     != NULL);
+   LTC_ARGCHK(out      != NULL);
+   LTC_ARGCHK(outlen   != NULL);
+
+   /* test hash IDX */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   buf[0] = XMALLOC(MAXBLOCKSIZE * 2);
+   hmac   = XMALLOC(sizeof(hmac_state));
+   if (hmac == NULL || buf[0] == NULL) {
+      if (hmac != NULL) {
+         XFREE(hmac);
+      }
+      if (buf[0] != NULL) {
+         XFREE(buf[0]);
+      }
+      return CRYPT_MEM;
+   }
+   /* buf[1] points to the second block of MAXBLOCKSIZE bytes */
+   buf[1] = buf[0] + MAXBLOCKSIZE;
+
+   left   = *outlen;
+   blkno  = 1;
+   stored = 0;
+   while (left != 0) {
+       /* process block number blkno */
+       zeromem(buf[0], MAXBLOCKSIZE*2);
+       
+       /* store current block number and increment for next pass */
+       STORE32H(blkno, buf[1]);
+       ++blkno;
+
+       /* get PRF(P, S||int(blkno)) */
+       if ((err = hmac_init(hmac, hash_idx, password, password_len)) != CRYPT_OK) { 
+          goto LBL_ERR;
+       }
+       if ((err = hmac_process(hmac, salt, salt_len)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       if ((err = hmac_process(hmac, buf[1], 4)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       x = MAXBLOCKSIZE;
+       if ((err = hmac_done(hmac, buf[0], &x)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+
+       /* now compute repeated and XOR it in buf[1] */
+       XMEMCPY(buf[1], buf[0], x);
+       for (itts = 1; itts < iteration_count; ++itts) {
+           if ((err = hmac_memory(hash_idx, password, password_len, buf[0], x, buf[0], &x)) != CRYPT_OK) {
+              goto LBL_ERR;
+           }
+           for (y = 0; y < x; y++) {
+               buf[1][y] ^= buf[0][y];
+           }
+       }
+
+       /* now emit upto x bytes of buf[1] to output */
+       for (y = 0; y < x && left != 0; ++y) {
+           out[stored++] = buf[1][y];
+           --left;
+       }
+   }
+   *outlen = stored;
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf[0], MAXBLOCKSIZE*2);
+   zeromem(hmac, sizeof(hmac_state));
+#endif
+
+   XFREE(hmac);
+   XFREE(buf[0]);
+
+   return err;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/pkcs5/pkcs_5_2.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/misc/zeromem.c b/src/misc/zeromem.c
new file mode 100644
index 0000000..1ab07dc
--- /dev/null
+++ b/src/misc/zeromem.c
@@ -0,0 +1,34 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file zeromem.c
+   Zero a block of memory, Tom St Denis
+*/
+
+/**
+   Zero a block of memory
+   @param out    The destination of the area to zero
+   @param outlen The length of the area to zero (octets)
+*/
+void zeromem(void *out, size_t outlen)
+{
+   unsigned char *mem = out;
+   LTC_ARGCHK(out != NULL);
+   while (outlen-- > 0) {
+      *mem++ = 0;
+   }
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/src/misc/zeromem.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cbc/cbc_decrypt.c b/src/modes/cbc/cbc_decrypt.c
new file mode 100644
index 0000000..fc3fdd5
--- /dev/null
+++ b/src/modes/cbc/cbc_decrypt.c
@@ -0,0 +1,95 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cbc_decrypt.c
+   CBC implementation, encrypt block, Tom St Denis
+*/
+
+
+#ifdef CBC
+
+/**
+  CBC decrypt
+  @param ct     Ciphertext
+  @param pt     [out] Plaintext
+  @param len    The number of bytes to process (must be multiple of block length)
+  @param cbc    CBC state
+  @return CRYPT_OK if successful
+*/
+int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc)
+{
+   int x, err;
+   unsigned char tmp[16];
+#ifdef LTC_FAST
+   LTC_FAST_TYPE tmpy;
+#else
+   unsigned char tmpy;
+#endif         
+
+   LTC_ARGCHK(pt  != NULL);
+   LTC_ARGCHK(ct  != NULL);
+   LTC_ARGCHK(cbc != NULL);
+
+   if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
+       return err;
+   }
+   
+   /* is blocklen valid? */
+   if (cbc->blocklen < 0 || cbc->blocklen > (int)sizeof(cbc->IV)) {
+      return CRYPT_INVALID_ARG;
+   }    
+
+   if (len % cbc->blocklen) {
+      return CRYPT_INVALID_ARG;
+   }
+#ifdef LTC_FAST
+   if (len % sizeof(LTC_FAST_TYPE)) {   
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+   
+   if (cipher_descriptor[cbc->cipher].accel_cbc_decrypt != NULL) {
+      cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
+   } else {
+      while (len) {
+         /* decrypt */
+         cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key);
+
+         /* xor IV against plaintext */
+         #if defined(LTC_FAST)
+	     for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+	         tmpy = *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^ *((LTC_FAST_TYPE*)((unsigned char *)tmp + x));
+		 *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
+		 *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) = tmpy;
+	     }
+	 #else 
+            for (x = 0; x < cbc->blocklen; x++) {
+               tmpy       = tmp[x] ^ cbc->IV[x];
+               cbc->IV[x] = ct[x];
+               pt[x]      = tmpy;
+            }
+	 #endif
+       
+         ct  += cbc->blocklen;
+         pt  += cbc->blocklen;
+         len -= cbc->blocklen;
+      }
+   }
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_decrypt.c,v $ */
+/* $Revision: 1.9 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cbc/cbc_done.c b/src/modes/cbc/cbc_done.c
new file mode 100644
index 0000000..afaa9bb
--- /dev/null
+++ b/src/modes/cbc/cbc_done.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cbc_done.c
+   CBC implementation, finish chain, Tom St Denis
+*/
+
+#ifdef CBC
+
+/** Terminate the chain
+  @param cbc    The CBC chain to terminate
+  @return CRYPT_OK on success
+*/
+int cbc_done(symmetric_CBC *cbc)
+{
+   int err;
+   LTC_ARGCHK(cbc != NULL);
+
+   if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   cipher_descriptor[cbc->cipher].done(&cbc->key);
+   return CRYPT_OK;
+}
+
+   
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cbc/cbc_encrypt.c b/src/modes/cbc/cbc_encrypt.c
new file mode 100644
index 0000000..a6b41b1
--- /dev/null
+++ b/src/modes/cbc/cbc_encrypt.c
@@ -0,0 +1,96 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cbc_encrypt.c
+   CBC implementation, encrypt block, Tom St Denis
+*/
+
+
+#ifdef CBC
+
+/**
+  CBC encrypt
+  @param pt     Plaintext
+  @param ct     [out] Ciphertext
+  @param len    The number of bytes to process (must be multiple of block length)
+  @param cbc    CBC state
+  @return CRYPT_OK if successful
+*/
+int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc)
+{
+   int x, err;
+
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(cbc != NULL);
+
+   if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
+       return err;
+   }
+   
+   /* is blocklen valid? */
+   if (cbc->blocklen < 0 || cbc->blocklen > (int)sizeof(cbc->IV)) {
+      return CRYPT_INVALID_ARG;
+   }    
+
+   if (len % cbc->blocklen) {
+      return CRYPT_INVALID_ARG;
+   }
+#ifdef LTC_FAST
+   if (len % sizeof(LTC_FAST_TYPE)) {   
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+
+   if (cipher_descriptor[cbc->cipher].accel_cbc_encrypt != NULL) {
+      cipher_descriptor[cbc->cipher].accel_cbc_encrypt(pt, ct, len / cbc->blocklen, cbc->IV, &cbc->key);
+   } else {
+      while (len) {
+         /* xor IV against plaintext */
+         #if defined(LTC_FAST)
+	     for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+	         *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) ^= *((LTC_FAST_TYPE*)((unsigned char *)pt + x));
+	     }
+	 #else 
+            for (x = 0; x < cbc->blocklen; x++) {
+               cbc->IV[x] ^= pt[x];
+            }
+	 #endif
+
+         /* encrypt */
+         cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key);
+
+        /* store IV [ciphertext] for a future block */
+         #if defined(LTC_FAST)
+	     for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+	         *((LTC_FAST_TYPE*)((unsigned char *)cbc->IV + x)) = *((LTC_FAST_TYPE*)((unsigned char *)ct + x));
+	     }
+	 #else 
+             for (x = 0; x < cbc->blocklen; x++) {
+                cbc->IV[x] = ct[x];
+             }
+	 #endif
+        
+        ct  += cbc->blocklen;
+        pt  += cbc->blocklen;
+        len -= cbc->blocklen;
+     }
+   }
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_encrypt.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cbc/cbc_getiv.c b/src/modes/cbc/cbc_getiv.c
new file mode 100644
index 0000000..ab418b1
--- /dev/null
+++ b/src/modes/cbc/cbc_getiv.c
@@ -0,0 +1,45 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cbc_getiv.c
+   CBC implementation, get IV, Tom St Denis
+*/
+
+#ifdef CBC
+
+/**
+   Get the current initial vector
+   @param IV   [out] The destination of the initial vector
+   @param len  [in/out]  The max size and resulting size of the initial vector
+   @param cbc  The CBC state
+   @return CRYPT_OK if successful
+*/
+int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc)
+{
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(len != NULL);
+   LTC_ARGCHK(cbc != NULL);
+   if ((unsigned long)cbc->blocklen > *len) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+   XMEMCPY(IV, cbc->IV, cbc->blocklen);
+   *len = cbc->blocklen;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_getiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cbc/cbc_setiv.c b/src/modes/cbc/cbc_setiv.c
new file mode 100644
index 0000000..c38e713
--- /dev/null
+++ b/src/modes/cbc/cbc_setiv.c
@@ -0,0 +1,44 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cbc_setiv.c
+   CBC implementation, set IV, Tom St Denis
+*/
+
+
+#ifdef CBC
+
+/**
+   Set an initial vector
+   @param IV   The initial vector
+   @param len  The length of the vector (in octets)
+   @param cbc  The CBC state
+   @return CRYPT_OK if successful
+*/
+int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc)
+{
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(cbc != NULL);
+   if (len != (unsigned long)cbc->blocklen) {
+      return CRYPT_INVALID_ARG;
+   }
+   XMEMCPY(cbc->IV, IV, len);
+   return CRYPT_OK;
+}
+
+#endif 
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_setiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cbc/cbc_start.c b/src/modes/cbc/cbc_start.c
new file mode 100644
index 0000000..833bb87
--- /dev/null
+++ b/src/modes/cbc/cbc_start.c
@@ -0,0 +1,62 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cbc_start.c
+   CBC implementation, start chain, Tom St Denis
+*/
+
+#ifdef CBC
+
+/**
+   Initialize a CBC context
+   @param cipher      The index of the cipher desired
+   @param IV          The initial vector
+   @param key         The secret key 
+   @param keylen      The length of the secret key (octets)
+   @param num_rounds  Number of rounds in the cipher desired (0 for default)
+   @param cbc         The CBC state to initialize
+   @return CRYPT_OK if successful
+*/
+int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+              int keylen, int num_rounds, symmetric_CBC *cbc)
+{
+   int x, err;
+ 
+   LTC_ARGCHK(IV != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(cbc != NULL);
+
+   /* bad param? */
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* setup cipher */
+   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cbc->key)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* copy IV */
+   cbc->blocklen = cipher_descriptor[cipher].block_length;
+   cbc->cipher   = cipher;
+   for (x = 0; x < cbc->blocklen; x++) {
+       cbc->IV[x] = IV[x];
+   }
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cbc/cbc_start.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/cfb_decrypt.c b/src/modes/cfb/cfb_decrypt.c
similarity index 64%
rename from cfb_decrypt.c
rename to src/modes/cfb/cfb_decrypt.c
index 1e1d3c0..3d51ba5 100644
--- a/cfb_decrypt.c
+++ b/src/modes/cfb/cfb_decrypt.c
@@ -6,19 +6,32 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file cfb_decrypt.c
+  CFB implementation, decrypt data, Tom St Denis
+*/
 
 #ifdef CFB
 
+/**
+   CFB decrypt
+   @param ct      Ciphertext
+   @param pt      [out] Plaintext
+   @param len     Length of ciphertext (octets)
+   @param cfb     CFB state
+   @return CRYPT_OK if successful
+*/
 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb)
 {
    int err;
 
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(cfb != NULL);
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(cfb != NULL);
 
    if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
        return err;
@@ -46,3 +59,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_decrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cfb/cfb_done.c b/src/modes/cfb/cfb_done.c
new file mode 100644
index 0000000..8924761
--- /dev/null
+++ b/src/modes/cfb/cfb_done.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cfb_done.c
+   CFB implementation, finish chain, Tom St Denis
+*/
+
+#ifdef CFB
+
+/** Terminate the chain
+  @param cfb    The CFB chain to terminate
+  @return CRYPT_OK on success
+*/
+int cfb_done(symmetric_CFB *cfb)
+{
+   int err;
+   LTC_ARGCHK(cfb != NULL);
+
+   if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   cipher_descriptor[cfb->cipher].done(&cfb->key);
+   return CRYPT_OK;
+}
+
+   
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/cfb_encrypt.c b/src/modes/cfb/cfb_encrypt.c
similarity index 64%
rename from cfb_encrypt.c
rename to src/modes/cfb/cfb_encrypt.c
index 8016959..cca0116 100644
--- a/cfb_encrypt.c
+++ b/src/modes/cfb/cfb_encrypt.c
@@ -6,19 +6,32 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file cfb_encrypt.c
+  CFB implementation, encrypt data, Tom St Denis
+*/
 
 #ifdef CFB
 
+/**
+  CFB encrypt
+  @param pt     Plaintext
+  @param ct     [out] Ciphertext
+  @param len    Length of plaintext (octets)
+  @param cfb    CFB state
+  @return CRYPT_OK if successful
+*/
 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb)
 {
    int err;
 
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(cfb != NULL);
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(cfb != NULL);
 
    if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
        return err;
@@ -44,3 +57,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_encrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cfb/cfb_getiv.c b/src/modes/cfb/cfb_getiv.c
new file mode 100644
index 0000000..5c5b4c4
--- /dev/null
+++ b/src/modes/cfb/cfb_getiv.c
@@ -0,0 +1,45 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cfb_getiv.c
+   CFB implementation, get IV, Tom St Denis
+*/
+
+#ifdef CFB
+
+/**
+   Get the current initial vector
+   @param IV   [out] The destination of the initial vector
+   @param len  [in/out]  The max size and resulting size of the initial vector
+   @param cfb  The CFB state
+   @return CRYPT_OK if successful
+*/
+int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb)
+{
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(len != NULL);
+   LTC_ARGCHK(cfb != NULL);
+   if ((unsigned long)cfb->blocklen > *len) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+   XMEMCPY(IV, cfb->IV, cfb->blocklen);
+   *len = cfb->blocklen;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_getiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cfb/cfb_setiv.c b/src/modes/cfb/cfb_setiv.c
new file mode 100644
index 0000000..d075a0d
--- /dev/null
+++ b/src/modes/cfb/cfb_setiv.c
@@ -0,0 +1,53 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file cfb_setiv.c
+  CFB implementation, set IV, Tom St Denis
+*/  
+#ifdef CFB
+
+/**
+   Set an initial vector
+   @param IV   The initial vector
+   @param len  The length of the vector (in octets)
+   @param cfb  The CFB state
+   @return CRYPT_OK if successful
+*/
+int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb)
+{
+   int err;
+   
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(cfb != NULL);
+
+   if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
+       return err;
+   }
+   
+   if (len != (unsigned long)cfb->blocklen) {
+      return CRYPT_INVALID_ARG;
+   }
+      
+   /* force next block */
+   cfb->padlen = 0;
+   cipher_descriptor[cfb->cipher].ecb_encrypt(IV, cfb->IV, &cfb->key);
+
+   return CRYPT_OK;
+}
+
+#endif 
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_setiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/cfb/cfb_start.c b/src/modes/cfb/cfb_start.c
new file mode 100644
index 0000000..755e173
--- /dev/null
+++ b/src/modes/cfb/cfb_start.c
@@ -0,0 +1,67 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file cfb_start.c
+   CFB implementation, start chain, Tom St Denis
+*/
+
+
+#ifdef CFB
+
+/**
+   Initialize a CFB context
+   @param cipher      The index of the cipher desired
+   @param IV          The initial vector
+   @param key         The secret key 
+   @param keylen      The length of the secret key (octets)
+   @param num_rounds  Number of rounds in the cipher desired (0 for default)
+   @param cfb         The CFB state to initialize
+   @return CRYPT_OK if successful
+*/
+int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+              int keylen, int num_rounds, symmetric_CFB *cfb)
+{
+   int x, err;
+
+   LTC_ARGCHK(IV != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(cfb != NULL);
+
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   
+
+   /* copy data */
+   cfb->cipher = cipher;
+   cfb->blocklen = cipher_descriptor[cipher].block_length;
+   for (x = 0; x < cfb->blocklen; x++)
+       cfb->IV[x] = IV[x];
+
+   /* init the cipher */
+   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* encrypt the IV */
+   cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);
+   cfb->padlen = 0;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/cfb/cfb_start.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ctr/ctr_decrypt.c b/src/modes/ctr/ctr_decrypt.c
new file mode 100644
index 0000000..e1d1d51
--- /dev/null
+++ b/src/modes/ctr/ctr_decrypt.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ctr_decrypt.c
+  CTR implementation, decrypt data, Tom St Denis
+*/
+
+#ifdef CTR
+
+/**
+   CTR decrypt
+   @param ct      Ciphertext
+   @param pt      [out] Plaintext
+   @param len     Length of ciphertext (octets)
+   @param ctr     CTR state
+   @return CRYPT_OK if successful
+*/
+int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr)
+{
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(ctr != NULL);
+
+   return ctr_encrypt(ct, pt, len, ctr);
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_decrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ctr/ctr_done.c b/src/modes/ctr/ctr_done.c
new file mode 100644
index 0000000..f2e79ba
--- /dev/null
+++ b/src/modes/ctr/ctr_done.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ctr_done.c
+   CTR implementation, finish chain, Tom St Denis
+*/
+
+#ifdef CTR
+
+/** Terminate the chain
+  @param ctr    The CTR chain to terminate
+  @return CRYPT_OK on success
+*/
+int ctr_done(symmetric_CTR *ctr)
+{
+   int err;
+   LTC_ARGCHK(ctr != NULL);
+
+   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   cipher_descriptor[ctr->cipher].done(&ctr->key);
+   return CRYPT_OK;
+}
+
+   
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ctr/ctr_encrypt.c b/src/modes/ctr/ctr_encrypt.c
new file mode 100644
index 0000000..79795ae
--- /dev/null
+++ b/src/modes/ctr/ctr_encrypt.c
@@ -0,0 +1,108 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ctr_encrypt.c
+  CTR implementation, encrypt data, Tom St Denis
+*/
+
+
+#ifdef CTR
+
+/**
+  CTR encrypt
+  @param pt     Plaintext
+  @param ct     [out] Ciphertext
+  @param len    Length of plaintext (octets)
+  @param ctr    CTR state
+  @return CRYPT_OK if successful
+*/
+int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr)
+{
+   int x, err;
+
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(ctr != NULL);
+
+   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
+       return err;
+   }
+   
+   /* is blocklen/padlen valid? */
+   if (ctr->blocklen < 0 || ctr->blocklen > (int)sizeof(ctr->ctr) ||
+       ctr->padlen   < 0 || ctr->padlen   > (int)sizeof(ctr->pad)) {
+      return CRYPT_INVALID_ARG;
+   }
+
+#ifdef LTC_FAST
+   if (ctr->blocklen % sizeof(LTC_FAST_TYPE)) {
+      return CRYPT_INVALID_ARG;
+   }
+#endif
+   
+   /* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */
+   if ((ctr->padlen == ctr->blocklen) && cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL && (len >= (unsigned long)ctr->blocklen)) {
+      cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key);
+      len %= ctr->blocklen;
+   }
+
+   while (len) {
+      /* is the pad empty? */
+      if (ctr->padlen == ctr->blocklen) {
+         /* increment counter */
+         if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
+            /* little-endian */
+            for (x = 0; x < ctr->blocklen; x++) {
+               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
+               if (ctr->ctr[x] != (unsigned char)0) {
+                  break;
+               }
+            }
+         } else {
+            /* big-endian */
+            for (x = ctr->blocklen-1; x >= 0; x--) {
+               ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
+               if (ctr->ctr[x] != (unsigned char)0) {
+                  break;
+               }
+            }
+         }
+
+         /* encrypt it */
+         cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
+         ctr->padlen = 0;
+      }
+#ifdef LTC_FAST
+      if (ctr->padlen == 0 && len >= (unsigned long)ctr->blocklen) {
+         for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+            *((LTC_FAST_TYPE*)((unsigned char *)ct + x)) = *((LTC_FAST_TYPE*)((unsigned char *)pt + x)) ^
+                                                           *((LTC_FAST_TYPE*)((unsigned char *)ctr->pad + x));
+         }
+	    pt         += ctr->blocklen;
+	    ct         += ctr->blocklen;
+	    len        -= ctr->blocklen;
+	    ctr->padlen = ctr->blocklen;
+	    continue;
+	 }
+#endif	 
+    *ct++ = *pt++ ^ ctr->pad[ctr->padlen++];
+	 --len;
+   }
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_encrypt.c,v $ */
+/* $Revision: 1.13 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ctr/ctr_getiv.c b/src/modes/ctr/ctr_getiv.c
new file mode 100644
index 0000000..50ce6a0
--- /dev/null
+++ b/src/modes/ctr/ctr_getiv.c
@@ -0,0 +1,45 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ctr_getiv.c
+   CTR implementation, get IV, Tom St Denis
+*/
+
+#ifdef CTR
+
+/**
+   Get the current initial vector
+   @param IV   [out] The destination of the initial vector
+   @param len  [in/out]  The max size and resulting size of the initial vector
+   @param ctr  The CTR state
+   @return CRYPT_OK if successful
+*/
+int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr)
+{
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(len != NULL);
+   LTC_ARGCHK(ctr != NULL);
+   if ((unsigned long)ctr->blocklen > *len) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+   XMEMCPY(IV, ctr->ctr, ctr->blocklen);
+   *len = ctr->blocklen;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_getiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ctr/ctr_setiv.c b/src/modes/ctr/ctr_setiv.c
new file mode 100644
index 0000000..64d4c43
--- /dev/null
+++ b/src/modes/ctr/ctr_setiv.c
@@ -0,0 +1,58 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ctr_setiv.c
+  CTR implementation, set IV, Tom St Denis
+*/
+  
+#ifdef CTR
+
+/**
+   Set an initial vector
+   @param IV   The initial vector
+   @param len  The length of the vector (in octets)
+   @param ctr  The CTR state
+   @return CRYPT_OK if successful
+*/
+int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
+{
+   int err;
+   
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(ctr != NULL);
+
+   /* bad param? */
+   if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   
+   if (len != (unsigned long)ctr->blocklen) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* set IV */
+   XMEMCPY(ctr->ctr, IV, len);
+   
+   /* force next block */
+   ctr->padlen = 0;
+   cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
+   
+   return CRYPT_OK;
+}
+
+#endif 
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_setiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ctr/ctr_start.c b/src/modes/ctr/ctr_start.c
new file mode 100644
index 0000000..7c7eebb
--- /dev/null
+++ b/src/modes/ctr/ctr_start.c
@@ -0,0 +1,70 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ctr_start.c
+   CTR implementation, start chain, Tom St Denis
+*/
+
+
+#ifdef CTR
+
+/**
+   Initialize a CTR context
+   @param cipher      The index of the cipher desired
+   @param IV          The initial vector
+   @param key         The secret key 
+   @param keylen      The length of the secret key (octets)
+   @param num_rounds  Number of rounds in the cipher desired (0 for default)
+   @param ctr_mode    The counter mode (CTR_COUNTER_LITTLE_ENDIAN or CTR_COUNTER_BIG_ENDIAN)
+   @param ctr         The CTR state to initialize
+   @return CRYPT_OK if successful
+*/
+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 x, err;
+
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(ctr != NULL);
+
+   /* bad param? */
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* setup cipher */
+   if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* copy ctr */
+   ctr->blocklen = cipher_descriptor[cipher].block_length;
+   ctr->cipher   = cipher;
+   ctr->padlen   = 0;
+   ctr->mode     = ctr_mode;
+   for (x = 0; x < ctr->blocklen; x++) {
+       ctr->ctr[x] = IV[x];
+   }
+   cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_start.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ecb/ecb_decrypt.c b/src/modes/ecb/ecb_decrypt.c
new file mode 100644
index 0000000..aa83661
--- /dev/null
+++ b/src/modes/ecb/ecb_decrypt.c
@@ -0,0 +1,59 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ecb_decrypt.c
+  ECB implementation, decrypt a block, Tom St Denis
+*/
+
+#ifdef ECB
+
+/**
+  ECB decrypt
+  @param ct     Ciphertext
+  @param pt     [out] Plaintext
+  @param len    The number of octets to process (must be multiple of the cipher block size)
+  @param ecb    ECB state
+  @return CRYPT_OK if successful
+*/
+int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb)
+{
+   int err;
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(ecb != NULL);
+   if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
+       return err;
+   }
+   if (len % cipher_descriptor[ecb->cipher].block_length) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* check for accel */
+   if (cipher_descriptor[ecb->cipher].accel_ecb_decrypt != NULL) {
+      cipher_descriptor[ecb->cipher].accel_ecb_decrypt(ct, pt, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
+   } else {
+      while (len) {
+         cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key);
+         pt  += cipher_descriptor[ecb->cipher].block_length;
+         ct  += cipher_descriptor[ecb->cipher].block_length;
+         len -= cipher_descriptor[ecb->cipher].block_length;
+      }
+   }
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_decrypt.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ecb/ecb_done.c b/src/modes/ecb/ecb_done.c
new file mode 100644
index 0000000..a072615
--- /dev/null
+++ b/src/modes/ecb/ecb_done.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ecb_done.c
+   ECB implementation, finish chain, Tom St Denis
+*/
+
+#ifdef ECB
+
+/** Terminate the chain
+  @param ecb    The ECB chain to terminate
+  @return CRYPT_OK on success
+*/
+int ecb_done(symmetric_ECB *ecb)
+{
+   int err;
+   LTC_ARGCHK(ecb != NULL);
+
+   if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   cipher_descriptor[ecb->cipher].done(&ecb->key);
+   return CRYPT_OK;
+}
+
+   
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_done.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ecb/ecb_encrypt.c b/src/modes/ecb/ecb_encrypt.c
new file mode 100644
index 0000000..21e0385
--- /dev/null
+++ b/src/modes/ecb/ecb_encrypt.c
@@ -0,0 +1,59 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ecb_encrypt.c
+  ECB implementation, encrypt a block, Tom St Denis
+*/
+
+#ifdef ECB
+
+/**
+  ECB encrypt
+  @param pt     Plaintext
+  @param ct     [out] Ciphertext
+  @param len    The number of octets to process (must be multiple of the cipher block size)
+  @param ecb    ECB state
+  @return CRYPT_OK if successful
+*/
+int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb)
+{
+   int err;
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(ecb != NULL);
+   if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
+       return err;
+   }
+   if (len % cipher_descriptor[ecb->cipher].block_length) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* check for accel */
+   if (cipher_descriptor[ecb->cipher].accel_ecb_encrypt != NULL) {
+      cipher_descriptor[ecb->cipher].accel_ecb_encrypt(pt, ct, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
+   } else {
+      while (len) {
+         cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key);
+         pt  += cipher_descriptor[ecb->cipher].block_length;
+         ct  += cipher_descriptor[ecb->cipher].block_length;
+         len -= cipher_descriptor[ecb->cipher].block_length;
+      }
+   }
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_encrypt.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ecb/ecb_start.c b/src/modes/ecb/ecb_start.c
new file mode 100644
index 0000000..f7baa81
--- /dev/null
+++ b/src/modes/ecb/ecb_start.c
@@ -0,0 +1,48 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ecb_start.c
+   ECB implementation, start chain, Tom St Denis
+*/
+
+
+#ifdef ECB
+
+/**
+   Initialize a ECB context
+   @param cipher      The index of the cipher desired
+   @param key         The secret key 
+   @param keylen      The length of the secret key (octets)
+   @param num_rounds  Number of rounds in the cipher desired (0 for default)
+   @param ecb         The ECB state to initialize
+   @return CRYPT_OK if successful
+*/
+int ecb_start(int cipher, const unsigned char *key, int keylen, int num_rounds, symmetric_ECB *ecb)
+{
+   int err;
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(ecb != NULL);
+
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+   ecb->cipher = cipher;
+   ecb->blocklen = cipher_descriptor[cipher].block_length;
+   return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ecb->key);
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_start.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ofb/ofb_decrypt.c b/src/modes/ofb/ofb_decrypt.c
new file mode 100644
index 0000000..cf5f19d
--- /dev/null
+++ b/src/modes/ofb/ofb_decrypt.c
@@ -0,0 +1,43 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ofb_decrypt.c
+  OFB implementation, decrypt data, Tom St Denis
+*/
+
+#ifdef OFB
+
+/**
+   OFB decrypt
+   @param ct      Ciphertext
+   @param pt      [out] Plaintext
+   @param len     Length of ciphertext (octets)
+   @param ofb     OFB state
+   @return CRYPT_OK if successful
+*/
+int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb)
+{
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(ofb != NULL);
+   return ofb_encrypt(ct, pt, len, ofb);
+}
+
+
+#endif
+
+ 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_decrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ofb/ofb_done.c b/src/modes/ofb/ofb_done.c
new file mode 100644
index 0000000..5e114f4
--- /dev/null
+++ b/src/modes/ofb/ofb_done.c
@@ -0,0 +1,42 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ofb_done.c
+   OFB implementation, finish chain, Tom St Denis
+*/
+
+#ifdef OFB
+
+/** Terminate the chain
+  @param ofb    The OFB chain to terminate
+  @return CRYPT_OK on success
+*/
+int ofb_done(symmetric_OFB *ofb)
+{
+   int err;
+   LTC_ARGCHK(ofb != NULL);
+
+   if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
+      return err;
+   }
+   cipher_descriptor[ofb->cipher].done(&ofb->key);
+   return CRYPT_OK;
+}
+
+   
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_done.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/ofb_encrypt.c b/src/modes/ofb/ofb_encrypt.c
similarity index 63%
rename from ofb_encrypt.c
rename to src/modes/ofb/ofb_encrypt.c
index d5d06f3..d66979a 100644
--- a/ofb_encrypt.c
+++ b/src/modes/ofb/ofb_encrypt.c
@@ -6,18 +6,31 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file ofb_encrypt.c
+  OFB implementation, encrypt data, Tom St Denis
+*/
 
 #ifdef OFB
 
+/**
+  OFB encrypt
+  @param pt     Plaintext
+  @param ct     [out] Ciphertext
+  @param len    Length of plaintext (octets)
+  @param ofb    OFB state
+  @return CRYPT_OK if successful
+*/
 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb)
 {
    int err;
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(ofb != NULL);
+   LTC_ARGCHK(pt != NULL);
+   LTC_ARGCHK(ct != NULL);
+   LTC_ARGCHK(ofb != NULL);
    if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
        return err;
    }
@@ -39,3 +52,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_encrypt.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ofb/ofb_getiv.c b/src/modes/ofb/ofb_getiv.c
new file mode 100644
index 0000000..f945fff
--- /dev/null
+++ b/src/modes/ofb/ofb_getiv.c
@@ -0,0 +1,45 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ofb_getiv.c
+   OFB implementation, get IV, Tom St Denis
+*/
+
+#ifdef OFB
+
+/**
+   Get the current initial vector
+   @param IV   [out] The destination of the initial vector
+   @param len  [in/out]  The max size and resulting size of the initial vector
+   @param ofb  The OFB state
+   @return CRYPT_OK if successful
+*/
+int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb)
+{
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(len != NULL);
+   LTC_ARGCHK(ofb != NULL);
+   if ((unsigned long)ofb->blocklen > *len) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+   XMEMCPY(IV, ofb->IV, ofb->blocklen);
+   *len = ofb->blocklen;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_getiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ofb/ofb_setiv.c b/src/modes/ofb/ofb_setiv.c
new file mode 100644
index 0000000..f678601
--- /dev/null
+++ b/src/modes/ofb/ofb_setiv.c
@@ -0,0 +1,53 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ofb_setiv.c
+   OFB implementation, set IV, Tom St Denis
+*/
+
+#ifdef OFB
+
+/**
+   Set an initial vector
+   @param IV   The initial vector
+   @param len  The length of the vector (in octets)
+   @param ofb  The OFB state
+   @return CRYPT_OK if successful
+*/
+int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb)
+{
+   int err;
+
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(ofb != NULL);
+
+   if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
+       return err;
+   }
+
+   if (len != (unsigned long)ofb->blocklen) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* force next block */
+   ofb->padlen = 0;
+   cipher_descriptor[ofb->cipher].ecb_encrypt(IV, ofb->IV, &ofb->key);
+   return CRYPT_OK;
+}
+
+#endif 
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_setiv.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/modes/ofb/ofb_start.c b/src/modes/ofb/ofb_start.c
new file mode 100644
index 0000000..083e381
--- /dev/null
+++ b/src/modes/ofb/ofb_start.c
@@ -0,0 +1,60 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ofb_start.c
+   OFB implementation, start chain, Tom St Denis
+*/
+
+
+#ifdef OFB
+
+/**
+   Initialize a OFB context
+   @param cipher      The index of the cipher desired
+   @param IV          The initial vector
+   @param key         The secret key 
+   @param keylen      The length of the secret key (octets)
+   @param num_rounds  Number of rounds in the cipher desired (0 for default)
+   @param ofb         The OFB state to initialize
+   @return CRYPT_OK if successful
+*/
+int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+              int keylen, int num_rounds, symmetric_OFB *ofb)
+{
+   int x, err;
+
+   LTC_ARGCHK(IV != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(ofb != NULL);
+
+   if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* copy details */
+   ofb->cipher = cipher;
+   ofb->blocklen = cipher_descriptor[cipher].block_length;
+   for (x = 0; x < ofb->blocklen; x++) {
+       ofb->IV[x] = IV[x];
+   }
+
+   /* init the cipher */
+   ofb->padlen = ofb->blocklen;
+   return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ofb->key);
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/modes/ofb/ofb_start.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/asn1/der/bit/der_decode_bit_string.c b/src/pk/asn1/der/bit/der_decode_bit_string.c
new file mode 100644
index 0000000..da5b989
--- /dev/null
+++ b/src/pk/asn1/der/bit/der_decode_bit_string.c
@@ -0,0 +1,101 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_bit_string.c
+  ASN.1 DER, encode a BIT STRING, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Store a BIT STRING
+  @param in      The DER encoded BIT STRING
+  @param inlen   The size of the DER BIT STRING
+  @param out     [out] The array of bits stored (one per char)
+  @param outlen  [in/out] The number of bits stored
+  @return CRYPT_OK if successful
+*/
+int der_decode_bit_string(const unsigned char *in,  unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen)
+{
+   unsigned long dlen, blen, x, y;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* packet must be at least 4 bytes */
+   if (inlen < 4) {
+       return CRYPT_INVALID_ARG;
+   }
+
+   /* check for 0x03 */
+   if ((in[0]&0x1F) != 0x03) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+    /* offset in the data */
+    x = 1;
+
+   /* get the length of the data */
+   if (in[x] & 0x80) {
+      /* long format get number of length bytes */
+      y = in[x++] & 127;
+
+      /* invalid if 0 or > 2 */
+      if (y == 0 || y > 2) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* read the data len */
+      dlen = 0;
+      while (y--) {
+         dlen = (dlen << 8) | (unsigned long)in[x++];
+      }
+   } else {
+      /* short format */
+      dlen = in[x++] & 127;
+   }
+  
+   /* is the data len too long or too short? */
+   if ((dlen == 0) || (dlen + x > inlen)) {
+       return CRYPT_INVALID_PACKET;
+   }
+
+   /* get padding count */
+   blen = ((dlen - 1) << 3) - (in[x++] & 7);
+
+   /* too many bits? */
+   if (blen > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* decode/store the bits */
+   for (y = 0; y < blen; y++) {
+       out[y] = (in[x] & (1 << (7 - (y & 7)))) ? 1 : 0;
+       if ((y & 7) == 7) {
+          ++x;
+       }
+   }
+
+   /* we done */
+   *outlen = blen;
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_decode_bit_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/bit/der_encode_bit_string.c b/src/pk/asn1/der/bit/der_encode_bit_string.c
new file mode 100644
index 0000000..569c15b
--- /dev/null
+++ b/src/pk/asn1/der/bit/der_encode_bit_string.c
@@ -0,0 +1,87 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_bit_string.c
+  ASN.1 DER, encode a BIT STRING, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Store a BIT STRING
+  @param in       The array of bits to store (one per char)
+  @param inlen    The number of bits tostore
+  @param out      [out] The destination for the DER encoded BIT STRING
+  @param outlen   [in/out] The max size and resulting size of the DER BIT STRING
+  @return CRYPT_OK if successful
+*/
+int der_encode_bit_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen)
+{
+   unsigned long len, x, y, buf;
+   int           err;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* avoid overflows */
+   if ((err = der_length_bit_string(inlen, &len)) != CRYPT_OK) {
+      return err;
+   }
+
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* store header (include bit padding count in length) */
+   x = 0;
+   y = (inlen >> 3) + ((inlen&7) ? 1 : 0) + 1;
+
+   out[x++] = 0x03;
+   if (y < 128) {
+      out[x++] = y;
+   } else if (y < 256) {
+      out[x++] = 0x81;
+      out[x++] = y;
+   } else if (y < 65536) {
+      out[x++] = 0x82;
+      out[x++] = (y>>8)&255;
+      out[x++] = y&255;
+   }
+
+   /* store number of zero padding bits */
+   out[x++] = (8 - inlen) & 7;
+
+   /* store the bits in big endian format */
+   for (y = buf = 0; y < inlen; y++) {
+       buf |= (in[y] ? 1 : 0) << (7 - (y & 7));
+       if ((y & 7) == 7) {
+          out[x++] = buf;
+          buf      = 0;
+       }
+   }
+   /* store last byte */
+   if (inlen & 7) {
+      out[x++] = buf;
+   }
+   *outlen = x;
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_encode_bit_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/bit/der_length_bit_string.c b/src/pk/asn1/der/bit/der_length_bit_string.c
new file mode 100644
index 0000000..dd6ea6d
--- /dev/null
+++ b/src/pk/asn1/der/bit/der_length_bit_string.c
@@ -0,0 +1,54 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_bit_string.c
+  ASN.1 DER, get length of BIT STRING, Tom St Denis
+*/
+
+#ifdef LTC_DER
+/**
+  Gets length of DER encoding of BIT STRING 
+  @param nbits  The number of bits in the string to encode
+  @param outlen [out] The length of the DER encoding for the given string
+  @return CRYPT_OK if successful
+*/
+int der_length_bit_string(unsigned long nbits, unsigned long *outlen)
+{
+   unsigned long nbytes;
+   LTC_ARGCHK(outlen != NULL);
+
+   /* get the number of the bytes */
+   nbytes = (nbits >> 3) + ((nbits & 7) ? 1 : 0) + 1;
+ 
+   if (nbytes < 128) {
+      /* 03 LL PP DD DD DD ... */
+      *outlen = 2 + nbytes;
+   } else if (nbytes < 256) {
+      /* 03 81 LL PP DD DD DD ... */
+      *outlen = 3 + nbytes;
+   } else if (nbytes < 65536) {
+      /* 03 82 LL LL PP DD DD DD ... */
+      *outlen = 4 + nbytes;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_length_bit_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/choice/der_decode_choice.c b/src/pk/asn1/der/choice/der_decode_choice.c
new file mode 100644
index 0000000..61cba11
--- /dev/null
+++ b/src/pk/asn1/der/choice/der_decode_choice.c
@@ -0,0 +1,168 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_choice.c
+  ASN.1 DER, decode a CHOICE, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+   Decode a CHOICE
+   @param in       The DER encoded input
+   @param inlen    [in/out] The size of the input and resulting size of read type
+   @param list     The list of items to decode
+   @param outlen   The number of items in the list
+   @return CRYPT_OK on success
+*/
+int der_decode_choice(const unsigned char *in,   unsigned long *inlen,
+                            ltc_asn1_list *list, unsigned long  outlen)
+{
+   unsigned long size, x, z;
+   void          *data;
+
+   LTC_ARGCHK(in    != NULL);
+   LTC_ARGCHK(inlen != NULL);
+   LTC_ARGCHK(list  != NULL);
+
+   /* get blk size */
+   if (*inlen < 2) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* set all of the "used" flags to zero */
+   for (x = 0; x < outlen; x++) {
+       list[x].used = 0;
+   }
+
+   /* now scan until we have a winner */
+   for (x = 0; x < outlen; x++) {
+       size = list[x].size;
+       data = list[x].data;
+
+       switch (list[x].type) {
+           case LTC_ASN1_INTEGER:
+               if (der_decode_integer(in, *inlen, data) == CRYPT_OK) {
+                  if (der_length_integer(data, &z) == CRYPT_OK) {
+                      list[x].used = 1;
+                      *inlen       = z;
+                      return CRYPT_OK;
+                  }
+               }
+               break;
+
+           case LTC_ASN1_SHORT_INTEGER:
+               if (der_decode_short_integer(in, *inlen, data) == CRYPT_OK) {
+                  if (der_length_short_integer(size, &z) == CRYPT_OK) {
+                      list[x].used = 1;
+                      *inlen       = z;
+                      return CRYPT_OK;
+                  }
+               }
+               break;
+
+           case LTC_ASN1_BIT_STRING:
+               if (der_decode_bit_string(in, *inlen, data, &size) == CRYPT_OK) {
+                  if (der_length_bit_string(size, &z) == CRYPT_OK) {
+                     list[x].used = 1;
+                     list[x].size = size;
+                     *inlen       = z;
+                     return CRYPT_OK;
+                  }
+               }
+               break;
+
+           case LTC_ASN1_OCTET_STRING:
+               if (der_decode_octet_string(in, *inlen, data, &size) == CRYPT_OK) {
+                  if (der_length_octet_string(size, &z) == CRYPT_OK) {
+                     list[x].used = 1;
+                     list[x].size = size;
+                     *inlen       = z;
+                     return CRYPT_OK;
+                  }
+               }
+               break;
+
+           case LTC_ASN1_NULL:
+               if (*inlen == 2 && in[x] == 0x05 && in[x+1] == 0x00) {
+                  *inlen = 2;
+                  return CRYPT_OK;
+               }
+               break;
+                  
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+               if (der_decode_object_identifier(in, *inlen, data, &size) == CRYPT_OK) {
+                  if (der_length_object_identifier(data, size, &z) == CRYPT_OK) {
+                     list[x].used = 1;
+                     list[x].size = size;
+                     *inlen       = z;
+                     return CRYPT_OK;
+                  }
+               }
+               break;
+
+           case LTC_ASN1_IA5_STRING:
+               if (der_decode_ia5_string(in, *inlen, data, &size) == CRYPT_OK) {
+                  if (der_length_ia5_string(data, size, &z) == CRYPT_OK) {
+                     list[x].used = 1;
+                     list[x].size = size;
+                     *inlen       = z;
+                     return CRYPT_OK;
+                  }
+               }
+               break;
+
+
+           case LTC_ASN1_PRINTABLE_STRING:
+               if (der_decode_printable_string(in, *inlen, data, &size) == CRYPT_OK) {
+                  if (der_length_printable_string(data, size, &z) == CRYPT_OK) {
+                     list[x].used = 1;
+                     list[x].size = size;
+                     *inlen       = z;
+                     return CRYPT_OK;
+                  }
+               }
+               break;
+
+           case LTC_ASN1_UTCTIME:
+               z = *inlen;
+               if (der_decode_utctime(in, &z, data) == CRYPT_OK) {
+                  list[x].used = 1;
+                  *inlen       = z;
+                  return CRYPT_OK;
+               }
+               break;
+
+           case LTC_ASN1_SEQUENCE:
+               if (der_decode_sequence(in, *inlen, data, size) == CRYPT_OK) {
+                  if (der_length_sequence(data, size, &z) == CRYPT_OK) {
+                     list[x].used = 1;
+                     *inlen       = z;
+                     return CRYPT_OK;
+                  }
+               }
+               break;
+
+           default:
+               return CRYPT_INVALID_ARG;
+       }
+   }
+
+   return CRYPT_INVALID_PACKET;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/choice/der_decode_choice.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/19 11:25:01 $ */
diff --git a/src/pk/asn1/der/ia5/der_decode_ia5_string.c b/src/pk/asn1/der/ia5/der_decode_ia5_string.c
new file mode 100644
index 0000000..ac0a4af
--- /dev/null
+++ b/src/pk/asn1/der/ia5/der_decode_ia5_string.c
@@ -0,0 +1,95 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_ia5_string.c
+  ASN.1 DER, encode a IA5 STRING, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Store a IA5 STRING
+  @param in      The DER encoded IA5 STRING
+  @param inlen   The size of the DER IA5 STRING
+  @param out     [out] The array of octets stored (one per char)
+  @param outlen  [in/out] The number of octets stored
+  @return CRYPT_OK if successful
+*/
+int der_decode_ia5_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x, y, len;
+   int           t;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* must have header at least */
+   if (inlen < 2) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* check for 0x16 */
+   if ((in[0] & 0x1F) != 0x16) {
+      return CRYPT_INVALID_PACKET;
+   }
+   x = 1;
+
+   /* decode the length */
+   if (in[x] & 0x80) {
+      /* valid # of bytes in length are 1,2,3 */
+      y = in[x] & 0x7F;
+      if ((y == 0) || (y > 3) || ((x + y) > inlen)) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* read the length in */
+      len = 0;
+      ++x;
+      while (y--) {
+         len = (len << 8) | in[x++];
+      }
+   } else {
+      len = in[x++] & 0x7F;
+   }
+
+   /* is it too long? */
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (len + x > inlen) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* read the data */
+   for (y = 0; y < len; y++) {
+       t = der_ia5_value_decode(in[x++]);
+       if (t == -1) {
+           return CRYPT_INVALID_ARG;
+       }
+       out[y] = t;
+   }
+
+   *outlen = y;
+
+   return CRYPT_OK;
+}
+ 
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_decode_ia5_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/ia5/der_encode_ia5_string.c b/src/pk/asn1/der/ia5/der_encode_ia5_string.c
new file mode 100644
index 0000000..a79b46e
--- /dev/null
+++ b/src/pk/asn1/der/ia5/der_encode_ia5_string.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_ia5_string.c
+  ASN.1 DER, encode a IA5 STRING, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+  Store an IA5 STRING
+  @param in       The array of IA5 to store (one per char)
+  @param inlen    The number of IA5 to store
+  @param out      [out] The destination for the DER encoded IA5 STRING
+  @param outlen   [in/out] The max size and resulting size of the DER IA5 STRING
+  @return CRYPT_OK if successful
+*/
+int der_encode_ia5_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x, y, len;
+   int           err;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* get the size */
+   if ((err = der_length_ia5_string(in, inlen, &len)) != CRYPT_OK) {
+      return err; 
+   }
+
+   /* too big? */
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* encode the header+len */
+   x = 0;
+   out[x++] = 0x16;
+   if (inlen < 128) {
+      out[x++] = inlen;
+   } else if (inlen < 256) {
+      out[x++] = 0x81;
+      out[x++] = inlen;
+   } else if (inlen < 65536UL) {
+      out[x++] = 0x82;
+      out[x++] = (inlen>>8)&255;
+      out[x++] = inlen&255;
+   } else if (inlen < 16777216UL) {
+      out[x++] = 0x83;
+      out[x++] = (inlen>>16)&255;
+      out[x++] = (inlen>>8)&255;
+      out[x++] = inlen&255;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* store octets */
+   for (y = 0; y < inlen; y++) {
+       out[x++] = der_ia5_char_encode(in[y]);
+   }
+
+   /* retun length */
+   *outlen = x;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_encode_ia5_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/ia5/der_length_ia5_string.c b/src/pk/asn1/der/ia5/der_length_ia5_string.c
new file mode 100644
index 0000000..d07d630
--- /dev/null
+++ b/src/pk/asn1/der/ia5/der_length_ia5_string.c
@@ -0,0 +1,194 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_ia5_string.c
+  ASN.1 DER, get length of IA5 STRING, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+static const struct {
+   int code, value;
+} ia5_table[] = {
+{ '\0', 0 },
+{ '\a', 7 }, 
+{ '\b', 8 }, 
+{ '\t', 9 }, 
+{ '\n', 10 }, 
+{ '\f', 12 }, 
+{ '\r', 13 }, 
+{ ' ', 32 }, 
+{ '!', 33 }, 
+{ '"', 34 }, 
+{ '#', 35 }, 
+{ '$', 36 }, 
+{ '%', 37 }, 
+{ '&', 38 }, 
+{ '\'', 39 }, 
+{ '(', 40 }, 
+{ ')', 41 }, 
+{ '*', 42 }, 
+{ '+', 43 }, 
+{ ',', 44 }, 
+{ '-', 45 }, 
+{ '.', 46 }, 
+{ '/', 47 }, 
+{ '0', 48 }, 
+{ '1', 49 }, 
+{ '2', 50 }, 
+{ '3', 51 }, 
+{ '4', 52 }, 
+{ '5', 53 }, 
+{ '6', 54 }, 
+{ '7', 55 }, 
+{ '8', 56 }, 
+{ '9', 57 }, 
+{ ':', 58 }, 
+{ ';', 59 }, 
+{ '<', 60 }, 
+{ '=', 61 }, 
+{ '>', 62 }, 
+{ '?', 63 }, 
+{ '@', 64 }, 
+{ 'A', 65 }, 
+{ 'B', 66 }, 
+{ 'C', 67 }, 
+{ 'D', 68 }, 
+{ 'E', 69 }, 
+{ 'F', 70 }, 
+{ 'G', 71 }, 
+{ 'H', 72 }, 
+{ 'I', 73 }, 
+{ 'J', 74 }, 
+{ 'K', 75 }, 
+{ 'L', 76 }, 
+{ 'M', 77 }, 
+{ 'N', 78 }, 
+{ 'O', 79 }, 
+{ 'P', 80 }, 
+{ 'Q', 81 }, 
+{ 'R', 82 }, 
+{ 'S', 83 }, 
+{ 'T', 84 }, 
+{ 'U', 85 }, 
+{ 'V', 86 }, 
+{ 'W', 87 }, 
+{ 'X', 88 }, 
+{ 'Y', 89 }, 
+{ 'Z', 90 }, 
+{ '[', 91 }, 
+{ '\\', 92 }, 
+{ ']', 93 }, 
+{ '^', 94 }, 
+{ '_', 95 }, 
+{ '`', 96 }, 
+{ 'a', 97 }, 
+{ 'b', 98 }, 
+{ 'c', 99 }, 
+{ 'd', 100 }, 
+{ 'e', 101 }, 
+{ 'f', 102 }, 
+{ 'g', 103 }, 
+{ 'h', 104 }, 
+{ 'i', 105 }, 
+{ 'j', 106 }, 
+{ 'k', 107 }, 
+{ 'l', 108 }, 
+{ 'm', 109 }, 
+{ 'n', 110 }, 
+{ 'o', 111 }, 
+{ 'p', 112 }, 
+{ 'q', 113 }, 
+{ 'r', 114 }, 
+{ 's', 115 }, 
+{ 't', 116 }, 
+{ 'u', 117 }, 
+{ 'v', 118 }, 
+{ 'w', 119 }, 
+{ 'x', 120 }, 
+{ 'y', 121 }, 
+{ 'z', 122 }, 
+{ '{', 123 }, 
+{ '|', 124 }, 
+{ '}', 125 }, 
+{ '~', 126 }
+};
+
+int der_ia5_char_encode(int c)
+{
+   int x;
+   for (x = 0; x < (int)(sizeof(ia5_table)/sizeof(ia5_table[0])); x++) {
+       if (ia5_table[x].code == c) {
+          return ia5_table[x].value;
+       }
+   }
+   return -1;
+}
+
+int der_ia5_value_decode(int v)
+{
+   int x;
+   for (x = 0; x < (int)(sizeof(ia5_table)/sizeof(ia5_table[0])); x++) {
+       if (ia5_table[x].value == v) {
+          return ia5_table[x].code;
+       }
+   }
+   return -1;
+}
+   
+/**
+  Gets length of DER encoding of IA5 STRING 
+  @param octets   The values you want to encode 
+  @param noctets  The number of octets in the string to encode
+  @param outlen   [out] The length of the DER encoding for the given string
+  @return CRYPT_OK if successful
+*/
+int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen)
+{
+   unsigned long x;
+
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(octets != NULL);
+
+   /* scan string for validity */
+   for (x = 0; x < noctets; x++) {
+       if (der_ia5_char_encode(octets[x]) == -1) {
+          return CRYPT_INVALID_ARG;
+       }
+   }
+
+   if (noctets < 128) {
+      /* 16 LL DD DD DD ... */
+      *outlen = 2 + noctets;
+   } else if (noctets < 256) {
+      /* 16 81 LL DD DD DD ... */
+      *outlen = 3 + noctets;
+   } else if (noctets < 65536UL) {
+      /* 16 82 LL LL DD DD DD ... */
+      *outlen = 4 + noctets;
+   } else if (noctets < 16777216UL) {
+      /* 16 83 LL LL LL DD DD DD ... */
+      *outlen = 5 + noctets;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/ia5/der_length_ia5_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/integer/der_decode_integer.c b/src/pk/asn1/der/integer/der_decode_integer.c
new file mode 100644
index 0000000..e68b2c9
--- /dev/null
+++ b/src/pk/asn1/der/integer/der_decode_integer.c
@@ -0,0 +1,110 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_integer.c
+  ASN.1 DER, decode an integer, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Read a mp_int integer
+  @param in       The DER encoded data
+  @param inlen    Size of DER encoded data
+  @param num      The first mp_int to decode
+  @return CRYPT_OK if successful
+*/
+int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int *num)
+{
+   unsigned long x, y, z;
+   int           err;
+
+   LTC_ARGCHK(num    != NULL);
+   LTC_ARGCHK(in     != NULL);
+
+   /* min DER INTEGER is 0x02 01 00 == 0 */
+   if (inlen < (1 + 1 + 1)) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* ok expect 0x02 when we AND with 0001 1111 [1F] */
+   x = 0;
+   if ((in[x++] & 0x1F) != 0x02) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* now decode the len stuff */
+   z = in[x++];
+
+   if ((z & 0x80) == 0x00) {
+      /* short form */
+
+      /* will it overflow? */
+      if (x + z > inlen) {
+         return CRYPT_INVALID_PACKET;
+      }
+     
+      /* no so read it */
+      if ((err = mpi_to_ltc_error(mp_read_unsigned_bin(num, (unsigned char *)in + x, z))) != CRYPT_OK) {
+         return err;
+      }
+   } else {
+      /* long form */
+      z &= 0x7F;
+      
+      /* will number of length bytes overflow? (or > 4) */
+      if (((x + z) > inlen) || (z > 4) || (z == 0)) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* now read it in */
+      y = 0;
+      while (z--) {
+         y = ((unsigned long)(in[x++])) | (y << 8);
+      }
+
+      /* now will reading y bytes overrun? */
+      if ((x + y) > inlen) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* no so read it */
+      if ((err = mpi_to_ltc_error(mp_read_unsigned_bin(num, (unsigned char *)in + x, y))) != CRYPT_OK) {
+         return err;
+      }
+   }
+
+   /* see if it's negative */
+   if (in[x] & 0x80) {
+      mp_int tmp;
+      if (mp_init(&tmp) != MP_OKAY) {
+         return CRYPT_MEM;
+      }
+
+      if (mp_2expt(&tmp, mp_count_bits(num)) != MP_OKAY || mp_sub(num, &tmp, num) != MP_OKAY) {
+         mp_clear(&tmp);
+         return CRYPT_MEM;
+      }
+      mp_clear(&tmp);
+   } 
+
+   return CRYPT_OK;
+
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_decode_integer.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/06/01 00:06:05 $ */
diff --git a/src/pk/asn1/der/integer/der_encode_integer.c b/src/pk/asn1/der/integer/der_encode_integer.c
new file mode 100644
index 0000000..f0f41be
--- /dev/null
+++ b/src/pk/asn1/der/integer/der_encode_integer.c
@@ -0,0 +1,128 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_integer.c
+  ASN.1 DER, encode an integer, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/* Exports a positive bignum as DER format (upto 2^32 bytes in size) */
+/**
+  Store a mp_int integer
+  @param num      The first mp_int to encode
+  @param out      [out] The destination for the DER encoded integers
+  @param outlen   [in/out] The max size and resulting size of the DER encoded integers
+  @return CRYPT_OK if successful
+*/
+int der_encode_integer(mp_int *num, unsigned char *out, unsigned long *outlen)
+{  
+   unsigned long tmplen, y;
+   int           err, leading_zero;
+
+   LTC_ARGCHK(num    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* find out how big this will be */
+   if ((err = der_length_integer(num, &tmplen)) != CRYPT_OK) {
+      return err;
+   }
+
+   if (*outlen < tmplen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (mp_cmp_d(num, 0) != MP_LT) {
+      /* we only need a leading zero if the msb of the first byte is one */
+      if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == MP_YES) {
+         leading_zero = 1;
+      } else {
+         leading_zero = 0;
+      }
+
+      /* get length of num in bytes (plus 1 since we force the msbyte to zero) */
+      y = mp_unsigned_bin_size(num) + leading_zero;
+   } else {
+      leading_zero = 0;
+      y            = mp_count_bits(num);
+      y            = y + (8 - (y & 7));
+      y            = y >> 3;
+
+   }
+
+   /* now store initial data */
+   *out++ = 0x02;
+   if (y < 128) {
+      /* short form */
+      *out++ = (unsigned char)y;
+   } else if (y < 256) {
+      *out++ = 0x81;
+      *out++ = y;
+   } else if (y < 65536UL) {
+      *out++ = 0x82;
+      *out++ = (y>>8)&255;
+      *out++ = y;
+   } else if (y < 16777216UL) {
+      *out++ = 0x83;
+      *out++ = (y>>16)&255;
+      *out++ = (y>>8)&255;
+      *out++ = y;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* now store msbyte of zero if num is non-zero */
+   if (leading_zero) {
+      *out++ = 0x00;
+   }
+
+   /* if it's not zero store it as big endian */
+   if (mp_cmp_d(num, 0) == MP_GT) {
+      /* now store the mpint */
+      if ((err = mp_to_unsigned_bin(num, out)) != MP_OKAY) {
+          return mpi_to_ltc_error(err);
+      }
+   } else if (mp_iszero(num) != MP_YES) {
+      mp_int tmp;
+      /* negative */
+      if (mp_init(&tmp) != MP_OKAY) {
+         return CRYPT_MEM;
+      }
+
+      /* 2^roundup and subtract */
+      y = mp_count_bits(num);
+      y = y + (8 - (y & 7));
+      if (mp_2expt(&tmp, y) != MP_OKAY || mp_add(&tmp, num, &tmp) != MP_OKAY) {
+         mp_clear(&tmp);
+         return CRYPT_MEM;
+      }
+
+      if ((err = mp_to_unsigned_bin(&tmp, out)) != MP_OKAY) {
+         mp_clear(&tmp);
+         return mpi_to_ltc_error(err);
+      }
+      mp_clear(&tmp);
+   }
+
+   /* we good */
+   *outlen = tmplen; 
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_encode_integer.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/integer/der_length_integer.c b/src/pk/asn1/der/integer/der_length_integer.c
new file mode 100644
index 0000000..1bfee45
--- /dev/null
+++ b/src/pk/asn1/der/integer/der_length_integer.c
@@ -0,0 +1,81 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_integer.c
+  ASN.1 DER, get length of encoding, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+/**
+  Gets length of DER encoding of num 
+  @param num    The mp_int to get the size of 
+  @param outlen [out] The length of the DER encoding for the given integer
+  @return CRYPT_OK if successful
+*/
+int der_length_integer(mp_int *num, unsigned long *outlen)
+{
+   unsigned long z, len;
+   int           leading_zero;
+
+   LTC_ARGCHK(num     != NULL);
+   LTC_ARGCHK(outlen  != NULL);
+
+   if (mp_cmp_d(num, 0) != MP_LT) {
+      /* positive */
+
+      /* we only need a leading zero if the msb of the first byte is one */
+      if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == MP_YES) {
+         leading_zero = 1;
+      } else {
+         leading_zero = 0;
+      }
+
+      /* size for bignum */
+      z = len = leading_zero + mp_unsigned_bin_size(num);
+   } else {
+      /* it's negative */
+      /* find power of 2 that is a multiple of eight and greater than count bits */
+      leading_zero = 0;
+      z = mp_count_bits(num);
+      z = z + (8 - (z & 7));
+      len = z = z >> 3;
+   }
+
+   /* now we need a length */
+   if (z < 128) {
+      /* short form */
+      ++len;
+   } else {
+      /* long form (relies on z != 0), assumes length bytes < 128 */
+      ++len;
+
+      while (z) {
+         ++len;
+         z >>= 8;
+      }
+   }
+
+   /* we need a 0x02 to indicate it's INTEGER */
+   ++len;
+
+   /* return length */
+   *outlen = len; 
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/integer/der_length_integer.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c b/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c
new file mode 100644
index 0000000..c69c9a3
--- /dev/null
+++ b/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c
@@ -0,0 +1,99 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_object_identifier.c
+  ASN.1 DER, Decode Object Identifier, Tom St Denis
+*/
+
+#ifdef LTC_DER
+/**
+  Decode OID data and store the array of integers in words
+  @param in      The OID DER encoded data
+  @param inlen   The length of the OID data
+  @param words   [out] The destination of the OID words
+  @param outlen  [in/out] The number of OID words
+  @return CRYPT_OK if successful
+*/
+int der_decode_object_identifier(const unsigned char *in,    unsigned long  inlen,
+                                       unsigned long *words, unsigned long *outlen)
+{
+   unsigned long x, y, t, len;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(words  != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* header is at least 3 bytes */
+   if (inlen < 3) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* must be room for at least two words */
+   if (*outlen < 2) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* decode the packet header */
+   x = 0;
+   if ((in[x++] & 0x1F) != 0x06) {
+      return CRYPT_INVALID_PACKET;
+   }
+   
+   /* get the length */
+   if (in[x] < 128) {
+      len = in[x++]; 
+   } else {
+       if (in[x] < 0x81 || in[x] > 0x82) {
+          return CRYPT_INVALID_PACKET;
+       }
+       y   = in[x++] & 0x7F;
+       len = 0;
+       while (y--) {
+          len = (len << 8) | (unsigned long)in[x++];
+       }
+   }
+
+   if (len < 1 || (len + x) > inlen) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* decode word1 and word2 */
+   --len;
+   t = in[x++];
+   words[0] = t/40;
+   words[1] = t%40;
+
+   /* decode rest */
+   y = 2;
+   t = 0;
+   while (len--) {
+       t = (t << 7) | (in[x] & 0x7F);
+       if (!(in[x++] & 0x80)) {
+           /* store t */
+           if (y >= *outlen) {
+              return CRYPT_BUFFER_OVERFLOW;
+           }
+           words[y++] = t;
+           t          = 0;
+       }
+   }
+       
+   *outlen = y;
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_decode_object_identifier.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c b/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c
new file mode 100644
index 0000000..16eb112
--- /dev/null
+++ b/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c
@@ -0,0 +1,103 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_object_identifier.c
+  ASN.1 DER, Encode Object Identifier, Tom St Denis
+*/
+
+#ifdef LTC_DER
+/**
+  Encode an OID
+  @param words   The words to encode  (upto 32-bits each)
+  @param nwords  The number of words in the OID
+  @param out     [out] Destination of OID data
+  @param outlen  [in/out] The max and resulting size of the OID
+  @return CRYPT_OK if successful
+*/
+int der_encode_object_identifier(unsigned long *words, unsigned long  nwords,
+                                 unsigned char *out,   unsigned long *outlen)
+{
+   unsigned long i, x, y, z, t, mask;
+   int           err;
+
+   LTC_ARGCHK(words  != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* check length */
+   if ((err = der_length_object_identifier(words, nwords, &x)) != CRYPT_OK) {
+      return err;
+   }
+   if (x > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* compute length to store OID data */
+   z = 1;
+   for (y = 2; y < nwords; y++) {
+       t = der_object_identifier_bits(words[y]);
+       z += t/7 + ((t%7) ? 1 : 0);
+   }
+
+   /* store header + length */
+   x = 0; 
+   out[x++] = 0x06;
+   if (z < 128) {
+      out[x++] = z;
+   } else if (z < 256) {
+      out[x++] = 0x81;
+      out[x++] = z;
+   } else if (z < 65536UL) {
+      out[x++] = 0x82;
+      out[x++] = (z>>8)&255;
+      out[x++] = z&255;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* store first byte */
+   out[x++] = words[0] * 40 + words[1];   
+   
+    for (i = 2; i < nwords; i++) {
+        /* store 7 bit words in little endian */
+        t    = words[i] & 0xFFFFFFFF;
+        if (t) {
+           y    = x;
+           mask = 0;
+           while (t) {
+               out[x++] = (t & 0x7F) | mask;
+               t    >>= 7;
+               mask  |= 0x80;  /* upper bit is set on all but the last byte */
+           }
+           /* now swap bytes y...x-1 */
+           z = x - 1;
+           while (y < z) {
+               t = out[y]; out[y] = out[z]; out[z] = t;
+               ++y; 
+               --z;
+           }
+       } else {
+          /* zero word */
+          out[x++] = 0x00;
+       }
+   }
+
+   *outlen = x;
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/object_identifier/der_length_object_identifier.c b/src/pk/asn1/der/object_identifier/der_length_object_identifier.c
new file mode 100644
index 0000000..d03d1a7
--- /dev/null
+++ b/src/pk/asn1/der/object_identifier/der_length_object_identifier.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_object_identifier.c
+  ASN.1 DER, get length of Object Identifier, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+unsigned long der_object_identifier_bits(unsigned long x)
+{
+   unsigned long c;
+   x &= 0xFFFFFFFF;
+   c  = 0;
+   while (x) {
+     ++c;
+     x >>= 1;
+   }
+   return c;
+}
+
+
+/**
+  Gets length of DER encoding of Object Identifier
+  @param nwords   The number of OID words 
+  @param words    The actual OID words to get the size of
+  @param outlen   [out] The length of the DER encoding for the given string
+  @return CRYPT_OK if successful
+*/
+int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen)
+{
+   unsigned long y, z, t;   
+
+   LTC_ARGCHK(words  != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+
+   /* must be >= 2 words */
+   if (nwords < 2) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* word1 = 0,1,2 and word2 0..39 */
+   if (words[0] > 2 || words[1] > 39) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* leading byte of first two words */
+   z = 1;
+   for (y = 2; y < nwords; y++) {
+       t = der_object_identifier_bits(words[y]);
+       z += t/7 + ((t%7) ? 1 : 0);
+   }
+
+   /* now depending on the length our length encoding changes */
+   if (z < 128) {
+      z += 2;
+   } else if (z < 256) {
+      z += 3;
+   } else if (z < 65536UL) {
+      z += 4;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   *outlen = z;
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/octet/der_decode_octet_string.c b/src/pk/asn1/der/octet/der_decode_octet_string.c
new file mode 100644
index 0000000..2d3800f
--- /dev/null
+++ b/src/pk/asn1/der/octet/der_decode_octet_string.c
@@ -0,0 +1,90 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_octet_string.c
+  ASN.1 DER, encode a OCTET STRING, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Store a OCTET STRING
+  @param in      The DER encoded OCTET STRING
+  @param inlen   The size of the DER OCTET STRING
+  @param out     [out] The array of octets stored (one per char)
+  @param outlen  [in/out] The number of octets stored
+  @return CRYPT_OK if successful
+*/
+int der_decode_octet_string(const unsigned char *in, unsigned long inlen,
+                                  unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x, y, len;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* must have header at least */
+   if (inlen < 2) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* check for 0x04 */
+   if ((in[0] & 0x1F) != 0x04) {
+      return CRYPT_INVALID_PACKET;
+   }
+   x = 1;
+
+   /* decode the length */
+   if (in[x] & 0x80) {
+      /* valid # of bytes in length are 1,2,3 */
+      y = in[x] & 0x7F;
+      if ((y == 0) || (y > 3) || ((x + y) > inlen)) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* read the length in */
+      len = 0;
+      ++x;
+      while (y--) {
+         len = (len << 8) | in[x++];
+      }
+   } else {
+      len = in[x++] & 0x7F;
+   }
+
+   /* is it too long? */
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (len + x > inlen) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* read the data */
+   for (y = 0; y < len; y++) {
+       out[y] = in[x++];
+   }
+
+   *outlen = y;
+
+   return CRYPT_OK;
+}
+ 
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_decode_octet_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/octet/der_encode_octet_string.c b/src/pk/asn1/der/octet/der_encode_octet_string.c
new file mode 100644
index 0000000..f34b708
--- /dev/null
+++ b/src/pk/asn1/der/octet/der_encode_octet_string.c
@@ -0,0 +1,85 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_octet_string.c
+  ASN.1 DER, encode a OCTET STRING, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Store an OCTET STRING
+  @param in       The array of OCTETS to store (one per char)
+  @param inlen    The number of OCTETS to store
+  @param out      [out] The destination for the DER encoded OCTET STRING
+  @param outlen   [in/out] The max size and resulting size of the DER OCTET STRING
+  @return CRYPT_OK if successful
+*/
+int der_encode_octet_string(const unsigned char *in, unsigned long inlen,
+                                  unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x, y, len;
+   int           err;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* get the size */
+   if ((err = der_length_octet_string(inlen, &len)) != CRYPT_OK) {
+      return err; 
+   }
+
+   /* too big? */
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* encode the header+len */
+   x = 0;
+   out[x++] = 0x04;
+   if (inlen < 128) {
+      out[x++] = inlen;
+   } else if (inlen < 256) {
+      out[x++] = 0x81;
+      out[x++] = inlen;
+   } else if (inlen < 65536UL) {
+      out[x++] = 0x82;
+      out[x++] = (inlen>>8)&255;
+      out[x++] = inlen&255;
+   } else if (inlen < 16777216UL) {
+      out[x++] = 0x83;
+      out[x++] = (inlen>>16)&255;
+      out[x++] = (inlen>>8)&255;
+      out[x++] = inlen&255;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* store octets */
+   for (y = 0; y < inlen; y++) {
+       out[x++] = in[y];
+   }
+
+   /* retun length */
+   *outlen = x;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_encode_octet_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/octet/der_length_octet_string.c b/src/pk/asn1/der/octet/der_length_octet_string.c
new file mode 100644
index 0000000..9a0bed3
--- /dev/null
+++ b/src/pk/asn1/der/octet/der_length_octet_string.c
@@ -0,0 +1,53 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_octet_string.c
+  ASN.1 DER, get length of OCTET STRING, Tom St Denis
+*/
+
+#ifdef LTC_DER
+/**
+  Gets length of DER encoding of OCTET STRING 
+  @param noctets  The number of octets in the string to encode
+  @param outlen   [out] The length of the DER encoding for the given string
+  @return CRYPT_OK if successful
+*/
+int der_length_octet_string(unsigned long noctets, unsigned long *outlen)
+{
+   LTC_ARGCHK(outlen != NULL);
+
+   if (noctets < 128) {
+      /* 04 LL DD DD DD ... */
+      *outlen = 2 + noctets;
+   } else if (noctets < 256) {
+      /* 04 81 LL DD DD DD ... */
+      *outlen = 3 + noctets;
+   } else if (noctets < 65536UL) {
+      /* 04 82 LL LL DD DD DD ... */
+      *outlen = 4 + noctets;
+   } else if (noctets < 16777216UL) {
+      /* 04 83 LL LL LL DD DD DD ... */
+      *outlen = 5 + noctets;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_length_octet_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/16 15:08:11 $ */
diff --git a/src/pk/asn1/der/printable_string/der_decode_printable_string.c b/src/pk/asn1/der/printable_string/der_decode_printable_string.c
new file mode 100644
index 0000000..cbc9239
--- /dev/null
+++ b/src/pk/asn1/der/printable_string/der_decode_printable_string.c
@@ -0,0 +1,95 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_printable_string.c
+  ASN.1 DER, encode a printable STRING, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Store a printable STRING
+  @param in      The DER encoded printable STRING
+  @param inlen   The size of the DER printable STRING
+  @param out     [out] The array of octets stored (one per char)
+  @param outlen  [in/out] The number of octets stored
+  @return CRYPT_OK if successful
+*/
+int der_decode_printable_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x, y, len;
+   int           t;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* must have header at least */
+   if (inlen < 2) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* check for 0x13 */
+   if ((in[0] & 0x1F) != 0x13) {
+      return CRYPT_INVALID_PACKET;
+   }
+   x = 1;
+
+   /* decode the length */
+   if (in[x] & 0x80) {
+      /* valid # of bytes in length are 1,2,3 */
+      y = in[x] & 0x7F;
+      if ((y == 0) || (y > 3) || ((x + y) > inlen)) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* read the length in */
+      len = 0;
+      ++x;
+      while (y--) {
+         len = (len << 8) | in[x++];
+      }
+   } else {
+      len = in[x++] & 0x7F;
+   }
+
+   /* is it too long? */
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (len + x > inlen) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* read the data */
+   for (y = 0; y < len; y++) {
+       t = der_printable_value_decode(in[x++]);
+       if (t == -1) {
+           return CRYPT_INVALID_ARG;
+       }
+       out[y] = t;
+   }
+
+   *outlen = y;
+
+   return CRYPT_OK;
+}
+ 
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/printable_string/der_decode_printable_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/21 02:29:54 $ */
diff --git a/src/pk/asn1/der/printable_string/der_encode_printable_string.c b/src/pk/asn1/der/printable_string/der_encode_printable_string.c
new file mode 100644
index 0000000..ab4e8bf
--- /dev/null
+++ b/src/pk/asn1/der/printable_string/der_encode_printable_string.c
@@ -0,0 +1,84 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_printable_string.c
+  ASN.1 DER, encode a printable STRING, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+  Store an printable STRING
+  @param in       The array of printable to store (one per char)
+  @param inlen    The number of printable to store
+  @param out      [out] The destination for the DER encoded printable STRING
+  @param outlen   [in/out] The max size and resulting size of the DER printable STRING
+  @return CRYPT_OK if successful
+*/
+int der_encode_printable_string(const unsigned char *in, unsigned long inlen,
+                                unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x, y, len;
+   int           err;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* get the size */
+   if ((err = der_length_printable_string(in, inlen, &len)) != CRYPT_OK) {
+      return err; 
+   }
+
+   /* too big? */
+   if (len > *outlen) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* encode the header+len */
+   x = 0;
+   out[x++] = 0x13;
+   if (inlen < 128) {
+      out[x++] = inlen;
+   } else if (inlen < 256) {
+      out[x++] = 0x81;
+      out[x++] = inlen;
+   } else if (inlen < 65536UL) {
+      out[x++] = 0x82;
+      out[x++] = (inlen>>8)&255;
+      out[x++] = inlen&255;
+   } else if (inlen < 16777216UL) {
+      out[x++] = 0x83;
+      out[x++] = (inlen>>16)&255;
+      out[x++] = (inlen>>8)&255;
+      out[x++] = inlen&255;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* store octets */
+   for (y = 0; y < inlen; y++) {
+       out[x++] = der_printable_char_encode(in[y]);
+   }
+
+   /* retun length */
+   *outlen = x;
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/printable_string/der_encode_printable_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/21 02:29:54 $ */
diff --git a/src/pk/asn1/der/printable_string/der_length_printable_string.c b/src/pk/asn1/der/printable_string/der_length_printable_string.c
new file mode 100644
index 0000000..34065f2
--- /dev/null
+++ b/src/pk/asn1/der/printable_string/der_length_printable_string.c
@@ -0,0 +1,166 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_printable_string.c
+  ASN.1 DER, get length of Printable STRING, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+static const struct {
+   int code, value;
+} printable_table[] = {
+{ ' ', 32 }, 
+{ '\'', 39 }, 
+{ '(', 40 }, 
+{ ')', 41 }, 
+{ '+', 43 }, 
+{ ',', 44 }, 
+{ '-', 45 }, 
+{ '.', 46 }, 
+{ '/', 47 }, 
+{ '0', 48 }, 
+{ '1', 49 }, 
+{ '2', 50 }, 
+{ '3', 51 }, 
+{ '4', 52 }, 
+{ '5', 53 }, 
+{ '6', 54 }, 
+{ '7', 55 }, 
+{ '8', 56 }, 
+{ '9', 57 }, 
+{ ':', 58 }, 
+{ '=', 61 }, 
+{ '?', 63 }, 
+{ 'A', 65 }, 
+{ 'B', 66 }, 
+{ 'C', 67 }, 
+{ 'D', 68 }, 
+{ 'E', 69 }, 
+{ 'F', 70 }, 
+{ 'G', 71 }, 
+{ 'H', 72 }, 
+{ 'I', 73 }, 
+{ 'J', 74 }, 
+{ 'K', 75 }, 
+{ 'L', 76 }, 
+{ 'M', 77 }, 
+{ 'N', 78 }, 
+{ 'O', 79 }, 
+{ 'P', 80 }, 
+{ 'Q', 81 }, 
+{ 'R', 82 }, 
+{ 'S', 83 }, 
+{ 'T', 84 }, 
+{ 'U', 85 }, 
+{ 'V', 86 }, 
+{ 'W', 87 }, 
+{ 'X', 88 }, 
+{ 'Y', 89 }, 
+{ 'Z', 90 }, 
+{ 'a', 97 }, 
+{ 'b', 98 }, 
+{ 'c', 99 }, 
+{ 'd', 100 }, 
+{ 'e', 101 }, 
+{ 'f', 102 }, 
+{ 'g', 103 }, 
+{ 'h', 104 }, 
+{ 'i', 105 }, 
+{ 'j', 106 }, 
+{ 'k', 107 }, 
+{ 'l', 108 }, 
+{ 'm', 109 }, 
+{ 'n', 110 }, 
+{ 'o', 111 }, 
+{ 'p', 112 }, 
+{ 'q', 113 }, 
+{ 'r', 114 }, 
+{ 's', 115 }, 
+{ 't', 116 }, 
+{ 'u', 117 }, 
+{ 'v', 118 }, 
+{ 'w', 119 }, 
+{ 'x', 120 }, 
+{ 'y', 121 }, 
+{ 'z', 122 }, 
+};
+
+int der_printable_char_encode(int c)
+{
+   int x;
+   for (x = 0; x < (int)(sizeof(printable_table)/sizeof(printable_table[0])); x++) {
+       if (printable_table[x].code == c) {
+          return printable_table[x].value;
+       }
+   }
+   return -1;
+}
+
+int der_printable_value_decode(int v)
+{
+   int x;
+   for (x = 0; x < (int)(sizeof(printable_table)/sizeof(printable_table[0])); x++) {
+       if (printable_table[x].value == v) {
+          return printable_table[x].code;
+       }
+   }
+   return -1;
+}
+   
+/**
+  Gets length of DER encoding of Printable STRING 
+  @param octets   The values you want to encode 
+  @param noctets  The number of octets in the string to encode
+  @param outlen   [out] The length of the DER encoding for the given string
+  @return CRYPT_OK if successful
+*/
+int der_length_printable_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen)
+{
+   unsigned long x;
+
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(octets != NULL);
+
+   /* scan string for validity */
+   for (x = 0; x < noctets; x++) {
+       if (der_printable_char_encode(octets[x]) == -1) {
+          return CRYPT_INVALID_ARG;
+       }
+   }
+
+   if (noctets < 128) {
+      /* 16 LL DD DD DD ... */
+      *outlen = 2 + noctets;
+   } else if (noctets < 256) {
+      /* 16 81 LL DD DD DD ... */
+      *outlen = 3 + noctets;
+   } else if (noctets < 65536UL) {
+      /* 16 82 LL LL DD DD DD ... */
+      *outlen = 4 + noctets;
+   } else if (noctets < 16777216UL) {
+      /* 16 83 LL LL LL DD DD DD ... */
+      *outlen = 5 + noctets;
+   } else {
+      return CRYPT_INVALID_ARG;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/printable_string/der_length_printable_string.c,v $ */
+/* $Revision: 1.1 $ */
+/* $Date: 2005/05/21 02:29:54 $ */
diff --git a/src/pk/asn1/der/sequence/der_decode_sequence.c b/src/pk/asn1/der/sequence/der_decode_sequence.c
new file mode 100644
index 0000000..335a882
--- /dev/null
+++ b/src/pk/asn1/der/sequence/der_decode_sequence.c
@@ -0,0 +1,234 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+
+/**
+  @file der_decode_sequence.c
+  ASN.1 DER, decode a SEQUENCE, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+   Decode a SEQUENCE
+   @param in       The DER encoded input
+   @param inlen    The size of the input
+   @param list     The list of items to decode
+   @param outlen   The number of items in the list
+   @return CRYPT_OK on success
+*/
+int der_decode_sequence(const unsigned char *in,   unsigned long  inlen,
+                              ltc_asn1_list *list, unsigned long  outlen)
+{
+   int           err, type;
+   unsigned long size, x, y, z, i, blksize;
+   void          *data;
+
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(list != NULL);
+
+   /* get blk size */
+   if (inlen < 2) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* sequence type? */
+   x = 0;
+   if (in[x++] != 0x30) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   if (in[x] < 128) {
+      blksize = in[x++];
+   } else if (in[x] & 0x80) {
+      if (in[x] < 0x81 || in[x] > 0x83) {
+         return CRYPT_INVALID_PACKET;
+      }
+      y = in[x++] & 0x7F;
+
+      /* would reading the len bytes overrun? */
+      if (x + y > inlen) {
+         return CRYPT_INVALID_PACKET;
+      }
+
+      /* read len */
+      blksize = 0;
+      while (y--) {
+          blksize = (blksize << 8) | (unsigned long)in[x++];
+      }
+  }
+
+  /* would this blksize overflow? */
+  if (x + blksize > inlen) {
+     return CRYPT_INVALID_PACKET;
+  }
+
+  /* ok read data */
+   inlen = blksize;
+   for (i = 0; i < outlen; i++) {
+       type = list[i].type;
+       size = list[i].size;
+       data = list[i].data;
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+               z = inlen;
+               if ((err = der_decode_integer(in + x, z, data)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               if ((err = der_length_integer(data, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+
+           case LTC_ASN1_SHORT_INTEGER:
+               z = inlen;
+               if ((err = der_decode_short_integer(in + x, z, data)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               if ((err = der_length_short_integer(size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           case LTC_ASN1_BIT_STRING:
+               z = inlen;
+               if ((err = der_decode_bit_string(in + x, z, data, &size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               list[i].size = size;
+               if ((err = der_length_bit_string(size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           case LTC_ASN1_OCTET_STRING:
+               z = inlen;
+               if ((err = der_decode_octet_string(in + x, z, data, &size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               list[i].size = size;
+               if ((err = der_length_octet_string(size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           case LTC_ASN1_NULL:
+               if (inlen < 2 || in[x] != 0x05 || in[x+1] != 0x00) {
+                  err = CRYPT_INVALID_PACKET;
+                  goto LBL_ERR;
+               }
+               x     += 2;
+               inlen -= 2;
+               break;
+                  
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+               z = inlen;
+               if ((err = der_decode_object_identifier(in + x, z, data, &size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               list[i].size = size;
+               if ((err = der_length_object_identifier(data, size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           case LTC_ASN1_IA5_STRING:
+               z = inlen;
+               if ((err = der_decode_ia5_string(in + x, z, data, &size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               list[i].size = size;
+               if ((err = der_length_ia5_string(data, size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+
+           case LTC_ASN1_PRINTABLE_STRING:
+               z = inlen;
+               if ((err = der_decode_printable_string(in + x, z, data, &size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               list[i].size = size;
+               if ((err = der_length_printable_string(data, size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           case LTC_ASN1_UTCTIME:
+               z = inlen;
+               if ((err = der_decode_utctime(in + x, &z, data)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           case LTC_ASN1_SEQUENCE:
+               z = inlen;
+               if ((err = der_decode_sequence(in + x, z, data, size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               if ((err = der_length_sequence(data, size, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+
+           case LTC_ASN1_CHOICE:
+               z = inlen;
+               if ((err = der_decode_choice(in + x, &z, data, size)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x     += z;
+               inlen -= z;
+               break;
+
+           default:
+               err = CRYPT_INVALID_ARG;
+               goto LBL_ERR;
+       }
+   }
+   err = CRYPT_OK;   
+
+LBL_ERR:
+   return err;
+}  
+ 
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/06/18 19:20:23 $ */
diff --git a/src/pk/asn1/der/sequence/der_decode_sequence_multi.c b/src/pk/asn1/der/sequence/der_decode_sequence_multi.c
new file mode 100644
index 0000000..a4a1038
--- /dev/null
+++ b/src/pk/asn1/der/sequence/der_decode_sequence_multi.c
@@ -0,0 +1,124 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+
+/**
+  @file der_decode_sequence_multi.c
+  ASN.1 DER, decode a SEQUENCE, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+int der_decode_sequence_multi(const unsigned char *in, unsigned long inlen, ...)
+{
+   int           err, type;
+   unsigned long size, x;
+   void          *data;
+   va_list       args;
+   ltc_asn1_list *list;
+
+   LTC_ARGCHK(in    != NULL);
+
+   /* get size of output that will be required */
+   va_start(args, inlen);
+   x = 0;
+   for (;;) {
+       type = va_arg(args, int);
+       size = va_arg(args, unsigned long);
+       data = va_arg(args, void*);
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+           case LTC_ASN1_SHORT_INTEGER:
+           case LTC_ASN1_BIT_STRING:
+           case LTC_ASN1_OCTET_STRING:
+           case LTC_ASN1_NULL:
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+           case LTC_ASN1_IA5_STRING:
+           case LTC_ASN1_PRINTABLE_STRING:
+           case LTC_ASN1_UTCTIME:
+           case LTC_ASN1_SEQUENCE:
+           case LTC_ASN1_CHOICE:
+                ++x; 
+                break;
+          
+           default:
+               va_end(args);
+               return CRYPT_INVALID_ARG;
+       }
+   }
+   va_end(args);
+
+   /* allocate structure for x elements */
+   if (x == 0) {
+      return CRYPT_NOP;
+   }
+
+   list = XCALLOC(sizeof(*list), x);
+   if (list == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* fill in the structure */
+   va_start(args, inlen);
+   x = 0;
+   for (;;) {
+       type = va_arg(args, int);
+       size = va_arg(args, unsigned long);
+       data = va_arg(args, void*);
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+           case LTC_ASN1_SHORT_INTEGER:
+           case LTC_ASN1_BIT_STRING:
+           case LTC_ASN1_OCTET_STRING:
+           case LTC_ASN1_NULL:
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+           case LTC_ASN1_IA5_STRING:
+           case LTC_ASN1_PRINTABLE_STRING:
+           case LTC_ASN1_UTCTIME:
+           case LTC_ASN1_SEQUENCE:
+           case LTC_ASN1_CHOICE:
+                list[x].type   = type;
+                list[x].size   = size;
+                list[x++].data = data;
+                break;
+         
+           default:
+               va_end(args);
+               err = CRYPT_INVALID_ARG;
+               goto LBL_ERR;
+       }
+   }
+   va_end(args);
+
+   err = der_decode_sequence(in, inlen, list, x);
+LBL_ERR:
+   XFREE(list);
+   return err;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_decode_sequence_multi.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/06/18 19:20:23 $ */
diff --git a/src/pk/asn1/der/sequence/der_encode_sequence.c b/src/pk/asn1/der/sequence/der_encode_sequence.c
new file mode 100644
index 0000000..d53153c
--- /dev/null
+++ b/src/pk/asn1/der/sequence/der_encode_sequence.c
@@ -0,0 +1,281 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+
+/**
+  @file der_encode_sequence.c
+  ASN.1 DER, encode a SEQUENCE, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+   Encode a SEQUENCE
+   @param list      The list of items to encode
+   @param inlen     The number of items in the list
+   @param out       [out] The destination 
+   @param outlen    [in/out] The size of the output
+   @return CRYPT_OK on success
+*/
+int der_encode_sequence(ltc_asn1_list *list, unsigned long inlen,
+                        unsigned char *out,  unsigned long *outlen) 
+{
+   int           err, type;
+   unsigned long size, x, y, z, i;
+   void          *data;
+
+   LTC_ARGCHK(list    != NULL);
+   LTC_ARGCHK(out     != NULL);
+   LTC_ARGCHK(outlen  != NULL);
+
+   /* get size of output that will be required */
+   y = 0;
+   for (i = 0; i < inlen; i++) {
+       type = list[i].type;
+       size = list[i].size;
+       data = list[i].data;
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+               if ((err = der_length_integer(data, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_SHORT_INTEGER:
+               if ((err = der_length_short_integer(*((unsigned long*)data), &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_BIT_STRING:
+               if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_OCTET_STRING:
+               if ((err = der_length_octet_string(size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_NULL:
+               y += 2;
+               break;
+
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+               if ((err = der_length_object_identifier(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_IA5_STRING:
+               if ((err = der_length_ia5_string(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_PRINTABLE_STRING:
+               if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_UTCTIME:
+               if ((err = der_length_utctime(data, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_SEQUENCE:
+               if ((err = der_length_sequence(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+          
+           default:
+               err = CRYPT_INVALID_ARG;
+               goto LBL_ERR;
+       }
+   }
+
+   /* calc header size */
+   z = y;
+   if (y < 128) {
+      y += 2;
+   } else if (y < 256) {
+      /* 0x30 0x81 LL */
+      y += 3;
+   } else if (y < 65536UL) {
+      /* 0x30 0x82 LL LL */
+      y += 4;
+   } else if (y < 16777216UL) {
+      /* 0x30 0x83 LL LL LL */
+      y += 5;
+   } else {
+      err = CRYPT_INVALID_ARG;
+      goto LBL_ERR;
+   }
+
+   /* too big ? */
+   if (*outlen < y) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto LBL_ERR;
+   }
+
+   /* store header */
+   x = 0;
+   out[x++] = 0x30;
+   if (z < 128) {
+      out[x++] = z;
+   } else if (z < 256) {
+      out[x++] = 0x81;
+      out[x++] = z;
+   } else if (z < 65536UL) {
+      out[x++] = 0x82;
+      out[x++] = (z>>8UL)&255;
+      out[x++] = z&255;
+   } else if (z < 16777216UL) {
+      out[x++] = 0x83;
+      out[x++] = (z>>16UL)&255;
+      out[x++] = (z>>8UL)&255;
+      out[x++] = z&255;
+   }
+
+   /* store data */
+   *outlen -= x;
+   for (i = 0; i < inlen; i++) {
+       type = list[i].type;
+       size = list[i].size;
+       data = list[i].data;
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+               z = *outlen;
+               if ((err = der_encode_integer(data, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_SHORT_INTEGER:
+               z = *outlen;
+               if ((err = der_encode_short_integer(*((unsigned long*)data), out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_BIT_STRING:
+               z = *outlen;
+               if ((err = der_encode_bit_string(data, size, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_OCTET_STRING:
+               z = *outlen;
+               if ((err = der_encode_octet_string(data, size, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_NULL:
+               out[x++] = 0x05;
+               out[x++] = 0x00;
+               *outlen -= 2;
+               break;
+
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+               z = *outlen;
+               if ((err = der_encode_object_identifier(data, size, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_IA5_STRING:
+               z = *outlen;
+               if ((err = der_encode_ia5_string(data, size, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+          
+           case LTC_ASN1_PRINTABLE_STRING:
+               z = *outlen;
+               if ((err = der_encode_printable_string(data, size, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_UTCTIME:
+               z = *outlen;
+               if ((err = der_encode_utctime(data, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           case LTC_ASN1_SEQUENCE:
+               z = *outlen;
+               if ((err = der_encode_sequence(data, size, out + x, &z)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               x       += z;
+               *outlen -= z;
+               break;
+
+           default:
+               err = CRYPT_INVALID_ARG;
+               goto LBL_ERR;
+       }
+   }
+   *outlen = x;
+   err = CRYPT_OK;   
+
+LBL_ERR:
+   return err;
+}
+
+#endif
diff --git a/src/pk/asn1/der/sequence/der_encode_sequence_multi.c b/src/pk/asn1/der/sequence/der_encode_sequence_multi.c
new file mode 100644
index 0000000..9ff48b9
--- /dev/null
+++ b/src/pk/asn1/der/sequence/der_encode_sequence_multi.c
@@ -0,0 +1,123 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+
+/**
+  @file der_encode_sequence_multi.c
+  ASN.1 DER, encode a SEQUENCE, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+int der_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
+{
+   int           err, type;
+   unsigned long size, x;
+   void          *data;
+   va_list       args;
+   ltc_asn1_list *list;
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* get size of output that will be required */
+   va_start(args, outlen);
+   x = 0;
+   for (;;) {
+       type = va_arg(args, int);
+       size = va_arg(args, unsigned long);
+       data = va_arg(args, void*);
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+           case LTC_ASN1_SHORT_INTEGER:
+           case LTC_ASN1_BIT_STRING:
+           case LTC_ASN1_OCTET_STRING:
+           case LTC_ASN1_NULL:
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+           case LTC_ASN1_IA5_STRING:
+           case LTC_ASN1_PRINTABLE_STRING:
+           case LTC_ASN1_UTCTIME:
+           case LTC_ASN1_SEQUENCE:
+                ++x; 
+                break;
+          
+           default:
+               va_end(args);
+               return CRYPT_INVALID_ARG;
+       }
+   }
+   va_end(args);
+
+   /* allocate structure for x elements */
+   if (x == 0) {
+      return CRYPT_NOP;
+   }
+
+   list = XCALLOC(sizeof(*list), x);
+   if (list == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* fill in the structure */
+   va_start(args, outlen);
+   x = 0;
+   for (;;) {
+       type = va_arg(args, int);
+       size = va_arg(args, unsigned long);
+       data = va_arg(args, void*);
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+           case LTC_ASN1_SHORT_INTEGER:
+           case LTC_ASN1_BIT_STRING:
+           case LTC_ASN1_OCTET_STRING:
+           case LTC_ASN1_NULL:
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+           case LTC_ASN1_IA5_STRING:
+           case LTC_ASN1_PRINTABLE_STRING:
+           case LTC_ASN1_UTCTIME:
+           case LTC_ASN1_SEQUENCE:
+                list[x].type   = type;
+                list[x].size   = size;
+                list[x++].data = data;
+                break;
+         
+           default:
+               va_end(args);
+               err = CRYPT_INVALID_ARG;
+               goto LBL_ERR;
+       }
+   }
+   va_end(args);
+
+   err = der_encode_sequence(list, x, out, outlen);   
+LBL_ERR:
+   XFREE(list);
+   return err;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/sequence/der_encode_sequence_multi.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/06/18 19:20:23 $ */
diff --git a/src/pk/asn1/der/sequence/der_length_sequence.c b/src/pk/asn1/der/sequence/der_length_sequence.c
new file mode 100644
index 0000000..9120451
--- /dev/null
+++ b/src/pk/asn1/der/sequence/der_length_sequence.c
@@ -0,0 +1,144 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+#include <stdarg.h>
+
+
+/**
+  @file der_length_sequence.c
+  ASN.1 DER, length a SEQUENCE, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+   Get the length of a DER sequence 
+   @param list   The sequences of items in the SEQUENCE
+   @param inlen  The number of items
+   @param outlen [out] The length required in octets to store it 
+   @return CRYPT_OK on success
+*/
+int der_length_sequence(ltc_asn1_list *list, unsigned long inlen,
+                        unsigned long *outlen) 
+{
+   int           err, type;
+   unsigned long size, x, y, z, i;
+   void          *data;
+
+   LTC_ARGCHK(list    != NULL);
+   LTC_ARGCHK(outlen  != NULL);
+
+   /* get size of output that will be required */
+   y = 0;
+   for (i = 0; i < inlen; i++) {
+       type = list[i].type;
+       size = list[i].size;
+       data = list[i].data;
+
+       if (type == LTC_ASN1_EOL) { 
+          break;
+       }
+
+       switch (type) {
+           case LTC_ASN1_INTEGER:
+               if ((err = der_length_integer(data, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_SHORT_INTEGER:
+               if ((err = der_length_short_integer(*((unsigned long *)data), &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_BIT_STRING:
+               if ((err = der_length_bit_string(size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_OCTET_STRING:
+               if ((err = der_length_octet_string(size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_NULL:
+               y += 2;
+               break;
+
+           case LTC_ASN1_OBJECT_IDENTIFIER:
+               if ((err = der_length_object_identifier(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_IA5_STRING:
+               if ((err = der_length_ia5_string(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_PRINTABLE_STRING:
+               if ((err = der_length_printable_string(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+           case LTC_ASN1_SEQUENCE:
+               if ((err = der_length_sequence(data, size, &x)) != CRYPT_OK) {
+                  goto LBL_ERR;
+               }
+               y += x;
+               break;
+
+          
+           default:
+               err = CRYPT_INVALID_ARG;
+               goto LBL_ERR;
+       }
+   }
+
+   /* calc header size */
+   z = y;
+   if (y < 128) {
+      y += 2;
+   } else if (y < 256) {
+      /* 0x30 0x81 LL */
+      y += 3;
+   } else if (y < 65536UL) {
+      /* 0x30 0x82 LL LL */
+      y += 4;
+   } else if (y < 16777216UL) {
+      /* 0x30 0x83 LL LL LL */
+      y += 5;
+   } else {
+      err = CRYPT_INVALID_ARG;
+      goto LBL_ERR;
+   }
+
+   /* store size */
+   *outlen = y;
+   err     = CRYPT_OK;
+
+LBL_ERR:
+   return err;
+}
+
+#endif
diff --git a/src/pk/asn1/der/short_integer/der_decode_short_integer.c b/src/pk/asn1/der/short_integer/der_decode_short_integer.c
new file mode 100644
index 0000000..7d3d3b7
--- /dev/null
+++ b/src/pk/asn1/der/short_integer/der_decode_short_integer.c
@@ -0,0 +1,68 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_short_integer.c
+  ASN.1 DER, decode an integer, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/**
+  Read a mp_int integer
+  @param in       The DER encoded data
+  @param inlen    Size of data
+  @param num      [out] The integer to decode
+  @return CRYPT_OK if successful
+*/
+int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num)
+{
+   unsigned long len, x, y;
+
+   LTC_ARGCHK(num    != NULL);
+   LTC_ARGCHK(in     != NULL);
+
+   /* check length */
+   if (inlen < 2) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* check header */
+   x = 0;
+   if ((in[x++] & 0x1F) != 0x02) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* get the packet len */
+   len = in[x++];
+
+   if (x + len > inlen) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* read number */
+   y = 0;
+   while (len--) {
+      y = (y<<8) | (unsigned long)in[x++];
+   }
+   *num = y;
+
+   return CRYPT_OK;
+
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_decode_short_integer.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/23 01:04:13 $ */
diff --git a/src/pk/asn1/der/short_integer/der_encode_short_integer.c b/src/pk/asn1/der/short_integer/der_encode_short_integer.c
new file mode 100644
index 0000000..eb94d38
--- /dev/null
+++ b/src/pk/asn1/der/short_integer/der_encode_short_integer.c
@@ -0,0 +1,97 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_short_integer.c
+  ASN.1 DER, encode an integer, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/* Exports a positive integer as DER format (upto 32-bits in size) */
+/**
+  Store a mp_int integer
+  @param num      The integer to encode
+  @param out      [out] The destination for the DER encoded integers
+  @param outlen   [in/out] The max size and resulting size of the DER encoded integers
+  @return CRYPT_OK if successful
+*/
+int der_encode_short_integer(unsigned long num, unsigned char *out, unsigned long *outlen)
+{  
+   unsigned long len, x, y, z;
+   int           err;
+   
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* force to 32 bits */
+   num &= 0xFFFFFFFFUL;
+
+   /* find out how big this will be */
+   if ((err = der_length_short_integer(num, &len)) != CRYPT_OK) {
+      return err;
+   }
+
+   if (*outlen < len) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   /* get len of output */
+   z = 0;
+   y = num;
+   while (y) {
+     ++z;
+     y >>= 8;
+   }
+
+   /* handle zero */
+   if (z == 0) {
+      z = 1;
+   }
+
+   /* see if msb is set */
+   z += (num&(1UL<<((z<<3) - 1))) ? 1 : 0;
+
+   /* adjust the number so the msB is non-zero */
+   for (x = 0; (z <= 4) && (x < (4 - z)); x++) {
+      num <<= 8;
+   }
+
+   /* store header */
+   x = 0;
+   out[x++] = 0x02;
+   out[x++] = z;
+
+   /* if 31st bit is set output a leading zero and decrement count */
+   if (z == 5) {
+      out[x++] = 0;
+      --z;
+   }
+
+   /* store values */
+   for (y = 0; y < z; y++) {
+      out[x++] = (num >> 24) & 0xFF;
+      num    <<= 8;
+   }
+
+   /* we good */
+   *outlen = x;
+ 
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_encode_short_integer.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/23 01:27:03 $ */
diff --git a/src/pk/asn1/der/short_integer/der_length_short_integer.c b/src/pk/asn1/der/short_integer/der_length_short_integer.c
new file mode 100644
index 0000000..7324b4a
--- /dev/null
+++ b/src/pk/asn1/der/short_integer/der_length_short_integer.c
@@ -0,0 +1,69 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_short_integer.c
+  ASN.1 DER, get length of encoding, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+/**
+  Gets length of DER encoding of num 
+  @param num    The integer to get the size of 
+  @param outlen [out] The length of the DER encoding for the given integer
+  @return CRYPT_OK if successful
+*/
+int der_length_short_integer(unsigned long num, unsigned long *outlen)
+{
+   unsigned long z, y, len;
+
+   LTC_ARGCHK(outlen  != NULL);
+
+   /* force to 32 bits */
+   num &= 0xFFFFFFFFUL;
+
+   /* get the number of bytes */
+   z = 0;
+   y = num;
+   while (y) {
+     ++z;
+     y >>= 8;
+   }
+
+   /* handle zero */
+   if (z == 0) {
+      z = 1;
+   }
+
+   /* we need a 0x02 to indicate it's INTEGER */
+   len = 1;
+
+   /* length byte */
+   ++len;
+
+   /* bytes in value */
+   len += z;
+
+   /* see if msb is set */
+   len += (num&(1UL<<((z<<3) - 1))) ? 1 : 0;
+
+   /* return length */
+   *outlen = len; 
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/short_integer/der_length_short_integer.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/23 01:35:38 $ */
diff --git a/src/pk/asn1/der/utctime/der_decode_utctime.c b/src/pk/asn1/der/utctime/der_decode_utctime.c
new file mode 100644
index 0000000..43ba033
--- /dev/null
+++ b/src/pk/asn1/der/utctime/der_decode_utctime.c
@@ -0,0 +1,120 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_decode_utctime.c
+  ASN.1 DER, decode a  UTCTIME, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+static int char_to_int(unsigned char x)
+{
+   switch (x)  {
+      case '0': return 0;
+      case '1': return 1;
+      case '2': return 2;
+      case '3': return 3;
+      case '4': return 4;
+      case '5': return 5;
+      case '6': return 6;
+      case '7': return 7;
+      case '8': return 8;
+      case '9': return 9;
+   }
+   return 100;
+}
+
+#define DECODE_V(y, max) \
+   y  = char_to_int(buf[x])*10 + char_to_int(buf[x+1]); \
+   if (y >= max) return CRYPT_INVALID_PACKET;           \
+   x += 2;
+
+int der_decode_utctime(const unsigned char *in, unsigned long *inlen,
+                             ltc_utctime   *out)
+{
+   unsigned char buf[32];
+   unsigned long x;
+   int           y;
+
+   LTC_ARGCHK(in    != NULL);
+   LTC_ARGCHK(inlen != NULL);
+   LTC_ARGCHK(out   != NULL);
+
+   /* check header */
+   if (*inlen < 2UL || (in[1] >= sizeof(buf)) || ((in[1] + 2UL) > *inlen)) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* decode the string */
+   for (x = 0; x < in[1]; x++) {
+       y = der_ia5_value_decode(in[x+2]);
+       if (y == -1) {
+          return CRYPT_INVALID_PACKET;
+       }
+       buf[x] = y;
+   }
+   *inlen = 2 + x;
+
+
+   /* possible encodings are 
+YYMMDDhhmmZ
+YYMMDDhhmm+hh'mm'
+YYMMDDhhmm-hh'mm'
+YYMMDDhhmmssZ
+YYMMDDhhmmss+hh'mm'
+YYMMDDhhmmss-hh'mm'
+
+    So let's do a trivial decode upto [including] mm 
+   */
+
+    x = 0;
+    DECODE_V(out->YY, 100);
+    DECODE_V(out->MM, 13);
+    DECODE_V(out->DD, 32);
+    DECODE_V(out->hh, 24);
+    DECODE_V(out->mm, 60);
+
+    /* clear timezone and seconds info */
+    out->off_dir = out->off_hh = out->off_mm = out->ss = 0;
+
+    /* now is it Z, +, - or 0-9 */
+    if (buf[x] == 'Z') {
+       return CRYPT_OK;
+    } else if (buf[x] == '+' || buf[x] == '-') {
+       out->off_dir = (buf[x++] == '+') ? 0 : 1;
+       DECODE_V(out->off_hh, 24);
+       DECODE_V(out->off_mm, 60);
+       return CRYPT_OK;
+    }
+
+    /* decode seconds */
+    DECODE_V(out->ss, 60);
+
+    /* now is it Z, +, - */
+    if (buf[x] == 'Z') {
+       return CRYPT_OK;
+    } else if (buf[x] == '+' || buf[x] == '-') {
+       out->off_dir = (buf[x++] == '+') ? 0 : 1;
+       DECODE_V(out->off_hh, 24);
+       DECODE_V(out->off_mm, 60);
+       return CRYPT_OK;
+    } else {
+       return CRYPT_INVALID_PACKET;
+    }
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_decode_utctime.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/06/19 12:07:00 $ */
diff --git a/src/pk/asn1/der/utctime/der_encode_utctime.c b/src/pk/asn1/der/utctime/der_encode_utctime.c
new file mode 100644
index 0000000..dad8c84
--- /dev/null
+++ b/src/pk/asn1/der/utctime/der_encode_utctime.c
@@ -0,0 +1,80 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_encode_utctime.c
+  ASN.1 DER, encode a  UTCTIME, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+static const char *baseten = "0123456789";
+
+#define STORE_V(y) \
+    out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
+    out[x++] = der_ia5_char_encode(baseten[y % 10]);
+
+/**
+  Gets length of DER encoding of UTCTIME
+  @param outlen [out] The length of the DER encoding
+  @return CRYPT_OK if successful
+*/
+int der_encode_utctime(ltc_utctime *utctime, 
+                       unsigned char *out,   unsigned long *outlen)
+{
+    unsigned long x, tmplen;
+    int           err;
+ 
+    LTC_ARGCHK(utctime != NULL);
+    LTC_ARGCHK(out     != NULL);
+    LTC_ARGCHK(outlen  != NULL);
+
+    if ((err = der_length_utctime(utctime, &tmplen)) != CRYPT_OK) {
+       return err;
+    }
+    if (tmplen > *outlen) {
+        return CRYPT_BUFFER_OVERFLOW;
+    }
+    
+    /* store header */
+    out[0] = 0x17;
+
+    /* store values */
+    x = 2;
+    STORE_V(utctime->YY);
+    STORE_V(utctime->MM);
+    STORE_V(utctime->DD);
+    STORE_V(utctime->hh);
+    STORE_V(utctime->mm);
+    STORE_V(utctime->ss);
+
+    if (utctime->off_mm || utctime->off_hh) {
+       out[x++] = der_ia5_char_encode(utctime->off_dir ? '-' : '+');
+       STORE_V(utctime->off_hh);
+       STORE_V(utctime->off_mm);
+    } else {
+       out[x++] = der_ia5_char_encode('Z');
+    }
+
+    /* store length */
+    out[1] = x - 2;
+   
+    /* all good let's return */
+    *outlen = x;
+    return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_encode_utctime.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/06/19 12:07:00 $ */
diff --git a/src/pk/asn1/der/utctime/der_length_utctime.c b/src/pk/asn1/der/utctime/der_length_utctime.c
new file mode 100644
index 0000000..84e654a
--- /dev/null
+++ b/src/pk/asn1/der/utctime/der_length_utctime.c
@@ -0,0 +1,45 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file der_length_utctime.c
+  ASN.1 DER, get length of UTCTIME, Tom St Denis
+*/
+
+#ifdef LTC_DER
+
+/**
+  Gets length of DER encoding of UTCTIME
+  @param outlen [out] The length of the DER encoding
+  @return CRYPT_OK if successful
+*/
+int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen)
+{
+   LTC_ARGCHK(outlen  != NULL);
+   LTC_ARGCHK(utctime != NULL);
+
+   if (utctime->off_hh == 0 && utctime->off_mm == 0) {
+      /* we encode as YYMMDDhhmmssZ */
+      *outlen = 2 + 13;
+   } else {
+      /* we encode as YYMMDDhhmmss{+|-}hh'mm' */
+      *outlen = 2 + 17;
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_length_utctime.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/06/19 11:23:04 $ */
diff --git a/dh.c b/src/pk/dh/dh.c
similarity index 80%
rename from dh.c
rename to src/pk/dh/dh.c
index 8cf5632..a54f29b 100644
--- a/dh.c
+++ b/src/pk/dh/dh.c
@@ -6,12 +6,20 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
+/**
+  @file dh.c
+  DH crypto, Tom St Denis
+*/
+  
 #ifdef MDH
 
+/* max export size we'll encounter (smaller than this but lets round up a bit) */
+#define DH_BUF_SIZE 1200
+
 /* This holds the key settings.  ***MUST*** be organized by size from smallest to largest. */
 static const struct {
     int size;
@@ -154,6 +162,10 @@
    return 1;
 }
 
+/**
+   Test the DH sub-system (can take a while)
+   @return CRYPT_OK if successful
+*/
 int dh_test(void)
 {
     mp_int p, g, tmp;
@@ -201,11 +213,16 @@
     return err;
 }
 
+/**
+   Get the min and max DH key sizes (octets)
+   @param low    [out] The smallest key size supported
+   @param high   [out] The largest key size supported
+*/
 void dh_sizes(int *low, int *high)
 {
    int x;
-   _ARGCHK(low != NULL);
-   _ARGCHK(high != NULL);
+   LTC_ARGCHK(low != NULL);
+   LTC_ARGCHK(high != NULL);
    *low  = INT_MAX;
    *high = 0;
    for (x = 0; sets[x].size != 0; x++) {
@@ -214,9 +231,14 @@
    }
 }
 
+/**
+  Returns the key size of a given DH key (octets)
+  @param key   The DH key to get the size of
+  @return The size if valid or INT_MAX if not
+*/
 int dh_get_size(dh_key *key)
 {
-    _ARGCHK(key != NULL);
+    LTC_ARGCHK(key != NULL);
     if (is_valid_idx(key->idx) == 1) {
         return sets[key->idx].size;
     } else {
@@ -224,14 +246,22 @@
     }
 }
 
+/**
+  Make a DH key [private key pair]
+  @param prng     An active PRNG state
+  @param wprng    The index for the PRNG you desire to use
+  @param keysize  The key size (octets) desired
+  @param key      [out] Where the newly created DH key will be stored
+  @return CRYPT_OK if successful, note: on error all allocated memory will be freed automatically.
+*/
 int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key)
 {
-   unsigned char buf[512];
+   unsigned char *buf;
    unsigned long x;
    mp_int p, g;
    int err;
 
-   _ARGCHK(key  != NULL);
+   LTC_ARGCHK(key  != NULL);
 
    /* good prng? */
    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -251,14 +281,21 @@
    }
    key->idx = x;
 
+   /* allocate buffer */
+   buf = XMALLOC(keysize);
+   if (buf == NULL) {
+      return CRYPT_MEM;
+   }
+
    /* make up random string */
    if (prng_descriptor[wprng].read(buf, keysize, prng) != (unsigned long)keysize) {
-      return CRYPT_ERROR_READPRNG;
+      err = CRYPT_ERROR_READPRNG; 
+      goto error2;
    }
 
    /* init parameters */
    if ((err = mp_init_multi(&g, &p, &key->x, &key->y, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
+      goto error;
    }
    if ((err = mp_read_radix(&g, sets[key->idx].base, 64)) != MP_OKAY)      { goto error; }
    if ((err = mp_read_radix(&p, sets[key->idx].prime, 64)) != MP_OKAY)     { goto error; }
@@ -276,27 +313,43 @@
    goto done;
 error:
    err = mpi_to_ltc_error(err);
+error2:
    mp_clear_multi(&key->x, &key->y, NULL);
 done:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, keysize);
+#endif
    mp_clear_multi(&p, &g, NULL);
-   zeromem(buf, sizeof(buf));
+   XFREE(buf);
    return err;
 }
 
+/**
+  Free the allocated ram for a DH key
+  @param key   The key which you wish to free
+*/ 
 void dh_free(dh_key *key)
 {
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(key != NULL);
    mp_clear_multi(&key->x, &key->y, NULL);
 }
 
+/**
+  Export a DH key to a binary packet
+  @param out    [out] The destination for the key
+  @param outlen [in/out] The max size and resulting size of the DH key
+  @param type   Which type of key (PK_PRIVATE or PK_PUBLIC)
+  @param key    The key you wish to export
+  @return CRYPT_OK if successful
+*/
 int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key)
 {
    unsigned long y, z;
    int err;
 
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
 
    /* can we store the static header?  */
    if (*outlen < (PACKET_SIZE + 2)) {
@@ -330,13 +383,20 @@
    return CRYPT_OK;
 }
 
+/**
+  Import a DH key from a binary packet
+  @param in     The packet to read
+  @param inlen  The length of the input packet
+  @param key    [out] Where to import the key to
+  @return CRYPT_OK if successful, on error all allocated memory is freed automatically
+*/
 int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key)
 {
    unsigned long x, y, s;
    int err;
 
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(key != NULL);
 
    /* make sure valid length */
    if ((2+PACKET_SIZE) > inlen) {
@@ -399,6 +459,14 @@
    return err;
 }
 
+/**
+   Create a DH shared secret.
+   @param private_key     The private DH key in the pair
+   @param public_key      The public DH key in the pair 
+   @param out             [out] The destination of the shared data
+   @param outlen          [in/out] The max size and resulting size of the shared data.
+   @return CRYPT_OK if successful
+*/
 int dh_shared_secret(dh_key *private_key, dh_key *public_key,
                      unsigned char *out, unsigned long *outlen)
 {
@@ -406,10 +474,10 @@
    unsigned long x;
    int err;
 
-   _ARGCHK(private_key != NULL);
-   _ARGCHK(public_key  != NULL);
-   _ARGCHK(out         != NULL);
-   _ARGCHK(outlen      != NULL);
+   LTC_ARGCHK(private_key != NULL);
+   LTC_ARGCHK(public_key  != NULL);
+   LTC_ARGCHK(out         != NULL);
+   LTC_ARGCHK(outlen      != NULL);
 
    /* types valid? */
    if (private_key->type != PK_PRIVATE) {
@@ -450,3 +518,7 @@
 
 #endif
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dh/dh.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/dh_sys.c b/src/pk/dh/dh_sys.c
similarity index 61%
rename from dh_sys.c
rename to src/pk/dh/dh_sys.c
index fb05aa3..4f10556 100644
--- a/dh_sys.c
+++ b/src/pk/dh/dh_sys.c
@@ -6,22 +6,40 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-int dh_encrypt_key(const unsigned char *inkey, unsigned long keylen,
-                         unsigned char *out,  unsigned long *len,
+
+/**
+  @file dh_sys.c
+  DH Crypto, Tom St Denis
+*/
+  
+/**
+  Encrypt a short symmetric key with a public DH key
+  @param in        The symmetric key to encrypt
+  @param inlen     The length of the key (octets)
+  @param out       [out] The ciphertext
+  @param outlen    [in/out]  The max size and resulting size of the ciphertext
+  @param prng      An active PRNG state
+  @param wprng     The index of the PRNG desired
+  @param hash      The index of the hash desired (must produce a digest of size >= the size of the plaintext)
+  @param key       The public key you wish to encrypt with.
+  @return CRYPT_OK if successful
+*/
+int dh_encrypt_key(const unsigned char *in,   unsigned long inlen,
+                         unsigned char *out,  unsigned long *outlen,
                          prng_state *prng, int wprng, int hash,
                          dh_key *key)
 {
-    unsigned char pub_expt[768], dh_shared[768], skey[MAXBLOCKSIZE];
-    dh_key pubkey;
+    unsigned char *pub_expt, *dh_shared, *skey;
+    dh_key        pubkey;
     unsigned long x, y, z, hashsize, pubkeysize;
-    int err;
+    int           err;
 
-    _ARGCHK(inkey != NULL);
-    _ARGCHK(out   != NULL);
-    _ARGCHK(len   != NULL);
-    _ARGCHK(key   != NULL);
+    LTC_ARGCHK(in != NULL);
+    LTC_ARGCHK(out   != NULL);
+    LTC_ARGCHK(outlen   != NULL);
+    LTC_ARGCHK(key   != NULL);
 
     /* check that wprng/hash are not invalid */
     if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -32,40 +50,58 @@
        return err;
     }
 
-    if (keylen > hash_descriptor[hash].hashsize)  {
+    if (inlen > hash_descriptor[hash].hashsize)  {
         return CRYPT_INVALID_HASH;
     }
 
+    /* allocate memory */
+    pub_expt  = XMALLOC(DH_BUF_SIZE);
+    dh_shared = XMALLOC(DH_BUF_SIZE);
+    skey      = XMALLOC(MAXBLOCKSIZE);
+    if (pub_expt == NULL || dh_shared == NULL || skey == NULL) {
+       if (pub_expt != NULL) {
+          XFREE(pub_expt);
+       }
+       if (dh_shared != NULL) {
+          XFREE(dh_shared);
+       }
+       if (skey != NULL) {
+          XFREE(skey);
+       }
+       return CRYPT_MEM;
+    }
+
     /* make a random key and export the public copy */
     if ((err = dh_make_key(prng, wprng, dh_get_size(key), &pubkey)) != CRYPT_OK) {
-       return err;
+       goto LBL_ERR;
     }
 
-    pubkeysize = sizeof(pub_expt);
+    pubkeysize = DH_BUF_SIZE;
     if ((err = dh_export(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
        dh_free(&pubkey);
-       return err;
+       goto LBL_ERR;
     }
 
     /* now check if the out buffer is big enough */
-    if (*len < (1 + 4 + 4 + PACKET_SIZE + pubkeysize + keylen)) {
+    if (*outlen < (1 + 4 + 4 + PACKET_SIZE + pubkeysize + inlen)) {
        dh_free(&pubkey);
-       return CRYPT_BUFFER_OVERFLOW;
+       err = CRYPT_BUFFER_OVERFLOW;
+       goto LBL_ERR;
     }
 
     /* make random key */
     hashsize  = hash_descriptor[hash].hashsize;
 
-    x = (unsigned long)sizeof(dh_shared);
+    x = DH_BUF_SIZE;
     if ((err = dh_shared_secret(&pubkey, key, dh_shared, &x)) != CRYPT_OK) {
        dh_free(&pubkey);
-       return err;
+       goto LBL_ERR;
     }
     dh_free(&pubkey);
 
-    z = sizeof(skey);
+    z = MAXBLOCKSIZE;
     if ((err = hash_memory(hash, dh_shared, x, skey, &z)) != CRYPT_OK) {
-       return err;
+       goto LBL_ERR;
     }
 
     /* store header */
@@ -85,60 +121,89 @@
     }
 
     /* Store the encrypted key */
-    STORE32L(keylen, out+y);
+    STORE32L(inlen, out+y);
     y += 4;
 
-    for (x = 0; x < keylen; x++, y++) {
-      out[y] = skey[x] ^ inkey[x];
+    for (x = 0; x < inlen; x++, y++) {
+      out[y] = skey[x] ^ in[x];
     }
-    *len = y;
+    *outlen = y;
 
-#ifdef CLEAN_STACK
+    err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
     /* clean up */
-    zeromem(pub_expt, sizeof(pub_expt));
-    zeromem(dh_shared, sizeof(dh_shared));
-    zeromem(skey, sizeof(skey));
+    zeromem(pub_expt,  DH_BUF_SIZE);
+    zeromem(dh_shared, DH_BUF_SIZE);
+    zeromem(skey,      MAXBLOCKSIZE);
 #endif
+    XFREE(skey);
+    XFREE(dh_shared);
+    XFREE(pub_expt);
 
-    return CRYPT_OK;
+    return err;
 }
 
+/**
+   Decrypt a DH encrypted symmetric key
+   @param in       The DH encrypted packet
+   @param inlen    The length of the DH encrypted packet
+   @param out      The plaintext
+   @param outlen   [in/out]  The max size and resulting size of the plaintext
+   @param key      The private DH key corresponding to the public key that encrypted the plaintext
+   @return CRYPT_OK if successful
+*/
 int dh_decrypt_key(const unsigned char *in, unsigned long inlen,
-                         unsigned char *outkey, unsigned long *keylen, 
+                         unsigned char *out, unsigned long *outlen, 
                          dh_key *key)
 {
-   unsigned char shared_secret[768], skey[MAXBLOCKSIZE];
-   unsigned long x, y, z,hashsize, keysize;
-   int  hash, err;
-   dh_key pubkey;
+   unsigned char *shared_secret, *skey;
+   unsigned long  x, y, z, hashsize, keysize;
+   int            hash, err;
+   dh_key         pubkey;
 
-   _ARGCHK(in     != NULL);
-   _ARGCHK(outkey != NULL);
-   _ARGCHK(keylen != NULL);
-   _ARGCHK(key    != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
 
    /* right key type? */
    if (key->type != PK_PRIVATE) {
       return CRYPT_PK_NOT_PRIVATE;
    }
 
+   /* allocate ram */
+   shared_secret = XMALLOC(DH_BUF_SIZE);
+   skey          = XMALLOC(MAXBLOCKSIZE);
+   if (shared_secret == NULL || skey == NULL) {
+      if (shared_secret != NULL) {
+         XFREE(shared_secret);
+      }
+      if (skey != NULL) {
+         XFREE(skey);
+      }
+      return CRYPT_MEM;
+   }
+
    /* check if initial header should fit */
    if (inlen < PACKET_SIZE+1+4+4) {
-      return CRYPT_INVALID_PACKET;
+      err =  CRYPT_INVALID_PACKET;
+      goto LBL_ERR;
    } else {
       inlen -= PACKET_SIZE+1+4+4;
    }
 
    /* is header correct? */
    if ((err = packet_valid_header((unsigned char *)in, PACKET_SECT_DH, PACKET_SUB_ENC_KEY)) != CRYPT_OK)  {
-      return err;
+      goto LBL_ERR;
    }
 
    /* now lets get the hash name */
    y = PACKET_SIZE;
    hash = find_hash_id(in[y++]);
    if (hash == -1) {
-      return CRYPT_INVALID_HASH;
+      err = CRYPT_INVALID_HASH;
+      goto LBL_ERR;
    }
 
    /* common values */
@@ -149,58 +214,64 @@
    
    /* now check if the imported key will fit */
    if (inlen < x) {
-      return CRYPT_INVALID_PACKET;
+      err = CRYPT_INVALID_PACKET;
+      goto LBL_ERR;
    } else {
       inlen -= x;
    }
    
    y += 4;
    if ((err = dh_import(in+y, x, &pubkey)) != CRYPT_OK) {
-      return err;
+      goto LBL_ERR;
    }
    y += x;
 
    /* make shared key */
-   x = (unsigned long)sizeof(shared_secret);
+   x = DH_BUF_SIZE;
    if ((err = dh_shared_secret(key, &pubkey, shared_secret, &x)) != CRYPT_OK) {
       dh_free(&pubkey);
-      return err;
+      goto LBL_ERR;
    }
    dh_free(&pubkey);
 
-   z = sizeof(skey);
+   z = MAXBLOCKSIZE;
    if ((err = hash_memory(hash, shared_secret, x, skey, &z)) != CRYPT_OK) {
-      return err;
+      goto LBL_ERR;
    }
 
    /* load in the encrypted key */
    LOAD32L(keysize, in+y);
    
-   /* will the outkey fit as part of the input */
+   /* will the out fit as part of the input */
    if (inlen < keysize) {
-      return CRYPT_INVALID_PACKET;
+      err = CRYPT_INVALID_PACKET;
+      goto LBL_ERR;
    } else {
       inlen -= keysize;
    }
    
-   if (keysize > *keylen) {
+   if (keysize > *outlen) {
        err = CRYPT_BUFFER_OVERFLOW;
-       goto done;
+       goto LBL_ERR;
    }
    y += 4;
 
-   *keylen = keysize;
+   *outlen = keysize;
 
    for (x = 0; x < keysize; x++, y++) {
-      outkey[x] = skey[x] ^ in[y];
+      out[x] = skey[x] ^ in[y];
    }
 
    err = CRYPT_OK;
-done:
-#ifdef CLEAN_STACK
-   zeromem(shared_secret, sizeof(shared_secret));
-   zeromem(skey, sizeof(skey));
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(shared_secret, DH_BUF_SIZE);
+   zeromem(skey,          MAXBLOCKSIZE);
 #endif
+
+   XFREE(skey);
+   XFREE(shared_secret);
+
    return err;
 }
 
@@ -222,19 +293,31 @@
  2.  Compare against g^M mod p [based on input hash].
  3.  If result of #2 == result of #1 then signature valid 
 */
+
+/**
+  Sign a message digest using a DH private key 
+  @param in      The data to sign
+  @param inlen   The length of the input (octets)
+  @param out     [out] The destination of the signature
+  @param outlen  [in/out] The max size and resulting size of the output
+  @param prng    An active PRNG state
+  @param wprng   The index of the PRNG desired
+  @param key     A private DH key
+  @return CRYPT_OK if successful
+*/
 int dh_sign_hash(const unsigned char *in,  unsigned long inlen,
                        unsigned char *out, unsigned long *outlen,
                        prng_state *prng, int wprng, dh_key *key)
 {
-   mp_int a, b, k, m, g, p, p1, tmp;
-   unsigned char buf[520];
-   unsigned long x, y;
-   int err;
+   mp_int         a, b, k, m, g, p, p1, tmp;
+   unsigned char *buf;
+   unsigned long  x, y;
+   int            err;
 
-   _ARGCHK(in     != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
 
    /* check parameters */
    if (key->type != PK_PRIVATE) {
@@ -250,27 +333,28 @@
       return CRYPT_PK_INVALID_TYPE;
    }
 
+   /* allocate ram for buf */
+   buf = XMALLOC(520);
+
    /* make up a random value k,
     * since the order of the group is prime
     * we need not check if gcd(k, r) is 1 
     */
    if (prng_descriptor[wprng].read(buf, sets[key->idx].size, prng) != 
        (unsigned long)(sets[key->idx].size)) {
-      return CRYPT_ERROR_READPRNG;
+      err = CRYPT_ERROR_READPRNG;
+      goto LBL_ERR;
    }
 
    /* init bignums */
    if ((err = mp_init_multi(&a, &b, &k, &m, &p, &g, &p1, &tmp, NULL)) != MP_OKAY) { 
-      return mpi_to_ltc_error(err);
+      err = mpi_to_ltc_error(err);
+      goto LBL_ERR;
    }
 
    /* load k and m */
    if ((err = mp_read_unsigned_bin(&m, (unsigned char *)in, inlen)) != MP_OKAY)        { goto error; }
-#ifdef FAST_PK   
-   if ((err = mp_read_unsigned_bin(&k, buf, MIN(32,sets[key->idx].size))) != MP_OKAY)  { goto error; }
-#else   
    if ((err = mp_read_unsigned_bin(&k, buf, sets[key->idx].size)) != MP_OKAY)          { goto error; }
-#endif  
 
    /* load g, p and p1 */
    if ((err = mp_read_radix(&g, sets[key->idx].base, 64)) != MP_OKAY)               { goto error; }
@@ -290,7 +374,7 @@
    /* check for overflow */
    if ((unsigned long)(PACKET_SIZE + 4 + 4 + mp_unsigned_bin_size(&a) + mp_unsigned_bin_size(&b)) > *outlen) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto done;
+      goto LBL_ERR;
    }
    
    /* store header  */
@@ -310,7 +394,7 @@
    /* check if size too big */
    if (*outlen < y) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto done;
+      goto LBL_ERR;
    }
 
    /* store header */
@@ -318,28 +402,40 @@
    *outlen = y;
 
    err = CRYPT_OK;
-   goto done;
+   goto LBL_ERR;
 error:
    err = mpi_to_ltc_error(err);
-done:
+LBL_ERR:
    mp_clear_multi(&tmp, &p1, &g, &p, &m, &k, &b, &a, NULL);
+
+   XFREE(buf);
+
    return err;
 }
 
 
-/* verify the signature in sig of the given hash */
+/**
+   Verify the signature given
+   @param sig        The signature
+   @param siglen     The length of the signature (octets)
+   @param hash       The hash that was signed
+   @param hashlen    The length of the hash (octets)
+   @param stat       [out] Result of signature comparison, 1==valid, 0==invalid
+   @param key        The public DH key that signed the hash
+   @return CRYPT_OK if succsessful (even if signature is invalid)
+*/
 int dh_verify_hash(const unsigned char *sig, unsigned long siglen,
                    const unsigned char *hash, unsigned long hashlen, 
                          int *stat, dh_key *key)
 {
-   mp_int a, b, p, g, m, tmp;
+   mp_int        a, b, p, g, m, tmp;
    unsigned long x, y;
-   int err;
+   int           err;
 
-   _ARGCHK(sig  != NULL);
-   _ARGCHK(hash != NULL);
-   _ARGCHK(stat != NULL);
-   _ARGCHK(key  != NULL);
+   LTC_ARGCHK(sig  != NULL);
+   LTC_ARGCHK(hash != NULL);
+   LTC_ARGCHK(stat != NULL);
+   LTC_ARGCHK(key  != NULL);
 
    /* default to invalid */
    *stat = 0;
@@ -397,3 +493,7 @@
    return err;
 }
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dh/dh_sys.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/dsa/dsa_export.c b/src/pk/dsa/dsa_export.c
new file mode 100644
index 0000000..5a093d9
--- /dev/null
+++ b/src/pk/dsa/dsa_export.c
@@ -0,0 +1,72 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file dsa_export.c
+   DSA implementation, export key, Tom St Denis
+*/
+
+#ifdef MDSA
+
+/**
+  Export a DSA key to a binary packet
+  @param out    [out] Where to store the packet
+  @param outlen [in/out] The max size and resulting size of the packet
+  @param type   The type of key to export (PK_PRIVATE or PK_PUBLIC)
+  @param key    The key to export
+  @return CRYPT_OK if successful
+*/
+int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key)
+{
+   unsigned char flags[1];
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
+
+   /* can we store the static header?  */
+   if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
+      return CRYPT_PK_TYPE_MISMATCH;
+   }
+
+   if (type != PK_PUBLIC && type != PK_PRIVATE) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   flags[0] = (type != PK_PUBLIC) ? 1 : 0;
+
+   if (type == PK_PRIVATE) {
+      return der_encode_sequence_multi(out, outlen,
+                                 LTC_ASN1_BIT_STRING,   1UL, flags,
+                                 LTC_ASN1_INTEGER,      1UL, &key->g,
+                                 LTC_ASN1_INTEGER,      1UL, &key->p,
+                                 LTC_ASN1_INTEGER,      1UL, &key->q,
+                                 LTC_ASN1_INTEGER,      1UL, &key->y,
+                                 LTC_ASN1_INTEGER,      1UL, &key->x,
+                                 LTC_ASN1_EOL,          0UL, NULL);
+   } else {
+      return der_encode_sequence_multi(out, outlen,
+                                 LTC_ASN1_BIT_STRING,   1UL, flags,
+                                 LTC_ASN1_INTEGER,      1UL, &key->g,
+                                 LTC_ASN1_INTEGER,      1UL, &key->p,
+                                 LTC_ASN1_INTEGER,      1UL, &key->q,
+                                 LTC_ASN1_INTEGER,      1UL, &key->y,
+                                 LTC_ASN1_EOL,          0UL, NULL);
+   }
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_export.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/06/03 19:24:31 $ */
diff --git a/src/pk/dsa/dsa_free.c b/src/pk/dsa/dsa_free.c
new file mode 100644
index 0000000..9157acb
--- /dev/null
+++ b/src/pk/dsa/dsa_free.c
@@ -0,0 +1,34 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file dsa_free.c
+   DSA implementation, free a DSA key, Tom St Denis
+*/
+
+#ifdef MDSA
+
+/**
+   Free a DSA key
+   @param key   The key to free from memory
+*/
+void dsa_free(dsa_key *key)
+{
+   LTC_ARGCHK(key != NULL);
+   mp_clear_multi(&key->g, &key->q, &key->p, &key->x, &key->y, NULL);
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_free.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/dsa/dsa_import.c b/src/pk/dsa/dsa_import.c
new file mode 100644
index 0000000..e81bac8
--- /dev/null
+++ b/src/pk/dsa/dsa_import.c
@@ -0,0 +1,89 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file dsa_import.c
+   DSA implementation, import a DSA key, Tom St Denis
+*/
+
+#ifdef MDSA
+
+/**
+   Import a DSA key 
+   @param in       The binary packet to import from
+   @param inlen    The length of the binary packet
+   @param key      [out] Where to store the imported key
+   @return CRYPT_OK if successful, upon error this function will free all allocated memory
+*/
+int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
+{
+   unsigned char flags[1];
+   int           err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(key != NULL);
+
+   /* init key */
+   if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != MP_OKAY) {
+      return CRYPT_MEM;
+   }
+
+   /* get key type */
+   if ((err = der_decode_sequence_multi(in, inlen,
+                                  LTC_ASN1_BIT_STRING, 1UL, flags,
+                                  LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
+      goto error;
+   }
+
+   if (flags[0] == 1) {
+      if ((err = der_decode_sequence_multi(in, inlen,
+                                 LTC_ASN1_BIT_STRING,   1UL, flags,
+                                 LTC_ASN1_INTEGER,      1UL, &key->g,
+                                 LTC_ASN1_INTEGER,      1UL, &key->p,
+                                 LTC_ASN1_INTEGER,      1UL, &key->q,
+                                 LTC_ASN1_INTEGER,      1UL, &key->y,
+                                 LTC_ASN1_INTEGER,      1UL, &key->x,
+                                 LTC_ASN1_EOL,          0UL, NULL)) != CRYPT_OK) {
+         goto error;
+      }
+      key->type = PK_PRIVATE;
+   } else {
+      if ((err = der_decode_sequence_multi(in, inlen,
+                                 LTC_ASN1_BIT_STRING,   1UL, flags,
+                                 LTC_ASN1_INTEGER,      1UL, &key->g,
+                                 LTC_ASN1_INTEGER,      1UL, &key->p,
+                                 LTC_ASN1_INTEGER,      1UL, &key->q,
+                                 LTC_ASN1_INTEGER,      1UL, &key->y,
+                                 LTC_ASN1_EOL,          0UL, NULL)) != CRYPT_OK) {
+         goto error;
+      }
+      key->type = PK_PUBLIC;
+  }
+  key->qord = mp_unsigned_bin_size(&key->q);
+
+  if (key->qord >= MDSA_MAX_GROUP || key->qord <= 15 ||
+      key->qord >= mp_unsigned_bin_size(&key->p) || (mp_unsigned_bin_size(&key->p) - key->qord) >= MDSA_DELTA) {
+      err = CRYPT_INVALID_PACKET;
+      goto error;
+   }
+
+  return CRYPT_OK;
+error: 
+   mp_clear_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL);
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_import.c,v $ */
+/* $Revision: 1.7 $ */
+/* $Date: 2005/06/08 23:31:17 $ */
diff --git a/dsa_make_key.c b/src/pk/dsa/dsa_make_key.c
similarity index 69%
rename from dsa_make_key.c
rename to src/pk/dsa/dsa_make_key.c
index 4d2af24..02f69e0 100644
--- a/dsa_make_key.c
+++ b/src/pk/dsa/dsa_make_key.c
@@ -6,19 +6,33 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+   @file dsa_make_key.c
+   DSA implementation, generate a DSA key, Tom St Denis
+*/
 
 #ifdef MDSA
 
+/**
+  Create a DSA key
+  @param prng          An active PRNG state
+  @param wprng         The index of the PRNG desired
+  @param group_size    Size of the multiplicative group (octets)
+  @param modulus_size  Size of the modulus (octets)
+  @param key           [out] Where to store the created key
+  @return CRYPT_OK if successful, upon error this function will free all allocated memory
+*/
 int dsa_make_key(prng_state *prng, int wprng, int group_size, int modulus_size, dsa_key *key)
 {
-   mp_int tmp, tmp2;
-   int err, res;
-   unsigned char buf[512];
+   mp_int         tmp, tmp2;
+   int            err, res;
+   unsigned char *buf;
 
-   _ARGCHK(key  != NULL);
+   LTC_ARGCHK(key  != NULL);
 
    /* check prng */
    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -26,41 +40,48 @@
    }
 
    /* check size */
-   if (group_size >= 1024 || group_size <= 15 || 
-       group_size >= modulus_size || (modulus_size - group_size) >= (int)sizeof(buf)) {
+   if (group_size >= MDSA_MAX_GROUP || group_size <= 15 || 
+       group_size >= modulus_size || (modulus_size - group_size) >= MDSA_DELTA) {
       return CRYPT_INVALID_ARG;
    }
 
+   /* allocate ram */
+   buf = XMALLOC(MDSA_DELTA);
+   if (buf == NULL) {
+      return CRYPT_MEM;
+   }
+
    /* init mp_ints  */
    if ((err = mp_init_multi(&tmp, &tmp2, &key->g, &key->q, &key->p, &key->x, &key->y, NULL)) != MP_OKAY) {
-      return mpi_to_ltc_error(err);
+      err = mpi_to_ltc_error(err);
+      goto LBL_ERR;
    }
 
    /* make our prime q */
-   if ((err = rand_prime(&key->q, group_size*8, prng, wprng)) != CRYPT_OK)             { goto error2; }
+   if ((err = rand_prime(&key->q, group_size*8, prng, wprng)) != CRYPT_OK)             { goto LBL_ERR; }
 
    /* double q  */
-   if ((err = mp_mul_2(&key->q, &tmp)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_mul_2(&key->q, &tmp)) != MP_OKAY)                                     { goto error; }
 
    /* now make a random string and multply it against q */
    if (prng_descriptor[wprng].read(buf+1, modulus_size - group_size, prng) != (unsigned long)(modulus_size - group_size)) {
       err = CRYPT_ERROR_READPRNG;
-      goto error2;
+      goto LBL_ERR;
    }
 
    /* force magnitude */
-   buf[0] = 1;
+   buf[0] |= 0xC0;
 
    /* force even */
-   buf[modulus_size - group_size] &= ~1;
+   buf[modulus_size - group_size - 1] &= ~1;
 
-   if ((err = mp_read_unsigned_bin(&tmp2, buf, modulus_size - group_size+1)) != MP_OKAY) { goto error; }
+   if ((err = mp_read_unsigned_bin(&tmp2, buf, modulus_size - group_size)) != MP_OKAY) { goto error; }
    if ((err = mp_mul(&key->q, &tmp2, &key->p)) != MP_OKAY)                             { goto error; }
    if ((err = mp_add_d(&key->p, 1, &key->p)) != MP_OKAY)                               { goto error; }
-   
+
    /* now loop until p is prime */
    for (;;) {
-       if ((err = is_prime(&key->p, &res)) != CRYPT_OK)                                { goto error2; }
+       if ((err = is_prime(&key->p, &res)) != CRYPT_OK)                                { goto LBL_ERR; }
        if (res == MP_YES) break;
 
        /* add 2q to p and 2 to tmp2 */
@@ -85,7 +106,7 @@
    do {
       if (prng_descriptor[wprng].read(buf, group_size, prng) != (unsigned long)group_size) {
          err = CRYPT_ERROR_READPRNG;
-         goto error2;
+         goto LBL_ERR;
       }
       if ((err = mp_read_unsigned_bin(&key->x, buf, group_size)) != MP_OKAY)           { goto error; }
    } while (mp_cmp_d(&key->x, 1) != MP_GT);
@@ -101,17 +122,25 @@
    if ((err = mp_shrink(&key->x)) != MP_OKAY)                                          { goto error; }
    if ((err = mp_shrink(&key->y)) != MP_OKAY)                                          { goto error; }
 
-   err = CRYPT_OK;
-
-#ifdef CLEAN_STACK
-   zeromem(buf, sizeof(buf));
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, MDSA_DELTA);
 #endif
 
+   err = CRYPT_OK;
    goto done;
-error : err = mpi_to_ltc_error(err);
-error2: mp_clear_multi(&key->g, &key->q, &key->p, &key->x, &key->y, NULL);
-done  : mp_clear_multi(&tmp, &tmp2, NULL);
-   return err;
+error: 
+    err = mpi_to_ltc_error(err);
+LBL_ERR: 
+    mp_clear_multi(&key->g, &key->q, &key->p, &key->x, &key->y, NULL);
+done: 
+    mp_clear_multi(&tmp, &tmp2, NULL);
+
+    XFREE(buf);
+    return err;
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_make_key.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/11 05:45:35 $ */
diff --git a/src/pk/dsa/dsa_sign_hash.c b/src/pk/dsa/dsa_sign_hash.c
new file mode 100644
index 0000000..48d29a2
--- /dev/null
+++ b/src/pk/dsa/dsa_sign_hash.c
@@ -0,0 +1,159 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file dsa_sign_hash.c
+   DSA implementation, sign a hash, Tom St Denis
+*/
+
+#ifdef MDSA
+
+/**
+  Sign a hash with DSA
+  @param in       The hash to sign
+  @param inlen    The length of the hash to sign
+  @param r        The "r" integer of the signature (caller must initialize with mp_init() first)
+  @param s        The "s" integer of the signature (caller must initialize with mp_init() first)
+  @param prng     An active PRNG state
+  @param wprng    The index of the PRNG desired
+  @param key      A private DSA key
+  @return CRYPT_OK if successful
+*/
+int dsa_sign_hash_raw(const unsigned char *in,  unsigned long inlen,
+                                   mp_int *r,   mp_int *s,
+                               prng_state *prng, int wprng, dsa_key *key)
+{
+   mp_int         k, kinv, tmp;
+   unsigned char *buf;
+   int            err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(r   != NULL);
+   LTC_ARGCHK(s   != NULL);
+   LTC_ARGCHK(key != NULL);
+
+   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
+      return err;
+   }
+   if (key->type != PK_PRIVATE) {
+      return CRYPT_PK_NOT_PRIVATE;
+   }
+
+   /* check group order size  */
+   if (key->qord >= MDSA_MAX_GROUP) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   buf = XMALLOC(MDSA_MAX_GROUP);
+   if (buf == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* Init our temps */
+   if ((err = mp_init_multi(&k, &kinv, &tmp, NULL)) != MP_OKAY)               { goto error; }
+
+retry:
+
+   do {
+      /* gen random k */
+      if (prng_descriptor[wprng].read(buf, key->qord, prng) != (unsigned long)key->qord) {
+         err = CRYPT_ERROR_READPRNG;
+         goto LBL_ERR;
+      }
+
+      /* read k */
+      if ((err = mp_read_unsigned_bin(&k, buf, key->qord)) != MP_OKAY)                { goto error; }
+
+      /* k > 1 ? */
+      if (mp_cmp_d(&k, 1) != MP_GT)                                                   { goto retry; }
+
+      /* test gcd */
+      if ((err = mp_gcd(&k, &key->q, &tmp)) != MP_OKAY)                               { goto error; }
+   } while (mp_cmp_d(&tmp, 1) != MP_EQ);
+
+   /* now find 1/k mod q */
+   if ((err = mp_invmod(&k, &key->q, &kinv)) != MP_OKAY)                              { goto error; }
+
+   /* now find r = g^k mod p mod q */
+   if ((err = mp_exptmod(&key->g, &k, &key->p, r)) != MP_OKAY)                        { goto error; }
+   if ((err = mp_mod(r, &key->q, r)) != MP_OKAY)                                      { goto error; }
+
+   if (mp_iszero(r) == MP_YES)                                                        { goto retry; }
+
+   /* now find s = (in + xr)/k mod q */
+   if ((err = mp_read_unsigned_bin(&tmp, (unsigned char *)in, inlen)) != MP_OKAY)     { goto error; }
+   if ((err = mp_mul(&key->x, r, s)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_add(s, &tmp, s)) != MP_OKAY)                                         { goto error; }
+   if ((err = mp_mulmod(s, &kinv, &key->q, s)) != MP_OKAY)                            { goto error; }
+
+   if (mp_iszero(s) == MP_YES)                                                        { goto retry; }
+
+   err = CRYPT_OK;
+   goto LBL_ERR;
+
+error: 
+   err = mpi_to_ltc_error(err);
+LBL_ERR: 
+   mp_clear_multi(&k, &kinv, &tmp, NULL);
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, MDSA_MAX_GROUP);
+#endif
+   XFREE(buf);
+   return err;
+}
+
+/**
+  Sign a hash with DSA
+  @param in       The hash to sign
+  @param inlen    The length of the hash to sign
+  @param out      [out] Where to store the signature
+  @param outlen   [in/out] The max size and resulting size of the signature
+  @param prng     An active PRNG state
+  @param wprng    The index of the PRNG desired
+  @param key      A private DSA key
+  @return CRYPT_OK if successful
+*/
+int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
+                        unsigned char *out, unsigned long *outlen,
+                        prng_state *prng, int wprng, dsa_key *key)
+{
+   mp_int        r, s;
+   int           err;
+
+   LTC_ARGCHK(in      != NULL);
+   LTC_ARGCHK(out     != NULL);
+   LTC_ARGCHK(outlen  != NULL);
+   LTC_ARGCHK(key     != NULL);
+
+   if (mp_init_multi(&r, &s, NULL) != MP_OKAY) {
+      return CRYPT_MEM;
+   }
+
+   if ((err = dsa_sign_hash_raw(in, inlen, &r, &s, prng, wprng, key)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   err = der_encode_sequence_multi(out, outlen, 
+                             LTC_ASN1_INTEGER, 1UL, &r, 
+                             LTC_ASN1_INTEGER, 1UL, &s, 
+                             LTC_ASN1_EOL,     0UL, NULL);
+
+LBL_ERR:
+   mp_clear_multi(&r, &s, NULL);
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_sign_hash.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/15 21:48:59 $ */
diff --git a/src/pk/dsa/dsa_verify_hash.c b/src/pk/dsa/dsa_verify_hash.c
new file mode 100644
index 0000000..11e5c33
--- /dev/null
+++ b/src/pk/dsa/dsa_verify_hash.c
@@ -0,0 +1,128 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file dsa_verify_hash.c
+   DSA implementation, verify a signature, Tom St Denis
+*/
+
+
+#ifdef MDSA
+
+/**
+  Verify a DSA signature
+  @param r        DSA "r" parameter
+  @param s        DSA "s" parameter
+  @param hash     The hash that was signed
+  @param hashlen  The length of the hash that was signed
+  @param stat     [out] The result of the signature verification, 1==valid, 0==invalid
+  @param key      The corresponding public DH key
+  @return CRYPT_OK if successful (even if the signature is invalid)
+*/
+int dsa_verify_hash_raw(         mp_int *r,          mp_int *s,
+                    const unsigned char *hash, unsigned long hashlen, 
+                                    int *stat,      dsa_key *key)
+{
+   mp_int        w, v, u1, u2;
+   int           err;
+
+   LTC_ARGCHK(r    != NULL);
+   LTC_ARGCHK(s    != NULL);
+   LTC_ARGCHK(stat != NULL);
+   LTC_ARGCHK(key  != NULL);
+
+   /* default to invalid signature */
+   *stat = 0;
+
+   /* init our variables */
+   if ((err = mp_init_multi(&w, &v, &u1, &u2, NULL)) != MP_OKAY) {
+      return mpi_to_ltc_error(err);
+   }
+
+   /* neither r or s can be null or >q*/
+   if (mp_iszero(r) == MP_YES || mp_iszero(s) == MP_YES || mp_cmp(r, &key->q) != MP_LT || mp_cmp(s, &key->q) != MP_LT) {
+      err = CRYPT_INVALID_PACKET;
+      goto done;
+   }
+   
+   /* w = 1/s mod q */
+   if ((err = mp_invmod(s, &key->q, &w)) != MP_OKAY)                                      { goto error; }
+
+   /* u1 = m * w mod q */
+   if ((err = mp_read_unsigned_bin(&u1, (unsigned char *)hash, hashlen)) != MP_OKAY)       { goto error; }
+   if ((err = mp_mulmod(&u1, &w, &key->q, &u1)) != MP_OKAY)                                { goto error; }
+
+   /* u2 = r*w mod q */
+   if ((err = mp_mulmod(r, &w, &key->q, &u2)) != MP_OKAY)                                 { goto error; } 
+
+   /* v = g^u1 * y^u2 mod p mod q */
+   if ((err = mp_exptmod(&key->g, &u1, &key->p, &u1)) != MP_OKAY)                          { goto error; }
+   if ((err = mp_exptmod(&key->y, &u2, &key->p, &u2)) != MP_OKAY)                          { goto error; }
+   if ((err = mp_mulmod(&u1, &u2, &key->p, &v)) != MP_OKAY)                                { goto error; }
+   if ((err = mp_mod(&v, &key->q, &v)) != MP_OKAY)                                         { goto error; }
+
+   /* if r = v then we're set */
+   if (mp_cmp(r, &v) == MP_EQ) {
+      *stat = 1;
+   }
+
+   err = CRYPT_OK;
+   goto done;
+
+error : err = mpi_to_ltc_error(err);
+done  : mp_clear_multi(&w, &v, &u1, &u2, NULL);
+   return err;
+}
+
+/**
+  Verify a DSA signature
+  @param sig      The signature
+  @param siglen   The length of the signature (octets)
+  @param hash     The hash that was signed
+  @param hashlen  The length of the hash that was signed
+  @param stat     [out] The result of the signature verification, 1==valid, 0==invalid
+  @param key      The corresponding public DH key
+  @return CRYPT_OK if successful (even if the signature is invalid)
+*/
+int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,
+                    const unsigned char *hash, unsigned long hashlen, 
+                    int *stat, dsa_key *key)
+{
+   int    err;
+   mp_int r, s;
+
+   if ((err = mp_init_multi(&r, &s, NULL)) != CRYPT_OK) {
+      return CRYPT_MEM;
+   }
+
+   /* decode the sequence */
+   if ((err = der_decode_sequence_multi(sig, siglen,
+                                  LTC_ASN1_INTEGER, 1UL, &r, 
+                                  LTC_ASN1_INTEGER, 1UL, &s, 
+                                  LTC_ASN1_EOL,     0UL, NULL)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* do the op */
+   err = dsa_verify_hash_raw(&r, &s, hash, hashlen, stat, key);
+
+LBL_ERR:
+   mp_clear_multi(&r, &s, NULL);
+   return err;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_verify_hash.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/15 21:48:59 $ */
diff --git a/dsa_verify_key.c b/src/pk/dsa/dsa_verify_key.c
similarity index 78%
rename from dsa_verify_key.c
rename to src/pk/dsa/dsa_verify_key.c
index c17bab8..b7be103 100644
--- a/dsa_verify_key.c
+++ b/src/pk/dsa/dsa_verify_key.c
@@ -6,20 +6,32 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+   @file dsa_verify_key.c
+   DSA implementation, verify a key, Tom St Denis
+*/
 
 #ifdef MDSA
 
+/**
+   Verify a DSA key for validity
+   @param key   The key to verify
+   @param stat  [out]  Result of test, 1==valid, 0==invalid
+   @return CRYPT_OK if successful
+*/
 int dsa_verify_key(dsa_key *key, int *stat)
 {
    mp_int tmp, tmp2;
-   int res, err;
+   int    res, err;
 
-   _ARGCHK(key  != NULL);
-   _ARGCHK(stat != NULL);
+   LTC_ARGCHK(key  != NULL);
+   LTC_ARGCHK(stat != NULL);
 
+   /* default to an invalid key */
    *stat = 0;
 
    /* first make sure key->q and key->p are prime */
@@ -84,3 +96,7 @@
    return err;
 }
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/dsa/dsa_verify_key.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/ecc/ecc.c b/src/pk/ecc/ecc.c
new file mode 100644
index 0000000..469d56d
--- /dev/null
+++ b/src/pk/ecc/ecc.c
@@ -0,0 +1,1036 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
+ *
+ * All curves taken from NIST recommendation paper of July 1999
+ * Available at http://csrc.nist.gov/cryptval/dss.htm
+ */
+#include "tomcrypt.h"
+
+/**
+  @file ecc.c
+  ECC Crypto, Tom St Denis
+*/  
+
+#ifdef MECC
+
+/* size of our temp buffers for exported keys */
+#define ECC_BUF_SIZE 256
+
+/* max private key size */
+#define ECC_MAXSIZE  66
+
+/* This holds the key settings.  ***MUST*** be organized by size from smallest to largest. */
+static const struct {
+   int size;
+   char *name, *prime, *B, *order, *Gx, *Gy;
+} sets[] = {
+#ifdef ECC192
+{
+    24,
+   "ECC-192",
+   /* prime */
+   "/////////////////////l//////////",
+
+   /* B */
+   "P2456UMSWESFf+chSYGmIVwutkp1Hhcn",
+
+   /* order */
+   "////////////////cTxuDXHhoR6qqYWn",
+
+   /* Gx */
+   "68se3h0maFPylo3hGw680FJ/2ls2/n0I",
+
+   /* Gy */
+   "1nahbV/8sdXZ417jQoJDrNFvTw4UUKWH"
+},
+#endif
+#ifdef ECC224
+{
+   28,
+   "ECC-224",
+
+   /* prime */
+   "3/////////////////////0000000000000001",
+
+   /* B */
+   "2q1Gg530Ipg/L1CbPGHB2trx/OkYSBEKCZLV+q",
+
+   /* order */
+   "3//////////////////nQYuBZmFXFTAKLSN2ez",
+
+   /* Gx */
+   "2t3WozQxI/Vp8JaBbA0y7JLi8H8ZGoWDOHN1qX",
+
+
+   /* Gy */
+   "2zDsE8jVSZ+qmYt+RDGtMWMWT7P4JLWPc507uq",
+},
+#endif
+#ifdef ECC256
+{
+   32,
+   "ECC-256",
+   /* Prime */
+   "F////y000010000000000000000////////////////",
+
+   /* B */
+   "5h6DTYgEfFdi+kzLNQOXhnb7GQmp5EmzZlEF3udqc1B",
+
+   /* Order */
+   "F////y00000//////////+yvlgjfnUUXFEvoiByOoLH",
+
+   /* Gx */
+   "6iNqVBXB497+BpcvMEaGF9t0ts1BUipeFIXEKNOcCAM",
+
+   /* Gy */
+   "4/ZGkB+6d+RZkVhIdmFdXOhpZDNQp5UpiksG6Wtlr7r"
+},
+#endif
+#ifdef ECC384
+{
+   48,
+   "ECC-384",
+   /* prime */
+   "//////////////////////////////////////////x/////00000000003/"
+   "////",
+
+   /* B */
+   "ip4lf+8+v+IOZWLhu/Wj6HWTd6x+WK4I0nG8Zr0JXrh6LZcDYYxHdIg5oEtJ"
+   "x2hl",
+
+   /* Order */
+   "////////////////////////////////nsDDWVGtBTzO6WsoIB2dUkpi6MhC"
+   "nIbp",
+
+   /* Gx and Gy */
+   "geVA8hwB1JUEiSSUyo2jT6uTEsABfvkOMVT1u89KAZXL0l9TlrKfR3fKNZXo"
+   "TWgt",
+
+   "DXVUIfOcB6zTdfY/afBSAVZq7RqecXHywTen4xNmkC0AOB7E7Nw1dNf37NoG"
+   "wWvV"
+},
+#endif
+#ifdef ECC521
+{
+   65,
+   "ECC-521",
+   /* prime */
+   "V///////////////////////////////////////////////////////////"
+   "///////////////////////////",
+
+   /* B */
+   "56LFhbXZXoQ7vAQ8Q2sXK3kejfoMvcp5VEuj8cHZl49uLOPEL7iVfDx5bB0l"
+   "JknlmSrSz+8FImqyUz57zHhK3y0",
+
+   /* Order */
+   "V//////////////////////////////////////////+b66XuE/BvPhVym1I"
+   "FS9fT0xjScuYPn7hhjljnwHE6G9",
+
+   /* Gx and Gy */
+   "CQ5ZWQt10JfpPu+osOZbRH2d6I1EGK/jI7uAAzWQqqzkg5BNdVlvrae/Xt19"
+   "wB/gDupIBF1XMf2c/b+VZ72vRrc",
+
+   "HWvAMfucZl015oANxGiVHlPcFL4ILURH6WNhxqN9pvcB9VkSfbUz2P0nL2v0"
+   "J+j1s4rF726edB2G8Y+b7QVqMPG",
+},
+#endif
+{
+   0,
+   NULL, NULL, NULL, NULL, NULL, NULL
+}
+};
+
+static int is_valid_idx(int n)
+{
+   int x;
+
+   for (x = 0; sets[x].size != 0; x++);
+   if ((n < 0) || (n >= x)) {
+      return 0;
+   }
+   return 1;
+}
+
+static ecc_point *new_point(void)
+{
+   ecc_point *p;
+   p = XMALLOC(sizeof(ecc_point));
+   if (p == NULL) {
+      return NULL;
+   }
+   if (mp_init_multi(&p->x, &p->y, &p->z, NULL) != MP_OKAY) {
+      XFREE(p);
+      return NULL;
+   }
+   return p;
+}
+
+static void del_point(ecc_point *p)
+{
+   /* prevents free'ing null arguments */
+   if (p != NULL) {
+      mp_clear_multi(&p->x, &p->y, &p->z, NULL);
+      XFREE(p);
+   }
+}
+
+static int ecc_map(ecc_point *P, mp_int *modulus, mp_digit mp)
+{
+   mp_int t1, t2;
+   int err;
+
+   if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) {
+      return CRYPT_MEM;
+   }
+
+   /* first map z back to normal */
+   if ((err = mp_montgomery_reduce(&P->z, modulus, mp)) != MP_OKAY)           { goto error; }
+
+   /* get 1/z */
+   if ((err = mp_invmod(&P->z, modulus, &t1)) != MP_OKAY)                     { goto error; }
+ 
+   /* get 1/z^2 and 1/z^3 */
+   if ((err = mp_sqr(&t1, &t2)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_mod(&t2, modulus, &t2)) != MP_OKAY)                          { goto error; }
+   if ((err = mp_mul(&t1, &t2, &t1)) != MP_OKAY)                              { goto error; }
+   if ((err = mp_mod(&t1, modulus, &t1)) != MP_OKAY)                          { goto error; }
+
+   /* multiply against x/y */
+   if ((err = mp_mul(&P->x, &t2, &P->x)) != MP_OKAY)                          { goto error; }
+   if ((err = mp_montgomery_reduce(&P->x, modulus, mp)) != MP_OKAY)           { goto error; }
+   if ((err = mp_mul(&P->y, &t1, &P->y)) != MP_OKAY)                          { goto error; }
+   if ((err = mp_montgomery_reduce(&P->y, modulus, mp)) != MP_OKAY)           { goto error; }
+   mp_set(&P->z, 1);
+
+   err = CRYPT_OK;
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   mp_clear_multi(&t1, &t2, NULL);
+   return err;
+
+}
+
+/* double a point R = 2P, R can be P*/
+static int dbl_point(ecc_point *P, ecc_point *R, mp_int *modulus, mp_digit mp)
+{
+   mp_int t1, t2;
+   int err;
+
+   if ((err = mp_init_multi(&t1, &t2, NULL)) != MP_OKAY) {
+      return mpi_to_ltc_error(err);
+   }
+
+   if ((err = mp_copy(&P->x, &R->x)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_copy(&P->y, &R->y)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_copy(&P->z, &R->z)) != MP_OKAY)                                   { goto error; }
+
+   /* t1 = Z * Z */
+   if ((err = mp_sqr(&R->z, &t1)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)                  { goto error; }
+   /* Z = Y * Z */
+   if ((err = mp_mul(&R->z, &R->y, &R->z)) != MP_OKAY)                             { goto error; }
+   if ((err = mp_montgomery_reduce(&R->z, modulus, mp)) != MP_OKAY)                { goto error; }
+   /* Z = 2Z */
+   if ((err = mp_mul_2(&R->z, &R->z)) != MP_OKAY)                                  { goto error; }
+   if (mp_cmp(&R->z, modulus) != MP_LT) {
+      if ((err = mp_sub(&R->z, modulus, &R->z)) != MP_OKAY)                        { goto error; }
+   }
+
+   /* T2 = X - T1 */
+   if ((err = mp_sub(&R->x, &t1, &t2)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp_d(&t2, 0) == MP_LT) {
+      if ((err = mp_add(&t2, modulus, &t2)) != MP_OKAY)                            { goto error; }
+   }
+   /* T1 = X + T1 */
+   if ((err = mp_add(&t1, &R->x, &t1)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp(&t1, modulus) != MP_LT) {
+      if ((err = mp_sub(&t1, modulus, &t1)) != MP_OKAY)                            { goto error; }
+   }
+   /* T2 = T1 * T2 */
+   if ((err = mp_mul(&t1, &t2, &t2)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_montgomery_reduce(&t2, modulus, mp)) != MP_OKAY)                  { goto error; }
+   /* T1 = 2T2 */
+   if ((err = mp_mul_2(&t2, &t1)) != MP_OKAY)                                      { goto error; }
+   if (mp_cmp(&t1, modulus) != MP_LT) {
+      if ((err = mp_sub(&t1, modulus, &t1)) != MP_OKAY)                            { goto error; }
+   }
+   /* T1 = T1 + T2 */
+   if ((err = mp_add(&t1, &t2, &t1)) != MP_OKAY)                                   { goto error; }
+   if (mp_cmp(&t1, modulus) != MP_LT) {
+      if ((err = mp_sub(&t1, modulus, &t1)) != MP_OKAY)                            { goto error; }
+   }
+
+   /* Y = 2Y */
+   if ((err = mp_mul_2(&R->y, &R->y)) != MP_OKAY)                                  { goto error; }
+   if (mp_cmp(&R->y, modulus) != MP_LT) {
+      if ((err = mp_sub(&R->y, modulus, &R->y)) != MP_OKAY)                        { goto error; }
+   }
+   /* Y = Y * Y */
+   if ((err = mp_sqr(&R->y, &R->y)) != MP_OKAY)                                    { goto error; }
+   if ((err = mp_montgomery_reduce(&R->y, modulus, mp)) != MP_OKAY)                { goto error; }
+   /* T2 = Y * Y */
+   if ((err = mp_sqr(&R->y, &t2)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_montgomery_reduce(&t2, modulus, mp)) != MP_OKAY)                  { goto error; }
+   /* T2 = T2/2 */
+   if (mp_isodd(&t2)) {
+      if ((err = mp_add(&t2, modulus, &t2)) != MP_OKAY)                            { goto error; }
+   }
+   if ((err = mp_div_2(&t2, &t2)) != MP_OKAY)                                      { goto error; }
+   /* Y = Y * X */
+   if ((err = mp_mul(&R->y, &R->x, &R->y)) != MP_OKAY)                             { goto error; }
+   if ((err = mp_montgomery_reduce(&R->y, modulus, mp)) != MP_OKAY)                { goto error; }
+
+   /* X  = T1 * T1 */
+   if ((err = mp_sqr(&t1, &R->x)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_montgomery_reduce(&R->x, modulus, mp)) != MP_OKAY)                { goto error; }
+   /* X = X - Y */
+   if ((err = mp_sub(&R->x, &R->y, &R->x)) != MP_OKAY)                             { goto error; }
+   if (mp_cmp_d(&R->x, 0) == MP_LT) {
+      if ((err = mp_add(&R->x, modulus, &R->x)) != MP_OKAY)                        { goto error; }
+   }
+   /* X = X - Y */
+   if ((err = mp_sub(&R->x, &R->y, &R->x)) != MP_OKAY)                             { goto error; }
+   if (mp_cmp_d(&R->x, 0) == MP_LT) {
+      if ((err = mp_add(&R->x, modulus, &R->x)) != MP_OKAY)                        { goto error; }
+   }
+
+   /* Y = Y - X */     
+   if ((err = mp_sub(&R->y, &R->x, &R->y)) != MP_OKAY)                             { goto error; }
+   if (mp_cmp_d(&R->y, 0) == MP_LT) {
+      if ((err = mp_add(&R->y, modulus, &R->y)) != MP_OKAY)                        { goto error; }
+   }
+   /* Y = Y * T1 */
+   if ((err = mp_mul(&R->y, &t1, &R->y)) != MP_OKAY)                               { goto error; }
+   if ((err = mp_montgomery_reduce(&R->y, modulus, mp)) != MP_OKAY)                { goto error; }
+   /* Y = Y - T2 */
+   if ((err = mp_sub(&R->y, &t2, &R->y)) != MP_OKAY)                               { goto error; }
+   if (mp_cmp_d(&R->y, 0) == MP_LT) {
+      if ((err = mp_add(&R->y, modulus, &R->y)) != MP_OKAY)                        { goto error; }
+   }
+ 
+   err = CRYPT_OK;
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   mp_clear_multi(&t1, &t2, NULL);
+   return err;
+}
+
+/* add two different points over Z/pZ, R = P + Q, note R can equal either P or Q */
+static int add_point(ecc_point *P, ecc_point *Q, ecc_point *R, mp_int *modulus, mp_digit mp)
+{
+   mp_int t1, t2, x, y, z;
+   int err;
+
+   if ((err = mp_init_multi(&t1, &t2, &x, &y, &z, NULL)) != MP_OKAY) {
+      return mpi_to_ltc_error(err);
+   }
+
+   if ((err = mp_copy(&P->x, &x)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_copy(&P->y, &y)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_copy(&P->z, &z)) != MP_OKAY)                                   { goto error; }
+
+      /* T1 = Z' * Z' */
+      if ((err = mp_sqr(&Q->z, &t1)) != MP_OKAY)                                { goto error; }
+      if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)            { goto error; }
+      /* X = X * T1 */
+      if ((err = mp_mul(&t1, &x, &x)) != MP_OKAY)                               { goto error; }
+      if ((err = mp_montgomery_reduce(&x, modulus, mp)) != MP_OKAY)             { goto error; }
+      /* T1 = Z' * T1 */
+      if ((err = mp_mul(&Q->z, &t1, &t1)) != MP_OKAY)                           { goto error; }
+      if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)            { goto error; }
+      /* Y = Y * T1 */
+      if ((err = mp_mul(&t1, &y, &y)) != MP_OKAY)                               { goto error; }
+      if ((err = mp_montgomery_reduce(&y, modulus, mp)) != MP_OKAY)             { goto error; }
+
+   /* T1 = Z*Z */
+   if ((err = mp_sqr(&z, &t1)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)               { goto error; }
+   /* T2 = X' * T1 */
+   if ((err = mp_mul(&Q->x, &t1, &t2)) != MP_OKAY)                              { goto error; }
+   if ((err = mp_montgomery_reduce(&t2, modulus, mp)) != MP_OKAY)               { goto error; }
+   /* T1 = Z * T1 */
+   if ((err = mp_mul(&z, &t1, &t1)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)               { goto error; }
+   /* T1 = Y' * T1 */
+   if ((err = mp_mul(&Q->y, &t1, &t1)) != MP_OKAY)                              { goto error; }
+   if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)               { goto error; }
+
+   /* Y = Y - T1 */
+   if ((err = mp_sub(&y, &t1, &y)) != MP_OKAY)                                  { goto error; }
+   if (mp_cmp_d(&y, 0) == MP_LT) {
+      if ((err = mp_add(&y, modulus, &y)) != MP_OKAY)                           { goto error; }
+   }
+   /* T1 = 2T1 */
+   if ((err = mp_mul_2(&t1, &t1)) != MP_OKAY)                                   { goto error; }
+   if (mp_cmp(&t1, modulus) != MP_LT) {
+      if ((err = mp_sub(&t1, modulus, &t1)) != MP_OKAY)                         { goto error; }
+   }
+   /* T1 = Y + T1 */
+   if ((err = mp_add(&t1, &y, &t1)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp(&t1, modulus) != MP_LT) {
+      if ((err = mp_sub(&t1, modulus, &t1)) != MP_OKAY)                         { goto error; }
+   }
+   /* X = X - T2 */
+   if ((err = mp_sub(&x, &t2, &x)) != MP_OKAY)                                  { goto error; }
+   if (mp_cmp_d(&x, 0) == MP_LT) {
+      if ((err = mp_add(&x, modulus, &x)) != MP_OKAY)                           { goto error; }
+   }
+   /* T2 = 2T2 */
+   if ((err = mp_mul_2(&t2, &t2)) != MP_OKAY)                                   { goto error; }
+   if (mp_cmp(&t2, modulus) != MP_LT) {
+      if ((err = mp_sub(&t2, modulus, &t2)) != MP_OKAY)                         { goto error; }
+   }
+   /* T2 = X + T2 */
+   if ((err = mp_add(&t2, &x, &t2)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp(&t2, modulus) != MP_LT) {
+      if ((err = mp_sub(&t2, modulus, &t2)) != MP_OKAY)                         { goto error; }
+   }
+
+   /* if Z' != 1 */
+   if (mp_cmp_d(&Q->z, 1) != MP_EQ) {
+      /* Z = Z * Z' */
+      if ((err = mp_mul(&z, &Q->z, &z)) != MP_OKAY)                             { goto error; }
+      if ((err = mp_montgomery_reduce(&z, modulus, mp)) != MP_OKAY)             { goto error; }
+   }
+   /* Z = Z * X */
+   if ((err = mp_mul(&z, &x, &z)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_montgomery_reduce(&z, modulus, mp)) != MP_OKAY)                { goto error; }
+
+   /* T1 = T1 * X  */
+   if ((err = mp_mul(&t1, &x, &t1)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)               { goto error; }
+   /* X = X * X */
+   if ((err = mp_sqr(&x, &x)) != MP_OKAY)                                       { goto error; }
+   if ((err = mp_montgomery_reduce(&x, modulus, mp)) != MP_OKAY)                { goto error; }
+   /* T2 = T2 * x */
+   if ((err = mp_mul(&t2, &x, &t2)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_montgomery_reduce(&t2, modulus, mp)) != MP_OKAY)               { goto error; }
+   /* T1 = T1 * X  */
+   if ((err = mp_mul(&t1, &x, &t1)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_montgomery_reduce(&t1, modulus, mp)) != MP_OKAY)               { goto error; }
+ 
+   /* X = Y*Y */
+   if ((err = mp_sqr(&y, &x)) != MP_OKAY)                                       { goto error; }
+   if ((err = mp_montgomery_reduce(&x, modulus, mp)) != MP_OKAY)                { goto error; }
+   /* X = X - T2 */
+   if ((err = mp_sub(&x, &t2, &x)) != MP_OKAY)                                  { goto error; }
+   if (mp_cmp_d(&x, 0) == MP_LT) {
+      if ((err = mp_add(&x, modulus, &x)) != MP_OKAY)                           { goto error; }
+   }
+
+   /* T2 = T2 - X */
+   if ((err = mp_sub(&t2, &x, &t2)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp_d(&t2, 0) == MP_LT) {
+      if ((err = mp_add(&t2, modulus, &t2)) != MP_OKAY)                         { goto error; }
+   } 
+   /* T2 = T2 - X */
+   if ((err = mp_sub(&t2, &x, &t2)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp_d(&t2, 0) == MP_LT) {
+      if ((err = mp_add(&t2, modulus, &t2)) != MP_OKAY)                         { goto error; }
+   }
+   /* T2 = T2 * Y */
+   if ((err = mp_mul(&t2, &y, &t2)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_montgomery_reduce(&t2, modulus, mp)) != MP_OKAY)               { goto error; }
+   /* Y = T2 - T1 */
+   if ((err = mp_sub(&t2, &t1, &y)) != MP_OKAY)                                 { goto error; }
+   if (mp_cmp_d(&y, 0) == MP_LT) {
+      if ((err = mp_add(&y, modulus, &y)) != MP_OKAY)                           { goto error; }
+   }
+   /* Y = Y/2 */
+   if (mp_isodd(&y)) {
+      if ((err = mp_add(&y, modulus, &y)) != MP_OKAY)                           { goto error; }
+   }
+   if ((err = mp_div_2(&y, &y)) != MP_OKAY)                                     { goto error; }
+
+   if ((err = mp_copy(&x, &R->x)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_copy(&y, &R->y)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_copy(&z, &R->z)) != MP_OKAY)                                   { goto error; }
+
+   err = CRYPT_OK;
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   mp_clear_multi(&t1, &t2, &x, &y, &z, NULL);
+   return err;
+}
+
+/* size of sliding window, don't change this! */
+#define WINSIZE 4
+
+/* perform R = kG where k == integer and G == ecc_point */
+static int ecc_mulmod(mp_int *k, ecc_point *G, ecc_point *R, mp_int *modulus, int map)
+{
+   ecc_point *tG, *M[8];
+   int        i, j, err;
+   mp_int     mu;
+   mp_digit   buf, mp;
+   int        first, bitbuf, bitcpy, bitcnt, mode, digidx;
+
+   /* init montgomery reduction */
+   if ((err = mp_montgomery_setup(modulus, &mp)) != MP_OKAY) {
+      return CRYPT_INVALID_ARG;
+   }
+   if ((err = mp_init(&mu)) != MP_OKAY) {
+      return CRYPT_MEM;
+   }
+   if ((err = mp_montgomery_calc_normalization(&mu, modulus)) != MP_OKAY) {
+      mp_clear(&mu);
+      return CRYPT_INVALID_ARG;
+   }
+
+  /* alloc ram for window temps */
+  for (i = 0; i < 8; i++) {
+      M[i] = new_point();
+      if (M[i] == NULL) {
+         for (j = 0; j < i; j++) {
+             del_point(M[j]);
+         }
+         mp_clear(&mu);
+         return CRYPT_MEM;
+      }
+  }
+
+   /* make a copy of G incase R==G */
+   tG = new_point();
+   if (tG == NULL)                                                            { err = CRYPT_MEM; goto done; }
+
+   /* tG = G  and convert to montgomery */
+   if ((err = mp_mulmod(&G->x, &mu, modulus, &tG->x)) != MP_OKAY)             { goto error; }
+   if ((err = mp_mulmod(&G->y, &mu, modulus, &tG->y)) != MP_OKAY)             { goto error; }
+   if ((err = mp_mulmod(&G->z, &mu, modulus, &tG->z)) != MP_OKAY)             { goto error; }
+   mp_clear(&mu);
+   
+   /* calc the M tab, which holds kG for k==8..15 */
+   /* M[0] == 8G */
+   if ((err = dbl_point(tG,   M[0], modulus, mp)) != CRYPT_OK)               { goto done; }
+   if ((err = dbl_point(M[0], M[0], modulus, mp)) != CRYPT_OK)               { goto done; }
+   if ((err = dbl_point(M[0], M[0], modulus, mp)) != CRYPT_OK)               { goto done; }
+
+   /* now find (8+k)G for k=1..7 */
+   for (j = 9; j < 16; j++) {
+       if ((err = add_point(M[j-9], tG, M[j-8], modulus, mp)) != CRYPT_OK)   { goto done; }
+   }
+
+   /* setup sliding window */
+   mode   = 0;
+   bitcnt = 1;
+   buf    = 0;
+   digidx = k->used - 1;
+   bitcpy = bitbuf = 0;
+   first  = 1;
+
+   /* perform ops */
+   for (;;) {
+     /* grab next digit as required */
+     if (--bitcnt == 0) {
+       if (digidx == -1) {
+          break;
+       }
+       buf = k->dp[digidx--];
+       bitcnt = (int) DIGIT_BIT;
+     }
+
+     /* grab the next msb from the ltiplicand */
+     i = (buf >> (DIGIT_BIT - 1)) & 1;
+     buf <<= 1;
+
+     /* skip leading zero bits */
+     if (mode == 0 && i == 0) {
+        continue;
+     }
+
+     /* if the bit is zero and mode == 1 then we double */
+     if (mode == 1 && i == 0) {
+        if ((err = dbl_point(R, R, modulus, mp)) != CRYPT_OK)                { goto done; }
+        continue;
+     }
+
+     /* else we add it to the window */
+     bitbuf |= (i << (WINSIZE - ++bitcpy));
+     mode = 2;
+
+     if (bitcpy == WINSIZE) {
+       /* if this is the first window we do a simple copy */
+       if (first == 1) {
+          /* R = kG [k = first window] */
+          if ((err = mp_copy(&M[bitbuf-8]->x, &R->x)) != MP_OKAY)             { goto error; }
+          if ((err = mp_copy(&M[bitbuf-8]->y, &R->y)) != MP_OKAY)             { goto error; }
+          if ((err = mp_copy(&M[bitbuf-8]->z, &R->z)) != MP_OKAY)             { goto error; }
+          first = 0;
+       } else {
+         /* normal window */
+         /* ok window is filled so double as required and add  */
+         /* double first */
+         for (j = 0; j < WINSIZE; j++) {
+           if ((err = dbl_point(R, R, modulus, mp)) != CRYPT_OK)             { goto done; }
+         }
+
+         /* then add, bitbuf will be 8..15 [8..2^WINSIZE] guaranteed */
+         if ((err = add_point(R, M[bitbuf-8], R, modulus, mp)) != CRYPT_OK)  { goto done; }
+       }
+       /* empty window and reset */
+       bitcpy = bitbuf = 0;
+       mode = 1;
+    }
+  }
+
+   /* if bits remain then double/add */
+   if (mode == 2 && bitcpy > 0) {
+     /* double then add */
+     for (j = 0; j < bitcpy; j++) {
+       /* only double if we have had at least one add first */
+       if (first == 0) {
+          if ((err = dbl_point(R, R, modulus, mp)) != CRYPT_OK)               { goto done; }
+       }
+
+       bitbuf <<= 1;
+       if ((bitbuf & (1 << WINSIZE)) != 0) {
+         if (first == 1){
+            /* first add, so copy */
+            if ((err = mp_copy(&tG->x, &R->x)) != MP_OKAY)                     { goto error; }
+            if ((err = mp_copy(&tG->y, &R->y)) != MP_OKAY)                     { goto error; }
+            if ((err = mp_copy(&tG->z, &R->z)) != MP_OKAY)                     { goto error; }
+            first = 0;
+         } else {
+            /* then add */
+            if ((err = add_point(R, tG, R, modulus, mp)) != CRYPT_OK)         { goto done; }
+         }
+       }
+     }
+   }
+
+   /* map R back from projective space */
+   if (map) {
+      err = ecc_map(R, modulus, mp);
+   } else {
+      err = CRYPT_OK;
+   }
+
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   del_point(tG);
+   for (i = 0; i < 8; i++) {
+       del_point(M[i]);
+   }
+   return err;
+}
+
+#undef WINSIZE
+
+/**
+  Perform on the ECC system
+  @return CRYPT_OK if successful
+*/
+int ecc_test(void)
+{
+   mp_int     modulus, order;
+   ecc_point  *G, *GG;
+   int i, err, primality;
+
+   if ((err = mp_init_multi(&modulus, &order, NULL)) != MP_OKAY) {
+      return mpi_to_ltc_error(err);
+   }
+
+   G   = new_point();
+   GG  = new_point();
+   if (G == NULL || GG == NULL) {
+      mp_clear_multi(&modulus, &order, NULL);
+      del_point(G);
+      del_point(GG);
+      return CRYPT_MEM;
+   }
+
+   for (i = 0; sets[i].size; i++) {
+       #if 0
+          printf("Testing %d\n", sets[i].size);
+       #endif
+       if ((err = mp_read_radix(&modulus, (char *)sets[i].prime, 64)) != MP_OKAY)   { goto error; }
+       if ((err = mp_read_radix(&order, (char *)sets[i].order, 64)) != MP_OKAY)     { goto error; }
+
+       /* is prime actually prime? */
+       if ((err = is_prime(&modulus, &primality)) != CRYPT_OK)                      { goto done; }
+       if (primality == 0) {
+          err = CRYPT_FAIL_TESTVECTOR;
+          goto done;
+       }
+
+       /* is order prime ? */
+       if ((err = is_prime(&order, &primality)) != CRYPT_OK)                        { goto done; }
+       if (primality == 0) {
+          err = CRYPT_FAIL_TESTVECTOR;
+          goto done;
+       }
+
+       if ((err = mp_read_radix(&G->x, (char *)sets[i].Gx, 64)) != MP_OKAY)         { goto error; }
+       if ((err = mp_read_radix(&G->y, (char *)sets[i].Gy, 64)) != MP_OKAY)         { goto error; }
+       mp_set(&G->z, 1);
+
+       /* then we should have G == (order + 1)G */
+       if ((err = mp_add_d(&order, 1, &order)) != MP_OKAY)                          { goto error; }
+       if ((err = ecc_mulmod(&order, G, GG, &modulus, 1)) != CRYPT_OK)              { goto done; }
+       if (mp_cmp(&G->x, &GG->x) != 0 || mp_cmp(&G->y, &GG->y) != 0) {
+          err = CRYPT_FAIL_TESTVECTOR;
+          goto done;
+       }
+   }
+   err = CRYPT_OK;
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   del_point(GG);
+   del_point(G);
+   mp_clear_multi(&order, &modulus, NULL);
+   return err;
+}
+
+void ecc_sizes(int *low, int *high)
+{
+ int i;
+ LTC_ARGCHK(low  != NULL);
+ LTC_ARGCHK(high != NULL);
+
+ *low = INT_MAX;
+ *high = 0;
+ for (i = 0; sets[i].size != 0; i++) {
+     if (sets[i].size < *low)  {
+        *low  = sets[i].size;
+     }
+     if (sets[i].size > *high) {
+        *high = sets[i].size;
+     }
+ }
+}
+
+/**
+  Make a new ECC key 
+  @param prng         An active PRNG state
+  @param wprng        The index of the PRNG you wish to use
+  @param keysize      The keysize for the new key (in octets from 20 to 65 bytes)
+  @param key          [out] Destination of the newly created key
+  @return CRYPT_OK if successful, upon error all allocated memory will be freed
+*/
+int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key)
+{
+   int            x, err;
+   ecc_point     *base;
+   mp_int         prime;
+   unsigned char *buf;
+
+   LTC_ARGCHK(key != NULL);
+
+   /* good prng? */
+   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* find key size */
+   for (x = 0; (keysize > sets[x].size) && (sets[x].size != 0); x++);
+   keysize = sets[x].size;
+
+   if (keysize > ECC_MAXSIZE || sets[x].size == 0) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+   key->idx = x;
+
+   /* allocate ram */
+   base = NULL;
+   buf  = XMALLOC(ECC_MAXSIZE);
+   if (buf == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* make up random string */
+   if (prng_descriptor[wprng].read(buf, (unsigned long)keysize, prng) != (unsigned long)keysize) {
+      err = CRYPT_ERROR_READPRNG;
+      goto LBL_ERR2;
+   }
+
+   /* setup the key variables */
+   if ((err = mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, &prime, NULL)) != MP_OKAY) {
+      err = mpi_to_ltc_error(err);
+      goto LBL_ERR;
+   }
+   base = new_point();
+   if (base == NULL) {
+      mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, &prime, NULL);
+      err = CRYPT_MEM;
+      goto LBL_ERR;
+   }
+
+   /* read in the specs for this key */
+   if ((err = mp_read_radix(&prime, (char *)sets[key->idx].prime, 64)) != MP_OKAY)      { goto error; }
+   if ((err = mp_read_radix(&base->x, (char *)sets[key->idx].Gx, 64)) != MP_OKAY)       { goto error; }
+   if ((err = mp_read_radix(&base->y, (char *)sets[key->idx].Gy, 64)) != MP_OKAY)       { goto error; }
+   mp_set(&base->z, 1);
+   if ((err = mp_read_unsigned_bin(&key->k, (unsigned char *)buf, keysize)) != MP_OKAY) { goto error; }
+
+   /* make the public key */
+   if ((err = ecc_mulmod(&key->k, base, &key->pubkey, &prime, 1)) != CRYPT_OK)          { goto LBL_ERR; }
+   key->type = PK_PRIVATE;
+
+   /* shrink key */
+   if ((err = mp_shrink(&key->k)) != MP_OKAY)                                           { goto error; }
+   if ((err = mp_shrink(&key->pubkey.x)) != MP_OKAY)                                    { goto error; }
+   if ((err = mp_shrink(&key->pubkey.y)) != MP_OKAY)                                    { goto error; }
+   if ((err = mp_shrink(&key->pubkey.z)) != MP_OKAY)                                    { goto error; }
+
+   /* free up ram */
+   err = CRYPT_OK;
+   goto LBL_ERR;
+error:
+   err = mpi_to_ltc_error(err);
+LBL_ERR:
+   del_point(base);
+   mp_clear(&prime);
+LBL_ERR2:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, ECC_MAXSIZE);
+#endif
+
+   XFREE(buf);
+
+   return err;
+}
+
+/**
+  Free an ECC key from memory
+  @param key   The key you wish to free
+*/
+void ecc_free(ecc_key *key)
+{
+   LTC_ARGCHK(key != NULL);
+   mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL);
+}
+
+/**
+  Export an ECC key as a binary packet
+  @param out     [out] Destination for the key
+  @param outlen  [in/out] Max size and resulting size of the exported key
+  @param type    The type of key you want to export (PK_PRIVATE or PK_PUBLIC)
+  @param key     The key to export
+  @return CRYPT_OK if successful
+*/
+int ecc_export(unsigned char *out, unsigned long *outlen, int type, ecc_key *key)
+{
+   int           err;
+   unsigned char flags[1];
+   unsigned long key_size;
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
+   
+   /* type valid? */
+   if (key->type != PK_PRIVATE && type == PK_PRIVATE) {
+      return CRYPT_PK_TYPE_MISMATCH;
+   }
+
+   if (is_valid_idx(key->idx) == 0) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* we store the NIST byte size */
+   key_size = sets[key->idx].size;
+
+   if (type == PK_PRIVATE) {
+       flags[0] = 1;
+       err = der_encode_sequence_multi(out, outlen,
+                                 LTC_ASN1_BIT_STRING,      1UL, flags,
+                                 LTC_ASN1_SHORT_INTEGER,   1UL, &key_size,
+                                 LTC_ASN1_INTEGER,         1UL, &key->pubkey.x,
+                                 LTC_ASN1_INTEGER,         1UL, &key->pubkey.y,
+                                 LTC_ASN1_INTEGER,         1UL, &key->k,
+                                 LTC_ASN1_EOL,             0UL, NULL);
+   } else {
+       flags[0] = 0;
+       err = der_encode_sequence_multi(out, outlen,
+                                 LTC_ASN1_BIT_STRING,      1UL, flags,
+                                 LTC_ASN1_SHORT_INTEGER,   1UL, &key_size,
+                                 LTC_ASN1_INTEGER,         1UL, &key->pubkey.x,
+                                 LTC_ASN1_INTEGER,         1UL, &key->pubkey.y,
+                                 LTC_ASN1_EOL,             0UL, NULL);
+   }
+
+   return err;
+}
+
+/**
+  Import an ECC key from a binary packet
+  @param in      The packet to import
+  @param inlen   The length of the packet
+  @param key     [out] The destination of the import
+  @return CRYPT_OK if successful, upon error all allocated memory will be freed
+*/
+int ecc_import(const unsigned char *in, unsigned long inlen, ecc_key *key)
+{
+   unsigned long key_size;
+   unsigned char flags[1];
+   int           err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(key != NULL);
+
+   /* init key */
+   if (mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL) != MP_OKAY) {
+      return CRYPT_MEM;
+   }
+
+   /* find out what type of key it is */
+   if ((err = der_decode_sequence_multi(in, inlen, 
+                                  LTC_ASN1_BIT_STRING, 1UL, &flags,
+                                  LTC_ASN1_EOL,        0UL, NULL)) != CRYPT_OK) {
+      goto error;
+   }
+
+
+   if (flags[0] == 1) {
+      /* private key */
+      key->type = PK_PRIVATE;
+      if ((err = der_decode_sequence_multi(in, inlen,
+                                     LTC_ASN1_BIT_STRING,      1UL, flags,
+                                     LTC_ASN1_SHORT_INTEGER,   1UL, &key_size,
+                                     LTC_ASN1_INTEGER,         1UL, &key->pubkey.x,
+                                     LTC_ASN1_INTEGER,         1UL, &key->pubkey.y,
+                                     LTC_ASN1_INTEGER,         1UL, &key->k,
+                                     LTC_ASN1_EOL,             0UL, NULL)) != CRYPT_OK) {
+         goto error;
+      }
+   } else {
+      /* public key */
+      /* private key */
+      key->type = PK_PUBLIC;
+      if ((err = der_decode_sequence_multi(in, inlen,
+                                     LTC_ASN1_BIT_STRING,      1UL, flags,
+                                     LTC_ASN1_SHORT_INTEGER,   1UL, &key_size,
+                                     LTC_ASN1_INTEGER,         1UL, &key->pubkey.x,
+                                     LTC_ASN1_INTEGER,         1UL, &key->pubkey.y,
+                                     LTC_ASN1_EOL,             0UL, NULL)) != CRYPT_OK) {
+         goto error;
+      }
+   }
+
+   /* find the idx */
+   for (key->idx = 0; sets[key->idx].size && (unsigned long)sets[key->idx].size != key_size; ++key->idx);
+   if (sets[key->idx].size == 0) {
+      err = CRYPT_INVALID_PACKET;
+      goto error;
+   }
+
+   /* set z */
+   mp_set(&key->pubkey.z, 1);
+
+   /* we're good */
+   return CRYPT_OK;
+error:
+   mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, NULL);
+   return err;
+}
+
+/**
+  Create an ECC shared secret between two keys
+  @param private_key      The private ECC key
+  @param public_key       The public key
+  @param out              [out] Destination of the shared secret (Conforms to EC-DH from ANSI X9.63)
+  @param outlen           [in/out] The max size and resulting size of the shared secret
+  @return CRYPT_OK if successful
+*/
+int ecc_shared_secret(ecc_key *private_key, ecc_key *public_key,
+                      unsigned char *out, unsigned long *outlen)
+{
+   unsigned long x;
+   ecc_point *result;
+   mp_int prime;
+   int err;
+
+   LTC_ARGCHK(private_key != NULL);
+   LTC_ARGCHK(public_key  != NULL);
+   LTC_ARGCHK(out         != NULL);
+   LTC_ARGCHK(outlen      != NULL);
+
+   /* type valid? */
+   if (private_key->type != PK_PRIVATE) {
+      return CRYPT_PK_NOT_PRIVATE;
+   }
+
+   if (is_valid_idx(private_key->idx) == 0) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if (private_key->idx != public_key->idx) {
+      return CRYPT_PK_TYPE_MISMATCH;
+   }
+
+   /* make new point */
+   result = new_point();
+   if (result == NULL) {
+      return CRYPT_MEM;
+   }
+
+   if ((err = mp_init(&prime)) != MP_OKAY) {
+      del_point(result);
+      return mpi_to_ltc_error(err);
+   }
+
+   if ((err = mp_read_radix(&prime, (char *)sets[private_key->idx].prime, 64)) != MP_OKAY)            { goto error; }
+   if ((err = ecc_mulmod(&private_key->k, &public_key->pubkey, result, &prime, 1)) != CRYPT_OK)       { goto done1; }
+
+   x = (unsigned long)mp_unsigned_bin_size(&prime);
+   if (*outlen < x) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto done1;
+   }
+   zeromem(out, x);
+   if ((err = mp_to_unsigned_bin(&result->x, out + (x - mp_unsigned_bin_size(&result->x))))   != MP_OKAY)          { goto error; }
+
+   err     = CRYPT_OK;
+   *outlen = x;
+   goto done1;
+error:
+   err = mpi_to_ltc_error(err);
+done1:
+   mp_clear(&prime);
+   del_point(result);
+   return err;
+}
+
+/**
+  Get the size of an ECC key
+  @param key    The key to get the size of 
+  @return The size (octets) of the key or INT_MAX on error
+*/
+int ecc_get_size(ecc_key *key)
+{
+   LTC_ARGCHK(key != NULL);
+   if (is_valid_idx(key->idx))
+      return sets[key->idx].size;
+   else
+      return INT_MAX; /* large value known to cause it to fail when passed to ecc_make_key() */
+}
+
+#include "ecc_sys.c"
+
+#endif
+
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc.c,v $ */
+/* $Revision: 1.20 $ */
+/* $Date: 2005/06/14 20:42:28 $ */
diff --git a/src/pk/ecc/ecc_sys.c b/src/pk/ecc/ecc_sys.c
new file mode 100644
index 0000000..65ead31
--- /dev/null
+++ b/src/pk/ecc/ecc_sys.c
@@ -0,0 +1,462 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+
+/**
+  @file ecc_sys.c
+  ECC Crypto, Tom St Denis
+*/
+  
+/**
+  Encrypt a symmetric key with ECC 
+  @param in         The symmetric key you want to encrypt
+  @param inlen      The length of the key to encrypt (octets)
+  @param out        [out] The destination for the ciphertext
+  @param outlen     [in/out] The max size and resulting size of the ciphertext
+  @param prng       An active PRNG state
+  @param wprng      The index of the PRNG you wish to use 
+  @param hash       The index of the hash you want to use 
+  @param key        The ECC key you want to encrypt to
+  @return CRYPT_OK if successful
+*/
+int ecc_encrypt_key(const unsigned char *in,   unsigned long inlen,
+                          unsigned char *out,  unsigned long *outlen, 
+                          prng_state *prng, int wprng, int hash, 
+                          ecc_key *key)
+{
+    unsigned char *pub_expt, *ecc_shared, *skey;
+    ecc_key        pubkey;
+    unsigned long  x, y, pubkeysize;
+    int            err;
+
+    LTC_ARGCHK(in      != NULL);
+    LTC_ARGCHK(out     != NULL);
+    LTC_ARGCHK(outlen  != NULL);
+    LTC_ARGCHK(key     != NULL);
+
+    /* check that wprng/cipher/hash are not invalid */
+    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
+       return err;
+    }
+
+    if ((err = hash_is_valid(hash)) != CRYPT_OK) {
+       return err;
+    }
+
+    if (inlen > hash_descriptor[hash].hashsize) {
+       return CRYPT_INVALID_HASH;
+    }
+
+    /* make a random key and export the public copy */
+    if ((err = ecc_make_key(prng, wprng, ecc_get_size(key), &pubkey)) != CRYPT_OK) {
+       return err;
+    }
+
+    pub_expt   = XMALLOC(ECC_BUF_SIZE);
+    ecc_shared = XMALLOC(ECC_BUF_SIZE);
+    skey       = XMALLOC(MAXBLOCKSIZE);
+    if (pub_expt == NULL || ecc_shared == NULL || skey == NULL) {
+       if (pub_expt != NULL) {
+          XFREE(pub_expt);
+       }
+       if (ecc_shared != NULL) {
+          XFREE(ecc_shared);
+       }
+       if (skey != NULL) {
+          XFREE(skey);
+       }
+       ecc_free(&pubkey);
+       return CRYPT_MEM;
+    }
+
+    pubkeysize = ECC_BUF_SIZE;
+    if ((err = ecc_export(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
+       ecc_free(&pubkey);
+       goto LBL_ERR;
+    }
+    
+    /* make random key */
+    x        = ECC_BUF_SIZE;
+    if ((err = ecc_shared_secret(&pubkey, key, ecc_shared, &x)) != CRYPT_OK) {
+       ecc_free(&pubkey);
+       goto LBL_ERR;
+    }
+    ecc_free(&pubkey);
+    y = MAXBLOCKSIZE;
+    if ((err = hash_memory(hash, ecc_shared, x, skey, &y)) != CRYPT_OK) {
+       goto LBL_ERR;
+    }
+    
+    /* Encrypt key */
+    for (x = 0; x < inlen; x++) {
+      skey[x] ^= in[x];
+    }
+
+    err = der_encode_sequence_multi(out, outlen,
+                                    LTC_ASN1_OBJECT_IDENTIFIER,  hash_descriptor[hash].OIDlen,   hash_descriptor[hash].OID,
+                                    LTC_ASN1_OCTET_STRING,       pubkeysize,                     pub_expt,
+                                    LTC_ASN1_OCTET_STRING,       inlen,                          skey,
+                                    LTC_ASN1_EOL,                0UL,                            NULL);
+
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+    /* clean up */
+    zeromem(pub_expt,   ECC_BUF_SIZE);
+    zeromem(ecc_shared, ECC_BUF_SIZE);
+    zeromem(skey,       MAXBLOCKSIZE);
+#endif
+
+    XFREE(skey);
+    XFREE(ecc_shared);
+    XFREE(pub_expt);
+
+    return err;
+}
+
+/**
+  Decrypt an ECC encrypted key
+  @param in       The ciphertext
+  @param inlen    The length of the ciphertext (octets)
+  @param out      [out] The plaintext
+  @param outlen   [in/out] The max size and resulting size of the plaintext
+  @param key      The corresponding private ECC key
+  @return CRYPT_OK if successful
+*/
+int ecc_decrypt_key(const unsigned char *in,  unsigned long  inlen,
+                          unsigned char *out, unsigned long *outlen, 
+                          ecc_key *key)
+{
+   unsigned char *ecc_shared, *skey, *pub_expt;
+   unsigned long  x, y, hashOID[32];
+   int            hash, err;
+   ecc_key        pubkey;
+   ltc_asn1_list  decode[3];
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
+
+   /* right key type? */
+   if (key->type != PK_PRIVATE) {
+      return CRYPT_PK_NOT_PRIVATE;
+   }
+   
+   /* decode to find out hash */
+   LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, sizeof(hashOID)/sizeof(hashOID[0]));
+ 
+   if ((err = der_decode_sequence(in, inlen, decode, 1)) != CRYPT_OK) {
+      return err;
+   }
+   for (hash = 0; hash_descriptor[hash].name   != NULL             && 
+                  (hash_descriptor[hash].OIDlen != decode[0].size   || 
+                   memcmp(hash_descriptor[hash].OID, hashOID, sizeof(unsigned long)*decode[0].size)); hash++);
+
+   if (hash_descriptor[hash].name == NULL) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* we now have the hash! */
+
+   /* allocate memory */
+   pub_expt   = XMALLOC(ECC_BUF_SIZE);
+   ecc_shared = XMALLOC(ECC_BUF_SIZE);
+   skey       = XMALLOC(MAXBLOCKSIZE);
+   if (pub_expt == NULL || ecc_shared == NULL || skey == NULL) {
+      if (pub_expt != NULL) {
+         XFREE(pub_expt);
+      }
+      if (ecc_shared != NULL) {
+         XFREE(ecc_shared);
+      }
+      if (skey != NULL) {
+         XFREE(skey);
+      }
+      return CRYPT_MEM;
+   }
+   LTC_SET_ASN1(decode, 1, LTC_ASN1_OCTET_STRING,      pub_expt,  ECC_BUF_SIZE);
+   LTC_SET_ASN1(decode, 2, LTC_ASN1_OCTET_STRING,      skey,      MAXBLOCKSIZE);
+
+   /* read the structure in now */
+   if ((err = der_decode_sequence(in, inlen, decode, 3)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* import ECC key from packet */
+   if ((err = ecc_import(decode[1].data, decode[1].size, &pubkey)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* make shared key */
+   x = ECC_BUF_SIZE;
+   if ((err = ecc_shared_secret(key, &pubkey, ecc_shared, &x)) != CRYPT_OK) {
+      ecc_free(&pubkey);
+      goto LBL_ERR;
+   }
+   ecc_free(&pubkey);
+
+   y = MAXBLOCKSIZE;
+   if ((err = hash_memory(hash, ecc_shared, x, ecc_shared, &y)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* ensure the hash of the shared secret is at least as big as the encrypt itself */
+   if (decode[2].size > y) {
+      err = CRYPT_INVALID_PACKET;
+      goto LBL_ERR;
+   }
+
+   /* avoid buffer overflow */
+   if (*outlen < decode[2].size) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto LBL_ERR;
+   }
+
+   /* Decrypt the key */
+   for (x = 0; x < decode[2].size; x++) {
+     out[x] = skey[x] ^ ecc_shared[x];
+   }
+   *outlen = x;
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(pub_expt,   ECC_BUF_SIZE);
+   zeromem(ecc_shared, ECC_BUF_SIZE);
+   zeromem(skey,       MAXBLOCKSIZE);
+#endif
+
+   XFREE(pub_expt);
+   XFREE(ecc_shared);
+   XFREE(skey);
+
+   return err;
+}
+
+/**
+  Sign a message digest
+  @param in        The message digest to sign
+  @param inlen     The length of the digest
+  @param out       [out] The destination for the signature
+  @param outlen    [in/out] The max size and resulting size of the signature
+  @param prng      An active PRNG state
+  @param wprng     The index of the PRNG you wish to use
+  @param key       A private ECC key
+  @return CRYPT_OK if successful
+*/
+int ecc_sign_hash(const unsigned char *in,  unsigned long inlen, 
+                        unsigned char *out, unsigned long *outlen, 
+                        prng_state *prng, int wprng, ecc_key *key)
+{
+   ecc_key       pubkey;
+   mp_int        r, s, e, p;
+   int           err;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
+
+   /* is this a private key? */
+   if (key->type != PK_PRIVATE) {
+      return CRYPT_PK_NOT_PRIVATE;
+   }
+   
+   /* is the IDX valid ?  */
+   if (is_valid_idx(key->idx) != 1) {
+      return CRYPT_PK_INVALID_TYPE;
+   }
+   
+   if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* get the hash and load it as a bignum into 'e' */
+   /* init the bignums */
+   if ((err = mp_init_multi(&r, &s, &p, &e, NULL)) != MP_OKAY) { 
+      ecc_free(&pubkey);
+      err = mpi_to_ltc_error(err);
+      goto LBL_ERR;
+   }
+   if ((err = mp_read_radix(&p, (char *)sets[key->idx].order, 64)) != MP_OKAY)        { goto error; }
+   if ((err = mp_read_unsigned_bin(&e, (unsigned char *)in, (int)inlen)) != MP_OKAY)  { goto error; }
+
+   /* make up a key and export the public copy */
+   for (;;) {
+      if ((err = ecc_make_key(prng, wprng, ecc_get_size(key), &pubkey)) != CRYPT_OK) {
+         return err;
+      }
+
+      /* find r = x1 mod n */
+      if ((err = mp_mod(&pubkey.pubkey.x, &p, &r)) != MP_OKAY)                           { goto error; }
+
+      if (mp_iszero(&r)) {
+         ecc_free(&pubkey);
+      } else { 
+        /* find s = (e + xr)/k */
+        if ((err = mp_invmod(&pubkey.k, &p, &pubkey.k)) != MP_OKAY)            { goto error; } /* k = 1/k */
+        if ((err = mp_mulmod(&key->k, &r, &p, &s)) != MP_OKAY)                 { goto error; } /* s = xr */
+        if ((err = mp_addmod(&e, &s, &p, &s)) != MP_OKAY)                      { goto error; } /* s = e +  xr */
+        if ((err = mp_mulmod(&s, &pubkey.k, &p, &s)) != MP_OKAY)               { goto error; } /* s = (e + xr)/k */
+
+        if (mp_iszero(&s)) {
+           ecc_free(&pubkey);
+        } else {
+           break;
+        }
+      }
+   }
+
+   /* store as SEQUENCE { r, s -- integer } */
+   err = der_encode_sequence_multi(out, outlen,
+                             LTC_ASN1_INTEGER, 1UL, &r,
+                             LTC_ASN1_INTEGER, 1UL, &s,
+                             LTC_ASN1_EOL, 0UL, NULL);
+   goto LBL_ERR;
+error:
+   err = mpi_to_ltc_error(err);
+LBL_ERR:
+   mp_clear_multi(&r, &s, &p, &e, NULL);
+   ecc_free(&pubkey);
+
+   return err;   
+}
+
+/* verify 
+ *
+ * w  = s^-1 mod n
+ * u1 = xw 
+ * u2 = rw
+ * X = u1*G + u2*Q
+ * v = X_x1 mod n
+ * accept if v == r
+ */
+
+/**
+   Verify an ECC signature
+   @param sig         The signature to verify
+   @param siglen      The length of the signature (octets)
+   @param hash        The hash (message digest) that was signed
+   @param hashlen     The length of the hash (octets)
+   @param stat        Result of signature, 1==valid, 0==invalid
+   @param key         The corresponding public ECC key
+   @return CRYPT_OK if successful (even if the signature is not valid)
+*/
+int ecc_verify_hash(const unsigned char *sig,  unsigned long siglen,
+                    const unsigned char *hash, unsigned long hashlen, 
+                    int *stat, ecc_key *key)
+{
+   ecc_point    *mG, *mQ;
+   mp_int        r, s, v, w, u1, u2, e, p, m;
+   mp_digit      mp;
+   int           err;
+
+   LTC_ARGCHK(sig  != NULL);
+   LTC_ARGCHK(hash != NULL);
+   LTC_ARGCHK(stat != NULL);
+   LTC_ARGCHK(key  != NULL);
+
+   /* default to invalid signature */
+   *stat = 0;
+
+   /* is the IDX valid ?  */
+   if (is_valid_idx(key->idx) != 1) {
+      return CRYPT_PK_INVALID_TYPE;
+   }
+
+   /* allocate ints */
+   if ((err = mp_init_multi(&r, &s, &v, &w, &u1, &u2, &p, &e, &m, NULL)) != MP_OKAY) {
+      return CRYPT_MEM;
+   }
+
+   /* allocate points */
+   mG = new_point();
+   mQ = new_point();
+   if (mQ  == NULL || mG == NULL) {
+      err = CRYPT_MEM;
+      goto done;
+   }
+
+   /* parse header */
+   if ((err = der_decode_sequence_multi(sig, siglen,
+                                  LTC_ASN1_INTEGER, 1UL, &r,
+                                  LTC_ASN1_INTEGER, 1UL, &s,
+                                  LTC_ASN1_EOL, 0UL, NULL)) != CRYPT_OK) {
+      goto done;
+   }
+
+   /* get the order */
+   if ((err = mp_read_radix(&p, (char *)sets[key->idx].order, 64)) != MP_OKAY)                  { goto error; }
+
+   /* get the modulus */
+   if ((err = mp_read_radix(&m, (char *)sets[key->idx].prime, 64)) != MP_OKAY)                  { goto error; }
+
+   /* check for zero */
+   if (mp_iszero(&r) || mp_iszero(&s) || mp_cmp(&r, &p) != MP_LT || mp_cmp(&s, &p) != MP_LT) {
+      err = CRYPT_INVALID_PACKET;
+      goto done;
+   }
+
+   /* read hash */
+   if ((err = mp_read_unsigned_bin(&e, (unsigned char *)hash, (int)hashlen)) != MP_OKAY)        { goto error; }
+
+   /*  w  = s^-1 mod n */
+   if ((err = mp_invmod(&s, &p, &w)) != MP_OKAY)                                                { goto error; }
+
+   /* u1 = ew */
+   if ((err = mp_mulmod(&e, &w, &p, &u1)) != MP_OKAY)                                           { goto error; }
+
+   /* u2 = rw */
+   if ((err = mp_mulmod(&r, &w, &p, &u2)) != MP_OKAY)                                           { goto error; }
+
+   /* find mG = u1*G */
+   if ((err = mp_read_radix(&mG->x, (char *)sets[key->idx].Gx, 64)) != MP_OKAY)                 { goto error; }
+   if ((err = mp_read_radix(&mG->y, (char *)sets[key->idx].Gy, 64)) != MP_OKAY)                 { goto error; }
+   mp_set(&mG->z, 1);  
+   if ((err = ecc_mulmod(&u1, mG, mG, &m, 0)) != CRYPT_OK)                                      { goto done; }
+
+   /* find mQ = u2*Q */
+   if ((err = mp_copy(&key->pubkey.x, &mQ->x)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_copy(&key->pubkey.y, &mQ->y)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_copy(&key->pubkey.z, &mQ->z)) != MP_OKAY)                                      { goto error; }
+   if ((err = ecc_mulmod(&u2, mQ, mQ, &m, 0)) != CRYPT_OK)                                      { goto done; }
+  
+   /* find the montgomery mp */
+   if ((err = mp_montgomery_setup(&m, &mp)) != MP_OKAY)                                         { goto error; }
+   /* add them */
+   if ((err = add_point(mQ, mG, mG, &m, mp)) != CRYPT_OK)                                       { goto done; }
+   
+   /* reduce */
+   if ((err = ecc_map(mG, &m, mp)) != CRYPT_OK)                                                 { goto done; }
+
+   /* v = X_x1 mod n */
+   if ((err = mp_mod(&mG->x, &p, &v)) != CRYPT_OK)                                              { goto done; }
+
+   /* does v == r */
+   if (mp_cmp(&v, &r) == MP_EQ) {
+      *stat = 1;
+   }
+
+   /* clear up and return */
+   err = CRYPT_OK;
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   del_point(mG);
+   del_point(mQ);
+   mp_clear_multi(&r, &s, &v, &w, &u1, &u2, &p, &e, &m, NULL);
+   return err;
+}
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_sys.c,v $ */
+/* $Revision: 1.18 $ */
+/* $Date: 2005/06/14 20:47:55 $ */
diff --git a/packet_store_header.c b/src/pk/packet_store_header.c
similarity index 71%
rename from packet_store_header.c
rename to src/pk/packet_store_header.c
index d750718..855ca70 100644
--- a/packet_store_header.c
+++ b/src/pk/packet_store_header.c
@@ -6,15 +6,15 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
 #ifdef PACKET
 
 void packet_store_header(unsigned char *dst, int section, int subsection)
 {
-   _ARGCHK(dst != NULL);
+   LTC_ARGCHK(dst != NULL);
 
    /* store version number */
    dst[0] = (unsigned char)(CRYPT&255);
@@ -27,3 +27,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/packet_store_header.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/packet_valid_header.c b/src/pk/packet_valid_header.c
similarity index 74%
rename from packet_valid_header.c
rename to src/pk/packet_valid_header.c
index 7fda507..59db0f7 100644
--- a/packet_valid_header.c
+++ b/src/pk/packet_valid_header.c
@@ -6,9 +6,9 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
 #ifdef PACKET
 
@@ -16,7 +16,7 @@
 {
    unsigned long ver;
 
-   _ARGCHK(src != NULL);
+   LTC_ARGCHK(src != NULL);
 
    /* check version */
    ver = ((unsigned long)src[0]) | ((unsigned long)src[1] << 8U);
@@ -35,3 +35,7 @@
 #endif
 
  
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/packet_valid_header.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/pkcs_1_i2osp.c b/src/pk/pkcs1/pkcs_1_i2osp.c
similarity index 60%
rename from pkcs_1_i2osp.c
rename to src/pk/pkcs1/pkcs_1_i2osp.c
index 1a7fadd..3e68eb8 100644
--- a/pkcs_1_i2osp.c
+++ b/src/pk/pkcs1/pkcs_1_i2osp.c
@@ -6,17 +6,28 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
-/* Integer to Octet I2OSP -- Tom St Denis */
+/** 
+  @file pkcs_1_i2osp.c
+  Integer to Octet I2OSP, Tom St Denis 
+*/
 
 #ifdef PKCS_1
 
 /* always stores the same # of bytes, pads with leading zero bytes
    as required
  */
+
+/**
+   PKCS #1 Integer to binary
+   @param n             The integer to store
+   @param modulus_len   The length of the RSA modulus
+   @param out           [out] The destination for the integer
+   @return CRYPT_OK if successful
+*/
 int pkcs_1_i2osp(mp_int *n, unsigned long modulus_len, unsigned char *out)
 {
    int err;
@@ -38,3 +49,7 @@
 
 #endif /* PKCS_1 */
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_i2osp.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/pkcs1/pkcs_1_mgf1.c b/src/pk/pkcs1/pkcs_1_mgf1.c
new file mode 100644
index 0000000..aac7494
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_mgf1.c
@@ -0,0 +1,108 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file pkcs_1_mgf1.c
+  The Mask Generation Function (MGF1) for PKCS #1, Tom St Denis 
+*/
+
+#ifdef PKCS_1
+
+/**
+   Perform PKCS #1 MGF1 (internal)
+   @param seed        The seed for MGF1
+   @param seedlen     The length of the seed
+   @param hash_idx    The index of the hash desired
+   @param mask        [out] The destination
+   @param masklen     The length of the mask desired
+   @return CRYPT_OK if successful
+*/
+int pkcs_1_mgf1(const unsigned char *seed, unsigned long seedlen,
+                      int            hash_idx,
+                      unsigned char *mask, unsigned long masklen)
+{
+   unsigned long hLen, x;
+   ulong32       counter;
+   int           err;
+   hash_state    *md;
+   unsigned char *buf;
+ 
+   LTC_ARGCHK(seed != NULL);
+   LTC_ARGCHK(mask != NULL);
+
+   /* ensure valid hash */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
+      return err;
+   }
+
+   /* get hash output size */
+   hLen = hash_descriptor[hash_idx].hashsize;
+
+   /* allocate memory */
+   md  = XMALLOC(sizeof(hash_state));
+   buf = XMALLOC(hLen);
+   if (md == NULL || buf == NULL) {
+      if (md != NULL) {
+         XFREE(md);
+      }
+      if (buf != NULL) {
+         XFREE(buf);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* start counter */
+   counter = 0;
+
+   while (masklen > 0) {
+       /* handle counter */
+       STORE32H(counter, buf);
+       ++counter;
+
+       /* get hash of seed || counter */
+       if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       if ((err = hash_descriptor[hash_idx].process(md, seed, seedlen)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       if ((err = hash_descriptor[hash_idx].process(md, buf, 4)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+       if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
+          goto LBL_ERR;
+       }
+
+       /* store it */
+       for (x = 0; x < hLen && masklen > 0; x++, masklen--) {
+          *mask++ = buf[x];
+       }
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(buf, hLen);
+   zeromem(md,  sizeof(hash_state));
+#endif
+
+   XFREE(buf);
+   XFREE(md);
+
+   return err;
+}
+
+#endif /* PKCS_1 */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_mgf1.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/pkcs1/pkcs_1_oaep_decode.c b/src/pk/pkcs1/pkcs_1_oaep_decode.c
new file mode 100644
index 0000000..cd4931b
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_oaep_decode.c
@@ -0,0 +1,188 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file pkcs_1_oaep_decode.c
+  OAEP Padding for PKCS #1, Tom St Denis 
+*/
+
+#ifdef PKCS_1
+
+/**
+   PKCS #1 v2.00 OAEP decode
+   @param msg              The encoded data to decode
+   @param msglen           The length of the encoded data (octets)
+   @param lparam           The session or system data (can be NULL)
+   @param lparamlen        The length of the lparam
+   @param modulus_bitlen   The bit length of the RSA modulus
+   @param hash_idx         The index of the hash desired
+   @param out              [out] Destination of decoding
+   @param outlen           [in/out] The max size and resulting size of the decoding
+   @param res              [out] Result of decoding, 1==valid, 0==invalid
+   @return CRYPT_OK if successful (even if invalid)
+*/
+int pkcs_1_oaep_decode(const unsigned char *msg,    unsigned long msglen,
+                       const unsigned char *lparam, unsigned long lparamlen,
+                             unsigned long modulus_bitlen, int hash_idx,
+                             unsigned char *out,    unsigned long *outlen,
+                             int           *res)
+{
+   unsigned char *DB, *seed, *mask;
+   unsigned long hLen, x, y, modulus_len;
+   int           err;
+
+   LTC_ARGCHK(msg    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(res    != NULL);
+
+   /* default to invalid packet */
+   *res = 0;
+   
+   /* test valid hash */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
+      return err;
+   }
+   hLen        = hash_descriptor[hash_idx].hashsize;
+   modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
+
+   /* test hash/message size */
+   if ((2*hLen >= (modulus_len - 2)) || (msglen != modulus_len)) {
+      return CRYPT_PK_INVALID_SIZE;
+   }
+
+   /* allocate ram for DB/mask/salt of size modulus_len */
+   DB   = XMALLOC(modulus_len);
+   mask = XMALLOC(modulus_len);
+   seed = XMALLOC(hLen);
+   if (DB == NULL || mask == NULL || seed == NULL) {
+      if (DB != NULL) {
+         XFREE(DB);
+      }
+      if (mask != NULL) {
+         XFREE(mask);
+      }
+      if (seed != NULL) {
+         XFREE(seed);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* ok so it's now in the form
+  
+      0x00  || maskedseed || maskedDB 
+  
+       1    ||   hLen     ||  modulus_len - hLen - 1
+   
+    */
+
+   /* must have leading 0x00 byte */
+   if (msg[0] != 0x00) {
+      err = CRYPT_OK;
+      goto LBL_ERR;
+   }
+
+   /* now read the masked seed */
+   x = 1;
+   XMEMCPY(seed, msg + x, hLen);
+   x += hLen;
+
+   /* now read the masked DB */
+   XMEMCPY(DB, msg + x, modulus_len - hLen - 1);
+   x += modulus_len - hLen - 1;
+
+   /* compute MGF1 of maskedDB (hLen) */ 
+   if ((err = pkcs_1_mgf1(DB, modulus_len - hLen - 1, hash_idx, mask, hLen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* XOR against seed */
+   for (y = 0; y < hLen; y++) {
+      seed[y] ^= mask[y];
+   }
+
+   /* compute MGF1 of seed (k - hlen - 1) */
+   if ((err = pkcs_1_mgf1(seed, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* xor against DB */
+   for (y = 0; y < (modulus_len - hLen - 1); y++) {
+       DB[y] ^= mask[y]; 
+   }
+
+   /* now DB == lhash || PS || 0x01 || M, PS == k - mlen - 2hlen - 2 zeroes */
+
+   /* compute lhash and store it in seed [reuse temps!] */
+   x = modulus_len;
+   if (lparam != NULL) {
+      if ((err = hash_memory(hash_idx, lparam, lparamlen, seed, &x)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+   } else {
+      /* can't pass hash_memory a NULL so use DB with zero length */
+      if ((err = hash_memory(hash_idx, DB, 0, seed, &x)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+   }
+
+   /* compare the lhash'es */
+   if (memcmp(seed, DB, hLen) != 0) {
+      err = CRYPT_OK;
+      goto LBL_ERR;
+   }
+
+   /* now zeroes before a 0x01 */
+   for (x = hLen; x < (modulus_len - hLen - 1) && DB[x] == 0x00; x++) {
+      /* step... */
+   }
+
+   /* error out if wasn't 0x01 */
+   if (x == (modulus_len - hLen - 1) || DB[x] != 0x01) {
+      err = CRYPT_OK;
+      goto LBL_ERR;
+   }
+
+   /* rest is the message (and skip 0x01) */
+   if ((modulus_len - hLen - 1) - ++x > *outlen) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto LBL_ERR;
+   }
+
+   /* copy message */
+   *outlen = (modulus_len - hLen - 1) - x;
+   XMEMCPY(out, DB + x, modulus_len - hLen - 1 - x);
+   x += modulus_len - hLen - 1;
+
+   /* valid packet */
+   *res = 1;
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(DB,   modulus_len);
+   zeromem(seed, hLen);
+   zeromem(mask, modulus_len);
+#endif
+
+   XFREE(seed);
+   XFREE(mask);
+   XFREE(DB);
+
+   return err;
+}
+
+#endif /* PKCS_1 */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_decode.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/06/18 02:37:06 $ */
diff --git a/src/pk/pkcs1/pkcs_1_oaep_encode.c b/src/pk/pkcs1/pkcs_1_oaep_encode.c
new file mode 100644
index 0000000..12670b5
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_oaep_encode.c
@@ -0,0 +1,172 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file pkcs_1_oaep_encode.c
+  OAEP Padding for PKCS #1, Tom St Denis 
+*/
+
+#ifdef PKCS_1
+
+/**
+  PKCS #1 v2.00 OAEP encode
+  @param msg             The data to encode
+  @param msglen          The length of the data to encode (octets)
+  @param lparam          A session or system parameter (can be NULL)
+  @param lparamlen       The length of the lparam data
+  @param modulus_bitlen  The bit length of the RSA modulus
+  @param prng            An active PRNG state
+  @param prng_idx        The index of the PRNG desired
+  @param hash_idx        The index of the hash desired
+  @param out             [out] The destination for the encoded data
+  @param outlen          [in/out] The max size and resulting size of the encoded data
+  @return CRYPT_OK if successful
+*/
+int pkcs_1_oaep_encode(const unsigned char *msg,    unsigned long msglen,
+                       const unsigned char *lparam, unsigned long lparamlen,
+                             unsigned long modulus_bitlen, prng_state *prng,
+                             int           prng_idx,         int  hash_idx,
+                             unsigned char *out,    unsigned long *outlen)
+{
+   unsigned char *DB, *seed, *mask;
+   unsigned long hLen, x, y, modulus_len;
+   int           err;
+
+   LTC_ARGCHK(msg    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* test valid hash */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
+      return err;
+   }
+
+   /* valid prng */
+   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   hLen        = hash_descriptor[hash_idx].hashsize;
+   modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
+
+   /* test message size */
+   if ((2*hLen >= (modulus_len - 2)) || (msglen > (modulus_len - 2*hLen - 2))) {
+      return CRYPT_PK_INVALID_SIZE;
+   }
+
+   /* allocate ram for DB/mask/salt of size modulus_len */
+   DB   = XMALLOC(modulus_len);
+   mask = XMALLOC(modulus_len);
+   seed = XMALLOC(hLen);
+   if (DB == NULL || mask == NULL || seed == NULL) {
+      if (DB != NULL) {
+         XFREE(DB);
+      }
+      if (mask != NULL) {
+         XFREE(mask);
+      }
+      if (seed != NULL) {
+         XFREE(seed);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* get lhash */
+   /* DB == lhash || PS || 0x01 || M, PS == k - mlen - 2hlen - 2 zeroes */
+   x = modulus_len;
+   if (lparam != NULL) {
+      if ((err = hash_memory(hash_idx, lparam, lparamlen, DB, &x)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+   } else {
+      /* can't pass hash_memory a NULL so use DB with zero length */
+      if ((err = hash_memory(hash_idx, DB, 0, DB, &x)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+   }
+
+   /* append PS then 0x01 (to lhash)  */
+   x = hLen;
+   y = modulus_len - msglen - 2*hLen - 2;
+   XMEMSET(DB+x, 0, y);
+   x += y;
+
+   /* 0x01 byte */
+   DB[x++] = 0x01;
+
+   /* message (length = msglen) */
+   XMEMCPY(DB+x, msg, msglen);
+   x += msglen;
+
+   /* now choose a random seed */
+   if (prng_descriptor[prng_idx].read(seed, hLen, prng) != hLen) {
+      err = CRYPT_ERROR_READPRNG;
+      goto LBL_ERR;
+   }
+
+   /* compute MGF1 of seed (k - hlen - 1) */
+   if ((err = pkcs_1_mgf1(seed, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* xor against DB */
+   for (y = 0; y < (modulus_len - hLen - 1); y++) {
+       DB[y] ^= mask[y]; 
+   }
+
+   /* compute MGF1 of maskedDB (hLen) */ 
+   if ((err = pkcs_1_mgf1(DB, modulus_len - hLen - 1, hash_idx, mask, hLen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* XOR against seed */
+   for (y = 0; y < hLen; y++) {
+      seed[y] ^= mask[y];
+   }
+
+   /* create string of length modulus_len */
+   if (*outlen < modulus_len) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto LBL_ERR;
+   }
+
+   /* start output which is 0x00 || maskedSeed || maskedDB */
+   x = 0;
+   out[x++] = 0x00;
+   XMEMCPY(out+x, seed, hLen);
+   x += hLen;
+   XMEMCPY(out+x, DB, modulus_len - hLen - 1);
+   x += modulus_len - hLen - 1;
+
+   *outlen = x;
+    
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(DB,   modulus_len);
+   zeromem(seed, hLen);
+   zeromem(mask, modulus_len);
+#endif
+
+   XFREE(seed);
+   XFREE(mask);
+   XFREE(DB);
+
+   return err;
+}
+
+#endif /* PKCS_1 */
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_oaep_encode.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/pkcs1/pkcs_1_os2ip.c b/src/pk/pkcs1/pkcs_1_os2ip.c
new file mode 100644
index 0000000..a9a1858
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_os2ip.c
@@ -0,0 +1,41 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file pkcs_1_os2ip.c
+  Octet to Integer OS2IP, Tom St Denis 
+*/
+#ifdef PKCS_1
+
+/**
+  Read a binary string into an mp_int
+  @param n          [out] The mp_int destination
+  @param in         The binary string to read
+  @param inlen      The length of the binary string
+  @return CRYPT_OK if successful
+*/
+int pkcs_1_os2ip(mp_int *n, unsigned char *in, unsigned long inlen)
+{
+   int err;
+   /* read it */
+   if ((err = mp_read_unsigned_bin(n, in, inlen)) != MP_OKAY) {
+      return mpi_to_ltc_error(err);
+   }
+   return CRYPT_OK;
+}
+
+#endif /* PKCS_1 */
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_os2ip.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/pkcs1/pkcs_1_pss_decode.c b/src/pk/pkcs1/pkcs_1_pss_decode.c
new file mode 100644
index 0000000..e61c33f
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_pss_decode.c
@@ -0,0 +1,177 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file pkcs_1_pss_decode.c
+  PKCS #1 PSS Signature Padding, Tom St Denis 
+*/
+
+#ifdef PKCS_1
+
+/**
+   PKCS #1 v2.00 PSS decode
+   @param  msghash         The hash to verify
+   @param  msghashlen      The length of the hash (octets)
+   @param  sig             The signature data (encoded data)
+   @param  siglen          The length of the signature data (octets)
+   @param  saltlen         The length of the salt used (octets)
+   @param  hash_idx        The index of the hash desired
+   @param  modulus_bitlen  The bit length of the RSA modulus
+   @param  res             [out] The result of the comparison, 1==valid, 0==invalid
+   @return CRYPT_OK if successful (even if the comparison failed)
+*/
+int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
+                      const unsigned char *sig,     unsigned long siglen,
+                            unsigned long saltlen,  int           hash_idx,
+                            unsigned long modulus_bitlen, int    *res)
+{
+   unsigned char *DB, *mask, *salt, *hash;
+   unsigned long x, y, hLen, modulus_len;
+   int           err;
+   hash_state    md;
+
+   LTC_ARGCHK(msghash != NULL);
+   LTC_ARGCHK(res     != NULL);
+
+   /* default to invalid */
+   *res = 0;
+
+   /* ensure hash is valid */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   hLen        = hash_descriptor[hash_idx].hashsize;
+   modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
+
+   /* check sizes */
+   if ((saltlen > modulus_len) || 
+       (modulus_len < hLen + saltlen + 2) || (siglen != modulus_len)) {
+      return CRYPT_PK_INVALID_SIZE;
+   }
+
+   /* allocate ram for DB/mask/salt/hash of size modulus_len */
+   DB   = XMALLOC(modulus_len);
+   mask = XMALLOC(modulus_len);
+   salt = XMALLOC(modulus_len);
+   hash = XMALLOC(modulus_len);
+   if (DB == NULL || mask == NULL || salt == NULL || hash == NULL) {
+      if (DB != NULL) {
+         XFREE(DB);
+      }
+      if (mask != NULL) {
+         XFREE(mask);
+      }
+      if (salt != NULL) {
+         XFREE(salt);
+      }
+      if (hash != NULL) {
+         XFREE(hash);
+      }
+      return CRYPT_MEM;
+   }
+
+   /* ensure the 0xBC byte */
+   if (sig[siglen-1] != 0xBC) {
+      err = CRYPT_OK;
+      goto LBL_ERR;
+   }
+
+   /* copy out the DB */
+   x = 0;
+   XMEMCPY(DB, sig + x, modulus_len - hLen - 1);
+   x += modulus_len - hLen - 1;
+
+   /* copy out the hash */
+   XMEMCPY(hash, sig + x, hLen);
+   x += hLen;
+
+   /* check the MSB */
+   if ((sig[0] & ~(0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)))) != 0) {
+      err = CRYPT_OK;
+      goto LBL_ERR;
+   }
+
+   /* generate mask of length modulus_len - hLen - 1 from hash */
+   if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* xor against DB */
+   for (y = 0; y < (modulus_len - hLen - 1); y++) {
+      DB[y] ^= mask[y];
+   }
+   
+   /* now clear the first byte [make sure smaller than modulus] */
+   DB[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1));
+
+   /* DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */
+
+   /* check for zeroes and 0x01 */
+   for (x = 0; x < modulus_len - saltlen - hLen - 2; x++) {
+       if (DB[x] != 0x00) {
+          err = CRYPT_OK;
+          goto LBL_ERR;
+       }
+   }
+
+   /* check for the 0x01 */
+   if (DB[x++] != 0x01) {
+      err = CRYPT_OK;
+      goto LBL_ERR;
+   }
+
+   /* M = (eight) 0x00 || msghash || salt, mask = H(M) */
+   if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   zeromem(mask, 8);
+   if ((err = hash_descriptor[hash_idx].process(&md, mask, 8)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].process(&md, DB+x, saltlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].done(&md, mask)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* mask == hash means valid signature */
+   if (memcmp(mask, hash, hLen) == 0) {
+      *res = 1;
+   }
+
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(DB,   modulus_len);   
+   zeromem(mask, modulus_len);   
+   zeromem(salt, modulus_len);   
+   zeromem(hash, modulus_len);   
+#endif
+
+   XFREE(hash);
+   XFREE(salt);
+   XFREE(mask);
+   XFREE(DB);
+
+   return err;
+}
+
+#endif /* PKCS_1 */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_decode.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/pkcs1/pkcs_1_pss_encode.c b/src/pk/pkcs1/pkcs_1_pss_encode.c
new file mode 100644
index 0000000..899605c
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_pss_encode.c
@@ -0,0 +1,174 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/** 
+  @file pkcs_1_pss_encode.c
+  PKCS #1 PSS Signature Padding, Tom St Denis 
+*/
+
+#ifdef PKCS_1
+
+/**
+   PKCS #1 v2.00 Signature Encoding
+   @param msghash          The hash to encode
+   @param msghashlen       The length of the hash (octets)
+   @param saltlen          The length of the salt desired (octets)
+   @param prng             An active PRNG context
+   @param prng_idx         The index of the PRNG desired
+   @param hash_idx         The index of the hash desired
+   @param modulus_bitlen   The bit length of the RSA modulus
+   @param out              [out] The destination of the encoding
+   @param outlen           [in/out] The max size and resulting size of the encoded data
+   @return CRYPT_OK if successful
+*/
+int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
+                            unsigned long saltlen,  prng_state   *prng,     
+                            int           prng_idx, int           hash_idx,
+                            unsigned long modulus_bitlen,
+                            unsigned char *out,     unsigned long *outlen)
+{
+   unsigned char *DB, *mask, *salt, *hash;
+   unsigned long x, y, hLen, modulus_len;
+   int           err;
+   hash_state    md;
+
+   LTC_ARGCHK(msghash != NULL);
+   LTC_ARGCHK(out     != NULL);
+   LTC_ARGCHK(outlen  != NULL);
+
+   /* ensure hash and PRNG are valid */
+   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+      return err;
+   }
+   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
+      return err;
+   }
+
+   hLen        = hash_descriptor[hash_idx].hashsize;
+   modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
+
+   /* check sizes */
+   if ((saltlen > modulus_len) || (modulus_len < hLen + saltlen + 2)) {
+      return CRYPT_PK_INVALID_SIZE;
+   }
+
+   /* allocate ram for DB/mask/salt/hash of size modulus_len */
+   DB   = XMALLOC(modulus_len);
+   mask = XMALLOC(modulus_len);
+   salt = XMALLOC(modulus_len);
+   hash = XMALLOC(modulus_len);
+   if (DB == NULL || mask == NULL || salt == NULL || hash == NULL) {
+      if (DB != NULL) {
+         XFREE(DB);
+      }
+      if (mask != NULL) {
+         XFREE(mask);
+      }
+      if (salt != NULL) {
+         XFREE(salt);
+      }
+      if (hash != NULL) {
+         XFREE(hash);
+      }
+      return CRYPT_MEM;
+   }
+
+
+   /* generate random salt */
+   if (saltlen > 0) {
+      if (prng_descriptor[prng_idx].read(salt, saltlen, prng) != saltlen) {
+         err = CRYPT_ERROR_READPRNG;
+         goto LBL_ERR;
+      }
+   }
+
+   /* M = (eight) 0x00 || msghash || salt, hash = H(M) */
+   if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   zeromem(DB, 8);
+   if ((err = hash_descriptor[hash_idx].process(&md, DB, 8)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].process(&md, salt, saltlen)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+   if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */
+   x = 0;
+   XMEMSET(DB + x, 0, modulus_len - saltlen - hLen - 2);
+   x += modulus_len - saltlen - hLen - 2;
+   DB[x++] = 0x01;
+   XMEMCPY(DB + x, salt, saltlen);
+   x += saltlen;
+
+   /* generate mask of length modulus_len - hLen - 1 from hash */
+   if ((err = pkcs_1_mgf1(hash, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* xor against DB */
+   for (y = 0; y < (modulus_len - hLen - 1); y++) {
+      DB[y] ^= mask[y];
+   }
+
+   /* output is DB || hash || 0xBC */
+   if (*outlen < modulus_len) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto LBL_ERR;
+   }
+
+   /* DB len = modulus_len - hLen - 1 */
+   y = 0;
+   XMEMCPY(out + y, DB, modulus_len - hLen - 1);
+   y += modulus_len - hLen - 1;
+
+   /* hash */
+   XMEMCPY(out + y, hash, hLen);
+   y += hLen;
+
+   /* 0xBC */
+   out[y] = 0xBC;
+
+   /* now clear the 8*modulus_len - modulus_bitlen most significant bits */
+   out[0] &= 0xFF >> ((modulus_len<<3) - (modulus_bitlen-1));
+
+   /* store output size */
+   *outlen = modulus_len;
+   err = CRYPT_OK;
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(DB,   modulus_len);   
+   zeromem(mask, modulus_len);   
+   zeromem(salt, modulus_len);   
+   zeromem(hash, modulus_len);   
+#endif
+
+   XFREE(hash);
+   XFREE(salt);
+   XFREE(mask);
+   XFREE(DB);
+
+   return err;
+}
+
+#endif /* PKCS_1 */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_pss_encode.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/rsa/rsa_decrypt_key.c b/src/pk/rsa/rsa_decrypt_key.c
new file mode 100644
index 0000000..7cea807
--- /dev/null
+++ b/src/pk/rsa/rsa_decrypt_key.c
@@ -0,0 +1,93 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_decrypt_key.c
+  RSA PKCS #1 OAEP Decryption, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+   (PKCS #1 v2.0) decrypt then OAEP depad  
+   @param in          The ciphertext
+   @param inlen       The length of the ciphertext (octets)
+   @param out         [out] The plaintext
+   @param outlen      [in/out] The max size and resulting size of the plaintext (octets)
+   @param lparam      The system "lparam" value
+   @param lparamlen   The length of the lparam value (octets)
+   @param hash_idx    The index of the hash desired
+   @param stat        [out] Result of the decryption, 1==valid, 0==invalid
+   @param key         The corresponding private RSA key
+   @return CRYPT_OK if succcessul (even if invalid)
+*/
+int rsa_decrypt_key(const unsigned char *in,       unsigned long  inlen,
+                          unsigned char *out,      unsigned long *outlen, 
+                    const unsigned char *lparam,   unsigned long  lparamlen,
+                          int            hash_idx, int           *stat,
+                          rsa_key       *key)
+{
+  unsigned long modulus_bitlen, modulus_bytelen, x;
+  int           err;
+  unsigned char *tmp;
+  
+  LTC_ARGCHK(out    != NULL);
+  LTC_ARGCHK(outlen != NULL);
+  LTC_ARGCHK(key    != NULL);
+  LTC_ARGCHK(stat   != NULL);
+
+  /* default to invalid */
+  *stat = 0;
+
+  /* valid hash ? */
+  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+     return err;
+  }
+  
+  /* get modulus len in bits */
+  modulus_bitlen = mp_count_bits(&(key->N));
+
+  /* outlen must be at least the size of the modulus */
+  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
+  if (modulus_bytelen != inlen) {
+     return CRYPT_INVALID_PACKET;
+  }
+
+  /* allocate ram */
+  tmp = XMALLOC(inlen);
+  if (tmp == NULL) {
+     return CRYPT_MEM;
+  }
+
+  /* rsa decode the packet */
+  x = inlen;
+  if ((err = rsa_exptmod(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) {
+     XFREE(tmp);
+     return err;
+  }
+
+  /* now OAEP decode the packet */
+  err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx,
+                           out, outlen, stat);
+  XFREE(tmp);
+  return err;
+}
+
+#endif /* MRSA */
+
+
+
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_decrypt_key.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/rsa/rsa_encrypt_key.c b/src/pk/rsa/rsa_encrypt_key.c
new file mode 100644
index 0000000..d29aa83
--- /dev/null
+++ b/src/pk/rsa/rsa_encrypt_key.c
@@ -0,0 +1,80 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_encrypt_key.c
+  RSA PKCS OAEP encryption, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+    (PKCS #1 v2.0) OAEP pad then encrypt
+    @param in          The plaintext
+    @param inlen       The length of the plaintext (octets)
+    @param out         [out] The ciphertext
+    @param outlen      [in/out] The max size and resulting size of the ciphertext
+    @param lparam      The system "lparam" for the encryption
+    @param lparamlen   The length of lparam (octets)
+    @param prng        An active PRNG
+    @param prng_idx    The index of the desired prng
+    @param hash_idx    The index of the desired hash
+    @param key         The RSA key to encrypt to
+    @return CRYPT_OK if successful
+*/    
+int rsa_encrypt_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, rsa_key *key)
+{
+  unsigned long modulus_bitlen, modulus_bytelen, x;
+  int           err;
+  
+  LTC_ARGCHK(in     != NULL);
+  LTC_ARGCHK(out    != NULL);
+  LTC_ARGCHK(outlen != NULL);
+  LTC_ARGCHK(key    != NULL);
+  
+  /* valid prng and hash ? */
+  if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
+     return err;
+  }
+  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+     return err;
+  }
+  
+  /* get modulus len in bits */
+  modulus_bitlen = mp_count_bits(&(key->N));
+
+  /* outlen must be at least the size of the modulus */
+  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
+  if (modulus_bytelen > *outlen) {
+     return CRYPT_BUFFER_OVERFLOW;
+  }
+      
+  /* OAEP pad the key */
+  x = *outlen;
+  if ((err = pkcs_1_oaep_encode(in, inlen, lparam, 
+                                lparamlen, modulus_bitlen, prng, prng_idx, hash_idx, 
+                                out, &x)) != CRYPT_OK) {
+     return err;
+  }                                
+
+  /* rsa exptmod the OAEP pad */
+  return rsa_exptmod(out, x, out, outlen, PK_PUBLIC, key);
+}
+
+#endif /* MRSA */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_encrypt_key.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/rsa/rsa_export.c b/src/pk/rsa/rsa_export.c
new file mode 100644
index 0000000..f2e324d
--- /dev/null
+++ b/src/pk/rsa/rsa_export.c
@@ -0,0 +1,76 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_export.c
+  Export RSA PKCS keys, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+    This will export either an RSAPublicKey or RSAPrivateKey [defined in PKCS #1 v2.1] 
+    @param out       [out] Destination of the packet
+    @param outlen    [in/out] The max size and resulting size of the packet
+    @param type      The type of exported key (PK_PRIVATE or PK_PUBLIC)
+    @param key       The RSA key to export
+    @return CRYPT_OK if successful
+*/    
+int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
+{
+   int           err;
+   unsigned long zero=0;
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
+
+   /* type valid? */
+   if (!(key->type == PK_PRIVATE) && (type == PK_PRIVATE)) {
+      return CRYPT_PK_INVALID_TYPE;
+   }
+
+   if (type == PK_PRIVATE) {
+      /* private key */
+      /* output is 
+            Version, n, e, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p
+       */
+      if ((err = der_encode_sequence_multi(out, outlen, 
+                          LTC_ASN1_SHORT_INTEGER, 1UL, &zero, 
+                          LTC_ASN1_INTEGER, 1UL, &key->N, 
+                          LTC_ASN1_INTEGER, 1UL, &key->e,
+                          LTC_ASN1_INTEGER, 1UL, &key->d, 
+                          LTC_ASN1_INTEGER, 1UL, &key->p, 
+                          LTC_ASN1_INTEGER, 1UL, &key->q, 
+                          LTC_ASN1_INTEGER, 1UL, &key->dP,
+                          LTC_ASN1_INTEGER, 1UL, &key->dQ, 
+                          LTC_ASN1_INTEGER, 1UL, &key->qP, 
+                          LTC_ASN1_EOL,     0UL, NULL)) != CRYPT_OK) {
+         return err;
+      }
+ 
+      /* clear zero and return */
+      return CRYPT_OK;
+   } else {
+      /* public key */
+      return der_encode_sequence_multi(out, outlen, 
+                                 LTC_ASN1_INTEGER, 1UL, &key->N, 
+                                 LTC_ASN1_INTEGER, 1UL, &key->e, 
+                                 LTC_ASN1_EOL,     0UL, NULL);
+   }
+}
+
+#endif /* MRSA */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_export.c,v $ */
+/* $Revision: 1.11 $ */
+/* $Date: 2005/06/04 01:42:48 $ */
diff --git a/src/pk/rsa/rsa_exptmod.c b/src/pk/rsa/rsa_exptmod.c
new file mode 100644
index 0000000..379404c
--- /dev/null
+++ b/src/pk/rsa/rsa_exptmod.c
@@ -0,0 +1,115 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_exptmod.c
+  RSA PKCS exptmod, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/** 
+   Compute an RSA modular exponentiation 
+   @param in         The input data to send into RSA
+   @param inlen      The length of the input (octets)
+   @param out        [out] The destination 
+   @param outlen     [in/out] The max size and resulting size of the output
+   @param which      Which exponent to use, e.g. PK_PRIVATE or PK_PUBLIC
+   @param key        The RSA key to use 
+   @return CRYPT_OK if successful
+*/   
+int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
+                      unsigned char *out,  unsigned long *outlen, int which,
+                      rsa_key *key)
+{
+   mp_int        tmp, tmpa, tmpb;
+   unsigned long x;
+   int           err;
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
+   
+   /* is the key of the right type for the operation? */
+   if (which == PK_PRIVATE && (key->type != PK_PRIVATE)) {
+      return CRYPT_PK_NOT_PRIVATE;
+   }
+
+   /* must be a private or public operation */
+   if (which != PK_PRIVATE && which != PK_PUBLIC) {
+      return CRYPT_PK_INVALID_TYPE;
+   }
+
+   /* init and copy into tmp */
+   if ((err = mp_init_multi(&tmp, &tmpa, &tmpb, NULL)) != MP_OKAY)                                    { return mpi_to_ltc_error(err); }
+   if ((err = mp_read_unsigned_bin(&tmp, (unsigned char *)in, (int)inlen)) != MP_OKAY)                { goto error; }
+
+   /* sanity check on the input */
+   if (mp_cmp(&key->N, &tmp) == MP_LT) {
+      err = CRYPT_PK_INVALID_SIZE;
+      goto done;
+   }
+
+   /* are we using the private exponent and is the key optimized? */
+   if (which == PK_PRIVATE) {
+      /* tmpa = tmp^dP mod p */
+      if ((err = mp_exptmod(&tmp, &key->dP, &key->p, &tmpa)) != MP_OKAY)                               { goto error; }
+
+      /* tmpb = tmp^dQ mod q */
+      if ((err = mp_exptmod(&tmp, &key->dQ, &key->q, &tmpb)) != MP_OKAY)                               { goto error; }
+
+      /* tmp = (tmpa - tmpb) * qInv (mod p) */
+      if ((err = mp_sub(&tmpa, &tmpb, &tmp)) != MP_OKAY)                                              { goto error; }
+      if ((err = mp_mulmod(&tmp, &key->qP, &key->p, &tmp)) != MP_OKAY)                                { goto error; }
+
+      /* tmp = tmpb + q * tmp */
+      if ((err = mp_mul(&tmp, &key->q, &tmp)) != MP_OKAY)                                             { goto error; }
+      if ((err = mp_add(&tmp, &tmpb, &tmp)) != MP_OKAY)                                               { goto error; }
+   } else {
+      /* exptmod it */
+      if ((err = mp_exptmod(&tmp, &key->e, &key->N, &tmp)) != MP_OKAY)                                { goto error; }
+   }
+
+   /* read it back */
+   x = (unsigned long)mp_unsigned_bin_size(&key->N);
+   if (x > *outlen) {
+      err = CRYPT_BUFFER_OVERFLOW;
+      goto done;
+   }
+
+   /* this should never happen ... */
+   if (mp_unsigned_bin_size(&tmp) > mp_unsigned_bin_size(&key->N)) {
+      err = CRYPT_ERROR;
+      goto done;
+   }
+   *outlen = x;
+
+   /* convert it */
+   zeromem(out, x);
+   if ((err = mp_to_unsigned_bin(&tmp, out+(x-mp_unsigned_bin_size(&tmp)))) != MP_OKAY)               { goto error; }
+
+   /* clean up and return */
+   err = CRYPT_OK;
+   goto done;
+error:
+   err = mpi_to_ltc_error(err);
+done:
+   mp_clear_multi(&tmp, &tmpa, &tmpb, NULL);
+   return err;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_exptmod.c,v $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2005/06/23 02:10:22 $ */
diff --git a/src/pk/rsa/rsa_free.c b/src/pk/rsa/rsa_free.c
new file mode 100644
index 0000000..69eeaec
--- /dev/null
+++ b/src/pk/rsa/rsa_free.c
@@ -0,0 +1,35 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_free.c
+  Free an RSA key, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+  Free an RSA key from memory
+  @param key   The RSA key to free
+*/
+void rsa_free(rsa_key *key)
+{
+   LTC_ARGCHK(key != NULL);
+   mp_clear_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP,
+                  &key->qP, &key->p, &key->q, NULL);
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_free.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/rsa/rsa_import.c b/src/pk/rsa/rsa_import.c
new file mode 100644
index 0000000..5706134
--- /dev/null
+++ b/src/pk/rsa/rsa_import.c
@@ -0,0 +1,92 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_import.c
+  Import a PKCS RSA key, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+  Import an RSAPublicKey or RSAPrivateKey [two-prime only, only support >= 1024-bit keys, defined in PKCS #1 v2.1]
+  @param in      The packet to import from
+  @param inlen   It's length (octets)
+  @param key     [out] Destination for newly imported key
+  @return CRYPT_OK if successful, upon error allocated memory is freed
+*/
+int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key)
+{
+   int           err;
+   mp_int        zero;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(key != NULL);
+
+   /* init key */
+   if ((err = mp_init_multi(&zero, &key->e, &key->d, &key->N, &key->dQ, 
+                            &key->dP, &key->qP, &key->p, &key->q, NULL)) != MP_OKAY) {
+      return mpi_to_ltc_error(err);
+   }
+
+   if ((err = der_decode_sequence_multi(in, inlen, 
+                                  LTC_ASN1_INTEGER, 1UL, &key->N, 
+                                  LTC_ASN1_EOL,     0UL, NULL)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   if (mp_cmp_d(&key->N, 0) == MP_EQ) {
+      /* it's a private key */
+      if ((err = der_decode_sequence_multi(in, inlen, 
+                          LTC_ASN1_INTEGER, 1UL, &zero, 
+                          LTC_ASN1_INTEGER, 1UL, &key->N, 
+                          LTC_ASN1_INTEGER, 1UL, &key->e,
+                          LTC_ASN1_INTEGER, 1UL, &key->d, 
+                          LTC_ASN1_INTEGER, 1UL, &key->p, 
+                          LTC_ASN1_INTEGER, 1UL, &key->q, 
+                          LTC_ASN1_INTEGER, 1UL, &key->dP,
+                          LTC_ASN1_INTEGER, 1UL, &key->dQ, 
+                          LTC_ASN1_INTEGER, 1UL, &key->qP, 
+                          LTC_ASN1_EOL,     0UL, NULL)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+      key->type = PK_PRIVATE;
+   } else if (mp_cmp_d(&key->N, 1) == MP_EQ) {
+      /* we don't support multi-prime RSA */
+      err = CRYPT_PK_INVALID_TYPE;
+      goto LBL_ERR;
+   } else {
+      /* it's a public key and we lack e */
+      if ((err = der_decode_sequence_multi(in, inlen, 
+                                     LTC_ASN1_INTEGER, 1UL, &key->N, 
+                                     LTC_ASN1_INTEGER, 1UL, &key->e, 
+                                     LTC_ASN1_EOL,     0UL, NULL)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+
+      /* free up some ram */
+      mp_clear_multi(&key->p, &key->q, &key->qP, &key->dP, &key->dQ, NULL);
+      key->type = PK_PUBLIC;
+   }
+   return CRYPT_OK;
+LBL_ERR:
+   mp_clear_multi(&zero, &key->d, &key->e, &key->N, &key->dQ, &key->dP,
+                  &key->qP, &key->p, &key->q, NULL);
+   return err;
+}
+
+#endif /* MRSA */
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_import.c,v $ */
+/* $Revision: 1.10 $ */
+/* $Date: 2005/06/03 18:48:28 $ */
diff --git a/rsa_make_key.c b/src/pk/rsa/rsa_make_key.c
similarity index 69%
rename from rsa_make_key.c
rename to src/pk/rsa/rsa_make_key.c
index 3a06ca7..d874106 100644
--- a/rsa_make_key.c
+++ b/src/pk/rsa/rsa_make_key.c
@@ -6,20 +6,32 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
+#include "tomcrypt.h"
 
-/* RSA Code by Tom St Denis */
-#include "mycrypt.h"
+/**
+  @file rsa_make_key.c
+  RSA key generation, Tom St Denis
+*/  
 
 #ifdef MRSA
 
+/** 
+   Create an RSA key
+   @param prng     An active PRNG state
+   @param wprng    The index of the PRNG desired
+   @param size     The size of the modulus (key size) desired (octets)
+   @param e        The "e" value (public key).  e==65537 is a good choice
+   @param key      [out] Destination of a newly created private key pair
+   @return CRYPT_OK if successful, upon error all allocated ram is freed
+*/
 int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key)
 {
    mp_int p, q, tmp1, tmp2, tmp3;
    int    err;
 
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(key != NULL);
 
    if ((size < (MIN_RSA_SIZE/8)) || (size > (MAX_RSA_SIZE/8))) {
       return CRYPT_INVALID_KEYSIZE;
@@ -61,48 +73,44 @@
 
    /* make key */
    if ((err = mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP,
-                     &key->qP, &key->pQ, &key->p, &key->q, NULL)) != MP_OKAY) {
+                     &key->qP, &key->p, &key->q, NULL)) != MP_OKAY) {
       goto error;
    }
 
-   if ((err = mp_set_int(&key->e, e)) != MP_OKAY)                  { goto error2; } /* key->e =  e */
-   if ((err = mp_invmod(&key->e, &tmp1, &key->d)) != MP_OKAY)      { goto error2; } /* key->d = 1/e mod lcm(p-1,q-1) */
-   if ((err = mp_mul(&p, &q, &key->N)) != MP_OKAY)                 { goto error2; } /* key->N = pq */
+   if ((err = mp_set_int(&key->e, e)) != MP_OKAY)                     { goto error2; } /* key->e =  e */
+   if ((err = mp_invmod(&key->e, &tmp1, &key->d)) != MP_OKAY)         { goto error2; } /* key->d = 1/e mod lcm(p-1,q-1) */
+   if ((err = mp_mul(&p, &q, &key->N)) != MP_OKAY)                    { goto error2; } /* key->N = pq */
 
-/* optimize for CRT now */
+   /* optimize for CRT now */
    /* find d mod q-1 and d mod p-1 */
-   if ((err = mp_sub_d(&p, 1, &tmp1)) != MP_OKAY)                  { goto error2; } /* tmp1 = q-1 */
-   if ((err = mp_sub_d(&q, 1, &tmp2)) != MP_OKAY)                  { goto error2; } /* tmp2 = p-1 */
+   if ((err = mp_sub_d(&p, 1, &tmp1)) != MP_OKAY)                     { goto error2; } /* tmp1 = q-1 */
+   if ((err = mp_sub_d(&q, 1, &tmp2)) != MP_OKAY)                     { goto error2; } /* tmp2 = p-1 */
+   if ((err = mp_mod(&key->d, &tmp1, &key->dP)) != MP_OKAY)           { goto error2; } /* dP = d mod p-1 */
+   if ((err = mp_mod(&key->d, &tmp2, &key->dQ)) != MP_OKAY)           { goto error2; } /* dQ = d mod q-1 */
+   if ((err = mp_invmod(&q, &p, &key->qP)) != MP_OKAY)                { goto error2; } /* qP = 1/q mod p */
 
-   if ((err = mp_mod(&key->d, &tmp1, &key->dP)) != MP_OKAY)        { goto error2; } /* dP = d mod p-1 */
-   if ((err = mp_mod(&key->d, &tmp2, &key->dQ)) != MP_OKAY)        { goto error2; } /* dQ = d mod q-1 */
-
-   if ((err = mp_invmod(&q, &p, &key->qP)) != MP_OKAY)             { goto error2; } /* qP = 1/q mod p */
-   if ((err = mp_mulmod(&key->qP, &q, &key->N, &key->qP)) != MP_OKAY)         { goto error2; } /* qP = q * (1/q mod p) mod N */
-
-   if ((err = mp_invmod(&p, &q, &key->pQ)) != MP_OKAY)             { goto error2; } /* pQ = 1/p mod q */
-   if ((err = mp_mulmod(&key->pQ, &p, &key->N, &key->pQ)) != MP_OKAY)         { goto error2; } /* pQ = p * (1/p mod q) mod N */
-
-   if ((err = mp_copy(&p, &key->p)) != MP_OKAY)                    { goto error2; }
-   if ((err = mp_copy(&q, &key->q)) != MP_OKAY)                    { goto error2; }
+   if ((err = mp_copy(&p, &key->p)) != MP_OKAY)                       { goto error2; }
+   if ((err = mp_copy(&q, &key->q)) != MP_OKAY)                       { goto error2; }
 
    /* shrink ram required  */
-   if ((err = mp_shrink(&key->e)) != MP_OKAY)                      { goto error2; }
-   if ((err = mp_shrink(&key->d)) != MP_OKAY)                      { goto error2; }
-   if ((err = mp_shrink(&key->N)) != MP_OKAY)                      { goto error2; }
-   if ((err = mp_shrink(&key->dQ)) != MP_OKAY)                     { goto error2; }
-   if ((err = mp_shrink(&key->dP)) != MP_OKAY)                     { goto error2; }
-   if ((err = mp_shrink(&key->qP)) != MP_OKAY)                     { goto error2; }
-   if ((err = mp_shrink(&key->pQ)) != MP_OKAY)                     { goto error2; }
-   if ((err = mp_shrink(&key->p)) != MP_OKAY)                      { goto error2; }
-   if ((err = mp_shrink(&key->q)) != MP_OKAY)                      { goto error2; }
+   if ((err = mp_shrink(&key->e)) != MP_OKAY)                         { goto error2; }
+   if ((err = mp_shrink(&key->d)) != MP_OKAY)                         { goto error2; }
+   if ((err = mp_shrink(&key->N)) != MP_OKAY)                         { goto error2; }
+   if ((err = mp_shrink(&key->dQ)) != MP_OKAY)                        { goto error2; }
+   if ((err = mp_shrink(&key->dP)) != MP_OKAY)                        { goto error2; }
+   if ((err = mp_shrink(&key->qP)) != MP_OKAY)                        { goto error2; }
+   if ((err = mp_shrink(&key->p)) != MP_OKAY)                         { goto error2; }
+   if ((err = mp_shrink(&key->q)) != MP_OKAY)                         { goto error2; }
 
-   err = CRYPT_OK;
-   key->type = PK_PRIVATE_OPTIMIZED;
+   /* set key type (in this case it's CRT optimized) */
+   key->type = PK_PRIVATE;
+
+   /* return ok and free temps */
+   err       = CRYPT_OK;
    goto done;
 error2:
    mp_clear_multi(&key->d, &key->e, &key->N, &key->dQ, &key->dP,
-                  &key->qP, &key->pQ, &key->p, &key->q, NULL);
+                  &key->qP, &key->p, &key->q, NULL);
 error:
    err = mpi_to_ltc_error(err);
 done:
@@ -111,3 +119,7 @@
 }
 
 #endif
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_make_key.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/rsa/rsa_sign_hash.c b/src/pk/rsa/rsa_sign_hash.c
new file mode 100644
index 0000000..d31bda3
--- /dev/null
+++ b/src/pk/rsa/rsa_sign_hash.c
@@ -0,0 +1,79 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_sign_hash.c
+  RSA PKCS v2 PSS sign hash, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+  (PKCS #1, v2.0) PSS pad then sign 
+  @param in        The hash to sign
+  @param inlen     The length of the hash to sign (octets)
+  @param out       [out] The signature
+  @param outlen    [in/out] The max size and resulting size of the signature 
+  @param prng      An active PRNG state
+  @param prng_idx  The index of the PRNG desired
+  @param hash_idx  The index of the hash desired
+  @param saltlen   The length of the salt desired (octets)
+  @param key       The private RSA key to use
+  @return CRYPT_OK if successful
+*/
+int rsa_sign_hash(const unsigned char *in,       unsigned long  inlen, 
+                        unsigned char *out,      unsigned long *outlen, 
+                        prng_state    *prng,     int            prng_idx,
+                        int            hash_idx, unsigned long  saltlen,
+                        rsa_key *key)
+{
+   unsigned long modulus_bitlen, modulus_bytelen, x;
+   int           err;
+   
+  LTC_ARGCHK(in       != NULL);
+  LTC_ARGCHK(out      != NULL);
+  LTC_ARGCHK(outlen   != NULL);
+  LTC_ARGCHK(key      != NULL);
+  
+  /* valid prng and hash ? */
+  if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
+     return err;
+  }
+  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+     return err;
+  }
+  
+  /* get modulus len in bits */
+  modulus_bitlen = mp_count_bits(&(key->N));
+
+  /* outlen must be at least the size of the modulus */
+  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
+  if (modulus_bytelen > *outlen) {
+     return CRYPT_BUFFER_OVERFLOW;
+  }
+      
+  /* PSS pad the key */
+  x = *outlen;
+  if ((err = pkcs_1_pss_encode(in, inlen, saltlen, prng, prng_idx,
+                               hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) {
+     return err;
+  }
+
+  /* RSA encode it */
+  return rsa_exptmod(out, x, out, outlen, PK_PRIVATE, key);
+}
+
+#endif /* MRSA */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_sign_hash.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/pk/rsa/rsa_verify_hash.c b/src/pk/rsa/rsa_verify_hash.c
new file mode 100644
index 0000000..690364d
--- /dev/null
+++ b/src/pk/rsa/rsa_verify_hash.c
@@ -0,0 +1,86 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rsa_verify_hash.c
+  RSA PKCS v2 PSS signature verification, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+  (PKCS #1, v2.0) de-sign then PSS depad
+  @param sig              The signature data
+  @param siglen           The length of the signature data (octets)
+  @param hash             The hash of the message that was signed
+  @param hashlen          The length of the hash of the message that was signed (octets)
+  @param hash_idx         The index of the desired hash
+  @param saltlen          The length of the salt used during signature
+  @param stat             [out] The result of the signature comparison, 1==valid, 0==invalid
+  @param key              The public RSA key corresponding to the key that performed the signature
+  @return CRYPT_OK on success (even if the signature is invalid)
+*/
+int rsa_verify_hash(const unsigned char *sig,      unsigned long siglen,
+                    const unsigned char *hash,     unsigned long hashlen,
+                          int            hash_idx, unsigned long saltlen,
+                          int           *stat,     rsa_key      *key)
+{
+   unsigned long modulus_bitlen, modulus_bytelen, x;
+   int           err;
+   unsigned char *tmpbuf;
+   
+  LTC_ARGCHK(hash  != NULL);
+  LTC_ARGCHK(sig      != NULL);
+  LTC_ARGCHK(stat     != NULL);
+  LTC_ARGCHK(key      != NULL);
+
+  /* default to invalid */
+  *stat = 0;
+  
+  /* valid hash ? */
+  if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+     return err;
+  }
+  
+  /* get modulus len in bits */
+  modulus_bitlen = mp_count_bits(&(key->N));
+
+  /* outlen must be at least the size of the modulus */
+  modulus_bytelen = mp_unsigned_bin_size(&(key->N));
+  if (modulus_bytelen != siglen) {
+     return CRYPT_INVALID_PACKET;
+  }
+  
+  /* allocate temp buffer for decoded sig */
+  tmpbuf = XMALLOC(siglen);
+  if (tmpbuf == NULL) {
+     return CRYPT_MEM;
+  }
+      
+  /* RSA decode it  */
+  x = siglen;
+  if ((err = rsa_exptmod(sig, siglen, tmpbuf, &x, PK_PUBLIC, key)) != CRYPT_OK) {
+     XFREE(tmpbuf);
+     return err;
+  }
+  
+  /* PSS decode it */
+  err = pkcs_1_pss_decode(hash, hashlen, tmpbuf, x, saltlen, hash_idx, modulus_bitlen, stat);
+  XFREE(tmpbuf);
+  return err;
+}
+
+#endif /* MRSA */
+
+/* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_verify_hash.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/prngs/fortuna.c b/src/prngs/fortuna.c
new file mode 100644
index 0000000..8a3b8ea
--- /dev/null
+++ b/src/prngs/fortuna.c
@@ -0,0 +1,390 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file fortuna.c
+  Fortuna PRNG, Tom St Denis
+*/
+  
+/* Implementation of Fortuna by Tom St Denis 
+
+We deviate slightly here for reasons of simplicity [and to fit in the API].  First all "sources"
+in the AddEntropy function are fixed to 0.  Second since no reliable timer is provided 
+we reseed automatically when len(pool0) >= 64 or every FORTUNA_WD calls to the read function */
+
+#ifdef FORTUNA 
+
+/* requries SHA256 and AES  */
+#if !(defined(RIJNDAEL) && defined(SHA256))
+   #error FORTUNA requires SHA256 and RIJNDAEL (AES)
+#endif
+
+#ifndef FORTUNA_POOLS
+   #warning FORTUNA_POOLS was not previously defined (old headers?)
+   #define FORTUNA_POOLS 32
+#endif
+
+#if FORTUNA_POOLS < 4 || FORTUNA_POOLS > 32
+   #error FORTUNA_POOLS must be in [4..32]
+#endif
+
+const struct ltc_prng_descriptor fortuna_desc = {
+    "fortuna", 1024,
+    &fortuna_start,
+    &fortuna_add_entropy,
+    &fortuna_ready,
+    &fortuna_read,
+    &fortuna_done,
+    &fortuna_export,
+    &fortuna_import,
+    &fortuna_test
+};
+
+/* update the IV */
+static void fortuna_update_iv(prng_state *prng)
+{
+   int            x;
+   unsigned char *IV;
+   /* update IV */
+   IV = prng->fortuna.IV;
+   for (x = 0; x < 16; x++) {
+      IV[x] = (IV[x] + 1) & 255;
+      if (IV[x] != 0) break;
+   }
+}
+
+/* reseed the PRNG */
+static int fortuna_reseed(prng_state *prng)
+{
+   unsigned char tmp[MAXBLOCKSIZE];
+   hash_state    md;
+   int           err, x;
+
+   ++prng->fortuna.reset_cnt;
+
+   /* new K == SHA256(K || s) where s == SHA256(P0) || SHA256(P1) ... */
+   sha256_init(&md);
+   if ((err = sha256_process(&md, prng->fortuna.K, 32)) != CRYPT_OK) {
+      return err;
+   }
+
+   for (x = 0; x < FORTUNA_POOLS; x++) {
+       if (x == 0 || ((prng->fortuna.reset_cnt >> (x-1)) & 1) == 0) { 
+          /* terminate this hash */
+          if ((err = sha256_done(&prng->fortuna.pool[x], tmp)) != CRYPT_OK) {
+             return err; 
+          }
+          /* add it to the string */
+          if ((err = sha256_process(&md, tmp, 32)) != CRYPT_OK) {
+             return err;
+          }
+          /* reset this pool */
+          sha256_init(&prng->fortuna.pool[x]);
+       } else {
+          break;
+       }
+   }
+
+   /* finish key */
+   if ((err = sha256_done(&md, prng->fortuna.K)) != CRYPT_OK) {
+      return err; 
+   }
+   if ((err = rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey)) != CRYPT_OK) {
+      return err;
+   }
+   fortuna_update_iv(prng);
+
+   /* reset pool len */
+   prng->fortuna.pool0_len = 0;
+   prng->fortuna.wd        = 0;
+
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(&md, sizeof(md));
+   zeromem(tmp, sizeof(tmp));
+#endif
+
+   return CRYPT_OK;
+}
+
+/**
+  Start the PRNG
+  @param prng     [out] The PRNG state to initialize
+  @return CRYPT_OK if successful
+*/  
+int fortuna_start(prng_state *prng)
+{
+   int err, x;
+
+   LTC_ARGCHK(prng != NULL);
+   
+   /* initialize the pools */
+   for (x = 0; x < FORTUNA_POOLS; x++) {
+       sha256_init(&prng->fortuna.pool[x]);
+   }
+   prng->fortuna.pool_idx = prng->fortuna.pool0_len = prng->fortuna.reset_cnt = 
+   prng->fortuna.wd = 0;
+
+   /* reset bufs */
+   zeromem(prng->fortuna.K, 32);
+   if ((err = rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey)) != CRYPT_OK) {
+      return err;
+   }
+   zeromem(prng->fortuna.IV, 16);
+
+   return CRYPT_OK;
+}
+
+/**
+  Add entropy to the PRNG state
+  @param in       The data to add
+  @param inlen    Length of the data to add
+  @param prng     PRNG state to update
+  @return CRYPT_OK if successful
+*/  
+int fortuna_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   unsigned char tmp[2];
+   int           err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   /* ensure inlen <= 32 */
+   if (inlen > 32) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   /* add s || length(in) || in to pool[pool_idx] */
+   tmp[0] = 0;
+   tmp[1] = inlen;
+   if ((err = sha256_process(&prng->fortuna.pool[prng->fortuna.pool_idx], tmp, 2)) != CRYPT_OK) {
+      return err;
+   }
+   if ((err = sha256_process(&prng->fortuna.pool[prng->fortuna.pool_idx], in, inlen)) != CRYPT_OK) {
+      return err;
+   }
+   if (prng->fortuna.pool_idx == 0) {
+      prng->fortuna.pool0_len += inlen;
+   }
+   if (++(prng->fortuna.pool_idx) == FORTUNA_POOLS) {
+      prng->fortuna.pool_idx = 0;
+   }
+
+   return CRYPT_OK;
+}
+
+/**
+  Make the PRNG ready to read from
+  @param prng   The PRNG to make active
+  @return CRYPT_OK if successful
+*/  
+int fortuna_ready(prng_state *prng)
+{
+   return fortuna_reseed(prng);
+}
+
+/**
+  Read from the PRNG
+  @param out      Destination
+  @param outlen   Length of output
+  @param prng     The active PRNG to read from
+  @return Number of octets read
+*/  
+unsigned long fortuna_read(unsigned char *out, unsigned long outlen, prng_state *prng)
+{
+   unsigned char tmp[16];
+   int           err;
+   unsigned long tlen;
+
+   LTC_ARGCHK(out  != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   /* do we have to reseed? */
+   if (++prng->fortuna.wd == FORTUNA_WD || prng->fortuna.pool0_len >= 64) {
+      if ((err = fortuna_reseed(prng)) != CRYPT_OK) {
+         return 0;
+      }
+   }
+
+   /* now generate the blocks required */
+   tlen = outlen;
+
+   /* handle whole blocks without the extra memcpy */
+   while (outlen >= 16) {
+      /* encrypt the IV and store it */
+      rijndael_ecb_encrypt(prng->fortuna.IV, out, &prng->fortuna.skey);
+      out += 16;
+      outlen -= 16;
+      fortuna_update_iv(prng);
+   }
+
+   /* left over bytes? */
+   if (outlen > 0) {
+      rijndael_ecb_encrypt(prng->fortuna.IV, tmp, &prng->fortuna.skey);
+      XMEMCPY(out, tmp, outlen);
+      fortuna_update_iv(prng);
+   }
+       
+   /* generate new key */
+   rijndael_ecb_encrypt(prng->fortuna.IV, prng->fortuna.K   , &prng->fortuna.skey); fortuna_update_iv(prng);
+   rijndael_ecb_encrypt(prng->fortuna.IV, prng->fortuna.K+16, &prng->fortuna.skey); fortuna_update_iv(prng);
+   if ((err = rijndael_setup(prng->fortuna.K, 32, 0, &prng->fortuna.skey)) != CRYPT_OK) {
+      return 0;
+   }
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(tmp, sizeof(tmp));
+#endif
+   return tlen;
+}   
+
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
+int fortuna_done(prng_state *prng)
+{
+   int           err, x;
+   unsigned char tmp[32];
+
+   LTC_ARGCHK(prng != NULL);
+
+   /* terminate all the hashes */
+   for (x = 0; x < FORTUNA_POOLS; x++) {
+       if ((err = sha256_done(&(prng->fortuna.pool[x]), tmp)) != CRYPT_OK) {
+          return err; 
+       }
+   }
+   /* call cipher done when we invent one ;-) */
+
+#ifdef LTC_CLEAN_STACK
+   zeromem(tmp, sizeof(tmp));
+#endif
+
+   return CRYPT_OK;
+}
+
+/**
+  Export the PRNG state
+  @param out       [out] Destination
+  @param outlen    [in/out] Max size and resulting size of the state
+  @param prng      The PRNG to export
+  @return CRYPT_OK if successful
+*/  
+int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
+{
+   int         x, err;
+   hash_state *md;
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(prng   != NULL);
+
+   /* we'll write bytes for s&g's */
+   if (*outlen < 32*FORTUNA_POOLS) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   md = XMALLOC(sizeof(hash_state));
+   if (md == NULL) {
+      return CRYPT_MEM;
+   }
+
+   /* to emit the state we copy each pool, terminate it then hash it again so 
+    * an attacker who sees the state can't determine the current state of the PRNG 
+    */   
+   for (x = 0; x < FORTUNA_POOLS; x++) {
+      /* copy the PRNG */
+      XMEMCPY(md, &(prng->fortuna.pool[x]), sizeof(*md));
+
+      /* terminate it */
+      if ((err = sha256_done(md, out+x*32)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+
+      /* now hash it */
+      if ((err = sha256_init(md)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+      if ((err = sha256_process(md, out+x*32, 32)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+      if ((err = sha256_done(md, out+x*32)) != CRYPT_OK) {
+         goto LBL_ERR;
+      }
+   }
+   *outlen = 32*FORTUNA_POOLS;
+   err = CRYPT_OK;
+
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
+   zeromem(md, sizeof(*md));
+#endif
+   XFREE(md);
+   return err;
+}
+ 
+/**
+  Import a PRNG state
+  @param in       The PRNG state
+  @param inlen    Size of the state
+  @param prng     The PRNG to import
+  @return CRYPT_OK if successful
+*/  
+int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   int err, x;
+
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   if (inlen != 32*FORTUNA_POOLS) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if ((err = fortuna_start(prng)) != CRYPT_OK) {
+      return err;
+   }
+   for (x = 0; x < FORTUNA_POOLS; x++) {
+      if ((err = fortuna_add_entropy(in+x*32, 32, prng)) != CRYPT_OK) {
+         return err;
+      }
+   }
+   return err;
+}
+
+/**
+  PRNG self-test
+  @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+*/  
+int fortuna_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   int err;
+
+   if ((err = sha256_test()) != CRYPT_OK) {
+      return err;
+   }
+   return rijndael_test();
+#endif
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/fortuna.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/prngs/rc4.c b/src/prngs/rc4.c
new file mode 100644
index 0000000..4d29d9a
--- /dev/null
+++ b/src/prngs/rc4.c
@@ -0,0 +1,264 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file rc4.c
+  RC4 PRNG, Tom St Denis
+*/  
+
+#ifdef RC4
+
+const struct ltc_prng_descriptor rc4_desc = 
+{
+   "rc4", 32,
+    &rc4_start,
+    &rc4_add_entropy,
+    &rc4_ready,
+    &rc4_read,
+    &rc4_done,
+    &rc4_export,
+    &rc4_import,
+    &rc4_test
+};
+
+/**
+  Start the PRNG
+  @param prng     [out] The PRNG state to initialize
+  @return CRYPT_OK if successful
+*/  
+int rc4_start(prng_state *prng)
+{
+    LTC_ARGCHK(prng != NULL);
+
+    /* set keysize to zero */
+    prng->rc4.x = 0;
+    
+    return CRYPT_OK;
+}
+
+/**
+  Add entropy to the PRNG state
+  @param in       The data to add
+  @param inlen    Length of the data to add
+  @param prng     PRNG state to update
+  @return CRYPT_OK if successful
+*/  
+int rc4_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+    LTC_ARGCHK(in  != NULL);
+    LTC_ARGCHK(prng != NULL);
+ 
+    /* trim as required */
+    if (prng->rc4.x + inlen > 256) {
+       if (prng->rc4.x == 256) {
+          /* I can't possibly accept another byte, ok maybe a mint wafer... */
+          return CRYPT_OK;
+       } else {
+          /* only accept part of it */
+          inlen = 256 - prng->rc4.x;
+       }       
+    }
+
+    while (inlen--) {
+       prng->rc4.buf[prng->rc4.x++] = *in++;
+    }
+
+    return CRYPT_OK;
+    
+}
+
+/**
+  Make the PRNG ready to read from
+  @param prng   The PRNG to make active
+  @return CRYPT_OK if successful
+*/  
+int rc4_ready(prng_state *prng)
+{
+    unsigned char key[256], tmp, *s;
+    int keylen, x, y, j;
+
+    LTC_ARGCHK(prng != NULL);
+
+    /* extract the key */
+    s = prng->rc4.buf;
+    XMEMCPY(key, s, 256);
+    keylen = prng->rc4.x;
+
+    /* make RC4 perm and shuffle */
+    for (x = 0; x < 256; x++) {
+        s[x] = x;
+    }
+
+    for (j = x = y = 0; x < 256; x++) {
+        y = (y + prng->rc4.buf[x] + key[j++]) & 255;
+        if (j == keylen) {
+           j = 0; 
+        }
+        tmp = s[x]; s[x] = s[y]; s[y] = tmp;
+    }
+    prng->rc4.x = 0;
+    prng->rc4.y = 0;
+
+#ifdef LTC_CLEAN_STACK
+    zeromem(key, sizeof(key));
+#endif
+
+    return CRYPT_OK;
+}
+
+/**
+  Read from the PRNG
+  @param out      Destination
+  @param outlen   Length of output
+  @param prng     The active PRNG to read from
+  @return Number of octets read
+*/  
+unsigned long rc4_read(unsigned char *out, unsigned long outlen, prng_state *prng)
+{
+   unsigned char x, y, *s, tmp;
+   unsigned long n;
+
+   LTC_ARGCHK(out != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   n = outlen;
+   x = prng->rc4.x;
+   y = prng->rc4.y;
+   s = prng->rc4.buf;
+   while (outlen--) {
+      x = (x + 1) & 255;
+      y = (y + s[x]) & 255;
+      tmp = s[x]; s[x] = s[y]; s[y] = tmp;
+      tmp = (s[x] + s[y]) & 255;
+      *out++ ^= s[tmp];
+   }
+   prng->rc4.x = x;
+   prng->rc4.y = y;
+   return n;
+}
+
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
+int rc4_done(prng_state *prng)
+{
+   LTC_ARGCHK(prng != NULL);
+   return CRYPT_OK;
+}
+
+/**
+  Export the PRNG state
+  @param out       [out] Destination
+  @param outlen    [in/out] Max size and resulting size of the state
+  @param prng      The PRNG to export
+  @return CRYPT_OK if successful
+*/  
+int rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
+{
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(prng   != NULL);
+
+   if (*outlen < 32) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (rc4_read(out, 32, prng) != 32) {
+      return CRYPT_ERROR_READPRNG;
+   }
+   *outlen = 32;
+
+   return CRYPT_OK;
+}
+ 
+/**
+  Import a PRNG state
+  @param in       The PRNG state
+  @param inlen    Size of the state
+  @param prng     The PRNG to import
+  @return CRYPT_OK if successful
+*/  
+int rc4_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   int err;
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   if (inlen != 32) {
+      return CRYPT_INVALID_ARG;
+   }
+   
+   if ((err = rc4_start(prng)) != CRYPT_OK) {
+      return err;
+   }
+   return rc4_add_entropy(in, 32, prng);
+}
+
+/**
+  PRNG self-test
+  @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+*/  
+int rc4_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   static const struct {
+      unsigned char key[8], pt[8], ct[8];
+   } tests[] = {
+{
+   { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
+   { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
+   { 0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96 }
+}
+};
+   prng_state prng;
+   unsigned char dst[8];
+   int err, x;
+
+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+       if ((err = rc4_start(&prng)) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = rc4_add_entropy(tests[x].key, 8, &prng)) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = rc4_ready(&prng)) != CRYPT_OK) {
+          return err;
+       }
+       XMEMCPY(dst, tests[x].pt, 8);
+       if (rc4_read(dst, 8, &prng) != 8) {
+          return CRYPT_ERROR_READPRNG;
+       }
+       rc4_done(&prng);
+       if (memcmp(dst, tests[x].ct, 8)) {
+#if 0
+          int y;
+          printf("\n\nRC4 failed, I got:\n"); 
+          for (y = 0; y < 8; y++) printf("%02x ", dst[y]);
+          printf("\n");
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+   }
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/rc4.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/rng_get_bytes.c b/src/prngs/rng_get_bytes.c
similarity index 74%
rename from rng_get_bytes.c
rename to src/prngs/rng_get_bytes.c
index f3027cd..a711dfa 100644
--- a/rng_get_bytes.c
+++ b/src/prngs/rng_get_bytes.c
@@ -6,17 +6,21 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* portable way to get secure random bits to feed a PRNG */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/** 
+   @file rng_get_bytes.c
+   portable way to get secure random bits to feed a PRNG (Tom St Denis)
+*/
 
 #ifdef DEVRANDOM
 /* on *NIX read /dev/random */
 static unsigned long rng_nix(unsigned char *buf, unsigned long len, 
                              void (*callback)(void))
 {
-#ifdef NO_FILE
+#ifdef LTC_NO_FILE
     return 0;
 #else
     FILE *f;
@@ -40,7 +44,7 @@
     x = (unsigned long)fread(buf, 1, (size_t)len, f);
     fclose(f);
     return x;
-#endif /* NO_FILE */
+#endif /* LTC_NO_FILE */
 }
 
 #endif /* DEVRANDOM */
@@ -109,21 +113,32 @@
 
 #endif /* WIN32 */
 
-unsigned long rng_get_bytes(unsigned char *buf, unsigned long len, 
+/**
+  Read the system RNG
+  @param out       Destination
+  @param outlen    Length desired (octets)
+  @param callback  Pointer to void function to act as "callback" when RNG is slow.  This can be NULL
+  @return Number of octets read
+*/     
+unsigned long rng_get_bytes(unsigned char *out, unsigned long outlen, 
                             void (*callback)(void))
 {
    unsigned long x;
 
-   _ARGCHK(buf != NULL);
+   LTC_ARGCHK(out != NULL);
 
 #if defined(DEVRANDOM)
-   x = rng_nix(buf, len, callback);   if (x != 0) { return x; }
+   x = rng_nix(out, outlen, callback);   if (x != 0) { return x; }
 #endif
 #ifdef WIN32
-   x = rng_win32(buf, len, callback); if (x != 0) { return x; }
+   x = rng_win32(out, outlen, callback); if (x != 0) { return x; }
 #endif
 #ifdef ANSI_RNG
-   x = rng_ansic(buf, len, callback); if (x != 0) { return x; }
+   x = rng_ansic(out, outlen, callback); if (x != 0) { return x; }
 #endif
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/rng_get_bytes.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/rng_make_prng.c b/src/prngs/rng_make_prng.c
similarity index 61%
rename from rng_make_prng.c
rename to src/prngs/rng_make_prng.c
index 4c30e69..51b6e6c 100644
--- a/rng_make_prng.c
+++ b/src/prngs/rng_make_prng.c
@@ -6,18 +6,30 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
  */
-/* portable way to get secure random bits to feed a PRNG */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
+/** 
+  @file rng_make_prng.c
+  portable way to get secure random bits to feed a PRNG  (Tom St Denis)
+*/
+
+/**
+  Create a PRNG from a RNG
+  @param bits     Number of bits of entropy desired (64 ... 1024)
+  @param wprng    Index of which PRNG to setup
+  @param prng     [out] PRNG state to initialize
+  @param callback A pointer to a void function for when the RNG is slow, this can be NULL
+  @return CRYPT_OK if successful
+*/  
 int rng_make_prng(int bits, int wprng, prng_state *prng, 
                   void (*callback)(void))
 {
    unsigned char buf[256];
    int err;
    
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    /* check parameter */
    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -45,9 +57,13 @@
       return err;
    }
 
-   #ifdef CLEAN_STACK
+   #ifdef LTC_CLEAN_STACK
       zeromem(buf, sizeof(buf));
    #endif
    return CRYPT_OK;
 }
 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/rng_make_prng.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/prngs/sober128.c b/src/prngs/sober128.c
new file mode 100644
index 0000000..c89f01c
--- /dev/null
+++ b/src/prngs/sober128.c
@@ -0,0 +1,495 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+ @file sober128.c
+ Implementation of SOBER-128 by Tom St Denis.
+ Based on s128fast.c reference code supplied by Greg Rose of QUALCOMM.
+*/
+
+#ifdef SOBER128
+
+#include "sober128tab.c"
+
+const struct ltc_prng_descriptor sober128_desc = 
+{
+   "sober128", 64,
+    &sober128_start,
+    &sober128_add_entropy,
+    &sober128_ready,
+    &sober128_read,
+    &sober128_done,
+    &sober128_export,
+    &sober128_import,
+    &sober128_test
+};
+
+/* don't change these... */
+#define N                        17
+#define FOLD                      N /* how many iterations of folding to do */
+#define INITKONST        0x6996c53a /* value of KONST to use during key loading */
+#define KEYP                     15 /* where to insert key words */
+#define FOLDP                     4 /* where to insert non-linear feedback */
+
+#define B(x,i) ((unsigned char)(((x) >> (8*i)) & 0xFF))
+
+static ulong32 BYTE2WORD(unsigned char *b)
+{
+   ulong32 t;
+   LOAD32L(t, b);
+   return t;
+}
+
+#define WORD2BYTE(w, b) STORE32L(b, w)
+
+static void XORWORD(ulong32 w, unsigned char *b)
+{
+   ulong32 t;
+   LOAD32L(t, b);
+   t ^= w;
+   STORE32L(t, b);
+}
+
+/* give correct offset for the current position of the register,
+ * where logically R[0] is at position "zero".
+ */
+#define OFF(zero, i) (((zero)+(i)) % N)
+
+/* step the LFSR */
+/* After stepping, "zero" moves right one place */
+#define STEP(R,z) \
+    R[OFF(z,0)] = R[OFF(z,15)] ^ R[OFF(z,4)] ^ (R[OFF(z,0)] << 8) ^ Multab[(R[OFF(z,0)] >> 24) & 0xFF];
+
+static void cycle(ulong32 *R)
+{
+    ulong32 t;
+    int     i;
+
+    STEP(R,0);
+    t = R[0];
+    for (i = 1; i < N; ++i) {
+        R[i-1] = R[i];
+    }
+    R[N-1] = t;
+}
+
+/* Return a non-linear function of some parts of the register.
+ */
+#define NLFUNC(c,z) \
+{ \
+    t = c->R[OFF(z,0)] + c->R[OFF(z,16)]; \
+    t ^= Sbox[(t >> 24) & 0xFF]; \
+    t = RORc(t, 8); \
+    t = ((t + c->R[OFF(z,1)]) ^ c->konst) + c->R[OFF(z,6)]; \
+    t ^= Sbox[(t >> 24) & 0xFF]; \
+    t = t + c->R[OFF(z,13)]; \
+}
+
+static ulong32 nltap(struct sober128_prng *c)
+{
+    ulong32 t;
+    NLFUNC(c, 0);
+    return t;
+}
+
+/**
+  Start the PRNG
+  @param prng     [out] The PRNG state to initialize
+  @return CRYPT_OK if successful
+*/  
+int sober128_start(prng_state *prng)
+{
+    int                   i;
+    struct sober128_prng *c;
+
+    LTC_ARGCHK(prng != NULL);
+
+    c = &(prng->sober128);
+    
+    /* Register initialised to Fibonacci numbers */
+    c->R[0] = 1;
+    c->R[1] = 1;
+    for (i = 2; i < N; ++i) {
+       c->R[i] = c->R[i-1] + c->R[i-2];
+    }
+    c->konst = INITKONST;
+
+    /* next add_entropy will be the key */
+    c->flag  = 1;
+    c->set   = 0;
+
+    return CRYPT_OK;
+}
+
+/* Save the current register state
+ */
+static void s128_savestate(struct sober128_prng *c)
+{
+    int i;
+    for (i = 0; i < N; ++i) {
+        c->initR[i] = c->R[i];
+    }
+}
+
+/* initialise to previously saved register state
+ */
+static void s128_reloadstate(struct sober128_prng *c)
+{
+    int i;
+
+    for (i = 0; i < N; ++i) {
+        c->R[i] = c->initR[i];
+    }
+}
+
+/* Initialise "konst"
+ */
+static void s128_genkonst(struct sober128_prng *c)
+{
+    ulong32 newkonst;
+
+    do {
+       cycle(c->R);
+       newkonst = nltap(c);
+    } while ((newkonst & 0xFF000000) == 0);
+    c->konst = newkonst;
+}
+
+/* Load key material into the register
+ */
+#define ADDKEY(k) \
+   c->R[KEYP] += (k);
+
+#define XORNL(nl) \
+   c->R[FOLDP] ^= (nl);
+
+/* nonlinear diffusion of register for key */
+#define DROUND(z) STEP(c->R,z); NLFUNC(c,(z+1)); c->R[OFF((z+1),FOLDP)] ^= t; 
+static void s128_diffuse(struct sober128_prng *c)
+{
+    ulong32 t;
+    /* relies on FOLD == N == 17! */
+    DROUND(0);
+    DROUND(1);
+    DROUND(2);
+    DROUND(3);
+    DROUND(4);
+    DROUND(5);
+    DROUND(6);
+    DROUND(7);
+    DROUND(8);
+    DROUND(9);
+    DROUND(10);
+    DROUND(11);
+    DROUND(12);
+    DROUND(13);
+    DROUND(14);
+    DROUND(15);
+    DROUND(16);
+}
+
+/**
+  Add entropy to the PRNG state
+  @param in       The data to add
+  @param inlen    Length of the data to add
+  @param prng     PRNG state to update
+  @return CRYPT_OK if successful
+*/  
+int sober128_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+    struct sober128_prng *c;
+    ulong32               i, k;
+
+    LTC_ARGCHK(in != NULL);
+    LTC_ARGCHK(prng != NULL);
+    c = &(prng->sober128);
+
+    if (c->flag == 1) {
+       /* this is the first call to the add_entropy so this input is the key */
+       /* inlen must be multiple of 4 bytes */
+       if ((inlen & 3) != 0) {
+          return CRYPT_INVALID_KEYSIZE;
+       }
+    
+       for (i = 0; i < inlen; i += 4) {
+           k = BYTE2WORD((unsigned char *)&in[i]);
+          ADDKEY(k);
+          cycle(c->R);
+          XORNL(nltap(c));
+       }
+
+       /* also fold in the length of the key */
+       ADDKEY(inlen);
+
+       /* now diffuse */
+       s128_diffuse(c);
+
+       s128_genkonst(c);
+       s128_savestate(c);
+       c->nbuf = 0;
+       c->flag = 0;       
+       c->set  = 1;
+    } else {
+       /* ok we are adding an IV then... */
+       s128_reloadstate(c);
+
+       /* inlen must be multiple of 4 bytes */
+       if ((inlen & 3) != 0) {
+          return CRYPT_INVALID_KEYSIZE;
+       }
+    
+       for (i = 0; i < inlen; i += 4) {
+           k = BYTE2WORD((unsigned char *)&in[i]);
+          ADDKEY(k);
+          cycle(c->R);
+          XORNL(nltap(c));
+       }
+
+       /* also fold in the length of the key */
+       ADDKEY(inlen);
+
+       /* now diffuse */
+       s128_diffuse(c);
+       c->nbuf = 0;
+    }
+
+    return CRYPT_OK;
+}
+
+/**
+  Make the PRNG ready to read from
+  @param prng   The PRNG to make active
+  @return CRYPT_OK if successful
+*/  
+int sober128_ready(prng_state *prng)
+{
+   return prng->sober128.set == 1 ? CRYPT_OK : CRYPT_ERROR;
+}
+
+/* XOR pseudo-random bytes into buffer
+ */
+#define SROUND(z) STEP(c->R,z); NLFUNC(c,(z+1)); XORWORD(t, out+(z*4));
+
+/**
+  Read from the PRNG
+  @param out      Destination
+  @param outlen   Length of output
+  @param prng     The active PRNG to read from
+  @return Number of octets read
+*/  
+unsigned long sober128_read(unsigned char *out, unsigned long outlen, prng_state *prng)
+{
+   struct sober128_prng *c;
+   ulong32               t, tlen;
+
+   LTC_ARGCHK(out  != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   c = &(prng->sober128);
+   t = 0;
+   tlen = outlen;
+   
+   /* handle any previously buffered bytes */
+   while (c->nbuf != 0 && outlen != 0) {
+      *out++ ^= c->sbuf & 0xFF;
+       c->sbuf >>= 8;
+       c->nbuf -= 8;
+       --outlen;
+   }
+
+#ifndef LTC_SMALL_CODE
+    /* do lots at a time, if there's enough to do */
+    while (outlen >= N*4) {
+      SROUND(0);
+      SROUND(1);
+      SROUND(2);
+      SROUND(3);
+      SROUND(4);
+      SROUND(5);
+      SROUND(6);
+      SROUND(7);
+      SROUND(8);
+      SROUND(9);
+      SROUND(10);
+      SROUND(11);
+      SROUND(12);
+      SROUND(13);
+      SROUND(14);
+      SROUND(15);
+      SROUND(16);
+      out    += 4*N;
+      outlen -= 4*N;
+    }
+#endif
+
+    /* do small or odd size buffers the slow way */
+    while (4 <= outlen) {
+      cycle(c->R);
+      t = nltap(c);
+      XORWORD(t, out);
+      out    += 4;
+      outlen -= 4;
+    }
+
+    /* handle any trailing bytes */
+    if (outlen != 0) {
+      cycle(c->R);
+      c->sbuf = nltap(c);
+      c->nbuf = 32;
+      while (c->nbuf != 0 && outlen != 0) {
+          *out++ ^= c->sbuf & 0xFF;
+          c->sbuf >>= 8;
+          c->nbuf -= 8;
+          --outlen;
+      }
+    }
+
+    return tlen;
+}
+
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
+int sober128_done(prng_state *prng)
+{
+   LTC_ARGCHK(prng != NULL);
+   return CRYPT_OK;
+}
+
+/**
+  Export the PRNG state
+  @param out       [out] Destination
+  @param outlen    [in/out] Max size and resulting size of the state
+  @param prng      The PRNG to export
+  @return CRYPT_OK if successful
+*/  
+int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
+{
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(prng   != NULL);
+
+   if (*outlen < 64) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (sober128_read(out, 64, prng) != 64) {
+      return CRYPT_ERROR_READPRNG;
+   }
+   *outlen = 64;
+
+   return CRYPT_OK;
+}
+ 
+/**
+  Import a PRNG state
+  @param in       The PRNG state
+  @param inlen    Size of the state
+  @param prng     The PRNG to import
+  @return CRYPT_OK if successful
+*/  
+int sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   int err;
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   if (inlen != 64) {
+      return CRYPT_INVALID_ARG;
+   }
+   
+   if ((err = sober128_start(prng)) != CRYPT_OK) {
+      return err;
+   }
+   if ((err = sober128_add_entropy(in, 64, prng)) != CRYPT_OK) {
+      return err;
+   }
+   return sober128_ready(prng);
+}
+
+/**
+  PRNG self-test
+  @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+*/  
+int sober128_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   static const struct { 
+     int keylen, ivlen, len;
+     unsigned char key[16], iv[4], out[20];
+   } tests[] = {
+
+{
+   16, 4, 20,
+
+   /* key */
+   { 't', 'e', 's', 't', ' ', 'k', 'e', 'y', 
+     ' ', '1', '2', '8', 'b', 'i', 't', 's' },
+
+   /* IV */
+   { 0x00, 0x00, 0x00, 0x0 },
+
+   /* expected output */
+   { 0x43, 0x50, 0x0c, 0xcf, 0x89, 0x91, 0x9f, 0x1d,
+     0xaa, 0x37, 0x74, 0x95, 0xf4, 0xb4, 0x58, 0xc2, 
+     0x40, 0x37, 0x8b, 0xbb }
+}
+
+};
+   prng_state    prng;
+   unsigned char dst[20];
+   int           err, x;
+
+   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+       if ((err = sober128_start(&prng)) != CRYPT_OK) {
+          return err;
+       }
+       if ((err = sober128_add_entropy(tests[x].key, tests[x].keylen, &prng)) != CRYPT_OK) {
+          return err;
+       }
+       /* add IV */
+       if ((err = sober128_add_entropy(tests[x].iv, tests[x].ivlen, &prng)) != CRYPT_OK) {
+          return err;
+       }
+
+       /* ready up */
+       if ((err = sober128_ready(&prng)) != CRYPT_OK) {
+          return err;
+       }
+       memset(dst, 0, tests[x].len);
+       if (sober128_read(dst, tests[x].len, &prng) != (unsigned long)tests[x].len) {
+          return CRYPT_ERROR_READPRNG;
+       }
+       sober128_done(&prng);
+       if (memcmp(dst, tests[x].out, tests[x].len)) {
+#if 0
+          printf("\n\nSOBER128 failed, I got:\n"); 
+          for (y = 0; y < tests[x].len; y++) printf("%02x ", dst[y]);
+          printf("\n");
+#endif
+          return CRYPT_FAIL_TESTVECTOR;
+       }
+   }
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/sober128.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/prngs/sober128tab.c b/src/prngs/sober128tab.c
new file mode 100644
index 0000000..b50c77b
--- /dev/null
+++ b/src/prngs/sober128tab.c
@@ -0,0 +1,162 @@
+/** 
+   @file sober128tab.c
+   SOBER-128 Tables
+*/   
+/* $Id: sober128tab.c,v 1.2 2005/05/05 14:35:59 tom Exp $ */
+/* @(#)TuringMultab.h   1.3 (QUALCOMM) 02/09/03 */
+/* Multiplication table for Turing using 0xD02B4367 */
+static const ulong32 Multab[256] = {
+    0x00000000, 0xD02B4367, 0xED5686CE, 0x3D7DC5A9,
+    0x97AC41D1, 0x478702B6, 0x7AFAC71F, 0xAAD18478,
+    0x631582EF, 0xB33EC188, 0x8E430421, 0x5E684746,
+    0xF4B9C33E, 0x24928059, 0x19EF45F0, 0xC9C40697,
+    0xC62A4993, 0x16010AF4, 0x2B7CCF5D, 0xFB578C3A,
+    0x51860842, 0x81AD4B25, 0xBCD08E8C, 0x6CFBCDEB,
+    0xA53FCB7C, 0x7514881B, 0x48694DB2, 0x98420ED5,
+    0x32938AAD, 0xE2B8C9CA, 0xDFC50C63, 0x0FEE4F04,
+    0xC154926B, 0x117FD10C, 0x2C0214A5, 0xFC2957C2,
+    0x56F8D3BA, 0x86D390DD, 0xBBAE5574, 0x6B851613,
+    0xA2411084, 0x726A53E3, 0x4F17964A, 0x9F3CD52D,
+    0x35ED5155, 0xE5C61232, 0xD8BBD79B, 0x089094FC,
+    0x077EDBF8, 0xD755989F, 0xEA285D36, 0x3A031E51,
+    0x90D29A29, 0x40F9D94E, 0x7D841CE7, 0xADAF5F80,
+    0x646B5917, 0xB4401A70, 0x893DDFD9, 0x59169CBE,
+    0xF3C718C6, 0x23EC5BA1, 0x1E919E08, 0xCEBADD6F,
+    0xCFA869D6, 0x1F832AB1, 0x22FEEF18, 0xF2D5AC7F,
+    0x58042807, 0x882F6B60, 0xB552AEC9, 0x6579EDAE,
+    0xACBDEB39, 0x7C96A85E, 0x41EB6DF7, 0x91C02E90,
+    0x3B11AAE8, 0xEB3AE98F, 0xD6472C26, 0x066C6F41,
+    0x09822045, 0xD9A96322, 0xE4D4A68B, 0x34FFE5EC,
+    0x9E2E6194, 0x4E0522F3, 0x7378E75A, 0xA353A43D,
+    0x6A97A2AA, 0xBABCE1CD, 0x87C12464, 0x57EA6703,
+    0xFD3BE37B, 0x2D10A01C, 0x106D65B5, 0xC04626D2,
+    0x0EFCFBBD, 0xDED7B8DA, 0xE3AA7D73, 0x33813E14,
+    0x9950BA6C, 0x497BF90B, 0x74063CA2, 0xA42D7FC5,
+    0x6DE97952, 0xBDC23A35, 0x80BFFF9C, 0x5094BCFB,
+    0xFA453883, 0x2A6E7BE4, 0x1713BE4D, 0xC738FD2A,
+    0xC8D6B22E, 0x18FDF149, 0x258034E0, 0xF5AB7787,
+    0x5F7AF3FF, 0x8F51B098, 0xB22C7531, 0x62073656,
+    0xABC330C1, 0x7BE873A6, 0x4695B60F, 0x96BEF568,
+    0x3C6F7110, 0xEC443277, 0xD139F7DE, 0x0112B4B9,
+    0xD31DD2E1, 0x03369186, 0x3E4B542F, 0xEE601748,
+    0x44B19330, 0x949AD057, 0xA9E715FE, 0x79CC5699,
+    0xB008500E, 0x60231369, 0x5D5ED6C0, 0x8D7595A7,
+    0x27A411DF, 0xF78F52B8, 0xCAF29711, 0x1AD9D476,
+    0x15379B72, 0xC51CD815, 0xF8611DBC, 0x284A5EDB,
+    0x829BDAA3, 0x52B099C4, 0x6FCD5C6D, 0xBFE61F0A,
+    0x7622199D, 0xA6095AFA, 0x9B749F53, 0x4B5FDC34,
+    0xE18E584C, 0x31A51B2B, 0x0CD8DE82, 0xDCF39DE5,
+    0x1249408A, 0xC26203ED, 0xFF1FC644, 0x2F348523,
+    0x85E5015B, 0x55CE423C, 0x68B38795, 0xB898C4F2,
+    0x715CC265, 0xA1778102, 0x9C0A44AB, 0x4C2107CC,
+    0xE6F083B4, 0x36DBC0D3, 0x0BA6057A, 0xDB8D461D,
+    0xD4630919, 0x04484A7E, 0x39358FD7, 0xE91ECCB0,
+    0x43CF48C8, 0x93E40BAF, 0xAE99CE06, 0x7EB28D61,
+    0xB7768BF6, 0x675DC891, 0x5A200D38, 0x8A0B4E5F,
+    0x20DACA27, 0xF0F18940, 0xCD8C4CE9, 0x1DA70F8E,
+    0x1CB5BB37, 0xCC9EF850, 0xF1E33DF9, 0x21C87E9E,
+    0x8B19FAE6, 0x5B32B981, 0x664F7C28, 0xB6643F4F,
+    0x7FA039D8, 0xAF8B7ABF, 0x92F6BF16, 0x42DDFC71,
+    0xE80C7809, 0x38273B6E, 0x055AFEC7, 0xD571BDA0,
+    0xDA9FF2A4, 0x0AB4B1C3, 0x37C9746A, 0xE7E2370D,
+    0x4D33B375, 0x9D18F012, 0xA06535BB, 0x704E76DC,
+    0xB98A704B, 0x69A1332C, 0x54DCF685, 0x84F7B5E2,
+    0x2E26319A, 0xFE0D72FD, 0xC370B754, 0x135BF433,
+    0xDDE1295C, 0x0DCA6A3B, 0x30B7AF92, 0xE09CECF5,
+    0x4A4D688D, 0x9A662BEA, 0xA71BEE43, 0x7730AD24,
+    0xBEF4ABB3, 0x6EDFE8D4, 0x53A22D7D, 0x83896E1A,
+    0x2958EA62, 0xF973A905, 0xC40E6CAC, 0x14252FCB,
+    0x1BCB60CF, 0xCBE023A8, 0xF69DE601, 0x26B6A566,
+    0x8C67211E, 0x5C4C6279, 0x6131A7D0, 0xB11AE4B7,
+    0x78DEE220, 0xA8F5A147, 0x958864EE, 0x45A32789,
+    0xEF72A3F1, 0x3F59E096, 0x0224253F, 0xD20F6658,
+};
+
+/* $Id: sober128tab.c,v 1.2 2005/05/05 14:35:59 tom Exp $ */
+/* Sbox for SOBER-128 */
+/*
+ * This is really the combination of two SBoxes; the least significant
+ * 24 bits comes from:
+ * 8->32 Sbox generated by Millan et. al. at Queensland University of
+ * Technology. See: E. Dawson, W. Millan, L. Burnett, G. Carter,
+ * "On the Design of 8*32 S-boxes". Unpublished report, by the
+ * Information Systems Research Centre,
+ * Queensland University of Technology, 1999.
+ * 
+ * The most significant 8 bits are the Skipjack "F table", which can be
+ * found at http://csrc.nist.gov/CryptoToolkit/skipjack/skipjack.pdf .
+ * In this optimised table, though, the intent is to XOR the word from
+ * the table selected by the high byte with the input word. Thus, the
+ * high byte is actually the Skipjack F-table entry XORED with its
+ * table index.
+ */
+static const ulong32 Sbox[256] = {
+    0xa3aa1887, 0xd65e435c, 0x0b65c042, 0x800e6ef4,
+    0xfc57ee20, 0x4d84fed3, 0xf066c502, 0xf354e8ae,
+    0xbb2ee9d9, 0x281f38d4, 0x1f829b5d, 0x735cdf3c,
+    0x95864249, 0xbc2e3963, 0xa1f4429f, 0xf6432c35,
+    0xf7f40325, 0x3cc0dd70, 0x5f973ded, 0x9902dc5e,
+    0xda175b42, 0x590012bf, 0xdc94d78c, 0x39aab26b,
+    0x4ac11b9a, 0x8c168146, 0xc3ea8ec5, 0x058ac28f,
+    0x52ed5c0f, 0x25b4101c, 0x5a2db082, 0x370929e1,
+    0x2a1843de, 0xfe8299fc, 0x202fbc4b, 0x833915dd,
+    0x33a803fa, 0xd446b2de, 0x46233342, 0x4fcee7c3,
+    0x3ad607ef, 0x9e97ebab, 0x507f859b, 0xe81f2e2f,
+    0xc55b71da, 0xd7e2269a, 0x1339c3d1, 0x7ca56b36,
+    0xa6c9def2, 0xb5c9fc5f, 0x5927b3a3, 0x89a56ddf,
+    0xc625b510, 0x560f85a7, 0xace82e71, 0x2ecb8816,
+    0x44951e2a, 0x97f5f6af, 0xdfcbc2b3, 0xce4ff55d,
+    0xcb6b6214, 0x2b0b83e3, 0x549ea6f5, 0x9de041af,
+    0x792f1f17, 0xf73b99ee, 0x39a65ec0, 0x4c7016c6,
+    0x857709a4, 0xd6326e01, 0xc7b280d9, 0x5cfb1418,
+    0xa6aff227, 0xfd548203, 0x506b9d96, 0xa117a8c0,
+    0x9cd5bf6e, 0xdcee7888, 0x61fcfe64, 0xf7a193cd,
+    0x050d0184, 0xe8ae4930, 0x88014f36, 0xd6a87088,
+    0x6bad6c2a, 0x1422c678, 0xe9204de7, 0xb7c2e759,
+    0x0200248e, 0x013b446b, 0xda0d9fc2, 0x0414a895,
+    0x3a6cc3a1, 0x56fef170, 0x86c19155, 0xcf7b8a66,
+    0x551b5e69, 0xb4a8623e, 0xa2bdfa35, 0xc4f068cc,
+    0x573a6acd, 0x6355e936, 0x03602db9, 0x0edf13c1,
+    0x2d0bb16d, 0x6980b83c, 0xfeb23763, 0x3dd8a911,
+    0x01b6bc13, 0xf55579d7, 0xf55c2fa8, 0x19f4196e,
+    0xe7db5476, 0x8d64a866, 0xc06e16ad, 0xb17fc515,
+    0xc46feb3c, 0x8bc8a306, 0xad6799d9, 0x571a9133,
+    0x992466dd, 0x92eb5dcd, 0xac118f50, 0x9fafb226,
+    0xa1b9cef3, 0x3ab36189, 0x347a19b1, 0x62c73084,
+    0xc27ded5c, 0x6c8bc58f, 0x1cdde421, 0xed1e47fb,
+    0xcdcc715e, 0xb9c0ff99, 0x4b122f0f, 0xc4d25184,
+    0xaf7a5e6c, 0x5bbf18bc, 0x8dd7c6e0, 0x5fb7e420,
+    0x521f523f, 0x4ad9b8a2, 0xe9da1a6b, 0x97888c02,
+    0x19d1e354, 0x5aba7d79, 0xa2cc7753, 0x8c2d9655,
+    0x19829da1, 0x531590a7, 0x19c1c149, 0x3d537f1c,
+    0x50779b69, 0xed71f2b7, 0x463c58fa, 0x52dc4418,
+    0xc18c8c76, 0xc120d9f0, 0xafa80d4d, 0x3b74c473,
+    0xd09410e9, 0x290e4211, 0xc3c8082b, 0x8f6b334a,
+    0x3bf68ed2, 0xa843cc1b, 0x8d3c0ff3, 0x20e564a0,
+    0xf8f55a4f, 0x2b40f8e7, 0xfea7f15f, 0xcf00fe21,
+    0x8a6d37d6, 0xd0d506f1, 0xade00973, 0xefbbde36,
+    0x84670fa8, 0xfa31ab9e, 0xaedab618, 0xc01f52f5,
+    0x6558eb4f, 0x71b9e343, 0x4b8d77dd, 0x8cb93da6,
+    0x740fd52d, 0x425412f8, 0xc5a63360, 0x10e53ad0,
+    0x5a700f1c, 0x8324ed0b, 0xe53dc1ec, 0x1a366795,
+    0x6d549d15, 0xc5ce46d7, 0xe17abe76, 0x5f48e0a0,
+    0xd0f07c02, 0x941249b7, 0xe49ed6ba, 0x37a47f78,
+    0xe1cfffbd, 0xb007ca84, 0xbb65f4da, 0xb59f35da,
+    0x33d2aa44, 0x417452ac, 0xc0d674a7, 0x2d61a46a,
+    0xdc63152a, 0x3e12b7aa, 0x6e615927, 0xa14fb118,
+    0xa151758d, 0xba81687b, 0xe152f0b3, 0x764254ed,
+    0x34c77271, 0x0a31acab, 0x54f94aec, 0xb9e994cd,
+    0x574d9e81, 0x5b623730, 0xce8a21e8, 0x37917f0b,
+    0xe8a9b5d6, 0x9697adf8, 0xf3d30431, 0x5dcac921,
+    0x76b35d46, 0xaa430a36, 0xc2194022, 0x22bca65e,
+    0xdaec70ba, 0xdfaea8cc, 0x777bae8b, 0x242924d5,
+    0x1f098a5a, 0x4b396b81, 0x55de2522, 0x435c1cb8,
+    0xaeb8fe1d, 0x9db3c697, 0x5b164f83, 0xe0c16376,
+    0xa319224c, 0xd0203b35, 0x433ac0fe, 0x1466a19a,
+    0x45f0b24f, 0x51fda998, 0xc0d52d71, 0xfa0896a8,
+    0xf9e6053f, 0xa4b0d300, 0xd499cbcc, 0xb95e3d40,
+};
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/sober128tab.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/prngs/sprng.c b/src/prngs/sprng.c
new file mode 100644
index 0000000..4e657da
--- /dev/null
+++ b/src/prngs/sprng.c
@@ -0,0 +1,136 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+   @file sprng.c
+   Secure PRNG, Tom St Denis
+*/
+   
+/* A secure PRNG using the RNG functions.  Basically this is a
+ * wrapper that allows you to use a secure RNG as a PRNG
+ * in the various other functions.
+ */
+
+#ifdef SPRNG
+
+const struct ltc_prng_descriptor sprng_desc =
+{
+    "sprng", 0,
+    &sprng_start,
+    &sprng_add_entropy,
+    &sprng_ready,
+    &sprng_read,
+    &sprng_done,
+    &sprng_export,
+    &sprng_import,
+    &sprng_test
+};
+
+/**
+  Start the PRNG
+  @param prng     [out] The PRNG state to initialize
+  @return CRYPT_OK if successful
+*/  
+int sprng_start(prng_state *prng)
+{
+   return CRYPT_OK;  
+}
+
+/**
+  Add entropy to the PRNG state
+  @param in       The data to add
+  @param inlen    Length of the data to add
+  @param prng     PRNG state to update
+  @return CRYPT_OK if successful
+*/  
+int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   return CRYPT_OK;
+}
+
+/**
+  Make the PRNG ready to read from
+  @param prng   The PRNG to make active
+  @return CRYPT_OK if successful
+*/  
+int sprng_ready(prng_state *prng)
+{
+   return CRYPT_OK;
+}
+
+/**
+  Read from the PRNG
+  @param out      Destination
+  @param outlen   Length of output
+  @param prng     The active PRNG to read from
+  @return Number of octets read
+*/  
+unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng)
+{
+   LTC_ARGCHK(out != NULL);
+   return rng_get_bytes(out, outlen, NULL);
+}
+
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
+int sprng_done(prng_state *prng)
+{
+   return CRYPT_OK;
+}
+
+/**
+  Export the PRNG state
+  @param out       [out] Destination
+  @param outlen    [in/out] Max size and resulting size of the state
+  @param prng      The PRNG to export
+  @return CRYPT_OK if successful
+*/  
+int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
+{
+   LTC_ARGCHK(outlen != NULL);
+
+   *outlen = 0;
+   return CRYPT_OK;
+}
+ 
+/**
+  Import a PRNG state
+  @param in       The PRNG state
+  @param inlen    Size of the state
+  @param prng     The PRNG to import
+  @return CRYPT_OK if successful
+*/  
+int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   return CRYPT_OK;
+}
+
+/**
+  PRNG self-test
+  @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+*/  
+int sprng_test(void)
+{
+   return CRYPT_OK;
+}
+
+#endif
+
+
+ 
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/sprng.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/src/prngs/yarrow.c b/src/prngs/yarrow.c
new file mode 100644
index 0000000..0e59c22
--- /dev/null
+++ b/src/prngs/yarrow.c
@@ -0,0 +1,317 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ *
+ * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
+ */
+#include "tomcrypt.h"
+
+/**
+  @file yarrow.c
+  Yarrow PRNG, Tom St Denis
+*/  
+
+#ifdef YARROW
+
+const struct ltc_prng_descriptor yarrow_desc =
+{
+    "yarrow", 64,
+    &yarrow_start,
+    &yarrow_add_entropy,
+    &yarrow_ready,
+    &yarrow_read,
+    &yarrow_done,
+    &yarrow_export,
+    &yarrow_import,
+    &yarrow_test
+};
+
+/**
+  Start the PRNG
+  @param prng     [out] The PRNG state to initialize
+  @return CRYPT_OK if successful
+*/  
+int yarrow_start(prng_state *prng)
+{
+   int err;
+   
+   LTC_ARGCHK(prng != NULL);
+
+   /* these are the default hash/cipher combo used */
+#ifdef RIJNDAEL
+#if    YARROW_AES==0
+   prng->yarrow.cipher = register_cipher(&rijndael_enc_desc);
+#elif  YARROW_AES==1
+   prng->yarrow.cipher = register_cipher(&aes_enc_desc);
+#elif  YARROW_AES==2
+   prng->yarrow.cipher = register_cipher(&rijndael_desc);
+#elif  YARROW_AES==3
+   prng->yarrow.cipher = register_cipher(&aes_desc);
+#endif
+#elif defined(BLOWFISH)
+   prng->yarrow.cipher = register_cipher(&blowfish_desc);
+#elif defined(TWOFISH)
+   prng->yarrow.cipher = register_cipher(&twofish_desc);
+#elif defined(RC6)
+   prng->yarrow.cipher = register_cipher(&rc6_desc);
+#elif defined(RC5)
+   prng->yarrow.cipher = register_cipher(&rc5_desc);
+#elif defined(SAFERP)
+   prng->yarrow.cipher = register_cipher(&saferp_desc);
+#elif defined(RC2)
+   prng->yarrow.cipher = register_cipher(&rc2_desc);
+#elif defined(NOEKEON)   
+   prng->yarrow.cipher = register_cipher(&noekeon_desc);
+#elif defined(CAST5)
+   prng->yarrow.cipher = register_cipher(&cast5_desc);
+#elif defined(XTEA)
+   prng->yarrow.cipher = register_cipher(&xtea_desc);
+#elif defined(SAFER)
+   prng->yarrow.cipher = register_cipher(&safer_sk128_desc);
+#elif defined(DES)
+   prng->yarrow.cipher = register_cipher(&des3_desc);
+#else
+   #error YARROW needs at least one CIPHER
+#endif
+   if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+#ifdef SHA256
+   prng->yarrow.hash   = register_hash(&sha256_desc);
+#elif defined(SHA512)
+   prng->yarrow.hash   = register_hash(&sha512_desc);
+#elif defined(TIGER)
+   prng->yarrow.hash   = register_hash(&tiger_desc);
+#elif defined(SHA1)
+   prng->yarrow.hash   = register_hash(&sha1_desc);
+#elif defined(RIPEMD160)
+   prng->yarrow.hash   = register_hash(&rmd160_desc);
+#elif defined(RIPEMD128)
+   prng->yarrow.hash   = register_hash(&rmd128_desc);
+#elif defined(MD5)
+   prng->yarrow.hash   = register_hash(&md5_desc);
+#elif defined(MD4)
+   prng->yarrow.hash   = register_hash(&md4_desc);
+#elif defined(MD2)
+   prng->yarrow.hash   = register_hash(&md2_desc);
+#elif defined(WHIRLPOOL)
+   prng->yarrow.hash   = register_hash(&whirlpool_desc);
+#else
+   #error YARROW needs at least one HASH
+#endif
+   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* zero the memory used */
+   zeromem(prng->yarrow.pool, sizeof(prng->yarrow.pool));
+
+   return CRYPT_OK;
+}
+
+/**
+  Add entropy to the PRNG state
+  @param in       The data to add
+  @param inlen    Length of the data to add
+  @param prng     PRNG state to update
+  @return CRYPT_OK if successful
+*/  
+int yarrow_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   hash_state md;
+   int err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* start the hash */
+   if ((err = hash_descriptor[prng->yarrow.hash].init(&md)) != CRYPT_OK) {
+      return err; 
+   }
+
+   /* hash the current pool */
+   if ((err = hash_descriptor[prng->yarrow.hash].process(&md, prng->yarrow.pool, 
+                                                        hash_descriptor[prng->yarrow.hash].hashsize)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* add the new entropy */
+   if ((err = hash_descriptor[prng->yarrow.hash].process(&md, in, inlen)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* store result */
+   if ((err = hash_descriptor[prng->yarrow.hash].done(&md, prng->yarrow.pool)) != CRYPT_OK) {
+      return err;
+   }
+
+   return CRYPT_OK;
+}
+
+/**
+  Make the PRNG ready to read from
+  @param prng   The PRNG to make active
+  @return CRYPT_OK if successful
+*/  
+int yarrow_ready(prng_state *prng)
+{
+   int ks, err;
+
+   LTC_ARGCHK(prng != NULL);
+
+   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
+      return err;
+   }
+   
+   if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
+      return err;
+   }
+
+   /* setup CTR mode using the "pool" as the key */
+   ks = (int)hash_descriptor[prng->yarrow.hash].hashsize;
+   if ((err = cipher_descriptor[prng->yarrow.cipher].keysize(&ks)) != CRYPT_OK) {
+      return err;
+   }
+
+   if ((err = ctr_start(prng->yarrow.cipher,     /* what cipher to use */
+                        prng->yarrow.pool,       /* IV */
+                        prng->yarrow.pool, ks,   /* KEY and key size */
+                        0,                       /* number of rounds */
+                        CTR_COUNTER_LITTLE_ENDIAN, /* little endian counter */
+                        &prng->yarrow.ctr)) != CRYPT_OK) {
+      return err;
+   }
+   return CRYPT_OK;
+}
+
+/**
+  Read from the PRNG
+  @param out      Destination
+  @param outlen   Length of output
+  @param prng     The active PRNG to read from
+  @return Number of octets read
+*/  
+unsigned long yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng)
+{
+   LTC_ARGCHK(out  != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   /* put out in predictable state first */
+   zeromem(out, outlen);
+   
+   /* now randomize it */
+   if (ctr_encrypt(out, out, outlen, &prng->yarrow.ctr) != CRYPT_OK) {
+      return 0;
+   }
+   return outlen;
+}
+
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
+int yarrow_done(prng_state *prng)
+{
+   LTC_ARGCHK(prng != NULL);
+
+   /* call cipher done when we invent one ;-) */
+
+   /* we invented one */
+   return ctr_done(&prng->yarrow.ctr);
+}
+
+/**
+  Export the PRNG state
+  @param out       [out] Destination
+  @param outlen    [in/out] Max size and resulting size of the state
+  @param prng      The PRNG to export
+  @return CRYPT_OK if successful
+*/  
+int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
+{
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(prng   != NULL);
+
+   /* we'll write 64 bytes for s&g's */
+   if (*outlen < 64) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+
+   if (yarrow_read(out, 64, prng) != 64) {
+      return CRYPT_ERROR_READPRNG;
+   }
+   *outlen = 64;
+
+   return CRYPT_OK;
+}
+ 
+/**
+  Import a PRNG state
+  @param in       The PRNG state
+  @param inlen    Size of the state
+  @param prng     The PRNG to import
+  @return CRYPT_OK if successful
+*/  
+int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
+{
+   int err;
+
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
+
+   if (inlen != 64) {
+      return CRYPT_INVALID_ARG;
+   }
+
+   if ((err = yarrow_start(prng)) != CRYPT_OK) {
+      return err;
+   }
+   return yarrow_add_entropy(in, 64, prng);
+}
+
+/**
+  PRNG self-test
+  @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
+*/  
+int yarrow_test(void)
+{
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
+   int err;
+   prng_state prng;
+
+   if ((err = yarrow_start(&prng)) != CRYPT_OK) {
+      return err;
+   }
+   
+   /* now let's test the hash/cipher that was chosen */
+   if ((err = cipher_descriptor[prng.yarrow.cipher].test()) != CRYPT_OK) {
+      return err; 
+   }
+   if ((err = hash_descriptor[prng.yarrow.hash].test()) != CRYPT_OK) {
+      return err; 
+   }
+
+   yarrow_done(&prng);
+   return CRYPT_OK;
+#endif
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/src/prngs/yarrow.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/strings.c b/strings.c
deleted file mode 100644
index b00cb63..0000000
--- a/strings.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* Future releases will make use of this */
-#include "mycrypt.h"
-
-static const char *err_2_str[] =
-{
-   "CRYPT_OK",
-   "CRYPT_ERROR",
-   "Non-fatal 'no-operation' requested.",
-
-   "Invalid keysize for block cipher.",
-   "Invalid number of rounds for block cipher.",
-   "Algorithm failed test vectors.",
-
-   "Buffer overflow.",
-   "Invalid input packet.",
-
-   "Invalid number of bits for a PRNG.",
-   "Error reading the PRNG.",
-
-   "Invalid cipher specified.",
-   "Invalid hash specified.",
-   "Invalid PRNG specified.",
-
-   "Out of memory.",
-
-   "Invalid PK key or key type specified for function.",
-   "A private PK key is required.",
-
-   "Invalid argument provided.",
-   "File Not Found",
-
-   "Invalid PK type.",
-   "Invalid PK system.",
-   "Duplicate PK key found on keyring.",
-   "Key not found in keyring.",
-   "Invalid sized parameter.",
-
-   "Invalid size for prime.",
-
-};
-
-#ifdef MPI
-static const struct {
-    int mpi_code, ltc_code;
-} mpi_to_ltc_codes[] = {
-   { MP_OKAY ,  CRYPT_OK},
-   { MP_MEM  ,  CRYPT_MEM},
-   { MP_VAL  ,  CRYPT_INVALID_ARG},
-};
-#endif
-
-const char *error_to_string(int err)
-{
-   if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) {
-      return "Invalid error code.";
-   } else {
-      return err_2_str[err];
-   }   
-}
-
-#ifdef MPI
-/* convert a MPI error to a LTC error (Possibly the most powerful function ever!  Oh wait... no) */
-int mpi_to_ltc_error(int err)
-{
-   int x;
-
-   for (x = 0; x < (int)(sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0])); x++) {
-       if (err == mpi_to_ltc_codes[x].mpi_code) { 
-          return mpi_to_ltc_codes[x].ltc_code;
-       }
-   }
-   return CRYPT_ERROR;
-}
-#endif
-
diff --git a/testbuild.sh b/testbuild.sh
new file mode 100644
index 0000000..a17c677
--- /dev/null
+++ b/testbuild.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+echo "$1 (Build Only, $2, $3)..."
+make clean 1>/dev/null 2>/dev/null
+echo -n "building..."
+touch testok.txt
+CFLAGS="$2" 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 && rm -f testok.txt && exit 1)
+if find testok.txt -type f 1>/dev/null 2>/dev/null ; then
+   echo "successful"
+   exit 0
+fi
+exit 1
diff --git a/testme.sh b/testme.sh
new file mode 100644
index 0000000..da0f97b
--- /dev/null
+++ b/testme.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# date
+echo "date="`date`
+
+# output version
+echo "Testing verion" `grep "^VERSION=" makefile | sed "s/.*=//"`
+#grep "VERSION=" makefile | perl -e "@a = split('=', <>); print @a[1];"`
+
+# get uname 
+echo "uname="`uname -a`
+echo
+
+# stock build
+bash run.sh "STOCK" " " $1 || exit 1
+
+# SMALL code
+bash run.sh "SMALL" "-DLTC_SMALL_CODE" $1 || exit 1
+
+# NOTABLES
+bash run.sh "NOTABLES" "-DLTC_NO_TABLES" $1 || exit 1
+
+# SMALL+NOTABLES
+bash run.sh "SMALL+NOTABLES" "-DLTC_SMALL_CODE -DLTC_NO_TABLES" $1 || exit 1
+
+# CLEANSTACK
+bash run.sh "CLEANSTACK" "-DLTC_CLEAN_STACK" $1 || exit 1
+
+# CLEANSTACK + SMALL
+bash run.sh "CLEANSTACK+SMALL" "-DLTC_SMALL_CODE -DLTC_CLEAN_STACK" $1 || exit 1
+
+# CLEANSTACK + NOTABLES
+bash run.sh "CLEANSTACK+NOTABLES" "-DLTC_NO_TABLES -DLTC_CLEAN_STACK" $1 || exit 1
+
+# CLEANSTACK + NOTABLES + SMALL
+bash run.sh "CLEANSTACK+NOTABLES+SMALL" "-DLTC_NO_TABLES -DLTC_CLEAN_STACK -DLTC_SMALL_CODE" $1 || exit 1
+
+# NO_FAST
+bash run.sh "NO_FAST" "-DLTC_NO_FAST" $1 || exit 1
+
+# NO_ASM
+bash run.sh "NO_ASM" "-DLTC_NO_ASM" $1 || exit 1
+
+# test build with no testing
+bash testbuild.sh "NOTEST" "-DLTC_NO_TEST" $1 || exit 1
+
+# test build with no file routines
+bash testbuild.sh "NOFILE" "-DLTC_NO_FILE" $1 || exit 1
+
+# $Source: /cvs/libtom/libtomcrypt/testme.sh,v $   
+# $Revision: 1.16 $   
+# $Date: 2005/05/11 18:59:53 $ 
diff --git a/testprof/base64_test.c b/testprof/base64_test.c
new file mode 100644
index 0000000..af20a67
--- /dev/null
+++ b/testprof/base64_test.c
@@ -0,0 +1,24 @@
+#include  <tomcrypt_test.h>
+
+int base64_test(void)
+{
+   unsigned char in[64], out[256], tmp[64];
+   unsigned long x, l1, l2;
+   
+   for  (x = 0; x < 64; x++) {
+       yarrow_read(in, x, &yarrow_prng);
+       l1 = sizeof(out);
+       DO(base64_encode(in, x, out, &l1));
+       l2 = sizeof(tmp);
+       DO(base64_decode(out, l1, tmp, &l2));
+       if (l2 != x || memcmp(tmp, in, x)) {
+           fprintf(stderr, "base64  failed %lu %lu %lu", x, l1, l2);
+           return 1;
+       }
+   }
+   return 0;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/base64_test.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/21 12:51:25 $ */
diff --git a/testprof/cipher_hash_test.c b/testprof/cipher_hash_test.c
new file mode 100644
index 0000000..27232e2
--- /dev/null
+++ b/testprof/cipher_hash_test.c
@@ -0,0 +1,45 @@
+/* test the ciphers and hashes using their built-in self-tests */
+
+#include <tomcrypt_test.h>
+
+int cipher_hash_test(void)
+{
+   int           x;
+   unsigned char buf[4096];
+   unsigned long n;
+   prng_state    nprng;
+   
+   /* test ciphers */
+   for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+      DO(cipher_descriptor[x].test());
+   }
+   
+   /* test hashes */
+   for (x = 0; hash_descriptor[x].name != NULL; x++) {
+      DO(hash_descriptor[x].test());
+   }
+ 
+   /* test prngs (test, import/export */
+   for (x = 0; prng_descriptor[x].name != NULL; x++) {
+      DO(prng_descriptor[x].test());
+      DO(prng_descriptor[x].start(&nprng));
+      DO(prng_descriptor[x].add_entropy((unsigned char *)"helloworld12", 12, &nprng));
+      DO(prng_descriptor[x].ready(&nprng));
+      n = sizeof(buf);
+      DO(prng_descriptor[x].pexport(buf, &n, &nprng));
+      prng_descriptor[x].done(&nprng);
+      DO(prng_descriptor[x].pimport(buf, n, &nprng));
+      DO(prng_descriptor[x].ready(&nprng));
+      if (prng_descriptor[x].read(buf, 100, &nprng) != 100) {
+         fprintf(stderr, "Error reading from imported PRNG!\n");
+         exit(EXIT_FAILURE);
+      }
+      prng_descriptor[x].done(&nprng);
+   }
+   
+   return 0;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/cipher_hash_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/testprof/der_tests.c b/testprof/der_tests.c
new file mode 100644
index 0000000..8119351
--- /dev/null
+++ b/testprof/der_tests.c
@@ -0,0 +1,370 @@
+#include <tomcrypt_test.h>
+
+#ifndef LTC_DER
+
+int der_tests(void)
+{
+   fprintf(stderr, "NOP");
+   return 0;
+}
+
+#else
+
+static int der_choice_test(void)
+{
+   ltc_asn1_list types[7], host[1];
+   unsigned char bitbuf[10], octetbuf[10], ia5buf[10], printbuf[10], outbuf[256];
+   unsigned long integer, oidbuf[10], outlen, inlen, x, y;
+   mp_int        mpinteger;
+   ltc_utctime   utctime = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
+
+   /* setup variables */
+   for (x = 0; x < sizeof(bitbuf); x++)   { bitbuf[x]   = x & 1; }
+   for (x = 0; x < sizeof(octetbuf); x++) { octetbuf[x] = x;     }
+   for (x = 0; x < sizeof(ia5buf); x++)   { ia5buf[x]   = 'a';   }
+   for (x = 0; x < sizeof(printbuf); x++) { printbuf[x] = 'a';   }
+   integer = 1;
+   for (x = 0; x < sizeof(oidbuf)/sizeof(oidbuf[0]); x++)   { oidbuf[x] = x + 1;   }
+   DO(mpi_to_ltc_error(mp_init(&mpinteger)));
+
+   for (x = 0; x < 14; x++) {
+       /* setup list */
+       LTC_SET_ASN1(types, 0, LTC_ASN1_PRINTABLE_STRING, printbuf, sizeof(printbuf));
+       LTC_SET_ASN1(types, 1, LTC_ASN1_BIT_STRING, bitbuf, sizeof(bitbuf));
+       LTC_SET_ASN1(types, 2, LTC_ASN1_OCTET_STRING, octetbuf, sizeof(octetbuf));
+       LTC_SET_ASN1(types, 3, LTC_ASN1_IA5_STRING, ia5buf, sizeof(ia5buf));
+       if (x > 7) {
+          LTC_SET_ASN1(types, 4, LTC_ASN1_SHORT_INTEGER, &integer, 1);
+       } else {
+          LTC_SET_ASN1(types, 4, LTC_ASN1_INTEGER, &mpinteger, 1);
+       }
+       LTC_SET_ASN1(types, 5, LTC_ASN1_OBJECT_IDENTIFIER, oidbuf, sizeof(oidbuf)/sizeof(oidbuf[0]));
+       LTC_SET_ASN1(types, 6, LTC_ASN1_UTCTIME, &utctime, 1);
+
+       LTC_SET_ASN1(host, 0, LTC_ASN1_CHOICE, types, 7);
+
+       
+       /* encode */
+       outlen = sizeof(outbuf);
+       DO(der_encode_sequence(&types[x>6?x-7:x], 1, outbuf, &outlen));
+
+       /* decode it */
+       inlen = outlen;
+       DO(der_decode_sequence(outbuf, inlen, &host, 1));
+
+       for (y = 0; y < 7; y++) {
+           if (types[y].used && y != (x>6?x-7:x)) {
+               fprintf(stderr, "CHOICE, flag %lu in trial %lu was incorrectly set to one\n", y, x);
+               return 1;
+           }
+           if (!types[y].used && y == (x>6?x-7:x)) {
+               fprintf(stderr, "CHOICE, flag %lu in trial %lu was incorrectly set to zero\n", y, x);
+               return 1;
+           }
+      }
+  }
+  mp_clear(&mpinteger);
+  return 0;
+}
+   
+
+int der_tests(void)
+{
+   unsigned long x, y, z, zz, oid[2][32];
+   unsigned char buf[3][2048];
+   mp_int a, b, c, d, e, f, g;
+
+   static const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
+   static const unsigned long rsa_oid[]     = { 1, 2, 840, 113549 };
+
+   static const unsigned char rsa_ia5[]     = "test1@rsa.com";
+   static const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
+                                                0x40, 0x72, 0x73, 0x61, 0x2e, 0x63, 0x6f, 0x6d };
+
+   static const unsigned char rsa_printable[] = "Test User 1";
+   static const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 
+                                                      0x73, 0x65, 0x72, 0x20, 0x31 };
+
+   static const ltc_utctime   rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
+   static const ltc_utctime   rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
+   ltc_utctime                tmp_time;
+
+   static const unsigned char rsa_time1_der[] = { 0x17, 0x11, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x31, 0x36, 0x34, 0x35, 0x34, 0x30, 0x2D, 0x30, 0x37, 0x30, 0x30 };
+   static const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
+
+   DO(mpi_to_ltc_error(mp_init_multi(&a, &b, &c, &d, &e, &f, &g, NULL)));
+   for (zz = 0; zz < 16; zz++) {
+      for (z = 0; z < 1024; z++) {
+         if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
+            fprintf(stderr, "Failed to read %lu bytes from yarrow\n", z);
+            return 1;
+         }
+         DO(mpi_to_ltc_error(mp_read_unsigned_bin(&a, buf[0], z)));
+         if (mp_iszero(&a) == MP_NO) { a.sign = buf[0][0] & 1 ? MP_ZPOS : MP_NEG; }
+         x = sizeof(buf[0]);
+         DO(der_encode_integer(&a, buf[0], &x));
+         DO(der_length_integer(&a, &y));
+         if (y != x) { fprintf(stderr, "DER INTEGER size mismatch\n"); return 1; }
+         mp_zero(&b);
+         DO(der_decode_integer(buf[0], y, &b));
+         if (y != x || mp_cmp(&a, &b) != MP_EQ) {
+            fprintf(stderr, "%lu: %lu vs %lu\n", z, x, y);
+#ifdef BN_MP_TORADIX_C
+            mp_todecimal(&a, buf[0]);
+            mp_todecimal(&b, buf[1]);
+            fprintf(stderr, "a == %s\nb == %s\n", buf[0], buf[1]);
+#endif
+            mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
+            return 1;
+         }
+      }
+   }
+
+/* test short integer */
+   for (zz = 0; zz < 256; zz++) {
+      for (z = 1; z < 4; z++) {
+         if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
+            fprintf(stderr, "Failed to read %lu bytes from yarrow\n", z);
+            return 1;
+         }
+         /* encode with normal */
+         DO(mpi_to_ltc_error(mp_read_unsigned_bin(&a, buf[0], z)));
+
+         x = sizeof(buf[0]);
+         DO(der_encode_integer(&a, buf[0], &x));
+
+         /* encode with short */
+         y = sizeof(buf[1]);
+         DO(der_encode_short_integer(mp_get_int(&a), buf[1], &y));
+         if (x != y || memcmp(buf[0], buf[1], x)) {
+            fprintf(stderr, "DER INTEGER short encoding failed, %lu, %lu\n", x, y);
+            for (z = 0; z < x; z++) fprintf(stderr, "%02x ", buf[0][z]); fprintf(stderr, "\n");
+            for (z = 0; z < y; z++) fprintf(stderr, "%02x ", buf[1][z]); fprintf(stderr, "\n");
+            mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
+            return 1;
+         }
+
+         /* decode it */
+         x = 0;
+         DO(der_decode_short_integer(buf[1], y, &x));
+         if (x != mp_get_int(&a)) {
+            fprintf(stderr, "DER INTEGER short decoding failed, %lu, %lu\n", x, mp_get_int(&a));
+            mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
+            return 1;
+         }
+      }
+   } 
+   mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
+
+   
+/* Test bit string */
+   for (zz = 1; zz < 1536; zz++) {
+       yarrow_read(buf[0], zz, &yarrow_prng);
+       for (z = 0; z < zz; z++) {
+           buf[0][z] &= 0x01;
+       }
+       x = sizeof(buf[1]);
+       DO(der_encode_bit_string(buf[0], zz, buf[1], &x));
+       DO(der_length_bit_string(zz, &y));
+       if (y != x) { 
+          fprintf(stderr, "\nDER BIT STRING length of encoded not match expected : %lu, %lu, %lu\n", z, x, y);
+          return 1;
+       }
+
+       y = sizeof(buf[2]);
+       DO(der_decode_bit_string(buf[1], x, buf[2], &y));
+       if (y != zz || memcmp(buf[0], buf[2], zz)) {
+          fprintf(stderr, "%lu, %lu, %d\n", y, zz, memcmp(buf[0], buf[2], zz));
+          return 1;
+       }
+   }
+
+/* Test octet string */
+   for (zz = 1; zz < 1536; zz++) {
+       yarrow_read(buf[0], zz, &yarrow_prng);
+       x = sizeof(buf[1]);
+       DO(der_encode_octet_string(buf[0], zz, buf[1], &x));
+       DO(der_length_octet_string(zz, &y));
+       if (y != x) { 
+          fprintf(stderr, "\nDER OCTET STRING length of encoded not match expected : %lu, %lu, %lu\n", z, x, y);
+          return 1;
+       }
+       y = sizeof(buf[2]);
+       DO(der_decode_octet_string(buf[1], x, buf[2], &y));
+       if (y != zz || memcmp(buf[0], buf[2], zz)) {
+          fprintf(stderr, "%lu, %lu, %d\n", y, zz, memcmp(buf[0], buf[2], zz));
+          return 1;
+       }
+   }
+
+/* test OID */
+   x = sizeof(buf[0]);
+   DO(der_encode_object_identifier(rsa_oid, sizeof(rsa_oid)/sizeof(rsa_oid[0]), buf[0], &x));
+   if (x != sizeof(rsa_oid_der) || memcmp(rsa_oid_der, buf[0], x)) {
+      fprintf(stderr, "rsa_oid_der encode failed to match, %lu, ", x);
+      for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]);
+      fprintf(stderr, "\n");
+      return 1;
+   }
+
+   y = sizeof(oid[0])/sizeof(oid[0][0]);
+   DO(der_decode_object_identifier(buf[0], x, oid[0], &y));
+   if (y != sizeof(rsa_oid)/sizeof(rsa_oid[0]) || memcmp(rsa_oid, oid[0], sizeof(rsa_oid))) {
+      fprintf(stderr, "rsa_oid_der decode failed to match, %lu, ", y);
+      for (z = 0; z < y; z++) fprintf(stderr, "%lu ", oid[0][z]);
+      fprintf(stderr, "\n");
+      return 1;
+   }
+
+   /* do random strings */
+   for (zz = 0; zz < 5000; zz++) {
+       /* pick a random number of words */
+       yarrow_read(buf[0], 4, &yarrow_prng);
+       LOAD32L(z, buf[0]);
+       z = 2 + (z % ((sizeof(oid[0])/sizeof(oid[0][0])) - 2));
+       
+       /* fill them in */
+       oid[0][0] = buf[0][0] % 3;
+       oid[0][1] = buf[0][1] % 40;
+
+       for (y = 2; y < z; y++) {
+          yarrow_read(buf[0], 4, &yarrow_prng);
+          LOAD32L(oid[0][y], buf[0]);
+       }
+
+       /* encode it */
+       x = sizeof(buf[0]);
+       DO(der_encode_object_identifier(oid[0], z, buf[0], &x));
+       DO(der_length_object_identifier(oid[0], z, &y));
+       if (x != y) {
+          fprintf(stderr, "Random OID %lu test failed, length mismatch: %lu, %lu\n", z, x, y);
+          for (x = 0; x < z; x++) fprintf(stderr, "%lu\n", oid[0][x]);
+          return 1;
+       }
+       
+       /* decode it */
+       y = sizeof(oid[0])/sizeof(oid[0][0]);
+       DO(der_decode_object_identifier(buf[0], x, oid[1], &y));
+       if (y != z) {
+          fprintf(stderr, "Random OID %lu test failed, decode length mismatch: %lu, %lu\n", z, x, y);
+          return 1;
+       }
+       if (memcmp(oid[0], oid[1], sizeof(oid[0][0]) * z)) {
+          fprintf(stderr, "Random OID %lu test failed, decoded values wrong\n", z);
+          for (x = 0; x < z; x++) fprintf(stderr, "%lu\n", oid[0][x]); fprintf(stderr, "\n\n Got \n\n");
+          for (x = 0; x < z; x++) fprintf(stderr, "%lu\n", oid[1][x]);
+          return 1;
+       }
+   }
+
+/* IA5 string */
+   x = sizeof(buf[0]);
+   DO(der_encode_ia5_string(rsa_ia5, strlen(rsa_ia5), buf[0], &x));
+   if (x != sizeof(rsa_ia5_der) || memcmp(buf[0], rsa_ia5_der, x)) {
+      fprintf(stderr, "IA5 encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_ia5_der));
+      return 1;
+   }
+   DO(der_length_ia5_string(rsa_ia5, strlen(rsa_ia5), &y));
+   if (y != x) {
+      fprintf(stderr, "IA5 length failed to match: %lu, %lu\n", x, y);
+      return 1;
+   }
+   y = sizeof(buf[1]);
+   DO(der_decode_ia5_string(buf[0], x, buf[1], &y));
+   if (y != strlen(rsa_ia5) || memcmp(buf[1], rsa_ia5, strlen(rsa_ia5))) {
+       fprintf(stderr, "DER IA5 failed test vector\n");
+       return 1;
+   }
+
+/* Printable string */
+   x = sizeof(buf[0]);
+   DO(der_encode_printable_string(rsa_printable, strlen(rsa_printable), buf[0], &x));
+   if (x != sizeof(rsa_printable_der) || memcmp(buf[0], rsa_printable_der, x)) {
+      fprintf(stderr, "PRINTABLE encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_printable_der));
+      return 1;
+   }
+   DO(der_length_printable_string(rsa_printable, strlen(rsa_printable), &y));
+   if (y != x) {
+      fprintf(stderr, "printable length failed to match: %lu, %lu\n", x, y);
+      return 1;
+   }
+   y = sizeof(buf[1]);
+   DO(der_decode_printable_string(buf[0], x, buf[1], &y));
+   if (y != strlen(rsa_printable) || memcmp(buf[1], rsa_printable, strlen(rsa_printable))) {
+       fprintf(stderr, "DER printable failed test vector\n");
+       return 1;
+   }
+
+/* Test UTC time */
+   x = sizeof(buf[0]);
+   DO(der_encode_utctime(&rsa_time1, buf[0], &x));
+   if (x != sizeof(rsa_time1_der) || memcmp(buf[0], rsa_time1_der, x)) {
+      fprintf(stderr, "UTCTIME encode of rsa_time1 failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_time1_der));
+fprintf(stderr, "\n\n");
+for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]); printf("\n");
+
+      return 1;
+   }
+   DO(der_length_utctime(&rsa_time1, &y));
+   if (y != x) {
+      fprintf(stderr, "UTCTIME length failed to match for rsa_time1: %lu, %lu\n", x, y);
+      return 1;
+   }
+   DO(der_decode_utctime(buf[0], &y, &tmp_time));
+   if (y != x || memcmp(&rsa_time1, &tmp_time, sizeof(ltc_utctime))) {
+      fprintf(stderr, "UTCTIME decode failed for rsa_time1: %lu %lu\n", x, y);
+fprintf(stderr, "\n\n%u %u %u %u %u %u %u %u %u\n\n", 
+tmp_time.YY,
+tmp_time.MM,
+tmp_time.DD,
+tmp_time.hh,
+tmp_time.mm,
+tmp_time.ss,
+tmp_time.off_dir,
+tmp_time.off_mm,
+tmp_time.off_hh);
+      return 1;
+   }
+
+   x = sizeof(buf[0]);
+   DO(der_encode_utctime(&rsa_time2, buf[0], &x));
+   if (x != sizeof(rsa_time2_der) || memcmp(buf[0], rsa_time2_der, x)) {
+      fprintf(stderr, "UTCTIME encode of rsa_time2 failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_time1_der));
+fprintf(stderr, "\n\n");
+for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]); printf("\n");
+
+      return 1;
+   }
+   DO(der_length_utctime(&rsa_time2, &y));
+   if (y != x) {
+      fprintf(stderr, "UTCTIME length failed to match for rsa_time2: %lu, %lu\n", x, y);
+      return 1;
+   }
+   DO(der_decode_utctime(buf[0], &y, &tmp_time));
+   if (y != x || memcmp(&rsa_time2, &tmp_time, sizeof(ltc_utctime))) {
+      fprintf(stderr, "UTCTIME decode failed for rsa_time2: %lu %lu\n", x, y);
+fprintf(stderr, "\n\n%u %u %u %u %u %u %u %u %u\n\n", 
+tmp_time.YY,
+tmp_time.MM,
+tmp_time.DD,
+tmp_time.hh,
+tmp_time.mm,
+tmp_time.ss,
+tmp_time.off_dir,
+tmp_time.off_mm,
+tmp_time.off_hh);
+
+
+      return 1;
+   }
+
+
+
+   return der_choice_test();
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/der_tests.c,v $ */
+/* $Revision: 1.25 $ */
+/* $Date: 2005/06/20 20:37:45 $ */
diff --git a/demos/test/dh_tests.c b/testprof/dh_tests.c
similarity index 61%
rename from demos/test/dh_tests.c
rename to testprof/dh_tests.c
index c2b6f0a..3852e47 100644
--- a/demos/test/dh_tests.c
+++ b/testprof/dh_tests.c
@@ -1,4 +1,6 @@
-#include "test.h"
+#include <tomcrypt_test.h>
+
+#ifdef MDH
 
 int dh_tests (void)
 {
@@ -10,8 +12,8 @@
   DO(dh_test());
 
   /* make up two keys */
-  DO(dh_make_key (&test_yarrow, find_prng ("yarrow"), 96, &usera));
-  DO(dh_make_key (&test_yarrow, find_prng ("yarrow"), 96, &userb));
+  DO(dh_make_key (&yarrow_prng, find_prng ("yarrow"), 512, &usera));
+  DO(dh_make_key (&yarrow_prng, find_prng ("yarrow"), 512, &userb));
 
   /* make the shared secret */
   x = 4096;
@@ -20,11 +22,11 @@
   y = 4096;
   DO(dh_shared_secret (&userb, &usera, buf[1], &y));
   if (y != x) {
-    printf ("DH Shared keys are not same size.\n");
+    fprintf(stderr, "DH Shared keys are not same size.\n");
     return 1;
   }
   if (memcmp (buf[0], buf[1], x)) {
-    printf ("DH Shared keys not same contents.\n");
+    fprintf(stderr, "DH Shared keys not same contents.\n");
     return 1;
   }
 
@@ -39,33 +41,33 @@
   DO(dh_shared_secret (&usera, &userb, buf[2], &z));
 
   if (z != x) {
-    printf ("failed.  Size don't match?\n");
+    fprintf(stderr, "failed.  Size don't match?\n");
     return 1;
   }
   if (memcmp (buf[0], buf[2], x)) {
-    printf ("Failed.  Content didn't match.\n");
+    fprintf(stderr, "Failed.  Content didn't match.\n");
     return 1;
   }
   dh_free (&usera);
   dh_free (&userb);
 
 /* test encrypt_key */
-  dh_make_key (&test_yarrow, find_prng ("yarrow"), 128, &usera);
+  dh_make_key (&yarrow_prng, find_prng ("yarrow"), 512, &usera);
   for (x = 0; x < 16; x++) {
     buf[0][x] = x;
   }
   y = sizeof (buf[1]);
-  DO(dh_encrypt_key (buf[0], 16, buf[1], &y, &test_yarrow, find_prng ("yarrow"), find_hash ("md5"), &usera));
+  DO(dh_encrypt_key (buf[0], 16, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("md5"), &usera));
   zeromem (buf[0], sizeof (buf[0]));
   x = sizeof (buf[0]);
   DO(dh_decrypt_key (buf[1], y, buf[0], &x, &usera));
   if (x != 16) {
-    printf ("Failed (length)\n");
+    fprintf(stderr, "Failed (length)\n");
     return 1;
   }
   for (x = 0; x < 16; x++)
     if (buf[0][x] != x) {
-      printf ("Failed (contents)\n");
+      fprintf(stderr, "Failed (contents)\n");
       return 1;
     }
 
@@ -74,14 +76,28 @@
      buf[0][x] = x;
   }
   x = sizeof (buf[1]);
-  DO(dh_sign_hash (buf[0], 16, buf[1], &x, &test_yarrow		, find_prng ("yarrow"), &usera));
+  DO(dh_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng		, find_prng ("yarrow"), &usera));
   DO(dh_verify_hash (buf[1], x, buf[0], 16, &stat, &usera));
   buf[0][0] ^= 1;
   DO(dh_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera));
   if (!(stat == 1 && stat2 == 0)) { 
-     printf("dh_sign/verify_hash %d %d", stat, stat2);
+     fprintf(stderr, "dh_sign/verify_hash %d %d", stat, stat2);
      return 1;
   }
   dh_free (&usera);
   return 0;
 }
+
+#else
+
+int dh_tests(void)
+{
+   fprintf(stderr, "NOP");
+   return 0;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/dh_tests.c,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/05/21 12:51:25 $ */
diff --git a/testprof/dsa_test.c b/testprof/dsa_test.c
new file mode 100644
index 0000000..aa4988c
--- /dev/null
+++ b/testprof/dsa_test.c
@@ -0,0 +1,68 @@
+#include <tomcrypt_test.h>
+
+#ifdef MDSA
+
+int dsa_test(void)
+{
+   unsigned char msg[16], out[1024], out2[1024];
+   unsigned long x;
+   int stat1, stat2;
+   dsa_key key, key2;
+
+   /* make a random key */
+   DO(dsa_make_key(&yarrow_prng, find_prng("yarrow"), 20, 128, &key));
+
+   /* verify it */
+   DO(dsa_verify_key(&key, &stat1));
+   if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; }
+
+   /* sign the message */
+   x = sizeof(out);
+   DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &yarrow_prng, find_prng("yarrow"), &key));
+
+   /* verify it once */
+   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key));
+
+   /* Modify and verify again */
+   msg[0] ^= 1;
+   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key));
+   msg[0] ^= 1;
+   if (!(stat1 == 1 && stat2 == 0)) { fprintf(stderr, "dsa_verify %d %d", stat1, stat2); return 1; }
+
+   /* test exporting it */
+   x = sizeof(out2);
+   DO(dsa_export(out2, &x, PK_PRIVATE, &key));
+   DO(dsa_import(out2, x, &key2));
+
+   /* verify a signature with it */
+   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
+   if (stat1 == 0) { fprintf(stderr, "dsa_verify (import private) %d ", stat1); return 1; }
+   dsa_free(&key2);
+
+   /* export as public now */
+   x = sizeof(out2);
+   DO(dsa_export(out2, &x, PK_PUBLIC, &key));
+
+   DO(dsa_import(out2, x, &key2));
+   /* verify a signature with it */
+   DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
+   if (stat1 == 0) { fprintf(stderr, "dsa_verify (import public) %d ", stat1); return 1; }
+   dsa_free(&key2);
+   dsa_free(&key);
+
+   return 0;
+}
+
+#else
+
+int dsa_test(void)
+{
+  fprintf(stderr, "NOP");
+  return 0;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/dsa_test.c,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/06/03 19:24:32 $ */
diff --git a/testprof/ecc_test.c b/testprof/ecc_test.c
new file mode 100644
index 0000000..d5f88ab
--- /dev/null
+++ b/testprof/ecc_test.c
@@ -0,0 +1,137 @@
+#include <tomcrypt_test.h>
+
+#ifdef MECC
+
+static int sizes[] = {
+#ifdef ECC192
+24,
+#endif
+#ifdef ECC224
+28,
+#endif
+#ifdef ECC256
+32,
+#endif
+#ifdef ECC384
+48,
+#endif
+#ifdef ECC512
+65
+#endif
+};
+
+int ecc_tests (void)
+{
+  unsigned char buf[4][4096];
+  unsigned long x, y, z, s;
+  int           stat, stat2;
+  ecc_key usera, userb, pubKey, privKey;
+	
+  DO(ecc_test ());
+
+  for (s = 0; s < (int)(sizeof(sizes)/sizeof(sizes[0])); s++) {
+     /* make up two keys */
+     DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
+     DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &userb));
+
+     /* make the shared secret */
+     x = 4096;
+     DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
+
+     y = 4096;
+     DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
+
+     if (y != x) {
+       fprintf(stderr, "ecc Shared keys are not same size.");
+       return 1;
+     }
+
+     if (memcmp (buf[0], buf[1], x)) {
+       fprintf(stderr, "ecc Shared keys not same contents.");
+       return 1;
+     }
+
+     /* now export userb */
+     y = 4096;
+     DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb));
+     ecc_free (&userb);
+
+     /* import and make the shared secret again */
+     DO(ecc_import (buf[1], y, &userb));
+
+     z = 4096;
+     DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
+
+     if (z != x) {
+       fprintf(stderr, "failed.  Size don't match?");
+       return 1;
+     }
+     if (memcmp (buf[0], buf[2], x)) {
+       fprintf(stderr, "Failed.  Contents didn't match.");
+       return 1;
+     }
+     ecc_free (&usera);
+     ecc_free (&userb);
+
+     /* test encrypt_key */
+     DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
+
+     /* export key */
+     x = sizeof(buf[0]);
+     DO(ecc_export(buf[0], &x, PK_PUBLIC, &usera));
+     DO(ecc_import(buf[0], x, &pubKey));
+     x = sizeof(buf[0]);
+     DO(ecc_export(buf[0], &x, PK_PRIVATE, &usera));
+     DO(ecc_import(buf[0], x, &privKey));
+
+     for (x = 0; x < 32; x++) {
+        buf[0][x] = x;
+     }
+     y = sizeof (buf[1]);
+     DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("sha256"), &pubKey));
+     zeromem (buf[0], sizeof (buf[0]));
+     x = sizeof (buf[0]);
+     DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &privKey));
+     if (x != 32) {
+       fprintf(stderr, "Failed (length)");
+       return 1;
+     }
+     for (x = 0; x < 32; x++) {
+        if (buf[0][x] != x) {
+           fprintf(stderr, "Failed (contents)");
+           return 1;
+        }
+     }
+     /* test sign_hash */
+     for (x = 0; x < 16; x++) {
+        buf[0][x] = x;
+     }
+     x = sizeof (buf[1]);
+     DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng, find_prng ("yarrow"), &privKey));
+     DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &pubKey));
+     buf[0][0] ^= 1;
+     DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &privKey));
+     if (!(stat == 1 && stat2 == 0)) { 
+        fprintf(stderr, "ecc_verify_hash failed %d, %d, ", stat, stat2);
+        return 1;
+     }
+     ecc_free (&usera); 
+     ecc_free (&pubKey);
+     ecc_free (&privKey);
+  }
+  return 0;
+}
+
+#else
+
+int ecc_tests(void)
+{
+   fprintf(stderr, "NOP");
+   return 0;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/ecc_test.c,v $ */
+/* $Revision: 1.9 $ */
+/* $Date: 2005/06/14 19:43:29 $ */
diff --git a/testprof/mac_test.c b/testprof/mac_test.c
new file mode 100644
index 0000000..3c9e902
--- /dev/null
+++ b/testprof/mac_test.c
@@ -0,0 +1,35 @@
+/* test pmac/omac/hmac */
+#include <tomcrypt_test.h>
+
+int mac_test(void)
+{
+#ifdef HMAC
+   DO(hmac_test()); 
+#endif
+#ifdef PMAC
+   DO(pmac_test()); 
+#endif
+#ifdef OMAC
+   DO(omac_test()); 
+#endif
+#ifdef EAX_MODE
+   DO(eax_test());  
+#endif
+#ifdef OCB_MODE
+   DO(ocb_test());  
+#endif
+#ifdef CCM_MODE
+   DO(ccm_test());
+#endif
+#ifdef GCM_MODE
+   DO(gcm_test());
+#endif
+#ifdef PELICAN
+   DO(pelican_test());
+#endif
+   return 0;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/mac_test.c,v $ */
+/* $Revision: 1.3 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/testprof/makefile b/testprof/makefile
new file mode 100644
index 0000000..f4be577
--- /dev/null
+++ b/testprof/makefile
@@ -0,0 +1,15 @@
+CFLAGS += -I../src/headers -I./ -Wall -W
+
+OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o                        \
+dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o                   \
+store_test.o test.o x86_prof.o
+
+default: libtomcrypt_prof.a
+
+libtomcrypt_prof.a: $(OBJECTS)
+	$(AR) $(ARFLAGS) libtomcrypt_prof.a $(OBJECTS)
+	ranlib libtomcrypt_prof.a
+
+clean:
+	rm -f *.o *.a
+
diff --git a/testprof/makefile.icc b/testprof/makefile.icc
new file mode 100644
index 0000000..ff87660
--- /dev/null
+++ b/testprof/makefile.icc
@@ -0,0 +1,15 @@
+CFLAGS += -I../src/headers -I./ 
+CC=icc
+
+OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o                        \
+dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o                   \
+store_test.o test.o x86_prof.o
+
+default: libtomcrypt_prof.a
+
+libtomcrypt_prof.a: $(OBJECTS)
+	$(AR) $(ARFLAGS) libtomcrypt_prof.a $(OBJECTS)
+
+clean:
+	rm -f *.o *.a
+
diff --git a/testprof/makefile.msvc b/testprof/makefile.msvc
new file mode 100644
index 0000000..6e15ffb
--- /dev/null
+++ b/testprof/makefile.msvc
@@ -0,0 +1,10 @@
+CFLAGS = /I../src/headers/ /I./ /Ox /DWIN32 /W3 /Fo$@
+
+OBJECTS=base64_test.obj cipher_hash_test.obj der_tests.obj dh_tests.obj \
+dsa_test.obj ecc_test.obj mac_test.obj modes_test.obj pkcs_1_test.obj \
+rsa_test.obj store_test.obj test.obj x86_prof.obj
+
+tomcrypt_prof.lib: $(OBJECTS)
+	lib /out:tomcrypt_prof.lib $(OBJECTS)
+
+
diff --git a/testprof/makefile.shared b/testprof/makefile.shared
new file mode 100644
index 0000000..b4219f0
--- /dev/null
+++ b/testprof/makefile.shared
@@ -0,0 +1,15 @@
+CC=libtool --mode=compile gcc
+
+CFLAGS += -I../src/headers -I./ -O3 -fomit-frame-pointer -funroll-loops -Wall -W
+
+OBJECTS = base64_test.o cipher_hash_test.o der_tests.o dh_tests.o                        \
+dsa_test.o ecc_test.o mac_test.o modes_test.o pkcs_1_test.o rsa_test.o                   \
+store_test.o test.o x86_prof.o
+
+default: $(LIBNAME)
+
+$(LIBNAME): $(OBJECTS)
+	libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]lo" |  xargs` -o libtomcrypt_prof.la -rpath $(LIBPATH) -version-info $(VERSION)
+	libtool --silent --mode=link gcc $(CFLAGS) `find . -type f | grep "[.]o" | xargs`  -o libtomcrypt_prof.a
+	ranlib libtomcrypt_prof.a
+	libtool --silent --mode=install install -c libtomcrypt_prof.la $(LIBPATH)/libtomcrypt_prof.la
diff --git a/demos/test/modes_test.c b/testprof/modes_test.c
similarity index 66%
rename from demos/test/modes_test.c
rename to testprof/modes_test.c
index 7494b4d..d394267 100644
--- a/demos/test/modes_test.c
+++ b/testprof/modes_test.c
@@ -1,10 +1,10 @@
 /* test CFB/OFB/CBC modes */
-#include "test.h"
+#include <tomcrypt_test.h>
 
 int modes_test(void)
 {
    unsigned char pt[64], ct[64], tmp[64], key[16], iv[16], iv2[16];
-   int x, cipher_idx;
+   int cipher_idx;
    symmetric_CBC cbc;
    symmetric_CFB cfb;
    symmetric_OFB ofb;
@@ -12,41 +12,40 @@
    unsigned long l;
    
    /* make a random pt, key and iv */
-   yarrow_read(pt,  64, &test_yarrow);
-   yarrow_read(key, 16, &test_yarrow);
-   yarrow_read(iv,  16, &test_yarrow);
+   yarrow_read(pt,  64, &yarrow_prng);
+   yarrow_read(key, 16, &yarrow_prng);
+   yarrow_read(iv,  16, &yarrow_prng);
    
    /* get idx of AES handy */
    cipher_idx = find_cipher("aes");
    if (cipher_idx == -1) {
-      printf("test requires AES");
+      fprintf(stderr, "test requires AES");
       return 1;
    }
    
+#ifdef CBC
    /* test CBC mode */
    /* encode the block */
    DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
    l = sizeof(iv2);
    DO(cbc_getiv(iv2, &l, &cbc));
    if (l != 16 || memcmp(iv2, iv, 16)) {
-      printf("cbc_getiv failed");
+      fprintf(stderr, "cbc_getiv failed");
       return 1;
    }
-   for (x = 0; x < 4; x++) {
-      DO(cbc_encrypt(pt+x*16, ct+x*16, &cbc));
-   }
+   DO(cbc_encrypt(pt, ct, 64, &cbc));
    
    /* decode the block */
    DO(cbc_setiv(iv2, l, &cbc));
    zeromem(tmp, sizeof(tmp));
-   for (x = 0; x < 4; x++) {
-      DO(cbc_decrypt(ct+x*16, tmp+x*16, &cbc));
-   }
+   DO(cbc_decrypt(ct, tmp, 64, &cbc));
    if (memcmp(tmp, pt, 64) != 0) {
-      printf("CBC failed");
+      fprintf(stderr, "CBC failed");
       return 1;
    }
-   
+#endif
+
+#ifdef CFB   
    /* test CFB mode */
    /* encode the block */
    DO(cfb_start(cipher_idx, iv, key, 16, 0, &cfb));
@@ -54,7 +53,7 @@
    DO(cfb_getiv(iv2, &l, &cfb));
    /* note we don't memcmp iv2/iv since cfb_start processes the IV for the first block */
    if (l != 16) {
-      printf("cfb_getiv failed");
+      fprintf(stderr, "cfb_getiv failed");
       return 1;
    }
    DO(cfb_encrypt(pt, ct, 64, &cfb));
@@ -64,17 +63,19 @@
    zeromem(tmp, sizeof(tmp));
    DO(cfb_decrypt(ct, tmp, 64, &cfb));
    if (memcmp(tmp, pt, 64) != 0) {
-      printf("CFB failed");
+      fprintf(stderr, "CFB failed");
       return 1;
    }
+#endif
    
+#ifdef OFB
    /* test OFB mode */
    /* encode the block */
    DO(ofb_start(cipher_idx, iv, key, 16, 0, &ofb));
    l = sizeof(iv2);
    DO(ofb_getiv(iv2, &l, &ofb));
    if (l != 16 || memcmp(iv2, iv, 16)) {
-      printf("ofb_getiv failed");
+      fprintf(stderr, "ofb_getiv failed");
       return 1;
    }
    DO(ofb_encrypt(pt, ct, 64, &ofb));
@@ -84,29 +85,36 @@
    zeromem(tmp, sizeof(tmp));
    DO(ofb_decrypt(ct, tmp, 64, &ofb));
    if (memcmp(tmp, pt, 64) != 0) {
-      printf("OFB failed");
+      fprintf(stderr, "OFB failed");
       return 1;
    }
-   
+#endif
+
+#ifdef CTR   
    /* test CTR mode */
    /* encode the block */
-   DO(ctr_start(cipher_idx, iv, key, 16, 0, &ctr));
+   DO(ctr_start(cipher_idx, iv, key, 16, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr));
    l = sizeof(iv2);
    DO(ctr_getiv(iv2, &l, &ctr));
    if (l != 16 || memcmp(iv2, iv, 16)) {
-      printf("ctr_getiv failed");
+      fprintf(stderr, "ctr_getiv failed");
       return 1;
    }
-   DO(ctr_encrypt(pt, ct, 64, &ctr));
+   DO(ctr_encrypt(pt, ct, 57, &ctr));
    
    /* decode the block */
    DO(ctr_setiv(iv2, l, &ctr));
    zeromem(tmp, sizeof(tmp));
-   DO(ctr_decrypt(ct, tmp, 64, &ctr));
-   if (memcmp(tmp, pt, 64) != 0) {
-      printf("CTR failed");
+   DO(ctr_decrypt(ct, tmp, 57, &ctr));
+   if (memcmp(tmp, pt, 57) != 0) {
+      fprintf(stderr, "CTR failed");
       return 1;
    }
+#endif
          
    return 0;
 }
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/modes_test.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/21 12:51:25 $ */
diff --git a/testprof/pkcs_1_test.c b/testprof/pkcs_1_test.c
new file mode 100644
index 0000000..1a47d85
--- /dev/null
+++ b/testprof/pkcs_1_test.c
@@ -0,0 +1,96 @@
+#include <tomcrypt_test.h>
+
+#ifdef PKCS_1
+
+int pkcs_1_test(void)
+{
+   unsigned char buf[3][128];
+   int res1, res2, res3, prng_idx, hash_idx;
+   unsigned long x, y, l1, l2, l3, i1, i2, lparamlen, saltlen, modlen;
+   static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
+
+   /* get hash/prng  */
+   hash_idx = find_hash("sha1");
+   prng_idx = find_prng("yarrow");
+   
+   if (hash_idx == -1 || prng_idx == -1) {
+      fprintf(stderr, "pkcs_1 tests require sha1/yarrow");
+      return 1;
+   }   
+
+   /* do many tests */
+   for (x = 0; x < 100; x++) {
+      zeromem(buf, sizeof(buf));
+
+      /* make a dummy message (of random length) */
+      l3 = (rand() & 31) + 8;
+      for (y = 0; y < l3; y++) buf[0][y] = rand() & 255;
+
+      /* random modulus len (v1.5 must be multiple of 8 though arbitrary sizes seem to work) */
+      modlen = 800 + 8 * (abs(rand()) % 28);
+
+      /* pick a random lparam len [0..16] */
+      lparamlen = abs(rand()) % 17;
+
+      /* pick a random saltlen 0..16 */
+      saltlen   = abs(rand()) % 17;
+
+      /* PKCS #1 v2.0 supports modlens not multiple of 8 */
+      modlen = 800 + (abs(rand()) % 224);
+
+      /* encode it */
+      l1 = sizeof(buf[1]);
+      DO(pkcs_1_oaep_encode(buf[0], l3, lparam, lparamlen, modlen, &yarrow_prng, prng_idx, hash_idx, buf[1], &l1));
+
+      /* decode it */
+      l2 = sizeof(buf[2]);
+      DO(pkcs_1_oaep_decode(buf[1], l1, lparam, lparamlen, modlen, hash_idx, buf[2], &l2, &res1));
+
+      if (res1 != 1 || l2 != l3 || memcmp(buf[2], buf[0], l3) != 0) {
+         fprintf(stderr, "Outsize == %lu, should have been %lu, res1 = %d, lparamlen = %lu, msg contents follow.\n", l2, l3, res1, lparamlen);
+         fprintf(stderr, "ORIGINAL:\n");
+         for (x = 0; x < l3; x++) {
+             fprintf(stderr, "%02x ", buf[0][x]);
+         }
+         fprintf(stderr, "\nRESULT:\n");
+         for (x = 0; x < l2; x++) {
+             fprintf(stderr, "%02x ", buf[2][x]);
+         }
+         fprintf(stderr, "\n\n");
+         return 1;
+      }
+
+      /* test PSS */
+      l1 = sizeof(buf[1]);
+      DO(pkcs_1_pss_encode(buf[0], l3, saltlen, &yarrow_prng, prng_idx, hash_idx, modlen, buf[1], &l1));
+      DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res1));
+      
+      buf[0][i1 = abs(rand()) % l3] ^= 1;
+      DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2));
+
+      buf[0][i1] ^= 1;
+      buf[1][i2 = abs(rand()) % l1] ^= 1;
+      DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3));
+
+      if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
+         fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
+         return 1;
+      }
+   }
+   return 0;
+}
+
+#else
+
+int pkcs_1_test(void)
+{
+   fprintf(stderr, "NOP");
+   return 0;
+}
+
+#endif
+
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/pkcs_1_test.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/21 12:51:25 $ */
diff --git a/testprof/rsa_test.c b/testprof/rsa_test.c
new file mode 100644
index 0000000..4facdcd
--- /dev/null
+++ b/testprof/rsa_test.c
@@ -0,0 +1,338 @@
+#include <tomcrypt_test.h>
+
+#ifdef MRSA 
+
+#define RSA_MSGSIZE 78
+
+/* These are test keys [see file test.key] that I use to test my import/export against */
+static const unsigned char openssl_private_rsa[] = {
+   0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xcf, 0x9a, 0xde, 0x64, 0x8a, 
+   0xda, 0xc8, 0x33, 0x20, 0xa9, 0xd7, 0x83, 0x31, 0x19, 0x54, 0xb2, 0x9a, 0x85, 0xa7, 0xa1, 0xb7, 
+   0x75, 0x33, 0xb6, 0xa9, 0xac, 0x84, 0x24, 0xb3, 0xde, 0xdb, 0x7d, 0x85, 0x2d, 0x96, 0x65, 0xe5, 
+   0x3f, 0x72, 0x95, 0x24, 0x9f, 0x28, 0x68, 0xca, 0x4f, 0xdb, 0x44, 0x1c, 0x3e, 0x60, 0x12, 0x8a, 
+   0xdd, 0x26, 0xa5, 0xeb, 0xff, 0x0b, 0x5e, 0xd4, 0x88, 0x38, 0x49, 0x2a, 0x6e, 0x5b, 0xbf, 0x12, 
+   0x37, 0x47, 0xbd, 0x05, 0x6b, 0xbc, 0xdb, 0xf3, 0xee, 0xe4, 0x11, 0x8e, 0x41, 0x68, 0x7c, 0x61, 
+   0x13, 0xd7, 0x42, 0xc8, 0x80, 0xbe, 0x36, 0x8f, 0xdc, 0x08, 0x8b, 0x4f, 0xac, 0xa4, 0xe2, 0x76, 
+   0x0c, 0xc9, 0x63, 0x6c, 0x49, 0x58, 0x93, 0xed, 0xcc, 0xaa, 0xdc, 0x25, 0x3b, 0x0a, 0x60, 0x3f, 
+   0x8b, 0x54, 0x3a, 0xc3, 0x4d, 0x31, 0xe7, 0x94, 0xa4, 0x44, 0xfd, 0x02, 0x03, 0x01, 0x00, 0x01, 
+   0x02, 0x81, 0x81, 0x00, 0xc8, 0x62, 0xb9, 0xea, 0xde, 0x44, 0x53, 0x1d, 0x56, 0x97, 0xd9, 0x97, 
+   0x9e, 0x1a, 0xcf, 0x30, 0x1e, 0x0a, 0x88, 0x45, 0x86, 0x29, 0x30, 0xa3, 0x4d, 0x9f, 0x61, 0x65, 
+   0x73, 0xe0, 0xd6, 0x87, 0x8f, 0xb6, 0xf3, 0x06, 0xa3, 0x82, 0xdc, 0x7c, 0xac, 0xfe, 0x9b, 0x28, 
+   0x9a, 0xae, 0xfd, 0xfb, 0xfe, 0x2f, 0x0e, 0xd8, 0x97, 0x04, 0xe3, 0xbb, 0x1f, 0xd1, 0xec, 0x0d, 
+   0xba, 0xa3, 0x49, 0x7f, 0x47, 0xac, 0x8a, 0x44, 0x04, 0x7e, 0x86, 0xb7, 0x39, 0x42, 0x3f, 0xad, 
+   0x1e, 0xb7, 0x0e, 0xa5, 0x51, 0xf4, 0x40, 0x63, 0x1e, 0xfd, 0xbd, 0xea, 0x9f, 0x41, 0x9f, 0xa8, 
+   0x90, 0x1d, 0x6f, 0x0a, 0x5a, 0x95, 0x13, 0x11, 0x0d, 0x80, 0xaf, 0x5f, 0x64, 0x98, 0x8a, 0x2c, 
+   0x78, 0x68, 0x65, 0xb0, 0x2b, 0x8b, 0xa2, 0x53, 0x87, 0xca, 0xf1, 0x64, 0x04, 0xab, 0xf2, 0x7b, 
+   0xdb, 0x83, 0xc8, 0x81, 0x02, 0x41, 0x00, 0xf7, 0xbe, 0x5e, 0x23, 0xc3, 0x32, 0x3f, 0xbf, 0x8b, 
+   0x8e, 0x3a, 0xee, 0xfc, 0xfc, 0xcb, 0xe5, 0xf7, 0xf1, 0x0b, 0xbc, 0x42, 0x82, 0xae, 0xd5, 0x7a, 
+   0x3e, 0xca, 0xf7, 0xd5, 0x69, 0x3f, 0x64, 0x25, 0xa2, 0x1f, 0xb7, 0x75, 0x75, 0x05, 0x92, 0x42, 
+   0xeb, 0xb8, 0xf1, 0xf3, 0x0a, 0x05, 0xe3, 0x94, 0xd1, 0x55, 0x78, 0x35, 0xa0, 0x36, 0xa0, 0x9b, 
+   0x7c, 0x92, 0x84, 0x6c, 0xdd, 0xdc, 0x4d, 0x02, 0x41, 0x00, 0xd6, 0x86, 0x0e, 0x85, 0x42, 0x0b, 
+   0x04, 0x08, 0x84, 0x21, 0x60, 0xf0, 0x0e, 0x0d, 0x88, 0xfd, 0x1e, 0x36, 0x10, 0x65, 0x4f, 0x1e, 
+   0x53, 0xb4, 0x08, 0x72, 0x80, 0x5c, 0x3f, 0x59, 0x66, 0x17, 0xe6, 0x98, 0xf2, 0xe9, 0x6c, 0x7a, 
+   0x06, 0x4c, 0xac, 0x76, 0x3d, 0xed, 0x8c, 0xa1, 0xce, 0xad, 0x1b, 0xbd, 0xb4, 0x7d, 0x28, 0xbc, 
+   0xe3, 0x0e, 0x38, 0x8d, 0x99, 0xd8, 0x05, 0xb5, 0xa3, 0x71, 0x02, 0x40, 0x6d, 0xeb, 0xc3, 0x2d, 
+   0x2e, 0xf0, 0x5e, 0xa4, 0x88, 0x31, 0x05, 0x29, 0x00, 0x8a, 0xd1, 0x95, 0x29, 0x9b, 0x83, 0xcf, 
+   0x75, 0xdb, 0x31, 0xe3, 0x7a, 0x27, 0xde, 0x3a, 0x74, 0x30, 0x0c, 0x76, 0x4c, 0xd4, 0x50, 0x2a, 
+   0x40, 0x2d, 0x39, 0xd9, 0x99, 0x63, 0xa9, 0x5d, 0x80, 0xae, 0x53, 0xca, 0x94, 0x3f, 0x05, 0x23, 
+   0x1e, 0xf8, 0x05, 0x04, 0xe1, 0xb8, 0x35, 0xf2, 0x17, 0xb3, 0xa0, 0x89, 0x02, 0x41, 0x00, 0xab, 
+   0x90, 0x88, 0xfa, 0x60, 0x08, 0x29, 0x50, 0x9a, 0x43, 0x8b, 0xa0, 0x50, 0xcc, 0xd8, 0x5a, 0xfe, 
+   0x97, 0x64, 0x63, 0x71, 0x74, 0x22, 0xa3, 0x20, 0x02, 0x5a, 0xcf, 0xeb, 0xc6, 0x16, 0x95, 0x54, 
+   0xd1, 0xcb, 0xab, 0x8d, 0x1a, 0xc6, 0x00, 0xfa, 0x08, 0x92, 0x9c, 0x71, 0xd5, 0x52, 0x52, 0x35, 
+   0x96, 0x71, 0x4b, 0x8b, 0x92, 0x0c, 0xd0, 0xe9, 0xbf, 0xad, 0x63, 0x0b, 0xa5, 0xe9, 0xb1, 0x02, 
+   0x41, 0x00, 0xdc, 0xcc, 0x27, 0xc8, 0xe4, 0xdc, 0x62, 0x48, 0xd5, 0x9b, 0xaf, 0xf5, 0xab, 0x60, 
+   0xf6, 0x21, 0xfd, 0x53, 0xe2, 0xb7, 0x5d, 0x09, 0xc9, 0x1a, 0xa1, 0x04, 0xa9, 0xfc, 0x61, 0x2c, 
+   0x5d, 0x04, 0x58, 0x3a, 0x5a, 0x39, 0xf1, 0x4a, 0x21, 0x56, 0x67, 0xfd, 0xcc, 0x20, 0xa3, 0x8f, 
+   0x78, 0x18, 0x5a, 0x79, 0x3d, 0x2e, 0x8e, 0x7e, 0x86, 0x0a, 0xe6, 0xa8, 0x33, 0xc1, 0x04, 0x17, 
+   0x4a, 0x9f,  };
+
+
+/*** NOTE:  OpenSSL seems to have more to their public key format.  I've stripped the extra headers... */
+static const unsigned char openssl_public_rsa[] = {
+   0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xcf, 0x9a, 0xde, 
+   0x64, 0x8a, 0xda, 0xc8, 0x33, 0x20, 0xa9, 0xd7, 0x83, 0x31, 0x19, 0x54, 0xb2, 0x9a, 0x85, 0xa7, 
+   0xa1, 0xb7, 0x75, 0x33, 0xb6, 0xa9, 0xac, 0x84, 0x24, 0xb3, 0xde, 0xdb, 0x7d, 0x85, 0x2d, 0x96, 
+   0x65, 0xe5, 0x3f, 0x72, 0x95, 0x24, 0x9f, 0x28, 0x68, 0xca, 0x4f, 0xdb, 0x44, 0x1c, 0x3e, 0x60, 
+   0x12, 0x8a, 0xdd, 0x26, 0xa5, 0xeb, 0xff, 0x0b, 0x5e, 0xd4, 0x88, 0x38, 0x49, 0x2a, 0x6e, 0x5b, 
+   0xbf, 0x12, 0x37, 0x47, 0xbd, 0x05, 0x6b, 0xbc, 0xdb, 0xf3, 0xee, 0xe4, 0x11, 0x8e, 0x41, 0x68, 
+   0x7c, 0x61, 0x13, 0xd7, 0x42, 0xc8, 0x80, 0xbe, 0x36, 0x8f, 0xdc, 0x08, 0x8b, 0x4f, 0xac, 0xa4, 
+   0xe2, 0x76, 0x0c, 0xc9, 0x63, 0x6c, 0x49, 0x58, 0x93, 0xed, 0xcc, 0xaa, 0xdc, 0x25, 0x3b, 0x0a, 
+   0x60, 0x3f, 0x8b, 0x54, 0x3a, 0xc3, 0x4d, 0x31, 0xe7, 0x94, 0xa4, 0x44, 0xfd, 0x02, 0x03, 0x01, 
+   0x00, 0x01,  };
+
+static int rsa_compat_test(void)
+{
+   rsa_key key;
+   unsigned char buf[1024];
+   unsigned long len;
+
+   /* try reading the key */
+   DO(rsa_import(openssl_private_rsa, sizeof(openssl_private_rsa), &key));
+
+   /* now try to export private/public and compare */
+   len = sizeof(buf);
+   DO(rsa_export(buf, &len, PK_PRIVATE, &key));
+   if (len != sizeof(openssl_private_rsa) || memcmp(buf, openssl_private_rsa, len)) {
+      fprintf(stderr, "RSA private export failed to match OpenSSL output, %lu, %lu\n", len, sizeof(openssl_private_rsa));
+
+
+{
+int x;
+printf("\n\n");
+for (x = 0; x < len; ) { if (buf[x] == openssl_private_rsa[x]) printf("-- "); else printf("%02x ", buf[x]^openssl_private_rsa[x]); if (!(++x & 15)) printf("\n"); }
+}
+printf("\n\n");
+
+      return 1;
+   }
+
+   len = sizeof(buf);
+   DO(rsa_export(buf, &len, PK_PUBLIC, &key));
+   if (len != sizeof(openssl_public_rsa) || memcmp(buf, openssl_public_rsa, len)) {
+      fprintf(stderr, "RSA(private) public export failed to match OpenSSL output\n");
+      return 1;
+   }
+   rsa_free(&key);
+
+   /* try reading the public key */
+   DO(rsa_import(openssl_public_rsa, sizeof(openssl_public_rsa), &key));
+   len = sizeof(buf);
+   DO(rsa_export(buf, &len, PK_PUBLIC, &key));
+   if (len != sizeof(openssl_public_rsa) || memcmp(buf, openssl_public_rsa, len)) {
+      fprintf(stderr, "RSA(public) public export failed to match OpenSSL output\n");
+      return 1;
+   }
+   rsa_free(&key);
+
+   return 0;
+}   
+
+int rsa_test(void)
+{
+   unsigned char in[1024], out[1024], tmp[1024];
+   rsa_key       key, privKey, pubKey;
+   int           hash_idx, prng_idx, stat, stat2;
+   unsigned long rsa_msgsize, len, len2, cnt;
+   static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
+
+   if (rsa_compat_test() != 0) {
+      return 1;
+   }
+      
+   hash_idx = find_hash("sha1");
+   prng_idx = find_prng("yarrow");
+   if (hash_idx == -1 || prng_idx == -1) {
+      fprintf(stderr, "rsa_test requires SHA1 and yarrow");
+      return 1;
+   }
+   
+   /* make 10 random key */
+   for (cnt = 0; cnt < 10; cnt++) {
+      DO(rsa_make_key(&yarrow_prng, prng_idx, 1024/8, 65537, &key));
+      if (mp_count_bits(&key.N) != 1024) {
+         fprintf(stderr, "rsa_1024 key modulus has %d bits\n", mp_count_bits(&key.N));
+
+len = mp_unsigned_bin_size(&key.N);
+mp_to_unsigned_bin(&key.N, tmp);
+ fprintf(stderr, "N == \n");
+for (cnt = 0; cnt < len; ) {
+   fprintf(stderr, "%02x ", tmp[cnt]);
+   if (!(++cnt & 15)) fprintf(stderr, "\n");
+}
+
+len = mp_unsigned_bin_size(&key.p);
+mp_to_unsigned_bin(&key.p, tmp);
+ fprintf(stderr, "p == \n");
+for (cnt = 0; cnt < len; ) {
+   fprintf(stderr, "%02x ", tmp[cnt]);
+   if (!(++cnt & 15)) fprintf(stderr, "\n");
+}
+
+len = mp_unsigned_bin_size(&key.q);
+mp_to_unsigned_bin(&key.q, tmp);
+ fprintf(stderr, "\nq == \n");
+for (cnt = 0; cnt < len; ) {
+   fprintf(stderr, "%02x ", tmp[cnt]);
+   if (!(++cnt & 15)) fprintf(stderr, "\n");
+}
+ fprintf(stderr, "\n");
+
+
+         return 1;
+      }
+      if (cnt != 9) {
+         rsa_free(&key);
+      }
+   }
+    
+   /* encrypt the key (without lparam) */
+   for (cnt = 0; cnt < 4; cnt++) {
+   for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
+      /* make a random key/msg */
+      yarrow_read(in, rsa_msgsize, &yarrow_prng);
+
+      len  = sizeof(out);
+      len2 = rsa_msgsize;
+   
+      DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, hash_idx, &key));
+      /* change a byte */
+      out[8] ^= 1;
+      DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat2, &key));
+      /* change a byte back */
+      out[8] ^= 1;
+      if (len2 != rsa_msgsize) {
+         fprintf(stderr, "\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
+         return 1;
+      }
+
+      len2 = rsa_msgsize;
+      DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat, &key));
+      if (!(stat == 1 && stat2 == 0)) {
+         fprintf(stderr, "rsa_decrypt_key failed");
+         return 1;
+      }
+      if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
+         unsigned long x;
+         fprintf(stderr, "\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
+         fprintf(stderr, "Original contents: \n"); 
+         for (x = 0; x < rsa_msgsize; ) {
+             fprintf(stderr, "%02x ", in[x]);
+             if (!(++x % 16)) {
+                fprintf(stderr, "\n");
+             }
+         }
+         fprintf(stderr, "\n");
+         fprintf(stderr, "Output contents: \n"); 
+         for (x = 0; x < rsa_msgsize; ) {
+             fprintf(stderr, "%02x ", out[x]);
+             if (!(++x % 16)) {
+                fprintf(stderr, "\n");
+             }
+         }     
+         fprintf(stderr, "\n");
+         return 1;
+      }
+   }
+   }
+
+   /* encrypt the key (with lparam) */
+   for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
+      len  = sizeof(out);
+      len2 = rsa_msgsize;
+      DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, lparam, sizeof(lparam), &yarrow_prng, prng_idx, hash_idx, &key));
+      /* change a byte */
+      out[8] ^= 1;
+      DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key));
+      if (len2 != rsa_msgsize) {
+         fprintf(stderr, "\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
+         return 1;
+      }
+      /* change a byte back */
+      out[8] ^= 1;
+
+      len2 = rsa_msgsize;
+      DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat, &key));
+      if (!(stat == 1 && stat2 == 0)) {
+         fprintf(stderr, "rsa_decrypt_key failed");
+         return 1;
+      }
+      if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
+         fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2);
+         return 1;
+      }
+   }
+
+   /* sign a message (unsalted, lower cholestorol and Atkins approved) now */
+   len = sizeof(out);
+   DO(rsa_sign_hash(in, 20, out, &len, &yarrow_prng, prng_idx, hash_idx, 0, &key));
+
+/* export key and import as both private and public */
+   len2 = sizeof(tmp);
+   DO(rsa_export(tmp, &len2, PK_PRIVATE, &key)); 
+   DO(rsa_import(tmp, len2, &privKey)); 
+   len2 = sizeof(tmp);
+   DO(rsa_export(tmp, &len2, PK_PUBLIC, &key));
+   DO(rsa_import(tmp, len2, &pubKey));
+
+   /* verify with original */
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &key));
+   /* change a byte */
+   in[0] ^= 1;
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &key));
+   
+   if (!(stat == 1 && stat2 == 0)) {
+      fprintf(stderr, "rsa_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2);
+      rsa_free(&key);
+      rsa_free(&pubKey);
+      rsa_free(&privKey);
+      return 1;
+   }
+
+   /* verify with privKey */
+   /* change a byte */
+   in[0] ^= 1;
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &privKey));
+   /* change a byte */
+   in[0] ^= 1;
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey));
+   
+   if (!(stat == 1 && stat2 == 0)) {
+      fprintf(stderr, "rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
+      rsa_free(&key);
+      rsa_free(&pubKey);
+      rsa_free(&privKey);
+      return 1;
+   }
+
+   /* verify with pubKey */
+   /* change a byte */
+   in[0] ^= 1;
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &pubKey));
+   /* change a byte */
+   in[0] ^= 1;
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &pubKey));
+   
+   if (!(stat == 1 && stat2 == 0)) {
+      fprintf(stderr, "rsa_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2);
+      rsa_free(&key);
+      rsa_free(&pubKey);
+      rsa_free(&privKey);
+      return 1;
+   }
+
+   /* sign a message (salted) now (use privKey to make, pubKey to verify) */
+   len = sizeof(out);
+   DO(rsa_sign_hash(in, 20, out, &len, &yarrow_prng, prng_idx, hash_idx, 8, &privKey));
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 8, &stat, &pubKey));
+   /* change a byte */
+   in[0] ^= 1;
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 8, &stat2, &pubKey));
+   
+   if (!(stat == 1 && stat2 == 0)) {
+      fprintf(stderr, "rsa_verify_hash (salted) failed, %d, %d", stat, stat2);
+      rsa_free(&key);
+      rsa_free(&pubKey);
+      rsa_free(&privKey);
+      return 1;
+   }
+   
+   /* free the key and return */
+   rsa_free(&key);
+   rsa_free(&pubKey);
+   rsa_free(&privKey);
+   return 0;
+}
+
+#else
+
+int rsa_test(void)
+{
+   fprintf(stderr, "NOP");
+   return 0;
+}
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/rsa_test.c,v $ */
+/* $Revision: 1.10 $ */
+/* $Date: 2005/06/03 19:18:33 $ */
diff --git a/testprof/store_test.c b/testprof/store_test.c
new file mode 100644
index 0000000..5a38d65
--- /dev/null
+++ b/testprof/store_test.c
@@ -0,0 +1,78 @@
+#include <tomcrypt_test.h>
+
+/* Test store/load macros with offsets */
+int store_test(void)
+{
+  unsigned char buf[256];
+  int y;
+  ulong32 L, L1;
+  ulong64 LL, LL1;
+#ifdef LTC_FAST
+  int x, z;
+#endif
+
+  for (y = 0; y < 4; y++) {
+      L  = 0x12345678UL;
+      L1 = 0;
+      STORE32L(L, buf + y);
+      LOAD32L(L1, buf + y);
+      if (L1 != L) {
+         fprintf(stderr, "\n32L failed at offset %d\n", y);
+         return 1;
+      }
+      STORE32H(L, buf + y);
+      LOAD32H(L1, buf + y);
+      if (L1 != L) {
+         fprintf(stderr, "\n32H failed at offset %d\n", y);
+         return 1;
+      }
+  }
+
+  for (y = 0; y < 8; y++) {
+      LL = CONST64 (0x01020304050607);
+      LL1 = 0;
+      STORE64L(LL, buf + y);
+      LOAD64L(LL1, buf + y);
+      if (LL1 != LL) {
+         fprintf(stderr, "\n64L failed at offset %d\n", y);
+         return 1;
+      }
+      STORE64H(LL, buf + y);
+      LOAD64H(LL1, buf + y);
+      if (LL1 != LL) {
+         fprintf(stderr, "\n64H failed at offset %d\n", y);
+         return 1;
+      }
+  }
+
+/* test LTC_FAST */
+#ifdef LTC_FAST
+  y = 16;
+
+  for (z = 0; z < y; z++) {
+     /* fill y bytes with random */
+     yarrow_read(buf+z,   y, &yarrow_prng);
+     yarrow_read(buf+z+y, y, &yarrow_prng);
+
+     /* now XOR it byte for byte */
+     for (x = 0; x < y; x++) {
+         buf[2*y+z+x] = buf[z+x] ^ buf[z+y+x];
+     }
+
+     /* now XOR it word for word */
+     for (x = 0; x < y; x += sizeof(LTC_FAST_TYPE)) {
+        *((LTC_FAST_TYPE*)(&buf[3*y+z+x])) = *((LTC_FAST_TYPE*)(&buf[z+x])) ^ *((LTC_FAST_TYPE*)(&buf[z+y+x]));
+     }
+
+     if (memcmp(&buf[2*y+z], &buf[3*y+z], y)) {
+        fprintf(stderr, "\nLTC_FAST failed at offset %d\n", z);
+        return 1;
+     }
+  }
+#endif
+  return 0;
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/store_test.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/testprof/test.c b/testprof/test.c
new file mode 100644
index 0000000..5a38421
--- /dev/null
+++ b/testprof/test.c
@@ -0,0 +1,13 @@
+#include <tomcrypt_test.h>
+
+void run_cmd(int res, int line, char *file, char *cmd)
+{
+   if (res != CRYPT_OK) {
+      fprintf(stderr, "%s (%d)\n%s:%d:%s\n", error_to_string(res), res, file, line, cmd);
+      exit(EXIT_FAILURE);
+   }
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/test.c,v $ */
+/* $Revision: 1.6 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/testprof/test.key b/testprof/test.key
new file mode 100644
index 0000000..e4996c3
--- /dev/null
+++ b/testprof/test.key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQDPmt5kitrIMyCp14MxGVSymoWnobd1M7aprIQks97bfYUtlmXl
+P3KVJJ8oaMpP20QcPmASit0mpev/C17UiDhJKm5bvxI3R70Fa7zb8+7kEY5BaHxh
+E9dCyIC+No/cCItPrKTidgzJY2xJWJPtzKrcJTsKYD+LVDrDTTHnlKRE/QIDAQAB
+AoGBAMhiuereRFMdVpfZl54azzAeCohFhikwo02fYWVz4NaHj7bzBqOC3Hys/pso
+mq79+/4vDtiXBOO7H9HsDbqjSX9HrIpEBH6GtzlCP60etw6lUfRAYx79veqfQZ+o
+kB1vClqVExENgK9fZJiKLHhoZbAri6JTh8rxZASr8nvbg8iBAkEA975eI8MyP7+L
+jjru/PzL5ffxC7xCgq7Vej7K99VpP2Qloh+3dXUFkkLruPHzCgXjlNFVeDWgNqCb
+fJKEbN3cTQJBANaGDoVCCwQIhCFg8A4NiP0eNhBlTx5TtAhygFw/WWYX5pjy6Wx6
+Bkysdj3tjKHOrRu9tH0ovOMOOI2Z2AW1o3ECQG3rwy0u8F6kiDEFKQCK0ZUpm4PP
+ddsx43on3jp0MAx2TNRQKkAtOdmZY6ldgK5TypQ/BSMe+AUE4bg18hezoIkCQQCr
+kIj6YAgpUJpDi6BQzNha/pdkY3F0IqMgAlrP68YWlVTRy6uNGsYA+giSnHHVUlI1
+lnFLi5IM0Om/rWMLpemxAkEA3MwnyOTcYkjVm6/1q2D2If1T4rddCckaoQSp/GEs
+XQRYOlo58UohVmf9zCCjj3gYWnk9Lo5+hgrmqDPBBBdKnw==
+-----END RSA PRIVATE KEY-----
diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h
new file mode 100644
index 0000000..2c66bad
--- /dev/null
+++ b/testprof/tomcrypt_test.h
@@ -0,0 +1,77 @@
+
+#ifndef __TEST_H_
+#define __TEST_H_
+
+#include <tomcrypt.h>
+
+/* enable stack testing */
+// #define STACK_TEST
+
+/* stack testing, define this if stack usage goes downwards [e.g. x86] */
+#define STACK_DOWN
+
+typedef struct {
+    char *name, *prov, *req;
+    int  (*entry)(void);
+} test_entry;
+
+extern prng_state yarrow_prng;
+
+void run_cmd(int res, int line, char *file, char *cmd);
+#define DO(x) { run_cmd((x), __LINE__, __FILE__, #x); }
+
+/* TESTS */
+int cipher_hash_test(void);
+int modes_test(void);
+int mac_test(void);
+int pkcs_1_test(void);
+int store_test(void);
+int rsa_test(void);
+int ecc_tests(void);
+int dsa_test(void);
+int dh_tests(void);
+int der_tests(void);
+
+/* timing */
+#define KTIMES  25
+#define TIMES   100000
+
+extern struct list {
+    int id;
+    unsigned long spd1, spd2, avg;
+} results[];
+
+extern int no_results;
+
+int sorter(const void *a, const void *b);
+void tally_results(int type);
+ulong64 rdtsc (void);
+
+void t_start(void);
+ulong64 t_read(void);
+void init_timer(void);
+
+/* register default algs */
+void reg_algs(void);
+int time_keysched(void);
+int time_cipher(void);
+int time_cipher2(void);
+int time_cipher3(void);
+int time_hash(void);
+void time_mult(void);
+void time_sqr(void);
+void time_prng(void);
+void time_rsa(void);
+void time_ecc(void);
+void time_dh(void);
+void time_macs_(unsigned long MAC_SIZE);
+void time_macs(void);
+void time_encmacs(void);
+
+
+
+#endif
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/tomcrypt_test.h,v $ */
+/* $Revision: 1.8 $ */
+/* $Date: 2005/05/05 14:35:59 $ */
diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c
new file mode 100644
index 0000000..997180c
--- /dev/null
+++ b/testprof/x86_prof.c
@@ -0,0 +1,1050 @@
+#include <tomcrypt_test.h>
+
+prng_state yarrow_prng;
+
+struct list results[100];
+int no_results;
+int sorter(const void *a, const void *b)
+{
+   const struct list *A, *B;
+   A = a;
+   B = b;
+   if (A->avg < B->avg) return -1;
+   if (A->avg > B->avg) return 1;
+   return 0;
+}
+
+void tally_results(int type)
+{
+   int x;
+
+   // qsort the results
+   qsort(results, no_results, sizeof(struct list), &sorter);
+
+   fprintf(stderr, "\n");
+   if (type == 0) {
+      for (x = 0; x < no_results; x++) {
+         fprintf(stderr, "%-20s: Schedule at %6lu\n", cipher_descriptor[results[x].id].name, (unsigned long)results[x].spd1);
+      } 
+   } else if (type == 1) {
+      for (x = 0; x < no_results; x++) {
+        printf
+          ("%-20s[%3d]: Encrypt at %5lu, Decrypt at %5lu\n", cipher_descriptor[results[x].id].name, cipher_descriptor[results[x].id].ID, results[x].spd1, results[x].spd2);
+      }
+   } else {
+      for (x = 0; x < no_results; x++) {
+        printf
+          ("%-20s: Process at %5lu\n", hash_descriptor[results[x].id].name, results[x].spd1 / 1000);
+      }
+   }
+}
+
+/* RDTSC from Scott Duplichan */
+ulong64 rdtsc (void)
+   {
+   #if defined __GNUC__ && !defined(LTC_NO_ASM)
+      #ifdef INTEL_CC
+			ulong64 a;
+			asm ( " rdtsc ":"=A"(a));
+         return a;
+      #elif defined(__i386__) || defined(__x86_64__)
+         ulong64 a;
+         asm __volatile__ ("rdtsc\nmovl %%eax,(%0)\nmovl %%edx,4(%0)\n"::"r"(&a):"%eax","%edx");
+         return a;
+      #elif defined(__ia64__)  /* gcc-IA64 version */
+         unsigned long result;
+         __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
+         while (__builtin_expect ((int) result == -1, 0))
+         __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
+         return result;
+      #else 
+         return XCLOCK();
+      #endif
+
+   // Microsoft and Intel Windows compilers
+   #elif defined _M_IX86 && !defined(LTC_NO_ASM)
+     __asm rdtsc
+   #elif defined _M_AMD64 && !defined(LTC_NO_ASM)
+     return __rdtsc ();
+   #elif defined _M_IA64 && !defined(LTC_NO_ASM)
+     #if defined __INTEL_COMPILER
+       #include <ia64intrin.h>
+     #endif
+      return __getReg (3116);
+   #else
+     return XCLOCK();
+   #endif
+   }
+
+static ulong64 timer, skew = 0;
+
+void t_start(void)
+{
+   timer = rdtsc();
+}
+
+ulong64 t_read(void)
+{
+   return rdtsc() - timer;
+}
+
+void init_timer(void)
+{
+   ulong64 c1, c2, t1, t2, t3;
+   unsigned long y1;
+
+   c1 = c2 = (ulong64)-1;
+   for (y1 = 0; y1 < TIMES*100; y1++) {
+      t_start();
+      t1 = t_read();
+      t3 = t_read();
+      t2 = (t_read() - t1)>>1;
+
+      c1 = (t1 > c1) ? t1 : c1;
+      c2 = (t2 > c2) ? t2 : c2;
+   }
+   skew = c2 - c1;
+   fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew);
+}
+
+void reg_algs(void)
+{
+  int err;
+#ifdef RIJNDAEL
+  register_cipher (&aes_desc);
+#endif
+#ifdef BLOWFISH
+  register_cipher (&blowfish_desc);
+#endif
+#ifdef XTEA
+  register_cipher (&xtea_desc);
+#endif
+#ifdef RC5
+  register_cipher (&rc5_desc);
+#endif
+#ifdef RC6
+  register_cipher (&rc6_desc);
+#endif
+#ifdef SAFERP
+  register_cipher (&saferp_desc);
+#endif
+#ifdef TWOFISH
+  register_cipher (&twofish_desc);
+#endif
+#ifdef SAFER
+  register_cipher (&safer_k64_desc);
+  register_cipher (&safer_sk64_desc);
+  register_cipher (&safer_k128_desc);
+  register_cipher (&safer_sk128_desc);
+#endif
+#ifdef RC2
+  register_cipher (&rc2_desc);
+#endif
+#ifdef DES
+  register_cipher (&des_desc);
+  register_cipher (&des3_desc);
+#endif
+#ifdef CAST5
+  register_cipher (&cast5_desc);
+#endif
+#ifdef NOEKEON
+  register_cipher (&noekeon_desc);
+#endif
+#ifdef SKIPJACK
+  register_cipher (&skipjack_desc);
+#endif
+#ifdef KHAZAD
+  register_cipher (&khazad_desc);
+#endif
+#ifdef ANUBIS
+  register_cipher (&anubis_desc);
+#endif
+
+#ifdef TIGER
+  register_hash (&tiger_desc);
+#endif
+#ifdef MD2
+  register_hash (&md2_desc);
+#endif
+#ifdef MD4
+  register_hash (&md4_desc);
+#endif
+#ifdef MD5
+  register_hash (&md5_desc);
+#endif
+#ifdef SHA1
+  register_hash (&sha1_desc);
+#endif
+#ifdef SHA224
+  register_hash (&sha224_desc);
+#endif
+#ifdef SHA256
+  register_hash (&sha256_desc);
+#endif
+#ifdef SHA384
+  register_hash (&sha384_desc);
+#endif
+#ifdef SHA512
+  register_hash (&sha512_desc);
+#endif
+#ifdef RIPEMD128
+  register_hash (&rmd128_desc);
+#endif
+#ifdef RIPEMD160
+  register_hash (&rmd160_desc);
+#endif
+#ifdef WHIRLPOOL
+  register_hash (&whirlpool_desc);
+#endif
+#ifdef CHC_HASH
+  register_hash(&chc_desc);
+  if ((err = chc_register(register_cipher(&aes_desc))) != CRYPT_OK) {
+     fprintf(stderr, "chc_register error: %s\n", error_to_string(err));
+     exit(EXIT_FAILURE);
+  }
+#endif
+
+
+#ifndef YARROW 
+   #error This demo requires Yarrow.
+#endif
+register_prng(&yarrow_desc);
+#ifdef FORTUNA
+register_prng(&fortuna_desc);
+#endif
+#ifdef RC4
+register_prng(&rc4_desc);
+#endif
+#ifdef SOBER128
+register_prng(&sober128_desc);
+#endif
+
+rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL);
+}
+
+int time_keysched(void)
+{
+  unsigned long x, y1;
+  ulong64 t1, c1;
+  symmetric_key skey;
+  int kl;
+  int    (*func) (const unsigned char *, int , int , symmetric_key *);
+  unsigned char key[MAXBLOCKSIZE];
+
+  fprintf(stderr, "\n\nKey Schedule Time Trials for the Symmetric Ciphers:\n(Times are cycles per key)\n");
+  no_results = 0; 
+ for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+#define DO1(k)   func(k, kl, 0, &skey);
+
+    func = cipher_descriptor[x].setup;
+    kl   = cipher_descriptor[x].min_key_length;
+    c1 = (ulong64)-1;
+    for (y1 = 0; y1 < KTIMES; y1++) {
+       yarrow_read(key, kl, &yarrow_prng);
+       t_start();
+       DO1(key);
+       t1 = t_read();
+       c1 = (t1 > c1) ? c1 : t1;
+    }
+    t1 = c1 - skew;
+    results[no_results].spd1 = results[no_results].avg = t1;
+    results[no_results++].id = x;
+    fprintf(stderr, "."); fflush(stdout);
+
+#undef DO1
+   }
+   tally_results(0);
+
+   return 0;
+}
+
+int time_cipher(void)
+{
+  unsigned long x, y1;
+  ulong64  t1, t2, c1, c2, a1, a2;
+  symmetric_ECB ecb;
+  unsigned char key[MAXBLOCKSIZE], pt[4096];
+  int err;
+
+  fprintf(stderr, "\n\nECB Time Trials for the Symmetric Ciphers:\n");
+  no_results = 0;
+  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+    ecb_start(x, key, cipher_descriptor[x].min_key_length, 0, &ecb);
+
+    /* sanity check on cipher */
+    if ((err = cipher_descriptor[x].test()) != CRYPT_OK) {
+       fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err));
+       exit(EXIT_FAILURE);
+    }
+
+#define DO1   ecb_encrypt(pt, pt, sizeof(pt), &ecb);
+#define DO2   DO1 DO1
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < 100; y1++) {
+        t_start();
+        DO1;
+        t1 = t_read();
+        DO2;
+        t2 = t_read();
+        t2 -= t1;
+
+        c1 = (t1 > c1 ? c1 : t1);
+        c2 = (t2 > c2 ? c2 : t2);
+    }
+    a1 = c2 - c1 - skew;
+
+#undef DO1
+#undef DO2
+#define DO1   ecb_decrypt(pt, pt, sizeof(pt), &ecb);
+#define DO2   DO1 DO1
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < 100; y1++) {
+        t_start();
+        DO1;
+        t1 = t_read();
+        DO2;
+        t2 = t_read();
+        t2 -= t1;
+
+        c1 = (t1 > c1 ? c1 : t1);
+        c2 = (t2 > c2 ? c2 : t2);
+    }
+    a2 = c2 - c1 - skew;
+    
+    results[no_results].id = x;
+    results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
+    results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length);
+    results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
+    ++no_results;
+    fprintf(stderr, "."); fflush(stdout);
+    
+#undef DO2
+#undef DO1
+   }
+   tally_results(1);
+
+   return 0;
+}
+
+#ifdef CBC 
+int time_cipher2(void)
+{
+  unsigned long x, y1;
+  ulong64  t1, t2, c1, c2, a1, a2;
+  symmetric_CBC cbc;
+  unsigned char key[MAXBLOCKSIZE], pt[4096];
+  int err;
+
+  fprintf(stderr, "\n\nCBC Time Trials for the Symmetric Ciphers:\n");
+  no_results = 0;
+  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+    cbc_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, &cbc);
+
+    /* sanity check on cipher */
+    if ((err = cipher_descriptor[x].test()) != CRYPT_OK) {
+       fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err));
+       exit(EXIT_FAILURE);
+    }
+
+#define DO1   cbc_encrypt(pt, pt, sizeof(pt), &cbc);
+#define DO2   DO1 DO1
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < 100; y1++) {
+        t_start();
+        DO1;
+        t1 = t_read();
+        DO2;
+        t2 = t_read();
+        t2 -= t1;
+
+        c1 = (t1 > c1 ? c1 : t1);
+        c2 = (t2 > c2 ? c2 : t2);
+    }
+    a1 = c2 - c1 - skew;
+
+#undef DO1
+#undef DO2
+#define DO1   cbc_decrypt(pt, pt, sizeof(pt), &cbc);
+#define DO2   DO1 DO1
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < 100; y1++) {
+        t_start();
+        DO1;
+        t1 = t_read();
+        DO2;
+        t2 = t_read();
+        t2 -= t1;
+
+        c1 = (t1 > c1 ? c1 : t1);
+        c2 = (t2 > c2 ? c2 : t2);
+    }
+    a2 = c2 - c1 - skew;
+    
+    results[no_results].id = x;
+    results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
+    results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length);
+    results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
+    ++no_results;
+    fprintf(stderr, "."); fflush(stdout);
+    
+#undef DO2
+#undef DO1
+   }
+   tally_results(1);
+
+   return 0;
+}
+#else
+int time_cipher2(void) { fprintf(stderr, "NO CBC\n"); return 0; }
+#endif
+
+#ifdef CTR
+int time_cipher3(void)
+{
+  unsigned long x, y1;
+  ulong64  t1, t2, c1, c2, a1, a2;
+  symmetric_CTR ctr;
+  unsigned char key[MAXBLOCKSIZE], pt[4096];
+  int err;
+
+  fprintf(stderr, "\n\nCTR Time Trials for the Symmetric Ciphers:\n");
+  no_results = 0;
+  for (x = 0; cipher_descriptor[x].name != NULL; x++) {
+    ctr_start(x, pt, key, cipher_descriptor[x].min_key_length, 0, CTR_COUNTER_LITTLE_ENDIAN, &ctr);
+
+    /* sanity check on cipher */
+    if ((err = cipher_descriptor[x].test()) != CRYPT_OK) {
+       fprintf(stderr, "\n\nERROR: Cipher %s failed self-test %s\n", cipher_descriptor[x].name, error_to_string(err));
+       exit(EXIT_FAILURE);
+    }
+
+#define DO1   ctr_encrypt(pt, pt, sizeof(pt), &ctr);
+#define DO2   DO1 DO1
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < 100; y1++) {
+        t_start();
+        DO1;
+        t1 = t_read();
+        DO2;
+        t2 = t_read();
+        t2 -= t1;
+
+        c1 = (t1 > c1 ? c1 : t1);
+        c2 = (t2 > c2 ? c2 : t2);
+    }
+    a1 = c2 - c1 - skew;
+
+#undef DO1
+#undef DO2
+#define DO1   ctr_decrypt(pt, pt, sizeof(pt), &ctr);
+#define DO2   DO1 DO1
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < 100; y1++) {
+        t_start();
+        DO1;
+        t1 = t_read();
+        DO2;
+        t2 = t_read();
+        t2 -= t1;
+
+        c1 = (t1 > c1 ? c1 : t1);
+        c2 = (t2 > c2 ? c2 : t2);
+    }
+    a2 = c2 - c1 - skew;
+    
+    results[no_results].id = x;
+    results[no_results].spd1 = a1/(sizeof(pt)/cipher_descriptor[x].block_length);
+    results[no_results].spd2 = a2/(sizeof(pt)/cipher_descriptor[x].block_length);
+    results[no_results].avg = (results[no_results].spd1 + results[no_results].spd2+1)/2;
+    ++no_results;
+    fprintf(stderr, "."); fflush(stdout);
+    
+#undef DO2
+#undef DO1
+   }
+   tally_results(1);
+
+   return 0;
+}
+#else
+int time_cipher3(void) { fprintf(stderr, "NO CTR\n"); return 0; }
+#endif
+
+int time_hash(void)
+{
+  unsigned long x, y1, len;
+  ulong64 t1, t2, c1, c2;
+  hash_state md;
+  int    (*func)(hash_state *, const unsigned char *, unsigned long), err;
+  unsigned char pt[MAXBLOCKSIZE];
+
+
+  fprintf(stderr, "\n\nHASH Time Trials for:\n");
+  no_results = 0;
+  for (x = 0; hash_descriptor[x].name != NULL; x++) {
+
+    /* sanity check on hash */
+    if ((err = hash_descriptor[x].test()) != CRYPT_OK) {
+       fprintf(stderr, "\n\nERROR: Hash %s failed self-test %s\n", hash_descriptor[x].name, error_to_string(err));
+       exit(EXIT_FAILURE);
+    }
+
+    hash_descriptor[x].init(&md);
+
+#define DO1   func(&md,pt,len);
+#define DO2   DO1 DO1
+
+    func = hash_descriptor[x].process;
+    len  = hash_descriptor[x].blocksize;
+
+    c1 = c2 = (ulong64)-1;
+    for (y1 = 0; y1 < TIMES; y1++) {
+       t_start();
+       DO1;
+       t1 = t_read();
+       DO2;
+       t2 = t_read() - t1;
+       c1 = (t1 > c1) ? c1 : t1;
+       c2 = (t2 > c2) ? c2 : t2;
+    }
+    t1 = c2 - c1 - skew;
+    t1 = ((t1 * CONST64(1000))) / ((ulong64)hash_descriptor[x].blocksize);
+    results[no_results].id = x;
+    results[no_results].spd1 = results[no_results].avg = t1;
+    ++no_results;
+    fprintf(stderr, "."); fflush(stdout);
+#undef DO2
+#undef DO1
+   }
+   tally_results(2);
+
+   return 0;
+}
+
+#ifdef MPI
+void time_mult(void)
+{
+   ulong64 t1, t2;
+   unsigned long x, y;
+   mp_int  a, b, c;
+
+   fprintf(stderr, "Timing Multiplying:\n");
+   mp_init_multi(&a,&b,&c,NULL);
+   for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {
+       mp_rand(&a, x);
+       mp_rand(&b, x);
+
+#define DO1 mp_mul(&a, &b, &c);
+#define DO2 DO1; DO1;
+
+       t2 = -1;
+       for (y = 0; y < TIMES; y++) {
+           t_start();
+           t1 = t_read();
+           DO2;
+           t1 = (t_read() - t1)>>1;
+           if (t1 < t2) t2 = t1;
+       }
+       fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
+   }
+   mp_clear_multi(&a,&b,&c,NULL);
+
+#undef DO1
+#undef DO2
+} 
+
+void time_sqr(void)
+{
+   ulong64 t1, t2;
+   unsigned long x, y;
+   mp_int  a, b;
+
+   fprintf(stderr, "Timing Squaring:\n");
+   mp_init_multi(&a,&b,NULL);
+   for (x = 128/DIGIT_BIT; x <= 1536/DIGIT_BIT; x += 128/DIGIT_BIT) {
+       mp_rand(&a, x);
+
+#define DO1 mp_sqr(&a, &b);
+#define DO2 DO1; DO1;
+
+       t2 = -1;
+       for (y = 0; y < TIMES; y++) {
+           t_start();
+           t1 = t_read();
+           DO2;
+           t1 = (t_read() - t1)>>1;
+           if (t1 < t2) t2 = t1;
+       }
+       fprintf(stderr, "%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
+   }
+   mp_clear_multi(&a,&b,NULL);
+
+#undef DO1
+#undef DO2
+}
+#else
+void time_mult(void) { fprintf(stderr, "NO MULT\n"); }
+void time_sqr(void) { fprintf(stderr, "NO SQR\n"); }
+#endif
+   
+void time_prng(void)
+{
+   ulong64 t1, t2;
+   unsigned char buf[4096];
+   prng_state tprng;
+   unsigned long x, y;
+   int           err;
+
+   fprintf(stderr, "Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) :\n");
+   for (x = 0; prng_descriptor[x].name != NULL; x++) {
+
+      /* sanity check on prng */
+      if ((err = prng_descriptor[x].test()) != CRYPT_OK) {
+         fprintf(stderr, "\n\nERROR: PRNG %s failed self-test %s\n", prng_descriptor[x].name, error_to_string(err));
+         exit(EXIT_FAILURE);
+      }
+
+      prng_descriptor[x].start(&tprng);
+      zeromem(buf, 256);
+      prng_descriptor[x].add_entropy(buf, 256, &tprng);
+      prng_descriptor[x].ready(&tprng);
+      t2 = -1;
+
+#define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); }
+#define DO2 DO1 DO1
+      for (y = 0; y < 10000; y++) {
+         t_start();
+         t1 = t_read();
+         DO2;
+         t1 = (t_read() - t1)>>1;
+         if (t1 < t2) t2 = t1;
+      }
+      fprintf(stderr, "%20s: %5llu ", prng_descriptor[x].name, t2>>12);
+#undef DO2
+#undef DO1
+
+#define DO1 prng_descriptor[x].start(&tprng); prng_descriptor[x].add_entropy(buf, 32, &tprng); prng_descriptor[x].ready(&tprng); prng_descriptor[x].done(&tprng);
+#define DO2 DO1 DO1
+      for (y = 0; y < 10000; y++) {
+         t_start();
+         t1 = t_read();
+         DO2;
+         t1 = (t_read() - t1)>>1;
+         if (t1 < t2) t2 = t1;
+      }
+      fprintf(stderr, "%5llu\n", t2);
+#undef DO2
+#undef DO1
+
+   }
+}
+
+#ifdef MRSA      
+/* time various RSA operations */
+void time_rsa(void)
+{
+   rsa_key key;
+   ulong64 t1, t2;
+   unsigned char buf[2][4096];
+   unsigned long x, y, z, zzz;
+   int           err, zz;
+
+   for (x = 1024; x <= 2048; x += 512) {
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           if ((err = rsa_make_key(&yarrow_prng, find_prng("yarrow"), x/8, 65537, &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\nrsa_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+
+           if (y < 15) {
+              rsa_free(&key);
+           }
+       }
+       t2 >>= 4;
+       fprintf(stderr, "RSA-%lu make_key    took %15llu cycles\n", x, t2);
+
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           z = sizeof(buf[1]);
+           if ((err = rsa_encrypt_key(buf[0], 32, buf[1], &z, "testprog", 8, &yarrow_prng,
+                                      find_prng("yarrow"), find_hash("sha1"),
+                                      &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\nrsa_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+       }
+       t2 >>= 4;
+       fprintf(stderr, "RSA-%lu encrypt_key took %15llu cycles\n", x, t2);
+
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           zzz = sizeof(buf[0]);
+           if ((err = rsa_decrypt_key(buf[1], z, buf[0], &zzz, "testprog", 8,  find_hash("sha1"), 
+                                      &zz, &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\nrsa_decrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+       }
+       t2 >>= 4;
+       fprintf(stderr, "RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
+
+
+       rsa_free(&key);
+  }
+}
+#else
+void time_rsa(void) { fprintf(stderr, "NO RSA\n"); }
+#endif
+
+#ifdef MECC
+/* time various ECC operations */
+void time_ecc(void)
+{
+   ecc_key key;
+   ulong64 t1, t2;
+   unsigned char buf[2][4096];
+   unsigned long i, x, y, z;
+   int           err;
+   static unsigned long sizes[] = {192/8, 256/8, 384/8, 521/8, 100000};
+
+   for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           if ((err = ecc_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\necc_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+
+           if (y < 15) {
+              ecc_free(&key);
+           }
+       }
+       t2 >>= 4;
+       fprintf(stderr, "ECC-%lu make_key    took %15llu cycles\n", x*8, t2);
+
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           z = sizeof(buf[1]);
+           if ((err = ecc_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),
+                                      &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\necc_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+       }
+       t2 >>= 4;
+       fprintf(stderr, "ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
+       ecc_free(&key);
+  }
+}
+#else
+void time_ecc(void) { fprintf(stderr, "NO ECC\n"); }
+#endif
+
+#ifdef MDH
+/* time various DH operations */
+void time_dh(void)
+{
+   dh_key key;
+   ulong64 t1, t2;
+   unsigned char buf[2][4096];
+   unsigned long i, x, y, z;
+   int           err;
+   static unsigned long sizes[] = {768/8, 1024/8, 1536/8, 2048/8, 3072/8, 4096/8, 100000};
+
+   for (x = sizes[i=0]; x < 100000; x = sizes[++i]) {
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           if ((err = dh_make_key(&yarrow_prng, find_prng("yarrow"), x, &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\ndh_make_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+
+           if (y < 15) {
+              dh_free(&key);
+           }
+       }
+       t2 >>= 4;
+       fprintf(stderr, "DH-%4lu make_key    took %15llu cycles\n", x*8, t2);
+
+       t2 = 0;
+       for (y = 0; y < 16; y++) {
+           t_start();
+           t1 = t_read();
+           z = sizeof(buf[1]);
+           if ((err = dh_encrypt_key(buf[0], 20, buf[1], &z, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"),
+                                      &key)) != CRYPT_OK) {
+              fprintf(stderr, "\n\ndh_encrypt_key says %s, wait...no it should say %s...damn you!\n", error_to_string(err), error_to_string(CRYPT_OK));
+              exit(EXIT_FAILURE);
+           }
+           t1 = t_read() - t1;
+           t2 += t1;
+       }
+       t2 >>= 4;
+       fprintf(stderr, "DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
+       dh_free(&key);
+  }
+}
+#else
+void time_dh(void) { fprintf(stderr, "NO DH\n"); }
+#endif
+
+void time_macs_(unsigned long MAC_SIZE)
+{
+   unsigned char *buf, key[16], tag[16];
+   ulong64 t1, t2;
+   unsigned long x, z;
+   int err, cipher_idx, hash_idx;
+
+   fprintf(stderr, "\nMAC Timings (cycles/byte on %luKB blocks):\n", MAC_SIZE);
+
+   buf = XMALLOC(MAC_SIZE*1024);
+   if (buf == NULL) {
+      fprintf(stderr, "\n\nout of heap yo\n\n");
+      exit(EXIT_FAILURE);
+   }
+
+   cipher_idx = find_cipher("aes");
+   hash_idx   = find_hash("md5");
+
+   yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng);
+   yarrow_read(key, 16, &yarrow_prng);
+
+#ifdef OMAC
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = omac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {
+           fprintf(stderr, "\n\nomac error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "OMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef PMAC
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = pmac_memory(cipher_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {
+           fprintf(stderr, "\n\npmac error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "PMAC-AES\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef PELICAN
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = pelican_memory(key, 16, buf, MAC_SIZE*1024, tag)) != CRYPT_OK) {
+           fprintf(stderr, "\n\npelican error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "PELICAN \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef HMAC
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = hmac_memory(hash_idx, key, 16, buf, MAC_SIZE*1024, tag, &z)) != CRYPT_OK) {
+           fprintf(stderr, "\n\nhmac error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "HMAC-MD5\t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+   XFREE(buf);
+}
+
+void time_macs(void)
+{
+   time_macs_(1);
+   time_macs_(4);
+   time_macs_(32);
+}
+
+void time_encmacs_(unsigned long MAC_SIZE)
+{
+   unsigned char *buf, IV[16], key[16], tag[16];
+   ulong64 t1, t2;
+   unsigned long x, z;
+   int err, cipher_idx;
+
+   fprintf(stderr, "\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks):\n", MAC_SIZE);
+
+   buf = XMALLOC(MAC_SIZE*1024);
+   if (buf == NULL) {
+      fprintf(stderr, "\n\nout of heap yo\n\n");
+      exit(EXIT_FAILURE);
+   }
+
+   cipher_idx = find_cipher("aes");
+
+   yarrow_read(buf, MAC_SIZE*1024, &yarrow_prng);
+   yarrow_read(key, 16, &yarrow_prng);
+   yarrow_read(IV, 16, &yarrow_prng);
+
+#ifdef EAX_MODE
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = eax_encrypt_authenticate_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) {
+           fprintf(stderr, "\nEAX error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "EAX \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef OCB_MODE
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = ocb_encrypt_authenticate_memory(cipher_idx, key, 16, IV, buf, MAC_SIZE*1024, buf, tag, &z)) != CRYPT_OK) {
+           fprintf(stderr, "\nOCB error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "OCB \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef CCM_MODE
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = ccm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, CCM_ENCRYPT)) != CRYPT_OK) {
+           fprintf(stderr, "\nCCM error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "CCM \t\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+#endif
+
+#ifdef GCM_MODE
+   t2 = -1;
+   for (x = 0; x < 100; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = gcm_memory(cipher_idx, key, 16, IV, 16, NULL, 0, buf, MAC_SIZE*1024, buf, tag, &z, GCM_ENCRYPT)) != CRYPT_OK) {
+           fprintf(stderr, "\nGCM error... %s\n", error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "GCM (no-precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+
+   {
+   gcm_state gcm;
+
+   if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { fprintf(stderr, "gcm_init: %s\n", error_to_string(err)); exit(EXIT_FAILURE); }
+   t2 = -1;
+   for (x = 0; x < 10000; x++) {
+        t_start();
+        t1 = t_read();
+        z = 16;
+        if ((err = gcm_reset(&gcm)) != CRYPT_OK) {
+            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        if ((err = gcm_add_iv(&gcm, IV, 16)) != CRYPT_OK) {
+            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        if ((err = gcm_add_aad(&gcm, NULL, 0)) != CRYPT_OK) {
+            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        if ((err = gcm_process(&gcm, buf, MAC_SIZE*1024, buf, GCM_ENCRYPT)) != CRYPT_OK) {
+            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        
+        if ((err = gcm_done(&gcm, tag, &z)) != CRYPT_OK) {
+            fprintf(stderr, "\nGCM error[%d]... %s\n", __LINE__, error_to_string(err));
+           exit(EXIT_FAILURE);
+        }
+        t1 = t_read() - t1;
+        if (t1 < t2) t2 = t1;
+   }
+   fprintf(stderr, "GCM (precomp)\t%9llu\n", t2/(ulong64)(MAC_SIZE*1024));
+   }
+
+#endif
+
+} 
+
+void time_encmacs(void)
+{
+   time_encmacs_(1);
+   time_encmacs_(4);
+   time_encmacs_(32);
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/testprof/x86_prof.c,v $ */
+/* $Revision: 1.16 $ */
+/* $Date: 2005/06/14 20:44:23 $ */
diff --git a/tim_exptmod.c b/tim_exptmod.c
deleted file mode 100644
index 865d458..0000000
--- a/tim_exptmod.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-/* RSA Code by Tom St Denis */
-#include "mycrypt.h"
-
-#ifdef RSA_TIMING
-
-/* decrypts c into m */
-int tim_exptmod(prng_state *prng, int prng_idx, 
-                mp_int *c, mp_int *e, mp_int *d, mp_int *n, mp_int *m)
-{
-   int           err;
-   mp_int        r, tmp, tmp2;
-   unsigned char *rtmp;
-   unsigned long rlen;
-
-   _ARGCHK(c != NULL);
-   _ARGCHK(e != NULL);
-   _ARGCHK(d != NULL);
-   _ARGCHK(n != NULL);
-   _ARGCHK(m != NULL);
-
-   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* pick random r */ 
-   rtmp = XMALLOC(MAX_RSA_SIZE/8);
-   if (rtmp == NULL) {
-      return CRYPT_MEM;
-   }
-
-
-   rlen = mp_unsigned_bin_size(n);
-   if (prng_descriptor[prng_idx].read(rtmp, rlen, prng) != rlen) {
-      XFREE(rtmp);
-      return CRYPT_ERROR_READPRNG;
-   }
-
-   if ((err = mp_init_multi(&r, &tmp, &tmp2, NULL)) != MP_OKAY) {
-      XFREE(rtmp);
-      return mpi_to_ltc_error(err);
-   }
-
-   /* read in r */
-   if ((err = mp_read_unsigned_bin(&r, rtmp, rlen)) != MP_OKAY)              { goto __ERR; }
-
-   /* compute tmp = r^e */
-   if ((err = mp_exptmod(&r, e, n, &tmp)) != MP_OKAY)                        { goto __ERR; }
-
-   /* multiply C into the mix */
-   if ((err = mp_mulmod(c, &tmp, n, &tmp)) != MP_OKAY)                       { goto __ERR; }
-
-   /* raise to d */
-   if ((err = mp_exptmod(&tmp, d, n, &tmp)) != MP_OKAY)                      { goto __ERR; }
-   
-   /* invert r and multiply */
-   if ((err = mp_invmod(&r, n, &tmp2)) != MP_OKAY)                           { goto __ERR; }
-
-   /* multiply and we are totally set */
-   if ((err = mp_mulmod(&tmp, &tmp2, n, m)) != MP_OKAY)                      { goto __ERR; }
-
-__ERR:  mp_clear_multi(&r, &tmp, &tmp2, NULL);
-   XFREE(rtmp);
-   return mpi_to_ltc_error(err);
-}
-
-#endif 
diff --git a/xtea.c b/xtea.c
deleted file mode 100644
index 1434149..0000000
--- a/xtea.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef XTEA
-
-const struct _cipher_descriptor xtea_desc =
-{
-    "xtea",
-    1,
-    16, 16, 8, 32,
-    &xtea_setup,
-    &xtea_ecb_encrypt,
-    &xtea_ecb_decrypt,
-    &xtea_test,
-    &xtea_keysize
-};
-
-int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
-{
-   unsigned long x, sum, K[4];
-   
-   _ARGCHK(key != NULL);
-   _ARGCHK(skey != NULL);
-
-   /* check arguments */
-   if (keylen != 16) {
-      return CRYPT_INVALID_KEYSIZE;
-   }
-
-   if (num_rounds != 0 && num_rounds != 32) {
-      return CRYPT_INVALID_ROUNDS;
-   }
-
-   /* load key */
-   LOAD32L(K[0], key+0);
-   LOAD32L(K[1], key+4);
-   LOAD32L(K[2], key+8);
-   LOAD32L(K[3], key+12);
-   
-   for (x = sum = 0; x < 32; x++) {
-       skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL;
-       sum = (sum + 0x9E3779B9UL) & 0xFFFFFFFFUL;
-       skey->xtea.B[x] = (sum + K[(sum>>11)&3]) & 0xFFFFFFFFUL;
-   }
-   
-#ifdef CLEAN_STACK
-   zeromem(&K, sizeof(K));
-#endif   
-   
-   return CRYPT_OK;
-}
-
-void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
-{
-   unsigned long y, z;
-   int r;
-
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(key != NULL);
-
-   LOAD32L(y, &pt[0]);
-   LOAD32L(z, &pt[4]);
-   for (r = 0; r < 32; r += 4) {
-       y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r])) & 0xFFFFFFFFUL;
-       z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r])) & 0xFFFFFFFFUL;
-
-       y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r+1])) & 0xFFFFFFFFUL;
-       z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r+1])) & 0xFFFFFFFFUL;
-
-       y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r+2])) & 0xFFFFFFFFUL;
-       z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r+2])) & 0xFFFFFFFFUL;
-
-       y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r+3])) & 0xFFFFFFFFUL;
-       z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r+3])) & 0xFFFFFFFFUL;
-   }
-   STORE32L(y, &ct[0]);
-   STORE32L(z, &ct[4]);
-}
-
-void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
-{
-   unsigned long y, z;
-   int r;
-
-   _ARGCHK(pt != NULL);
-   _ARGCHK(ct != NULL);
-   _ARGCHK(key != NULL);
-
-   LOAD32L(y, &ct[0]);
-   LOAD32L(z, &ct[4]);
-   for (r = 31; r >= 0; r -= 4) {
-       z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r])) & 0xFFFFFFFFUL;
-       y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r])) & 0xFFFFFFFFUL;
-
-       z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r-1])) & 0xFFFFFFFFUL;
-       y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r-1])) & 0xFFFFFFFFUL;
-
-       z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r-2])) & 0xFFFFFFFFUL;
-       y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r-2])) & 0xFFFFFFFFUL;
-
-       z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r-3])) & 0xFFFFFFFFUL;
-       y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r-3])) & 0xFFFFFFFFUL;
-   }
-   STORE32L(y, &pt[0]);
-   STORE32L(z, &pt[4]);
-}
-
-int xtea_test(void)
-{
- #ifndef LTC_TEST
-    return CRYPT_NOP;
- #else    
-   static const unsigned char key[16] = 
-      { 0x78, 0x56, 0x34, 0x12, 0xf0, 0xcd, 0xcb, 0x9a,
-        0x48, 0x37, 0x26, 0x15, 0xc0, 0xbf, 0xae, 0x9d };
-   static const unsigned char pt[8] = 
-      { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
-   static const unsigned char ct[8] = 
-      { 0x75, 0xd7, 0xc5, 0xbf, 0xcf, 0x58, 0xc9, 0x3f };
-   unsigned char tmp[2][8];
-   symmetric_key skey;
-   int err, y;
-
-   if ((err = xtea_setup(key, 16, 0, &skey)) != CRYPT_OK)  {
-      return err;
-   }
-   xtea_ecb_encrypt(pt, tmp[0], &skey);
-   xtea_ecb_decrypt(tmp[0], tmp[1], &skey);
-
-   if (memcmp(tmp[0], ct, 8) != 0 || memcmp(tmp[1], pt, 8) != 0) { 
-      return CRYPT_FAIL_TESTVECTOR;
-   }
-
-      /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
-      for (y = 0; y < 8; y++) tmp[0][y] = 0;
-      for (y = 0; y < 1000; y++) xtea_ecb_encrypt(tmp[0], tmp[0], &skey);
-      for (y = 0; y < 1000; y++) xtea_ecb_decrypt(tmp[0], tmp[0], &skey);
-      for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
-
-   return CRYPT_OK;
- #endif
-}
-
-int xtea_keysize(int *desired_keysize)
-{
-   _ARGCHK(desired_keysize != NULL);
-   if (*desired_keysize < 16) {
-      return CRYPT_INVALID_KEYSIZE; 
-   }
-   *desired_keysize = 16;
-   return CRYPT_OK;
-}
-
-
-#endif
-
-
-
diff --git a/yarrow.c b/yarrow.c
deleted file mode 100644
index 4415f78..0000000
--- a/yarrow.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-
-#include "mycrypt.h"
-
-#ifdef YARROW
-
-const struct _prng_descriptor yarrow_desc =
-{
-    "yarrow",
-    &yarrow_start,
-    &yarrow_add_entropy,
-    &yarrow_ready,
-    &yarrow_read
-};
-
-int yarrow_start(prng_state *prng)
-{
-   int err;
-   
-   _ARGCHK(prng != NULL);
-
-   /* these are the default hash/cipher combo used */
-#ifdef RIJNDAEL
-#if    YARROW_AES==0
-   prng->yarrow.cipher = register_cipher(&rijndael_enc_desc);
-#elif  YARROW_AES==1
-   prng->yarrow.cipher = register_cipher(&aes_enc_desc);
-#elif  YARROW_AES==2
-   prng->yarrow.cipher = register_cipher(&rijndael_desc);
-#elif  YARROW_AES==3
-   prng->yarrow.cipher = register_cipher(&aes_desc);
-#endif
-#elif defined(BLOWFISH)
-   prng->yarrow.cipher = register_cipher(&blowfish_desc);
-#elif defined(TWOFISH)
-   prng->yarrow.cipher = register_cipher(&twofish_desc);
-#elif defined(RC6)
-   prng->yarrow.cipher = register_cipher(&rc6_desc);
-#elif defined(RC5)
-   prng->yarrow.cipher = register_cipher(&rc5_desc);
-#elif defined(SAFERP)
-   prng->yarrow.cipher = register_cipher(&saferp_desc);
-#elif defined(RC2)
-   prng->yarrow.cipher = register_cipher(&rc2_desc);
-#elif defined(NOEKEON)   
-   prng->yarrow.cipher = register_cipher(&noekeon_desc);
-#elif defined(CAST5)
-   prng->yarrow.cipher = register_cipher(&cast5_desc);
-#elif defined(XTEA)
-   prng->yarrow.cipher = register_cipher(&xtea_desc);
-#elif defined(SAFER)
-   prng->yarrow.cipher = register_cipher(&safer_sk128_desc);
-#elif defined(DES)
-   prng->yarrow.cipher = register_cipher(&des3_desc);
-#elif
-   #error YARROW needs at least one CIPHER
-#endif
-   if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
-      return err;
-   }
-
-#ifdef SHA256
-   prng->yarrow.hash   = register_hash(&sha256_desc);
-#elif defined(SHA512)
-   prng->yarrow.hash   = register_hash(&sha512_desc);
-#elif defined(TIGER)
-   prng->yarrow.hash   = register_hash(&tiger_desc);
-#elif defined(SHA1)
-   prng->yarrow.hash   = register_hash(&sha1_desc);
-#elif defined(RIPEMD160)
-   prng->yarrow.hash   = register_hash(&rmd160_desc);
-#elif defined(RIPEMD128)
-   prng->yarrow.hash   = register_hash(&rmd128_desc);
-#elif defined(MD5)
-   prng->yarrow.hash   = register_hash(&md5_desc);
-#elif defined(MD4)
-   prng->yarrow.hash   = register_hash(&md4_desc);
-#elif defined(MD2)
-   prng->yarrow.hash   = register_hash(&md2_desc);
-#elif defined(WHIRLPOOL)
-   prng->yarrow.hash   = register_hash(&whirlpool_desc);
-#else
-   #error YARROW needs at least one HASH
-#endif
-   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* zero the memory used */
-   zeromem(prng->yarrow.pool, sizeof(prng->yarrow.pool));
-
-   return CRYPT_OK;
-}
-
-int yarrow_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
-{
-   hash_state md;
-   int err;
-
-   _ARGCHK(buf  != NULL);
-   _ARGCHK(prng != NULL);
-
-   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* start the hash */
-   hash_descriptor[prng->yarrow.hash].init(&md);
-
-   /* hash the current pool */
-   if ((err = hash_descriptor[prng->yarrow.hash].process(&md, prng->yarrow.pool, 
-                                                        hash_descriptor[prng->yarrow.hash].hashsize)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* add the new entropy */
-   if ((err = hash_descriptor[prng->yarrow.hash].process(&md, buf, len)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* store result */
-   if ((err = hash_descriptor[prng->yarrow.hash].done(&md, prng->yarrow.pool)) != CRYPT_OK) {
-      return err;
-   }
-
-   return CRYPT_OK;
-}
-
-int yarrow_ready(prng_state *prng)
-{
-   int ks, err;
-
-   _ARGCHK(prng != NULL);
-
-   if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
-      return err;
-   }
-   
-   if ((err = cipher_is_valid(prng->yarrow.cipher)) != CRYPT_OK) {
-      return err;
-   }
-
-   /* setup CTR mode using the "pool" as the key */
-   ks = (int)hash_descriptor[prng->yarrow.hash].hashsize;
-   if ((err = cipher_descriptor[prng->yarrow.cipher].keysize(&ks)) != CRYPT_OK) {
-      return err;
-   }
-
-   if ((err = ctr_start(prng->yarrow.cipher,     /* what cipher to use */
-                        prng->yarrow.pool,       /* IV */
-                        prng->yarrow.pool, ks,   /* KEY and key size */
-                        0,                       /* number of rounds */
-                        &prng->yarrow.ctr)) != CRYPT_OK) {
-      return err;
-   }
-   return CRYPT_OK;
-}
-
-unsigned long yarrow_read(unsigned char *buf, unsigned long len, prng_state *prng)
-{
-   _ARGCHK(buf  != NULL);
-   _ARGCHK(prng != NULL);
-
-   /* put buf in predictable state first */
-   zeromem(buf, len);
-   
-   /* now randomize it */
-   if (ctr_encrypt(buf, buf, len, &prng->yarrow.ctr) != CRYPT_OK) {
-      return 0;
-   }
-   return len;
-}
-
-#endif
-
diff --git a/zeromem.c b/zeromem.c
deleted file mode 100644
index 15181ac..0000000
--- a/zeromem.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* LibTomCrypt, modular cryptographic library -- Tom St Denis
- *
- * LibTomCrypt is a library that provides various cryptographic
- * algorithms in a highly modular and flexible manner.
- *
- * The library is free for all purposes without any express
- * guarantee it works.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
- */
-#include "mycrypt.h"
-
-void zeromem(void *dst, size_t len)
-{
- unsigned char *mem = (unsigned char *)dst;
- _ARGCHK(dst != NULL);
- while (len-- > 0)
-    *mem++ = 0;
-}