Explorar el Código

Merge pull request #353 from libtom/minor/improvements

Minor improvements
Steffen Jaeckel hace 7 años
padre
commit
70fd5dd83d

+ 31 - 2
doc/crypt.tex

@@ -6581,6 +6581,7 @@ int base64url_strict_decode(const unsigned char *in,  unsigned long len,
 
 The library provides functions to encode and decode a Base32 coding scheme. The supported mappings are:
 
+\begin{figure}[H]
 \begin{center}
 \begin{tabular}{|l|l|l|}
      \hline \textbf{id} & \textbf{Mapping} & \textbf{Name} \\
@@ -6591,6 +6592,8 @@ The library provides functions to encode and decode a Base32 coding scheme. The
      \hline
 \end{tabular}
 \end{center}
+\caption{Base32 coding schemes}
+\end{figure}
 
 To encode a binary string in base32 call:
 
@@ -6598,7 +6601,7 @@ To encode a binary string in base32 call:
 \begin{verbatim}
 int base32_encode(const unsigned char *in,
                         unsigned long  len,
-                        unsigned char *out,
+                                 char *out,
                         unsigned long *outlen,
                         base32_alphabet id);
 \end{verbatim}
@@ -6610,13 +6613,39 @@ To decode a base32 string call:
 
 \index{base32\_decode()}
 \begin{verbatim}
-int base32_decode(const unsigned char *in,
+int base32_decode(const          char *in,
                         unsigned long  len,
                         unsigned char *out,
                         unsigned long *outlen,
                         base32_alphabet id);
 \end{verbatim}
 
+
+\mysection{Base16 Encoding and Decoding}
+
+The library provides functions to encode and decode a Base16 a.k.a Hex string.
+
+To encode a binary string in base16 call:
+
+\index{base32\_encode()}
+\begin{verbatim}
+int base16_encode(const unsigned char *in,  unsigned long  inlen,
+                                 char *out, unsigned long *outlen,
+                                 int  caps);
+\end{verbatim}
+
+Where \textit{in} is the binary string,
+\textit{out} is where the ASCII output is placed
+and \textit{caps} is either $0$ to use lower-letter \textit{a..f} or else to use caps \textit{A..F}.
+
+To decode a base16 string call:
+
+\index{base32\_decode()}
+\begin{verbatim}
+int base16_decode(const          char *in,
+                        unsigned char *out, unsigned long *outlen);
+\end{verbatim}
+
 \mysection{Primality Testing}
 \index{Primality Testing}
 The library includes primality testing and random prime functions as well.  The primality tester will perform the test in

+ 12 - 0
libtomcrypt_VS2008.vcproj

@@ -1375,6 +1375,18 @@
 				RelativePath="src\misc\zeromem.c"
 				>
 			</File>
+			<Filter
+				Name="base16"
+				>
+				<File
+					RelativePath="src\misc\base16\base16_decode.c"
+					>
+				</File>
+				<File
+					RelativePath="src\misc\base16\base16_encode.c"
+					>
+				</File>
+			</Filter>
 			<Filter
 				Name="base32"
 				>

+ 22 - 21
makefile.mingw

@@ -91,21 +91,22 @@ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \
 src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \
 src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \
 src/math/radix_to_bin.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \
-src/misc/base32/base32_decode.o src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o \
-src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/compare_testvector.o \
-src/misc/copy_or_zeromem.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \
-src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \
-src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \
-src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
-src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
-src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_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_prng_rng_descriptor.o \
-src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \
-src/misc/crypt/crypt_register_all_prngs.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_sizes.o \
+src/misc/base16/base16_decode.o src/misc/base16/base16_encode.o src/misc/base32/base32_decode.o \
+src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o \
+src/misc/burn_stack.o src/misc/compare_testvector.o src/misc/copy_or_zeromem.o src/misc/crc32.o \
+src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
+src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \
+src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \
+src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \
+src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \
+src/misc/crypt/crypt_find_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_prng_rng_descriptor.o src/misc/crypt/crypt_register_all_ciphers.o \
+src/misc/crypt/crypt_register_all_hashes.o src/misc/crypt/crypt_register_all_prngs.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_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/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \
@@ -203,12 +204,12 @@ src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
 src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
 
 #List of test objects to compile
-TOBJECTS=tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o tests/common.o \
-tests/der_test.o tests/dh_test.o tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o \
-tests/mac_test.o tests/misc_test.o tests/modes_test.o tests/mpi_test.o tests/multi_test.o tests/no_prng.o \
-tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o \
-tests/pkcs_1_test.o tests/prng_test.o tests/rotate_test.o tests/rsa_test.o tests/store_test.o \
-tests/test.o
+TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \
+tests/common.o tests/der_test.o tests/dh_test.o tests/dsa_test.o tests/ecc_test.o tests/file_test.o \
+tests/katja_test.o tests/mac_test.o tests/misc_test.o tests/modes_test.o tests/mpi_test.o \
+tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o \
+tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o tests/prng_test.o \
+tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o
 
 #The following headers will be installed by "make install"
 HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \

+ 22 - 21
makefile.msvc

@@ -84,21 +84,22 @@ src/mac/xcbc/xcbc_file.obj src/mac/xcbc/xcbc_init.obj src/mac/xcbc/xcbc_memory.o
 src/mac/xcbc/xcbc_memory_multi.obj src/mac/xcbc/xcbc_process.obj src/mac/xcbc/xcbc_test.obj \
 src/math/fp/ltc_ecc_fp_mulmod.obj src/math/gmp_desc.obj src/math/ltm_desc.obj src/math/multi.obj \
 src/math/radix_to_bin.obj src/math/rand_bn.obj src/math/rand_prime.obj src/math/tfm_desc.obj src/misc/adler32.obj \
-src/misc/base32/base32_decode.obj src/misc/base32/base32_encode.obj src/misc/base64/base64_decode.obj \
-src/misc/base64/base64_encode.obj src/misc/burn_stack.obj src/misc/compare_testvector.obj \
-src/misc/copy_or_zeromem.obj src/misc/crc32.obj src/misc/crypt/crypt.obj src/misc/crypt/crypt_argchk.obj \
-src/misc/crypt/crypt_cipher_descriptor.obj src/misc/crypt/crypt_cipher_is_valid.obj \
-src/misc/crypt/crypt_constants.obj src/misc/crypt/crypt_find_cipher.obj \
-src/misc/crypt/crypt_find_cipher_any.obj src/misc/crypt/crypt_find_cipher_id.obj \
-src/misc/crypt/crypt_find_hash.obj src/misc/crypt/crypt_find_hash_any.obj \
-src/misc/crypt/crypt_find_hash_id.obj src/misc/crypt/crypt_find_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_prng_rng_descriptor.obj \
-src/misc/crypt/crypt_register_all_ciphers.obj src/misc/crypt/crypt_register_all_hashes.obj \
-src/misc/crypt/crypt_register_all_prngs.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_sizes.obj \
+src/misc/base16/base16_decode.obj src/misc/base16/base16_encode.obj src/misc/base32/base32_decode.obj \
+src/misc/base32/base32_encode.obj src/misc/base64/base64_decode.obj src/misc/base64/base64_encode.obj \
+src/misc/burn_stack.obj src/misc/compare_testvector.obj src/misc/copy_or_zeromem.obj src/misc/crc32.obj \
+src/misc/crypt/crypt.obj src/misc/crypt/crypt_argchk.obj src/misc/crypt/crypt_cipher_descriptor.obj \
+src/misc/crypt/crypt_cipher_is_valid.obj src/misc/crypt/crypt_constants.obj \
+src/misc/crypt/crypt_find_cipher.obj src/misc/crypt/crypt_find_cipher_any.obj \
+src/misc/crypt/crypt_find_cipher_id.obj src/misc/crypt/crypt_find_hash.obj \
+src/misc/crypt/crypt_find_hash_any.obj src/misc/crypt/crypt_find_hash_id.obj \
+src/misc/crypt/crypt_find_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_prng_rng_descriptor.obj src/misc/crypt/crypt_register_all_ciphers.obj \
+src/misc/crypt/crypt_register_all_hashes.obj src/misc/crypt/crypt_register_all_prngs.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_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/mem_neq.obj src/misc/pk_get_oid.obj src/misc/pkcs5/pkcs_5_1.obj \
@@ -196,12 +197,12 @@ src/stream/sober128/sober128_stream.obj src/stream/sober128/sober128_test.obj \
 src/stream/sosemanuk/sosemanuk.obj src/stream/sosemanuk/sosemanuk_test.obj
 
 #List of test objects to compile
-TOBJECTS=tests/base32_test.obj tests/base64_test.obj tests/cipher_hash_test.obj tests/common.obj \
-tests/der_test.obj tests/dh_test.obj tests/dsa_test.obj tests/ecc_test.obj tests/file_test.obj tests/katja_test.obj \
-tests/mac_test.obj tests/misc_test.obj tests/modes_test.obj tests/mpi_test.obj tests/multi_test.obj tests/no_prng.obj \
-tests/pkcs_1_eme_test.obj tests/pkcs_1_emsa_test.obj tests/pkcs_1_oaep_test.obj tests/pkcs_1_pss_test.obj \
-tests/pkcs_1_test.obj tests/prng_test.obj tests/rotate_test.obj tests/rsa_test.obj tests/store_test.obj \
-tests/test.obj
+TOBJECTS=tests/base16_test.obj tests/base32_test.obj tests/base64_test.obj tests/cipher_hash_test.obj \
+tests/common.obj tests/der_test.obj tests/dh_test.obj tests/dsa_test.obj tests/ecc_test.obj tests/file_test.obj \
+tests/katja_test.obj tests/mac_test.obj tests/misc_test.obj tests/modes_test.obj tests/mpi_test.obj \
+tests/multi_test.obj tests/no_prng.obj tests/pkcs_1_eme_test.obj tests/pkcs_1_emsa_test.obj \
+tests/pkcs_1_oaep_test.obj tests/pkcs_1_pss_test.obj tests/pkcs_1_test.obj tests/prng_test.obj \
+tests/rotate_test.obj tests/rsa_test.obj tests/store_test.obj tests/test.obj
 
 #The following headers will be installed by "make install"
 HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \

+ 22 - 21
makefile.unix

@@ -101,21 +101,22 @@ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \
 src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \
 src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \
 src/math/radix_to_bin.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \
-src/misc/base32/base32_decode.o src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o \
-src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/compare_testvector.o \
-src/misc/copy_or_zeromem.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \
-src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \
-src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \
-src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
-src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
-src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_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_prng_rng_descriptor.o \
-src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \
-src/misc/crypt/crypt_register_all_prngs.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_sizes.o \
+src/misc/base16/base16_decode.o src/misc/base16/base16_encode.o src/misc/base32/base32_decode.o \
+src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o \
+src/misc/burn_stack.o src/misc/compare_testvector.o src/misc/copy_or_zeromem.o src/misc/crc32.o \
+src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
+src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \
+src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \
+src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \
+src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \
+src/misc/crypt/crypt_find_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_prng_rng_descriptor.o src/misc/crypt/crypt_register_all_ciphers.o \
+src/misc/crypt/crypt_register_all_hashes.o src/misc/crypt/crypt_register_all_prngs.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_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/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \
@@ -213,12 +214,12 @@ src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
 src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
 
 #List of test objects to compile (all goes to libtomcrypt_prof.a)
-TOBJECTS=tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o tests/common.o \
-tests/der_test.o tests/dh_test.o tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o \
-tests/mac_test.o tests/misc_test.o tests/modes_test.o tests/mpi_test.o tests/multi_test.o tests/no_prng.o \
-tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o \
-tests/pkcs_1_test.o tests/prng_test.o tests/rotate_test.o tests/rsa_test.o tests/store_test.o \
-tests/test.o
+TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \
+tests/common.o tests/der_test.o tests/dh_test.o tests/dsa_test.o tests/ecc_test.o tests/file_test.o \
+tests/katja_test.o tests/mac_test.o tests/misc_test.o tests/modes_test.o tests/mpi_test.o \
+tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o \
+tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o tests/prng_test.o \
+tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o
 
 #The following headers will be installed by "make install"
 HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \

+ 22 - 21
makefile_include.mk

@@ -241,21 +241,22 @@ src/mac/xcbc/xcbc_file.o src/mac/xcbc/xcbc_init.o src/mac/xcbc/xcbc_memory.o \
 src/mac/xcbc/xcbc_memory_multi.o src/mac/xcbc/xcbc_process.o src/mac/xcbc/xcbc_test.o \
 src/math/fp/ltc_ecc_fp_mulmod.o src/math/gmp_desc.o src/math/ltm_desc.o src/math/multi.o \
 src/math/radix_to_bin.o src/math/rand_bn.o src/math/rand_prime.o src/math/tfm_desc.o src/misc/adler32.o \
-src/misc/base32/base32_decode.o src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o \
-src/misc/base64/base64_encode.o src/misc/burn_stack.o src/misc/compare_testvector.o \
-src/misc/copy_or_zeromem.o src/misc/crc32.o src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o \
-src/misc/crypt/crypt_cipher_descriptor.o src/misc/crypt/crypt_cipher_is_valid.o \
-src/misc/crypt/crypt_constants.o src/misc/crypt/crypt_find_cipher.o \
-src/misc/crypt/crypt_find_cipher_any.o src/misc/crypt/crypt_find_cipher_id.o \
-src/misc/crypt/crypt_find_hash.o src/misc/crypt/crypt_find_hash_any.o \
-src/misc/crypt/crypt_find_hash_id.o src/misc/crypt/crypt_find_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_prng_rng_descriptor.o \
-src/misc/crypt/crypt_register_all_ciphers.o src/misc/crypt/crypt_register_all_hashes.o \
-src/misc/crypt/crypt_register_all_prngs.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_sizes.o \
+src/misc/base16/base16_decode.o src/misc/base16/base16_encode.o src/misc/base32/base32_decode.o \
+src/misc/base32/base32_encode.o src/misc/base64/base64_decode.o src/misc/base64/base64_encode.o \
+src/misc/burn_stack.o src/misc/compare_testvector.o src/misc/copy_or_zeromem.o src/misc/crc32.o \
+src/misc/crypt/crypt.o src/misc/crypt/crypt_argchk.o src/misc/crypt/crypt_cipher_descriptor.o \
+src/misc/crypt/crypt_cipher_is_valid.o src/misc/crypt/crypt_constants.o \
+src/misc/crypt/crypt_find_cipher.o src/misc/crypt/crypt_find_cipher_any.o \
+src/misc/crypt/crypt_find_cipher_id.o src/misc/crypt/crypt_find_hash.o \
+src/misc/crypt/crypt_find_hash_any.o src/misc/crypt/crypt_find_hash_id.o \
+src/misc/crypt/crypt_find_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_prng_rng_descriptor.o src/misc/crypt/crypt_register_all_ciphers.o \
+src/misc/crypt/crypt_register_all_hashes.o src/misc/crypt/crypt_register_all_prngs.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_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/mem_neq.o src/misc/pk_get_oid.o src/misc/pkcs5/pkcs_5_1.o \
@@ -353,12 +354,12 @@ src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_test.o \
 src/stream/sosemanuk/sosemanuk.o src/stream/sosemanuk/sosemanuk_test.o
 
 # List of test objects to compile (all goes to libtomcrypt_prof.a)
-TOBJECTS=tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o tests/common.o \
-tests/der_test.o tests/dh_test.o tests/dsa_test.o tests/ecc_test.o tests/file_test.o tests/katja_test.o \
-tests/mac_test.o tests/misc_test.o tests/modes_test.o tests/mpi_test.o tests/multi_test.o tests/no_prng.o \
-tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o \
-tests/pkcs_1_test.o tests/prng_test.o tests/rotate_test.o tests/rsa_test.o tests/store_test.o \
-tests/test.o
+TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/cipher_hash_test.o \
+tests/common.o tests/der_test.o tests/dh_test.o tests/dsa_test.o tests/ecc_test.o tests/file_test.o \
+tests/katja_test.o tests/mac_test.o tests/misc_test.o tests/modes_test.o tests/mpi_test.o \
+tests/multi_test.o tests/no_prng.o tests/pkcs_1_eme_test.o tests/pkcs_1_emsa_test.o \
+tests/pkcs_1_oaep_test.o tests/pkcs_1_pss_test.o tests/pkcs_1_test.o tests/prng_test.o \
+tests/rotate_test.o tests/rsa_test.o tests/store_test.o tests/test.o
 
 # The following headers will be installed by "make install"
 HEADERS=src/headers/tomcrypt.h src/headers/tomcrypt_argchk.h src/headers/tomcrypt_cfg.h \

+ 2 - 0
src/headers/tomcrypt_custom.h

@@ -450,6 +450,8 @@
 #define LTC_BASE64_URL
 /* Base32 encoding/decoding */
 #define LTC_BASE32
+/* Base16/hex encoding/decoding */
+#define LTC_BASE16
 
 /* Keep LTC_NO_HKDF for compatibility reasons
  * superseeded by LTC_NO_MISC*/

+ 11 - 2
src/headers/tomcrypt_misc.h

@@ -39,13 +39,22 @@ typedef enum {
    BASE32_CROCKFORD = 3
 } base32_alphabet;
 int base32_encode(const unsigned char *in,  unsigned long inlen,
-                        unsigned char *out, unsigned long *outlen,
+                                 char *out, unsigned long *outlen,
                         base32_alphabet id);
-int base32_decode(const unsigned char *in,  unsigned long inlen,
+int base32_decode(const          char *in,  unsigned long inlen,
                         unsigned char *out, unsigned long *outlen,
                         base32_alphabet id);
 #endif
 
+/* ---- BASE16 Routines ---- */
+#ifdef LTC_BASE16
+int base16_encode(const unsigned char *in,  unsigned long  inlen,
+                                 char *out, unsigned long *outlen,
+                                 int  caps);
+int base16_decode(const          char *in,
+                        unsigned char *out, unsigned long *outlen);
+#endif
+
 /* ===> LTC_HKDF -- RFC5869 HMAC-based Key Derivation Function <=== */
 #ifdef LTC_HKDF
 

+ 11 - 9
src/headers/tomcrypt_pk.h

@@ -9,14 +9,16 @@
 
 /* ---- NUMBER THEORY ---- */
 
-enum {
-   PK_PUBLIC=0,
-   PK_PRIVATE=1
+enum public_key_type {
+   /* Refers to the public key */
+   PK_PUBLIC      = 0x0000,
+   /* Refers to the private key */
+   PK_PRIVATE     = 0x0001,
+
+   /* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */
+   PK_STD         = 0x1000,
 };
 
-/* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */
-#define PK_STD          0x1000
-
 int rand_prime(void *N, long len, prng_state *prng, int wprng);
 
 #ifdef LTC_SOURCE
@@ -847,12 +849,12 @@ int der_length_generalizedtime(ltc_generalizedtime *gtime, unsigned long *outlen
 /* internal helper functions */
 /* SUBJECT PUBLIC KEY INFO */
 int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen,
-        unsigned int algorithm, void* public_key, unsigned long public_key_len,
-        unsigned long parameters_type, void* parameters, unsigned long parameters_len);
+        unsigned int algorithm, const void* public_key, unsigned long public_key_len,
+        ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len);
 
 int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen,
         unsigned int algorithm, void* public_key, unsigned long* public_key_len,
-        unsigned long parameters_type, void* parameters, unsigned long *parameters_len);
+        ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len);
 #endif /* LTC_SOURCE */
 
 #endif

+ 65 - 0
src/misc/base16/base16_decode.c

@@ -0,0 +1,65 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ */
+
+#include "tomcrypt.h"
+
+/**
+   @file base16_decode.c
+   Base16/Hex decode a string.
+   Based on https://stackoverflow.com/a/23898449
+   Adapted for libtomcrypt by Steffen Jaeckel
+*/
+
+#ifdef LTC_BASE16
+
+/**
+   Base16 decode a string
+   @param in       The Base16 string to decode
+   @param out      [out] The destination of the binary decoded data
+   @param outlen   [in/out] The max size and resulting size of the decoded data
+   @return CRYPT_OK if successful
+*/
+int base16_decode(const          char *in,
+                        unsigned char *out, unsigned long *outlen)
+{
+   unsigned long pos, in_len, out_len;
+   unsigned char idx0;
+   unsigned char idx1;
+
+   const unsigned char hashmap[] = {
+         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */
+         0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 89:;<=>? */
+         0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, /* @ABCDEFG */
+         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* HIJKLMNO */
+         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* PQRSTUVW */
+         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* XYZ[\]^_ */
+         0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, /* `abcdefg */
+   };
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   in_len = strlen(in);
+   if ((in_len % 2) == 1) return CRYPT_INVALID_PACKET;
+   out_len = *outlen * 2;
+   for (pos = 0; ((pos + 1 < out_len) && (pos + 1 < in_len)); pos += 2) {
+      idx0 = (unsigned char) (in[pos + 0] & 0x1F) ^ 0x10;
+      idx1 = (unsigned char) (in[pos + 1] & 0x1F) ^ 0x10;
+      out[pos / 2] = (unsigned char) (hashmap[idx0] << 4) | hashmap[idx1];
+   }
+   *outlen = pos / 2;
+   return CRYPT_OK;
+}
+
+#endif
+
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */

+ 71 - 0
src/misc/base16/base16_encode.c

@@ -0,0 +1,71 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ */
+
+#include "tomcrypt.h"
+
+/**
+   @file base16_encode.c
+   Base16/Hex encode a string, Steffen Jaeckel
+*/
+
+#ifdef LTC_BASE16
+
+/**
+   Base16 encode a buffer
+   @param in       The input buffer to encode
+   @param inlen    The length of the input buffer
+   @param out      [out] The destination of the Base16 encoded data
+   @param outlen   [in/out] The max size and resulting size of the encoded data
+   @param caps     Output 'a-f' on 0 and 'A-F' otherwise.
+   @return CRYPT_OK if successful
+*/
+int base16_encode(const unsigned char *in,  unsigned long  inlen,
+                                 char *out, unsigned long *outlen,
+                                  int  caps)
+{
+   unsigned long i, x;
+   const char *alphabet;
+   const char *alphabets[2] = {
+      "0123456789abcdef",
+      "0123456789ABCDEF",
+   };
+
+   LTC_ARGCHK(in     != NULL);
+   LTC_ARGCHK(out    != NULL);
+   LTC_ARGCHK(outlen != NULL);
+
+   /* check the sizes */
+   x = inlen * 2 + 1;
+
+   if (x < inlen) return CRYPT_OVERFLOW;
+
+   if (*outlen < x) {
+      *outlen = x;
+      return CRYPT_BUFFER_OVERFLOW;
+   }
+   *outlen = x;
+
+   if (caps == 0) alphabet = alphabets[0];
+   else alphabet = alphabets[1];
+
+   x -= 1;
+   for (i = 0; i < x; i += 2) {
+      out[i]   = alphabet[(in[i/2] >> 4) & 0x0f];
+      out[i+1] = alphabet[in[i/2] & 0x0f];
+   }
+   out[x] = '\0';
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */

+ 4 - 5
src/misc/base32/base32_decode.c

@@ -20,14 +20,14 @@
    @param id       Alphabet to use BASE32_RFC4648, BASE32_BASE32HEX, BASE32_ZBASE32 or BASE32_CROCKFORD
    @return CRYPT_OK if successful
 */
-int base32_decode(const unsigned char *in,  unsigned long inlen,
+int base32_decode(const          char *in,  unsigned long inlen,
                         unsigned char *out, unsigned long *outlen,
                         base32_alphabet id)
 {
    unsigned long x;
    int y = 0;
    ulong64 t = 0;
-   unsigned char c;
+   char c;
    const unsigned char *map;
    const unsigned char tables[4][43] = {
       {  /* id = BASE32_RFC4648 : ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 */
@@ -90,11 +90,10 @@ int base32_decode(const unsigned char *in,  unsigned long inlen,
       c = in[x];
       /* convert to upper case */
       if ((c >= 'a') && (c <= 'z')) c -= 32;
-      /* '0' = 48 .. 'Z' = 90 */
-      if (c < 48 || c > 90 || map[c-48] > 31) {
+      if (c < '0' || c > 'Z' || map[c-'0'] > 31) {
          return CRYPT_INVALID_PACKET;
       }
-      t = (t<<5)|map[c-48];
+      t = (t<<5) | map[c-'0'];
       if (++y == 8) {
          *out++ = (unsigned char)((t>>32) & 255);
          *out++ = (unsigned char)((t>>24) & 255);

+ 3 - 3
src/misc/base32/base32_encode.c

@@ -21,11 +21,11 @@
    @return CRYPT_OK if successful
 */
 int base32_encode(const unsigned char *in,  unsigned long inlen,
-                        unsigned char *out, unsigned long *outlen,
+                                 char *out, unsigned long *outlen,
                         base32_alphabet id)
 {
    unsigned long i, x;
-   unsigned char *codes;
+   const char *codes;
    const char *alphabet[4] = {
       "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",     /* id = BASE32_RFC4648   */
       "0123456789ABCDEFGHIJKLMNOPQRSTUV",     /* id = BASE32_BASE32HEX */
@@ -53,7 +53,7 @@ int base32_encode(const unsigned char *in,  unsigned long inlen,
    }
    *outlen = x;
 
-   codes = (unsigned char*)alphabet[id];
+   codes = alphabet[id];
    x = 5 * (inlen / 5);
    for (i = 0; i < x; i += 5) {
       *out++ = codes[(in[0] >> 3) & 0x1F];

+ 3 - 0
src/misc/crypt/crypt.c

@@ -414,6 +414,9 @@ const char *crypt_build_settings =
 #if defined(LTC_BASE32)
     " BASE32 "
 #endif
+#if defined(LTC_BASE16)
+    " BASE16 "
+#endif
 #if defined(LTC_CRC32)
     " CRC32 "
 #endif

+ 17 - 8
src/pk/asn1/x509/x509_decode_subject_public_key_info.c

@@ -39,10 +39,10 @@
 */
 int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen,
         unsigned int algorithm, void* public_key, unsigned long* public_key_len,
-        unsigned long parameters_type, void* parameters, unsigned long *parameters_len)
+        ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long *parameters_len)
 {
    int err;
-   unsigned long len;
+   unsigned long len, alg_id_num;
    oid_st oid;
    unsigned char *tmpbuf;
    unsigned long  tmpoid[16];
@@ -52,7 +52,9 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
    LTC_ARGCHK(in    != NULL);
    LTC_ARGCHK(inlen != 0);
    LTC_ARGCHK(public_key_len != NULL);
-   LTC_ARGCHK(parameters_len != NULL);
+   if (parameters_type != LTC_ASN1_EOL) {
+      LTC_ARGCHK(parameters_len != NULL);
+   }
 
    err = pk_get_oid(algorithm, &oid);
    if (err != CRYPT_OK) {
@@ -68,20 +70,27 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
 
    /* this includes the internal hash ID and optional params (NULL in this case) */
    LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, sizeof(tmpoid)/sizeof(tmpoid[0]));
-   LTC_SET_ASN1(alg_id, 1, (ltc_asn1_type)parameters_type, parameters, *parameters_len);
+   if (parameters_type == LTC_ASN1_EOL) {
+      alg_id_num = 1;
+   }
+   else {
+      LTC_SET_ASN1(alg_id, 1, parameters_type, parameters, *parameters_len);
+      alg_id_num = 2;
+   }
 
    /* the actual format of the SSL DER key is odd, it stores a RSAPublicKey
     * in a **BIT** string ... so we have to extract it then proceed to convert bit to octet
     */
-   LTC_SET_ASN1(subject_pubkey, 0, LTC_ASN1_SEQUENCE, alg_id, 2);
+   LTC_SET_ASN1(subject_pubkey, 0, LTC_ASN1_SEQUENCE, alg_id, alg_id_num);
    LTC_SET_ASN1(subject_pubkey, 1, LTC_ASN1_RAW_BIT_STRING, tmpbuf, inlen*8U);
 
    err=der_decode_sequence(in, inlen, subject_pubkey, 2UL);
    if (err != CRYPT_OK) {
            goto LBL_ERR;
    }
-
-   *parameters_len = alg_id[1].size;
+   if (parameters_type != LTC_ASN1_EOL) {
+      *parameters_len = alg_id[1].size;
+   }
 
    if ((alg_id[0].size != oid.OIDlen) ||
         XMEMCMP(oid.OID, alg_id[0].data, oid.OIDlen * sizeof(oid.OID[0]))) {
@@ -91,7 +100,7 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
    }
 
    len = subject_pubkey[1].size/8;
-   if (*public_key_len > len) {
+   if (*public_key_len >= len) {
        XMEMCPY(public_key, subject_pubkey[1].data, len);
        *public_key_len = len;
     } else {

+ 3 - 3
src/pk/asn1/x509/x509_encode_subject_public_key_info.c

@@ -38,8 +38,8 @@
    @return CRYPT_OK on success
 */
 int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen,
-        unsigned int algorithm, void* public_key, unsigned long public_key_len,
-        unsigned long parameters_type, void* parameters, unsigned long parameters_len)
+        unsigned int algorithm, const void* public_key, unsigned long public_key_len,
+        ltc_asn1_type parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len)
 {
    int           err;
    ltc_asn1_list alg_id[2];
@@ -54,7 +54,7 @@ int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outle
    }
 
    LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, oid.OID,    oid.OIDlen);
-   LTC_SET_ASN1(alg_id, 1, (ltc_asn1_type)parameters_type,            parameters, parameters_len);
+   LTC_SET_ASN1(alg_id, 1, parameters_type,            parameters, parameters_len);
 
    return der_encode_sequence_multi(out, outlen,
         LTC_ASN1_SEQUENCE, (unsigned long)sizeof(alg_id)/sizeof(alg_id[0]), alg_id,

+ 53 - 0
tests/base16_test.c

@@ -0,0 +1,53 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ */
+
+#include  <tomcrypt_test.h>
+
+#ifdef LTC_BASE16
+
+int base16_test(void)
+{
+   unsigned char in[100], tmp[100];
+   char out[201];
+   unsigned char testin[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
+   const char *testout[2] = {
+      "0123456789abcdef",
+      "0123456789ABCDEF",
+   };
+   unsigned long x, l1, l2;
+   int idx;
+
+   for (idx = 0; idx < 2; idx++) {
+      for (x = 0; x < 100; x++) {
+         yarrow_read(in, x, &yarrow_prng);
+         l1 = sizeof(out);
+         DO(base16_encode(in, x, out, &l1, idx));
+         l2 = sizeof(tmp);
+         DO(base16_decode(out, tmp, &l2));
+         DO(do_compare_testvector(tmp, l2, in, x, "random base16", idx * 100 + x));
+      }
+   }
+
+   for (idx = 0; idx < 2; idx++) {
+      l1 = sizeof(out);
+      DO(base16_encode(testin, sizeof(testin), out, &l1, idx));
+      DO(do_compare_testvector(out, strlen(out), testout[idx], strlen(testout[idx]), "testout base16", idx));
+      l2 = sizeof(tmp);
+      DO(base16_decode(out, tmp, &l2));
+      DO(do_compare_testvector(tmp, l2, testin, sizeof(testin), "testin base16", idx));
+   }
+
+   return CRYPT_OK;
+}
+
+#endif
+
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */

+ 5 - 10
tests/base32_test.c

@@ -13,7 +13,8 @@
 
 int base32_test(void)
 {
-   unsigned char in[100], out[160], tmp[100];
+   unsigned char in[100], tmp[100];
+   char out[160];
    unsigned char testin[] = { 0x61,0xc2,0xcb,0xbc,0x5e,0x6d,0x2a,0x7a,0x1a,0x19,0x1a,0xae,0xc9,0x02,0xd4,0xbf,0x7d };
    const int testid[4] = {
       BASE32_RFC4648,
@@ -37,23 +38,17 @@ int base32_test(void)
          DO(base32_encode(in, x, out, &l1, testid[idx]));
          l2 = sizeof(tmp);
          DO(base32_decode(out, l1, tmp, &l2, testid[idx]));
-         if (compare_testvector(tmp, l2, in, x, "random base32", idx * 100 + x)) {
-            return CRYPT_FAIL_TESTVECTOR;
-         }
+         DO(do_compare_testvector(tmp, l2, in, x, "random base32", idx * 100 + x));
       }
    }
 
    for (idx = 0; idx < 4; idx++) {
       l1 = sizeof(out);
       DO(base32_encode(testin, sizeof(testin), out, &l1, testid[idx]));
-      if (compare_testvector(out, l1, testout[idx], strlen(testout[idx]), "testout base32", idx)) {
-         return CRYPT_FAIL_TESTVECTOR;
-      }
+      DO(do_compare_testvector(out, l1, testout[idx], strlen(testout[idx]), "testout base32", idx));
       l2 = sizeof(tmp);
       DO(base32_decode(out, l1, tmp, &l2, testid[idx]));
-      if (compare_testvector(tmp, l2, testin, sizeof(testin), "testin base32", idx)) {
-         return CRYPT_FAIL_TESTVECTOR;
-      }
+      DO(do_compare_testvector(tmp, l2, testin, sizeof(testin), "testin base32", idx));
    }
 
    return CRYPT_OK;

+ 5 - 13
tests/base64_test.c

@@ -67,18 +67,14 @@ int base64_test(void)
           DO(base64url_strict_decode((unsigned char*)url_cases[x].s, slen1, out, &l1));
        else
           DO(base64url_decode((unsigned char*)url_cases[x].s, slen1, out, &l1));
-       if (compare_testvector(out, l1, special_case, sizeof(special_case) - 1, "base64url decode", x)) {
-           return 1;
-       }
+       DO(do_compare_testvector(out, l1, special_case, sizeof(special_case) - 1, "base64url decode", x));
        if(x < 2) {
           l2 = sizeof(tmp);
           if(x == 0)
              DO(base64url_encode(out, l1, tmp, &l2));
           else
              DO(base64url_strict_encode(out, l1, tmp, &l2));
-          if (compare_testvector(tmp, l2, url_cases[x].s, strlen(url_cases[x].s), "base64url encode", x)) {
-              return 1;
-          }
+          DO(do_compare_testvector(tmp, l2, url_cases[x].s, strlen(url_cases[x].s), "base64url encode", x));
        }
    }
 
@@ -94,10 +90,8 @@ int base64_test(void)
        DO(base64_encode((unsigned char*)cases[x].s, slen1, out, &l1));
        l2 = sizeof(tmp);
        DO(base64_strict_decode(out, l1, tmp, &l2));
-       if (compare_testvector(out, l1, cases[x].b64, strlen(cases[x].b64), "base64 encode", x) ||
-             compare_testvector(tmp, l2, cases[x].s, slen1, "base64 decode", x)) {
-           return 1;
-       }
+       DO(do_compare_testvector(out, l1, cases[x].b64, strlen(cases[x].b64), "base64 encode", x));
+       DO(do_compare_testvector(tmp, l2, cases[x].s, slen1, "base64 decode", x));
    }
 
    for  (x = 0; x < 64; x++) {
@@ -106,9 +100,7 @@ int base64_test(void)
        DO(base64_encode(in, x, out, &l1));
        l2 = sizeof(tmp);
        DO(base64_decode(out, l1, tmp, &l2));
-       if (compare_testvector(tmp, x, in, x, "random base64", x)) {
-           return 1;
-       }
+       DO(do_compare_testvector(tmp, x, in, x, "random base64", x));
    }
 
    x--;

+ 9 - 0
tests/common.c

@@ -61,6 +61,15 @@ void print_hex(const char* what, const void* v, const unsigned long l)
   }
 }
 
+int do_compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
+{
+   if (compare_testvector(is, is_len, should, should_len, what, which) == 0) {
+      return CRYPT_OK;
+   } else {
+      return CRYPT_FAIL_TESTVECTOR;
+   }
+}
+
 prng_state yarrow_prng;
 
 /* ref:         $Format:%D$ */

+ 2 - 0
tests/common.h

@@ -25,6 +25,8 @@ void run_cmd(int res, int line, const char *file, const char *cmd, const char *a
 
 void print_hex(const char* what, const void* v, const unsigned long l);
 
+int do_compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which);
+
 #endif /* DEMOS_COMMON_H_ */
 
 /* ref:         $Format:%D$ */

+ 10 - 5
tests/der_test.c

@@ -17,10 +17,6 @@ int der_test(void)
 
 #else
 
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <dirent.h>
-
 #if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1
 #define LTC_DER_TESTS_PRINT_FLEXI
 #endif
@@ -1242,7 +1238,7 @@ static void der_Xcode_run(const der_Xcode_t* x)
       d2 = XREALLOC(d2, l2 * x->type_sz);
    }
    DO(x->decode(d1, l1, d2, &l2));
-   DO(compare_testvector(d2, (l2/x->factor) * x->type_sz, x->in, x->in_sz, x->what, __LINE__) == 0 ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR);
+   DO(do_compare_testvector(d2, (l2/x->factor) * x->type_sz, x->in, x->in_sz, x->what, __LINE__));
    XFREE(d2);
    XFREE(d1);
 }
@@ -1314,6 +1310,12 @@ static void der_Xcode_test(void)
    mp_clear(mpinteger);
 }
 
+#if !((defined(_WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__))
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+
 static off_t fsize(const char *filename)
 {
    struct stat st;
@@ -1375,6 +1377,7 @@ static void der_asn1_test(void)
    if (f != NULL) fclose(f);
    closedir(d);
 }
+#endif
 
 
 static void _der_regression_test(void)
@@ -1613,7 +1616,9 @@ int der_test(void)
 
    der_Xcode_test();
 
+#if !((defined(_WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__))
    der_asn1_test();
+#endif
 
    der_custom_test();
 

+ 11 - 55
tests/dh_test.c

@@ -134,11 +134,7 @@ static int _dhparam_test(void)
       return CRYPT_ERROR;
    }
    DO(mp_to_unsigned_bin(k.prime, buf));
-   if (compare_testvector(buf, sizeof(prime), prime, sizeof(prime), "dhparam_test", 1)) {
-      printf("dhparam_test: prime mismatch\n");
-      dh_free(&k);
-      return CRYPT_ERROR;
-   }
+   DO(do_compare_testvector(buf, sizeof(prime), prime, sizeof(prime), "dhparam_test: prime mismatch", 1));
    if (mp_cmp_d(k.base, 2) != LTC_MP_EQ) {
       printf("dhparam_test: base mismatch\n");
       dh_free(&k);
@@ -272,32 +268,16 @@ static int _set_test(void)
 
       len = sizeof(buf);
       DO(dh_export(buf, &len, PK_PRIVATE, &k1));
-      if (compare_testvector(buf, len, export_private, sizeof(export_private), "radix_test", i*10 + 0)) {
-         printf("radix_test: dh_export+PK_PRIVATE mismatch\n");
-         dh_free(&k1);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, export_private, sizeof(export_private), "radix_test: dh_export+PK_PRIVATE mismatch", i*10 + 0));
       len = sizeof(buf);
       DO(dh_export(buf, &len, PK_PUBLIC, &k1));
-      if (compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test", i*10 + 1)) {
-         printf("radix_test: dh_export+PK_PUBLIC mismatch\n");
-         dh_free(&k1);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 1));
       len = sizeof(buf);
       DO(dh_export_key(buf, &len, PK_PRIVATE, &k1));
-      if (compare_testvector(buf, len, xbin, sizeof(xbin), "radix_test", i*10 + 2)) {
-         printf("radix_test: dh_export+PK_PRIVATE mismatch\n");
-         dh_free(&k1);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, xbin, sizeof(xbin), "radix_test: dh_export+PK_PRIVATE mismatch", i*10 + 2));
       len = sizeof(buf);
       DO(dh_export_key(buf, &len, PK_PUBLIC, &k1));
-      if (compare_testvector(buf, len, ybin, sizeof(ybin), "radix_test", i*10 + 3)) {
-         printf("radix_test: dh_export+PK_PUBLIC mismatch\n");
-         dh_free(&k1);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, ybin, sizeof(ybin), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 3));
       dh_free(&k1);
 
       DO(dh_set_pg(test[i].p, test[i].plen, test[i].g, test[i].glen, &k1));
@@ -305,18 +285,10 @@ static int _set_test(void)
 
       len = sizeof(buf);
       DO(dh_export(buf, &len, PK_PRIVATE, &k1));
-      if (compare_testvector(buf, len, export_private, sizeof(export_private), "radix_test", i*10 + 4)) {
-         printf("radix_test: dh_export+PK_PRIVATE mismatch\n");
-         dh_free(&k1);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, export_private, sizeof(export_private), "radix_test: dh_export+PK_PRIVATE mismatc", i*10 + 4));
       len = sizeof(buf);
       DO(dh_export(buf, &len, PK_PUBLIC, &k1));
