Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Geofferey/dropbear
1 result
Show changes
Showing
with 3635 additions and 622 deletions
Loading
@@ -55,9 +55,9 @@ static const unsigned char OID_SEC521R1_BLOB[] = {0x2b, 0x81, 0x04, 0x00, 0x23};
Loading
@@ -55,9 +55,9 @@ static const unsigned char OID_SEC521R1_BLOB[] = {0x2b, 0x81, 0x04, 0x00, 0x23};
((unsigned long)(unsigned char)(cp)[3])) ((unsigned long)(unsigned char)(cp)[3]))
   
static int openssh_encrypted(const char *filename); static int openssh_encrypted(const char *filename);
static sign_key *openssh_read(const char *filename, char *passphrase); static sign_key *openssh_read(const char *filename, const char *passphrase);
static int openssh_write(const char *filename, sign_key *key, static int openssh_write(const char *filename, sign_key *key,
char *passphrase); const char *passphrase);
   
static int dropbear_write(const char*filename, sign_key * key); static int dropbear_write(const char*filename, sign_key * key);
static sign_key *dropbear_read(const char* filename); static sign_key *dropbear_read(const char* filename);
Loading
@@ -83,7 +83,7 @@ int import_encrypted(const char* filename, int filetype) {
Loading
@@ -83,7 +83,7 @@ int import_encrypted(const char* filename, int filetype) {
return 0; return 0;
} }
   
