Import of libtomcrypt 1.02 with manual path rename rearrangement etc

--HG--
branch : libtomcrypt-orig
extra : convert_revision : 128d85f93acd46086c361a9a17274f94beadd465
diff --git a/Doxyfile b/Doxyfile
new file mode 100644
index 0000000..d42b778
--- /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.02
+
+# 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 50e7435..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/TODO b/TODO
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/TODO
@@ -0,0 +1 @@
+
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_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/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 89356a0..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;
-   }
-   XMEMCPY(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 9fa562b..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;
-   }
-   XMEMCPY(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 c54f70f..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;
-   }
-   XMEMCPY(IV, cfb->IV, cfb->blocklen);
-   *len = cfb->blocklen;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/changes b/changes
index f887acf..54480cf 100644
--- a/changes
+++ b/changes
@@ -1,3 +1,138 @@
+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)
diff --git a/crypt.tex b/crypt.tex
index b8acb3f..c785e83 100644
--- a/crypt.tex
+++ b/crypt.tex
@@ -47,10 +47,10 @@
 \def\gap{\vspace{0.5ex}}
 \makeindex
 \begin{document}
-\title{LibTomCrypt \\ Version 0.99}
+\title{LibTomCrypt \\ Version 1.02}
 \author{Tom St Denis \\
 \\
-tomstdenis@iahu.ca \\
+tomstdenis@gmail.com \\
 http://libtomcrypt.org
 }
 \maketitle
@@ -79,56 +79,22 @@
 \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
@@ -143,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
@@ -170,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
@@ -178,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 seems to be free for use.
+``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.
 
@@ -193,7 +167,7 @@
 
 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 ``mycrypt\_custom.h''.  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 
@@ -221,7 +195,6 @@
 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}
@@ -255,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|}
@@ -284,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}
@@ -306,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);
@@ -331,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
@@ -352,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,
@@ -369,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,
@@ -385,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}
@@ -399,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;
@@ -415,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];
@@ -444,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}
@@ -459,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
@@ -467,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.
 
@@ -511,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 \\
@@ -523,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}
@@ -545,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
@@ -590,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];
@@ -631,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;
@@ -729,7 +766,7 @@
 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 
@@ -752,30 +789,32 @@
 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:
+Both 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()}
@@ -785,16 +824,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];
@@ -852,6 +903,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));
@@ -944,7 +1001,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;
@@ -1057,6 +1114,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()}
@@ -1090,6 +1149,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()}
@@ -1119,6 +1179,238 @@
 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_add_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;
+   }
+
+   /* 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}
 
@@ -1132,7 +1424,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 
@@ -1167,7 +1459,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;
@@ -1195,9 +1487,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}
@@ -1210,7 +1503,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];
@@ -1258,29 +1551,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;
@@ -1364,7 +1655,7 @@
 Example of using CHC with the AES block cipher.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int err; 
@@ -1417,18 +1708,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).
@@ -1439,22 +1730,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:
@@ -1467,7 +1759,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int idx, err;
@@ -1531,9 +1823,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}
@@ -1567,10 +1859,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.
 
@@ -1580,7 +1872,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
@@ -1597,7 +1889,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int idx, err;
@@ -1662,9 +1954,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}
@@ -1694,9 +1986,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
@@ -1716,13 +2008,80 @@
 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}
@@ -1735,12 +2094,11 @@
 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}
 
@@ -1754,7 +2112,7 @@
 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}
 
@@ -1831,7 +2189,7 @@
 {\bf NOT} secure since the entropy added is not random.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    prng_state prng;
@@ -1961,7 +2319,7 @@
 \subsubsection{Example Usage}
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    prng_state prng;
@@ -2029,7 +2387,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    ecc_key mykey;
@@ -2066,7 +2424,7 @@
 
 \begin{small}
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    ecc_key mykey;
@@ -2088,6 +2446,8 @@
 \end{verbatim}
 \end{small}
 
+
+
 \chapter{RSA Public Key Cryptography}
 
 \section{Introduction}
@@ -2307,8 +2667,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
@@ -2324,26 +2684,26 @@
 
 \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,
                           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$.
@@ -2354,15 +2714,15 @@
 
 \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()}
@@ -2382,7 +2742,7 @@
 to $1$.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    int           err, hash_idx, prng_idx, res;
@@ -2646,16 +3006,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.
@@ -2759,17 +3119,17 @@
 
 \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 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 ``ecc\_encrypt\_key()''.   The hash chosen must produce a message digest at least as large
 as the symmetric key you are trying to share.
@@ -2975,7 +3335,7 @@
 except they handle a \textbf{NULL} terminated list of operands.
 
 \begin{verbatim}
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 {
    mp_int        a, b, c, d;
@@ -3047,7 +3407,7 @@
 
 \begin{alltt}
 /* demo to show how to make session state material from a password */
-#include <mycrypt.h>
+#include <tomcrypt.h>
 int main(void)
 \{
     unsigned char password[100], salt[100],
@@ -3115,7 +3475,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;
@@ -3327,7 +3687,7 @@
 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 ``mycrypt.h'' in their program and linking against ``libtomcrypt.a''.
+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
 
@@ -3368,18 +3728,8 @@
 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''.
 
-You can also build LibTomCrypt as a shared library (DLL) in Windows with Cygwin.  Issue the following
-
-\begin{alltt}
-make -f makefile.cygwin_dll
-\end{alltt}
-This will build ``libtomcrypt.dll.a'' which is an import library for ``libtomcrypt.dll''.  You must copy 
-``libtomcrypt.dll.a'' to your library directory, ``libtomcrypt.dll' to somewhere in your PATH and the header
-files to your include directory.  So long as ``libtomcrypt.dll'' is in your system path you can run any LibTomCrypt
-program that uses it.
-
-\section{mycrypt\_cfg.h}
-The file ``mycrypt\_cfg.h'' is what lets you control various high level macros which control the behaviour 
+\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}
@@ -3398,38 +3748,38 @@
 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\_custom.h''.  
+There are also options you can specify from the configure script or ``tomcrypt\_custom.h''.  
 
-\subsubsection{X memory routines}
-At the top of mycrypt\_custom.h are four macros denoted as XMALLOC, XCALLOC, XREALLOC and XFREE which resolve to 
+\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\_NOP.  This should help resolve any linker errors stemming from a lack of
 file I/O on embedded platforms.
 
-\subsubsection{CLEAN\_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{LTC\_TEST}
+\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{Symmetric Ciphers, One-way Hashes, PRNGS and Public Key Functions}
+\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.
 
-\subsubsection{TWOFISH\_SMALL and TWOFISH\_TABLES}
+\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 
@@ -3441,23 +3791,462 @@
 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 lower up the per--packet latency.  
+It also increases the initialization time.  
+
+\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.
+
 \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 mycrypt\_custom.h
+   \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''.
+
+This is where things get tricky.  Currently there is no provision to allocate memory during initialization since there is no ``cipher done'' function.  So you have
+to either use an existing member of the symmetric\_key union or alias your own structure over top of it provided symmetric\_key is not smaller.
+
+\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 = 1$) or little ($mode = 0$) 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 DER identifier */
+    unsigned char DER[64];
+    /** Length of DER encoding */
+    unsigned long DERlen;
+    /** 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{DER Identifier}
+This is the DER identifier (including the SEQUENCE header).  This is used solely for PKCS \#1 style signatures.  
+
+\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}
 
diff --git a/crypt_cipher_descriptor.c b/crypt_cipher_descriptor.c
deleted file mode 100644
index 4a8a943..0000000
--- a/crypt_cipher_descriptor.c
+++ /dev/null
@@ -1,14 +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];
-
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_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_hash_descriptor.c b/crypt_hash_descriptor.c
deleted file mode 100644
index 5c02255..0000000
--- a/crypt_hash_descriptor.c
+++ /dev/null
@@ -1,14 +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];
-
diff --git a/crypt_prng_descriptor.c b/crypt_prng_descriptor.c
deleted file mode 100644
index 129118f..0000000
--- a/crypt_prng_descriptor.c
+++ /dev/null
@@ -1,13 +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];
diff --git a/crypt_register_cipher.c b/crypt_register_cipher.c
deleted file mode 100644
index e8e021e..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) {
-          XMEMCPY(&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 c8023a9..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) {
-          XMEMCPY(&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 8176338..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) {
-          XMEMCPY(&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/cscope.tmplst b/cscope.tmplst
deleted file mode 100644
index 7fabc86..0000000
--- a/cscope.tmplst
+++ /dev/null
@@ -1,219 +0,0 @@
-./aes.c
-./aes_tab.c
-./base64_decode.c
-./base64_encode.c
-./blowfish.c
-./burn_stack.c
-./cast5.c
-./cbc_decrypt.c
-./cbc_encrypt.c
-./cbc_getiv.c
-./cbc_setiv.c
-./cbc_start.c
-./cfb_decrypt.c
-./cfb_encrypt.c
-./cfb_getiv.c
-./cfb_setiv.c
-./cfb_start.c
-./chc.c
-./crypt.c
-./crypt_argchk.c
-./crypt_cipher_descriptor.c
-./crypt_cipher_is_valid.c
-./crypt_find_cipher.c
-./crypt_find_cipher_any.c
-./crypt_find_cipher_id.c
-./crypt_find_hash.c
-./crypt_find_hash_any.c
-./crypt_find_hash_id.c
-./crypt_find_prng.c
-./crypt_hash_descriptor.c
-./crypt_hash_is_valid.c
-./crypt_prng_descriptor.c
-./crypt_prng_is_valid.c
-./crypt_register_cipher.c
-./crypt_register_hash.c
-./crypt_register_prng.c
-./crypt_unregister_cipher.c
-./crypt_unregister_hash.c
-./crypt_unregister_prng.c
-./ctr_decrypt.c
-./ctr_encrypt.c
-./ctr_getiv.c
-./ctr_setiv.c
-./ctr_start.c
-./demos/encrypt.c
-./demos/hashsum.c
-./demos/small.c
-./demos/test/base64_test.c
-./demos/test/cipher_hash_test.c
-./demos/test/der_tests.c
-./demos/test/dh_tests.c
-./demos/test/dsa_test.c
-./demos/test/ecc_test.c
-./demos/test/mac_test.c
-./demos/test/makefile
-./demos/test/makefile.icc
-./demos/test/makefile.msvc
-./demos/test/makefile.shared
-./demos/test/modes_test.c
-./demos/test/pkcs_1_test.c
-./demos/test/rsa_test.c
-./demos/test/store_test.c
-./demos/test/test.c
-./demos/test/test.h
-./demos/tv_gen.c
-./demos/x86_prof.c
-./der_decode_integer.c
-./der_encode_integer.c
-./der_get_multi_integer.c
-./der_length_integer.c
-./der_put_multi_integer.c
-./des.c
-./dh.c
-./dh_sys.c
-./dsa_export.c
-./dsa_free.c
-./dsa_import.c
-./dsa_make_key.c
-./dsa_sign_hash.c
-./dsa_verify_hash.c
-./dsa_verify_key.c
-./eax_addheader.c
-./eax_decrypt.c
-./eax_decrypt_verify_memory.c
-./eax_done.c
-./eax_encrypt.c
-./eax_encrypt_authenticate_memory.c
-./eax_init.c
-./eax_test.c
-./ecb_decrypt.c
-./ecb_encrypt.c
-./ecb_start.c
-./ecc.c
-./ecc_sys.c
-./error_to_string.c
-./fortuna.c
-./hash_file.c
-./hash_filehandle.c
-./hash_memory.c
-./hmac_done.c
-./hmac_file.c
-./hmac_init.c
-./hmac_memory.c
-./hmac_process.c
-./hmac_test.c
-./is_prime.c
-./ltc_tommath.h
-./makefile
-./makefile.cygwin_dll
-./makefile.icc
-./makefile.msvc
-./makefile.shared
-./md2.c
-./md4.c
-./md5.c
-./mpi.c
-./mpi_to_ltc_error.c
-./mycrypt.h
-./mycrypt_argchk.h
-./mycrypt_cfg.h
-./mycrypt_cipher.h
-./mycrypt_custom.h
-./mycrypt_hash.h
-./mycrypt_macros.h
-./mycrypt_misc.h
-./mycrypt_pk.h
-./mycrypt_pkcs.h
-./mycrypt_prng.h
-./noekeon.c
-./notes/etc/whirlgen.c
-./notes/etc/whirltest.c
-./ocb_decrypt.c
-./ocb_decrypt_verify_memory.c
-./ocb_done_decrypt.c
-./ocb_done_encrypt.c
-./ocb_encrypt.c
-./ocb_encrypt_authenticate_memory.c
-./ocb_init.c
-./ocb_ntz.c
-./ocb_shift_xor.c
-./ocb_test.c
-./ofb_decrypt.c
-./ofb_encrypt.c
-./ofb_getiv.c
-./ofb_setiv.c
-./ofb_start.c
-./omac_done.c
-./omac_file.c
-./omac_init.c
-./omac_memory.c
-./omac_process.c
-./omac_test.c
-./packet_store_header.c
-./packet_valid_header.c
-./pkcs_1_i2osp.c
-./pkcs_1_mgf1.c
-./pkcs_1_oaep_decode.c
-./pkcs_1_oaep_encode.c
-./pkcs_1_os2ip.c
-./pkcs_1_pss_decode.c
-./pkcs_1_pss_encode.c
-./pkcs_1_v15_es_decode.c
-./pkcs_1_v15_es_encode.c
-./pkcs_1_v15_sa_decode.c
-./pkcs_1_v15_sa_encode.c
-./pkcs_5_1.c
-./pkcs_5_2.c
-./pmac_done.c
-./pmac_file.c
-./pmac_init.c
-./pmac_memory.c
-./pmac_ntz.c
-./pmac_process.c
-./pmac_shift_xor.c
-./pmac_test.c
-./rand_prime.c
-./rc2.c
-./rc4.c
-./rc5.c
-./rc6.c
-./rmd128.c
-./rmd160.c
-./rng_get_bytes.c
-./rng_make_prng.c
-./rsa_decrypt_key.c
-./rsa_encrypt_key.c
-./rsa_export.c
-./rsa_exptmod.c
-./rsa_free.c
-./rsa_import.c
-./rsa_make_key.c
-./rsa_sign_hash.c
-./rsa_v15_decrypt_key.c
-./rsa_v15_encrypt_key.c
-./rsa_v15_sign_hash.c
-./rsa_v15_verify_hash.c
-./rsa_verify_hash.c
-./s_ocb_done.c
-./safer.c
-./safer_tab.c
-./saferp.c
-./sha1.c
-./sha224.c
-./sha256.c
-./sha384.c
-./sha512.c
-./skipjack.c
-./sober128.c
-./sober128tab.c
-./sprng.c
-./tiger.c
-./tim_exptmod.c
-./twofish.c
-./twofish_tab.c
-./whirl.c
-./whirltab.c
-./xtea.c
-./yarrow.c
-./zeromem.c
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 ab20491..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;
-   }
-   XMEMCPY(IV, ctr->ctr, ctr->blocklen);
-   *len = ctr->blocklen;
-
-   return CRYPT_OK;
-}
-
-#endif
diff --git a/demos/encrypt.c b/demos/encrypt.c
index 5320c21..67627f7 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");
diff --git a/demos/hashsum.c b/demos/hashsum.c
index c633ca8..23946cc 100644
--- a/demos/hashsum.c
+++ b/demos/hashsum.c
@@ -7,7 +7,7 @@
  * more functions ;)
 */
 
-#include <mycrypt.h>
+#include <tomcrypt.h>
 
 int errno;
 
diff --git a/demos/multi.c b/demos/multi.c
new file mode 100644
index 0000000..fdc8dc6
--- /dev/null
+++ b/demos/multi.c
@@ -0,0 +1,106 @@
+/* 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;
+}
+
diff --git a/demos/small.c b/demos/small.c
index f5a0d43..bc9793b 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)
 {
diff --git a/demos/test.c b/demos/test.c
new file mode 100644
index 0000000..290861d
--- /dev/null
+++ b/demos/test.c
@@ -0,0 +1,19 @@
+#include <tomcrypt_test.h>
+
+int main(void)
+{
+   reg_algs();
+   printf("build == \n%s\n", crypt_build_settings);
+   printf("\ncipher_test..."); fflush(stdout); printf(cipher_hash_test() ? "failed" : "passed");
+   printf("\nmodes_test..."); fflush(stdout); printf(modes_test() ? "failed" : "passed");
+   printf("\nmac_test..."); fflush(stdout); printf(mac_test() ? "failed" : "passed");
+   printf("\npkcs_1_test..."); fflush(stdout); printf(pkcs_1_test() ? "failed" : "passed");
+   printf("\nstore_test..."); fflush(stdout); printf(store_test() ? "failed" : "passed");
+   printf("\nrsa_test..."); fflush(stdout); printf(rsa_test() ? "failed" : "passed");
+   printf("\necc_test..."); fflush(stdout); printf(ecc_tests() ? "failed" : "passed");
+   printf("\ndsa_test..."); fflush(stdout); printf(dsa_test() ? "failed" : "passed");
+   printf("\ndh_test..."); fflush(stdout); printf(dh_tests() ? "failed" : "passed");
+   printf("\nder_test..."); fflush(stdout); printf(der_tests() ? "failed" : "passed");
+
+   return EXIT_SUCCESS;
+}
diff --git a/demos/test/.ccmalloc b/demos/test/.ccmalloc
deleted file mode 100644
index 1b0aba2..0000000
--- a/demos/test/.ccmalloc
+++ /dev/null
@@ -1,356 +0,0 @@
-                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-                %%%% generic configuration file for %%%%
-                %%%%  the ccmalloc memory profiler  %%%%
-                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-    
-    %-----------------------------------------------------------------%
-    % COPY THIS FILE TO '.ccmalloc' in your project or home directory %
-    %-----------------------------------------------------------------%
-
-##############################################################################
-## (C) 1997-2003 Armin Biere, 1998 Johannes Keukelaar
-## $Id: ccmalloc.cfg,v 1.6 2003/02/03 08:03:54 biere Exp $
-##############################################################################
-
-%%% '%' and '#' are comments !!!!!!!
-
-% This file must be called '.ccmalloc' and is searched for in the
-% current directory and in the home directory of the user. If it
-% does not exist then the default values mentioned below are used.
-
-% It is also the only available user manual yet ;-) So here is a reading
-% hint. First have a look at the short one line descriptions of each option
-% ...
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% with 'file' the executable is specified [a.out]
-% ----------------------------------------------------------------------
-% This should not be necessary for Linux and Solaris because the proc
-% file system can be used to find argv[0].
-%
-% (the rest of this comment only applies to other OS)
-%
-% For other OS you should use this option unless the executable is
-% in the current directory or its name is 'a.out'.
-%
-% If you do not specify this then ccmalloc tries to find an executable
-% in the current directory that matches the running program starting
-% with 'a.out'. For this process it must call 'nm' on each executable
-% file in the directory which may be time consuming. With this option
-% you can speed up this process.
-%
-% You can also specify absolute or relative path names. This is 
-% necessary if you do not start your program from the current directory.
-% But you can also simply link or name your program to 'a.out'.
-
-%file FILE
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'log' specify the logfile [stderr]
-% ----------------------------------------------------------------------
-% The default is to use stderr. The argument to 'log' is the name of
-% the file you want to write to. It can also be 'stdout' or '-' which 
-% sets stdout as logfile. If the logfile is stdout or stderr and is
-% connected to a terminal then the output is slightly different.
-%
-% For big programs the logfile can be really big. To reduce the size
-% you can use a small chain length (see 'chain-length' below). The other
-% possibility is to use compressed logfiles. This can be done by
-% specifying a logfile name with  a '.gz' (or a '.Z') suffix. This means
-% that gnuzip (resp. compress) is used to compress the output.
-
-%log FILE
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'logpid' specify the logfile
-% ----------------------------------------------------------------------
-% Can be used alternatively to the 'log' command if you want to use
-% ccmalloc for debugging parallel applications where several copies of
-% the program you are debugging must be run simoultaneously. In this
-% case you can not use 'log' because you do not want to write to the same
-% log file. Using 'logpid' uses a file name ending with the <pid> of
-% the process which means the name is unique even if several copies of
-% your program are run simoultaneously.
-%
-% If you use the compressing suffixes then the <pid> is inserted before
-% the suffix (e.g. 'logpid ccmalloc.log.gz' uses 'ccmalloc.log.<pid>.gz'
-% as the name for the log file).
-
-%logpid FILE
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'dont-log-chain' skip info about certain chains []
-% ----------------------------------------------------------------------
-% This command may be repeated any number of times. The argument to this
-% command is a comma-separated list of function-or-file-and-line
-% specifications. Garbage allocated from a callchain that contains this
-% subchain anywhere will _not_ be logged.
-%
-% The ';'-separated list should not contain any spaces. E.g. not:
-%
-%    main ; foo ; bar
-%
-% but:
-%
-%     main;foo;bar
-%
-% A function-or-file-and-line specification is a string followed by an
-% optional colon and number, for example: main or main:14 or main.c or
-% main.c:15. Note that the string is compared with both the function and the
-% file name, if available. If main.c happens to be a function name, that
-% will cause a match (for that string at least).  Not specifying a line
-% number will match any line number. If line number information is not
-% available, anything will match!  Not specifying a name (e.g. ;;;) will
-% match an unknown function name.  Not giving any parameters at all, will
-% match a chain containing at least one unknown function.
-%
-% Note that if you say 'dont-log-chain wrapper.c' nothing will be logged.
-
-%dont-log-chain
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'only-log-chain' skip info about other chains []
-% ----------------------------------------------------------------------
-% The obvious counterpart to dont-log-chain. In this case, only matching
-% chains will be reported. Non-matching chains will not be reported.
-% Can be repeated any number of times; if the chain matches any of the
-% instances, it will be reported.
-
-%only-log-chain
-
-########################################################################
-#                                                                      #
-# This is the 'flag' section                                           #
-#                                                                      #
-#    'set FLAG' is the same as 'set FLAG 1'                            #
-#                                                                      #
-# The default values are those set below.  If 'silent' is disabled     #
-# then you will find the banner in the log file (or it is listed on    #
-# stdout or stderr). The banner describes the current settings of all  #
-# these flags.                                                         #
-#                                                                      #
-########################################################################
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% with 'only-count' ccmalloc only counts garbage - no call chains [0]
-% ----------------------------------------------------------------------
-% If only-count is set to one then only one additional pointer for
-% each allocated data is used and no call chain is generated. This is
-% the fasted and most space efficient mode ccmalloc can operate
-% in. In this mode you get at least the size of garbage produced.
-%
-% Note that 'check-free-space' does not work at all with 'only-count'
-% set and over writes ('check-overwrites') are only checked when
-% calling free.
-
-%set only-count 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'load-dynlibs' load dynamic linked libraries into gdb [0]
-% ----------------------------------------------------------------------
-% If your program is linked with dynamic libraries, function and file
-% name information is not available for addresses in those libraries,
-% unless you set 'load-dynlibs' to 1.
-
-%set load-dynlibs 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'keep-deallocated-data' does not recycle deallocated data [0]
-% ----------------------------------------------------------------------
-% If you enable keep-deallocated-data then all data deallocated with
-% 'free' (or 'delete' in C++) is not given back to the free store
-% but stays associated with the call chain of its allocation. This is
-% very useful if your program does multiple deallocation of the
-% same data.
-
-%set keep-deallocated-data 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'check-overwrites' detect overwrites [0]
-% ----------------------------------------------------------------------
-% If you want to detect 'off by n bytes' errors you should set
-% 'checking-overwrites' to n/4 (on 32-Bit machines).
-%
-% ccmalloc inserts a boundary above allocated data. This boundary
-% consists of 'check-overwrites' words. If your program writes to
-% this area then ccmalloc can detect this (see also check-start
-% and check-interval). 'ccmalloc' also does checking for overwrites
-% at non word boundaries (e.g. strcpy(malloc(strlen("hello")),"hello");)
-
-set check-overwrites 1
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'check-underwrites' detect underwrites [0]
-% ----------------------------------------------------------------------
-% same with writes below allocated data. You do not have to set this
-% option if you only want detect 'off (below) by one' errors because
-% ccmalloc keeps a magic value just before the user data.
-
-set check-underwrites 1
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'check-free-space' can be used to find dangling pointers. [0]
-% ----------------------------------------------------------------------
-% A very serious type of bug is to write on data that has already been
-% freed. If this happens the free space management of malloc is in
-% trouble and you will perhaps encounter non deterministic behaviour of
-% your program. To test this first enable 'keep-deallocated-data' and
-% restart your program. If the problem goes away and ccmalloc does not
-% report anything then you should *also* enable 'check-free-space'. Now
-% ccmalloc checks already deallocated data for corruption.
-%
-% Note that to perform this check 'keep-deallocated-data' also must
-% be enabled and 'only-count' disabled.
-
-set check-free-space 1
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'check-interval' can be used to speed up checks [0]
-% ----------------------------------------------------------------------
-% If check-overwrite, check-underwrites or check-free-space is set then
-% the default is to do 'write checks' when data is deallocated and
-% to do 'free space checks' when reporting together with
-% 'write checks' for garbage. When you want these checks to be
-% performed more often then you should set 'check-interval' to a
-% positive number. This number is the interval between the number of
-% calls to free or malloc without performing the checks.
-
-%set check-interval 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'check-start' can be used to speed up checks [0]
-% ----------------------------------------------------------------------
-% The flag 'check-start' delays the start of checks until the given
-% number of calls to free and malloc have occured. Together with
-% 'check-interval' you can use a binary search to find an aproximation
-% when a corruption occured! If you simply set check-interval to 1 and
-% check-start to 0 then this will slow done your program too much.
-
-%set check-start 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'silent' disables banner [0]
-% ----------------------------------------------------------------------
-% If you don't want to see the banner of ccmalloc then set
-% 'silent' to 1 (f.e. when logging to stderr)
-
-%set silent
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'file-info' en/disables file and line number information [1]
-% ----------------------------------------------------------------------
-% If your program was compiled with debugging information (-g) then
-% ccmalloc can generate line number and file info for call chains opening
-% a pipe to gdb. For very big programs this method is slow. In this case
-% you can set 'file-info' to zero and you will only get the function
-% names. For SunOS 4.3.1 'nm' does not 'demangle' C++ identifiers
-% very well. So gdb is called instead but only if 'file-info' is
-% not set to 0.
-
-%set file-info 1
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'continue' if ccmalloc aborts when something weired happened [0]
-% ----------------------------------------------------------------------
-% If the free function of ccmalloc is called with an argument that does
-% not make sense to ccmalloc or that has already been freed then you
-% probably want the program to stop at this point. This is also
-% the default behaviour. But you can force ccmalloc also to ignore
-% this if you set 'continue' to 1. This flag also controls the behaviour
-% of ccmalloc when free space is found to be corrupted or a write
-% boundary has been overwritten.
-
-%set continue 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'chain-length' is the length of the maximal call chain [0 = infinite]
-% ----------------------------------------------------------------------
-% You can restrict the length of call chains by setting 'chain-length'
-% to a number greater than zero. If 'chain-length' is zero (the default)
-% then chains are as long as possible (on a non x86 system only call
-% chains with a finite maximal length can be generated). For big
-% programs especially if keep-deallocated-data is enabled this can
-% reduce the size of the log file from over 100MB to several MB!
-
-%set chain-length 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'print-addresses' of data [0]
-% ----------------------------------------------------------------------
-% If you want to see the addresses of the allocated data (and
-% deallocated data if keep-deallocated-data is set to 1) set
-% 'print-addresses' to 1.
-
-%set print-addresses 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'print-on-one-line' shortens log file [0]
-% ----------------------------------------------------------------------
-% The default is to print function names and file/line number info
-% on separate lines. With 'print-on-one-line' set 1 all are printed
-% on one line.
-
-%set print-on-one-line 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'additional-line' enlarges readability [1]
-% ----------------------------------------------------------------------
-% When printing call chains an empty line is printed between to
-% call points. Set 'additional-line' to 0 to disable this feature.
-
-%set additional-line 1
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 'statistics' enables more accurate profiling [0] 
-% ----------------------------------------------------------------------
-% Calculate number of allocations and deallocations and bytes also on
-% a per call chain basis. This uses 4 additional pointers for each
-% call chain.
-
-set statistics 1
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% set order for sorting of call chains [1] [1]
-% ----------------------------------------------------------------------
-% When printing the report to the log file the call chains are sorted by
-% default with respect to the largest accumulated garbage produced by
-% that call chain. This can be changed with setting 'sort-by-wasted'
-% to 0. In this case they are sorted by the number of allocated bytes.
-% If you want the number of allocations (only possible if 'statistics'
-% is enabled) as sorting criteria instead then set 'sort-by-size' to 0.
-
-%set sort-by-wasted 1
-%set sort-by-size 1
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% report library chains [0]
-% ----------------------------------------------------------------------
-% Some external libraries (like libg++) have memory leaks. On some
-% systems even a call to printf produces a leak. ccmalloc tries to
-% detect this (only heuristically!) and with this flag you can control
-% if leaks produced by such library calls are reported.
-%
-% Since version 0.2.1 some similar effect can be achieved by using
-% 'dont-log-chain' with no argument.
-
-%set library-chains 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% print debugging information [X] (compile time dependend)
-% ----------------------------------------------------------------------
-
-%set debug X
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% align memory on 8 byte boundary [0] (no effect on SunOS or Solaris)
-% ----------------------------------------------------------------------
-
-%set align-8-byte 0
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% only report allocations which ended up being wasted (i.e don't report
-% allocations which were completely freed properly. ) [1]
-% ----------------------------------------------------------------------
-
-%set only-wasting-alloc 1
diff --git a/demos/test/mac_test.c b/demos/test/mac_test.c
deleted file mode 100644
index 52e75d8..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 e306d17..0000000
--- a/demos/test/makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# make test harness, it is good.
-CFLAGS += -Wall -W -Os -I../../ -I./
-
-# add -g3 for ccmalloc debugging 
-#CFLAGS += -g3
-
-# if you're not debugging
-CFLAGS += -fomit-frame-pointer
-
-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.o dh_tests.o der_tests.o 
-
-#uncomment this to get heap checking [e.g. memory leaks].  Note 
-#that you *MUST* build libtomcrypt.a with -g3 enabled [and make install it]
-#
-#
-#CCMALLOC = -lccmalloc -ldl
-
-test: $(OBJECTS)
-	$(CC) $(OBJECTS) /usr/lib/libtomcrypt.a  $(CCMALLOC) -o test
-	
-clean:
-	rm -rf test *.o *.obj *.exe *~	.libs
diff --git a/demos/test/makefile.icc b/demos/test/makefile.icc
deleted file mode 100644
index b32c9ba..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.o dh_tests.o der_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 8769ecf..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 der_tests.obj
-
-
-test.exe: $(OBJECTS)
-	cl $(OBJECTS) tomcrypt.lib advapi32.lib 
-	
-clean:
-	rm -f test.exe *.obj *~	
diff --git a/demos/test/makefile.shared b/demos/test/makefile.shared
deleted file mode 100644
index d90c1da..0000000
--- a/demos/test/makefile.shared
+++ /dev/null
@@ -1,19 +0,0 @@
-# make test harness, it is good.
-CFLAGS += -Wall -W -Os -I../../ -I./
-
-# if you're not debugging
-CFLAGS += -fomit-frame-pointer
-
-default: test
-
-#if you don't have mpi.o 
-#MPISHARED=-ltommath
-
-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.o dh_tests.o der_tests.o 
-
-test: $(OBJECTS)
-	libtool --mode=link gcc $(CFLAGS) $(OBJECTS) -o test -ltomcrypt $(MPISHARED)
-	
-clean:
-	rm -f test *.o *.obj *.exe *~	
diff --git a/demos/test/test.c b/demos/test/test.c
deleted file mode 100644
index a56e5d6..0000000
--- a/demos/test/test.c
+++ /dev/null
@@ -1,262 +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             },
-{"der_test",               "e",         "",          der_tests            },
-
-{"pkcs_1_test",            "f",        "e",          pkcs_1_test          },
-{"rsa_test",               "g",        "e",          rsa_test             },
-{"ecc_test",               "h",        "a",          ecc_tests            },
-{"dsa_test",               "i",        "a",          dsa_test             },
-{"dh_test",                "j",        "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)
-{
-  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 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 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
-
-
-#ifdef YARROW
-   register_prng(&yarrow_desc);
-#endif
-#ifdef FORTUNA
-   register_prng(&fortuna_desc);
-#endif
-#ifdef RC4
-   register_prng(&rc4_desc);
-#endif
-#ifdef SPRNG
-   register_prng(&sprng_desc);
-#endif
-#ifdef SOBER128
-   register_prng(&sober128_desc);
-#endif
-}
-
-/* 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);
-}
-
-#define STACKBLOCK       8
-#define STACK_EST_USAGE  32768
-
-unsigned char stack_mask[STACKBLOCK];
-unsigned long stack_cur=0;
-
-void stack_masker(void)
-{
-#ifdef STACK_TEST
-   volatile unsigned char M[STACK_EST_USAGE];
-   stack_cur   = 0;
-   for (stack_cur = 0; stack_cur < STACK_EST_USAGE/STACKBLOCK; stack_cur++) {
-       memcpy(M+(stack_cur*STACKBLOCK), stack_mask, STACKBLOCK);
-   }
-#endif
-}
-
-void stack_check(void)
-{
-#ifdef STACK_TEST
-   unsigned char M[STACK_EST_USAGE];
-   stack_cur   = 0;
-#ifdef STACK_DOWN
-   while (memcmp(M+(STACK_EST_USAGE-STACKBLOCK-stack_cur), stack_mask, STACKBLOCK) && 
-#else
-   while (memcmp(M+stack_cur, stack_mask, STACKBLOCK) &&
-#endif
-          stack_cur < (STACK_EST_USAGE - STACKBLOCK)) {
-      ++stack_cur;
-   }
-#endif
-}
-
-int main(void)
-{
-   int x;
-   unsigned char buf[16];
-
-   /* setup stack checker */
-   srand(time(NULL));
-   for (x = 0; x < STACKBLOCK; x++) {
-       stack_mask[x] = rand() & 255;
-   }
-   stack_masker();
-
-   printf("Built with\n%s\n", crypt_build_settings);
-
-   sort();
-   register_algs();
-      
-   // start dummy yarrow for internal use 
-   DO(yarrow_start(&test_yarrow));
-   sprng_read(buf, 16, NULL);
-   DO(yarrow_add_entropy(buf, 16, &test_yarrow));
-   DO(yarrow_ready(&test_yarrow));
-
-   // output sizes 
-   printf("Sizes of objects (in bytes)\n");
-   printf("\tsymmetric_key\t=\t%5lu\n", sizeof(symmetric_key));
-   printf("\thash_state\t=\t%5lu\n", sizeof(hash_state));
-   printf("\thmac_state\t=\t%5lu\n", sizeof(hmac_state));
-   printf("\tomac_state\t=\t%5lu\n", sizeof(omac_state));
-   printf("\tpmac_state\t=\t%5lu\n", sizeof(pmac_state));
-   printf("\tocb_state\t=\t%5lu\n", sizeof(ocb_state));
-   printf("\teax_state\t=\t%5lu\n", sizeof(eax_state));
-   printf("\tmp_int\t\t=\t%5lu\n", sizeof(mp_int));
-#ifdef MRSA
-   printf("\trsa_key\t\t=\t%5lu\n", sizeof(rsa_key));
-#endif
-#ifdef MDSA
-   printf("\tdsa_key\t\t=\t%5lu\n", sizeof(dsa_key));
-#endif
-#ifdef MDH
-   printf("\tdh_key\t\t=\t%5lu\n", sizeof(dh_key));
-#endif
-#ifdef MECC
-   printf("\tecc_key\t\t=\t%5lu\n", sizeof(ecc_key));
-#endif
-
-   printf("\n\n");
-   // 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 1dee4bf..0000000
--- a/demos/test/test.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef __TEST_H_
-#define __TEST_H_
-
-#include "mycrypt.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 test_yarrow;
-
-
-void stack_masker(void);
-void stack_check(void);
-extern unsigned long stack_cur;
-#define stack_chk(x) { stack_check(); if (stack_cur >= 1024) { fprintf(stderr, " Warning: Stack usage of %lu in %s, %s:%d\n", stack_cur, x, __FILE__, __LINE__); } }
-
-void run_cmd(int res, int line, char *file, char *cmd);
-#define DO(x) { stack_masker(); run_cmd((x), __LINE__, __FILE__, #x); stack_chk(#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);
-
-#endif
diff --git a/demos/timing.c b/demos/timing.c
new file mode 100644
index 0000000..54c0462
--- /dev/null
+++ b/demos/timing.c
@@ -0,0 +1,23 @@
+#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;
+
+}
diff --git a/demos/tv_gen.c b/demos/tv_gen.c
index 07633fc..c37d1af 100644
--- a/demos/tv_gen.c
+++ b/demos/tv_gen.c
@@ -1,4 +1,4 @@
-#include <mycrypt.h>
+#include <tomcrypt.h>
 
 void reg_algs(void)
 {
@@ -47,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);
@@ -495,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;
@@ -524,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;
 }
diff --git a/demos/x86_prof.c b/demos/x86_prof.c
deleted file mode 100644
index b77b76c..0000000
--- a/demos/x86_prof.c
+++ /dev/null
@@ -1,740 +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__
-      #if defined(__i386__) || defined(__x86_64__)
-         unsigned long long a;
-         __asm__ __volatile__ ("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::"m"(a):"%eax","%edx");
-         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)
-{
-  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 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) {
-     printf("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"), &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];
-
-  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];
-  int err;
-
-  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);
-
-    /* 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   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), err;
-  unsigned char pt[MAXBLOCKSIZE];
-
-
-  printf ("\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;
-    printf("."); fflush(stdout);
-#undef DO2
-#undef DO1
-   }
-   tally_results(2);
-
-   return 0;
-}
-
-void time_mult(void)
-{
-   ulong64 t1, t2;
-   unsigned long x, y;
-   mp_int  a, b, c;
-
-   printf("Timing Multiplying:\n");
-   mp_init_multi(&a,&b,&c,NULL);
-   for (x = 128/DIGIT_BIT; x <= 1024/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;
-       }
-       printf("%3lu digits: %9llu cycles\n", x, 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;
-
-   printf("Timing Squaring:\n");
-   mp_init_multi(&a,&b,NULL);
-   for (x = 128/DIGIT_BIT; x <= 1024/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;
-       }
-       printf("%3lu digits: %9llu cycles\n", x, t2);
-   }
-   mp_clear_multi(&a,&b,NULL);
-
-#undef DO1
-#undef DO2
-}    
-   
-void time_prng(void)
-{
-   ulong64 t1, t2;
-   unsigned char buf[4096];
-   prng_state tprng;
-   unsigned long x, y;
-   int           err;
-
-   printf("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) { printf("\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;
-      }
-      printf("%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;
-      }
-      printf("%5llu\n", t2);
-#undef DO2
-#undef DO1
-
-   }
-}
-      
-/* 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(&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;
-       printf("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, &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;
-       printf("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, &prng,
-                                      find_prng("yarrow"), 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;
-       printf("RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
-
-
-       rsa_free(&key);
-  }
-}
-
-/* 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[] = {160/8, 256/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(&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;
-       printf("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, &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;
-       printf("ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
-       ecc_free(&key);
-  }
-}
-
-/* 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(&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;
-       printf("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, &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;
-       printf("DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
-       dh_free(&key);
-  }
-}
-
-#define MAC_SIZE 32
-void time_macs(void)
-{
-   unsigned char *buf, key[16], tag[16];
-   ulong64 t1, t2;
-   unsigned long x, z;
-   int err, cipher_idx, hash_idx;
-
-   printf("\nMAC Timings (cycles/byte on %dKB 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, &prng);
-   yarrow_read(key, 16, &prng);
-
-   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;
-   }
-   printf("OMAC-AES\t\t%9llu\n", t2/(MAC_SIZE*1024));
-
-   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;
-   }
-   printf("PMAC-AES\t\t%9llu\n", t2/(MAC_SIZE*1024));
-
-   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;
-   }
-   printf("HMAC-MD5\t\t%9llu\n", t2/(MAC_SIZE*1024));
-
-   XFREE(buf);
-}
-
-int main(void)
-{
-  reg_algs();
-
-  printf("Timings for ciphers and hashes.  Times are listed as cycles per byte processed.\n\n");
-
-//  init_timer();
-  time_mult();
-  time_sqr();
-  time_rsa();
-  time_dh();
-  time_ecc();
-  time_prng();
-  time_cipher();
-  time_keysched();
-  time_hash();
-  time_macs();
-
-  return EXIT_SUCCESS;
-}
-
diff --git a/der_put_multi_integer.c b/der_put_multi_integer.c
deleted file mode 100644
index e166e0b..0000000
--- a/der_put_multi_integer.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 <stdarg.h>
-#include "mycrypt.h"
-
-/* store multiple mp_ints in DER INTEGER format to the dst, will not
- * overflow the length you give it [outlen] and store the number of 
- * bytes used in [outlen] 
- */
-int der_put_multi_integer(unsigned char *dst, unsigned long *outlen, 
-                  mp_int *num, ...)
-{
-   va_list        args;
-   mp_int        *next;
-   unsigned long  wrote, len;
-   int            err;
-
-   _ARGCHK(dst    != NULL);
-   _ARGCHK(outlen != NULL);
-
-   /* setup va list */
-   next  = num;
-   len   = *outlen;
-   wrote = 0;
-   va_start(args, num);
-
-   while (next != NULL) {
-        if ((err = der_encode_integer(next, dst, outlen)) != CRYPT_OK) {
-           va_end(args);
-           return err;
-        }
-        wrote   += *outlen;
-        dst     += *outlen;
-        len     -= *outlen;
-        *outlen  = len;
-        next     = va_arg(args, mp_int*);
-   }
-   va_end(args);
-   *outlen = wrote;
-   return CRYPT_OK;
-}
diff --git a/doc/crypt.pdf b/doc/crypt.pdf
index c0ad1e3..9eb60c6 100644
--- a/doc/crypt.pdf
+++ b/doc/crypt.pdf
Binary files differ
diff --git a/doc/footer.html b/doc/footer.html
new file mode 100644
index 0000000..fe5338c
--- /dev/null
+++ b/doc/footer.html
@@ -0,0 +1,4 @@
+<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">
diff --git a/doc/header.html b/doc/header.html
new file mode 100644
index 0000000..426d4e3
--- /dev/null
+++ b/doc/header.html
@@ -0,0 +1,6 @@
+<!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 -->
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 782d4f6..0000000
--- a/eax_decrypt_verify_memory.c
+++ /dev/null
@@ -1,80 +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;
-   unsigned long  buflen;
-
-   _ARGCHK(res != NULL);
-
-   /* default to zero */
-   *res = 0;
-
-   /* allocate ram */
-   buf = XMALLOC(taglen);
-   eax = XMALLOC(sizeof(eax_state));
-   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 __ERR;
-   }
-
-   if ((err = eax_decrypt(eax, ct, pt, ctlen)) != CRYPT_OK) {
-      goto __ERR;
-   }
- 
-   buflen = taglen;
-   if ((err = eax_done(eax, buf, &buflen)) != CRYPT_OK) {
-      goto __ERR;
-   }
-
-   /* compare tags */
-   if (buflen >= taglen && memcmp(buf, tag, taglen) == 0) {
-      *res = 1;
-   }
-   
-   err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(buf, taglen);
-   zeromem(eax, sizeof(eax_state));
-#endif
-
-   XFREE(eax);
-   XFREE(buf);
-
-   return err;
-}
-
-#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 9e9a428..0000000
--- a/eax_encrypt_authenticate_memory.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
- */
-
-/* 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;
-
-   eax = XMALLOC(sizeof(eax_state));
-
-   if ((err = eax_init(eax, cipher, key, keylen, nonce, noncelen, header, headerlen)) != CRYPT_OK) {
-      goto __ERR; 
-   }
-
-   if ((err = eax_encrypt(eax, pt, ct, ptlen)) != CRYPT_OK) {
-      goto __ERR; 
-   }
- 
-   if ((err = eax_done(eax, tag, taglen)) != CRYPT_OK) {
-      goto __ERR; 
-   }
-
-   err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(eax, sizeof(eax_state));
-#endif
-
-   XFREE(eax);
-
-   return err;   
-}
-
-#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 2c50a5f..0000000
--- a/ecc.c
+++ /dev/null
@@ -1,955 +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
-
-/* size of our temp buffers for exported keys */
-#define ECC_BUF_SIZE 160
-
-/* 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 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;
-
-   _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;
-   _ARGCHK(keysize <= ECC_MAXSIZE);
-
-   if (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 __ERR2;
-   }
-
-   /* setup the key variables */
-   if ((err = mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->k, &prime, NULL)) != MP_OKAY) {
-      err = mpi_to_ltc_error(err);
-      goto __ERR;
-   }
-   base = new_point();
-   if (base == NULL) {
-      mp_clear_multi(&key->pubkey.x, &key->pubkey.y, &key->k, &prime, NULL);
-      err = CRYPT_MEM;
-      goto __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; }
-   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 __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; }
-
-   /* free up ram */
-   err = CRYPT_OK;
-   goto __ERR;
-error:
-   err = mpi_to_ltc_error(err);
-__ERR:
-   del_point(base);
-   mp_clear(&prime);
-__ERR2:
-#ifdef CLEAN_STACK
-   zeromem(buf, ECC_MAXSIZE);
-#endif
-
-   XFREE(buf);
-
-   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/genlist.sh b/genlist.sh
new file mode 100644
index 0000000..73daa1d
--- /dev/null
+++ b/genlist.sh
@@ -0,0 +1,6 @@
+#!/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"
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 cf179e0..0000000
--- a/hash_filehandle.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
- */
-#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;
-    }
-    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, dst);
-
-#ifdef CLEAN_STACK
-    zeromem(buf, sizeof(buf));
-#endif
-    return err;
-#endif
-}
-
diff --git a/hash_memory.c b/hash_memory.c
deleted file mode 100644
index 2c87d76..0000000
--- a/hash_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
- */
-#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;
-    }
-
-    md = XMALLOC(sizeof(hash_state));
-    if (md == NULL) {
-       return CRYPT_MEM;
-    }
-
-    if ((err = hash_descriptor[hash].init(md)) != CRYPT_OK) {
-       goto __ERR;
-    }
-    if ((err = hash_descriptor[hash].process(md, data, len)) != CRYPT_OK) {
-       goto __ERR;
-    }
-    err = hash_descriptor[hash].done(md, dst);
-    *outlen = hash_descriptor[hash].hashsize;
-__ERR:
-#ifdef CLEAN_STACK
-    zeromem(md, sizeof(hash_state));
-#endif
-    XFREE(md);
-
-    return err;
-}
diff --git a/hmac_file.c b/hmac_file.c
deleted file mode 100644
index e88b62f..0000000
--- a/hmac_file.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
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-#ifdef HMAC
-
-/* 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_memory.c b/hmac_memory.c
deleted file mode 100644
index d6d3364..0000000
--- a/hmac_memory.c
+++ /dev/null
@@ -1,58 +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"
-
-#ifdef HMAC
-
-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);
-
-    /* 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 __ERR;
-    }
-
-    if ((err = hmac_process(hmac, data, len)) != CRYPT_OK) {
-       goto __ERR;
-    }
-
-    if ((err = hmac_done(hmac, dst, dstlen)) != CRYPT_OK) {
-       goto __ERR;
-    }
-
-   err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(hmac, sizeof(hmac_state));
-#endif
-
-   XFREE(hmac);
-   return err;   
-}
-
-#endif
-
diff --git a/hmac_process.c b/hmac_process.c
deleted file mode 100644
index ebc6f4c..0000000
--- a/hmac_process.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
- */
-/* Submited by Dobes Vandermeer  (dobes@smartt.com) */
-
-#include "mycrypt.h"
-
-#ifdef HMAC
-
-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/makefile b/makefile
index c90b88d..b38aa17 100644
--- a/makefile
+++ b/makefile
@@ -4,7 +4,7 @@
 # Modified by Clay Culver
 
 # The version
-VERSION=0.99
+VERSION=1.02
 
 # Compiler and Linker Names
 #CC=gcc
@@ -15,30 +15,39 @@
 #ARFLAGS=r
 
 # Compilation flags. Note the += does not write over the user's CFLAGS!
-CFLAGS += -c -I./ -Wall -Wsign-compare -W -Wshadow 
-# -Werror
+CFLAGS += -c -I./testprof/ -I./src/headers/ -Wall -Wsign-compare -W -Wshadow -Wno-unused-parameter
+
+# 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-all-loops
+CFLAGS += -O3 -funroll-loops
 
-#add -fomit-frame-pointer.  hinders debugging!
-#CFLAGS += -fomit-frame-pointer
+# add -fomit-frame-pointer.  hinders debugging!
+CFLAGS += -fomit-frame-pointer
 
 # optimize for SIZE
-CFLAGS += -Os -DSMALL_CODE
+#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
-
-#These flags control how the library gets built.
+#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.
@@ -48,85 +57,96 @@
 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=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    \
-\
-sober128.o fortuna.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 \
-rsa_v15_encrypt_key.o rsa_v15_decrypt_key.o rsa_v15_sign_hash.o rsa_v15_verify_hash.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 chc.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 \
-\
-der_encode_integer.o der_decode_integer.o der_length_integer.o \
-der_put_multi_integer.o der_get_multi_integer.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/der_decode_integer.o src/pk/asn1/der/der_encode_integer.o \
+src/pk/asn1/der/der_get_multi_integer.o src/pk/asn1/der/der_length_integer.o \
+src/pk/asn1/der/der_put_multi_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
+src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
+src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/packet_store_header.o \
+src/pk/packet_valid_header.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mgf1.o \
+src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
+src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v15_es_decode.o \
+src/pk/pkcs1/pkcs_1_v15_es_encode.o src/pk/pkcs1/pkcs_1_v15_sa_decode.o \
+src/pk/pkcs1/pkcs_1_v15_sa_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
+src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
+src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_v15_decrypt_key.o \
+src/pk/rsa/rsa_v15_encrypt_key.o src/pk/rsa/rsa_v15_sign_hash.o src/pk/rsa/rsa_v15_verify_hash.o \
+src/pk/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
-PROFS=demos/x86_prof.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
@@ -134,33 +154,31 @@
 #Compressed filenames
 COMPRESSED=crypt-$(VERSION).tar.bz2 crypt-$(VERSION).zip
 
-#Header files used by libtomcrypt.
-HEADERS=ltc_tommath.h mycrypt_cfg.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 mycrypt_pkcs.h tommath_class.h tommath_superclass.h
-
 #The default rule for make builds the libtomcrypt library.
 default:library
 
 #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
+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.
-aes.o: aes.c aes_tab.c
-twofish.o: twofish.c twofish_tab.c
-whirl.o: whirl.c whirltab.c
-ecc.o: ecc.c ecc_sys.c
-dh.o: dh.c dh_sys.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 ; CFLAGS="$(CFLAGS)" make 
 
 $(LIBNAME): $(OBJECTS)
 	$(AR) $(ARFLAGS) $@ $(OBJECTS) 
+	ranlib $(LIBNAME)
 
 #This rule makes the hash program included with libtomcrypt
 hashsum: library $(HASHOBJECTS)
@@ -174,38 +192,62 @@
 small: library $(SMALLOBJECTS)
 	$(CC) $(SMALLOBJECTS) $(LIBNAME) -o $(SMALL) $(WARN)
 	
-x86_prof: library $(PROFS)
-	$(CC) $(PROFS) $(LIBNAME) $(EXTRALIBS) -o $(PROF)
-
 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 root -o root $(DESTDIR)$(LIBPATH)
-	install -d -g root -o root $(DESTDIR)$(INCPATH)
-	install -d -g root -o root $(DESTDIR)$(DATAPATH)
-	install -g root -o root $(LIBNAME) $(DESTDIR)$(LIBPATH)
-	install -g root -o root $(HEADERS) $(DESTDIR)$(INCPATH)
-	install -g root -o root doc/crypt.pdf $(DESTDIR)$(DATAPATH)
+	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 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 $(HEADERS) $(DESTDIR)$(INCPATH)
+	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 $(OBJECTS) $(TESTOBJECTS) $(HASHOBJECTS) $(CRYPTOBJECTS) $(SMALLOBJECTS) $(LEFTOVERS) $(LIBNAME)
-	rm -f $(TEST) $(HASH) $(COMPRESSED) $(PROFS) $(PROF) $(TVS) $(TV)
-	rm -f *.la *.lo *.o *.a *.dll *stackdump *.lib *.exe *.obj demos/*.obj demos/*.o *.bat *.txt *.il *.da demos/*.il demos/*.da *.dyn *.dpi \
-	*.gcda *.gcno demos/*.gcno demos/*.gcda *~ doc/*
-	cd demos/test ; make clean   
-	rm -rf .libs demos/.libs demos/test/.libs
+	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
@@ -229,21 +271,15 @@
 	makeindex crypt.idx
 	latex crypt > /dev/null
 
-#pretty build
-pretty:
-	perl pretty.build
-
-#for GCC 3.4+
-profiled:
-	make clean
-	make CFLAGS="$(CFLAGS) -fprofile-generate" EXTRALIBS=-lgcov x86_prof
-	./x86_prof
-	rm *.o *.a x86_prof
-	make CFLAGS="$(CFLAGS) -fprofile-use" EXTRALIBS=-lgcov x86_prof
-
 #zipup the project (take that!)
-zipup: clean docs
+no_oops: clean
+	cd .. ; cvs commit 
+
+zipup: no_oops docs
 	cd .. ; rm -rf crypt* libtomcrypt-$(VERSION) ; mkdir libtomcrypt-$(VERSION) ; \
-	cp -R ./libtomcrypt/* ./libtomcrypt-$(VERSION)/ ; tar -c libtomcrypt-$(VERSION)/* > crypt-$(VERSION).tar ; \
-	bzip2 -9vv crypt-$(VERSION).tar ; zip -9 -r crypt-$(VERSION).zip libtomcrypt-$(VERSION)/* ; \
-	gpg -b -a crypt-$(VERSION).tar.bz2 ; gpg -b -a crypt-$(VERSION).zip
+	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/makefile.cygwin_dll b/makefile.cygwin_dll
deleted file mode 100644
index 5e11b7c..0000000
--- a/makefile.cygwin_dll
+++ /dev/null
@@ -1,95 +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-all-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    \
-\
-sober128.o fortuna.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 \
-rsa_v15_encrypt_key.o rsa_v15_decrypt_key.o rsa_v15_sign_hash.o rsa_v15_verify_hash.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 chc.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 \
-\
-der_encode_integer.o der_decode_integer.o der_length_integer.o \
-der_put_multi_integer.o der_get_multi_integer.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 ee7ba54..41848dc 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 -I./src/headers/ -DINTEL_CC
 
 #The default rule for make builds the libtomcrypt library.
 default:library
@@ -30,18 +30,18 @@
 # 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 
+CFLAGS += -O3 -xP -ip 
 
 # want to see stuff?
 #CFLAGS += -opt_report
@@ -50,11 +50,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,76 +71,80 @@
 #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    \
-\
-sober128.o fortuna.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 \
-rsa_v15_encrypt_key.o rsa_v15_decrypt_key.o rsa_v15_sign_hash.o rsa_v15_verify_hash.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 chc.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 \
-\
-der_encode_integer.o der_decode_integer.o der_length_integer.o \
-der_put_multi_integer.o der_get_multi_integer.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/der_decode_integer.o src/pk/asn1/der/der_encode_integer.o \
+src/pk/asn1/der/der_get_multi_integer.o src/pk/asn1/der/der_length_integer.o \
+src/pk/asn1/der/der_put_multi_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
+src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
+src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/packet_store_header.o \
+src/pk/packet_valid_header.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mgf1.o \
+src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
+src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v15_es_decode.o \
+src/pk/pkcs1/pkcs_1_v15_es_encode.o src/pk/pkcs1/pkcs_1_v15_sa_decode.o \
+src/pk/pkcs1/pkcs_1_v15_sa_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
+src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
+src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_v15_decrypt_key.o \
+src/pk/rsa/rsa_v15_encrypt_key.o src/pk/rsa/rsa_v15_sign_hash.o src/pk/rsa/rsa_v15_verify_hash.o \
+src/pk/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
@@ -145,8 +153,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
@@ -154,25 +163,28 @@
 #Compressed filenames
 COMPRESSED=crypt.tar.bz2 crypt.zip crypt.tar.gz
 
-#Header files used by libtomcrypt.
-HEADERS=ltc_tommath.h mycrypt_cfg.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)
@@ -186,19 +198,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)
 
-profiled:
-	make clean
-	make CFLAGS="$(CFLAGS) -prof_gen" x86_prof
-	./x86_prof
-	rm *.o *.a x86_prof
-	make CFLAGS="$(CFLAGS) -prof_use" x86_prof
+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
@@ -208,10 +215,3 @@
 	install -d -g root -o root $(DESTDIR)$(INCPATH)
 	install -g root -o root $(LIBNAME) $(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
diff --git a/makefile.msvc b/makefile.msvc
index a5b5ef9..16d4b8d 100644
--- a/makefile.msvc
+++ b/makefile.msvc
@@ -1,93 +1,104 @@
 #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    \
-\
-sober128.obj fortuna.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 \
-rsa_v15_encrypt_key.obj rsa_v15_decrypt_key.obj rsa_v15_sign_hash.obj rsa_v15_verify_hash.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 chc.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 \
-\
-der_encode_integer.obj der_decode_integer.obj der_length_integer.obj \
-der_put_multi_integer.obj der_get_multi_integer.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/der_decode_integer.obj src/pk/asn1/der/der_encode_integer.obj \
+src/pk/asn1/der/der_get_multi_integer.obj src/pk/asn1/der/der_length_integer.obj \
+src/pk/asn1/der/der_put_multi_integer.obj src/pk/dh/dh.obj src/pk/dsa/dsa_export.obj src/pk/dsa/dsa_free.obj \
+src/pk/dsa/dsa_import.obj src/pk/dsa/dsa_make_key.obj src/pk/dsa/dsa_sign_hash.obj \
+src/pk/dsa/dsa_verify_hash.obj src/pk/dsa/dsa_verify_key.obj src/pk/ecc/ecc.obj src/pk/packet_store_header.obj \
+src/pk/packet_valid_header.obj src/pk/pkcs1/pkcs_1_i2osp.obj src/pk/pkcs1/pkcs_1_mgf1.obj \
+src/pk/pkcs1/pkcs_1_oaep_decode.obj src/pk/pkcs1/pkcs_1_oaep_encode.obj src/pk/pkcs1/pkcs_1_os2ip.obj \
+src/pk/pkcs1/pkcs_1_pss_decode.obj src/pk/pkcs1/pkcs_1_pss_encode.obj src/pk/pkcs1/pkcs_1_v15_es_decode.obj \
+src/pk/pkcs1/pkcs_1_v15_es_encode.obj src/pk/pkcs1/pkcs_1_v15_sa_decode.obj \
+src/pk/pkcs1/pkcs_1_v15_sa_encode.obj src/pk/rsa/rsa_decrypt_key.obj src/pk/rsa/rsa_encrypt_key.obj \
+src/pk/rsa/rsa_export.obj src/pk/rsa/rsa_exptmod.obj src/pk/rsa/rsa_free.obj src/pk/rsa/rsa_import.obj \
+src/pk/rsa/rsa_make_key.obj src/pk/rsa/rsa_sign_hash.obj src/pk/rsa/rsa_v15_decrypt_key.obj \
+src/pk/rsa/rsa_v15_encrypt_key.obj src/pk/rsa/rsa_v15_sign_hash.obj src/pk/rsa/rsa_v15_verify_hash.obj \
+src/pk/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
diff --git a/makefile.shared b/makefile.shared
index 5f5f5b8..207ceea 100644
--- a/makefile.shared
+++ b/makefile.shared
@@ -1,25 +1,27 @@
 # 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
-# Modified by Clay Culver
 
 # The version
-VERSION=0:99
+VERSION=0:102
 
 # Compiler and Linker Names
 CC=libtool --mode=compile gcc
 
-# Archiver [makes .a files]
-AR=libtool --mode=link 
-
 # Compilation flags. Note the += does not write over the user's CFLAGS!
-CFLAGS += -c -I./ -Wall -Wsign-compare -W -Wshadow 
-# -Werror
+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 
 
 # optimize for SPEED
 CFLAGS += -O3 -funroll-all-loops
 
-#add -fomit-frame-pointer.  hinders debugging!
+# add -fomit-frame-pointer.  hinders debugging!
 CFLAGS += -fomit-frame-pointer
 
 # optimize for SIZE
@@ -28,15 +30,21 @@
 # compile for DEBUGING (required for ccmalloc checking!!!)
 #CFLAGS += -g3
 
-#These flags control how the library gets built.
+# 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.
@@ -46,141 +54,145 @@
 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=mpi.o
+MPIOBJECT=src/misc/mpi/mpi.o
 
 #If you don't want mpi.o then add this
 #MPISHARED=$(LIBPATH)/libtommath.la
 
-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    \
-\
-sober128.o fortuna.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 \
-rsa_v15_encrypt_key.o rsa_v15_decrypt_key.o rsa_v15_sign_hash.o rsa_v15_verify_hash.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 chc.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 \
-\
-der_encode_integer.o der_decode_integer.o der_length_integer.o \
-der_put_multi_integer.o der_get_multi_integer.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/der_decode_integer.o src/pk/asn1/der/der_encode_integer.o \
+src/pk/asn1/der/der_get_multi_integer.o src/pk/asn1/der/der_length_integer.o \
+src/pk/asn1/der/der_put_multi_integer.o src/pk/dh/dh.o src/pk/dsa/dsa_export.o src/pk/dsa/dsa_free.o \
+src/pk/dsa/dsa_import.o src/pk/dsa/dsa_make_key.o src/pk/dsa/dsa_sign_hash.o \
+src/pk/dsa/dsa_verify_hash.o src/pk/dsa/dsa_verify_key.o src/pk/ecc/ecc.o src/pk/packet_store_header.o \
+src/pk/packet_valid_header.o src/pk/pkcs1/pkcs_1_i2osp.o src/pk/pkcs1/pkcs_1_mgf1.o \
+src/pk/pkcs1/pkcs_1_oaep_decode.o src/pk/pkcs1/pkcs_1_oaep_encode.o src/pk/pkcs1/pkcs_1_os2ip.o \
+src/pk/pkcs1/pkcs_1_pss_decode.o src/pk/pkcs1/pkcs_1_pss_encode.o src/pk/pkcs1/pkcs_1_v15_es_decode.o \
+src/pk/pkcs1/pkcs_1_v15_es_encode.o src/pk/pkcs1/pkcs_1_v15_sa_decode.o \
+src/pk/pkcs1/pkcs_1_v15_sa_encode.o src/pk/rsa/rsa_decrypt_key.o src/pk/rsa/rsa_encrypt_key.o \
+src/pk/rsa/rsa_export.o src/pk/rsa/rsa_exptmod.o src/pk/rsa/rsa_free.o src/pk/rsa/rsa_import.o \
+src/pk/rsa/rsa_make_key.o src/pk/rsa/rsa_sign_hash.o src/pk/rsa/rsa_v15_decrypt_key.o \
+src/pk/rsa/rsa_v15_encrypt_key.o src/pk/rsa/rsa_v15_sign_hash.o src/pk/rsa/rsa_v15_verify_hash.o \
+src/pk/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
-PROFS=demos/x86_prof.o
 TVS=demos/tv_gen.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
-
-#Header files used by libtomcrypt.
-HEADERS=ltc_tommath.h mycrypt_cfg.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 mycrypt_pkcs.h tommath_class.h tommath_superclass.h
+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 
-aes_enc.o: aes.c aes_tab.c
-	$(CC) $(CFLAGS) -DENCRYPT_ONLY -c aes.c -o aes_enc.o
+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.
-aes.o: aes.c aes_tab.c
-twofish.o: twofish.c twofish_tab.c
-whirl.o: whirl.c whirltab.c
-ecc.o: ecc.c ecc_sys.c
-dh.o: dh.c dh_sys.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 ; CFLAGS="$(CFLAGS)" GROUP=$(GROUP) USER=$(USER) VERSION=$(VERSION) LIBPATH=$(LIBPATH) LIBNAME=$(LIBTEST) make -f makefile.shared
 
 $(LIBNAME): $(OBJECTS)
-	libtool --mode=link gcc $(CFLAGS) *.lo -o libtomcrypt.la -rpath $(LIBPATH) -version-info $(VERSION)
-	libtool --mode=link gcc $(CFLAGS) *.o  -o libtomcrypt.a
-	libtool --mode=install install -c libtomcrypt.la $(LIBPATH)/libtomcrypt.la
-	install -d -g root -o root $(DESTDIR)$(INCPATH)
-	install -g root -o root $(HEADERS) $(DESTDIR)$(INCPATH)
+	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
-	libtool --mode=link gcc -o hashsum hashsum.o -ltomcrypt $(MPISHARED)
+	gcc -o hashsum hashsum.o -ltomcrypt_prof -ltomcrypt $(MPISHARED)
 
 #makes the crypt program
 crypt: library 
 	gcc $(CFLAGS) demos/encrypt.c -o encrypt.o
-	libtool --mode=link gcc -o crypt encrypt.o -ltomcrypt $(MPISHARED)
-
-x86_prof: library
-	gcc $(CFLAGS) demos/x86_prof.c -o x86_prof.o
-	libtool --mode=link gcc -o x86_prof x86_prof.o -ltomcrypt $(MPISHARED) $(EXTRALIBS)
+	gcc -o crypt encrypt.o -ltomcrypt_prof -ltomcrypt $(MPISHARED)
 
 tv_gen: library $(TVS)
-	gcc $(CFLAGS) demos/tv_gen.c -o tv_gen.o
-	libtool --mode=link gcc -o tv_gen tv_gen.o -ltomcrypt $(MPISHARED)
+	gcc -o tv_gen $(TVS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+
+test: library $(TESTS)
+	gcc -o $(TEST) $(TESTS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+
+timing: library $(TIMINGS)
+	gcc -o $(TIMING) $(TIMINGS) -ltomcrypt_prof -ltomcrypt $(MPISHARED)
+
diff --git a/mycrypt_argchk.h b/mycrypt_argchk.h
deleted file mode 100644
index 69f27d6..0000000
--- a/mycrypt_argchk.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Defines the _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 _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
-
diff --git a/mycrypt_cipher.h b/mycrypt_cipher.h
deleted file mode 100644
index 65749db..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
- 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 *key);
- void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int blowfish_test(void);
- int blowfish_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void rc5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int rc5_test(void);
- int rc5_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int rc6_test(void);
- int rc6_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int rc2_test(void);
- int rc2_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void saferp_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int saferp_test(void);
- int saferp_keysize(int *desired_keysize);
- extern const struct _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);
-
- int safer_64_keysize(int *desired_keysize);
- 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
-
- 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 *key);
- void rijndael_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int rijndael_test(void);
- int rijndael_keysize(int *desired_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 *key);
- 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
- 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 *key);
- void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int xtea_test(void);
- int xtea_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int twofish_test(void);
- int twofish_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int des_test(void);
- int des_keysize(int *desired_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 *key);
- void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int des3_test(void);
- int des3_keysize(int *desired_keysize);
-
- extern const struct _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 *key);
- void cast5_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int cast5_test(void);
- int cast5_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int noekeon_test(void);
- int noekeon_keysize(int *desired_keysize);
- extern const struct _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 *key);
- void skipjack_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key);
- int skipjack_test(void);
- int skipjack_keysize(int *desired_keysize);
- extern const struct _cipher_descriptor skipjack_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, symmetric_ECB *ecb);
- int ecb_decrypt(const unsigned char *ct, unsigned char *pt, 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);
-#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);
-#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, symmetric_CBC *cbc);
- int cbc_decrypt(const unsigned char *ct, unsigned char *pt, 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);
-#endif
-
-#ifdef CTR
- int ctr_start(int cipher, const unsigned char *IV, const unsigned char *key, 
-                     int keylen, int num_rounds, 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);
-#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 _cipher_descriptor *cipher);
- int unregister_cipher(const struct _cipher_descriptor *cipher);
-
- int cipher_is_valid(int idx);
-
diff --git a/mycrypt_hash.h b/mycrypt_hash.h
deleted file mode 100644
index d5d8900..0000000
--- a/mycrypt_hash.h
+++ /dev/null
@@ -1,472 +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
-
-#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
-} 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 */
-    int (*init)(hash_state *);
-    int (*process)(hash_state *, const unsigned char *, unsigned long);
-    int (*done)(hash_state *, unsigned char *);
-    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 *buf, unsigned long len);
- int chc_done(hash_state * md, unsigned char *hash);
- int chc_test(void);
- extern const struct _hash_descriptor chc_desc;
-#endif
-
-#ifdef WHIRLPOOL
- int whirlpool_init(hash_state * md);
- int whirlpool_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int whirlpool_done(hash_state * md, unsigned char *hash);
- int whirlpool_test(void);
- extern const struct _hash_descriptor whirlpool_desc;
-#endif
-
-#ifdef SHA512
- int sha512_init(hash_state * md);
- int sha512_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int sha512_done(hash_state * md, unsigned char *hash);
- int sha512_test(void);
- extern const struct _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 _hash_descriptor sha384_desc;
-#endif
-
-#ifdef SHA256
- int sha256_init(hash_state * md);
- int sha256_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int sha256_done(hash_state * md, unsigned char *hash);
- int sha256_test(void);
- extern const struct _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 _hash_descriptor sha224_desc;
-#endif
-#endif
-
-#ifdef SHA1
- int sha1_init(hash_state * md);
- int sha1_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int sha1_done(hash_state * md, unsigned char *hash);
- int sha1_test(void);
- extern const struct _hash_descriptor sha1_desc;
-#endif
-
-#ifdef MD5
- int md5_init(hash_state * md);
- int md5_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int md5_done(hash_state * md, unsigned char *hash);
- int md5_test(void);
- extern const struct _hash_descriptor md5_desc;
-#endif
-
-#ifdef MD4
- int md4_init(hash_state * md);
- int md4_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int md4_done(hash_state * md, unsigned char *hash);
- int md4_test(void);
- extern const struct _hash_descriptor md4_desc;
-#endif
-
-#ifdef MD2
- int md2_init(hash_state * md);
- int md2_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int md2_done(hash_state * md, unsigned char *hash);
- int md2_test(void);
- extern const struct _hash_descriptor md2_desc;
-#endif
-
-#ifdef TIGER
- int tiger_init(hash_state * md);
- int tiger_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int tiger_done(hash_state * md, unsigned char *hash);
- int tiger_test(void);
- extern const struct _hash_descriptor tiger_desc;
-#endif
-
-#ifdef RIPEMD128
- int rmd128_init(hash_state * md);
- int rmd128_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int rmd128_done(hash_state * md, unsigned char *hash);
- int rmd128_test(void);
- extern const struct _hash_descriptor rmd128_desc;
-#endif
-
-#ifdef RIPEMD160
- int rmd160_init(hash_state * md);
- int rmd160_process(hash_state * md, const unsigned char *buf, unsigned long len);
- int rmd160_done(hash_state * md, unsigned char *hash);
- int rmd160_test(void);
- extern const struct _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 _hash_descriptor *hash);
- int unregister_hash(const struct _hash_descriptor *hash);
- int hash_is_valid(int idx);
-
- int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen);
- int hash_filehandle(int hash, FILE *in, unsigned char *dst, unsigned long *outlen);
- 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;                                                                        \
-    int           err;                                                                      \
-    _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) {                             \
-           if ((err = compress_name (md, (unsigned char *)buf)) != CRYPT_OK) { \
-              return err;         \
-           }                                        \
-           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) {                                      \
-              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;                                                                        \
-}
-
-#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 *buf, unsigned long len);
- int hmac_done(hmac_state *hmac, unsigned char *hashOut, unsigned long *outlen);
- int hmac_test(void);
- 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_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 *state, const unsigned char *buf, unsigned long len);
- int omac_done(omac_state *state, unsigned char *out, unsigned long *outlen);
- 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 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 *state, const unsigned char *buf, unsigned long len);
- int pmac_done(pmac_state *state, 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_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           *res);
-
- 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 *res);
-
- 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           *res);
-
- int ocb_test(void);
-
-/* internal functions */
- void ocb_shift_xor(ocb_state *ocb, unsigned char *Z);
- int ocb_ntz(unsigned long x);
- 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_misc.h b/mycrypt_misc.h
deleted file mode 100644
index b9f9dbd..0000000
--- a/mycrypt_misc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* ---- 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;
diff --git a/mycrypt_pk.h b/mycrypt_pk.h
deleted file mode 100644
index 6345116..0000000
--- a/mycrypt_pk.h
+++ /dev/null
@@ -1,285 +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;                                              \
-     }                                                           \
-}
-
- 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
-
-/* 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, 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,
-                      prng_state    *prng, int           prng_idx,
-                      rsa_key *key);
-
-#ifdef RSA_TIMING
-
- 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
-
- void rsa_free(rsa_key *key);
-
-/* These use PKCS #1 v2.0 padding */
-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);
-
-/* these use PKCS #1 v1.5 padding */
-int rsa_v15_encrypt_key(const unsigned char *inkey,    unsigned long  inlen,
-                              unsigned char *outkey,   unsigned long *outlen,
-                              prng_state    *prng,     int            prng_idx, 
-                              rsa_key       *key);
-			      
-int rsa_v15_decrypt_key(const unsigned char *in,     unsigned long  inlen,
-                              unsigned char *outkey, unsigned long keylen, 
-                              prng_state    *prng,   int            prng_idx,
-                              int           *res,    rsa_key       *key);
-
-int rsa_v15_sign_hash(const unsigned char *msghash,  unsigned long  msghashlen, 
-                            unsigned char *sig,      unsigned long *siglen, 
-                            prng_state    *prng,     int            prng_idx,
-                            int            hash_idx, rsa_key       *key);
-
-int rsa_v15_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, 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 *inkey, unsigned long keylen,
-                                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, 
-                                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;
-} 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 *inkey, unsigned long keylen,
-                                 unsigned char *out,  unsigned long *len, 
-                                 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, 
-                                 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(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(const unsigned char *sig, unsigned long siglen,
-                           const unsigned char *hash, unsigned long inlen, 
-                           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
-
-/* DER handling */
-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);
-int der_put_multi_integer(unsigned char *dst, unsigned long *outlen, mp_int *num, ...);
-int der_get_multi_integer(const unsigned char *src, unsigned long *inlen,  mp_int *num, ...);
-
diff --git a/mycrypt_prng.h b/mycrypt_prng.h
deleted file mode 100644
index e706849..0000000
--- a/mycrypt_prng.h
+++ /dev/null
@@ -1,141 +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];
-};
-
-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 */
-};
-
-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? */
-    
-};
-
-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 _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, prng_state *);
-    int (*done)(prng_state *);
-    int (*pexport)(unsigned char *, unsigned long *, prng_state *);
-    int (*pimport)(const unsigned char *, unsigned long, prng_state *);
-    int (*test)(void);
-} prng_descriptor[];
-
-#ifdef YARROW
- int yarrow_start(prng_state *prng);
- int yarrow_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
- int yarrow_ready(prng_state *prng);
- unsigned long yarrow_read(unsigned char *buf, unsigned long len, 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 _prng_descriptor yarrow_desc;
-#endif
-
-#ifdef FORTUNA
- int fortuna_start(prng_state *prng);
- int fortuna_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
- int fortuna_ready(prng_state *prng);
- unsigned long fortuna_read(unsigned char *buf, unsigned long len, 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 _prng_descriptor fortuna_desc;
-#endif
-
-#ifdef RC4
- int rc4_start(prng_state *prng);
- int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
- int rc4_ready(prng_state *prng);
- unsigned long rc4_read(unsigned char *buf, unsigned long len, 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 _prng_descriptor rc4_desc;
-#endif
-
-#ifdef SPRNG
- int sprng_start(prng_state *prng);
- int sprng_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
- int sprng_ready(prng_state *prng);
- unsigned long sprng_read(unsigned char *buf, unsigned long len, 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 _prng_descriptor sprng_desc;
-#endif
-
-#ifdef SOBER128
- int sober128_start(prng_state *prng);
- int sober128_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
- int sober128_ready(prng_state *prng);
- unsigned long sober128_read(unsigned char *buf, unsigned long len, 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 _prng_descriptor sober128_desc;
-#endif
-
- int find_prng(const char *name);
- int register_prng(const struct _prng_descriptor *prng);
- int unregister_prng(const struct _prng_descriptor *prng);
- 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
- */
-unsigned long rng_get_bytes(unsigned char *buf, 
-                                   unsigned long len, 
-                                   void (*callback)(void));
-
-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..664661a
--- /dev/null
+++ b/notes/etc/saferp_optimizer.c
@@ -0,0 +1,173 @@
+/* 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;
+}
+
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/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/ocb_decrypt_verify_memory.c b/ocb_decrypt_verify_memory.c
deleted file mode 100644
index 2e15b55..0000000
--- a/ocb_decrypt_verify_memory.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
- */
-
-/* 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);
-
-   /* 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 __ERR; 
-   }
-
-   while (ctlen > (unsigned long)ocb->block_len) {
-        if ((err = ocb_decrypt(ocb, ct, pt)) != CRYPT_OK) {
-            goto __ERR; 
-        }
-        ctlen   -= ocb->block_len;
-        pt      += ocb->block_len;
-        ct      += ocb->block_len;
-   }
-
-   err = ocb_done_decrypt(ocb, ct, ctlen, pt, tag, taglen, res);
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(ocb, sizeof(ocb_state));
-#endif
- 
-   XFREE(ocb);
-
-   return err;
-}
-
-#endif
diff --git a/ocb_done_decrypt.c b/ocb_done_decrypt.c
deleted file mode 100644
index 697beea..0000000
--- a/ocb_done_decrypt.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
- */
-
-/* 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;
-   unsigned long tagbuflen;
-
-   _ARGCHK(ocb != NULL);
-   _ARGCHK(pt  != NULL);
-   _ARGCHK(ct  != NULL);
-   _ARGCHK(tag != NULL);
-   _ARGCHK(res != NULL);
-
-   /* default to failed */
-   *res = 0;
-
-   /* allocate memory */
-   tagbuf = XMALLOC(MAXBLOCKSIZE);
-   if (tagbuf == NULL) {
-      return CRYPT_MEM;
-   }
-
-   tagbuflen = MAXBLOCKSIZE;
-   if ((err = __ocb_done(ocb, ct, ctlen, pt, tagbuf, &tagbuflen, 1)) != CRYPT_OK) {
-      goto __ERR;
-   }
-
-   if (taglen <= tagbuflen && memcmp(tagbuf, tag, taglen) == 0) {
-      *res = 1;
-   }
-
-   err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(tagbuf, MAXBLOCKSIZE);
-#endif
-
-   XFREE(tagbuf);
-
-   return err;
-}
-
-#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 73afd3f..0000000
--- a/ocb_encrypt_authenticate_memory.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
- */
-
-/* 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);
-
-   /* 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 __ERR;
-   }
-
-   while (ptlen > (unsigned long)ocb->block_len) {
-        if ((err = ocb_encrypt(ocb, pt, ct)) != CRYPT_OK) {
-           goto __ERR;
-        }
-        ptlen   -= ocb->block_len;
-        pt      += ocb->block_len;
-        ct      += ocb->block_len;
-   }
-
-   err = ocb_done_encrypt(ocb, pt, ptlen, ct, tag, taglen);
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(ocb, sizeof(ocb_state));
-#endif
-
-   XFREE(ocb);
-
-   return err;
-}
-
-#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/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 fee5768..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;
-   }
-   XMEMCPY(IV, ofb->IV, ofb->blocklen);
-   *len = ofb->blocklen;
-
-   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 958ee3e..0000000
--- a/omac_done.c
+++ /dev/null
@@ -1,68 +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;
-   unsigned  x;
-
-   _ARGCHK(state  != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != 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 < (unsigned)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 < (unsigned)state->blklen && 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 ca194c9..0000000
--- a/omac_memory.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
- */
-/* 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);
-
-   /* 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 __ERR;
-   }
-   if ((err = omac_process(omac, msg, msglen)) != CRYPT_OK) {
-      goto __ERR;
-   }
-   if ((err = omac_done(omac, out, outlen)) != CRYPT_OK) {
-      goto __ERR;
-   }
-
-   err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(omac, sizeof(omac_state));
-#endif
-
-   XFREE(omac);
-   return err;   
-}
-
-#endif
diff --git a/omac_process.c b/omac_process.c
deleted file mode 100644
index 0817359..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));
-       XMEMCPY(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..d6466c5
--- /dev/null
+++ b/parsenames.pl
@@ -0,0 +1,22 @@
+#!/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";
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/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 af2b197..0000000
--- a/pmac_memory.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
- */
-
-/* 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);
-
-   /* 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 __ERR;
-   }
-   if ((err = pmac_process(pmac, msg, msglen)) != CRYPT_OK) {
-      goto __ERR;
-   }
-   if ((err = pmac_done(pmac, out, outlen)) != CRYPT_OK) {
-      goto __ERR;
-   }
-
-   err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
-   zeromem(pmac, sizeof(pmac_state));
-#endif
-
-   XFREE(pmac);
-   return err;   
-}
-
-#endif
diff --git a/pmac_process.c b/pmac_process.c
deleted file mode 100644
index 84b8e58..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));
-       XMEMCPY(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/pretty.build b/pretty.build
deleted file mode 100644
index 3eac213..0000000
--- a/pretty.build
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/perl -w
-#
-# Cute little builder for perl 
-# Total waste of development time...
-#
-# This will build all the object files and then the archive .a file
-# requires GCC, GNU make and a sense of humour.
-#
-# Tom St Denis
-use strict;
-
-my $count = 0;
-my $starttime = time;
-my $rate  = 0;
-print "Scanning for source files...\n";
-foreach my $filename (glob "*.c") {
-    if (!($filename =~ "aes_tab.c")) {
-    if (!($filename =~ "twofish_tab.c")) {
-    if (!($filename =~ "whirltab.c")) {
-    if (!($filename =~ "sha224.c")) {
-    if (!($filename =~ "sha384.c")) {
-    if (!($filename =~ "dh_sys.c")) {
-    if (!($filename =~ "ecc_sys.c")) {
-    if (!($filename =~ "sober128tab.c")) {
-       ++$count;
-    }}}}}}}}
-}
-print "Source files to build: $count\nBuilding...\n";
-my $i = 0;
-my $lines = 0;
-my $filesbuilt = 0;
-foreach my $filename (glob "*.c") {
-    if (!($filename =~ "aes_tab.c")) {
-    if (!($filename =~ "twofish_tab.c")) {
-    if (!($filename =~ "whirltab.c")) {
-    if (!($filename =~ "sha224.c")) {
-    if (!($filename =~ "sha384.c")) {
-    if (!($filename =~ "dh_sys.c")) {
-    if (!($filename =~ "ecc_sys.c")) {
-    if (!($filename =~ "sober128tab.c")) {
-       printf("Building %3.2f%%, ", (++$i/$count)*100.0);
-       if ($i % 4 == 0) { print "/, "; }
-       if ($i % 4 == 1) { print "-, "; }
-       if ($i % 4 == 2) { print "\\, "; }
-       if ($i % 4 == 3) { print "|, "; }
-       if ($rate > 0) {
-           my $tleft = ($count - $i) / $rate;
-           my $tsec  = $tleft%60;
-           my $tmin  = ($tleft/60)%60;
-           my $thour = ($tleft/3600)%60;
-           printf("%2d:%02d:%02d left, ", $thour, $tmin, $tsec);
-       }
-       my $cnt = ($i/$count)*30.0;
-       my $x   = 0;
-       print "[";
-       for (; $x < $cnt; $x++) { print "#"; }
-       for (; $x < 30; $x++)   { print " "; }
-       print "]\r";
-       my $tmp = $filename;
-       $tmp =~ s/\.c/".o"/ge;
-       if (open(SRC, "<$tmp")) {
-          close SRC;
-       } else {
-          !system("make $tmp > /dev/null 2>/dev/null") or die "\nERROR: Failed to make $tmp!!!\n";
-          open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!";
-          ++$lines while (<SRC>);
-          close SRC or die "Error closing $filename after reading: $!";
-          ++$filesbuilt;
-       }      
-
-       # update timer 
-       if (time != $starttime) {
-          my $delay = time - $starttime;
-          $rate = $i/$delay;
-       }
-    }}}}}}}}
-}
-
-# finish building the library 
-printf("\nFinished building source (%d seconds, %3.2f files per second).\n", time - $starttime, $rate);
-print "Compiled approximately $filesbuilt files and $lines lines of code.\n";
-print "Doing final make (building archive...)\n";
-!system("make > /dev/null 2>/dev/null") or die "\nERROR: Failed to perform last make command!!!\n";
-print "done.\n";
\ No newline at end of file
diff --git a/rsa_decrypt_key.c b/rsa_decrypt_key.c
deleted file mode 100644
index 47a922c..0000000
--- a/rsa_decrypt_key.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"
-
-#ifdef MRSA
-
-/* (PKCS #1 v2.0) 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;
-  unsigned char *tmp;
-  
-  _ARGCHK(outkey != NULL);
-  _ARGCHK(keylen != NULL);
-  _ARGCHK(key    != NULL);
-  _ARGCHK(res    != NULL);
-
-  /* default to invalid */
-  *res = 0;
-
-  /* valid hash/prng ? */
-  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 != 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, prng, prng_idx, 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,
-                           outkey, keylen, res);
-  XFREE(tmp);
-  return err;
-}
-
-#endif /* MRSA */
-
-
-
-
diff --git a/rsa_encrypt_key.c b/rsa_encrypt_key.c
deleted file mode 100644
index c0c8400..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
-
-/* (PKCS #1 v2.0) 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 bee5cf6..0000000
--- a/rsa_export.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
- */
-
-#include "mycrypt.h"
-
-#ifdef MRSA
-
-/* This will export either an RSAPublicKey or RSAPrivateKey [defined in PKCS #1 v2.1] */
-int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key)
-{
-   int err;
-
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(key    != NULL);
-
-   /* type valid? */
-   if (!(key->type == PK_PRIVATE) && (type == PK_PRIVATE)) {
-      return CRYPT_PK_INVALID_TYPE;
-   }
-  
-   if (type == PK_PRIVATE) {
-      /* private key */
-      mp_int zero;
-
-      /* first INTEGER == 0 to signify two-prime RSA */
-      if ((err = mp_init(&zero)) != MP_OKAY) {
-         return mpi_to_ltc_error(err);
-      }
- 
-      /* output is 
-            Version, n, e, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p
-       */
-      err = der_put_multi_integer(out, outlen, &zero, &key->N, &key->e,
-                          &key->d, &key->p, &key->q, &key->dP,
-                          &key->dQ, &key->qP, NULL);
- 
-      /* clear zero and return */
-      mp_clear(&zero);
-      return err;
-   } else {
-      /* public key */
-      return der_put_multi_integer(out, outlen, &key->N, &key->e, NULL);
-   }
-}
-
-#endif /* MRSA */
-
diff --git a/rsa_import.c b/rsa_import.c
deleted file mode 100644
index 02b4ca8..0000000
--- a/rsa_import.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
-
-/* import an RSAPublicKey or RSAPrivateKey [two-prime only, defined in PKCS #1 v2.1] */
-int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key)
-{
-   unsigned long x;
-   int err;
-
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
-
-   /* init key */
-   if ((err = mp_init_multi(&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);
-   }
-
-   /* read first number, it's either N or 0 [0 == private key] */
-   x = inlen;
-   if ((err = der_get_multi_integer(in, &x, &key->N, NULL)) != CRYPT_OK) {
-      goto __ERR;
-   }
-
-   /* advance */
-   inlen -= x;
-   in    += x;
-
-   if (mp_cmp_d(&key->N, 0) == MP_EQ) {
-      /* it's a private key */
-      if ((err = der_get_multi_integer(in, &inlen, &key->N, &key->e,
-                          &key->d, &key->p, &key->q, &key->dP,
-                          &key->dQ, &key->qP, NULL)) != CRYPT_OK) {
-         goto __ERR;
-      }
-
-      key->type = PK_PRIVATE;
-   } else {
-      /* it's a public key and we lack e */
-      if ((err = der_get_multi_integer(in, &inlen, &key->e, NULL)) != CRYPT_OK) {
-         goto __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;
-__ERR:
-   mp_clear_multi(&key->d, &key->e, &key->N, &key->dQ, &key->dP,
-                  &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 a5d2f95..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
-
-/* (PKCS #1, v2.0) 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_v15_decrypt_key.c b/rsa_v15_decrypt_key.c
deleted file mode 100644
index e8c496b..0000000
--- a/rsa_v15_decrypt_key.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"
-
-#ifdef MRSA
-
-/* decrypt then PKCS #1 v1.5 depad  */
-int rsa_v15_decrypt_key(const unsigned char *in,     unsigned long  inlen,
-                              unsigned char *outkey, unsigned long keylen, 
-                              prng_state    *prng,   int            prng_idx,
-                              int           *res,    rsa_key       *key)
-{
-  unsigned long modulus_bitlen, modulus_bytelen, x;
-  int           err;
-  unsigned char *tmp;
-  
-  _ARGCHK(outkey != NULL);
-  _ARGCHK(key    != NULL);
-  _ARGCHK(res    != NULL);
- 
-  /* default to invalid */
-  *res = 0;
-
-  /* valid prng ? */
-  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 != 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, prng, prng_idx, key)) != CRYPT_OK) {
-     XFREE(tmp);
-     return err;
-  }
-
-  /* PKCS #1 v1.5 depad */
-  err = pkcs_1_v15_es_decode(tmp, x, modulus_bitlen, outkey, keylen, res);
-  XFREE(tmp);
-  return err;
-}
-
-#endif
diff --git a/rsa_v15_encrypt_key.c b/rsa_v15_encrypt_key.c
deleted file mode 100644
index 3724a72..0000000
--- a/rsa_v15_encrypt_key.c
+++ /dev/null
@@ -1,54 +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
-
-/* PKCS #1 v1.5 pad then encrypt */
-int rsa_v15_encrypt_key(const unsigned char *inkey,    unsigned long  inlen,
-                              unsigned char *outkey,   unsigned long *outlen,
-                              prng_state    *prng,     int            prng_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? */
-  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 > *outlen) {
-     return CRYPT_BUFFER_OVERFLOW;
-  }
-  
-  /* pad it */
-  x = *outlen;
-  if ((err = pkcs_1_v15_es_encode(inkey, inlen, modulus_bitlen, prng, prng_idx, outkey, &x)) != CRYPT_OK) {
-     return err;
-  }
-  
-  /* encrypt it */
-  return rsa_exptmod(outkey, x, outkey, outlen, PK_PUBLIC, prng, prng_idx, key);
-}
-
-#endif
diff --git a/rsa_v15_sign_hash.c b/rsa_v15_sign_hash.c
deleted file mode 100644
index 0a3da2a..0000000
--- a/rsa_v15_sign_hash.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 MRSA
-
-/* PKCS #1 v1.5 pad then sign */
-int rsa_v15_sign_hash(const unsigned char *msghash,  unsigned long  msghashlen, 
-                            unsigned char *sig,      unsigned long *siglen, 
-                            prng_state    *prng,     int            prng_idx,
-                            int            hash_idx, 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;
-  }
-      
-  /* PKCS #1 v1.5 pad the key */
-  x = *siglen;
-  if ((err = pkcs_1_v15_sa_encode(msghash, msghashlen, 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
diff --git a/rsa_v15_verify_hash.c b/rsa_v15_verify_hash.c
deleted file mode 100644
index 6f6ee99..0000000
--- a/rsa_v15_verify_hash.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
-
-/* de-sign then PKCS v1.5 depad */
-int rsa_v15_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, 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);
-
-  /* default to invalid */
-  *stat = 0;
-  
-  /* 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 = XMALLOC(siglen);
-  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_v15_sa_decode(msghash, msghashlen, tmpbuf, x, hash_idx, modulus_bitlen, stat);
-  XFREE(tmpbuf);
-  return err;
-}
-
-#endif
diff --git a/rsa_verify_hash.c b/rsa_verify_hash.c
deleted file mode 100644
index 1da1af3..0000000
--- a/rsa_verify_hash.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
-
-/* (PKCS #1, v2.0) de-sign 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);
-
-  /* default to invalid */
-  *stat = 0;
-  
-  /* 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 = XMALLOC(siglen);
-  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/sprng.c b/sprng.c
deleted file mode 100644
index 090bd01..0000000
--- a/sprng.c
+++ /dev/null
@@ -1,80 +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", 0,
-    &sprng_start,
-    &sprng_add_entropy,
-    &sprng_ready,
-    &sprng_read,
-    &sprng_done,
-    &sprng_export,
-    &sprng_import,
-    &sprng_test
-};
-
-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);
-}
-
-int sprng_done(prng_state *prng)
-{
-   return CRYPT_OK;
-}
-
-int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
-{
-   _ARGCHK(outlen != NULL);
-
-   *outlen = 0;
-   return CRYPT_OK;
-}
- 
-int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
-{
-   return CRYPT_OK;
-}
-
-int sprng_test(void)
-{
-   return CRYPT_OK;
-}
-
-#endif
-
-
- 
diff --git a/aes.c b/src/ciphers/aes/aes.c
similarity index 85%
rename from aes.c
rename to src/ciphers/aes/aes.c
index 949c22b..e698efd 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,26 @@
 #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 =
+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
 };
 
-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 +66,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 +99,7 @@
 }
 
 #ifndef ENCRYPT_ONLY
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
 static ulong32 setup_mix2(ulong32 temp)
 {
    return Td0(255 & Te4[byte(temp, 3)]) ^
@@ -100,21 +110,29 @@
 #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 +199,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 +207,7 @@
         }
     } else {
        /* this can't happen */
-       j = 4;
+       return CRYPT_ERROR;
     }
 
 #ifndef ENCRYPT_ONLY    
@@ -208,7 +226,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 +276,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 +291,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 +308,7 @@
     LOAD32H(s3, pt  + 12); s3 ^= rk[3];
 
 
-#ifdef SMALL_CODE
+#ifdef LTC_SMALL_CODE
 
     for (r = 0; ; r++) {
         rk += 4;
@@ -418,7 +442,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 +452,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 +467,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 +483,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 +618,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 +626,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,20 +713,34 @@
 
 #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;
    }
 }
diff --git a/aes_tab.c b/src/ciphers/aes/aes_tab.c
similarity index 99%
rename from aes_tab.c
rename to src/ciphers/aes/aes_tab.c
index cb450a7..0ad1dfe 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
diff --git a/src/ciphers/anubis.c b/src/ciphers/anubis.c
new file mode 100644
index 0000000..7e2af60
--- /dev/null
+++ b/src/ciphers/anubis.c
@@ -0,0 +1,1550 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis

+ *

+ * LibTomCrypt is a library that provides various cryptographic

+ * algorithms 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

+

diff --git a/blowfish.c b/src/ciphers/blowfish.c
similarity index 87%
rename from blowfish.c
rename to src/ciphers/blowfish.c
index 229ba88..2f0385d 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,14 +555,26 @@
  #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;
 }
diff --git a/cast5.c b/src/ciphers/cast5.c
similarity index 90%
rename from cast5.c
rename to src/ciphers/cast5.c
index dcb78ab..2b8e4a5 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; 
@@ -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,13 +685,25 @@
  #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;
 } 
diff --git a/des.c b/src/ciphers/des.c
similarity index 96%
rename from des.c
rename to src/ciphers/des.c
index e609014..d42c5fa 100644
--- a/des.c
+++ b/src/ciphers/des.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
  */
-/* 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 =
+const struct ltc_cipher_descriptor des_desc =
 {
     "des",
     13,
@@ -25,10 +29,12 @@
     &des_ecb_encrypt,
     &des_ecb_decrypt,
     &des_test,
-    &des_keysize
+    &des_done,
+    &des_keysize,
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
-const struct _cipher_descriptor des3_desc =
+const struct ltc_cipher_descriptor des3_desc =
 {
     "3des",
     14,
@@ -37,7 +43,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 +247,7 @@
     0x00001040UL, 0x00040040UL, 0x10000000UL, 0x10041000UL
 };
 
-#ifndef SMALL_CODE
+#ifndef LTC_SMALL_CODE
 
 static const ulong64 des_ip[8][256] = {
 
@@ -1292,10 +1300,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 +1352,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)
@@ -1380,7 +1388,7 @@
     XMEMCPY(keyout, dough, sizeof dough);
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void cookey(const ulong32 *raw1, ulong32 *keyout)
 {
    _cookey(raw1, keyout);
@@ -1388,7 +1396,7 @@
 }
 #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)
@@ -1400,7 +1408,7 @@
     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 +1425,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;
@@ -1440,7 +1448,7 @@
 #endif
 
     for (cur_round = 0; cur_round < 8; cur_round++) {
-        work  = ROR(right, 4) ^ *keys++;
+        work  = RORc(right, 4) ^ *keys++;
         leftt ^= SP7[work        & 0x3fL]
               ^ SP5[(work >>  8) & 0x3fL]
               ^ SP3[(work >> 16) & 0x3fL]
@@ -1451,7 +1459,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 +1471,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 +1510,7 @@
     block[1] = leftt;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static void desfunc(ulong32 *block, const ulong32 *keys)
 {
    _desfunc(block, keys);
@@ -1510,10 +1518,18 @@
 }
 #endif
 
+ /**
+    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;
@@ -1529,10 +1545,18 @@
     return CRYPT_OK;
 }
 
+ /**
+    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) {
         return CRYPT_INVALID_ROUNDS;
@@ -1553,63 +1577,91 @@
     return CRYPT_OK;
 }
 
-void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
+/**
+  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);
 }
 
-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);
 }
 
+/**
+  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 +1669,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 },
@@ -1789,23 +1841,48 @@
  #endif
 }
 
-int des_keysize(int *desired_keysize)
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void des_done(symmetric_key *skey)
 {
-    _ARGCHK(desired_keysize != NULL);
-    if(*desired_keysize < 8) {
+}
+
+/** Terminate the context 
+   @param skey    The scheduled key
+*/
+void des3_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 des_keysize(int *keysize)
+{
+    LTC_ARGCHK(keysize != NULL);
+    if(*keysize < 8) {
         return CRYPT_INVALID_KEYSIZE;
     }
-    *desired_keysize = 8;
+    *keysize = 8;
     return CRYPT_OK;
 }
 
-int des3_keysize(int *desired_keysize)
+/**
+  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)
 {
-    _ARGCHK(desired_keysize != NULL);
-    if(*desired_keysize < 24) {
+    LTC_ARGCHK(keysize != NULL);
+    if(*keysize < 24) {
         return CRYPT_INVALID_KEYSIZE;
     }
-    *desired_keysize = 24;
+    *keysize = 24;
     return CRYPT_OK;
 }
 
diff --git a/src/ciphers/khazad.c b/src/ciphers/khazad.c
new file mode 100644
index 0000000..4626923
--- /dev/null
+++ b/src/ciphers/khazad.c
@@ -0,0 +1,847 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/noekeon.c b/src/ciphers/noekeon.c
similarity index 66%
rename from noekeon.c
rename to src/ciphers/noekeon.c
index ef4796c..194cdbe 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[] = {
@@ -34,15 +39,15 @@
 };
 
 #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)     \
@@ -54,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;
@@ -89,25 +102,31 @@
    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;
    int r;
 
-   _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);
@@ -119,39 +138,45 @@
 #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;
    int r;
 
-   _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); \
@@ -163,20 +188,24 @@
 
 #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
@@ -236,13 +265,25 @@
  #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;
    }
 }
diff --git a/rc2.c b/src/ciphers/rc2.c
similarity index 69%
rename from rc2.c
rename to src/ciphers/rc2.c
index f3f8c31..6382941 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,19 +18,25 @@
 * 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
 };
 
 /* 256-entry permutation table, probably derived somehow from pi */
@@ -53,21 +59,29 @@
         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;
    }
 
@@ -96,7 +110,7 @@
         xkey[i] =  (unsigned)tmp[2*i] + ((unsigned)tmp[2*i+1] << 8);
     }        
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(tmp, sizeof(tmp));
 #endif
     
@@ -106,29 +120,35 @@
 /**********************************************************************\
 * 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;
@@ -151,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
@@ -174,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
 {
@@ -189,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) {
@@ -221,26 +246,30 @@
         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
@@ -292,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) {
diff --git a/rc5.c b/src/ciphers/rc5.c
similarity index 69%
rename from rc5.c
rename to src/ciphers/rc5.c
index 124deb9..32f666f 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) { 
@@ -87,7 +100,7 @@
     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;
 }
diff --git a/rc6.c b/src/ciphers/rc6.c
similarity index 73%
rename from rc6.c
rename to src/ciphers/rc6.c
index 62a2cf5..996c015 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) { 
@@ -77,7 +90,7 @@
     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;
 }
diff --git a/safer.c b/src/ciphers/safer/safer.c
similarity index 91%
rename from safer.c
rename to src/ciphers/safer/safer.c
index 580872a..e6e073a 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
diff --git a/safer_tab.c b/src/ciphers/safer/safer_tab.c
similarity index 95%
rename from safer_tab.c
rename to src/ciphers/safer/safer_tab.c
index 06859db..f63ba6c 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)
 
diff --git a/saferp.c b/src/ciphers/safer/saferp.c
similarity index 90%
rename from saferp.c
rename to src/ciphers/safer/saferp.c
index 8415deb..17112f4 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;
 }
diff --git a/skipjack.c b/src/ciphers/skipjack.c
similarity index 75%
rename from skipjack.c
rename to src/ciphers/skipjack.c
index a66efa1..e2431af 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,13 +305,25 @@
   #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;
 }
diff --git a/twofish.c b/src/ciphers/twofish/twofish.c
similarity index 80%
rename from twofish.c
rename to src/ciphers/twofish/twofish.c
index b618b98..7dbe9b7 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 */
@@ -86,7 +91,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 +130,7 @@
    return (ulong32)y;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static ulong32 sbox(int i, ulong32 x)
 {
    ulong32 y;
@@ -133,7 +138,7 @@
    burn_stack(sizeof(unsigned char) * 11);
    return y;
 }
-#endif /* CLEAN_STACK */
+#endif /* LTC_CLEAN_STACK */
 
 #endif /* TWOFISH_TABLES */
 
@@ -270,10 +275,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 +287,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 +318,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 +328,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 +353,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 +399,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 +450,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 +460,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 +478,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 +547,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 +563,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);
+        t2 = g1_func(b, skey);
         t1 = g_func(a, key) + t2;
-        c = ROL(c, 1) ^ (t1 + k[0]);
-        d = ROR(d ^ (t2 +  t1 + k[1]), 1);
+        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 +667,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;
    }
 }
diff --git a/twofish_tab.c b/src/ciphers/twofish/twofish_tab.c
similarity index 99%
rename from twofish_tab.c
rename to src/ciphers/twofish/twofish_tab.c
index 5a2bb5b..0bffade 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 */
diff --git a/src/ciphers/xtea.c b/src/ciphers/xtea.c
new file mode 100644
index 0000000..98546df
--- /dev/null
+++ b/src/ciphers/xtea.c
@@ -0,0 +1,203 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+
+
+
diff --git a/src/encauth/ccm/ccm_memory.c b/src/encauth/ccm/ccm_memory.c
new file mode 100644
index 0000000..34a254d
--- /dev/null
+++ b/src/encauth/ccm/ccm_memory.c
@@ -0,0 +1,306 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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(B,      sizeof(B));
+   zeromem(PAD,    sizeof(PAD));
+   zeromem(CTRPAD, sizeof(CTRPAD));
+#endif
+
+   XFREE(skey);
+
+   return CRYPT_OK;
+}
+
+#endif
diff --git a/src/encauth/ccm/ccm_test.c b/src/encauth/ccm/ccm_test.c
new file mode 100644
index 0000000..ee78523
--- /dev/null
+++ b/src/encauth/ccm/ccm_test.c
@@ -0,0 +1,170 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/src/encauth/eax/eax_addheader.c b/src/encauth/eax/eax_addheader.c
new file mode 100644
index 0000000..3004025
--- /dev/null
+++ b/src/encauth/eax/eax_addheader.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
+ */
+/** 
+    @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
diff --git a/src/encauth/eax/eax_decrypt.c b/src/encauth/eax/eax_decrypt.c
new file mode 100644
index 0000000..8711d2d
--- /dev/null
+++ b/src/encauth/eax/eax_decrypt.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 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
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..3fcab46
--- /dev/null
+++ b/src/encauth/eax/eax_decrypt_verify_memory.c
@@ -0,0 +1,104 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/eax_done.c b/src/encauth/eax/eax_done.c
similarity index 65%
rename from eax_done.c
rename to src/encauth/eax/eax_done.c
index 037251e..1d43651 100644
--- a/eax_done.c
+++ b/src/encauth/eax/eax_done.c
@@ -6,23 +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
  */
 
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
+/**
+   @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;
 
-   _ARGCHK(eax    != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(taglen != NULL);
+   LTC_ARGCHK(eax    != NULL);
+   LTC_ARGCHK(tag    != NULL);
+   LTC_ARGCHK(taglen != NULL);
 
    /* allocate ram */
    headermac = XMALLOC(MAXBLOCKSIZE);
@@ -41,7 +51,7 @@
    /* finish ctomac */
    len = MAXBLOCKSIZE;
    if ((err = omac_done(&eax->ctomac, ctmac, &len)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
 
    /* finish headeromac */
@@ -49,7 +59,12 @@
    /* note we specifically don't reset len so the two lens are minimal */
 
    if ((err = omac_done(&eax->headeromac, headermac, &len)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
+   }
+
+   /* terminate the CTR chain */
+   if ((err = ctr_done(&eax->ctr)) != CRYPT_OK) {
+      goto LBL_ERR;
    }
 
    /* compute N xor H xor C */
@@ -59,8 +74,8 @@
    *taglen = x;
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(ctmac,     MAXBLOCKSIZE);
    zeromem(headermac, MAXBLOCKSIZE);
    zeromem(eax,       sizeof(*eax));
diff --git a/src/encauth/eax/eax_encrypt.c b/src/encauth/eax/eax_encrypt.c
new file mode 100644
index 0000000..da23a8c
--- /dev/null
+++ b/src/encauth/eax/eax_encrypt.c
@@ -0,0 +1,47 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+
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..8a601cf
--- /dev/null
+++ b/src/encauth/eax/eax_encrypt_authenticate_memory.c
@@ -0,0 +1,78 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/eax_init.c b/src/encauth/eax/eax_init.c
similarity index 65%
rename from eax_init.c
rename to src/encauth/eax/eax_init.c
index 547c8d6..5a20db0 100644
--- a/eax_init.c
+++ b/src/encauth/eax/eax_init.c
@@ -6,16 +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
  */
 
-/* EAX Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file eax_init.c
+   EAX implementation, initialized EAX state, by Tom St Denis 
+*/
+#include "tomcrypt.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,
+/** 
+   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;
@@ -24,11 +40,11 @@
    unsigned long len;
 
 
-   _ARGCHK(eax   != NULL);
-   _ARGCHK(key   != NULL);
-   _ARGCHK(nonce != NULL);
+   LTC_ARGCHK(eax   != NULL);
+   LTC_ARGCHK(key   != NULL);
+   LTC_ARGCHK(nonce != NULL);
    if (headerlen > 0) {
-      _ARGCHK(header != NULL);
+      LTC_ARGCHK(header != NULL);
    }
 
    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
@@ -38,7 +54,7 @@
 
    /* allocate ram */
    buf  = XMALLOC(MAXBLOCKSIZE);
-   omac = XMALLOC(sizeof(omac_state));
+   omac = XMALLOC(sizeof(*omac));
 
    if (buf == NULL || omac == NULL) {
       if (buf != NULL) {
@@ -53,21 +69,21 @@
    /* N = OMAC_0K(nonce) */
    zeromem(buf, MAXBLOCKSIZE);
    if ((err = omac_init(omac, cipher, key, keylen)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
 
    /* omac the [0]_n */
    if ((err = omac_process(omac, buf, blklen)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
    /* omac the nonce */
    if ((err = omac_process(omac, nonce, noncelen)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
    /* store result */
    len = sizeof(eax->N);
    if ((err = omac_done(omac, eax->N, &len)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
 
    /* H = OMAC_1K(header) */
@@ -75,17 +91,17 @@
    buf[blklen - 1] = 1;
 
    if ((err = omac_init(&eax->headeromac, cipher, key, keylen)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
 
    /* omac the [1]_n */
    if ((err = omac_process(&eax->headeromac, buf, blklen)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
    /* omac the header */
    if (headerlen != 0) {
       if ((err = omac_process(&eax->headeromac, header, headerlen)) != CRYPT_OK) {
-          goto __ERR; 
+          goto LBL_ERR; 
       }
    }
 
@@ -93,28 +109,28 @@
 
    /* setup the CTR mode */
    if ((err = ctr_start(cipher, eax->N, key, keylen, 0, &eax->ctr)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
    /* use big-endian counter */
    eax->ctr.mode = 1;
 
    /* setup the OMAC for the ciphertext */
    if ((err = omac_init(&eax->ctomac, cipher, key, keylen)) != CRYPT_OK) { 
-      goto __ERR; 
+      goto LBL_ERR; 
    }
 
    /* omac [2]_n */
    zeromem(buf, MAXBLOCKSIZE);
    buf[blklen-1] = 2;
    if ((err = omac_process(&eax->ctomac, buf, blklen)) != CRYPT_OK) {
-      goto __ERR; 
+      goto LBL_ERR; 
    }
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(buf,  MAXBLOCKSIZE);
-   zeromem(omac, sizeof(omac_state));
+   zeromem(omac, sizeof(*omac));
 #endif
 
    XFREE(omac);
diff --git a/eax_test.c b/src/encauth/eax/eax_test.c
similarity index 96%
rename from eax_test.c
rename to src/encauth/eax/eax_test.c
index 93774b0..777dea1 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
diff --git a/src/encauth/gcm/gcm_add_aad.c b/src/encauth/gcm/gcm_add_aad.c
new file mode 100644
index 0000000..cdcc0d9
--- /dev/null
+++ b/src/encauth/gcm/gcm_add_aad.c
@@ -0,0 +1,117 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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, y;
+   int           err;
+
+   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
+   
diff --git a/src/encauth/gcm/gcm_add_iv.c b/src/encauth/gcm/gcm_add_iv.c
new file mode 100644
index 0000000..7faf4c0
--- /dev/null
+++ b/src/encauth/gcm/gcm_add_iv.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
+ */
+
+/**
+   @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
+   
diff --git a/src/encauth/gcm/gcm_done.c b/src/encauth/gcm/gcm_done.c
new file mode 100644
index 0000000..8b3a6dd
--- /dev/null
+++ b/src/encauth/gcm/gcm_done.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
+ */
+
+/**
+   @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
+
diff --git a/src/encauth/gcm/gcm_gf_mult.c b/src/encauth/gcm/gcm_gf_mult.c
new file mode 100644
index 0000000..a870c91
--- /dev/null
+++ b/src/encauth/gcm/gcm_gf_mult.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
+ */
+
+/**
+   @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
diff --git a/src/encauth/gcm/gcm_init.c b/src/encauth/gcm/gcm_init.c
new file mode 100644
index 0000000..35a5ab8
--- /dev/null
+++ b/src/encauth/gcm/gcm_init.c
@@ -0,0 +1,88 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+
+/**
+  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;
+#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 */
+   zeromem(B, 16);
+   for (x = 0; x < 16; x++) {
+       for (y = 0; y < 256; y++) {
+            B[x] = y;
+            gcm_gf_mult(gcm->H, B, &gcm->PC[x][y][0]);
+       }
+       B[x] = 0;
+   }
+#endif
+
+   return CRYPT_OK;
+}
+
+#endif
diff --git a/src/encauth/gcm/gcm_memory.c b/src/encauth/gcm/gcm_memory.c
new file mode 100644
index 0000000..e062413
--- /dev/null
+++ b/src/encauth/gcm/gcm_memory.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
+ */
+
+/**
+   @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
+
diff --git a/src/encauth/gcm/gcm_process.c b/src/encauth/gcm/gcm_process.c
new file mode 100644
index 0000000..577967b
--- /dev/null
+++ b/src/encauth/gcm/gcm_process.c
@@ -0,0 +1,143 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+   
diff --git a/src/encauth/gcm/gcm_reset.c b/src/encauth/gcm/gcm_reset.c
new file mode 100644
index 0000000..e73bf66
--- /dev/null
+++ b/src/encauth/gcm/gcm_reset.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
+ */
+
+/**
+   @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
diff --git a/src/encauth/gcm/gcm_test.c b/src/encauth/gcm/gcm_test.c
new file mode 100644
index 0000000..bc6ad7e
--- /dev/null
+++ b/src/encauth/gcm/gcm_test.c
@@ -0,0 +1,365 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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;
+   gcm_state     gcm;
+   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
+
diff --git a/ocb_decrypt.c b/src/encauth/ocb/ocb_decrypt.c
similarity index 67%
rename from ocb_decrypt.c
rename to src/encauth/ocb/ocb_decrypt.c
index b7c785b..d3bf480 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
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..378a8af
--- /dev/null
+++ b/src/encauth/ocb/ocb_decrypt_verify_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 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
diff --git a/src/encauth/ocb/ocb_done_decrypt.c b/src/encauth/ocb/ocb_done_decrypt.c
new file mode 100644
index 0000000..9f8b1b9
--- /dev/null
+++ b/src/encauth/ocb/ocb_done_decrypt.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
+ */
+
+/** 
+   @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
+
diff --git a/src/encauth/ocb/ocb_done_encrypt.c b/src/encauth/ocb/ocb_done_encrypt.c
new file mode 100644
index 0000000..1a07569
--- /dev/null
+++ b/src/encauth/ocb/ocb_done_encrypt.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_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
+
diff --git a/ocb_encrypt.c b/src/encauth/ocb/ocb_encrypt.c
similarity index 68%
rename from ocb_encrypt.c
rename to src/encauth/ocb/ocb_encrypt.c
index d951933..ba39c60 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
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..bcc9cfb
--- /dev/null
+++ b/src/encauth/ocb/ocb_encrypt_authenticate_memory.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_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
diff --git a/ocb_init.c b/src/encauth/ocb/ocb_init.c
similarity index 83%
rename from ocb_init.c
rename to src/encauth/ocb/ocb_init.c
index 6087207..57e04af 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) {
diff --git a/src/encauth/ocb/ocb_ntz.c b/src/encauth/ocb/ocb_ntz.c
new file mode 100644
index 0000000..4ffe7e8
--- /dev/null
+++ b/src/encauth/ocb/ocb_ntz.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 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
diff --git a/ocb_shift_xor.c b/src/encauth/ocb/ocb_shift_xor.c
similarity index 63%
rename from ocb_shift_xor.c
rename to src/encauth/ocb/ocb_shift_xor.c
index ce93138..b63b022 100644
--- a/ocb_shift_xor.c
+++ b/src/encauth/ocb/ocb_shift_xor.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
  */
 
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @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;
diff --git a/ocb_test.c b/src/encauth/ocb/ocb_test.c
similarity index 96%
rename from ocb_test.c
rename to src/encauth/ocb/ocb_test.c
index 0b5dafd..d6cb14b 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
diff --git a/s_ocb_done.c b/src/encauth/ocb/s_ocb_done.c
similarity index 72%
rename from s_ocb_done.c
rename to src/encauth/ocb/s_ocb_done.c
index d4a7748..6f6e63d 100644
--- a/s_ocb_done.c
+++ b/src/encauth/ocb/s_ocb_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
  */
 
-/* OCB Implementation by Tom St Denis */
-#include "mycrypt.h"
+/** 
+   @file s_ocb_done.c
+   OCB implementation, internal helper, by Tom St Denis
+*/
+#include "tomcrypt.h"
 
 #ifdef OCB_MODE
 
@@ -21,18 +24,30 @@
  *
  * 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)
+
+/**
+   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;
 
-   _ARGCHK(ocb    != NULL);
-   _ARGCHK(pt     != NULL);
-   _ARGCHK(ct     != NULL);
-   _ARGCHK(tag    != NULL);
-   _ARGCHK(taglen != NULL);
+   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;
    }
@@ -99,6 +114,7 @@
    
    /* 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++) {
@@ -106,7 +122,7 @@
    }
    *taglen = x;
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(X, MAXBLOCKSIZE);
    zeromem(Y, MAXBLOCKSIZE);
    zeromem(Z, MAXBLOCKSIZE);
diff --git a/chc.c b/src/hashes/chc/chc.c
similarity index 79%
rename from chc.c
rename to src/hashes/chc/chc.c
index e144b68..67dd090 100644
--- a/chc.c
+++ b/src/hashes/chc/chc.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 chc.c
+  CHC support. (Tom St Denis)
+*/
 
 #ifdef CHC_HASH
 
@@ -20,7 +25,7 @@
                       cipher_blocksize;               /* blocksize of cipher */
 
 
-const struct _hash_descriptor chc_desc = {
+const struct ltc_hash_descriptor chc_desc = {
    "chc_hash", 12, 0, 0, { 0 }, 0,
    &chc_init,
    &chc_process,
@@ -28,7 +33,11 @@
    &chc_test
 };
 
-/* initialize the CHC state with a given cipher */
+/**
+  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;
@@ -69,14 +78,18 @@
    return CRYPT_OK;
 }
 
-/* "hash init" is simply encrypt 0 with the 0 key.  Simple way to make an IV */
+/**
+   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;
  
-   _ARGCHK(md != NULL);
+   LTC_ARGCHK(md != NULL);
 
    /* is the cipher valid? */
    if ((err = cipher_is_valid(cipher_idx)) != CRYPT_OK) {
@@ -134,21 +147,30 @@
        md->chc.state[x] ^= T[0][x] ^ T[1][x];
    }
    XFREE(key);
-#ifdef CLEAN_STACK
+#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)
 
-int chc_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 chc_process(hash_state * md, const unsigned char *in, unsigned long inlen)
 {
    int err;
 
-   _ARGCHK(md   != NULL);
-   _ARGCHK(buf  != NULL);
+   LTC_ARGCHK(md   != NULL);
+   LTC_ARGCHK(in  != NULL);
 
    /* is the cipher valid? */
    if ((err = cipher_is_valid(cipher_idx)) != CRYPT_OK) {
@@ -158,15 +180,21 @@
       return CRYPT_INVALID_CIPHER;
    }
 
-   return _chc_process(md, buf, len);
+   return _chc_process(md, in, inlen);
 }
 
-int chc_done(hash_state *md, unsigned char *buf)
+/**
+   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;
 
-    _ARGCHK(md   != NULL);
-    _ARGCHK(buf  != NULL);
+    LTC_ARGCHK(md   != NULL);
+    LTC_ARGCHK(out  != NULL);
 
     /* is the cipher valid? */
     if ((err = cipher_is_valid(cipher_idx)) != CRYPT_OK) {
@@ -208,19 +236,23 @@
     chc_compress(md, md->chc.buf);
 
     /* copy output */
-    XMEMCPY(buf, md->chc.state, cipher_blocksize);
+    XMEMCPY(out, md->chc.state, cipher_blocksize);
 
-#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 chc_test(void)
 {
    static const struct {
       unsigned char *msg,
-                    md[MAXBLOCKSIZE];
+                     md[MAXBLOCKSIZE];
       int            len;
    } tests[] = {
 {
diff --git a/src/hashes/helper/hash_file.c b/src/hashes/helper/hash_file.c
new file mode 100644
index 0000000..78c290a
--- /dev/null
+++ b/src/hashes/helper/hash_file.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 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
+}
+
diff --git a/src/hashes/helper/hash_filehandle.c b/src/hashes/helper/hash_filehandle.c
new file mode 100644
index 0000000..c02c5a7
--- /dev/null
+++ b/src/hashes/helper/hash_filehandle.c
@@ -0,0 +1,66 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+}
+
diff --git a/src/hashes/helper/hash_memory.c b/src/hashes/helper/hash_memory.c
new file mode 100644
index 0000000..9786948
--- /dev/null
+++ b/src/hashes/helper/hash_memory.c
@@ -0,0 +1,64 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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;
+}
diff --git a/src/hashes/helper/hash_memory_multi.c b/src/hashes/helper/hash_memory_multi.c
new file mode 100644
index 0000000..ce22283
--- /dev/null
+++ b/src/hashes/helper/hash_memory_multi.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
+ */
+#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;
+}
diff --git a/md2.c b/src/hashes/md2.c
similarity index 80%
rename from md2.c
rename to src/hashes/md2.c
index 8e2a987..5381771 100644
--- a/md2.c
+++ b/src/hashes/md2.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
  */
-/* 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,
@@ -90,9 +94,14 @@
    }
 }
 
+/**
+   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));
@@ -102,20 +111,27 @@
    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));
-        XMEMCPY(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) {
@@ -127,12 +143,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;
@@ -154,14 +176,18 @@
     md2_compress(md);
 
     /* output is lower 16 bytes of X */
-    XMEMCPY(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
diff --git a/md4.c b/src/hashes/md4.c
similarity index 86%
rename from md4.c
rename to src/hashes/md4.c
index 0e0cc6b..477f5b0 100644
--- a/md4.c
+++ b/src/hashes/md4.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
  */
-/* 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,
@@ -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,7 +71,7 @@
     (a) = ROTATE_LEFT ((a), (s)); \
   }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int _md4_compress(hash_state *md, unsigned char *buf)
 #else
 static int  md4_compress(hash_state *md, unsigned char *buf)
@@ -151,7 +155,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int md4_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -161,9 +165,14 @@
 }
 #endif
 
+/**
+   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;
@@ -173,14 +182,27 @@
    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;
@@ -215,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
diff --git a/md5.c b/src/hashes/md5.c
similarity index 86%
rename from md5.c
rename to src/hashes/md5.c
index 5339169..e2e5c74 100644
--- a/md5.c
+++ b/src/hashes/md5.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
  */
+#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,
@@ -39,6 +42,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 +56,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 +81,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
+#ifdef LTC_CLEAN_STACK
 static int _md5_compress(hash_state *md, unsigned char *buf)
 #else
 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 +120,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;
@@ -198,7 +216,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int md5_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -208,9 +226,14 @@
 }
 #endif
 
+/**
+   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;
@@ -220,14 +243,27 @@
    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;
@@ -263,14 +299,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
diff --git a/rmd128.c b/src/hashes/rmd128.c
similarity index 88%
rename from rmd128.c
rename to src/hashes/rmd128.c
index f9351de..1c304a1 100644
--- a/rmd128.c
+++ b/src/hashes/rmd128.c
@@ -6,19 +6,24 @@
  * 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,
@@ -44,37 +49,37 @@
 /* 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
+#ifdef LTC_CLEAN_STACK
 static int _rmd128_compress(hash_state *md, unsigned char *buf)
 #else
 static int  rmd128_compress(hash_state *md, unsigned char *buf)
@@ -248,7 +253,7 @@
    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int rmd128_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -258,9 +263,14 @@
 }
 #endif
 
+/**
+   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;
@@ -270,14 +280,27 @@
    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;
@@ -313,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
diff --git a/rmd160.c b/src/hashes/rmd160.c
similarity index 88%
rename from rmd160.c
rename to src/hashes/rmd160.c
index 2079448..a617152 100644
--- a/rmd160.c
+++ b/src/hashes/rmd160.c
@@ -6,19 +6,24 @@
  * 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,
@@ -46,56 +51,56 @@
 /* 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
+#ifdef LTC_CLEAN_STACK
 static int _rmd160_compress(hash_state *md, unsigned char *buf)
 #else
 static int  rmd160_compress(hash_state *md, unsigned char *buf)
@@ -307,7 +312,7 @@
    return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int rmd160_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -317,9 +322,14 @@
 }
 #endif
 
+/**
+   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;
@@ -330,14 +340,27 @@
    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;
@@ -373,14 +396,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
diff --git a/sha1.c b/src/hashes/sha1.c
similarity index 77%
rename from sha1.c
rename to src/hashes/sha1.c
index d6e57c3..267729b 100644
--- a/sha1.c
+++ b/src/hashes/sha1.c
@@ -6,15 +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
  */
+#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,
@@ -37,14 +41,14 @@
 #define F2(x,y,z)  ((x & y) | (z & (x | y)))
 #define F3(x,y,z)  (x ^ y ^ z)
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int _sha1_compress(hash_state *md, unsigned char *buf)
 #else
 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 +71,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;
@@ -143,7 +147,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int sha1_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -153,9 +157,14 @@
 }
 #endif
 
+/**
+   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;
@@ -166,14 +175,27 @@
    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;
@@ -208,14 +230,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
diff --git a/sha224.c b/src/hashes/sha2/sha224.c
similarity index 72%
rename from sha224.c
rename to src/hashes/sha2/sha224.c
index 2b25ff0..8c0dcde 100644
--- a/sha224.c
+++ b/src/hashes/sha2/sha224.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
  */
+/**
+   @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,9 +31,14 @@
 };
 
 /* init the sha256 er... sha224 state ;-) */
+/**
+   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;
@@ -45,19 +53,32 @@
     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);
-    XMEMCPY(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
diff --git a/sha256.c b/src/hashes/sha2/sha256.c
similarity index 89%
rename from sha256.c
rename to src/hashes/sha2/sha256.c
index b918e3f..85eba2a 100644
--- a/sha256.c
+++ b/src/hashes/sha2/sha256.c
@@ -6,17 +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
  */
+#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,
@@ -35,7 +36,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 +58,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 +66,14 @@
 #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
 
 /* compress 512-bits */
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int _sha256_compress(hash_state * md, unsigned char *buf)
 #else
 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 +94,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);                    \
@@ -188,7 +189,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int sha256_compress(hash_state * md, unsigned char *buf)
 {
     int err;
@@ -198,10 +199,14 @@
 }
 #endif
 
-/* init the sha256 state */
+/**
+   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;
@@ -216,14 +221,27 @@
     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;
@@ -259,14 +277,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
diff --git a/sha384.c b/src/hashes/sha2/sha384.c
similarity index 77%
rename from sha384.c
rename to src/hashes/sha2/sha384.c
index 190e8ca..912145c 100644
--- a/sha384.c
+++ b/src/hashes/sha2/sha384.c
@@ -6,12 +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
  */
+/** 
+   @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,
@@ -30,9 +32,14 @@
     &sha384_test
 };
 
+/**
+   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;
@@ -47,25 +54,35 @@
     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);
-   XMEMCPY(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
diff --git a/sha512.c b/src/hashes/sha2/sha512.c
similarity index 88%
rename from sha512.c
rename to src/hashes/sha2/sha512.c
index baf27cf..3238f2b 100644
--- a/sha512.c
+++ b/src/hashes/sha2/sha512.c
@@ -6,16 +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
  */
+#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,
@@ -81,7 +83,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,7 +91,7 @@
 #define Gamma1(x)       (S(x, 19) ^ S(x, 61) ^ R(x, 6))
 
 /* compress 1024-bits */
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int _sha512_compress(hash_state * md, unsigned char *buf)
 #else
 static int  sha512_compress(hash_state * md, unsigned char *buf)
@@ -114,7 +116,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]);
@@ -156,7 +158,7 @@
 }
 
 /* compress 1024-bits */
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int sha512_compress(hash_state * md, unsigned char *buf)
 {
     int err;
@@ -166,10 +168,14 @@
 }
 #endif
 
-/* init the sha512 state */
+/**
+   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);
@@ -183,14 +189,27 @@
     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;
@@ -228,14 +247,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
diff --git a/tiger.c b/src/hashes/tiger.c
similarity index 97%
rename from tiger.c
rename to src/hashes/tiger.c
index 3235953..a1cd888 100644
--- a/tiger.c
+++ b/src/hashes/tiger.c
@@ -6,14 +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
  */
 
-#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,
@@ -605,7 +610,7 @@
     x[7] -= x[6] ^ CONST64(0x0123456789ABCDEF);
 }    
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int _tiger_compress(hash_state *md, unsigned char *buf)
 #else
 static int  tiger_compress(hash_state *md, unsigned char *buf)
@@ -636,7 +641,7 @@
     return CRYPT_OK;
 }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int tiger_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -646,9 +651,14 @@
 }
 #endif
 
+/**
+   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);
@@ -657,12 +667,25 @@
     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;
@@ -695,16 +718,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
diff --git a/whirl.c b/src/hashes/whirl/whirl.c
similarity index 88%
rename from whirl.c
rename to src/hashes/whirl/whirl.c
index 8135b93..ff0b436 100644
--- a/whirl.c
+++ b/src/hashes/whirl/whirl.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
  */
 
-/* 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,
@@ -49,7 +52,7 @@
     SB6(GB(a, i-6, 1)) ^                 \
     SB7(GB(a, i-7, 0))
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int _whirlpool_compress(hash_state *md, unsigned char *buf)
 #else
 static int whirlpool_compress(hash_state *md, unsigned char *buf)
@@ -105,7 +108,7 @@
 }
 
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
 static int whirlpool_compress(hash_state *md, unsigned char *buf)
 {
    int err;
@@ -116,21 +119,39 @@
 #endif
 
 
+/**
+   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;
@@ -165,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
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..fb99bea 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
 
diff --git a/ltc_tommath.h b/src/headers/ltc_tommath.h
similarity index 94%
rename from ltc_tommath.h
rename to src/headers/ltc_tommath.h
index 896d389..05212e5 100644
--- a/ltc_tommath.h
+++ b/src/headers/ltc_tommath.h
@@ -112,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
@@ -147,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;
@@ -429,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);
 
@@ -442,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);
@@ -509,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);
@@ -554,7 +564,7 @@
 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;
diff --git a/mycrypt.h b/src/headers/tomcrypt.h
similarity index 79%
rename from mycrypt.h
rename to src/headers/tomcrypt.h
index 1d6a938..0d34c74 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   0x0099
-#define SCRYPT  "0.99"
+#define CRYPT   0x0102
+#define SCRYPT  "1.02"
 
 /* max size of either a cipher/hash block or symmetric key [largest of the two] */
-#define MAXBLOCKSIZE  64
+#define MAXBLOCKSIZE  128
 
 /* descriptor table size */
 #define TAB_SIZE      32
@@ -62,19 +62,20 @@
    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_ */
 
diff --git a/src/headers/tomcrypt_argchk.h b/src/headers/tomcrypt_argchk.h
new file mode 100644
index 0000000..5c8759d
--- /dev/null
+++ b/src/headers/tomcrypt_argchk.h
@@ -0,0 +1,21 @@
+/* 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
+
diff --git a/mycrypt_cfg.h b/src/headers/tomcrypt_cfg.h
similarity index 81%
rename from mycrypt_cfg.h
rename to src/headers/tomcrypt_cfg.h
index b440e0b..a0022d1 100644
--- a/mycrypt_cfg.h
+++ b/src/headers/tomcrypt_cfg.h
@@ -4,12 +4,12 @@
  * out the line that #define's the word for the thing you want to remove.  phew!
  */
 
-#ifndef MYCRYPT_CFG_H
-#define MYCRYPT_CFG_H
+#ifndef TOMCRYPT_CFG_H
+#define TOMCRYPT_CFG_H
 
 /* you can change how memory allocation works ... */
 void *XMALLOC(size_t n);
-void *REALLOC(void *p, size_t n);
+void *XREALLOC(void *p, size_t n);
 void *XCALLOC(size_t n, size_t s);
 void XFREE(void *p);
 
@@ -34,6 +34,8 @@
 #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) */
@@ -46,6 +48,26 @@
 #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 */
@@ -82,5 +104,5 @@
     #define PACKET_SUB_ENC_KEY     3
 #endif
 
-#endif /* MYCRYPT_CFG_H */
+#endif
 
diff --git a/src/headers/tomcrypt_cipher.h b/src/headers/tomcrypt_cipher.h
new file mode 100644
index 0000000..af184c2
--- /dev/null
+++ b/src/headers/tomcrypt_cipher.h
@@ -0,0 +1,619 @@
+/* ---- 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
+
+#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
+int ctr_start(int cipher, const unsigned char *IV, const unsigned char *key, 
+              int keylen, int num_rounds, 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);
+
diff --git a/mycrypt_custom.h b/src/headers/tomcrypt_custom.h
similarity index 62%
rename from mycrypt_custom.h
rename to src/headers/tomcrypt_custom.h
index 03058bb..d786f0b 100644
--- a/mycrypt_custom.h
+++ b/src/headers/tomcrypt_custom.h
@@ -1,9 +1,8 @@
 /* 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_
+#ifndef TOMCRYPT_CUSTOM_H_
+#define TOMCRYPT_CUSTOM_H_
 
 /* macros for various libc functions you can change for embedded targets */
 #define XMALLOC  malloc
@@ -18,18 +17,27 @@
 #define XCLOCKS_PER_SEC CLOCKS_PER_SEC
 
 /* Use small code where possible */
-// #define SMALL_CODE
+/* #define LTC_SMALL_CODE */
 
 /* Enable self-test test vector checking */
 #define LTC_TEST
 
 /* clean the stack of functions which put private information on stack */
-// #define CLEAN_STACK
+/* #define LTC_CLEAN_STACK */
 
 /* disable all file related functions */
-// #define NO_FILE
+/* #define LTC_NO_FILE */
 
-/* various ciphers */
+/* disable all forms of ASM */
+/* #define LTC_NO_ASM */
+
+/* disable FAST mode */
+/* #define LTC_NO_FAST */
+
+/* disable BSWAP on x86 */
+/* #define LTC_NO_BSWAP */
+
+/* ---> Symmetric Block Ciphers <--- */
 #define BLOWFISH
 #define RC2
 #define RC5
@@ -41,26 +49,27 @@
  * (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
 #define TWOFISH
 #define TWOFISH_TABLES
-// #define TWOFISH_ALL_TABLES
-// #define TWOFISH_SMALL
+/* #define TWOFISH_ALL_TABLES */
+/* #define TWOFISH_SMALL */
 /* DES includes EDE triple-DES */
 #define DES
 #define CAST5
 #define NOEKEON
 #define SKIPJACK
-/* SAFER code isn't public domain.  It appears to be free to use 
- * but has been disabled by default to avoid any such problems 
- */
-//#define SAFER
+#define SAFER
+#define KHAZAD
+#define ANUBIS
+#define ANUBIS_TWEAK
 
-/* block cipher modes of operation */
+
+/* ---> Block Cipher Modes of Operation <--- */
 #define CFB
 #define OFB
 #define ECB
 #define CBC
 #define CTR
 
-/* hash functions */
+/* ---> One-Way Hash Functions <--- */
 #define CHC_HASH
 #define WHIRLPOOL
 #define SHA512
@@ -75,29 +84,47 @@
 #define RIPEMD128
 #define RIPEMD160
 
-/* MAC functions */
+/* ---> MAC functions <--- */
 #define HMAC
 #define OMAC
 #define PMAC
+#define PELICAN
 
-/* Encrypt + Authenticate Modes */
+#if defined(PELICAN) && !defined(RIJNDAEL)
+   #error Pelican-MAC requires RIJNDAEL
+#endif
+
+/* ---> Encrypt + Authenticate Modes <--- */
 #define EAX_MODE
+#if defined(EAX_MODE) && !(defined(CTR) && defined(OMAC))
+   #error EAX_MODE requires CTR and OMAC mode
+#endif
+
 #define OCB_MODE
+#define CCM_MODE
+
+#define GCM_MODE
+/* Use 64KiB tables */
+#define GCM_TABLES 
 
 /* Various tidbits of modern neatoness */
 #define BASE64
 
+/* --> Pseudo Random Number Generators <--- */
 /* Yarrow */
 #define YARROW
-// which descriptor of AES to use? 
-// 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full]
+/* which descriptor of AES to use?  */
+/* 0 = rijndael_enc 1 = aes_enc, 2 = rijndael [full], 3 = aes [full] */
 #define YARROW_AES 0
 
 #if defined(YARROW) && !defined(CTR)
    #error YARROW requires CTR chaining mode to be defined!
 #endif
 
+/* a PRNG that simply reads from an available system source */
 #define SPRNG
+
+/* The RC4 stream cipher */
 #define RC4
 
 /* Fortuna PRNG */
@@ -110,13 +137,13 @@
 /* Greg's SOBER128 PRNG ;-0 */
 #define SOBER128
 
+/* the *nix style /dev/random device */
 #define DEVRANDOM
+/* try /dev/urandom before trying /dev/random */
 #define TRY_URANDOM_FIRST
 
-/* Public Key Neatoness */
+/* ---> Public Key Crypto <--- */
 #define MRSA
-/* enable RSA side channel timing prevention */
-#define RSA_TIMING
 
 /* Digital Signature Algorithm */
 #define MDSA
@@ -155,5 +182,15 @@
 #define PKCS_1
 #define PKCS_5
 
+/* Include ASN.1 DER (required by DSA/RSA) */
+#define LTC_DER
+#if defined(LTC_DER) && !defined(MPI) 
+   #error ASN.1 DER requires MPI functionality
+#endif
+
+#if (defined(MDSA) || defined(MRSA)) && !defined(LTC_DER)
+   #error RSA/DSA requires ASN.1 DER functionality, make sure LTC_DER is enabled
+#endif
+
 #endif
 
diff --git a/src/headers/tomcrypt_hash.h b/src/headers/tomcrypt_hash.h
new file mode 100644
index 0000000..d295a59
--- /dev/null
+++ b/src/headers/tomcrypt_hash.h
@@ -0,0 +1,324 @@
+/* ---- 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 DER identifier */
+    unsigned char DER[64];
+    /** Length of DER encoding */
+    unsigned long DERlen;
+    /** 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);
+
+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;                                                                        \
+}
diff --git a/src/headers/tomcrypt_mac.h b/src/headers/tomcrypt_mac.h
new file mode 100644
index 0000000..6b5e1ce
--- /dev/null
+++ b/src/headers/tomcrypt_mac.h
@@ -0,0 +1,297 @@
+#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
diff --git a/mycrypt_macros.h b/src/headers/tomcrypt_macros.h
similarity index 78%
rename from mycrypt_macros.h
rename to src/headers/tomcrypt_macros.h
index 6e2eaa2..f083984 100644
--- a/mycrypt_macros.h
+++ b/src/headers/tomcrypt_macros.h
@@ -67,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); }
@@ -77,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);     \
@@ -89,6 +127,8 @@
          (((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)        \
@@ -190,19 +230,23 @@
 #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(__x86_64__)) && !defined(INTEL_CC)
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
 
 static inline unsigned ROL(unsigned word, int i)
 {
-   __asm__("roll %%cl,%0"
+   asm ("roll %%cl,%0"
       :"=r" (word)
       :"0" (word),"c" (i));
    return word;
@@ -210,25 +254,54 @@
 
 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
 
-#if defined(__GNUCC__) && defined(__x86_64__)
+
+/* 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"
+   asm("rolq %%cl,%0"
       :"=r" (word)
       :"0" (word),"c" (i));
    return word;
@@ -236,13 +309,38 @@
 
 static inline unsigned long ROR64(unsigned long word, int i)
 {
-   __asm__("rorq %%cl,%0"
+   asm("rorq %%cl,%0"
       :"=r" (word)
       :"0" (word),"c" (i));
    return word;
 }
 
-#else
+#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)) | \
@@ -252,6 +350,14 @@
     ( ((((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
diff --git a/src/headers/tomcrypt_misc.h b/src/headers/tomcrypt_misc.h
new file mode 100644
index 0000000..bed5015
--- /dev/null
+++ b/src/headers/tomcrypt_misc.h
@@ -0,0 +1,17 @@
+/* ---- 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;
diff --git a/src/headers/tomcrypt_pk.h b/src/headers/tomcrypt_pk.h
new file mode 100644
index 0000000..065ca99
--- /dev/null
+++ b/src/headers/tomcrypt_pk.h
@@ -0,0 +1,270 @@
+/* ---- 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
+
+/* 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, 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);
+
+/* these use PKCS #1 v1.5 padding */
+int rsa_v15_encrypt_key(const unsigned char *in,    unsigned long  inlen,
+                              unsigned char *out,   unsigned long *outlen,
+                              prng_state    *prng,     int            prng_idx, 
+                              rsa_key       *key);
+         
+int rsa_v15_decrypt_key(const unsigned char *in,     unsigned long  inlen,
+                              unsigned char *out,    unsigned long  outlen, 
+                              int           *stat,   rsa_key       *key);
+
+int rsa_v15_sign_hash(const unsigned char *in,       unsigned long  inlen, 
+                            unsigned char *out,      unsigned long *siglen, 
+                            int            hash_idx, rsa_key       *key);
+
+int rsa_v15_verify_hash(const unsigned char *sig,      unsigned long siglen,
+                        const unsigned char *hash,     unsigned long hashlen,
+                              int            hash_idx, 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(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(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 */
+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);
+int der_put_multi_integer(unsigned char *dst, unsigned long *outlen, mp_int *num, ...);
+int der_get_multi_integer(const unsigned char *src, unsigned long *inlen,  mp_int *num, ...);
+#endif
diff --git a/mycrypt_pkcs.h b/src/headers/tomcrypt_pkcs.h
similarity index 100%
rename from mycrypt_pkcs.h
rename to src/headers/tomcrypt_pkcs.h
diff --git a/src/headers/tomcrypt_prng.h b/src/headers/tomcrypt_prng.h
new file mode 100644
index 0000000..2ae5749
--- /dev/null
+++ b/src/headers/tomcrypt_prng.h
@@ -0,0 +1,190 @@
+/* ---- 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);
+
+/* 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));
+
diff --git a/tommath_class.h b/src/headers/tommath_class.h
similarity index 94%
rename from tommath_class.h
rename to src/headers/tommath_class.h
index c94e8e0..6d05b7b 100644
--- a/tommath_class.h
+++ b/src/headers/tommath_class.h
@@ -90,8 +90,11 @@
 #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
@@ -105,7 +108,9 @@
 #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
@@ -132,7 +137,7 @@
    #define BN_MP_ISEVEN_C
    #define BN_MP_INIT_MULTI_C
    #define BN_MP_COPY_C
-   #define BN_MP_ABS_C
+   #define BN_MP_MOD_C
    #define BN_MP_SET_C
    #define BN_MP_DIV_2_C
    #define BN_MP_ISODD_C
@@ -146,7 +151,6 @@
 #endif
 
 #if defined(BN_FAST_MP_MONTGOMERY_REDUCE_C)
-   #define BN_MP_MONTGOMERY_REDUCE_C
    #define BN_MP_GROW_C
    #define BN_MP_RSHD_C
    #define BN_MP_CLAMP_C
@@ -160,7 +164,6 @@
 #endif
 
 #if defined(BN_FAST_S_MP_MUL_HIGH_DIGS_C)
-   #define BN_FAST_S_MP_MUL_DIGS_C
    #define BN_MP_GROW_C
    #define BN_MP_CLAMP_C
 #endif
@@ -244,6 +247,7 @@
    #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
@@ -325,11 +329,12 @@
    #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
-   #define BN_S_MP_EXPTMOD_C
 #endif
 
 #if defined(BN_MP_EXPTMOD_FAST_C)
@@ -361,6 +366,7 @@
    #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
@@ -435,6 +441,7 @@
 #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
@@ -481,7 +488,6 @@
 #endif
 
 #if defined(BN_MP_KARATSUBA_SQR_C)
-   #define BN_MP_KARATSUBA_MUL_C
    #define BN_MP_INIT_SIZE_C
    #define BN_MP_CLAMP_C
    #define BN_MP_SQR_C
@@ -534,10 +540,8 @@
 #endif
 
 #if defined(BN_MP_MONTGOMERY_REDUCE_C)
-   #define BN_MP_MUL_C
    #define BN_FAST_MP_MONTGOMERY_REDUCE_C
    #define BN_MP_GROW_C
-   #define BN_MP_MONTGOMERY_SETUP_C
    #define BN_MP_CLAMP_C
    #define BN_MP_RSHD_C
    #define BN_MP_CMP_MAG_C
@@ -705,6 +709,7 @@
    #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
@@ -728,6 +733,17 @@
    #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
@@ -736,11 +752,22 @@
    #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
@@ -818,6 +845,11 @@
    #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
@@ -825,6 +857,11 @@
    #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
@@ -905,10 +942,12 @@
    #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_REDUCE_C
    #define BN_MP_MUL_C
    #define BN_MP_SET_C
    #define BN_MP_EXCH_C
diff --git a/tommath_superclass.h b/src/headers/tommath_superclass.h
similarity index 94%
rename from tommath_superclass.h
rename to src/headers/tommath_superclass.h
index 043b224..b50ecb0 100644
--- a/tommath_superclass.h
+++ b/src/headers/tommath_superclass.h
@@ -7,7 +7,9 @@
 // #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 */
@@ -32,7 +34,7 @@
    #define BN_PRIME_TAB_C
 
    /* other modifiers */
-//   #define BN_MP_DIV_SMALL                    /* Slower division, not critical (currently buggy?) */
+   #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
diff --git a/hmac_done.c b/src/mac/hmac/hmac_done.c
similarity index 61%
rename from hmac_done.c
rename to src/mac/hmac/hmac_done.c
index b31460b..fdf20be 100644
--- a/hmac_done.c
+++ b/src/mac/hmac/hmac_done.c
@@ -6,41 +6,34 @@
  * 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_done.c
+  HMAC support, terminate stream, Tom St Denis/Dobes Vandermeer
 */
 
 #ifdef HMAC
 
 #define HMAC_BLOCKSIZE hash_descriptor[hash].blocksize
 
-int hmac_done(hmac_state *hmac, unsigned char *hashOut, unsigned long *outlen)
+/**
+   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;
 
-    _ARGCHK(hmac    != NULL);
-    _ARGCHK(hashOut != NULL);
+    LTC_ARGCHK(hmac  != NULL);
+    LTC_ARGCHK(out   != NULL);
 
     /* test hash */
     hash = hmac->hash;
@@ -66,7 +59,7 @@
 
     /* Get the hash of the first HMAC vector plus the data */
     if ((err = hash_descriptor[hash].done(&hmac->md, isha)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     /* Create the second HMAC vector vector for step (3) */
@@ -76,28 +69,28 @@
 
     /* Now calculate the "outer" hash for step (5), (6), and (7) */
     if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
     if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
     if ((err = hash_descriptor[hash].process(&hmac->md, isha, hashsize)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
     if ((err = hash_descriptor[hash].done(&hmac->md, buf)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     /* copy to output  */
     for (i = 0; i < hashsize && i < *outlen; i++) {
-        hashOut[i] = buf[i];
+        out[i] = buf[i];
     }
     *outlen = i;
 
     err = CRYPT_OK;
-__ERR:
+LBL_ERR:
     XFREE(hmac->key);
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(isha, hashsize);
     zeromem(buf,  hashsize);
     zeromem(hmac, sizeof(*hmac));
diff --git a/src/mac/hmac/hmac_file.c b/src/mac/hmac/hmac_file.c
new file mode 100644
index 0000000..edbb6a6
--- /dev/null
+++ b/src/mac/hmac/hmac_file.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 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
+
diff --git a/hmac_init.c b/src/mac/hmac/hmac_init.c
similarity index 67%
rename from hmac_init.c
rename to src/mac/hmac/hmac_init.c
index 0d894f1..d060a5b 100644
--- a/hmac_init.c
+++ b/src/mac/hmac/hmac_init.c
@@ -6,33 +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
  */
-/* 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_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;
@@ -40,8 +34,8 @@
     unsigned long i, z;
     int err;
 
-    _ARGCHK(hmac != NULL);
-    _ARGCHK(key  != NULL);
+    LTC_ARGCHK(hmac != NULL);
+    LTC_ARGCHK(key  != NULL);
 
     /* valid hash? */
     if ((err = hash_is_valid(hash)) != CRYPT_OK) {
@@ -72,7 +66,7 @@
     if(keylen > HMAC_BLOCKSIZE) {
         z = HMAC_BLOCKSIZE;
         if ((err = hash_memory(hash, key, keylen, hmac->key, &z)) != CRYPT_OK) {
-           goto __ERR;
+           goto LBL_ERR;
         }
         if(hashsize < HMAC_BLOCKSIZE) {
             zeromem((hmac->key) + hashsize, (size_t)(HMAC_BLOCKSIZE - hashsize));
@@ -92,18 +86,18 @@
 
     /* Pre-pend that to the hash data */
     if ((err = hash_descriptor[hash].init(&hmac->md)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     if ((err = hash_descriptor[hash].process(&hmac->md, buf, HMAC_BLOCKSIZE)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
     goto done;
-__ERR:
+LBL_ERR:
     /* free the key since we failed */
     XFREE(hmac->key);
 done:
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, HMAC_BLOCKSIZE);
 #endif
  
diff --git a/src/mac/hmac/hmac_memory.c b/src/mac/hmac/hmac_memory.c
new file mode 100644
index 0000000..036ee36
--- /dev/null
+++ b/src/mac/hmac/hmac_memory.c
@@ -0,0 +1,73 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+
diff --git a/src/mac/hmac/hmac_memory_multi.c b/src/mac/hmac/hmac_memory_multi.c
new file mode 100644
index 0000000..4a5b9be
--- /dev/null
+++ b/src/mac/hmac/hmac_memory_multi.c
@@ -0,0 +1,88 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+
diff --git a/src/mac/hmac/hmac_process.c b/src/mac/hmac/hmac_process.c
new file mode 100644
index 0000000..30e64c3
--- /dev/null
+++ b/src/mac/hmac/hmac_process.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 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
+
diff --git a/hmac_test.c b/src/mac/hmac/hmac_test.c
similarity index 92%
rename from hmac_test.c
rename to src/mac/hmac/hmac_test.c
index 2b97777..0d542d4 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
diff --git a/src/mac/omac/omac_done.c b/src/mac/omac/omac_done.c
new file mode 100644
index 0000000..0a91a14
--- /dev/null
+++ b/src/mac/omac/omac_done.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 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
+
diff --git a/src/mac/omac/omac_file.c b/src/mac/omac/omac_file.c
new file mode 100644
index 0000000..1e3d2f6
--- /dev/null
+++ b/src/mac/omac/omac_file.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 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
diff --git a/omac_init.c b/src/mac/omac/omac_init.c
similarity index 77%
rename from omac_init.c
rename to src/mac/omac/omac_init.c
index cc933d0..d39219d 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 (16 % sizeof(LTC_FAST_TYPE)) {
+       return CRYPT_INVALID_ARG;
+   }
+#endif
+
    /* now setup the system */
    switch (cipher_descriptor[cipher].block_length) {
        case 8:  mask = 0x1B;
diff --git a/src/mac/omac/omac_memory.c b/src/mac/omac/omac_memory.c
new file mode 100644
index 0000000..51d0ce2
--- /dev/null
+++ b/src/mac/omac/omac_memory.c
@@ -0,0 +1,71 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/src/mac/omac/omac_memory_multi.c b/src/mac/omac/omac_memory_multi.c
new file mode 100644
index 0000000..76e4eb0
--- /dev/null
+++ b/src/mac/omac/omac_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 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
diff --git a/src/mac/omac/omac_process.c b/src/mac/omac/omac_process.c
new file mode 100644
index 0000000..6b603f7
--- /dev/null
+++ b/src/mac/omac/omac_process.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 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)
+{
+   int err, n, x;
+
+   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 < 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
+
diff --git a/omac_test.c b/src/mac/omac/omac_test.c
similarity index 92%
rename from omac_test.c
rename to src/mac/omac/omac_test.c
index e346073..42e42bd 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)
diff --git a/src/mac/pelican/pelican.c b/src/mac/pelican/pelican.c
new file mode 100644
index 0000000..fb7ce58
--- /dev/null
+++ b/src/mac/pelican/pelican.c
@@ -0,0 +1,149 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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);
+#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);
+   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
diff --git a/src/mac/pelican/pelican_memory.c b/src/mac/pelican/pelican_memory.c
new file mode 100644
index 0000000..9e0fc7b
--- /dev/null
+++ b/src/mac/pelican/pelican_memory.c
@@ -0,0 +1,55 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/src/mac/pelican/pelican_test.c b/src/mac/pelican/pelican_test.c
new file mode 100644
index 0000000..e694f61
--- /dev/null
+++ b/src/mac/pelican/pelican_test.c
@@ -0,0 +1,116 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/pmac_done.c b/src/mac/pmac/pmac_done.c
similarity index 82%
rename from pmac_done.c
rename to src/mac/pmac/pmac_done.c
index 8051da7..610e433 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;
diff --git a/src/mac/pmac/pmac_file.c b/src/mac/pmac/pmac_file.c
new file mode 100644
index 0000000..5b7dd24
--- /dev/null
+++ b/src/mac/pmac/pmac_file.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 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
diff --git a/pmac_init.c b/src/mac/pmac/pmac_init.c
similarity index 82%
rename from pmac_init.c
rename to src/mac/pmac/pmac_init.c
index 2f96927..a02b20c 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;
 
-   _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,7 +65,14 @@
    }
    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) {
@@ -110,7 +128,7 @@
     zeromem(pmac->Li,       sizeof(pmac->Li));
     zeromem(pmac->checksum, sizeof(pmac->checksum));
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(L, pmac->block_len);
 #endif
 
diff --git a/src/mac/pmac/pmac_memory.c b/src/mac/pmac/pmac_memory.c
new file mode 100644
index 0000000..a04cd78
--- /dev/null
+++ b/src/mac/pmac/pmac_memory.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 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
diff --git a/src/mac/pmac/pmac_memory_multi.c b/src/mac/pmac/pmac_memory_multi.c
new file mode 100644
index 0000000..289d2e0
--- /dev/null
+++ b/src/mac/pmac/pmac_memory_multi.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"
+#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
diff --git a/pmac_ntz.c b/src/mac/pmac/pmac_ntz.c
similarity index 68%
rename from pmac_ntz.c
rename to src/mac/pmac/pmac_ntz.c
index 98ec430..97f0a15 100644
--- a/pmac_ntz.c
+++ b/src/mac/pmac/pmac_ntz.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 "tomcrypt.h"
 
-/* PMAC implementation by Tom St Denis */
-#include "mycrypt.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;
diff --git a/src/mac/pmac/pmac_process.c b/src/mac/pmac/pmac_process.c
new file mode 100644
index 0000000..5cee5ec
--- /dev/null
+++ b/src/mac/pmac/pmac_process.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 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
diff --git a/src/mac/pmac/pmac_shift_xor.c b/src/mac/pmac/pmac_shift_xor.c
new file mode 100644
index 0000000..18c6141
--- /dev/null
+++ b/src/mac/pmac/pmac_shift_xor.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 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
diff --git a/pmac_test.c b/src/mac/pmac/pmac_test.c
similarity index 92%
rename from pmac_test.c
rename to src/mac/pmac/pmac_test.c
index e813eb5..6c610f9 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)
diff --git a/base64_decode.c b/src/misc/base64/base64_decode.c
similarity index 66%
rename from base64_decode.c
rename to src/misc/base64/base64_decode.c
index 6729480..ac6db57 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; 
diff --git a/src/misc/base64/base64_encode.c b/src/misc/base64/base64_encode.c
new file mode 100644
index 0000000..047980c
--- /dev/null
+++ b/src/misc/base64/base64_encode.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 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
+
diff --git a/burn_stack.c b/src/misc/burn_stack.c
similarity index 66%
rename from burn_stack.c
rename to src/misc/burn_stack.c
index 17b1391..3bc69ab 100644
--- a/burn_stack.c
+++ b/src/misc/burn_stack.c
@@ -6,10 +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
  */
-#include "mycrypt.h"
+#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];
diff --git a/crypt.c b/src/misc/crypt/crypt.c
similarity index 69%
rename from crypt.c
rename to src/misc/crypt/crypt.c
index 3a4bdc3..83f1414 100644
--- a/crypt.c
+++ b/src/misc/crypt/crypt.c
@@ -6,12 +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
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @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"
@@ -31,7 +38,7 @@
    #endif
 #endif
    "Clean stack: "
-#if defined(CLEAN_STACK)
+#if defined(LTC_CLEAN_STACK)
    "enabled\n"
 #else
    "disabled\n"
@@ -63,12 +70,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
@@ -85,6 +100,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)
@@ -154,6 +179,9 @@
 #if defined(PMAC)
     "   PMAC\n"
 #endif
+#if defined(PELICAN)
+    "   PELICAN\n"
+#endif
 
     "\nENC + AUTH modes:\n"
 #if defined(EAX_MODE)
@@ -162,6 +190,16 @@
 #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"
@@ -183,11 +221,7 @@
 
     "\nPK Algs:\n"
 #if defined(MRSA)
-    "   RSA"
-#if defined(RSA_TIMING)
-    " + RSA_TIMING "
-#endif
-    "\n"
+    "   RSA \n"
 #endif
 #if defined(MDH)
     "   DH\n"
@@ -203,10 +237,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)
@@ -218,6 +252,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)
@@ -238,14 +275,26 @@
 #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(LTMSSE)
-    " LTMSSE "
+#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
     "\n"
     "\n\n\n"
diff --git a/crypt_argchk.c b/src/misc/crypt/crypt_argchk.c
similarity index 64%
rename from crypt_argchk.c
rename to src/misc/crypt/crypt_argchk.c
index 3bb73a0..d345c8d 100644
--- a/crypt_argchk.c
+++ b/src/misc/crypt/crypt_argchk.c
@@ -6,15 +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"
 #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, "_ARGCHK '%s' failure on line %d of file %s\n",
+ fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n",
          v, d, s);
  (void)raise(SIGABRT);
 }
diff --git a/src/misc/crypt/crypt_cipher_descriptor.c b/src/misc/crypt/crypt_cipher_descriptor.c
new file mode 100644
index 0000000..e274449
--- /dev/null
+++ b/src/misc/crypt/crypt_cipher_descriptor.c
@@ -0,0 +1,21 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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 }
+ };
+
diff --git a/crypt_cipher_is_valid.c b/src/misc/crypt/crypt_cipher_is_valid.c
similarity index 60%
rename from crypt_cipher_is_valid.c
rename to src/misc/crypt/crypt_cipher_is_valid.c
index 8b0c448..b179402 100644
--- a/crypt_cipher_is_valid.c
+++ b/src/misc/crypt/crypt_cipher_is_valid.c
@@ -6,10 +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 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)
 {
    if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
diff --git a/src/misc/crypt/crypt_find_cipher.c b/src/misc/crypt/crypt_find_cipher.c
new file mode 100644
index 0000000..b83109c
--- /dev/null
+++ b/src/misc/crypt/crypt_find_cipher.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 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);
+   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/src/misc/crypt/crypt_find_cipher_any.c b/src/misc/crypt/crypt_find_cipher_any.c
new file mode 100644
index 0000000..42e59c0
--- /dev/null
+++ b/src/misc/crypt/crypt_find_cipher_any.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 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;
+
+   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/src/misc/crypt/crypt_find_cipher_id.c
similarity index 62%
rename from crypt_find_cipher_id.c
rename to src/misc/crypt/crypt_find_cipher_id.c
index 91b19d5..986baf5 100644
--- a/crypt_find_cipher_id.c
+++ b/src/misc/crypt/crypt_find_cipher_id.c
@@ -6,10 +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 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;
diff --git a/crypt_find_hash.c b/src/misc/crypt/crypt_find_hash.c
similarity index 61%
rename from crypt_find_hash.c
rename to src/misc/crypt/crypt_find_hash.c
index 1422233..d66201c 100644
--- a/crypt_find_hash.c
+++ b/src/misc/crypt/crypt_find_hash.c
@@ -6,14 +6,24 @@
  * 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 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;
-   _ARGCHK(name != NULL);
+   LTC_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;
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..0d6d430
--- /dev/null
+++ b/src/misc/crypt/crypt_find_hash_any.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 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;
+
+   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/src/misc/crypt/crypt_find_hash_id.c
similarity index 62%
rename from crypt_find_hash_id.c
rename to src/misc/crypt/crypt_find_hash_id.c
index ff04aea..8628d53 100644
--- a/crypt_find_hash_id.c
+++ b/src/misc/crypt/crypt_find_hash_id.c
@@ -6,10 +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 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;
diff --git a/crypt_find_prng.c b/src/misc/crypt/crypt_find_prng.c
similarity index 61%
rename from crypt_find_prng.c
rename to src/misc/crypt/crypt_find_prng.c
index 7fc4e45..c01a023 100644
--- a/crypt_find_prng.c
+++ b/src/misc/crypt/crypt_find_prng.c
@@ -6,14 +6,24 @@
  * 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 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;
-   _ARGCHK(name != NULL);
+   LTC_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;
diff --git a/src/misc/crypt/crypt_hash_descriptor.c b/src/misc/crypt/crypt_hash_descriptor.c
new file mode 100644
index 0000000..cbd6d03
--- /dev/null
+++ b/src/misc/crypt/crypt_hash_descriptor.c
@@ -0,0 +1,20 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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 }
+};
diff --git a/crypt_hash_is_valid.c b/src/misc/crypt/crypt_hash_is_valid.c
similarity index 60%
rename from crypt_hash_is_valid.c
rename to src/misc/crypt/crypt_hash_is_valid.c
index b924e59..c9784b8 100644
--- a/crypt_hash_is_valid.c
+++ b/src/misc/crypt/crypt_hash_is_valid.c
@@ -6,10 +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 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)
 {
    if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
diff --git a/src/misc/crypt/crypt_prng_descriptor.c b/src/misc/crypt/crypt_prng_descriptor.c
new file mode 100644
index 0000000..8a99510
--- /dev/null
+++ b/src/misc/crypt/crypt_prng_descriptor.c
@@ -0,0 +1,19 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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 }
+};
diff --git a/crypt_prng_is_valid.c b/src/misc/crypt/crypt_prng_is_valid.c
similarity index 60%
rename from crypt_prng_is_valid.c
rename to src/misc/crypt/crypt_prng_is_valid.c
index cc66bc2..7795bbb 100644
--- a/crypt_prng_is_valid.c
+++ b/src/misc/crypt/crypt_prng_is_valid.c
@@ -6,10 +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 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)
 {
    if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
diff --git a/src/misc/crypt/crypt_register_cipher.c b/src/misc/crypt/crypt_register_cipher.c
new file mode 100644
index 0000000..74349e6
--- /dev/null
+++ b/src/misc/crypt/crypt_register_cipher.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
+ */
+#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? */
+   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) {
+          XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor));
+          return x;
+       }
+   }
+
+   /* no spot */
+   return -1;
+}
diff --git a/src/misc/crypt/crypt_register_hash.c b/src/misc/crypt/crypt_register_hash.c
new file mode 100644
index 0000000..d5cf5b8
--- /dev/null
+++ b/src/misc/crypt/crypt_register_hash.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
+ */
+#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? */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
+          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));
+          return x;
+       }
+   }
+
+   /* no spot */
+   return -1;
+}
diff --git a/src/misc/crypt/crypt_register_prng.c b/src/misc/crypt/crypt_register_prng.c
new file mode 100644
index 0000000..6a1be77
--- /dev/null
+++ b/src/misc/crypt/crypt_register_prng.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
+ */
+#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? */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {
+          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));
+          return x;
+       }
+   }
+
+   /* no spot */
+   return -1;
+}
diff --git a/src/misc/crypt/crypt_unregister_cipher.c b/src/misc/crypt/crypt_unregister_cipher.c
new file mode 100644
index 0000000..0511de5
--- /dev/null
+++ b/src/misc/crypt/crypt_unregister_cipher.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
+ */
+#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? */
+   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;
+          return CRYPT_OK;
+       }
+   }
+   return CRYPT_ERROR;
+}
diff --git a/src/misc/crypt/crypt_unregister_hash.c b/src/misc/crypt/crypt_unregister_hash.c
new file mode 100644
index 0000000..25e36f2
--- /dev/null
+++ b/src/misc/crypt/crypt_unregister_hash.c
@@ -0,0 +1,37 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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? */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
+          hash_descriptor[x].name = NULL;
+          return CRYPT_OK;
+       }
+   }
+   return CRYPT_ERROR;
+}
diff --git a/src/misc/crypt/crypt_unregister_prng.c b/src/misc/crypt/crypt_unregister_prng.c
new file mode 100644
index 0000000..55cc554
--- /dev/null
+++ b/src/misc/crypt/crypt_unregister_prng.c
@@ -0,0 +1,37 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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? */
+   for (x = 0; x < TAB_SIZE; x++) {
+       if (memcmp(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) != 0) {
+          prng_descriptor[x].name = NULL;
+          return CRYPT_OK;
+       }
+   }
+   return CRYPT_ERROR;
+}
diff --git a/error_to_string.c b/src/misc/error_to_string.c
similarity index 77%
rename from error_to_string.c
rename to src/misc/error_to_string.c
index 9c388fa..3a325a2 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]))) {
diff --git a/is_prime.c b/src/misc/mpi/is_prime.c
similarity index 71%
rename from is_prime.c
rename to src/misc/mpi/is_prime.c
index d6fc84e..f58391f 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);
    }
diff --git a/mpi.c b/src/misc/mpi/mpi.c
similarity index 89%
rename from mpi.c
rename to src/misc/mpi/mpi.c
index 2ddd0de..ba3a7ed 100644
--- a/mpi.c
+++ b/src/misc/mpi/mpi.c
@@ -13,7 +13,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 static const struct {
@@ -60,7 +60,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes the modular inverse via binary extended euclidean algorithm, 
@@ -69,8 +69,7 @@
  * Based on slow 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)
+int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
 {
   mp_int  x, y, u, v, B, D;
   int     res, neg;
@@ -87,20 +86,20 @@
 
   /* x == modulus, y == value to invert */
   if ((res = mp_copy (b, &x)) != MP_OKAY) {
-    goto __ERR;
+    goto LBL_ERR;
   }
 
   /* we need y = |a| */
-  if ((res = mp_abs (a, &y)) != MP_OKAY) {
-    goto __ERR;
+  if ((res = mp_mod (a, b, &y)) != MP_OKAY) {
+    goto LBL_ERR;
   }
 
   /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
   if ((res = mp_copy (&x, &u)) != MP_OKAY) {
-    goto __ERR;
+    goto LBL_ERR;
   }
   if ((res = mp_copy (&y, &v)) != MP_OKAY) {
-    goto __ERR;
+    goto LBL_ERR;
   }
   mp_set (&D, 1);
 
@@ -109,17 +108,17 @@
   while (mp_iseven (&u) == 1) {
     /* 4.1 u = u/2 */
     if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
     /* 4.2 if B is odd then */
     if (mp_isodd (&B) == 1) {
       if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
-        goto __ERR;
+        goto LBL_ERR;
       }
     }
     /* B = B/2 */
     if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   }
 
@@ -127,18 +126,18 @@
   while (mp_iseven (&v) == 1) {
     /* 5.1 v = v/2 */
     if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_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;
+        goto LBL_ERR;
       }
     }
     /* D = D/2 */
     if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   }
 
@@ -146,20 +145,20 @@
   if (mp_cmp (&u, &v) != MP_LT) {
     /* u = u - v, B = B - D */
     if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
 
     if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   } else {
     /* v - v - u, D = D - B */
     if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
 
     if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   }
 
@@ -173,21 +172,21 @@
   /* if v != 1 then there is no inverse */
   if (mp_cmp_d (&v, 1) != MP_EQ) {
     res = MP_VAL;
-    goto __ERR;
+    goto LBL_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;
+      goto LBL_ERR;
     }
   }
   mp_exch (&D, c);
   c->sign = neg;
   res = MP_OKAY;
 
-__ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
   return res;
 }
 #endif
@@ -209,7 +208,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction
@@ -220,8 +219,7 @@
  *
  * 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 fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
 {
   int     ix, res, olduse;
   mp_word W[MP_WARRAY];
@@ -382,7 +380,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Fast (comba) multiplier
@@ -401,8 +399,7 @@
  * 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 fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
 {
   int     olduse, res, pa, ix, iz;
   mp_digit W[MP_WARRAY];
@@ -420,7 +417,7 @@
 
   /* clear the carry */
   _W = 0;
-  for (ix = 0; ix <= pa; ix++) { 
+  for (ix = 0; ix < pa; ix++) { 
       int      tx, ty;
       int      iy;
       mp_digit *tmpx, *tmpy;
@@ -433,7 +430,7 @@
       tmpx = a->dp + tx;
       tmpy = b->dp + ty;
 
-      /* this is the number of times the loop will iterrate, essentially its 
+      /* this is the number of times the loop will iterrate, essentially 
          while (tx++ < a->used && ty-- >= 0) { ... }
        */
       iy = MIN(a->used-tx, ty+1);
@@ -450,14 +447,17 @@
       _W = _W >> ((mp_word)DIGIT_BIT);
   }
 
+  /* store final carry */
+  W[ix] = (mp_digit)(_W & MP_MASK);
+
   /* setup dest */
   olduse  = c->used;
-  c->used = digs;
+  c->used = pa;
 
   {
     register mp_digit *tmpc;
     tmpc = c->dp;
-    for (ix = 0; ix < digs; ix++) {
+    for (ix = 0; ix < pa+1; ix++) {
       /* now extract the previous digit [below the carry] */
       *tmpc++ = W[ix];
     }
@@ -489,7 +489,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* this is a modified version of fast_s_mul_digs that only produces
@@ -501,8 +501,7 @@
  *
  * 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 fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
 {
   int     olduse, res, pa, ix, iz;
   mp_digit W[MP_WARRAY];
@@ -519,7 +518,7 @@
   /* number of output digits to produce */
   pa = a->used + b->used;
   _W = 0;
-  for (ix = digs; ix <= pa; ix++) { 
+  for (ix = digs; ix < pa; ix++) { 
       int      tx, ty, iy;
       mp_digit *tmpx, *tmpy;
 
@@ -547,6 +546,9 @@
       /* make next carry */
       _W = _W >> ((mp_word)DIGIT_BIT);
   }
+  
+  /* store final carry */
+  W[ix] = (mp_digit)(_W & MP_MASK);
 
   /* setup dest */
   olduse  = c->used;
@@ -588,36 +590,17 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
-/* 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.
- *
- */
 /* the jist of squaring...
-
-you do like mult except the offset of the tmpx [one that starts closer to zero]
-can't equal the offset of tmpy.  So basically you set up iy like before then you min it with
-(ty-tx) so that it never happens.  You double all those you add in the inner loop
+ * you do like mult except the offset of the tmpx [one that 
+ * starts closer to zero] can't equal the offset of tmpy.  
+ * So basically you set up iy like before then you min it with
+ * (ty-tx) so that it never happens.  You double all those 
+ * you add in the inner loop
 
 After that loop you do the squares and add them in.
-
-Remove W2 and don't memset W
-
 */
 
 int fast_s_mp_sqr (mp_int * a, mp_int * b)
@@ -636,7 +619,7 @@
 
   /* number of output digits to produce */
   W1 = 0;
-  for (ix = 0; ix <= pa; ix++) { 
+  for (ix = 0; ix < pa; ix++) { 
       int      tx, ty, iy;
       mp_word  _W;
       mp_digit *tmpy;
@@ -652,7 +635,7 @@
       tmpx = a->dp + tx;
       tmpy = a->dp + ty;
 
-      /* this is the number of times the loop will iterrate, essentially its 
+      /* this is the number of times the loop will iterrate, essentially
          while (tx++ < a->used && ty-- >= 0) { ... }
        */
       iy = MIN(a->used-tx, ty+1);
@@ -677,7 +660,7 @@
       }
 
       /* store it */
-      W[ix] = _W;
+      W[ix] = (mp_digit)(_W & MP_MASK);
 
       /* make next carry */
       W1 = _W >> ((mp_word)DIGIT_BIT);
@@ -721,7 +704,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes a = 2**b 
@@ -769,7 +752,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* b = |a| 
@@ -812,7 +795,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* high level addition (handles signs) */
@@ -865,7 +848,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* single digit addition */
@@ -974,7 +957,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* d = a + b (mod c) */
@@ -1015,7 +998,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* AND two ints together */
@@ -1072,7 +1055,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* trim unused digits 
@@ -1116,7 +1099,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* clear one (frees)  */
@@ -1160,7 +1143,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 #include <stdarg.h>
 
@@ -1194,7 +1177,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* compare two ints (signed)*/
@@ -1237,7 +1220,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* compare a digit */
@@ -1281,7 +1264,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* compare maginitude of two ints (unsigned) */
@@ -1336,7 +1319,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 static const int lnz[16] = { 
@@ -1389,7 +1372,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* copy, b = a */
@@ -1457,7 +1440,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* returns the number of bits in an int */
@@ -1502,7 +1485,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 #ifdef BN_MP_DIV_SMALL
@@ -1539,23 +1522,23 @@
 
   mp_set(&tq, 1);
   n = mp_count_bits(a) - mp_count_bits(b);
-  if (((res = mp_copy(a, &ta)) != MP_OKAY) ||
-      ((res = mp_copy(b, &tb)) != MP_OKAY) || 
+  if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
+      ((res = mp_abs(b, &tb)) != MP_OKAY) || 
       ((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
       ((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) {
-      goto __ERR;
+      goto LBL_ERR;
   }
 
   while (n-- >= 0) {
      if (mp_cmp(&tb, &ta) != MP_GT) {
         if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) ||
             ((res = mp_add(&q, &tq, &q)) != MP_OKAY)) {
-           goto __ERR;
+           goto LBL_ERR;
         }
      }
      if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) ||
          ((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) {
-           goto __ERR;
+           goto LBL_ERR;
      }
   }
 
@@ -1564,13 +1547,13 @@
   n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG);
   if (c != NULL) {
      mp_exch(c, &q);
-     c->sign  = n2;
+     c->sign  = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
   }
   if (d != NULL) {
      mp_exch(d, &ta);
-     d->sign = n;
+     d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n;
   }
-__ERR:
+LBL_ERR:
    mp_clear_multi(&ta, &tb, &tq, &q, NULL);
    return res;
 }
@@ -1619,19 +1602,19 @@
   q.used = a->used + 2;
 
   if ((res = mp_init (&t1)) != MP_OKAY) {
-    goto __Q;
+    goto LBL_Q;
   }
 
   if ((res = mp_init (&t2)) != MP_OKAY) {
-    goto __T1;
+    goto LBL_T1;
   }
 
   if ((res = mp_init_copy (&x, a)) != MP_OKAY) {
-    goto __T2;
+    goto LBL_T2;
   }
 
   if ((res = mp_init_copy (&y, b)) != MP_OKAY) {
-    goto __X;
+    goto LBL_X;
   }
 
   /* fix the sign */
@@ -1643,10 +1626,10 @@
   if (norm < (int)(DIGIT_BIT-1)) {
      norm = (DIGIT_BIT-1) - norm;
      if ((res = mp_mul_2d (&x, norm, &x)) != MP_OKAY) {
-       goto __Y;
+       goto LBL_Y;
      }
      if ((res = mp_mul_2d (&y, norm, &y)) != MP_OKAY) {
-       goto __Y;
+       goto LBL_Y;
      }
   } else {
      norm = 0;
@@ -1658,13 +1641,13 @@
 
   /* 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;
+    goto LBL_Y;
   }
 
   while (mp_cmp (&x, &y) != MP_LT) {
     ++(q.dp[n - t]);
     if ((res = mp_sub (&x, &y, &x)) != MP_OKAY) {
-      goto __Y;
+      goto LBL_Y;
     }
   }
 
@@ -1706,7 +1689,7 @@
       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;
+        goto LBL_Y;
       }
 
       /* find right hand */
@@ -1718,27 +1701,27 @@
 
     /* 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;
+      goto LBL_Y;
     }
 
     if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
-      goto __Y;
+      goto LBL_Y;
     }
 
     if ((res = mp_sub (&x, &t1, &x)) != MP_OKAY) {
-      goto __Y;
+      goto LBL_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;
+        goto LBL_Y;
       }
       if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
-        goto __Y;
+        goto LBL_Y;
       }
       if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
-        goto __Y;
+        goto LBL_Y;
       }
 
       q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
@@ -1765,11 +1748,11 @@
 
   res = MP_OKAY;
 
-__Y:mp_clear (&y);
-__X:mp_clear (&x);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
-__Q:mp_clear (&q);
+LBL_Y:mp_clear (&y);
+LBL_X:mp_clear (&x);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
+LBL_Q:mp_clear (&q);
   return res;
 }
 
@@ -1794,7 +1777,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* b = a/2 */
@@ -1862,7 +1845,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* shift right by a certain bit count (store quotient in c, optional remainder in d) */
@@ -1959,7 +1942,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* divide by three (based on routine from MPI and the GMP manual) */
@@ -2038,7 +2021,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 static int s_is_power_of_two(mp_digit b, int *p)
@@ -2148,7 +2131,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* determines if a number is a valid DR modulus */
@@ -2191,7 +2174,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
@@ -2199,7 +2182,7 @@
  * Based on algorithm from the paper
  *
  * "Generating Efficient Primes for Discrete Log Cryptosystems"
- *                 Chae Hoon Lim, Pil Loong Lee,
+ *                 Chae Hoon Lim, Pil Joong Lee,
  *          POSTECH Information Research Laboratories
  *
  * The modulus must be of a special format [see manual]
@@ -2285,7 +2268,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* determines the setup value */
@@ -2317,7 +2300,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* swap the elements of two integers, for cases where you can't simply swap the 
@@ -2351,7 +2334,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* calculate c = a**b  using a square-multiply algorithm */
@@ -2408,7 +2391,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 
@@ -2457,25 +2440,33 @@
      return err;
 #else 
      /* no invmod */
-     return MP_VAL
+     return MP_VAL;
 #endif
   }
 
+/* modified diminished radix reduction */
+#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C)
+  if (mp_reduce_is_2k_l(P) == MP_YES) {
+     return s_mp_exptmod(G, X, P, Y, 1);
+  }
+#endif
+
 #ifdef BN_MP_DR_IS_MODULUS_C
   /* is it a DR modulus? */
   dr = mp_dr_is_modulus(P);
 #else
+  /* default to no */
   dr = 0;
 #endif
 
 #ifdef BN_MP_REDUCE_IS_2K_C
-  /* if not, is it a uDR modulus? */
+  /* if not, is it a unrestricted DR modulus? */
   if (dr == 0) {
      dr = mp_reduce_is_2k(P) << 1;
   }
 #endif
     
-  /* if the modulus is odd or dr != 0 use the fast method */
+  /* if the modulus is odd or dr != 0 use the montgomery method */
 #ifdef BN_MP_EXPTMOD_FAST_C
   if (mp_isodd (P) == 1 || dr !=  0) {
     return mp_exptmod_fast (G, X, P, Y, dr);
@@ -2483,7 +2474,7 @@
 #endif
 #ifdef BN_S_MP_EXPTMOD_C
     /* otherwise use the generic Barrett reduction technique */
-    return s_mp_exptmod (G, X, P, Y);
+    return s_mp_exptmod (G, X, P, Y, 0);
 #else
     /* no exptmod for evens */
     return MP_VAL;
@@ -2512,7 +2503,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
@@ -2529,8 +2520,7 @@
    #define TAB_SIZE 256
 #endif
 
-int
-mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
+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;
@@ -2588,11 +2578,11 @@
 #ifdef BN_MP_MONTGOMERY_SETUP_C     
      /* now setup montgomery  */
      if ((err = mp_montgomery_setup (P, &mp)) != MP_OKAY) {
-        goto __M;
+        goto LBL_M;
      }
 #else
      err = MP_VAL;
-     goto __M;
+     goto LBL_M;
 #endif
 
      /* automatically pick the comba one if available (saves quite a few calls/ifs) */
@@ -2608,7 +2598,7 @@
         redux = mp_montgomery_reduce;
 #else
         err = MP_VAL;
-        goto __M;
+        goto LBL_M;
 #endif
      }
   } else if (redmode == 1) {
@@ -2618,24 +2608,24 @@
      redux = mp_dr_reduce;
 #else
      err = MP_VAL;
-     goto __M;
+     goto LBL_M;
 #endif
   } else {
 #if defined(BN_MP_REDUCE_2K_SETUP_C) && defined(BN_MP_REDUCE_2K_C)
      /* setup DR reduction for moduli of the form 2**k - b */
      if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY) {
-        goto __M;
+        goto LBL_M;
      }
      redux = mp_reduce_2k;
 #else
      err = MP_VAL;
-     goto __M;
+     goto LBL_M;
 #endif
   }
 
   /* setup result */
   if ((err = mp_init (&res)) != MP_OKAY) {
-    goto __M;
+    goto LBL_M;
   }
 
   /* create M table
@@ -2649,45 +2639,45 @@
 #ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
      /* now we need R mod m */
      if ((err = mp_montgomery_calc_normalization (&res, P)) != MP_OKAY) {
-       goto __RES;
+       goto LBL_RES;
      }
 #else 
      err = MP_VAL;
-     goto __RES;
+     goto LBL_RES;
 #endif
 
      /* now set M[1] to G * R mod m */
      if ((err = mp_mulmod (G, &res, P, &M[1])) != MP_OKAY) {
-       goto __RES;
+       goto LBL_RES;
      }
   } else {
      mp_set(&res, 1);
      if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
-        goto __RES;
+        goto LBL_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;
+    goto LBL_RES;
   }
 
   for (x = 0; x < (winsize - 1); x++) {
     if ((err = mp_sqr (&M[1 << (winsize - 1)], &M[1 << (winsize - 1)])) != MP_OKAY) {
-      goto __RES;
+      goto LBL_RES;
     }
     if ((err = redux (&M[1 << (winsize - 1)], P, mp)) != MP_OKAY) {
-      goto __RES;
+      goto LBL_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;
+      goto LBL_RES;
     }
     if ((err = redux (&M[x], P, mp)) != MP_OKAY) {
-      goto __RES;
+      goto LBL_RES;
     }
   }
 
@@ -2727,10 +2717,10 @@
     /* 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;
+        goto LBL_RES;
       }
       if ((err = redux (&res, P, mp)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
       continue;
     }
@@ -2744,19 +2734,19 @@
       /* square first */
       for (x = 0; x < winsize; x++) {
         if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-          goto __RES;
+          goto LBL_RES;
         }
         if ((err = redux (&res, P, mp)) != MP_OKAY) {
-          goto __RES;
+          goto LBL_RES;
         }
       }
 
       /* then multiply */
       if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
       if ((err = redux (&res, P, mp)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
 
       /* empty window and reset */
@@ -2771,10 +2761,10 @@
     /* square then multiply if the bit is set */
     for (x = 0; x < bitcpy; x++) {
       if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
       if ((err = redux (&res, P, mp)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
 
       /* get next bit of the window */
@@ -2782,10 +2772,10 @@
       if ((bitbuf & (1 << winsize)) != 0) {
         /* then multiply */
         if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
-          goto __RES;
+          goto LBL_RES;
         }
         if ((err = redux (&res, P, mp)) != MP_OKAY) {
-          goto __RES;
+          goto LBL_RES;
         }
       }
     }
@@ -2799,15 +2789,15 @@
       * of R.
       */
      if ((err = redux(&res, P, mp)) != MP_OKAY) {
-       goto __RES;
+       goto LBL_RES;
      }
   }
 
   /* swap res with Y */
   mp_exch (&res, Y);
   err = MP_OKAY;
-__RES:mp_clear (&res);
-__M:
+LBL_RES:mp_clear (&res);
+LBL_M:
   mp_clear(&M[1]);
   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
     mp_clear (&M[x]);
@@ -2834,7 +2824,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Extended euclidean algorithm of (a, b) produces 
@@ -2881,6 +2871,13 @@
        if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto _ERR; }
    }
 
+   /* make sure U3 >= 0 */
+   if (u3.sign == MP_NEG) {
+      mp_neg(&u1, &u1);
+      mp_neg(&u2, &u2);
+      mp_neg(&u3, &u3);
+   }
+
    /* copy result out */
    if (U1 != NULL) { mp_exch(U1, &u1); }
    if (U2 != NULL) { mp_exch(U2, &u2); }
@@ -2909,7 +2906,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* read a bigint from a file stream in ASCII */
@@ -2976,7 +2973,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 int mp_fwrite(mp_int *a, int radix, FILE *stream)
@@ -3028,7 +3025,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Greatest Common Divisor using the binary method */
@@ -3059,7 +3056,7 @@
   }
 
   if ((res = mp_init_copy (&v, b)) != MP_OKAY) {
-    goto __U;
+    goto LBL_U;
   }
 
   /* must be positive for the remainder of the algorithm */
@@ -3073,24 +3070,24 @@
   if (k > 0) {
      /* divide the power of two out */
      if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
-        goto __V;
+        goto LBL_V;
      }
 
      if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
-        goto __V;
+        goto LBL_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;
+        goto LBL_V;
      }
   }
 
   if (v_lsb != k) {
      if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
-        goto __V;
+        goto LBL_V;
      }
   }
 
@@ -3103,23 +3100,23 @@
      
      /* subtract smallest from largest */
      if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
-        goto __V;
+        goto LBL_V;
      }
      
      /* Divide out all factors of two */
      if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
-        goto __V;
+        goto LBL_V;
      } 
   } 
 
   /* multiply by 2**k which we divided out at the beginning */
   if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) {
-     goto __V;
+     goto LBL_V;
   }
   c->sign = MP_ZPOS;
   res = MP_OKAY;
-__V:mp_clear (&u);
-__U:mp_clear (&v);
+LBL_V:mp_clear (&u);
+LBL_U:mp_clear (&v);
   return res;
 }
 #endif
@@ -3141,7 +3138,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* get the lower 32-bits of an mp_int */
@@ -3186,7 +3183,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* grow as required */
@@ -3243,7 +3240,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* init a new mp_int */
@@ -3289,7 +3286,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* creates "a" then copies b into it */
@@ -3321,7 +3318,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 #include <stdarg.h>
 
@@ -3380,7 +3377,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* initialize and set a digit */
@@ -3412,7 +3409,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* initialize and set a digit */
@@ -3443,7 +3440,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* init an mp_init for a given size */
@@ -3491,7 +3488,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* hac 14.61, pp608 */
@@ -3534,7 +3531,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* hac 14.61, pp608 */
@@ -3555,25 +3552,25 @@
   }
 
   /* x = a, y = b */
-  if ((res = mp_copy (a, &x)) != MP_OKAY) {
-    goto __ERR;
+  if ((res = mp_mod(a, b, &x)) != MP_OKAY) {
+      goto LBL_ERR;
   }
   if ((res = mp_copy (b, &y)) != MP_OKAY) {
-    goto __ERR;
+    goto LBL_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;
+    goto LBL_ERR;
   }
 
   /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
   if ((res = mp_copy (&x, &u)) != MP_OKAY) {
-    goto __ERR;
+    goto LBL_ERR;
   }
   if ((res = mp_copy (&y, &v)) != MP_OKAY) {
-    goto __ERR;
+    goto LBL_ERR;
   }
   mp_set (&A, 1);
   mp_set (&D, 1);
@@ -3583,24 +3580,24 @@
   while (mp_iseven (&u) == 1) {
     /* 4.1 u = u/2 */
     if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_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;
+         goto LBL_ERR;
       }
       if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
-         goto __ERR;
+         goto LBL_ERR;
       }
     }
     /* A = A/2, B = B/2 */
     if ((res = mp_div_2 (&A, &A)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
     if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   }
 
@@ -3608,24 +3605,24 @@
   while (mp_iseven (&v) == 1) {
     /* 5.1 v = v/2 */
     if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_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;
+         goto LBL_ERR;
       }
       if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
-         goto __ERR;
+         goto LBL_ERR;
       }
     }
     /* C = C/2, D = D/2 */
     if ((res = mp_div_2 (&C, &C)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
     if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   }
 
@@ -3633,28 +3630,28 @@
   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;
+      goto LBL_ERR;
     }
 
     if ((res = mp_sub (&A, &C, &A)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
 
     if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   } else {
     /* v - v - u, C = C - A, D = D - B */
     if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
 
     if ((res = mp_sub (&C, &A, &C)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
 
     if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
-      goto __ERR;
+      goto LBL_ERR;
     }
   }
 
@@ -3667,27 +3664,27 @@
   /* if v != 1 then there is no inverse */
   if (mp_cmp_d (&v, 1) != MP_EQ) {
     res = MP_VAL;
-    goto __ERR;
+    goto LBL_ERR;
   }
 
   /* if its too low */
   while (mp_cmp_d(&C, 0) == MP_LT) {
       if ((res = mp_add(&C, b, &C)) != MP_OKAY) {
-         goto __ERR;
+         goto LBL_ERR;
       }
   }
   
   /* too big */
   while (mp_cmp_mag(&C, b) != MP_LT) {
       if ((res = mp_sub(&C, b, &C)) != MP_OKAY) {
-         goto __ERR;
+         goto LBL_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);
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
   return res;
 }
 #endif
@@ -3709,7 +3706,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Check if remainders are possible squares - fast exclude non-squares */
@@ -3818,7 +3815,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes the jacobi c = (a | n) (or Legendre if n is prime)
@@ -3856,13 +3853,13 @@
   }
 
   if ((res = mp_init (&p1)) != MP_OKAY) {
-    goto __A1;
+    goto LBL_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;
+     goto LBL_P1;
   }
 
   /* step 4.  if e is even set s=1 */
@@ -3890,18 +3887,18 @@
   } else {
     /* n1 = n mod a1 */
     if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) {
-      goto __P1;
+      goto LBL_P1;
     }
     if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) {
-      goto __P1;
+      goto LBL_P1;
     }
     *c = s * r;
   }
 
   /* done */
   res = MP_OKAY;
-__P1:mp_clear (&p1);
-__A1:mp_clear (&a1);
+LBL_P1:mp_clear (&p1);
+LBL_A1:mp_clear (&a1);
   return res;
 }
 #endif
@@ -3923,7 +3920,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* c = |a| * |b| using Karatsuba Multiplication using 
@@ -4090,7 +4087,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Karatsuba squaring, computes b = a*a using three 
@@ -4211,7 +4208,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes least common multiple as |a*b|/(a, b) */
@@ -4227,20 +4224,20 @@
 
   /* t1 = get the GCD of the two inputs */
   if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) {
-    goto __T;
+    goto LBL_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;
+        goto LBL_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;
+        goto LBL_T;
      }
      res = mp_mul(a, &t2, c);
   }
@@ -4248,7 +4245,7 @@
   /* fix the sign to positive */
   c->sign = MP_ZPOS;
 
-__T:
+LBL_T:
   mp_clear_multi (&t1, &t2, NULL);
   return res;
 }
@@ -4271,7 +4268,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* shift left a certain amount of digits */
@@ -4338,7 +4335,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* c = a mod b, 0 <= c < b */
@@ -4386,7 +4383,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* calc a value mod 2**b */
@@ -4402,7 +4399,7 @@
   }
 
   /* if the modulus is larger than the value than return */
-  if (b > (int) (a->used * DIGIT_BIT)) {
+  if (b >= (int) (a->used * DIGIT_BIT)) {
     res = mp_copy (a, c);
     return res;
   }
@@ -4441,7 +4438,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 int
@@ -4468,7 +4465,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /*
@@ -4484,7 +4481,6 @@
   /* how many bits of last digit does b use */
   bits = mp_count_bits (b) % DIGIT_BIT;
 
-
   if (b->used > 1) {
      if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) {
         return res;
@@ -4528,7 +4524,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes xR**-1 == x (mod N) via Montgomery Reduction */
@@ -4646,7 +4642,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* setups the montgomery reduction stuff */
@@ -4705,7 +4701,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* high level multiplication (handles sign) */
@@ -4771,7 +4767,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* b = a*2 */
@@ -4853,7 +4849,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* shift left by a certain bit count */
@@ -4938,7 +4934,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* multiply by a digit */
@@ -4983,8 +4979,9 @@
     u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
   }
 
-  /* store final carry [if any] */
+  /* store final carry [if any] and increment ix offset  */
   *tmpc++ = u;
+  ++ix;
 
   /* now zero digits above the top */
   while (ix++ < olduse) {
@@ -5016,7 +5013,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* d = a * b (mod c) */
@@ -5057,7 +5054,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* find the n'th root of an integer 
@@ -5085,11 +5082,11 @@
   }
 
   if ((res = mp_init (&t2)) != MP_OKAY) {
-    goto __T1;
+    goto LBL_T1;
   }
 
   if ((res = mp_init (&t3)) != MP_OKAY) {
-    goto __T2;
+    goto LBL_T2;
   }
 
   /* if a is negative fudge the sign but keep track */
@@ -5102,52 +5099,52 @@
   do {
     /* t1 = t2 */
     if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
-      goto __T3;
+      goto LBL_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;
+      goto LBL_T3;
     }
 
     /* numerator */
     /* t2 = t1**b */
     if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {    
-      goto __T3;
+      goto LBL_T3;
     }
 
     /* t2 = t1**b - a */
     if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {  
-      goto __T3;
+      goto LBL_T3;
     }
 
     /* denominator */
     /* t3 = t1**(b-1) * b  */
     if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {    
-      goto __T3;
+      goto LBL_T3;
     }
 
     /* t3 = (t1**b - a)/(b * t1**(b-1)) */
     if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {  
-      goto __T3;
+      goto LBL_T3;
     }
 
     if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
-      goto __T3;
+      goto LBL_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;
+      goto LBL_T3;
     }
 
     if (mp_cmp (&t2, a) == MP_GT) {
       if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
-         goto __T3;
+         goto LBL_T3;
       }
     } else {
       break;
@@ -5165,9 +5162,9 @@
 
   res = MP_OKAY;
 
-__T3:mp_clear (&t3);
-__T2:mp_clear (&t2);
-__T1:mp_clear (&t1);
+LBL_T3:mp_clear (&t3);
+LBL_T2:mp_clear (&t2);
+LBL_T1:mp_clear (&t1);
   return res;
 }
 #endif
@@ -5189,19 +5186,25 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* b = -a */
 int mp_neg (mp_int * a, mp_int * b)
 {
   int     res;
-  if ((res = mp_copy (a, b)) != MP_OKAY) {
-    return res;
+  if (a != b) {
+     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;
+  } else {
+     b->sign = MP_ZPOS;
   }
+
   return MP_OKAY;
 }
 #endif
@@ -5223,7 +5226,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* OR two ints together */
@@ -5273,7 +5276,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* performs one Fermat test.
@@ -5304,7 +5307,7 @@
 
   /* compute t = b**a mod a */
   if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
-    goto __T;
+    goto LBL_T;
   }
 
   /* is it equal to b? */
@@ -5313,7 +5316,7 @@
   }
 
   err = MP_OKAY;
-__T:mp_clear (&t);
+LBL_T:mp_clear (&t);
   return err;
 }
 #endif
@@ -5335,7 +5338,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* determines if an integers is divisible by one 
@@ -5352,8 +5355,8 @@
   *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) {
+    /* what is a mod LBL_prime_tab[ix] */
+    if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
       return err;
     }
 
@@ -5385,7 +5388,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* performs a variable number of rounds of Miller-Rabin
@@ -5410,7 +5413,7 @@
 
   /* 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) {
+      if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
          *result = 1;
          return MP_OKAY;
       }
@@ -5433,20 +5436,20 @@
 
   for (ix = 0; ix < t; ix++) {
     /* set the prime */
-    mp_set (&b, __prime_tab[ix]);
+    mp_set (&b, ltm_prime_tab[ix]);
 
     if ((err = mp_prime_miller_rabin (a, &b, &res)) != MP_OKAY) {
-      goto __B;
+      goto LBL_B;
     }
 
     if (res == MP_NO) {
-      goto __B;
+      goto LBL_B;
     }
   }
 
   /* passed the test */
   *result = MP_YES;
-__B:mp_clear (&b);
+LBL_B:mp_clear (&b);
   return err;
 }
 #endif
@@ -5468,7 +5471,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Miller-Rabin test of "a" to the base of "b" as described in 
@@ -5496,12 +5499,12 @@
     return err;
   }
   if ((err = mp_sub_d (&n1, 1, &n1)) != MP_OKAY) {
-    goto __N1;
+    goto LBL_N1;
   }
 
   /* set 2**s * r = n1 */
   if ((err = mp_init_copy (&r, &n1)) != MP_OKAY) {
-    goto __N1;
+    goto LBL_N1;
   }
 
   /* count the number of least significant bits
@@ -5511,15 +5514,15 @@
 
   /* now divide n - 1 by 2**s */
   if ((err = mp_div_2d (&r, s, &r, NULL)) != MP_OKAY) {
-    goto __R;
+    goto LBL_R;
   }
 
   /* compute y = b**r mod a */
   if ((err = mp_init (&y)) != MP_OKAY) {
-    goto __R;
+    goto LBL_R;
   }
   if ((err = mp_exptmod (b, &r, a, &y)) != MP_OKAY) {
-    goto __Y;
+    goto LBL_Y;
   }
 
   /* if y != 1 and y != n1 do */
@@ -5528,12 +5531,12 @@
     /* 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;
+         goto LBL_Y;
       }
 
       /* if y == 1 then composite */
       if (mp_cmp_d (&y, 1) == MP_EQ) {
-         goto __Y;
+         goto LBL_Y;
       }
 
       ++j;
@@ -5541,15 +5544,15 @@
 
     /* if y != n1 then composite */
     if (mp_cmp (&y, &n1) != MP_EQ) {
-      goto __Y;
+      goto LBL_Y;
     }
   }
 
   /* probably prime now */
   *result = MP_YES;
-__Y:mp_clear (&y);
-__R:mp_clear (&r);
-__N1:mp_clear (&n1);
+LBL_Y:mp_clear (&y);
+LBL_R:mp_clear (&r);
+LBL_N1:mp_clear (&n1);
   return err;
 }
 #endif
@@ -5571,7 +5574,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* finds the next prime after the number "a" using "t" trials
@@ -5594,10 +5597,10 @@
    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) {
+   if (mp_cmp_d(a, ltm_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 (mp_cmp_d(a, ltm_prime_tab[x]) != MP_LT) {
              if (bbs_style == 1) {
                 /* ok we found a prime smaller or
                  * equal [so the next is larger]
@@ -5605,17 +5608,17 @@
                  * however, the prime must be
                  * congruent to 3 mod 4
                  */
-                if ((__prime_tab[x + 1] & 3) != 3) {
+                if ((ltm_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]);
+                       if ((ltm_prime_tab[y] & 3) == 3) {
+                          mp_set(a, ltm_prime_tab[y]);
                           return MP_OKAY;
                        }
                    }
                 }
              } else {
-                mp_set(a, __prime_tab[x + 1]);
+                mp_set(a, ltm_prime_tab[x + 1]);
                 return MP_OKAY;
              }
           }
@@ -5653,7 +5656,7 @@
 
    /* generate the restable */
    for (x = 1; x < PRIME_SIZE; x++) {
-      if ((err = mp_mod_d(a, __prime_tab[x], res_tab + x)) != MP_OKAY) {
+      if ((err = mp_mod_d(a, ltm_prime_tab[x], res_tab + x)) != MP_OKAY) {
          return err;
       }
    }
@@ -5679,8 +5682,8 @@
              res_tab[x] += kstep;
 
              /* subtract the modulus [instead of using division] */
-             if (res_tab[x] >= __prime_tab[x]) {
-                res_tab[x]  -= __prime_tab[x];
+             if (res_tab[x] >= ltm_prime_tab[x]) {
+                res_tab[x]  -= ltm_prime_tab[x];
              }
 
              /* set flag if zero */
@@ -5692,7 +5695,7 @@
 
       /* add the step */
       if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
-         goto __ERR;
+         goto LBL_ERR;
       }
 
       /* if didn't pass sieve and step == MAX then skip test */
@@ -5702,9 +5705,9 @@
 
       /* is this prime? */
       for (x = 0; x < t; x++) {
-          mp_set(&b, __prime_tab[t]);
+          mp_set(&b, ltm_prime_tab[t]);
           if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
-             goto __ERR;
+             goto LBL_ERR;
           }
           if (res == MP_NO) {
              break;
@@ -5717,7 +5720,7 @@
    }
 
    err = MP_OKAY;
-__ERR:
+LBL_ERR:
    mp_clear(&b);
    return err;
 }
@@ -5741,7 +5744,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 
@@ -5793,7 +5796,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* makes a truly random prime of a given size (bits),
@@ -5828,7 +5831,7 @@
    }
 
    /* calc the byte size */
-   bsize = (size>>3)+(size&7?1:0);
+   bsize = (size>>3) + ((size&7)?1:0);
 
    /* we need a buffer of bsize bytes */
    tmp = OPT_CAST(unsigned char) XMALLOC(bsize);
@@ -5837,19 +5840,17 @@
    }
 
    /* calc the maskAND value for the MSbyte*/
-   maskAND = 0xFF >> (8 - (size & 7));
+   maskAND = ((size&7) == 0) ? 0xFF : (0xFF >> (8 - (size & 7)));
 
    /* calc the maskOR_msb */
    maskOR_msb        = 0;
-   maskOR_msb_offset = (size - 2) >> 3;
+   maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
    if (flags & LTM_PRIME_2MSB_ON) {
-      maskOR_msb     |= 1 << ((size - 2) & 7);
-   } else if (flags & LTM_PRIME_2MSB_OFF) {
-      maskAND        &= ~(1 << ((size - 2) & 7));
-   }
+      maskOR_msb       |= 0x80 >> ((9 - size) & 7);
+   }  
 
    /* get the maskOR_lsb */
-   maskOR_lsb         = 0;
+   maskOR_lsb         = 1;
    if (flags & LTM_PRIME_BBS) {
       maskOR_lsb     |= 3;
    }
@@ -5920,7 +5921,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* returns size of ASCII reprensentation */
@@ -5943,22 +5944,29 @@
     return MP_VAL;
   }
 
-  /* init a copy of the input */
-  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
-    return res;
+  if (mp_iszero(a) == MP_YES) {
+     *size = 2;
+    return MP_OKAY;
   }
 
   /* digs is the digit count */
   digs = 0;
 
   /* if it's negative add one for the sign */
-  if (t.sign == MP_NEG) {
+  if (a->sign == MP_NEG) {
     ++digs;
-    t.sign = MP_ZPOS;
   }
 
+  /* init a copy of the input */
+  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
+    return res;
+  }
+
+  /* force temp to positive */
+  t.sign = MP_ZPOS; 
+
   /* fetch out all of the digits */
-  while (mp_iszero (&t) == 0) {
+  while (mp_iszero (&t) == MP_NO) {
     if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
       mp_clear (&t);
       return res;
@@ -5991,7 +5999,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* chars used in radix conversions */
@@ -6015,7 +6023,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* makes a pseudo-random int of a given size */
@@ -6032,14 +6040,14 @@
 
   /* first place a random non-zero digit */
   do {
-    d = ((mp_digit) abs (rand ()));
+    d = ((mp_digit) abs (rand ())) & MP_MASK;
   } while (d == 0);
 
   if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
     return res;
   }
 
-  while (digits-- > 0) {
+  while (--digits > 0) {
     if ((res = mp_lshd (a, 1)) != MP_OKAY) {
       return res;
     }
@@ -6070,11 +6078,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* read a string [ASCII] in a given radix */
-int mp_read_radix (mp_int * a, char *str, int radix)
+int mp_read_radix (mp_int * a, const char *str, int radix)
 {
   int     y, res, neg;
   char    ch;
@@ -6152,12 +6160,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* 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 mp_read_signed_bin (mp_int * a, const unsigned char *b, int c)
 {
   int     res;
 
@@ -6194,12 +6201,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* 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 mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c)
 {
   int     res;
 
@@ -6250,15 +6256,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* 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)
+int mp_reduce (mp_int * x, mp_int * m, mp_int * mu)
 {
   mp_int  q;
   int     res, um = m->used;
@@ -6278,11 +6283,11 @@
     }
   } else {
 #ifdef BN_S_MP_MUL_HIGH_DIGS_C
-    if ((res = s_mp_mul_high_digs (&q, mu, &q, um - 1)) != MP_OKAY) {
+    if ((res = s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) {
       goto CLEANUP;
     }
 #elif defined(BN_FAST_S_MP_MUL_HIGH_DIGS_C)
-    if ((res = fast_s_mp_mul_high_digs (&q, mu, &q, um - 1)) != MP_OKAY) {
+    if ((res = fast_s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) {
       goto CLEANUP;
     }
 #else 
@@ -6351,12 +6356,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* 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)
+int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d)
 {
    mp_int q;
    int    p, res;
@@ -6398,6 +6402,68 @@
 
 /* End: bn_mp_reduce_2k.c */
 
+/* Start: bn_mp_reduce_2k_l.c */
+#include <ltc_tommath.h>
+#ifdef BN_MP_REDUCE_2K_L_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@gmail.com, http://math.libtomcrypt.org
+ */
+
+/* reduces a modulo n where n is of the form 2**p - d 
+   This differs from reduce_2k since "d" can be larger
+   than a single digit.
+*/
+int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *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;
+   }
+   
+   /* q = q * d */
+   if ((res = mp_mul(&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;
+}
+
+#endif
+
+/* End: bn_mp_reduce_2k_l.c */
+
 /* Start: bn_mp_reduce_2k_setup.c */
 #include <ltc_tommath.h>
 #ifdef BN_MP_REDUCE_2K_SETUP_C
@@ -6413,12 +6479,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* determines the setup value */
-int 
-mp_reduce_2k_setup(mp_int *a, mp_digit *d)
+int mp_reduce_2k_setup(mp_int *a, mp_digit *d)
 {
    int res, p;
    mp_int tmp;
@@ -6446,6 +6511,50 @@
 
 /* End: bn_mp_reduce_2k_setup.c */
 
+/* Start: bn_mp_reduce_2k_setup_l.c */
+#include <ltc_tommath.h>
+#ifdef BN_MP_REDUCE_2K_SETUP_L_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@gmail.com, http://math.libtomcrypt.org
+ */
+
+/* determines the setup value */
+int mp_reduce_2k_setup_l(mp_int *a, mp_int *d)
+{
+   int    res;
+   mp_int tmp;
+   
+   if ((res = mp_init(&tmp)) != MP_OKAY) {
+      return res;
+   }
+   
+   if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) {
+      goto ERR;
+   }
+   
+   if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) {
+      goto ERR;
+   }
+   
+ERR:
+   mp_clear(&tmp);
+   return res;
+}
+#endif
+
+/* End: bn_mp_reduce_2k_setup_l.c */
+
 /* Start: bn_mp_reduce_is_2k.c */
 #include <ltc_tommath.h>
 #ifdef BN_MP_REDUCE_IS_2K_C
@@ -6461,7 +6570,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* determines if mp_reduce_2k can be used */
@@ -6471,9 +6580,9 @@
    mp_digit iz;
    
    if (a->used == 0) {
-      return 0;
+      return MP_NO;
    } else if (a->used == 1) {
-      return 1;
+      return MP_YES;
    } else if (a->used > 1) {
       iy = mp_count_bits(a);
       iz = 1;
@@ -6482,7 +6591,7 @@
       /* 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;
+             return MP_NO;
           }
           iz <<= 1;
           if (iz > (mp_digit)MP_MASK) {
@@ -6491,13 +6600,57 @@
           }
       }
    }
-   return 1;
+   return MP_YES;
 }
 
 #endif
 
 /* End: bn_mp_reduce_is_2k.c */
 
+/* Start: bn_mp_reduce_is_2k_l.c */
+#include <ltc_tommath.h>
+#ifdef BN_MP_REDUCE_IS_2K_L_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@gmail.com, http://math.libtomcrypt.org
+ */
+
+/* determines if reduce_2k_l can be used */
+int mp_reduce_is_2k_l(mp_int *a)
+{
+   int ix, iy;
+   
+   if (a->used == 0) {
+      return MP_NO;
+   } else if (a->used == 1) {
+      return MP_YES;
+   } else if (a->used > 1) {
+      /* if more than half of the digits are -1 we're sold */
+      for (iy = ix = 0; ix < a->used; ix++) {
+          if (a->dp[ix] == MP_MASK) {
+              ++iy;
+          }
+      }
+      return (iy >= (a->used/2)) ? MP_YES : MP_NO;
+      
+   }
+   return MP_NO;
+}
+
+#endif
+
+/* End: bn_mp_reduce_is_2k_l.c */
+
 /* Start: bn_mp_reduce_setup.c */
 #include <ltc_tommath.h>
 #ifdef BN_MP_REDUCE_SETUP_C
@@ -6513,7 +6666,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* pre-calculate the value required for Barrett reduction
@@ -6547,7 +6700,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* shift right a certain amount of digits */
@@ -6619,7 +6772,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* set to a digit */
@@ -6648,7 +6801,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* set a 32-bit const */
@@ -6696,7 +6849,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* shrink a bignum */
@@ -6731,7 +6884,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* get the size for an signed equivalent */
@@ -6758,7 +6911,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* computes b = a*a */
@@ -6816,7 +6969,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* c = a * a (mod b) */
@@ -6857,7 +7010,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* this function is less generic than mp_n_root, simpler and faster */
@@ -6938,7 +7091,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* high level subtraction (handles signs) */
@@ -6997,7 +7150,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* single digit subtraction */
@@ -7086,7 +7239,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* d = a - b (mod c) */
@@ -7128,12 +7281,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* store in signed [big endian] format */
-int
-mp_to_signed_bin (mp_int * a, unsigned char *b)
+int mp_to_signed_bin (mp_int * a, unsigned char *b)
 {
   int     res;
 
@@ -7147,6 +7299,37 @@
 
 /* End: bn_mp_to_signed_bin.c */
 
+/* Start: bn_mp_to_signed_bin_n.c */
+#include <ltc_tommath.h>
+#ifdef BN_MP_TO_SIGNED_BIN_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@gmail.com, http://math.libtomcrypt.org
+ */
+
+/* store in signed [big endian] format */
+int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen)
+{
+   if (*outlen < (unsigned long)mp_signed_bin_size(a)) {
+      return MP_VAL;
+   }
+   *outlen = mp_signed_bin_size(a);
+   return mp_to_signed_bin(a, b);
+}
+#endif
+
+/* End: bn_mp_to_signed_bin_n.c */
+
 /* Start: bn_mp_to_unsigned_bin.c */
 #include <ltc_tommath.h>
 #ifdef BN_MP_TO_UNSIGNED_BIN_C
@@ -7162,12 +7345,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* store in unsigned [big endian] format */
-int
-mp_to_unsigned_bin (mp_int * a, unsigned char *b)
+int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
 {
   int     x, res;
   mp_int  t;
@@ -7196,6 +7378,37 @@
 
 /* End: bn_mp_to_unsigned_bin.c */
 
+/* Start: bn_mp_to_unsigned_bin_n.c */
+#include <ltc_tommath.h>
+#ifdef BN_MP_TO_UNSIGNED_BIN_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@gmail.com, http://math.libtomcrypt.org
+ */
+
+/* store in unsigned [big endian] format */
+int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen)
+{
+   if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) {
+      return MP_VAL;
+   }
+   *outlen = mp_unsigned_bin_size(a);
+   return mp_to_unsigned_bin(a, b);
+}
+#endif
+
+/* End: bn_mp_to_unsigned_bin_n.c */
+
 /* Start: bn_mp_toom_mul.c */
 #include <ltc_tommath.h>
 #ifdef BN_MP_TOOM_MUL_C
@@ -7211,14 +7424,15 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* multiplication using the Toom-Cook 3-way algorithm 
  *
- * Much more complicated than Karatsuba but has a lower asymptotic running time of 
- * O(N**1.464).  This algorithm is only particularly useful on VERY large
- * inputs (we're talking 1000s of digits here...).
+ * Much more complicated than Karatsuba but has a lower 
+ * asymptotic running time of O(N**1.464).  This algorithm is 
+ * only particularly useful on VERY large inputs 
+ * (we're talking 1000s of digits here...).
 */
 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
 {
@@ -7494,7 +7708,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* squaring using Toom-Cook 3-way algorithm */
@@ -7720,7 +7934,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) */
@@ -7795,7 +8009,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* stores a bignum as a ASCII string in a given radix (2..64) 
@@ -7884,12 +8098,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* get the size for an unsigned equivalent */
-int
-mp_unsigned_bin_size (mp_int * a)
+int mp_unsigned_bin_size (mp_int * a)
 {
   int     size = mp_count_bits (a);
   return (size / 8 + ((size & 7) != 0 ? 1 : 0));
@@ -7913,7 +8126,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* XOR two ints together */
@@ -7938,7 +8151,7 @@
   }
 
   for (ix = 0; ix < px; ix++) {
-
+     t.dp[ix] ^= x->dp[ix];
   }
   mp_clamp (&t);
   mp_exch (c, &t);
@@ -7964,16 +8177,22 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* set to zero */
-void
-mp_zero (mp_int * a)
+void mp_zero (mp_int * a)
 {
+  int       n;
+  mp_digit *tmp;
+
   a->sign = MP_ZPOS;
   a->used = 0;
-  memset (a->dp, 0, sizeof (mp_digit) * a->alloc);
+
+  tmp = a->dp;
+  for (n = 0; n < a->alloc; n++) {
+     *tmp++ = 0;
+  }
 }
 #endif
 
@@ -7994,9 +8213,9 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
-const mp_digit __prime_tab[] = {
+const mp_digit ltm_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,
@@ -8055,7 +8274,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* reverse an array, used for radix code */
@@ -8094,7 +8313,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* low level addition, based on HAC pp.594, Algorithm 14.7 */
@@ -8203,7 +8422,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 #ifdef MP_LOW_MEM
@@ -8212,11 +8431,12 @@
    #define TAB_SIZE 256
 #endif
 
-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 redmode)
 {
   mp_int  M[TAB_SIZE], res, mu;
   mp_digit buf;
   int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
+  int (*redux)(mp_int*,mp_int*,mp_int*);
 
   /* find window size */
   x = mp_count_bits (X);
@@ -8261,11 +8481,20 @@
 
   /* create mu, used for Barrett reduction */
   if ((err = mp_init (&mu)) != MP_OKAY) {
-    goto __M;
+    goto LBL_M;
   }
-  if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
-    goto __MU;
-  }
+  
+  if (redmode == 0) {
+     if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
+        goto LBL_MU;
+     }
+     redux = mp_reduce;
+  } else {
+     if ((err = mp_reduce_2k_setup_l (P, &mu)) != MP_OKAY) {
+        goto LBL_MU;
+     }
+     redux = mp_reduce_2k_l;
+  }    
 
   /* create M table
    *
@@ -8276,23 +8505,26 @@
    * computed though accept for M[0] and M[1]
    */
   if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) {
-    goto __MU;
+    goto LBL_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;
+    goto LBL_MU;
   }
 
   for (x = 0; x < (winsize - 1); x++) {
+    /* square it */
     if ((err = mp_sqr (&M[1 << (winsize - 1)], 
                        &M[1 << (winsize - 1)])) != MP_OKAY) {
-      goto __MU;
+      goto LBL_MU;
     }
-    if ((err = mp_reduce (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
-      goto __MU;
+
+    /* reduce modulo P */
+    if ((err = redux (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
+      goto LBL_MU;
     }
   }
 
@@ -8301,16 +8533,16 @@
    */
   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;
+      goto LBL_MU;
     }
-    if ((err = mp_reduce (&M[x], P, &mu)) != MP_OKAY) {
-      goto __MU;
+    if ((err = redux (&M[x], P, &mu)) != MP_OKAY) {
+      goto LBL_MU;
     }
   }
 
   /* setup result */
   if ((err = mp_init (&res)) != MP_OKAY) {
-    goto __MU;
+    goto LBL_MU;
   }
   mp_set (&res, 1);
 
@@ -8350,10 +8582,10 @@
     /* 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;
+        goto LBL_RES;
       }
-      if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-        goto __RES;
+      if ((err = redux (&res, P, &mu)) != MP_OKAY) {
+        goto LBL_RES;
       }
       continue;
     }
@@ -8367,19 +8599,19 @@
       /* square first */
       for (x = 0; x < winsize; x++) {
         if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-          goto __RES;
+          goto LBL_RES;
         }
-        if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-          goto __RES;
+        if ((err = redux (&res, P, &mu)) != MP_OKAY) {
+          goto LBL_RES;
         }
       }
 
       /* then multiply */
       if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
-      if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-        goto __RES;
+      if ((err = redux (&res, P, &mu)) != MP_OKAY) {
+        goto LBL_RES;
       }
 
       /* empty window and reset */
@@ -8394,20 +8626,20 @@
     /* square then multiply if the bit is set */
     for (x = 0; x < bitcpy; x++) {
       if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
-        goto __RES;
+        goto LBL_RES;
       }
-      if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-        goto __RES;
+      if ((err = redux (&res, P, &mu)) != MP_OKAY) {
+        goto LBL_RES;
       }
 
       bitbuf <<= 1;
       if ((bitbuf & (1 << winsize)) != 0) {
         /* then multiply */
         if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
-          goto __RES;
+          goto LBL_RES;
         }
-        if ((err = mp_reduce (&res, P, &mu)) != MP_OKAY) {
-          goto __RES;
+        if ((err = redux (&res, P, &mu)) != MP_OKAY) {
+          goto LBL_RES;
         }
       }
     }
@@ -8415,9 +8647,9 @@
 
   mp_exch (&res, Y);
   err = MP_OKAY;
-__RES:mp_clear (&res);
-__MU:mp_clear (&mu);
-__M:
+LBL_RES:mp_clear (&res);
+LBL_MU:mp_clear (&mu);
+LBL_M:
   mp_clear(&M[1]);
   for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
     mp_clear (&M[x]);
@@ -8443,15 +8675,14 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* 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)
+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;
@@ -8534,7 +8765,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* multiplies |a| * |b| and does not compute the lower digs digits
@@ -8615,12 +8846,11 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
-int
-s_mp_sqr (mp_int * a, mp_int * b)
+int s_mp_sqr (mp_int * a, mp_int * b)
 {
   mp_int  t;
   int     res, ix, iy, pa;
@@ -8700,7 +8930,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
@@ -8789,7 +9019,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.org
  */
 
 /* Known optimal configurations
@@ -8797,11 +9027,12 @@
  CPU                    /Compiler     /MUL CUTOFF/SQR CUTOFF
 -------------------------------------------------------------
  Intel P4 Northwood     /GCC v3.4.1   /        88/       128/LTM 0.32 ;-)
+ AMD Athlon64           /GCC v3.4.4   /        74/       124/LTM 0.34
  
 */
 
-int     KARATSUBA_MUL_CUTOFF = 88,      /* Min. number of digits before Karatsuba multiplication is used. */
-        KARATSUBA_SQR_CUTOFF = 128,     /* Min. number of digits before Karatsuba squaring is used. */
+int     KARATSUBA_MUL_CUTOFF = 74,      /* Min. number of digits before Karatsuba multiplication is used. */
+        KARATSUBA_SQR_CUTOFF = 124,     /* 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; 
diff --git a/mpi_to_ltc_error.c b/src/misc/mpi/mpi_to_ltc_error.c
similarity index 66%
rename from mpi_to_ltc_error.c
rename to src/misc/mpi/mpi_to_ltc_error.c
index 015b1b2..3a4ea17 100644
--- a/mpi_to_ltc_error.c
+++ b/src/misc/mpi/mpi_to_ltc_error.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 "tomcrypt.h"
 
-#include "mycrypt.h"
+/**
+  @file mpi_to_ltc_error.c
+  Convert MPI errors to LTC, Tom St Denis
+*/  
 
 #ifdef MPI
 static const struct {
@@ -20,7 +24,11 @@
    { MP_VAL  ,  CRYPT_INVALID_ARG},
 };
 
-/* convert a MPI error to a LTC error (Possibly the most powerful function ever!  Oh wait... no) */
+/**
+   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;
diff --git a/rand_prime.c b/src/misc/mpi/rand_prime.c
similarity index 86%
rename from rand_prime.c
rename to src/misc/mpi/rand_prime.c
index 4e9cdbd..97ddf73 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.
diff --git a/pkcs_5_1.c b/src/misc/pkcs5/pkcs_5_1.c
similarity index 65%
rename from pkcs_5_1.c
rename to src/misc/pkcs5/pkcs_5_1.c
index a98affa..ec47372 100644
--- a/pkcs_5_1.c
+++ b/src/misc/pkcs5/pkcs_5_1.c
@@ -6,13 +6,26 @@
  * 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>
 
-/* PKCS #5, Algorithm #1 */
+/** 
+   @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,
@@ -23,10 +36,10 @@
    hash_state    *md;
    unsigned char *buf;
 
-   _ARGCHK(password != NULL);
-   _ARGCHK(salt     != NULL);
-   _ARGCHK(out      != NULL);
-   _ARGCHK(outlen   != NULL);
+   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) {
@@ -48,23 +61,23 @@
 
    /* hash initial password + salt */
    if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].process(md, password, password_len)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].process(md, salt, 8)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
    }
 
    while (--iteration_count) {
-      // code goes here.
+      /* code goes here. */
       x = MAXBLOCKSIZE;
       if ((err = hash_memory(hash_idx, buf, hash_descriptor[hash_idx].hashsize, buf, &x)) != CRYPT_OK) {
-         goto __ERR;
+         goto LBL_ERR;
       }
    }
 
@@ -74,8 +87,8 @@
    }
    *outlen = x;
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK 
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK 
    zeromem(buf, MAXBLOCKSIZE);
    zeromem(md, sizeof(hash_state));
 #endif
diff --git a/pkcs_5_2.c b/src/misc/pkcs5/pkcs_5_2.c
similarity index 69%
rename from pkcs_5_2.c
rename to src/misc/pkcs5/pkcs_5_2.c
index a58994f..aac811b 100644
--- a/pkcs_5_2.c
+++ b/src/misc/pkcs5/pkcs_5_2.c
@@ -6,27 +6,43 @@
  * 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>
 
-/* PKCS #5, Algorithm #2 */
+/** 
+   @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;
-   unsigned long stored, left, x, y, blkno;
+   ulong32  blkno;
+   unsigned long stored, left, x, y;
    unsigned char *buf[2];
    hmac_state    *hmac;
 
-   _ARGCHK(password != NULL);
-   _ARGCHK(salt     != NULL);
-   _ARGCHK(out      != NULL);
-   _ARGCHK(outlen   != NULL);
+   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) {
@@ -60,24 +76,24 @@
 
        /* get PRF(P, S||int(blkno)) */
        if ((err = hmac_init(hmac, hash_idx, password, password_len)) != CRYPT_OK) { 
-          goto __ERR;
+          goto LBL_ERR;
        }
        if ((err = hmac_process(hmac, salt, salt_len)) != CRYPT_OK) {
-          goto __ERR;
+          goto LBL_ERR;
        }
        if ((err = hmac_process(hmac, buf[1], 4)) != CRYPT_OK) {
-          goto __ERR;
+          goto LBL_ERR;
        }
        x = MAXBLOCKSIZE;
        if ((err = hmac_done(hmac, buf[0], &x)) != CRYPT_OK) {
-          goto __ERR;
+          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 __ERR;
+              goto LBL_ERR;
            }
            for (y = 0; y < x; y++) {
                buf[1][y] ^= buf[0][y];
@@ -93,8 +109,8 @@
    *outlen = stored;
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(buf[0], MAXBLOCKSIZE*2);
    zeromem(hmac, sizeof(hmac_state));
 #endif
diff --git a/src/misc/zeromem.c b/src/misc/zeromem.c
new file mode 100644
index 0000000..c640bb4
--- /dev/null
+++ b/src/misc/zeromem.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"
+
+/**
+   @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;
+   }
+}
diff --git a/src/modes/cbc/cbc_decrypt.c b/src/modes/cbc/cbc_decrypt.c
new file mode 100644
index 0000000..c79631c
--- /dev/null
+++ b/src/modes/cbc/cbc_decrypt.c
@@ -0,0 +1,91 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/src/modes/cbc/cbc_done.c b/src/modes/cbc/cbc_done.c
new file mode 100644
index 0000000..daa9110
--- /dev/null
+++ b/src/modes/cbc/cbc_done.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
+ */
+#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
diff --git a/src/modes/cbc/cbc_encrypt.c b/src/modes/cbc/cbc_encrypt.c
new file mode 100644
index 0000000..00ca05f
--- /dev/null
+++ b/src/modes/cbc/cbc_encrypt.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 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
diff --git a/src/modes/cbc/cbc_getiv.c b/src/modes/cbc/cbc_getiv.c
new file mode 100644
index 0000000..0f5c3e4
--- /dev/null
+++ b/src/modes/cbc/cbc_getiv.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 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
diff --git a/src/modes/cbc/cbc_setiv.c b/src/modes/cbc/cbc_setiv.c
new file mode 100644
index 0000000..f2e8b31
--- /dev/null
+++ b/src/modes/cbc/cbc_setiv.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 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 
+
diff --git a/src/modes/cbc/cbc_start.c b/src/modes/cbc/cbc_start.c
new file mode 100644
index 0000000..680faab
--- /dev/null
+++ b/src/modes/cbc/cbc_start.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 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
diff --git a/cfb_decrypt.c b/src/modes/cfb/cfb_decrypt.c
similarity index 70%
rename from cfb_decrypt.c
rename to src/modes/cfb/cfb_decrypt.c
index 1e1d3c0..8b78898 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;
diff --git a/src/modes/cfb/cfb_done.c b/src/modes/cfb/cfb_done.c
new file mode 100644
index 0000000..04e775c
--- /dev/null
+++ b/src/modes/cfb/cfb_done.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
+ */
+#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
diff --git a/cfb_encrypt.c b/src/modes/cfb/cfb_encrypt.c
similarity index 70%
rename from cfb_encrypt.c
rename to src/modes/cfb/cfb_encrypt.c
index 8016959..b960368 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;
diff --git a/src/modes/cfb/cfb_getiv.c b/src/modes/cfb/cfb_getiv.c
new file mode 100644
index 0000000..e59c1e4
--- /dev/null
+++ b/src/modes/cfb/cfb_getiv.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 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
diff --git a/cfb_setiv.c b/src/modes/cfb/cfb_setiv.c
similarity index 64%
rename from cfb_setiv.c
rename to src/modes/cfb/cfb_setiv.c
index ddbbe59..e475ad9 100644
--- a/cfb_setiv.c
+++ b/src/modes/cfb/cfb_setiv.c
@@ -6,19 +6,29 @@
  * 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"
 
-#include "mycrypt.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;
    
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(cfb != NULL);
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(cfb != NULL);
 
    if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
        return err;
diff --git a/cfb_start.c b/src/modes/cfb/cfb_start.c
similarity index 61%
rename from cfb_start.c
rename to src/modes/cfb/cfb_start.c
index d471412..7157fc3 100644
--- a/cfb_start.c
+++ b/src/modes/cfb/cfb_start.c
@@ -6,20 +6,36 @@
  * 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_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;
 
-   _ARGCHK(IV != NULL);
-   _ARGCHK(key != NULL);
-   _ARGCHK(cfb != NULL);
+   LTC_ARGCHK(IV != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(cfb != NULL);
 
    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
       return err;
diff --git a/src/modes/ctr/ctr_decrypt.c b/src/modes/ctr/ctr_decrypt.c
new file mode 100644
index 0000000..daa78a8
--- /dev/null
+++ b/src/modes/ctr/ctr_decrypt.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
+ */
+#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
+
diff --git a/src/modes/ctr/ctr_done.c b/src/modes/ctr/ctr_done.c
new file mode 100644
index 0000000..88508ba
--- /dev/null
+++ b/src/modes/ctr/ctr_done.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
+ */
+#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
diff --git a/src/modes/ctr/ctr_encrypt.c b/src/modes/ctr/ctr_encrypt.c
new file mode 100644
index 0000000..a96b806
--- /dev/null
+++ b/src/modes/ctr/ctr_encrypt.c
@@ -0,0 +1,104 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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 == 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;
+      }
+#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
diff --git a/src/modes/ctr/ctr_getiv.c b/src/modes/ctr/ctr_getiv.c
new file mode 100644
index 0000000..3997033
--- /dev/null
+++ b/src/modes/ctr/ctr_getiv.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 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
diff --git a/ctr_setiv.c b/src/modes/ctr/ctr_setiv.c
similarity index 66%
rename from ctr_setiv.c
rename to src/modes/ctr/ctr_setiv.c
index f15ee22..2aab190 100644
--- a/ctr_setiv.c
+++ b/src/modes/ctr/ctr_setiv.c
@@ -6,19 +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
  */
+#include "tomcrypt.h"
 
-#include "mycrypt.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;
    
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(ctr != NULL);
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(ctr != NULL);
 
    /* bad param? */
    if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
diff --git a/ctr_start.c b/src/modes/ctr/ctr_start.c
similarity index 61%
rename from ctr_start.c
rename to src/modes/ctr/ctr_start.c
index f752b65..db8c464 100644
--- a/ctr_start.c
+++ b/src/modes/ctr/ctr_start.c
@@ -6,20 +6,36 @@
  * 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 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 count       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         The CTR state to initialize
+   @return CRYPT_OK if successful
+*/
 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);
+   LTC_ARGCHK(count != NULL);
+   LTC_ARGCHK(key != NULL);
+   LTC_ARGCHK(ctr != NULL);
 
    /* bad param? */
    if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
diff --git a/src/modes/ecb/ecb_decrypt.c b/src/modes/ecb/ecb_decrypt.c
new file mode 100644
index 0000000..8db4d37
--- /dev/null
+++ b/src/modes/ecb/ecb_decrypt.c
@@ -0,0 +1,55 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/src/modes/ecb/ecb_done.c b/src/modes/ecb/ecb_done.c
new file mode 100644
index 0000000..31a42fa
--- /dev/null
+++ b/src/modes/ecb/ecb_done.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
+ */
+#include "tomcrypt.h"
+
+/**
+   @file ecb_done.c
+   ECB implementation, finish chain, Tom St Denis
+*/
+
+#ifdef ECB
+
+/** Terminate the chain
+  @param rcb    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
diff --git a/src/modes/ecb/ecb_encrypt.c b/src/modes/ecb/ecb_encrypt.c
new file mode 100644
index 0000000..dc045e9
--- /dev/null
+++ b/src/modes/ecb/ecb_encrypt.c
@@ -0,0 +1,55 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/src/modes/ecb/ecb_start.c b/src/modes/ecb/ecb_start.c
new file mode 100644
index 0000000..a8b6d45
--- /dev/null
+++ b/src/modes/ecb/ecb_start.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 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
diff --git a/src/modes/ofb/ofb_decrypt.c b/src/modes/ofb/ofb_decrypt.c
new file mode 100644
index 0000000..f725410
--- /dev/null
+++ b/src/modes/ofb/ofb_decrypt.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 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
+
+ 
diff --git a/src/modes/ofb/ofb_done.c b/src/modes/ofb/ofb_done.c
new file mode 100644
index 0000000..ff72ddc
--- /dev/null
+++ b/src/modes/ofb/ofb_done.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
+ */
+#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
diff --git a/ofb_encrypt.c b/src/modes/ofb/ofb_encrypt.c
similarity index 69%
rename from ofb_encrypt.c
rename to src/modes/ofb/ofb_encrypt.c
index d5d06f3..4409ac8 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;
    }
diff --git a/src/modes/ofb/ofb_getiv.c b/src/modes/ofb/ofb_getiv.c
new file mode 100644
index 0000000..eb8ef1e
--- /dev/null
+++ b/src/modes/ofb/ofb_getiv.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 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
diff --git a/ofb_setiv.c b/src/modes/ofb/ofb_setiv.c
similarity index 63%
rename from ofb_setiv.c
rename to src/modes/ofb/ofb_setiv.c
index 6683bc7..96b3f1c 100644
--- a/ofb_setiv.c
+++ b/src/modes/ofb/ofb_setiv.c
@@ -6,19 +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
  */
+#include "tomcrypt.h"
 
-#include "mycrypt.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;
 
-   _ARGCHK(IV  != NULL);
-   _ARGCHK(ofb != NULL);
+   LTC_ARGCHK(IV  != NULL);
+   LTC_ARGCHK(ofb != NULL);
 
    if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
        return err;
diff --git a/src/modes/ofb/ofb_start.c b/src/modes/ofb/ofb_start.c
new file mode 100644
index 0000000..977e6a3
--- /dev/null
+++ b/src/modes/ofb/ofb_start.c
@@ -0,0 +1,56 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
diff --git a/der_decode_integer.c b/src/pk/asn1/der/der_decode_integer.c
similarity index 79%
rename from der_decode_integer.c
rename to src/pk/asn1/der/der_decode_integer.c
index 71ce1f6..b798bd4 100644
--- a/der_decode_integer.c
+++ b/src/pk/asn1/der/der_decode_integer.c
@@ -6,24 +6,37 @@
  * 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"
 
-#include "mycrypt.h"
+/**
+  @file der_decode_integer.c
+  ASN.1 DER, decode an integer, Tom St Denis
+*/
 
 
+#ifdef LTC_DER
+
 /* decodes a DER INTEGER in [in].  You have to tell this function
  * how many bytes are available [inlen].  It will then attempt to 
  * read the INTEGER.  If all goes well it stores the number of bytes
  * read in [inlen] and the number in [num].
  */
+/**
+  Read a mp_int integer
+  @param in       The DER encoded data
+  @param inlen    [in] Size of the in data, [out] number of bytes read
+  @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 tmplen, y, z;
 
-   _ARGCHK(num    != NULL);
-   _ARGCHK(in     != NULL);
-   _ARGCHK(inlen  != NULL);
+   LTC_ARGCHK(num    != NULL);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(inlen  != NULL);
 
    /* save copy of max output size */
    tmplen = *inlen;
@@ -81,3 +94,5 @@
       return mpi_to_ltc_error(mp_read_unsigned_bin(num, (unsigned char *)in, y));
    }
 }
+
+#endif
diff --git a/der_encode_integer.c b/src/pk/asn1/der/der_encode_integer.c
similarity index 79%
rename from der_encode_integer.c
rename to src/pk/asn1/der/der_encode_integer.c
index b742dec..c5c5267 100644
--- a/der_encode_integer.c
+++ b/src/pk/asn1/der/der_encode_integer.c
@@ -6,20 +6,34 @@
  * 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"
 
-#include "mycrypt.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, x, y, z;
    int           err, leading_zero;
 
-   _ARGCHK(num    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
+   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) {
@@ -91,3 +105,5 @@
    *outlen = tmplen; 
    return CRYPT_OK;
 }
+
+#endif
diff --git a/der_get_multi_integer.c b/src/pk/asn1/der/der_get_multi_integer.c
similarity index 65%
rename from der_get_multi_integer.c
rename to src/pk/asn1/der/der_get_multi_integer.c
index d2b83c5..75ae0bc 100644
--- a/der_get_multi_integer.c
+++ b/src/pk/asn1/der/der_get_multi_integer.c
@@ -6,15 +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 <stdarg.h>
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file der_get_multi_integer.c
+  ASN.1 DER, read multiple integers, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
 
 /* will read multiple DER INTEGER encoded mp_ints from src
  * of upto [inlen] bytes.  It will store the number of bytes
  * read back into [inlen].
  */
+/**
+  Read multiple mp_int integers one after another
+  @param src      The DER encoded integers
+  @param inlen    [in] The length of the src buffer, [out] the amount of bytes read
+  @param num      The first mp_int to decode
+  @param ...      A NULL terminated list of mp_ints to decode
+  @return CRYPT_OK if successful
+*/
 int der_get_multi_integer(const unsigned char *src, unsigned long *inlen, 
                   mp_int *num, ...)
 {
@@ -23,8 +39,8 @@
    unsigned long  wrote, len;
    int            err;
 
-   _ARGCHK(src    != NULL);
-   _ARGCHK(inlen  != NULL);
+   LTC_ARGCHK(src    != NULL);
+   LTC_ARGCHK(inlen  != NULL);
 
    /* setup va list */
    next  = num;
@@ -48,3 +64,4 @@
    return CRYPT_OK;
 }
 
+#endif
diff --git a/der_length_integer.c b/src/pk/asn1/der/der_length_integer.c
similarity index 68%
rename from der_length_integer.c
rename to src/pk/asn1/der/der_length_integer.c
index 5291f82..f86738a 100644
--- a/der_length_integer.c
+++ b/src/pk/asn1/der/der_length_integer.c
@@ -6,20 +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
  */
+#include "tomcrypt.h"
 
-#include "mycrypt.h"
+/**
+  @file der_length_integer.c
+  ASN.1 DER, get length of encoding, Tom St Denis
+*/
 
-/* Gets length of DER encoding of num */
 
+#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;
 
-   _ARGCHK(num     != NULL);
-   _ARGCHK(outlen  != NULL);
+   LTC_ARGCHK(num     != NULL);
+   LTC_ARGCHK(outlen  != NULL);
 
    /* we only need a leading zero if the msb of the first byte is one */
    if ((mp_count_bits(num) & 7) == 7 || mp_iszero(num) == MP_YES) {
@@ -52,3 +62,4 @@
    return CRYPT_OK;
 }
 
+#endif
diff --git a/src/pk/asn1/der/der_put_multi_integer.c b/src/pk/asn1/der/der_put_multi_integer.c
new file mode 100644
index 0000000..af2ca88
--- /dev/null
+++ b/src/pk/asn1/der/der_put_multi_integer.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 <stdarg.h>
+#include "tomcrypt.h"
+
+/**
+  @file der_put_multi_integer.c
+  ASN.1 DER, store multiple integers, Tom St Denis
+*/
+
+
+#ifdef LTC_DER
+
+/* store multiple mp_ints in DER INTEGER format to the out, will not
+ * overflow the length you give it [outlen] and store the number of 
+ * bytes used in [outlen] 
+ */
+/**
+  Store multiple mp_int integers one after another
+  @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
+  @param num      The first mp_int to encode
+  @param ...      A NULL terminated list of mp_ints to encode
+  @return CRYPT_OK if successful
+*/
+int der_put_multi_integer(unsigned char *out, unsigned long *outlen, 
+                  mp_int *num, ...)
+{
+   va_list        args;
+   mp_int        *next;
+   unsigned long  wrote, len;
+   int            err;
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* setup va list */
+   next  = num;
+   len   = *outlen;
+   wrote = 0;
+   va_start(args, num);
+
+   while (next != NULL) {
+        if ((err = der_encode_integer(next, out, outlen)) != CRYPT_OK) {
+           va_end(args);
+           return err;
+        }
+        wrote   += *outlen;
+        out     += *outlen;
+        len     -= *outlen;
+        *outlen  = len;
+        next     = va_arg(args, mp_int*);
+   }
+   va_end(args);
+   *outlen = wrote;
+   return CRYPT_OK;
+}
+
+#endif
diff --git a/dh.c b/src/pk/dh/dh.c
similarity index 83%
rename from dh.c
rename to src/pk/dh/dh.c
index f2defb0..c2085a6 100644
--- a/dh.c
+++ b/src/pk/dh/dh.c
@@ -6,13 +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
  */
-#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 */
+/* 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. */
@@ -157,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;
@@ -204,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++) {
@@ -217,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 {
@@ -227,6 +246,14 @@
     }
 }
 
+/**
+  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;
@@ -234,7 +261,7 @@
    mp_int p, g;
    int err;
 
-   _ARGCHK(key  != NULL);
+   LTC_ARGCHK(key  != NULL);
 
    /* good prng? */
    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -289,7 +316,7 @@
 error2:
    mp_clear_multi(&key->x, &key->y, NULL);
 done:
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, keysize);
 #endif
    mp_clear_multi(&p, &g, NULL);
@@ -297,20 +324,32 @@
    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)) {
@@ -344,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) {
@@ -413,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)
 {
@@ -420,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) {
diff --git a/dh_sys.c b/src/pk/dh/dh_sys.c
similarity index 73%
rename from dh_sys.c
rename to src/pk/dh/dh_sys.c
index e0439c3..801f85a 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, *dh_shared, *skey;
-    dh_key pubkey;
+    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,7 +50,7 @@
        return err;
     }
 
-    if (keylen > hash_descriptor[hash].hashsize)  {
+    if (inlen > hash_descriptor[hash].hashsize)  {
         return CRYPT_INVALID_HASH;
     }
 
@@ -55,20 +73,20 @@
 
     /* make a random key and export the public copy */
     if ((err = dh_make_key(prng, wprng, dh_get_size(key), &pubkey)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     pubkeysize = DH_BUF_SIZE;
     if ((err = dh_export(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
        dh_free(&pubkey);
-       goto __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);
        err = CRYPT_BUFFER_OVERFLOW;
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     /* make random key */
@@ -77,13 +95,13 @@
     x = DH_BUF_SIZE;
     if ((err = dh_shared_secret(&pubkey, key, dh_shared, &x)) != CRYPT_OK) {
        dh_free(&pubkey);
-       goto __ERR;
+       goto LBL_ERR;
     }
     dh_free(&pubkey);
 
     z = MAXBLOCKSIZE;
     if ((err = hash_memory(hash, dh_shared, x, skey, &z)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     /* store header */
@@ -103,17 +121,17 @@
     }
 
     /* 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;
 
     err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
     /* clean up */
     zeromem(pub_expt,  DH_BUF_SIZE);
     zeromem(dh_shared, DH_BUF_SIZE);
@@ -126,19 +144,28 @@
     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, *skey;
-   unsigned long x, y, z,hashsize, keysize;
-   int  hash, err;
-   dh_key pubkey;
+   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) {
@@ -161,14 +188,14 @@
    /* check if initial header should fit */
    if (inlen < PACKET_SIZE+1+4+4) {
       err =  CRYPT_INVALID_PACKET;
-      goto __ERR;
+      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)  {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* now lets get the hash name */
@@ -176,7 +203,7 @@
    hash = find_hash_id(in[y++]);
    if (hash == -1) {
       err = CRYPT_INVALID_HASH;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* common values */
@@ -188,14 +215,14 @@
    /* now check if the imported key will fit */
    if (inlen < x) {
       err = CRYPT_INVALID_PACKET;
-      goto __ERR;
+      goto LBL_ERR;
    } else {
       inlen -= x;
    }
    
    y += 4;
    if ((err = dh_import(in+y, x, &pubkey)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    y += x;
 
@@ -203,41 +230,41 @@
    x = DH_BUF_SIZE;
    if ((err = dh_shared_secret(key, &pubkey, shared_secret, &x)) != CRYPT_OK) {
       dh_free(&pubkey);
-      goto __ERR;
+      goto LBL_ERR;
    }
    dh_free(&pubkey);
 
    z = MAXBLOCKSIZE;
    if ((err = hash_memory(hash, shared_secret, x, skey, &z)) != CRYPT_OK) {
-      goto __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) {
       err = CRYPT_INVALID_PACKET;
-      goto __ERR;
+      goto LBL_ERR;
    } else {
       inlen -= keysize;
    }
    
-   if (keysize > *keylen) {
+   if (keysize > *outlen) {
        err = CRYPT_BUFFER_OVERFLOW;
-       goto __ERR;
+       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;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(shared_secret, DH_BUF_SIZE);
    zeromem(skey,          MAXBLOCKSIZE);
 #endif
@@ -266,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;
+   mp_int         a, b, k, m, g, p, p1, tmp;
    unsigned char *buf;
-   unsigned long x, y;
-   int err;
+   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) {
@@ -304,22 +343,18 @@
    if (prng_descriptor[wprng].read(buf, sets[key->idx].size, prng) != 
        (unsigned long)(sets[key->idx].size)) {
       err = CRYPT_ERROR_READPRNG;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* init bignums */
    if ((err = mp_init_multi(&a, &b, &k, &m, &p, &g, &p1, &tmp, NULL)) != MP_OKAY) { 
       err = mpi_to_ltc_error(err);
-      goto __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; }
@@ -339,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 __ERR;
+      goto LBL_ERR;
    }
    
    /* store header  */
@@ -359,7 +394,7 @@
    /* check if size too big */
    if (*outlen < y) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* store header */
@@ -367,10 +402,10 @@
    *outlen = y;
 
    err = CRYPT_OK;
-   goto __ERR;
+   goto LBL_ERR;
 error:
    err = mpi_to_ltc_error(err);
-__ERR:
+LBL_ERR:
    mp_clear_multi(&tmp, &p1, &g, &p, &m, &k, &b, &a, NULL);
 
    XFREE(buf);
@@ -379,19 +414,28 @@
 }
 
 
-/* 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;
diff --git a/dsa_export.c b/src/pk/dsa/dsa_export.c
similarity index 68%
rename from dsa_export.c
rename to src/pk/dsa/dsa_export.c
index 995b1cf..773023e 100644
--- a/dsa_export.c
+++ b/src/pk/dsa/dsa_export.c
@@ -6,20 +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_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 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 + 1 + 2)) {
diff --git a/dsa_free.c b/src/pk/dsa/dsa_free.c
similarity index 60%
rename from dsa_free.c
rename to src/pk/dsa/dsa_free.c
index c451951..862a2dd 100644
--- a/dsa_free.c
+++ b/src/pk/dsa/dsa_free.c
@@ -6,15 +6,24 @@
  * 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_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)
 {
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(key != NULL);
    mp_clear_multi(&key->g, &key->q, &key->p, &key->x, &key->y, NULL);
 }
 
diff --git a/dsa_import.c b/src/pk/dsa/dsa_import.c
similarity index 71%
rename from dsa_import.c
rename to src/pk/dsa/dsa_import.c
index 429876d..6de56e3 100644
--- a/dsa_import.c
+++ b/src/pk/dsa/dsa_import.c
@@ -6,19 +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 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 long x, y;
-   int err;
+   int           err;
 
-   _ARGCHK(in  != NULL);
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(key != NULL);
 
    /* check length */
    if ((1+2+PACKET_SIZE) > inlen) {
diff --git a/dsa_make_key.c b/src/pk/dsa/dsa_make_key.c
similarity index 84%
rename from dsa_make_key.c
rename to src/pk/dsa/dsa_make_key.c
index 09953a2..60683a0 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;
 
-   _ARGCHK(key  != NULL);
+   LTC_ARGCHK(key  != NULL);
 
    /* check prng */
    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -40,11 +54,11 @@
    /* init mp_ints  */
    if ((err = mp_init_multi(&tmp, &tmp2, &key->g, &key->q, &key->p, &key->x, &key->y, NULL)) != MP_OKAY) {
       err = mpi_to_ltc_error(err);
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* make our prime q */
-   if ((err = rand_prime(&key->q, group_size*8, prng, wprng)) != CRYPT_OK)             { goto __ERR; }
+   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; }
@@ -52,7 +66,7 @@
    /* 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 __ERR;
+      goto LBL_ERR;
    }
 
    /* force magnitude */
@@ -67,7 +81,7 @@
    
    /* now loop until p is prime */
    for (;;) {
-       if ((err = is_prime(&key->p, &res)) != CRYPT_OK)                                { goto __ERR; }
+       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 */
@@ -92,7 +106,7 @@
    do {
       if (prng_descriptor[wprng].read(buf, group_size, prng) != (unsigned long)group_size) {
          err = CRYPT_ERROR_READPRNG;
-         goto __ERR;
+         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);
@@ -108,7 +122,7 @@
    if ((err = mp_shrink(&key->x)) != MP_OKAY)                                          { goto error; }
    if ((err = mp_shrink(&key->y)) != MP_OKAY)                                          { goto error; }
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, MDSA_DELTA);
 #endif
 
@@ -116,7 +130,7 @@
    goto done;
 error: 
     err = mpi_to_ltc_error(err);
-__ERR: 
+LBL_ERR: 
     mp_clear_multi(&key->g, &key->q, &key->p, &key->x, &key->y, NULL);
 done: 
     mp_clear_multi(&tmp, &tmp2, NULL);
diff --git a/dsa_sign_hash.c b/src/pk/dsa/dsa_sign_hash.c
similarity index 71%
rename from dsa_sign_hash.c
rename to src/pk/dsa/dsa_sign_hash.c
index c790f24..da92a82 100644
--- a/dsa_sign_hash.c
+++ b/src/pk/dsa/dsa_sign_hash.c
@@ -6,25 +6,41 @@
  * 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_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 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         k, kinv, tmp, r, s;
    unsigned char *buf;
-   int            err, y;
-   unsigned long  len;
+   int            err;
+   unsigned long  out1, out2;
 
-   _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);
 
    if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
       return err;
@@ -52,7 +68,7 @@
       /* gen random k */
       if (prng_descriptor[wprng].read(buf, key->qord, prng) != (unsigned long)key->qord) {
          err = CRYPT_ERROR_READPRNG;
-         goto __ERR;
+         goto LBL_ERR;
       }
 
       /* read k */
@@ -85,44 +101,22 @@
    /* 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))) {
+   if ((err = der_length_integer(&s, &out1)) != CRYPT_OK)                             { goto LBL_ERR; }
+   if ((err = der_length_integer(&r, &out2)) != CRYPT_OK)                             { goto LBL_ERR; }
+   if (*outlen < (out1+out2)) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
-   /* 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 __ERR;
+   /* store ints */
+   err = der_put_multi_integer(out, outlen, &r, &s, NULL);
+   goto LBL_ERR;
 
 error: 
    err = mpi_to_ltc_error(err);
-__ERR: 
+LBL_ERR: 
    mp_clear_multi(&k, &kinv, &r, &s, &tmp, NULL);
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, MDSA_MAX_GROUP);
 #endif
    XFREE(buf);
diff --git a/dsa_verify_hash.c b/src/pk/dsa/dsa_verify_hash.c
similarity index 60%
rename from dsa_verify_hash.c
rename to src/pk/dsa/dsa_verify_hash.c
index 745cd7c..140f0e2 100644
--- a/dsa_verify_hash.c
+++ b/src/pk/dsa/dsa_verify_hash.c
@@ -6,69 +6,62 @@
  * 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_hash.c
+   DSA implementation, verify a signature, Tom St Denis
+*/
+
 
 #ifdef MDSA
 
+/**
+  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 inlen, 
+                    const unsigned char *hash, unsigned long hashlen, 
                     int *stat, dsa_key *key)
 {
-   mp_int r, s, w, v, u1, u2;
-   unsigned long x, y;
-   int err;
+   mp_int        r, s, w, v, u1, u2;
+   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 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) { 
+   if ((err = der_get_multi_integer(sig, &siglen, &r, &s, NULL)) != CRYPT_OK)              { goto done; }
+
+   /* neither r or s can be null */
+   if (mp_iszero(&r) == MP_YES || mp_iszero(&s) == MP_YES) {
       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_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 */
diff --git a/dsa_verify_key.c b/src/pk/dsa/dsa_verify_key.c
similarity index 82%
rename from dsa_verify_key.c
rename to src/pk/dsa/dsa_verify_key.c
index c17bab8..3e84261 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 */
diff --git a/src/pk/ecc/ecc.c b/src/pk/ecc/ecc.c
new file mode 100644
index 0000000..b5e088b
--- /dev/null
+++ b/src/pk/ecc/ecc.c
@@ -0,0 +1,1194 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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 160
+
+/* 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 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, &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_int *mu)
+{
+   mp_int t1, t2;
+   int err;
+
+   if ((err = mp_init_multi(&t1, &t2, NULL)) != CRYPT_OK) {
+      return CRYPT_MEM;
+   }
+
+   /* 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_reduce(&t2, modulus, mu)) != MP_OKAY)             { goto error; }
+   if ((err = mp_mul(&t1, &t2, &t1)) != MP_OKAY)                   { goto error; }
+   if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)             { goto error; }
+
+   /* multiply against x/y */
+   if ((err = mp_mul(&P->x, &t2, &P->x)) != MP_OKAY)               { goto error; }
+   if ((err = mp_reduce(&P->x, modulus, mu)) != MP_OKAY)           { goto error; }
+   if ((err = mp_mul(&P->y, &t1, &P->y)) != MP_OKAY)               { goto error; }
+   if ((err = mp_reduce(&P->y, modulus, mu)) != 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_int *mu)
+{
+   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_reduce(&t1, modulus, mu)) != MP_OKAY)                             { goto error; }
+   /* Z = Y * Z */
+   if ((err = mp_mul(&R->z, &R->y, &R->z)) != MP_OKAY)                             { goto error; }
+   if ((err = mp_reduce(&R->z, modulus, mu)) != 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_reduce(&t2, modulus, mu)) != 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_reduce(&R->y, modulus, mu)) != MP_OKAY)                           { goto error; }
+   /* T2 = Y * Y */
+   if ((err = mp_sqr(&R->y, &t2)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_reduce(&t2, modulus, mu)) != 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_reduce(&R->y, modulus, mu)) != MP_OKAY)                           { goto error; }
+
+   /* X  = T1 * T1 */
+   if ((err = mp_sqr(&t1, &R->x)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_reduce(&R->x, modulus, mu)) != 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_reduce(&R->y, modulus, mu)) != 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_int *mu)
+{
+   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; }
+
+   /* if Z' != 1 */
+   if (mp_cmp_d(&Q->z, 1) != MP_EQ) {
+      /* T1 = Z' * Z' */
+      if ((err = mp_sqr(&Q->z, &t1)) != MP_OKAY)                                { goto error; }
+      if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)                       { goto error; }
+      /* X = X * T1 */
+      if ((err = mp_mul(&t1, &x, &x)) != MP_OKAY)                               { goto error; }
+      if ((err = mp_reduce(&x, modulus, mu)) != MP_OKAY)                        { goto error; }
+      /* T1 = Z' * T1 */
+      if ((err = mp_mul(&Q->z, &t1, &t1)) != MP_OKAY)                           { goto error; }
+      if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)                       { goto error; }
+      /* Y = Y * T1 */
+      if ((err = mp_mul(&t1, &y, &y)) != MP_OKAY)                               { goto error; }
+      if ((err = mp_reduce(&y, modulus, mu)) != MP_OKAY)                        { goto error; }
+   }
+
+   /* T1 = Z*Z */
+   if ((err = mp_sqr(&z, &t1)) != MP_OKAY)                                      { goto error; }
+   if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)                          { goto error; }
+   /* T2 = X' * T1 */
+   if ((err = mp_mul(&Q->x, &t1, &t2)) != MP_OKAY)                              { goto error; }
+   if ((err = mp_reduce(&t2, modulus, mu)) != MP_OKAY)                          { goto error; }
+   /* T1 = Z * T1 */
+   if ((err = mp_mul(&z, &t1, &t1)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)                          { goto error; }
+   /* T1 = Y' * T1 */
+   if ((err = mp_mul(&Q->y, &t1, &t1)) != MP_OKAY)                              { goto error; }
+   if ((err = mp_reduce(&t1, modulus, mu)) != 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_reduce(&z, modulus, mu)) != MP_OKAY)                        { goto error; }
+   }
+   /* Z = Z * X */
+   if ((err = mp_mul(&z, &x, &z)) != MP_OKAY)                                   { goto error; }
+   if ((err = mp_reduce(&z, modulus, mu)) != MP_OKAY)                           { goto error; }
+
+   /* T1 = T1 * X  */
+   if ((err = mp_mul(&t1, &x, &t1)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)                          { goto error; }
+   /* X = X * X */
+   if ((err = mp_sqr(&x, &x)) != MP_OKAY)                                       { goto error; }
+   if ((err = mp_reduce(&x, modulus, mu)) != MP_OKAY)                           { goto error; }
+   /* T2 = T2 * x */
+   if ((err = mp_mul(&t2, &x, &t2)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_reduce(&t2, modulus, mu)) != MP_OKAY)                          { goto error; }
+   /* T1 = T1 * X  */
+   if ((err = mp_mul(&t1, &x, &t1)) != MP_OKAY)                                 { goto error; }
+   if ((err = mp_reduce(&t1, modulus, mu)) != MP_OKAY)                          { goto error; }
+ 
+   /* X = Y*Y */
+   if ((err = mp_sqr(&y, &x)) != MP_OKAY)                                       { goto error; }
+   if ((err = mp_reduce(&x, modulus, mu)) != 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_reduce(&t2, modulus, mu)) != 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)
+{
+   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; }
+   if ((err = mp_copy(&G->z, &tG->z)) != 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; }
+          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, &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; }
+            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, &mu)) != CRYPT_OK)         { goto done; }
+         }
+       }
+     }
+   }
+
+   /* map R back from projective space */
+   err = ecc_map(R, modulus, &mu);
+   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
+
+/**
+  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)) != 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)) != 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);
+}
+
+static int compress_y_point(ecc_point *pt, int idx, int *result)
+{
+   mp_int tmp, tmp2, p;
+   int err;
+
+   LTC_ARGCHK(pt     != NULL);
+   LTC_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;
+
+   LTC_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;
+}
+
+/**
+  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)
+{
+   unsigned long y, z;
+   int cp, err;
+
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_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;
+}
+
+/**
+  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 x, y, s;
+   int err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_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->pubkey.z, &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);
+   }
+
+   /* z is always 1 */
+   mp_set(&key->pubkey.z, 1);
+
+   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
+  @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, y;
+   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 (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;
+}
+
+/**
+  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
+
+
diff --git a/ecc_sys.c b/src/pk/ecc/ecc_sys.c
similarity index 75%
rename from ecc_sys.c
rename to src/pk/ecc/ecc_sys.c
index 5b0ef82..d5576f6 100644
--- a/ecc_sys.c
+++ b/src/pk/ecc/ecc_sys.c
@@ -6,10 +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
  */
-int ecc_encrypt_key(const unsigned char *inkey, unsigned long keylen,
-                          unsigned char *out,  unsigned long *len, 
+
+/**
+  @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)
 {
@@ -18,10 +36,10 @@
     unsigned long  x, y, z, hashsize, pubkeysize;
     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/cipher/hash are not invalid */
     if ((err = prng_is_valid(wprng)) != CRYPT_OK) {
@@ -32,7 +50,7 @@
        return err;
     }
 
-    if (keylen > hash_descriptor[hash].hashsize) {
+    if (inlen > hash_descriptor[hash].hashsize) {
        return CRYPT_INVALID_HASH;
     }
 
@@ -61,14 +79,14 @@
     pubkeysize = ECC_BUF_SIZE;
     if ((err = ecc_export(pub_expt, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
        ecc_free(&pubkey);
-       goto __ERR;
+       goto LBL_ERR;
     }
     
     /* now check if the out buffer is big enough */
-    if (*len < (9 + PACKET_SIZE + pubkeysize + hash_descriptor[hash].hashsize)) {
+    if (*outlen < (9 + PACKET_SIZE + pubkeysize + hash_descriptor[hash].hashsize)) {
        ecc_free(&pubkey);
        err = CRYPT_BUFFER_OVERFLOW;
-       goto __ERR;
+       goto LBL_ERR;
     }
 
     /* make random key */
@@ -76,12 +94,12 @@
     x = ECC_BUF_SIZE;
     if ((err = ecc_shared_secret(&pubkey, key, ecc_shared, &x)) != CRYPT_OK) {
        ecc_free(&pubkey);
-       goto __ERR;
+       goto LBL_ERR;
     }
     ecc_free(&pubkey);
     z = MAXBLOCKSIZE;
     if ((err = hash_memory(hash, ecc_shared, x, skey, &z)) != CRYPT_OK) {
-       goto __ERR;
+       goto LBL_ERR;
     }
     
     /* store header */
@@ -101,18 +119,18 @@
         out[y] = pub_expt[x];
     }
 
-    STORE32L(keylen, out+y);
+    STORE32L(inlen, out+y);
     y += 4;
 
     /* Encrypt/Store the encrypted key */
-    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;
 
     err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
     /* clean up */
     zeromem(pub_expt,   ECC_BUF_SIZE);
     zeromem(ecc_shared, ECC_BUF_SIZE);
@@ -126,8 +144,17 @@
     return err;
 }
 
-int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
-                          unsigned char *outkey, unsigned long *keylen, 
+/**
+  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 *shared_secret, *skey;
@@ -135,10 +162,10 @@
    int            hash, err;
    ecc_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) {
@@ -198,39 +225,39 @@
    x = ECC_BUF_SIZE;
    if ((err = ecc_shared_secret(key, &pubkey, shared_secret, &x)) != CRYPT_OK) {
       ecc_free(&pubkey);
-      goto __ERR;
+      goto LBL_ERR;
    }
    ecc_free(&pubkey);
 
    z = MAXBLOCKSIZE;
    if ((err = hash_memory(hash, shared_secret, x, skey, &z)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    LOAD32L(keysize, in+y);
    if (inlen < keysize) {
       err = CRYPT_INVALID_PACKET;
-      goto __ERR;
+      goto LBL_ERR;
    } else {
       inlen -= keysize;
    }
    y += 4;
 
-   if (*keylen < keysize) {
+   if (*outlen < keysize) {
        err = CRYPT_BUFFER_OVERFLOW;
-       goto __ERR;
+       goto LBL_ERR;
    }
 
    /* Decrypt the key */
    for (x = 0; x < keysize; x++, y++) {
-     outkey[x] = skey[x] ^ in[y];
+     out[x] = skey[x] ^ in[y];
    }
 
-   *keylen = keysize;
+   *outlen = keysize;
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(shared_secret, ECC_BUF_SIZE);
    zeromem(skey,          MAXBLOCKSIZE);
 #endif
@@ -241,6 +268,17 @@
    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)
@@ -251,10 +289,10 @@
    unsigned long x, y, pubkeysize, rsize;
    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);
 
    /* is this a private key? */
    if (key->type != PK_PRIVATE) {
@@ -292,7 +330,7 @@
    pubkeysize = ECC_BUF_SIZE;
    if ((err = ecc_export(epubkey, &pubkeysize, PK_PUBLIC, &pubkey)) != CRYPT_OK) {
       ecc_free(&pubkey);
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* get the hash and load it as a bignum into 'b' */
@@ -300,7 +338,7 @@
    if ((err = mp_init_multi(&b, &p, NULL)) != MP_OKAY) { 
       ecc_free(&pubkey);
       err = mpi_to_ltc_error(err);
-      goto __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(&b, (unsigned char *)in, (int)inlen)) != MP_OKAY)  { goto error; }
@@ -321,7 +359,7 @@
    /* now lets check the outlen before we write */
    if (*outlen < (12 + rsize + pubkeysize)) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* lets output */
@@ -351,13 +389,13 @@
 
    /* all ok */
    err = CRYPT_OK;
-   goto __ERR;
+   goto LBL_ERR;
 error:
    err = mpi_to_ltc_error(err);
-__ERR:
+LBL_ERR:
    mp_clear_multi(&b, &p, NULL);
    ecc_free(&pubkey);
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(er,      ECC_BUF_SIZE);
    zeromem(epubkey, ECC_BUF_SIZE);
 #endif
@@ -381,8 +419,19 @@
  * 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, 
+
+/**
+   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;
@@ -391,10 +440,10 @@
    unsigned long x, y;
    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 signature */
    *stat = 0;
@@ -455,7 +504,7 @@
    y += x;
 
    /* get m in binary a bignum */
-   if ((err = mp_read_unsigned_bin(&m, (unsigned char *)hash, (int)inlen)) != MP_OKAY)     { goto error; }
+   if ((err = mp_read_unsigned_bin(&m, (unsigned char *)hash, (int)hashlen)) != MP_OKAY)   { goto error; }
    
    /* load prime */
    if ((err = mp_read_radix(&p, (char *)sets[key->idx].prime, 64)) != MP_OKAY)             { goto error; }
@@ -471,9 +520,13 @@
    /* get bA + Y */
    if ((err = add_point(&pubkey.pubkey, &key->pubkey, &pubkey.pubkey, &p, &mu)) != CRYPT_OK)    { goto done; }
 
+   /* we have to transform it */
+   if ((err = ecc_map(&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; }
+   mp_set(&mG->z, 1);
    if ((err = ecc_mulmod(&m, mG, mG, &p)) != CRYPT_OK)                                          { goto done; }
 
    /* compare mG to bA + Y */
diff --git a/packet_store_header.c b/src/pk/packet_store_header.c
similarity index 84%
rename from packet_store_header.c
rename to src/pk/packet_store_header.c
index d750718..a2442cc 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);
diff --git a/packet_valid_header.c b/src/pk/packet_valid_header.c
similarity index 86%
rename from packet_valid_header.c
rename to src/pk/packet_valid_header.c
index 7fda507..b2eb9c9 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);
diff --git a/pkcs_1_i2osp.c b/src/pk/pkcs1/pkcs_1_i2osp.c
similarity index 67%
rename from pkcs_1_i2osp.c
rename to src/pk/pkcs1/pkcs_1_i2osp.c
index 1a7fadd..7f13626 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;
diff --git a/pkcs_1_mgf1.c b/src/pk/pkcs1/pkcs_1_mgf1.c
similarity index 71%
rename from pkcs_1_mgf1.c
rename to src/pk/pkcs1/pkcs_1_mgf1.c
index 8b2bf8b..0fe177f 100644
--- a/pkcs_1_mgf1.c
+++ b/src/pk/pkcs1/pkcs_1_mgf1.c
@@ -6,25 +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
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
-/* The Mask Generation Function (MGF1) for PKCS #1 -- Tom St Denis */
+/** 
+  @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, counter, x;
+   unsigned long hLen, x;
+   ulong32       counter;
    int           err;
    hash_state    *md;
    unsigned char *buf;
  
-   _ARGCHK(seed != NULL);
-   _ARGCHK(mask != NULL);
+   LTC_ARGCHK(seed != NULL);
+   LTC_ARGCHK(mask != NULL);
 
    /* ensure valid hash */
    if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
@@ -57,16 +70,16 @@
 
        /* get hash of seed || counter */
        if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
-          goto __ERR;
+          goto LBL_ERR;
        }
        if ((err = hash_descriptor[hash_idx].process(md, seed, seedlen)) != CRYPT_OK) {
-          goto __ERR;
+          goto LBL_ERR;
        }
        if ((err = hash_descriptor[hash_idx].process(md, buf, 4)) != CRYPT_OK) {
-          goto __ERR;
+          goto LBL_ERR;
        }
        if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
-          goto __ERR;
+          goto LBL_ERR;
        }
 
        /* store it */
@@ -76,8 +89,8 @@
    }
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(buf, hLen);
    zeromem(md,  sizeof(hash_state));
 #endif
diff --git a/pkcs_1_oaep_decode.c b/src/pk/pkcs1/pkcs_1_oaep_decode.c
similarity index 73%
rename from pkcs_1_oaep_decode.c
rename to src/pk/pkcs1/pkcs_1_oaep_decode.c
index 2275bb3..82862c1 100644
--- a/pkcs_1_oaep_decode.c
+++ b/src/pk/pkcs1/pkcs_1_oaep_decode.c
@@ -6,14 +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
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
-/* OAEP Padding for PKCS #1 -- Tom St Denis */
+/** 
+  @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,
@@ -24,10 +40,10 @@
    unsigned long hLen, x, y, modulus_len;
    int           err;
 
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(res    != NULL);
+   LTC_ARGCHK(msg    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(res    != NULL);
 
    /* default to invalid packet */
    *res = 0;
@@ -39,6 +55,11 @@
    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);
@@ -56,13 +77,6 @@
       return CRYPT_MEM;
    }
 
-
-   /* test message size */
-   if (msglen != modulus_len) {
-      err = CRYPT_PK_INVALID_SIZE;
-      goto __ERR;
-   }
-
    /* ok so it's now in the form
   
       0x00  || maskedseed || maskedDB 
@@ -74,7 +88,7 @@
    /* must have leading 0x00 byte */
    if (msg[0] != 0x00) {
       err = CRYPT_OK;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* now read the masked seed */
@@ -89,7 +103,7 @@
 
    /* compute MGF1 of maskedDB (hLen) */ 
    if ((err = pkcs_1_mgf1(DB, modulus_len - hLen - 1, hash_idx, mask, hLen)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* XOR against seed */
@@ -99,7 +113,7 @@
 
    /* compute MGF1 of seed (k - hlen - 1) */
    if ((err = pkcs_1_mgf1(seed, hLen, hash_idx, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* xor against DB */
@@ -113,19 +127,19 @@
    x = modulus_len;
    if (lparam != NULL) {
       if ((err = hash_memory(hash_idx, lparam, lparamlen, seed, &x)) != CRYPT_OK) {
-         goto __ERR;
+         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 __ERR;
+         goto LBL_ERR;
       }
    }
 
    /* compare the lhash'es */
    if (memcmp(seed, DB, hLen) != 0) {
       err = CRYPT_OK;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* now zeroes before a 0x01 */
@@ -136,13 +150,13 @@
    /* error out if wasn't 0x01 */
    if (x == (modulus_len - hLen - 1) || DB[x] != 0x01) {
       err = CRYPT_OK;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* rest is the message (and skip 0x01) */
    if ((modulus_len - hLen - 1) - ++x > *outlen) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* copy message */
@@ -155,8 +169,8 @@
    *res = 1;
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(DB,   modulus_len);
    zeromem(seed, modulus_len);
    zeromem(mask, modulus_len);
diff --git a/pkcs_1_oaep_encode.c b/src/pk/pkcs1/pkcs_1_oaep_encode.c
similarity index 73%
rename from pkcs_1_oaep_encode.c
rename to src/pk/pkcs1/pkcs_1_oaep_encode.c
index 56816e6..7afea60 100644
--- a/pkcs_1_oaep_encode.c
+++ b/src/pk/pkcs1/pkcs_1_oaep_encode.c
@@ -6,14 +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"
 
-/* OAEP Padding for PKCS #1 -- Tom St Denis */
+/**
+  @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,
@@ -24,9 +41,9 @@
    unsigned long hLen, x, y, modulus_len;
    int           err;
 
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
+   LTC_ARGCHK(msg    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
 
    /* test valid hash */
    if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 
@@ -41,6 +58,11 @@
    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);
@@ -58,23 +80,17 @@
       return CRYPT_MEM;
    }
 
-   /* test message size */
-   if (msglen > (modulus_len - 2*hLen - 2)) {
-      err = CRYPT_PK_INVALID_SIZE;
-      goto __ERR;
-   }
-
    /* 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 __ERR;
+         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 __ERR;
+         goto LBL_ERR;
       }
    }
 
@@ -95,12 +111,12 @@
    /* now choose a random seed */
    if (prng_descriptor[prng_idx].read(seed, hLen, prng) != hLen) {
       err = CRYPT_ERROR_READPRNG;
-      goto __ERR;
+      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 __ERR;
+      goto LBL_ERR;
    }
 
    /* xor against DB */
@@ -110,7 +126,7 @@
 
    /* compute MGF1 of maskedDB (hLen) */ 
    if ((err = pkcs_1_mgf1(DB, modulus_len - hLen - 1, hash_idx, mask, hLen)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* XOR against seed */
@@ -121,7 +137,7 @@
    /* create string of length modulus_len */
    if (*outlen < modulus_len) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* start output which is 0x00 || maskedSeed || maskedDB */
@@ -136,8 +152,8 @@
    *outlen = x;
     
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(DB,   modulus_len);
    zeromem(seed, modulus_len);
    zeromem(mask, modulus_len);
diff --git a/src/pk/pkcs1/pkcs_1_os2ip.c b/src/pk/pkcs1/pkcs_1_os2ip.c
new file mode 100644
index 0000000..db6b58c
--- /dev/null
+++ b/src/pk/pkcs1/pkcs_1_os2ip.c
@@ -0,0 +1,37 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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 */
+
diff --git a/pkcs_1_pss_decode.c b/src/pk/pkcs1/pkcs_1_pss_decode.c
similarity index 76%
rename from pkcs_1_pss_decode.c
rename to src/pk/pkcs1/pkcs_1_pss_decode.c
index 564c90c..a19e7d8 100644
--- a/pkcs_1_pss_decode.c
+++ b/src/pk/pkcs1/pkcs_1_pss_decode.c
@@ -6,14 +6,29 @@
  * 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"
 
-/* PKCS #1 PSS Signature Padding -- Tom St Denis */
+/** 
+  @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,
@@ -24,8 +39,8 @@
    int           err;
    hash_state    md;
 
-   _ARGCHK(msghash != NULL);
-   _ARGCHK(res     != NULL);
+   LTC_ARGCHK(msghash != NULL);
+   LTC_ARGCHK(res     != NULL);
 
    /* default to invalid */
    *res = 0;
@@ -38,6 +53,12 @@
    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);
@@ -59,17 +80,10 @@
       return CRYPT_MEM;
    }
 
-   /* check sizes */
-   if ((saltlen > modulus_len) || 
-       (modulus_len < hLen + saltlen + 2) || (siglen != modulus_len)) {
-      err = CRYPT_INVALID_ARG;
-      goto __ERR;
-   }
-
    /* ensure the 0xBC byte */
    if (sig[siglen-1] != 0xBC) {
       err = CRYPT_OK;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* copy out the DB */
@@ -85,12 +99,12 @@
    /* check the MSB */
    if ((sig[0] & ~(0xFF >> ((modulus_len<<3) - (modulus_bitlen-1)))) != 0) {
       err = CRYPT_OK;
-      goto __ERR;
+      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 __ERR;
+      goto LBL_ERR;
    }
 
    /* xor against DB */
@@ -107,32 +121,32 @@
    for (x = 0; x < modulus_len - saltlen - hLen - 2; x++) {
        if (DB[x] != 0x00) {
           err = CRYPT_OK;
-          goto __ERR;
+          goto LBL_ERR;
        }
    }
 
    /* check for the 0x01 */
    if (DB[x++] != 0x01) {
       err = CRYPT_OK;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* M = (eight) 0x00 || msghash || salt, mask = H(M) */
    if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    zeromem(mask, 8);
    if ((err = hash_descriptor[hash_idx].process(&md, mask, 8)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].process(&md, DB+x, saltlen)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].done(&md, mask)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* mask == hash means valid signature */
@@ -141,8 +155,8 @@
    }
 
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(DB,   modulus_len);   
    zeromem(mask, modulus_len);   
    zeromem(salt, modulus_len);   
diff --git a/pkcs_1_pss_encode.c b/src/pk/pkcs1/pkcs_1_pss_encode.c
similarity index 76%
rename from pkcs_1_pss_encode.c
rename to src/pk/pkcs1/pkcs_1_pss_encode.c
index 43691fc..58a03d5 100644
--- a/pkcs_1_pss_encode.c
+++ b/src/pk/pkcs1/pkcs_1_pss_encode.c
@@ -6,14 +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
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
-/* PKCS #1 PSS Signature Padding -- Tom St Denis */
+/** 
+  @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,
@@ -25,9 +41,9 @@
    int           err;
    hash_state    md;
 
-   _ARGCHK(msghash != NULL);
-   _ARGCHK(out     != NULL);
-   _ARGCHK(outlen  != NULL);
+   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) {
@@ -40,6 +56,11 @@
    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);
@@ -62,36 +83,30 @@
    }
 
 
-   /* check sizes */
-   if ((saltlen > modulus_len) || (modulus_len < hLen + saltlen + 2)) {
-      err = CRYPT_INVALID_ARG;
-      goto __ERR;
-   }
-
    /* generate random salt */
    if (saltlen > 0) {
       if (prng_descriptor[prng_idx].read(salt, saltlen, prng) != saltlen) {
          err = CRYPT_ERROR_READPRNG;
-         goto __ERR;
+         goto LBL_ERR;
       }
    }
 
    /* M = (eight) 0x00 || msghash || salt, hash = H(M) */
    if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    zeromem(DB, 8);
    if ((err = hash_descriptor[hash_idx].process(&md, DB, 8)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].process(&md, salt, saltlen)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
    if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) {
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */
@@ -105,7 +120,7 @@
 
    /* 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 __ERR;
+      goto LBL_ERR;
    }
 
    /* xor against DB */
@@ -116,7 +131,7 @@
    /* output is DB || hash || 0xBC */
    if (*outlen < modulus_len) {
       err = CRYPT_BUFFER_OVERFLOW;
-      goto __ERR;
+      goto LBL_ERR;
    }
 
    /* DB */
@@ -136,8 +151,8 @@
    /* store output size */
    *outlen = modulus_len;
    err = CRYPT_OK;
-__ERR:
-#ifdef CLEAN_STACK
+LBL_ERR:
+#ifdef LTC_CLEAN_STACK
    zeromem(DB,   modulus_len);   
    zeromem(mask, modulus_len);   
    zeromem(salt, modulus_len);   
diff --git a/pkcs_1_v15_es_decode.c b/src/pk/pkcs1/pkcs_1_v15_es_decode.c
similarity index 64%
rename from pkcs_1_v15_es_decode.c
rename to src/pk/pkcs1/pkcs_1_v15_es_decode.c
index 7de4c15..fc54845 100644
--- a/pkcs_1_v15_es_decode.c
+++ b/src/pk/pkcs1/pkcs_1_v15_es_decode.c
@@ -6,14 +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 "mycrypt.h"
+#include "tomcrypt.h"
 
-/* PKCS #1 v1.5 Encryption Padding -- Tom St Denis */
+/** 
+  @file pkcs_1_v15_es_decode.c
+  PKCS #1 v1.5 Encryption Padding, Tom St Denis 
+*/
 
 #ifdef PKCS_1
 
+/**
+  PKCS #1 v1.5 Encryption Decoding
+  @param msg             The padded data
+  @param msglen          The length of the padded data (octets)
+  @param modulus_bitlen  The bit length of the RSA modulus
+  @param out             [out] Where to store the decoded data
+  @param outlen          The length of the decoded data
+  @param res             [out] Result of the decoding, 1==valid, 0==invalid
+  @return CRYPT_OK if successful
+*/
 int pkcs_1_v15_es_decode(const unsigned char *msg,  unsigned long msglen,
                                unsigned long modulus_bitlen,
                                unsigned char *out,  unsigned long outlen,
@@ -21,9 +34,9 @@
 {
    unsigned long x, modulus_bytelen;
 
-   _ARGCHK(msg != NULL);
-   _ARGCHK(out != NULL);
-   _ARGCHK(res != NULL);
+   LTC_ARGCHK(msg != NULL);
+   LTC_ARGCHK(out != NULL);
+   LTC_ARGCHK(res != NULL);
    
    /* default to failed */
    *res = 0;
diff --git a/pkcs_1_v15_es_encode.c b/src/pk/pkcs1/pkcs_1_v15_es_encode.c
similarity index 63%
rename from pkcs_1_v15_es_encode.c
rename to src/pk/pkcs1/pkcs_1_v15_es_encode.c
index 1794774..b6ac429 100644
--- a/pkcs_1_v15_es_encode.c
+++ b/src/pk/pkcs1/pkcs_1_v15_es_encode.c
@@ -6,14 +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"
 
-/* v1.5 Encryption Padding for PKCS #1 -- Tom St Denis */
+/** 
+  @file pkcs_1_v15_es_encode.c
+  v1.5 Encryption Padding for PKCS #1, Tom St Denis 
+*/
 
 #ifdef PKCS_1
 
+/**
+  PKCS #1 v1.5 Encryption Padding
+  @param msg            The data to encode
+  @param msglen         The length of the data (octets)
+  @param modulus_bitlen The bit length of the RSA modulus
+  @param prng           An active PRNG
+  @param prng_idx       The index of the PRNG desired
+  @param out            [out] The destination of the padding
+  @param outlen         [in/out] The max size and resulting size of the padding
+  @return CRYPT_OK if successful
+*/
 int pkcs_1_v15_es_encode(const unsigned char *msg,    unsigned long msglen,
                                unsigned long  modulus_bitlen, 
                                prng_state    *prng,   int           prng_idx,
@@ -21,9 +35,9 @@
 { 
    unsigned long modulus_bytelen, x, y;
 
-   _ARGCHK(msg    != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
+   LTC_ARGCHK(msg    != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
 
    /* get modulus len */
    modulus_bytelen = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
diff --git a/pkcs_1_v15_sa_decode.c b/src/pk/pkcs1/pkcs_1_v15_sa_decode.c
similarity index 71%
rename from pkcs_1_v15_sa_decode.c
rename to src/pk/pkcs1/pkcs_1_v15_sa_decode.c
index 1b5307c..7cad021 100644
--- a/pkcs_1_v15_sa_decode.c
+++ b/src/pk/pkcs1/pkcs_1_v15_sa_decode.c
@@ -6,14 +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"
 
-/* PKCS #1 v1.5 Signature Padding -- Tom St Denis */
+/** 
+  @file pkcs_1_v15_sa_decode.c
+  PKCS #1 v1.5 Signature Padding, Tom St Denis 
+*/
 
 #ifdef PKCS_1
 
+/**
+  Perform PKCS #1 v1.5 Signature Decoding
+  @param msghash         The hash that was signed
+  @param msghashlen      The length of the hash
+  @param sig             The signature [padded data]
+  @param siglen          The length of the signature
+  @param hash_idx        The index of the hash used
+  @param modulus_bitlen  The bit length of the RSA modulus 
+  @param res             [out]  Result of comparison, 1==valid, 0==invalid
+  @return CRYPT_OK if successful
+*/
 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, 
@@ -22,9 +36,9 @@
    unsigned long x, y, modulus_bytelen, derlen;
    int err;
    
-   _ARGCHK(msghash != NULL);
-   _ARGCHK(sig     != NULL);
-   _ARGCHK(res     != NULL);
+   LTC_ARGCHK(msghash != NULL);
+   LTC_ARGCHK(sig     != NULL);
+   LTC_ARGCHK(res     != NULL);
 
    /* default to invalid */
    *res = 0;
diff --git a/pkcs_1_v15_sa_encode.c b/src/pk/pkcs1/pkcs_1_v15_sa_encode.c
similarity index 69%
rename from pkcs_1_v15_sa_encode.c
rename to src/pk/pkcs1/pkcs_1_v15_sa_encode.c
index f0f258a..60c77ef 100644
--- a/pkcs_1_v15_sa_encode.c
+++ b/src/pk/pkcs1/pkcs_1_v15_sa_encode.c
@@ -6,14 +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 "mycrypt.h"
+#include "tomcrypt.h"
 
-/* PKCS #1 v1.5 Signature Padding -- Tom St Denis */
+/** 
+  @file pkcs_1_v15_sa_encode.c
+  PKCS #1 v1.5 Signature Padding, Tom St Denis 
+*/
 
 #ifdef PKCS_1
 
+/**
+  Perform PKCS #1 v1.5 Signature Padding
+  @param msghash         The hash you wish to incorporate in the padding
+  @param msghashlen      The length of the hash
+  @param hash_idx        The index of the hash used
+  @param modulus_bitlen  The length of the RSA modulus that will sign this (bits)
+  @param out             [out] Where to store the padded data
+  @param outlen          [in/out] Max size and resulting size of the padded data
+  @return CRYPT_OK if successful
+*/
 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)
@@ -21,9 +34,9 @@
   unsigned long derlen, modulus_bytelen, x, y;
   int err;
 
-  _ARGCHK(msghash != NULL)
-  _ARGCHK(out     != NULL);
-  _ARGCHK(outlen  != NULL);
+  LTC_ARGCHK(msghash != NULL)
+  LTC_ARGCHK(out     != NULL);
+  LTC_ARGCHK(outlen  != NULL);
 
   if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
      return err;
diff --git a/src/pk/rsa/rsa_decrypt_key.c b/src/pk/rsa/rsa_decrypt_key.c
new file mode 100644
index 0000000..3117715
--- /dev/null
+++ b/src/pk/rsa/rsa_decrypt_key.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 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 */
+
+
+
+
diff --git a/src/pk/rsa/rsa_encrypt_key.c b/src/pk/rsa/rsa_encrypt_key.c
new file mode 100644
index 0000000..891b43e
--- /dev/null
+++ b/src/pk/rsa/rsa_encrypt_key.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_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 */
diff --git a/src/pk/rsa/rsa_export.c b/src/pk/rsa/rsa_export.c
new file mode 100644
index 0000000..951be70
--- /dev/null
+++ b/src/pk/rsa/rsa_export.c
@@ -0,0 +1,98 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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, x;
+
+   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 (*outlen < 4) {
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+  
+   /* Mental Note: push space for the header 0x30 0x82 LL LL (LL = length of packet EXcluding 4 bytes) 
+    * we assume LL > 255 which is true since the smallest RSA key has a 128-byte modulus (1024-bit)
+    */
+   *outlen -= 4;
+
+   if (type == PK_PRIVATE) {
+      /* private key */
+      mp_int zero;
+
+      /* first INTEGER == 0 to signify two-prime RSA */
+      if ((err = mp_init(&zero)) != MP_OKAY) {
+         return mpi_to_ltc_error(err);
+      }
+ 
+      /* output is 
+            Version, n, e, d, p, q, d mod (p-1), d mod (q - 1), 1/q mod p
+       */
+      if ((err = der_put_multi_integer(
+                          out+4, outlen, &zero, &key->N, &key->e,
+                          &key->d, &key->p, &key->q, &key->dP,
+                          &key->dQ, &key->qP, NULL)) != CRYPT_OK) {
+         mp_clear(&zero);
+         return err;
+      }
+ 
+      /* clear zero and return */
+      mp_clear(&zero);
+   } else {
+      /* public key */
+      if ((err = der_put_multi_integer(out+4, outlen, &key->N, &key->e, NULL)) != CRYPT_OK) {
+         return err;
+      }
+   }
+
+   /* store the header */
+   out[0] = 0x30;
+   if (*outlen < 256) {
+      /* shift the output up one byte if the header is only 3 bytes */
+      for (x = 0; x < *outlen; x++) {
+          out[x+3] = out[x+4];
+      }
+      out[1] = 0x81;
+      out[2] = (*outlen & 255);
+      *outlen += 3;
+   } else {
+      out[1] = 0x82;
+      out[2] = (*outlen >> 8) & 255;
+      out[3] = (*outlen & 255);
+      *outlen += 4;
+   }
+   return err;
+}
+
+#endif /* MRSA */
+
diff --git a/rsa_exptmod.c b/src/pk/rsa/rsa_exptmod.c
similarity index 61%
rename from rsa_exptmod.c
rename to src/pk/rsa/rsa_exptmod.c
index 2eebd86..fda6cbb 100644
--- a/rsa_exptmod.c
+++ b/src/pk/rsa/rsa_exptmod.c
@@ -6,34 +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
  */
+#include "tomcrypt.h"
 
-/* RSA Code by Tom St Denis */
-#include "mycrypt.h"
+/**
+  @file rsa_exptmod.c
+  RSA PKCS exptmod, Tom St Denis
+*/  
 
 #ifdef MRSA
 
-/* compute an RSA modular exponentiation */
+/** 
+   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,
-                      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);
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(key    != NULL);
    
-   /* valid prng? */
-   if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
-      return err;
-   }
-
    /* is the key of the right type for the operation? */
    if (which == PK_PRIVATE && (key->type != PK_PRIVATE)) {
       return CRYPT_PK_NOT_PRIVATE;
@@ -45,8 +51,8 @@
    }
 
    /* 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; }
+   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) {
@@ -57,21 +63,21 @@
    /* are we using the private exponent and is the key optimized? */
    if (which == PK_PRIVATE) {
       /* tmpa = tmp^dP mod p */
-      if ((err = tim_exptmod(prng, prng_idx, &tmp, &key->e, &key->dP, &key->p, &tmpa)) != MP_OKAY)    { goto error; }
+      if ((err = mp_exptmod(&tmp, &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; }
+      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; }
+      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; }
+      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; }
+      if ((err = mp_exptmod(&tmp, &key->e, &key->N, &tmp)) != MP_OKAY)                                { goto error; }
    }
 
    /* read it back */
@@ -84,7 +90,7 @@
 
    /* convert it */
    zeromem(out, x);
-   if ((err = mp_to_unsigned_bin(&tmp, out+(x-mp_unsigned_bin_size(&tmp)))) != MP_OKAY) { goto error; }
+   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;
diff --git a/rsa_free.c b/src/pk/rsa/rsa_free.c
similarity index 64%
rename from rsa_free.c
rename to src/pk/rsa/rsa_free.c
index 4562788..85ade97 100644
--- a/rsa_free.c
+++ b/src/pk/rsa/rsa_free.c
@@ -6,17 +6,24 @@
  * 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_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)
 {
-   _ARGCHK(key != NULL);
+   LTC_ARGCHK(key != NULL);
    mp_clear_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP,
                   &key->qP, &key->p, &key->q, NULL);
 }
diff --git a/src/pk/rsa/rsa_import.c b/src/pk/rsa/rsa_import.c
new file mode 100644
index 0000000..5408df0
--- /dev/null
+++ b/src/pk/rsa/rsa_import.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 rsa_import.c
+  Import a PKCS RSA key, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+  Import an RSAPublicKey or RSAPrivateKey [two-prime only, 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)
+{
+   unsigned long x, y;
+   int err;
+
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(key != NULL);
+
+   /* init key */
+   if ((err = mp_init_multi(&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);
+   }
+
+   /* check the header */
+   if (inlen < 4) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* should be 0x30 0x8{1|2} LL LL */
+   if ((in[0] != 0x30) || ((in[1] != 0x81) && (in[1] != 0x82))) {
+      return CRYPT_INVALID_PACKET;
+   }
+
+   /* ok all the ASN.1 params are fine so far, let's move up */
+   x = ((unsigned long)in[2]);
+   y = 0;
+   if ((in[1] & ~0x80) == 2) {
+      x   = (x << 8) + ((unsigned long)in[3]) + 1;
+      in += 1;
+      y   = 1;
+   }
+   in += 3; /* advance input */
+   x  += 3; /* size of packet according to header */
+   y  += 3; /* used input */
+
+   if (x != inlen) {
+      return CRYPT_INVALID_PACKET;
+   }
+   
+   /* decrement inlen by the header size */
+   inlen -= y;
+
+   /* read first number, it's either N or 0 [0 == private key] */
+   x = inlen;
+   if ((err = der_get_multi_integer(in, &x, &key->N, NULL)) != CRYPT_OK) {
+      goto LBL_ERR;
+   }
+
+   /* advance */
+   inlen -= x;
+   in    += x;
+
+   if (mp_cmp_d(&key->N, 0) == MP_EQ) {
+      /* it's a private key */
+      if ((err = der_get_multi_integer(in, &inlen, &key->N, &key->e,
+                          &key->d, &key->p, &key->q, &key->dP,
+                          &key->dQ, &key->qP, 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_get_multi_integer(in, &inlen, &key->e, 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(&key->d, &key->e, &key->N, &key->dQ, &key->dP,
+                  &key->qP, &key->p, &key->q, NULL);
+   return err;
+}
+
+#endif /* MRSA */
+
diff --git a/rsa_make_key.c b/src/pk/rsa/rsa_make_key.c
similarity index 88%
rename from rsa_make_key.c
rename to src/pk/rsa/rsa_make_key.c
index fc95450..9d49e3c 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;
diff --git a/src/pk/rsa/rsa_sign_hash.c b/src/pk/rsa/rsa_sign_hash.c
new file mode 100644
index 0000000..b86ad64
--- /dev/null
+++ b/src/pk/rsa/rsa_sign_hash.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 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 */
diff --git a/src/pk/rsa/rsa_v15_decrypt_key.c b/src/pk/rsa/rsa_v15_decrypt_key.c
new file mode 100644
index 0000000..eb5fe7d
--- /dev/null
+++ b/src/pk/rsa/rsa_v15_decrypt_key.c
@@ -0,0 +1,73 @@
+   /* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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_v15_decrypt_key.c
+  RSA PKCS v1.5 Decryption, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/**
+   RSA decrypt then PKCS #1 v1.5 depad 
+   @param in        The ciphertext
+   @param inlen     The length of the ciphertext (octets)
+   @param out       [out] The plaintext
+   @param outlen    The length of the plaintext (you have to tell this function as it's not part of PKCS #1 v1.0 padding!)
+   @param stat      [out] Status of decryption, 1==valid, 0==invalid
+   @param key       The corresponding private RSA key
+   @return CRYPT_OK if successful (even if invalid)   
+*/
+int rsa_v15_decrypt_key(const unsigned char *in,     unsigned long  inlen,
+                              unsigned char *out,    unsigned long  outlen, 
+                              int           *stat,   rsa_key       *key)
+{
+  unsigned long modulus_bitlen, modulus_bytelen, x;
+  int           err;
+  unsigned char *tmp;
+  
+  LTC_ARGCHK(out    != NULL);
+  LTC_ARGCHK(key    != NULL);
+  LTC_ARGCHK(stat   != NULL);
+ 
+  /* default to invalid */
+  *stat = 0;
+
+  /* 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;
+  }
+
+  /* PKCS #1 v1.5 depad */
+  err = pkcs_1_v15_es_decode(tmp, x, modulus_bitlen, out, outlen, stat);
+  XFREE(tmp);
+  return err;
+}
+
+#endif
diff --git a/src/pk/rsa/rsa_v15_encrypt_key.c b/src/pk/rsa/rsa_v15_encrypt_key.c
new file mode 100644
index 0000000..d422f67
--- /dev/null
+++ b/src/pk/rsa/rsa_v15_encrypt_key.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 rsa_v15_encrypt_key.c
+  RSA PKCS v1.5 Encryption, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/** 
+   PKCS #1 v1.5 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 prng        An active PRNG
+   @param prng_idx    The index of the desired PRNG
+   @param key         The public RSA key
+   @return CRYPT_OK if successful
+*/   
+int rsa_v15_encrypt_key(const unsigned char *in,    unsigned long  inlen,
+                              unsigned char *out,   unsigned long *outlen,
+                              prng_state    *prng,  int            prng_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? */
+  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 > *outlen) {
+     return CRYPT_BUFFER_OVERFLOW;
+  }
+  
+  /* pad it */
+  x = *outlen;
+  if ((err = pkcs_1_v15_es_encode(in, inlen, modulus_bitlen, prng, prng_idx, out, &x)) != CRYPT_OK) {
+     return err;
+  }
+  
+  /* encrypt it */
+  return rsa_exptmod(out, x, out, outlen, PK_PUBLIC, key);
+}
+
+#endif
diff --git a/src/pk/rsa/rsa_v15_sign_hash.c b/src/pk/rsa/rsa_v15_sign_hash.c
new file mode 100644
index 0000000..7e9b350
--- /dev/null
+++ b/src/pk/rsa/rsa_v15_sign_hash.c
@@ -0,0 +1,66 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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_v15_sign_hash.c
+   RSA PKCS v1.5 Signature, Tom St Denis
+*/   
+
+#ifdef MRSA
+
+/** 
+   PKCS #1 v1.5 pad then sign
+   @param in             The hash to sign
+   @param inlen          The length of the message hash (octets)
+   @param out            [out] The signature
+   @param siglen         [in/out] The max size and resulting size of the signature
+   @param hash_idx       The index of the hash desired
+   @param key            The private RSA key to perform the signature with
+   @return CRYPT_OK if successful
+*/
+int rsa_v15_sign_hash(const unsigned char *in,       unsigned long  inlen, 
+                            unsigned char *out,      unsigned long *siglen, 
+                            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(siglen   != NULL);
+  LTC_ARGCHK(key      != 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 > *siglen) {
+     return CRYPT_BUFFER_OVERFLOW;
+  }
+      
+  /* PKCS #1 v1.5 pad the key */
+  x = *siglen;
+  if ((err = pkcs_1_v15_sa_encode(in, inlen, hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) {
+     return err;
+  }
+
+  /* RSA encode it */
+  return rsa_exptmod(out, x, out, siglen, PK_PRIVATE, key);
+}
+
+#endif
diff --git a/src/pk/rsa/rsa_v15_verify_hash.c b/src/pk/rsa/rsa_v15_verify_hash.c
new file mode 100644
index 0000000..e742cba
--- /dev/null
+++ b/src/pk/rsa/rsa_v15_verify_hash.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 rsa_v15_verify_hash.c
+  RSA PKCS v1.5 Signature verification, Tom St Denis
+*/  
+
+#ifdef MRSA
+
+/** 
+   RSA de-sign then PKCS v1.5 signature depad
+   @param sig           The signature data
+   @param siglen        The length of the signature (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 stat          [out] The result of the signature comparison, 1==valid, 0==invalid
+   @param key           The corresponding public RSA key that performed the signature
+   @return CRYPT_OK if successful (even if the signature is invalid)
+*/
+int rsa_v15_verify_hash(const unsigned char *sig,      unsigned long siglen,
+                        const unsigned char *hash,  unsigned long hashlen,
+                              int            hash_idx, 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_v15_sa_decode(hash, hashlen, tmpbuf, x, hash_idx, modulus_bitlen, stat);
+  XFREE(tmpbuf);
+  return err;
+}
+
+#endif
diff --git a/src/pk/rsa/rsa_verify_hash.c b/src/pk/rsa/rsa_verify_hash.c
new file mode 100644
index 0000000..7072083
--- /dev/null
+++ b/src/pk/rsa/rsa_verify_hash.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
+ */
+#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 */
diff --git a/fortuna.c b/src/prngs/fortuna.c
similarity index 73%
rename from fortuna.c
rename to src/prngs/fortuna.c
index 5d81255..4548a90 100644
--- a/fortuna.c
+++ b/src/prngs/fortuna.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
  */
+#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 */
 
-#include "mycrypt.h"
-
 #ifdef FORTUNA 
 
 /* requries SHA256 and AES  */
@@ -33,7 +37,7 @@
    #error FORTUNA_POOLS must be in [4..32]
 #endif
 
-const struct _prng_descriptor fortuna_desc = {
+const struct ltc_prng_descriptor fortuna_desc = {
     "fortuna", 1024,
     &fortuna_start,
     &fortuna_add_entropy,
@@ -104,7 +108,7 @@
    prng->fortuna.wd        = 0;
 
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
    zeromem(&md, sizeof(md));
    zeromem(tmp, sizeof(tmp));
 #endif
@@ -112,11 +116,16 @@
    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;
 
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(prng != NULL);
    
    /* initialize the pools */
    for (x = 0; x < FORTUNA_POOLS; x++) {
@@ -135,30 +144,37 @@
    return CRYPT_OK;
 }
 
-int fortuna_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
+/**
+  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;
 
-   _ARGCHK(buf  != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(prng != NULL);
 
-   /* ensure len <= 32 */
-   if (len > 32) {
+   /* ensure inlen <= 32 */
+   if (inlen > 32) {
       return CRYPT_INVALID_ARG;
    }
 
-   /* add s || length(buf) || buf to pool[pool_idx] */
+   /* add s || length(in) || in to pool[pool_idx] */
    tmp[0] = 0;
-   tmp[1] = len;
+   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], buf, len)) != CRYPT_OK) {
+   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 += len;
+      prng->fortuna.pool0_len += inlen;
    }
    if (++(prng->fortuna.pool_idx) == FORTUNA_POOLS) {
       prng->fortuna.pool_idx = 0;
@@ -167,19 +183,31 @@
    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);
 }
 
-unsigned long fortuna_read(unsigned char *dst, unsigned long len, prng_state *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;
 
-   _ARGCHK(dst  != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(out  != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    /* do we have to reseed? */
    if (++prng->fortuna.wd == FORTUNA_WD || prng->fortuna.pool0_len >= 64) {
@@ -189,21 +217,21 @@
    }
 
    /* now generate the blocks required */
-   tlen = len;
+   tlen = outlen;
 
    /* handle whole blocks without the extra memcpy */
-   while (len >= 16) {
+   while (outlen >= 16) {
       /* encrypt the IV and store it */
-      rijndael_ecb_encrypt(prng->fortuna.IV, dst, &prng->fortuna.skey);
-      dst += 16;
-      len -= 16;
+      rijndael_ecb_encrypt(prng->fortuna.IV, out, &prng->fortuna.skey);
+      out += 16;
+      outlen -= 16;
       fortuna_update_iv(prng);
    }
 
    /* left over bytes? */
-   if (len > 0) {
+   if (outlen > 0) {
       rijndael_ecb_encrypt(prng->fortuna.IV, tmp, &prng->fortuna.skey);
-      XMEMCPY(dst, tmp, len);
+      XMEMCPY(out, tmp, outlen);
       fortuna_update_iv(prng);
    }
        
@@ -214,18 +242,23 @@
       return 0;
    }
 
-#ifdef CLEAN_STACK
+#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];
 
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    /* terminate all the hashes */
    for (x = 0; x < FORTUNA_POOLS; x++) {
@@ -235,21 +268,28 @@
    }
    /* call cipher done when we invent one ;-) */
 
-#ifdef CLEAN_STACK
+#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;
 
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(prng   != NULL);
+   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) {
@@ -270,37 +310,44 @@
 
       /* terminate it */
       if ((err = sha256_done(md, out+x*32)) != CRYPT_OK) {
-         goto __ERR;
+         goto LBL_ERR;
       }
 
       /* now hash it */
       if ((err = sha256_init(md)) != CRYPT_OK) {
-         goto __ERR;
+         goto LBL_ERR;
       }
       if ((err = sha256_process(md, out+x*32, 32)) != CRYPT_OK) {
-         goto __ERR;
+         goto LBL_ERR;
       }
       if ((err = sha256_done(md, out+x*32)) != CRYPT_OK) {
-         goto __ERR;
+         goto LBL_ERR;
       }
    }
    *outlen = 32*FORTUNA_POOLS;
    err = CRYPT_OK;
 
-__ERR:
-#ifdef CLEAN_STACK
+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;
 
-   _ARGCHK(in   != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    if (inlen != 32*FORTUNA_POOLS) {
       return CRYPT_INVALID_ARG;
@@ -317,6 +364,10 @@
    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
diff --git a/rc4.c b/src/prngs/rc4.c
similarity index 62%
rename from rc4.c
rename to src/prngs/rc4.c
index e8139ad..750c38b 100644
--- a/rc4.c
+++ b/src/prngs/rc4.c
@@ -6,13 +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
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
+
+/**
+  @file rc4.c
+  RC4 PRNG, Tom St Denis
+*/  
 
 #ifdef RC4
 
-const struct _prng_descriptor rc4_desc = 
+const struct ltc_prng_descriptor rc4_desc = 
 {
    "rc4", 32,
     &rc4_start,
@@ -25,9 +30,14 @@
     &rc4_test
 };
 
+/**
+  Start the PRNG
+  @param prng     [out] The PRNG state to initialize
+  @return CRYPT_OK if successful
+*/  
 int rc4_start(prng_state *prng)
 {
-    _ARGCHK(prng != NULL);
+    LTC_ARGCHK(prng != NULL);
 
     /* set keysize to zero */
     prng->rc4.x = 0;
@@ -35,36 +45,48 @@
     return CRYPT_OK;
 }
 
-int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
+/**
+  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)
 {
-    _ARGCHK(buf  != NULL);
-    _ARGCHK(prng != NULL);
+    LTC_ARGCHK(in  != NULL);
+    LTC_ARGCHK(prng != NULL);
  
     /* trim as required */
-    if (prng->rc4.x + len > 256) {
+    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 */
-          len = 256 - prng->rc4.x;
+          inlen = 256 - prng->rc4.x;
        }       
     }
 
-    while (len--) {
-       prng->rc4.buf[prng->rc4.x++] = *buf++;
+    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;
 
-    _ARGCHK(prng != NULL);
+    LTC_ARGCHK(prng != NULL);
 
     /* extract the key */
     s = prng->rc4.buf;
@@ -86,48 +108,67 @@
     prng->rc4.x = 0;
     prng->rc4.y = 0;
 
-#ifdef CLEAN_STACK
+#ifdef LTC_CLEAN_STACK
     zeromem(key, sizeof(key));
 #endif
 
     return CRYPT_OK;
 }
 
-unsigned long rc4_read(unsigned char *buf, unsigned long len, prng_state *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 rc4_read(unsigned char *out, unsigned long outlen, prng_state *prng)
 {
    unsigned char x, y, *s, tmp;
    unsigned long n;
 
-   _ARGCHK(buf != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(out != NULL);
+   LTC_ARGCHK(prng != NULL);
 
-   n = len;
+   n = outlen;
    x = prng->rc4.x;
    y = prng->rc4.y;
    s = prng->rc4.buf;
-   while (len--) {
+   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;
-      *buf++ ^= s[tmp];
+      *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)
 {
-   _ARGCHK(prng != NULL);
+   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)
 {
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(prng   != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(prng   != NULL);
 
    if (*outlen < 32) {
       return CRYPT_BUFFER_OVERFLOW;
@@ -141,11 +182,18 @@
    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;
-   _ARGCHK(in   != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    if (inlen != 32) {
       return CRYPT_INVALID_ARG;
@@ -157,6 +205,10 @@
    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
diff --git a/rng_get_bytes.c b/src/prngs/rng_get_bytes.c
similarity index 77%
rename from rng_get_bytes.c
rename to src/prngs/rng_get_bytes.c
index f3027cd..8519e0a 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,28 @@
 
 #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;
 }
diff --git a/rng_make_prng.c b/src/prngs/rng_make_prng.c
similarity index 66%
rename from rng_make_prng.c
rename to src/prngs/rng_make_prng.c
index 4c30e69..94132e7 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,7 +57,7 @@
       return err;
    }
 
-   #ifdef CLEAN_STACK
+   #ifdef LTC_CLEAN_STACK
       zeromem(buf, sizeof(buf));
    #endif
    return CRYPT_OK;
diff --git a/sober128.c b/src/prngs/sober128.c
similarity index 73%
rename from sober128.c
rename to src/prngs/sober128.c
index bc00748..48667bd 100644
--- a/sober128.c
+++ b/src/prngs/sober128.c
@@ -6,19 +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
  */
-#include "mycrypt.h"
+#include "tomcrypt.h"
 
-/* Implementation of SOBER-128 by Tom St Denis.
- * Based on s128fast.c reference code supplied by Greg Rose of QUALCOMM.
- */
+/**
+ @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 _prng_descriptor sober128_desc = 
+const struct ltc_prng_descriptor sober128_desc = 
 {
    "sober128", 64,
     &sober128_start,
@@ -86,7 +88,7 @@
 { \
     t = c->R[OFF(z,0)] + c->R[OFF(z,16)]; \
     t ^= Sbox[(t >> 24) & 0xFF]; \
-    t = ROR(t, 8); \
+    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)]; \
@@ -99,14 +101,17 @@
     return t;
 }
 
-/* initialise to known state
- */
+/**
+  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;
 
-    _ARGCHK(prng != NULL);
+    LTC_ARGCHK(prng != NULL);
 
     c = &(prng->sober128);
     
@@ -192,31 +197,38 @@
     DROUND(16);
 }
 
-int sober128_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
+/**
+  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;
 
-    _ARGCHK(buf != NULL);
-    _ARGCHK(prng != NULL);
+    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 */
-       /* len must be multiple of 4 bytes */
-       if ((len & 3) != 0) {
+       /* inlen must be multiple of 4 bytes */
+       if ((inlen & 3) != 0) {
           return CRYPT_INVALID_KEYSIZE;
        }
     
-       for (i = 0; i < len; i += 4) {
-           k = BYTE2WORD((unsigned char *)&buf[i]);
+       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(len);
+       ADDKEY(inlen);
 
        /* now diffuse */
        s128_diffuse(c);
@@ -230,20 +242,20 @@
        /* ok we are adding an IV then... */
        s128_reloadstate(c);
 
-       /* len must be multiple of 4 bytes */
-       if ((len & 3) != 0) {
+       /* inlen must be multiple of 4 bytes */
+       if ((inlen & 3) != 0) {
           return CRYPT_INVALID_KEYSIZE;
        }
     
-       for (i = 0; i < len; i += 4) {
-           k = BYTE2WORD((unsigned char *)&buf[i]);
+       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(len);
+       ADDKEY(inlen);
 
        /* now diffuse */
        s128_diffuse(c);
@@ -253,6 +265,11 @@
     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;
@@ -260,31 +277,38 @@
 
 /* XOR pseudo-random bytes into buffer
  */
-#define SROUND(z) STEP(c->R,z); NLFUNC(c,(z+1)); XORWORD(t, buf+(z*4));
+#define SROUND(z) STEP(c->R,z); NLFUNC(c,(z+1)); XORWORD(t, out+(z*4));
 
-unsigned long sober128_read(unsigned char *buf, unsigned long nbytes, prng_state *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 sober128_read(unsigned char *out, unsigned long outlen, prng_state *prng)
 {
    struct sober128_prng *c;
    ulong32               t, tlen;
 
-   _ARGCHK(buf  != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(out  != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    c = &(prng->sober128);
    t = 0;
-   tlen = nbytes;
+   tlen = outlen;
    
    /* handle any previously buffered bytes */
-   while (c->nbuf != 0 && nbytes != 0) {
-      *buf++ ^= c->sbuf & 0xFF;
+   while (c->nbuf != 0 && outlen != 0) {
+      *out++ ^= c->sbuf & 0xFF;
        c->sbuf >>= 8;
        c->nbuf -= 8;
-       --nbytes;
+       --outlen;
    }
 
-#ifndef SMALL_CODE
+#ifndef LTC_SMALL_CODE
     /* do lots at a time, if there's enough to do */
-    while (nbytes >= N*4) {
+    while (outlen >= N*4) {
       SROUND(0);
       SROUND(1);
       SROUND(2);
@@ -302,47 +326,59 @@
       SROUND(14);
       SROUND(15);
       SROUND(16);
-      buf    += 4*N;
-      nbytes -= 4*N;
+      out    += 4*N;
+      outlen -= 4*N;
     }
 #endif
 
     /* do small or odd size buffers the slow way */
-    while (4 <= nbytes) {
+    while (4 <= outlen) {
       cycle(c->R);
       t = nltap(c);
-      XORWORD(t, buf);
-      buf    += 4;
-      nbytes -= 4;
+      XORWORD(t, out);
+      out    += 4;
+      outlen -= 4;
     }
 
     /* handle any trailing bytes */
-    if (nbytes != 0) {
+    if (outlen != 0) {
       cycle(c->R);
       c->sbuf = nltap(c);
       c->nbuf = 32;
-      while (c->nbuf != 0 && nbytes != 0) {
-          *buf++ ^= c->sbuf & 0xFF;
+      while (c->nbuf != 0 && outlen != 0) {
+          *out++ ^= c->sbuf & 0xFF;
           c->sbuf >>= 8;
           c->nbuf -= 8;
-          --nbytes;
+          --outlen;
       }
     }
 
     return tlen;
 }
 
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
 int sober128_done(prng_state *prng)
 {
-   _ARGCHK(prng != NULL);
+   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)
 {
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(out    != NULL);
-   _ARGCHK(prng   != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(prng   != NULL);
 
    if (*outlen < 64) {
       return CRYPT_BUFFER_OVERFLOW;
@@ -356,11 +392,18 @@
    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;
-   _ARGCHK(in   != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    if (inlen != 64) {
       return CRYPT_INVALID_ARG;
@@ -375,6 +418,10 @@
    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
diff --git a/sober128tab.c b/src/prngs/sober128tab.c
similarity index 96%
rename from sober128tab.c
rename to src/prngs/sober128tab.c
index f50afb5..dc6f3e2 100644
--- a/sober128tab.c
+++ b/src/prngs/sober128tab.c
@@ -1,5 +1,9 @@
-/* $Id: s128multab.h 213 2003-12-16 04:27:12Z ggr $ */
-/* @(#)TuringMultab.h	1.3 (QUALCOMM) 02/09/03 */
+/** 
+   @file sober128tab.c
+   SOBER-128 Tables
+*/   
+/* $Id: sober128tab.c,v 1.1.1.1 2005/03/18 23:19:17 root Exp $ */
+/* @(#)TuringMultab.h   1.3 (QUALCOMM) 02/09/03 */
 /* Multiplication table for Turing using 0xD02B4367 */
 static const ulong32 Multab[256] = {
     0x00000000, 0xD02B4367, 0xED5686CE, 0x3D7DC5A9,
@@ -68,7 +72,7 @@
     0xEF72A3F1, 0x3F59E096, 0x0224253F, 0xD20F6658,
 };
 
-/* $Id: s128sbox.h 213 2003-12-16 04:27:12Z ggr $ */
+/* $Id: sober128tab.c,v 1.1.1.1 2005/03/18 23:19:17 root Exp $ */
 /* Sbox for SOBER-128 */
 /*
  * This is really the combination of two SBoxes; the least significant
diff --git a/src/prngs/sprng.c b/src/prngs/sprng.c
new file mode 100644
index 0000000..dce8347
--- /dev/null
+++ b/src/prngs/sprng.c
@@ -0,0 +1,132 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms 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
+
+
+ 
diff --git a/yarrow.c b/src/prngs/yarrow.c
similarity index 72%
rename from yarrow.c
rename to src/prngs/yarrow.c
index 333892e..1582856 100644
--- a/yarrow.c
+++ b/src/prngs/yarrow.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
  */
+#include "tomcrypt.h"
 
-#include "mycrypt.h"
+/**
+  @file yarrow.c
+  Yarrow PRNG, Tom St Denis
+*/  
 
 #ifdef YARROW
 
-const struct _prng_descriptor yarrow_desc =
+const struct ltc_prng_descriptor yarrow_desc =
 {
     "yarrow", 64,
     &yarrow_start,
@@ -26,11 +30,16 @@
     &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;
    
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    /* these are the default hash/cipher combo used */
 #ifdef RIJNDAEL
@@ -105,13 +114,20 @@
    return CRYPT_OK;
 }
 
-int yarrow_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng)
+/**
+  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;
 
-   _ARGCHK(buf  != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(in  != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
       return err;
@@ -129,7 +145,7 @@
    }
 
    /* add the new entropy */
-   if ((err = hash_descriptor[prng->yarrow.hash].process(&md, buf, len)) != CRYPT_OK) {
+   if ((err = hash_descriptor[prng->yarrow.hash].process(&md, in, inlen)) != CRYPT_OK) {
       return err;
    }
 
@@ -141,11 +157,16 @@
    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;
 
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    if ((err = hash_is_valid(prng->yarrow.hash)) != CRYPT_OK) {
       return err;
@@ -171,34 +192,55 @@
    return CRYPT_OK;
 }
 
-unsigned long yarrow_read(unsigned char *buf, unsigned long len, prng_state *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 yarrow_read(unsigned char *out, unsigned long outlen, prng_state *prng)
 {
-   _ARGCHK(buf  != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(out  != NULL);
+   LTC_ARGCHK(prng != NULL);
 
-   /* put buf in predictable state first */
-   zeromem(buf, len);
+   /* put out in predictable state first */
+   zeromem(out, outlen);
    
    /* now randomize it */
-   if (ctr_encrypt(buf, buf, len, &prng->yarrow.ctr) != CRYPT_OK) {
+   if (ctr_encrypt(out, out, outlen, &prng->yarrow.ctr) != CRYPT_OK) {
       return 0;
    }
-   return len;
+   return outlen;
 }
 
+/**
+  Terminate the PRNG
+  @param prng   The PRNG to terminate
+  @return CRYPT_OK if successful
+*/  
 int yarrow_done(prng_state *prng)
 {
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(prng != NULL);
+
    /* call cipher done when we invent one ;-) */
 
-   return CRYPT_OK;
+   /* 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)
 {
-   _ARGCHK(out    != NULL);
-   _ARGCHK(outlen != NULL);
-   _ARGCHK(prng   != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+   LTC_ARGCHK(prng   != NULL);
 
    /* we'll write 64 bytes for s&g's */
    if (*outlen < 64) {
@@ -213,12 +255,19 @@
    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;
 
-   _ARGCHK(in   != NULL);
-   _ARGCHK(prng != NULL);
+   LTC_ARGCHK(in   != NULL);
+   LTC_ARGCHK(prng != NULL);
 
    if (inlen != 64) {
       return CRYPT_INVALID_ARG;
@@ -230,6 +279,10 @@
    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
diff --git a/demos/test/base64_test.c b/testprof/base64_test.c
similarity index 85%
rename from demos/test/base64_test.c
rename to testprof/base64_test.c
index b02c1a2..e93ebef 100644
--- a/demos/test/base64_test.c
+++ b/testprof/base64_test.c
@@ -1,4 +1,4 @@
-#include  "test.h"
+#include  <tomcrypt_test.h>
 
 int base64_test(void)
 {
@@ -6,7 +6,7 @@
    unsigned long x, l1, l2;
    
    for  (x = 0; x < 64; x++) {
-       yarrow_read(in, x, &test_yarrow);
+       yarrow_read(in, x, &yarrow_prng);
        l1 = sizeof(out);
        DO(base64_encode(in, x, out, &l1));
        l2 = sizeof(tmp);
diff --git a/demos/test/cipher_hash_test.c b/testprof/cipher_hash_test.c
similarity index 97%
rename from demos/test/cipher_hash_test.c
rename to testprof/cipher_hash_test.c
index 2737623..d2f3bfc 100644
--- a/demos/test/cipher_hash_test.c
+++ b/testprof/cipher_hash_test.c
@@ -1,6 +1,6 @@
 /* test the ciphers and hashes using their built-in self-tests */
 
-#include "test.h"
+#include <tomcrypt_test.h>
 
 int cipher_hash_test(void)
 {
diff --git a/demos/test/der_tests.c b/testprof/der_tests.c
similarity index 92%
rename from demos/test/der_tests.c
rename to testprof/der_tests.c
index 0c0e3df..fe8eb00 100644
--- a/demos/test/der_tests.c
+++ b/testprof/der_tests.c
@@ -1,4 +1,14 @@
-#include "test.h"
+#include <tomcrypt_test.h>
+
+#ifndef LTC_DER
+
+int der_tests(void)
+{
+   printf("NOP");
+   return 0;
+}
+
+#else
 
 int der_tests(void)
 {
@@ -9,7 +19,7 @@
    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, &test_yarrow) != z) {
+         if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
             printf("Failed to read %lu bytes from yarrow\n", z);
             return 1;
          }
@@ -80,3 +90,5 @@
    mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
    return 0;
 }
+
+#endif
diff --git a/demos/test/dh_tests.c b/testprof/dh_tests.c
similarity index 84%
rename from demos/test/dh_tests.c
rename to testprof/dh_tests.c
index 6977c58..feb74ac 100644
--- a/demos/test/dh_tests.c
+++ b/testprof/dh_tests.c
@@ -1,4 +1,4 @@
-#include "test.h"
+#include <tomcrypt_test.h>
 
 #ifdef MDH
 
@@ -12,8 +12,8 @@
   DO(dh_test());
 
   /* make up two keys */
-  DO(dh_make_key (&test_yarrow, find_prng ("yarrow"), 512, &usera));
-  DO(dh_make_key (&test_yarrow, find_prng ("yarrow"), 512, &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;
@@ -52,12 +52,12 @@
   dh_free (&userb);
 
 /* test encrypt_key */
-  dh_make_key (&test_yarrow, find_prng ("yarrow"), 512, &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));
@@ -76,7 +76,7 @@
      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));
diff --git a/demos/test/dsa_test.c b/testprof/dsa_test.c
similarity index 90%
rename from demos/test/dsa_test.c
rename to testprof/dsa_test.c
index c5eeb6d..cd2e89a 100644
--- a/demos/test/dsa_test.c
+++ b/testprof/dsa_test.c
@@ -1,4 +1,4 @@
-#include "test.h"
+#include <tomcrypt_test.h>
 
 #ifdef MDSA
 
@@ -10,7 +10,7 @@
    dsa_key key, key2;
 
    /* make a random key */
-   DO(dsa_make_key(&test_yarrow, find_prng("yarrow"), 20, 128, &key));
+   DO(dsa_make_key(&yarrow_prng, find_prng("yarrow"), 20, 128, &key));
 
    /* verify it */
    DO(dsa_verify_key(&key, &stat1));
@@ -18,7 +18,7 @@
 
    /* sign the message */
    x = sizeof(out);
-   DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &test_yarrow, find_prng("yarrow"), &key));
+   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));
diff --git a/demos/test/ecc_test.c b/testprof/ecc_test.c
similarity index 61%
rename from demos/test/ecc_test.c
rename to testprof/ecc_test.c
index eb66c58..0b37ba2 100644
--- a/demos/test/ecc_test.c
+++ b/testprof/ecc_test.c
@@ -1,4 +1,4 @@
-#include "test.h"
+#include <tomcrypt_test.h>
 
 #ifdef MECC
 
@@ -7,13 +7,13 @@
   unsigned char buf[4][4096];
   unsigned long x, y, z;
   int           stat, stat2;
-  ecc_key usera, userb;
+  ecc_key usera, userb, pubKey, privKey;
 	
   DO(ecc_test ());
 
   /* make up two keys */
-  DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &usera));
-  DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &userb));
+  DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), 65, &usera));
+  DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), 65, &userb));
 
   /* make the shared secret */
   x = 4096;
@@ -55,15 +55,24 @@
   ecc_free (&userb);
 
 /* test encrypt_key */
-  ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &usera);
+  DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), 65, &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, &test_yarrow, find_prng ("yarrow"), find_hash ("sha256"), &usera));
+  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, &usera));
+  DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &privKey));
   if (x != 32) {
     printf ("Failed (length)");
     return 1;
@@ -78,15 +87,17 @@
     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));
+  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, &usera));
+  DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &privKey));
   if (!(stat == 1 && stat2 == 0)) { 
-    printf("ecc_verify_hash failed");
+    printf("ecc_verify_hash failed %d, %d, ", stat, stat2);
     return 1;
   }
-  ecc_free (&usera);
+  ecc_free (&usera); 
+  ecc_free (&pubKey);
+  ecc_free (&privKey);
   return 0;
 }
 
diff --git a/testprof/mac_test.c b/testprof/mac_test.c
new file mode 100644
index 0000000..b076d7b
--- /dev/null
+++ b/testprof/mac_test.c
@@ -0,0 +1,31 @@
+/* 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;
+}
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..c9226fb
--- /dev/null
+++ b/testprof/makefile.icc
@@ -0,0 +1,15 @@
+CFLAGS += -I../src/headers -I./ -O3 -xP -ip 
+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 83%
rename from demos/test/modes_test.c
rename to testprof/modes_test.c
index 7494b4d..46beb8a 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,9 +12,9 @@
    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");
@@ -23,6 +23,7 @@
       return 1;
    }
    
+#ifdef CBC
    /* test CBC mode */
    /* encode the block */
    DO(cbc_start(cipher_idx, iv, key, 16, 0, &cbc));
@@ -32,21 +33,19 @@
       printf("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");
       return 1;
    }
-   
+#endif
+
+#ifdef CFB   
    /* test CFB mode */
    /* encode the block */
    DO(cfb_start(cipher_idx, iv, key, 16, 0, &cfb));
@@ -67,7 +66,9 @@
       printf("CFB failed");
       return 1;
    }
+#endif
    
+#ifdef OFB
    /* test OFB mode */
    /* encode the block */
    DO(ofb_start(cipher_idx, iv, key, 16, 0, &ofb));
@@ -87,7 +88,9 @@
       printf("OFB failed");
       return 1;
    }
-   
+#endif
+
+#ifdef CTR   
    /* test CTR mode */
    /* encode the block */
    DO(ctr_start(cipher_idx, iv, key, 16, 0, &ctr));
@@ -97,16 +100,17 @@
       printf("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) {
+   DO(ctr_decrypt(ct, tmp, 57, &ctr));
+   if (memcmp(tmp, pt, 57) != 0) {
       printf("CTR failed");
       return 1;
    }
+#endif
          
    return 0;
 }
diff --git a/demos/test/pkcs_1_test.c b/testprof/pkcs_1_test.c
similarity index 94%
rename from demos/test/pkcs_1_test.c
rename to testprof/pkcs_1_test.c
index 52af7b6..40cf630 100644
--- a/demos/test/pkcs_1_test.c
+++ b/testprof/pkcs_1_test.c
@@ -1,4 +1,4 @@
-#include "test.h"
+#include <tomcrypt_test.h>
 
 #ifdef PKCS_1
 
@@ -31,7 +31,7 @@
 
       /* 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_encode(buf[0], l3, modlen, &yarrow_prng, 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);
@@ -64,7 +64,7 @@
 
       /* 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));
+      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]);
@@ -86,7 +86,7 @@
 
       /* 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_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;
diff --git a/demos/test/rsa_test.c b/testprof/rsa_test.c
similarity index 65%
rename from demos/test/rsa_test.c
rename to testprof/rsa_test.c
index a6034dd..f114e49 100644
--- a/demos/test/rsa_test.c
+++ b/testprof/rsa_test.c
@@ -1,4 +1,4 @@
-#include "test.h"
+#include <tomcrypt_test.h>
 
 #ifdef MRSA 
 
@@ -8,7 +8,7 @@
 {
    unsigned char in[1024], out[1024], tmp[1024];
    rsa_key       key, privKey, pubKey;
-   int           hash_idx, prng_idx, stat, stat2;
+   int           hash_idx, prng_idx, stat, stat2, cnt;
    unsigned long rsa_msgsize, len, len2;
    static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
       
@@ -19,50 +19,89 @@
       return 1;
    }
    
-   /* make a random key */
-   DO(rsa_make_key(&test_yarrow, prng_idx, 1024/8, 65537, &key));
+   /* 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) {
+         printf("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);
+printf("N == \n");
+for (cnt = 0; cnt < len; ) {
+   printf("%02x ", tmp[cnt]);
+   if (!(++cnt & 15)) printf("\n");
+}
+
+len = mp_unsigned_bin_size(&key.p);
+mp_to_unsigned_bin(&key.p, tmp);
+printf("p == \n");
+for (cnt = 0; cnt < len; ) {
+   printf("%02x ", tmp[cnt]);
+   if (!(++cnt & 15)) printf("\n");
+}
+
+len = mp_unsigned_bin_size(&key.q);
+mp_to_unsigned_bin(&key.q, tmp);
+printf("\nq == \n");
+for (cnt = 0; cnt < len; ) {
+   printf("%02x ", tmp[cnt]);
+   if (!(++cnt & 15)) printf("\n");
+}
+printf("\n");
+
+
+         return 1;
+      }
+      if (cnt != 9) {
+         rsa_free(&key);
+      }
+   }
    
    /* test PKCS #1 v1.5 */
+   for (cnt = 0; cnt < 4; cnt++) {
    for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) {
       /* make a random key/msg */
-      yarrow_read(in, rsa_msgsize, &test_yarrow);
+      yarrow_read(in, rsa_msgsize, &yarrow_prng);
 
       len  = sizeof(out);
       len2 = rsa_msgsize;
 
       /* encrypt */
-      DO(rsa_v15_encrypt_key(in, rsa_msgsize, out, &len, &test_yarrow, prng_idx, &key));
-      DO(rsa_v15_decrypt_key(out, len, tmp, rsa_msgsize, &test_yarrow, prng_idx, &stat, &key));
+      DO(rsa_v15_encrypt_key(in, rsa_msgsize, out, &len, &yarrow_prng, prng_idx, &key));
+      DO(rsa_v15_decrypt_key(out, len, tmp, rsa_msgsize, &stat, &key));
       if (stat != 1 || memcmp(tmp, in, rsa_msgsize)) {
          printf("PKCS #1 v1.5 encrypt/decrypt failure (rsa_msgsize: %lu, stat: %d)\n", rsa_msgsize, stat);
-	 return 1;
+         return 1;
       }
    }
-   
+   }
+
    /* signature */
    len = sizeof(out);
-   DO(rsa_v15_sign_hash(in, 20, out, &len, &test_yarrow, prng_idx, hash_idx, &key));
+   DO(rsa_v15_sign_hash(in, 20, out, &len, hash_idx, &key));
    in[1] ^= 1;
-   DO(rsa_v15_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, &stat, &key));
+   DO(rsa_v15_verify_hash(out, len, in, 20, hash_idx, &stat, &key));
    in[1] ^= 1;
-   DO(rsa_v15_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, &stat2, &key));
+   DO(rsa_v15_verify_hash(out, len, in, 20, hash_idx, &stat2, &key));
    if (!(stat == 0 && stat2 == 1)) {
       printf("PKCS #1 v1.5 sign/verify failure (stat %d, stat2 %d)\n", stat, stat2);
       return 1;
    }
    
    /* 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, &test_yarrow);
+      yarrow_read(in, rsa_msgsize, &yarrow_prng);
 
       len  = sizeof(out);
       len2 = rsa_msgsize;
    
-      DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, NULL, 0, &test_yarrow, prng_idx, hash_idx, &key));
+      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, &test_yarrow, prng_idx, hash_idx, &stat2, &key));
+      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) {
@@ -71,7 +110,7 @@
       }
 
       len2 = rsa_msgsize;
-      DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, &test_yarrow, prng_idx, hash_idx, &stat, &key));
+      DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat, &key));
       if (!(stat == 1 && stat2 == 0)) {
          printf("rsa_decrypt_key failed");
          return 1;
@@ -98,15 +137,16 @@
          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), &test_yarrow, prng_idx, hash_idx, &key));
+      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), &test_yarrow, prng_idx, hash_idx, &stat2, &key));
+      DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key));
       if (len2 != rsa_msgsize) {
          printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
          return 1;
@@ -115,7 +155,7 @@
       out[8] ^= 1;
 
       len2 = rsa_msgsize;
-      DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), &test_yarrow, prng_idx, hash_idx, &stat, &key));
+      DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat, &key));
       if (!(stat == 1 && stat2 == 0)) {
          printf("rsa_decrypt_key failed");
          return 1;
@@ -128,7 +168,7 @@
 
    /* 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_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);
@@ -139,10 +179,10 @@
    DO(rsa_import(tmp, len2, &pubKey));
 
    /* verify with original */
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 0, &stat, &key));
+   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, &test_yarrow, prng_idx, hash_idx, 0, &stat2, &key));
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &key));
    
    if (!(stat == 1 && stat2 == 0)) {
       printf("rsa_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2);
@@ -155,10 +195,10 @@
    /* verify with privKey */
    /* change a byte */
    in[0] ^= 1;
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 0, &stat, &privKey));
+   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, &test_yarrow, prng_idx, hash_idx, 0, &stat2, &privKey));
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey));
    
    if (!(stat == 1 && stat2 == 0)) {
       printf("rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
@@ -171,10 +211,10 @@
    /* verify with pubKey */
    /* change a byte */
    in[0] ^= 1;
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 0, &stat, &pubKey));
+   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, &test_yarrow, prng_idx, hash_idx, 0, &stat2, &pubKey));
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &pubKey));
    
    if (!(stat == 1 && stat2 == 0)) {
       printf("rsa_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2);
@@ -186,11 +226,11 @@
 
    /* sign a message (salted) now (use privKey to make, pubKey to verify) */
    len = sizeof(out);
-   DO(rsa_sign_hash(in, 20, out, &len, &test_yarrow, prng_idx, hash_idx, 8, &privKey));
-   DO(rsa_verify_hash(out, len, in, 20, &test_yarrow, prng_idx, hash_idx, 8, &stat, &pubKey));
+   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, &test_yarrow, prng_idx, hash_idx, 8, &stat2, &pubKey));
+   DO(rsa_verify_hash(out, len, in, 20, hash_idx, 8, &stat2, &pubKey));
    
    if (!(stat == 1 && stat2 == 0)) {
       printf("rsa_verify_hash (salted) failed, %d, %d", stat, stat2);
diff --git a/demos/test/store_test.c b/testprof/store_test.c
similarity index 94%
rename from demos/test/store_test.c
rename to testprof/store_test.c
index e033594..41b2f92 100644
--- a/demos/test/store_test.c
+++ b/testprof/store_test.c
@@ -1,11 +1,11 @@
-#include "test.h"
+#include <tomcrypt_test.h>
 
 /* Test store/load macros with offsets */
 int store_test(void)
 {
   unsigned char buf[24];
-  unsigned long L, L1;
   int y;
+  ulong32 L, L1;
   ulong64 LL, LL1;
 
   L = 0x12345678UL;
diff --git a/testprof/test.c b/testprof/test.c
new file mode 100644
index 0000000..9f6df71
--- /dev/null
+++ b/testprof/test.c
@@ -0,0 +1,9 @@
+#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);
+   }
+}
diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h
new file mode 100644
index 0000000..fc28430
--- /dev/null
+++ b/testprof/tomcrypt_test.h
@@ -0,0 +1,73 @@
+
+#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
diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c
new file mode 100644
index 0000000..bcc25f4
--- /dev/null
+++ b/testprof/x86_prof.c
@@ -0,0 +1,1046 @@
+#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);
+
+   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[%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__
+      #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
+     __asm rdtsc
+   #elif defined _M_AMD64
+     return __rdtsc ();
+   #elif defined _M_IA64
+     #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;
+   printf("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) {
+     printf("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];
+
+  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, &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;
+    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_ECB ecb;
+  unsigned char key[MAXBLOCKSIZE], pt[4096];
+  int err;
+
+  printf ("\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;
+    printf("."); 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;
+
+  printf ("\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;
+    printf("."); fflush(stdout);
+    
+#undef DO2
+#undef DO1
+   }
+   tally_results(1);
+
+   return 0;
+}
+#else
+int time_cipher2(void) { printf("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;
+
+  printf ("\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);
+
+    /* 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;
+    printf("."); fflush(stdout);
+    
+#undef DO2
+#undef DO1
+   }
+   tally_results(1);
+
+   return 0;
+}
+#else
+int time_cipher3(void) { printf("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];
+
+
+  printf ("\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;
+    printf("."); 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;
+
+   printf("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;
+       }
+       printf("%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;
+
+   printf("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;
+       }
+       printf("%4lu bits: %9llu cycles\n", x*DIGIT_BIT, t2);
+   }
+   mp_clear_multi(&a,&b,NULL);
+
+#undef DO1
+#undef DO2
+}
+#else
+void time_mult(void) { printf("NO MULT\n"); }
+void time_sqr(void) { printf("NO SQR\n"); }
+#endif
+   
+void time_prng(void)
+{
+   ulong64 t1, t2;
+   unsigned char buf[4096];
+   prng_state tprng;
+   unsigned long x, y;
+   int           err;
+
+   printf("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) { printf("\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;
+      }
+      printf("%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;
+      }
+      printf("%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;
+       printf("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;
+       printf("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;
+       printf("RSA-%lu decrypt_key took %15llu cycles\n", x, t2);
+
+
+       rsa_free(&key);
+  }
+}
+#else
+void time_rsa(void) { printf("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[] = {160/8, 256/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;
+       printf("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;
+       printf("ECC-%lu encrypt_key took %15llu cycles\n", x*8, t2);
+       ecc_free(&key);
+  }
+}
+#else
+void time_ecc(void) { printf("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;
+       printf("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;
+       printf("DH-%4lu encrypt_key took %15llu cycles\n", x*8, t2);
+       dh_free(&key);
+  }
+}
+#else
+void time_dh(void) { printf("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;
+
+   printf("\nMAC Timings (cycles/byte on %dKB 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;
+   }
+   printf("OMAC-AES\t\t%9llu\n", t2/(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;
+   }
+   printf("PMAC-AES\t\t%9llu\n", t2/(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;
+   }
+   printf("PELICAN \t\t%9llu\n", t2/(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;
+   }
+   printf("HMAC-MD5\t\t%9llu\n", t2/(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;
+
+   printf("\nENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %dKB 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;
+   }
+   printf("EAX \t\t%9llu\n", t2/(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;
+   }
+   printf("OCB \t\t%9llu\n", t2/(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;
+   }
+   printf("CCM \t\t%9llu\n", t2/(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;
+   }
+   printf("GCM (no-precomp)\t%9llu\n", t2/(MAC_SIZE*1024));
+
+   {
+   gcm_state gcm;
+
+   if ((err = gcm_init(&gcm, cipher_idx, key, 16)) != CRYPT_OK) { printf("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;
+   }
+   printf("GCM (precomp)\t%9llu\n", t2/(MAC_SIZE*1024));
+   }
+
+#endif
+
+} 
+
+void time_encmacs(void)
+{
+   time_encmacs_(1);
+   time_encmacs_(4);
+   time_encmacs_(32);
+}
diff --git a/tim_exptmod.c b/tim_exptmod.c
deleted file mode 100644
index 67fe445..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 */ 
-   rlen = mp_unsigned_bin_size(n);
-   rtmp = XMALLOC(rlen);
-   if (rtmp == NULL) {
-      return CRYPT_MEM;
-   }
-
-   /* read in random value "r" */
-   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/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;
-}