-      if (compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test", i*10 + 5)) {
-         printf("radix_test: dh_export+PK_PUBLIC mismatch\n");
-         dh_free(&k1);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 5));
       dh_free(&k1);
 
       DO(dh_set_pg(test[i].p, test[i].plen, test[i].g, test[i].glen, &k2));
@@ -324,18 +296,10 @@ static int _set_test(void)
 
       len = sizeof(buf);
       DO(dh_export(buf, &len, PK_PUBLIC, &k2));
-      if (compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test", i*10 + 6)) {
-         printf("radix_test: dh_export+PK_PUBLIC mismatch\n");
-         dh_free(&k2);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 6));
       len = sizeof(buf);
       DO(dh_export_key(buf, &len, PK_PUBLIC, &k2));
-      if (compare_testvector(buf, len, ybin, sizeof(ybin), "radix_test", i*10 + 7)) {
-         printf("radix_test: dh_export+PK_PUBLIC mismatch\n");
-         dh_free(&k2);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, ybin, sizeof(ybin), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 7));
       dh_free(&k2);
 
       DO(dh_set_pg(test[i].p, test[i].plen, test[i].g, test[i].glen, &k3));
@@ -343,18 +307,10 @@ static int _set_test(void)
 
       len = mp_unsigned_bin_size(k3.prime);
       DO(mp_to_unsigned_bin(k3.prime, buf));