sign_key *import_read(const char *filename, char *passphrase, int filetype) { sign_key *import_read(const char *filename, const char *passphrase, int filetype) {
   
if (filetype == KEYFILE_OPENSSH) { if (filetype == KEYFILE_OPENSSH) {
return openssh_read(filename, passphrase); return openssh_read(filename, passphrase);
Loading
@@ -97,7 +97,7 @@ sign_key *import_read(const char *filename, char *passphrase, int filetype) {
Loading
@@ -97,7 +97,7 @@ sign_key *import_read(const char *filename, char *passphrase, int filetype) {
return NULL; return NULL;
} }
   
int import_write(const char *filename, sign_key *key, char *passphrase, int import_write(const char *filename, sign_key *key, const char *passphrase,
int filetype) { int filetype) {
   
if (filetype == KEYFILE_OPENSSH) { if (filetype == KEYFILE_OPENSSH) {
Loading
@@ -194,7 +194,7 @@ out:
Loading
@@ -194,7 +194,7 @@ out:
) )
   
/* cpl has to be less than 100 */ /* cpl has to be less than 100 */
static void base64_encode_fp(FILE * fp, unsigned char *data, static void base64_encode_fp(FILE * fp, const unsigned char *data,
int datalen, int cpl) int datalen, int cpl)
{ {
unsigned char out[100]; unsigned char out[100];
Loading
@@ -509,7 +509,7 @@ static int openssh_encrypted(const char *filename)
Loading
@@ -509,7 +509,7 @@ static int openssh_encrypted(const char *filename)
return ret; return ret;
} }
   
static sign_key *openssh_read(const char *filename, char * UNUSED(passphrase)) static sign_key *openssh_read(const char *filename, const char * UNUSED(passphrase))
{ {
struct openssh_key *key; struct openssh_key *key;
unsigned char *p; unsigned char *p;
Loading
@@ -828,7 +828,7 @@ static sign_key *openssh_read(const char *filename, char * UNUSED(passphrase))
Loading
@@ -828,7 +828,7 @@ static sign_key *openssh_read(const char *filename, char * UNUSED(passphrase))
} }
   
static int openssh_write(const char *filename, sign_key *key, static int openssh_write(const char *filename, sign_key *key,
char *passphrase) const char *passphrase)
{ {
buffer * keyblob = NULL; buffer * keyblob = NULL;
buffer * extrablob = NULL; /* used for calculated values to write */ buffer * extrablob = NULL; /* used for calculated values to write */
Loading
Loading
Loading
@@ -34,9 +34,9 @@ enum {
Loading
@@ -34,9 +34,9 @@ enum {
KEYFILE_SSHCOM KEYFILE_SSHCOM
}; };
   
int import_write(const char *filename, sign_key *key, char *passphrase, int import_write(const char *filename, sign_key *key, const char *passphrase,
int filetype); int filetype);
sign_key *import_read(const char *filename, char *passphrase, int filetype); sign_key *import_read(const char *filename, const char *passphrase, int filetype);
int import_encrypted(const char* filename, int filetype); int import_encrypted(const char* filename, int filetype);
   
#endif /* DROPBEAR_KEYIMPORT_H_ */ #endif /* DROPBEAR_KEYIMPORT_H_ */
dist: trusty
sudo: required
language: c
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
packages:
- clang-3.8
install:
- sudo apt-get update -qq
- sudo apt-get install libtommath-dev
before_script:
- gem install coveralls-lcov
- curl http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz | tar xz
- export PATH=$PATH:`pwd`/lcov-1.11/bin
- curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
- sudo apt-get install libtfm-dev=0.13-5
matrix:
fast_finish: true
branches:
only:
- master
- develop
- /^release\/.*$/
compiler:
- gcc
- clang
script:
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile V=1" "-DUSE_LTM -DLTM_DESC" "-ltommath"
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile.shared V=1" "-DUSE_TFM -DTFM_DESC" "-ltfm"
env:
- |
BUILDSCRIPT="check_source.sh"
BUILDNAME="CHECK_SOURCES"
BUILDOPTIONS=" "
- |
BUILDSCRIPT="scan_build.sh"
BUILDNAME="SCAN_BUILD"
BUILDOPTIONS=" "
- |
BUILDSCRIPT="coverage.sh"
BUILDNAME="COVERAGE"
BUILDOPTIONS=" "
- |
BUILDSCRIPT="run.sh"
BUILDNAME="STOCK"
BUILDOPTIONS=" "
- |
BUILDSCRIPT="run.sh"
BUILDNAME="EASY"
BUILDOPTIONS="-DLTC_EASY"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="SMALL"
BUILDOPTIONS="-DLTC_SMALL_CODE"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="NOTABLES"
BUILDOPTIONS="-DLTC_NO_TABLES"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="SMALL+NOTABLES"
BUILDOPTIONS="-DLTC_SMALL_CODE -DLTC_NO_TABLES"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK"
BUILDOPTIONS="-DLTC_CLEAN_STACK"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK+SMALL"
BUILDOPTIONS="-DLTC_SMALL_CODE -DLTC_CLEAN_STACK"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK+NOTABLES"
BUILDOPTIONS="-DLTC_NO_TABLES -DLTC_CLEAN_STACK"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK+NOTABLES+SMALL"
BUILDOPTIONS="-DLTC_NO_TABLES -DLTC_CLEAN_STACK -DLTC_SMALL_CODE"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="NO_FAST"
BUILDOPTIONS="-DLTC_NO_FAST"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="NO_FAST+NOTABLES"
BUILDOPTIONS="-DLTC_NO_FAST -DLTC_NO_TABLES"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="NO_ASM"
BUILDOPTIONS="-DLTC_NO_ASM"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="NO_TIMING_RESISTANCE"
BUILDOPTIONS="-DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE"
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="PTHREAD"
BUILDOPTIONS="-DLTC_PTHREAD"
- |
BUILDSCRIPT="run.sh"
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE+PTHREAD"
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING -DLTC_PTHREAD"
- |
BUILDSCRIPT="testbuild.sh"
BUILDNAME="NOTEST"
BUILDOPTIONS="-DLTC_NO_TEST"
- |
BUILDSCRIPT="testbuild.sh"
BUILDNAME="NOFILE"
BUILDOPTIONS="-DLTC_NO_FILE"
after_failure:
- cat test_std.txt
- cat test_err.txt
- cat tv.txt
after_script:
- cat gcc_1.txt
- cat gcc_2.txt
notifications:
irc: "chat.freenode.net#libtom-notifications"
LibTomCrypt is licensed under DUAL licensing terms.
Choose and use the license of your needs.
[LICENSE #1]
LibTomCrypt is public domain. As should all quality software be. LibTomCrypt is public domain. As should all quality software be.
   
Tom St Denis Tom St Denis
   
[/LICENSE #1]
[LICENSE #2]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
   
[/LICENSE #2]
This diff is collapsed.
#!/bin/bash #!/bin/bash
echo "$1 ($2, $3)..." echo "$1 ($2, $3)..."
make clean 1>/dev/null 2>/dev/null make clean 1>/dev/null 2>/dev/null
echo -n "building..." echo -n "building..."
CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j4 -f $3 test tv_gen 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && exit 1)
if [ -f /proc/cpuinfo ]
then
MAKE_JOBS=$(( ($(cat /proc/cpuinfo | grep -E '^processor[[:space:]]*:' | tail -n -1 | cut -d':' -f2) + 1) * 2 + 1 ))
else
MAKE_JOBS=8
fi
CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j$MAKE_JOBS -f $3 all_test 1>gcc_1.txt 2>gcc_2.txt
mret=$?
cnt=$(wc -l < gcc_2.txt)
# ignore 1 line since ar prints to stderr instead of stdout and ar is called for
# $(LIBNAME)
if [[ $mret -ne 0 ]] || [[ $cnt -gt 1 ]]; then
echo "build $1 failed! printing gcc_2.txt now for convenience"
cat gcc_2.txt
exit 1
fi
echo -n "testing..." echo -n "testing..."
if [ -a test ] && [ -f test ] && [ -x test ]; then if [ -a test ] && [ -f test ] && [ -x test ]; then
((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed" && cat test_err.txt && exit 1) ((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed, look at test_err.txt or tv.txt" && exit 1)
if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then
for f in *_tv.txt; do if (diff --ignore-case $f notes/$f) then true; else (echo "tv_gen $f failed" && rm -f testok.txt && exit 1); fi; done for f in *_tv.txt; do
# check for lines starting with '<' ($f might be a subset of notes/$f)
difftroubles=$(diff -i -w -B $f notes/$f | grep '^<')
if [ -n "$difftroubles" ]; then
echo "FAILURE: $f"
diff -i -w -B $f notes/$f
echo "tv_gen $f failed" && rm -f testok.txt && exit 1
else
true
fi
done
fi fi
fi fi
if [ -a testok.txt ] && [ -f testok.txt ]; then if [ -a testok.txt ] && [ -f testok.txt ]; then
if [ "$LTC_COVERAGE" != "" ]; then
./coverage_more.sh > test_coverage_more.txt || exit 1
lcov_opts="--capture --no-external --directory src -q"
lcov_out=$(echo coverage_$1_$2_$3 | tr ' -=+' '_')".info"
lcov $lcov_opts --output-file $lcov_out
fi
exit 0 exit 0
fi fi
exit 1 exit 1
   
# $Source: /cvs/libtom/libtomcrypt/build.sh,v $ # ref: $Format:%D$
# $Revision: 1.9 $ # git commit: $Format:%H$
# $Date: 2006/03/18 14:10:55 $ # commit time: $Format:%ai$
January 22nd, 2018
v1.18.1
-- Fix wrong SHA3 blocksizes, thanks to Claus Fischer for reporting this via Mail (PR #329)
-- Fix NULL-pointer dereference in `ccm_memory()` with LTC_CLEAN_STACK enabled (PR #327)
-- Fix `ccm_process()` being unable to process input buffers longer than 256 bytes (PR #326)
-- Fix the `register_all_{ciphers,hashes,prngs}()` return values (PR #316)
-- Fix some typos, warnings and duplicate prototypes in code & doc (PR's #310 #320 #321 #335)
-- Fix possible undefined behavior with LTC_PTHREAD (PR #337)
-- Fix some DER bugs (PR #339)
-- Fix CTR-mode when accelerator is used (OP-TEE/optee_os #2086)
-- Fix installation procedure (Issue #340)
October 10th, 2017
v1.18.0
-- Bugfix multi2
-- Bugfix Noekeon
-- Bugfix XTEA
-- Bugfix rng_get_bytes() on windows where we could read from c:\dev\random
-- Fixed the Bleichbacher Signature attack in PKCS#1 v1.5 EMSA, thanks to Alex Dent
-- Fixed a potential cache-based timing attack in CCM, thanks to Sebastian Verschoor
-- Fix GCM counter reuse and potential timing attacks in EAX, OCB and OCBv3,
thanks to Raphaël Jamet
-- Implement hardened RSA operations when CRT is used
-- Enabled timing resistant calculations of ECC and RSA operations per default
-- Applied some patches from the OLPC project regarding PKCS#1 and preventing
the hash algorithms from overflowing
-- Larry Bugbee contributed the necessary stuff to more easily call libtomcrypt
from a dynamic language like Python, as shown in his pyTomCrypt
-- Nikos Mavrogiannopoulos contributed RSA blinding and export of RSA and DSA keys
in OpenSSL/GnuTLS compatible format
-- Patrick Pelletier contributed a smart volley of patches
-- Christopher Brown contributed some patches and additions to ASN.1/DER
-- Pascal Brand of STMicroelectronics contributed patches regarding CCM, the
XTS mode and RSA private key operations with keys without CRT parameters
-- RC2 now also works with smaller key-sizes
-- Improved/extended several tests & demos
-- Hardened DSA and RSA by testing (through Karel's perl-CryptX)
against Google's "Wycheproof" and Kudelski Security's "CDF"
-- Fixed all compiler warnings
-- Fixed several build issues on FreeBSD, NetBSD, Linux x32 ABI, HP-UX/IA64,
Mac OS X, Windows (32&64bit, Cygwin, MingW & MSVC) ...
-- Re-worked all makefiles
-- Re-worked most PRNG's
-- The code is now verified by a linter, thanks to Francois Perrad
-- Documentation (crypt.pdf) is now built deterministically, thanks to Michael Stapelberg
-- Add Adler32 and CRC32 checksum algorithms
-- Add Base64-URL de-/encoding and some strict variants
-- Add Blake2b & Blake2s (hash & mac), thanks to Kelvin Sherlock
-- Add Camellia block cipher
-- Add ChaCha (stream cipher), Poly1305 (mac), ChaCha20Poly1305 (encauth)
-- Add constant-time mem-compare mem_neq()
-- Add DER GeneralizedTime de-/encoding
-- Add DSA and ECC key generation FIPS-186-4 compliance
-- Add HKDF, thanks to RyanC (especially for also providing documentation :-) )
-- Add OCBv3
-- Add PKCS#1 v1.5 mode of SSL3.0
-- Add PKCS#1 testvectors from RSA
-- Add PKCS#8 & X.509 import for RSA keys
-- Add stream cipher API
-- Add SHA3 & SHAKE
-- Add SHA512/256 and SHA512/224
-- Add Triple-DES 2-key mode, thanks to Paul Howarth
-- Brought back Diffie-Hellman
May 12th, 2007 May 12th, 2007
v1.17 -- Cryptography Research Inc. contributed another small volley of patches, one to fix __WCHAR_DEFINED__ for BSD platforms, v1.17 -- Cryptography Research Inc. contributed another small volley of patches, one to fix __WCHAR_DEFINED__ for BSD platforms,
another to silence MSVC warnings. another to silence MSVC warnings.
Loading
Loading
#!/bin/bash
# output version
bash printinfo.sh
make clean > /dev/null
echo "checking..."
./helper.pl --check-source --check-makefiles --check-defines|| exit 1
exit 0
# ref: $Format:%D$
# git commit: $Format:%H$
# commit time: $Format:%ai$
#!/bin/bash
set -e
if [ "$TRAVIS_CI" == "private" ]; then
exit 0
fi
if [ "$#" != "5" ]; then
echo "Usage is: ${0} \"coverage\" \"<prepend CFLAGS>\" \"<makefile>\" \"<append CFLAGS>\" <math library to link to>"
echo "CC=gcc ${0} \"coverage\" \" \" \"makefile\" \"-DUSE_LTM -DLTM_DESC -I../libtommath\" ../libtommath/libtommath.a"
exit -1
fi
if [ -z "$(echo $CC | grep "gcc")" ]; then
echo "no gcc detected, early exit success"
exit 0
fi
if [ "$(echo $3 | grep -v 'makefile[.]')" == "" ]; then
echo "only run $0 for the regular makefile, early exit success"
exit 0
fi
# output version
bash printinfo.sh
bash build.sh " $1" " $2" " $3 COVERAGE=1" "$4" "$5"
if [ -a testok.txt ] && [ -f testok.txt ]; then
echo
else
echo
echo "Test failed"
exit 1
fi
./coverage_more.sh > test_coverage_more.txt || { rm -f testok.txt && exit 1 ; }
make lcov-single
# if this was executed as './coverage.sh ...' create coverage locally
if [[ "${0%% *}" == "./${0##*/}" ]]; then
make lcov-html
else
coveralls-lcov coverage.info
fi
exit 0
# ref: $Format:%D$
# git commit: $Format:%H$
# commit time: $Format:%ai$
#!/bin/bash
set -e
./sizes
./constants
for i in $(for j in $(echo $(./hashsum -h | awk '/Algorithms/,EOF' | tail -n +2)); do echo $j; done | sort); do echo -n "$i: " && ./hashsum -a $i tests/test.key ; done > hashsum_tv.txt
difftroubles=$(diff -i -w -B hashsum_tv.txt notes/hashsum_tv.txt | grep '^<') || true
if [ -n "$difftroubles" ]; then
echo "FAILURE: hashsum_tv.tx"
diff -i -w -B hashsum_tv.txt notes/hashsum_tv.txt
echo "hashsum failed"
exit 1
else
echo "hashsum okay"
fi
exit 0
# ref: $Format:%D$
# git commit: $Format:%H$
# commit time: $Format:%ai$
#!/bin/bash
if [ $# -lt 2 ]
then
echo "usage is: ${0##*/} <path to coverity scan> <extra compiler options>"
echo "e.g. \"${0##*/} \"/usr/local/bin/coverity\" \"-DLTM_DESC -I/path/to/libtommath/\"\""
exit -1
fi
PATH=$PATH:$1/bin
make clean
rm -r cov-int/
myCflags=""
myCflags="$myCflags -O2 ${2}"
myCflags="$myCflags -pipe -Werror -Wpointer-arith -Winit-self -Wextra -Wall -Wformat -Wformat-security"
CFLAGS="$myCflags" cov-build --dir cov-int make -f makefile.unix $MAKE_OPTS IGNORE_SPEED=1 1>gcc_1.txt
if [ $? -ne 0 ]
then
echo "make failed"
exit -1
fi
# zipup everything
tar caf libtomcrypt.lzma cov-int
mytoken=$(cat .coverity_token)
mymail=$(cat .coverity_mail)
myversion=$(git describe --dirty)
curl -k --form project=libtomcrypt \
--form token=${mytoken} \
--form email=${mymail} \
--form file=@libtomcrypt.lzma \
--form version=\"${myversion}\" \
--form description="\"libtomcrypt version ${myversion}\"" \
https://scan.coverity.com/builds?project=libtom%2Flibtomcrypt
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
#include "tomcrypt.h"
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
#include <libgen.h>
#else
#define basename(x) x
#endif
/**
@file demo_crypt_constants.c
Demo how to get various constants to dynamic languages
like Python
Larry Bugbee, February 2013
*/
static void _print_line(const char* cmd, const char* desc)
{
printf(" %-16s - %s\n", cmd, desc);
}
int main(int argc, char **argv)
{
if (argc == 1) {
/* given a specific constant name, get and print its value */
char name[] = "CTR_COUNTER_BIG_ENDIAN";
int value;
char *names_list;
unsigned int names_list_len;
if (crypt_get_constant(name, &value) != 0) exit(EXIT_FAILURE);
printf("\n %s is %d \n\n", name, value);
/* get and print the length of the names (and values) list */
if (crypt_list_all_constants(NULL, &names_list_len) != 0) exit(EXIT_FAILURE);
printf(" need to allocate %u bytes \n\n", names_list_len);
/* get and print the names (and values) list */
if ((names_list = malloc(names_list_len)) == NULL) exit(EXIT_FAILURE);
if (crypt_list_all_constants(names_list, &names_list_len) != 0) exit(EXIT_FAILURE);
printf(" supported constants:\n\n%s\n\n", names_list);
free(names_list);
} else if (argc == 2) {
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
char* base = strdup(basename(argv[0]));
printf("Usage: %s [-a] [-s name]\n\n", base);
_print_line("<no argument>", "The old behavior of the demo");
_print_line("-a", "Only lists all constants");
_print_line("-s name", "List a single constant given as argument");
_print_line("-h", "The help you're looking at");
free(base);
} else if (strcmp(argv[1], "-a") == 0) {
char *names_list;
unsigned int names_list_len;
/* get and print the length of the names (and values) list */
if (crypt_list_all_constants(NULL, &names_list_len) != 0) exit(EXIT_FAILURE);
/* get and print the names (and values) list */
names_list = malloc(names_list_len);
if (crypt_list_all_constants(names_list, &names_list_len) != 0) exit(EXIT_FAILURE);
printf("%s\n", names_list);
}
} else if (argc == 3) {
if (strcmp(argv[1], "-s") == 0) {
int value;
if (crypt_get_constant(argv[2], &value) != 0) exit(EXIT_FAILURE);
printf("%s,%u\n", argv[2], value);
}
}
return 0;
}
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
"""
demo_dynamic.py v2b
This program demonstrates Python's use of the dynamic
language support additions to LTC, namely access to LTC
constants, struct and union sizes, and the binding of a
math package to LTC. Also provided are simple code
fragments to illustrate how one might write a Python
wrapper for LTC and how an app might call the wrapper.
This or a similar model should work for Ruby and other
dynamic languages.
This instance uses Python's ctypes and requires a single
.dylib linking together LTC and a math library. Building
a single .dylib is needed because LTC wants a fairly tight
relationship between itself and the mathlib. (ctypes can
load multiple .dylibs, but it does not support this level
of tight coupling between otherwise independent libraries.)
My .dylib was created on OSX/macOS with the following:
sudo make -j5 -f makefile.shared \
CFLAGS="-DUSE_TFM -DTFM_DESC -I/usr/local/include" \
EXTRALIBS=/usr/local/lib/libtfm.a install
For python 2.7.12 on Ubuntu Xenial the following worked for
me (without MPI support):
sudo make -f makefile.shared install PREFIX="/usr"
Reminder: you don't need to bind in a math library unless
you are going to use LTC functions that need a
mathlib. For example, public key crypto requires
a mathlib; hashing and symmetric encryption do not.
------
This code was originally written for Python 2.7 with the
ctypes standard library. This version is modified to run
under both Python 2.7 and 3.6.
Arguably the biggest change for Python3 has to do with
strings. Under Python2, native strings are ASCII bytes and
passing them to LTC is natural and requires no conversion.
Under Python3 all native strings are Unicode which requires
they be converted to bytes before use by LTC.
Note the following for Python3.
- ASCII keys, IVs and other string arguments must be
'bytes'. Define them with a 'b' prefix or convert
via the 'bytes()' function.
- "strings" returned from LTC are bytes and conversion
to Unicode might be necessary for proper printing.
If so, use <string>.decode('utf-8').
- The Python2 'print' statement becomes a function in
Python3 which requires parenthesis, eg. 'print()'.
NB: Unicode is achieved under Python2 by either defining
a Unicode string with a 'u' prefix or passing ASCII
strings thru the 'unicode()' function.
Larry Bugbee
March 2014 v1
August 2017 v2b
"""
import sys
from ctypes import *
from ctypes.util import find_library
# switches to enable/disable selected output
SHOW_ALL_CONSTANTS = True
SHOW_ALL_SIZES = True
SHOW_SELECTED_CONSTANTS = True
SHOW_SELECTED_SIZES = True
SHOW_BUILD_OPTIONS_ALGS = True
SHOW_SHA256_EXAMPLE = True
SHOW_CHACHA_EXAMPLE = True
print(' ')
print(' demo_dynamic.py')
def inprint(s, indent=0):
"prints strings indented, including multline strings"
for line in s.split('\n'):
print(' '*indent + line)
#-------------------------------------------------------------------------------
# load the .dylib
libname = 'tomcrypt'
libpath = find_library(libname)
print(' ')
print(' path to library %s: %s' % (libname, libpath))
LTC = cdll.LoadLibrary(libpath)
print(' loaded: %s' % LTC)
print(' ')
#-------------------------------------------------------------------------------
# get list of all supported constants followed by a list of all
# supported sizes. One alternative: these lists may be parsed
# and used as needed.
if SHOW_ALL_CONSTANTS:
print('-'*60)
print(' all supported constants and their values:')
# get size to allocate for constants output list
str_len = c_int(0)
ret = LTC.crypt_list_all_constants(None, byref(str_len))
print(' need to allocate %d bytes to build list \n' % str_len.value)
# allocate that size and get (name, size) pairs, each pair
# separated by a newline char.
names_sizes = c_buffer(str_len.value)
ret = LTC.crypt_list_all_constants(names_sizes, byref(str_len))
print(names_sizes.value.decode("utf-8"))
print(' ')
if SHOW_ALL_SIZES:
print('-'*60)
print(' all supported sizes:')
# get size to allocate for sizes output list
str_len = c_int(0)
ret = LTC.crypt_list_all_sizes(None, byref(str_len))
print(' need to allocate %d bytes to build list \n' % str_len.value)
# allocate that size and get (name, size) pairs, each pair
# separated by a newline char.
names_sizes = c_buffer(str_len.value)
ret = LTC.crypt_list_all_sizes(names_sizes, byref(str_len))
print(names_sizes.value.decode("utf-8"))
print(' ')
#-------------------------------------------------------------------------------
# get individually named constants and sizes
if SHOW_SELECTED_CONSTANTS:
print('-'*60)
print('\n selected constants:')
names = [
b'ENDIAN_LITTLE',
b'ENDIAN_64BITWORD',
b'PK_PUBLIC',
b'LTC_MILLER_RABIN_REPS',
b'CTR_COUNTER_BIG_ENDIAN',
]
for name in names:
const_value = c_int(0)
rc = LTC.crypt_get_constant(name, byref(const_value))
value = const_value.value
print(' %-25s %d' % (name.decode("utf-8"), value))
print(' ')
if SHOW_SELECTED_SIZES:
print('-'*60)
print('\n selected sizes:')
names = [
b'rijndael_key',
b'rsa_key',
b'symmetric_CTR',
b'twofish_key',
b'ecc_point',
b'gcm_state',
b'sha512_state',
]
for name in names:
size_value = c_int(0)
rc = LTC.crypt_get_size(name, byref(size_value))
value = size_value.value
print(' %-25s %d' % (name.decode("utf-8"), value))
print(' ')
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# LibTomCrypt exposes one interesting string that can be accessed
# via Python's ctypes module, "crypt_build_settings", which
# provides a list of this build's compiler switches and supported
# algorithms. If someday LTC exposes other interesting strings,
# they can be found with:
# nm /usr/local/lib/libtomcrypt.dylib | grep " D "
def get_named_string(lib, name):
return c_char_p.in_dll(lib, name).value.decode("utf-8")
if SHOW_BUILD_OPTIONS_ALGS:
print('-'*60)
print('This is a string compiled into LTC showing compile')
print('options and algorithms supported by this build \n')
# print(get_named_string(LTC, 'crypt_build_settings'))
inprint(get_named_string(LTC, 'crypt_build_settings'), 4)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# here is an example of how Python code can be written to access
# LTC's implementation of SHA256 and ChaCha,
# - - - - - - - - - - - - -
# definitions
from binascii import hexlify, unhexlify
def _err2str(err):
# define return type
errstr = LTC.error_to_string
errstr.restype = c_char_p
# get and return err string
return errstr(err)
def _get_size(name):
size = c_int(0)
rc = LTC.crypt_get_size(bytes(name), byref(size))
if rc != 0:
raise Exception('LTC.crypt_get_size(%s) rc = %d' % (name, rc))
return size.value
def _get_constant(name):
constant = c_int(0)
rc = LTC.crypt_get_constant(bytes(name), byref(constant))
if rc != 0:
raise Exception('LTC.crypt_get_constant(%s) rc = %d' % (name, rc))
return constant.value
CRYPT_OK = _get_constant(b'CRYPT_OK')
class SHA256(object):
def __init__(self):
self.state = c_buffer(_get_size(b'sha256_state'))
LTC.sha256_init(byref(self.state))
def update(self, data):
LTC.sha256_process(byref(self.state), data, len(data))
def digest(self):
md = c_buffer(32)
LTC.sha256_done(byref(self.state), byref(md))
return md.raw
class ChaCha(object):
def __init__(self, key, rounds):
self.state = c_buffer(_get_size(b'chacha_state'))
self.counter = c_int(1)
err = LTC.chacha_setup(byref(self.state), key, len(key), rounds)
if err != CRYPT_OK:
raise Exception('LTC.chacha_setup(), err = %d, "%s"' % (err, _err2str(err)))
def set_iv32(self, iv):
err = LTC.chacha_ivctr32(byref(self.state), iv, len(iv), byref(self.counter))
if err != CRYPT_OK:
raise Exception('LTC.chacha_ivctr32(), err = %d, "%s"' % (err, _err2str(err)))
def crypt(self, datain):
dataout = c_buffer(len(datain))
err = LTC.chacha_crypt(byref(self.state), datain, len(datain), byref(dataout))
if err != CRYPT_OK:
raise Exception('LTC.chacha_crypt(), err = %d, "%s"' % (err, _err2str(err)))
return dataout.raw
# - - - - - - - - - - - - -
# a SHA256 app fragment
if SHOW_SHA256_EXAMPLE:
print('-'*60)
data = b'hello world' # we want bytes, not Unicode
sha256 = SHA256()
sha256.update(data)
md = sha256.digest()
template = '\n the SHA256 digest for "%s" is %s \n'
print(template % (data, hexlify(md)))
# - - - - - - - - - - - - -
# a ChaCha app fragment
if SHOW_CHACHA_EXAMPLE:
print('-'*60)
key = b'hownowbrowncow\x00\x00' # exactly 16 or 32 bytes
rounds = 12 # common values: 8, 12, 20
iv = b'123456789012' # exactly 12 bytes
plain = b'Kilroy was here, there, and everywhere!'
cha = ChaCha(key, rounds)
cha.set_iv32(iv)
cipher = cha.crypt(plain)
template = '\n ChaCha%d ciphertext for "%s" is "%s"'
print(template % (rounds, plain, hexlify(cipher)))
cha.set_iv32(iv) # reset to decrypt
decrypted = cha.crypt(cipher)
template = ' ChaCha%d decoded text for "%s" is "%s" \n'
print(template % (rounds, plain, decrypted.decode("utf-8")))
# Footnote: Keys should be erased fm memory as soon as possible after use,
# and that includes Python. For a tip on how to do that in Python, see
# http://buggywhip.blogspot.com/2010/12/erase-keys-and-credit-card-numbers-in.html
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
/* /*
* Written by Daniel Richards <kyhwana@world-net.co.nz> 6/7/2002 * Written by Daniel Richards <kyhwana@world-net.co.nz> 6/7/2002
* hash.c: This app uses libtomcrypt to hash either stdin or a file * hash.c: This app uses libtomcrypt to hash either stdin or a file
Loading
@@ -9,111 +18,283 @@
Loading
@@ -9,111 +18,283 @@
   
#include <tomcrypt.h> #include <tomcrypt.h>
   
int errno; #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
#include <libgen.h>
#else
#define basename(x) x
#endif
   
void register_algs(); #if !defined(PATH_MAX) && defined(_MSC_VER)
#include <windows.h>
#define PATH_MAX MAX_PATH
#endif
   
int main(int argc, char **argv) /* thanks http://stackoverflow.com/a/8198009 */
#define _base(x) ((x >= '0' && x <= '9') ? '0' : \
(x >= 'a' && x <= 'f') ? 'a' - 10 : \
(x >= 'A' && x <= 'F') ? 'A' - 10 : \
'\255')
#define HEXOF(x) (x - _base(x))
static char* hashsum;
static void cleanup(void)
{ {
int idx, x, z; free(hashsum);
unsigned long w; }
unsigned char hash_buffer[MAXBLOCKSIZE];
hash_state md;
   
/* You need to register algorithms before using them */ static void die(int status)
register_algs(); {
if (argc < 2) { unsigned long w, x;
printf("usage: ./hash algorithm file [file ...]\n"); FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
printf("Algorithms:\n"); fprintf(o, "usage: %s -a algorithm [-c] [file...]\n\n", hashsum);
for (x = 0; hash_descriptor[x].name != NULL; x++) { fprintf(o, "\t-c\tCheck the hash(es) of the file(s) written in [file].\n");
printf(" %s (%d)\n", hash_descriptor[x].name, hash_descriptor[x].ID); fprintf(o, "\t\t(-a not required)\n");
fprintf(o, "\nAlgorithms:\n\t");
w = 0;
for (x = 0; hash_descriptor[x].name != NULL; x++) {
w += fprintf(o, "%-14s", hash_descriptor[x].name);
if (w >= 70) {
fprintf(o, "\n\t");
w = 0;
} }
exit(EXIT_SUCCESS);
} }
if (w != 0) fprintf(o, "\n");
exit(status);
}
   
idx = find_hash(argv[1]); static void printf_hex(unsigned char* hash_buffer, unsigned long w)
if (idx == -1) { {
fprintf(stderr, "\nInvalid hash specified on command line.\n"); unsigned long x;
return -1; for (x = 0; x < w; x++) {
printf("%02x",hash_buffer[x]);
} }
}
   
if (argc == 2) { static void check_file(int argn, int argc, char **argv)
hash_descriptor[idx].init(&md); {
do { int err, failed, invalid;
x = fread(hash_buffer, 1, sizeof(hash_buffer), stdin); unsigned char is_buffer[MAXBLOCKSIZE], should_buffer[MAXBLOCKSIZE];
hash_descriptor[idx].process(&md, hash_buffer, x); char buf[PATH_MAX + (MAXBLOCKSIZE * 3)];
} while (x == sizeof(hash_buffer)); /* iterate through all files */
hash_descriptor[idx].done(&md, hash_buffer); while(argn < argc) {
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) { char* s;
printf("%02x",hash_buffer[x]); FILE* f = fopen(argv[argn], "rb");
if(f == NULL) {
int n = snprintf(buf, sizeof(buf), "%s: %s", hashsum, argv[argn]);
if (n > 0 && n < (int)sizeof(buf))
perror(buf);
else
perror(argv[argn]);
exit(EXIT_FAILURE);
} }
printf(" (stdin)\n"); failed = 0;
} else { invalid = 0;
for (z = 2; z < argc; z++) { /* read the file line by line */
w = sizeof(hash_buffer); while((s = fgets(buf, sizeof(buf), f)) != NULL)
if ((errno = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) { {
printf("File hash error: %s\n", error_to_string(errno)); int tries, n;
} else { unsigned long hash_len, w, x;
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) { char* space = strstr(s, " ");
printf("%02x",hash_buffer[x]);
} /* skip lines with comments */
printf(" %s\n", argv[z]); if (buf[0] == '#') continue;
if (space == NULL) {
fprintf(stderr, "%s: no properly formatted checksum lines found\n", hashsum);
goto ERR;
}
hash_len = space - s;
hash_len /= 2;
if (hash_len > sizeof(should_buffer)) {
fprintf(stderr, "%s: hash too long\n", hashsum);
goto ERR;
}
/* convert the hex-string back to binary */
for (x = 0; x < hash_len; ++x) {
should_buffer[x] = HEXOF(s[x*2]) << 4 | HEXOF(s[x*2 + 1]);
} }
space++;
if (*space != '*') {
fprintf(stderr, "%s: unsupported input mode '%c'\n", hashsum, *space);
goto ERR;
}
space++;
for (n = 0; n < (buf + sizeof(buf)) - space; ++n) {
if(iscntrl((int)space[n])) {
space[n] = '\0';
break;
}
}
/* try all hash algorithms that have the appropriate hash size */
tries = 0;
for (x = 0; hash_descriptor[x].name != NULL; ++x) {
if (hash_descriptor[x].hashsize == hash_len) {
tries++;
w = sizeof(is_buffer);
if ((err = hash_file(x, space, is_buffer, &w)) != CRYPT_OK) {
fprintf(stderr, "%s: File hash error: %s: %s\n", hashsum, space, error_to_string(err));
ERR:
fclose(f);
exit(EXIT_FAILURE);
}
if(XMEMCMP(should_buffer, is_buffer, w) == 0) {
printf("%s: OK\n", space);
break;
}
}
} /* for */
if (hash_descriptor[x].name == NULL) {
if(tries > 0) {
printf("%s: FAILED\n", space);
failed++;
}
else {
invalid++;
}
}
} /* while */
fclose(f);
if(invalid) {
fprintf(stderr, "%s: WARNING: %d %s is improperly formatted\n", hashsum, invalid, invalid > 1?"lines":"line");
}
if(failed) {
fprintf(stderr, "%s: WARNING: %d computed %s did NOT match\n", hashsum, failed, failed > 1?"checksums":"checksum");
} }
argn++;
} }
return EXIT_SUCCESS; exit(EXIT_SUCCESS);
} }
   
void register_algs(void) int main(int argc, char **argv)
{ {
int err; int idxs[TAB_SIZE], idx, check, y, z, err, argn;
unsigned long w, x;
unsigned char hash_buffer[MAXBLOCKSIZE];
   
#ifdef LTC_TIGER hashsum = strdup(basename(argv[0]));
register_hash (&tiger_desc); atexit(cleanup);
#endif
#ifdef LTC_MD2 /* You need to register algorithms before using them */
register_hash (&md2_desc); register_all_ciphers();
#endif register_all_hashes();
#ifdef LTC_MD4 if (argc > 1 && (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0)) {
register_hash (&md4_desc); die(EXIT_SUCCESS);
#endif }
#ifdef LTC_MD5 if (argc < 3) {
register_hash (&md5_desc); die(EXIT_FAILURE);
#endif }
for (x = 0; x < sizeof(idxs)/sizeof(idxs[0]); ++x) {
idxs[x] = -2;
}
argn = 1;
check = 0;
idx = 0;
while(argn < argc){
if(strcmp("-a", argv[argn]) == 0) {
argn++;
if(argn < argc) {
idxs[idx] = find_hash(argv[argn]);
if (idxs[idx] == -1) {
struct {
const char* is;
const char* should;
} shasum_compat[] =
{
#ifdef LTC_SHA1 #ifdef LTC_SHA1
register_hash (&sha1_desc); { "1", sha1_desc.name },
#endif #endif
#ifdef LTC_SHA224 #ifdef LTC_SHA224
register_hash (&sha224_desc); { "224", sha224_desc.name },
#endif #endif
#ifdef LTC_SHA256 #ifdef LTC_SHA256
register_hash (&sha256_desc); { "256", sha256_desc.name },
#endif #endif
#ifdef LTC_SHA384 #ifdef LTC_SHA384
register_hash (&sha384_desc); { "384", sha384_desc.name },
#endif #endif
#ifdef LTC_SHA512 #ifdef LTC_SHA512
register_hash (&sha512_desc); { "512", sha512_desc.name },
#endif
#ifdef LTC_RIPEMD128
register_hash (&rmd128_desc);
#endif #endif
#ifdef LTC_RIPEMD160 #ifdef LTC_SHA512_224
register_hash (&rmd160_desc); { "512224", sha512_224_desc.name },
#endif #endif
#ifdef LTC_WHIRLPOOL #ifdef LTC_SHA512_256
register_hash (&whirlpool_desc); { "512256", sha512_256_desc.name },
#endif
#ifdef LTC_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 #endif
{ NULL, NULL }
};
for (x = 0; shasum_compat[x].is != NULL; ++x) {
if(XSTRCMP(shasum_compat[x].is, argv[argn]) == 0) {
idxs[idx] = find_hash(shasum_compat[x].should);
break;
}
}
}
if (idxs[idx] == -1) {
fprintf(stderr, "%s: Unrecognized algorithm\n", hashsum);
die(EXIT_FAILURE);
}
idx++;
if ((size_t)idx >= sizeof(idxs)/sizeof(idxs[0])) {
fprintf(stderr, "%s: Too many '-a' options chosen\n", hashsum);
die(EXIT_FAILURE);
}
argn++;
continue;
}
else {
die(EXIT_FAILURE);
}
}
if(strcmp("-c", argv[argn]) == 0) {
check = 1;
argn++;
continue;
}
break;
}
if (check == 1) {
check_file(argn, argc, argv);
}
   
if (argc == argn) {
w = sizeof(hash_buffer);
if ((err = hash_filehandle(idxs[0], stdin, hash_buffer, &w)) != CRYPT_OK) {
fprintf(stderr, "%s: File hash error: %s\n", hashsum, error_to_string(err));
return EXIT_FAILURE;
} else {
for (x = 0; x < w; x++) {
printf("%02x",hash_buffer[x]);
}
printf(" *-\n");
}
} else {
for (z = argn; z < argc; z++) {
for (y = 0; y < idx; ++y) {
w = sizeof(hash_buffer);
if ((err = hash_file(idxs[y],argv[z],hash_buffer,&w)) != CRYPT_OK) {
fprintf(stderr, "%s: File hash error: %s\n", hashsum, error_to_string(err));
return EXIT_FAILURE;
} else {
printf_hex(hash_buffer, w);
printf(" *%s\n", argv[z]);
}
}
}
}
return EXIT_SUCCESS;
} }
   
/* $Source$ */ /* ref: $Format:%D$ */
/* $Revision$ */ /* git commit: $Format:%H$ */
/* $Date$ */ /* commit time: $Format:%ai$ */
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
/* encrypt V1.1 Fri Oct 18 04:28:03 NZDT 2002 */
/* File de/encryption, using libtomcrypt */
/* Written by Daniel Richards <kyhwana@world-net.co.nz> */
/* Help from Tom St Denis with various bits */
/* This code is public domain, no rights reserved. */
/* Encrypts by default, -d flag enables decryption */
/* ie: ./encrypt blowfish story.txt story.ct */
/* ./encrypt -d blowfish story.ct story.pt */
#include <tomcrypt.h>
int usage(char *name)
{
int x;
printf("Usage encrypt: %s cipher infile outfile\n", name);
printf("Usage decrypt: %s -d cipher infile outfile\n", name);
printf("Usage test: %s -t cipher\nCiphers:\n", name);
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
printf("%s\n",cipher_descriptor[x].name);
}
exit(1);
}
int main(int argc, char *argv[])
{
unsigned char plaintext[512],ciphertext[512];
unsigned char tmpkey[512], key[MAXBLOCKSIZE], IV[MAXBLOCKSIZE];
unsigned char inbuf[512]; /* i/o block size */
unsigned long outlen, y, ivsize, x, decrypt;
symmetric_CTR ctr;
int cipher_idx, hash_idx, ks;
char *infile, *outfile, *cipher;
prng_state prng;
FILE *fdin, *fdout;
int err;
/* register algs, so they can be printed */
register_all_ciphers();
register_all_hashes();
register_all_prngs();
if (argc < 4) {
if ((argc > 2) && (!strcmp(argv[1], "-t"))) {
cipher = argv[2];
cipher_idx = find_cipher(cipher);
if (cipher_idx == -1) {
printf("Invalid cipher %s entered on command line.\n", cipher);
exit(-1);
} /* if */
if (cipher_descriptor[cipher_idx].test)
{
if (cipher_descriptor[cipher_idx].test() != CRYPT_OK)
{
printf("Error when testing cipher %s.\n", cipher);
exit(-1);
}
else
{
printf("Testing cipher %s succeeded.\n", cipher);
exit(0);
} /* if ... else */
} /* if */
}
return usage(argv[0]);
}
if (!strcmp(argv[1], "-d")) {
decrypt = 1;
cipher = argv[2];
infile = argv[3];
outfile = argv[4];
} else {
decrypt = 0;
cipher = argv[1];
infile = argv[2];
outfile = argv[3];
}
/* file handles setup */
fdin = fopen(infile,"rb");
if (fdin == NULL) {
perror("Can't open input for reading");
exit(-1);
}
fdout = fopen(outfile,"wb");
if (fdout == NULL) {
perror("Can't open output for writing");
exit(-1);
}
cipher_idx = find_cipher(cipher);
if (cipher_idx == -1) {
printf("Invalid cipher entered on command line.\n");
exit(-1);
}
hash_idx = find_hash("sha256");
if (hash_idx == -1) {
printf("LTC_SHA256 not found...?\n");
exit(-1);
}
ivsize = cipher_descriptor[cipher_idx].block_length;
ks = hash_descriptor[hash_idx].hashsize;
if (cipher_descriptor[cipher_idx].keysize(&ks) != CRYPT_OK) {
printf("Invalid keysize???\n");
exit(-1);
}
printf("\nEnter key: ");
if(fgets((char *)tmpkey,sizeof(tmpkey), stdin) == NULL)
exit(-1);
outlen = sizeof(key);
if ((err = hash_memory(hash_idx,tmpkey,strlen((char *)tmpkey),key,&outlen)) != CRYPT_OK) {
printf("Error hashing key: %s\n", error_to_string(err));
exit(-1);
}
if (decrypt) {
/* Need to read in IV */
if (fread(IV,1,ivsize,fdin) != ivsize) {
printf("Error reading IV from input.\n");
exit(-1);
}
if ((err = ctr_start(cipher_idx,IV,key,ks,0,CTR_COUNTER_LITTLE_ENDIAN,&ctr)) != CRYPT_OK) {
printf("ctr_start error: %s\n",error_to_string(err));
exit(-1);
}
/* IV done */
do {
y = fread(inbuf,1,sizeof(inbuf),fdin);
if ((err = ctr_decrypt(inbuf,plaintext,y,&ctr)) != CRYPT_OK) {
printf("ctr_decrypt error: %s\n", error_to_string(err));
exit(-1);
}
if (fwrite(plaintext,1,y,fdout) != y) {
printf("Error writing to file.\n");
exit(-1);
}
} while (y == sizeof(inbuf));
fclose(fdin);
fclose(fdout);
} else { /* encrypt */
/* Setup yarrow for random bytes for IV */
if ((err = rng_make_prng(128, find_prng("yarrow"), &prng, NULL)) != CRYPT_OK) {
printf("Error setting up PRNG, %s\n", error_to_string(err));
}
/* You can use rng_get_bytes on platforms that support it */
/* x = rng_get_bytes(IV,ivsize,NULL);*/
x = yarrow_read(IV,ivsize,&prng);
if (x != ivsize) {
printf("Error reading PRNG for IV required.\n");
exit(-1);
}
if (fwrite(IV,1,ivsize,fdout) != ivsize) {
printf("Error writing IV to output.\n");
exit(-1);
}
if ((err = ctr_start(cipher_idx,IV,key,ks,0,CTR_COUNTER_LITTLE_ENDIAN,&ctr)) != CRYPT_OK) {
printf("ctr_start error: %s\n",error_to_string(err));
exit(-1);
}
do {
y = fread(inbuf,1,sizeof(inbuf),fdin);
if ((err = ctr_encrypt(inbuf,ciphertext,y,&ctr)) != CRYPT_OK) {
printf("ctr_encrypt error: %s\n", error_to_string(err));
exit(-1);
}
if (fwrite(ciphertext,1,y,fdout) != y) {
printf("Error writing to output.\n");
exit(-1);
}
} while (y == sizeof(inbuf));
fclose(fdout);
fclose(fdin);
}
return 0;
}
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
/*
* Demo to do the rough equivalent of:
*
* openssl enc -aes-256-cbc -pass pass:foobar -in infile -out outfile -p
*
* Compilation:
*
* $(CC) -I /path/to/headers -L .../libs \
* -o openssl-enc \
* openssl-enc.c -ltomcrypt
*
* Usage:
*
* ./openssl-enc <enc|dec> infile outfile "passphrase" [salt]
*
* If provided, the salt must be EXACTLY a 16-char hex string.
*
* Demo is an example of:
*
* - (When decrypting) yanking salt out of the OpenSSL "Salted__..." header
* - OpenSSL-compatible key derivation (in OpenSSL's modified PKCS#5v1 approach)
* - Grabbing an Initialization Vector from the key generator
* - Performing simple block encryption using AES
* - PKCS#7-type padding (which hopefully can get ripped out of this demo and
* made a libtomcrypt thing someday).
*
* This program is free for all purposes without any express guarantee it
* works. If you really want to see a license here, assume the WTFPL :-)
*
* BJ Black, bblack@barracuda.com, https://wjblack.com
*
* BUGS:
* Passing a password on a command line is a HORRIBLE idea. Don't use
* this program for serious work!
*/
#include <tomcrypt.h>
#ifndef LTC_RIJNDAEL
#error Cannot compile this demo; Rijndael (AES) required
#endif
#ifndef LTC_CBC_MODE
#error Cannot compile this demo; CBC mode required
#endif
#ifndef LTC_PKCS_5
#error Cannot compile this demo; PKCS5 required
#endif
#ifndef LTC_RNG_GET_BYTES
#error Cannot compile this demo; random generator required
#endif
#ifndef LTC_MD5
#error Cannot compile this demo; MD5 required
#endif
/* OpenSSL by default only runs one hash round */
#define OPENSSL_ITERATIONS 1
/* Use aes-256-cbc, so 256 bits of key, 128 of IV */
#define KEY_LENGTH (256>>3)
#define IV_LENGTH (128>>3)
/* PKCS#5v1 requires exactly an 8-byte salt */
#define SALT_LENGTH 8
/* The header OpenSSL puts on an encrypted file */
static char salt_header[] = { 'S', 'a', 'l', 't', 'e', 'd', '_', '_' };
#include <errno.h>
#include <stdio.h>
#include <string.h>
/* A simple way to handle the possibility that a block may increase in size
after padding. */
union paddable {
unsigned char unpad[1024];
unsigned char pad[1024+MAXBLOCKSIZE];
};
/*
* Print usage and exit with a bad status (and perror() if any errno).
*
* Input: argv[0] and the error string
* Output: <no return>
* Side Effects: print messages and barf (does exit(3))
*/
void barf(const char *pname, const char *err)
{
printf("Usage: %s <enc|dec> infile outfile passphrase [salt]\n", pname);
printf("\n");
printf(" # encrypts infile->outfile, random salt\n");
printf(" %s enc infile outfile \"passphrase\"\n", pname);
printf("\n");
printf(" # encrypts infile->outfile, salt from cmdline\n");
printf(" %s enc infile outfile pass 0123456789abcdef\n", pname);
printf("\n");
printf(" # decrypts infile->outfile, pulls salt from infile\n");
printf(" %s dec infile outfile pass\n", pname);
printf("\n");
printf(" # decrypts infile->outfile, salt specified\n");
printf(" # (don't try to read the salt from infile)\n");
printf(" %s dec infile outfile pass 0123456789abcdef"
"\n", pname);
printf("\n");
printf("Application Error: %s\n", err);
if(errno)
perror(" System Error");
exit(-1);
}
/*
* Parse a salt value passed in on the cmdline.
*
* Input: string passed in and a buf to put it in (exactly 8 bytes!)
* Output: CRYPT_OK if parsed OK, CRYPT_ERROR if not
* Side Effects: none
*/
int parse_hex_salt(unsigned char *in, unsigned char *out)
{
int idx;
for(idx=0; idx<SALT_LENGTH; idx++)
if(sscanf((char*)in+idx*2, "%02hhx", out+idx) != 1)
return CRYPT_ERROR;
return CRYPT_OK;
}
/*
* Parse the Salted__[+8 bytes] from an OpenSSL-compatible file header.
*
* Input: file to read from and a to put the salt in (exactly 8 bytes!)
* Output: CRYPT_OK if parsed OK, CRYPT_ERROR if not
* Side Effects: infile's read pointer += 16
*/
int parse_openssl_header(FILE *in, unsigned char *out)
{
unsigned char tmp[SALT_LENGTH];
if(fread(tmp, 1, sizeof(tmp), in) != sizeof(tmp))
return CRYPT_ERROR;
if(memcmp(tmp, salt_header, sizeof(tmp)))
return CRYPT_ERROR;
if(fread(tmp, 1, sizeof(tmp), in) != sizeof(tmp))
return CRYPT_ERROR;
memcpy(out, tmp, sizeof(tmp));
return CRYPT_OK;
}
/*
* Dump a hexed stream of bytes (convenience func).
*
* Input: buf to read from, length
* Output: none
* Side Effects: bytes printed as a hex blob, no lf at the end
*/
void dump_bytes(unsigned char *in, unsigned long len)
{
unsigned long idx;
for(idx=0; idx<len; idx++)
printf("%02hhX", *(in+idx));
}
/*
* Pad or unpad a message using PKCS#7 padding.
* Padding will add 1-(blocksize) bytes and unpadding will remove that amount.
* Set is_padding to 1 to pad, 0 to unpad.
*
* Input: paddable buffer, size read, block length of cipher, mode
* Output: number of bytes after padding resp. after unpadding
* Side Effects: none
*/
size_t pkcs7_pad(union paddable *buf, size_t nb, int block_length,
int is_padding)
{
unsigned char padval;
off_t idx;
if(is_padding) {
/* We are PADDING this block (and therefore adding bytes) */
/* The pad value in PKCS#7 is the number of bytes remaining in
the block, so for a 16-byte block and 3 bytes left, it's
0x030303. In the oddball case where nb is an exact multiple
multiple of block_length, set the padval to blocksize (i.e.
add one full block) */
padval = (unsigned char) (block_length - (nb % block_length));
padval = padval ? padval : block_length;
memset(buf->pad+nb, padval, padval);
return nb+padval;
} else {
/* We are UNPADDING this block (and removing bytes)
We really just need to verify that the pad bytes are correct,
so start at the end of the string and work backwards. */
/* Figure out what the padlength should be by looking at the
last byte */
idx = nb-1;
padval = buf->pad[idx];
/* padval must be nonzero and <= block length */
if(padval <= 0 || padval > block_length)
return 0;
/* First byte's accounted for; do the rest */
idx--;
while(idx >= (off_t)(nb-padval))
if(buf->pad[idx] != padval)
return 0;
else
idx--;
/* If we got here, the pad checked out, so return a smaller
number of bytes than nb (basically where we left off+1) */
return idx+1;
}
}
/*
* Perform an encrypt/decrypt operation to/from files using AES+CBC+PKCS7 pad.
* Set encrypt to 1 to encrypt, 0 to decrypt.
*
* Input: in/out files, key, iv, and mode
* Output: CRYPT_OK if no error
* Side Effects: bytes slurped from infile, pushed to outfile, fds updated.
*/
int do_crypt(FILE *infd, FILE *outfd, unsigned char *key, unsigned char *iv,
int encrypt)
{
union paddable inbuf, outbuf;
int cipher, ret;
symmetric_CBC cbc;
size_t nb;
/* Register your cipher! */
cipher = register_cipher(&aes_desc);
if(cipher == -1)
return CRYPT_INVALID_CIPHER;
/* Start a CBC session with cipher/key/val params */
ret = cbc_start(cipher, iv, key, KEY_LENGTH, 0, &cbc);
if( ret != CRYPT_OK )
return -1;
do {
/* Get bytes from the source */
nb = fread(inbuf.unpad, 1, sizeof(inbuf.unpad), infd);
if(!nb)
return encrypt ? CRYPT_OK : CRYPT_ERROR;
/* Barf if we got a read error */
if(ferror(infd))
return CRYPT_ERROR;
if(encrypt) {
/* We're encrypting, so pad first (if at EOF) and then
crypt */
if(feof(infd))
nb = pkcs7_pad(&inbuf, nb,
aes_desc.block_length, 1);
ret = cbc_encrypt(inbuf.pad, outbuf.pad, nb, &cbc);
if(ret != CRYPT_OK)
return ret;
} else {
/* We're decrypting, so decrypt and then unpad if at
EOF */
ret = cbc_decrypt(inbuf.unpad, outbuf.unpad, nb, &cbc);
if( ret != CRYPT_OK )
return ret;
if( feof(infd) )
nb = pkcs7_pad(&outbuf, nb,
aes_desc.block_length, 0);
if(nb == 0)
/* The file didn't decrypt correctly */
return CRYPT_ERROR;
}
/* Push bytes to outfile */
if(fwrite(outbuf.unpad, 1, nb, outfd) != nb)
return CRYPT_ERROR;
} while(!feof(infd));
/* Close up */
cbc_done(&cbc);
return CRYPT_OK;
}
/* Convenience macro for the various barfable places below */
#define BARF(a) { \
if(infd) fclose(infd); \
if(outfd) { fclose(outfd); remove(argv[3]); } \
barf(argv[0], a); \
}
/*
* The main routine. Mostly validate cmdline params, open files, run the KDF,
* and do the crypt.
*/
int main(int argc, char *argv[]) {
unsigned char salt[SALT_LENGTH];
FILE *infd = NULL, *outfd = NULL;
int encrypt = -1;
int hash = -1;
int ret;
unsigned char keyiv[KEY_LENGTH + IV_LENGTH];
unsigned long keyivlen = (KEY_LENGTH + IV_LENGTH);
unsigned char *key, *iv;
/* Check proper number of cmdline args */
if(argc < 5 || argc > 6)
BARF("Invalid number of arguments");
/* Check proper mode of operation */
if (!strncmp(argv[1], "enc", 3))
encrypt = 1;
else if(!strncmp(argv[1], "dec", 3))
encrypt = 0;
else
BARF("Bad command name");
/* Check we can open infile/outfile */
infd = fopen(argv[2], "rb");
if(infd == NULL)
BARF("Could not open infile");
outfd = fopen(argv[3], "wb");
if(outfd == NULL)
BARF("Could not open outfile");
/* Get the salt from wherever */
if(argc == 6) {
/* User-provided */
if(parse_hex_salt((unsigned char*) argv[5], salt) != CRYPT_OK)
BARF("Bad user-specified salt");
} else if(!strncmp(argv[1], "enc", 3)) {
/* Encrypting; get from RNG */
if(rng_get_bytes(salt, sizeof(salt), NULL) != sizeof(salt))
BARF("Not enough random data");
} else {
/* Parse from infile (decrypt only) */
if(parse_openssl_header(infd, salt) != CRYPT_OK)
BARF("Invalid OpenSSL header in infile");
}
/* Fetch the MD5 hasher for PKCS#5 */
hash = register_hash(&md5_desc);
if(hash == -1)
BARF("Could not register MD5 hash");
/* Set things to a sane initial state */
zeromem(keyiv, sizeof(keyiv));
key = keyiv + 0; /* key comes first */
iv = keyiv + KEY_LENGTH; /* iv comes next */
/* Run the key derivation from the provided passphrase. This gets us
the key and iv. */
ret = pkcs_5_alg1_openssl((unsigned char*)argv[4], strlen(argv[4]), salt,
OPENSSL_ITERATIONS, hash, keyiv, &keyivlen );
if(ret != CRYPT_OK)
BARF("Could not derive key/iv from passphrase");
/* Display the salt/key/iv like OpenSSL cmdline does when -p */
printf("salt="); dump_bytes(salt, sizeof(salt)); printf("\n");
printf("key="); dump_bytes(key, KEY_LENGTH); printf("\n");
printf("iv ="); dump_bytes(iv, IV_LENGTH ); printf("\n");
/* If we're encrypting, write the salt header as OpenSSL does */
if(!strncmp(argv[1], "enc", 3)) {
if(fwrite(salt_header, 1, sizeof(salt_header), outfd) !=
sizeof(salt_header) )
BARF("Error writing salt header to outfile");
if(fwrite(salt, 1, sizeof(salt), outfd) != sizeof(salt))
BARF("Error writing salt to outfile");
}
/* At this point, the files are open, the salt has been figured out,
and we're ready to pump data through crypt. */
/* Do the crypt operation */
if(do_crypt(infd, outfd, key, iv, encrypt) != CRYPT_OK)
BARF("Error during crypt operation");
/* Clean up */
fclose(infd); fclose(outfd);
return 0;
}
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
#include "tomcrypt.h"
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
#include <libgen.h>
#else
#define basename(x) x
#endif
/**
@file demo_crypt_sizes.c
Demo how to get various sizes to dynamic languages
like Python - Larry Bugbee, February 2013
*/
static void _print_line(const char* cmd, const char* desc)
{
printf(" %-16s - %s\n", cmd, desc);
}
int main(int argc, char **argv)
{
if (argc == 1) {
/* given a specific size name, get and print its size */
char name[] = "ltc_hash_descriptor";
unsigned int size;
char *sizes_list;
unsigned int sizes_list_len;
if (crypt_get_size(name, &size) != 0) exit(EXIT_FAILURE);
printf("\n size of '%s' is %u \n\n", name, size);
/* get and print the length of the names (and sizes) list */
if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE);
printf(" need to allocate %u bytes \n\n", sizes_list_len);
/* get and print the names (and sizes) list */
sizes_list = malloc(sizes_list_len);
if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
printf(" supported sizes:\n\n%s\n\n", sizes_list);
} else if (argc == 2) {
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
char* base = strdup(basename(argv[0]));
printf("Usage: %s [-a] [-s name]\n\n", base);
_print_line("<no argument>", "The old behavior of the demo");
_print_line("-a", "Only lists all sizes");
_print_line("-s name", "List a single size given as argument");
_print_line("-h", "The help you're looking at");
free(base);
} else if (strcmp(argv[1], "-a") == 0) {
char *sizes_list;
unsigned int sizes_list_len;
/* get and print the length of the names (and sizes) list */
if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE);
/* get and print the names (and sizes) list */
sizes_list = malloc(sizes_list_len);
if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
printf("%s\n", sizes_list);
}
} else if (argc == 3) {
if (strcmp(argv[1], "-s") == 0) {
unsigned int size;
if (crypt_get_size(argv[2], &size) != 0) exit(EXIT_FAILURE);
printf("%s,%u\n", argv[2], size);
}
}
return 0;
}
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
/* small demo app that just includes a cipher/hash/prng */ /* small demo app that just includes a cipher/hash/prng */
#include <tomcrypt.h> #include <tomcrypt.h>
   
Loading
@@ -9,6 +17,6 @@ int main(void)
Loading
@@ -9,6 +17,6 @@ int main(void)
return 0; return 0;
} }
   
/* $Source$ */ /* ref: $Format:%D$ */
/* $Revision$ */ /* git commit: $Format:%H$ */
/* $Date$ */ /* commit time: $Format:%ai$ */
This diff is collapsed.
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
*
* LibTomCrypt is a library that provides various cryptographic
* algorithms in a highly modular and flexible manner.
*
* The library is free for all purposes without any express
* guarantee it works.
*/
#include <tomcrypt.h> #include <tomcrypt.h>
   
void reg_algs(void)
{
int err;
#ifdef LTC_RIJNDAEL
register_cipher (&aes_desc);
#endif
#ifdef LTC_BLOWFISH
register_cipher (&blowfish_desc);
#endif
#ifdef LTC_XTEA
register_cipher (&xtea_desc);
#endif
#ifdef LTC_RC5
register_cipher (&rc5_desc);
#endif
#ifdef LTC_RC6
register_cipher (&rc6_desc);
#endif
#ifdef LTC_SAFERP
register_cipher (&saferp_desc);
#endif
#ifdef LTC_TWOFISH
register_cipher (&twofish_desc);
#endif
#ifdef LTC_SAFER
register_cipher (&safer_k64_desc);
register_cipher (&safer_sk64_desc);
register_cipher (&safer_k128_desc);
register_cipher (&safer_sk128_desc);
#endif
#ifdef LTC_RC2
register_cipher (&rc2_desc);
#endif
#ifdef LTC_DES
register_cipher (&des_desc);
register_cipher (&des3_desc);
#endif
#ifdef LTC_CAST5
register_cipher (&cast5_desc);
#endif
#ifdef LTC_NOEKEON
register_cipher (&noekeon_desc);
#endif
#ifdef LTC_SKIPJACK
register_cipher (&skipjack_desc);
#endif
#ifdef LTC_ANUBIS
register_cipher (&anubis_desc);
#endif
#ifdef LTC_KHAZAD
register_cipher (&khazad_desc);
#endif
#ifdef LTC_TIGER
register_hash (&tiger_desc);
#endif
#ifdef LTC_MD2
register_hash (&md2_desc);
#endif
#ifdef LTC_MD4
register_hash (&md4_desc);
#endif
#ifdef LTC_MD5
register_hash (&md5_desc);
#endif
#ifdef LTC_SHA1
register_hash (&sha1_desc);
#endif
#ifdef LTC_SHA224
register_hash (&sha224_desc);
#endif
#ifdef LTC_SHA256
register_hash (&sha256_desc);
#endif
#ifdef LTC_SHA384
register_hash (&sha384_desc);
#endif
#ifdef LTC_SHA512
register_hash (&sha512_desc);
#endif
#ifdef LTC_RIPEMD128
register_hash (&rmd128_desc);
#endif
#ifdef LTC_RIPEMD160
register_hash (&rmd160_desc);
#endif
#ifdef LTC_WHIRLPOOL
register_hash (&whirlpool_desc);
#endif
#ifdef LTC_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
#ifdef USE_LTM
ltc_mp = ltm_desc;
#elif defined(USE_TFM)
ltc_mp = tfm_desc;
#elif defined(USE_GMP)
ltc_mp = gmp_desc;
#else
extern ltc_math_descriptor EXT_MATH_LIB;
ltc_mp = EXT_MATH_LIB;
#endif
}
void hash_gen(void) void hash_gen(void)
{ {
unsigned char md[MAXBLOCKSIZE], *buf; unsigned char md[MAXBLOCKSIZE], *buf;
unsigned long outlen, x, y, z; unsigned long outlen, x, y, z;
FILE *out; FILE *out;
int err; int err;
out = fopen("hash_tv.txt", "w"); out = fopen("hash_tv.txt", "w");
if (out == NULL) { if (out == NULL) {
perror("can't open hash_tv"); perror("can't open hash_tv");
} }
fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n"); fprintf(out, "Hash Test Vectors:\n\nThese are the hashes of nn bytes '00 01 02 03 .. (nn-1)'\n\n");
for (x = 0; hash_descriptor[x].name != NULL; x++) { for (x = 0; hash_descriptor[x].name != NULL; x++) {
buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1); buf = XMALLOC(2 * hash_descriptor[x].blocksize + 1);
Loading
@@ -160,16 +56,16 @@ void cipher_gen(void)
Loading
@@ -160,16 +56,16 @@ void cipher_gen(void)
int err, kl, lastkl; int err, kl, lastkl;
FILE *out; FILE *out;
symmetric_key skey; symmetric_key skey;
out = fopen("cipher_tv.txt", "w"); out = fopen("cipher_tv.txt", "w");
fprintf(out, fprintf(out,
"Cipher Test Vectors\n\nThese are test encryptions with key of nn bytes '00 01 02 03 .. (nn-1)' and original PT of the same style.\n" "Cipher Test Vectors\n\nThese are test encryptions with key of nn bytes '00 01 02 03 .. (nn-1)' and original PT of the same style.\n"
"The output of step N is used as the key and plaintext for step N+1 (key bytes repeated as required to fill the key)\n\n"); "The output of step N is used as the key and plaintext for step N+1 (key bytes repeated as required to fill the key)\n\n");
for (x = 0; cipher_descriptor[x].name != NULL; x++) { for (x = 0; cipher_descriptor[x].name != NULL; x++) {
fprintf(out, "Cipher: %s\n", cipher_descriptor[x].name); fprintf(out, "Cipher: %s\n", cipher_descriptor[x].name);
/* three modes, smallest, medium, large keys */ /* three modes, smallest, medium, large keys */
lastkl = 10000; lastkl = 10000;
for (y = 0; y < 3; y++) { for (y = 0; y < 3; y++) {
Loading
@@ -199,7 +95,7 @@ void cipher_gen(void)
Loading
@@ -199,7 +95,7 @@ void cipher_gen(void)
printf("setup error: %s\n", error_to_string(err)); printf("setup error: %s\n", error_to_string(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) { for (z = 0; (int)z < cipher_descriptor[x].block_length; z++) {
pt[z] = (unsigned char)z; pt[z] = (unsigned char)z;
} }
Loading
@@ -226,7 +122,7 @@ void cipher_gen(void)
Loading
@@ -226,7 +122,7 @@ void cipher_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
} }
   
void hmac_gen(void) void hmac_gen(void)
{ {
Loading
@@ -234,17 +130,17 @@ void hmac_gen(void)
Loading
@@ -234,17 +130,17 @@ void hmac_gen(void)
int x, y, z, err; int x, y, z, err;
FILE *out; FILE *out;
unsigned long len; unsigned long len;
out = fopen("hmac_tv.txt", "w"); out = fopen("hmac_tv.txt", "w");
   
fprintf(out, fprintf(out,
"LTC_HMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are LTC_HMACed. The initial key is\n" "HMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are HMACed. The initial key is\n"
"of the same format (the same length as the HASH output size). The LTC_HMAC key in step N+1 is the LTC_HMAC output of\n" "of the same format (the same length as the HASH output size). The HMAC key in step N+1 is the HMAC output of\n"
"step N.\n\n"); "step N.\n\n");
   
for (x = 0; hash_descriptor[x].name != NULL; x++) { for (x = 0; hash_descriptor[x].name != NULL; x++) {
fprintf(out, "LTC_HMAC-%s\n", hash_descriptor[x].name); fprintf(out, "HMAC-%s\n", hash_descriptor[x].name);
/* initial key */ /* initial key */
for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) { for (y = 0; y < (int)hash_descriptor[x].hashsize; y++) {
key[y] = (y&255); key[y] = (y&255);
Loading
@@ -255,7 +151,7 @@ void hmac_gen(void)
Loading
@@ -255,7 +151,7 @@ void hmac_gen(void)
perror("Can't malloc memory"); perror("Can't malloc memory");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) { for (y = 0; y <= (int)(hash_descriptor[x].blocksize * 2); y++) {
for (z = 0; z < y; z++) { for (z = 0; z < y; z++) {
input[z] = (unsigned char)(z & 255); input[z] = (unsigned char)(z & 255);
Loading
@@ -279,19 +175,20 @@ void hmac_gen(void)
Loading
@@ -279,19 +175,20 @@ void hmac_gen(void)
} }
fclose(out); fclose(out);
} }
void omac_gen(void) void omac_gen(void)
{ {
#ifdef LTC_OMAC
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2]; unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
int err, x, y, z, kl; int err, x, y, z, kl;
FILE *out; FILE *out;
unsigned long len; unsigned long len;
out = fopen("omac_tv.txt", "w"); out = fopen("omac_tv.txt", "w");
   
fprintf(out, fprintf(out,
"LTC_OMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are LTC_OMAC'ed. The initial key is\n" "OMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are OMAC'ed. The initial key is\n"
"of the same format (length specified per cipher). The LTC_OMAC key in step N+1 is the LTC_OMAC output of\n" "of the same format (length specified per cipher). The OMAC key in step N+1 is the OMAC output of\n"
"step N (repeated as required to fill the array).\n\n"); "step N (repeated as required to fill the array).\n\n");
   
for (x = 0; cipher_descriptor[x].name != NULL; x++) { for (x = 0; cipher_descriptor[x].name != NULL; x++) {
Loading
@@ -303,13 +200,13 @@ void omac_gen(void)
Loading
@@ -303,13 +200,13 @@ void omac_gen(void)
if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) { if (cipher_descriptor[x].keysize(&kl) != CRYPT_OK) {
kl = cipher_descriptor[x].max_key_length; kl = cipher_descriptor[x].max_key_length;
} }
fprintf(out, "LTC_OMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl); fprintf(out, "OMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
/* initial key/block */ /* initial key/block */
for (y = 0; y < kl; y++) { for (y = 0; y < kl; y++) {
key[y] = (y & 255); key[y] = (y & 255);
} }
for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) { for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
for (z = 0; z < y; z++) { for (z = 0; z < y; z++) {
input[z] = (unsigned char)(z & 255); input[z] = (unsigned char)(z & 255);
Loading
@@ -333,20 +230,22 @@ void omac_gen(void)
Loading
@@ -333,20 +230,22 @@ void omac_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
#endif
} }
   
void pmac_gen(void) void pmac_gen(void)
{ {
#ifdef LTC_PMAC
unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2]; unsigned char key[MAXBLOCKSIZE], output[MAXBLOCKSIZE], input[MAXBLOCKSIZE*2+2];
int err, x, y, z, kl; int err, x, y, z, kl;
FILE *out; FILE *out;
unsigned long len; unsigned long len;
out = fopen("pmac_tv.txt", "w"); out = fopen("pmac_tv.txt", "w");
   
fprintf(out, fprintf(out,
"PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are LTC_OMAC'ed. The initial key is\n" "PMAC Tests. In these tests messages of N bytes long (00,01,02,...,NN-1) are PMAC'ed. The initial key is\n"
"of the same format (length specified per cipher). The LTC_OMAC key in step N+1 is the LTC_OMAC output of\n" "of the same format (length specified per cipher). The PMAC key in step N+1 is the PMAC output of\n"
"step N (repeated as required to fill the array).\n\n"); "step N (repeated as required to fill the array).\n\n");
   
for (x = 0; cipher_descriptor[x].name != NULL; x++) { for (x = 0; cipher_descriptor[x].name != NULL; x++) {
Loading
@@ -359,12 +258,12 @@ void pmac_gen(void)
Loading
@@ -359,12 +258,12 @@ void pmac_gen(void)
kl = cipher_descriptor[x].max_key_length; kl = cipher_descriptor[x].max_key_length;
} }
fprintf(out, "PMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl); fprintf(out, "PMAC-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
/* initial key/block */ /* initial key/block */
for (y = 0; y < kl; y++) { for (y = 0; y < kl; y++) {
key[y] = (y & 255); key[y] = (y & 255);
} }
for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) { for (y = 0; y <= (int)(cipher_descriptor[x].block_length*2); y++) {
for (z = 0; z < y; z++) { for (z = 0; z < y; z++) {
input[z] = (unsigned char)(z & 255); input[z] = (unsigned char)(z & 255);
Loading
@@ -388,13 +287,15 @@ void pmac_gen(void)
Loading
@@ -388,13 +287,15 @@ void pmac_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
#endif
} }
   
void eax_gen(void) void eax_gen(void)
{ {
#ifdef LTC_EAX_MODE
int err, kl, x, y1, z; int err, kl, x, y1, z;
FILE *out; FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2], unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], header[MAXBLOCKSIZE*2],
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
unsigned long len; unsigned long len;
   
Loading
@@ -418,7 +319,7 @@ void eax_gen(void)
Loading
@@ -418,7 +319,7 @@ void eax_gen(void)
for (z = 0; z < kl; z++) { for (z = 0; z < kl; z++) {
key[z] = (z & 255); key[z] = (z & 255);
} }
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
plaintext[z] = (unsigned char)(z & 255); plaintext[z] = (unsigned char)(z & 255);
Loading
@@ -448,13 +349,15 @@ void eax_gen(void)
Loading
@@ -448,13 +349,15 @@ void eax_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
#endif
} }
   
void ocb_gen(void) void ocb_gen(void)
{ {
#ifdef LTC_OCB_MODE
int err, kl, x, y1, z; int err, kl, x, y1, z;
FILE *out; FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
unsigned long len; unsigned long len;
   
Loading
@@ -483,7 +386,7 @@ void ocb_gen(void)
Loading
@@ -483,7 +386,7 @@ void ocb_gen(void)
for (z = 0; z < cipher_descriptor[x].block_length; z++) { for (z = 0; z < cipher_descriptor[x].block_length; z++) {
nonce[z] = z; nonce[z] = z;
} }
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
plaintext[z] = (unsigned char)(z & 255); plaintext[z] = (unsigned char)(z & 255);
Loading
@@ -511,14 +414,81 @@ void ocb_gen(void)
Loading
@@ -511,14 +414,81 @@ void ocb_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
#endif
} }
   
void ocb3_gen(void)
{
#ifdef LTC_OCB3_MODE
int err, kl, x, y1, z, noncelen;
FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
unsigned long len;
out = fopen("ocb3_tv.txt", "w");
fprintf(out, "OCB3 Test Vectors. Uses the 00010203...NN-1 pattern for nonce/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. AAD is fixed to 3 bytes (ASCII) 'AAD'.\n\n");
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
kl = cipher_descriptor[x].block_length;
/* skip ciphers which do not have 64 or 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, "OCB3-%s (%d byte key)\n", cipher_descriptor[x].name, kl);
/* the key */
for (z = 0; z < kl; z++) {
key[z] = (z & 255);
}
/* fixed nonce */
noncelen = MIN(15, cipher_descriptor[x].block_length);
for (z = 0; z < noncelen; 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 = 16;
if ((err = ocb3_encrypt_authenticate_memory(x, key, kl, nonce, noncelen, (unsigned char*)"AAD", 3, plaintext, y1, plaintext, tag, &len)) != CRYPT_OK) {
printf("Error OCB3'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);
#endif
}
   
void ccm_gen(void) void ccm_gen(void)
{ {
#ifdef LTC_CCM_MODE
int err, kl, x, y1, z; int err, kl, x, y1, z;
FILE *out; FILE *out;
unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2], unsigned char key[MAXBLOCKSIZE], nonce[MAXBLOCKSIZE*2],
plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
unsigned long len; unsigned long len;
   
Loading
@@ -547,7 +517,7 @@ void ccm_gen(void)
Loading
@@ -547,7 +517,7 @@ void ccm_gen(void)
for (z = 0; z < cipher_descriptor[x].block_length; z++) { for (z = 0; z < cipher_descriptor[x].block_length; z++) {
nonce[z] = z; nonce[z] = z;
} }
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
plaintext[z] = (unsigned char)(z & 255); plaintext[z] = (unsigned char)(z & 255);
Loading
@@ -557,6 +527,10 @@ void ccm_gen(void)
Loading
@@ -557,6 +527,10 @@ void ccm_gen(void)
printf("Error CCM'ing: %s\n", error_to_string(err)); printf("Error CCM'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (len == 0) {
printf("Error CCM'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y1); fprintf(out, "%3d: ", y1);
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
fprintf(out, "%02X", plaintext[z]); fprintf(out, "%02X", plaintext[z]);
Loading
@@ -575,10 +549,12 @@ void ccm_gen(void)
Loading
@@ -575,10 +549,12 @@ void ccm_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
#endif
} }
   
void gcm_gen(void) void gcm_gen(void)
{ {
#ifdef LTC_GCM_MODE
int err, kl, x, y1, z; int err, kl, x, y1, z;
FILE *out; FILE *out;
unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE]; unsigned char key[MAXBLOCKSIZE], plaintext[MAXBLOCKSIZE*2], tag[MAXBLOCKSIZE];
Loading
@@ -604,8 +580,8 @@ void gcm_gen(void)
Loading
@@ -604,8 +580,8 @@ void gcm_gen(void)
for (z = 0; z < kl; z++) { for (z = 0; z < kl; z++) {
key[z] = (z & 255); key[z] = (z & 255);
} }
for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){ for (y1 = 1; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
plaintext[z] = (unsigned char)(z & 255); plaintext[z] = (unsigned char)(z & 255);
} }
Loading
@@ -614,6 +590,10 @@ void gcm_gen(void)
Loading
@@ -614,6 +590,10 @@ void gcm_gen(void)
printf("Error GCM'ing: %s\n", error_to_string(err)); printf("Error GCM'ing: %s\n", error_to_string(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (len == 0) {
printf("Error GCM'ing: zero length\n");
exit(EXIT_FAILURE);
}
fprintf(out, "%3d: ", y1); fprintf(out, "%3d: ", y1);
for (z = 0; z < y1; z++) { for (z = 0; z < y1; z++) {
fprintf(out, "%02X", plaintext[z]); fprintf(out, "%02X", plaintext[z]);
Loading
@@ -632,19 +612,20 @@ void gcm_gen(void)
Loading
@@ -632,19 +612,20 @@ void gcm_gen(void)
fprintf(out, "\n"); fprintf(out, "\n");
} }
fclose(out); fclose(out);
#endif
} }
   
void base64_gen(void) void base64_gen(void)
{ {
FILE *out; FILE *out;
unsigned char dst[256], src[32]; unsigned char dst[256], src[32], ch;
unsigned long x, y, len; unsigned long x, len;
out = fopen("base64_tv.txt", "w"); out = fopen("base64_tv.txt", "w");
fprintf(out, "Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1\n\n"); fprintf(out, "Base64 vectors. These are the base64 encodings of the strings 00,01,02...NN-1\n\n");
for (x = 0; x <= 32; x++) { for (x = 0; x <= 32; x++) {
for (y = 0; y < x; y++) { for (ch = 0; ch < x; ch++) {
src[y] = y; src[ch] = ch;
} }
len = sizeof(dst); len = sizeof(dst);
base64_encode(src, x, dst, &len); base64_encode(src, x, dst, &len);
Loading
@@ -681,7 +662,7 @@ void ecc_gen(void)
Loading
@@ -681,7 +662,7 @@ void ecc_gen(void)
mp_read_radix(modulus, (char *)ltc_ecc_sets[x].prime, 16); mp_read_radix(modulus, (char *)ltc_ecc_sets[x].prime, 16);
mp_read_radix(G->x, (char *)ltc_ecc_sets[x].Gx, 16); mp_read_radix(G->x, (char *)ltc_ecc_sets[x].Gx, 16);
mp_read_radix(G->y, (char *)ltc_ecc_sets[x].Gy, 16); mp_read_radix(G->y, (char *)ltc_ecc_sets[x].Gy, 16);
mp_set(G->z, 1); mp_set(G->z, 1);
   
while (mp_cmp(k, order) == LTC_MP_LT) { while (mp_cmp(k, order) == LTC_MP_LT) {
ltc_mp.ecc_ptmul(k, G, R, modulus, 1); ltc_mp.ecc_ptmul(k, G, R, modulus, 1);
Loading
@@ -699,11 +680,12 @@ void ecc_gen(void)
Loading
@@ -699,11 +680,12 @@ void ecc_gen(void)
   
void lrw_gen(void) void lrw_gen(void)
{ {
#ifdef LTC_LRW_MODE
FILE *out; FILE *out;
unsigned char tweak[16], key[16], iv[16], buf[1024]; unsigned char tweak[16], key[16], iv[16], buf[1024];
int x, y, err; int x, y, err;
symmetric_LRW lrw; symmetric_LRW lrw;
/* initialize default key and tweak */ /* initialize default key and tweak */
for (x = 0; x < 16; x++) { for (x = 0; x < 16; x++) {
tweak[x] = key[x] = iv[x] = x; tweak[x] = key[x] = iv[x] = x;
Loading
@@ -760,27 +742,61 @@ void lrw_gen(void)
Loading
@@ -760,27 +742,61 @@ void lrw_gen(void)
lrw_done(&lrw); lrw_done(&lrw);
} }
fclose(out); fclose(out);
} #endif
}
   
int main(void) int main(void)
{ {
reg_algs(); register_all_ciphers();
register_all_hashes();
register_all_prngs();
#ifdef USE_LTM
ltc_mp = ltm_desc;
#elif defined(USE_TFM)
ltc_mp = tfm_desc;
#elif defined(USE_GMP)
ltc_mp = gmp_desc;
#elif defined(EXT_MATH_LIB)
extern ltc_math_descriptor EXT_MATH_LIB;
ltc_mp = EXT_MATH_LIB;
#else
fprintf(stderr, "No MPI provider available\n");
exit(EXIT_FAILURE);
#endif
printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n");
printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n");
printf("Generating LTC_HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n"); printf("Generating HMAC vectors..."); fflush(stdout); hmac_gen(); printf("done\n");
printf("Generating LTC_OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n"); #ifdef LTC_OMAC
printf("Generating OMAC vectors..."); fflush(stdout); omac_gen(); printf("done\n");
#endif
#ifdef LTC_PMAC
printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n"); printf("Generating PMAC vectors..."); fflush(stdout); pmac_gen(); printf("done\n");
#endif
#ifdef LTC_EAX_MODE
printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n"); printf("Generating EAX vectors..."); fflush(stdout); eax_gen(); printf("done\n");
#endif
#ifdef LTC_OCB_MODE
printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n"); printf("Generating OCB vectors..."); fflush(stdout); ocb_gen(); printf("done\n");
#endif
#ifdef LTC_OCB3_MODE
printf("Generating OCB3 vectors..."); fflush(stdout); ocb3_gen(); printf("done\n");
#endif
#ifdef LTC_CCM_MODE
printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n"); printf("Generating CCM vectors..."); fflush(stdout); ccm_gen(); printf("done\n");
#endif
#ifdef LTC_GCM_MODE
printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n"); printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n");
printf("Generating LTC_BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n"); #endif
printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n"); printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n");
printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n"); printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n");
#ifdef LTC_LRW_MODE
printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n"); printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n");
#endif
return 0; return 0;
} }
   
/* $Source$ */ /* ref: $Format:%D$ */
/* $Revision$ */ /* git commit: $Format:%H$ */
/* $Date$ */ /* commit time: $Format:%ai$ */