diff --git a/.gitignore b/.gitignore index 8f8f6d1..fe67ca5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,10 +14,14 @@ tv.txt *_tv.txt # *nix/windows test executables +constants +constants.exe encrypt encrypt.exe hashsum hashsum.exe +sizes +sizes.exe small small.exe test diff --git a/demos/demo_crypt_constants.c b/demos/demo_crypt_constants.c new file mode 100644 index 0000000..9c41cf7 --- /dev/null +++ b/demos/demo_crypt_constants.c @@ -0,0 +1,54 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +/** + @file demo_crypt_constants.c + + Demo how to get various constants to dynamic languages + like Python + + Larry Bugbee, February 2013 +*/ + + +int main(void) { + // given a specific constant name, get and print its value + char name[] = "CTR_COUNTER_BIG_ENDIAN"; + int value; + + 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 + char *names_list; + unsigned long names_list_len; + + if (crypt_list_all_constants(NULL, &names_list_len) != 0) + exit(EXIT_FAILURE); + printf(" need to allocate %lu 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); + + return 0; +} + + +/* $Source$ */ +/* $Revision$ */ +/* $Date$ */ diff --git a/demos/demo_crypt_sizes.c b/demos/demo_crypt_sizes.c new file mode 100644 index 0000000..ea1cef1 --- /dev/null +++ b/demos/demo_crypt_sizes.c @@ -0,0 +1,45 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +/** + @file demo_crypt_sizes.c + + Demo how to get various sizes to dynamic languages + like Python - Larry Bugbee, February 2013 +*/ + + +int main(void) { + int rc; + + // given a specific size name, get and print its size + char name[] = "ecc_key"; + int size; + rc = crypt_get_size(name, &size); + printf("\n size of '%s' is %d \n\n", name, size); + + // get and print the length of the names (and sizes) list + char *sizes_list; + unsigned long sizes_list_len; + rc = crypt_list_all_sizes(NULL, &sizes_list_len); + printf(" need to allocate %lu bytes \n\n", sizes_list_len); + + // get and print the names (and sizes) list + sizes_list = malloc(sizes_list_len); + rc = crypt_list_all_sizes(sizes_list, &sizes_list_len); + printf(" supported sizes:\n\n%s\n\n", sizes_list); +} + + +/* $Source: $ */ +/* $Revision: $ */ +/* $Date: $ */ diff --git a/demos/demo_dynamic.py b/demos/demo_dynamic.py new file mode 100755 index 0000000..81f6f8b --- /dev/null +++ b/demos/demo_dynamic.py @@ -0,0 +1,206 @@ + + +""" + demo_dynamic.py v1 + + 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 with the following steps: + + 1- compile LTC to a .a static lib: + CFLAGS="-DLTM_DESC -DUSE_LTM" make + + 2- link LTC and LTM into a single .dylib: + ar2dylib_with tomcrypt tommath + where ar2dylib_with is a shell script that combines + the LTC .a with the LTM .dylib + + Reminder: you don't need to bind in a math library unless + you are going to use LTC functions that depend + on a mathlib. For example, public key crypto + needs a mathlib; hashing and symmetric encryption + do not. + + This code was written for Python 2.7. + + Larry Bugbee + March 2014 + +""" + + +from ctypes import * +from ctypes.util import find_library + + +#--------------------------------------------------------------- +# load the .dylib + +libname = 'tomcrypt' +libpath = find_library(libname) + +print +print(' demo_dynamic.py') +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 1: + 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 \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 + print + + +if 1: + 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 \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 + print + + +#--------------------------------------------------------------- +# get individually named constants and sizes + +# print selected constants +if 1: + print '\n selected constants:' + + names = [ + 'ENDIAN_LITTLE', + 'ENDIAN_64BITWORD', + 'PK_PUBLIC', + 'MAX_RSA_SIZE', + '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, value) + +# print selected sizes +if 1: + print '\n selected sizes:' + + names = [ + 'rijndael_key', + 'rsa_key', + 'symmetric_CTR', + 'twofish_key', + 'ecc_point', + 'gcm_state', + '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, value) + + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# ctypes getting a list of this build's supported algorithms +# and compiler switches + +def get_named_string(lib, name): + return c_char_p.in_dll(lib, name).value + +if 0: + print '\n%s' % ('-'*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') + print + + + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +# here is an example of how a wrapper can make Python access +# more Pythonic + +# - - - - - - - - - - - - - +# a wrapper fragment... + +def _get_size(name): + size = c_int(0) + rc = LTC.crypt_get_size(name, byref(size)) + return size.value + +sha256_state_struct_size = _get_size('sha256_state') +sha512_state_struct_size = _get_size('sha512_state') + +class SHA256(object): + def __init__(self): + self.state = c_buffer(sha256_state_struct_size) + 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 + +# - - - - - - - - - - - - - +# an app fragment... + +# from wrapper import * # uncomment in real life + +data = 'hello world' + +sha256 = SHA256() +sha256.update(data) +md = sha256.digest() + +template = '\n\n the SHA256 digest for "%s" is %s \n' +print template % (data, md.encode('hex')) + + + +#--------------------------------------------------------------- +#--------------------------------------------------------------- +#--------------------------------------------------------------- diff --git a/makefile b/makefile index 7a055f2..dea1ea2 100644 --- a/makefile +++ b/makefile @@ -81,6 +81,8 @@ TV=tv_gen MULTI=multi TIMING=timing TEST=test +SIZES=sizes +CONSTANTS=constants #LIBPATH-The directory for libtomcrypt to be installed to. #INCPATH-The directory to install the header files for libtomcrypt. @@ -157,24 +159,26 @@ src/mac/xcbc/xcbc_test.o src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src src/math/multi.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o \ src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_id.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ -src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ -src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ +src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_id.o \ +src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ +src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ +src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \ -src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \ -src/misc/error_to_string.o src/misc/hkdf/hkdf.o src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o \ -src/misc/pkcs5/pkcs_5_2.o src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o \ -src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \ -src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \ -src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \ -src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \ -src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \ -src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ +src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ +src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ +src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o \ +src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o src/modes/cbc/cbc_decrypt.o \ +src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o src/modes/cbc/cbc_getiv.o \ +src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o src/modes/cfb/cfb_decrypt.o \ +src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o src/modes/cfb/cfb_getiv.o \ +src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o src/modes/ctr/ctr_decrypt.o \ +src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o src/modes/ctr/ctr_getiv.o \ +src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \ src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \ src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \ @@ -255,6 +259,8 @@ TVS=demos/tv_gen.o MULTIS=demos/multi.o TIMINGS=demos/timing.o TESTS=demos/test.o +CRYPTSIZES=demos/demo_crypt_sizes.o +CRYPTCONSTANTS=demos/demo_crypt_constants.o #Files left over from making the crypt.pdf. LEFTOVERS=*.dvi *.log *.aux *.toc *.idx *.ilg *.ind *.out *.lof @@ -312,6 +318,12 @@ timing: library testprof/$(LIBTEST) $(TIMINGS) test: library testprof/$(LIBTEST) $(TESTS) $(CC) $(LDFLAGS) $(TESTS) testprof/$(LIBTEST) $(LIBNAME) $(EXTRALIBS) -o $(TEST) +sizes: library $(CRYPTSIZES) + $(CC) $(LDFLAGS) $(CRYPTSIZES) $(LIBNAME) $(EXTRALIBS) -o $(SIZES) + +constants: library $(CRYPTCONSTANTS) + $(CC) $(LDFLAGS) $(CRYPTCONSTANTS) $(LIBNAME) $(EXTRALIBS) -o $(CONSTANTS) + #This rule installs the library and the header files. This must be run #as root in order to have a high enough permission to write to the correct #directories and to set the owner and group to root. @@ -360,6 +372,7 @@ clean: rm -rf `find . -type d -name "*.libs" | xargs` rm -f crypt.aux crypt.dvi crypt.idx crypt.ilg crypt.ind crypt.log crypt.toc rm -f $(TV) $(SMALL) $(CRYPT) $(HASH) $(MULTI) $(TIMING) $(TEST) + rm -f $(SIZES) $(CONSTANTS) rm -rf doc/doxygen rm -f `find . -type f -name "*.pdf" | grep -FL crypt.pdf | xargs` rm -f *.txt diff --git a/makefile.icc b/makefile.icc index f18d1d5..6d5a4d2 100644 --- a/makefile.icc +++ b/makefile.icc @@ -142,24 +142,26 @@ src/mac/xcbc/xcbc_test.o src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src src/math/multi.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o \ src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_id.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ -src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ -src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ +src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_id.o \ +src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ +src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ +src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \ -src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \ -src/misc/error_to_string.o src/misc/hkdf/hkdf.o src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o \ -src/misc/pkcs5/pkcs_5_2.o src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o \ -src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \ -src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \ -src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \ -src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \ -src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \ -src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ +src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ +src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ +src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o \ +src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o src/modes/cbc/cbc_decrypt.o \ +src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o src/modes/cbc/cbc_getiv.o \ +src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o src/modes/cfb/cfb_decrypt.o \ +src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o src/modes/cfb/cfb_getiv.o \ +src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o src/modes/ctr/ctr_decrypt.o \ +src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o src/modes/ctr/ctr_getiv.o \ +src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \ src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \ src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \ diff --git a/makefile.mingw b/makefile.mingw index bae91a5..888fac2 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -89,24 +89,26 @@ src/mac/xcbc/xcbc_test.o src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src src/math/multi.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o \ src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_id.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ -src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ -src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ +src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_id.o \ +src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ +src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ +src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \ -src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \ -src/misc/error_to_string.o src/misc/hkdf/hkdf.o src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o \ -src/misc/pkcs5/pkcs_5_2.o src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o \ -src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \ -src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \ -src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \ -src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \ -src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \ -src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ +src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ +src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ +src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o \ +src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o src/modes/cbc/cbc_decrypt.o \ +src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o src/modes/cbc/cbc_getiv.o \ +src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o src/modes/cfb/cfb_decrypt.o \ +src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o src/modes/cfb/cfb_getiv.o \ +src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o src/modes/ctr/ctr_decrypt.o \ +src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o src/modes/ctr/ctr_getiv.o \ +src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \ src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \ src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \ diff --git a/makefile.msvc b/makefile.msvc index 13e25eb..afb1ad6 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -47,24 +47,26 @@ src/mac/xcbc/xcbc_test.obj src/math/fp/ltc_ecc_fp_mulmod.obj src/math/gmp_desc.o src/math/multi.obj src/math/rand_bn.obj src/math/rand_prime.obj src/math/tfm_desc.obj \ src/misc/base64/base64_decode.obj src/misc/base64/base64_encode.obj src/misc/burn_stack.obj \ src/misc/crypt/crypt_argchk.obj src/misc/crypt/crypt.obj src/misc/crypt/crypt_cipher_descriptor.obj \ -src/misc/crypt/crypt_cipher_is_valid.obj src/misc/crypt/crypt_find_cipher_any.obj \ -src/misc/crypt/crypt_find_cipher.obj src/misc/crypt/crypt_find_cipher_id.obj \ -src/misc/crypt/crypt_find_hash_any.obj src/misc/crypt/crypt_find_hash.obj \ -src/misc/crypt/crypt_find_hash_id.obj src/misc/crypt/crypt_find_hash_oid.obj \ -src/misc/crypt/crypt_find_prng.obj src/misc/crypt/crypt_fsa.obj src/misc/crypt/crypt_hash_descriptor.obj \ -src/misc/crypt/crypt_hash_is_valid.obj src/misc/crypt/crypt_ltc_mp_descriptor.obj \ +src/misc/crypt/crypt_cipher_is_valid.obj src/misc/crypt/crypt_constants.obj \ +src/misc/crypt/crypt_find_cipher_any.obj src/misc/crypt/crypt_find_cipher.obj \ +src/misc/crypt/crypt_find_cipher_id.obj src/misc/crypt/crypt_find_hash_any.obj \ +src/misc/crypt/crypt_find_hash.obj src/misc/crypt/crypt_find_hash_id.obj \ +src/misc/crypt/crypt_find_hash_oid.obj src/misc/crypt/crypt_find_prng.obj src/misc/crypt/crypt_fsa.obj \ +src/misc/crypt/crypt_hash_descriptor.obj src/misc/crypt/crypt_hash_is_valid.obj \ +src/misc/crypt/crypt_inits.obj src/misc/crypt/crypt_ltc_mp_descriptor.obj \ src/misc/crypt/crypt_prng_descriptor.obj src/misc/crypt/crypt_prng_is_valid.obj \ src/misc/crypt/crypt_register_cipher.obj src/misc/crypt/crypt_register_hash.obj \ -src/misc/crypt/crypt_register_prng.obj src/misc/crypt/crypt_unregister_cipher.obj \ -src/misc/crypt/crypt_unregister_hash.obj src/misc/crypt/crypt_unregister_prng.obj \ -src/misc/error_to_string.obj src/misc/hkdf/hkdf.obj src/misc/hkdf/hkdf_test.obj src/misc/pkcs5/pkcs_5_1.obj \ -src/misc/pkcs5/pkcs_5_2.obj src/misc/pkcs5/pkcs_5_test.obj src/misc/pk_get_oid.obj src/misc/zeromem.obj \ -src/modes/cbc/cbc_decrypt.obj src/modes/cbc/cbc_done.obj src/modes/cbc/cbc_encrypt.obj \ -src/modes/cbc/cbc_getiv.obj src/modes/cbc/cbc_setiv.obj src/modes/cbc/cbc_start.obj \ -src/modes/cfb/cfb_decrypt.obj src/modes/cfb/cfb_done.obj src/modes/cfb/cfb_encrypt.obj \ -src/modes/cfb/cfb_getiv.obj src/modes/cfb/cfb_setiv.obj src/modes/cfb/cfb_start.obj \ -src/modes/ctr/ctr_decrypt.obj src/modes/ctr/ctr_done.obj src/modes/ctr/ctr_encrypt.obj \ -src/modes/ctr/ctr_getiv.obj src/modes/ctr/ctr_setiv.obj src/modes/ctr/ctr_start.obj src/modes/ctr/ctr_test.obj \ +src/misc/crypt/crypt_register_prng.obj src/misc/crypt/crypt_sizes.obj \ +src/misc/crypt/crypt_unregister_cipher.obj src/misc/crypt/crypt_unregister_hash.obj \ +src/misc/crypt/crypt_unregister_prng.obj src/misc/error_to_string.obj src/misc/hkdf/hkdf.obj \ +src/misc/hkdf/hkdf_test.obj src/misc/pkcs5/pkcs_5_1.obj src/misc/pkcs5/pkcs_5_2.obj \ +src/misc/pkcs5/pkcs_5_test.obj src/misc/pk_get_oid.obj src/misc/zeromem.obj src/modes/cbc/cbc_decrypt.obj \ +src/modes/cbc/cbc_done.obj src/modes/cbc/cbc_encrypt.obj src/modes/cbc/cbc_getiv.obj \ +src/modes/cbc/cbc_setiv.obj src/modes/cbc/cbc_start.obj src/modes/cfb/cfb_decrypt.obj \ +src/modes/cfb/cfb_done.obj src/modes/cfb/cfb_encrypt.obj src/modes/cfb/cfb_getiv.obj \ +src/modes/cfb/cfb_setiv.obj src/modes/cfb/cfb_start.obj src/modes/ctr/ctr_decrypt.obj \ +src/modes/ctr/ctr_done.obj src/modes/ctr/ctr_encrypt.obj src/modes/ctr/ctr_getiv.obj \ +src/modes/ctr/ctr_setiv.obj src/modes/ctr/ctr_start.obj src/modes/ctr/ctr_test.obj \ src/modes/ecb/ecb_decrypt.obj src/modes/ecb/ecb_done.obj src/modes/ecb/ecb_encrypt.obj \ src/modes/ecb/ecb_start.obj src/modes/f8/f8_decrypt.obj src/modes/f8/f8_done.obj src/modes/f8/f8_encrypt.obj \ src/modes/f8/f8_getiv.obj src/modes/f8/f8_setiv.obj src/modes/f8/f8_start.obj src/modes/f8/f8_test_mode.obj \ diff --git a/makefile.shared b/makefile.shared index d658e08..3aa78b4 100644 --- a/makefile.shared +++ b/makefile.shared @@ -141,24 +141,26 @@ src/mac/xcbc/xcbc_test.o src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src src/math/multi.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o \ src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_id.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ -src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ -src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ +src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_id.o \ +src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ +src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ +src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \ -src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \ -src/misc/error_to_string.o src/misc/hkdf/hkdf.o src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o \ -src/misc/pkcs5/pkcs_5_2.o src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o \ -src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \ -src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \ -src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \ -src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \ -src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \ -src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ +src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ +src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ +src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o \ +src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o src/modes/cbc/cbc_decrypt.o \ +src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o src/modes/cbc/cbc_getiv.o \ +src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o src/modes/cfb/cfb_decrypt.o \ +src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o src/modes/cfb/cfb_getiv.o \ +src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o src/modes/ctr/ctr_decrypt.o \ +src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o src/modes/ctr/ctr_getiv.o \ +src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \ src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \ src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \ diff --git a/makefile.unix b/makefile.unix index eb2f38c..9e2a645 100644 --- a/makefile.unix +++ b/makefile.unix @@ -83,24 +83,26 @@ src/mac/xcbc/xcbc_test.o src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src src/math/multi.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o \ src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o src/misc/burn_stack.o \ src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt.o src/misc/crypt/crypt_cipher_descriptor.o \ -src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_find_cipher_any.o \ -src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_id.o \ -src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash.o \ -src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_hash_oid.o \ -src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o src/misc/crypt/crypt_hash_descriptor.o \ -src/misc/crypt/crypt_hash_is_valid.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ +src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \ +src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher.o \ +src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash_any.o \ +src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_id.o \ +src/misc/crypt/crypt_find_hash_oid.o src/misc/crypt/crypt_find_prng.o src/misc/crypt/crypt_fsa.o \ +src/misc/crypt/crypt_hash_descriptor.o src/misc/crypt/crypt_hash_is_valid.o \ +src/misc/crypt/crypt_inits.o src/misc/crypt/crypt_ltc_mp_descriptor.o \ src/misc/crypt/crypt_prng_descriptor.o src/misc/crypt/crypt_prng_is_valid.o \ src/misc/crypt/crypt_register_cipher.o src/misc/crypt/crypt_register_hash.o \ -src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_unregister_cipher.o \ -src/misc/crypt/crypt_unregister_hash.o src/misc/crypt/crypt_unregister_prng.o \ -src/misc/error_to_string.o src/misc/hkdf/hkdf.o src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o \ -src/misc/pkcs5/pkcs_5_2.o src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o \ -src/modes/cbc/cbc_decrypt.o src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o \ -src/modes/cbc/cbc_getiv.o src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o \ -src/modes/cfb/cfb_decrypt.o src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o \ -src/modes/cfb/cfb_getiv.o src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o \ -src/modes/ctr/ctr_decrypt.o src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o \ -src/modes/ctr/ctr_getiv.o src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ +src/misc/crypt/crypt_register_prng.o src/misc/crypt/crypt_sizes.o \ +src/misc/crypt/crypt_unregister_cipher.o src/misc/crypt/crypt_unregister_hash.o \ +src/misc/crypt/crypt_unregister_prng.o src/misc/error_to_string.o src/misc/hkdf/hkdf.o \ +src/misc/hkdf/hkdf_test.o src/misc/pkcs5/pkcs_5_1.o src/misc/pkcs5/pkcs_5_2.o \ +src/misc/pkcs5/pkcs_5_test.o src/misc/pk_get_oid.o src/misc/zeromem.o src/modes/cbc/cbc_decrypt.o \ +src/modes/cbc/cbc_done.o src/modes/cbc/cbc_encrypt.o src/modes/cbc/cbc_getiv.o \ +src/modes/cbc/cbc_setiv.o src/modes/cbc/cbc_start.o src/modes/cfb/cfb_decrypt.o \ +src/modes/cfb/cfb_done.o src/modes/cfb/cfb_encrypt.o src/modes/cfb/cfb_getiv.o \ +src/modes/cfb/cfb_setiv.o src/modes/cfb/cfb_start.o src/modes/ctr/ctr_decrypt.o \ +src/modes/ctr/ctr_done.o src/modes/ctr/ctr_encrypt.o src/modes/ctr/ctr_getiv.o \ +src/modes/ctr/ctr_setiv.o src/modes/ctr/ctr_start.o src/modes/ctr/ctr_test.o \ src/modes/ecb/ecb_decrypt.o src/modes/ecb/ecb_done.o src/modes/ecb/ecb_encrypt.o \ src/modes/ecb/ecb_start.o src/modes/f8/f8_decrypt.o src/modes/f8/f8_done.o src/modes/f8/f8_encrypt.o \ src/modes/f8/f8_getiv.o src/modes/f8/f8_setiv.o src/modes/f8/f8_start.o src/modes/f8/f8_test_mode.o \ diff --git a/src/headers/tomcrypt_misc.h b/src/headers/tomcrypt_misc.h index e1e4457..503447c 100644 --- a/src/headers/tomcrypt_misc.h +++ b/src/headers/tomcrypt_misc.h @@ -49,6 +49,26 @@ extern const char *crypt_build_settings; /* ---- HMM ---- */ int crypt_fsa(void *mp, ...); +/* ---- Dynamic language support ---- */ +int crypt_get_constant(const char* namein, int *valueout); +int crypt_list_all_constants(char *names_list, unsigned long *names_list_size); + +int crypt_get_size(const char* namein, int *sizeout); +int crypt_list_all_sizes(char *names_list, unsigned long *names_list_size); + +#ifdef LTM_DESC +void init_LTM(void); +#endif +#ifdef TFM_DESC +void init_TFM(void); +#endif +/* *** use of GMP is untested *** +#ifdef GMP_DESC +void init_GMP(void); +#endif +*/ + + /* $Source$ */ /* $Revision$ */ /* $Date$ */ diff --git a/src/misc/crypt/crypt_constants.c b/src/misc/crypt/crypt_constants.c new file mode 100755 index 0000000..adb6836 --- /dev/null +++ b/src/misc/crypt/crypt_constants.c @@ -0,0 +1,231 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +/** + @file crypt_constants.c + + Make various constants available to dynamic languages + like Python - Larry Bugbee, February 2013 + + LB - Dec 2013 - revised to include compiler define options + LB - Mar 2014 - added endianness and word size +*/ + +typedef struct { + const char *name; + const long value; +} crypt_constant; + +#define _C_STRINGIFY(s) { #s, s } + +static const crypt_constant _crypt_constants[] = { + _C_STRINGIFY(PK_PUBLIC), + _C_STRINGIFY(PK_PRIVATE), + + _C_STRINGIFY(PKA_RSA), + _C_STRINGIFY(PKA_DSA), + +#ifdef LTC_PKCS_1 + {"LTC_PKCS_1", 1}, + /* Block types */ + _C_STRINGIFY(LTC_PKCS_1_EMSA), + _C_STRINGIFY(LTC_PKCS_1_EME), + + /* Padding types */ + _C_STRINGIFY(LTC_PKCS_1_V1_5), + _C_STRINGIFY(LTC_PKCS_1_OAEP), + _C_STRINGIFY(LTC_PKCS_1_PSS), +#else + {"LTC_PKCS_1", 0}, +#endif + +#ifdef LTC_MRSA + {"LTC_MRSA", 1}, + _C_STRINGIFY(MIN_RSA_SIZE), + _C_STRINGIFY(MAX_RSA_SIZE), +#else + {"LTC_MRSA", 0}, +#endif + +#ifdef MKAT + {"MKAT", 1}, + _C_STRINGIFY(MIN_KAT_SIZE), + _C_STRINGIFY(MAX_KAT_SIZE), +#else + {"MKAT", 0}, +#endif + +#ifdef LTC_MECC + {"LTC_MECC", 1}, + _C_STRINGIFY(ECC_BUF_SIZE), + _C_STRINGIFY(ECC_MAXSIZE), +#else + {"LTC_MECC", 0}, +#endif + +#ifdef LTC_MDSA + {"LTC_MDSA", 1}, + _C_STRINGIFY(LTC_MDSA_DELTA), + _C_STRINGIFY(LTC_MDSA_MAX_GROUP), +#else + {"LTC_MDSA", 0}, +#endif + +#ifdef LTC_CTR_MODE + {"LTC_CTR_MODE", 1}, + _C_STRINGIFY(CTR_COUNTER_LITTLE_ENDIAN), + _C_STRINGIFY(CTR_COUNTER_BIG_ENDIAN), + _C_STRINGIFY(LTC_CTR_RFC3686), +#else + {"LTC_CTR_MODE", 0}, +#endif + + _C_STRINGIFY(MAXBLOCKSIZE), + _C_STRINGIFY(TAB_SIZE), + _C_STRINGIFY(ARGTYPE), + +#ifdef LTM_DESC + {"LTM_DESC", 1}, +#else + {"LTM_DESC", 0}, +#endif +#ifdef TFM_DESC + {"TFM_DESC", 1}, +#else + {"TFM_DESC", 0}, +#endif +#ifdef GMP_DESC + {"GMP_DESC", 1}, +#else + {"GMP_DESC", 0}, +#endif + +#ifdef LTC_FAST + {"LTC_FAST", 1}, +#else + {"LTC_FAST", 0}, +#endif + +#ifdef LTC_NO_FILE + {"LTC_NO_FILE", 1}, +#else + {"LTC_NO_FILE", 0}, +#endif + +#ifdef ENDIAN_LITTLE + {"ENDIAN_LITTLE", 1}, +#else + {"ENDIAN_LITTLE", 0}, +#endif + +#ifdef ENDIAN_BIG + {"ENDIAN_BIG", 1}, +#else + {"ENDIAN_BIG", 0}, +#endif + +#ifdef ENDIAN_32BITWORD + {"ENDIAN_32BITWORD", 1}, +#else + {"ENDIAN_32BITWORD", 0}, +#endif + +#ifdef ENDIAN_64BITWORD + {"ENDIAN_64BITWORD", 1}, +#else + {"ENDIAN_64BITWORD", 0}, +#endif + +#ifdef ENDIAN_NEUTRAL + {"ENDIAN_NEUTRAL", 1}, +#else + {"ENDIAN_NEUTRAL", 0}, +#endif +}; + + +/* crypt_get_constant() + * valueout will be the value of the named constant + * return -1 if named item not found + */ +int crypt_get_constant(const char* namein, int *valueout) { + int i; + int _crypt_constants_len = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]); + for (i=0; i<_crypt_constants_len; i++) { + if (strcmp(_crypt_constants[i].name, namein) == 0) { + *valueout = _crypt_constants[i].value; + return 0; + } + } + return 1; +} + +/* crypt_list_all_constants() + * if names_list is NULL, names_list_size will be the minimum + * number of bytes needed to receive the complete names_list + * if names_list is NOT NULL, names_list must be the addr of + * sufficient memory allocated into which the names_list + * is to be written. Also, the value in names_list_size + * sets the upper bound of the number of characters to be + * written. + * a -1 return value signifies insufficient space made available + */ +int crypt_list_all_constants(char *names_list, unsigned long *names_list_size) { + int i; + unsigned long total_len = 0; + char number[32]; + int number_len; + int count = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]); + + /* calculate amount of memory required for the list */ + for (i=0; i= sizeof(number))) + return -1; + total_len += number_len + 1; + /* this last +1 is for newlines (and ending NULL) */ + } + + if (names_list == NULL) { + *names_list_size = total_len; + } else { + if (total_len > *names_list_size) { + return -1; + } + /* build the names list */ + char *ptr = names_list; + for (i=0; i= sizeof(number))) + return -1; + total_len += strlen(number) + 1; + /* this last +1 is for newlines (and ending NULL) */ + } + + if (names_list == NULL) { + *names_list_size = total_len; + } else { + if (total_len > *names_list_size) { + return -1; + } + /* build the names list */ + char *ptr = names_list; + for (i=0; i