-      if (compare_testvector(buf, len, pbin, sizeof(pbin), "radix_test", i*10 + 8)) {
-         printf("radix_test: dh_make_key_ex prime mismatch\n");
-         dh_free(&k3);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, pbin, sizeof(pbin), "radix_test: dh_make_key_ex prime mismatch", i*10 + 8));
       len = mp_unsigned_bin_size(k3.base);
       DO(mp_to_unsigned_bin(k3.base, buf));
-      if (compare_testvector(buf, len, gbin, sizeof(gbin), "radix_test", i*10 + 9)) {
-         printf("radix_test: dh_make_key_ex base mismatch\n");
-         dh_free(&k3);
-         return CRYPT_ERROR;
-      }
+      DO(do_compare_testvector(buf, len, gbin, sizeof(gbin), "radix_test: dh_make_key_ex base mismatch", i*10 + 9));
       dh_free(&k3);
    }
 

+ 14 - 28
tests/dsa_test.c

@@ -142,27 +142,21 @@ static int _dsa_compat_test(void)
 
   x = sizeof(tmp);
   DO(dsa_export(tmp, &x, PK_PRIVATE | PK_STD, &key));
-  if (compare_testvector(tmp, x, openssl_priv_dsa, sizeof(openssl_priv_dsa),
-                         "DSA private export failed from dsa_import(priv_key)\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(tmp, x, openssl_priv_dsa, sizeof(openssl_priv_dsa),
+                         "DSA private export failed from dsa_import(priv_key)\n", __LINE__));
 
   x = sizeof(tmp);
   DO(dsa_export(tmp, &x, PK_PUBLIC | PK_STD, &key));
-  if (compare_testvector(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
-                         "DSA public export failed from dsa_import(priv_key)\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
+                         "DSA public export failed from dsa_import(priv_key)\n", __LINE__));
   dsa_free(&key);
 
   DO(dsa_import(openssl_pub_dsa, sizeof(openssl_pub_dsa), &key));
 
   x = sizeof(tmp);
   DO(dsa_export(tmp, &x, PK_PUBLIC | PK_STD, &key));
-  if (compare_testvector(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
-                         "DSA public export failed from dsa_import(pub_key)\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
+                         "DSA public export failed from dsa_import(pub_key)\n", __LINE__));
   dsa_free(&key);
 
   /* try import private key from raw hexadecimal numbers */
@@ -184,10 +178,8 @@ static int _dsa_compat_test(void)
                  &key));
   len = sizeof(buf);
   DO(dsa_export(buf, &len, PK_PRIVATE | PK_STD, &key));
-  if (compare_testvector(buf, len, openssl_priv_dsa, sizeof(openssl_priv_dsa),
-                         "DSA private export failed from dsa_set_pqg() & dsa_set_key()\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(buf, len, openssl_priv_dsa, sizeof(openssl_priv_dsa),
+                         "DSA private export failed from dsa_set_pqg() & dsa_set_key()\n", __LINE__));
   dsa_free(&key);
 
   /* try import public key from raw hexadecimal numbers */
@@ -200,10 +192,8 @@ static int _dsa_compat_test(void)
                  &key));
   len = sizeof(buf);
   DO(dsa_export(buf, &len, PK_PUBLIC | PK_STD, &key));
-  if (compare_testvector(buf, len, openssl_pub_dsa, sizeof(openssl_pub_dsa),
-                         "DSA public export failed from dsa_set_pqg() & dsa_set_key()\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(buf, len, openssl_pub_dsa, sizeof(openssl_pub_dsa),
+                         "DSA public export failed from dsa_set_pqg() & dsa_set_key()\n", __LINE__));
   dsa_free(&key);
 
   /* try import dsaparam */
@@ -224,10 +214,8 @@ static int _dsa_compat_test(void)
                  &key));
   len = sizeof(buf);
   DO(dsa_export(buf, &len, PK_PUBLIC | PK_STD, &key));
-  if (compare_testvector(buf, len, openssl_pub_dsa, sizeof(openssl_pub_dsa),
-                         "DSA public export failed from dsa_set_pqg_dsaparam()\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(buf, len, openssl_pub_dsa, sizeof(openssl_pub_dsa),
+                         "DSA public export failed from dsa_set_pqg_dsaparam()\n", __LINE__));
   dsa_free(&key);
 
   /* try import dsaparam - our private key */
@@ -237,10 +225,8 @@ static int _dsa_compat_test(void)
                  &key));
   len = sizeof(buf);
   DO(dsa_export(buf, &len, PK_PRIVATE | PK_STD, &key));
-  if (compare_testvector(buf, len, openssl_priv_dsa, sizeof(openssl_priv_dsa),
-                         "DSA private export failed from dsa_set_pqg_dsaparam()\n", __LINE__)) {
-     return CRYPT_FAIL_TESTVECTOR;
-  }
+  DO(do_compare_testvector(buf, len, openssl_priv_dsa, sizeof(openssl_priv_dsa),
+                         "DSA private export failed from dsa_set_pqg_dsaparam()\n", __LINE__));
   dsa_free(&key);
 
   return CRYPT_OK;

+ 20 - 20
tests/file_test.c

@@ -33,76 +33,76 @@ int file_test(void)
    if ((in = fopen(fname, "rb")) == NULL)                                       return CRYPT_FILE_NOTFOUND;
    err = hash_filehandle(isha256, in, buf, &len);
    fclose(in);
-   if (err != CRYPT_OK)                                                         return err;
-   if (compare_testvector(buf, len, exp_sha256, 32, "hash_filehandle", 1))      return 1;
+   DO(err);
+   DO(do_compare_testvector(buf, len, exp_sha256, 32, "hash_filehandle", 1));
 
    len = sizeof(buf);
-   if ((err = hash_file(isha256, fname, buf, &len)) != CRYPT_OK)                return err;
-   if (compare_testvector(buf, len, exp_sha256, 32, "hash_file", 1))            return 1;
+   DO(hash_file(isha256, fname, buf, &len));
+   DO(do_compare_testvector(buf, len, exp_sha256, 32, "hash_file", 1));
 
 #ifdef LTC_HMAC
    {
       unsigned char exp_hmacsha256[32] = { 0xE4, 0x07, 0x74, 0x95, 0xF1, 0xF8, 0x5B, 0xB5, 0xF1, 0x4F, 0x7D, 0x4F, 0x59, 0x8E, 0x4B, 0xBC,
                                            0x8F, 0x68, 0xCF, 0xBA, 0x2E, 0xAD, 0xC4, 0x63, 0x9D, 0x7F, 0x02, 0x99, 0x8C, 0x08, 0xAC, 0xC0 };
       len = sizeof(buf);
-      if ((err = hmac_file(isha256, fname, key, 32, buf, &len)) != CRYPT_OK)    return err;
-      if (compare_testvector(buf, len, exp_hmacsha256, 32, "hmac_file", 1))     return 1;
+      DO(hmac_file(isha256, fname, key, 32, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_hmacsha256, 32, "hmac_file", 1));
    }
 #endif
 #ifdef LTC_OMAC
    {
       unsigned char exp_omacaes[16]    = { 0x50, 0xB4, 0x6C, 0x62, 0xE9, 0xCA, 0x48, 0xFC, 0x38, 0x8D, 0xF4, 0xA2, 0x7D, 0x6A, 0x1E, 0xD8 };
       len = sizeof(buf);
-      if ((err = omac_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK)       return err;
-      if (compare_testvector(buf, len, exp_omacaes, 16, "omac_file", 1))        return 1;
+      DO(omac_file(iaes, key, 32, fname, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_omacaes, 16, "omac_file", 1));
    }
 #endif
 #ifdef LTC_PMAC
    {
       unsigned char exp_pmacaes[16]    = { 0x7D, 0x65, 0xF0, 0x75, 0x4F, 0x8D, 0xE2, 0xB0, 0xE4, 0xFA, 0x54, 0x4E, 0x45, 0x01, 0x36, 0x1B };
       len = sizeof(buf);
-      if ((err = pmac_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK)       return err;
-      if (compare_testvector(buf, len, exp_pmacaes, 16, "pmac_file", 1))        return 1;
+      DO(pmac_file(iaes, key, 32, fname, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_pmacaes, 16, "pmac_file", 1));
    }
 #endif
 #ifdef LTC_XCBC
    {
       unsigned char exp_xcbcaes[16]    = { 0x9C, 0x73, 0xA2, 0xD7, 0x90, 0xA5, 0x86, 0x25, 0x4D, 0x3C, 0x8A, 0x6A, 0x24, 0x6D, 0xD1, 0xAB };
       len = sizeof(buf);
-      if ((err = xcbc_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK)       return err;
-      if (compare_testvector(buf, len, exp_xcbcaes, 16, "xcbc_file", 1))        return 1;
+      DO(xcbc_file(iaes, key, 32, fname, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_xcbcaes, 16, "xcbc_file", 1));
    }
 #endif
 #ifdef LTC_F9_MODE
    {
       unsigned char exp_f9aes[16]      = { 0x6B, 0x6A, 0x18, 0x34, 0x13, 0x8E, 0x01, 0xEF, 0x33, 0x8E, 0x7A, 0x3F, 0x5B, 0x9A, 0xA6, 0x7A };
       len = sizeof(buf);
-      if ((err = f9_file(iaes, key, 32, fname, buf, &len)) != CRYPT_OK)         return err;
-      if (compare_testvector(buf, len, exp_f9aes, 16, "f9_file", 1))            return 1;
+      DO(f9_file(iaes, key, 32, fname, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_f9aes, 16, "f9_file", 1));
    }
 #endif
 #ifdef LTC_POLY1305
    {
       unsigned char exp_poly1305[16]   = { 0xD0, 0xC7, 0xFB, 0x13, 0xA8, 0x87, 0x84, 0x23, 0x21, 0xCC, 0xA9, 0x43, 0x81, 0x18, 0x75, 0xBE };
       len = sizeof(buf);
-      if ((err = poly1305_file(fname, key, 32, buf, &len)) != CRYPT_OK)         return err;
-      if (compare_testvector(buf, len, exp_poly1305, 16, "poly1305_file", 1))   return 1;
+      DO(poly1305_file(fname, key, 32, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_poly1305, 16, "poly1305_file", 1));
    }
 #endif
 #ifdef LTC_BLAKE2SMAC
    {
       unsigned char exp_blake2smac[16]   = { 0x4f, 0x94, 0x45, 0x15, 0xcd, 0xd1, 0xca, 0x02, 0x1a, 0x0c, 0x7a, 0xe4, 0x6d, 0x2f, 0xe8, 0xb3 };
       len = 16;
-      if ((err = blake2smac_file(fname, key, 32, buf, &len)) != CRYPT_OK)             return err;
-      if (compare_testvector(buf, len, exp_blake2smac, 16, "exp_blake2smac_file", 1)) return 1;
+      DO(blake2smac_file(fname, key, 32, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_blake2smac, 16, "exp_blake2smac_file", 1));
    }
 #endif
 #ifdef LTC_BLAKE2BMAC
    {
       unsigned char exp_blake2bmac[16]   = { 0xdf, 0x0e, 0x7a, 0xab, 0x96, 0x6b, 0x75, 0x4e, 0x52, 0x6a, 0x43, 0x96, 0xbd, 0xef, 0xab, 0x44 };
       len = 16;
-      if ((err = blake2bmac_file(fname, key, 32, buf, &len)) != CRYPT_OK)             return err;
-      if (compare_testvector(buf, len, exp_blake2bmac, 16, "exp_blake2bmac_file", 1)) return 1;
+      DO(blake2bmac_file(fname, key, 32, buf, &len));
+      DO(do_compare_testvector(buf, len, exp_blake2bmac, 16, "exp_blake2bmac_file", 1));
    }
 #endif
 

+ 3 - 0
tests/misc_test.c

@@ -22,6 +22,9 @@ int misc_test(void)
 #ifdef LTC_BASE32
    DO(base32_test());
 #endif
+#ifdef LTC_BASE16
+   DO(base16_test());
+#endif
 #ifdef LTC_ADLER32
    DO(adler32_test());
 #endif

+ 4 - 4
tests/mpi_test.c

@@ -123,10 +123,10 @@ static int _radix_to_bin_test(void)
       DO(radix_to_bin(test[i].p, test[i].radix, key_parts[2], &key_lens[2]));
       DO(radix_to_bin(test[i].g, test[i].radix, key_parts[3], &key_lens[3]));
 
-      if (compare_testvector(key_parts[0], key_lens[0], test[0].x, test[0].xlen, "radix_to_bin(x)", i)) return CRYPT_FAIL_TESTVECTOR;
-      if (compare_testvector(key_parts[1], key_lens[1], test[0].y, test[0].ylen, "radix_to_bin(y)", i)) return CRYPT_FAIL_TESTVECTOR;
-      if (compare_testvector(key_parts[2], key_lens[2], test[0].p, test[0].plen, "radix_to_bin(p)", i)) return CRYPT_FAIL_TESTVECTOR;
-      if (compare_testvector(key_parts[3], key_lens[3], test[0].g, test[0].glen, "radix_to_bin(g)", i)) return CRYPT_FAIL_TESTVECTOR;
+      DO(do_compare_testvector(key_parts[0], key_lens[0], test[0].x, test[0].xlen, "radix_to_bin(x)", i));
+      DO(do_compare_testvector(key_parts[1], key_lens[1], test[0].y, test[0].ylen, "radix_to_bin(y)", i));
+      DO(do_compare_testvector(key_parts[2], key_lens[2], test[0].p, test[0].plen, "radix_to_bin(p)", i));
+      DO(do_compare_testvector(key_parts[3], key_lens[3], test[0].g, test[0].glen, "radix_to_bin(g)", i));
    }
    return CRYPT_OK;
 }

+ 16 - 25
tests/rsa_test.c

@@ -10,10 +10,6 @@
 
 #if defined(LTC_MRSA)
 
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <dirent.h>
-
 #define RSA_MSGSIZE 78
 
 /* These are test keys [see file test.key] that I use to test my import/export against */
@@ -211,42 +207,32 @@ static int rsa_compat_test(void)
    /* now try to export private/public and compare */
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PRIVATE, &key));
-   if (compare_testvector(buf, len, openssl_private_rsa, sizeof(openssl_private_rsa), "RSA private export (from OpenSSL)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_private_rsa, sizeof(openssl_private_rsa), "RSA private export (from OpenSSL)", 0));
 
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PUBLIC, &key));
-   if (compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from OpenSSL private key)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from OpenSSL private key)", 0));
    rsa_free(&key);
 
    /* try reading the public key */
    DO(rsa_import(openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), &key));
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PUBLIC, &key));
-   if (compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from stripped OpenSSL)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from stripped OpenSSL)", 0));
    rsa_free(&key);
 
    /* try reading the public key */
    DO(rsa_import(openssl_public_rsa, sizeof(openssl_public_rsa), &key));
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PUBLIC, &key));
-   if (compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from OpenSSL)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from OpenSSL)", 0));
    rsa_free(&key);
 
    /* try import private key in pkcs8 format */
    DO(rsa_import_pkcs8(pkcs8_private_rsa, sizeof(pkcs8_private_rsa), NULL, 0, &key));
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PRIVATE, &key));
-   if (compare_testvector(buf, len, openssl_private_rsa, sizeof(openssl_private_rsa), "RSA private export (from PKCS#8)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_private_rsa, sizeof(openssl_private_rsa), "RSA private export (from PKCS#8)", 0));
    rsa_free(&key);
 
    /* convert raw hexadecimal numbers to binary */
@@ -260,18 +246,14 @@ static int rsa_compat_test(void)
    DO(rsa_set_crt_params(key_parts[pk_dP], key_lens[pk_dP], key_parts[pk_dQ], key_lens[pk_dQ], key_parts[pk_qP], key_lens[pk_qP], &key));
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PRIVATE, &key));
-   if (compare_testvector(buf, len, openssl_private_rsa, sizeof(openssl_private_rsa), "RSA private export (from hex)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_private_rsa, sizeof(openssl_private_rsa), "RSA private export (from hex)", 0));
    rsa_free(&key);
 
    /* try import public key from converted raw hexadecimal numbers */
    DO(rsa_set_key(key_parts[pk_N], key_lens[pk_N], key_parts[pk_e], key_lens[pk_e], NULL, 0, &key));
    len = sizeof(buf);
    DO(rsa_export(buf, &len, PK_PUBLIC, &key));
-   if (compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from hex)", 0)) {
-      return 1;
-   }
+   DO(do_compare_testvector(buf, len, openssl_public_rsa_stripped, sizeof(openssl_public_rsa_stripped), "RSA public export (from hex)", 0));
    rsa_free(&key);
 
    /* try export in SubjectPublicKeyInfo format of the public key */
@@ -347,6 +329,12 @@ static int _rsa_issue_301(int prng_idx)
    return CRYPT_OK;
 }
 
+#if !((defined(_WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__))
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+
 static off_t fsize(const char *filename)
 {
    struct stat st;
@@ -416,6 +404,7 @@ static int _rsa_size_test(void)
    closedir(d);
    return err;
 }
+#endif
 
 int rsa_test(void)
 {
@@ -442,7 +431,9 @@ int rsa_test(void)
       return 1;
    }
 
+#if !((defined(_WIN32) || defined(_WIN32_WCE)) && !defined(__GNUC__))
    DO(_rsa_size_test());
+#endif
 
    DO(_rsa_issue_301(prng_idx));
 

+ 1 - 0
tests/tomcrypt_test.h

@@ -39,6 +39,7 @@ int der_test(void);
 int misc_test(void);
 int base64_test(void);
 int base32_test(void);
+int base16_test(void);
 int file_test(void);
 int multi_test(void);
 int prng_test(void);