mirror of
https://github.com/libtom/libtomcrypt
synced 2026-08-25 20:26:07 -04:00
Compare commits
No commits in common. "develop" and "0.97b" have entirely different histories.
1229 changed files with 37422 additions and 192777 deletions
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
<s_decode_header>
|
||||
Memcheck:Cond
|
||||
...
|
||||
fun:s_decode_header
|
||||
}
|
||||
71
.ci/build.sh
71
.ci/build.sh
|
|
@ -1,71 +0,0 @@
|
|||
#!/bin/bash
|
||||
echo "$1 ($2, $3)..."
|
||||
|
||||
make clean 1>/dev/null 2>/dev/null
|
||||
|
||||
echo -n "building..."
|
||||
|
||||
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
|
||||
|
||||
# remove the standard arguments from the make options
|
||||
opts=${3//makefile.shared/}
|
||||
opts=${opts//makefile/}
|
||||
opts=${opts//V=1/}
|
||||
opts=${opts//COVERAGE=1/}
|
||||
opts=$(echo $opts | tr -d '[:space:]')
|
||||
|
||||
# if there's something else than the standard arguments we check if we're currently
|
||||
# building a Travis PR and if it's like that, we skip those tests
|
||||
if [ ! -z "$opts" ]; then
|
||||
if [ ! -z "$TRAVIS_PULL_REQUEST" ] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
|
||||
echo "PR Tests skipped" | tee testok.txt
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -n "testing..."
|
||||
|
||||
if [ -a test ] && [ -f test ] && [ -x test ]; then
|
||||
((./test >test_std.txt 2>test_err.txt && ./tv_gen > tv.txt) && echo "$1 test passed." && echo "y" > testok.txt) || (echo "$1 test failed, look at test_err.txt or tv.txt" && exit 1)
|
||||
if find *_tv.txt -type f 1>/dev/null 2>/dev/null ; then
|
||||
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
|
||||
|
||||
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
if [ "$LTC_COVERAGE" != "" ]; then
|
||||
bash .ci/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
|
||||
fi
|
||||
exit 1
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ "$#" != "5" ]; then
|
||||
echo "Usage is: ${0} \"build_options\" \"<prepend CFLAGS>\" \"<makefile>\" \"<append CFLAGS>\" <math library to link to>"
|
||||
echo "CC=gcc ${0} \"build_options\" \" \" \"makefile\" \"-DUSE_LTM -DLTM_DESC -I../libtommath\" ../libtommath/libtommath.a"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
set -e
|
||||
|
||||
options=(
|
||||
-DLTC_EASY
|
||||
-DLTC_FORTUNA_RESEED_RATELIMIT_STATIC
|
||||
-DLTC_FORTUNA_USE_ENCRYPT_ONLY
|
||||
-DLTC_MECC_FP
|
||||
-DLTC_NO_TABLES
|
||||
-DLTC_NO_FAST
|
||||
-DLTC_NO_ASM
|
||||
-DLTC_NO_DEPRECATED_APIS
|
||||
-DLTC_NO_ECC_TIMING_RESISTANT
|
||||
-DLTC_NO_RSA_BLINDING
|
||||
-DLTC_PTHREAD
|
||||
-DLTC_SMALL_CODE
|
||||
-DLTC_SMALL_STACK
|
||||
)
|
||||
|
||||
make clean V=0
|
||||
make pre_gen
|
||||
for opt in ${options[@]}; do
|
||||
echo "Build: $opt"
|
||||
CFLAGS="$2 $CFLAGS $4 $opt" EXTRALIBS="$5" make -j$(nproc) -f $3 AMALGAM=1 all 1>>gcc_1.txt 2>>gcc_2.txt
|
||||
./small
|
||||
make clean V=0
|
||||
done
|
||||
|
||||
# we don't want LTC_EASY when running the tests now
|
||||
unset 'options[0]'
|
||||
|
||||
echo "All: ${options[@]}"
|
||||
CFLAGS="$2 $CFLAGS $4 ${options[@]}" EXTRALIBS="$5" make -j$(nproc) -f $3 AMALGAM=1 all 1>>gcc_1.txt 2>>gcc_2.txt
|
||||
./test >test_std.txt 2>test_err.txt
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
make clean > /dev/null
|
||||
|
||||
echo "checking..."
|
||||
./helper.pl --check-all || exit 1
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
# tested with clang-tidy from llvm-6.0.0
|
||||
# not tested with Travis-CI
|
||||
|
||||
#### we use the main test sets:
|
||||
# readability
|
||||
# misc
|
||||
# clang-analyzer
|
||||
# google
|
||||
# performance
|
||||
# modernize
|
||||
# cert
|
||||
# bugprone
|
||||
# portability
|
||||
|
||||
#### the following checks are skipped
|
||||
# google-readability-function-size
|
||||
# readability-function-size
|
||||
# google-readability-casting
|
||||
# readability-braces-around-statements
|
||||
# misc-macro-parentheses
|
||||
# clang-analyzer-valist.Uninitialized
|
||||
|
||||
echo "Run clang-tidy version"
|
||||
|
||||
clang-tidy --version || exit 1
|
||||
|
||||
echo "Run clang-tidy..."
|
||||
|
||||
clang-tidy src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/*.c -warnings-as-errors='*' --quiet --checks=-*,\
|
||||
readability-*,-readability-function-size,-readability-braces-around-statements,\
|
||||
misc-*,-misc-macro-parentheses,\
|
||||
clang-analyzer-*,-clang-analyzer-valist.Uninitialized,\
|
||||
google-*,-google-readability-function-size,-google-readability-casting,\
|
||||
performance-*,\
|
||||
modernize-*,\
|
||||
cert-*,\
|
||||
bugprone-*,\
|
||||
portability-* -- -DUSE_LTM -DLTM_DESC -Isrc/headers -I../libtommath || { echo "clang-tidy FAILED!"; exit 1; }
|
||||
|
||||
echo "clang-tidy ok"
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" goto :eof
|
||||
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" goto :eof
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "Ninja" ..
|
||||
ninja
|
||||
cd..
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#!/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 .ci/printinfo.sh
|
||||
|
||||
bash .ci/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
|
||||
|
||||
bash .ci/coverage_more.sh "$5" > test_coverage_more.txt || { rm -f testok.txt && exit 1 ; }
|
||||
|
||||
make lcov-single
|
||||
# if this isn't run on CI create coverage locally
|
||||
if [ "$CI" == "" ]; then
|
||||
make lcov-html
|
||||
else
|
||||
coveralls-lcov coverage.info --service-job-id="$GITHUB_RUN_ID" --service-name="github" --repo-token="$REPO_TOKEN" --branch="$GITHUB_REF_NAME" --service-pull-request="$PR_NUMBER"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
function pdiv() {
|
||||
printf "\n====== %s ======\n" "$*"
|
||||
}
|
||||
|
||||
if [ "$#" = "1" -a "$(echo $1 | grep 'gmp')" != "" ]; then
|
||||
pdiv "Test GMP"
|
||||
./test t gmp
|
||||
fi
|
||||
|
||||
pdiv "Sizes"
|
||||
./sizes
|
||||
pdiv "Constants"
|
||||
./constants
|
||||
|
||||
pdiv "Generate hashsum_tv.txt"
|
||||
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
|
||||
|
||||
pdiv "Compare 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
|
||||
|
||||
pdiv "aesgcm"
|
||||
./hashsum -a sha256 aesgcm > aesgcm.sha256sum
|
||||
./aesgcm -e aesgcm aesgcm.enc0 "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF"
|
||||
./aesgcm -d aesgcm.enc0 aesgcm.dec0 "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF"
|
||||
./aesgcm -e aesgcm aesgcm.enc1 "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABB"
|
||||
./aesgcm -d aesgcm.enc1 aesgcm.dec1 "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABB"
|
||||
for i in {0..1}; do
|
||||
rm aesgcm
|
||||
mv aesgcm.dec${i} aesgcm
|
||||
./hashsum -c aesgcm.sha256sum
|
||||
done
|
||||
chmod +x aesgcm
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This builds different stuff depending on the compiler:
|
||||
# gcc - valgrind, coverage
|
||||
# clang - asan, ubsan, scan-build
|
||||
# both - the two testbuild's NOTEST and NOFILE
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$#" = "5" -a "$(echo $3 | grep -v 'makefile[.]')" = "" ]; then
|
||||
echo "only run $0 for the regular makefile, early exit success"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
function run_gcc() {
|
||||
bash .ci/check_source.sh "CHECK_SOURCES" "$2" "$3" "$4" "$5"
|
||||
|
||||
make -j$(nproc) latex-tables V=0
|
||||
|
||||
./latex-tables
|
||||
|
||||
echo "verify docs..."
|
||||
while read -r line; do
|
||||
grep -q -e "$line" doc/crypt.tex || { echo "Failed to find \"$line\" in doc/crypt.tex"; exit 1; }
|
||||
done < <(./latex-tables | grep '^\\' | sed 's@\\@\\\\@g')
|
||||
echo "docs OK"
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
echo
|
||||
echo "Build for ASAN..."
|
||||
|
||||
make -j$MAKE_JOBS CFLAGS="-fsanitize=address -fno-omit-frame-pointer -static-libasan $2 $CFLAGS $4" EXTRALIBS="-lasan $5" test LTC_DEBUG=1 V=1 1>gcc_1.txt 2>gcc_2.txt
|
||||
|
||||
echo
|
||||
echo "Run ASAN tests with LTM..."
|
||||
|
||||
ASAN_OPTIONS=verbosity=1 ./test t ltm 1>test_std.txt 2> test_err.txt || exit 1
|
||||
|
||||
if echo $* | grep -q GMP ; then
|
||||
echo
|
||||
echo "Run ASAN tests with GMP..."
|
||||
|
||||
ASAN_OPTIONS=verbosity=1 ./test t gmp 1>test_std.txt 2> test_err.txt || exit 1
|
||||
fi
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
echo
|
||||
echo "Create code coverage"
|
||||
|
||||
bash .ci/coverage.sh "COVERAGE" "$2" "$3" "$4" "$5"
|
||||
}
|
||||
|
||||
function run_clang() {
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
scan_build=$(which scan-build) || true
|
||||
[ -z "$scan_build" ] && scan_build=$(find /usr/bin/ -name 'scan-build-[0-9]*' | sort -nr | head -n1) || true
|
||||
[ -z "$scan_build" ] && { echo "couldn't find clang scan-build"; exit 1; } || echo "run $scan_build"
|
||||
$scan_build --status-bugs make -j$MAKE_JOBS all CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5"
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
echo
|
||||
echo "Build for UBSAN..."
|
||||
|
||||
make -j$MAKE_JOBS LDFLAGS="-fsanitize=undefined" CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" all LTC_DEBUG=1 V=1 1>gcc_1.txt 2>gcc_2.txt
|
||||
|
||||
echo "Run UBSAN tests with LTM..."
|
||||
UBSAN_OPTIONS=verbosity=1 ./test t ltm 1>test_std.txt 2> test_err.txt || exit 1
|
||||
|
||||
if echo $* | grep -q GMP ; then
|
||||
echo
|
||||
echo "Run UBSAN tests with GMP..."
|
||||
|
||||
UBSAN_OPTIONS=verbosity=1 ./test t gmp 1>test_std.txt 2> test_err.txt || exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
EXTRALIBS="$5"
|
||||
|
||||
echo $* | grep -q GMP && EXTRALIBS="$EXTRALIBS -lgmp"
|
||||
|
||||
if [ -z "$(echo $CC | grep "clang")" ]; then
|
||||
run_gcc "$1" "$2" "$3" "$4" "$EXTRALIBS"
|
||||
else
|
||||
run_clang "$1" "$2" "$3" "$4" "$EXTRALIBS"
|
||||
fi
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
bash .ci/testbuild.sh "NOTEST" "-DLTC_NO_TEST" "$3" "$4" "$EXTRALIBS"
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
bash .ci/testbuild.sh "NOFILE" "-DLTC_NO_FILE" "$3" "$4" "$EXTRALIBS"
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
echo
|
||||
echo "Build full debug..."
|
||||
|
||||
make -j$MAKE_JOBS CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$EXTRALIBS" all_test LTC_DEBUG=2 V=1 1>gcc_1.txt 2>gcc_2.txt
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
version=$(git describe --tags --always --dirty 2>/dev/null)
|
||||
if [ ! -e ".git" ] || [ -z $version ]
|
||||
then
|
||||
version=$(grep "^VERSION=" makefile_include.mk | sed "s/.*=//")
|
||||
fi
|
||||
echo "Testing version:" $version
|
||||
#grep "VERSION=" makefile | perl -e "@a = split('=', <>); print @a[1];"`
|
||||
|
||||
# get uname
|
||||
echo "uname="`uname -a`
|
||||
|
||||
# get gcc name
|
||||
if [ -z ${CC} ]
|
||||
then
|
||||
CC="gcc"
|
||||
fi
|
||||
echo "${CC}="`${CC} -dumpversion`
|
||||
echo
|
||||
45
.ci/run.sh
45
.ci/run.sh
|
|
@ -1,45 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
bash .ci/build.sh " $1" "$2" "$3" "$4" "$5"
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
echo
|
||||
else
|
||||
echo
|
||||
echo "Test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f testok.txt
|
||||
bash .ci/build.sh " $1" "$2" "$3 LTC_DEBUG=1" "$4" "$5"
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
echo
|
||||
else
|
||||
echo
|
||||
echo "Test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f testok.txt
|
||||
bash .ci/build.sh " $1" "$2 -O2" "$3 IGNORE_SPEED=1" "$4" "$5"
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
echo
|
||||
else
|
||||
echo
|
||||
echo "Test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f testok.txt
|
||||
bash .ci/build.sh " $1" "$2" "$3 IGNORE_SPEED=1 LTC_SMALL=1" "$4" "$5"
|
||||
if [ -a testok.txt ] && [ -f testok.txt ]; then
|
||||
echo
|
||||
else
|
||||
echo
|
||||
echo "Test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
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
|
||||
|
||||
echo "$1 (Build Only, $2, $3)..."
|
||||
make clean 1>/dev/null 2>/dev/null
|
||||
echo -n "building..."
|
||||
touch testok.txt
|
||||
make -j$MAKE_JOBS -f $3 test tv_gen CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && rm -f testok.txt && exit 1)
|
||||
if find testok.txt -type f 1>/dev/null 2>/dev/null ; then
|
||||
echo "successful"
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$#" = "5" -a "$(echo $3 | grep -v 'makefile[.]')" = "" ]; then
|
||||
echo "only run $0 for the regular makefile, early exit success"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
# output version
|
||||
bash .ci/printinfo.sh
|
||||
|
||||
make clean &>/dev/null
|
||||
|
||||
echo "Build for valgrind..."
|
||||
|
||||
# set DWARFv4 as debug format for clang, since it creates DWARFv5 as default which isn't support in old valgrind
|
||||
[ -z "$(echo $CC | grep "clang")" ] || GFLAG="-gdwarf-4"
|
||||
|
||||
make -j$MAKE_JOBS CFLAGS="$2 $CFLAGS $4 $GFLAG" EXTRALIBS="$5" test LTC_DEBUG=1 1>gcc_1.txt 2>gcc_2.txt
|
||||
|
||||
echo "Run tests with valgrind..."
|
||||
|
||||
for i in `seq 1 10` ; do sleep 300 && echo "Valgrind tests in Progress..."; done &
|
||||
alive_pid=$!
|
||||
|
||||
readonly VALGRIND_OPTS="--error-exitcode=666 --leak-check=full --show-leak-kinds=all --errors-for-leak-kinds=all"
|
||||
|
||||
readonly distro="$(lsb_release -si)_$(lsb_release -sc)"
|
||||
readonly suppfile=".ci/Valgrind-${distro}.supp"
|
||||
function get_suppfile() { [ -f "$suppfile" ] && echo "--suppressions=$suppfile" || echo ""; }
|
||||
readonly VALGRIND_EXTRA_OPTS=$(get_suppfile)
|
||||
|
||||
valgrind $VALGRIND_OPTS $VALGRIND_EXTRA_OPTS ./test >test_std.txt 2> >(tee -a test_err.txt >&2) || { kill $alive_pid; echo "Valgrind failed"; exit 1; }
|
||||
|
||||
kill $alive_pid
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
---
|
||||
AccessModifierOffset: -2
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BinPackParameters: true
|
||||
ColumnLimit: 120
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
DerivePointerBinding: true
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
IndentCaseLabels: true
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakComment: 60
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerBindsToType: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
Cpp11BracedListStyle: false
|
||||
Standard: Cpp03
|
||||
IndentWidth: 3
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
BreakBeforeBraces: Linux
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
SpacesInParentheses: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpaceAfterControlStatementKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
...
|
||||
|
||||
7
.gitattributes
vendored
7
.gitattributes
vendored
|
|
@ -1,7 +0,0 @@
|
|||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
|
||||
/** export-subst
|
||||
|
||||
/tests/test.key -text
|
||||
39
.github/ISSUE_TEMPLATE/01-bug_report.md
vendored
39
.github/ISSUE_TEMPLATE/01-bug_report.md
vendored
|
|
@ -1,39 +0,0 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a bug report
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
|
||||
Do you want to ask a question? Are you looking for support? The Mailing list is the best place for getting support: https://groups.google.com/forum/#!forum/libtom
|
||||
|
||||
This is a very generic template, remove items that do not apply. For completed items, change [ ] to [x].
|
||||
|
||||
-->
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* [ ] Checked the developer manual
|
||||
* [ ] Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=repo%3Alibtom%2Flibtomcrypt
|
||||
* [ ] Checked that your issue isn't due to the fact that you're using asymmetric cryptography and you forgot linking in and/or setting an MPI provider (usually this causes either random crashes or runtime errors like `LTC_ARGCHK 'ltc_mp.name != NULL' failure ...`). c.f. Ch. "Math Descriptors" of the developer manual.
|
||||
* [ ] Checked that your issue isn't related to TomsFastMath's limitation that PK operations can by default only be done with max. 2048bit keys
|
||||
|
||||
### Description
|
||||
|
||||
[Description of the issue]
|
||||
|
||||
### Steps to Reproduce
|
||||
<!-- Please either describe your issue or even better, provide a functional code example reproducing your issue. -->
|
||||
|
||||
### Version
|
||||
|
||||
You can get this information from the define `SCRYPT` in `src/include/tomcrypt.h` or your local git repository by running `git describe --always --tags --dirty`.
|
||||
Also, please include the compiler, the compiler version, the architecture and (if applicable) the MPI provider, the OS and what version of the OS you're experiencing the issue.
|
||||
|
||||
### Additional Information
|
||||
|
||||
Any additional information, configuration or data that might be necessary to reproduce the issue.
|
||||
18
.github/PULL_REQUEST_TEMPLATE.md
vendored
18
.github/PULL_REQUEST_TEMPLATE.md
vendored
|
|
@ -1,18 +0,0 @@
|
|||
<!--
|
||||
|
||||
Thank you for your pull request.
|
||||
|
||||
If this fixes an existing github issue, make sure to have a line saying 'Fixes: <github-issue>' (without quotes) in the commit message.
|
||||
Please use the long format to refer to an issue 'libtom/libtomcrypt#<issue-id>'.
|
||||
|
||||
If this fixes something (even if there exists no github issue), make sure to have a line saying 'Fixes: <commit-id> ("Description")'
|
||||
This can be created via e.g. `git --no-pager log -1 --pretty=fixes <commid-id>
|
||||
|
||||
-->
|
||||
|
||||
### Checklist
|
||||
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
|
||||
|
||||
* [ ] documentation is added or updated
|
||||
* [ ] tests are added or updated
|
||||
* [ ] if this fixes something: added a `Fixes:` tag to the commit message
|
||||
168
.github/workflows/main.yml
vendored
168
.github/workflows/main.yml
vendored
|
|
@ -1,168 +0,0 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- 'release/**'
|
||||
- 'support/**'
|
||||
- 'ci/**'
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- 'release/**'
|
||||
- 'support/**'
|
||||
- 'ci/**'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
Docs:
|
||||
runs-on: ubuntu-24.04
|
||||
container: texlive/texlive:latest-medium
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: generate PDF
|
||||
run: |
|
||||
make docs
|
||||
cp doc/crypt.pdf crypt-${{ github.run_id }}.pdf
|
||||
- name: upload PDF
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: crypt-${{ github.run_id }}.pdf
|
||||
path: crypt-${{ github.run_id }}.pdf
|
||||
Build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
cc: [ gcc, clang ]
|
||||
os: [ ubuntu-22.04, ubuntu-24.04 ]
|
||||
config:
|
||||
- { BUILDNAME: 'META_BUILDS', BUILDOPTIONS: '-DGMP_DESC', BUILDSCRIPT: '.ci/meta_builds.sh' }
|
||||
- { BUILDNAME: 'VALGRIND', BUILDOPTIONS: '', BUILDSCRIPT: '.ci/valgrind.sh' }
|
||||
- { BUILDNAME: 'STOCK', BUILDOPTIONS: '', BUILDSCRIPT: '.ci/run.sh' }
|
||||
- { BUILDNAME: 'BUILD_OPTIONS', BUILDOPTIONS: '', BUILDSCRIPT: '.ci/build_options.sh' }
|
||||
- { BUILDNAME: 'STOCK-MPI', BUILDOPTIONS: '-ULTM_DESC -UTFM_DESC -UUSE_LTM -UUSE_TFM', BUILDSCRIPT: '.ci/run.sh' }
|
||||
- { BUILDNAME: 'STOCK+ARGTYPE=1', BUILDOPTIONS: '-DARGTYPE=1', BUILDSCRIPT: '.ci/run.sh' }
|
||||
- { BUILDNAME: 'STOCK+ARGTYPE=2', BUILDOPTIONS: '-DARGTYPE=2', BUILDSCRIPT: '.ci/run.sh' }
|
||||
- { BUILDNAME: 'STOCK+ARGTYPE=3', BUILDOPTIONS: '-DARGTYPE=3', BUILDSCRIPT: '.ci/run.sh' }
|
||||
- { BUILDNAME: 'STOCK+ARGTYPE=4', BUILDOPTIONS: '-DARGTYPE=4', BUILDSCRIPT: '.ci/run.sh' }
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
uses: nick-fields/retry@v4.0.0
|
||||
with:
|
||||
timeout_minutes: 20
|
||||
max_attempts: 3
|
||||
command: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y libgmp-dev valgrind libtool-bin clang-tools lcov ruby clang
|
||||
sudo apt-get remove -y libtommath1
|
||||
sudo gem install coveralls-lcov
|
||||
curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
|
||||
sudo apt-get install libtfm-git-dev libtommath-git-dev
|
||||
- name: run tests
|
||||
env:
|
||||
CC: "${{ matrix.cc }}"
|
||||
PR_NUMBER: ${{ github.event.number }}
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
bash "${{ matrix.config.BUILDSCRIPT }}" "${{ matrix.config.BUILDNAME }}" "-DUSE_LTM -DLTM_DESC" "makefile V=1" "${{ matrix.config.BUILDOPTIONS }}" "-ltommath"
|
||||
bash "${{ matrix.config.BUILDSCRIPT }}" "${{ matrix.config.BUILDNAME }}" "-DUSE_TFM -DTFM_DESC" "makefile.shared V=1" "${{ matrix.config.BUILDOPTIONS }}" "-ltfm"
|
||||
- name: regular logs
|
||||
if: ${{ !failure() }}
|
||||
run: |
|
||||
cat gcc_1.txt || true
|
||||
cat gcc_2.txt || true
|
||||
- name: error logs
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
cat gcc_1.txt || true
|
||||
cat gcc_2.txt || true
|
||||
cat test_std.txt || true
|
||||
cat test_err.txt || true
|
||||
cat tv.txt || true
|
||||
- name: pack build directory
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
tar cJf build-${{ github.run_id }}.tar.xz --exclude ./build-${{ github.run_id }}.tar.xz .
|
||||
- name: upload Artifact
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-${{ github.run_id }}.tar.xz
|
||||
path: build-${{ github.run_id }}.tar.xz
|
||||
retention-days: 1
|
||||
|
||||
Amalgam:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
cc: [ gcc, clang ]
|
||||
os: [ ubuntu-22.04, ubuntu-24.04 ]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
uses: nick-fields/retry@v4.0.0
|
||||
with:
|
||||
timeout_minutes: 20
|
||||
max_attempts: 3
|
||||
command: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get remove -y libtommath1
|
||||
curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
|
||||
sudo apt-get install libtommath-git-dev
|
||||
- name: run tests
|
||||
env:
|
||||
CC: "${{ matrix.cc }}"
|
||||
run: |
|
||||
make pre_gen
|
||||
make CFLAGS="-DLTM_DESC -DUSE_LTM" EXTRALIBS="-ltommath" AMALGAM=1 -j$(nproc) check
|
||||
|
||||
CMake:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-22.04, ubuntu-24.04, ubuntu-22.04-arm, ubuntu-24.04-arm ]
|
||||
build_type: [ '', -DCMAKE_BUILD_TYPE=Debug, -DCMAKE_BUILD_TYPE=Release, -DCMAKE_BUILD_TYPE=RelWithDebInfo, -DCMAKE_BUILD_TYPE=MinSizeRel ]
|
||||
cc: [ clang, gcc ]
|
||||
cflags: [ '', '-DLTC_CFLAGS="-DLTC_NO_ASM"']
|
||||
config:
|
||||
# Static library build
|
||||
- { CMAKEOPTIONS: '-DBUILD_SHARED_LIBS=Off' }
|
||||
# Shared library build
|
||||
- { CMAKEOPTIONS: '-DBUILD_SHARED_LIBS=On' }
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install dependencies
|
||||
uses: nick-fields/retry@v4.0.0
|
||||
with:
|
||||
timeout_minutes: 20
|
||||
max_attempts: 3
|
||||
command: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get remove -y libtommath1
|
||||
curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
|
||||
sudo apt-get install libtommath-git-dev
|
||||
sudo apt-get install -y cmake gcc clang llvm
|
||||
- name: build
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} ${{ matrix.cflags }} ..
|
||||
make -j$(nproc)
|
||||
- name: test
|
||||
run: |
|
||||
cd build
|
||||
CC=${{ matrix.cc }} cmake ${{ matrix.config.CMAKEOPTIONS }} ${{ matrix.build_type }} ${{ matrix.cflags }} -DBUILD_TESTING=On ..
|
||||
make -j$(nproc)
|
||||
ctest
|
||||
- name: error logs
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
cat build/Testing/Temporary/LastTest.log || true
|
||||
cat demo/build/Testing/Temporary/LastTest.log || true
|
||||
121
.gitignore
vendored
121
.gitignore
vendored
|
|
@ -1,121 +0,0 @@
|
|||
# suppress compiler/linker output
|
||||
*.[oa]
|
||||
*.obj
|
||||
*.dylib*
|
||||
*.dll*
|
||||
*.so*
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
/MSVC_*
|
||||
.bin/
|
||||
|
||||
# release files
|
||||
/libtomcrypt-*
|
||||
/crypt-*
|
||||
pre_gen/
|
||||
|
||||
# suppress output of build process
|
||||
gcc_[12].txt
|
||||
testok.txt
|
||||
test_*.txt
|
||||
tv.txt
|
||||
*_tv.txt
|
||||
doxygen/
|
||||
doc/crypt.pdf
|
||||
doc/refman.pdf
|
||||
|
||||
# *nix/windows test executables
|
||||
ltc-*
|
||||
aesgcm
|
||||
aesgcm.exe
|
||||
constants
|
||||
constants.exe
|
||||
crypt
|
||||
crypt.exe
|
||||
der_print_flexi
|
||||
der_print_flexi.exe
|
||||
hashsum
|
||||
hashsum.exe
|
||||
multi
|
||||
multi.exe
|
||||
openssl-enc
|
||||
openssl-enc.exe
|
||||
openssh-privkey
|
||||
openssh-privkey.exe
|
||||
latex-tables
|
||||
latex-tables.exe
|
||||
sizes
|
||||
sizes.exe
|
||||
small
|
||||
small.exe
|
||||
test
|
||||
test.exe
|
||||
tv_gen
|
||||
tv_gen.exe
|
||||
timing
|
||||
timing.exe
|
||||
|
||||
# Visual Studio special files
|
||||
# ignore user specific settings
|
||||
*.user
|
||||
*.suo
|
||||
# ignore non-compressed browse file (holds information for ClassView, IntelliSense and WizardBar)
|
||||
*.ncb
|
||||
# ignore VS intermediate and program database files
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Eclipse special files
|
||||
.project
|
||||
.cproject
|
||||
.settings/
|
||||
|
||||
# KDevelop special files
|
||||
*.kdev4
|
||||
|
||||
|
||||
# macOS special files
|
||||
.DS_Store
|
||||
|
||||
# other special files
|
||||
showlibs # symlink to .libs
|
||||
|
||||
# oops ;) but we don't want them to appear in the repository...
|
||||
*.stackdump
|
||||
*.core
|
||||
|
||||
# misc
|
||||
*.rej
|
||||
*.patch
|
||||
*.diff
|
||||
*.orig
|
||||
*.out
|
||||
*.ll
|
||||
*.gcda
|
||||
*.gcno
|
||||
*.gcov
|
||||
libtomcrypt.pc
|
||||
|
||||
# output from doc generation
|
||||
doxygen/
|
||||
*.dvi
|
||||
*.log
|
||||
*.aux
|
||||
*.toc
|
||||
*.idx
|
||||
*.ilg
|
||||
*.ind
|
||||
*.out
|
||||
*.lof
|
||||
*.bak
|
||||
|
||||
coverage*/
|
||||
coverage*.info
|
||||
|
||||
# coverity intermediate directory etc.
|
||||
cov-int/
|
||||
.coverity_*
|
||||
libtomcrypt.lzma
|
||||
|
||||
# cmake build directories
|
||||
build*/
|
||||
441
CMakeLists.txt
441
CMakeLists.txt
|
|
@ -1,441 +0,0 @@
|
|||
# SPDX-License-Identifier: Unlicense
|
||||
#
|
||||
# LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(
|
||||
libtomcrypt
|
||||
VERSION 1.18.2
|
||||
DESCRIPTION "A modular cryptographic library."
|
||||
HOMEPAGE_URL "https://www.libtom.net/LibTomCrypt"
|
||||
LANGUAGES C
|
||||
)
|
||||
|
||||
# package release version
|
||||
#
|
||||
# * bump if re-releasing the same VERSION + patches
|
||||
# * set to 1 if releasing a new VERSION
|
||||
set(PACKAGE_RELEASE_VERSION 1)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Include CMake modules
|
||||
# -----------------------------------------------------------------------------
|
||||
include(GNUInstallDirs)
|
||||
include(CheckIPOSupported)
|
||||
include(CMakePackageConfigHelpers)
|
||||
# for potential builds against gnump
|
||||
include(FindPkgConfig)
|
||||
# for potential builds with MSVC
|
||||
include(CMakePushCheckState)
|
||||
include(CheckSymbolExists)
|
||||
# default is "No tests"
|
||||
option(BUILD_TESTING "" OFF)
|
||||
include(CTest)
|
||||
include(sources.cmake)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Options
|
||||
# -----------------------------------------------------------------------------
|
||||
option(WITH_LTM "Build with support for libtommath" TRUE)
|
||||
option(WITH_TFM "Build with support for tomsfastmath" FALSE)
|
||||
option(WITH_GMP "Build with support for GNU Multi Precision Arithmetic Library" FALSE)
|
||||
set(MPI_PROVIDER
|
||||
"LTM"
|
||||
CACHE STRING "Build tests and demos against 'LTM', 'TFM' or 'GMP', default is LTM"
|
||||
)
|
||||
option(BUILD_SHARED_LIBS
|
||||
"Build shared library and only the shared library if \"ON\", default is static" OFF
|
||||
)
|
||||
option(WITH_PTHREAD "Build with pthread support" FALSE)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Compose CFLAGS
|
||||
# -----------------------------------------------------------------------------
|
||||
set(LTC_CFLAGS "" CACHE STRING "Optional user-specific CFLAGS")
|
||||
set(LTC_LDFLAGS "" CACHE STRING "Optional user-specific LDFLAGS")
|
||||
|
||||
# Some information ported from makefile_include.mk
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS "Setting build type to 'Release' as none was specified.")
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
# We differentiate between MSVC, WATCOM and GCC-compatible compilers
|
||||
if(MSVC)
|
||||
set(LTC_C_FLAGS -W3)
|
||||
elseif(WATCOM)
|
||||
set(LTC_C_FLAGS -fo=.obj -oaxt -3r -w3)
|
||||
else()
|
||||
set(LTC_C_FLAGS
|
||||
-Wall
|
||||
-Wsign-compare
|
||||
-Wextra
|
||||
-Wshadow
|
||||
-Wdeclaration-after-statement
|
||||
-Wbad-function-cast
|
||||
-Wcast-align
|
||||
-Wstrict-prototypes
|
||||
-Wpointer-arith
|
||||
-Wsystem-headers
|
||||
)
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g3")
|
||||
if(LTC_CFLAGS MATCHES "-DARGTYPE")
|
||||
set(ARGTYPE "")
|
||||
else()
|
||||
set(ARGTYPE "-DARGTYPE=4")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer ${ARGTYPE}")
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2 ${ARGTYPE}")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
|
||||
endif()
|
||||
|
||||
# What compiler do we have and what are their...uhm... peculiarities
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
|
||||
list(APPEND LTC_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare
|
||||
-Wno-builtin-requires-header
|
||||
)
|
||||
# Clang requires at least '-O1' for dead code eliminiation
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}")
|
||||
endif()
|
||||
if(CMAKE_C_COMPILER MATCHES "mingw")
|
||||
list(APPEND LTC_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement
|
||||
-Wno-bad-function-cast
|
||||
)
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||
list(APPEND LTC_C_FLAGS -Wno-nullability-completeness)
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
|
||||
list(APPEND LTC_C_FLAGS -no-undefined)
|
||||
endif()
|
||||
|
||||
# If the user set the environment variables at generate-time, append them in order to allow
|
||||
# overriding our defaults.
|
||||
# ~~~
|
||||
# ${LTC_CFLAGS} means the user passed it via sth like:
|
||||
# $ cmake -DLTC_CFLAGS="foo"
|
||||
# ~~~
|
||||
list(APPEND LTC_C_FLAGS ${LTC_CFLAGS})
|
||||
list(APPEND LTC_LD_FLAGS ${LTC_LDFLAGS})
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Library targets
|
||||
# -----------------------------------------------------------------------------
|
||||
add_library(${PROJECT_NAME} ${SOURCES} ${PUBLIC_HEADERS} ${PRIVATE_HEADERS})
|
||||
|
||||
target_include_directories(
|
||||
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/headers>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
|
||||
)
|
||||
|
||||
target_compile_options(${PROJECT_NAME} BEFORE PRIVATE ${LTC_C_FLAGS})
|
||||
target_link_options(${PROJECT_NAME} BEFORE PRIVATE ${LTC_LD_FLAGS})
|
||||
|
||||
set_target_properties(
|
||||
${PROJECT_NAME}
|
||||
PROPERTIES OUTPUT_NAME tomcrypt
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
PUBLIC_HEADER "${PUBLIC_HEADERS}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
cmake_push_check_state()
|
||||
set(CMAKE_REQUIRED_LIBRARIES bcrypt)
|
||||
check_symbol_exists(BCryptGenRandom "Windows.h;bcrypt.h" BCRYPT_AVAILABLE)
|
||||
cmake_pop_check_state()
|
||||
if(BCRYPT_AVAILABLE)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Bcrypt)
|
||||
list(APPEND LTC_C_FLAGS -DLTC_WIN32_BCRYPT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(COMPILE_LTO "Build with LTO enabled")
|
||||
if(COMPILE_LTO)
|
||||
check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO)
|
||||
if(COMPILER_SUPPORTS_LTO)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
else()
|
||||
message(
|
||||
SEND_ERROR
|
||||
"This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF."
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# MPI provider
|
||||
# -----------------------------------------------------------------------------
|
||||
# libtommath
|
||||
if(WITH_LTM)
|
||||
find_package(libtommath 1.2.0 REQUIRED)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC LTM_DESC)
|
||||
if(MPI_PROVIDER MATCHES "LTM")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_LTM)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC libtommath)
|
||||
list(APPEND LTC_PKG_CONFIG_CFLAGS -DLTM_DESC)
|
||||
list(APPEND LTC_PKG_CONFIG_LIBS -ltommath)
|
||||
list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libtommath-dev)
|
||||
endif()
|
||||
# tomsfastmath
|
||||
if(WITH_TFM)
|
||||
find_package(tomsfastmath 0.13.1 REQUIRED)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC TFM_DESC)
|
||||
if(MPI_PROVIDER MATCHES "TFM")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_TFM)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC tomsfastmath)
|
||||
list(APPEND LTC_PKG_CONFIG_CFLAGS -DTFM_DESC)
|
||||
list(APPEND LTC_PKG_CONFIG_LIBS -ltfm)
|
||||
list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libtfm-dev)
|
||||
endif()
|
||||
# GNU MP
|
||||
if(WITH_GMP)
|
||||
pkg_check_modules(GMP REQUIRED gmp>=6.1.2)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC GMP_DESC)
|
||||
if(MPI_PROVIDER MATCHES "GMP")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_GMP)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GMP_LIBRARIES})
|
||||
list(APPEND LTC_PKG_CONFIG_CFLAGS -DGMP_DESC)
|
||||
list(APPEND LTC_PKG_CONFIG_LIBS -lgmp)
|
||||
list(APPEND LTC_DEBIAN_MPI_PROVIDER_DEPENDS libgmp-dev)
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# other options
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if(WITH_PTHREAD)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
if(CMAKE_USE_PTHREADS_INIT)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC LTC_PTHREAD)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
|
||||
list(APPEND LTC_PKG_CONFIG_CFLAGS -DLTC_PTHREAD)
|
||||
else()
|
||||
message(
|
||||
SEND_ERROR
|
||||
"pthreads not supported. Reconfigure ${PROJECT_NAME} with -DWITH_PTHREAD=OFF."
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(JOIN LTC_PKG_CONFIG_CFLAGS " " PKG_CONFIG_CFLAGS)
|
||||
list(JOIN LTC_PKG_CONFIG_LIBS " " PKG_CONFIG_LIBS)
|
||||
list(JOIN LTC_DEBIAN_MPI_PROVIDER_DEPENDS " " DEBIAN_MPI_PROVIDER_DEPENDS)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# demos&test targets
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
add_subdirectory(demos)
|
||||
if(BUILD_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Install/export targets and files
|
||||
# ---------------------------------------------------------------------------------------
|
||||
set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||
set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
|
||||
set(PROJECT_CONFIG_FILE "${PROJECT_NAME}-config.cmake")
|
||||
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
||||
|
||||
# install targets
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${TARGETS_EXPORT_NAME}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
# Install libtomcrypt.pc for pkg-config if we build a shared library
|
||||
if(BUILD_SHARED_LIBS)
|
||||
# Let the user override the default directory of the pkg-config file (usually this shouldn't be
|
||||
# required to be changed)
|
||||
set(CMAKE_INSTALL_PKGCONFIGDIR
|
||||
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
|
||||
CACHE PATH "Folder where to install .pc files"
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY
|
||||
)
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
|
||||
DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
# generate package version file
|
||||
write_basic_package_version_file(
|
||||
${PROJECT_VERSION_FILE}
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
# install version file
|
||||
install(FILES ${PROJECT_VERSION_FILE} DESTINATION ${CONFIG_INSTALL_DIR})
|
||||
|
||||
# build directory package config
|
||||
export(EXPORT ${TARGETS_EXPORT_NAME} FILE ${PROJECT_CONFIG_FILE})
|
||||
|
||||
# installed package config
|
||||
install(
|
||||
EXPORT ${TARGETS_EXPORT_NAME}
|
||||
DESTINATION ${CONFIG_INSTALL_DIR}
|
||||
FILE ${PROJECT_CONFIG_FILE}
|
||||
)
|
||||
|
||||
# add to CMake registry
|
||||
export(PACKAGE ${PROJECT_NAME})
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Create release packages
|
||||
# ---------------------------------------------------------------------------------------
|
||||
|
||||
# determine distribution and architecture
|
||||
find_program(LSB_RELEASE lsb_release)
|
||||
find_program(SYSCTL sysctl)
|
||||
find_program(UNAME uname)
|
||||
|
||||
if(UNAME)
|
||||
execute_process(
|
||||
COMMAND uname -m
|
||||
OUTPUT_VARIABLE MACHINE_ARCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
elseif(SYSCTL)
|
||||
execute_process(
|
||||
COMMAND sysctl -b hw.machine_arch
|
||||
OUTPUT_VARIABLE MACHINE_ARCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
else()
|
||||
string(TOLOWER ${CMAKE_SYSTEM_NAME} MACHINE_ARCH)
|
||||
endif()
|
||||
|
||||
if(LSB_RELEASE)
|
||||
execute_process(
|
||||
COMMAND lsb_release -si
|
||||
OUTPUT_VARIABLE LINUX_DISTRO
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(
|
||||
COMMAND lsb_release -sc
|
||||
OUTPUT_VARIABLE LINUX_DISTRO_CODENAME
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(
|
||||
COMMAND lsb_release -sr
|
||||
OUTPUT_VARIABLE LINUX_DISTRO_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
string(TOLOWER ${LINUX_DISTRO} LINUX_DISTRO)
|
||||
if(LINUX_DISTRO_CODENAME STREQUAL "n/a")
|
||||
set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_VERSION}/)
|
||||
else()
|
||||
set(DISTRO_PACK_PATH ${LINUX_DISTRO}/${LINUX_DISTRO_CODENAME}/)
|
||||
endif()
|
||||
else()
|
||||
set(DISTRO_PACK_PATH ${CMAKE_SYSTEM_NAME}/)
|
||||
endif()
|
||||
|
||||
# make sure untagged versions get a different package name
|
||||
execute_process(
|
||||
COMMAND git describe --exact-match --tags
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE REPO_HAS_TAG
|
||||
)
|
||||
if(REPO_HAS_TAG EQUAL 0)
|
||||
set(PACKAGE_NAME_SUFFIX "")
|
||||
else()
|
||||
set(PACKAGE_NAME_SUFFIX "-git")
|
||||
message(STATUS "Use -git suffix")
|
||||
endif()
|
||||
|
||||
# default CPack generators
|
||||
set(CPACK_GENERATOR TGZ STGZ)
|
||||
|
||||
# extra CPack generators
|
||||
if(LINUX_DISTRO STREQUAL "debian"
|
||||
OR LINUX_DISTRO STREQUAL "ubuntu"
|
||||
OR LINUX_DISTRO STREQUAL "linuxmint"
|
||||
)
|
||||
list(APPEND CPACK_GENERATOR DEB)
|
||||
elseif(
|
||||
LINUX_DISTRO STREQUAL "fedora"
|
||||
OR LINUX_DISTRO STREQUAL "opensuse"
|
||||
OR LINUX_DISTRO STREQUAL "centos"
|
||||
)
|
||||
list(APPEND CPACK_GENERATOR RPM)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||
list(APPEND CPACK_GENERATOR FREEBSD)
|
||||
endif()
|
||||
|
||||
set(LTC_DEBIAN_SHARED_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}${PROJECT_VERSION_MAJOR}")
|
||||
|
||||
# general CPack config
|
||||
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/${DISTRO_PACK_PATH})
|
||||
message(STATUS "CPack: packages will be generated under ${CPACK_PACKAGE_DIRECTORY}")
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${PROJECT_VERSION_MAJOR}")
|
||||
set(CPACK_DEBIAN_PACKAGE_NAME "${LTC_DEBIAN_SHARED_PACKAGE_NAME}")
|
||||
else()
|
||||
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}-devel")
|
||||
set(CPACK_DEBIAN_LIBRARIES_PACKAGE_NAME "${PROJECT_NAME}${PACKAGE_NAME_SUFFIX}-dev")
|
||||
endif()
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LibTomCrypt")
|
||||
set(CPACK_PACKAGE_VENDOR "libtom projects")
|
||||
set(CPACK_PACKAGE_CONTACT "libtom@googlegroups.com")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||
set(PACKAGE_NAME_TRAILER ${CPACK_PACKAGE_VERSION}-${PACKAGE_RELEASE_VERSION}_${MACHINE_ARCH})
|
||||
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${PACKAGE_NAME_TRAILER})
|
||||
set(CPACK_STRIP_FILES ON)
|
||||
|
||||
# deb specific CPack config
|
||||
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
|
||||
set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
|
||||
set(CPACK_DEBIAN_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS ${DEBIAN_MPI_PROVIDER_DEPENDS})
|
||||
else()
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel")
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS ${LTC_DEBIAN_SHARED_PACKAGE_NAME})
|
||||
set(CPACK_DEB_COMPONENT_INSTALL ON)
|
||||
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
|
||||
set(CPACK_COMPONENTS_ALL Libraries)
|
||||
endif()
|
||||
|
||||
# rpm specific CPack config
|
||||
set(CPACK_RPM_PACKAGE_RELEASE ${PACKAGE_RELEASE_VERSION})
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${MACHINE_ARCH})
|
||||
set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}")
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "The Unlicense")
|
||||
|
||||
# FreeBSD specific CPack config
|
||||
set(CPACK_FREEBSD_PACKAGE_MAINTAINER "gahr@FreeBSD.org")
|
||||
set(CPACK_FREEBSD_PACKAGE_ORIGIN "security/libtomcrypt")
|
||||
set(CPACK_FREEBSD_PACKAGE_CATEGORIES "security")
|
||||
|
||||
include(CPack)
|
||||
27
LICENSE
27
LICENSE
|
|
@ -1,26 +1,9 @@
|
|||
The LibTom license
|
||||
LibTomCrypt is public domain. As should all quality software be.
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
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.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
Tom St Denis
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
|
|
|
|||
204
README.md
204
README.md
|
|
@ -1,204 +0,0 @@
|
|||
# libtomcrypt
|
||||
|
||||
Previously the git repository contained `doc/crypt.pdf` for detailed documentation.
|
||||
This was changed and the file is now only available from the tarball of the appropriate version
|
||||
or from the page https://github.com/libtom/libtomcrypt/releases .
|
||||
|
||||
## Project Status
|
||||
|
||||
### Travis CI
|
||||
|
||||
master: [](https://github.com/libtom/libtomcrypt/actions/workflows/main.yml?query=branch%3Amaster+++) [](https://coveralls.io/r/libtom/libtomcrypt)
|
||||
|
||||
develop: [](https://github.com/libtom/libtomcrypt/actions/workflows/main.yml?query=branch%3Adevelop+++) [](https://coveralls.io/r/libtom/libtomcrypt)
|
||||
|
||||
### AppVeyor
|
||||
|
||||
master: [](https://ci.appveyor.com/project/libtom/libtomcrypt/branch/master)
|
||||
|
||||
develop: [](https://ci.appveyor.com/project/libtom/libtomcrypt/branch/develop)
|
||||
|
||||
### Coverity
|
||||
|
||||
[](https://scan.coverity.com/projects/487)
|
||||
|
||||
### ABI Laboratory
|
||||
|
||||
API/ABI changes: [check here](https://abi-laboratory.pro/tracker/timeline/libtomcrypt/)
|
||||
|
||||
## Submitting patches
|
||||
|
||||
Please branch off from develop if you want to submit a patch.
|
||||
|
||||
Patch integration will be faster if tests and documentation are included.
|
||||
|
||||
Please update the makefiles in a separate commit. To update them simply run the `updatemakes.sh` script.
|
||||
|
||||
If you have something bigger to submit, feel free to contact us beforehand.
|
||||
Then we can give you write access to this repo, so you can open your PR based on this repo
|
||||
and we can easier follow the rebase-before-merge approach we're using (or even do the rebase ourself).
|
||||
|
||||
### Reviews
|
||||
|
||||
We're using Pull Request reviews to make sure that the code is in line with the existing code base.
|
||||
|
||||
Please have a look [here](https://help.github.com/articles/approving-a-pull-request-with-required-reviews/) to get an idea of the approach.
|
||||
|
||||
## Branches
|
||||
|
||||
Please be aware, that all branches besides _master_ and _develop_ __can__ and __will be__ force-pushed, rebased and/or removed!
|
||||
|
||||
If you want to rely on such an _unstable_ branch, create your own fork of this repository to make sure nothing breaks for you.
|
||||
|
||||
## Configuration options
|
||||
|
||||
By default the library builds its entire feature set (besides `katja`) in a (depending on your needs more or less) optimal way.
|
||||
|
||||
There are numerous configuration options available if you want to trim down the functionality of the library.
|
||||
|
||||
Please have a look at `src/headers/tomcrypt_custom.h` for all available configuration options.
|
||||
|
||||
The following list is a small part of the available, but the most often required, configuration switches.
|
||||
|
||||
| Flag | Behavior |
|
||||
| ---- | -------- |
|
||||
| `LTC_NO_TEST` | Remove all algorithm self-tests from the library |
|
||||
| `LTC_NO_FILE` | Remove all API functions requiring a pre-defined `FILE` data-type (mostly useful for embedded targets) |
|
||||
| `GMP_DESC` | enable [gmp](https://gmplib.org/) as MPI provider *\*1* |
|
||||
| `LTM_DESC` | enable [libtommath](http://www.libtom.net/) as MPI provider *\*1* |
|
||||
| `TFM_DESC` | enable [tomsfastmath](http://www.libtom.net/) as MPI provider *\*1* *\*2* |
|
||||
| `USE_GMP` | use `gmp` as MPI provider when building the binaries *\*3* |
|
||||
| `USE_LTM` | use `libtommath` as MPI provider when building the binaries *\*3* |
|
||||
| `USE_TFM` | use `tomsfastmath` as MPI provider when building the binaries *\*3* |
|
||||
|
||||
*\*1* It is possible to build the library against all MPI providers in parallel and choose at startup-time which math library should be used.
|
||||
|
||||
*\*2* Please be aware that `tomsfastmath` has the limitation of a fixed max size of MPI's.
|
||||
|
||||
*\*3* Only one is supported at the time & this is only required when building the binaries, not when building the library itself.
|
||||
|
||||
## Building the library
|
||||
|
||||
There are several `makefile`s provided. Please choose the one that fits best for you.
|
||||
|
||||
| makefile | use-case |
|
||||
| -------- | -------- |
|
||||
| `makefile` | builds a static library (GNU Make required) |
|
||||
| `makefile.shared` | builds a shared (and static) library (GNU Make required) |
|
||||
| `makefile.unix` | for unusual UNIX platforms, or if you do not have GNU Make |
|
||||
| `makefile.mingw` | for usage with the mingw compiler on MS Windows |
|
||||
| `makefile.msvc` | for usage with the MSVC compiler on MS Windows |
|
||||
| `libtomcrypt_VS2008.sln` | A VisualStudio 2008 project for MS Windows |
|
||||
|
||||
### Make targets
|
||||
|
||||
The `makefile`s provide several targets to build (VS project excluded).
|
||||
The following list does not claim to be complete resp. to be available across all `makefile` variants.
|
||||
|
||||
| target | application |
|
||||
| ------ | ----------- |
|
||||
| *empty target*/none given | c.f. `library`
|
||||
| `library` | builds only the library |
|
||||
| `hashsum` | builds the `hashsum` binary, similar to [`shasum`](https://linux.die.net/man/1/shasum), but with support for all hash-algorithms included in the library *\*4* |
|
||||
| `crypt` | builds the `crypt` binary, implementing something similar to [`crypt`](https://linux.die.net/man/3/crypt) *\*4* |
|
||||
| `sizes` | builds the `sizes` binary, printing all internal data sizes on invocation *\*4* |
|
||||
| `constants` | builds the `constants` binary, printing all internal constants on invocation *\*4* |
|
||||
| `openssl-enc` | builds the `openssl-enc` binary, which is more or less compatible to [`openssl enc`](https://linux.die.net/man/1/enc) *\*4* *\*5* |
|
||||
| `test` | builds the `test` binary, which runs all algorithm self-tests + some extended tests *\*4* |
|
||||
| `timing` | builds the `timing` binary, which can be used to measure timings for algorithms and modes *\*4* |
|
||||
| `bins` | builds `hashsum` *\*4* |
|
||||
| `all_test` | builds `test`, `hashsum`, `crypt`, `small`, `tv_gen`, `sizes` & `constants` *\*4* |
|
||||
| `docs` | builds the developer documentation `doc/crypt.pdf` |
|
||||
| `install` | installs the `library` and header files *\*7* *\*8* |
|
||||
| `install_bins` | installs the binaries created by the `bins` target *\*7* *\*8* |
|
||||
| `install_docs` | installs the documentation created by the `docs` target *\*7* *\*8* |
|
||||
| `install_test` | installs the test-app created by the `test` target *\*7* *\*8* |
|
||||
| `install_all` | installs everything (i.e. `library`, `bins`, `docs` and `test`) *\*8* |
|
||||
| `uninstall` | uninstalls the `library` and header files |
|
||||
|
||||
*\*4* also builds `library`
|
||||
|
||||
*\*5* broken build in some configurations, therefore not built by default
|
||||
|
||||
*\*7* also builds the necessary artifact(s) before installing it
|
||||
|
||||
*\*8* also have a look at the 'Installation' section of this file
|
||||
|
||||
### Examples
|
||||
|
||||
You want to build the library as static library
|
||||
|
||||
make
|
||||
|
||||
You want to build the library as shared library
|
||||
|
||||
make -f makefile.shared
|
||||
|
||||
You have `libtommath` installed on your system and want to build a static library and the `test` binary to run the self-tests.
|
||||
|
||||
make CFLAGS="-DUSE_LTM -DLTM_DESC" EXTRALIBS="-ltommath" test
|
||||
|
||||
You have `tomsfastmath` installed on your system and want to build a shared library and all binaries
|
||||
|
||||
make -f makefile.shared CFLAGS="-DUSE_TFM -DTFM_DESC" EXTRALIBS="-ltfm" all demos
|
||||
|
||||
You have `gmp`, `libtommath` and `tomsfastmath` installed on your system and want to build a static library and the `timing` binary to measure timings against `gmp`.
|
||||
|
||||
make CFLAGS="-DUSE_GMP -DGMP_DESC -DLTM_DESC -DTFM_DESC" EXTRALIBS="-lgmp" timing
|
||||
|
||||
If you have `libtommath` in a non-standard location:
|
||||
|
||||
make CFLAGS="-DUSE_LTM -DLTM_DESC -I/opt/devel/ltm" EXTRALIBS="/opt/devel/ltm/libtommath.a" all
|
||||
|
||||
You want to enable AES-NI support:
|
||||
|
||||
make CFLAGS=-DLTC_AES_NI
|
||||
|
||||
## Installation
|
||||
|
||||
There exist several _install_ make-targets which are described in the table above.
|
||||
|
||||
These targets support the standard ways (c.f. [[GNU]], [[FreeBSD]])
|
||||
to modify the installation path via the following set of variables:
|
||||
|
||||
DESTDIR
|
||||
PREFIX
|
||||
LIBPATH
|
||||
INCPATH
|
||||
DATAPATH
|
||||
BINPATH
|
||||
|
||||
The entire set of the variables is only supported in `makefile`, `makefile.shared` and `makefile.unix`.
|
||||
|
||||
In case you have to use one of the other makefiles, check in the file which variables are supported.
|
||||
|
||||
### Examples
|
||||
|
||||
You want to install the static library to the default paths
|
||||
|
||||
make install
|
||||
|
||||
You want to install the shared library to a special path and use it from this path
|
||||
|
||||
make -f makefile.shared PREFIX=/opt/special/path
|
||||
|
||||
Have a look at the developer documentation, [[GNU]] or [[FreeBSD]] to get a detailed explanation of all the variables.
|
||||
|
||||
## CMake support
|
||||
|
||||
The project provides support for the CMake build system.
|
||||
|
||||
```
|
||||
git clone https://github.com/libtom/libtomcrypt.git
|
||||
mkdir -p libtomcrypt/build
|
||||
cd libtomcrypt/build
|
||||
cmake ..
|
||||
make -j$(nproc)
|
||||
```
|
||||
|
||||
More details around building with CMake can be found in the developer documentation.
|
||||
|
||||
|
||||
[GNU]: https://www.gnu.org/prep/standards/html_node/DESTDIR.html
|
||||
|
||||
[FreeBSD]: https://www.freebsd.org/doc/en/books/porters-handbook/porting-prefix.html
|
||||
701
aes.c
Normal file
701
aes.c
Normal file
|
|
@ -0,0 +1,701 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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
|
||||
*/
|
||||
|
||||
/* AES implementation by Tom St Denis
|
||||
*
|
||||
* Derived from the Public Domain source code by
|
||||
|
||||
---
|
||||
* rijndael-alg-fst.c
|
||||
*
|
||||
* @version 3.0 (December 2000)
|
||||
*
|
||||
* Optimised ANSI C code for the Rijndael cipher (now AES)
|
||||
*
|
||||
* @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
|
||||
* @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
|
||||
* @author Paulo Barreto <paulo.barreto@terra.com.br>
|
||||
---
|
||||
*/
|
||||
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef RIJNDAEL
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
|
||||
#define SETUP rijndael_setup
|
||||
#define ECB_ENC rijndael_ecb_encrypt
|
||||
#define ECB_DEC rijndael_ecb_decrypt
|
||||
#define ECB_TEST rijndael_test
|
||||
#define ECB_KS rijndael_keysize
|
||||
|
||||
const struct _cipher_descriptor rijndael_desc =
|
||||
{
|
||||
"rijndael",
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_KS
|
||||
};
|
||||
|
||||
const struct _cipher_descriptor aes_desc =
|
||||
{
|
||||
"aes",
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_KS
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#define SETUP rijndael_enc_setup
|
||||
#define ECB_ENC rijndael_enc_ecb_encrypt
|
||||
#define ECB_KS rijndael_enc_keysize
|
||||
|
||||
const struct _cipher_descriptor rijndael_enc_desc =
|
||||
{
|
||||
"rijndael",
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, NULL, NULL, ECB_KS
|
||||
};
|
||||
|
||||
const struct _cipher_descriptor aes_enc_desc =
|
||||
{
|
||||
"aes",
|
||||
6,
|
||||
16, 32, 16, 10,
|
||||
SETUP, ECB_ENC, NULL, NULL, ECB_KS
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#include "aes_tab.c"
|
||||
|
||||
static ulong32 setup_mix(ulong32 temp)
|
||||
{
|
||||
return (Te4_3[byte(temp, 2)]) ^
|
||||
(Te4_2[byte(temp, 1)]) ^
|
||||
(Te4_1[byte(temp, 0)]) ^
|
||||
(Te4_0[byte(temp, 3)]);
|
||||
}
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
#ifdef SMALL_CODE
|
||||
static ulong32 setup_mix2(ulong32 temp)
|
||||
{
|
||||
return Td0(255 & Te4[byte(temp, 3)]) ^
|
||||
Td1(255 & Te4[byte(temp, 2)]) ^
|
||||
Td2(255 & Te4[byte(temp, 1)]) ^
|
||||
Td3(255 & Te4[byte(temp, 0)]);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int SETUP(const unsigned char *key, int keylen, int rounds, symmetric_key *skey)
|
||||
{
|
||||
int i, j;
|
||||
ulong32 temp, *rk;
|
||||
#ifndef ENCRYPT_ONLY
|
||||
ulong32 *rrk;
|
||||
#endif
|
||||
_ARGCHK(key != NULL);
|
||||
_ARGCHK(skey != NULL);
|
||||
|
||||
if (keylen != 16 && keylen != 24 && keylen != 32) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
|
||||
if (rounds != 0 && rounds != (10 + ((keylen/8)-2)*2)) {
|
||||
return CRYPT_INVALID_ROUNDS;
|
||||
}
|
||||
|
||||
skey->rijndael.Nr = 10 + ((keylen/8)-2)*2;
|
||||
|
||||
/* setup the forward key */
|
||||
i = 0;
|
||||
rk = skey->rijndael.eK;
|
||||
LOAD32H(rk[0], key );
|
||||
LOAD32H(rk[1], key + 4);
|
||||
LOAD32H(rk[2], key + 8);
|
||||
LOAD32H(rk[3], key + 12);
|
||||
if (keylen == 16) {
|
||||
j = 44;
|
||||
for (;;) {
|
||||
temp = rk[3];
|
||||
rk[4] = rk[0] ^ setup_mix(temp) ^ rcon[i];
|
||||
rk[5] = rk[1] ^ rk[4];
|
||||
rk[6] = rk[2] ^ rk[5];
|
||||
rk[7] = rk[3] ^ rk[6];
|
||||
if (++i == 10) {
|
||||
break;
|
||||
}
|
||||
rk += 4;
|
||||
}
|
||||
} else if (keylen == 24) {
|
||||
j = 52;
|
||||
LOAD32H(rk[4], key + 16);
|
||||
LOAD32H(rk[5], key + 20);
|
||||
for (;;) {
|
||||
#ifdef _MSC_VER
|
||||
temp = skey->rijndael.eK[rk - skey->rijndael.eK + 5];
|
||||
#else
|
||||
temp = rk[5];
|
||||
#endif
|
||||
rk[ 6] = rk[ 0] ^ setup_mix(temp) ^ rcon[i];
|
||||
rk[ 7] = rk[ 1] ^ rk[ 6];
|
||||
rk[ 8] = rk[ 2] ^ rk[ 7];
|
||||
rk[ 9] = rk[ 3] ^ rk[ 8];
|
||||
if (++i == 8) {
|
||||
break;
|
||||
}
|
||||
rk[10] = rk[ 4] ^ rk[ 9];
|
||||
rk[11] = rk[ 5] ^ rk[10];
|
||||
rk += 6;
|
||||
}
|
||||
} else if (keylen == 32) {
|
||||
j = 60;
|
||||
LOAD32H(rk[4], key + 16);
|
||||
LOAD32H(rk[5], key + 20);
|
||||
LOAD32H(rk[6], key + 24);
|
||||
LOAD32H(rk[7], key + 28);
|
||||
for (;;) {
|
||||
#ifdef _MSC_VER
|
||||
temp = skey->rijndael.eK[rk - skey->rijndael.eK + 7];
|
||||
#else
|
||||
temp = rk[7];
|
||||
#endif
|
||||
rk[ 8] = rk[ 0] ^ setup_mix(temp) ^ rcon[i];
|
||||
rk[ 9] = rk[ 1] ^ rk[ 8];
|
||||
rk[10] = rk[ 2] ^ rk[ 9];
|
||||
rk[11] = rk[ 3] ^ rk[10];
|
||||
if (++i == 7) {
|
||||
break;
|
||||
}
|
||||
temp = rk[11];
|
||||
rk[12] = rk[ 4] ^ setup_mix(ROR(temp, 8));
|
||||
rk[13] = rk[ 5] ^ rk[12];
|
||||
rk[14] = rk[ 6] ^ rk[13];
|
||||
rk[15] = rk[ 7] ^ rk[14];
|
||||
rk += 8;
|
||||
}
|
||||
} else {
|
||||
/* this can't happen */
|
||||
j = 4;
|
||||
}
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
/* setup the inverse key now */
|
||||
rk = skey->rijndael.dK;
|
||||
rrk = skey->rijndael.eK + j - 4;
|
||||
|
||||
/* apply the inverse MixColumn transform to all round keys but the first and the last: */
|
||||
/* copy first */
|
||||
*rk++ = *rrk++;
|
||||
*rk++ = *rrk++;
|
||||
*rk++ = *rrk++;
|
||||
*rk = *rrk;
|
||||
rk -= 3; rrk -= 3;
|
||||
|
||||
for (i = 1; i < skey->rijndael.Nr; i++) {
|
||||
rrk -= 4;
|
||||
rk += 4;
|
||||
#ifdef SMALL_CODE
|
||||
temp = rrk[0];
|
||||
rk[0] = setup_mix2(temp);
|
||||
temp = rrk[1];
|
||||
rk[1] = setup_mix2(temp);
|
||||
temp = rrk[2];
|
||||
rk[2] = setup_mix2(temp);
|
||||
temp = rrk[3];
|
||||
rk[3] = setup_mix2(temp);
|
||||
#else
|
||||
temp = rrk[0];
|
||||
rk[0] =
|
||||
Tks0[byte(temp, 3)] ^
|
||||
Tks1[byte(temp, 2)] ^
|
||||
Tks2[byte(temp, 1)] ^
|
||||
Tks3[byte(temp, 0)];
|
||||
temp = rrk[1];
|
||||
rk[1] =
|
||||
Tks0[byte(temp, 3)] ^
|
||||
Tks1[byte(temp, 2)] ^
|
||||
Tks2[byte(temp, 1)] ^
|
||||
Tks3[byte(temp, 0)];
|
||||
temp = rrk[2];
|
||||
rk[2] =
|
||||
Tks0[byte(temp, 3)] ^
|
||||
Tks1[byte(temp, 2)] ^
|
||||
Tks2[byte(temp, 1)] ^
|
||||
Tks3[byte(temp, 0)];
|
||||
temp = rrk[3];
|
||||
rk[3] =
|
||||
Tks0[byte(temp, 3)] ^
|
||||
Tks1[byte(temp, 2)] ^
|
||||
Tks2[byte(temp, 1)] ^
|
||||
Tks3[byte(temp, 0)];
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/* copy last */
|
||||
rrk -= 4;
|
||||
rk += 4;
|
||||
*rk++ = *rrk++;
|
||||
*rk++ = *rrk++;
|
||||
*rk++ = *rrk++;
|
||||
*rk = *rrk;
|
||||
#endif /* ENCRYPT_ONLY */
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef 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)
|
||||
#endif
|
||||
{
|
||||
ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
|
||||
int Nr, r;
|
||||
|
||||
_ARGCHK(pt != NULL);
|
||||
_ARGCHK(ct != NULL);
|
||||
_ARGCHK(skey != NULL);
|
||||
|
||||
Nr = skey->rijndael.Nr;
|
||||
rk = skey->rijndael.eK;
|
||||
|
||||
/*
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
LOAD32H(s0, pt ); s0 ^= rk[0];
|
||||
LOAD32H(s1, pt + 4); s1 ^= rk[1];
|
||||
LOAD32H(s2, pt + 8); s2 ^= rk[2];
|
||||
LOAD32H(s3, pt + 12); s3 ^= rk[3];
|
||||
|
||||
|
||||
#ifdef SMALL_CODE
|
||||
|
||||
for (r = 0; ; r++) {
|
||||
rk += 4;
|
||||
t0 =
|
||||
Te0(byte(s0, 3)) ^
|
||||
Te1(byte(s1, 2)) ^
|
||||
Te2(byte(s2, 1)) ^
|
||||
Te3(byte(s3, 0)) ^
|
||||
rk[0];
|
||||
t1 =
|
||||
Te0(byte(s1, 3)) ^
|
||||
Te1(byte(s2, 2)) ^
|
||||
Te2(byte(s3, 1)) ^
|
||||
Te3(byte(s0, 0)) ^
|
||||
rk[1];
|
||||
t2 =
|
||||
Te0(byte(s2, 3)) ^
|
||||
Te1(byte(s3, 2)) ^
|
||||
Te2(byte(s0, 1)) ^
|
||||
Te3(byte(s1, 0)) ^
|
||||
rk[2];
|
||||
t3 =
|
||||
Te0(byte(s3, 3)) ^
|
||||
Te1(byte(s0, 2)) ^
|
||||
Te2(byte(s1, 1)) ^
|
||||
Te3(byte(s2, 0)) ^
|
||||
rk[3];
|
||||
if (r == Nr-2) {
|
||||
break;
|
||||
}
|
||||
s0 = t0; s1 = t1; s2 = t2; s3 = t3;
|
||||
}
|
||||
rk += 4;
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Nr - 1 full rounds:
|
||||
*/
|
||||
r = Nr >> 1;
|
||||
for (;;) {
|
||||
t0 =
|
||||
Te0(byte(s0, 3)) ^
|
||||
Te1(byte(s1, 2)) ^
|
||||
Te2(byte(s2, 1)) ^
|
||||
Te3(byte(s3, 0)) ^
|
||||
rk[4];
|
||||
t1 =
|
||||
Te0(byte(s1, 3)) ^
|
||||
Te1(byte(s2, 2)) ^
|
||||
Te2(byte(s3, 1)) ^
|
||||
Te3(byte(s0, 0)) ^
|
||||
rk[5];
|
||||
t2 =
|
||||
Te0(byte(s2, 3)) ^
|
||||
Te1(byte(s3, 2)) ^
|
||||
Te2(byte(s0, 1)) ^
|
||||
Te3(byte(s1, 0)) ^
|
||||
rk[6];
|
||||
t3 =
|
||||
Te0(byte(s3, 3)) ^
|
||||
Te1(byte(s0, 2)) ^
|
||||
Te2(byte(s1, 1)) ^
|
||||
Te3(byte(s2, 0)) ^
|
||||
rk[7];
|
||||
|
||||
rk += 8;
|
||||
if (--r == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
s0 =
|
||||
Te0(byte(t0, 3)) ^
|
||||
Te1(byte(t1, 2)) ^
|
||||
Te2(byte(t2, 1)) ^
|
||||
Te3(byte(t3, 0)) ^
|
||||
rk[0];
|
||||
s1 =
|
||||
Te0(byte(t1, 3)) ^
|
||||
Te1(byte(t2, 2)) ^
|
||||
Te2(byte(t3, 1)) ^
|
||||
Te3(byte(t0, 0)) ^
|
||||
rk[1];
|
||||
s2 =
|
||||
Te0(byte(t2, 3)) ^
|
||||
Te1(byte(t3, 2)) ^
|
||||
Te2(byte(t0, 1)) ^
|
||||
Te3(byte(t1, 0)) ^
|
||||
rk[2];
|
||||
s3 =
|
||||
Te0(byte(t3, 3)) ^
|
||||
Te1(byte(t0, 2)) ^
|
||||
Te2(byte(t1, 1)) ^
|
||||
Te3(byte(t2, 0)) ^
|
||||
rk[3];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* apply last round and
|
||||
* map cipher state to byte array block:
|
||||
*/
|
||||
s0 =
|
||||
(Te4_3[byte(t0, 3)]) ^
|
||||
(Te4_2[byte(t1, 2)]) ^
|
||||
(Te4_1[byte(t2, 1)]) ^
|
||||
(Te4_0[byte(t3, 0)]) ^
|
||||
rk[0];
|
||||
STORE32H(s0, ct);
|
||||
s1 =
|
||||
(Te4_3[byte(t1, 3)]) ^
|
||||
(Te4_2[byte(t2, 2)]) ^
|
||||
(Te4_1[byte(t3, 1)]) ^
|
||||
(Te4_0[byte(t0, 0)]) ^
|
||||
rk[1];
|
||||
STORE32H(s1, ct+4);
|
||||
s2 =
|
||||
(Te4_3[byte(t2, 3)]) ^
|
||||
(Te4_2[byte(t3, 2)]) ^
|
||||
(Te4_1[byte(t0, 1)]) ^
|
||||
(Te4_0[byte(t1, 0)]) ^
|
||||
rk[2];
|
||||
STORE32H(s2, ct+8);
|
||||
s3 =
|
||||
(Te4_3[byte(t3, 3)]) ^
|
||||
(Te4_2[byte(t0, 2)]) ^
|
||||
(Te4_1[byte(t1, 1)]) ^
|
||||
(Te4_0[byte(t2, 0)]) ^
|
||||
rk[3];
|
||||
STORE32H(s3, ct+12);
|
||||
}
|
||||
|
||||
#ifdef CLEAN_STACK
|
||||
void ECB_ENC(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
|
||||
{
|
||||
_rijndael_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
|
||||
#ifdef 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)
|
||||
#endif
|
||||
{
|
||||
ulong32 s0, s1, s2, s3, t0, t1, t2, t3, *rk;
|
||||
int Nr, r;
|
||||
|
||||
_ARGCHK(pt != NULL);
|
||||
_ARGCHK(ct != NULL);
|
||||
_ARGCHK(skey != NULL);
|
||||
|
||||
Nr = skey->rijndael.Nr;
|
||||
rk = skey->rijndael.dK;
|
||||
|
||||
/*
|
||||
* map byte array block to cipher state
|
||||
* and add initial round key:
|
||||
*/
|
||||
LOAD32H(s0, ct ); s0 ^= rk[0];
|
||||
LOAD32H(s1, ct + 4); s1 ^= rk[1];
|
||||
LOAD32H(s2, ct + 8); s2 ^= rk[2];
|
||||
LOAD32H(s3, ct + 12); s3 ^= rk[3];
|
||||
|
||||
#ifdef SMALL_CODE
|
||||
for (r = 0; ; r++) {
|
||||
rk += 4;
|
||||
t0 =
|
||||
Td0(byte(s0, 3)) ^
|
||||
Td1(byte(s3, 2)) ^
|
||||
Td2(byte(s2, 1)) ^
|
||||
Td3(byte(s1, 0)) ^
|
||||
rk[0];
|
||||
t1 =
|
||||
Td0(byte(s1, 3)) ^
|
||||
Td1(byte(s0, 2)) ^
|
||||
Td2(byte(s3, 1)) ^
|
||||
Td3(byte(s2, 0)) ^
|
||||
rk[1];
|
||||
t2 =
|
||||
Td0(byte(s2, 3)) ^
|
||||
Td1(byte(s1, 2)) ^
|
||||
Td2(byte(s0, 1)) ^
|
||||
Td3(byte(s3, 0)) ^
|
||||
rk[2];
|
||||
t3 =
|
||||
Td0(byte(s3, 3)) ^
|
||||
Td1(byte(s2, 2)) ^
|
||||
Td2(byte(s1, 1)) ^
|
||||
Td3(byte(s0, 0)) ^
|
||||
rk[3];
|
||||
if (r == Nr-2) {
|
||||
break;
|
||||
}
|
||||
s0 = t0; s1 = t1; s2 = t2; s3 = t3;
|
||||
}
|
||||
rk += 4;
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Nr - 1 full rounds:
|
||||
*/
|
||||
r = Nr >> 1;
|
||||
for (;;) {
|
||||
|
||||
t0 =
|
||||
Td0(byte(s0, 3)) ^
|
||||
Td1(byte(s3, 2)) ^
|
||||
Td2(byte(s2, 1)) ^
|
||||
Td3(byte(s1, 0)) ^
|
||||
rk[4];
|
||||
t1 =
|
||||
Td0(byte(s1, 3)) ^
|
||||
Td1(byte(s0, 2)) ^
|
||||
Td2(byte(s3, 1)) ^
|
||||
Td3(byte(s2, 0)) ^
|
||||
rk[5];
|
||||
t2 =
|
||||
Td0(byte(s2, 3)) ^
|
||||
Td1(byte(s1, 2)) ^
|
||||
Td2(byte(s0, 1)) ^
|
||||
Td3(byte(s3, 0)) ^
|
||||
rk[6];
|
||||
t3 =
|
||||
Td0(byte(s3, 3)) ^
|
||||
Td1(byte(s2, 2)) ^
|
||||
Td2(byte(s1, 1)) ^
|
||||
Td3(byte(s0, 0)) ^
|
||||
rk[7];
|
||||
|
||||
rk += 8;
|
||||
if (--r == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
s0 =
|
||||
Td0(byte(t0, 3)) ^
|
||||
Td1(byte(t3, 2)) ^
|
||||
Td2(byte(t2, 1)) ^
|
||||
Td3(byte(t1, 0)) ^
|
||||
rk[0];
|
||||
s1 =
|
||||
Td0(byte(t1, 3)) ^
|
||||
Td1(byte(t0, 2)) ^
|
||||
Td2(byte(t3, 1)) ^
|
||||
Td3(byte(t2, 0)) ^
|
||||
rk[1];
|
||||
s2 =
|
||||
Td0(byte(t2, 3)) ^
|
||||
Td1(byte(t1, 2)) ^
|
||||
Td2(byte(t0, 1)) ^
|
||||
Td3(byte(t3, 0)) ^
|
||||
rk[2];
|
||||
s3 =
|
||||
Td0(byte(t3, 3)) ^
|
||||
Td1(byte(t2, 2)) ^
|
||||
Td2(byte(t1, 1)) ^
|
||||
Td3(byte(t0, 0)) ^
|
||||
rk[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* apply last round and
|
||||
* map cipher state to byte array block:
|
||||
*/
|
||||
s0 =
|
||||
(Td4[byte(t0, 3)] & 0xff000000) ^
|
||||
(Td4[byte(t3, 2)] & 0x00ff0000) ^
|
||||
(Td4[byte(t2, 1)] & 0x0000ff00) ^
|
||||
(Td4[byte(t1, 0)] & 0x000000ff) ^
|
||||
rk[0];
|
||||
STORE32H(s0, pt);
|
||||
s1 =
|
||||
(Td4[byte(t1, 3)] & 0xff000000) ^
|
||||
(Td4[byte(t0, 2)] & 0x00ff0000) ^
|
||||
(Td4[byte(t3, 1)] & 0x0000ff00) ^
|
||||
(Td4[byte(t2, 0)] & 0x000000ff) ^
|
||||
rk[1];
|
||||
STORE32H(s1, pt+4);
|
||||
s2 =
|
||||
(Td4[byte(t2, 3)] & 0xff000000) ^
|
||||
(Td4[byte(t1, 2)] & 0x00ff0000) ^
|
||||
(Td4[byte(t0, 1)] & 0x0000ff00) ^
|
||||
(Td4[byte(t3, 0)] & 0x000000ff) ^
|
||||
rk[2];
|
||||
STORE32H(s2, pt+8);
|
||||
s3 =
|
||||
(Td4[byte(t3, 3)] & 0xff000000) ^
|
||||
(Td4[byte(t2, 2)] & 0x00ff0000) ^
|
||||
(Td4[byte(t1, 1)] & 0x0000ff00) ^
|
||||
(Td4[byte(t0, 0)] & 0x000000ff) ^
|
||||
rk[3];
|
||||
STORE32H(s3, pt+12);
|
||||
}
|
||||
|
||||
|
||||
#ifdef CLEAN_STACK
|
||||
void ECB_DEC(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
|
||||
{
|
||||
_rijndael_ecb_decrypt(ct, pt, skey);
|
||||
burn_stack(sizeof(unsigned long)*8 + sizeof(unsigned long*) + sizeof(int)*2);
|
||||
}
|
||||
#endif
|
||||
|
||||
int ECB_TEST(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
int err;
|
||||
static const struct {
|
||||
int keylen;
|
||||
unsigned char key[32], pt[16], ct[16];
|
||||
} tests[] = {
|
||||
{ 16,
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
|
||||
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
|
||||
{ 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30,
|
||||
0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a }
|
||||
}, {
|
||||
24,
|
||||
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
|
||||
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
|
||||
{ 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0,
|
||||
0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 }
|
||||
}, {
|
||||
32,
|
||||
{ 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 },
|
||||
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
|
||||
{ 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
|
||||
0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 }
|
||||
}
|
||||
};
|
||||
|
||||
symmetric_key key;
|
||||
unsigned char tmp[2][16];
|
||||
int i, y;
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
zeromem(&key, sizeof(key));
|
||||
if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key);
|
||||
rijndael_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16) || memcmp(tmp[1], tests[i].pt, 16)) {
|
||||
#if 0
|
||||
printf("\n\nTest %d failed\n", i);
|
||||
if (memcmp(tmp[0], tests[i].ct, 16)) {
|
||||
printf("CT: ");
|
||||
for (i = 0; i < 16; i++) {
|
||||
printf("%02x ", tmp[0][i]);
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("PT: ");
|
||||
for (i = 0; i < 16; i++) {
|
||||
printf("%02x ", tmp[1][i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
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 < 16; y++) tmp[0][y] = 0;
|
||||
for (y = 0; y < 1000; y++) rijndael_ecb_encrypt(tmp[0], tmp[0], &key);
|
||||
for (y = 0; y < 1000; y++) rijndael_ecb_decrypt(tmp[0], tmp[0], &key);
|
||||
for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* ENCRYPT_ONLY */
|
||||
|
||||
int ECB_KS(int *desired_keysize)
|
||||
{
|
||||
_ARGCHK(desired_keysize != NULL);
|
||||
|
||||
if (*desired_keysize < 16)
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
if (*desired_keysize < 24) {
|
||||
*desired_keysize = 16;
|
||||
return CRYPT_OK;
|
||||
} else if (*desired_keysize < 32) {
|
||||
*desired_keysize = 24;
|
||||
return CRYPT_OK;
|
||||
} else {
|
||||
*desired_keysize = 32;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,5 +1,13 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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
|
||||
*/
|
||||
/* The precomputed tables for AES */
|
||||
/*
|
||||
Te0[x] = S [x].[02, 01, 01, 03];
|
||||
|
|
@ -15,12 +23,6 @@ Td3[x] = Si[x].[09, 0d, 0b, 0e];
|
|||
Td4[x] = Si[x].[01, 01, 01, 01];
|
||||
*/
|
||||
|
||||
#if defined(LTC_RIJNDAEL) && defined(LTC_AES_TAB_C)
|
||||
|
||||
/**
|
||||
@file aes_tab.c
|
||||
AES tables
|
||||
*/
|
||||
static const ulong32 TE0[256] = {
|
||||
0xc66363a5UL, 0xf87c7c84UL, 0xee777799UL, 0xf67b7b8dUL,
|
||||
0xfff2f20dUL, 0xd66b6bbdUL, 0xde6f6fb1UL, 0x91c5c554UL,
|
||||
|
|
@ -88,7 +90,6 @@ static const ulong32 TE0[256] = {
|
|||
0x7bb0b0cbUL, 0xa85454fcUL, 0x6dbbbbd6UL, 0x2c16163aUL,
|
||||
};
|
||||
|
||||
#if !defined(PELI_TAB) && defined(LTC_SMALL_CODE)
|
||||
static const ulong32 Te4[256] = {
|
||||
0x63636363UL, 0x7c7c7c7cUL, 0x77777777UL, 0x7b7b7b7bUL,
|
||||
0xf2f2f2f2UL, 0x6b6b6b6bUL, 0x6f6f6f6fUL, 0xc5c5c5c5UL,
|
||||
|
|
@ -155,7 +156,6 @@ static const ulong32 Te4[256] = {
|
|||
0x41414141UL, 0x99999999UL, 0x2d2d2d2dUL, 0x0f0f0f0fUL,
|
||||
0xb0b0b0b0UL, 0x54545454UL, 0xbbbbbbbbUL, 0x16161616UL,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
|
||||
|
|
@ -295,17 +295,17 @@ static const ulong32 Td4[256] = {
|
|||
|
||||
#endif /* ENCRYPT_ONLY */
|
||||
|
||||
#ifdef LTC_SMALL_CODE
|
||||
#ifdef SMALL_CODE
|
||||
|
||||
#define Te0(x) TE0[x]
|
||||
#define Te1(x) RORc(TE0[x], 8)
|
||||
#define Te2(x) RORc(TE0[x], 16)
|
||||
#define Te3(x) RORc(TE0[x], 24)
|
||||
#define Te1(x) ROR(TE0[x], 8)
|
||||
#define Te2(x) ROR(TE0[x], 16)
|
||||
#define Te3(x) ROR(TE0[x], 24)
|
||||
|
||||
#define Td0(x) TD0[x]
|
||||
#define Td1(x) RORc(TD0[x], 8)
|
||||
#define Td2(x) RORc(TD0[x], 16)
|
||||
#define Td3(x) RORc(TD0[x], 24)
|
||||
#define Td1(x) ROR(TD0[x], 8)
|
||||
#define Td2(x) ROR(TD0[x], 16)
|
||||
#define Td3(x) ROR(TD0[x], 24)
|
||||
|
||||
#define Te4_0 0x000000FF & Te4
|
||||
#define Te4_1 0x0000FF00 & Te4
|
||||
|
|
@ -524,147 +524,145 @@ static const ulong32 TE3[256] = {
|
|||
0xb0b0cb7bUL, 0x5454fca8UL, 0xbbbbd66dUL, 0x16163a2cUL,
|
||||
};
|
||||
|
||||
#ifndef PELI_TAB
|
||||
static const ulong32 Te4_0[] = {
|
||||
0x00000063UL, 0x0000007cUL, 0x00000077UL, 0x0000007bUL, 0x000000f2UL, 0x0000006bUL, 0x0000006fUL, 0x000000c5UL,
|
||||
0x00000030UL, 0x00000001UL, 0x00000067UL, 0x0000002bUL, 0x000000feUL, 0x000000d7UL, 0x000000abUL, 0x00000076UL,
|
||||
0x000000caUL, 0x00000082UL, 0x000000c9UL, 0x0000007dUL, 0x000000faUL, 0x00000059UL, 0x00000047UL, 0x000000f0UL,
|
||||
0x000000adUL, 0x000000d4UL, 0x000000a2UL, 0x000000afUL, 0x0000009cUL, 0x000000a4UL, 0x00000072UL, 0x000000c0UL,
|
||||
0x000000b7UL, 0x000000fdUL, 0x00000093UL, 0x00000026UL, 0x00000036UL, 0x0000003fUL, 0x000000f7UL, 0x000000ccUL,
|
||||
0x00000034UL, 0x000000a5UL, 0x000000e5UL, 0x000000f1UL, 0x00000071UL, 0x000000d8UL, 0x00000031UL, 0x00000015UL,
|
||||
0x00000004UL, 0x000000c7UL, 0x00000023UL, 0x000000c3UL, 0x00000018UL, 0x00000096UL, 0x00000005UL, 0x0000009aUL,
|
||||
0x00000007UL, 0x00000012UL, 0x00000080UL, 0x000000e2UL, 0x000000ebUL, 0x00000027UL, 0x000000b2UL, 0x00000075UL,
|
||||
0x00000009UL, 0x00000083UL, 0x0000002cUL, 0x0000001aUL, 0x0000001bUL, 0x0000006eUL, 0x0000005aUL, 0x000000a0UL,
|
||||
0x00000052UL, 0x0000003bUL, 0x000000d6UL, 0x000000b3UL, 0x00000029UL, 0x000000e3UL, 0x0000002fUL, 0x00000084UL,
|
||||
0x00000053UL, 0x000000d1UL, 0x00000000UL, 0x000000edUL, 0x00000020UL, 0x000000fcUL, 0x000000b1UL, 0x0000005bUL,
|
||||
0x0000006aUL, 0x000000cbUL, 0x000000beUL, 0x00000039UL, 0x0000004aUL, 0x0000004cUL, 0x00000058UL, 0x000000cfUL,
|
||||
0x000000d0UL, 0x000000efUL, 0x000000aaUL, 0x000000fbUL, 0x00000043UL, 0x0000004dUL, 0x00000033UL, 0x00000085UL,
|
||||
0x00000045UL, 0x000000f9UL, 0x00000002UL, 0x0000007fUL, 0x00000050UL, 0x0000003cUL, 0x0000009fUL, 0x000000a8UL,
|
||||
0x00000051UL, 0x000000a3UL, 0x00000040UL, 0x0000008fUL, 0x00000092UL, 0x0000009dUL, 0x00000038UL, 0x000000f5UL,
|
||||
0x000000bcUL, 0x000000b6UL, 0x000000daUL, 0x00000021UL, 0x00000010UL, 0x000000ffUL, 0x000000f3UL, 0x000000d2UL,
|
||||
0x000000cdUL, 0x0000000cUL, 0x00000013UL, 0x000000ecUL, 0x0000005fUL, 0x00000097UL, 0x00000044UL, 0x00000017UL,
|
||||
0x000000c4UL, 0x000000a7UL, 0x0000007eUL, 0x0000003dUL, 0x00000064UL, 0x0000005dUL, 0x00000019UL, 0x00000073UL,
|
||||
0x00000060UL, 0x00000081UL, 0x0000004fUL, 0x000000dcUL, 0x00000022UL, 0x0000002aUL, 0x00000090UL, 0x00000088UL,
|
||||
0x00000046UL, 0x000000eeUL, 0x000000b8UL, 0x00000014UL, 0x000000deUL, 0x0000005eUL, 0x0000000bUL, 0x000000dbUL,
|
||||
0x000000e0UL, 0x00000032UL, 0x0000003aUL, 0x0000000aUL, 0x00000049UL, 0x00000006UL, 0x00000024UL, 0x0000005cUL,
|
||||
0x000000c2UL, 0x000000d3UL, 0x000000acUL, 0x00000062UL, 0x00000091UL, 0x00000095UL, 0x000000e4UL, 0x00000079UL,
|
||||
0x000000e7UL, 0x000000c8UL, 0x00000037UL, 0x0000006dUL, 0x0000008dUL, 0x000000d5UL, 0x0000004eUL, 0x000000a9UL,
|
||||
0x0000006cUL, 0x00000056UL, 0x000000f4UL, 0x000000eaUL, 0x00000065UL, 0x0000007aUL, 0x000000aeUL, 0x00000008UL,
|
||||
0x000000baUL, 0x00000078UL, 0x00000025UL, 0x0000002eUL, 0x0000001cUL, 0x000000a6UL, 0x000000b4UL, 0x000000c6UL,
|
||||
0x000000e8UL, 0x000000ddUL, 0x00000074UL, 0x0000001fUL, 0x0000004bUL, 0x000000bdUL, 0x0000008bUL, 0x0000008aUL,
|
||||
0x00000070UL, 0x0000003eUL, 0x000000b5UL, 0x00000066UL, 0x00000048UL, 0x00000003UL, 0x000000f6UL, 0x0000000eUL,
|
||||
0x00000061UL, 0x00000035UL, 0x00000057UL, 0x000000b9UL, 0x00000086UL, 0x000000c1UL, 0x0000001dUL, 0x0000009eUL,
|
||||
0x000000e1UL, 0x000000f8UL, 0x00000098UL, 0x00000011UL, 0x00000069UL, 0x000000d9UL, 0x0000008eUL, 0x00000094UL,
|
||||
0x0000009bUL, 0x0000001eUL, 0x00000087UL, 0x000000e9UL, 0x000000ceUL, 0x00000055UL, 0x00000028UL, 0x000000dfUL,
|
||||
0x0000008cUL, 0x000000a1UL, 0x00000089UL, 0x0000000dUL, 0x000000bfUL, 0x000000e6UL, 0x00000042UL, 0x00000068UL,
|
||||
0x00000063UL, 0x0000007cUL, 0x00000077UL, 0x0000007bUL, 0x000000f2UL, 0x0000006bUL, 0x0000006fUL, 0x000000c5UL,
|
||||
0x00000030UL, 0x00000001UL, 0x00000067UL, 0x0000002bUL, 0x000000feUL, 0x000000d7UL, 0x000000abUL, 0x00000076UL,
|
||||
0x000000caUL, 0x00000082UL, 0x000000c9UL, 0x0000007dUL, 0x000000faUL, 0x00000059UL, 0x00000047UL, 0x000000f0UL,
|
||||
0x000000adUL, 0x000000d4UL, 0x000000a2UL, 0x000000afUL, 0x0000009cUL, 0x000000a4UL, 0x00000072UL, 0x000000c0UL,
|
||||
0x000000b7UL, 0x000000fdUL, 0x00000093UL, 0x00000026UL, 0x00000036UL, 0x0000003fUL, 0x000000f7UL, 0x000000ccUL,
|
||||
0x00000034UL, 0x000000a5UL, 0x000000e5UL, 0x000000f1UL, 0x00000071UL, 0x000000d8UL, 0x00000031UL, 0x00000015UL,
|
||||
0x00000004UL, 0x000000c7UL, 0x00000023UL, 0x000000c3UL, 0x00000018UL, 0x00000096UL, 0x00000005UL, 0x0000009aUL,
|
||||
0x00000007UL, 0x00000012UL, 0x00000080UL, 0x000000e2UL, 0x000000ebUL, 0x00000027UL, 0x000000b2UL, 0x00000075UL,
|
||||
0x00000009UL, 0x00000083UL, 0x0000002cUL, 0x0000001aUL, 0x0000001bUL, 0x0000006eUL, 0x0000005aUL, 0x000000a0UL,
|
||||
0x00000052UL, 0x0000003bUL, 0x000000d6UL, 0x000000b3UL, 0x00000029UL, 0x000000e3UL, 0x0000002fUL, 0x00000084UL,
|
||||
0x00000053UL, 0x000000d1UL, 0x00000000UL, 0x000000edUL, 0x00000020UL, 0x000000fcUL, 0x000000b1UL, 0x0000005bUL,
|
||||
0x0000006aUL, 0x000000cbUL, 0x000000beUL, 0x00000039UL, 0x0000004aUL, 0x0000004cUL, 0x00000058UL, 0x000000cfUL,
|
||||
0x000000d0UL, 0x000000efUL, 0x000000aaUL, 0x000000fbUL, 0x00000043UL, 0x0000004dUL, 0x00000033UL, 0x00000085UL,
|
||||
0x00000045UL, 0x000000f9UL, 0x00000002UL, 0x0000007fUL, 0x00000050UL, 0x0000003cUL, 0x0000009fUL, 0x000000a8UL,
|
||||
0x00000051UL, 0x000000a3UL, 0x00000040UL, 0x0000008fUL, 0x00000092UL, 0x0000009dUL, 0x00000038UL, 0x000000f5UL,
|
||||
0x000000bcUL, 0x000000b6UL, 0x000000daUL, 0x00000021UL, 0x00000010UL, 0x000000ffUL, 0x000000f3UL, 0x000000d2UL,
|
||||
0x000000cdUL, 0x0000000cUL, 0x00000013UL, 0x000000ecUL, 0x0000005fUL, 0x00000097UL, 0x00000044UL, 0x00000017UL,
|
||||
0x000000c4UL, 0x000000a7UL, 0x0000007eUL, 0x0000003dUL, 0x00000064UL, 0x0000005dUL, 0x00000019UL, 0x00000073UL,
|
||||
0x00000060UL, 0x00000081UL, 0x0000004fUL, 0x000000dcUL, 0x00000022UL, 0x0000002aUL, 0x00000090UL, 0x00000088UL,
|
||||
0x00000046UL, 0x000000eeUL, 0x000000b8UL, 0x00000014UL, 0x000000deUL, 0x0000005eUL, 0x0000000bUL, 0x000000dbUL,
|
||||
0x000000e0UL, 0x00000032UL, 0x0000003aUL, 0x0000000aUL, 0x00000049UL, 0x00000006UL, 0x00000024UL, 0x0000005cUL,
|
||||
0x000000c2UL, 0x000000d3UL, 0x000000acUL, 0x00000062UL, 0x00000091UL, 0x00000095UL, 0x000000e4UL, 0x00000079UL,
|
||||
0x000000e7UL, 0x000000c8UL, 0x00000037UL, 0x0000006dUL, 0x0000008dUL, 0x000000d5UL, 0x0000004eUL, 0x000000a9UL,
|
||||
0x0000006cUL, 0x00000056UL, 0x000000f4UL, 0x000000eaUL, 0x00000065UL, 0x0000007aUL, 0x000000aeUL, 0x00000008UL,
|
||||
0x000000baUL, 0x00000078UL, 0x00000025UL, 0x0000002eUL, 0x0000001cUL, 0x000000a6UL, 0x000000b4UL, 0x000000c6UL,
|
||||
0x000000e8UL, 0x000000ddUL, 0x00000074UL, 0x0000001fUL, 0x0000004bUL, 0x000000bdUL, 0x0000008bUL, 0x0000008aUL,
|
||||
0x00000070UL, 0x0000003eUL, 0x000000b5UL, 0x00000066UL, 0x00000048UL, 0x00000003UL, 0x000000f6UL, 0x0000000eUL,
|
||||
0x00000061UL, 0x00000035UL, 0x00000057UL, 0x000000b9UL, 0x00000086UL, 0x000000c1UL, 0x0000001dUL, 0x0000009eUL,
|
||||
0x000000e1UL, 0x000000f8UL, 0x00000098UL, 0x00000011UL, 0x00000069UL, 0x000000d9UL, 0x0000008eUL, 0x00000094UL,
|
||||
0x0000009bUL, 0x0000001eUL, 0x00000087UL, 0x000000e9UL, 0x000000ceUL, 0x00000055UL, 0x00000028UL, 0x000000dfUL,
|
||||
0x0000008cUL, 0x000000a1UL, 0x00000089UL, 0x0000000dUL, 0x000000bfUL, 0x000000e6UL, 0x00000042UL, 0x00000068UL,
|
||||
0x00000041UL, 0x00000099UL, 0x0000002dUL, 0x0000000fUL, 0x000000b0UL, 0x00000054UL, 0x000000bbUL, 0x00000016UL
|
||||
};
|
||||
|
||||
static const ulong32 Te4_1[] = {
|
||||
0x00006300UL, 0x00007c00UL, 0x00007700UL, 0x00007b00UL, 0x0000f200UL, 0x00006b00UL, 0x00006f00UL, 0x0000c500UL,
|
||||
0x00003000UL, 0x00000100UL, 0x00006700UL, 0x00002b00UL, 0x0000fe00UL, 0x0000d700UL, 0x0000ab00UL, 0x00007600UL,
|
||||
0x0000ca00UL, 0x00008200UL, 0x0000c900UL, 0x00007d00UL, 0x0000fa00UL, 0x00005900UL, 0x00004700UL, 0x0000f000UL,
|
||||
0x0000ad00UL, 0x0000d400UL, 0x0000a200UL, 0x0000af00UL, 0x00009c00UL, 0x0000a400UL, 0x00007200UL, 0x0000c000UL,
|
||||
0x0000b700UL, 0x0000fd00UL, 0x00009300UL, 0x00002600UL, 0x00003600UL, 0x00003f00UL, 0x0000f700UL, 0x0000cc00UL,
|
||||
0x00003400UL, 0x0000a500UL, 0x0000e500UL, 0x0000f100UL, 0x00007100UL, 0x0000d800UL, 0x00003100UL, 0x00001500UL,
|
||||
0x00000400UL, 0x0000c700UL, 0x00002300UL, 0x0000c300UL, 0x00001800UL, 0x00009600UL, 0x00000500UL, 0x00009a00UL,
|
||||
0x00000700UL, 0x00001200UL, 0x00008000UL, 0x0000e200UL, 0x0000eb00UL, 0x00002700UL, 0x0000b200UL, 0x00007500UL,
|
||||
0x00000900UL, 0x00008300UL, 0x00002c00UL, 0x00001a00UL, 0x00001b00UL, 0x00006e00UL, 0x00005a00UL, 0x0000a000UL,
|
||||
0x00005200UL, 0x00003b00UL, 0x0000d600UL, 0x0000b300UL, 0x00002900UL, 0x0000e300UL, 0x00002f00UL, 0x00008400UL,
|
||||
0x00005300UL, 0x0000d100UL, 0x00000000UL, 0x0000ed00UL, 0x00002000UL, 0x0000fc00UL, 0x0000b100UL, 0x00005b00UL,
|
||||
0x00006a00UL, 0x0000cb00UL, 0x0000be00UL, 0x00003900UL, 0x00004a00UL, 0x00004c00UL, 0x00005800UL, 0x0000cf00UL,
|
||||
0x0000d000UL, 0x0000ef00UL, 0x0000aa00UL, 0x0000fb00UL, 0x00004300UL, 0x00004d00UL, 0x00003300UL, 0x00008500UL,
|
||||
0x00004500UL, 0x0000f900UL, 0x00000200UL, 0x00007f00UL, 0x00005000UL, 0x00003c00UL, 0x00009f00UL, 0x0000a800UL,
|
||||
0x00005100UL, 0x0000a300UL, 0x00004000UL, 0x00008f00UL, 0x00009200UL, 0x00009d00UL, 0x00003800UL, 0x0000f500UL,
|
||||
0x0000bc00UL, 0x0000b600UL, 0x0000da00UL, 0x00002100UL, 0x00001000UL, 0x0000ff00UL, 0x0000f300UL, 0x0000d200UL,
|
||||
0x0000cd00UL, 0x00000c00UL, 0x00001300UL, 0x0000ec00UL, 0x00005f00UL, 0x00009700UL, 0x00004400UL, 0x00001700UL,
|
||||
0x0000c400UL, 0x0000a700UL, 0x00007e00UL, 0x00003d00UL, 0x00006400UL, 0x00005d00UL, 0x00001900UL, 0x00007300UL,
|
||||
0x00006000UL, 0x00008100UL, 0x00004f00UL, 0x0000dc00UL, 0x00002200UL, 0x00002a00UL, 0x00009000UL, 0x00008800UL,
|
||||
0x00004600UL, 0x0000ee00UL, 0x0000b800UL, 0x00001400UL, 0x0000de00UL, 0x00005e00UL, 0x00000b00UL, 0x0000db00UL,
|
||||
0x0000e000UL, 0x00003200UL, 0x00003a00UL, 0x00000a00UL, 0x00004900UL, 0x00000600UL, 0x00002400UL, 0x00005c00UL,
|
||||
0x0000c200UL, 0x0000d300UL, 0x0000ac00UL, 0x00006200UL, 0x00009100UL, 0x00009500UL, 0x0000e400UL, 0x00007900UL,
|
||||
0x0000e700UL, 0x0000c800UL, 0x00003700UL, 0x00006d00UL, 0x00008d00UL, 0x0000d500UL, 0x00004e00UL, 0x0000a900UL,
|
||||
0x00006c00UL, 0x00005600UL, 0x0000f400UL, 0x0000ea00UL, 0x00006500UL, 0x00007a00UL, 0x0000ae00UL, 0x00000800UL,
|
||||
0x0000ba00UL, 0x00007800UL, 0x00002500UL, 0x00002e00UL, 0x00001c00UL, 0x0000a600UL, 0x0000b400UL, 0x0000c600UL,
|
||||
0x0000e800UL, 0x0000dd00UL, 0x00007400UL, 0x00001f00UL, 0x00004b00UL, 0x0000bd00UL, 0x00008b00UL, 0x00008a00UL,
|
||||
0x00007000UL, 0x00003e00UL, 0x0000b500UL, 0x00006600UL, 0x00004800UL, 0x00000300UL, 0x0000f600UL, 0x00000e00UL,
|
||||
0x00006100UL, 0x00003500UL, 0x00005700UL, 0x0000b900UL, 0x00008600UL, 0x0000c100UL, 0x00001d00UL, 0x00009e00UL,
|
||||
0x0000e100UL, 0x0000f800UL, 0x00009800UL, 0x00001100UL, 0x00006900UL, 0x0000d900UL, 0x00008e00UL, 0x00009400UL,
|
||||
0x00009b00UL, 0x00001e00UL, 0x00008700UL, 0x0000e900UL, 0x0000ce00UL, 0x00005500UL, 0x00002800UL, 0x0000df00UL,
|
||||
0x00008c00UL, 0x0000a100UL, 0x00008900UL, 0x00000d00UL, 0x0000bf00UL, 0x0000e600UL, 0x00004200UL, 0x00006800UL,
|
||||
0x00006300UL, 0x00007c00UL, 0x00007700UL, 0x00007b00UL, 0x0000f200UL, 0x00006b00UL, 0x00006f00UL, 0x0000c500UL,
|
||||
0x00003000UL, 0x00000100UL, 0x00006700UL, 0x00002b00UL, 0x0000fe00UL, 0x0000d700UL, 0x0000ab00UL, 0x00007600UL,
|
||||
0x0000ca00UL, 0x00008200UL, 0x0000c900UL, 0x00007d00UL, 0x0000fa00UL, 0x00005900UL, 0x00004700UL, 0x0000f000UL,
|
||||
0x0000ad00UL, 0x0000d400UL, 0x0000a200UL, 0x0000af00UL, 0x00009c00UL, 0x0000a400UL, 0x00007200UL, 0x0000c000UL,
|
||||
0x0000b700UL, 0x0000fd00UL, 0x00009300UL, 0x00002600UL, 0x00003600UL, 0x00003f00UL, 0x0000f700UL, 0x0000cc00UL,
|
||||
0x00003400UL, 0x0000a500UL, 0x0000e500UL, 0x0000f100UL, 0x00007100UL, 0x0000d800UL, 0x00003100UL, 0x00001500UL,
|
||||
0x00000400UL, 0x0000c700UL, 0x00002300UL, 0x0000c300UL, 0x00001800UL, 0x00009600UL, 0x00000500UL, 0x00009a00UL,
|
||||
0x00000700UL, 0x00001200UL, 0x00008000UL, 0x0000e200UL, 0x0000eb00UL, 0x00002700UL, 0x0000b200UL, 0x00007500UL,
|
||||
0x00000900UL, 0x00008300UL, 0x00002c00UL, 0x00001a00UL, 0x00001b00UL, 0x00006e00UL, 0x00005a00UL, 0x0000a000UL,
|
||||
0x00005200UL, 0x00003b00UL, 0x0000d600UL, 0x0000b300UL, 0x00002900UL, 0x0000e300UL, 0x00002f00UL, 0x00008400UL,
|
||||
0x00005300UL, 0x0000d100UL, 0x00000000UL, 0x0000ed00UL, 0x00002000UL, 0x0000fc00UL, 0x0000b100UL, 0x00005b00UL,
|
||||
0x00006a00UL, 0x0000cb00UL, 0x0000be00UL, 0x00003900UL, 0x00004a00UL, 0x00004c00UL, 0x00005800UL, 0x0000cf00UL,
|
||||
0x0000d000UL, 0x0000ef00UL, 0x0000aa00UL, 0x0000fb00UL, 0x00004300UL, 0x00004d00UL, 0x00003300UL, 0x00008500UL,
|
||||
0x00004500UL, 0x0000f900UL, 0x00000200UL, 0x00007f00UL, 0x00005000UL, 0x00003c00UL, 0x00009f00UL, 0x0000a800UL,
|
||||
0x00005100UL, 0x0000a300UL, 0x00004000UL, 0x00008f00UL, 0x00009200UL, 0x00009d00UL, 0x00003800UL, 0x0000f500UL,
|
||||
0x0000bc00UL, 0x0000b600UL, 0x0000da00UL, 0x00002100UL, 0x00001000UL, 0x0000ff00UL, 0x0000f300UL, 0x0000d200UL,
|
||||
0x0000cd00UL, 0x00000c00UL, 0x00001300UL, 0x0000ec00UL, 0x00005f00UL, 0x00009700UL, 0x00004400UL, 0x00001700UL,
|
||||
0x0000c400UL, 0x0000a700UL, 0x00007e00UL, 0x00003d00UL, 0x00006400UL, 0x00005d00UL, 0x00001900UL, 0x00007300UL,
|
||||
0x00006000UL, 0x00008100UL, 0x00004f00UL, 0x0000dc00UL, 0x00002200UL, 0x00002a00UL, 0x00009000UL, 0x00008800UL,
|
||||
0x00004600UL, 0x0000ee00UL, 0x0000b800UL, 0x00001400UL, 0x0000de00UL, 0x00005e00UL, 0x00000b00UL, 0x0000db00UL,
|
||||
0x0000e000UL, 0x00003200UL, 0x00003a00UL, 0x00000a00UL, 0x00004900UL, 0x00000600UL, 0x00002400UL, 0x00005c00UL,
|
||||
0x0000c200UL, 0x0000d300UL, 0x0000ac00UL, 0x00006200UL, 0x00009100UL, 0x00009500UL, 0x0000e400UL, 0x00007900UL,
|
||||
0x0000e700UL, 0x0000c800UL, 0x00003700UL, 0x00006d00UL, 0x00008d00UL, 0x0000d500UL, 0x00004e00UL, 0x0000a900UL,
|
||||
0x00006c00UL, 0x00005600UL, 0x0000f400UL, 0x0000ea00UL, 0x00006500UL, 0x00007a00UL, 0x0000ae00UL, 0x00000800UL,
|
||||
0x0000ba00UL, 0x00007800UL, 0x00002500UL, 0x00002e00UL, 0x00001c00UL, 0x0000a600UL, 0x0000b400UL, 0x0000c600UL,
|
||||
0x0000e800UL, 0x0000dd00UL, 0x00007400UL, 0x00001f00UL, 0x00004b00UL, 0x0000bd00UL, 0x00008b00UL, 0x00008a00UL,
|
||||
0x00007000UL, 0x00003e00UL, 0x0000b500UL, 0x00006600UL, 0x00004800UL, 0x00000300UL, 0x0000f600UL, 0x00000e00UL,
|
||||
0x00006100UL, 0x00003500UL, 0x00005700UL, 0x0000b900UL, 0x00008600UL, 0x0000c100UL, 0x00001d00UL, 0x00009e00UL,
|
||||
0x0000e100UL, 0x0000f800UL, 0x00009800UL, 0x00001100UL, 0x00006900UL, 0x0000d900UL, 0x00008e00UL, 0x00009400UL,
|
||||
0x00009b00UL, 0x00001e00UL, 0x00008700UL, 0x0000e900UL, 0x0000ce00UL, 0x00005500UL, 0x00002800UL, 0x0000df00UL,
|
||||
0x00008c00UL, 0x0000a100UL, 0x00008900UL, 0x00000d00UL, 0x0000bf00UL, 0x0000e600UL, 0x00004200UL, 0x00006800UL,
|
||||
0x00004100UL, 0x00009900UL, 0x00002d00UL, 0x00000f00UL, 0x0000b000UL, 0x00005400UL, 0x0000bb00UL, 0x00001600UL
|
||||
};
|
||||
|
||||
static const ulong32 Te4_2[] = {
|
||||
0x00630000UL, 0x007c0000UL, 0x00770000UL, 0x007b0000UL, 0x00f20000UL, 0x006b0000UL, 0x006f0000UL, 0x00c50000UL,
|
||||
0x00300000UL, 0x00010000UL, 0x00670000UL, 0x002b0000UL, 0x00fe0000UL, 0x00d70000UL, 0x00ab0000UL, 0x00760000UL,
|
||||
0x00ca0000UL, 0x00820000UL, 0x00c90000UL, 0x007d0000UL, 0x00fa0000UL, 0x00590000UL, 0x00470000UL, 0x00f00000UL,
|
||||
0x00ad0000UL, 0x00d40000UL, 0x00a20000UL, 0x00af0000UL, 0x009c0000UL, 0x00a40000UL, 0x00720000UL, 0x00c00000UL,
|
||||
0x00b70000UL, 0x00fd0000UL, 0x00930000UL, 0x00260000UL, 0x00360000UL, 0x003f0000UL, 0x00f70000UL, 0x00cc0000UL,
|
||||
0x00340000UL, 0x00a50000UL, 0x00e50000UL, 0x00f10000UL, 0x00710000UL, 0x00d80000UL, 0x00310000UL, 0x00150000UL,
|
||||
0x00040000UL, 0x00c70000UL, 0x00230000UL, 0x00c30000UL, 0x00180000UL, 0x00960000UL, 0x00050000UL, 0x009a0000UL,
|
||||
0x00070000UL, 0x00120000UL, 0x00800000UL, 0x00e20000UL, 0x00eb0000UL, 0x00270000UL, 0x00b20000UL, 0x00750000UL,
|
||||
0x00090000UL, 0x00830000UL, 0x002c0000UL, 0x001a0000UL, 0x001b0000UL, 0x006e0000UL, 0x005a0000UL, 0x00a00000UL,
|
||||
0x00520000UL, 0x003b0000UL, 0x00d60000UL, 0x00b30000UL, 0x00290000UL, 0x00e30000UL, 0x002f0000UL, 0x00840000UL,
|
||||
0x00530000UL, 0x00d10000UL, 0x00000000UL, 0x00ed0000UL, 0x00200000UL, 0x00fc0000UL, 0x00b10000UL, 0x005b0000UL,
|
||||
0x006a0000UL, 0x00cb0000UL, 0x00be0000UL, 0x00390000UL, 0x004a0000UL, 0x004c0000UL, 0x00580000UL, 0x00cf0000UL,
|
||||
0x00d00000UL, 0x00ef0000UL, 0x00aa0000UL, 0x00fb0000UL, 0x00430000UL, 0x004d0000UL, 0x00330000UL, 0x00850000UL,
|
||||
0x00450000UL, 0x00f90000UL, 0x00020000UL, 0x007f0000UL, 0x00500000UL, 0x003c0000UL, 0x009f0000UL, 0x00a80000UL,
|
||||
0x00510000UL, 0x00a30000UL, 0x00400000UL, 0x008f0000UL, 0x00920000UL, 0x009d0000UL, 0x00380000UL, 0x00f50000UL,
|
||||
0x00bc0000UL, 0x00b60000UL, 0x00da0000UL, 0x00210000UL, 0x00100000UL, 0x00ff0000UL, 0x00f30000UL, 0x00d20000UL,
|
||||
0x00cd0000UL, 0x000c0000UL, 0x00130000UL, 0x00ec0000UL, 0x005f0000UL, 0x00970000UL, 0x00440000UL, 0x00170000UL,
|
||||
0x00c40000UL, 0x00a70000UL, 0x007e0000UL, 0x003d0000UL, 0x00640000UL, 0x005d0000UL, 0x00190000UL, 0x00730000UL,
|
||||
0x00600000UL, 0x00810000UL, 0x004f0000UL, 0x00dc0000UL, 0x00220000UL, 0x002a0000UL, 0x00900000UL, 0x00880000UL,
|
||||
0x00460000UL, 0x00ee0000UL, 0x00b80000UL, 0x00140000UL, 0x00de0000UL, 0x005e0000UL, 0x000b0000UL, 0x00db0000UL,
|
||||
0x00e00000UL, 0x00320000UL, 0x003a0000UL, 0x000a0000UL, 0x00490000UL, 0x00060000UL, 0x00240000UL, 0x005c0000UL,
|
||||
0x00c20000UL, 0x00d30000UL, 0x00ac0000UL, 0x00620000UL, 0x00910000UL, 0x00950000UL, 0x00e40000UL, 0x00790000UL,
|
||||
0x00e70000UL, 0x00c80000UL, 0x00370000UL, 0x006d0000UL, 0x008d0000UL, 0x00d50000UL, 0x004e0000UL, 0x00a90000UL,
|
||||
0x006c0000UL, 0x00560000UL, 0x00f40000UL, 0x00ea0000UL, 0x00650000UL, 0x007a0000UL, 0x00ae0000UL, 0x00080000UL,
|
||||
0x00ba0000UL, 0x00780000UL, 0x00250000UL, 0x002e0000UL, 0x001c0000UL, 0x00a60000UL, 0x00b40000UL, 0x00c60000UL,
|
||||
0x00e80000UL, 0x00dd0000UL, 0x00740000UL, 0x001f0000UL, 0x004b0000UL, 0x00bd0000UL, 0x008b0000UL, 0x008a0000UL,
|
||||
0x00700000UL, 0x003e0000UL, 0x00b50000UL, 0x00660000UL, 0x00480000UL, 0x00030000UL, 0x00f60000UL, 0x000e0000UL,
|
||||
0x00610000UL, 0x00350000UL, 0x00570000UL, 0x00b90000UL, 0x00860000UL, 0x00c10000UL, 0x001d0000UL, 0x009e0000UL,
|
||||
0x00e10000UL, 0x00f80000UL, 0x00980000UL, 0x00110000UL, 0x00690000UL, 0x00d90000UL, 0x008e0000UL, 0x00940000UL,
|
||||
0x009b0000UL, 0x001e0000UL, 0x00870000UL, 0x00e90000UL, 0x00ce0000UL, 0x00550000UL, 0x00280000UL, 0x00df0000UL,
|
||||
0x008c0000UL, 0x00a10000UL, 0x00890000UL, 0x000d0000UL, 0x00bf0000UL, 0x00e60000UL, 0x00420000UL, 0x00680000UL,
|
||||
0x00630000UL, 0x007c0000UL, 0x00770000UL, 0x007b0000UL, 0x00f20000UL, 0x006b0000UL, 0x006f0000UL, 0x00c50000UL,
|
||||
0x00300000UL, 0x00010000UL, 0x00670000UL, 0x002b0000UL, 0x00fe0000UL, 0x00d70000UL, 0x00ab0000UL, 0x00760000UL,
|
||||
0x00ca0000UL, 0x00820000UL, 0x00c90000UL, 0x007d0000UL, 0x00fa0000UL, 0x00590000UL, 0x00470000UL, 0x00f00000UL,
|
||||
0x00ad0000UL, 0x00d40000UL, 0x00a20000UL, 0x00af0000UL, 0x009c0000UL, 0x00a40000UL, 0x00720000UL, 0x00c00000UL,
|
||||
0x00b70000UL, 0x00fd0000UL, 0x00930000UL, 0x00260000UL, 0x00360000UL, 0x003f0000UL, 0x00f70000UL, 0x00cc0000UL,
|
||||
0x00340000UL, 0x00a50000UL, 0x00e50000UL, 0x00f10000UL, 0x00710000UL, 0x00d80000UL, 0x00310000UL, 0x00150000UL,
|
||||
0x00040000UL, 0x00c70000UL, 0x00230000UL, 0x00c30000UL, 0x00180000UL, 0x00960000UL, 0x00050000UL, 0x009a0000UL,
|
||||
0x00070000UL, 0x00120000UL, 0x00800000UL, 0x00e20000UL, 0x00eb0000UL, 0x00270000UL, 0x00b20000UL, 0x00750000UL,
|
||||
0x00090000UL, 0x00830000UL, 0x002c0000UL, 0x001a0000UL, 0x001b0000UL, 0x006e0000UL, 0x005a0000UL, 0x00a00000UL,
|
||||
0x00520000UL, 0x003b0000UL, 0x00d60000UL, 0x00b30000UL, 0x00290000UL, 0x00e30000UL, 0x002f0000UL, 0x00840000UL,
|
||||
0x00530000UL, 0x00d10000UL, 0x00000000UL, 0x00ed0000UL, 0x00200000UL, 0x00fc0000UL, 0x00b10000UL, 0x005b0000UL,
|
||||
0x006a0000UL, 0x00cb0000UL, 0x00be0000UL, 0x00390000UL, 0x004a0000UL, 0x004c0000UL, 0x00580000UL, 0x00cf0000UL,
|
||||
0x00d00000UL, 0x00ef0000UL, 0x00aa0000UL, 0x00fb0000UL, 0x00430000UL, 0x004d0000UL, 0x00330000UL, 0x00850000UL,
|
||||
0x00450000UL, 0x00f90000UL, 0x00020000UL, 0x007f0000UL, 0x00500000UL, 0x003c0000UL, 0x009f0000UL, 0x00a80000UL,
|
||||
0x00510000UL, 0x00a30000UL, 0x00400000UL, 0x008f0000UL, 0x00920000UL, 0x009d0000UL, 0x00380000UL, 0x00f50000UL,
|
||||
0x00bc0000UL, 0x00b60000UL, 0x00da0000UL, 0x00210000UL, 0x00100000UL, 0x00ff0000UL, 0x00f30000UL, 0x00d20000UL,
|
||||
0x00cd0000UL, 0x000c0000UL, 0x00130000UL, 0x00ec0000UL, 0x005f0000UL, 0x00970000UL, 0x00440000UL, 0x00170000UL,
|
||||
0x00c40000UL, 0x00a70000UL, 0x007e0000UL, 0x003d0000UL, 0x00640000UL, 0x005d0000UL, 0x00190000UL, 0x00730000UL,
|
||||
0x00600000UL, 0x00810000UL, 0x004f0000UL, 0x00dc0000UL, 0x00220000UL, 0x002a0000UL, 0x00900000UL, 0x00880000UL,
|
||||
0x00460000UL, 0x00ee0000UL, 0x00b80000UL, 0x00140000UL, 0x00de0000UL, 0x005e0000UL, 0x000b0000UL, 0x00db0000UL,
|
||||
0x00e00000UL, 0x00320000UL, 0x003a0000UL, 0x000a0000UL, 0x00490000UL, 0x00060000UL, 0x00240000UL, 0x005c0000UL,
|
||||
0x00c20000UL, 0x00d30000UL, 0x00ac0000UL, 0x00620000UL, 0x00910000UL, 0x00950000UL, 0x00e40000UL, 0x00790000UL,
|
||||
0x00e70000UL, 0x00c80000UL, 0x00370000UL, 0x006d0000UL, 0x008d0000UL, 0x00d50000UL, 0x004e0000UL, 0x00a90000UL,
|
||||
0x006c0000UL, 0x00560000UL, 0x00f40000UL, 0x00ea0000UL, 0x00650000UL, 0x007a0000UL, 0x00ae0000UL, 0x00080000UL,
|
||||
0x00ba0000UL, 0x00780000UL, 0x00250000UL, 0x002e0000UL, 0x001c0000UL, 0x00a60000UL, 0x00b40000UL, 0x00c60000UL,
|
||||
0x00e80000UL, 0x00dd0000UL, 0x00740000UL, 0x001f0000UL, 0x004b0000UL, 0x00bd0000UL, 0x008b0000UL, 0x008a0000UL,
|
||||
0x00700000UL, 0x003e0000UL, 0x00b50000UL, 0x00660000UL, 0x00480000UL, 0x00030000UL, 0x00f60000UL, 0x000e0000UL,
|
||||
0x00610000UL, 0x00350000UL, 0x00570000UL, 0x00b90000UL, 0x00860000UL, 0x00c10000UL, 0x001d0000UL, 0x009e0000UL,
|
||||
0x00e10000UL, 0x00f80000UL, 0x00980000UL, 0x00110000UL, 0x00690000UL, 0x00d90000UL, 0x008e0000UL, 0x00940000UL,
|
||||
0x009b0000UL, 0x001e0000UL, 0x00870000UL, 0x00e90000UL, 0x00ce0000UL, 0x00550000UL, 0x00280000UL, 0x00df0000UL,
|
||||
0x008c0000UL, 0x00a10000UL, 0x00890000UL, 0x000d0000UL, 0x00bf0000UL, 0x00e60000UL, 0x00420000UL, 0x00680000UL,
|
||||
0x00410000UL, 0x00990000UL, 0x002d0000UL, 0x000f0000UL, 0x00b00000UL, 0x00540000UL, 0x00bb0000UL, 0x00160000UL
|
||||
};
|
||||
|
||||
static const ulong32 Te4_3[] = {
|
||||
0x63000000UL, 0x7c000000UL, 0x77000000UL, 0x7b000000UL, 0xf2000000UL, 0x6b000000UL, 0x6f000000UL, 0xc5000000UL,
|
||||
0x30000000UL, 0x01000000UL, 0x67000000UL, 0x2b000000UL, 0xfe000000UL, 0xd7000000UL, 0xab000000UL, 0x76000000UL,
|
||||
0xca000000UL, 0x82000000UL, 0xc9000000UL, 0x7d000000UL, 0xfa000000UL, 0x59000000UL, 0x47000000UL, 0xf0000000UL,
|
||||
0xad000000UL, 0xd4000000UL, 0xa2000000UL, 0xaf000000UL, 0x9c000000UL, 0xa4000000UL, 0x72000000UL, 0xc0000000UL,
|
||||
0xb7000000UL, 0xfd000000UL, 0x93000000UL, 0x26000000UL, 0x36000000UL, 0x3f000000UL, 0xf7000000UL, 0xcc000000UL,
|
||||
0x34000000UL, 0xa5000000UL, 0xe5000000UL, 0xf1000000UL, 0x71000000UL, 0xd8000000UL, 0x31000000UL, 0x15000000UL,
|
||||
0x04000000UL, 0xc7000000UL, 0x23000000UL, 0xc3000000UL, 0x18000000UL, 0x96000000UL, 0x05000000UL, 0x9a000000UL,
|
||||
0x07000000UL, 0x12000000UL, 0x80000000UL, 0xe2000000UL, 0xeb000000UL, 0x27000000UL, 0xb2000000UL, 0x75000000UL,
|
||||
0x09000000UL, 0x83000000UL, 0x2c000000UL, 0x1a000000UL, 0x1b000000UL, 0x6e000000UL, 0x5a000000UL, 0xa0000000UL,
|
||||
0x52000000UL, 0x3b000000UL, 0xd6000000UL, 0xb3000000UL, 0x29000000UL, 0xe3000000UL, 0x2f000000UL, 0x84000000UL,
|
||||
0x53000000UL, 0xd1000000UL, 0x00000000UL, 0xed000000UL, 0x20000000UL, 0xfc000000UL, 0xb1000000UL, 0x5b000000UL,
|
||||
0x6a000000UL, 0xcb000000UL, 0xbe000000UL, 0x39000000UL, 0x4a000000UL, 0x4c000000UL, 0x58000000UL, 0xcf000000UL,
|
||||
0xd0000000UL, 0xef000000UL, 0xaa000000UL, 0xfb000000UL, 0x43000000UL, 0x4d000000UL, 0x33000000UL, 0x85000000UL,
|
||||
0x45000000UL, 0xf9000000UL, 0x02000000UL, 0x7f000000UL, 0x50000000UL, 0x3c000000UL, 0x9f000000UL, 0xa8000000UL,
|
||||
0x51000000UL, 0xa3000000UL, 0x40000000UL, 0x8f000000UL, 0x92000000UL, 0x9d000000UL, 0x38000000UL, 0xf5000000UL,
|
||||
0xbc000000UL, 0xb6000000UL, 0xda000000UL, 0x21000000UL, 0x10000000UL, 0xff000000UL, 0xf3000000UL, 0xd2000000UL,
|
||||
0xcd000000UL, 0x0c000000UL, 0x13000000UL, 0xec000000UL, 0x5f000000UL, 0x97000000UL, 0x44000000UL, 0x17000000UL,
|
||||
0xc4000000UL, 0xa7000000UL, 0x7e000000UL, 0x3d000000UL, 0x64000000UL, 0x5d000000UL, 0x19000000UL, 0x73000000UL,
|
||||
0x60000000UL, 0x81000000UL, 0x4f000000UL, 0xdc000000UL, 0x22000000UL, 0x2a000000UL, 0x90000000UL, 0x88000000UL,
|
||||
0x46000000UL, 0xee000000UL, 0xb8000000UL, 0x14000000UL, 0xde000000UL, 0x5e000000UL, 0x0b000000UL, 0xdb000000UL,
|
||||
0xe0000000UL, 0x32000000UL, 0x3a000000UL, 0x0a000000UL, 0x49000000UL, 0x06000000UL, 0x24000000UL, 0x5c000000UL,
|
||||
0xc2000000UL, 0xd3000000UL, 0xac000000UL, 0x62000000UL, 0x91000000UL, 0x95000000UL, 0xe4000000UL, 0x79000000UL,
|
||||
0xe7000000UL, 0xc8000000UL, 0x37000000UL, 0x6d000000UL, 0x8d000000UL, 0xd5000000UL, 0x4e000000UL, 0xa9000000UL,
|
||||
0x6c000000UL, 0x56000000UL, 0xf4000000UL, 0xea000000UL, 0x65000000UL, 0x7a000000UL, 0xae000000UL, 0x08000000UL,
|
||||
0xba000000UL, 0x78000000UL, 0x25000000UL, 0x2e000000UL, 0x1c000000UL, 0xa6000000UL, 0xb4000000UL, 0xc6000000UL,
|
||||
0xe8000000UL, 0xdd000000UL, 0x74000000UL, 0x1f000000UL, 0x4b000000UL, 0xbd000000UL, 0x8b000000UL, 0x8a000000UL,
|
||||
0x70000000UL, 0x3e000000UL, 0xb5000000UL, 0x66000000UL, 0x48000000UL, 0x03000000UL, 0xf6000000UL, 0x0e000000UL,
|
||||
0x61000000UL, 0x35000000UL, 0x57000000UL, 0xb9000000UL, 0x86000000UL, 0xc1000000UL, 0x1d000000UL, 0x9e000000UL,
|
||||
0xe1000000UL, 0xf8000000UL, 0x98000000UL, 0x11000000UL, 0x69000000UL, 0xd9000000UL, 0x8e000000UL, 0x94000000UL,
|
||||
0x9b000000UL, 0x1e000000UL, 0x87000000UL, 0xe9000000UL, 0xce000000UL, 0x55000000UL, 0x28000000UL, 0xdf000000UL,
|
||||
0x8c000000UL, 0xa1000000UL, 0x89000000UL, 0x0d000000UL, 0xbf000000UL, 0xe6000000UL, 0x42000000UL, 0x68000000UL,
|
||||
0x63000000UL, 0x7c000000UL, 0x77000000UL, 0x7b000000UL, 0xf2000000UL, 0x6b000000UL, 0x6f000000UL, 0xc5000000UL,
|
||||
0x30000000UL, 0x01000000UL, 0x67000000UL, 0x2b000000UL, 0xfe000000UL, 0xd7000000UL, 0xab000000UL, 0x76000000UL,
|
||||
0xca000000UL, 0x82000000UL, 0xc9000000UL, 0x7d000000UL, 0xfa000000UL, 0x59000000UL, 0x47000000UL, 0xf0000000UL,
|
||||
0xad000000UL, 0xd4000000UL, 0xa2000000UL, 0xaf000000UL, 0x9c000000UL, 0xa4000000UL, 0x72000000UL, 0xc0000000UL,
|
||||
0xb7000000UL, 0xfd000000UL, 0x93000000UL, 0x26000000UL, 0x36000000UL, 0x3f000000UL, 0xf7000000UL, 0xcc000000UL,
|
||||
0x34000000UL, 0xa5000000UL, 0xe5000000UL, 0xf1000000UL, 0x71000000UL, 0xd8000000UL, 0x31000000UL, 0x15000000UL,
|
||||
0x04000000UL, 0xc7000000UL, 0x23000000UL, 0xc3000000UL, 0x18000000UL, 0x96000000UL, 0x05000000UL, 0x9a000000UL,
|
||||
0x07000000UL, 0x12000000UL, 0x80000000UL, 0xe2000000UL, 0xeb000000UL, 0x27000000UL, 0xb2000000UL, 0x75000000UL,
|
||||
0x09000000UL, 0x83000000UL, 0x2c000000UL, 0x1a000000UL, 0x1b000000UL, 0x6e000000UL, 0x5a000000UL, 0xa0000000UL,
|
||||
0x52000000UL, 0x3b000000UL, 0xd6000000UL, 0xb3000000UL, 0x29000000UL, 0xe3000000UL, 0x2f000000UL, 0x84000000UL,
|
||||
0x53000000UL, 0xd1000000UL, 0x00000000UL, 0xed000000UL, 0x20000000UL, 0xfc000000UL, 0xb1000000UL, 0x5b000000UL,
|
||||
0x6a000000UL, 0xcb000000UL, 0xbe000000UL, 0x39000000UL, 0x4a000000UL, 0x4c000000UL, 0x58000000UL, 0xcf000000UL,
|
||||
0xd0000000UL, 0xef000000UL, 0xaa000000UL, 0xfb000000UL, 0x43000000UL, 0x4d000000UL, 0x33000000UL, 0x85000000UL,
|
||||
0x45000000UL, 0xf9000000UL, 0x02000000UL, 0x7f000000UL, 0x50000000UL, 0x3c000000UL, 0x9f000000UL, 0xa8000000UL,
|
||||
0x51000000UL, 0xa3000000UL, 0x40000000UL, 0x8f000000UL, 0x92000000UL, 0x9d000000UL, 0x38000000UL, 0xf5000000UL,
|
||||
0xbc000000UL, 0xb6000000UL, 0xda000000UL, 0x21000000UL, 0x10000000UL, 0xff000000UL, 0xf3000000UL, 0xd2000000UL,
|
||||
0xcd000000UL, 0x0c000000UL, 0x13000000UL, 0xec000000UL, 0x5f000000UL, 0x97000000UL, 0x44000000UL, 0x17000000UL,
|
||||
0xc4000000UL, 0xa7000000UL, 0x7e000000UL, 0x3d000000UL, 0x64000000UL, 0x5d000000UL, 0x19000000UL, 0x73000000UL,
|
||||
0x60000000UL, 0x81000000UL, 0x4f000000UL, 0xdc000000UL, 0x22000000UL, 0x2a000000UL, 0x90000000UL, 0x88000000UL,
|
||||
0x46000000UL, 0xee000000UL, 0xb8000000UL, 0x14000000UL, 0xde000000UL, 0x5e000000UL, 0x0b000000UL, 0xdb000000UL,
|
||||
0xe0000000UL, 0x32000000UL, 0x3a000000UL, 0x0a000000UL, 0x49000000UL, 0x06000000UL, 0x24000000UL, 0x5c000000UL,
|
||||
0xc2000000UL, 0xd3000000UL, 0xac000000UL, 0x62000000UL, 0x91000000UL, 0x95000000UL, 0xe4000000UL, 0x79000000UL,
|
||||
0xe7000000UL, 0xc8000000UL, 0x37000000UL, 0x6d000000UL, 0x8d000000UL, 0xd5000000UL, 0x4e000000UL, 0xa9000000UL,
|
||||
0x6c000000UL, 0x56000000UL, 0xf4000000UL, 0xea000000UL, 0x65000000UL, 0x7a000000UL, 0xae000000UL, 0x08000000UL,
|
||||
0xba000000UL, 0x78000000UL, 0x25000000UL, 0x2e000000UL, 0x1c000000UL, 0xa6000000UL, 0xb4000000UL, 0xc6000000UL,
|
||||
0xe8000000UL, 0xdd000000UL, 0x74000000UL, 0x1f000000UL, 0x4b000000UL, 0xbd000000UL, 0x8b000000UL, 0x8a000000UL,
|
||||
0x70000000UL, 0x3e000000UL, 0xb5000000UL, 0x66000000UL, 0x48000000UL, 0x03000000UL, 0xf6000000UL, 0x0e000000UL,
|
||||
0x61000000UL, 0x35000000UL, 0x57000000UL, 0xb9000000UL, 0x86000000UL, 0xc1000000UL, 0x1d000000UL, 0x9e000000UL,
|
||||
0xe1000000UL, 0xf8000000UL, 0x98000000UL, 0x11000000UL, 0x69000000UL, 0xd9000000UL, 0x8e000000UL, 0x94000000UL,
|
||||
0x9b000000UL, 0x1e000000UL, 0x87000000UL, 0xe9000000UL, 0xce000000UL, 0x55000000UL, 0x28000000UL, 0xdf000000UL,
|
||||
0x8c000000UL, 0xa1000000UL, 0x89000000UL, 0x0d000000UL, 0xbf000000UL, 0xe6000000UL, 0x42000000UL, 0x68000000UL,
|
||||
0x41000000UL, 0x99000000UL, 0x2d000000UL, 0x0f000000UL, 0xb0000000UL, 0x54000000UL, 0xbb000000UL, 0x16000000UL
|
||||
};
|
||||
#endif /* pelimac */
|
||||
|
||||
#ifndef ENCRYPT_ONLY
|
||||
|
||||
|
|
@ -868,142 +866,142 @@ static const ulong32 TD3[256] = {
|
|||
};
|
||||
|
||||
static const ulong32 Tks0[] = {
|
||||
0x00000000UL, 0x0e090d0bUL, 0x1c121a16UL, 0x121b171dUL, 0x3824342cUL, 0x362d3927UL, 0x24362e3aUL, 0x2a3f2331UL,
|
||||
0x70486858UL, 0x7e416553UL, 0x6c5a724eUL, 0x62537f45UL, 0x486c5c74UL, 0x4665517fUL, 0x547e4662UL, 0x5a774b69UL,
|
||||
0xe090d0b0UL, 0xee99ddbbUL, 0xfc82caa6UL, 0xf28bc7adUL, 0xd8b4e49cUL, 0xd6bde997UL, 0xc4a6fe8aUL, 0xcaaff381UL,
|
||||
0x90d8b8e8UL, 0x9ed1b5e3UL, 0x8ccaa2feUL, 0x82c3aff5UL, 0xa8fc8cc4UL, 0xa6f581cfUL, 0xb4ee96d2UL, 0xbae79bd9UL,
|
||||
0xdb3bbb7bUL, 0xd532b670UL, 0xc729a16dUL, 0xc920ac66UL, 0xe31f8f57UL, 0xed16825cUL, 0xff0d9541UL, 0xf104984aUL,
|
||||
0xab73d323UL, 0xa57ade28UL, 0xb761c935UL, 0xb968c43eUL, 0x9357e70fUL, 0x9d5eea04UL, 0x8f45fd19UL, 0x814cf012UL,
|
||||
0x3bab6bcbUL, 0x35a266c0UL, 0x27b971ddUL, 0x29b07cd6UL, 0x038f5fe7UL, 0x0d8652ecUL, 0x1f9d45f1UL, 0x119448faUL,
|
||||
0x4be30393UL, 0x45ea0e98UL, 0x57f11985UL, 0x59f8148eUL, 0x73c737bfUL, 0x7dce3ab4UL, 0x6fd52da9UL, 0x61dc20a2UL,
|
||||
0xad766df6UL, 0xa37f60fdUL, 0xb16477e0UL, 0xbf6d7aebUL, 0x955259daUL, 0x9b5b54d1UL, 0x894043ccUL, 0x87494ec7UL,
|
||||
0xdd3e05aeUL, 0xd33708a5UL, 0xc12c1fb8UL, 0xcf2512b3UL, 0xe51a3182UL, 0xeb133c89UL, 0xf9082b94UL, 0xf701269fUL,
|
||||
0x4de6bd46UL, 0x43efb04dUL, 0x51f4a750UL, 0x5ffdaa5bUL, 0x75c2896aUL, 0x7bcb8461UL, 0x69d0937cUL, 0x67d99e77UL,
|
||||
0x3daed51eUL, 0x33a7d815UL, 0x21bccf08UL, 0x2fb5c203UL, 0x058ae132UL, 0x0b83ec39UL, 0x1998fb24UL, 0x1791f62fUL,
|
||||
0x764dd68dUL, 0x7844db86UL, 0x6a5fcc9bUL, 0x6456c190UL, 0x4e69e2a1UL, 0x4060efaaUL, 0x527bf8b7UL, 0x5c72f5bcUL,
|
||||
0x0605bed5UL, 0x080cb3deUL, 0x1a17a4c3UL, 0x141ea9c8UL, 0x3e218af9UL, 0x302887f2UL, 0x223390efUL, 0x2c3a9de4UL,
|
||||
0x96dd063dUL, 0x98d40b36UL, 0x8acf1c2bUL, 0x84c61120UL, 0xaef93211UL, 0xa0f03f1aUL, 0xb2eb2807UL, 0xbce2250cUL,
|
||||
0xe6956e65UL, 0xe89c636eUL, 0xfa877473UL, 0xf48e7978UL, 0xdeb15a49UL, 0xd0b85742UL, 0xc2a3405fUL, 0xccaa4d54UL,
|
||||
0x41ecdaf7UL, 0x4fe5d7fcUL, 0x5dfec0e1UL, 0x53f7cdeaUL, 0x79c8eedbUL, 0x77c1e3d0UL, 0x65daf4cdUL, 0x6bd3f9c6UL,
|
||||
0x31a4b2afUL, 0x3fadbfa4UL, 0x2db6a8b9UL, 0x23bfa5b2UL, 0x09808683UL, 0x07898b88UL, 0x15929c95UL, 0x1b9b919eUL,
|
||||
0xa17c0a47UL, 0xaf75074cUL, 0xbd6e1051UL, 0xb3671d5aUL, 0x99583e6bUL, 0x97513360UL, 0x854a247dUL, 0x8b432976UL,
|
||||
0xd134621fUL, 0xdf3d6f14UL, 0xcd267809UL, 0xc32f7502UL, 0xe9105633UL, 0xe7195b38UL, 0xf5024c25UL, 0xfb0b412eUL,
|
||||
0x9ad7618cUL, 0x94de6c87UL, 0x86c57b9aUL, 0x88cc7691UL, 0xa2f355a0UL, 0xacfa58abUL, 0xbee14fb6UL, 0xb0e842bdUL,
|
||||
0xea9f09d4UL, 0xe49604dfUL, 0xf68d13c2UL, 0xf8841ec9UL, 0xd2bb3df8UL, 0xdcb230f3UL, 0xcea927eeUL, 0xc0a02ae5UL,
|
||||
0x7a47b13cUL, 0x744ebc37UL, 0x6655ab2aUL, 0x685ca621UL, 0x42638510UL, 0x4c6a881bUL, 0x5e719f06UL, 0x5078920dUL,
|
||||
0x0a0fd964UL, 0x0406d46fUL, 0x161dc372UL, 0x1814ce79UL, 0x322bed48UL, 0x3c22e043UL, 0x2e39f75eUL, 0x2030fa55UL,
|
||||
0xec9ab701UL, 0xe293ba0aUL, 0xf088ad17UL, 0xfe81a01cUL, 0xd4be832dUL, 0xdab78e26UL, 0xc8ac993bUL, 0xc6a59430UL,
|
||||
0x9cd2df59UL, 0x92dbd252UL, 0x80c0c54fUL, 0x8ec9c844UL, 0xa4f6eb75UL, 0xaaffe67eUL, 0xb8e4f163UL, 0xb6edfc68UL,
|
||||
0x0c0a67b1UL, 0x02036abaUL, 0x10187da7UL, 0x1e1170acUL, 0x342e539dUL, 0x3a275e96UL, 0x283c498bUL, 0x26354480UL,
|
||||
0x7c420fe9UL, 0x724b02e2UL, 0x605015ffUL, 0x6e5918f4UL, 0x44663bc5UL, 0x4a6f36ceUL, 0x587421d3UL, 0x567d2cd8UL,
|
||||
0x37a10c7aUL, 0x39a80171UL, 0x2bb3166cUL, 0x25ba1b67UL, 0x0f853856UL, 0x018c355dUL, 0x13972240UL, 0x1d9e2f4bUL,
|
||||
0x47e96422UL, 0x49e06929UL, 0x5bfb7e34UL, 0x55f2733fUL, 0x7fcd500eUL, 0x71c45d05UL, 0x63df4a18UL, 0x6dd64713UL,
|
||||
0xd731dccaUL, 0xd938d1c1UL, 0xcb23c6dcUL, 0xc52acbd7UL, 0xef15e8e6UL, 0xe11ce5edUL, 0xf307f2f0UL, 0xfd0efffbUL,
|
||||
0x00000000UL, 0x0e090d0bUL, 0x1c121a16UL, 0x121b171dUL, 0x3824342cUL, 0x362d3927UL, 0x24362e3aUL, 0x2a3f2331UL,
|
||||
0x70486858UL, 0x7e416553UL, 0x6c5a724eUL, 0x62537f45UL, 0x486c5c74UL, 0x4665517fUL, 0x547e4662UL, 0x5a774b69UL,
|
||||
0xe090d0b0UL, 0xee99ddbbUL, 0xfc82caa6UL, 0xf28bc7adUL, 0xd8b4e49cUL, 0xd6bde997UL, 0xc4a6fe8aUL, 0xcaaff381UL,
|
||||
0x90d8b8e8UL, 0x9ed1b5e3UL, 0x8ccaa2feUL, 0x82c3aff5UL, 0xa8fc8cc4UL, 0xa6f581cfUL, 0xb4ee96d2UL, 0xbae79bd9UL,
|
||||
0xdb3bbb7bUL, 0xd532b670UL, 0xc729a16dUL, 0xc920ac66UL, 0xe31f8f57UL, 0xed16825cUL, 0xff0d9541UL, 0xf104984aUL,
|
||||
0xab73d323UL, 0xa57ade28UL, 0xb761c935UL, 0xb968c43eUL, 0x9357e70fUL, 0x9d5eea04UL, 0x8f45fd19UL, 0x814cf012UL,
|
||||
0x3bab6bcbUL, 0x35a266c0UL, 0x27b971ddUL, 0x29b07cd6UL, 0x038f5fe7UL, 0x0d8652ecUL, 0x1f9d45f1UL, 0x119448faUL,
|
||||
0x4be30393UL, 0x45ea0e98UL, 0x57f11985UL, 0x59f8148eUL, 0x73c737bfUL, 0x7dce3ab4UL, 0x6fd52da9UL, 0x61dc20a2UL,
|
||||
0xad766df6UL, 0xa37f60fdUL, 0xb16477e0UL, 0xbf6d7aebUL, 0x955259daUL, 0x9b5b54d1UL, 0x894043ccUL, 0x87494ec7UL,
|
||||
0xdd3e05aeUL, 0xd33708a5UL, 0xc12c1fb8UL, 0xcf2512b3UL, 0xe51a3182UL, 0xeb133c89UL, 0xf9082b94UL, 0xf701269fUL,
|
||||
0x4de6bd46UL, 0x43efb04dUL, 0x51f4a750UL, 0x5ffdaa5bUL, 0x75c2896aUL, 0x7bcb8461UL, 0x69d0937cUL, 0x67d99e77UL,
|
||||
0x3daed51eUL, 0x33a7d815UL, 0x21bccf08UL, 0x2fb5c203UL, 0x058ae132UL, 0x0b83ec39UL, 0x1998fb24UL, 0x1791f62fUL,
|
||||
0x764dd68dUL, 0x7844db86UL, 0x6a5fcc9bUL, 0x6456c190UL, 0x4e69e2a1UL, 0x4060efaaUL, 0x527bf8b7UL, 0x5c72f5bcUL,
|
||||
0x0605bed5UL, 0x080cb3deUL, 0x1a17a4c3UL, 0x141ea9c8UL, 0x3e218af9UL, 0x302887f2UL, 0x223390efUL, 0x2c3a9de4UL,
|
||||
0x96dd063dUL, 0x98d40b36UL, 0x8acf1c2bUL, 0x84c61120UL, 0xaef93211UL, 0xa0f03f1aUL, 0xb2eb2807UL, 0xbce2250cUL,
|
||||
0xe6956e65UL, 0xe89c636eUL, 0xfa877473UL, 0xf48e7978UL, 0xdeb15a49UL, 0xd0b85742UL, 0xc2a3405fUL, 0xccaa4d54UL,
|
||||
0x41ecdaf7UL, 0x4fe5d7fcUL, 0x5dfec0e1UL, 0x53f7cdeaUL, 0x79c8eedbUL, 0x77c1e3d0UL, 0x65daf4cdUL, 0x6bd3f9c6UL,
|
||||
0x31a4b2afUL, 0x3fadbfa4UL, 0x2db6a8b9UL, 0x23bfa5b2UL, 0x09808683UL, 0x07898b88UL, 0x15929c95UL, 0x1b9b919eUL,
|
||||
0xa17c0a47UL, 0xaf75074cUL, 0xbd6e1051UL, 0xb3671d5aUL, 0x99583e6bUL, 0x97513360UL, 0x854a247dUL, 0x8b432976UL,
|
||||
0xd134621fUL, 0xdf3d6f14UL, 0xcd267809UL, 0xc32f7502UL, 0xe9105633UL, 0xe7195b38UL, 0xf5024c25UL, 0xfb0b412eUL,
|
||||
0x9ad7618cUL, 0x94de6c87UL, 0x86c57b9aUL, 0x88cc7691UL, 0xa2f355a0UL, 0xacfa58abUL, 0xbee14fb6UL, 0xb0e842bdUL,
|
||||
0xea9f09d4UL, 0xe49604dfUL, 0xf68d13c2UL, 0xf8841ec9UL, 0xd2bb3df8UL, 0xdcb230f3UL, 0xcea927eeUL, 0xc0a02ae5UL,
|
||||
0x7a47b13cUL, 0x744ebc37UL, 0x6655ab2aUL, 0x685ca621UL, 0x42638510UL, 0x4c6a881bUL, 0x5e719f06UL, 0x5078920dUL,
|
||||
0x0a0fd964UL, 0x0406d46fUL, 0x161dc372UL, 0x1814ce79UL, 0x322bed48UL, 0x3c22e043UL, 0x2e39f75eUL, 0x2030fa55UL,
|
||||
0xec9ab701UL, 0xe293ba0aUL, 0xf088ad17UL, 0xfe81a01cUL, 0xd4be832dUL, 0xdab78e26UL, 0xc8ac993bUL, 0xc6a59430UL,
|
||||
0x9cd2df59UL, 0x92dbd252UL, 0x80c0c54fUL, 0x8ec9c844UL, 0xa4f6eb75UL, 0xaaffe67eUL, 0xb8e4f163UL, 0xb6edfc68UL,
|
||||
0x0c0a67b1UL, 0x02036abaUL, 0x10187da7UL, 0x1e1170acUL, 0x342e539dUL, 0x3a275e96UL, 0x283c498bUL, 0x26354480UL,
|
||||
0x7c420fe9UL, 0x724b02e2UL, 0x605015ffUL, 0x6e5918f4UL, 0x44663bc5UL, 0x4a6f36ceUL, 0x587421d3UL, 0x567d2cd8UL,
|
||||
0x37a10c7aUL, 0x39a80171UL, 0x2bb3166cUL, 0x25ba1b67UL, 0x0f853856UL, 0x018c355dUL, 0x13972240UL, 0x1d9e2f4bUL,
|
||||
0x47e96422UL, 0x49e06929UL, 0x5bfb7e34UL, 0x55f2733fUL, 0x7fcd500eUL, 0x71c45d05UL, 0x63df4a18UL, 0x6dd64713UL,
|
||||
0xd731dccaUL, 0xd938d1c1UL, 0xcb23c6dcUL, 0xc52acbd7UL, 0xef15e8e6UL, 0xe11ce5edUL, 0xf307f2f0UL, 0xfd0efffbUL,
|
||||
0xa779b492UL, 0xa970b999UL, 0xbb6bae84UL, 0xb562a38fUL, 0x9f5d80beUL, 0x91548db5UL, 0x834f9aa8UL, 0x8d4697a3UL
|
||||
};
|
||||
|
||||
static const ulong32 Tks1[] = {
|
||||
0x00000000UL, 0x0b0e090dUL, 0x161c121aUL, 0x1d121b17UL, 0x2c382434UL, 0x27362d39UL, 0x3a24362eUL, 0x312a3f23UL,
|
||||
0x58704868UL, 0x537e4165UL, 0x4e6c5a72UL, 0x4562537fUL, 0x74486c5cUL, 0x7f466551UL, 0x62547e46UL, 0x695a774bUL,
|
||||
0xb0e090d0UL, 0xbbee99ddUL, 0xa6fc82caUL, 0xadf28bc7UL, 0x9cd8b4e4UL, 0x97d6bde9UL, 0x8ac4a6feUL, 0x81caaff3UL,
|
||||
0xe890d8b8UL, 0xe39ed1b5UL, 0xfe8ccaa2UL, 0xf582c3afUL, 0xc4a8fc8cUL, 0xcfa6f581UL, 0xd2b4ee96UL, 0xd9bae79bUL,
|
||||
0x7bdb3bbbUL, 0x70d532b6UL, 0x6dc729a1UL, 0x66c920acUL, 0x57e31f8fUL, 0x5ced1682UL, 0x41ff0d95UL, 0x4af10498UL,
|
||||
0x23ab73d3UL, 0x28a57adeUL, 0x35b761c9UL, 0x3eb968c4UL, 0x0f9357e7UL, 0x049d5eeaUL, 0x198f45fdUL, 0x12814cf0UL,
|
||||
0xcb3bab6bUL, 0xc035a266UL, 0xdd27b971UL, 0xd629b07cUL, 0xe7038f5fUL, 0xec0d8652UL, 0xf11f9d45UL, 0xfa119448UL,
|
||||
0x934be303UL, 0x9845ea0eUL, 0x8557f119UL, 0x8e59f814UL, 0xbf73c737UL, 0xb47dce3aUL, 0xa96fd52dUL, 0xa261dc20UL,
|
||||
0xf6ad766dUL, 0xfda37f60UL, 0xe0b16477UL, 0xebbf6d7aUL, 0xda955259UL, 0xd19b5b54UL, 0xcc894043UL, 0xc787494eUL,
|
||||
0xaedd3e05UL, 0xa5d33708UL, 0xb8c12c1fUL, 0xb3cf2512UL, 0x82e51a31UL, 0x89eb133cUL, 0x94f9082bUL, 0x9ff70126UL,
|
||||
0x464de6bdUL, 0x4d43efb0UL, 0x5051f4a7UL, 0x5b5ffdaaUL, 0x6a75c289UL, 0x617bcb84UL, 0x7c69d093UL, 0x7767d99eUL,
|
||||
0x1e3daed5UL, 0x1533a7d8UL, 0x0821bccfUL, 0x032fb5c2UL, 0x32058ae1UL, 0x390b83ecUL, 0x241998fbUL, 0x2f1791f6UL,
|
||||
0x8d764dd6UL, 0x867844dbUL, 0x9b6a5fccUL, 0x906456c1UL, 0xa14e69e2UL, 0xaa4060efUL, 0xb7527bf8UL, 0xbc5c72f5UL,
|
||||
0xd50605beUL, 0xde080cb3UL, 0xc31a17a4UL, 0xc8141ea9UL, 0xf93e218aUL, 0xf2302887UL, 0xef223390UL, 0xe42c3a9dUL,
|
||||
0x3d96dd06UL, 0x3698d40bUL, 0x2b8acf1cUL, 0x2084c611UL, 0x11aef932UL, 0x1aa0f03fUL, 0x07b2eb28UL, 0x0cbce225UL,
|
||||
0x65e6956eUL, 0x6ee89c63UL, 0x73fa8774UL, 0x78f48e79UL, 0x49deb15aUL, 0x42d0b857UL, 0x5fc2a340UL, 0x54ccaa4dUL,
|
||||
0xf741ecdaUL, 0xfc4fe5d7UL, 0xe15dfec0UL, 0xea53f7cdUL, 0xdb79c8eeUL, 0xd077c1e3UL, 0xcd65daf4UL, 0xc66bd3f9UL,
|
||||
0xaf31a4b2UL, 0xa43fadbfUL, 0xb92db6a8UL, 0xb223bfa5UL, 0x83098086UL, 0x8807898bUL, 0x9515929cUL, 0x9e1b9b91UL,
|
||||
0x47a17c0aUL, 0x4caf7507UL, 0x51bd6e10UL, 0x5ab3671dUL, 0x6b99583eUL, 0x60975133UL, 0x7d854a24UL, 0x768b4329UL,
|
||||
0x1fd13462UL, 0x14df3d6fUL, 0x09cd2678UL, 0x02c32f75UL, 0x33e91056UL, 0x38e7195bUL, 0x25f5024cUL, 0x2efb0b41UL,
|
||||
0x8c9ad761UL, 0x8794de6cUL, 0x9a86c57bUL, 0x9188cc76UL, 0xa0a2f355UL, 0xabacfa58UL, 0xb6bee14fUL, 0xbdb0e842UL,
|
||||
0xd4ea9f09UL, 0xdfe49604UL, 0xc2f68d13UL, 0xc9f8841eUL, 0xf8d2bb3dUL, 0xf3dcb230UL, 0xeecea927UL, 0xe5c0a02aUL,
|
||||
0x3c7a47b1UL, 0x37744ebcUL, 0x2a6655abUL, 0x21685ca6UL, 0x10426385UL, 0x1b4c6a88UL, 0x065e719fUL, 0x0d507892UL,
|
||||
0x640a0fd9UL, 0x6f0406d4UL, 0x72161dc3UL, 0x791814ceUL, 0x48322bedUL, 0x433c22e0UL, 0x5e2e39f7UL, 0x552030faUL,
|
||||
0x01ec9ab7UL, 0x0ae293baUL, 0x17f088adUL, 0x1cfe81a0UL, 0x2dd4be83UL, 0x26dab78eUL, 0x3bc8ac99UL, 0x30c6a594UL,
|
||||
0x599cd2dfUL, 0x5292dbd2UL, 0x4f80c0c5UL, 0x448ec9c8UL, 0x75a4f6ebUL, 0x7eaaffe6UL, 0x63b8e4f1UL, 0x68b6edfcUL,
|
||||
0xb10c0a67UL, 0xba02036aUL, 0xa710187dUL, 0xac1e1170UL, 0x9d342e53UL, 0x963a275eUL, 0x8b283c49UL, 0x80263544UL,
|
||||
0xe97c420fUL, 0xe2724b02UL, 0xff605015UL, 0xf46e5918UL, 0xc544663bUL, 0xce4a6f36UL, 0xd3587421UL, 0xd8567d2cUL,
|
||||
0x7a37a10cUL, 0x7139a801UL, 0x6c2bb316UL, 0x6725ba1bUL, 0x560f8538UL, 0x5d018c35UL, 0x40139722UL, 0x4b1d9e2fUL,
|
||||
0x2247e964UL, 0x2949e069UL, 0x345bfb7eUL, 0x3f55f273UL, 0x0e7fcd50UL, 0x0571c45dUL, 0x1863df4aUL, 0x136dd647UL,
|
||||
0xcad731dcUL, 0xc1d938d1UL, 0xdccb23c6UL, 0xd7c52acbUL, 0xe6ef15e8UL, 0xede11ce5UL, 0xf0f307f2UL, 0xfbfd0effUL,
|
||||
0x00000000UL, 0x0b0e090dUL, 0x161c121aUL, 0x1d121b17UL, 0x2c382434UL, 0x27362d39UL, 0x3a24362eUL, 0x312a3f23UL,
|
||||
0x58704868UL, 0x537e4165UL, 0x4e6c5a72UL, 0x4562537fUL, 0x74486c5cUL, 0x7f466551UL, 0x62547e46UL, 0x695a774bUL,
|
||||
0xb0e090d0UL, 0xbbee99ddUL, 0xa6fc82caUL, 0xadf28bc7UL, 0x9cd8b4e4UL, 0x97d6bde9UL, 0x8ac4a6feUL, 0x81caaff3UL,
|
||||
0xe890d8b8UL, 0xe39ed1b5UL, 0xfe8ccaa2UL, 0xf582c3afUL, 0xc4a8fc8cUL, 0xcfa6f581UL, 0xd2b4ee96UL, 0xd9bae79bUL,
|
||||
0x7bdb3bbbUL, 0x70d532b6UL, 0x6dc729a1UL, 0x66c920acUL, 0x57e31f8fUL, 0x5ced1682UL, 0x41ff0d95UL, 0x4af10498UL,
|
||||
0x23ab73d3UL, 0x28a57adeUL, 0x35b761c9UL, 0x3eb968c4UL, 0x0f9357e7UL, 0x049d5eeaUL, 0x198f45fdUL, 0x12814cf0UL,
|
||||
0xcb3bab6bUL, 0xc035a266UL, 0xdd27b971UL, 0xd629b07cUL, 0xe7038f5fUL, 0xec0d8652UL, 0xf11f9d45UL, 0xfa119448UL,
|
||||
0x934be303UL, 0x9845ea0eUL, 0x8557f119UL, 0x8e59f814UL, 0xbf73c737UL, 0xb47dce3aUL, 0xa96fd52dUL, 0xa261dc20UL,
|
||||
0xf6ad766dUL, 0xfda37f60UL, 0xe0b16477UL, 0xebbf6d7aUL, 0xda955259UL, 0xd19b5b54UL, 0xcc894043UL, 0xc787494eUL,
|
||||
0xaedd3e05UL, 0xa5d33708UL, 0xb8c12c1fUL, 0xb3cf2512UL, 0x82e51a31UL, 0x89eb133cUL, 0x94f9082bUL, 0x9ff70126UL,
|
||||
0x464de6bdUL, 0x4d43efb0UL, 0x5051f4a7UL, 0x5b5ffdaaUL, 0x6a75c289UL, 0x617bcb84UL, 0x7c69d093UL, 0x7767d99eUL,
|
||||
0x1e3daed5UL, 0x1533a7d8UL, 0x0821bccfUL, 0x032fb5c2UL, 0x32058ae1UL, 0x390b83ecUL, 0x241998fbUL, 0x2f1791f6UL,
|
||||
0x8d764dd6UL, 0x867844dbUL, 0x9b6a5fccUL, 0x906456c1UL, 0xa14e69e2UL, 0xaa4060efUL, 0xb7527bf8UL, 0xbc5c72f5UL,
|
||||
0xd50605beUL, 0xde080cb3UL, 0xc31a17a4UL, 0xc8141ea9UL, 0xf93e218aUL, 0xf2302887UL, 0xef223390UL, 0xe42c3a9dUL,
|
||||
0x3d96dd06UL, 0x3698d40bUL, 0x2b8acf1cUL, 0x2084c611UL, 0x11aef932UL, 0x1aa0f03fUL, 0x07b2eb28UL, 0x0cbce225UL,
|
||||
0x65e6956eUL, 0x6ee89c63UL, 0x73fa8774UL, 0x78f48e79UL, 0x49deb15aUL, 0x42d0b857UL, 0x5fc2a340UL, 0x54ccaa4dUL,
|
||||
0xf741ecdaUL, 0xfc4fe5d7UL, 0xe15dfec0UL, 0xea53f7cdUL, 0xdb79c8eeUL, 0xd077c1e3UL, 0xcd65daf4UL, 0xc66bd3f9UL,
|
||||
0xaf31a4b2UL, 0xa43fadbfUL, 0xb92db6a8UL, 0xb223bfa5UL, 0x83098086UL, 0x8807898bUL, 0x9515929cUL, 0x9e1b9b91UL,
|
||||
0x47a17c0aUL, 0x4caf7507UL, 0x51bd6e10UL, 0x5ab3671dUL, 0x6b99583eUL, 0x60975133UL, 0x7d854a24UL, 0x768b4329UL,
|
||||
0x1fd13462UL, 0x14df3d6fUL, 0x09cd2678UL, 0x02c32f75UL, 0x33e91056UL, 0x38e7195bUL, 0x25f5024cUL, 0x2efb0b41UL,
|
||||
0x8c9ad761UL, 0x8794de6cUL, 0x9a86c57bUL, 0x9188cc76UL, 0xa0a2f355UL, 0xabacfa58UL, 0xb6bee14fUL, 0xbdb0e842UL,
|
||||
0xd4ea9f09UL, 0xdfe49604UL, 0xc2f68d13UL, 0xc9f8841eUL, 0xf8d2bb3dUL, 0xf3dcb230UL, 0xeecea927UL, 0xe5c0a02aUL,
|
||||
0x3c7a47b1UL, 0x37744ebcUL, 0x2a6655abUL, 0x21685ca6UL, 0x10426385UL, 0x1b4c6a88UL, 0x065e719fUL, 0x0d507892UL,
|
||||
0x640a0fd9UL, 0x6f0406d4UL, 0x72161dc3UL, 0x791814ceUL, 0x48322bedUL, 0x433c22e0UL, 0x5e2e39f7UL, 0x552030faUL,
|
||||
0x01ec9ab7UL, 0x0ae293baUL, 0x17f088adUL, 0x1cfe81a0UL, 0x2dd4be83UL, 0x26dab78eUL, 0x3bc8ac99UL, 0x30c6a594UL,
|
||||
0x599cd2dfUL, 0x5292dbd2UL, 0x4f80c0c5UL, 0x448ec9c8UL, 0x75a4f6ebUL, 0x7eaaffe6UL, 0x63b8e4f1UL, 0x68b6edfcUL,
|
||||
0xb10c0a67UL, 0xba02036aUL, 0xa710187dUL, 0xac1e1170UL, 0x9d342e53UL, 0x963a275eUL, 0x8b283c49UL, 0x80263544UL,
|
||||
0xe97c420fUL, 0xe2724b02UL, 0xff605015UL, 0xf46e5918UL, 0xc544663bUL, 0xce4a6f36UL, 0xd3587421UL, 0xd8567d2cUL,
|
||||
0x7a37a10cUL, 0x7139a801UL, 0x6c2bb316UL, 0x6725ba1bUL, 0x560f8538UL, 0x5d018c35UL, 0x40139722UL, 0x4b1d9e2fUL,
|
||||
0x2247e964UL, 0x2949e069UL, 0x345bfb7eUL, 0x3f55f273UL, 0x0e7fcd50UL, 0x0571c45dUL, 0x1863df4aUL, 0x136dd647UL,
|
||||
0xcad731dcUL, 0xc1d938d1UL, 0xdccb23c6UL, 0xd7c52acbUL, 0xe6ef15e8UL, 0xede11ce5UL, 0xf0f307f2UL, 0xfbfd0effUL,
|
||||
0x92a779b4UL, 0x99a970b9UL, 0x84bb6baeUL, 0x8fb562a3UL, 0xbe9f5d80UL, 0xb591548dUL, 0xa8834f9aUL, 0xa38d4697UL
|
||||
};
|
||||
|
||||
static const ulong32 Tks2[] = {
|
||||
0x00000000UL, 0x0d0b0e09UL, 0x1a161c12UL, 0x171d121bUL, 0x342c3824UL, 0x3927362dUL, 0x2e3a2436UL, 0x23312a3fUL,
|
||||
0x68587048UL, 0x65537e41UL, 0x724e6c5aUL, 0x7f456253UL, 0x5c74486cUL, 0x517f4665UL, 0x4662547eUL, 0x4b695a77UL,
|
||||
0xd0b0e090UL, 0xddbbee99UL, 0xcaa6fc82UL, 0xc7adf28bUL, 0xe49cd8b4UL, 0xe997d6bdUL, 0xfe8ac4a6UL, 0xf381caafUL,
|
||||
0xb8e890d8UL, 0xb5e39ed1UL, 0xa2fe8ccaUL, 0xaff582c3UL, 0x8cc4a8fcUL, 0x81cfa6f5UL, 0x96d2b4eeUL, 0x9bd9bae7UL,
|
||||
0xbb7bdb3bUL, 0xb670d532UL, 0xa16dc729UL, 0xac66c920UL, 0x8f57e31fUL, 0x825ced16UL, 0x9541ff0dUL, 0x984af104UL,
|
||||
0xd323ab73UL, 0xde28a57aUL, 0xc935b761UL, 0xc43eb968UL, 0xe70f9357UL, 0xea049d5eUL, 0xfd198f45UL, 0xf012814cUL,
|
||||
0x6bcb3babUL, 0x66c035a2UL, 0x71dd27b9UL, 0x7cd629b0UL, 0x5fe7038fUL, 0x52ec0d86UL, 0x45f11f9dUL, 0x48fa1194UL,
|
||||
0x03934be3UL, 0x0e9845eaUL, 0x198557f1UL, 0x148e59f8UL, 0x37bf73c7UL, 0x3ab47dceUL, 0x2da96fd5UL, 0x20a261dcUL,
|
||||
0x6df6ad76UL, 0x60fda37fUL, 0x77e0b164UL, 0x7aebbf6dUL, 0x59da9552UL, 0x54d19b5bUL, 0x43cc8940UL, 0x4ec78749UL,
|
||||
0x05aedd3eUL, 0x08a5d337UL, 0x1fb8c12cUL, 0x12b3cf25UL, 0x3182e51aUL, 0x3c89eb13UL, 0x2b94f908UL, 0x269ff701UL,
|
||||
0xbd464de6UL, 0xb04d43efUL, 0xa75051f4UL, 0xaa5b5ffdUL, 0x896a75c2UL, 0x84617bcbUL, 0x937c69d0UL, 0x9e7767d9UL,
|
||||
0xd51e3daeUL, 0xd81533a7UL, 0xcf0821bcUL, 0xc2032fb5UL, 0xe132058aUL, 0xec390b83UL, 0xfb241998UL, 0xf62f1791UL,
|
||||
0xd68d764dUL, 0xdb867844UL, 0xcc9b6a5fUL, 0xc1906456UL, 0xe2a14e69UL, 0xefaa4060UL, 0xf8b7527bUL, 0xf5bc5c72UL,
|
||||
0xbed50605UL, 0xb3de080cUL, 0xa4c31a17UL, 0xa9c8141eUL, 0x8af93e21UL, 0x87f23028UL, 0x90ef2233UL, 0x9de42c3aUL,
|
||||
0x063d96ddUL, 0x0b3698d4UL, 0x1c2b8acfUL, 0x112084c6UL, 0x3211aef9UL, 0x3f1aa0f0UL, 0x2807b2ebUL, 0x250cbce2UL,
|
||||
0x6e65e695UL, 0x636ee89cUL, 0x7473fa87UL, 0x7978f48eUL, 0x5a49deb1UL, 0x5742d0b8UL, 0x405fc2a3UL, 0x4d54ccaaUL,
|
||||
0xdaf741ecUL, 0xd7fc4fe5UL, 0xc0e15dfeUL, 0xcdea53f7UL, 0xeedb79c8UL, 0xe3d077c1UL, 0xf4cd65daUL, 0xf9c66bd3UL,
|
||||
0xb2af31a4UL, 0xbfa43fadUL, 0xa8b92db6UL, 0xa5b223bfUL, 0x86830980UL, 0x8b880789UL, 0x9c951592UL, 0x919e1b9bUL,
|
||||
0x0a47a17cUL, 0x074caf75UL, 0x1051bd6eUL, 0x1d5ab367UL, 0x3e6b9958UL, 0x33609751UL, 0x247d854aUL, 0x29768b43UL,
|
||||
0x621fd134UL, 0x6f14df3dUL, 0x7809cd26UL, 0x7502c32fUL, 0x5633e910UL, 0x5b38e719UL, 0x4c25f502UL, 0x412efb0bUL,
|
||||
0x618c9ad7UL, 0x6c8794deUL, 0x7b9a86c5UL, 0x769188ccUL, 0x55a0a2f3UL, 0x58abacfaUL, 0x4fb6bee1UL, 0x42bdb0e8UL,
|
||||
0x09d4ea9fUL, 0x04dfe496UL, 0x13c2f68dUL, 0x1ec9f884UL, 0x3df8d2bbUL, 0x30f3dcb2UL, 0x27eecea9UL, 0x2ae5c0a0UL,
|
||||
0xb13c7a47UL, 0xbc37744eUL, 0xab2a6655UL, 0xa621685cUL, 0x85104263UL, 0x881b4c6aUL, 0x9f065e71UL, 0x920d5078UL,
|
||||
0xd9640a0fUL, 0xd46f0406UL, 0xc372161dUL, 0xce791814UL, 0xed48322bUL, 0xe0433c22UL, 0xf75e2e39UL, 0xfa552030UL,
|
||||
0xb701ec9aUL, 0xba0ae293UL, 0xad17f088UL, 0xa01cfe81UL, 0x832dd4beUL, 0x8e26dab7UL, 0x993bc8acUL, 0x9430c6a5UL,
|
||||
0xdf599cd2UL, 0xd25292dbUL, 0xc54f80c0UL, 0xc8448ec9UL, 0xeb75a4f6UL, 0xe67eaaffUL, 0xf163b8e4UL, 0xfc68b6edUL,
|
||||
0x67b10c0aUL, 0x6aba0203UL, 0x7da71018UL, 0x70ac1e11UL, 0x539d342eUL, 0x5e963a27UL, 0x498b283cUL, 0x44802635UL,
|
||||
0x0fe97c42UL, 0x02e2724bUL, 0x15ff6050UL, 0x18f46e59UL, 0x3bc54466UL, 0x36ce4a6fUL, 0x21d35874UL, 0x2cd8567dUL,
|
||||
0x0c7a37a1UL, 0x017139a8UL, 0x166c2bb3UL, 0x1b6725baUL, 0x38560f85UL, 0x355d018cUL, 0x22401397UL, 0x2f4b1d9eUL,
|
||||
0x642247e9UL, 0x692949e0UL, 0x7e345bfbUL, 0x733f55f2UL, 0x500e7fcdUL, 0x5d0571c4UL, 0x4a1863dfUL, 0x47136dd6UL,
|
||||
0xdccad731UL, 0xd1c1d938UL, 0xc6dccb23UL, 0xcbd7c52aUL, 0xe8e6ef15UL, 0xe5ede11cUL, 0xf2f0f307UL, 0xfffbfd0eUL,
|
||||
0x00000000UL, 0x0d0b0e09UL, 0x1a161c12UL, 0x171d121bUL, 0x342c3824UL, 0x3927362dUL, 0x2e3a2436UL, 0x23312a3fUL,
|
||||
0x68587048UL, 0x65537e41UL, 0x724e6c5aUL, 0x7f456253UL, 0x5c74486cUL, 0x517f4665UL, 0x4662547eUL, 0x4b695a77UL,
|
||||
0xd0b0e090UL, 0xddbbee99UL, 0xcaa6fc82UL, 0xc7adf28bUL, 0xe49cd8b4UL, 0xe997d6bdUL, 0xfe8ac4a6UL, 0xf381caafUL,
|
||||
0xb8e890d8UL, 0xb5e39ed1UL, 0xa2fe8ccaUL, 0xaff582c3UL, 0x8cc4a8fcUL, 0x81cfa6f5UL, 0x96d2b4eeUL, 0x9bd9bae7UL,
|
||||
0xbb7bdb3bUL, 0xb670d532UL, 0xa16dc729UL, 0xac66c920UL, 0x8f57e31fUL, 0x825ced16UL, 0x9541ff0dUL, 0x984af104UL,
|
||||
0xd323ab73UL, 0xde28a57aUL, 0xc935b761UL, 0xc43eb968UL, 0xe70f9357UL, 0xea049d5eUL, 0xfd198f45UL, 0xf012814cUL,
|
||||
0x6bcb3babUL, 0x66c035a2UL, 0x71dd27b9UL, 0x7cd629b0UL, 0x5fe7038fUL, 0x52ec0d86UL, 0x45f11f9dUL, 0x48fa1194UL,
|
||||
0x03934be3UL, 0x0e9845eaUL, 0x198557f1UL, 0x148e59f8UL, 0x37bf73c7UL, 0x3ab47dceUL, 0x2da96fd5UL, 0x20a261dcUL,
|
||||
0x6df6ad76UL, 0x60fda37fUL, 0x77e0b164UL, 0x7aebbf6dUL, 0x59da9552UL, 0x54d19b5bUL, 0x43cc8940UL, 0x4ec78749UL,
|
||||
0x05aedd3eUL, 0x08a5d337UL, 0x1fb8c12cUL, 0x12b3cf25UL, 0x3182e51aUL, 0x3c89eb13UL, 0x2b94f908UL, 0x269ff701UL,
|
||||
0xbd464de6UL, 0xb04d43efUL, 0xa75051f4UL, 0xaa5b5ffdUL, 0x896a75c2UL, 0x84617bcbUL, 0x937c69d0UL, 0x9e7767d9UL,
|
||||
0xd51e3daeUL, 0xd81533a7UL, 0xcf0821bcUL, 0xc2032fb5UL, 0xe132058aUL, 0xec390b83UL, 0xfb241998UL, 0xf62f1791UL,
|
||||
0xd68d764dUL, 0xdb867844UL, 0xcc9b6a5fUL, 0xc1906456UL, 0xe2a14e69UL, 0xefaa4060UL, 0xf8b7527bUL, 0xf5bc5c72UL,
|
||||
0xbed50605UL, 0xb3de080cUL, 0xa4c31a17UL, 0xa9c8141eUL, 0x8af93e21UL, 0x87f23028UL, 0x90ef2233UL, 0x9de42c3aUL,
|
||||
0x063d96ddUL, 0x0b3698d4UL, 0x1c2b8acfUL, 0x112084c6UL, 0x3211aef9UL, 0x3f1aa0f0UL, 0x2807b2ebUL, 0x250cbce2UL,
|
||||
0x6e65e695UL, 0x636ee89cUL, 0x7473fa87UL, 0x7978f48eUL, 0x5a49deb1UL, 0x5742d0b8UL, 0x405fc2a3UL, 0x4d54ccaaUL,
|
||||
0xdaf741ecUL, 0xd7fc4fe5UL, 0xc0e15dfeUL, 0xcdea53f7UL, 0xeedb79c8UL, 0xe3d077c1UL, 0xf4cd65daUL, 0xf9c66bd3UL,
|
||||
0xb2af31a4UL, 0xbfa43fadUL, 0xa8b92db6UL, 0xa5b223bfUL, 0x86830980UL, 0x8b880789UL, 0x9c951592UL, 0x919e1b9bUL,
|
||||
0x0a47a17cUL, 0x074caf75UL, 0x1051bd6eUL, 0x1d5ab367UL, 0x3e6b9958UL, 0x33609751UL, 0x247d854aUL, 0x29768b43UL,
|
||||
0x621fd134UL, 0x6f14df3dUL, 0x7809cd26UL, 0x7502c32fUL, 0x5633e910UL, 0x5b38e719UL, 0x4c25f502UL, 0x412efb0bUL,
|
||||
0x618c9ad7UL, 0x6c8794deUL, 0x7b9a86c5UL, 0x769188ccUL, 0x55a0a2f3UL, 0x58abacfaUL, 0x4fb6bee1UL, 0x42bdb0e8UL,
|
||||
0x09d4ea9fUL, 0x04dfe496UL, 0x13c2f68dUL, 0x1ec9f884UL, 0x3df8d2bbUL, 0x30f3dcb2UL, 0x27eecea9UL, 0x2ae5c0a0UL,
|
||||
0xb13c7a47UL, 0xbc37744eUL, 0xab2a6655UL, 0xa621685cUL, 0x85104263UL, 0x881b4c6aUL, 0x9f065e71UL, 0x920d5078UL,
|
||||
0xd9640a0fUL, 0xd46f0406UL, 0xc372161dUL, 0xce791814UL, 0xed48322bUL, 0xe0433c22UL, 0xf75e2e39UL, 0xfa552030UL,
|
||||
0xb701ec9aUL, 0xba0ae293UL, 0xad17f088UL, 0xa01cfe81UL, 0x832dd4beUL, 0x8e26dab7UL, 0x993bc8acUL, 0x9430c6a5UL,
|
||||
0xdf599cd2UL, 0xd25292dbUL, 0xc54f80c0UL, 0xc8448ec9UL, 0xeb75a4f6UL, 0xe67eaaffUL, 0xf163b8e4UL, 0xfc68b6edUL,
|
||||
0x67b10c0aUL, 0x6aba0203UL, 0x7da71018UL, 0x70ac1e11UL, 0x539d342eUL, 0x5e963a27UL, 0x498b283cUL, 0x44802635UL,
|
||||
0x0fe97c42UL, 0x02e2724bUL, 0x15ff6050UL, 0x18f46e59UL, 0x3bc54466UL, 0x36ce4a6fUL, 0x21d35874UL, 0x2cd8567dUL,
|
||||
0x0c7a37a1UL, 0x017139a8UL, 0x166c2bb3UL, 0x1b6725baUL, 0x38560f85UL, 0x355d018cUL, 0x22401397UL, 0x2f4b1d9eUL,
|
||||
0x642247e9UL, 0x692949e0UL, 0x7e345bfbUL, 0x733f55f2UL, 0x500e7fcdUL, 0x5d0571c4UL, 0x4a1863dfUL, 0x47136dd6UL,
|
||||
0xdccad731UL, 0xd1c1d938UL, 0xc6dccb23UL, 0xcbd7c52aUL, 0xe8e6ef15UL, 0xe5ede11cUL, 0xf2f0f307UL, 0xfffbfd0eUL,
|
||||
0xb492a779UL, 0xb999a970UL, 0xae84bb6bUL, 0xa38fb562UL, 0x80be9f5dUL, 0x8db59154UL, 0x9aa8834fUL, 0x97a38d46UL
|
||||
};
|
||||
|
||||
static const ulong32 Tks3[] = {
|
||||
0x00000000UL, 0x090d0b0eUL, 0x121a161cUL, 0x1b171d12UL, 0x24342c38UL, 0x2d392736UL, 0x362e3a24UL, 0x3f23312aUL,
|
||||
0x48685870UL, 0x4165537eUL, 0x5a724e6cUL, 0x537f4562UL, 0x6c5c7448UL, 0x65517f46UL, 0x7e466254UL, 0x774b695aUL,
|
||||
0x90d0b0e0UL, 0x99ddbbeeUL, 0x82caa6fcUL, 0x8bc7adf2UL, 0xb4e49cd8UL, 0xbde997d6UL, 0xa6fe8ac4UL, 0xaff381caUL,
|
||||
0xd8b8e890UL, 0xd1b5e39eUL, 0xcaa2fe8cUL, 0xc3aff582UL, 0xfc8cc4a8UL, 0xf581cfa6UL, 0xee96d2b4UL, 0xe79bd9baUL,
|
||||
0x3bbb7bdbUL, 0x32b670d5UL, 0x29a16dc7UL, 0x20ac66c9UL, 0x1f8f57e3UL, 0x16825cedUL, 0x0d9541ffUL, 0x04984af1UL,
|
||||
0x73d323abUL, 0x7ade28a5UL, 0x61c935b7UL, 0x68c43eb9UL, 0x57e70f93UL, 0x5eea049dUL, 0x45fd198fUL, 0x4cf01281UL,
|
||||
0xab6bcb3bUL, 0xa266c035UL, 0xb971dd27UL, 0xb07cd629UL, 0x8f5fe703UL, 0x8652ec0dUL, 0x9d45f11fUL, 0x9448fa11UL,
|
||||
0xe303934bUL, 0xea0e9845UL, 0xf1198557UL, 0xf8148e59UL, 0xc737bf73UL, 0xce3ab47dUL, 0xd52da96fUL, 0xdc20a261UL,
|
||||
0x766df6adUL, 0x7f60fda3UL, 0x6477e0b1UL, 0x6d7aebbfUL, 0x5259da95UL, 0x5b54d19bUL, 0x4043cc89UL, 0x494ec787UL,
|
||||
0x3e05aeddUL, 0x3708a5d3UL, 0x2c1fb8c1UL, 0x2512b3cfUL, 0x1a3182e5UL, 0x133c89ebUL, 0x082b94f9UL, 0x01269ff7UL,
|
||||
0xe6bd464dUL, 0xefb04d43UL, 0xf4a75051UL, 0xfdaa5b5fUL, 0xc2896a75UL, 0xcb84617bUL, 0xd0937c69UL, 0xd99e7767UL,
|
||||
0xaed51e3dUL, 0xa7d81533UL, 0xbccf0821UL, 0xb5c2032fUL, 0x8ae13205UL, 0x83ec390bUL, 0x98fb2419UL, 0x91f62f17UL,
|
||||
0x4dd68d76UL, 0x44db8678UL, 0x5fcc9b6aUL, 0x56c19064UL, 0x69e2a14eUL, 0x60efaa40UL, 0x7bf8b752UL, 0x72f5bc5cUL,
|
||||
0x05bed506UL, 0x0cb3de08UL, 0x17a4c31aUL, 0x1ea9c814UL, 0x218af93eUL, 0x2887f230UL, 0x3390ef22UL, 0x3a9de42cUL,
|
||||
0xdd063d96UL, 0xd40b3698UL, 0xcf1c2b8aUL, 0xc6112084UL, 0xf93211aeUL, 0xf03f1aa0UL, 0xeb2807b2UL, 0xe2250cbcUL,
|
||||
0x956e65e6UL, 0x9c636ee8UL, 0x877473faUL, 0x8e7978f4UL, 0xb15a49deUL, 0xb85742d0UL, 0xa3405fc2UL, 0xaa4d54ccUL,
|
||||
0xecdaf741UL, 0xe5d7fc4fUL, 0xfec0e15dUL, 0xf7cdea53UL, 0xc8eedb79UL, 0xc1e3d077UL, 0xdaf4cd65UL, 0xd3f9c66bUL,
|
||||
0xa4b2af31UL, 0xadbfa43fUL, 0xb6a8b92dUL, 0xbfa5b223UL, 0x80868309UL, 0x898b8807UL, 0x929c9515UL, 0x9b919e1bUL,
|
||||
0x7c0a47a1UL, 0x75074cafUL, 0x6e1051bdUL, 0x671d5ab3UL, 0x583e6b99UL, 0x51336097UL, 0x4a247d85UL, 0x4329768bUL,
|
||||
0x34621fd1UL, 0x3d6f14dfUL, 0x267809cdUL, 0x2f7502c3UL, 0x105633e9UL, 0x195b38e7UL, 0x024c25f5UL, 0x0b412efbUL,
|
||||
0xd7618c9aUL, 0xde6c8794UL, 0xc57b9a86UL, 0xcc769188UL, 0xf355a0a2UL, 0xfa58abacUL, 0xe14fb6beUL, 0xe842bdb0UL,
|
||||
0x9f09d4eaUL, 0x9604dfe4UL, 0x8d13c2f6UL, 0x841ec9f8UL, 0xbb3df8d2UL, 0xb230f3dcUL, 0xa927eeceUL, 0xa02ae5c0UL,
|
||||
0x47b13c7aUL, 0x4ebc3774UL, 0x55ab2a66UL, 0x5ca62168UL, 0x63851042UL, 0x6a881b4cUL, 0x719f065eUL, 0x78920d50UL,
|
||||
0x0fd9640aUL, 0x06d46f04UL, 0x1dc37216UL, 0x14ce7918UL, 0x2bed4832UL, 0x22e0433cUL, 0x39f75e2eUL, 0x30fa5520UL,
|
||||
0x9ab701ecUL, 0x93ba0ae2UL, 0x88ad17f0UL, 0x81a01cfeUL, 0xbe832dd4UL, 0xb78e26daUL, 0xac993bc8UL, 0xa59430c6UL,
|
||||
0xd2df599cUL, 0xdbd25292UL, 0xc0c54f80UL, 0xc9c8448eUL, 0xf6eb75a4UL, 0xffe67eaaUL, 0xe4f163b8UL, 0xedfc68b6UL,
|
||||
0x0a67b10cUL, 0x036aba02UL, 0x187da710UL, 0x1170ac1eUL, 0x2e539d34UL, 0x275e963aUL, 0x3c498b28UL, 0x35448026UL,
|
||||
0x420fe97cUL, 0x4b02e272UL, 0x5015ff60UL, 0x5918f46eUL, 0x663bc544UL, 0x6f36ce4aUL, 0x7421d358UL, 0x7d2cd856UL,
|
||||
0xa10c7a37UL, 0xa8017139UL, 0xb3166c2bUL, 0xba1b6725UL, 0x8538560fUL, 0x8c355d01UL, 0x97224013UL, 0x9e2f4b1dUL,
|
||||
0xe9642247UL, 0xe0692949UL, 0xfb7e345bUL, 0xf2733f55UL, 0xcd500e7fUL, 0xc45d0571UL, 0xdf4a1863UL, 0xd647136dUL,
|
||||
0x31dccad7UL, 0x38d1c1d9UL, 0x23c6dccbUL, 0x2acbd7c5UL, 0x15e8e6efUL, 0x1ce5ede1UL, 0x07f2f0f3UL, 0x0efffbfdUL,
|
||||
0x00000000UL, 0x090d0b0eUL, 0x121a161cUL, 0x1b171d12UL, 0x24342c38UL, 0x2d392736UL, 0x362e3a24UL, 0x3f23312aUL,
|
||||
0x48685870UL, 0x4165537eUL, 0x5a724e6cUL, 0x537f4562UL, 0x6c5c7448UL, 0x65517f46UL, 0x7e466254UL, 0x774b695aUL,
|
||||
0x90d0b0e0UL, 0x99ddbbeeUL, 0x82caa6fcUL, 0x8bc7adf2UL, 0xb4e49cd8UL, 0xbde997d6UL, 0xa6fe8ac4UL, 0xaff381caUL,
|
||||
0xd8b8e890UL, 0xd1b5e39eUL, 0xcaa2fe8cUL, 0xc3aff582UL, 0xfc8cc4a8UL, 0xf581cfa6UL, 0xee96d2b4UL, 0xe79bd9baUL,
|
||||
0x3bbb7bdbUL, 0x32b670d5UL, 0x29a16dc7UL, 0x20ac66c9UL, 0x1f8f57e3UL, 0x16825cedUL, 0x0d9541ffUL, 0x04984af1UL,
|
||||
0x73d323abUL, 0x7ade28a5UL, 0x61c935b7UL, 0x68c43eb9UL, 0x57e70f93UL, 0x5eea049dUL, 0x45fd198fUL, 0x4cf01281UL,
|
||||
0xab6bcb3bUL, 0xa266c035UL, 0xb971dd27UL, 0xb07cd629UL, 0x8f5fe703UL, 0x8652ec0dUL, 0x9d45f11fUL, 0x9448fa11UL,
|
||||
0xe303934bUL, 0xea0e9845UL, 0xf1198557UL, 0xf8148e59UL, 0xc737bf73UL, 0xce3ab47dUL, 0xd52da96fUL, 0xdc20a261UL,
|
||||
0x766df6adUL, 0x7f60fda3UL, 0x6477e0b1UL, 0x6d7aebbfUL, 0x5259da95UL, 0x5b54d19bUL, 0x4043cc89UL, 0x494ec787UL,
|
||||
0x3e05aeddUL, 0x3708a5d3UL, 0x2c1fb8c1UL, 0x2512b3cfUL, 0x1a3182e5UL, 0x133c89ebUL, 0x082b94f9UL, 0x01269ff7UL,
|
||||
0xe6bd464dUL, 0xefb04d43UL, 0xf4a75051UL, 0xfdaa5b5fUL, 0xc2896a75UL, 0xcb84617bUL, 0xd0937c69UL, 0xd99e7767UL,
|
||||
0xaed51e3dUL, 0xa7d81533UL, 0xbccf0821UL, 0xb5c2032fUL, 0x8ae13205UL, 0x83ec390bUL, 0x98fb2419UL, 0x91f62f17UL,
|
||||
0x4dd68d76UL, 0x44db8678UL, 0x5fcc9b6aUL, 0x56c19064UL, 0x69e2a14eUL, 0x60efaa40UL, 0x7bf8b752UL, 0x72f5bc5cUL,
|
||||
0x05bed506UL, 0x0cb3de08UL, 0x17a4c31aUL, 0x1ea9c814UL, 0x218af93eUL, 0x2887f230UL, 0x3390ef22UL, 0x3a9de42cUL,
|
||||
0xdd063d96UL, 0xd40b3698UL, 0xcf1c2b8aUL, 0xc6112084UL, 0xf93211aeUL, 0xf03f1aa0UL, 0xeb2807b2UL, 0xe2250cbcUL,
|
||||
0x956e65e6UL, 0x9c636ee8UL, 0x877473faUL, 0x8e7978f4UL, 0xb15a49deUL, 0xb85742d0UL, 0xa3405fc2UL, 0xaa4d54ccUL,
|
||||
0xecdaf741UL, 0xe5d7fc4fUL, 0xfec0e15dUL, 0xf7cdea53UL, 0xc8eedb79UL, 0xc1e3d077UL, 0xdaf4cd65UL, 0xd3f9c66bUL,
|
||||
0xa4b2af31UL, 0xadbfa43fUL, 0xb6a8b92dUL, 0xbfa5b223UL, 0x80868309UL, 0x898b8807UL, 0x929c9515UL, 0x9b919e1bUL,
|
||||
0x7c0a47a1UL, 0x75074cafUL, 0x6e1051bdUL, 0x671d5ab3UL, 0x583e6b99UL, 0x51336097UL, 0x4a247d85UL, 0x4329768bUL,
|
||||
0x34621fd1UL, 0x3d6f14dfUL, 0x267809cdUL, 0x2f7502c3UL, 0x105633e9UL, 0x195b38e7UL, 0x024c25f5UL, 0x0b412efbUL,
|
||||
0xd7618c9aUL, 0xde6c8794UL, 0xc57b9a86UL, 0xcc769188UL, 0xf355a0a2UL, 0xfa58abacUL, 0xe14fb6beUL, 0xe842bdb0UL,
|
||||
0x9f09d4eaUL, 0x9604dfe4UL, 0x8d13c2f6UL, 0x841ec9f8UL, 0xbb3df8d2UL, 0xb230f3dcUL, 0xa927eeceUL, 0xa02ae5c0UL,
|
||||
0x47b13c7aUL, 0x4ebc3774UL, 0x55ab2a66UL, 0x5ca62168UL, 0x63851042UL, 0x6a881b4cUL, 0x719f065eUL, 0x78920d50UL,
|
||||
0x0fd9640aUL, 0x06d46f04UL, 0x1dc37216UL, 0x14ce7918UL, 0x2bed4832UL, 0x22e0433cUL, 0x39f75e2eUL, 0x30fa5520UL,
|
||||
0x9ab701ecUL, 0x93ba0ae2UL, 0x88ad17f0UL, 0x81a01cfeUL, 0xbe832dd4UL, 0xb78e26daUL, 0xac993bc8UL, 0xa59430c6UL,
|
||||
0xd2df599cUL, 0xdbd25292UL, 0xc0c54f80UL, 0xc9c8448eUL, 0xf6eb75a4UL, 0xffe67eaaUL, 0xe4f163b8UL, 0xedfc68b6UL,
|
||||
0x0a67b10cUL, 0x036aba02UL, 0x187da710UL, 0x1170ac1eUL, 0x2e539d34UL, 0x275e963aUL, 0x3c498b28UL, 0x35448026UL,
|
||||
0x420fe97cUL, 0x4b02e272UL, 0x5015ff60UL, 0x5918f46eUL, 0x663bc544UL, 0x6f36ce4aUL, 0x7421d358UL, 0x7d2cd856UL,
|
||||
0xa10c7a37UL, 0xa8017139UL, 0xb3166c2bUL, 0xba1b6725UL, 0x8538560fUL, 0x8c355d01UL, 0x97224013UL, 0x9e2f4b1dUL,
|
||||
0xe9642247UL, 0xe0692949UL, 0xfb7e345bUL, 0xf2733f55UL, 0xcd500e7fUL, 0xc45d0571UL, 0xdf4a1863UL, 0xd647136dUL,
|
||||
0x31dccad7UL, 0x38d1c1d9UL, 0x23c6dccbUL, 0x2acbd7c5UL, 0x15e8e6efUL, 0x1ce5ede1UL, 0x07f2f0f3UL, 0x0efffbfdUL,
|
||||
0x79b492a7UL, 0x70b999a9UL, 0x6bae84bbUL, 0x62a38fb5UL, 0x5d80be9fUL, 0x548db591UL, 0x4f9aa883UL, 0x4697a38dUL
|
||||
};
|
||||
|
||||
|
|
@ -1011,12 +1009,8 @@ static const ulong32 Tks3[] = {
|
|||
|
||||
#endif /* SMALL CODE */
|
||||
|
||||
#ifndef PELI_TAB
|
||||
static const ulong32 rcon[] = {
|
||||
0x01000000UL, 0x02000000UL, 0x04000000UL, 0x08000000UL,
|
||||
0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL,
|
||||
0x1B000000UL, 0x36000000UL, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* LTC_AES_TAB_C */
|
||||
56
appveyor.yml
56
appveyor.yml
|
|
@ -1,56 +0,0 @@
|
|||
version: 1.18.2-develop+{build}
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /^release/
|
||||
- /^appveyor/
|
||||
- /^build-ci/
|
||||
image:
|
||||
- Visual Studio 2022
|
||||
- Visual Studio 2019
|
||||
- Visual Studio 2017
|
||||
- Visual Studio 2015
|
||||
environment:
|
||||
matrix:
|
||||
- LTC_CC: cl
|
||||
- LTC_CC: clang-cl
|
||||
matrix:
|
||||
exclude:
|
||||
- image: Visual Studio 2019
|
||||
LTC_CC: clang-cl
|
||||
- image: Visual Studio 2017
|
||||
LTC_CC: clang-cl
|
||||
- image: Visual Studio 2015
|
||||
LTC_CC: clang-cl
|
||||
build_script:
|
||||
- cmd: >-
|
||||
if "Visual Studio 2022"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if "Visual Studio 2019"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
|
||||
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
|
||||
if "clang-cl"=="%LTC_CC%" set "PATH=C:\Program Files\LLVM\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin;%PATH%"
|
||||
if "clang-cl"=="%LTC_CC%" clang-cl --version
|
||||
cd..
|
||||
git clone https://github.com/libtom/libtommath.git --branch=master
|
||||
cp libtomcrypt\.ci\cmake.bat libtommath\cmake.bat
|
||||
cd libtommath
|
||||
cmake.bat
|
||||
nmake -f makefile.msvc
|
||||
cd..
|
||||
cd libtomcrypt
|
||||
.ci\cmake.bat
|
||||
nmake -f makefile.msvc all CC=%LTC_CC%
|
||||
cp test.exe test-stock.exe
|
||||
cp timing.exe timing-stock.exe
|
||||
nmake -f makefile.msvc clean
|
||||
nmake -f makefile.msvc all CC=%LTC_CC% CFLAGS="/Ox /DUSE_LTM /DLTM_DESC /DLTC_NO_ACCEL /I../libtommath"
|
||||
test_script:
|
||||
- cmd: >-
|
||||
test-stock.exe
|
||||
test.exe
|
||||
timing-stock.exe cipher_ecb aes
|
||||
timing.exe cipher_ecb aes
|
||||
timing-stock.exe hash sha
|
||||
timing.exe hash sha
|
||||
55
authors
Normal file
55
authors
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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.
|
||||
76
base64_decode.c
Normal file
76
base64_decode.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
|
||||
/* compliant base64 code donated by Wayne Scott (wscott@bitmover.com) */
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef BASE64
|
||||
|
||||
static const unsigned char map[256] = {
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
|
||||
255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
|
||||
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
|
||||
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255 };
|
||||
|
||||
int base64_decode(const unsigned char *in, unsigned long len,
|
||||
unsigned char *out, unsigned long *outlen)
|
||||
{
|
||||
unsigned long t, x, y, z;
|
||||
unsigned char c;
|
||||
int g;
|
||||
|
||||
_ARGCHK(in != NULL);
|
||||
_ARGCHK(out != NULL);
|
||||
_ARGCHK(outlen != NULL);
|
||||
|
||||
g = 3;
|
||||
for (x = y = z = t = 0; x < len; x++) {
|
||||
c = map[in[x]&0xFF];
|
||||
if (c == 255) continue;
|
||||
if (c == 254) { c = 0; g--; }
|
||||
t = (t<<6)|c;
|
||||
if (++y == 4) {
|
||||
if (z + g > *outlen) {
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
out[z++] = (unsigned char)((t>>16)&255);
|
||||
if (g > 1) out[z++] = (unsigned char)((t>>8)&255);
|
||||
if (g > 2) out[z++] = (unsigned char)(t&255);
|
||||
y = t = 0;
|
||||
}
|
||||
}
|
||||
if (y != 0) {
|
||||
return CRYPT_INVALID_PACKET;
|
||||
}
|
||||
*outlen = z;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
63
base64_encode.c
Normal file
63
base64_encode.c
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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
|
||||
|
||||
19
bin.in
19
bin.in
|
|
@ -1,19 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Shell wrapper script for the executables when built with the shared
|
||||
# libtomcrypt library.
|
||||
|
||||
set -euf
|
||||
|
||||
rootdir="$(cd -- "${0%/*}/" && pwd -P)"
|
||||
binpath="$rootdir/.bin/${0##*/}"
|
||||
|
||||
[ -z "${LD_LIBRARY_PATH:=$rootdir}" ] ||
|
||||
LD_LIBRARY_PATH="$rootdir:$LD_LIBRARY_PATH"
|
||||
|
||||
export LD_LIBRARY_PATH
|
||||
|
||||
if [ -n "${1+x}" ]; then
|
||||
exec "$binpath" "${@:-}"
|
||||
else
|
||||
exec "$binpath"
|
||||
fi
|
||||
|
|
@ -1,25 +1,27 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
/**
|
||||
@file blowfish.c
|
||||
Implementation of the Blowfish block cipher, Tom St Denis
|
||||
*/
|
||||
#include "tomcrypt_private.h"
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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 LTC_BLOWFISH
|
||||
#ifdef BLOWFISH
|
||||
|
||||
const struct ltc_cipher_descriptor blowfish_desc =
|
||||
const struct _cipher_descriptor blowfish_desc =
|
||||
{
|
||||
"blowfish",
|
||||
0,
|
||||
8, 72, 8, 16,
|
||||
8, 56, 8, 16,
|
||||
&blowfish_setup,
|
||||
&blowfish_ecb_encrypt,
|
||||
&blowfish_ecb_decrypt,
|
||||
&blowfish_test,
|
||||
&blowfish_done,
|
||||
&blowfish_keysize,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
&blowfish_keysize
|
||||
};
|
||||
|
||||
static const ulong32 ORIG_P[16 + 2] = {
|
||||
|
|
@ -289,250 +291,154 @@ static const ulong32 ORIG_S[4][256] = {
|
|||
0xB74E6132UL, 0xCE77E25BUL, 0x578FDFE3UL, 0x3AC372E6UL }
|
||||
};
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define F(x) ((S1[LTC_BYTE(x,3)] + S2[LTC_BYTE(x,2)]) ^ S3[LTC_BYTE(x,1)]) + S4[LTC_BYTE(x,0)]
|
||||
#else
|
||||
#define F(x) ((skey->blowfish.S[0][LTC_BYTE(x,3)] + skey->blowfish.S[1][LTC_BYTE(x,2)]) ^ skey->blowfish.S[2][LTC_BYTE(x,1)]) + skey->blowfish.S[3][LTC_BYTE(x,0)]
|
||||
#endif
|
||||
|
||||
static void s_blowfish_encipher(ulong32 *L, ulong32 *R, const symmetric_key *skey)
|
||||
int blowfish_setup(const unsigned char *key, int keylen, int num_rounds,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
int rounds;
|
||||
ulong32 x, y, z, A;
|
||||
unsigned char B[8];
|
||||
|
||||
ulong32 l, r;
|
||||
#ifndef __GNUC__
|
||||
const ulong32 *S1, *S2, *S3, *S4;
|
||||
_ARGCHK(key != NULL);
|
||||
_ARGCHK(skey != NULL);
|
||||
|
||||
S1 = skey->blowfish.S[0];
|
||||
S2 = skey->blowfish.S[1];
|
||||
S3 = skey->blowfish.S[2];
|
||||
S4 = skey->blowfish.S[3];
|
||||
#endif
|
||||
|
||||
l = *L;
|
||||
r = *R;
|
||||
|
||||
/* do 16 rounds */
|
||||
for (rounds = 0; rounds < 16; ) {
|
||||
l ^= skey->blowfish.K[rounds++]; r ^= F(l);
|
||||
r ^= skey->blowfish.K[rounds++]; l ^= F(r);
|
||||
l ^= skey->blowfish.K[rounds++]; r ^= F(l);
|
||||
r ^= skey->blowfish.K[rounds++]; l ^= F(r);
|
||||
/* check key length */
|
||||
if (keylen < 8 || keylen > 56) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
|
||||
/* last keying */
|
||||
l ^= skey->blowfish.K[16];
|
||||
r ^= skey->blowfish.K[17];
|
||||
/* check rounds */
|
||||
if (num_rounds != 0 && num_rounds != 16) {
|
||||
return CRYPT_INVALID_ROUNDS;
|
||||
}
|
||||
|
||||
*L = r;
|
||||
*R = l;
|
||||
}
|
||||
|
||||
void blowfish_enc(ulong32 *data, unsigned long blocks, const symmetric_key *skey)
|
||||
{
|
||||
unsigned long i;
|
||||
ulong32 *d = data;
|
||||
|
||||
for (i = 0; i < blocks; ++i) {
|
||||
s_blowfish_encipher(d, d + 1, skey);
|
||||
d += 2;
|
||||
/* load in key bytes (Supplied by David Hopwood) */
|
||||
for (x = y = 0; x < 18; x++) {
|
||||
A = 0;
|
||||
for (z = 0; z < 4; z++) {
|
||||
A = (A << 8) | ((ulong32)key[y++] & 255);
|
||||
if (y == (ulong32)keylen) {
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
skey->blowfish.K[x] = ORIG_P[x] ^ A;
|
||||
}
|
||||
}
|
||||
|
||||
static ulong32 s_blowfish_stream2word(const unsigned char *d, int dlen, int *cur)
|
||||
{
|
||||
unsigned int z;
|
||||
int y = *cur;
|
||||
ulong32 ret = 0;
|
||||
|
||||
for (z = 0; z < 4; z++) {
|
||||
ret = (ret << 8) | ((ulong32)d[y++] & 255);
|
||||
if (y == dlen) {
|
||||
y = 0;
|
||||
/* copy sboxes */
|
||||
for (x = 0; x < 4; x++) {
|
||||
for (y = 0; y < 256; y++) {
|
||||
skey->blowfish.S[x][y] = ORIG_S[x][y];
|
||||
}
|
||||
}
|
||||
|
||||
*cur = y;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
Expand the Blowfish internal state
|
||||
@param key The symmetric key you wish to pass
|
||||
@param keylen The key length in bytes
|
||||
@param data The additional data you wish to pass (can be NULL)
|
||||
@param datalen The additional data 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_expand(const unsigned char *key, int keylen,
|
||||
const unsigned char *data, int datalen,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
ulong32 x, y, A, B[2];
|
||||
int i;
|
||||
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
|
||||
/* load in key bytes (Supplied by David Hopwood) */
|
||||
i = 0;
|
||||
for (x = 0; x < 18; x++) {
|
||||
A = s_blowfish_stream2word(key, keylen, &i);
|
||||
skey->blowfish.K[x] ^= A;
|
||||
/* encrypt K array */
|
||||
for (x = 0; x < 8; x++) {
|
||||
B[x] = 0;
|
||||
}
|
||||
|
||||
|
||||
i = 0;
|
||||
B[0] = 0;
|
||||
B[1] = 0;
|
||||
|
||||
for (x = 0; x < 18; x += 2) {
|
||||
if (data != NULL) {
|
||||
B[0] ^= s_blowfish_stream2word(data, datalen, &i);
|
||||
B[1] ^= s_blowfish_stream2word(data, datalen, &i);
|
||||
}
|
||||
/* encrypt it */
|
||||
s_blowfish_encipher(&B[0], &B[1], skey);
|
||||
/* copy it */
|
||||
skey->blowfish.K[x] = B[0];
|
||||
skey->blowfish.K[x+1] = B[1];
|
||||
/* encrypt it */
|
||||
blowfish_ecb_encrypt(B, B, skey);
|
||||
/* copy it */
|
||||
LOAD32H(skey->blowfish.K[x], &B[0]);
|
||||
LOAD32H(skey->blowfish.K[x+1], &B[4]);
|
||||
}
|
||||
|
||||
/* encrypt S array */
|
||||
for (x = 0; x < 4; x++) {
|
||||
for (y = 0; y < 256; y += 2) {
|
||||
if (data != NULL) {
|
||||
B[0] ^= s_blowfish_stream2word(data, datalen, &i);
|
||||
B[1] ^= s_blowfish_stream2word(data, datalen, &i);
|
||||
}
|
||||
/* encrypt it */
|
||||
s_blowfish_encipher(&B[0], &B[1], skey);
|
||||
blowfish_ecb_encrypt(B, B, skey);
|
||||
/* copy it */
|
||||
skey->blowfish.S[x][y] = B[0];
|
||||
skey->blowfish.S[x][y+1] = B[1];
|
||||
LOAD32H(skey->blowfish.S[x][y], &B[0]);
|
||||
LOAD32H(skey->blowfish.S[x][y+1], &B[4]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
#ifdef CLEAN_STACK
|
||||
zeromem(B, sizeof(B));
|
||||
#endif
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
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)
|
||||
{
|
||||
/* check key length */
|
||||
if (keylen < 8 || keylen > 72) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
/* check rounds */
|
||||
if (num_rounds != 0 && num_rounds != 16) {
|
||||
return CRYPT_INVALID_ROUNDS;
|
||||
}
|
||||
|
||||
return blowfish_setup_with_data(key, keylen, NULL, 0, skey);
|
||||
}
|
||||
|
||||
/**
|
||||
Alternative initialize of the Blowfish block cipher
|
||||
@param key The symmetric key you wish to pass
|
||||
@param keylen The key length in bytes
|
||||
@param data The additional data you wish to pass (can be NULL)
|
||||
@param datalen The additional data 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_with_data(const unsigned char *key, int keylen,
|
||||
const unsigned char *data, int datalen,
|
||||
symmetric_key *skey)
|
||||
{
|
||||
XMEMCPY(skey->blowfish.K, ORIG_P, sizeof(ORIG_P));
|
||||
XMEMCPY(skey->blowfish.S, ORIG_S, sizeof(ORIG_S));
|
||||
return blowfish_expand(key, keylen, data, datalen, skey);
|
||||
}
|
||||
|
||||
/**
|
||||
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
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static int s_blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
|
||||
#ifndef __GNUC__
|
||||
#define F(x) ((S1[byte(x,3)] + S2[byte(x,2)]) ^ S3[byte(x,1)]) + S4[byte(x,0)]
|
||||
#else
|
||||
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
|
||||
#endif
|
||||
{
|
||||
ulong32 L, R;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
|
||||
/* load it */
|
||||
LOAD32H(L, &pt[0]);
|
||||
LOAD32H(R, &pt[4]);
|
||||
|
||||
s_blowfish_encipher(&L, &R, skey);
|
||||
|
||||
/* store */
|
||||
STORE32H(L, &ct[0]);
|
||||
STORE32H(R, &ct[4]);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey)
|
||||
{
|
||||
int err = s_blowfish_ecb_encrypt(pt, ct, skey);
|
||||
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#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)]
|
||||
#endif
|
||||
|
||||
/**
|
||||
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
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
static int s_blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
|
||||
#ifdef CLEAN_STACK
|
||||
static void _blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
|
||||
#else
|
||||
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
|
||||
void blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key)
|
||||
#endif
|
||||
{
|
||||
ulong32 L, R;
|
||||
int r;
|
||||
#ifndef __GNUC__
|
||||
const ulong32 *S1, *S2, *S3, *S4;
|
||||
ulong32 *S1, *S2, *S3, *S4;
|
||||
#endif
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(skey != NULL);
|
||||
_ARGCHK(pt != NULL);
|
||||
_ARGCHK(ct != NULL);
|
||||
_ARGCHK(key != NULL);
|
||||
|
||||
#ifndef __GNUC__
|
||||
S1 = skey->blowfish.S[0];
|
||||
S2 = skey->blowfish.S[1];
|
||||
S3 = skey->blowfish.S[2];
|
||||
S4 = skey->blowfish.S[3];
|
||||
S1 = key->blowfish.S[0];
|
||||
S2 = key->blowfish.S[1];
|
||||
S3 = key->blowfish.S[2];
|
||||
S4 = key->blowfish.S[3];
|
||||
#endif
|
||||
|
||||
/* load it */
|
||||
LOAD32H(L, &pt[0]);
|
||||
LOAD32H(R, &pt[4]);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* last keying */
|
||||
R ^= key->blowfish.K[17];
|
||||
L ^= key->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)
|
||||
{
|
||||
_blowfish_ecb_encrypt(pt, ct, key);
|
||||
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)
|
||||
#else
|
||||
void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
|
||||
#endif
|
||||
{
|
||||
ulong32 L, R;
|
||||
int r;
|
||||
#ifndef __GNUC__
|
||||
ulong32 *S1, *S2, *S3, *S4;
|
||||
#endif
|
||||
|
||||
_ARGCHK(pt != NULL);
|
||||
_ARGCHK(ct != NULL);
|
||||
_ARGCHK(key != NULL);
|
||||
|
||||
#ifndef __GNUC__
|
||||
S1 = key->blowfish.S[0];
|
||||
S2 = key->blowfish.S[1];
|
||||
S3 = key->blowfish.S[2];
|
||||
S4 = key->blowfish.S[3];
|
||||
#endif
|
||||
|
||||
/* load it */
|
||||
|
|
@ -540,42 +446,36 @@ int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symme
|
|||
LOAD32H(L, &ct[4]);
|
||||
|
||||
/* undo last keying */
|
||||
R ^= skey->blowfish.K[17];
|
||||
L ^= skey->blowfish.K[16];
|
||||
R ^= key->blowfish.K[17];
|
||||
L ^= key->blowfish.K[16];
|
||||
|
||||
/* do 16 rounds */
|
||||
for (r = 15; r > 0; ) {
|
||||
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--];
|
||||
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--];
|
||||
}
|
||||
|
||||
/* store */
|
||||
STORE32H(L, &pt[0]);
|
||||
STORE32H(R, &pt[4]);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
int blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey)
|
||||
#ifdef CLEAN_STACK
|
||||
void blowfish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key)
|
||||
{
|
||||
int err = s_blowfish_ecb_decrypt(ct, pt, skey);
|
||||
_blowfish_ecb_decrypt(ct, pt, key);
|
||||
burn_stack(sizeof(ulong32) * 2 + sizeof(int));
|
||||
return err;
|
||||
}
|
||||
#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
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
#else
|
||||
int err;
|
||||
symmetric_key key;
|
||||
static const struct {
|
||||
|
|
@ -611,8 +511,7 @@ int blowfish_test(void)
|
|||
blowfish_ecb_decrypt(tmp[0], tmp[1], &key);
|
||||
|
||||
/* compare */
|
||||
if ((ltc_compare_testvector(tmp[0], 8, tests[x].ct, 8, "Blowfish Encrypt", x) != 0) ||
|
||||
(ltc_compare_testvector(tmp[1], 8, tests[x].pt, 8, "Blowfish Decrypt", x) != 0)) {
|
||||
if ((memcmp(tmp[0], tests[x].ct, 8) != 0) || (memcmp(tmp[1], tests[x].pt, 8) != 0)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
|
|
@ -622,39 +521,21 @@ int blowfish_test(void)
|
|||
for (y = 0; y < 1000; y++) blowfish_ecb_decrypt(tmp[0], tmp[0], &key);
|
||||
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 blowfish_done(symmetric_key *skey)
|
||||
int blowfish_keysize(int *desired_keysize)
|
||||
{
|
||||
LTC_UNUSED_PARAM(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 blowfish_keysize(int *keysize)
|
||||
{
|
||||
LTC_ARGCHK(keysize != NULL);
|
||||
|
||||
if (*keysize < 8) {
|
||||
if (*desired_keysize < 8) {
|
||||
return CRYPT_INVALID_KEYSIZE;
|
||||
}
|
||||
if (*keysize > 72) {
|
||||
*keysize = 72;
|
||||
} else if (*desired_keysize > 56) {
|
||||
*desired_keysize = 56;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#endif
|
||||
|
||||
21
burn_stack.c
Normal file
21
burn_stack.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
void burn_stack(unsigned long len)
|
||||
{
|
||||
unsigned char buf[32];
|
||||
zeromem(buf, sizeof(buf));
|
||||
if (len > (unsigned long)sizeof(buf))
|
||||
burn_stack(len - sizeof(buf));
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load diff
57
cbc_decrypt.c
Normal file
57
cbc_decrypt.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@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
|
||||
|
||||
52
cbc_encrypt.c
Normal file
52
cbc_encrypt.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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
|
||||
30
cbc_getiv.c
Normal file
30
cbc_getiv.c
Normal file
|
|
@ -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@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
|
||||
28
cbc_setiv.c
Normal file
28
cbc_setiv.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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
|
||||
|
||||
43
cbc_start.c
Normal file
43
cbc_start.c
Normal file
|
|
@ -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@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
|
||||
48
cfb_decrypt.c
Normal file
48
cfb_decrypt.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef CFB
|
||||
|
||||
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);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
|
||||
cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
while (len-- > 0) {
|
||||
if (cfb->padlen == cfb->blocklen) {
|
||||
cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key);
|
||||
cfb->padlen = 0;
|
||||
}
|
||||
cfb->pad[cfb->padlen] = *ct;
|
||||
*pt = *ct ^ cfb->IV[cfb->padlen];
|
||||
++pt;
|
||||
++ct;
|
||||
++cfb->padlen;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
46
cfb_encrypt.c
Normal file
46
cfb_encrypt.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef CFB
|
||||
|
||||
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);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
|
||||
cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
while (len-- > 0) {
|
||||
if (cfb->padlen == cfb->blocklen) {
|
||||
cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key);
|
||||
cfb->padlen = 0;
|
||||
}
|
||||
cfb->pad[cfb->padlen] = (*ct = *pt ^ cfb->IV[cfb->padlen]);
|
||||
++pt;
|
||||
++ct;
|
||||
++cfb->padlen;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
30
cfb_getiv.c
Normal file
30
cfb_getiv.c
Normal file
|
|
@ -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@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
|
||||
39
cfb_setiv.c
Normal file
39
cfb_setiv.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef CFB
|
||||
|
||||
int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb)
|
||||
{
|
||||
int err;
|
||||
|
||||
_ARGCHK(IV != NULL);
|
||||
_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)cfb->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* force next block */
|
||||
cfb->padlen = 0;
|
||||
cipher_descriptor[cfb->cipher].ecb_encrypt(IV, cfb->IV, &cfb->key);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
47
cfb_start.c
Normal file
47
cfb_start.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef CFB
|
||||
|
||||
int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
int keylen, int num_rounds, symmetric_CFB *cfb)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
_ARGCHK(IV != NULL);
|
||||
_ARGCHK(key != NULL);
|
||||
_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* copy data */
|
||||
cfb->cipher = cipher;
|
||||
cfb->blocklen = cipher_descriptor[cipher].block_length;
|
||||
for (x = 0; x < cfb->blocklen; x++)
|
||||
cfb->IV[x] = IV[x];
|
||||
|
||||
/* init the cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* encrypt the IV */
|
||||
cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);
|
||||
cfb->padlen = 0;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
612
changes
612
changes
|
|
@ -1,606 +1,3 @@
|
|||
July 1st, 2018
|
||||
v1.18.2
|
||||
-- Fix Side Channel Based ECDSA Key Extraction (CVE-2018-12437) (PR #408)
|
||||
-- Fix potential stack overflow when DER flexi-decoding (CVE-2018-0739) (PR #373)
|
||||
-- Fix two-key 3DES (PR #390)
|
||||
-- Fix accelerated CTR mode (PR #359)
|
||||
-- Fix Fortuna PRNG (PR #363)
|
||||
-- Fix compilation on platforms where cc doesn't point to gcc (PR #382)
|
||||
-- Fix using the wrong environment variable LT instead of LIBTOOL (PR #392)
|
||||
-- Fix build on platforms where the compiler provides __WCHAR_MAX__ but wchar.h is not available (PR #390)
|
||||
-- Fix & re-factor crypt_list_all_sizes() and crypt_list_all_constants() (PR #414)
|
||||
-- Minor fixes (PR's #350 #351 #375 #377 #378 #379)
|
||||
|
||||
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
|
||||
v1.17 -- Cryptography Research Inc. contributed another small volley of patches, one to fix __WCHAR_DEFINED__ for BSD platforms,
|
||||
another to silence MSVC warnings.
|
||||
-- Added LTC_XCBC_PURE to XCBC mode which lets you use it in three-key mode.
|
||||
-- [CRI] Added libtomcrypt.dsp for Visual C++ users.
|
||||
-- [CRI] Added more functions for manipulating the ECC fixed point cache (including saving and loading)
|
||||
-- [CRI] Modified ecc_make_key() to always produce keys smaller than base point order, for standards-compliance
|
||||
-- Elliptic Semiconductor contributed XTS chaining mode to the cipher suite (subsequently optimized it)
|
||||
-- Fixed xcbc_init() keylen when using single key mode.
|
||||
-- Bruce Fortune pointed out a typo in the hmac_process() description in the manual. Fixed.
|
||||
-- Added variable width counter support to CTR mode
|
||||
-- Fixed CMAC (aka OMAC) when using 64-bit block ciphers and LTC_FAST ... my bad.
|
||||
-- Fixed bug in ecc_is_valid() that would basically always return true
|
||||
-- renamed a lot of macros to add the LTC_ prefix [e.g. RIJNDAEL => LTC_RIJNDAEL]
|
||||
|
||||
December 16th, 2006
|
||||
v1.16 -- Brian Gladman pointed out that a recent change to GCM broke how the IV was handled. Currently the code complies against his test vectors
|
||||
so the code should be considered frozen now.
|
||||
-- Trevor from Cryptography Research Inc. submitted patches to convert the ECC code to be generic allowing curve parameters to be submitted
|
||||
at runtime.
|
||||
-- Fixed various doxygen comments
|
||||
-- Added UTF8 support to the ASN1 code
|
||||
-- Fixed STOREXXH macros for x86 platforms (Fix found at Elliptic Inc.)
|
||||
-- Added makefile.unix which is BSD compatible, you have to manually tweak it since well I don't use it normally
|
||||
-- removed a few lingering memcpy's
|
||||
-- Fixed memory free errors in ecc_sign_hash() that can arise if the mp_init_multi() fails
|
||||
-- Fixed incorrect return value in pkcs_1_pss_decode() which would correctly set res to 0 (indicating an incorrect signature) but
|
||||
would return CRYPT_OK to the caller
|
||||
-- ltc_ecc_mulmod() could leak memory if mp_init(&mu) failed, fixed. Would you believe that ltc_ecc_mulmod_timing() had the same
|
||||
bug? Also fixed. :-)
|
||||
-- Added Shamir's trick to the ECC side (defined as LTC_ECC_SHAMIR, enabled by default), gets ~1.34x to ~1.40x faster ECC verifications
|
||||
-- Added Brian's vector #46 to the GCM code. It catches the ctr counter error from v1.15. Originally I was going to add all of his vectors,
|
||||
but they're not as easy to parse and I got a lot of other things to do. Regression!
|
||||
-- Various other small fixes to the ECC code to clean up error handling (I think most of that was from the move in 1.06 to the plugins)
|
||||
All of the errors were in cleaning up from heap failures. So they were not likely to be triggered in normal usage
|
||||
Made similar fixes to the RSA and DSA code (my bad)
|
||||
-- Cryptography Research Inc. contributed a bunch of fixes to silence warnings (with MSVC) w.r.t. assigned data to unsigned char types.
|
||||
-- Martin Marko suggested some fixes to make the RNG build with WinCE.
|
||||
-- Updates to the manual for print (some fixes thanks to Martin Marko)
|
||||
|
||||
|
||||
November 17th, 2006
|
||||
v1.15 -- Andreas Lange found that if sha256_init DID fail in fortuna it wouldn't clean up the state correctly. Thanks.
|
||||
Fortunately sha256_init cannot fail (as of v1.14) :-)
|
||||
-- Andreas Lange contributed RMD-256 and RMD-320 code.
|
||||
-- Removed mutex locks from fortuna_import as they create a deadlock and aren't required anyways [Avi Zelmanovich]
|
||||
-- Added LTC_NO_PROTOTYPES to avoid prototyping functions like memset/memcpy. Required for fans of GCC 3.3.x
|
||||
-- David Eder caught a off by one overrun bug in pmac_done() which can be exploited if your output tag buffer is
|
||||
smaller than the block size of the cipher, e.g. if you have a 4-byte buffer and you tell pmac_done that you want
|
||||
a 4-byte TAG it will store 4 bytes but return an outlen of 5.
|
||||
-- Added signatures to the ECC and RSA benchmarks
|
||||
-- Added LTC_PROFILE to run the PK tests only once in the timing demo (so you can capture events properly)
|
||||
-- Andreas contributed PKCS #1 v1.5 code that merged cleanly with the existing PKCS code. w00t.
|
||||
(update: I had to fix it to include the digestInfo and what not. Bad Andreas, bad! hehehe)
|
||||
-- Fixed a signed variable error in gcm_process() (hard to trigger bug fortunately)
|
||||
-- Removed all memcmp/memset/memcpy from the source (replaced with X macros)
|
||||
-- Renamed macros HMAC/OMAC/PMAC to have a LTC_ prefix. If you pass these on the command line please update your makefiles
|
||||
-- Added XCBC-MAC support [RFC 3566]
|
||||
-- fixed LOAD32H and LOAD64H to stop putting out that darn warning :-)
|
||||
-- Added the Korean SEED block cipher [RFC 4269]
|
||||
-- Added LTC_VALGRIND define which makes SOBER-128 and RC4 a pure PRNG (and not a stream cipher). Useful if you use
|
||||
Valgrind to debug your code (reported by Andreas Lange)
|
||||
-- Made SOBER-128 more portable by removing the ASCII key in the test function (my bad, sorry).
|
||||
-- Martin Mocko pointed out that if you have no PRNGs defined the lib won't build. Fixed, also fixed for if you have no
|
||||
hashes defined.
|
||||
-- Sped up F8 mode with LTC_FAST
|
||||
-- Made CTR mode RFC 3686 compliant (increment counter first), to enable, OR the value LTC_CTR_RFC3686 to the "mode"
|
||||
parameter you pass to ctr_start(), otherwise it will be LTC compliant (e.g. encrypt then increment)
|
||||
-- Added ctr_test() to test CTR mode against RFC 3686
|
||||
-- Added crypt_fsa() ... O_o
|
||||
-- Fixed LTC_ECC_TIMING_RESISTANT so it once again builds properly (pt add/dbl are through the plugin now)
|
||||
-- Added ANSI X9.63 (sec 4.3.6) import/export of public keys (cannot export to compressed formats but will import
|
||||
hybrid compressed)
|
||||
-- Added SECP curves for 112, 128, and 160 bits (only the 'r1' curves)
|
||||
-- Added 3GPP-F9 MAC (thanks to Greg Rose for the test vectors)
|
||||
-- Added the KASUMI block cipher
|
||||
-- Added F9/XCBC/OMAC callbacks to the cipher plugin
|
||||
-- Added RSA PKCS #1 v1.5 signature/encrypt tests to rsa_test.c
|
||||
-- Fix to yarrow_test() to not call yarrow_done() which is invalid in that context (thanks Valgrind)
|
||||
-- Christophe Devine pointed out that Anubis would fail on various 64-bit UNIX boxes when "x>>24" was used as an index, we needed
|
||||
to mask it with 0xFF. Thanks. Fixed.
|
||||
|
||||
August 0x1E, 0x07D6
|
||||
v1.14 -- Renamed the chaining mode macros from XXX to LTC_XXX_MODE. Should help avoid polluting the macro name space.
|
||||
-- clean up of SHA-256
|
||||
-- Chris Colman pointed out that der_decode_sequence_* allows LTC_ASN1_SETOF to accept SEQUENCEs and vice versa.
|
||||
Decoder [non-flexi decoder that is] is more strict now and requires a match.
|
||||
-- Steffen Jaeckel pointed out a typo in the user manual (re: rsa_exptmod). Fixed. This disproves the notion that
|
||||
nobody reads it. :-)
|
||||
-- Made GCM a bit more portable w.r.t. handling the CTR IV (e.g. & with 255)
|
||||
-- Add LTC_VERBOSE if you really want to see what test is doing :-)
|
||||
-- Added SSE2 support to GCM [use GCM_TABLES_SSE2 to enable], shaves 2 cycles per byte on Opteron processors
|
||||
Shaved 4 cycles on a Prescott (Intel P4)
|
||||
Requires you align your gcm_state on a 16 byte boundary, see gcm_memory() for more info
|
||||
-- Added missing prototype for f8_test_mode()
|
||||
-- two fixes to CCM for corner cases [L+noncelen > 15] and fixing the CTR pad to encrypt the CBC-MAC tag
|
||||
-- Franz Glasner pointed out the ARGTYPE=4 is not actually valid. Fixed.
|
||||
-- Fixed bug in f8_start() if your key < saltkey unspecified behaviour occurs. :-(
|
||||
-- Documented F8 mode. Yeah, because you read the manual.
|
||||
-- Minor updates to the technotes.
|
||||
|
||||
|
||||
June 17th, 2006
|
||||
v1.13 -- Fixed to fortuna_start() to clean up state if an error occurs. Not really useful at this stage (sha256 can't fail) but useful
|
||||
if I ever make fortuna pluggable
|
||||
-- Mike Marin submitted a whole bunch of patches for fixing up the libs on traditional UNIX platforms. Go AIX! Thanks!
|
||||
-- One of bugs found in the multi demo highlights that at least with gcc you need to pass integers with a UL prefix to ensure
|
||||
they're unsigned long
|
||||
-- Updated the FP ECC code to use affine points. It's teh fast.
|
||||
-- Made it so many functions which return CRYPT_BUFFER_OVERFLOW now also indicate the required buffer size, note that not all functions
|
||||
do this (most do though).
|
||||
-- Added F8 chaining mode. It's super neato.
|
||||
|
||||
May 29th, 2006
|
||||
v1.12 -- Fixed OID encoder/decoder/length to properly handle the first two parts of an OID, matches 2002 X.690 now.
|
||||
-- [Wesley Shields] Allows both GMP/LTM and TFM to be defined now.
|
||||
-- [Wesley Shields] GMP pluggin is cleaner now and doesn't use deprecated symbols. Yipee
|
||||
-- Added count_lsb_bits to get the number of leading LSB zero bits there are.
|
||||
-- Fixed a bug in the INTEGER encoders for values of -(256**k)/2
|
||||
-- Added BOOLEAN type to ASN.1 thingy-ma-do-hicky
|
||||
-- Testprof doesn't strictly require GMP ... oops [Nils Durner]
|
||||
-- Added LTC_CALL and LTC_EXPORT macros in tomcrypt_cfg.h to support various calling and linker conventions
|
||||
(Thanks to John Kirk from Demonware)
|
||||
-- In what has to be the best thing since sliced bread I bring you MECC_FP which is the fixed point
|
||||
ECC point multiplier. It's fast, it's sexy and what's more it's hella fast [did I mention it's fast?]
|
||||
You can tune it somewhat with FP_LUT (default to 8) for look-up width.
|
||||
Read section 8.2 of the manual for more info.
|
||||
It is disabled by default, you'll have to build LTC with it defined to get it.
|
||||
-- Fixed bug in ecc_test.c (from testprof) to include the 521 [not 512] bit curve. :-)
|
||||
|
||||
April 4th, 2006
|
||||
v1.11 -- Removed printf's from lrw_test ... whoops
|
||||
-- lrw_process now checks the return of the cipher ecb encrypt/decrypt calls
|
||||
-- lrw_start was not using num_rounds ...
|
||||
-- Adam Miller reported a bug in the flexi decoder with elements past the end of a sequence. Fixed.
|
||||
-- Bruce Guenter suggested I use --tag=CC for libtool builds where the compiler may think it's C++. (I applied this to LTM and TFM)
|
||||
-- Optimized the ECC for TFM a bit by removing the useless "if" statements (most TFM functions don't return error codes)
|
||||
Actually shaved a good chunk of time off and made the code smaller. By default with TFM the stock LTC point add/dbl functions
|
||||
will be totally omitted (ECC-256 make key times on a Prescott for old vs. new are 11.03M vs. 9.59M cycles)
|
||||
-- added missing CVS tags to ltc_ecc_mulmod.c
|
||||
-- corrected typo in tomcrypt_cfg.h about what the file has been called
|
||||
-- corrected my address in the user manual. A "bit" out of date.
|
||||
-- added lrw_gen to tv_gen
|
||||
-- added GMP plugin, only tested on a AMD64 and x86_32 Gentoo Linux box so be aware
|
||||
-- made testme.sh runs diff case insensitivityly [whatever...] cuz GMP outputs lowercase satan text
|
||||
-- added LDFLAGS to the makefile to allow cross porting linking options
|
||||
-- added lrw_test() to the header file ... whoops
|
||||
-- changed libtomcrypt.org to libtomcrypt.com .... mumble mumble
|
||||
-- Updates to detect __STRICT_ANSI__ which is defined in --std=c99 modes (note -ansi is not supported as it lacks long long) so you can
|
||||
build LTC out of the box with c99 (note: it'll be slower as there is no asm in this case)
|
||||
-- Updated pelican.c and aes_tab.c to undef tables not-required. The tables are static so both AES and Pelican MAC would have copies. Save a few KB in the final binary.
|
||||
-- Added LTC_NO_FAST to the makefile.icc to compensate for the fact ICC v9 can't handle it (Pelican MAC fails for instance)
|
||||
|
||||
February 11th, 2006
|
||||
v1.10 -- Free ecb/cbc/ctr/lrw structures in timing code by calling the "done" function
|
||||
-- fixed bug in lrw_process() which would always use the slow update ...
|
||||
-- vastly sped up gcm_gf_mult() when LTC_FAST is defined. This speeds up LRW and GCM state creation, useful for servers with GCM
|
||||
-- Removed NLS since there are some attacks against it.
|
||||
-- fixed memory leak in rsa_import reported by John Kuhns
|
||||
++ re-released as the rsa fix was incorrect (bad John bad ... hehehe) and I missed some NULLs in the static descriptor entry for ciphers
|
||||
|
||||
January 26th, 2006
|
||||
v1.09 -- Added missing doxygen comments to some of the ASN.1 routines
|
||||
-- Added "easy button" define LTC_EASY and LTC will build with a subset of all the algos. Reduces build times for typical
|
||||
configurations. Tunable [see tomcrypt_custom.h]
|
||||
-- Added some error detection to reg_algs() of the testprof.a library to detect when the PRNG is not setup correctly (took me 10 mins to figure out, PITA!)
|
||||
-- Similar fixes to timing demo (MD5 not defined when EASY is defined)
|
||||
-- Added the NLS enc+mac stream cipher from QUALCOMM, disabled for this release, waiting on test vectors
|
||||
-- Finally added an auto-update script for the makefiles. So when I add new files/dirs it can automatically fix up the makefiles [all four of them...]
|
||||
-- Added LRW to the list of cipher modes supported
|
||||
-- cleaned up ciphers definitions to remove cbc/cfb/ofb/ctr/etc from the namespace when not used.
|
||||
|
||||
November 24th, 2005
|
||||
v1.08 -- Added SET and SET OF support to the ASN.1 side
|
||||
-- Fixed up X macros, added QSORT to the mix [thanks SET/SETOF]
|
||||
-- Added XMEMCMP to the list of X macros
|
||||
-- In der_decode_sequence() the SHORT_INTEGER type was not being handled correctly [oddly enough it worked just enough to make RSA work ... go figure!]
|
||||
-- Fixed bug in math descriptors where if you hadn't defined MECC (ECC support) you would get linker errors
|
||||
-- Added RSA accelerators to the math descriptors to make it possible to not include the stock routines if you supply your own.
|
||||
-- dsa_decrypt_key() was erroneously dependent on MECC not MDSA ... whoops
|
||||
-- Moved DSA size limits to tomcrypt_pk.h so they're defined with LTC_NO_PK+MDSA
|
||||
-- cleaned up tomcrypt_custom.h to make customizable PK easier (and also cleaned up the error traps so they're correctly reported)
|
||||
|
||||
November 18th, 2005
|
||||
v1.07 -- Craig Schlenter pointed out the "encrypt" demo doesn't call ctr_start() correctly. That's because as of a few releases ago
|
||||
I added support to set the mode of the counter at init time
|
||||
-- Fixed some "testprof" make issues
|
||||
-- Added RSA keygen to the math descriptors
|
||||
-- Fixed install_test target ... oops
|
||||
-- made the "ranlib" program renamable useful for cross-compiling
|
||||
-- Made the cipher accelerators return error codes. :-)
|
||||
-- Made CCM accept a pre-scheduled key to speed it up if you use the same key for multiple packets
|
||||
-- Added "Katja" public key crypto. It's based on the recent N = p^2q work by Katja. I added OAEP padding
|
||||
to it. Note this code has been disabled not because it doesn't work but because it hasn't been thoroughly
|
||||
analyzed. It does carry some advantages over RSA (slightly smaller public key, faster decrypt) but also
|
||||
some annoying "setup" issues like the primes are smaller which makes ECM factoring more plausible.
|
||||
-- Made makefile accept a NODOCS flag to disable the requirement of tetex to install LTC for you no tetex people... all 3 of ya :-)
|
||||
-- Cleaned up rsa_export() since "zero" was handled with a SHORT_INTEGER
|
||||
-- Cleaned up the LIBTEST_S definitions in both GNU makefiles. A few minor touchups as well.
|
||||
-- Made the cipher ecb encrypt/decrypt return an int as well, changed ALL dependent code to check for this.
|
||||
-- der_decode_choice() would fail to mark a NULL as "used" when decoding. Fixed
|
||||
-- ecc_decrypt_key() now uses find_hash_oid() to clean up the code ;-)
|
||||
-- Added mp_neg() to the math descriptors.
|
||||
-- Swapped arguments for the pkcs_1_mgf1() function so the hash_idx is the first param (to be more consistent)
|
||||
-- Made the math descriptors buildable when RSA has been undefined
|
||||
-- ECC timing demo now capable of detecting which curves have been defined
|
||||
-- Refactored the ECC code so it's easier to maintain. (note: the form of this code hasn't really changed since I first added ECC ... :-/)
|
||||
-- Updated the documentation w.r.t. ECC and the accelerators to keep it current
|
||||
-- Fixed bug in ltc_init_multi() which would fail to free all allocated memory on error.
|
||||
-- Fixed bug in ecc_decrypt_key() which could possibly lead to overflows (if MAXBLOCKSIZE > ECC_BUF_SIZE and you have a hash that emits MAXBLOCKSIZE bytes)
|
||||
-- Added encrypt/decrypt to the DSA side (basically DH with DSA parameters)
|
||||
-- Updated makefiles to remove references to the old DH object files and the ecc_sys.o crap ... clean code ahead!
|
||||
-- ecc_import() now checks if the point it reads in lies on the curve (to prevent degenerative points from being used)
|
||||
-- ECC code now ALWAYS uses the accelerator interface. This allows people who use the accelerators to not have the stock
|
||||
ECC point add/dbl/mul code linked in. Yeah space savings! Rah Rah Rah.
|
||||
-- Added LTC_MUTEX_* support to Yarrow and Fortuna allowing you to use respective prng_state as a global PRNG state [e.g. thread-safe] if you define one of the LTC_* defines at
|
||||
build time (e.g. LTC_PTHREAD == pthreads)
|
||||
-- Added PPC32 support to the rotate macros (tested on an IBM PPC 405) and LTC_FAST macros (it aint fast but it's faster than stock)
|
||||
-- Added ltc_mp checks in all *_make_key() and *_import() which will help catch newbs who don't register their bignum first :-)
|
||||
-- the UTCTIME type was missing from der_length_sequence() [oops, oh like you've never done that]
|
||||
-- the main makefile allows you to rename the make command [e.g. MAKE=gmake gmake install] so you can build LTC on platforms where the default make command sucks [e.g. BSD]
|
||||
-- Added DER flexi decoder which allows the decoding of arbitrary DER encoded packets without knowing
|
||||
their structure in advance (thanks to MSVC for finding 3 bugs in it just prior to release! ... don't ask)
|
||||
|
||||
August 1st, 2005
|
||||
v1.06 -- Fixed rand_prime() to accept negative inputs as a signal for BBS primes. [Fredrik Olsson]
|
||||
-- Added fourth ARGCHK type which outputs to stderr and continues. Useful if you trap sigsegv. [Valient Gough]
|
||||
-- Removed the DH code from the tree
|
||||
-- Made the ECC code fully public (you can access ecc_mulmod directly now) useful for debuging
|
||||
-- Added ecc test to tv_gen
|
||||
-- Added hmac callback to hash descriptors.
|
||||
-- Fixed two doxy comment errors in the UTCTIME functions
|
||||
-- rsa_import() can now read OpenSSL format DER public keys as well as the PKCS #1 RSAPublicKey format.
|
||||
Note that rsa_export() **ONLY** writes PKCS #1 formats
|
||||
-- Changed MIN/MAX to only define if not already present. -- Kirk J from Demonware ...
|
||||
-- Ported tv_gen to new framework (and yes, I made ecc vectors BEFORE changing the API and YES they match now :-))
|
||||
-- ported testing scripts to support pluggable math. yipee!
|
||||
-- Wrote a TFM descriptor ... yipee
|
||||
-- Cleaned up LTC_FAST in CBC mode a bit
|
||||
-- Merged in patches from Michael Brown for the sparc/sparc64 targets
|
||||
-- Added find_hash_oid() to search for a hash by its OID
|
||||
-- Cleaned up a few stray CLEAN_STACKs that should have been LTC_CLEAN_STACK
|
||||
-- Added timing resistant ECC, enable by defining LTC_ECC_TIMING_RESISTANT then use ECC API as normal
|
||||
-- Updated the ECC documentation as it was a bit out of date
|
||||
|
||||
June 27th, 2005
|
||||
v1.05
|
||||
-- Added Technote #6 which covers the current PK compliance.
|
||||
-- Fixed buffer overflow in OAEP decoder
|
||||
-- Added CHOICE to the list of ASN.1 types
|
||||
-- Added UTCTIME to the list of ASN.1 types
|
||||
-- Added MUTEX locks around descriptor table functions [but not on the functions that are dependent on them]
|
||||
All functions call *_is_valid() before using a descriptor index which means the respective table must be unlocked before
|
||||
it can be accessed. However, during the operation [e.g. CCM] if the descriptor has been altered the results will be
|
||||
undefined.
|
||||
-- Minor updates to the manual to reflect recent changes
|
||||
-- Added a catch to for an error that should never come up in rsa_exptmod(). Just being thorough.
|
||||
|
||||
June 15th, 2005
|
||||
v1.04
|
||||
-- Fixed off by one [bit] error in dsa_make_key() it was too high by one bit [not a security problem just inconsistent]
|
||||
-- ECC-224 curve was wrong [it was an ok curve just not NIST, so no security flaw just interoperability].
|
||||
-- Removed point compression since it slows down ECC ops to save a measly couple bytes.
|
||||
This makes the ecc export format incompatible with 1.03 [it shouldn't change in the future]
|
||||
-- Removed ECC-160 from timing and added the other curves
|
||||
|
||||
June 9th, 2005
|
||||
v1.03
|
||||
-- Users may want to note that on a P4/GCC3.4 platform "-fno-regmove" greatly accelerates the ciphers/hashes.
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
-- Made it install the testing library in the icc/static makefiles
|
||||
-- Found bug in ccm_memory.c which would fail to compile when LTC_CLEAN_STACK was enabled
|
||||
-- Simon Johnson proposed I do a fully automated test suite. Hence "testme.sh" was born
|
||||
-- Added LTC_NO_TEST which forces test vectors off (regardless of what tomcrypt_custom.h has)
|
||||
-- Added LTC_NO_TABLES which disables large tables (where possible, regardless of what tomcrypt_custom.h has)
|
||||
-- New test script found a bug in twofish.c when TABLES was disabled. Yeah testing!
|
||||
-- Added a LTC_FAST specific test to the testing software.
|
||||
-- Updated test driver to actually halt on errors and just print them out (useful for say... automated testing...)
|
||||
-- Added bounds checking to Pelican MAC
|
||||
-- Added BIT and OCTET STRING to the ASN.1 side of things.
|
||||
-- Pekka Riikonen pointed out that my ctr_start() function should accept the counter mode.
|
||||
-- Cleaned up warnings in testprof
|
||||
-- Removed redundant mu and point mapping in ecc_verify_hash() so it should be a bit faster now
|
||||
-- Pekka pointed out that the AES key structure was using 32 bytes more than it ought to.
|
||||
-- Added quick defines to remove entire classes of algorithms. This makes it easier if you want to build with just
|
||||
one algorithm (say AES or SHA-256). Defines are LTC_NO_CIPHERS, LTC_NO_MODES, LTC_NO_HASHES, LTC_NO_MACS,
|
||||
LTC_NO_PRNGS, LTC_NO_PK, LTC_NO_PKCS
|
||||
-- As part of the move for ECC to X9.62 I've changed the signature algorithm to EC DSA. No API changes.
|
||||
-- Pekka helped me clean up the PKCS #1 v2.1 [OAEP/PSS] code
|
||||
-- Wrote new DER SEQUENCE coder/decoder
|
||||
-- RSA, DSA and ECDSA now use the DER SEQUENCE code (saves a lot of code!)
|
||||
-- DSA output is now a DER SEQUENCE (so not compatible with previous releases).
|
||||
-- Added Technote #5 which shows how to build LTC on an AMD64 to have a variety of algorithms in only ~80KB of code.
|
||||
-- Changed temp variable in LOAD/STORE macros to "ulong32" for 32-bit ops. Makes it safer on Big endian platforms
|
||||
-- Added INSTALL_GROUP and INSTALL_USER which you can specify on the build to override the default USER/GROUP the library
|
||||
is to be installed as
|
||||
-- Removed "testprof" from the default build.
|
||||
-- Added IA5, NULL and Object Identifier to the list of ASN.1 DER supported types
|
||||
-- The "no_oops" target (part of zipup) now scans for non-cvs files. This helps prevent temp/scratch files from appearing in releases ;-)
|
||||
-- Added DERs for missing hashes, but just the OID not the PKCS #1 v1.5 additions.
|
||||
-- Removed PKCS #1 v1.5 from the tree since it's taking up space and you ought to use v2.1 anyways
|
||||
-- Kevin Kenny pointed out a few stray // comments
|
||||
-- INTEGER code properly supports negatives and zero padding [Pekka!]
|
||||
-- Sorted asn1/der/ directory ... less of a mess now ;-)
|
||||
-- Added PRINTABLE STRING type
|
||||
-- Removed ECC-160 as it wasn't a standard curve
|
||||
-- Made ecc_shared_secret() ANSI X9.63 compliant
|
||||
-- Changed "printf" to "fprintf(stderr, " in the testbench... ;-)
|
||||
-- Optimized the GCM table creation. On 1KB packets [with key switching] the new GCM is 12.7x faster than before.
|
||||
-- Changed OID representation for hashes to be just a list of unsigned longs (so you can compare against them nicely after decoding a sequence)
|
||||
-- ECC code now uses Montgomery reduction ... it's even faster [ECC-256 make key down from 37.4M to 4.6M cycles on an Athlon64]
|
||||
-- Added SHORT_INTEGER so users can easily store DER encoded INTEGER types without using the bignum math library
|
||||
-- Fixed OMAC code so that with LTC_FAST it doesn't require that LTC_FAST_TYPE divides 16 [it has to divide the block size instead]
|
||||
-- ECC key export is now a simple [and documented] SEQUENCE, the "encrypt_key" also uses a new SEQUENCE format.
|
||||
-- Thanks goes to the following testers
|
||||
Michael Brown - Solaris 10/uSPARCII
|
||||
Richard Outerbridge - MacOS
|
||||
Martin Carpenter - Solaris 8/uSPARCII [Thanks for cleaning up the scripts]
|
||||
Greg Rose - ... SunOS 5.8/SPARC [... what's with the SPARCS?]
|
||||
Matt Johnston - MacOS X [Thanks for pointing out GCC 4 problems with -Os]
|
||||
|
||||
April 19th, 2005
|
||||
v1.02
|
||||
-- Added LTC_TEST support to gcm_test()
|
||||
-- "pt/ct" can now be NULL in gcm_process() if you are processing zero bytes
|
||||
-- Optimized GCM by removing the "double copy" handling of the plaintext/aad
|
||||
-- Richard Outerbridge pointed out that x86_prof won't build on MACOS and that the manual
|
||||
erroneously refers to "mycrypt" all over the place. Fixed.
|
||||
|
||||
April 17th, 2005
|
||||
v1.01
|
||||
** Secure Science Corporation has supported this release cycle by sponsoring the development time taken. Their
|
||||
continuing support of this project has helped me maintain a steady pace in order to keep LibTomCrypt up to date,
|
||||
stable and more efficient.
|
||||
-----------------------------------------------------------------------------------------------------
|
||||
-- Updated base64_decode.c so if there are more than 3 '=' signs it would stop parsing
|
||||
-- Merged in latest mpi that fixed a few bugs here and there
|
||||
-- Updated OAEP encoder/decoder to catch when the hash output is too large
|
||||
Cleaned up PSS code too
|
||||
-- Andy Bontoft fixed a bug in my demos/tests/makefile.msvc ... seems "dsa_test.c" isn't an object
|
||||
afterall. Thanks.
|
||||
-- Made invalid ECC key sizes (configuration) not hard fault the program (it returns an error code now)
|
||||
-- SAFER has been re-enabled after I was pointed to http://www.ciphersbyritter.com/NEWS2/95032301.HTM
|
||||
[Mark Kotiaho]
|
||||
-- Added CCM mode to the encauth list (now has EAX, OCB and CCM, c'est un treo magnifique!)
|
||||
-- Added missing ASN.1 header to the RSA keys ... oops... now the rsa_export/import are FULLY compatible
|
||||
with other libs like OpenSSL (comment: Test vectors would go a long way RSA...)
|
||||
-- Manually merged in fix to the prime_random_ex() LTM function that ensures the 2nd MSB is set properly. Now
|
||||
When you say "I want a 1024/8 byte RSA key" the MSB bit of the modulus is set as expected. Note I generally
|
||||
don't view this as a "huge issue" but it's just one less nit to worry about. [Bryan Klisch]
|
||||
-- A new CVS has been setup on my Athlon64 box... if you want developer access send me an email (and at this point the email would have to be awesome).
|
||||
-- Updated API for ECB and CBC shell code. Now can process N whole blocks in one call (like $DEITY intended)
|
||||
-- Introduced a new "hardware accel" framework that can be used to speed up cipher ECB, CBC and CTR mode
|
||||
calls. Later on dependent code (e.g. OMAC, CCM) will be re-written to use the generic cbc/ctr functions. But now
|
||||
if you [say] call ctr_encrypt() with a cipher descriptor that has hardware CTR it will automatically
|
||||
be used (e.g. no code rewrites)
|
||||
-- Now ships with 20% more love.
|
||||
-- x86_prof now uses ECB shell code (hint: accelerators) and outputs cycles per BLOCK not byte. This will make it a bit
|
||||
easier to compare hardware vs. software cipher implementations. It also emits timings for CBC and CTR modes
|
||||
-- [Peter LaDow] fixed a typo w.r.t. XREALLOC macro (spelling counts kids!)
|
||||
-- Fixed bug with __x86_64__ where ROL64/ROR64 with LTC_NO_ROLC would be the 32-bit versions instead...
|
||||
-- Shipping with preliminary GCM code (disabled). It's buggy (stack overflow hidden somewhere). If anyone can spot it let me know.
|
||||
-- Added Pelican MAC [it's an AES based fast MAC] to the list of supported MACs
|
||||
-- Added LTC_FAST [and you can disable by defining LTC_NO_FAST] so that CBC and CTR mode XOR whole words [e.g. 32 or 64 bits] at a time
|
||||
instead of one byte. On my AMD64 this reduced the overhead for AES-128-CBC from 4.56 cycles/byte to around 1 cycle/byte. This requires
|
||||
that you either allow unaligned read/writes [e.g. x86_32/x86_64] or align all your data. It won't go out of it's way to ensure
|
||||
aligned access. Only enabled for x86_* platforms by default since they allow unaligned read/writes.
|
||||
-- Added LTC_FAST support to PMAC (drops the cycle/byte by about 9 cycles on my AMD64) [note: I later rewrote this prior to release]
|
||||
-- Updated "profiled" target to work with the new directory layout
|
||||
-- Added [demo only] optimized RC5-CTR code to x86_prof demo to show off how to make an accelerator
|
||||
[This has been removed prior to release... It may re-appear later]
|
||||
-- Added CCM acelerator callbacks to the list [now supports ECB, CTR, CBC and now CCM].
|
||||
-- Added chapter to manual about accelerators (you know you want it)
|
||||
-- Added "bswap" optimizations to x86 LOAD/STORE with big endian. Can be disabled by defining LTC_NO_BSWAP
|
||||
-- LTC_NO_ASM is now the official "disable all non-portable stuff" macro. When defined it will make the code endian-neutral,
|
||||
disable any form of ASM and disable LTC_FAST load/stores. Essentially build the library with this defined if you're having
|
||||
trouble building the library (old GCCs for instance dislike the ROLc macro)
|
||||
-- Added tomcrypt_mac.h and moved MAC/encMAC functions from tomcrypt_hash.h into it
|
||||
-- Added "done" function to ciphers and the five chaining modes [and things like omac/pmac/etc]
|
||||
-- Changed install group to "wheel" from "root".
|
||||
-- Replaced // comments with /**/ so it will build on older UNIX-like platforms
|
||||
-- x86_prof builds and runs with IntelCC fine now
|
||||
-- Added "stest" build to intel CC to test static linked from within the dir (so you don't have to install to test)
|
||||
-- Moved testing/benchmark into testprof directory and build it as part of the build. Now you can link against libtomcrypt_prof.a to get
|
||||
testing info (hint: hardware developers ;-) )
|
||||
-- Added CCM to tv_gen
|
||||
-- Added demos to MSVC makefile
|
||||
-- Removed -funroll-all-loops from GCC makefile and replaced with -funroll-loops which is a bit more sane (P4 ain't got much cache for the IDATA)
|
||||
-- Fixed GCM prior to release and re-enabled it. It has not been optimized but it does conform when compiled with optimizations.
|
||||
-- I've since optimized GCM and CCM. They're close in speed but GCM is more flexible imho (though EAX is more flexible than both)
|
||||
-- For kicks I optimized the ECC code to use projective points. Gets between 3.21x (Prescott P4) to 4.53x (AMD64) times faster than before at 160-bit keys and the
|
||||
speedup grows as the keysize grows. Basically removing most practical reasons to "not use the ECC code". Enjoy.
|
||||
-- Added LTC_FAST support to OMAC/PMAC and doubled it's speed on my amd64 [faster on the P4 too I guess]
|
||||
-- Added GCM to tv_gen
|
||||
-- Removed "makefile.cygwin_dll" as it's not really used by anyone and not worth the effort (hell I hardly maintain the MSVC makefiles ...)
|
||||
-- Updated a few files in the "misc" directory to have correct @file comments for doxygen
|
||||
-- Removed "profile" target since it was slower anyways (go figure...)
|
||||
|
||||
December 31st, 2004
|
||||
v1.00
|
||||
-- Added "r,s == 0" check to dsa_verify_hash()
|
||||
-- Added "multi block" helpers for hash, hmac, pmac and omac routines so you can process multiple non-adjacent
|
||||
blocks of data with one call (added demos/multi.c to make sure they work)
|
||||
-- Note these are not documented but they do have doxygen comments inside them
|
||||
-- Also I don't use them in other functions (like pkcs_5_2()) because I didn't have the time. Job for the new LTC maintainer ;-)
|
||||
-- Added tweaked Anubis test vectors and made it default (undefined ANUBIS_TWEAK to get original Anubis)
|
||||
-- Merged in fix for mp_prime_random_ex() to deal with MSB and LSB "bugs"
|
||||
-- Removed tim_exptmod() completely, updated several RSA functions (notably v15 and the decrypt/verify) so they
|
||||
don't require a prng now
|
||||
-- This release brought to you by the fine tunes of Macy Gray. We miss you.
|
||||
|
||||
December 23rd, 2004
|
||||
v1.00rc1
|
||||
-- Renamed "mycrypt_*" to "tomcrypt_*" to be more specific and professional
|
||||
Now just include "tomcrypt.h" instead of "mycrypt.h" to get LTC ;-)
|
||||
-- Cleaned up makefiles to ensure all headers are correctly installed
|
||||
-- Added "rotate by constant" macros for portable, x86-32 and x86-64
|
||||
You can disable this new code with LTC_NO_ROLC which is useful for older GCCs
|
||||
-- Cleaned up detection of x86-64 so it works for ROL/ROR macros
|
||||
-- Fixed rsa_import() so that it would detect multi-prime RSA keys and error appropriately
|
||||
-- Sorted the source files by category and updated the makefiles appropriately
|
||||
-- Added LTC_DER define so you can trim out DER code if not required
|
||||
-- Fixed up RSA's decrypt functions changing "res" to "stat" to be more in sync
|
||||
with the signature variables nomenclature. (no code change just renamed the arguments)
|
||||
-- Removed all labels starting with __ and replaced with LBL_ to avoid namespace conflicts (Randy Howard)
|
||||
-- Merged in LTM fix to mp_prime_random_ex() which zap'ed the most significant byte if the bit size
|
||||
requested was a multiple of eight.
|
||||
-- Made RSA_TIMING off by default as it's not terribly useful [and likely to be deprecated]
|
||||
-- Renamed SMALL_CODE, CLEAN_STACK and NO_FILE to have a LTC_ prefix to avoid namespace collisions
|
||||
with other programs. e.g. SMALL_CODE => LTC_SMALL_CODE
|
||||
-- Zed Shaw pointed out that on certain systems installing libs as "root" isn't possible as the super-user
|
||||
is not root. Now the makefiles allow this to be changed easily.
|
||||
-- Renamed "struct _*_descriptor" to "struct ltc_*_descriptor" to avoid using a leading _
|
||||
Also renamed _ARGCHK to LTC_ARGCHK
|
||||
-- Zed Shaw pointed out that I still defined the prng structs in tomcrypt_prng.h even if they
|
||||
weren't defined. This made undef'ing FORTUNA break the build.
|
||||
-- Added LTC_NO_ASM to disable inline asm macros [ROL/ROR/etc]
|
||||
-- Changed RSA decrypt functions to change the output length variable name from "keylen" to "outlen" to make
|
||||
it more consistent.
|
||||
-- Added the 64-bit Khazad block cipher [NESSIE]
|
||||
-- Added the 128-bit Anubis block cipher [with key support for 128...320 bit keys] [NESSIE]
|
||||
-- Changes to several MAC functions to rename input arguments to more sensible names
|
||||
-- Removed FAST_PK support from dh_sys.c
|
||||
-- Declared deskey() from des.c as static instead of a global
|
||||
-- Added pretty much all practical GCC warning tests to the GCC [related] makefiles. These additional
|
||||
warnings can easily be disabled for those with older copies of GCC [or even non GNU cc's]
|
||||
-- Added doxygen @ tags to the code... phew that was a hell of a lot of [repetitive] work
|
||||
-- Also added pre-configured Doxygen script.
|
||||
-- Cleaned up quite a few functions [ciphers, pk, etc] to make the parameters naming style consistent
|
||||
E.g. ciphers keys are called "skey" consistently now. The input to PK encryption is called "in", etc.
|
||||
These changes require no code changes on the behalf of developers fortunately
|
||||
-- Started a SAFER+ optimizer [does encrypt only] which shaves a good 30 or so cycles/byte on my AMD64
|
||||
at an expense of huge code. It's in notes/etc/saferp_optimizer.c
|
||||
-- DSA sign/verify now uses DER encoded output/inputs and no LTC style headers.
|
||||
-- Matt Johnston found a missing semi-colon in mp_exptmod(). Fix has been merged in.
|
||||
|
||||
October 29th, 2004
|
||||
v0.99 -- Merged in the latest version of LTM which includes all of the recent bug fixes
|
||||
-- Deprecated LTMSSE and removed it (to be replaced with TFM later on)
|
||||
-- Stefan Arentz pointed out that mp_s_rmap should be extern
|
||||
-- Kristian Gj?steen pointed out that there are typos in the
|
||||
"test" makefile and minor issues in Yarrow and Sober [just cosmetics really]
|
||||
-- Matthew P. Cashdollar pointed out that "export" is a C++ keyword
|
||||
so changed the PRNG api to use "pexport" and "pimport"
|
||||
-- Updated "hashsum" demo so it builds ;-)
|
||||
-- Added automatic support for x86-64 (will configure for 64-bit little endian automagically)
|
||||
-- Zhi Chen pointed out a bug in rsa_exptmod which would leak memory on error.
|
||||
-- Made hash functions "init" return an int. slight change to API ;-(
|
||||
-- Added "CHC" mode which turns any cipher into a hash the other LTC functions can use
|
||||
-- Added CHC mode stuff to demos such as tv_gen and hashsum
|
||||
-- Added "makefile.shared" which builds and installs shared/static object copies
|
||||
of the library.
|
||||
-- Added DER for bignum support
|
||||
-- RSA is now fully joy. rsa_export/rsa_import use PKCS #1 encodings and should be
|
||||
compatible with other crypto libs that use the format.
|
||||
-- Added support for x86-64 for the ROL/ROR macros
|
||||
-- Changed the DLL and SO makefiles to optimize for speed, commented SMALL_CODE in
|
||||
mycrypt_custom.h and added -DSMALL_CODE to the default makefile
|
||||
-- Updated primality testing code so it does a minimum of 5 tests [of Miller-Rabin]
|
||||
(AFAIK not a security fix, just warm fuzzies)
|
||||
-- Minor updates to the OMAC code (additional __ARGCHK and removed printf from omac_test... oops!)
|
||||
-- Update build and configuration info which was really really really out of date. (Chapter 14)
|
||||
++ Minor update, switch RSA to use the PKCS style CRT
|
||||
|
||||
August 6th, 2004
|
||||
v0.98 -- Update to hmac_init to free all allocated memory on error
|
||||
-- Update to PRNG API to fix import/export functions of Fortuna and Yarrow
|
||||
-- Added test functions to PRNG api, RC4 now conforms ;-) [was a minor issue]
|
||||
-- Added the SOBER-128 PRNG based off of code donated by Greg Rose.
|
||||
-- Added Tech Note #4 [notes/tech0004.txt]
|
||||
-- Changed RC4 back [due to request]. It will now XOR the output so you can use it like
|
||||
a stream cipher easily.
|
||||
-- Update Fortuna's export() to emit a hash of each pool. This means that the accumulated
|
||||
entropy that was spread over all the pools isn't entirely lost when you export/import.
|
||||
-- Zhi Chen suggested a comment for rsa_encrypt_key() to let users know [easily] that it was
|
||||
PKCS #1 v2.0 padding. (updated other rsa_* functions)
|
||||
-- Cleaned up Noekeon to remove unrolling [wasn't required, was messy and actually slower with GCC/ICC]
|
||||
-- Updated RC4 so that when you feed it >256 bytes of entropy it quietly ignores additional
|
||||
bytes. Also removed the % from the key setup to speed it up a bit.
|
||||
-- Added cipher/hash/prng tests to x86_prof to help catch bugs while testing
|
||||
-- Made the PRNG "done" return int, fixed sprng_done to not require prng* to be non-null
|
||||
-- Spruced up mycrypt_custom.h to trap more errors and also help prevent LTMSSE from being defined
|
||||
on non-i386 platforms by accident.
|
||||
-- Added RSA/ECC/DH speed tests to x86_prof and cleaned it up to build with zero warnings
|
||||
-- Changed Fortuna to count only entropy [not the 2 byte header] added to pool[0] into the
|
||||
reseed mechanism.
|
||||
-- Added "export_size" member to prng_descriptor tables so you can know in advance the size of
|
||||
the exported state for any given PRNG.
|
||||
-- Ported over patch on LTM 0.30 [not ready to release LTM 0.31] that fixes bug in mp_mul()/mp_div()
|
||||
that used to result in negative zeroes when you multiplied zero by a negative integer.
|
||||
(patch due to "Wolfgang Ehrhardt" <Wolfgang.Ehrhardt@munich.netsurf.de>)
|
||||
-- Fixed rsa_*decrypt_key() and rsa_*verify_hash() to default to invalid "stat" or "res". This way
|
||||
if any of the higher level functions fail [before you get to the padding] the result will be in
|
||||
a known state]. Applied to both v2 and v1.5 padding helpers.
|
||||
-- Added MACs to x86_prof
|
||||
-- Fixed up "warnings" in x86_prof and tv_gen
|
||||
-- Added a "profiled" target back [for GCC 3.4 and ICC v8]. Doesn't seem to help but might be worth
|
||||
tinkering with.
|
||||
-- Beefed up load/store test in demos/test
|
||||
|
||||
++ New note, in order to use the optimized LOAD/STORE macros your platform
|
||||
must support unaligned 32/64 bit load/stores. The x86s support this
|
||||
but some [ARM for instance] do not. If your platform cannot perform
|
||||
unaligned operations you must use the endian neutral code which is safe for
|
||||
any sort of platform.
|
||||
|
||||
July 23rd, 2004
|
||||
v0.97b -- Added PKCS #1 v1.5 RSA encrypt/sign helpers (like rsa_sign_hash, etc...)
|
||||
-- Added missing prng check to rsa_decrypt_key() [not critical as I don't use
|
||||
|
|
@ -665,7 +62,7 @@ v0.96 -- Removed GF and Keyring code
|
|||
-- Changed PSS/OAEP API slightly to be more consistent with other PK functions (order of arguments)
|
||||
-- rsa_exptmod() now pads with leading zeroes as per I2OSP.
|
||||
-- added error checking to yarrow code
|
||||
-- pointed out that tommath.h from this distro will overwrite tommath.h
|
||||
-- Mike Frysinger pointed out that tommath.h from this distro will overwrite tommath.h
|
||||
from libtommath. I changed this to ltc_tommath.h to avoid any such problems.
|
||||
-- Fixed bug in PSS encoder/decoder that didn't handle the MSB properly
|
||||
-- refactored AES, now sports an "encrypt only" descriptor which uses half as much code space.
|
||||
|
|
@ -914,7 +311,7 @@ v0.81 -- Merged in new makefile from Clay Culver and Mike Frysinger
|
|||
as much as possible. This sped the routine up quite a bit.
|
||||
-- Fixed a huge flaw in ecc_verify_hash() where it would return CRYPT_OK on error... Now fixed.
|
||||
-- Fixed up config.pl by fixing an invalid query and the file is saved in non-windows [e.g. not CR/LF] format
|
||||
(fix due to Mika Bostr?m)
|
||||
(fix due to Mika Boström)
|
||||
-- Merged in LibTomMath for kicks
|
||||
-- Changed the build process so that by default "mycrypt_custom.h" is included and provided
|
||||
The makefile doesn't include any build options anymore
|
||||
|
|
@ -1641,8 +1038,3 @@ v0.02 -- Changed RC5 to only allow 12 to 24 rounds
|
|||
-- Added more to the manual.
|
||||
|
||||
v0.01 -- We will call this the first version.
|
||||
|
||||
/* $Source: /cvs/libtom/libtomcrypt/changes,v $ */
|
||||
/* $Revision: 1.288 $ */
|
||||
/* $Date: 2007/05/12 14:37:41 $ */
|
||||
|
||||
|
|
|
|||
241
cmake-format.py
241
cmake-format.py
|
|
@ -1,241 +0,0 @@
|
|||
# ----------------------------------
|
||||
# Options affecting listfile parsing
|
||||
# ----------------------------------
|
||||
with section("parse"):
|
||||
|
||||
# Specify structure for custom cmake functions
|
||||
additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'],
|
||||
'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}}
|
||||
|
||||
# Override configurations per-command where available
|
||||
override_spec = {}
|
||||
|
||||
# Specify variable tags.
|
||||
vartags = []
|
||||
|
||||
# Specify property tags.
|
||||
proptags = []
|
||||
|
||||
# -----------------------------
|
||||
# Options affecting formatting.
|
||||
# -----------------------------
|
||||
with section("format"):
|
||||
|
||||
# Disable formatting entirely, making cmake-format a no-op
|
||||
disable = False
|
||||
|
||||
# How wide to allow formatted cmake files
|
||||
line_width = 100
|
||||
|
||||
# How many spaces to tab for indent
|
||||
tab_size = 4
|
||||
|
||||
# If true, lines are indented using tab characters (utf-8 0x09) instead of
|
||||
# <tab_size> space characters (utf-8 0x20). In cases where the layout would
|
||||
# require a fractional tab character, the behavior of the fractional
|
||||
# indentation is governed by <fractional_tab_policy>
|
||||
use_tabchars = False
|
||||
|
||||
# If <use_tabchars> is True, then the value of this variable indicates how
|
||||
# fractional indentions are handled during whitespace replacement. If set to
|
||||
# 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set
|
||||
# to `round-up` fractional indentation is replaced with a single tab character
|
||||
# (utf-8 0x09) effectively shifting the column to the next tabstop
|
||||
fractional_tab_policy = 'use-space'
|
||||
|
||||
# If an argument group contains more than this many sub-groups (parg or kwarg
|
||||
# groups) then force it to a vertical layout.
|
||||
max_subgroups_hwrap = 2
|
||||
|
||||
# If a positional argument group contains more than this many arguments, then
|
||||
# force it to a vertical layout.
|
||||
max_pargs_hwrap = 6
|
||||
|
||||
# If a cmdline positional group consumes more than this many lines without
|
||||
# nesting, then invalidate the layout (and nest)
|
||||
max_rows_cmdline = 2
|
||||
|
||||
# If true, separate flow control names from their parentheses with a space
|
||||
separate_ctrl_name_with_space = False
|
||||
|
||||
# If true, separate function names from parentheses with a space
|
||||
separate_fn_name_with_space = False
|
||||
|
||||
# If a statement is wrapped to more than one line, than dangle the closing
|
||||
# parenthesis on its own line.
|
||||
dangle_parens = True
|
||||
|
||||
# If the trailing parenthesis must be 'dangled' on its on line, then align it
|
||||
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
|
||||
# the start of the statement, plus one indentation level, `child`: align to
|
||||
# the column of the arguments
|
||||
dangle_align = 'prefix'
|
||||
|
||||
# If the statement spelling length (including space and parenthesis) is
|
||||
# smaller than this amount, then force reject nested layouts.
|
||||
min_prefix_chars = 4
|
||||
|
||||
# If the statement spelling length (including space and parenthesis) is larger
|
||||
# than the tab width by more than this amount, then force reject un-nested
|
||||
# layouts.
|
||||
max_prefix_chars = 10
|
||||
|
||||
# If a candidate layout is wrapped horizontally but it exceeds this many
|
||||
# lines, then reject the layout.
|
||||
max_lines_hwrap = 2
|
||||
|
||||
# What style line endings to use in the output.
|
||||
line_ending = 'unix'
|
||||
|
||||
# Format command names consistently as 'lower' or 'upper' case
|
||||
command_case = 'lower'
|
||||
|
||||
# Format keywords consistently as 'lower' or 'upper' case
|
||||
keyword_case = 'upper'
|
||||
|
||||
# A list of command names which should always be wrapped
|
||||
always_wrap = []
|
||||
|
||||
# If true, the argument lists which are known to be sortable will be sorted
|
||||
# lexicographicall
|
||||
enable_sort = True
|
||||
|
||||
# If true, the parsers may infer whether or not an argument list is sortable
|
||||
# (without annotation).
|
||||
autosort = False
|
||||
|
||||
# By default, if cmake-format cannot successfully fit everything into the
|
||||
# desired linewidth it will apply the last, most agressive attempt that it
|
||||
# made. If this flag is True, however, cmake-format will print error, exit
|
||||
# with non-zero status code, and write-out nothing
|
||||
require_valid_layout = False
|
||||
|
||||
# A dictionary mapping layout nodes to a list of wrap decisions. See the
|
||||
# documentation for more information.
|
||||
layout_passes = {}
|
||||
|
||||
# ------------------------------------------------
|
||||
# Options affecting comment reflow and formatting.
|
||||
# ------------------------------------------------
|
||||
with section("markup"):
|
||||
|
||||
# What character to use for bulleted lists
|
||||
bullet_char = '*'
|
||||
|
||||
# What character to use as punctuation after numerals in an enumerated list
|
||||
enum_char = '.'
|
||||
|
||||
# If comment markup is enabled, don't reflow the first comment block in each
|
||||
# listfile. Use this to preserve formatting of your copyright/license
|
||||
# statements.
|
||||
first_comment_is_literal = False
|
||||
|
||||
# If comment markup is enabled, don't reflow any comment block which matches
|
||||
# this (regex) pattern. Default is `None` (disabled).
|
||||
literal_comment_pattern = None
|
||||
|
||||
# Regular expression to match preformat fences in comments default=
|
||||
# ``r'^\s*([`~]{3}[`~]*)(.*)$'``
|
||||
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
|
||||
|
||||
# Regular expression to match rulers in comments default=
|
||||
# ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
|
||||
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
|
||||
|
||||
# If a comment line matches starts with this pattern then it is explicitly a
|
||||
# trailing comment for the preceeding argument. Default is '#<'
|
||||
explicit_trailing_pattern = '#<'
|
||||
|
||||
# If a comment line starts with at least this many consecutive hash
|
||||
# characters, then don't lstrip() them off. This allows for lazy hash rulers
|
||||
# where the first hash char is not separated by space
|
||||
hashruler_min_length = 10
|
||||
|
||||
# If true, then insert a space between the first hash char and remaining hash
|
||||
# chars in a hash ruler, and normalize its length to fill the column
|
||||
canonicalize_hashrulers = True
|
||||
|
||||
# enable comment markup parsing and reflow
|
||||
enable_markup = True
|
||||
|
||||
# ----------------------------
|
||||
# Options affecting the linter
|
||||
# ----------------------------
|
||||
with section("lint"):
|
||||
|
||||
# a list of lint codes to disable
|
||||
disabled_codes = []
|
||||
|
||||
# regular expression pattern describing valid function names
|
||||
function_pattern = '[0-9a-z_]+'
|
||||
|
||||
# regular expression pattern describing valid macro names
|
||||
macro_pattern = '[0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for variables with global
|
||||
# (cache) scope
|
||||
global_var_pattern = '[A-Z][0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for variables with global
|
||||
# scope (but internal semantic)
|
||||
internal_var_pattern = '_[A-Z][0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for variables with local
|
||||
# scope
|
||||
local_var_pattern = '[a-z][a-z0-9_]+'
|
||||
|
||||
# regular expression pattern describing valid names for privatedirectory
|
||||
# variables
|
||||
private_var_pattern = '_[0-9a-z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for public directory
|
||||
# variables
|
||||
public_var_pattern = '[A-Z][0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for function/macro
|
||||
# arguments and loop variables.
|
||||
argument_var_pattern = '[a-z][a-z0-9_]+'
|
||||
|
||||
# regular expression pattern describing valid names for keywords used in
|
||||
# functions or macros
|
||||
keyword_pattern = '[A-Z][0-9A-Z_]+'
|
||||
|
||||
# In the heuristic for C0201, how many conditionals to match within a loop in
|
||||
# before considering the loop a parser.
|
||||
max_conditionals_custom_parser = 2
|
||||
|
||||
# Require at least this many newlines between statements
|
||||
min_statement_spacing = 1
|
||||
|
||||
# Require no more than this many newlines between statements
|
||||
max_statement_spacing = 2
|
||||
max_returns = 6
|
||||
max_branches = 12
|
||||
max_arguments = 5
|
||||
max_localvars = 15
|
||||
max_statements = 50
|
||||
|
||||
# -------------------------------
|
||||
# Options affecting file encoding
|
||||
# -------------------------------
|
||||
with section("encode"):
|
||||
|
||||
# If true, emit the unicode byte-order mark (BOM) at the start of the file
|
||||
emit_byteorder_mark = False
|
||||
|
||||
# Specify the encoding of the input file. Defaults to utf-8
|
||||
input_encoding = 'utf-8'
|
||||
|
||||
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
|
||||
# only claims to support utf-8 so be careful when using anything else
|
||||
output_encoding = 'utf-8'
|
||||
|
||||
# -------------------------------------
|
||||
# Miscellaneous configurations options.
|
||||
# -------------------------------------
|
||||
with section("misc"):
|
||||
|
||||
# A dictionary containing any per-command configuration overrides. Currently
|
||||
# only `command_case` is supported.
|
||||
per_command = {}
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
# To find libtomcrypt no matter what the installation look like, start with
|
||||
# looking for the CMake specific configuration, and failing that, try the
|
||||
# pkg-config package instead. The resulting target is different in each
|
||||
# case, but is recorded in the variable ${LIBTOMCRYPT}, so please use that
|
||||
# for all targets that depend on libtomcrypt.
|
||||
|
||||
find_package(libtomcrypt QUIET)
|
||||
if (libtomcrypt_FOUND)
|
||||
set(LIBTOMCRYPT libtomcrypt)
|
||||
else()
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(libtomcrypt REQUIRED IMPORTED_TARGET libtomcrypt)
|
||||
set(LIBTOMCRYPT PkgConfig::libtomcrypt)
|
||||
endif()
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
{
|
||||
"bomFormat": "CycloneDX",
|
||||
"specVersion": "1.6",
|
||||
"version": 1,
|
||||
"metadata": {
|
||||
"authors": [
|
||||
{
|
||||
"name": "@VCS_SBOM_AUTHORS@"
|
||||
}
|
||||
]
|
||||
},
|
||||
"components": [
|
||||
{
|
||||
"type": "library",
|
||||
"bom-ref": "pkg:github/libtom/libtomcrypt@@VCS_TAG@",
|
||||
"cpe": "cpe:2.3:a:libtom:libtomcrypt:@VCS_TAG@:*:*:*:*:*:*:*",
|
||||
"name": "libtomcrypt",
|
||||
"version": "@VCS_VERSION@",
|
||||
"description": "Modular and portable cryptographic toolkit",
|
||||
"authors": [
|
||||
{
|
||||
"name": "libtomcrypt developers"
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"license": {
|
||||
"id": "Unlicense"
|
||||
}
|
||||
}
|
||||
],
|
||||
"externalReferences": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://github.com/libtom/libtomcrypt"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
42
coverity.sh
42
coverity.sh
|
|
@ -1,42 +0,0 @@
|
|||
#!/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
|
||||
|
||||
# EOF
|
||||
25
crypt
Normal file
25
crypt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
%PDF-1.3
|
||||
%Çì<C387>¢
|
||||
3 0 obj
|
||||
<< /Type /Pages /Kids [
|
||||
] /Count 0
|
||||
>>
|
||||
endobj
|
||||
1 0 obj
|
||||
<</Type /Catalog /Pages 3 0 R
|
||||
>>
|
||||
endobj
|
||||
2 0 obj
|
||||
<</Producer(ESP Ghostscript 7.07)>>endobj
|
||||
xref
|
||||
0 4
|
||||
0000000000 65535 f
|
||||
0000000068 00000 n
|
||||
0000000116 00000 n
|
||||
0000000015 00000 n
|
||||
trailer
|
||||
<< /Size 4 /Root 1 0 R /Info 2 0 R
|
||||
>>
|
||||
startxref
|
||||
166
|
||||
%%EOF
|
||||
236
crypt.c
Normal file
236
crypt.c
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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"
|
||||
|
||||
const char *crypt_build_settings =
|
||||
"LibTomCrypt " SCRYPT "\n\n"
|
||||
"Endianess: "
|
||||
#if defined(ENDIAN_NEUTRAL)
|
||||
"neutral\n"
|
||||
#elif defined(ENDIAN_LITTLE)
|
||||
"little"
|
||||
#if defined(ENDIAN_32BITWORD)
|
||||
" (32-bit words)\n"
|
||||
#else
|
||||
" (64-bit words)\n"
|
||||
#endif
|
||||
#elif defined(ENDIAN_BIG)
|
||||
"big"
|
||||
#if defined(ENDIAN_32BITWORD)
|
||||
" (32-bit words)\n"
|
||||
#else
|
||||
" (64-bit words)\n"
|
||||
#endif
|
||||
#endif
|
||||
"Clean stack: "
|
||||
#if defined(CLEAN_STACK)
|
||||
"enabled\n"
|
||||
#else
|
||||
"disabled\n"
|
||||
#endif
|
||||
"Ciphers built-in:\n"
|
||||
#if defined(BLOWFISH)
|
||||
" Blowfish\n"
|
||||
#endif
|
||||
#if defined(RC2)
|
||||
" RC2\n"
|
||||
#endif
|
||||
#if defined(RC5)
|
||||
" RC5\n"
|
||||
#endif
|
||||
#if defined(RC6)
|
||||
" RC6\n"
|
||||
#endif
|
||||
#if defined(SAFERP)
|
||||
" Safer+\n"
|
||||
#endif
|
||||
#if defined(SAFER)
|
||||
" Safer\n"
|
||||
#endif
|
||||
#if defined(RIJNDAEL)
|
||||
" Rijndael\n"
|
||||
#endif
|
||||
#if defined(XTEA)
|
||||
" XTEA\n"
|
||||
#endif
|
||||
#if defined(TWOFISH)
|
||||
" Twofish "
|
||||
#if defined(TWOFISH_SMALL) && defined(TWOFISH_TABLES)
|
||||
"(small, tables)\n"
|
||||
#elif defined(TWOFISH_SMALL)
|
||||
"(small)\n"
|
||||
#elif defined(TWOFISH_TABLES)
|
||||
"(tables)\n"
|
||||
#else
|
||||
"\n"
|
||||
#endif
|
||||
#endif
|
||||
#if defined(DES)
|
||||
" DES\n"
|
||||
#endif
|
||||
#if defined(CAST5)
|
||||
" CAST5\n"
|
||||
#endif
|
||||
#if defined(NOEKEON)
|
||||
" Noekeon\n"
|
||||
#endif
|
||||
#if defined(SKIPJACK)
|
||||
" Skipjack\n"
|
||||
#endif
|
||||
|
||||
"\nHashes built-in:\n"
|
||||
#if defined(SHA512)
|
||||
" SHA-512\n"
|
||||
#endif
|
||||
#if defined(SHA384)
|
||||
" SHA-384\n"
|
||||
#endif
|
||||
#if defined(SHA256)
|
||||
" SHA-256\n"
|
||||
#endif
|
||||
#if defined(SHA224)
|
||||
" SHA-224\n"
|
||||
#endif
|
||||
#if defined(TIGER)
|
||||
" TIGER\n"
|
||||
#endif
|
||||
#if defined(SHA1)
|
||||
" SHA1\n"
|
||||
#endif
|
||||
#if defined(MD5)
|
||||
" MD5\n"
|
||||
#endif
|
||||
#if defined(MD4)
|
||||
" MD4\n"
|
||||
#endif
|
||||
#if defined(MD2)
|
||||
" MD2\n"
|
||||
#endif
|
||||
#if defined(RIPEMD128)
|
||||
" RIPEMD128\n"
|
||||
#endif
|
||||
#if defined(RIPEMD160)
|
||||
" RIPEMD160\n"
|
||||
#endif
|
||||
#if defined(WHIRLPOOL)
|
||||
" WHIRLPOOL\n"
|
||||
#endif
|
||||
|
||||
"\nBlock Chaining Modes:\n"
|
||||
#if defined(CFB)
|
||||
" CFB\n"
|
||||
#endif
|
||||
#if defined(OFB)
|
||||
" OFB\n"
|
||||
#endif
|
||||
#if defined(ECB)
|
||||
" ECB\n"
|
||||
#endif
|
||||
#if defined(CBC)
|
||||
" CBC\n"
|
||||
#endif
|
||||
#if defined(CTR)
|
||||
" CTR\n"
|
||||
#endif
|
||||
|
||||
"\nPRNG:\n"
|
||||
#if defined(YARROW)
|
||||
" Yarrow\n"
|
||||
#endif
|
||||
#if defined(SPRNG)
|
||||
" SPRNG\n"
|
||||
#endif
|
||||
#if defined(RC4)
|
||||
" RC4\n"
|
||||
#endif
|
||||
|
||||
"\nPK Algs:\n"
|
||||
#if defined(MRSA)
|
||||
" RSA"
|
||||
#if defined(RSA_TIMING)
|
||||
" + RSA_TIMING "
|
||||
#endif
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MDH)
|
||||
" DH\n"
|
||||
#endif
|
||||
#if defined(MECC)
|
||||
" ECC\n"
|
||||
#endif
|
||||
#if defined(MDSA)
|
||||
" DSA\n"
|
||||
#endif
|
||||
|
||||
"\nCompiler:\n"
|
||||
#if defined(WIN32)
|
||||
" WIN32 platform detected.\n"
|
||||
#endif
|
||||
#if defined(__CYGWIN__)
|
||||
" CYGWIN Detected.\n"
|
||||
#endif
|
||||
#if defined(__DJGPP__)
|
||||
" DJGPP Detected.\n"
|
||||
#endif
|
||||
#if defined(_MSC_VER)
|
||||
" MSVC compiler detected.\n"
|
||||
#endif
|
||||
#if defined(__GNUC__)
|
||||
" GCC compiler detected.\n"
|
||||
#endif
|
||||
#if defined(INTEL_CC)
|
||||
" Intel C Compiler detected.\n"
|
||||
#endif
|
||||
|
||||
"\nVarious others: "
|
||||
#if defined(BASE64)
|
||||
" BASE64 "
|
||||
#endif
|
||||
#if defined(MPI)
|
||||
" MPI "
|
||||
#endif
|
||||
#if defined(HMAC)
|
||||
" HMAC "
|
||||
#endif
|
||||
#if defined(OMAC)
|
||||
" OMAC "
|
||||
#endif
|
||||
#if defined(PMAC)
|
||||
" PMAC "
|
||||
#endif
|
||||
#if defined(EAX_MODE)
|
||||
" EAX_MODE "
|
||||
#endif
|
||||
#if defined(OCB_MODE)
|
||||
" OCB_MODE "
|
||||
#endif
|
||||
#if defined(TRY_UNRANDOM_FIRST)
|
||||
" TRY_UNRANDOM_FIRST "
|
||||
#endif
|
||||
#if defined(LTC_TEST)
|
||||
" LTC_TEST "
|
||||
#endif
|
||||
#if defined(PKCS_1)
|
||||
" PKCS#1 "
|
||||
#endif
|
||||
#if defined(PKCS_5)
|
||||
" PKCS#5 "
|
||||
#endif
|
||||
#if defined(SMALL_CODE)
|
||||
" SMALL_CODE "
|
||||
#endif
|
||||
#if defined(NO_FILE)
|
||||
" NO_FILE "
|
||||
#endif
|
||||
"\n"
|
||||
"\n\n\n"
|
||||
;
|
||||
|
||||
21
crypt_argchk.c
Normal file
21
crypt_argchk.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
#include <signal.h>
|
||||
|
||||
#if (ARGTYPE == 0)
|
||||
void crypt_argchk(char *v, char *s, int d)
|
||||
{
|
||||
fprintf(stderr, "_ARGCHK '%s' failure on line %d of file %s\n",
|
||||
v, d, s);
|
||||
(void)raise(SIGABRT);
|
||||
}
|
||||
#endif
|
||||
14
crypt_cipher_descriptor.c
Normal file
14
crypt_cipher_descriptor.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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];
|
||||
|
||||
19
crypt_cipher_is_valid.c
Normal file
19
crypt_cipher_is_valid.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int cipher_is_valid(int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
|
||||
return CRYPT_INVALID_CIPHER;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
24
crypt_find_cipher.c
Normal file
24
crypt_find_cipher.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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;
|
||||
}
|
||||
|
||||
32
crypt_find_cipher_any.c
Normal file
32
crypt_find_cipher_any.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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;
|
||||
}
|
||||
22
crypt_find_cipher_id.c
Normal file
22
crypt_find_cipher_id.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int find_cipher_id(unsigned char ID)
|
||||
{
|
||||
int x;
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].ID == ID) {
|
||||
return (cipher_descriptor[x].name == NULL) ? -1 : x;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
23
crypt_find_hash.c
Normal file
23
crypt_find_hash.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int find_hash(const char *name)
|
||||
{
|
||||
int x;
|
||||
_ARGCHK(name != NULL);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name != NULL && strcmp(hash_descriptor[x].name, name) == 0) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
34
crypt_find_hash_any.c
Normal file
34
crypt_find_hash_any.c
Normal file
|
|
@ -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@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;
|
||||
}
|
||||
22
crypt_find_hash_id.c
Normal file
22
crypt_find_hash_id.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int find_hash_id(unsigned char ID)
|
||||
{
|
||||
int x;
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].ID == ID) {
|
||||
return (hash_descriptor[x].name == NULL) ? -1 : x;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
24
crypt_find_prng.c
Normal file
24
crypt_find_prng.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int find_prng(const char *name)
|
||||
{
|
||||
int x;
|
||||
_ARGCHK(name != NULL);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if ((prng_descriptor[x].name != NULL) && strcmp(prng_descriptor[x].name, name) == 0) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
14
crypt_hash_descriptor.c
Normal file
14
crypt_hash_descriptor.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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];
|
||||
|
||||
19
crypt_hash_is_valid.c
Normal file
19
crypt_hash_is_valid.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int hash_is_valid(int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
|
||||
return CRYPT_INVALID_HASH;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
13
crypt_prng_descriptor.c
Normal file
13
crypt_prng_descriptor.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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];
|
||||
19
crypt_prng_is_valid.c
Normal file
19
crypt_prng_is_valid.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
int prng_is_valid(int idx)
|
||||
{
|
||||
if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
|
||||
return CRYPT_INVALID_PRNG;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
36
crypt_register_cipher.c
Normal file
36
crypt_register_cipher.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@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;
|
||||
}
|
||||
36
crypt_register_hash.c
Normal file
36
crypt_register_hash.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@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;
|
||||
}
|
||||
36
crypt_register_prng.c
Normal file
36
crypt_register_prng.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@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;
|
||||
}
|
||||
28
crypt_unregister_cipher.c
Normal file
28
crypt_unregister_cipher.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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;
|
||||
}
|
||||
27
crypt_unregister_hash.c
Normal file
27
crypt_unregister_hash.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@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;
|
||||
}
|
||||
27
crypt_unregister_prng.c
Normal file
27
crypt_unregister_prng.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@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;
|
||||
}
|
||||
25
ctr_decrypt.c
Normal file
25
ctr_decrypt.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms 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
|
||||
|
||||
64
ctr_encrypt.c
Normal file
64
ctr_encrypt.c
Normal file
|
|
@ -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@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
|
||||
30
ctr_getiv.c
Normal file
30
ctr_getiv.c
Normal file
|
|
@ -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@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
|
||||
43
ctr_setiv.c
Normal file
43
ctr_setiv.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef CTR
|
||||
|
||||
int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
|
||||
{
|
||||
int err;
|
||||
|
||||
_ARGCHK(IV != NULL);
|
||||
_ARGCHK(ctr != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)ctr->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* set IV */
|
||||
XMEMCPY(ctr->ctr, IV, len);
|
||||
|
||||
/* force next block */
|
||||
ctr->padlen = 0;
|
||||
cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
46
ctr_start.c
Normal file
46
ctr_start.c
Normal file
|
|
@ -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@iahu.ca, http://libtomcrypt.org
|
||||
*/
|
||||
#include "mycrypt.h"
|
||||
|
||||
#ifdef CTR
|
||||
|
||||
int ctr_start(int cipher, const unsigned char *count, const unsigned char *key, int keylen,
|
||||
int num_rounds, symmetric_CTR *ctr)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
_ARGCHK(count != NULL);
|
||||
_ARGCHK(key != NULL);
|
||||
_ARGCHK(ctr != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* setup cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy ctr */
|
||||
ctr->blocklen = cipher_descriptor[cipher].block_length;
|
||||
ctr->cipher = cipher;
|
||||
ctr->padlen = 0;
|
||||
ctr->mode = 0;
|
||||
for (x = 0; x < ctr->blocklen; x++) {
|
||||
ctr->ctr[x] = count[x];
|
||||
}
|
||||
cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
# -----------------------------------------------------------------------------
|
||||
# Options
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
option(INSTALL_DEMOS "Install enabled demos (USEFUL and/or USABLE) and ltc wrapper script" FALSE)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Useful demos
|
||||
#
|
||||
# Demos that are even somehow useful and could be installed as a system-tool
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
set(USEFUL_DEMOS hashsum)
|
||||
list(JOIN USEFUL_DEMOS " " USEFUL_DEMOS_STR)
|
||||
option(BUILD_USEFUL_DEMOS "Build useful demos (${USEFUL_DEMOS_STR})" FALSE)
|
||||
|
||||
if(BUILD_USEFUL_DEMOS)
|
||||
list(APPEND USABLE_DEMOS_TARGETS ${USEFUL_DEMOS})
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Usable demos
|
||||
#
|
||||
# Demos that are usable but only rarely make sense to be installed
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
set(USABLE_DEMOS aesgcm constants crypt der_print_flexi latex-tables openssh-privkey openssl-enc sizes timing)
|
||||
list(JOIN USABLE_DEMOS " " USABLE_DEMOS_STR)
|
||||
option(BUILD_USABLE_DEMOS "Build usable demos (${USABLE_DEMOS_STR})" FALSE)
|
||||
|
||||
if(BUILD_USABLE_DEMOS)
|
||||
list(APPEND USABLE_DEMOS_TARGETS ${USABLE_DEMOS})
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Test demos
|
||||
#
|
||||
# Demos that are used for testing or measuring
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
set(TEST_DEMOS small tv_gen)
|
||||
list(JOIN TEST_DEMOS " " TEST_DEMOS_STR)
|
||||
option(BUILD_TEST_DEMOS "Build test demos (${TEST_DEMOS_STR})" FALSE)
|
||||
|
||||
if(BUILD_TEST_DEMOS)
|
||||
list(APPEND ALL_DEMOS_TARGETS ${TEST_DEMOS})
|
||||
endif()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Generate executables
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# USABLE_DEMOS can get installed, so they're prefixed with `ltc-`
|
||||
foreach(target ${USABLE_DEMOS_TARGETS})
|
||||
list(APPEND ALL_DEMOS_INSTALL_TARGETS ltc-${target})
|
||||
|
||||
add_executable(ltc-${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
|
||||
|
||||
target_link_libraries(ltc-${target} PRIVATE ${PROJECT_NAME})
|
||||
endforeach()
|
||||
|
||||
foreach(target ${ALL_DEMOS_TARGETS})
|
||||
add_executable(${target} ${CMAKE_CURRENT_SOURCE_DIR}/${target}.c)
|
||||
|
||||
target_link_libraries(${target} PRIVATE ${PROJECT_NAME})
|
||||
endforeach()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Install targets
|
||||
# -----------------------------------------------------------------------------
|
||||
if(INSTALL_DEMOS)
|
||||
install(
|
||||
TARGETS ${ALL_DEMOS_INSTALL_TARGETS}
|
||||
COMPONENT "runtime"
|
||||
EXPORT ${TARGETS_EXPORT_NAME}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
# Also install the `ltc` wrapper script
|
||||
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/ltc DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
140
demos/aesgcm.c
140
demos/aesgcm.c
|
|
@ -1,140 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/**
|
||||
@file aesgcm.c
|
||||
AES128-GCM demo - file en-&decryption, Steffen Jaeckel
|
||||
Uses the format: |ciphertext|tag-16-bytes|
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <tomcrypt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef LTC_GCM_MODE
|
||||
int main(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
|
||||
#include "gcm-file/gcm_filehandle.c"
|
||||
#include "gcm-file/gcm_file.c"
|
||||
|
||||
|
||||
static off_t fsize(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(filename, &st) == 0) return st.st_size;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(__linux__) && defined(__GLIBC_PREREQ)
|
||||
#if __GLIBC_PREREQ(2, 14)
|
||||
#define HAS_SYNCFS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int mv(const char *old_name, const char *new_name)
|
||||
{
|
||||
int fd;
|
||||
if (rename(old_name, new_name) == -1) return -1;
|
||||
fd = open(new_name, 0);
|
||||
if (fd == -1) return -1;
|
||||
#if !defined(_WIN32)
|
||||
if (fsync(fd) != 0) goto OUT;
|
||||
#if defined(HAS_SYNCFS)
|
||||
syncfs(fd);
|
||||
#else
|
||||
sync();
|
||||
#endif
|
||||
OUT:
|
||||
#endif
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void LTC_NORETURN die(int ret)
|
||||
{
|
||||
fprintf(stderr, "Usage: aesgcm <-e|-d> <infile> <outfile> <88|96 char hex-string 'IV | key'>\n");
|
||||
exit(ret);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = 0, err, arg, direction, res, tmp;
|
||||
size_t keylen;
|
||||
uint8_t keybuf[48] = {0};
|
||||
char *out = NULL;
|
||||
const char *mode, *in_file, *out_file, *key_string;
|
||||
unsigned long ivlen, key_len;
|
||||
|
||||
if (argc < 5) {
|
||||
if (argc > 1 && strstr(argv[1], "-h"))
|
||||
die(0);
|
||||
else
|
||||
die(__LINE__);
|
||||
}
|
||||
|
||||
arg = 1;
|
||||
mode = argv[arg++];
|
||||
in_file = argv[arg++];
|
||||
out_file = argv[arg++];
|
||||
key_string = argv[arg++];
|
||||
|
||||
if(strcmp(mode, "-d") == 0) direction = GCM_DECRYPT;
|
||||
else if(strcmp(mode, "-e") == 0) direction = GCM_ENCRYPT;
|
||||
else die(__LINE__);
|
||||
|
||||
if (fsize(in_file) <= 0) die(__LINE__);
|
||||
|
||||
keylen = XSTRLEN(key_string);
|
||||
if (keylen != 88 && keylen != 96) die(__LINE__);
|
||||
|
||||
key_len = sizeof(keybuf);
|
||||
if ((err = base16_decode(key_string, keylen, keybuf, &key_len)) != CRYPT_OK) {
|
||||
fprintf(stderr, "boooh %s\n", error_to_string(err));
|
||||
die(__LINE__);
|
||||
}
|
||||
|
||||
register_all_ciphers();
|
||||
|
||||
if(asprintf(&out, "%s-XXXXXX", out_file) < 0) die(__LINE__);
|
||||
if((tmp = mkstemp(out)) == -1) {
|
||||
ret = __LINE__;
|
||||
goto cleanup;
|
||||
}
|
||||
close(tmp);
|
||||
ivlen = keylen/2 - 32;
|
||||
if((err = gcm_file(find_cipher("aes"), &keybuf[ivlen], 32, keybuf, ivlen, NULL, 0, in_file, out, 16, direction, &res)) != CRYPT_OK) {
|
||||
fprintf(stderr, "boooh %s\n", error_to_string(err));
|
||||
ret = __LINE__;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(res != 1) {
|
||||
ret = __LINE__;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mv(out, out_file) != 0) ret = __LINE__;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if(ret != 0) unlink(out);
|
||||
free(out);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L /* otherwise PATH_MAX + strdup are not defined for build with -std=c99 */
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#include <string.h>
|
||||
#define basename(path) ( strrchr((path), '/') ? strrchr((path), '/') + 1 : strrchr((path), '\\') ? strrchr((path), '\\') + 1 : (path) )
|
||||
|
||||
/**
|
||||
@file demo_crypt_constants.c
|
||||
|
||||
Demo how to get various constants to dynamic languages
|
||||
like Python
|
||||
|
||||
Larry Bugbee, February 2013
|
||||
*/
|
||||
|
||||
static void s_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);
|
||||
s_print_line("<no argument>", "The old behavior of the demo");
|
||||
s_print_line("-a", "Only lists all constants");
|
||||
s_print_line("-s name", "List a single constant given as argument");
|
||||
s_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 */
|
||||
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("%s\n", names_list);
|
||||
free(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;
|
||||
}
|
||||
|
||||
|
|
@ -1,309 +0,0 @@
|
|||
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
# - - - - - - - - - - - - -
|
||||
# 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)))
|
||||
|
||||
class ChaCha(object):
|
||||
def __init__(self, key, rounds):
|
||||
self.state = c_buffer(_get_size(b'chacha_state'))
|
||||
self.counter = c_uint(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), 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 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
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
/* DER flexi-decode a certificate */
|
||||
#include "tomcrypt_private.h"
|
||||
#include <wchar.h>
|
||||
|
||||
#define ASN1_FMTSTRING_FMT "line: %d, type=%d, size=%lu, data=%p, self=%p, next=%p, prev=%p, parent=%p, child=%p"
|
||||
#define ASN1_FMTSTRING_VAL(l) __LINE__, (l)->type, (l)->size, (l)->data, (l), (l)->next, (l)->prev, (l)->parent, (l)->child
|
||||
|
||||
static void* s_xmalloc(int l)
|
||||
{
|
||||
void *r = XCALLOC(1, l);
|
||||
|
||||
#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 3
|
||||
fprintf(stderr, "ALLOC %9d to %p\n", l, r);
|
||||
#endif
|
||||
if (!r) {
|
||||
fprintf(stderr, "Could not allocate %d bytes of memory\n", l);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifndef S_FREE
|
||||
static void s_free(void *p)
|
||||
{
|
||||
#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 3
|
||||
fprintf(stderr, "FREE %p\n", p);
|
||||
#endif
|
||||
XFREE(p);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void s_der_print_flexi_i(const ltc_asn1_list* l, unsigned int level)
|
||||
{
|
||||
char *buf = NULL;
|
||||
const char *name = NULL;
|
||||
const char *text = NULL;
|
||||
ltc_asn1_list *ostring = NULL;
|
||||
unsigned int n;
|
||||
int slen;
|
||||
const wchar_t *wtmp;
|
||||
|
||||
switch (l->type)
|
||||
{
|
||||
case LTC_ASN1_EOL:
|
||||
name = "EOL";
|
||||
slen = snprintf(NULL, 0, ASN1_FMTSTRING_FMT "\n", ASN1_FMTSTRING_VAL(l));
|
||||
buf = s_xmalloc(slen);
|
||||
snprintf(buf, slen, ASN1_FMTSTRING_FMT "\n", ASN1_FMTSTRING_VAL(l));
|
||||
text = buf;
|
||||
break;
|
||||
case LTC_ASN1_BOOLEAN:
|
||||
name = "BOOLEAN";
|
||||
{
|
||||
if (*(int*) l->data)
|
||||
text = "true";
|
||||
else
|
||||
text = "false";
|
||||
}
|
||||
break;
|
||||
case LTC_ASN1_INTEGER:
|
||||
name = "INTEGER";
|
||||
buf = s_xmalloc(((ltc_mp_get_digit_count(l->data) + 1) * ltc_mp.bits_per_digit) / 3);
|
||||
ltc_mp_toradix(l->data, buf, 10);
|
||||
text = buf;
|
||||
break;
|
||||
case LTC_ASN1_SHORT_INTEGER:
|
||||
name = "SHORT INTEGER";
|
||||
break;
|
||||
case LTC_ASN1_BIT_STRING:
|
||||
name = "BIT STRING";
|
||||
if (l->size <= 16) {
|
||||
int r;
|
||||
int sz = l->size + 1;
|
||||
char *s = buf = s_xmalloc(sz);
|
||||
for (n = 0; n < l->size; ++n) {
|
||||
r = snprintf(s, sz, "%c", ((unsigned char*) l->data)[n] ? '1' : '0');
|
||||
if (r < 0 || r >= sz) {
|
||||
fprintf(stderr, "%s boom\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
s += r;
|
||||
sz -= r;
|
||||
}
|
||||
} else {
|
||||
slen = snprintf(NULL, 0, "Length %lu", l->size);
|
||||
buf = s_xmalloc(slen);
|
||||
snprintf(buf, slen, "Length %lu", l->size);
|
||||
}
|
||||
text = buf;
|
||||
break;
|
||||
case LTC_ASN1_OCTET_STRING:
|
||||
name = "OCTET STRING";
|
||||
{
|
||||
unsigned long ostring_l = l->size;
|
||||
/* sometimes there's another sequence in an octet string...
|
||||
* try to decode that... if it fails print out the octet string
|
||||
*/
|
||||
if (der_decode_sequence_flexi(l->data, &ostring_l, &ostring) == CRYPT_OK) {
|
||||
text = "";
|
||||
} else {
|
||||
int r;
|
||||
int sz = l->size * 2 + 1;
|
||||
char *s = buf = s_xmalloc(sz);
|
||||
for (n = 0; n < l->size; ++n) {
|
||||
r = snprintf(s, sz, "%02X", ((unsigned char*) l->data)[n]);
|
||||
if (r < 0 || r >= sz) {
|
||||
fprintf(stderr, "%s boom\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
s += r;
|
||||
sz -= r;
|
||||
}
|
||||
text = buf;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LTC_ASN1_NULL:
|
||||
name = "NULL";
|
||||
text = "";
|
||||
break;
|
||||
case LTC_ASN1_OBJECT_IDENTIFIER:
|
||||
name = "OBJECT IDENTIFIER";
|
||||
{
|
||||
unsigned long len = 0;
|
||||
if (pk_oid_num_to_str(l->data, l->size, buf, &len) != CRYPT_BUFFER_OVERFLOW) {
|
||||
fprintf(stderr, "%s WTF\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
buf = s_xmalloc(len);
|
||||
if (pk_oid_num_to_str(l->data, l->size, buf, &len) != CRYPT_OK) {
|
||||
fprintf(stderr, "%s boom\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
text = buf;
|
||||
}
|
||||
break;
|
||||
case LTC_ASN1_IA5_STRING:
|
||||
name = "IA5 STRING";
|
||||
text = l->data;
|
||||
break;
|
||||
case LTC_ASN1_PRINTABLE_STRING:
|
||||
name = "PRINTABLE STRING";
|
||||
text = l->data;
|
||||
break;
|
||||
case LTC_ASN1_UTF8_STRING:
|
||||
name = "UTF8 STRING";
|
||||
wtmp = l->data;
|
||||
slen = wcsrtombs(NULL, &wtmp, 0, NULL);
|
||||
if (slen != -1) {
|
||||
slen++;
|
||||
buf = s_xmalloc(slen);
|
||||
if (wcsrtombs(buf, &wtmp, slen, NULL) == (size_t)-1) {
|
||||
fprintf(stderr, "%s boom\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
text = buf;
|
||||
}
|
||||
break;
|
||||
case LTC_ASN1_UTCTIME:
|
||||
name = "UTCTIME";
|
||||
{
|
||||
ltc_utctime *ut = l->data;
|
||||
slen = 32;
|
||||
buf = s_xmalloc(slen);
|
||||
snprintf(buf, slen, "%02d-%02d-%02d %02d:%02d:%02d %c%02d:%02d", ut->YY, ut->MM, ut->DD, ut->hh, ut->mm,
|
||||
ut->ss, ut->off_dir ? '-' : '+', ut->off_hh, ut->off_mm);
|
||||
text = buf;
|
||||
}
|
||||
break;
|
||||
case LTC_ASN1_GENERALIZEDTIME:
|
||||
name = "GENERALIZED TIME";
|
||||
{
|
||||
ltc_generalizedtime *gt = l->data;
|
||||
slen = 32;
|
||||
buf = s_xmalloc(slen);
|
||||
if (gt->fs)
|
||||
snprintf(buf, slen, "%04d-%02d-%02d %02d:%02d:%02d.%02dZ", gt->YYYY, gt->MM, gt->DD, gt->hh, gt->mm,
|
||||
gt->ss, gt->fs);
|
||||
else
|
||||
snprintf(buf, slen, "%04d-%02d-%02d %02d:%02d:%02dZ", gt->YYYY, gt->MM, gt->DD, gt->hh, gt->mm, gt->ss);
|
||||
text = buf;
|
||||
}
|
||||
break;
|
||||
case LTC_ASN1_CHOICE:
|
||||
name = "CHOICE";
|
||||
break;
|
||||
case LTC_ASN1_SEQUENCE:
|
||||
name = "SEQUENCE";
|
||||
text = "";
|
||||
break;
|
||||
case LTC_ASN1_SET:
|
||||
name = "SET";
|
||||
text = "";
|
||||
break;
|
||||
case LTC_ASN1_SETOF:
|
||||
name = "SETOF";
|
||||
text = "";
|
||||
break;
|
||||
case LTC_ASN1_RAW_BIT_STRING:
|
||||
name = "RAW BIT STRING";
|
||||
break;
|
||||
case LTC_ASN1_TELETEX_STRING:
|
||||
name = "TELETEX STRING";
|
||||
text = l->data;
|
||||
break;
|
||||
case LTC_ASN1_CUSTOM_TYPE:
|
||||
name = "NON STANDARD";
|
||||
{
|
||||
int r;
|
||||
int sz = 128;
|
||||
char *s = buf = s_xmalloc(sz);
|
||||
|
||||
r = snprintf(s, sz, "[%s %s %llu]", der_asn1_class_to_string_map[l->klass],
|
||||
der_asn1_pc_to_string_map[l->pc], l->tag);
|
||||
if (r < 0 || r >= sz) {
|
||||
fprintf(stderr, "%s boom\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
text = buf;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (n = 0; n < level; ++n) {
|
||||
fprintf(stderr, " ");
|
||||
}
|
||||
if (name) {
|
||||
if (text)
|
||||
fprintf(stderr, "%s %s\n", name, text);
|
||||
else
|
||||
fprintf(stderr, "%s <missing decoding>\n", name);
|
||||
} else
|
||||
fprintf(stderr, "WTF type=%i\n", l->type);
|
||||
|
||||
if (buf) {
|
||||
s_free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
|
||||
if (ostring) {
|
||||
s_der_print_flexi_i(ostring, level + 1);
|
||||
der_free_sequence_flexi(ostring);
|
||||
}
|
||||
|
||||
if (l->child) s_der_print_flexi_i(l->child, level + 1);
|
||||
|
||||
if (l->next) s_der_print_flexi_i(l->next, level);
|
||||
}
|
||||
|
||||
#ifndef LTC_DER_PRINT_FLEXI_NO_MAIN
|
||||
|
||||
static void s_der_print_flexi(const ltc_asn1_list* l)
|
||||
{
|
||||
fprintf(stderr, "\n\n");
|
||||
s_der_print_flexi_i(l, 0);
|
||||
fprintf(stderr, "\n\n");
|
||||
}
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int fd;
|
||||
static ltc_asn1_list *l;
|
||||
|
||||
static void print_err(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void die_(int err, int line)
|
||||
{
|
||||
print_err("%3d: LTC sez %s\n", line, error_to_string(err));
|
||||
der_free_sequence_flexi(l);
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#define die(i) do { die_(i, __LINE__); } while(0)
|
||||
#define DIE(s, ...) do { print_err("%3d: " s "\n", __LINE__, ##__VA_ARGS__); exit(EXIT_FAILURE); } while(0)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *addr;
|
||||
int err, argn = 1;
|
||||
struct stat sb;
|
||||
unsigned long len;
|
||||
|
||||
if ((err = register_all_hashes()) != CRYPT_OK) {
|
||||
die(err);
|
||||
}
|
||||
if ((err = crypt_mp_init("ltm")) != CRYPT_OK) {
|
||||
die(err);
|
||||
}
|
||||
if (argc > argn) fd = open(argv[argn], O_RDONLY);
|
||||
else fd = STDIN_FILENO;
|
||||
if (fd == -1) DIE("open sez no");
|
||||
if (fstat(fd, &sb) == -1) DIE("fstat");
|
||||
|
||||
addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (addr == MAP_FAILED) DIE("mmap");
|
||||
|
||||
len = sb.st_size;
|
||||
|
||||
if ((err = der_decode_sequence_flexi(addr, &len, &l)) != CRYPT_OK) {
|
||||
die(err);
|
||||
}
|
||||
|
||||
s_der_print_flexi(l);
|
||||
|
||||
der_free_sequence_flexi(l);
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* LTC_DER_PRINT_FLEXI_NO_MAIN */
|
||||
|
|
@ -1,6 +1,3 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* 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> */
|
||||
|
|
@ -10,34 +7,86 @@
|
|||
/* ie: ./encrypt blowfish story.txt story.ct */
|
||||
/* ./encrypt -d blowfish story.ct story.pt */
|
||||
|
||||
#include <tomcrypt.h>
|
||||
#include <mycrypt.h>
|
||||
|
||||
static int LTC_NORETURN die(int status)
|
||||
int errno;
|
||||
|
||||
int usage(char *name)
|
||||
{
|
||||
int x, w, tot = 0;
|
||||
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
|
||||
fprintf(o,
|
||||
"Usage encrypt: crypt <cipher> <infile> <outfile>\n"
|
||||
"Usage decrypt: crypt -d <cipher> <infile> <outfile>\n"
|
||||
"Usage test: crypt -t <cipher>\n"
|
||||
"This help: crypt -h\n\nCiphers:\n\t");
|
||||
int x;
|
||||
|
||||
printf("Usage: %s [-d](ecrypt) cipher infile outfile\nCiphers:\n", name);
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
w = fprintf(o, "%-14s",cipher_descriptor[x].name);
|
||||
if (w < 0) {
|
||||
status = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
tot += w;
|
||||
if (tot >= 70) {
|
||||
fprintf(o, "\n\t");
|
||||
tot = 0;
|
||||
}
|
||||
printf("%s\n",cipher_descriptor[x].name);
|
||||
}
|
||||
if (tot != 0) fprintf(o, "\n");
|
||||
exit(status);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
void register_algs(void)
|
||||
{
|
||||
int x;
|
||||
|
||||
#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
|
||||
|
||||
if (register_hash(&sha256_desc) == -1) {
|
||||
printf("Error registering SHA256\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (register_prng(&yarrow_desc) == -1) {
|
||||
printf("Error registering yarrow PRNG\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (register_prng(&sprng_desc) == -1) {
|
||||
printf("Error registering sprng PRNG\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned char plaintext[512],ciphertext[512];
|
||||
unsigned char tmpkey[512], key[MAXBLOCKSIZE], IV[MAXBLOCKSIZE];
|
||||
|
|
@ -48,36 +97,12 @@ int main(int argc, char *argv[])
|
|||
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();
|
||||
register_algs();
|
||||
|
||||
if (argc < 4) {
|
||||
if ((argc > 2) && (!strcmp(argv[1], "-t"))) {
|
||||
cipher = argv[2];
|
||||
cipher_idx = find_cipher(cipher);
|
||||
if (cipher_idx == -1) {
|
||||
fprintf(stderr, "Invalid cipher %s entered on command line.\n", cipher);
|
||||
die(EXIT_FAILURE);
|
||||
} /* if */
|
||||
if (cipher_descriptor[cipher_idx].test) {
|
||||
if (cipher_descriptor[cipher_idx].test() != CRYPT_OK) {
|
||||
fprintf(stderr, "Error when testing cipher %s.\n", cipher);
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
else {
|
||||
printf("Testing cipher %s succeeded.\n", cipher);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Cipher %s has no tests.\n", cipher);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
return die(argc > 1 && strstr(argv[1], "-h") != NULL ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
return usage(argv[0]);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "-d")) {
|
||||
|
|
@ -90,7 +115,7 @@ int main(int argc, char *argv[])
|
|||
cipher = argv[1];
|
||||
infile = argv[2];
|
||||
outfile = argv[3];
|
||||
}
|
||||
}
|
||||
|
||||
/* file handles setup */
|
||||
fdin = fopen(infile,"rb");
|
||||
|
|
@ -100,11 +125,11 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
fdout = fopen(outfile,"wb");
|
||||
if (fdout == NULL) {
|
||||
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");
|
||||
|
|
@ -113,35 +138,34 @@ int main(int argc, char *argv[])
|
|||
|
||||
hash_idx = find_hash("sha256");
|
||||
if (hash_idx == -1) {
|
||||
printf("LTC_SHA256 not found...?\n");
|
||||
printf("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) {
|
||||
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);
|
||||
fgets((char *)tmpkey,sizeof(tmpkey), stdin);
|
||||
outlen = sizeof(key);
|
||||
if ((err = hash_memory(hash_idx,tmpkey,XSTRLEN((char *)tmpkey),key,&outlen)) != CRYPT_OK) {
|
||||
printf("Error hashing key: %s\n", error_to_string(err));
|
||||
if ((errno = hash_memory(hash_idx,tmpkey,strlen((char *)tmpkey),key,&outlen)) != CRYPT_OK) {
|
||||
printf("Error hashing key: %s\n", error_to_string(errno));
|
||||
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));
|
||||
|
||||
if ((errno = ctr_start(cipher_idx,IV,key,ks,0,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_start error: %s\n",error_to_string(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
|
@ -149,8 +173,8 @@ int main(int argc, char *argv[])
|
|||
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));
|
||||
if ((errno = ctr_decrypt(inbuf,plaintext,y,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_decrypt error: %s\n", error_to_string(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
|
@ -164,10 +188,10 @@ int main(int argc, char *argv[])
|
|||
|
||||
} 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));
|
||||
}
|
||||
|
||||
if ((errno = rng_make_prng(128, find_prng("yarrow"), &prng, NULL)) != CRYPT_OK) {
|
||||
printf("Error setting up PRNG, %s\n", error_to_string(errno));
|
||||
}
|
||||
|
||||
/* You can use rng_get_bytes on platforms that support it */
|
||||
/* x = rng_get_bytes(IV,ivsize,NULL);*/
|
||||
|
|
@ -176,22 +200,22 @@ int main(int argc, char *argv[])
|
|||
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));
|
||||
if ((errno = ctr_start(cipher_idx,IV,key,ks,0,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_start error: %s\n",error_to_string(errno));
|
||||
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));
|
||||
if ((errno = ctr_encrypt(inbuf,ciphertext,y,&ctr)) != CRYPT_OK) {
|
||||
printf("ctr_encrypt error: %s\n", error_to_string(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +223,7 @@ int main(int argc, char *argv[])
|
|||
printf("Error writing to output.\n");
|
||||
exit(-1);
|
||||
}
|
||||
} while (y == sizeof(inbuf));
|
||||
} while (y == sizeof(inbuf));
|
||||
fclose(fdout);
|
||||
fclose(fdin);
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file gcm_file.c
|
||||
GCM process a file, Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#ifdef LTC_GCM_MODE
|
||||
#ifndef LTC_NO_FILE
|
||||
|
||||
/**
|
||||
Process a file.
|
||||
|
||||
c.f. gcm_filehandle() for basic documentation.
|
||||
|
||||
It is possible, that in error-cases the 'out' file
|
||||
will be created and after the error occurred it will
|
||||
be removed again.
|
||||
|
||||
@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 in The input file
|
||||
@param out The output file
|
||||
@param taglen The MAC tag length
|
||||
@param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
|
||||
@param res [out] Result of the operation, 1==valid, 0==invalid
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
static int gcm_file(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *IV, unsigned long IVlen,
|
||||
const unsigned char *adata, unsigned long adatalen,
|
||||
const char *in,
|
||||
const char *out,
|
||||
unsigned long taglen,
|
||||
int direction,
|
||||
int *res)
|
||||
{
|
||||
int err;
|
||||
FILE *f_in = NULL, *f_out = NULL;
|
||||
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(res != NULL);
|
||||
|
||||
*res = 0;
|
||||
|
||||
f_in = fopen(in, "rb");
|
||||
if (f_in == NULL) {
|
||||
err = CRYPT_FILE_NOTFOUND;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
f_out = fopen(out, "w+b");
|
||||
if (f_out == NULL) {
|
||||
err = CRYPT_FILE_NOTFOUND;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
err = gcm_filehandle(cipher, key, keylen, IV, IVlen, adata, adatalen, f_in, f_out, taglen, direction, res);
|
||||
|
||||
LBL_ERR:
|
||||
if (f_out != NULL && fclose(f_out) != 0) {
|
||||
err = CRYPT_ERROR;
|
||||
}
|
||||
if (*res != 1) {
|
||||
remove(out);
|
||||
}
|
||||
if (f_in != NULL && fclose(f_in) != 0) {
|
||||
err = CRYPT_ERROR;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -1,194 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file gcm_filehandle.c
|
||||
GCM process a filehandle, Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#ifdef LTC_GCM_MODE
|
||||
#ifndef LTC_NO_FILE
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ftruncate _chsize
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
Process a filehandle.
|
||||
|
||||
This uses the widely established scheme where the tag is appended
|
||||
to the ciphertext.
|
||||
|
||||
encrypted_file = aesgcm(plain_file) | aesgcm_tag(plain_file)
|
||||
|
||||
Depending on 'direction' this function does:
|
||||
|
||||
Encrypt file 'in' to 'out' and append the tag of length 'taglen'
|
||||
to 'out'.
|
||||
|
||||
or
|
||||
|
||||
Decrypt file 'in' to 'out' and check the tag of length 'taglen'
|
||||
and strip the tag from 'in'.
|
||||
|
||||
In error-cases 'out' will be zeroed out first and then truncated to
|
||||
a length of 0.
|
||||
|
||||
@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 in The input file
|
||||
@param out The output file
|
||||
@param taglen The MAC tag length
|
||||
@param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
|
||||
@param res [out] Result of the operation, 1==valid, 0==invalid
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
static int gcm_filehandle(int cipher,
|
||||
const unsigned char *key, unsigned long keylen,
|
||||
const unsigned char *IV, unsigned long IVlen,
|
||||
const unsigned char *adata, unsigned long adatalen,
|
||||
FILE *in,
|
||||
FILE *out,
|
||||
unsigned long taglen,
|
||||
int direction,
|
||||
int *res)
|
||||
{
|
||||
void *orig;
|
||||
gcm_state *gcm;
|
||||
int err;
|
||||
unsigned char *buf, tag[16];
|
||||
size_t x, tot_data;
|
||||
unsigned long tag_len;
|
||||
|
||||
LTC_ARGCHK(in != NULL);
|
||||
LTC_ARGCHK(out != NULL);
|
||||
LTC_ARGCHK(res != NULL);
|
||||
|
||||
*res = 0;
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifndef LTC_GCM_TABLES_SSE2
|
||||
orig = gcm = XMALLOC(sizeof(*gcm));
|
||||
#else
|
||||
orig = gcm = XMALLOC(sizeof(*gcm) + 16);
|
||||
#endif
|
||||
if (gcm == NULL) {
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
if ((buf = XMALLOC(LTC_FILE_READ_BUFSIZE)) == NULL) {
|
||||
XFREE(gcm);
|
||||
return CRYPT_MEM;
|
||||
}
|
||||
|
||||
/* Force GCM to be on a multiple of 16 so we can use 128-bit aligned operations
|
||||
* note that we only modify gcm and keep orig intact. This code is not portable
|
||||
* but again it's only for SSE2 anyways, so who cares?
|
||||
*/
|
||||
#ifdef LTC_GCM_TABLES_SSE2
|
||||
gcm = LTC_ALIGN_BUF(gcm, 16);
|
||||
#endif
|
||||
|
||||
if ((err = gcm_init(gcm, cipher, key, keylen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = gcm_add_iv(gcm, IV, IVlen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = gcm_add_aad(gcm, adata, adatalen)) != CRYPT_OK) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
tot_data = ftell(in);
|
||||
if (direction == GCM_DECRYPT) {
|
||||
tot_data -= taglen;
|
||||
}
|
||||
fseek(in, 0, SEEK_SET);
|
||||
do {
|
||||
x = MIN(tot_data, LTC_FILE_READ_BUFSIZE);
|
||||
x = fread(buf, 1, x, in);
|
||||
tot_data -= x;
|
||||
if ((err = gcm_process(gcm, buf, (unsigned long)x, buf, direction)) != CRYPT_OK) {
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
if(fwrite(buf, 1, x, out) != x) {
|
||||
err = CRYPT_ERROR;
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
} while (x == LTC_FILE_READ_BUFSIZE);
|
||||
|
||||
tag_len = taglen;
|
||||
if ((err = gcm_done(gcm, tag, &tag_len)) != CRYPT_OK) {
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
if (tag_len != taglen) {
|
||||
err = CRYPT_ERROR;
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
|
||||
if (direction == GCM_DECRYPT) {
|
||||
if (feof(in) || ferror(in)) {
|
||||
err = CRYPT_ERROR;
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
x = fread(buf, 1, taglen, in);
|
||||
if (x != taglen) {
|
||||
err = CRYPT_ERROR;
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
|
||||
if (XMEM_NEQ(buf, tag, taglen) == 0) {
|
||||
*res = 1;
|
||||
}
|
||||
} else {
|
||||
if(fwrite(tag, 1, taglen, out) != taglen) {
|
||||
err = CRYPT_ERROR;
|
||||
goto LBL_CLEANBUF;
|
||||
}
|
||||
*res = 1;
|
||||
}
|
||||
|
||||
LBL_CLEANBUF:
|
||||
zeromem(buf, LTC_FILE_READ_BUFSIZE);
|
||||
zeromem(tag, sizeof(tag));
|
||||
LBL_ERR:
|
||||
#ifdef LTC_CLEAN_STACK
|
||||
#ifndef LTC_GCM_TABLES_SSE2
|
||||
zeromem(orig, sizeof(*gcm));
|
||||
#else
|
||||
zeromem(orig, sizeof(*gcm) + 16);
|
||||
#endif
|
||||
#endif
|
||||
if(*res == 0) {
|
||||
x = ftell(out);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
while((size_t)ftell(out) < x) {
|
||||
fwrite(buf, 1, LTC_FILE_READ_BUFSIZE, out);
|
||||
}
|
||||
if(ftruncate(fileno(out), 0)) {
|
||||
/* well, what shall we do here... */
|
||||
}
|
||||
}
|
||||
fflush(out);
|
||||
|
||||
XFREE(buf);
|
||||
XFREE(orig);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
345
demos/hashsum.c
345
demos/hashsum.c
|
|
@ -1,6 +1,3 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
|
@ -10,288 +7,100 @@
|
|||
* more functions ;)
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L /* otherwise PATH_MAX + strdup are not defined for build with -std=c99 */
|
||||
#include <tomcrypt.h>
|
||||
#include <mycrypt_custom.h>
|
||||
|
||||
#include <string.h>
|
||||
#define basename(path) ( strrchr((path), '/') ? strrchr((path), '/') + 1 : strrchr((path), '\\') ? strrchr((path), '\\') + 1 : (path) )
|
||||
int errno;
|
||||
|
||||
#if !defined(PATH_MAX) && defined(_MSC_VER)
|
||||
#include <windows.h>
|
||||
#define PATH_MAX MAX_PATH
|
||||
#endif
|
||||
|
||||
/* thanks http://stackoverflow.com/a/8198009 */
|
||||
#define s_base(x) ((x >= '0' && x <= '9') ? '0' : \
|
||||
(x >= 'a' && x <= 'f') ? 'a' - 10 : \
|
||||
(x >= 'A' && x <= 'F') ? 'A' - 10 : \
|
||||
'\255')
|
||||
#define HEXOF(x) (x - s_base(x))
|
||||
|
||||
#ifndef LTC_ARRAY_SIZE
|
||||
#define LTC_ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||
#endif
|
||||
|
||||
static char* hashsum;
|
||||
|
||||
static void cleanup(void)
|
||||
{
|
||||
free(hashsum);
|
||||
}
|
||||
|
||||
static void die(int status)
|
||||
{
|
||||
unsigned long w, x;
|
||||
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
|
||||
fprintf(o,
|
||||
"Usage: %s [-a <algorithm>...] [-c|-h] [<file>...]\n\n"
|
||||
"\t-c\tCheck the hash(es) of the file(s) written in <file>.\n"
|
||||
"\t\tNote: -a is not required when checking the hash(es).\n"
|
||||
"\t-h\tThis help\n\n"
|
||||
"Examples:\n"
|
||||
"\t%s -a sha1 file > file.sha1sum\n"
|
||||
"\t%s -c file.sha1sum\n"
|
||||
"\t%s -a sha1 -a sha256 -a sha512-256 file > file.hashsum\n"
|
||||
"\t%s -c file.hashsum\n\n"
|
||||
"Algorithms:\n\t", hashsum, hashsum, hashsum, hashsum, hashsum);
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (w != 0) fprintf(o, "\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
static void printf_hex(unsigned char* hash_buffer, unsigned long w)
|
||||
{
|
||||
unsigned long x;
|
||||
for (x = 0; x < w; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
}
|
||||
}
|
||||
|
||||
static void check_file(int argn, int argc, char **argv)
|
||||
{
|
||||
int err, failed = 0, invalid = 0;
|
||||
unsigned char is_buffer[MAXBLOCKSIZE], should_buffer[MAXBLOCKSIZE];
|
||||
char buf[PATH_MAX + (MAXBLOCKSIZE * 3)];
|
||||
/* iterate through all files */
|
||||
while(argn < argc) {
|
||||
char* s;
|
||||
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);
|
||||
}
|
||||
/* read the file line by line */
|
||||
while((s = fgets(buf, sizeof(buf), f)) != NULL)
|
||||
{
|
||||
int tries, n;
|
||||
unsigned long hash_len, w, x;
|
||||
char* space = strstr(s, " ");
|
||||
|
||||
/* skip lines with comments */
|
||||
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++;
|
||||
}
|
||||
exit(failed == 0 && invalid == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
void register_algs();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int idxs[TAB_SIZE], idx, check, y, z, err, argn;
|
||||
unsigned long w, x;
|
||||
int idx, x, z;
|
||||
unsigned long w;
|
||||
unsigned char hash_buffer[MAXBLOCKSIZE];
|
||||
|
||||
hashsum = strdup(basename(argv[0]));
|
||||
atexit(cleanup);
|
||||
hash_state md;
|
||||
|
||||
/* You need to register algorithms before using them */
|
||||
register_all_ciphers();
|
||||
register_all_hashes();
|
||||
if (argc > 1 && strstr(argv[1], "-h")) {
|
||||
die(EXIT_SUCCESS);
|
||||
}
|
||||
if (argc < 3) {
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (x = 0; x < LTC_ARRAY_SIZE(idxs); ++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
|
||||
{ "1", sha1_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA224
|
||||
{ "224", sha224_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA256
|
||||
{ "256", sha256_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA384
|
||||
{ "384", sha384_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA512
|
||||
{ "512", sha512_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA512_224
|
||||
{ "512224", sha512_224_desc.name },
|
||||
#endif
|
||||
#ifdef LTC_SHA512_256
|
||||
{ "512256", sha512_256_desc.name },
|
||||
#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 >= LTC_ARRAY_SIZE(idxs)) {
|
||||
fprintf(stderr, "%s: Too many '-a' options chosen\n", hashsum);
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
argn++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
die(EXIT_FAILURE);
|
||||
}
|
||||
register_algs();
|
||||
if (argc < 2) {
|
||||
printf("usage: ./hash algorithm file [file ...]\n");
|
||||
printf("Algorithms:\n");
|
||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||
printf(" %s\n", hash_descriptor[x].name);
|
||||
}
|
||||
if(strcmp("-c", argv[argn]) == 0) {
|
||||
check = 1;
|
||||
argn++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (check == 1) {
|
||||
check_file(argn, argc, argv);
|
||||
idx = find_hash(argv[1]);
|
||||
if (idx == -1) {
|
||||
fprintf(stderr, "\nInvalid hash specified on command line.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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");
|
||||
if (argc == 2) {
|
||||
hash_descriptor[idx].init(&md);
|
||||
do {
|
||||
x = fread(hash_buffer, 1, sizeof(hash_buffer), stdin);
|
||||
hash_descriptor[idx].process(&md, hash_buffer, x);
|
||||
} while (x == sizeof(hash_buffer));
|
||||
hash_descriptor[idx].done(&md, hash_buffer);
|
||||
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
}
|
||||
printf(" (stdin)\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]);
|
||||
}
|
||||
for (z = 2; z < argc; z++) {
|
||||
w = sizeof(hash_buffer);
|
||||
if ((errno = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) {
|
||||
printf("File hash error: %s\n", error_to_string(errno));
|
||||
} else {
|
||||
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) {
|
||||
printf("%02x",hash_buffer[x]);
|
||||
}
|
||||
printf(" %s\n", argv[z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void register_algs(void)
|
||||
{
|
||||
#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
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,349 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
/* print all PEM related infos */
|
||||
#include "tomcrypt_private.h"
|
||||
|
||||
#if defined(LTC_PEM_SSH)
|
||||
static const struct {
|
||||
const char *is, *should;
|
||||
} cipher_name_map[] = {
|
||||
{ "", "none" },
|
||||
{ "aes", "AES" },
|
||||
{ "aria", "ARIA" },
|
||||
{ "blowfish", "Blowfish" },
|
||||
{ "c20p1305", "ChaCha20Poly1305" },
|
||||
{ "camellia", "Camellia" },
|
||||
{ "cast5", "CAST5" },
|
||||
{ "chacha20", "ChaCha20" },
|
||||
{ "3des", "3DES (EDE)" },
|
||||
{ "des", "DES" },
|
||||
{ "desx", "DES-X" },
|
||||
{ "idea", "IDEA" },
|
||||
{ "rc5", "RC5" },
|
||||
{ "rc2", "RC2" },
|
||||
{ "seed", "SEED" },
|
||||
{ "serpent", "Serpent" },
|
||||
{ "twofish", "Twofish" },
|
||||
};
|
||||
|
||||
static const char *s_map_cipher(const char *name)
|
||||
{
|
||||
unsigned long n;
|
||||
for (n = 0; n < LTC_ARRAY_SIZE(cipher_name_map); ++n) {
|
||||
if (strcmp(name, cipher_name_map[n].is) == 0)
|
||||
return cipher_name_map[n].should;
|
||||
}
|
||||
fprintf(stderr, "Error: Can't map %s\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static const struct {
|
||||
enum cipher_mode mode;
|
||||
const char *name;
|
||||
} cipher_mode_map[] = {
|
||||
{ cm_none, "none", },
|
||||
{ cm_cbc, "CBC", },
|
||||
{ cm_cfb, "CFB", },
|
||||
{ cm_cfb1, "CFB1", },
|
||||
{ cm_cfb8, "CFB8", },
|
||||
{ cm_ctr, "CTR", },
|
||||
{ cm_ofb, "OFB", },
|
||||
{ cm_stream, "STREAM", },
|
||||
{ cm_gcm, "GCM", },
|
||||
};
|
||||
|
||||
static const char *s_map_mode(enum cipher_mode mode)
|
||||
{
|
||||
size_t n;
|
||||
mode &= cm_modes | cm_1bit | cm_8bit;
|
||||
for (n = 0; n < LTC_ARRAY_SIZE(cipher_mode_map); ++n) {
|
||||
if (cipher_mode_map[n].mode == mode)
|
||||
return cipher_mode_map[n].name;
|
||||
}
|
||||
fprintf(stderr, "Error: Can't map cipher_mode %d\n", mode);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int print_pem_ciphers(void)
|
||||
{
|
||||
unsigned long n;
|
||||
printf("\nPEM ciphers:\n\n");
|
||||
for (n = 0; n < pem_dek_infos_num; ++n) {
|
||||
char nbuf[32] = {0};
|
||||
size_t nlen = strlen(pem_dek_infos[n].name);
|
||||
memcpy(nbuf, pem_dek_infos[n].name, nlen);
|
||||
nbuf[nlen-1] = '}';
|
||||
printf("\\hline \\texttt{%-18s & %-15s & %-25ld & %-6s \\\\\n",
|
||||
nbuf, s_map_cipher(pem_dek_infos[n].algo),
|
||||
pem_dek_infos[n].keylen * 8,
|
||||
s_map_mode(pem_dek_infos[n].mode));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_ssh_ciphers(void)
|
||||
{
|
||||
unsigned long n;
|
||||
printf("\nSSH ciphers:\n\n");
|
||||
for (n = 0; n < ssh_ciphers_num; ++n) {
|
||||
char nbuf[32] = {0};
|
||||
size_t nlen = strlen(ssh_ciphers[n].name);
|
||||
memcpy(nbuf, ssh_ciphers[n].name, nlen);
|
||||
nbuf[nlen] = '}';
|
||||
printf("\\hline \\texttt{%-30s & %-16s & %-24ld & %-6s \\\\\n",
|
||||
nbuf, s_map_cipher(ssh_ciphers[n].algo),
|
||||
ssh_ciphers[n].keylen * 8,
|
||||
s_map_mode(ssh_ciphers[n].mode));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s_to_lower(const char *in, char *out, unsigned long *outlen)
|
||||
{
|
||||
unsigned long n;
|
||||
for (n = 0; n < *outlen && in[n]; ++n) {
|
||||
out[n] = tolower(in[n]);
|
||||
}
|
||||
if (n == *outlen)
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
out[n] = '\0';
|
||||
*outlen = n;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int print_ecc_curves(void)
|
||||
{
|
||||
unsigned long n;
|
||||
printf("\nECC curves:\n\n");
|
||||
for (n = 0; ltc_ecc_curves[n].OID != NULL; ++n) {
|
||||
const char * const *names;
|
||||
char lower[32] = {0}, buf[64] = {0};
|
||||
unsigned long m, bufl = 0, lowerl;
|
||||
int err = ecc_get_curve_names(ltc_ecc_curves[n].OID, &names);
|
||||
if (err != CRYPT_OK) {
|
||||
printf("\\error: OID %s not found (%s)\n", ltc_ecc_curves[n].OID, error_to_string(err));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (m = 1; names[m]; ++m) {
|
||||
const char *name = names[m];
|
||||
if (memcmp(name, "P-", 2) == 0 || memcmp(name, "ECC-", 4) == 0) {
|
||||
/* Use the original name */
|
||||
} else {
|
||||
lowerl = sizeof(lower);
|
||||
if ((err = s_to_lower(name, lower, &lowerl)) != CRYPT_OK) {
|
||||
printf("\\error: %s could not be converted to lowercase (%s)\n", name, error_to_string(err));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
name = lower;
|
||||
}
|
||||
if (m == 1) {
|
||||
err = snprintf(buf + bufl, sizeof(buf) - bufl, "%s", name);
|
||||
} else {
|
||||
err = snprintf(buf + bufl, sizeof(buf) - bufl, ", %s", name);
|
||||
}
|
||||
if (err == -1 || (unsigned)err > sizeof(buf) - bufl) {
|
||||
printf("\\error: snprintf returned %d at %s\n", err, name);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
bufl += err;
|
||||
}
|
||||
lower[0] = '{';
|
||||
lowerl = sizeof(lower) - 2;
|
||||
if ((err = s_to_lower(names[0], &lower[1], &lowerl)) != CRYPT_OK) {
|
||||
printf("\\error: %s could not be converted to lowercase (%s)\n", names[0], error_to_string(err));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
lower[lowerl + 1] = '}';
|
||||
lower[lowerl + 2] = '\0';
|
||||
printf("\\hline \\texttt%-17s & %-36s & %-21s \\\\\n", lower, buf, ltc_ecc_curves[n].OID);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s_to_upper(const char *in, char *out, unsigned long *outlen)
|
||||
{
|
||||
unsigned long n;
|
||||
for (n = 0; n < *outlen && in[n]; ++n) {
|
||||
out[n] = toupper(in[n]);
|
||||
}
|
||||
if (n == *outlen)
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
out[n] = '\0';
|
||||
*outlen = n;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static int s_to_desc(const char *in, char *out, unsigned long outlen, int has_desc)
|
||||
{
|
||||
unsigned long n, m;
|
||||
if (outlen < 6) goto err_exit;
|
||||
XMEMCPY(out, "\\code{", 6);
|
||||
m = 6;
|
||||
for (n = 0; m < outlen - 1 && in[n]; ++n, ++m) {
|
||||
if (in[n] == '-' || in[n] == '_') {
|
||||
out[m++] = '\\';
|
||||
out[m] = '_';
|
||||
} else
|
||||
out[m] = tolower(in[n]);
|
||||
}
|
||||
if (outlen <= m) goto err_exit;
|
||||
if (!has_desc) {
|
||||
XMEMCPY(&out[m], "\\_desc", 6);
|
||||
m += 6;
|
||||
}
|
||||
out[m++] = '}';
|
||||
out[m] = '\0';
|
||||
return CRYPT_OK;
|
||||
err_exit:
|
||||
fprintf(stderr, "Error: Can't print descriptor %s\n", in);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct desc {
|
||||
void *orig;
|
||||
char desc[64];
|
||||
};
|
||||
|
||||
static int hash_sorter(const void *a, const void *b)
|
||||
{
|
||||
const struct ltc_hash_descriptor *A, *B;
|
||||
A = ((const struct desc*)a)->orig;
|
||||
B = ((const struct desc*)b)->orig;
|
||||
if (A->hashsize < B->hashsize) return 1;
|
||||
if (A->hashsize > B->hashsize) return -1;
|
||||
if (A->ID < B->ID) return -1;
|
||||
if (A->ID > B->ID) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_hash_line(const char *name, const struct ltc_hash_descriptor *p)
|
||||
{
|
||||
char nbuf[32];
|
||||
unsigned long nlen = sizeof(nbuf);
|
||||
s_to_upper(p->name, nbuf, &nlen);
|
||||
printf("\\hline %-17s & %-32s & %lu & %2d \\\\\n", nbuf, name, p->hashsize, p->ID);
|
||||
}
|
||||
|
||||
static int print_hash_descriptors(void)
|
||||
{
|
||||
const struct {
|
||||
const char *name;
|
||||
const struct ltc_hash_descriptor * desc;
|
||||
} special_hash_descriptors[] = {
|
||||
#define HASH_DESC(name) { #name, &name }
|
||||
HASH_DESC(sha256_portable_desc),
|
||||
#ifdef LTC_SHA256_X86
|
||||
HASH_DESC(sha256_x86_desc),
|
||||
#endif
|
||||
HASH_DESC(sha224_portable_desc),
|
||||
#ifdef LTC_SHA224_X86
|
||||
HASH_DESC(sha224_x86_desc),
|
||||
#endif
|
||||
HASH_DESC(sha1_portable_desc),
|
||||
#ifdef LTC_SHA1_X86
|
||||
HASH_DESC(sha1_x86_desc),
|
||||
#endif
|
||||
HASH_DESC(sha512_portable_desc),
|
||||
#ifdef LTC_SHA512_X86
|
||||
HASH_DESC(sha512_x86_desc),
|
||||
#endif
|
||||
HASH_DESC(sha384_portable_desc),
|
||||
#ifdef LTC_SHA384_X86
|
||||
HASH_DESC(sha384_x86_desc),
|
||||
#endif
|
||||
HASH_DESC(sha512_224_portable_desc),
|
||||
#ifdef LTC_SHA512_224_X86
|
||||
HASH_DESC(sha512_224_x86_desc),
|
||||
#endif
|
||||
HASH_DESC(sha512_256_portable_desc),
|
||||
#ifdef LTC_SHA512_256_X86
|
||||
HASH_DESC(sha512_256_x86_desc),
|
||||
#endif
|
||||
};
|
||||
struct desc descs[TAB_SIZE + 1] = {0};
|
||||
int ids[TAB_SIZE + 1] = {0};
|
||||
unsigned long n;
|
||||
|
||||
printf("\nhash descriptors:\n\n");
|
||||
register_all_hashes();
|
||||
|
||||
for (n = 0; hash_descriptor[n].name != NULL && n < TAB_SIZE; ++n) {
|
||||
if (hash_descriptor[n].ID > TAB_SIZE) {
|
||||
printf("Hash descriptor '%s' has invalid ID %d\n", hash_descriptor[n].name, hash_descriptor[n].ID);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (ids[hash_descriptor[n].ID] != 0) {
|
||||
printf("Hash descriptor '%s' has duplicate ID %d\n", hash_descriptor[n].name, hash_descriptor[n].ID);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ids[hash_descriptor[n].ID] = 1;
|
||||
descs[n].orig = &hash_descriptor[n];
|
||||
s_to_desc(hash_descriptor[n].name, descs[n].desc, sizeof(descs[n].desc), 0);
|
||||
}
|
||||
qsort(descs, n, sizeof(struct desc), &hash_sorter);
|
||||
for (n = 0; hash_descriptor[n].name != NULL && n < TAB_SIZE; ++n) {
|
||||
print_hash_line(descs[n].desc, descs[n].orig);
|
||||
}
|
||||
|
||||
printf("\nspecial hash descriptors:\n\n");
|
||||
for (n = 0; n < LTC_ARRAY_SIZE(special_hash_descriptors); ++n) {
|
||||
char nbuf[64];
|
||||
unsigned long nlen = sizeof(nbuf);
|
||||
s_to_desc(special_hash_descriptors[n].name, nbuf, nlen, 1);
|
||||
print_hash_line(nbuf, special_hash_descriptors[n].desc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void LTC_NORETURN die(int status)
|
||||
{
|
||||
FILE* o = status == EXIT_SUCCESS ? stdout : stderr;
|
||||
fprintf(o,
|
||||
"Usage: latex-tables [<-h|-l|type>]\n\n"
|
||||
"Generate LaTeX tables from some library internal data.\n\n"
|
||||
"\ttype\tThe type of table to print.\n"
|
||||
"\t-l\tList all built-in types that can be printed.\n"
|
||||
"\t-h\tThe help you're looking at.\n"
|
||||
);
|
||||
exit(status);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const struct {
|
||||
const char *name;
|
||||
int (*printer)(void);
|
||||
} printers[] = {
|
||||
#define PRINTER(name) { #name, print_ ## name }
|
||||
PRINTER(hash_descriptors),
|
||||
PRINTER(pem_ciphers),
|
||||
PRINTER(ssh_ciphers),
|
||||
PRINTER(ecc_curves),
|
||||
#undef PRINTER
|
||||
};
|
||||
int err;
|
||||
unsigned long n;
|
||||
if (argc > 1) {
|
||||
if (strstr(argv[1], "-h"))
|
||||
die(0);
|
||||
if (strstr(argv[1], "-l")) {
|
||||
for (n = 0; n < LTC_ARRAY_SIZE(printers); ++n) {
|
||||
printf("%s\n", printers[n].name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
printf("libtomcrypt latex tables\n");
|
||||
|
||||
for (n = 0; n < LTC_ARRAY_SIZE(printers); ++n) {
|
||||
if (argc > 1 && strstr(printers[n].name, argv[1]) == NULL)
|
||||
continue;
|
||||
if ((err = printers[n].printer()) != 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int main(void) { return EXIT_FAILURE; }
|
||||
#endif
|
||||
34
demos/ltc
34
demos/ltc
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
RELDIR="/$0"
|
||||
RELDIR="${RELDIR%/*}"
|
||||
RELDIR="${RELDIR:-.}"
|
||||
RELDIR="${RELDIR##/}/"
|
||||
|
||||
BINDIR=`cd "$RELDIR"; pwd`
|
||||
|
||||
err_out() {
|
||||
err=$1
|
||||
shift
|
||||
echo $* >&2
|
||||
exit $err
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat >&$(($1 + 1)) << EOF
|
||||
Available commands are:
|
||||
`ls -1 $BINDIR/ltc-* | sed "s@$BINDIR/ltc-@ @g"`
|
||||
help
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
[ $# -gt 0 ] || usage 1
|
||||
|
||||
TOOL="$1"
|
||||
shift
|
||||
[ "$TOOL" == "help" ] || [ "$TOOL" == "--help" ] || [ "$TOOL" == "-h" ] && usage 0
|
||||
|
||||
test -x "$BINDIR/ltc-$TOOL" || err_out 1 "Unknown command: $TOOL"
|
||||
|
||||
[ $# -gt 0 ] && "$BINDIR/ltc-$TOOL" "$@" || "$BINDIR/ltc-$TOOL"
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/**
|
||||
@file openssh-privkey.c
|
||||
OpenSSH Private Key decryption demo, Steffen Jaeckel
|
||||
*/
|
||||
|
||||
#include <tomcrypt.h>
|
||||
#include <stdarg.h>
|
||||
#include <termios.h>
|
||||
|
||||
#if defined(LTC_PEM_SSH)
|
||||
static void print_err(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void die_(int err, int line)
|
||||
{
|
||||
print_err("%3d: LTC sez %s\n", line, error_to_string(err));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#define die(i) do { die_(i, __LINE__); } while(0)
|
||||
#define DIE(s, ...) do { print_err("%3d: " s "\n", __LINE__, ##__VA_ARGS__); exit(EXIT_FAILURE); } while(0)
|
||||
|
||||
static char* getpassword(const char *prompt, size_t maxlen)
|
||||
{
|
||||
char *wr, *end, *pass = XCALLOC(1, maxlen + 1);
|
||||
struct termios tio;
|
||||
tcflag_t c_lflag;
|
||||
if (pass == NULL)
|
||||
return NULL;
|
||||
wr = pass;
|
||||
end = pass + maxlen;
|
||||
|
||||
tcgetattr(0, &tio);
|
||||
c_lflag = tio.c_lflag;
|
||||
tio.c_lflag &= ~ECHO;
|
||||
tcsetattr(0, TCSANOW, &tio);
|
||||
|
||||
printf("%s", prompt);
|
||||
fflush(stdout);
|
||||
while (pass < end) {
|
||||
int c = getchar();
|
||||
if (c == '\r' || c == '\n' || c == -1)
|
||||
break;
|
||||
*wr++ = c;
|
||||
}
|
||||
tio.c_lflag = c_lflag;
|
||||
tcsetattr(0, TCSAFLUSH, &tio);
|
||||
printf("\n");
|
||||
return pass;
|
||||
}
|
||||
|
||||
static int password_get(void **p, unsigned long *l, void *u)
|
||||
{
|
||||
(void)u;
|
||||
*p = getpassword("Enter passphrase: ", 256);
|
||||
*l = strlen(*p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print(ltc_pka_key *k)
|
||||
{
|
||||
int err = CRYPT_OK;
|
||||
unsigned char buf[256];
|
||||
unsigned long lbuf = sizeof(buf);
|
||||
char pubkey[256*4/3];
|
||||
unsigned long lpubkey = sizeof(pubkey);
|
||||
void *mpint = NULL;
|
||||
switch (k->id) {
|
||||
case LTC_PKA_ED25519:
|
||||
ltc_mp.init(&mpint);
|
||||
ltc_mp.unsigned_read(mpint, k->u.ed25519.pub, sizeof(k->u.ed25519.pub));
|
||||
if ((err = ssh_encode_sequence_multi(buf, &lbuf,
|
||||
LTC_SSHDATA_STRING, "ssh-ed25519", strlen("ssh-ed25519"),
|
||||
LTC_SSHDATA_MPINT, mpint,
|
||||
0, NULL)) != CRYPT_OK)
|
||||
goto errout;
|
||||
if ((err = base64_encode(buf, lbuf, pubkey, &lpubkey)) != CRYPT_OK)
|
||||
goto errout;
|
||||
printf("\rssh-ed25519 %s\n", pubkey);
|
||||
break;
|
||||
default:
|
||||
print_err("Unsupported key type: %d\n", k->id);
|
||||
break;
|
||||
}
|
||||
errout:
|
||||
if (mpint != NULL)
|
||||
ltc_mp.deinit(mpint);
|
||||
if (err != CRYPT_OK)
|
||||
die(err);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int err;
|
||||
|
||||
FILE *f = NULL;
|
||||
ltc_pka_key k;
|
||||
password_ctx pw_ctx = { .callback = password_get };
|
||||
|
||||
if ((err = register_all_ciphers()) != CRYPT_OK) {
|
||||
die(err);
|
||||
}
|
||||
if ((err = register_all_hashes()) != CRYPT_OK) {
|
||||
die(err);
|
||||
}
|
||||
if ((err = crypt_mp_init("ltm")) != CRYPT_OK) {
|
||||
die(err);
|
||||
}
|
||||
|
||||
if (argc > 1) f = fopen(argv[1], "r");
|
||||
else f = stdin;
|
||||
if (f == NULL) DIE("fopen sez no");
|
||||
|
||||
if ((err = pem_decode_openssh_filehandle(f, &k, &pw_ctx))) {
|
||||
die(err);
|
||||
}
|
||||
print(&k);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#else
|
||||
int main(void) { return EXIT_FAILURE; }
|
||||
#endif
|
||||
|
|
@ -1,385 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* 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>
|
||||
#include <termios.h>
|
||||
|
||||
#if !defined(LTC_RIJNDAEL) || !defined(LTC_CBC_MODE) || !defined(LTC_PKCS_5) || !defined(LTC_RNG_GET_BYTES) || !defined(LTC_MD5)
|
||||
int main(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
|
||||
/* 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))
|
||||
*/
|
||||
static void LTC_NORETURN barf(const char *pname, const char *err)
|
||||
{
|
||||
FILE* o = err == NULL ? stdout : stderr;
|
||||
fprintf(o,
|
||||
"Usage: %s <enc|dec> infile outfile [passphrase | -] [salt]\n"
|
||||
"\n"
|
||||
" The passphrase can either be given at the command line\n"
|
||||
" or if it's passed as '-' it will be read interactively.\n"
|
||||
"\n"
|
||||
" # encrypts infile->outfile, random salt\n"
|
||||
" %s enc infile outfile pass\n"
|
||||
"\n"
|
||||
" # encrypts infile->outfile, salt from cmdline\n"
|
||||
" %s enc infile outfile pass 0123456789abcdef\n"
|
||||
"\n"
|
||||
" # decrypts infile->outfile, pulls salt from infile\n"
|
||||
" %s dec infile outfile pass\n"
|
||||
"\n"
|
||||
" # decrypts infile->outfile, salt specified\n"
|
||||
" # (don't try to read the salt from infile)\n"
|
||||
" %s dec infile outfile pass 0123456789abcdef\n"
|
||||
"\n"
|
||||
"Application Error: %s\n", pname, pname, pname, pname, pname, err ? err : "None");
|
||||
if(errno)
|
||||
perror(
|
||||
" System Error");
|
||||
exit(err == NULL ? 0 : -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
static 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
|
||||
*/
|
||||
static 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
|
||||
*/
|
||||
static size_t s_pkcs7_pad(union paddable *buf, size_t nb, int block_length,
|
||||
int is_padding)
|
||||
{
|
||||
unsigned long length;
|
||||
|
||||
if(is_padding) {
|
||||
length = sizeof(buf->pad);
|
||||
if (padding_pad(buf->pad, nb, &length, LTC_PAD_PKCS7 | block_length) != CRYPT_OK)
|
||||
return 0;
|
||||
return length;
|
||||
} else {
|
||||
length = nb;
|
||||
if (padding_depad(buf->pad, &length, LTC_PAD_PKCS7) != CRYPT_OK)
|
||||
return 0;
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static 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 = s_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 = s_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;
|
||||
}
|
||||
|
||||
|
||||
static char* getpassword(const char *prompt, size_t maxlen)
|
||||
{
|
||||
char *wr, *end, *pass = XCALLOC(1, maxlen + 1);
|
||||
struct termios tio;
|
||||
tcflag_t c_lflag;
|
||||
if (pass == NULL)
|
||||
return NULL;
|
||||
wr = pass;
|
||||
end = pass + maxlen;
|
||||
|
||||
tcgetattr(0, &tio);
|
||||
c_lflag = tio.c_lflag;
|
||||
tio.c_lflag &= ~ECHO;
|
||||
tcsetattr(0, TCSANOW, &tio);
|
||||
|
||||
printf("%s", prompt);
|
||||
fflush(stdout);
|
||||
while (pass < end) {
|
||||
int c = getchar();
|
||||
if (c == '\r' || c == '\n' || c == -1)
|
||||
break;
|
||||
*wr++ = c;
|
||||
}
|
||||
tio.c_lflag = c_lflag;
|
||||
tcsetattr(0, TCSAFLUSH, &tio);
|
||||
printf("\n");
|
||||
return pass;
|
||||
}
|
||||
|
||||
/* Convenience macro for the various barfable places below */
|
||||
#define BARF(a) { \
|
||||
if(password) free(password); \
|
||||
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;
|
||||
const void *pass;
|
||||
char *password = NULL;
|
||||
unsigned long saltlen = sizeof(salt);
|
||||
|
||||
if (argc > 1 && strstr(argv[1], "-h"))
|
||||
barf(argv[0], NULL);
|
||||
|
||||
/* 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(base16_decode(argv[5], strlen(argv[5]), salt, &saltlen) != CRYPT_OK)
|
||||
BARF("Bad user-specified salt");
|
||||
} else if(encrypt) {
|
||||
/* 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 */
|
||||
|
||||
if (argv[4] && strcmp(argv[4], "-")) {
|
||||
pass = argv[4];
|
||||
} else {
|
||||
password = getpassword("Enter password: ", 256);
|
||||
if (!password)
|
||||
BARF("Could not get password");
|
||||
pass = password;
|
||||
}
|
||||
|
||||
/* Run the key derivation from the provided passphrase. This gets us
|
||||
the key and iv. */
|
||||
ret = pkcs_5_alg1_openssl(pass, XSTRLEN(pass), 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 */
|
||||
if(password) free(password);
|
||||
fclose(infd); fclose(outfd);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#define _POSIX_C_SOURCE 200809L /* otherwise PATH_MAX + strdup are not defined for build with -std=c99 */
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#include <string.h>
|
||||
#define basename(path) ( strrchr((path), '/') ? strrchr((path), '/') + 1 : strrchr((path), '\\') ? strrchr((path), '\\') + 1 : (path) )
|
||||
|
||||
/**
|
||||
@file demo_crypt_sizes.c
|
||||
|
||||
Demo how to get various sizes to dynamic languages
|
||||
like Python - Larry Bugbee, February 2013
|
||||
*/
|
||||
|
||||
static void s_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 */
|
||||
if ((sizes_list = malloc(sizes_list_len)) == NULL) exit(EXIT_FAILURE);
|
||||
if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf(" supported sizes:\n\n%s\n\n", sizes_list);
|
||||
free(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);
|
||||
s_print_line("<no argument>", "The old behavior of the demo");
|
||||
s_print_line("-a", "Only lists all sizes");
|
||||
s_print_line("-s name", "List a single size given as argument");
|
||||
s_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 */
|
||||
if ((sizes_list = malloc(sizes_list_len)) == NULL) exit(EXIT_FAILURE);
|
||||
if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
|
||||
printf("%s\n", sizes_list);
|
||||
free(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;
|
||||
}
|
||||
|
|
@ -1,15 +1,10 @@
|
|||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
/* small demo app that just includes a cipher/hash/prng */
|
||||
#include <tomcrypt.h>
|
||||
// small demo app that just includes a cipher/hash/prng
|
||||
|
||||
#include <mycrypt.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#ifdef LTC_RIJNDAEL
|
||||
#ifdef ENCRYPT_ONLY
|
||||
register_cipher(&rijndael_enc_desc);
|
||||
#endif
|
||||
#endif
|
||||
register_prng(&yarrow_desc);
|
||||
register_hash(&sha256_desc);
|
||||
return 0;
|
||||
|
|
|
|||
356
demos/test/.ccmalloc
Normal file
356
demos/test/.ccmalloc
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%% 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
|
||||
20
demos/test/base64_test.c
Normal file
20
demos/test/base64_test.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "test.h"
|
||||
|
||||
int base64_test(void)
|
||||
{
|
||||
unsigned char in[64], out[256], tmp[64];
|
||||
unsigned long x, l1, l2;
|
||||
|
||||
for (x = 0; x < 64; x++) {
|
||||
yarrow_read(in, x, &test_yarrow);
|
||||
l1 = sizeof(out);
|
||||
DO(base64_encode(in, x, out, &l1));
|
||||
l2 = sizeof(tmp);
|
||||
DO(base64_decode(out, l1, tmp, &l2));
|
||||
if (l2 != x || memcmp(tmp, in, x)) {
|
||||
printf("base64 failed %lu %lu %lu", x, l1, l2);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
20
demos/test/cipher_hash_test.c
Normal file
20
demos/test/cipher_hash_test.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* test the ciphers and hashes using their built-in self-tests */
|
||||
|
||||
#include "test.h"
|
||||
|
||||
int cipher_hash_test(void)
|
||||
{
|
||||
int x;
|
||||
|
||||
/* test ciphers */
|
||||
for (x = 0; cipher_descriptor[x].name != NULL; x++) {
|
||||
DO(cipher_descriptor[x].test());
|
||||
}
|
||||
|
||||
/* test hashes */
|
||||
for (x = 0; hash_descriptor[x].name != NULL; x++) {
|
||||
DO(hash_descriptor[x].test());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
87
demos/test/dh_tests.c
Normal file
87
demos/test/dh_tests.c
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include "test.h"
|
||||
|
||||
int dh_tests (void)
|
||||
{
|
||||
unsigned char buf[3][4096];
|
||||
unsigned long x, y, z;
|
||||
int stat, stat2;
|
||||
dh_key usera, userb;
|
||||
|
||||
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));
|
||||
|
||||
/* make the shared secret */
|
||||
x = 4096;
|
||||
DO(dh_shared_secret (&usera, &userb, buf[0], &x));
|
||||
|
||||
y = 4096;
|
||||
DO(dh_shared_secret (&userb, &usera, buf[1], &y));
|
||||
if (y != x) {
|
||||
printf ("DH Shared keys are not same size.\n");
|
||||
return 1;
|
||||
}
|
||||
if (memcmp (buf[0], buf[1], x)) {
|
||||
printf ("DH Shared keys not same contents.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* now export userb */
|
||||
y = 4096;
|
||||
DO(dh_export (buf[1], &y, PK_PUBLIC, &userb));
|
||||
dh_free (&userb);
|
||||
|
||||
/* import and make the shared secret again */
|
||||
DO(dh_import (buf[1], y, &userb));
|
||||
z = 4096;
|
||||
DO(dh_shared_secret (&usera, &userb, buf[2], &z));
|
||||
|
||||
if (z != x) {
|
||||
printf ("failed. Size don't match?\n");
|
||||
return 1;
|
||||
}
|
||||
if (memcmp (buf[0], buf[2], x)) {
|
||||
printf ("Failed. Content didn't match.\n");
|
||||
return 1;
|
||||
}
|
||||
dh_free (&usera);
|
||||
dh_free (&userb);
|
||||
|
||||
/* test encrypt_key */
|
||||
dh_make_key (&test_yarrow, find_prng ("yarrow"), 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));
|
||||
zeromem (buf[0], sizeof (buf[0]));
|
||||
x = sizeof (buf[0]);
|
||||
DO(dh_decrypt_key (buf[1], y, buf[0], &x, &usera));
|
||||
if (x != 16) {
|
||||
printf ("Failed (length)\n");
|
||||
return 1;
|
||||
}
|
||||
for (x = 0; x < 16; x++)
|
||||
if (buf[0][x] != x) {
|
||||
printf ("Failed (contents)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test sign_hash */
|
||||
for (x = 0; x < 16; x++) {
|
||||
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_verify_hash (buf[1], x, buf[0], 16, &stat, &usera));
|
||||
buf[0][0] ^= 1;
|
||||
DO(dh_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera));
|
||||
if (!(stat == 1 && stat2 == 0)) {
|
||||
printf("dh_sign/verify_hash %d %d", stat, stat2);
|
||||
return 1;
|
||||
}
|
||||
dh_free (&usera);
|
||||
return 0;
|
||||
}
|
||||
51
demos/test/dsa_test.c
Normal file
51
demos/test/dsa_test.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "test.h"
|
||||
|
||||
int dsa_test(void)
|
||||
{
|
||||
unsigned char msg[16], out[1024], out2[1024];
|
||||
unsigned long x, y;
|
||||
int err, stat1, stat2;
|
||||
dsa_key key, key2;
|
||||
|
||||
/* make a random key */
|
||||
DO(dsa_make_key(&test_yarrow, find_prng("yarrow"), 20, 128, &key));
|
||||
|
||||
/* verify it */
|
||||
DO(dsa_verify_key(&key, &stat1));
|
||||
if (stat1 == 0) { printf("dsa_verify_key "); return 1; }
|
||||
|
||||
/* sign the message */
|
||||
x = sizeof(out);
|
||||
DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &test_yarrow, find_prng("yarrow"), &key));
|
||||
|
||||
/* verify it once */
|
||||
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key));
|
||||
|
||||
/* Modify and verify again */
|
||||
msg[0] ^= 1;
|
||||
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key));
|
||||
msg[0] ^= 1;
|
||||
if (!(stat1 == 1 && stat2 == 0)) { printf("dsa_verify %d %d", stat1, stat2); return 1; }
|
||||
|
||||
/* test exporting it */
|
||||
x = sizeof(out2);
|
||||
DO(dsa_export(out2, &x, PK_PRIVATE, &key));
|
||||
DO(dsa_import(out2, x, &key2));
|
||||
|
||||
/* verify a signature with it */
|
||||
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
|
||||
if (stat1 == 0) { printf("dsa_verify (import private) %d ", stat1); return 1; }
|
||||
dsa_free(&key2);
|
||||
|
||||
/* export as public now */
|
||||
x = sizeof(out2);
|
||||
DO(dsa_export(out2, &x, PK_PUBLIC, &key));
|
||||
DO(dsa_import(out2, x, &key2));
|
||||
/* verify a signature with it */
|
||||
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
|
||||
if (stat1 == 0) { printf("dsa_verify (import public) %d ", stat1); return 1; }
|
||||
dsa_free(&key2);
|
||||
dsa_free(&key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
89
demos/test/ecc_test.c
Normal file
89
demos/test/ecc_test.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "test.h"
|
||||
|
||||
int ecc_tests (void)
|
||||
{
|
||||
unsigned char buf[4][4096];
|
||||
unsigned long x, y, z;
|
||||
int stat, stat2;
|
||||
ecc_key usera, userb;
|
||||
|
||||
DO(ecc_test ());
|
||||
|
||||
/* make up two keys */
|
||||
DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &usera));
|
||||
DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &userb));
|
||||
|
||||
/* make the shared secret */
|
||||
x = 4096;
|
||||
DO(ecc_shared_secret (&usera, &userb, buf[0], &x));
|
||||
|
||||
y = 4096;
|
||||
DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
|
||||
|
||||
if (y != x) {
|
||||
printf ("ecc Shared keys are not same size.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (memcmp (buf[0], buf[1], x)) {
|
||||
printf ("ecc Shared keys not same contents.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* now export userb */
|
||||
y = 4096;
|
||||
DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb));
|
||||
ecc_free (&userb);
|
||||
|
||||
/* import and make the shared secret again */
|
||||
DO(ecc_import (buf[1], y, &userb));
|
||||
|
||||
z = 4096;
|
||||
DO(ecc_shared_secret (&usera, &userb, buf[2], &z));
|
||||
|
||||
if (z != x) {
|
||||
printf ("failed. Size don't match?");
|
||||
return 1;
|
||||
}
|
||||
if (memcmp (buf[0], buf[2], x)) {
|
||||
printf ("Failed. Content didn't match.");
|
||||
return 1;
|
||||
}
|
||||
ecc_free (&usera);
|
||||
ecc_free (&userb);
|
||||
|
||||
/* test encrypt_key */
|
||||
ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &usera);
|
||||
for (x = 0; x < 32; x++) {
|
||||
buf[0][x] = x;
|
||||
}
|
||||
y = sizeof (buf[1]);
|
||||
DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &test_yarrow, find_prng ("yarrow"), find_hash ("sha256"), &usera));
|
||||
zeromem (buf[0], sizeof (buf[0]));
|
||||
x = sizeof (buf[0]);
|
||||
DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &usera));
|
||||
if (x != 32) {
|
||||
printf ("Failed (length)");
|
||||
return 1;
|
||||
}
|
||||
for (x = 0; x < 32; x++)
|
||||
if (buf[0][x] != x) {
|
||||
printf ("Failed (contents)");
|
||||
return 1;
|
||||
}
|
||||
/* test sign_hash */
|
||||
for (x = 0; x < 16; x++) {
|
||||
buf[0][x] = x;
|
||||
}
|
||||
x = sizeof (buf[1]);
|
||||
DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &test_yarrow, find_prng ("yarrow"), &usera));
|
||||
DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &usera));
|
||||
buf[0][0] ^= 1;
|
||||
DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera));
|
||||
if (!(stat == 1 && stat2 == 0)) {
|
||||
printf("ecc_verify_hash failed");
|
||||
return 1;
|
||||
}
|
||||
ecc_free (&usera);
|
||||
return 0;
|
||||
}
|
||||
12
demos/test/mac_test.c
Normal file
12
demos/test/mac_test.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/* 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;
|
||||
}
|
||||
25
demos/test/makefile
Normal file
25
demos/test/makefile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# 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.c dh_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) -ltomcrypt $(CCMALLOC) -o test
|
||||
|
||||
clean:
|
||||
rm -f test *.o *.obj *.exe *~
|
||||
14
demos/test/makefile.icc
Normal file
14
demos/test/makefile.icc
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# make test harness, it is good.
|
||||
CFLAGS += -O3 -xN -ip -I../../ -I./
|
||||
CC=icc
|
||||
|
||||
default: test
|
||||
|
||||
OBJECTS=test.o cipher_hash_test.o mac_test.o modes_test.o \
|
||||
pkcs_1_test.o store_test.o rsa_test.o ecc_test.o dsa_test.c dh_tests.o
|
||||
|
||||
test: $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -ltomcrypt -o test
|
||||
|
||||
clean:
|
||||
rm -f test *.o *~
|
||||
14
demos/test/makefile.msvc
Normal file
14
demos/test/makefile.msvc
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# make test harness, it is good.
|
||||
CFLAGS = $(CFLAGS) /W3 /Ox -I../../ -I./
|
||||
|
||||
default: test.exe
|
||||
|
||||
OBJECTS = test.obj cipher_hash_test.obj mac_test.obj modes_test.obj \
|
||||
pkcs_1_test.obj store_test.obj rsa_test.obj ecc_test.obj dsa_test.c dh_tests.obj
|
||||
|
||||
|
||||
test.exe: $(OBJECTS)
|
||||
cl $(OBJECTS) tomcrypt.lib advapi32.lib
|
||||
|
||||
clean:
|
||||
rm -f test.exe *.obj *~
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue