summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Miko <karel.miko@gmail.com>2018-07-06 19:00:34 +0200
committerKarel Miko <karel.miko@gmail.com>2018-07-06 19:00:34 +0200
commit448b7611e3c8f3e4ee974f03fca8c4de71bb8cfb (patch)
tree1b6c0e0df0e5048b08c10a127f0055d65be4bfb5
parente2a581d8a956970f45f00b43841ea90b199ab19a (diff)
libtomcrypt update
-rw-r--r--src/Makefile76
-rw-r--r--src/Makefile.nmake29
-rw-r--r--src/ltc/ciphers/aes/aes.c11
-rw-r--r--src/ltc/ciphers/blowfish.c3
-rw-r--r--src/ltc/ciphers/cast5.c3
-rw-r--r--src/ltc/ciphers/des.c3
-rw-r--r--src/ltc/ciphers/kasumi.c3
-rw-r--r--src/ltc/ciphers/khazad.c3
-rw-r--r--src/ltc/ciphers/noekeon.c5
-rw-r--r--src/ltc/ciphers/rc2.c3
-rw-r--r--src/ltc/ciphers/rc5.c3
-rw-r--r--src/ltc/ciphers/rc6.c3
-rw-r--r--src/ltc/ciphers/safer/safer.c97
-rw-r--r--src/ltc/ciphers/safer/saferp.c3
-rw-r--r--src/ltc/ciphers/skipjack.c3
-rw-r--r--src/ltc/ciphers/twofish/twofish.c13
-rw-r--r--src/ltc/encauth/ocb3/ocb3_decrypt_last.c5
-rw-r--r--src/ltc/encauth/ocb3/ocb3_encrypt_last.c8
-rw-r--r--src/ltc/hashes/blake2b.c20
-rw-r--r--src/ltc/hashes/blake2s.c28
-rw-r--r--src/ltc/hashes/chc/chc.c2
-rw-r--r--src/ltc/hashes/sha3.c21
-rw-r--r--src/ltc/headers/tomcrypt.h4
-rw-r--r--src/ltc/headers/tomcrypt_cipher.h6
-rw-r--r--src/ltc/headers/tomcrypt_custom.h3
-rw-r--r--src/ltc/headers/tomcrypt_hash.h42
-rw-r--r--src/ltc/headers/tomcrypt_mac.h8
-rw-r--r--src/ltc/headers/tomcrypt_misc.h14
-rw-r--r--src/ltc/headers/tomcrypt_pk.h6
-rw-r--r--src/ltc/headers/tomcrypt_pkcs.h1
-rw-r--r--src/ltc/headers/tomcrypt_private.h23
-rw-r--r--src/ltc/mac/pmac/pmac_done.c34
-rw-r--r--src/ltc/misc/adler32.c6
-rw-r--r--src/ltc/misc/base16/base16_encode.c7
-rw-r--r--src/ltc/misc/base64/base64_decode.c12
-rw-r--r--src/ltc/misc/burn_stack.c3
-rw-r--r--src/ltc/misc/compare_testvector.c6
-rw-r--r--src/ltc/misc/crc32.c3
-rw-r--r--src/ltc/misc/crypt/crypt.c3
-rw-r--r--src/ltc/misc/crypt/crypt_constants.c3
-rw-r--r--src/ltc/misc/crypt/crypt_sizes.c3
-rw-r--r--src/ltc/misc/error_to_string.c3
-rw-r--r--src/ltc/misc/hkdf/hkdf.c12
-rw-r--r--src/ltc/misc/padding/padding_pad.c7
-rw-r--r--src/ltc/misc/pkcs12/pkcs12_kdf.c92
-rw-r--r--src/ltc/misc/pkcs12/pkcs12_utf8_to_utf16.c69
-rw-r--r--src/ltc/misc/pkcs5/pkcs_5_1.c12
-rw-r--r--src/ltc/modes/cbc/cbc_decrypt.c47
-rw-r--r--src/ltc/modes/cbc/cbc_encrypt.c59
-rw-r--r--src/ltc/modes/cfb/cfb_start.c3
-rw-r--r--src/ltc/modes/ecb/ecb_decrypt.c15
-rw-r--r--src/ltc/modes/ecb/ecb_encrypt.c15
-rw-r--r--src/ltc/pk/asn1/der/general/der_decode_asn1_length.c6
-rw-r--r--src/ltc/pk/asn1/der/general/der_encode_asn1_identifier.c19
-rw-r--r--src/ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c9
-rw-r--r--src/ltc/pk/asn1/der/set/der_encode_set.c3
-rw-r--r--src/ltc/pk/asn1/der/utctime/der_decode_utctime.c9
-rw-r--r--src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c13
-rw-r--r--src/ltc/pk/dh/dh_generate_key.c16
-rw-r--r--src/ltc/pk/dsa/dsa_export.c26
-rw-r--r--src/ltc/pk/ecc/ecc_ansi_x963_import.c4
-rw-r--r--src/ltc/pk/ecc/ecc_decrypt_key.c2
-rw-r--r--src/ltc/pk/ecc/ecc_encrypt_key.c2
-rw-r--r--src/ltc/pk/ecc/ecc_find_curve.c (renamed from src/ltc/pk/ecc/ecc_get_curve.c)8
-rw-r--r--src/ltc/pk/ecc/ecc_import.c4
-rw-r--r--src/ltc/pk/ecc/ecc_import_openssl.c6
-rw-r--r--src/ltc/pk/ecc/ecc_import_pkcs8.c121
-rw-r--r--src/ltc/pk/ecc/ecc_import_x509.c6
-rw-r--r--src/ltc/pk/ecc/ecc_make_key.c6
-rw-r--r--src/ltc/pk/ecc/ecc_set_curve.c (renamed from src/ltc/pk/ecc/ecc_set_dp.c)42
-rw-r--r--src/ltc/pk/ecc/ecc_set_curve_internal.c (renamed from src/ltc/pk/ecc/ecc_set_dp_internal.c)4
-rw-r--r--src/ltc/pk/ecc/ecc_sign_hash.c2
-rw-r--r--src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c5
-rw-r--r--src/ltc/pk/rsa/rsa_export.c24
-rw-r--r--src/ltc/pk/rsa/rsa_import.c6
-rw-r--r--src/ltc/prngs/fortuna.c6
-rw-r--r--src/ltc/prngs/rng_get_bytes.c7
-rw-r--r--src/ltc/prngs/sprng.c1
-rw-r--r--src/ltc/stream/rabbit/rabbit.c29
-rw-r--r--src/ltc/stream/sober128/sober128_stream.c124
-rw-r--r--src/ltc/stream/sosemanuk/sosemanuk.c9
81 files changed, 750 insertions, 635 deletions
diff --git a/src/Makefile b/src/Makefile
index 05bed2b1..45e5373e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -56,38 +56,38 @@ ltc/misc/crypt/crypt_register_all_hashes.o ltc/misc/crypt/crypt_register_all_prn
ltc/misc/crypt/crypt_register_cipher.o ltc/misc/crypt/crypt_register_hash.o ltc/misc/crypt/crypt_register_prng.o \
ltc/misc/crypt/crypt_sizes.o ltc/misc/crypt/crypt_unregister_cipher.o ltc/misc/crypt/crypt_unregister_hash.o \
ltc/misc/crypt/crypt_unregister_prng.o ltc/misc/hkdf/hkdf.o ltc/misc/padding/padding_depad.o \
-ltc/misc/padding/padding_pad.o ltc/misc/pkcs5/pkcs_5_1.o ltc/misc/pkcs5/pkcs_5_2.o \
-ltc/modes/cbc/cbc_decrypt.o ltc/modes/cbc/cbc_done.o ltc/modes/cbc/cbc_encrypt.o \
-ltc/modes/cbc/cbc_getiv.o ltc/modes/cbc/cbc_setiv.o ltc/modes/cbc/cbc_start.o ltc/modes/cfb/cfb_decrypt.o \
-ltc/modes/cfb/cfb_done.o ltc/modes/cfb/cfb_encrypt.o ltc/modes/cfb/cfb_getiv.o ltc/modes/cfb/cfb_setiv.o \
-ltc/modes/cfb/cfb_start.o ltc/modes/ctr/ctr_decrypt.o ltc/modes/ctr/ctr_done.o ltc/modes/ctr/ctr_encrypt.o \
-ltc/modes/ctr/ctr_getiv.o ltc/modes/ctr/ctr_setiv.o ltc/modes/ctr/ctr_start.o ltc/modes/ecb/ecb_decrypt.o \
-ltc/modes/ecb/ecb_done.o ltc/modes/ecb/ecb_encrypt.o ltc/modes/ecb/ecb_start.o ltc/modes/ofb/ofb_decrypt.o \
-ltc/modes/ofb/ofb_done.o ltc/modes/ofb/ofb_encrypt.o ltc/modes/ofb/ofb_getiv.o ltc/modes/ofb/ofb_setiv.o \
-ltc/modes/ofb/ofb_start.o ltc/pk/asn1/der/bit/der_decode_bit_string.o ltc/pk/asn1/der/bit/der_decode_raw_bit_string.o \
-ltc/pk/asn1/der/bit/der_encode_bit_string.o ltc/pk/asn1/der/bit/der_encode_raw_bit_string.o \
-ltc/pk/asn1/der/bit/der_length_bit_string.o ltc/pk/asn1/der/boolean/der_decode_boolean.o \
-ltc/pk/asn1/der/boolean/der_encode_boolean.o ltc/pk/asn1/der/boolean/der_length_boolean.o \
-ltc/pk/asn1/der/choice/der_decode_choice.o ltc/pk/asn1/der/custom_type/der_decode_custom_type.o \
-ltc/pk/asn1/der/custom_type/der_encode_custom_type.o ltc/pk/asn1/der/custom_type/der_length_custom_type.o \
-ltc/pk/asn1/der/general/der_asn1_maps.o ltc/pk/asn1/der/general/der_decode_asn1_identifier.o \
-ltc/pk/asn1/der/general/der_decode_asn1_length.o ltc/pk/asn1/der/general/der_encode_asn1_identifier.o \
-ltc/pk/asn1/der/general/der_encode_asn1_length.o ltc/pk/asn1/der/general/der_length_asn1_identifier.o \
-ltc/pk/asn1/der/general/der_length_asn1_length.o ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.o \
-ltc/pk/asn1/der/generalizedtime/der_encode_generalizedtime.o ltc/pk/asn1/der/generalizedtime/der_length_generalizedtime.o \
-ltc/pk/asn1/der/ia5/der_decode_ia5_string.o ltc/pk/asn1/der/ia5/der_encode_ia5_string.o \
-ltc/pk/asn1/der/ia5/der_length_ia5_string.o ltc/pk/asn1/der/integer/der_decode_integer.o \
-ltc/pk/asn1/der/integer/der_encode_integer.o ltc/pk/asn1/der/integer/der_length_integer.o \
-ltc/pk/asn1/der/object_identifier/der_decode_object_identifier.o ltc/pk/asn1/der/object_identifier/der_encode_object_identifier.o \
-ltc/pk/asn1/der/object_identifier/der_length_object_identifier.o ltc/pk/asn1/der/octet/der_decode_octet_string.o \
-ltc/pk/asn1/der/octet/der_encode_octet_string.o ltc/pk/asn1/der/octet/der_length_octet_string.o \
-ltc/pk/asn1/der/printable_string/der_decode_printable_string.o ltc/pk/asn1/der/printable_string/der_encode_printable_string.o \
-ltc/pk/asn1/der/printable_string/der_length_printable_string.o ltc/pk/asn1/der/sequence/der_decode_sequence_ex.o \
-ltc/pk/asn1/der/sequence/der_decode_sequence_flexi.o ltc/pk/asn1/der/sequence/der_decode_sequence_multi.o \
-ltc/pk/asn1/der/sequence/der_encode_sequence_ex.o ltc/pk/asn1/der/sequence/der_encode_sequence_multi.o \
-ltc/pk/asn1/der/sequence/der_length_sequence.o ltc/pk/asn1/der/sequence/der_sequence_free.o \
-ltc/pk/asn1/der/sequence/der_sequence_shrink.o ltc/pk/asn1/der/set/der_encode_set.o \
-ltc/pk/asn1/der/set/der_encode_setof.o ltc/pk/asn1/der/short_integer/der_decode_short_integer.o \
+ltc/misc/padding/padding_pad.o ltc/misc/pkcs12/pkcs12_kdf.o ltc/misc/pkcs12/pkcs12_utf8_to_utf16.o \
+ltc/misc/pkcs5/pkcs_5_1.o ltc/misc/pkcs5/pkcs_5_2.o ltc/modes/cbc/cbc_decrypt.o ltc/modes/cbc/cbc_done.o \
+ltc/modes/cbc/cbc_encrypt.o ltc/modes/cbc/cbc_getiv.o ltc/modes/cbc/cbc_setiv.o ltc/modes/cbc/cbc_start.o \
+ltc/modes/cfb/cfb_decrypt.o ltc/modes/cfb/cfb_done.o ltc/modes/cfb/cfb_encrypt.o \
+ltc/modes/cfb/cfb_getiv.o ltc/modes/cfb/cfb_setiv.o ltc/modes/cfb/cfb_start.o ltc/modes/ctr/ctr_decrypt.o \
+ltc/modes/ctr/ctr_done.o ltc/modes/ctr/ctr_encrypt.o ltc/modes/ctr/ctr_getiv.o ltc/modes/ctr/ctr_setiv.o \
+ltc/modes/ctr/ctr_start.o ltc/modes/ecb/ecb_decrypt.o ltc/modes/ecb/ecb_done.o ltc/modes/ecb/ecb_encrypt.o \
+ltc/modes/ecb/ecb_start.o ltc/modes/ofb/ofb_decrypt.o ltc/modes/ofb/ofb_done.o ltc/modes/ofb/ofb_encrypt.o \
+ltc/modes/ofb/ofb_getiv.o ltc/modes/ofb/ofb_setiv.o ltc/modes/ofb/ofb_start.o ltc/pk/asn1/der/bit/der_decode_bit_string.o \
+ltc/pk/asn1/der/bit/der_decode_raw_bit_string.o ltc/pk/asn1/der/bit/der_encode_bit_string.o \
+ltc/pk/asn1/der/bit/der_encode_raw_bit_string.o ltc/pk/asn1/der/bit/der_length_bit_string.o \
+ltc/pk/asn1/der/boolean/der_decode_boolean.o ltc/pk/asn1/der/boolean/der_encode_boolean.o \
+ltc/pk/asn1/der/boolean/der_length_boolean.o ltc/pk/asn1/der/choice/der_decode_choice.o \
+ltc/pk/asn1/der/custom_type/der_decode_custom_type.o ltc/pk/asn1/der/custom_type/der_encode_custom_type.o \
+ltc/pk/asn1/der/custom_type/der_length_custom_type.o ltc/pk/asn1/der/general/der_asn1_maps.o \
+ltc/pk/asn1/der/general/der_decode_asn1_identifier.o ltc/pk/asn1/der/general/der_decode_asn1_length.o \
+ltc/pk/asn1/der/general/der_encode_asn1_identifier.o ltc/pk/asn1/der/general/der_encode_asn1_length.o \
+ltc/pk/asn1/der/general/der_length_asn1_identifier.o ltc/pk/asn1/der/general/der_length_asn1_length.o \
+ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.o ltc/pk/asn1/der/generalizedtime/der_encode_generalizedtime.o \
+ltc/pk/asn1/der/generalizedtime/der_length_generalizedtime.o ltc/pk/asn1/der/ia5/der_decode_ia5_string.o \
+ltc/pk/asn1/der/ia5/der_encode_ia5_string.o ltc/pk/asn1/der/ia5/der_length_ia5_string.o \
+ltc/pk/asn1/der/integer/der_decode_integer.o ltc/pk/asn1/der/integer/der_encode_integer.o \
+ltc/pk/asn1/der/integer/der_length_integer.o ltc/pk/asn1/der/object_identifier/der_decode_object_identifier.o \
+ltc/pk/asn1/der/object_identifier/der_encode_object_identifier.o ltc/pk/asn1/der/object_identifier/der_length_object_identifier.o \
+ltc/pk/asn1/der/octet/der_decode_octet_string.o ltc/pk/asn1/der/octet/der_encode_octet_string.o \
+ltc/pk/asn1/der/octet/der_length_octet_string.o ltc/pk/asn1/der/printable_string/der_decode_printable_string.o \
+ltc/pk/asn1/der/printable_string/der_encode_printable_string.o ltc/pk/asn1/der/printable_string/der_length_printable_string.o \
+ltc/pk/asn1/der/sequence/der_decode_sequence_ex.o ltc/pk/asn1/der/sequence/der_decode_sequence_flexi.o \
+ltc/pk/asn1/der/sequence/der_decode_sequence_multi.o ltc/pk/asn1/der/sequence/der_encode_sequence_ex.o \
+ltc/pk/asn1/der/sequence/der_encode_sequence_multi.o ltc/pk/asn1/der/sequence/der_length_sequence.o \
+ltc/pk/asn1/der/sequence/der_sequence_free.o ltc/pk/asn1/der/sequence/der_sequence_shrink.o \
+ltc/pk/asn1/der/set/der_encode_set.o ltc/pk/asn1/der/set/der_encode_setof.o ltc/pk/asn1/der/short_integer/der_decode_short_integer.o \
ltc/pk/asn1/der/short_integer/der_encode_short_integer.o ltc/pk/asn1/der/short_integer/der_length_short_integer.o \
ltc/pk/asn1/der/teletex_string/der_decode_teletex_string.o ltc/pk/asn1/der/teletex_string/der_length_teletex_string.o \
ltc/pk/asn1/der/utctime/der_decode_utctime.o ltc/pk/asn1/der/utctime/der_encode_utctime.o \
@@ -102,12 +102,12 @@ ltc/pk/dsa/dsa_generate_pqg.o ltc/pk/dsa/dsa_import.o ltc/pk/dsa/dsa_make_key.o
ltc/pk/dsa/dsa_set_pqg_dsaparam.o ltc/pk/dsa/dsa_shared_secret.o ltc/pk/dsa/dsa_sign_hash.o \
ltc/pk/dsa/dsa_verify_hash.o ltc/pk/dsa/dsa_verify_key.o ltc/pk/ecc/ecc.o ltc/pk/ecc/ecc_ansi_x963_export.o \
ltc/pk/ecc/ecc_ansi_x963_import.o ltc/pk/ecc/ecc_decrypt_key.o ltc/pk/ecc/ecc_encrypt_key.o \
-ltc/pk/ecc/ecc_export.o ltc/pk/ecc/ecc_export_openssl.o ltc/pk/ecc/ecc_free.o ltc/pk/ecc/ecc_get_curve.o \
-ltc/pk/ecc/ecc_get_key.o ltc/pk/ecc/ecc_get_oid_str.o ltc/pk/ecc/ecc_get_size.o ltc/pk/ecc/ecc_import.o \
-ltc/pk/ecc/ecc_import_openssl.o ltc/pk/ecc/ecc_import_pkcs8.o ltc/pk/ecc/ecc_import_x509.o \
-ltc/pk/ecc/ecc_make_key.o ltc/pk/ecc/ecc_set_dp.o ltc/pk/ecc/ecc_set_dp_internal.o \
-ltc/pk/ecc/ecc_set_key.o ltc/pk/ecc/ecc_shared_secret.o ltc/pk/ecc/ecc_sign_hash.o \
-ltc/pk/ecc/ecc_sizes.o ltc/pk/ecc/ecc_verify_hash.o ltc/pk/ecc/ltc_ecc_export_point.o \
+ltc/pk/ecc/ecc_export.o ltc/pk/ecc/ecc_export_openssl.o ltc/pk/ecc/ecc_find_curve.o \
+ltc/pk/ecc/ecc_free.o ltc/pk/ecc/ecc_get_key.o ltc/pk/ecc/ecc_get_oid_str.o ltc/pk/ecc/ecc_get_size.o \
+ltc/pk/ecc/ecc_import.o ltc/pk/ecc/ecc_import_openssl.o ltc/pk/ecc/ecc_import_pkcs8.o \
+ltc/pk/ecc/ecc_import_x509.o ltc/pk/ecc/ecc_make_key.o ltc/pk/ecc/ecc_set_curve.o \
+ltc/pk/ecc/ecc_set_curve_internal.o ltc/pk/ecc/ecc_set_key.o ltc/pk/ecc/ecc_shared_secret.o \
+ltc/pk/ecc/ecc_sign_hash.o ltc/pk/ecc/ecc_sizes.o ltc/pk/ecc/ecc_verify_hash.o ltc/pk/ecc/ltc_ecc_export_point.o \
ltc/pk/ecc/ltc_ecc_import_point.o ltc/pk/ecc/ltc_ecc_is_point.o ltc/pk/ecc/ltc_ecc_is_point_at_infinity.o \
ltc/pk/ecc/ltc_ecc_map.o ltc/pk/ecc/ltc_ecc_mul2add.o ltc/pk/ecc/ltc_ecc_mulmod.o \
ltc/pk/ecc/ltc_ecc_mulmod_timing.o ltc/pk/ecc/ltc_ecc_points.o ltc/pk/ecc/ltc_ecc_projective_add_point.o \
diff --git a/src/Makefile.nmake b/src/Makefile.nmake
index 47703d56..05f9f991 100644
--- a/src/Makefile.nmake
+++ b/src/Makefile.nmake
@@ -60,17 +60,18 @@ ltc/misc/crypt/crypt_register_all_prngs.obj ltc/misc/crypt/crypt_register_cipher
ltc/misc/crypt/crypt_register_hash.obj ltc/misc/crypt/crypt_register_prng.obj ltc/misc/crypt/crypt_sizes.obj \
ltc/misc/crypt/crypt_unregister_cipher.obj ltc/misc/crypt/crypt_unregister_hash.obj \
ltc/misc/crypt/crypt_unregister_prng.obj ltc/misc/hkdf/hkdf.obj ltc/misc/padding/padding_depad.obj \
-ltc/misc/padding/padding_pad.obj ltc/misc/pkcs5/pkcs_5_1.obj ltc/misc/pkcs5/pkcs_5_2.obj \
-ltc/modes/cbc/cbc_decrypt.obj ltc/modes/cbc/cbc_done.obj ltc/modes/cbc/cbc_encrypt.obj \
-ltc/modes/cbc/cbc_getiv.obj ltc/modes/cbc/cbc_setiv.obj ltc/modes/cbc/cbc_start.obj \
-ltc/modes/cfb/cfb_decrypt.obj ltc/modes/cfb/cfb_done.obj ltc/modes/cfb/cfb_encrypt.obj \
-ltc/modes/cfb/cfb_getiv.obj ltc/modes/cfb/cfb_setiv.obj ltc/modes/cfb/cfb_start.obj \
-ltc/modes/ctr/ctr_decrypt.obj ltc/modes/ctr/ctr_done.obj ltc/modes/ctr/ctr_encrypt.obj \
-ltc/modes/ctr/ctr_getiv.obj ltc/modes/ctr/ctr_setiv.obj ltc/modes/ctr/ctr_start.obj \
-ltc/modes/ecb/ecb_decrypt.obj ltc/modes/ecb/ecb_done.obj ltc/modes/ecb/ecb_encrypt.obj \
-ltc/modes/ecb/ecb_start.obj ltc/modes/ofb/ofb_decrypt.obj ltc/modes/ofb/ofb_done.obj \
-ltc/modes/ofb/ofb_encrypt.obj ltc/modes/ofb/ofb_getiv.obj ltc/modes/ofb/ofb_setiv.obj \
-ltc/modes/ofb/ofb_start.obj ltc/pk/asn1/der/bit/der_decode_bit_string.obj ltc/pk/asn1/der/bit/der_decode_raw_bit_string.obj \
+ltc/misc/padding/padding_pad.obj ltc/misc/pkcs12/pkcs12_kdf.obj ltc/misc/pkcs12/pkcs12_utf8_to_utf16.obj \
+ltc/misc/pkcs5/pkcs_5_1.obj ltc/misc/pkcs5/pkcs_5_2.obj ltc/modes/cbc/cbc_decrypt.obj \
+ltc/modes/cbc/cbc_done.obj ltc/modes/cbc/cbc_encrypt.obj ltc/modes/cbc/cbc_getiv.obj \
+ltc/modes/cbc/cbc_setiv.obj ltc/modes/cbc/cbc_start.obj ltc/modes/cfb/cfb_decrypt.obj \
+ltc/modes/cfb/cfb_done.obj ltc/modes/cfb/cfb_encrypt.obj ltc/modes/cfb/cfb_getiv.obj \
+ltc/modes/cfb/cfb_setiv.obj ltc/modes/cfb/cfb_start.obj ltc/modes/ctr/ctr_decrypt.obj \
+ltc/modes/ctr/ctr_done.obj ltc/modes/ctr/ctr_encrypt.obj ltc/modes/ctr/ctr_getiv.obj \
+ltc/modes/ctr/ctr_setiv.obj ltc/modes/ctr/ctr_start.obj ltc/modes/ecb/ecb_decrypt.obj \
+ltc/modes/ecb/ecb_done.obj ltc/modes/ecb/ecb_encrypt.obj ltc/modes/ecb/ecb_start.obj \
+ltc/modes/ofb/ofb_decrypt.obj ltc/modes/ofb/ofb_done.obj ltc/modes/ofb/ofb_encrypt.obj \
+ltc/modes/ofb/ofb_getiv.obj ltc/modes/ofb/ofb_setiv.obj ltc/modes/ofb/ofb_start.obj \
+ltc/pk/asn1/der/bit/der_decode_bit_string.obj ltc/pk/asn1/der/bit/der_decode_raw_bit_string.obj \
ltc/pk/asn1/der/bit/der_encode_bit_string.obj ltc/pk/asn1/der/bit/der_encode_raw_bit_string.obj \
ltc/pk/asn1/der/bit/der_length_bit_string.obj ltc/pk/asn1/der/boolean/der_decode_boolean.obj \
ltc/pk/asn1/der/boolean/der_encode_boolean.obj ltc/pk/asn1/der/boolean/der_length_boolean.obj \
@@ -109,11 +110,11 @@ ltc/pk/dsa/dsa_make_key.obj ltc/pk/dsa/dsa_set.obj ltc/pk/dsa/dsa_set_pqg_dsapar
ltc/pk/dsa/dsa_shared_secret.obj ltc/pk/dsa/dsa_sign_hash.obj ltc/pk/dsa/dsa_verify_hash.obj \
ltc/pk/dsa/dsa_verify_key.obj ltc/pk/ecc/ecc.obj ltc/pk/ecc/ecc_ansi_x963_export.obj \
ltc/pk/ecc/ecc_ansi_x963_import.obj ltc/pk/ecc/ecc_decrypt_key.obj ltc/pk/ecc/ecc_encrypt_key.obj \
-ltc/pk/ecc/ecc_export.obj ltc/pk/ecc/ecc_export_openssl.obj ltc/pk/ecc/ecc_free.obj \
-ltc/pk/ecc/ecc_get_curve.obj ltc/pk/ecc/ecc_get_key.obj ltc/pk/ecc/ecc_get_oid_str.obj \
+ltc/pk/ecc/ecc_export.obj ltc/pk/ecc/ecc_export_openssl.obj ltc/pk/ecc/ecc_find_curve.obj \
+ltc/pk/ecc/ecc_free.obj ltc/pk/ecc/ecc_get_key.obj ltc/pk/ecc/ecc_get_oid_str.obj \
ltc/pk/ecc/ecc_get_size.obj ltc/pk/ecc/ecc_import.obj ltc/pk/ecc/ecc_import_openssl.obj \
ltc/pk/ecc/ecc_import_pkcs8.obj ltc/pk/ecc/ecc_import_x509.obj ltc/pk/ecc/ecc_make_key.obj \
-ltc/pk/ecc/ecc_set_dp.obj ltc/pk/ecc/ecc_set_dp_internal.obj ltc/pk/ecc/ecc_set_key.obj \
+ltc/pk/ecc/ecc_set_curve.obj ltc/pk/ecc/ecc_set_curve_internal.obj ltc/pk/ecc/ecc_set_key.obj \
ltc/pk/ecc/ecc_shared_secret.obj ltc/pk/ecc/ecc_sign_hash.obj ltc/pk/ecc/ecc_sizes.obj \
ltc/pk/ecc/ecc_verify_hash.obj ltc/pk/ecc/ltc_ecc_export_point.obj ltc/pk/ecc/ltc_ecc_import_point.obj \
ltc/pk/ecc/ltc_ecc_is_point.obj ltc/pk/ecc/ltc_ecc_is_point_at_infinity.obj ltc/pk/ecc/ltc_ecc_map.obj \
diff --git a/src/ltc/ciphers/aes/aes.c b/src/ltc/ciphers/aes/aes.c
index 537fecef..17122481 100644
--- a/src/ltc/ciphers/aes/aes.c
+++ b/src/ltc/ciphers/aes/aes.c
@@ -723,18 +723,19 @@ int ECB_KS(int *keysize)
{
LTC_ARGCHK(keysize != NULL);
- if (*keysize < 16)
+ if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
+ }
if (*keysize < 24) {
*keysize = 16;
return CRYPT_OK;
- } else if (*keysize < 32) {
+ }
+ if (*keysize < 32) {
*keysize = 24;
return CRYPT_OK;
- } else {
- *keysize = 32;
- return CRYPT_OK;
}
+ *keysize = 32;
+ return CRYPT_OK;
}
#endif
diff --git a/src/ltc/ciphers/blowfish.c b/src/ltc/ciphers/blowfish.c
index caeb46ee..355a2359 100644
--- a/src/ltc/ciphers/blowfish.c
+++ b/src/ltc/ciphers/blowfish.c
@@ -580,7 +580,8 @@ int blowfish_keysize(int *keysize)
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
- } else if (*keysize > 56) {
+ }
+ if (*keysize > 56) {
*keysize = 56;
}
return CRYPT_OK;
diff --git a/src/ltc/ciphers/cast5.c b/src/ltc/ciphers/cast5.c
index 1089ade3..712b57d5 100644
--- a/src/ltc/ciphers/cast5.c
+++ b/src/ltc/ciphers/cast5.c
@@ -707,7 +707,8 @@ int cast5_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 5) {
return CRYPT_INVALID_KEYSIZE;
- } else if (*keysize > 16) {
+ }
+ if (*keysize > 16) {
*keysize = 16;
}
return CRYPT_OK;
diff --git a/src/ltc/ciphers/des.c b/src/ltc/ciphers/des.c
index a72fdf53..a5210306 100644
--- a/src/ltc/ciphers/des.c
+++ b/src/ltc/ciphers/des.c
@@ -2068,8 +2068,9 @@ int des_keysize(int *keysize)
int des3_keysize(int *keysize)
{
LTC_ARGCHK(keysize != NULL);
- if (*keysize < 16)
+ if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
+ }
if (*keysize < 24) {
*keysize = 16;
return CRYPT_OK;
diff --git a/src/ltc/ciphers/kasumi.c b/src/ltc/ciphers/kasumi.c
index fba9b655..ccd84e56 100644
--- a/src/ltc/ciphers/kasumi.c
+++ b/src/ltc/ciphers/kasumi.c
@@ -243,9 +243,8 @@ int kasumi_keysize(int *keysize)
if (*keysize >= 16) {
*keysize = 16;
return CRYPT_OK;
- } else {
- return CRYPT_INVALID_KEYSIZE;
}
+ return CRYPT_INVALID_KEYSIZE;
}
int kasumi_test(void)
diff --git a/src/ltc/ciphers/khazad.c b/src/ltc/ciphers/khazad.c
index c8d8d7a5..aa751821 100644
--- a/src/ltc/ciphers/khazad.c
+++ b/src/ltc/ciphers/khazad.c
@@ -843,9 +843,8 @@ int khazad_keysize(int *keysize)
if (*keysize >= 16) {
*keysize = 16;
return CRYPT_OK;
- } else {
- return CRYPT_INVALID_KEYSIZE;
}
+ return CRYPT_INVALID_KEYSIZE;
}
#endif
diff --git a/src/ltc/ciphers/noekeon.c b/src/ltc/ciphers/noekeon.c
index c933d45c..8850273b 100644
--- a/src/ltc/ciphers/noekeon.c
+++ b/src/ltc/ciphers/noekeon.c
@@ -314,10 +314,9 @@ int noekeon_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
- } else {
- *keysize = 16;
- return CRYPT_OK;
}
+ *keysize = 16;
+ return CRYPT_OK;
}
#endif
diff --git a/src/ltc/ciphers/rc2.c b/src/ltc/ciphers/rc2.c
index 61219fe7..ba09573e 100644
--- a/src/ltc/ciphers/rc2.c
+++ b/src/ltc/ciphers/rc2.c
@@ -401,7 +401,8 @@ int rc2_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 1) {
return CRYPT_INVALID_KEYSIZE;
- } else if (*keysize > 128) {
+ }
+ if (*keysize > 128) {
*keysize = 128;
}
return CRYPT_OK;
diff --git a/src/ltc/ciphers/rc5.c b/src/ltc/ciphers/rc5.c
index 41305f04..77951ebf 100644
--- a/src/ltc/ciphers/rc5.c
+++ b/src/ltc/ciphers/rc5.c
@@ -308,7 +308,8 @@ int rc5_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
- } else if (*keysize > 128) {
+ }
+ if (*keysize > 128) {
*keysize = 128;
}
return CRYPT_OK;
diff --git a/src/ltc/ciphers/rc6.c b/src/ltc/ciphers/rc6.c
index 1a71e50a..6d4ee2ad 100644
--- a/src/ltc/ciphers/rc6.c
+++ b/src/ltc/ciphers/rc6.c
@@ -318,7 +318,8 @@ int rc6_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
- } else if (*keysize > 128) {
+ }
+ if (*keysize > 128) {
*keysize = 128;
}
return CRYPT_OK;
diff --git a/src/ltc/ciphers/safer/safer.c b/src/ltc/ciphers/safer/safer.c
index 913e1936..61b394a5 100644
--- a/src/ltc/ciphers/safer/safer.c
+++ b/src/ltc/ciphers/safer/safer.c
@@ -113,8 +113,9 @@ static void Safer_Expand_Userkey(const unsigned char *userkey_1,
unsigned char ka[LTC_SAFER_BLOCK_LEN + 1];
unsigned char kb[LTC_SAFER_BLOCK_LEN + 1];
- if (LTC_SAFER_MAX_NOF_ROUNDS < nof_rounds)
+ if (LTC_SAFER_MAX_NOF_ROUNDS < nof_rounds) {
nof_rounds = LTC_SAFER_MAX_NOF_ROUNDS;
+ }
*key++ = (unsigned char)nof_rounds;
ka[LTC_SAFER_BLOCK_LEN] = (unsigned char)0;
kb[LTC_SAFER_BLOCK_LEN] = (unsigned char)0;
@@ -176,12 +177,12 @@ static void Safer_Expand_Userkey(const unsigned char *userkey_1,
}
#endif
-int safer_k64_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
+int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(skey != NULL);
- if (numrounds != 0 && (numrounds < 6 || numrounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
+ if (num_rounds != 0 && (num_rounds < 6 || num_rounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
return CRYPT_INVALID_ROUNDS;
}
@@ -189,16 +190,16 @@ int safer_k64_setup(const unsigned char *key, int keylen, int numrounds, symmetr
return CRYPT_INVALID_KEYSIZE;
}
- Safer_Expand_Userkey(key, key, (unsigned int)(numrounds != 0 ?numrounds:LTC_SAFER_K64_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
+ Safer_Expand_Userkey(key, key, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_K64_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
return CRYPT_OK;
}
-int safer_sk64_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
+int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(skey != NULL);
- if (numrounds != 0 && (numrounds < 6 || numrounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
+ if (num_rounds != 0 && (num_rounds < 6 || num_rounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
return CRYPT_INVALID_ROUNDS;
}
@@ -206,16 +207,16 @@ int safer_sk64_setup(const unsigned char *key, int keylen, int numrounds, symmet
return CRYPT_INVALID_KEYSIZE;
}
- Safer_Expand_Userkey(key, key, (unsigned int)(numrounds != 0 ?numrounds:LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
+ Safer_Expand_Userkey(key, key, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_SK64_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
return CRYPT_OK;
}
-int safer_k128_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
+int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(skey != NULL);
- if (numrounds != 0 && (numrounds < 6 || numrounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
+ if (num_rounds != 0 && (num_rounds < 6 || num_rounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
return CRYPT_INVALID_ROUNDS;
}
@@ -223,16 +224,16 @@ int safer_k128_setup(const unsigned char *key, int keylen, int numrounds, symmet
return CRYPT_INVALID_KEYSIZE;
}
- Safer_Expand_Userkey(key, key+8, (unsigned int)(numrounds != 0 ?numrounds:LTC_SAFER_K128_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
+ Safer_Expand_Userkey(key, key+8, (unsigned int)(num_rounds != 0 ?num_rounds:LTC_SAFER_K128_DEFAULT_NOF_ROUNDS), 0, skey->safer.key);
return CRYPT_OK;
}
-int safer_sk128_setup(const unsigned char *key, int keylen, int numrounds, symmetric_key *skey)
+int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
{
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(skey != NULL);
- if (numrounds != 0 && (numrounds < 6 || numrounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
+ if (num_rounds != 0 && (num_rounds < 6 || num_rounds > LTC_SAFER_MAX_NOF_ROUNDS)) {
return CRYPT_INVALID_ROUNDS;
}
@@ -240,30 +241,30 @@ int safer_sk128_setup(const unsigned char *key, int keylen, int numrounds, symme
return CRYPT_INVALID_KEYSIZE;
}
- Safer_Expand_Userkey(key, key+8, (unsigned int)(numrounds != 0?numrounds:LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
+ Safer_Expand_Userkey(key, key+8, (unsigned int)(num_rounds != 0?num_rounds:LTC_SAFER_SK128_DEFAULT_NOF_ROUNDS), 1, skey->safer.key);
return CRYPT_OK;
}
#ifdef LTC_CLEAN_STACK
-static int _safer_ecb_encrypt(const unsigned char *block_in,
- unsigned char *block_out,
+static int _safer_ecb_encrypt(const unsigned char *pt,
+ unsigned char *ct,
const symmetric_key *skey)
#else
-int safer_ecb_encrypt(const unsigned char *block_in,
- unsigned char *block_out,
+int safer_ecb_encrypt(const unsigned char *pt,
+ unsigned char *ct,
const symmetric_key *skey)
#endif
{ unsigned char a, b, c, d, e, f, g, h, t;
unsigned int round;
const unsigned char *key;
- LTC_ARGCHK(block_in != NULL);
- LTC_ARGCHK(block_out != NULL);
+ LTC_ARGCHK(pt != NULL);
+ LTC_ARGCHK(ct != NULL);
LTC_ARGCHK(skey != NULL);
key = skey->safer.key;
- a = block_in[0]; b = block_in[1]; c = block_in[2]; d = block_in[3];
- e = block_in[4]; f = block_in[5]; g = block_in[6]; h = block_in[7];
+ a = pt[0]; b = pt[1]; c = pt[2]; d = pt[3];
+ e = pt[4]; f = pt[5]; g = pt[6]; h = pt[7];
if (LTC_SAFER_MAX_NOF_ROUNDS < (round = *key)) round = LTC_SAFER_MAX_NOF_ROUNDS;
while(round-- > 0)
{
@@ -280,44 +281,44 @@ int safer_ecb_encrypt(const unsigned char *block_in,
}
a ^= *++key; b += *++key; c += *++key; d ^= *++key;
e ^= *++key; f += *++key; g += *++key; h ^= *++key;
- block_out[0] = a & 0xFF; block_out[1] = b & 0xFF;
- block_out[2] = c & 0xFF; block_out[3] = d & 0xFF;
- block_out[4] = e & 0xFF; block_out[5] = f & 0xFF;
- block_out[6] = g & 0xFF; block_out[7] = h & 0xFF;
+ ct[0] = a & 0xFF; ct[1] = b & 0xFF;
+ ct[2] = c & 0xFF; ct[3] = d & 0xFF;
+ ct[4] = e & 0xFF; ct[5] = f & 0xFF;
+ ct[6] = g & 0xFF; ct[7] = h & 0xFF;
return CRYPT_OK;
}
#ifdef LTC_CLEAN_STACK
-int safer_ecb_encrypt(const unsigned char *block_in,
- unsigned char *block_out,
+int safer_ecb_encrypt(const unsigned char *pt,
+ unsigned char *ct,
const symmetric_key *skey)
{
- int err = _safer_ecb_encrypt(block_in, block_out, skey);
+ int err = _safer_ecb_encrypt(pt, ct, skey);
burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
return err;
}
#endif
#ifdef LTC_CLEAN_STACK
-static int _safer_ecb_decrypt(const unsigned char *block_in,
- unsigned char *block_out,
+static int _safer_ecb_decrypt(const unsigned char *ct,
+ unsigned char *pt,
const symmetric_key *skey)
#else
-int safer_ecb_decrypt(const unsigned char *block_in,
- unsigned char *block_out,
+int safer_ecb_decrypt(const unsigned char *ct,
+ unsigned char *pt,
const symmetric_key *skey)
#endif
{ unsigned char a, b, c, d, e, f, g, h, t;
unsigned int round;
const unsigned char *key;
- LTC_ARGCHK(block_in != NULL);
- LTC_ARGCHK(block_out != NULL);
+ LTC_ARGCHK(ct != NULL);
+ LTC_ARGCHK(pt != NULL);
LTC_ARGCHK(skey != NULL);
key = skey->safer.key;
- a = block_in[0]; b = block_in[1]; c = block_in[2]; d = block_in[3];
- e = block_in[4]; f = block_in[5]; g = block_in[6]; h = block_in[7];
+ a = ct[0]; b = ct[1]; c = ct[2]; d = ct[3];
+ e = ct[4]; f = ct[5]; g = ct[6]; h = ct[7];
if (LTC_SAFER_MAX_NOF_ROUNDS < (round = *key)) round = LTC_SAFER_MAX_NOF_ROUNDS;
key += LTC_SAFER_BLOCK_LEN * (1 + 2 * round);
h ^= *key; g -= *--key; f -= *--key; e ^= *--key;
@@ -335,19 +336,19 @@ int safer_ecb_decrypt(const unsigned char *block_in,
d = LOG(d) ^ *--key; c = EXP(c) - *--key;
b = EXP(b) - *--key; a = LOG(a) ^ *--key;
}
- block_out[0] = a & 0xFF; block_out[1] = b & 0xFF;
- block_out[2] = c & 0xFF; block_out[3] = d & 0xFF;
- block_out[4] = e & 0xFF; block_out[5] = f & 0xFF;
- block_out[6] = g & 0xFF; block_out[7] = h & 0xFF;
+ pt[0] = a & 0xFF; pt[1] = b & 0xFF;
+ pt[2] = c & 0xFF; pt[3] = d & 0xFF;
+ pt[4] = e & 0xFF; pt[5] = f & 0xFF;
+ pt[6] = g & 0xFF; pt[7] = h & 0xFF;
return CRYPT_OK;
}
#ifdef LTC_CLEAN_STACK
-int safer_ecb_decrypt(const unsigned char *block_in,
- unsigned char *block_out,
+int safer_ecb_decrypt(const unsigned char *ct,
+ unsigned char *pt,
const symmetric_key *skey)
{
- int err = _safer_ecb_decrypt(block_in, block_out, skey);
+ int err = _safer_ecb_decrypt(ct, pt, skey);
burn_stack(sizeof(unsigned char) * 9 + sizeof(unsigned int) + sizeof(unsigned char *));
return err;
}
@@ -358,10 +359,9 @@ int safer_64_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 8) {
return CRYPT_INVALID_KEYSIZE;
- } else {
- *keysize = 8;
- return CRYPT_OK;
}
+ *keysize = 8;
+ return CRYPT_OK;
}
int safer_128_keysize(int *keysize)
@@ -369,10 +369,9 @@ int safer_128_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
- } else {
- *keysize = 16;
- return CRYPT_OK;
}
+ *keysize = 16;
+ return CRYPT_OK;
}
int safer_k64_test(void)
diff --git a/src/ltc/ciphers/safer/saferp.c b/src/ltc/ciphers/safer/saferp.c
index e6e1c909..562b2e95 100644
--- a/src/ltc/ciphers/safer/saferp.c
+++ b/src/ltc/ciphers/safer/saferp.c
@@ -547,8 +547,9 @@ int saferp_keysize(int *keysize)
{
LTC_ARGCHK(keysize != NULL);
- if (*keysize < 16)
+ if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
+ }
if (*keysize < 24) {
*keysize = 16;
} else if (*keysize < 32) {
diff --git a/src/ltc/ciphers/skipjack.c b/src/ltc/ciphers/skipjack.c
index 8726af23..8df1f85b 100644
--- a/src/ltc/ciphers/skipjack.c
+++ b/src/ltc/ciphers/skipjack.c
@@ -330,7 +330,8 @@ int skipjack_keysize(int *keysize)
LTC_ARGCHK(keysize != NULL);
if (*keysize < 10) {
return CRYPT_INVALID_KEYSIZE;
- } else if (*keysize > 10) {
+ }
+ if (*keysize > 10) {
*keysize = 10;
}
return CRYPT_OK;
diff --git a/src/ltc/ciphers/twofish/twofish.c b/src/ltc/ciphers/twofish/twofish.c
index cbc85fad..0a52aefa 100644
--- a/src/ltc/ciphers/twofish/twofish.c
+++ b/src/ltc/ciphers/twofish/twofish.c
@@ -689,25 +689,24 @@ void twofish_done(symmetric_key *skey)
int twofish_keysize(int *keysize)
{
LTC_ARGCHK(keysize);
- if (*keysize < 16)
+ if (*keysize < 16) {
return CRYPT_INVALID_KEYSIZE;
+ }
if (*keysize < 24) {
*keysize = 16;
return CRYPT_OK;
- } else if (*keysize < 32) {
+ }
+ if (*keysize < 32) {
*keysize = 24;
return CRYPT_OK;
- } else {
- *keysize = 32;
- return CRYPT_OK;
}
+ *keysize = 32;
+ return CRYPT_OK;
}
#endif
-
-
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
diff --git a/src/ltc/encauth/ocb3/ocb3_decrypt_last.c b/src/ltc/encauth/ocb3/ocb3_decrypt_last.c
index cb0b6ead..2b5158c3 100644
--- a/src/ltc/encauth/ocb3/ocb3_decrypt_last.c
+++ b/src/ltc/encauth/ocb3/ocb3_decrypt_last.c
@@ -66,10 +66,11 @@ int ocb3_decrypt_last(ocb3_state *ocb, const unsigned char *ct, unsigned long ct
/* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len);
for(x=last_block_len; x<ocb->block_len; x++) {
- if (x == last_block_len)
+ if (x == last_block_len) {
ocb->checksum[x] ^= 0x80;
- else
+ } else {
ocb->checksum[x] ^= 0x00;
+ }
}
/* Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */
diff --git a/src/ltc/encauth/ocb3/ocb3_encrypt_last.c b/src/ltc/encauth/ocb3/ocb3_encrypt_last.c
index 5834ef4a..03343057 100644
--- a/src/ltc/encauth/ocb3/ocb3_encrypt_last.c
+++ b/src/ltc/encauth/ocb3/ocb3_encrypt_last.c
@@ -68,10 +68,11 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
/* Checksum_* = Checksum_m xor (P_* || 1 || zeros(127-bitlen(P_*))) */
ocb3_int_xor_blocks(ocb->checksum, ocb->checksum, pt+full_blocks_len, last_block_len);
for(x=last_block_len; x<ocb->block_len; x++) {
- if (x == last_block_len)
+ if (x == last_block_len) {
ocb->checksum[x] ^= 0x80;
- else
+ } else {
ocb->checksum[x] ^= 0x00;
+ }
}
/* Tag = ENCIPHER(K, Checksum_* xor Offset_* xor L_$) xor HASH(K,A) */
@@ -82,8 +83,7 @@ int ocb3_encrypt_last(ocb3_state *ocb, const unsigned char *pt, unsigned long pt
if ((err = cipher_descriptor[ocb->cipher].ecb_encrypt(ocb->tag_part, ocb->tag_part, &ocb->key)) != CRYPT_OK) {
goto LBL_ERR;
}
- }
- else {
+ } else {
/* Tag = ENCIPHER(K, Checksum_m xor Offset_m xor L_$) xor HASH(K,A) */
/* at this point we calculate only: Tag_part = ENCIPHER(K, Checksum_m xor Offset_m xor L_$) */
for(x=0; x<ocb->block_len; x++) {
diff --git a/src/ltc/hashes/blake2b.c b/src/ltc/hashes/blake2b.c
index 6b91a851..0f6f0c07 100644
--- a/src/ltc/hashes/blake2b.c
+++ b/src/ltc/hashes/blake2b.c
@@ -160,9 +160,9 @@ static int blake2b_is_lastblock(const hash_state *md) { return md->blake2b.f[0]
static void blake2b_set_lastblock(hash_state *md)
{
- if (md->blake2b.last_node)
+ if (md->blake2b.last_node) {
blake2b_set_lastnode(md);
-
+ }
md->blake2b.f[0] = CONST64(0xffffffffffffffff);
}
@@ -177,8 +177,9 @@ static void blake2b_init0(hash_state *md)
unsigned long i;
XMEMSET(&md->blake2b, 0, sizeof(md->blake2b));
- for (i = 0; i < 8; ++i)
+ for (i = 0; i < 8; ++i) {
md->blake2b.h[i] = blake2b_IV[i];
+ }
}
/* init xors IV with input parameter block */
@@ -219,11 +220,12 @@ int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key,
LTC_ARGCHK(md != NULL);
- if ((!outlen) || (outlen > BLAKE2B_OUTBYTES))
+ if ((!outlen) || (outlen > BLAKE2B_OUTBYTES)) {
return CRYPT_INVALID_ARG;
-
- if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES))
+ }
+ if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2B_KEYBYTES)) {
return CRYPT_INVALID_ARG;
+ }
XMEMSET(P, 0, sizeof(P));
@@ -416,16 +418,18 @@ int blake2b_done(hash_state *md, unsigned char *out)
/* if(md->blakebs.outlen != outlen) return CRYPT_INVALID_ARG; */
- if (blake2b_is_lastblock(md))
+ if (blake2b_is_lastblock(md)) {
return CRYPT_ERROR;
+ }
blake2b_increment_counter(md, md->blake2b.curlen);
blake2b_set_lastblock(md);
XMEMSET(md->blake2b.buf + md->blake2b.curlen, 0, BLAKE2B_BLOCKBYTES - md->blake2b.curlen); /* Padding */
blake2b_compress(md, md->blake2b.buf);
- for (i = 0; i < 8; ++i) /* Output full hash to temp buffer */
+ for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
STORE64L(md->blake2b.h[i], buffer + i * 8);
+ }
XMEMCPY(out, buffer, md->blake2b.outlen);
zeromem(md, sizeof(hash_state));
diff --git a/src/ltc/hashes/blake2s.c b/src/ltc/hashes/blake2s.c
index 96439eb6..2714ce63 100644
--- a/src/ltc/hashes/blake2s.c
+++ b/src/ltc/hashes/blake2s.c
@@ -152,9 +152,9 @@ static int blake2s_is_lastblock(const hash_state *md) { return md->blake2s.f[0]
static void blake2s_set_lastblock(hash_state *md)
{
- if (md->blake2s.last_node)
+ if (md->blake2s.last_node) {
blake2s_set_lastnode(md);
-
+ }
md->blake2s.f[0] = 0xffffffffUL;
}
@@ -169,8 +169,9 @@ static int blake2s_init0(hash_state *md)
int i;
XMEMSET(&md->blake2s, 0, sizeof(struct blake2s_state));
- for (i = 0; i < 8; ++i)
+ for (i = 0; i < 8; ++i) {
md->blake2s.h[i] = blake2s_IV[i];
+ }
return CRYPT_OK;
}
@@ -213,11 +214,12 @@ int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key,
LTC_ARGCHK(md != NULL);
- if ((!outlen) || (outlen > BLAKE2S_OUTBYTES))
+ if ((!outlen) || (outlen > BLAKE2S_OUTBYTES)) {
return CRYPT_INVALID_ARG;
-
- if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2S_KEYBYTES))
+ }
+ if ((key && !keylen) || (keylen && !key) || (keylen > BLAKE2S_KEYBYTES)) {
return CRYPT_INVALID_ARG;
+ }
XMEMSET(P, 0, sizeof(P));
@@ -308,8 +310,9 @@ static int blake2s_compress(hash_state *md, const unsigned char *buf)
LOAD32L(m[i], buf + i * sizeof(m[i]));
}
- for (i = 0; i < 8; ++i)
+ for (i = 0; i < 8; ++i) {
v[i] = md->blake2s.h[i];
+ }
v[8] = blake2s_IV[0];
v[9] = blake2s_IV[1];
@@ -331,9 +334,9 @@ static int blake2s_compress(hash_state *md, const unsigned char *buf)
ROUND(8);
ROUND(9);
- for (i = 0; i < 8; ++i)
+ for (i = 0; i < 8; ++i) {
md->blake2s.h[i] = md->blake2s.h[i] ^ v[i] ^ v[i + 8];
-
+ }
return CRYPT_OK;
}
#undef G
@@ -404,16 +407,17 @@ int blake2s_done(hash_state *md, unsigned char *out)
/* if(md->blake2s.outlen != outlen) return CRYPT_INVALID_ARG; */
- if (blake2s_is_lastblock(md))
+ if (blake2s_is_lastblock(md)) {
return CRYPT_ERROR;
-
+ }
blake2s_increment_counter(md, md->blake2s.curlen);
blake2s_set_lastblock(md);
XMEMSET(md->blake2s.buf + md->blake2s.curlen, 0, BLAKE2S_BLOCKBYTES - md->blake2s.curlen); /* Padding */
blake2s_compress(md, md->blake2s.buf);
- for (i = 0; i < 8; ++i) /* Output full hash to temp buffer */
+ for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
STORE32L(md->blake2s.h[i], buffer + i * 4);
+ }
XMEMCPY(out, buffer, md->blake2s.outlen);
zeromem(md, sizeof(hash_state));
diff --git a/src/ltc/hashes/chc/chc.c b/src/ltc/hashes/chc/chc.c
index bcb6947a..0a526d6b 100644
--- a/src/ltc/hashes/chc/chc.c
+++ b/src/ltc/hashes/chc/chc.c
@@ -160,7 +160,7 @@ static int chc_compress(hash_state *md, const unsigned char *buf)
@param len The length of the data (octets)
@return CRYPT_OK if successful
*/
-static int _chc_process(hash_state * md, const unsigned char *buf, unsigned long len);
+static int _chc_process(hash_state * md, const unsigned char *in, unsigned long inlen);
static HASH_PROCESS(_chc_process, chc_compress, chc, (unsigned long)cipher_blocksize)
/**
diff --git a/src/ltc/hashes/sha3.c b/src/ltc/hashes/sha3.c
index d9bbc8af..180344e9 100644
--- a/src/ltc/hashes/sha3.c
+++ b/src/ltc/hashes/sha3.c
@@ -167,13 +167,14 @@ static void keccakf(ulong64 s[25])
for(round = 0; round < SHA3_KECCAK_ROUNDS; round++) {
/* Theta */
- for(i = 0; i < 5; i++)
+ for(i = 0; i < 5; i++) {
bc[i] = s[i] ^ s[i + 5] ^ s[i + 10] ^ s[i + 15] ^ s[i + 20];
-
+ }
for(i = 0; i < 5; i++) {
t = bc[(i + 4) % 5] ^ ROL64(bc[(i + 1) % 5], 1);
- for(j = 0; j < 25; j += 5)
+ for(j = 0; j < 25; j += 5) {
s[j + i] ^= t;
+ }
}
/* Rho Pi */
t = s[1];
@@ -185,10 +186,12 @@ static void keccakf(ulong64 s[25])
}
/* Chi */
for(j = 0; j < 25; j += 5) {
- for(i = 0; i < 5; i++)
+ for(i = 0; i < 5; i++) {
bc[i] = s[j + i];
- for(i = 0; i < 5; i++)
+ }
+ for(i = 0; i < 5; i++) {
s[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
+ }
}
/* Iota */
s[0] ^= keccakf_rndc[round];
@@ -313,16 +316,16 @@ int sha3_process(hash_state *md, const unsigned char *in, unsigned long inlen)
}
#ifdef LTC_SHA3
-int sha3_done(hash_state *md, unsigned char *hash)
+int sha3_done(hash_state *md, unsigned char *out)
{
- return _done(md, hash, CONST64(0x06));
+ return _done(md, out, CONST64(0x06));
}
#endif
#ifdef LTC_KECCAK
-int keccak_done(hash_state *md, unsigned char *hash)
+int keccak_done(hash_state *md, unsigned char *out)
{
- return _done(md, hash, CONST64(0x01));
+ return _done(md, out, CONST64(0x01));
}
#endif
diff --git a/src/ltc/headers/tomcrypt.h b/src/ltc/headers/tomcrypt.h
index 1aca366e..38641ae8 100644
--- a/src/ltc/headers/tomcrypt.h
+++ b/src/ltc/headers/tomcrypt.h
@@ -27,13 +27,15 @@ extern "C" {
/* version */
#define CRYPT 0x0118
-#define SCRYPT "1.18.1-develop"
+#define SCRYPT "1.18.2-develop"
/* max size of either a cipher/hash block or symmetric key [largest of the two] */
#define MAXBLOCKSIZE 144
+#ifndef TAB_SIZE
/* descriptor table size */
#define TAB_SIZE 34
+#endif
/* error codes [will be expanded in future releases] */
enum {
diff --git a/src/ltc/headers/tomcrypt_cipher.h b/src/ltc/headers/tomcrypt_cipher.h
index 4b983593..5c3a5e63 100644
--- a/src/ltc/headers/tomcrypt_cipher.h
+++ b/src/ltc/headers/tomcrypt_cipher.h
@@ -673,8 +673,8 @@ int safer_k64_setup(const unsigned char *key, int keylen, int num_rounds, symmet
int safer_sk64_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
int safer_k128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
int safer_sk128_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
-int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *key);
-int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *key);
+int safer_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
+int safer_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
int safer_k64_test(void);
int safer_sk64_test(void);
int safer_sk128_test(void);
@@ -1057,7 +1057,7 @@ typedef struct {
int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long keylen);
int sosemanuk_setiv(sosemanuk_state *ss, const unsigned char *iv, unsigned long ivlen);
-int sosemanuk_crypt(sosemanuk_state *ss, const unsigned char *in, unsigned long datalen, unsigned char *out);
+int sosemanuk_crypt(sosemanuk_state *ss, const unsigned char *in, unsigned long inlen, unsigned char *out);
int sosemanuk_keystream(sosemanuk_state *ss, unsigned char *out, unsigned long outlen);
int sosemanuk_done(sosemanuk_state *ss);
int sosemanuk_test(void);
diff --git a/src/ltc/headers/tomcrypt_custom.h b/src/ltc/headers/tomcrypt_custom.h
index 27727186..a151187f 100644
--- a/src/ltc/headers/tomcrypt_custom.h
+++ b/src/ltc/headers/tomcrypt_custom.h
@@ -417,7 +417,7 @@
#define LTC_DH1536
#define LTC_DH2048
-#ifndef TFM_DESC
+#if defined(LTM_DESC) || defined(GMP_DESC)
/* tfm has a problem in fp_isprime for larger key sizes */
#define LTC_DH3072
#define LTC_DH4096
@@ -463,6 +463,7 @@
#define LTC_PKCS_1
#define LTC_PKCS_5
+#define LTC_PKCS_12
/* Include ASN.1 DER (required by DSA/RSA) */
#define LTC_DER
diff --git a/src/ltc/headers/tomcrypt_hash.h b/src/ltc/headers/tomcrypt_hash.h
index dbb6b9a1..fb043ca4 100644
--- a/src/ltc/headers/tomcrypt_hash.h
+++ b/src/ltc/headers/tomcrypt_hash.h
@@ -250,7 +250,7 @@ extern struct ltc_hash_descriptor {
int chc_register(int cipher);
int chc_init(hash_state * md);
int chc_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int chc_done(hash_state * md, unsigned char *hash);
+int chc_done(hash_state * md, unsigned char *out);
int chc_test(void);
extern const struct ltc_hash_descriptor chc_desc;
#endif
@@ -258,7 +258,7 @@ extern const struct ltc_hash_descriptor chc_desc;
#ifdef LTC_WHIRLPOOL
int whirlpool_init(hash_state * md);
int whirlpool_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int whirlpool_done(hash_state * md, unsigned char *hash);
+int whirlpool_done(hash_state * md, unsigned char *out);
int whirlpool_test(void);
extern const struct ltc_hash_descriptor whirlpool_desc;
#endif
@@ -282,7 +282,7 @@ int sha3_256_test(void);
extern const struct ltc_hash_descriptor sha3_256_desc;
int sha3_224_test(void);
extern const struct ltc_hash_descriptor sha3_224_desc;
-int sha3_done(hash_state *md, unsigned char *hash);
+int sha3_done(hash_state *md, unsigned char *out);
/* SHAKE128 + SHAKE256 */
int sha3_shake_init(hash_state *md, int num);
#define sha3_shake_process(a,b,c) sha3_process(a,b,c)
@@ -305,13 +305,13 @@ extern const struct ltc_hash_descriptor keccak_256_desc;
int keccak_256_test(void);
extern const struct ltc_hash_descriptor keccak_224_desc;
int keccak_224_test(void);
-int keccak_done(hash_state *md, unsigned char *hash);
+int keccak_done(hash_state *md, unsigned char *out);
#endif
#ifdef LTC_SHA512
int sha512_init(hash_state * md);
int sha512_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int sha512_done(hash_state * md, unsigned char *hash);
+int sha512_done(hash_state * md, unsigned char *out);
int sha512_test(void);
extern const struct ltc_hash_descriptor sha512_desc;
#endif
@@ -322,7 +322,7 @@ extern const struct ltc_hash_descriptor sha512_desc;
#endif
int sha384_init(hash_state * md);
#define sha384_process sha512_process
-int sha384_done(hash_state * md, unsigned char *hash);
+int sha384_done(hash_state * md, unsigned char *out);
int sha384_test(void);
extern const struct ltc_hash_descriptor sha384_desc;
#endif
@@ -333,7 +333,7 @@ extern const struct ltc_hash_descriptor sha384_desc;
#endif
int sha512_256_init(hash_state * md);
#define sha512_256_process sha512_process
-int sha512_256_done(hash_state * md, unsigned char *hash);
+int sha512_256_done(hash_state * md, unsigned char *out);
int sha512_256_test(void);
extern const struct ltc_hash_descriptor sha512_256_desc;
#endif
@@ -344,7 +344,7 @@ extern const struct ltc_hash_descriptor sha512_256_desc;
#endif
int sha512_224_init(hash_state * md);
#define sha512_224_process sha512_process
-int sha512_224_done(hash_state * md, unsigned char *hash);
+int sha512_224_done(hash_state * md, unsigned char *out);
int sha512_224_test(void);
extern const struct ltc_hash_descriptor sha512_224_desc;
#endif
@@ -352,7 +352,7 @@ extern const struct ltc_hash_descriptor sha512_224_desc;
#ifdef LTC_SHA256
int sha256_init(hash_state * md);
int sha256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int sha256_done(hash_state * md, unsigned char *hash);
+int sha256_done(hash_state * md, unsigned char *out);
int sha256_test(void);
extern const struct ltc_hash_descriptor sha256_desc;
@@ -362,7 +362,7 @@ extern const struct ltc_hash_descriptor sha256_desc;
#endif
int sha224_init(hash_state * md);
#define sha224_process sha256_process
-int sha224_done(hash_state * md, unsigned char *hash);
+int sha224_done(hash_state * md, unsigned char *out);
int sha224_test(void);
extern const struct ltc_hash_descriptor sha224_desc;
#endif
@@ -371,7 +371,7 @@ extern const struct ltc_hash_descriptor sha224_desc;
#ifdef LTC_SHA1
int sha1_init(hash_state * md);
int sha1_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int sha1_done(hash_state * md, unsigned char *hash);
+int sha1_done(hash_state * md, unsigned char *out);
int sha1_test(void);
extern const struct ltc_hash_descriptor sha1_desc;
#endif
@@ -395,7 +395,7 @@ int blake2s_128_test(void);
int blake2s_init(hash_state * md, unsigned long outlen, const unsigned char *key, unsigned long keylen);
int blake2s_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int blake2s_done(hash_state * md, unsigned char *hash);
+int blake2s_done(hash_state * md, unsigned char *out);
#endif
#ifdef LTC_BLAKE2B
@@ -417,13 +417,13 @@ int blake2b_160_test(void);
int blake2b_init(hash_state * md, unsigned long outlen, const unsigned char *key, unsigned long keylen);
int blake2b_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int blake2b_done(hash_state * md, unsigned char *hash);
+int blake2b_done(hash_state * md, unsigned char *out);
#endif
#ifdef LTC_MD5
int md5_init(hash_state * md);
int md5_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int md5_done(hash_state * md, unsigned char *hash);
+int md5_done(hash_state * md, unsigned char *out);
int md5_test(void);
extern const struct ltc_hash_descriptor md5_desc;
#endif
@@ -431,7 +431,7 @@ extern const struct ltc_hash_descriptor md5_desc;
#ifdef LTC_MD4
int md4_init(hash_state * md);
int md4_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int md4_done(hash_state * md, unsigned char *hash);
+int md4_done(hash_state * md, unsigned char *out);
int md4_test(void);
extern const struct ltc_hash_descriptor md4_desc;
#endif
@@ -439,7 +439,7 @@ extern const struct ltc_hash_descriptor md4_desc;
#ifdef LTC_MD2
int md2_init(hash_state * md);
int md2_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int md2_done(hash_state * md, unsigned char *hash);
+int md2_done(hash_state * md, unsigned char *out);
int md2_test(void);
extern const struct ltc_hash_descriptor md2_desc;
#endif
@@ -447,7 +447,7 @@ extern const struct ltc_hash_descriptor md2_desc;
#ifdef LTC_TIGER
int tiger_init(hash_state * md);
int tiger_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int tiger_done(hash_state * md, unsigned char *hash);
+int tiger_done(hash_state * md, unsigned char *out);
int tiger_test(void);
extern const struct ltc_hash_descriptor tiger_desc;
#endif
@@ -455,7 +455,7 @@ extern const struct ltc_hash_descriptor tiger_desc;
#ifdef LTC_RIPEMD128
int rmd128_init(hash_state * md);
int rmd128_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int rmd128_done(hash_state * md, unsigned char *hash);
+int rmd128_done(hash_state * md, unsigned char *out);
int rmd128_test(void);
extern const struct ltc_hash_descriptor rmd128_desc;
#endif
@@ -463,7 +463,7 @@ extern const struct ltc_hash_descriptor rmd128_desc;
#ifdef LTC_RIPEMD160
int rmd160_init(hash_state * md);
int rmd160_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int rmd160_done(hash_state * md, unsigned char *hash);
+int rmd160_done(hash_state * md, unsigned char *out);
int rmd160_test(void);
extern const struct ltc_hash_descriptor rmd160_desc;
#endif
@@ -471,7 +471,7 @@ extern const struct ltc_hash_descriptor rmd160_desc;
#ifdef LTC_RIPEMD256
int rmd256_init(hash_state * md);
int rmd256_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int rmd256_done(hash_state * md, unsigned char *hash);
+int rmd256_done(hash_state * md, unsigned char *out);
int rmd256_test(void);
extern const struct ltc_hash_descriptor rmd256_desc;
#endif
@@ -479,7 +479,7 @@ extern const struct ltc_hash_descriptor rmd256_desc;
#ifdef LTC_RIPEMD320
int rmd320_init(hash_state * md);
int rmd320_process(hash_state * md, const unsigned char *in, unsigned long inlen);
-int rmd320_done(hash_state * md, unsigned char *hash);
+int rmd320_done(hash_state * md, unsigned char *out);
int rmd320_test(void);
extern const struct ltc_hash_descriptor rmd320_desc;
#endif
diff --git a/src/ltc/headers/tomcrypt_mac.h b/src/ltc/headers/tomcrypt_mac.h
index e4fdf14a..cafb9a09 100644
--- a/src/ltc/headers/tomcrypt_mac.h
+++ b/src/ltc/headers/tomcrypt_mac.h
@@ -29,7 +29,7 @@ int hmac_memory_multi(int hash,
const unsigned char *in, unsigned long inlen, ...);
int hmac_file(int hash, const char *fname, const unsigned char *key,
unsigned long keylen,
- unsigned char *dst, unsigned long *dstlen);
+ unsigned char *out, unsigned long *outlen);
#endif
#ifdef LTC_OMAC
@@ -84,7 +84,7 @@ int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen);
int pmac_memory(int cipher,
const unsigned char *key, unsigned long keylen,
- const unsigned char *msg, unsigned long msglen,
+ const unsigned char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
int pmac_memory_multi(int cipher,
@@ -230,7 +230,7 @@ int f9_memory_multi(int cipher,
const unsigned char *in, unsigned long inlen, ...);
int f9_file(int cipher,
const unsigned char *key, unsigned long keylen,
- const char *filename,
+ const char *fname,
unsigned char *out, unsigned long *outlen);
int f9_test(void);
@@ -419,7 +419,7 @@ typedef struct {
} ccm_state;
int ccm_init(ccm_state *ccm, int cipher,
- const unsigned char *key, int keylen, int ptlen, int taglen, int aad_len);
+ const unsigned char *key, int keylen, int ptlen, int taglen, int aadlen);
int ccm_reset(ccm_state *ccm);
diff --git a/src/ltc/headers/tomcrypt_misc.h b/src/ltc/headers/tomcrypt_misc.h
index b30e087d..a5dd130e 100644
--- a/src/ltc/headers/tomcrypt_misc.h
+++ b/src/ltc/headers/tomcrypt_misc.h
@@ -9,26 +9,26 @@
/* ---- LTC_BASE64 Routines ---- */
#ifdef LTC_BASE64
-int base64_encode(const unsigned char *in, unsigned long len,
+int base64_encode(const unsigned char *in, unsigned long inlen,
char *out, unsigned long *outlen);
-int base64_decode(const char *in, unsigned long len,
+int base64_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
-int base64_strict_decode(const char *in, unsigned long len,
+int base64_strict_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
int base64_sane_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
#endif
#ifdef LTC_BASE64_URL
-int base64url_encode(const unsigned char *in, unsigned long len,
+int base64url_encode(const unsigned char *in, unsigned long inlen,
char *out, unsigned long *outlen);
int base64url_strict_encode(const unsigned char *in, unsigned long inlen,
char *out, unsigned long *outlen);
-int base64url_decode(const char *in, unsigned long len,
+int base64url_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
-int base64url_strict_decode(const char *in, unsigned long len,
+int base64url_strict_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
int base64url_sane_decode(const char *in, unsigned long inlen,
unsigned char *out, unsigned long *outlen);
@@ -84,7 +84,7 @@ int hkdf(int hash_idx,
/* ---- MEM routines ---- */
int mem_neq(const void *a, const void *b, size_t len);
-void zeromem(volatile void *dst, size_t len);
+void zeromem(volatile void *out, size_t outlen);
void burn_stack(unsigned long len);
const char *error_to_string(int err);
diff --git a/src/ltc/headers/tomcrypt_pk.h b/src/ltc/headers/tomcrypt_pk.h
index 64e83bd4..b4e5fffd 100644
--- a/src/ltc/headers/tomcrypt_pk.h
+++ b/src/ltc/headers/tomcrypt_pk.h
@@ -251,8 +251,8 @@ int ecc_test(void);
void ecc_sizes(int *low, int *high);
int ecc_get_size(const ecc_key *key);
-int ecc_get_curve(const char* name_or_oid, const ltc_ecc_curve** cu);
-int ecc_set_dp(const ltc_ecc_curve *cu, ecc_key *key);
+int ecc_find_curve(const char* name_or_oid, const ltc_ecc_curve** cu);
+int ecc_set_curve(const ltc_ecc_curve *cu, ecc_key *key);
int ecc_generate_key(prng_state *prng, int wprng, ecc_key *key);
int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key *key);
int ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_key *key);
@@ -573,7 +573,7 @@ int der_decode_boolean(const unsigned char *in, unsigned long inlen,
/* INTEGER */
int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen);
int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num);
-int der_length_integer(void *num, unsigned long *len);
+int der_length_integer(void *num, unsigned long *outlen);
/* INTEGER -- handy for 0..2^32-1 values */
int der_decode_short_integer(const unsigned char *in, unsigned long inlen, unsigned long *num);
diff --git a/src/ltc/headers/tomcrypt_pkcs.h b/src/ltc/headers/tomcrypt_pkcs.h
index 247e5387..0c99f7c3 100644
--- a/src/ltc/headers/tomcrypt_pkcs.h
+++ b/src/ltc/headers/tomcrypt_pkcs.h
@@ -103,6 +103,7 @@ int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
int pkcs_5_test (void);
#endif /* LTC_PKCS_5 */
+
/* ref: $Format:%D$ */
/* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */
diff --git a/src/ltc/headers/tomcrypt_private.h b/src/ltc/headers/tomcrypt_private.h
index eeabfc23..7fe4b014 100644
--- a/src/ltc/headers/tomcrypt_private.h
+++ b/src/ltc/headers/tomcrypt_private.h
@@ -192,9 +192,9 @@ int dh_check_pubkey(const dh_key *key);
/* ---- ECC Routines ---- */
#ifdef LTC_MECC
-int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key);
-int ecc_copy_dp(const ecc_key *srckey, ecc_key *key);
-int ecc_set_dp_by_size(int size, ecc_key *key);
+int ecc_set_curve_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key);
+int ecc_copy_curve(const ecc_key *srckey, ecc_key *key);
+int ecc_set_curve_by_size(int size, ecc_key *key);
int ecc_import_subject_public_key_info(const unsigned char *in, unsigned long inlen, ecc_key *key);
/* low level functions */
@@ -275,7 +275,7 @@ int der_decode_asn1_identifier(const unsigned char *in, unsigned long *inlen, lt
int der_length_asn1_identifier(const ltc_asn1_list *id, unsigned long *idlen);
int der_encode_asn1_length(unsigned long len, unsigned char* out, unsigned long* outlen);
-int der_decode_asn1_length(const unsigned char* len, unsigned long* lenlen, unsigned long* outlen);
+int der_decode_asn1_length(const unsigned char *in, unsigned long *inlen, unsigned long *outlen);
int der_length_asn1_length(unsigned long len, unsigned long *outlen);
int der_length_sequence_ex(const ltc_asn1_list *list, unsigned long inlen,
@@ -305,6 +305,21 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
#endif /* LTC_DER */
+/* tomcrypt_pkcs.h */
+
+#ifdef LTC_PKCS_12
+
+int pkcs12_utf8_to_utf16(const unsigned char *in, unsigned long inlen,
+ unsigned char *out, unsigned long *outlen);
+
+int pkcs12_kdf( int hash_id,
+ const unsigned char *pw, unsigned long pwlen,
+ const unsigned char *salt, unsigned long saltlen,
+ unsigned int iterations, unsigned char purpose,
+ unsigned char *out, unsigned long outlen);
+
+#endif /* LTC_PKCS_12 */
+
/* tomcrypt_prng.h */
#define _LTC_PRNG_EXPORT(which) \
diff --git a/src/ltc/mac/pmac/pmac_done.c b/src/ltc/mac/pmac/pmac_done.c
index 18296e02..347890ff 100644
--- a/src/ltc/mac/pmac/pmac_done.c
+++ b/src/ltc/mac/pmac/pmac_done.c
@@ -15,51 +15,51 @@
#ifdef LTC_PMAC
-int pmac_done(pmac_state *state, unsigned char *out, unsigned long *outlen)
+int pmac_done(pmac_state *pmac, unsigned char *out, unsigned long *outlen)
{
int err, x;
- LTC_ARGCHK(state != NULL);
- LTC_ARGCHK(out != NULL);
- if ((err = cipher_is_valid(state->cipher_idx)) != CRYPT_OK) {
+ LTC_ARGCHK(pmac != NULL);
+ LTC_ARGCHK(out != NULL);
+ if ((err = cipher_is_valid(pmac->cipher_idx)) != CRYPT_OK) {
return err;
}
- if ((state->buflen > (int)sizeof(state->block)) || (state->buflen < 0) ||
- (state->block_len > (int)sizeof(state->block)) || (state->buflen > state->block_len)) {
+ if ((pmac->buflen > (int)sizeof(pmac->block)) || (pmac->buflen < 0) ||
+ (pmac->block_len > (int)sizeof(pmac->block)) || (pmac->buflen > pmac->block_len)) {
return CRYPT_INVALID_ARG;
}
/* handle padding. If multiple xor in L/x */
- if (state->buflen == state->block_len) {
+ if (pmac->buflen == pmac->block_len) {
/* xor Lr against the checksum */
- for (x = 0; x < state->block_len; x++) {
- state->checksum[x] ^= state->block[x] ^ state->Lr[x];
+ for (x = 0; x < pmac->block_len; x++) {
+ pmac->checksum[x] ^= pmac->block[x] ^ pmac->Lr[x];
}
} else {
/* otherwise xor message bytes then the 0x80 byte */
- for (x = 0; x < state->buflen; x++) {
- state->checksum[x] ^= state->block[x];
+ for (x = 0; x < pmac->buflen; x++) {
+ pmac->checksum[x] ^= pmac->block[x];
}
- state->checksum[x] ^= 0x80;
+ pmac->checksum[x] ^= 0x80;
}
/* encrypt it */
- if ((err = cipher_descriptor[state->cipher_idx].ecb_encrypt(state->checksum, state->checksum, &state->key)) != CRYPT_OK) {
+ if ((err = cipher_descriptor[pmac->cipher_idx].ecb_encrypt(pmac->checksum, pmac->checksum, &pmac->key)) != CRYPT_OK) {
return err;
}
- cipher_descriptor[state->cipher_idx].done(&state->key);
+ cipher_descriptor[pmac->cipher_idx].done(&pmac->key);
/* store it */
- for (x = 0; x < state->block_len && x < (int)*outlen; x++) {
- out[x] = state->checksum[x];
+ for (x = 0; x < pmac->block_len && x < (int)*outlen; x++) {
+ out[x] = pmac->checksum[x];
}
*outlen = x;
#ifdef LTC_CLEAN_STACK
- zeromem(state, sizeof(*state));
+ zeromem(pmac, sizeof(*pmac));
#endif
return CRYPT_OK;
}
diff --git a/src/ltc/misc/adler32.c b/src/ltc/misc/adler32.c
index c1d7c86f..6f9a869c 100644
--- a/src/ltc/misc/adler32.c
+++ b/src/ltc/misc/adler32.c
@@ -41,8 +41,9 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
length--;
} while (length % 8 != 0);
- if (s1 >= _adler32_base)
+ if (s1 >= _adler32_base) {
s1 -= _adler32_base;
+ }
s2 %= _adler32_base;
}
@@ -67,8 +68,9 @@ void adler32_update(adler32_state *ctx, const unsigned char *input, unsigned lon
length -= 8;
input += 8;
- if (s1 >= _adler32_base)
+ if (s1 >= _adler32_base) {
s1 -= _adler32_base;
+ }
s2 %= _adler32_base;
}
diff --git a/src/ltc/misc/base16/base16_encode.c b/src/ltc/misc/base16/base16_encode.c
index f052fd1f..5646ee92 100644
--- a/src/ltc/misc/base16/base16_encode.c
+++ b/src/ltc/misc/base16/base16_encode.c
@@ -52,8 +52,11 @@ int base16_encode(const unsigned char *in, unsigned long inlen,
x--;
*outlen = x; /* returning the length without terminating NUL */
- if (options == 0) alphabet = alphabets[0];
- else alphabet = alphabets[1];
+ if (options == 0) {
+ alphabet = alphabets[0];
+ } else {
+ alphabet = alphabets[1];
+ }
for (i = 0; i < x; i += 2) {
out[i] = alphabet[(in[i/2] >> 4) & 0x0f];
diff --git a/src/ltc/misc/base64/base64_decode.c b/src/ltc/misc/base64/base64_decode.c
index 7506d50b..9511ba13 100644
--- a/src/ltc/misc/base64/base64_decode.c
+++ b/src/ltc/misc/base64/base64_decode.c
@@ -104,16 +104,16 @@ static int _base64_decode_internal(const char *in, unsigned long inlen,
continue;
}
if (c == 253) {
- if (mode == strict)
+ if (mode == strict) {
return CRYPT_INVALID_PACKET;
- else
- continue; /* allow to ignore white-spaces (relaxed+insane) */
+ }
+ continue; /* allow to ignore white-spaces (relaxed+insane) */
}
if (c == 255) {
- if (mode == insane)
+ if (mode == insane) {
continue; /* allow to ignore invalid garbage (insane) */
- else
- return CRYPT_INVALID_PACKET;
+ }
+ return CRYPT_INVALID_PACKET;
}
if ((g > 0) && (mode != insane)) {
/* we only allow '=' to be at the end (strict+relaxed) */
diff --git a/src/ltc/misc/burn_stack.c b/src/ltc/misc/burn_stack.c
index b79f5409..95fc699b 100644
--- a/src/ltc/misc/burn_stack.c
+++ b/src/ltc/misc/burn_stack.c
@@ -21,8 +21,9 @@ void burn_stack(unsigned long len)
{
unsigned char buf[32];
zeromem(buf, sizeof(buf));
- if (len > (unsigned long)sizeof(buf))
+ if (len > (unsigned long)sizeof(buf)) {
burn_stack(len - sizeof(buf));
+ }
}
diff --git a/src/ltc/misc/compare_testvector.c b/src/ltc/misc/compare_testvector.c
index 842678a4..b0d7baab 100644
--- a/src/ltc/misc/compare_testvector.c
+++ b/src/ltc/misc/compare_testvector.c
@@ -63,11 +63,11 @@ static void _print_hex(const char* what, const void* v, const unsigned long l)
int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
{
int res = 0;
- if(is_len != should_len)
+ if(is_len != should_len) {
res = is_len > should_len ? -1 : 1;
- else
+ } else {
res = XMEMCMP(is, should, is_len);
-
+ }
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
if (res != 0) {
fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
diff --git a/src/ltc/misc/crc32.c b/src/ltc/misc/crc32.c
index 5c49f421..99c66457 100644
--- a/src/ltc/misc/crc32.c
+++ b/src/ltc/misc/crc32.c
@@ -153,8 +153,9 @@ void crc32_update(crc32_state *ctx, const unsigned char *input, unsigned long le
LTC_ARGCHKVD(input != NULL);
crc = ctx->crc;
- while (length--)
+ while (length--) {
crc = crc32_m_tab[CRC32_INDEX(crc) ^ *input++] ^ CRC32_SHIFTED(crc);
+ }
ctx->crc = crc;
}
diff --git a/src/ltc/misc/crypt/crypt.c b/src/ltc/misc/crypt/crypt.c
index 1f76662e..0b4912c4 100644
--- a/src/ltc/misc/crypt/crypt.c
+++ b/src/ltc/misc/crypt/crypt.c
@@ -436,6 +436,9 @@ const char *crypt_build_settings =
#if defined(LTC_PKCS_5)
" PKCS#5 "
#endif
+#if defined(LTC_PKCS_12)
+ " PKCS#12 "
+#endif
#if defined(LTC_PADDING)
" PADDING "
#endif
diff --git a/src/ltc/misc/crypt/crypt_constants.c b/src/ltc/misc/crypt/crypt_constants.c
index 8d7623d7..a0d09af2 100644
--- a/src/ltc/misc/crypt/crypt_constants.c
+++ b/src/ltc/misc/crypt/crypt_constants.c
@@ -265,8 +265,9 @@ int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
- if (number_len < 0)
+ if (number_len < 0) {
return -1;
+ }
total_len += number_len;
}
diff --git a/src/ltc/misc/crypt/crypt_sizes.c b/src/ltc/misc/crypt/crypt_sizes.c
index 5681cc00..e34197ea 100644
--- a/src/ltc/misc/crypt/crypt_sizes.c
+++ b/src/ltc/misc/crypt/crypt_sizes.c
@@ -326,8 +326,9 @@ int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
- if (number_len < 0)
+ if (number_len < 0) {
return -1;
+ }
total_len += number_len;
/* this last +1 is for newlines (and ending NULL) */
}
diff --git a/src/ltc/misc/error_to_string.c b/src/ltc/misc/error_to_string.c
index 64e5e6da..74b34b9b 100644
--- a/src/ltc/misc/error_to_string.c
+++ b/src/ltc/misc/error_to_string.c
@@ -68,9 +68,8 @@ const char *error_to_string(int err)
{
if (err < 0 || err >= (int)(sizeof(err_2_str)/sizeof(err_2_str[0]))) {
return "Invalid error code.";
- } else {
- return err_2_str[err];
}
+ return err_2_str[err];
}
diff --git a/src/ltc/misc/hkdf/hkdf.c b/src/ltc/misc/hkdf/hkdf.c
index 1ca3ae3f..c43a1627 100644
--- a/src/ltc/misc/hkdf/hkdf.c
+++ b/src/ltc/misc/hkdf/hkdf.c
@@ -30,9 +30,8 @@ int hkdf_extract(int hash_idx, const unsigned char *salt, unsigned long saltlen
valid results for HKDF. */
if (salt == NULL || saltlen == 0) {
return hmac_memory(hash_idx, (const unsigned char *)"", 1, in, inlen, out, outlen);
- } else {
- return hmac_memory(hash_idx, salt, saltlen, in, inlen, out, outlen);
}
+ return hmac_memory(hash_idx, salt, saltlen, in, inlen, out, outlen);
}
int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
@@ -55,10 +54,12 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
hashsize = hash_descriptor[hash_idx].hashsize;
/* RFC5869 parameter restrictions */
- if (inlen < hashsize || outlen > hashsize * 255)
+ if (inlen < hashsize || outlen > hashsize * 255) {
return CRYPT_INVALID_ARG;
- if (info == NULL && infolen != 0)
+ }
+ if (info == NULL && infolen != 0) {
return CRYPT_INVALID_ARG;
+ }
LTC_ARGCHK(out != NULL);
Tlen = hashsize + infolen + 1;
@@ -87,8 +88,9 @@ int hkdf_expand(int hash_idx, const unsigned char *info, unsigned long infolen,
}
outoff += Noutlen;
- if (outoff >= outlen) /* loop exit condition */
+ if (outoff >= outlen) { /* loop exit condition */
break;
+ }
/* All subsequent HMAC data T(N) DOES include the previous hash value */
XMEMCPY(T, out + hashsize * (N-1), hashsize);
diff --git a/src/ltc/misc/padding/padding_pad.c b/src/ltc/misc/padding/padding_pad.c
index ae1a8ae2..b1745ae8 100644
--- a/src/ltc/misc/padding/padding_pad.c
+++ b/src/ltc/misc/padding/padding_pad.c
@@ -99,8 +99,11 @@ int padding_pad(unsigned char *data, unsigned long length, unsigned long* padded
type = mode & LTC_PAD_MASK;
if (*padded_length < l) {
- if (type != LTC_PAD_ISO_10126) *padded_length = l;
- else *padded_length = length + 256;
+ if (type != LTC_PAD_ISO_10126) {
+ *padded_length = l;
+ } else {
+ *padded_length = length + 256;
+ }
return CRYPT_BUFFER_OVERFLOW;
}
diff --git a/src/ltc/misc/pkcs12/pkcs12_kdf.c b/src/ltc/misc/pkcs12/pkcs12_kdf.c
new file mode 100644
index 00000000..d097e8a9
--- /dev/null
+++ b/src/ltc/misc/pkcs12/pkcs12_kdf.c
@@ -0,0 +1,92 @@
+/* LibTomCrypt, modular cryptographic library -- Tom St Denis
+ *
+ * LibTomCrypt is a library that provides various cryptographic
+ * algorithms in a highly modular and flexible manner.
+ *
+ * The library is free for all purposes without any express
+ * guarantee it works.
+ */
+
+#include "tomcrypt_private.h"
+
+#ifdef LTC_PKCS_12
+
+int pkcs12_kdf( int hash_id,
+ const unsigned char *pw, unsigned long pwlen,
+ const unsigned char *salt, unsigned long saltlen,
+ unsigned int iterations, unsigned char purpose,
+ unsigned char *out, unsigned long outlen)
+{
+ unsigned long u = hash_descriptor[hash_id].hashsize;
+ unsigned long v = hash_descriptor[hash_id].blocksize;
+ unsigned long c = (outlen + u - 1) / u;
+ unsigned long Slen = ((saltlen + v - 1) / v) * v;
+ unsigned long Plen = ((pwlen + v - 1) / v) * v;
+ unsigned long k = (Plen + Slen) / v;
+ unsigned long Alen, keylen = 0;
+ unsigned int tmp, i, j, n;
+ unsigned char ch;
+ unsigned char D[MAXBLOCKSIZE], A[MAXBLOCKSIZE], B[MAXBLOCKSIZE];
+ unsigned char *I = NULL, *key = NULL;
+ int err = CRYPT_ERROR;
+
+ LTC_ARGCHK(pw != NULL);
+ LTC_ARGCHK(salt != NULL);
+ LTC_ARGCHK(out != NULL);
+
+ key = XMALLOC(u * c);
+ I = XMALLOC(Plen + Slen);
+ if (key == NULL || I == NULL) goto DONE;
+ zeromem(key, u * c);
+
+ for (i = 0; i < v; i++) D[i] = purpose; /* D - diversifier */
+ for (i = 0; i < Slen; i++) I[i] = salt[i % saltlen];
+ for (i = 0; i < Plen; i++) I[Slen + i] = pw[i % pwlen]; /* I = Salt || Pass */
+
+ for (i = 0; i < c; i++) {
+ Alen = sizeof(A);
+ err = hash_memory_multi(hash_id, A, &Alen, D, v, I, Slen + Plen, NULL); /* A = HASH(D || I) */
+ if (err != CRYPT_OK) goto DONE;
+ for (j = 1; j < iterations; j++) {
+ err = hash_memory(hash_id, A, Alen, A, &Alen); /* A = HASH(A) */
+ if (err != CRYPT_OK) goto DONE;
+ }
+ /* fill buffer B with A */
+ for (j = 0; j < v; j++) B[j] = A[j % Alen];
+ /* B += 1 */
+ for (j = v; j > 0; j--) {
+ if (++B[j - 1] != 0) break;
+ }
+ /* I_n += B */
+ for (n = 0; n < k; n++) {
+ ch = 0;
+ for (j = v; j > 0; j--) {
+ tmp = I[n * v + j - 1] + B[j - 1] + ch;
+ ch = (unsigned char)((tmp >> 8) & 0xFF);
+ I[n * v + j - 1] = (unsigned char)(tmp & 0xFF);
+ }
+ }
+ /* store derived key block */
+ XMEMCPY(&key[keylen], A, Alen);
+ keylen += Alen;
+ }
+
+ XMEMCPY(out, key, outlen);
+ err = CRYPT_OK;
+DONE:
+ if (I) {
+ zeromem(I, Plen + Slen);
+ XFREE(I);
+ }
+ if (key) {
+ zeromem(key, u * c);
+ XFREE(key);
+ }
+ return err;
+}
+
+#endif
+
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/src/ltc/misc/pkcs12/pkcs12_utf8_to_utf16.c b/src/ltc/misc/pkcs12/pkcs12_utf8_to_utf16.c
new file mode 100644
index 00000000..5175a152
--- /dev/null
+++ b/src/ltc/misc/pkcs12/pkcs12_utf8_to_utf16.c
@@ -0,0 +1,69 @@
+/* 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_private.h"
+
+#ifdef LTC_PKCS_12
+
+int pkcs12_utf8_to_utf16(const unsigned char *in, unsigned long inlen,
+ unsigned char *out, unsigned long *outlen) {
+ unsigned long len = 0;
+ const unsigned char* in_end = in + inlen;
+ const ulong32 offset[6] = {
+ 0x00000000UL, 0x00003080UL, 0x000E2080UL,
+ 0x03C82080UL, 0xFA082080UL, 0x82082080UL
+ };
+ int err = CRYPT_ERROR;
+
+ LTC_ARGCHK(in != NULL);
+ LTC_ARGCHK(out != NULL);
+ LTC_ARGCHK(outlen != NULL);
+
+ while (in < in_end) {
+ ulong32 ch = 0;
+ unsigned short extra = 0; /* 0 */
+ if (*in >= 192) extra++; /* 1 */
+ if (*in >= 224) extra++; /* 2 */
+ if (*in >= 240) extra++; /* 3 */
+ if (*in >= 248) extra++; /* 4 */
+ if (*in >= 252) extra++; /* 5 */
+ if (in + extra >= in_end) goto ERROR;
+ switch (extra) {
+ case 5: ch += *in++; ch <<= 6;
+ /* FALLTHROUGH */
+ case 4: ch += *in++; ch <<= 6;
+ /* FALLTHROUGH */
+ case 3: ch += *in++; ch <<= 6;
+ /* FALLTHROUGH */
+ case 2: ch += *in++; ch <<= 6;
+ /* FALLTHROUGH */
+ case 1: ch += *in++; ch <<= 6;
+ /* FALLTHROUGH */
+ case 0: ch += *in++;
+ }
+ ch -= offset[extra];
+ if (ch > 0xFFFF) goto ERROR;
+ if (*outlen >= len + 2) {
+ out[len] = (unsigned short)((ch >> 8) & 0xFF);
+ out[len + 1] = (unsigned char)(ch & 0xFF);
+ }
+ len += 2;
+ }
+
+ err = len > *outlen ? CRYPT_BUFFER_OVERFLOW : CRYPT_OK;
+ *outlen = len;
+ERROR:
+ return err;
+}
+
+#endif
+
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/src/ltc/misc/pkcs5/pkcs_5_1.c b/src/ltc/misc/pkcs5/pkcs_5_1.c
index 07946983..a90bc571 100644
--- a/src/ltc/misc/pkcs5/pkcs_5_1.c
+++ b/src/ltc/misc/pkcs5/pkcs_5_1.c
@@ -109,19 +109,23 @@ static int _pkcs_5_alg1_common(const unsigned char *password,
the output buffer (and how many bytes we have to copy) */
outidx = block*hash_descriptor[hash_idx].hashsize;
nb = hash_descriptor[hash_idx].hashsize;
- if(outidx+nb > *outlen)
+ if(outidx+nb > *outlen) {
nb = *outlen - outidx;
- if(nb > 0)
+ }
+ if(nb > 0) {
XMEMCPY(out+outidx, buf, nb);
+ }
block++;
- if (!openssl_compat)
+ if (!openssl_compat) {
break;
+ }
}
/* In strict mode, we always return the hashsize, in compat we filled it
as much as was requested, so we leave it alone. */
- if(!openssl_compat)
+ if(!openssl_compat) {
*outlen = hash_descriptor[hash_idx].hashsize;
+ }
err = CRYPT_OK;
LBL_ERR:
diff --git a/src/ltc/modes/cbc/cbc_decrypt.c b/src/ltc/modes/cbc/cbc_decrypt.c
index 9cbf6f30..fa56c69e 100644
--- a/src/ltc/modes/cbc/cbc_decrypt.c
+++ b/src/ltc/modes/cbc/cbc_decrypt.c
@@ -58,32 +58,31 @@ int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
if (cipher_descriptor[cbc->cipher].accel_cbc_decrypt != NULL) {
return cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
- } else {
- while (len) {
- /* decrypt */
- if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
- return err;
- }
-
- /* xor IV against plaintext */
- #if defined(LTC_FAST)
- for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- tmpy = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)tmp + x));
- *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
- *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) = tmpy;
- }
- #else
- for (x = 0; x < cbc->blocklen; x++) {
- tmpy = tmp[x] ^ cbc->IV[x];
- cbc->IV[x] = ct[x];
- pt[x] = tmpy;
- }
- #endif
+ }
+ while (len) {
+ /* decrypt */
+ if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
+ return err;
+ }
- ct += cbc->blocklen;
- pt += cbc->blocklen;
- len -= cbc->blocklen;
+ /* xor IV against plaintext */
+#if defined(LTC_FAST)
+ for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+ tmpy = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)tmp + x));
+ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
+ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) = tmpy;
}
+#else
+ for (x = 0; x < cbc->blocklen; x++) {
+ tmpy = tmp[x] ^ cbc->IV[x];
+ cbc->IV[x] = ct[x];
+ pt[x] = tmpy;
+ }
+#endif
+
+ ct += cbc->blocklen;
+ pt += cbc->blocklen;
+ len -= cbc->blocklen;
}
return CRYPT_OK;
}
diff --git a/src/ltc/modes/cbc/cbc_encrypt.c b/src/ltc/modes/cbc/cbc_encrypt.c
index 6ba9a0ca..88f519d1 100644
--- a/src/ltc/modes/cbc/cbc_encrypt.c
+++ b/src/ltc/modes/cbc/cbc_encrypt.c
@@ -52,39 +52,38 @@ int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
if (cipher_descriptor[cbc->cipher].accel_cbc_encrypt != NULL) {
return cipher_descriptor[cbc->cipher].accel_cbc_encrypt(pt, ct, len / cbc->blocklen, cbc->IV, &cbc->key);
- } else {
- while (len) {
- /* xor IV against plaintext */
- #if defined(LTC_FAST)
- for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^= *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x));
- }
- #else
- for (x = 0; x < cbc->blocklen; x++) {
- cbc->IV[x] ^= pt[x];
- }
- #endif
-
- /* encrypt */
- if ((err = cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key)) != CRYPT_OK) {
- return err;
- }
+ }
+ while (len) {
+ /* xor IV against plaintext */
+#if defined(LTC_FAST)
+ for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^= *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x));
+ }
+#else
+ for (x = 0; x < cbc->blocklen; x++) {
+ cbc->IV[x] ^= pt[x];
+ }
+#endif
- /* store IV [ciphertext] for a future block */
- #if defined(LTC_FAST)
- for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
- *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
- }
- #else
- for (x = 0; x < cbc->blocklen; x++) {
- cbc->IV[x] = ct[x];
- }
- #endif
+ /* encrypt */
+ if ((err = cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key)) != CRYPT_OK) {
+ return err;
+ }
- ct += cbc->blocklen;
- pt += cbc->blocklen;
- len -= cbc->blocklen;
+ /* store IV [ciphertext] for a future block */
+#if defined(LTC_FAST)
+ for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
+ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
+ }
+#else
+ for (x = 0; x < cbc->blocklen; x++) {
+ cbc->IV[x] = ct[x];
}
+#endif
+
+ ct += cbc->blocklen;
+ pt += cbc->blocklen;
+ len -= cbc->blocklen;
}
return CRYPT_OK;
}
diff --git a/src/ltc/modes/cfb/cfb_start.c b/src/ltc/modes/cfb/cfb_start.c
index caccb5aa..22b3e3c4 100644
--- a/src/ltc/modes/cfb/cfb_start.c
+++ b/src/ltc/modes/cfb/cfb_start.c
@@ -43,8 +43,9 @@ int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
/* copy data */
cfb->cipher = cipher;
cfb->blocklen = cipher_descriptor[cipher].block_length;
- for (x = 0; x < cfb->blocklen; x++)
+ for (x = 0; x < cfb->blocklen; x++) {
cfb->IV[x] = IV[x];
+ }
/* init the cipher */
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
diff --git a/src/ltc/modes/ecb/ecb_decrypt.c b/src/ltc/modes/ecb/ecb_decrypt.c
index b8727d2f..fdeec4db 100644
--- a/src/ltc/modes/ecb/ecb_decrypt.c
+++ b/src/ltc/modes/ecb/ecb_decrypt.c
@@ -39,15 +39,14 @@ int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, s
/* check for accel */
if (cipher_descriptor[ecb->cipher].accel_ecb_decrypt != NULL) {
return cipher_descriptor[ecb->cipher].accel_ecb_decrypt(ct, pt, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
- } else {
- while (len) {
- if ((err = cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key)) != CRYPT_OK) {
- return err;
- }
- pt += cipher_descriptor[ecb->cipher].block_length;
- ct += cipher_descriptor[ecb->cipher].block_length;
- len -= cipher_descriptor[ecb->cipher].block_length;
+ }
+ while (len) {
+ if ((err = cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key)) != CRYPT_OK) {
+ return err;
}
+ pt += cipher_descriptor[ecb->cipher].block_length;
+ ct += cipher_descriptor[ecb->cipher].block_length;
+ len -= cipher_descriptor[ecb->cipher].block_length;
}
return CRYPT_OK;
}
diff --git a/src/ltc/modes/ecb/ecb_encrypt.c b/src/ltc/modes/ecb/ecb_encrypt.c
index d31635ba..e36c3d32 100644
--- a/src/ltc/modes/ecb/ecb_encrypt.c
+++ b/src/ltc/modes/ecb/ecb_encrypt.c
@@ -39,15 +39,14 @@ int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, s
/* check for accel */
if (cipher_descriptor[ecb->cipher].accel_ecb_encrypt != NULL) {
return cipher_descriptor[ecb->cipher].accel_ecb_encrypt(pt, ct, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
- } else {
- while (len) {
- if ((err = cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key)) != CRYPT_OK) {
- return err;
- }
- pt += cipher_descriptor[ecb->cipher].block_length;
- ct += cipher_descriptor[ecb->cipher].block_length;
- len -= cipher_descriptor[ecb->cipher].block_length;
+ }
+ while (len) {
+ if ((err = cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key)) != CRYPT_OK) {
+ return err;
}
+ pt += cipher_descriptor[ecb->cipher].block_length;
+ ct += cipher_descriptor[ecb->cipher].block_length;
+ len -= cipher_descriptor[ecb->cipher].block_length;
}
return CRYPT_OK;
}
diff --git a/src/ltc/pk/asn1/der/general/der_decode_asn1_length.c b/src/ltc/pk/asn1/der/general/der_decode_asn1_length.c
index 0021eea9..bf8595de 100644
--- a/src/ltc/pk/asn1/der/general/der_decode_asn1_length.c
+++ b/src/ltc/pk/asn1/der/general/der_decode_asn1_length.c
@@ -41,9 +41,11 @@ int der_decode_asn1_length(const unsigned char *in, unsigned long *inlen, unsign
real_len &= 0x7F;
if (real_len == 0) {
return CRYPT_PK_ASN1_ERROR;
- } else if (real_len > sizeof(decoded_len)) {
+ }
+ if (real_len > sizeof(decoded_len)) {
return CRYPT_OVERFLOW;
- } else if (real_len > (*inlen - 1)) {
+ }
+ if (real_len > (*inlen - 1)) {
return CRYPT_BUFFER_OVERFLOW;
}
decoded_len = 0;
diff --git a/src/ltc/pk/asn1/der/general/der_encode_asn1_identifier.c b/src/ltc/pk/asn1/der/general/der_encode_asn1_identifier.c
index c366ad3f..38fcaf67 100644
--- a/src/ltc/pk/asn1/der/general/der_encode_asn1_identifier.c
+++ b/src/ltc/pk/asn1/der/general/der_encode_asn1_identifier.c
@@ -41,16 +41,15 @@ int der_encode_asn1_identifier(const ltc_asn1_list *id, unsigned char *out, unsi
}
*outlen = 1;
return CRYPT_OK;
- } else {
- if (id->klass < LTC_ASN1_CL_UNIVERSAL || id->klass > LTC_ASN1_CL_PRIVATE) {
- return CRYPT_INVALID_ARG;
- }
- if (id->pc < LTC_ASN1_PC_PRIMITIVE || id->pc > LTC_ASN1_PC_CONSTRUCTED) {
- return CRYPT_INVALID_ARG;
- }
- if (id->tag > (ULONG_MAX >> (8 + 7))) {
- return CRYPT_INVALID_ARG;
- }
+ }
+ if (id->klass < LTC_ASN1_CL_UNIVERSAL || id->klass > LTC_ASN1_CL_PRIVATE) {
+ return CRYPT_INVALID_ARG;
+ }
+ if (id->pc < LTC_ASN1_PC_PRIMITIVE || id->pc > LTC_ASN1_PC_CONSTRUCTED) {
+ return CRYPT_INVALID_ARG;
+ }
+ if (id->tag > (ULONG_MAX >> (8 + 7))) {
+ return CRYPT_INVALID_ARG;
}
if (out != NULL) {
diff --git a/src/ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c b/src/ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c
index a5f84739..34ea828c 100644
--- a/src/ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c
+++ b/src/ltc/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c
@@ -112,7 +112,8 @@ YYYYMMDDhhmmss.fs-hh'mm'
/* now is it Z or . */
if (buf[x] == 'Z') {
return CRYPT_OK;
- } else if (buf[x] == '.') {
+ }
+ if (buf[x] == '.') {
x++;
while (buf[x] >= '0' && buf[x] <= '9') {
unsigned fs = out->fs;
@@ -127,14 +128,14 @@ YYYYMMDDhhmmss.fs-hh'mm'
/* now is it Z, +, - */
if (buf[x] == 'Z') {
return CRYPT_OK;
- } else if (buf[x] == '+' || buf[x] == '-') {
+ }
+ if (buf[x] == '+' || buf[x] == '-') {
out->off_dir = (buf[x++] == '+') ? 0 : 1;
DECODE_V(out->off_hh, 24);
DECODE_V(out->off_mm, 60);
return CRYPT_OK;
- } else {
- return CRYPT_INVALID_PACKET;
}
+ return CRYPT_INVALID_PACKET;
}
#endif
diff --git a/src/ltc/pk/asn1/der/set/der_encode_set.c b/src/ltc/pk/asn1/der/set/der_encode_set.c
index 636669c7..25971978 100644
--- a/src/ltc/pk/asn1/der/set/der_encode_set.c
+++ b/src/ltc/pk/asn1/der/set/der_encode_set.c
@@ -33,9 +33,8 @@ static int _qsort_helper(const void *a, const void *b)
if (r == 0) {
/* their order in the original list now determines the position */
return A->used - B->used;
- } else {
- return r;
}
+ return r;
}
/*
diff --git a/src/ltc/pk/asn1/der/utctime/der_decode_utctime.c b/src/ltc/pk/asn1/der/utctime/der_decode_utctime.c
index fba9184b..c377396c 100644
--- a/src/ltc/pk/asn1/der/utctime/der_decode_utctime.c
+++ b/src/ltc/pk/asn1/der/utctime/der_decode_utctime.c
@@ -95,7 +95,8 @@ YYMMDDhhmmss-hh'mm'
/* now is it Z, +, - or 0-9 */
if (buf[x] == 'Z') {
return CRYPT_OK;
- } else if (buf[x] == '+' || buf[x] == '-') {
+ }
+ if (buf[x] == '+' || buf[x] == '-') {
out->off_dir = (buf[x++] == '+') ? 0 : 1;
DECODE_V(out->off_hh, 24);
DECODE_V(out->off_mm, 60);
@@ -108,14 +109,14 @@ YYMMDDhhmmss-hh'mm'
/* now is it Z, +, - */
if (buf[x] == 'Z') {
return CRYPT_OK;
- } else if (buf[x] == '+' || buf[x] == '-') {
+ }
+ if (buf[x] == '+' || buf[x] == '-') {
out->off_dir = (buf[x++] == '+') ? 0 : 1;
DECODE_V(out->off_hh, 24);
DECODE_V(out->off_mm, 60);
return CRYPT_OK;
- } else {
- return CRYPT_INVALID_PACKET;
}
+ return CRYPT_INVALID_PACKET;
}
#endif
diff --git a/src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c b/src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c
index 48eed3bb..acece0cb 100644
--- a/src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c
+++ b/src/ltc/pk/asn1/der/utf8/der_length_utf8_string.c
@@ -23,18 +23,17 @@ unsigned long der_utf8_charsize(const wchar_t c)
{
if (c <= 0x7F) {
return 1;
- } else if (c <= 0x7FF) {
+ }
+ if (c <= 0x7FF) {
return 2;
-#if LTC_WCHAR_MAX == 0xFFFF
- } else {
- return 3;
}
+#if LTC_WCHAR_MAX == 0xFFFF
+ return 3;
#else
- } else if (c <= 0xFFFF) {
+ if (c <= 0xFFFF) {
return 3;
- } else {
- return 4;
}
+ return 4;
#endif
}
diff --git a/src/ltc/pk/dh/dh_generate_key.c b/src/ltc/pk/dh/dh_generate_key.c
index ba737fcf..fc9e8511 100644
--- a/src/ltc/pk/dh/dh_generate_key.c
+++ b/src/ltc/pk/dh/dh_generate_key.c
@@ -19,27 +19,25 @@ static int _dh_groupsize_to_keysize(int groupsize)
if (groupsize <= 0) {
return 0;
}
- else if (groupsize <= 192) {
+ if (groupsize <= 192) {
return 30; /* 1536-bit => key size 240-bit */
}
- else if (groupsize <= 256) {
+ if (groupsize <= 256) {
return 40; /* 2048-bit => key size 320-bit */
}
- else if (groupsize <= 384) {
+ if (groupsize <= 384) {
return 52; /* 3072-bit => key size 416-bit */
}
- else if (groupsize <= 512) {
+ if (groupsize <= 512) {
return 60; /* 4096-bit => key size 480-bit */
}
- else if (groupsize <= 768) {
+ if (groupsize <= 768) {
return 67; /* 6144-bit => key size 536-bit */
}
- else if (groupsize <= 1024) {
+ if (groupsize <= 1024) {
return 77; /* 8192-bit => key size 616-bit */
}
- else {
- return 0;
- }
+ return 0;
}
int dh_generate_key(prng_state *prng, int wprng, dh_key *key)
diff --git a/src/ltc/pk/dsa/dsa_export.c b/src/ltc/pk/dsa/dsa_export.c
index 9058dd31..d254ae6e 100644
--- a/src/ltc/pk/dsa/dsa_export.c
+++ b/src/ltc/pk/dsa/dsa_export.c
@@ -26,6 +26,7 @@
int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_key *key)
{
unsigned long zero=0;
+ unsigned char flags[1];
int err, std;
LTC_ARGCHK(out != NULL);
@@ -35,15 +36,10 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_ke
std = type & PK_STD;
type &= ~PK_STD;
- /* can we store the static header? */
if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
return CRYPT_PK_TYPE_MISMATCH;
}
- if (type != PK_PUBLIC && type != PK_PRIVATE) {
- return CRYPT_INVALID_ARG;
- }
-
if (type == PK_PRIVATE) {
if (std) {
return der_encode_sequence_multi(out, outlen,
@@ -55,10 +51,8 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_ke
LTC_ASN1_INTEGER, 1UL, key->x,
LTC_ASN1_EOL, 0UL, NULL);
}
- else {
- unsigned char flags[1];
- flags[0] = 1;
- return der_encode_sequence_multi(out, outlen,
+ flags[0] = 1;
+ return der_encode_sequence_multi(out, outlen,
LTC_ASN1_BIT_STRING, 1UL, flags,
LTC_ASN1_INTEGER, 1UL, key->g,
LTC_ASN1_INTEGER, 1UL, key->p,
@@ -66,8 +60,9 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_ke
LTC_ASN1_INTEGER, 1UL, key->y,
LTC_ASN1_INTEGER, 1UL, key->x,
LTC_ASN1_EOL, 0UL, NULL);
- }
- } else {
+ }
+
+ if (type == PK_PUBLIC) {
if (std) {
unsigned long tmplen = (unsigned long)(mp_count_bits(key->y) / 8) + 8;
unsigned char* tmp = XMALLOC(tmplen);
@@ -94,18 +89,17 @@ error:
XFREE(tmp);
return err;
}
- else {
- unsigned char flags[1];
- flags[0] = 0;
- return der_encode_sequence_multi(out, outlen,
+ flags[0] = 0;
+ return der_encode_sequence_multi(out, outlen,
LTC_ASN1_BIT_STRING, 1UL, flags,
LTC_ASN1_INTEGER, 1UL, key->g,
LTC_ASN1_INTEGER, 1UL, key->p,
LTC_ASN1_INTEGER, 1UL, key->q,
LTC_ASN1_INTEGER, 1UL, key->y,
LTC_ASN1_EOL, 0UL, NULL);
- }
}
+
+ return CRYPT_INVALID_ARG;
}
#endif
diff --git a/src/ltc/pk/ecc/ecc_ansi_x963_import.c b/src/ltc/pk/ecc/ecc_ansi_x963_import.c
index 6dbdd215..1dccfbe3 100644
--- a/src/ltc/pk/ecc/ecc_ansi_x963_import.c
+++ b/src/ltc/pk/ecc/ecc_ansi_x963_import.c
@@ -41,11 +41,11 @@ int ecc_ansi_x963_import_ex(const unsigned char *in, unsigned long inlen, ecc_ke
/* initialize key->dp */
if (cu == NULL) {
/* this case works only for uncompressed public keys */
- if ((err = ecc_set_dp_by_size((inlen-1)>>1, key)) != CRYPT_OK) { return err; }
+ if ((err = ecc_set_curve_by_size((inlen-1)>>1, key)) != CRYPT_OK) { return err; }
}
else {
/* this one works for both compressed / uncompressed pubkeys */
- if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { return err; }
+ if ((err = ecc_set_curve(cu, key)) != CRYPT_OK) { return err; }
}
/* load public key */
diff --git a/src/ltc/pk/ecc/ecc_decrypt_key.c b/src/ltc/pk/ecc/ecc_decrypt_key.c
index 8c29a174..d6b825e8 100644
--- a/src/ltc/pk/ecc/ecc_decrypt_key.c
+++ b/src/ltc/pk/ecc/ecc_decrypt_key.c
@@ -85,7 +85,7 @@ int ecc_decrypt_key(const unsigned char *in, unsigned long inlen,
}
/* import ECC key from packet */
- if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { goto LBL_ERR; }
+ if ((err = ecc_copy_curve(key, &pubkey)) != CRYPT_OK) { goto LBL_ERR; }
if ((err = ecc_set_key(decode[1].data, decode[1].size, PK_PUBLIC, &pubkey)) != CRYPT_OK) { goto LBL_ERR; }
/* make shared key */
diff --git a/src/ltc/pk/ecc/ecc_encrypt_key.c b/src/ltc/pk/ecc/ecc_encrypt_key.c
index 17201df6..2ea7e35d 100644
--- a/src/ltc/pk/ecc/ecc_encrypt_key.c
+++ b/src/ltc/pk/ecc/ecc_encrypt_key.c
@@ -52,7 +52,7 @@ int ecc_encrypt_key(const unsigned char *in, unsigned long inlen,
}
/* make a random key and export the public copy */
- if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { return err; }
+ if ((err = ecc_copy_curve(key, &pubkey)) != CRYPT_OK) { return err; }
if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK) { return err; }
pub_expt = XMALLOC(ECC_BUF_SIZE);
diff --git a/src/ltc/pk/ecc/ecc_get_curve.c b/src/ltc/pk/ecc/ecc_find_curve.c
index a2f52b0a..d9544fd8 100644
--- a/src/ltc/pk/ecc/ecc_get_curve.c
+++ b/src/ltc/pk/ecc/ecc_find_curve.c
@@ -208,13 +208,11 @@ static int _name_match(const char *left, const char *right)
right++;
}
- if ((*left == '\0') && (*right == '\0'))
- return 1;
- else
- return 0;
+ if ((*left == '\0') && (*right == '\0')) return 1;
+ return 0;
}
-int ecc_get_curve(const char *name_or_oid, const ltc_ecc_curve **cu)
+int ecc_find_curve(const char *name_or_oid, const ltc_ecc_curve **cu)
{
int i, j;
const char *OID = NULL;
diff --git a/src/ltc/pk/ecc/ecc_import.c b/src/ltc/pk/ecc/ecc_import.c
index e691add5..74097a7d 100644
--- a/src/ltc/pk/ecc/ecc_import.c
+++ b/src/ltc/pk/ecc/ecc_import.c
@@ -56,9 +56,9 @@ int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, co
/* allocate & initialize the key */
if (cu == NULL) {
- if ((err = ecc_set_dp_by_size(key_size, key)) != CRYPT_OK) { goto done; }
+ if ((err = ecc_set_curve_by_size(key_size, key)) != CRYPT_OK) { goto done; }
} else {
- if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { goto done; }
+ if ((err = ecc_set_curve(cu, key)) != CRYPT_OK) { goto done; }
}
if (flags[0] == 1) {
diff --git a/src/ltc/pk/ecc/ecc_import_openssl.c b/src/ltc/pk/ecc/ecc_import_openssl.c
index a4b2cf50..e7650912 100644
--- a/src/ltc/pk/ecc/ecc_import_openssl.c
+++ b/src/ltc/pk/ecc/ecc_import_openssl.c
@@ -36,8 +36,8 @@ static int _ecc_import_private_with_oid(const unsigned char *in, unsigned long i
/* load curve parameters for given curve OID */
len = sizeof(OID);
if ((err = pk_oid_num_to_str(curveoid, custom[0].size, OID, &len)) != CRYPT_OK) { goto error; }
- if ((err = ecc_get_curve(OID, &curve)) != CRYPT_OK) { goto error; }
- if ((err = ecc_set_dp(curve, key)) != CRYPT_OK) { goto error; }
+ if ((err = ecc_find_curve(OID, &curve)) != CRYPT_OK) { goto error; }
+ if ((err = ecc_set_curve(curve, key)) != CRYPT_OK) { goto error; }
/* load private+public key */
err = ecc_set_key(bin_k, seq_priv[1].size, PK_PRIVATE, key);
}
@@ -96,7 +96,7 @@ static int _ecc_import_private_with_curve(const unsigned char *in, unsigned long
if ((err = mp_read_unsigned_bin(b, bin_b, len_b)) != CRYPT_OK) { goto error; }
if ((err = ltc_ecc_import_point(bin_g, len_g, prime, a, b, gx, gy)) != CRYPT_OK) { goto error; }
/* load curve parameters */
- if ((err = ecc_set_dp_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; }
+ if ((err = ecc_set_curve_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; }
/* load private+public key */
err = ecc_set_key(bin_k, len_k, PK_PRIVATE, key);
}
diff --git a/src/ltc/pk/ecc/ecc_import_pkcs8.c b/src/ltc/pk/ecc/ecc_import_pkcs8.c
index 323db2aa..e606699b 100644
--- a/src/ltc/pk/ecc/ecc_import_pkcs8.c
+++ b/src/ltc/pk/ecc/ecc_import_pkcs8.c
@@ -54,115 +54,6 @@ static const oid_st oid_list[] = {
{ { 0 }, 0 },
};
-static int _simple_utf8_to_utf16(const unsigned char *in, unsigned long inlen,
- unsigned char *out, unsigned long *outlen) {
- unsigned long len = 0;
- const unsigned char* in_end = in + inlen;
- const ulong32 offset[6] = {
- 0x00000000UL, 0x00003080UL, 0x000E2080UL,
- 0x03C82080UL, 0xFA082080UL, 0x82082080UL
- };
- int err = CRYPT_ERROR;
-
- while (in < in_end) {
- ulong32 ch = 0;
- unsigned short extra = 0; /* 0 */
- if (*in >= 192) extra++; /* 1 */
- if (*in >= 224) extra++; /* 2 */
- if (*in >= 240) extra++; /* 3 */
- if (*in >= 248) extra++; /* 4 */
- if (*in >= 252) extra++; /* 5 */
- if (in + extra >= in_end) goto ERROR;
- switch (extra) {
- case 5: ch += *in++; ch <<= 6;
- /* FALLTHROUGH */
- case 4: ch += *in++; ch <<= 6;
- /* FALLTHROUGH */
- case 3: ch += *in++; ch <<= 6;
- /* FALLTHROUGH */
- case 2: ch += *in++; ch <<= 6;
- /* FALLTHROUGH */
- case 1: ch += *in++; ch <<= 6;
- /* FALLTHROUGH */
- case 0: ch += *in++;
- }
- ch -= offset[extra];
- if (ch > 0xFFFF) goto ERROR;
- if (*outlen >= len + 2) {
- out[len] = (unsigned short)((ch >> 8) & 0xFF);
- out[len + 1] = (unsigned char)(ch & 0xFF);
- }
- len += 2;
- }
-
- err = len > *outlen ? CRYPT_BUFFER_OVERFLOW : CRYPT_OK;
- *outlen = len;
-ERROR:
- return err;
-}
-
-static int _kdf_pkcs12(int hash_id, const unsigned char *pw, unsigned long pwlen,
- const unsigned char *salt, unsigned long saltlen,
- unsigned int iterations, unsigned char purpose,
- unsigned char *out, unsigned long outlen)
-{
- unsigned long u = hash_descriptor[hash_id].hashsize;
- unsigned long v = hash_descriptor[hash_id].blocksize;
- unsigned long c = (outlen + u - 1) / u;
- unsigned long Slen = ((saltlen + v - 1) / v) * v;
- unsigned long Plen = ((pwlen + v - 1) / v) * v;
- unsigned long k = (Plen + Slen) / v;
- unsigned long Alen, keylen = 0;
- unsigned int tmp, i, j, n;
- unsigned char ch;
- unsigned char D[MAXBLOCKSIZE], A[MAXBLOCKSIZE], B[MAXBLOCKSIZE];
- unsigned char *I = NULL, *key = NULL;
- int err = CRYPT_ERROR;
-
- key = XMALLOC(u * c);
- I = XMALLOC(Plen + Slen);
- if (key == NULL || I == NULL) goto DONE;
- zeromem(key, u * c);
-
- for (i = 0; i < v; i++) D[i] = purpose; /* D - diversifier */
- for (i = 0; i < Slen; i++) I[i] = salt[i % saltlen];
- for (i = 0; i < Plen; i++) I[Slen + i] = pw[i % pwlen]; /* I = Salt || Pass */
-
- for (i = 0; i < c; i++) {
- Alen = u; /* hash size */
- err = hash_memory_multi(hash_id, A, &Alen, D, v, I, Slen + Plen, NULL); /* A = HASH(D || I) */
- if (err != CRYPT_OK) goto DONE;
- for (j = 1; j < iterations; j++) {
- err = hash_memory(hash_id, A, Alen, A, &Alen); /* A = HASH(A) */
- if (err != CRYPT_OK) goto DONE;
- }
- /* fill buffer B with A */
- for (j = 0; j < v; j++) B[j] = A[j % Alen];
- /* B += 1 */
- for (j = v; j > 0; j--) {
- if (++B[j - 1] != 0) break;
- }
- /* I_n += B */
- for (n = 0; n < k; n++) {
- ch = 0;
- for (j = v; j > 0; j--) {
- tmp = I[n * v + j - 1] + B[j - 1] + ch;
- ch = (unsigned char)((tmp >> 8) & 0xFF);
- I[n * v + j - 1] = (unsigned char)(tmp & 0xFF);
- }
- }
- /* store derived key block */
- for (j = 0; j < Alen; j++) key[keylen++] = A[j];
- }
-
- for (i = 0; i < outlen; i++) out[i] = key[i];
- err = CRYPT_OK;
-DONE:
- if (I) XFREE(I);
- if (key) XFREE(key);
- return err;
-}
-
static int _oid_to_id(const unsigned long *oid, unsigned long oid_size)
{
int i, j;
@@ -216,13 +107,13 @@ static int _pbes1_decrypt(const unsigned char *enc_data, unsigned long enc_size,
pwlen = pass_size * 2;
pw = XMALLOC(pwlen + 2);
if (pw == NULL) goto LBL_ERROR;
- if ((err = _simple_utf8_to_utf16(pass, pass_size, pw, &pwlen) != CRYPT_OK)) goto LBL_ERROR;
+ if ((err = pkcs12_utf8_to_utf16(pass, pass_size, pw, &pwlen) != CRYPT_OK)) goto LBL_ERROR;
pw[pwlen++] = 0;
pw[pwlen++] = 0;
/* derive KEY */
- if ((err = _kdf_pkcs12(hid, pw, pwlen, salt, salt_size, iterations, 1, key_iv, keylen)) != CRYPT_OK) goto LBL_ERROR;
+ if ((err = pkcs12_kdf(hid, pw, pwlen, salt, salt_size, iterations, 1, key_iv, keylen)) != CRYPT_OK) goto LBL_ERROR;
/* derive IV */
- if ((err = _kdf_pkcs12(hid, pw, pwlen, salt, salt_size, iterations, 2, key_iv+24, blklen)) != CRYPT_OK) goto LBL_ERROR;
+ if ((err = pkcs12_kdf(hid, pw, pwlen, salt, salt_size, iterations, 2, key_iv+24, blklen)) != CRYPT_OK) goto LBL_ERROR;
}
else {
if ((err = pkcs_5_alg1(pass, pass_size, salt, iterations, hid, key_iv, &len)) != CRYPT_OK) goto LBL_ERROR;
@@ -515,8 +406,8 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen,
ltc_asn1_list *loid = lseq->child->next;
len = sizeof(OID);
if ((err = pk_oid_num_to_str(loid->data, loid->size, OID, &len)) != CRYPT_OK) { goto LBL_DONE; }
- if ((err = ecc_get_curve(OID, &curve)) != CRYPT_OK) { goto LBL_DONE; }
- if ((err = ecc_set_dp(curve, key)) != CRYPT_OK) { goto LBL_DONE; }
+ if ((err = ecc_find_curve(OID, &curve)) != CRYPT_OK) { goto LBL_DONE; }
+ if ((err = ecc_set_curve(curve, key)) != CRYPT_OK) { goto LBL_DONE; }
}
else if (LTC_ASN1_IS_TYPE(lseq->child->next, LTC_ASN1_SEQUENCE)) {
/* CASE 2: explicit curve parameters (AKA long variant):
@@ -567,7 +458,7 @@ int ecc_import_pkcs8(const unsigned char *in, unsigned long inlen,
if ((err = ltc_ecc_import_point(lg->data, lg->size, lprime->data, a, b, gx, gy)) != CRYPT_OK) {
goto LBL_DONE;
}
- if ((err = ecc_set_dp_from_mpis(a, b, lprime->data, lorder->data, gx, gy, cofactor, key)) != CRYPT_OK) {
+ if ((err = ecc_set_curve_from_mpis(a, b, lprime->data, lorder->data, gx, gy, cofactor, key)) != CRYPT_OK) {
goto LBL_DONE;
}
}
diff --git a/src/ltc/pk/ecc/ecc_import_x509.c b/src/ltc/pk/ecc/ecc_import_x509.c
index 2e7eb10c..99a27507 100644
--- a/src/ltc/pk/ecc/ecc_import_x509.c
+++ b/src/ltc/pk/ecc/ecc_import_x509.c
@@ -27,8 +27,8 @@ static int _ecc_import_x509_with_oid(const unsigned char *in, unsigned long inle
/* load curve parameters for given curve OID */
len = sizeof(OID);
if ((err = pk_oid_num_to_str(curveoid, len_oid, OID, &len)) != CRYPT_OK) { goto error; }
- if ((err = ecc_get_curve(OID, &curve)) != CRYPT_OK) { goto error; }
- if ((err = ecc_set_dp(curve, key)) != CRYPT_OK) { goto error; }
+ if ((err = ecc_find_curve(OID, &curve)) != CRYPT_OK) { goto error; }
+ if ((err = ecc_set_curve(curve, key)) != CRYPT_OK) { goto error; }
/* load public key */
err = ecc_set_key(bin_xy, len_xy, PK_PUBLIC, key);
}
@@ -80,7 +80,7 @@ static int _ecc_import_x509_with_curve(const unsigned char *in, unsigned long in
if ((err = mp_read_unsigned_bin(b, bin_b, len_b)) != CRYPT_OK) { goto error; }
if ((err = ltc_ecc_import_point(bin_g, len_g, prime, a, b, gx, gy)) != CRYPT_OK) { goto error; }
/* load curve parameters */
- if ((err = ecc_set_dp_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; }
+ if ((err = ecc_set_curve_from_mpis(a, b, prime, order, gx, gy, cofactor, key)) != CRYPT_OK) { goto error; }
/* load public key */
err = ecc_set_key(bin_xy, len_xy, PK_PUBLIC, key);
}
diff --git a/src/ltc/pk/ecc/ecc_make_key.c b/src/ltc/pk/ecc/ecc_make_key.c
index da595850..4a8f91ef 100644
--- a/src/ltc/pk/ecc/ecc_make_key.c
+++ b/src/ltc/pk/ecc/ecc_make_key.c
@@ -28,15 +28,15 @@ int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key)
{
int err;
- if ((err = ecc_set_dp_by_size(keysize, key)) != CRYPT_OK) { return err; }
- if ((err = ecc_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; }
+ if ((err = ecc_set_curve_by_size(keysize, key)) != CRYPT_OK) { return err; }
+ if ((err = ecc_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; }
return CRYPT_OK;
}
int ecc_make_key_ex(prng_state *prng, int wprng, ecc_key *key, const ltc_ecc_curve *cu)
{
int err;
- if ((err = ecc_set_dp(cu, key)) != CRYPT_OK) { return err; }
+ if ((err = ecc_set_curve(cu, key)) != CRYPT_OK) { return err; }
if ((err = ecc_generate_key(prng, wprng, key)) != CRYPT_OK) { return err; }
return CRYPT_OK;
}
diff --git a/src/ltc/pk/ecc/ecc_set_dp.c b/src/ltc/pk/ecc/ecc_set_curve.c
index 4c4f4877..9fa44fdd 100644
--- a/src/ltc/pk/ecc/ecc_set_dp.c
+++ b/src/ltc/pk/ecc/ecc_set_curve.c
@@ -11,12 +11,12 @@
#ifdef LTC_MECC
-int ecc_set_dp(const ltc_ecc_curve *curve, ecc_key *key)
+int ecc_set_curve(const ltc_ecc_curve *cu, ecc_key *key)
{
int err;
LTC_ARGCHK(key != NULL);
- LTC_ARGCHK(curve != NULL);
+ LTC_ARGCHK(cu != NULL);
if ((err = mp_init_multi(&key->dp.prime, &key->dp.order, &key->dp.A, &key->dp.B,
&key->dp.base.x, &key->dp.base.y, &key->dp.base.z,
@@ -26,19 +26,19 @@ int ecc_set_dp(const ltc_ecc_curve *curve, ecc_key *key)
}
/* A, B, order, prime, Gx, Gy */
- if ((err = mp_read_radix(key->dp.prime, curve->prime, 16)) != CRYPT_OK) { goto error; }
- if ((err = mp_read_radix(key->dp.order, curve->order, 16)) != CRYPT_OK) { goto error; }
- if ((err = mp_read_radix(key->dp.A, curve->A, 16)) != CRYPT_OK) { goto error; }
- if ((err = mp_read_radix(key->dp.B, curve->B, 16)) != CRYPT_OK) { goto error; }
- if ((err = mp_read_radix(key->dp.base.x, curve->Gx, 16)) != CRYPT_OK) { goto error; }
- if ((err = mp_read_radix(key->dp.base.y, curve->Gy, 16)) != CRYPT_OK) { goto error; }
- if ((err = mp_set(key->dp.base.z, 1)) != CRYPT_OK) { goto error; }
+ if ((err = mp_read_radix(key->dp.prime, cu->prime, 16)) != CRYPT_OK) { goto error; }
+ if ((err = mp_read_radix(key->dp.order, cu->order, 16)) != CRYPT_OK) { goto error; }
+ if ((err = mp_read_radix(key->dp.A, cu->A, 16)) != CRYPT_OK) { goto error; }
+ if ((err = mp_read_radix(key->dp.B, cu->B, 16)) != CRYPT_OK) { goto error; }
+ if ((err = mp_read_radix(key->dp.base.x, cu->Gx, 16)) != CRYPT_OK) { goto error; }
+ if ((err = mp_read_radix(key->dp.base.y, cu->Gy, 16)) != CRYPT_OK) { goto error; }
+ if ((err = mp_set(key->dp.base.z, 1)) != CRYPT_OK) { goto error; }
/* cofactor & size */
- key->dp.cofactor = curve->cofactor;
+ key->dp.cofactor = cu->cofactor;
key->dp.size = mp_unsigned_bin_size(key->dp.prime);
/* OID string >> unsigned long oid[16] + oidlen */
key->dp.oidlen = 16;
- if ((err = pk_oid_str_to_num(curve->OID, key->dp.oid, &key->dp.oidlen)) != CRYPT_OK) { goto error; }
+ if ((err = pk_oid_str_to_num(cu->OID, key->dp.oid, &key->dp.oidlen)) != CRYPT_OK) { goto error; }
/* success */
return CRYPT_OK;
@@ -47,38 +47,38 @@ error:
return err;
}
-int ecc_set_dp_by_size(int size, ecc_key *key)
+int ecc_set_curve_by_size(int size, ecc_key *key)
{
const ltc_ecc_curve *cu = NULL;
int err = CRYPT_ERROR;
/* for compatibility with libtomcrypt-1.17 the sizes below must match the specific curves */
if (size <= 14) {
- err = ecc_get_curve("SECP112R1", &cu);
+ err = ecc_find_curve("SECP112R1", &cu);
}
else if (size <= 16) {
- err = ecc_get_curve("SECP128R1", &cu);
+ err = ecc_find_curve("SECP128R1", &cu);
}
else if (size <= 20) {
- err = ecc_get_curve("SECP160R1", &cu);
+ err = ecc_find_curve("SECP160R1", &cu);
}
else if (size <= 24) {
- err = ecc_get_curve("SECP192R1", &cu);
+ err = ecc_find_curve("SECP192R1", &cu);
}
else if (size <= 28) {
- err = ecc_get_curve("SECP224R1", &cu);
+ err = ecc_find_curve("SECP224R1", &cu);
}
else if (size <= 32) {
- err = ecc_get_curve("SECP256R1", &cu);
+ err = ecc_find_curve("SECP256R1", &cu);
}
else if (size <= 48) {
- err = ecc_get_curve("SECP384R1", &cu);
+ err = ecc_find_curve("SECP384R1", &cu);
}
else if (size <= 66) {
- err = ecc_get_curve("SECP521R1", &cu);
+ err = ecc_find_curve("SECP521R1", &cu);
}
- if (err == CRYPT_OK && cu != NULL) return ecc_set_dp(cu, key);
+ if (err == CRYPT_OK && cu != NULL) return ecc_set_curve(cu, key);
return CRYPT_INVALID_ARG;
}
diff --git a/src/ltc/pk/ecc/ecc_set_dp_internal.c b/src/ltc/pk/ecc/ecc_set_curve_internal.c
index cf9020bf..aed515ca 100644
--- a/src/ltc/pk/ecc/ecc_set_dp_internal.c
+++ b/src/ltc/pk/ecc/ecc_set_curve_internal.c
@@ -42,7 +42,7 @@ static void _ecc_oid_lookup(ecc_key *key)
}
}
-int ecc_copy_dp(const ecc_key *srckey, ecc_key *key)
+int ecc_copy_curve(const ecc_key *srckey, ecc_key *key)
{
unsigned long i;
int err;
@@ -82,7 +82,7 @@ error:
return err;
}
-int ecc_set_dp_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key)
+int ecc_set_curve_from_mpis(void *a, void *b, void *prime, void *order, void *gx, void *gy, unsigned long cofactor, ecc_key *key)
{
int err;
diff --git a/src/ltc/pk/ecc/ecc_sign_hash.c b/src/ltc/pk/ecc/ecc_sign_hash.c
index bad5286c..3302b077 100644
--- a/src/ltc/pk/ecc/ecc_sign_hash.c
+++ b/src/ltc/pk/ecc/ecc_sign_hash.c
@@ -63,7 +63,7 @@ static int _ecc_sign_hash(const unsigned char *in, unsigned long inlen,
/* make up a key and export the public copy */
do {
- if ((err = ecc_copy_dp(key, &pubkey)) != CRYPT_OK) { goto errnokey; }
+ if ((err = ecc_copy_curve(key, &pubkey)) != CRYPT_OK) { goto errnokey; }
if ((err = ecc_generate_key(prng, wprng, &pubkey)) != CRYPT_OK) { goto errnokey; }
/* find r = x1 mod n */
diff --git a/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c b/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c
index 85bd47a1..146f9f40 100644
--- a/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c
+++ b/src/ltc/pk/ecc/ltc_ecc_is_point_at_infinity.c
@@ -44,10 +44,11 @@ int ltc_ecc_is_point_at_infinity(const ecc_point *P, void *modulus, int *retval)
/* test y^2 == x^3 */
err = CRYPT_OK;
- if ((mp_cmp(x3, y2) == LTC_MP_EQ) && !mp_iszero(y2))
+ if ((mp_cmp(x3, y2) == LTC_MP_EQ) && !mp_iszero(y2)) {
*retval = 1;
- else
+ } else {
*retval = 0;
+ }
cleanup:
mp_clear_multi(x3, y2, NULL);
diff --git a/src/ltc/pk/rsa/rsa_export.c b/src/ltc/pk/rsa/rsa_export.c
index 6bd2199e..43ff7c31 100644
--- a/src/ltc/pk/rsa/rsa_export.c
+++ b/src/ltc/pk/rsa/rsa_export.c
@@ -26,14 +26,16 @@
int rsa_export(unsigned char *out, unsigned long *outlen, int type, const rsa_key *key)
{
unsigned long zero=0;
- int err;
+ int err, std;
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(outlen != NULL);
LTC_ARGCHK(key != NULL);
- /* type valid? */
- if (!(key->type == PK_PRIVATE) && (type == PK_PRIVATE)) {
- return CRYPT_PK_INVALID_TYPE;
+ std = type & PK_STD;
+ type &= ~PK_STD;
+
+ if (type == PK_PRIVATE && key->type != PK_PRIVATE) {
+ return CRYPT_PK_TYPE_MISMATCH;
}
if (type == PK_PRIVATE) {
@@ -52,12 +54,14 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, const rsa_ke
LTC_ASN1_INTEGER, 1UL, key->dQ,
LTC_ASN1_INTEGER, 1UL, key->qP,
LTC_ASN1_EOL, 0UL, NULL);
- } else {
+ }
+
+ if (type == PK_PUBLIC) {
/* public key */
unsigned long tmplen, *ptmplen;
unsigned char* tmp = NULL;
- if (type & PK_STD) {
+ if (std) {
tmplen = (unsigned long)(mp_count_bits(key->N) / 8) * 2 + 8;
tmp = XMALLOC(tmplen);
ptmplen = &tmplen;
@@ -75,7 +79,7 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, const rsa_ke
LTC_ASN1_INTEGER, 1UL, key->e,
LTC_ASN1_EOL, 0UL, NULL);
- if ((err != CRYPT_OK) || !(type & PK_STD)) {
+ if ((err != CRYPT_OK) || !std) {
goto finish;
}
@@ -83,11 +87,11 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, const rsa_ke
PKA_RSA, tmp, tmplen, LTC_ASN1_NULL, NULL, 0);
finish:
- if (tmp != out)
- XFREE(tmp);
+ if (tmp != out) XFREE(tmp);
return err;
-
}
+
+ return CRYPT_INVALID_ARG;
}
#endif /* LTC_MRSA */
diff --git a/src/ltc/pk/rsa/rsa_import.c b/src/ltc/pk/rsa/rsa_import.c
index bb8793dd..69f5b23c 100644
--- a/src/ltc/pk/rsa/rsa_import.c
+++ b/src/ltc/pk/rsa/rsa_import.c
@@ -116,9 +116,9 @@ LBL_ERR:
mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
LBL_FREE:
- if (tmpbuf != NULL)
- XFREE(tmpbuf);
-
+ if (tmpbuf != NULL) {
+ XFREE(tmpbuf);
+ }
return err;
}
diff --git a/src/ltc/prngs/fortuna.c b/src/ltc/prngs/fortuna.c
index ab56defc..908f6a58 100644
--- a/src/ltc/prngs/fortuna.c
+++ b/src/ltc/prngs/fortuna.c
@@ -108,11 +108,13 @@ static int _fortuna_reseed(prng_state *prng)
#ifdef LTC_FORTUNA_RESEED_RATELIMIT_TIMED
ulong64 now = _fortuna_current_time();
- if (now == prng->u.fortuna.wd)
+ if (now == prng->u.fortuna.wd) {
return CRYPT_OK;
+ }
#else
- if (++prng->u.fortuna.wd < LTC_FORTUNA_WD)
+ if (++prng->u.fortuna.wd < LTC_FORTUNA_WD) {
return CRYPT_OK;
+ }
#endif
/* new K == LTC_SHA256(K || s) where s == LTC_SHA256(P0) || LTC_SHA256(P1) ... */
diff --git a/src/ltc/prngs/rng_get_bytes.c b/src/ltc/prngs/rng_get_bytes.c
index 10b3cadd..1a32f33a 100644
--- a/src/ltc/prngs/rng_get_bytes.c
+++ b/src/ltc/prngs/rng_get_bytes.c
@@ -30,9 +30,12 @@ static unsigned long _rng_nix(unsigned char *buf, unsigned long len,
LTC_UNUSED_PARAM(callback);
#ifdef LTC_TRY_URANDOM_FIRST
f = fopen("/dev/urandom", "rb");
- if (f == NULL)
-#endif /* LTC_TRY_URANDOM_FIRST */
+ if (f == NULL) {
f = fopen("/dev/random", "rb");
+ }
+#else
+ f = fopen("/dev/random", "rb");
+#endif /* LTC_TRY_URANDOM_FIRST */
if (f == NULL) {
return 0;
diff --git a/src/ltc/prngs/sprng.c b/src/ltc/prngs/sprng.c
index a5876065..085e43a5 100644
--- a/src/ltc/prngs/sprng.c
+++ b/src/ltc/prngs/sprng.c
@@ -102,6 +102,7 @@ int sprng_done(prng_state *prng)
@param prng The PRNG to export
@return CRYPT_OK if successful
*/
+/* NOLINTNEXTLINE(readability-non-const-parameter) - silence clang-tidy warning */
int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
{
LTC_ARGCHK(outlen != NULL);
diff --git a/src/ltc/stream/rabbit/rabbit.c b/src/ltc/stream/rabbit/rabbit.c
index 4607bc9e..7314d32b 100644
--- a/src/ltc/stream/rabbit/rabbit.c
+++ b/src/ltc/stream/rabbit/rabbit.c
@@ -99,8 +99,9 @@ static LTC_INLINE void _rabbit_next_state(rabbit_ctx *p_instance)
ulong32 g[8], c_old[8], i;
/* Save old counter values */
- for (i=0; i<8; i++)
+ for (i=0; i<8; i++) {
c_old[i] = p_instance->c[i];
+ }
/* Calculate new counter values */
p_instance->c[0] = (ulong32)(p_instance->c[0] + 0x4D34D34D + p_instance->carry);
@@ -114,8 +115,9 @@ static LTC_INLINE void _rabbit_next_state(rabbit_ctx *p_instance)
p_instance->carry = (p_instance->c[7] < c_old[7]);
/* Calculate the g-values */
- for (i=0;i<8;i++)
+ for (i=0;i<8;i++) {
g[i] = _rabbit_g_func((ulong32)(p_instance->x[i] + p_instance->c[i]));
+ }
/* Calculate new state values */
p_instance->x[0] = (ulong32)(g[0] + ROLc(g[7],16) + ROLc(g[6], 16));
@@ -198,12 +200,14 @@ int rabbit_setup(rabbit_state* st, const unsigned char *key, unsigned long keyle
st->master_ctx.carry = 0;
/* Iterate the master context four times */
- for (i=0; i<4; i++)
+ for (i=0; i<4; i++) {
_rabbit_next_state(&(st->master_ctx));
+ }
/* Modify the counters */
- for (i=0; i<8; i++)
+ for (i=0; i<8; i++) {
st->master_ctx.c[i] ^= st->master_ctx.x[(i+4)&0x7];
+ }
/* Copy master instance to work instance */
for (i=0; i<8; i++) {
@@ -250,13 +254,15 @@ int rabbit_setiv(rabbit_state* st, const unsigned char *iv, unsigned long ivlen)
st->work_ctx.c[7] = st->master_ctx.c[7] ^ i3;
/* Copy state variables */
- for (i=0; i<8; i++)
+ for (i=0; i<8; i++) {
st->work_ctx.x[i] = st->master_ctx.x[i];
+ }
st->work_ctx.carry = st->master_ctx.carry;
/* Iterate the work context four times */
- for (i=0; i<4; i++)
+ for (i=0; i<4; i++) {
_rabbit_next_state(&(st->work_ctx));
+ }
/* reset keystream buffer and unused count */
XMEMSET(&(st->block), 0, sizeof(st->block));
@@ -297,13 +303,12 @@ int rabbit_crypt(rabbit_state* st, const unsigned char *in, unsigned long inlen,
/* copy remainder to block */
for (i = inlen; i < 16; ++i) st->block[i] = buf[i];
return CRYPT_OK;
- } else {
- /* XOR entire buf and send to out */
- for (i = 0; i < 16; ++i) out[i] = in[i] ^ buf[i];
- inlen -= 16;
- out += 16;
- in += 16;
}
+ /* XOR entire buf and send to out */
+ for (i = 0; i < 16; ++i) out[i] = in[i] ^ buf[i];
+ inlen -= 16;
+ out += 16;
+ in += 16;
}
}
diff --git a/src/ltc/stream/sober128/sober128_stream.c b/src/ltc/stream/sober128/sober128_stream.c
index 44e0c327..ecbe4d8d 100644
--- a/src/ltc/stream/sober128/sober128_stream.c
+++ b/src/ltc/stream/sober128/sober128_stream.c
@@ -68,68 +68,68 @@ static void cycle(ulong32 *R)
/* Return a non-linear function of some parts of the register.
*/
-#define NLFUNC(c,z) \
+#define NLFUNC(st,z) \
{ \
- t = c->R[OFF(z,0)] + c->R[OFF(z,16)]; \
+ t = st->R[OFF(z,0)] + st->R[OFF(z,16)]; \
t ^= Sbox[(t >> 24) & 0xFF]; \
t = RORc(t, 8); \
- t = ((t + c->R[OFF(z,1)]) ^ c->konst) + c->R[OFF(z,6)]; \
+ t = ((t + st->R[OFF(z,1)]) ^ st->konst) + st->R[OFF(z,6)]; \
t ^= Sbox[(t >> 24) & 0xFF]; \
- t = t + c->R[OFF(z,13)]; \
+ t = t + st->R[OFF(z,13)]; \
}
-static ulong32 nltap(const sober128_state *c)
+static ulong32 nltap(const sober128_state *st)
{
ulong32 t;
- NLFUNC(c, 0);
+ NLFUNC(st, 0);
return t;
}
/* Save the current register state
*/
-static void s128_savestate(sober128_state *c)
+static void s128_savestate(sober128_state *st)
{
int i;
for (i = 0; i < N; ++i) {
- c->initR[i] = c->R[i];
+ st->initR[i] = st->R[i];
}
}
/* initialise to previously saved register state
*/
-static void s128_reloadstate(sober128_state *c)
+static void s128_reloadstate(sober128_state *st)
{
int i;
for (i = 0; i < N; ++i) {
- c->R[i] = c->initR[i];
+ st->R[i] = st->initR[i];
}
}
/* Initialise "konst"
*/
-static void s128_genkonst(sober128_state *c)
+static void s128_genkonst(sober128_state *st)
{
ulong32 newkonst;
do {
- cycle(c->R);
- newkonst = nltap(c);
+ cycle(st->R);
+ newkonst = nltap(st);
} while ((newkonst & 0xFF000000) == 0);
- c->konst = newkonst;
+ st->konst = newkonst;
}
/* Load key material into the register
*/
#define ADDKEY(k) \
- c->R[KEYP] += (k);
+ st->R[KEYP] += (k);
#define XORNL(nl) \
- c->R[FOLDP] ^= (nl);
+ st->R[FOLDP] ^= (nl);
/* nonlinear diffusion of register for key */
-#define DROUND(z) STEP(c->R,z); NLFUNC(c,(z+1)); c->R[OFF((z+1),FOLDP)] ^= t;
-static void s128_diffuse(sober128_state *c)
+#define DROUND(z) STEP(st->R,z); NLFUNC(st,(z+1)); st->R[OFF((z+1),FOLDP)] ^= t;
+static void s128_diffuse(sober128_state *st)
{
ulong32 t;
/* relies on FOLD == N == 17! */
@@ -154,16 +154,16 @@ static void s128_diffuse(sober128_state *c)
/**
Initialize an Sober128 context (only the key)
- @param c [out] The destination of the Sober128 state
+ @param st [out] The destination of the Sober128 state
@param key The secret key
@param keylen The length of the secret key (octets)
@return CRYPT_OK if successful
*/
-int sober128_stream_setup(sober128_state *c, const unsigned char *key, unsigned long keylen)
+int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned long keylen)
{
ulong32 i, k;
- LTC_ARGCHK(c != NULL);
+ LTC_ARGCHK(st != NULL);
LTC_ARGCHK(key != NULL);
LTC_ARGCHK(keylen > 0);
@@ -173,49 +173,49 @@ int sober128_stream_setup(sober128_state *c, const unsigned char *key, unsigned
}
/* Register initialised to Fibonacci numbers */
- c->R[0] = 1;
- c->R[1] = 1;
+ st->R[0] = 1;
+ st->R[1] = 1;
for (i = 2; i < N; ++i) {
- c->R[i] = c->R[i-1] + c->R[i-2];
+ st->R[i] = st->R[i-1] + st->R[i-2];
}
- c->konst = INITKONST;
+ st->konst = INITKONST;
for (i = 0; i < keylen; i += 4) {
k = BYTE2WORD((unsigned char *)&key[i]);
ADDKEY(k);
- cycle(c->R);
- XORNL(nltap(c));
+ cycle(st->R);
+ XORNL(nltap(st));
}
/* also fold in the length of the key */
ADDKEY(keylen);
/* now diffuse */
- s128_diffuse(c);
- s128_genkonst(c);
- s128_savestate(c);
- c->nbuf = 0;
+ s128_diffuse(st);
+ s128_genkonst(st);
+ s128_savestate(st);
+ st->nbuf = 0;
return CRYPT_OK;
}
/**
Set IV to the Sober128 state
- @param c The Sober12820 state
+ @param st The Sober12820 state
@param iv The IV data to add
@param ivlen The length of the IV (must be 12)
@return CRYPT_OK on success
*/
-int sober128_stream_setiv(sober128_state *c, const unsigned char *iv, unsigned long ivlen)
+int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned long ivlen)
{
ulong32 i, k;
- LTC_ARGCHK(c != NULL);
+ LTC_ARGCHK(st != NULL);
LTC_ARGCHK(iv != NULL);
LTC_ARGCHK(ivlen > 0);
/* ok we are adding an IV then... */
- s128_reloadstate(c);
+ s128_reloadstate(st);
/* ivlen must be multiple of 4 bytes */
if ((ivlen & 3) != 0) {
@@ -225,45 +225,45 @@ int sober128_stream_setiv(sober128_state *c, const unsigned char *iv, unsigned l
for (i = 0; i < ivlen; i += 4) {
k = BYTE2WORD((unsigned char *)&iv[i]);
ADDKEY(k);
- cycle(c->R);
- XORNL(nltap(c));
+ cycle(st->R);
+ XORNL(nltap(st));
}
/* also fold in the length of the key */
ADDKEY(ivlen);
/* now diffuse */
- s128_diffuse(c);
- c->nbuf = 0;
+ s128_diffuse(st);
+ st->nbuf = 0;
return CRYPT_OK;
}
/* XOR pseudo-random bytes into buffer
*/
-#define SROUND(z) STEP(c->R,z); NLFUNC(c,(z+1)); XORWORD(t, in+(z*4), out+(z*4));
+#define SROUND(z) STEP(st->R,z); NLFUNC(st,(z+1)); XORWORD(t, in+(z*4), out+(z*4));
/**
Encrypt (or decrypt) bytes of ciphertext (or plaintext) with Sober128
- @param c The Sober128 state
+ @param st The Sober128 state
@param in The plaintext (or ciphertext)
@param inlen The length of the input (octets)
@param out [out] The ciphertext (or plaintext), length inlen
@return CRYPT_OK if successful
*/
-int sober128_stream_crypt(sober128_state *c, const unsigned char *in, unsigned long inlen, unsigned char *out)
+int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out)
{
ulong32 t;
if (inlen == 0) return CRYPT_OK; /* nothing to do */
LTC_ARGCHK(out != NULL);
- LTC_ARGCHK(c != NULL);
+ LTC_ARGCHK(st != NULL);
/* handle any previously buffered bytes */
- while (c->nbuf != 0 && inlen != 0) {
- *out++ = *in++ ^ (unsigned char)(c->sbuf & 0xFF);
- c->sbuf >>= 8;
- c->nbuf -= 8;
+ while (st->nbuf != 0 && inlen != 0) {
+ *out++ = *in++ ^ (unsigned char)(st->sbuf & 0xFF);
+ st->sbuf >>= 8;
+ st->nbuf -= 8;
--inlen;
}
@@ -295,8 +295,8 @@ int sober128_stream_crypt(sober128_state *c, const unsigned char *in, unsigned l
/* do small or odd size buffers the slow way */
while (4 <= inlen) {
- cycle(c->R);
- t = nltap(c);
+ cycle(st->R);
+ t = nltap(st);
XORWORD(t, in, out);
out += 4;
in += 4;
@@ -305,13 +305,13 @@ int sober128_stream_crypt(sober128_state *c, const unsigned char *in, unsigned l
/* handle any trailing bytes */
if (inlen != 0) {
- cycle(c->R);
- c->sbuf = nltap(c);
- c->nbuf = 32;
- while (c->nbuf != 0 && inlen != 0) {
- *out++ = *in++ ^ (unsigned char)(c->sbuf & 0xFF);
- c->sbuf >>= 8;
- c->nbuf -= 8;
+ cycle(st->R);
+ st->sbuf = nltap(st);
+ st->nbuf = 32;
+ while (st->nbuf != 0 && inlen != 0) {
+ *out++ = *in++ ^ (unsigned char)(st->sbuf & 0xFF);
+ st->sbuf >>= 8;
+ st->nbuf -= 8;
--inlen;
}
}
@@ -319,23 +319,23 @@ int sober128_stream_crypt(sober128_state *c, const unsigned char *in, unsigned l
return CRYPT_OK;
}
-int sober128_stream_keystream(sober128_state *c, unsigned char *out, unsigned long outlen)
+int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen)
{
if (outlen == 0) return CRYPT_OK; /* nothing to do */
LTC_ARGCHK(out != NULL);
XMEMSET(out, 0, outlen);
- return sober128_stream_crypt(c, out, outlen, out);
+ return sober128_stream_crypt(st, out, outlen, out);
}
/**
Terminate and clear Sober128 state
- @param c The Sober128 state
+ @param st The Sober128 state
@return CRYPT_OK on success
*/
-int sober128_stream_done(sober128_state *c)
+int sober128_stream_done(sober128_state *st)
{
- LTC_ARGCHK(c != NULL);
- XMEMSET(c, 0, sizeof(sober128_state));
+ LTC_ARGCHK(st != NULL);
+ XMEMSET(st, 0, sizeof(sober128_state));
return CRYPT_OK;
}
diff --git a/src/ltc/stream/sosemanuk/sosemanuk.c b/src/ltc/stream/sosemanuk/sosemanuk.c
index b0838f84..41371989 100644
--- a/src/ltc/stream/sosemanuk/sosemanuk.c
+++ b/src/ltc/stream/sosemanuk/sosemanuk.c
@@ -266,8 +266,9 @@ int sosemanuk_setup(sosemanuk_state *ss, const unsigned char *key, unsigned long
XMEMCPY(wbuf, key, keylen);
if (keylen < 32) {
wbuf[keylen] = 0x01;
- if (keylen < 31)
+ if (keylen < 31) {
XMEMSET(wbuf + keylen + 1, 0, 31 - keylen);
+ }
}
LOAD32L(w0, wbuf);
@@ -725,8 +726,9 @@ static LTC_INLINE void _sosemanuk_internal(sosemanuk_state *ss)
static LTC_INLINE void _xorbuf(const unsigned char *in1, const unsigned char *in2,
unsigned char *out, unsigned long datalen)
{
- while (datalen -- > 0)
+ while (datalen -- > 0) {
*out ++ = *in1 ++ ^ *in2 ++;
+ }
}
@@ -751,8 +753,9 @@ int sosemanuk_crypt(sosemanuk_state *ss,
if (ss->ptr < (sizeof(ss->buf))) {
unsigned long rlen = (sizeof(ss->buf)) - ss->ptr;
- if (rlen > inlen)
+ if (rlen > inlen) {
rlen = inlen;
+ }
_xorbuf(ss->buf + ss->ptr, in, out, rlen);
in += rlen;
out += rlen;