Browse Source

Merge pull request #596 from libtom/amalgamation

Amalgamation
Steffen Jaeckel 7 months ago
parent
commit
d032686639
100 changed files with 885 additions and 518 deletions
  1. 21 0
      .github/workflows/main.yml
  2. 1 0
      .gitignore
  3. 13 13
      demos/timing.c
  4. 17 17
      demos/tv_gen.c
  5. 22 0
      doc/crypt.tex
  6. 19 0
      makefile
  7. 7 0
      makefile_include.mk
  8. 9 1
      src/ciphers/aes/aes.c
  9. 17 0
      src/ciphers/anubis.c
  10. 2 0
      src/ciphers/blowfish.c
  11. 2 0
      src/ciphers/camellia.c
  12. 4 0
      src/ciphers/cast5.c
  13. 3 0
      src/ciphers/des.c
  14. 8 0
      src/ciphers/idea.c
  15. 4 0
      src/ciphers/kasumi.c
  16. 2 0
      src/ciphers/khazad.c
  17. 3 0
      src/ciphers/kseed.c
  18. 7 0
      src/ciphers/noekeon.c
  19. 3 0
      src/ciphers/rc5.c
  20. 4 2
      src/ciphers/rc6.c
  21. 8 3
      src/ciphers/safer/safer.c
  22. 11 2
      src/ciphers/safer/saferp.c
  23. 42 0
      src/ciphers/serpent.c
  24. 5 0
      src/ciphers/skipjack.c
  25. 3 0
      src/ciphers/tea.c
  26. 11 0
      src/ciphers/twofish/twofish.c
  27. 4 0
      src/encauth/gcm/gcm_gf_mult.c
  28. 3 0
      src/encauth/ocb/ocb_init.c
  29. 3 0
      src/encauth/ocb3/ocb3_init.c
  30. 17 17
      src/hashes/blake2b.c
  31. 16 16
      src/hashes/blake2s.c
  32. 20 0
      src/hashes/md4.c
  33. 9 2
      src/hashes/md5.c
  34. 13 1
      src/hashes/rmd128.c
  35. 16 1
      src/hashes/rmd160.c
  36. 13 0
      src/hashes/rmd256.c
  37. 16 0
      src/hashes/rmd320.c
  38. 9 0
      src/hashes/sha1.c
  39. 9 0
      src/hashes/sha2/sha256.c
  40. 9 3
      src/hashes/sha2/sha512.c
  41. 5 0
      src/hashes/tiger.c
  42. 4 0
      src/hashes/whirl/whirl.c
  43. 3 3
      src/headers/tomcrypt_math.h
  44. 71 64
      src/headers/tomcrypt_private.h
  45. 2 0
      src/mac/pelican/pelican.c
  46. 3 0
      src/mac/pmac/pmac_init.c
  47. 114 114
      src/math/fp/ltc_ecc_fp_mulmod.c
  48. 7 7
      src/math/multi.c
  49. 5 5
      src/math/radix_to_bin.c
  50. 3 3
      src/math/rand_bn.c
  51. 2 2
      src/math/rand_prime.c
  52. 1 6
      src/misc/pbes/pbes1.c
  53. 2 7
      src/misc/pbes/pbes2.c
  54. 20 20
      src/misc/pem/pem_ssh.c
  55. 2 2
      src/misc/ssh/ssh_decode_sequence_multi.c
  56. 7 7
      src/misc/ssh/ssh_encode_sequence_multi.c
  57. 3 0
      src/modes/cfb/cfb_decrypt.c
  58. 3 0
      src/modes/cfb/cfb_encrypt.c
  59. 1 1
      src/pk/asn1/der/general/der_decode_asn1_identifier.c
  60. 7 1
      src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c
  61. 4 2
      src/pk/asn1/der/generalizedtime/der_encode_generalizedtime.c
  62. 5 5
      src/pk/asn1/der/integer/der_decode_integer.c
  63. 16 16
      src/pk/asn1/der/integer/der_encode_integer.c
  64. 5 5
      src/pk/asn1/der/integer/der_length_integer.c
  65. 1 1
      src/pk/asn1/der/sequence/der_decode_sequence_flexi.c
  66. 1 1
      src/pk/asn1/der/sequence/der_sequence_free.c
  67. 2 1
      src/pk/asn1/der/set/der_encode_set.c
  68. 3 0
      src/pk/asn1/der/set/der_encode_setof.c
  69. 6 1
      src/pk/asn1/der/utctime/der_decode_utctime.c
  70. 3 2
      src/pk/asn1/der/utctime/der_encode_utctime.c
  71. 1 1
      src/pk/asn1/pkcs8/pkcs8_get.c
  72. 2 2
      src/pk/dh/dh.c
  73. 6 6
      src/pk/dh/dh_check_pubkey.c
  74. 2 2
      src/pk/dh/dh_export_key.c
  75. 1 1
      src/pk/dh/dh_free.c
  76. 3 3
      src/pk/dh/dh_generate_key.c
  77. 1 1
      src/pk/dh/dh_import.c
  78. 3 3
      src/pk/dh/dh_import_pkcs8.c
  79. 7 7
      src/pk/dh/dh_set.c
  80. 7 7
      src/pk/dh/dh_shared_secret.c
  81. 7 7
      src/pk/dsa/dsa_decrypt_key.c
  82. 7 7
      src/pk/dsa/dsa_encrypt_key.c
  83. 1 1
      src/pk/dsa/dsa_export.c
  84. 1 1
      src/pk/dsa/dsa_free.c
  85. 1 1
      src/pk/dsa/dsa_generate_key.c
  86. 31 31
      src/pk/dsa/dsa_generate_pqg.c
  87. 1 1
      src/pk/dsa/dsa_import.c
  88. 2 2
      src/pk/dsa/dsa_import_pkcs8.c
  89. 1 1
      src/pk/dsa/dsa_init.c
  90. 7 7
      src/pk/dsa/dsa_set.c
  91. 1 1
      src/pk/dsa/dsa_set_pqg_dsaparam.c
  92. 6 6
      src/pk/dsa/dsa_shared_secret.c
  93. 20 20
      src/pk/dsa/dsa_sign_hash.c
  94. 14 14
      src/pk/dsa/dsa_verify_hash.c
  95. 21 21
      src/pk/dsa/dsa_verify_key.c
  96. 5 0
      src/pk/ec25519/tweetnacl.c
  97. 6 6
      src/pk/ecc/ecc_export_openssl.c
  98. 1 1
      src/pk/ecc/ecc_free.c
  99. 2 2
      src/pk/ecc/ecc_get_key.c
  100. 1 1
      src/pk/ecc/ecc_import.c

+ 21 - 0
.github/workflows/main.yml

@@ -98,3 +98,24 @@ jobs:
           name: build-${{ github.run_id }}.tar.xz
           name: build-${{ github.run_id }}.tar.xz
           path: build-${{ github.run_id }}.tar.xz
           path: build-${{ github.run_id }}.tar.xz
           retention-days: 1
           retention-days: 1
+
+  Amalgam:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        cc: [ gcc, clang ]
+        os: [ ubuntu-22.04, ubuntu-24.04 ]
+    steps:
+      - uses: actions/checkout@v4
+      - name: install dependencies
+        run: |
+          sudo apt-get update -qq
+          sudo apt-get remove -y libtommath1
+          curl -s https://packagecloud.io/install/repositories/libtom/packages/script.deb.sh | sudo bash
+          sudo apt-get install libtommath-git-dev
+      - name: run tests
+        env:
+          CC: "${{ matrix.cc }}"
+        run: |
+          make pre_gen
+          make CFLAGS="-DLTM_DESC -DUSE_LTM" EXTRALIBS="-ltommath" AMALGAM=1 -j$(nproc) check

+ 1 - 0
.gitignore

@@ -10,6 +10,7 @@
 # release files
 # release files
 /libtomcrypt-*
 /libtomcrypt-*
 /crypt-*
 /crypt-*
+pre_gen/
 
 
 # suppress output of build process
 # suppress output of build process
 gcc_[12].txt
 gcc_[12].txt

+ 13 - 13
demos/timing.c

@@ -528,12 +528,12 @@ static void time_mult(void)
    if (ltc_mp.name == NULL) return;
    if (ltc_mp.name == NULL) return;
 
 
    fprintf(stderr, "Timing Multiplying:\n");
    fprintf(stderr, "Timing Multiplying:\n");
-   mp_init_multi(&a,&b,&c,NULL);
-   for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) {
-       mp_rand(a, x);
-       mp_rand(b, x);
+   ltc_mp_init_multi(&a,&b,&c,NULL);
+   for (x = 128/LTC_MP_DIGIT_BIT; x <= (unsigned long)1536/LTC_MP_DIGIT_BIT; x += 128/LTC_MP_DIGIT_BIT) {
+       ltc_mp_rand(a, x);
+       ltc_mp_rand(b, x);
 
 
-#define DO1 mp_mul(a, b, c);
+#define DO1 ltc_mp_mul(a, b, c);
 #define DO2 DO1; DO1;
 #define DO2 DO1; DO1;
 
 
        t2 = -1;
        t2 = -1;
@@ -544,9 +544,9 @@ static void time_mult(void)
            t1 = (t_read() - t1)>>1;
            t1 = (t_read() - t1)>>1;
            if (t1 < t2) t2 = t1;
            if (t1 < t2) t2 = t1;
        }
        }
-       fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2);
+       fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*LTC_MP_DIGIT_BIT, t2);
    }
    }
-   mp_clear_multi(a,b,c,NULL);
+   ltc_mp_deinit_multi(a,b,c,NULL);
 
 
 #undef DO1
 #undef DO1
 #undef DO2
 #undef DO2
@@ -561,11 +561,11 @@ static void time_sqr(void)
    if (ltc_mp.name == NULL) return;
    if (ltc_mp.name == NULL) return;
 
 
    fprintf(stderr, "Timing Squaring:\n");
    fprintf(stderr, "Timing Squaring:\n");
-   mp_init_multi(&a,&b,NULL);
-   for (x = 128/MP_DIGIT_BIT; x <= (unsigned long)1536/MP_DIGIT_BIT; x += 128/MP_DIGIT_BIT) {
-       mp_rand(a, x);
+   ltc_mp_init_multi(&a,&b,NULL);
+   for (x = 128/LTC_MP_DIGIT_BIT; x <= (unsigned long)1536/LTC_MP_DIGIT_BIT; x += 128/LTC_MP_DIGIT_BIT) {
+       ltc_mp_rand(a, x);
 
 
-#define DO1 mp_sqr(a, b);
+#define DO1 ltc_mp_sqr(a, b);
 #define DO2 DO1; DO1;
 #define DO2 DO1; DO1;
 
 
        t2 = -1;
        t2 = -1;
@@ -576,9 +576,9 @@ static void time_sqr(void)
            t1 = (t_read() - t1)>>1;
            t1 = (t_read() - t1)>>1;
            if (t1 < t2) t2 = t1;
            if (t1 < t2) t2 = t1;
        }
        }
-       fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*MP_DIGIT_BIT, t2);
+       fprintf(stderr, "%4lu bits: %9"PRI64"u cycles\n", x*LTC_MP_DIGIT_BIT, t2);
    }
    }
-   mp_clear_multi(a,b,NULL);
+   ltc_mp_deinit_multi(a,b,NULL);
 
 
 #undef DO1
 #undef DO1
 #undef DO2
 #undef DO2

+ 17 - 17
demos/tv_gen.c

@@ -670,31 +670,31 @@ static void ecc_gen(void)
    fprintf(out, "ecc vectors.  These are for kG for k=1,3,9,27,...,3**n until k > order of the curve outputs are <k,x,y> triplets\n\n");
    fprintf(out, "ecc vectors.  These are for kG for k=1,3,9,27,...,3**n until k > order of the curve outputs are <k,x,y> triplets\n\n");
    G = ltc_ecc_new_point();
    G = ltc_ecc_new_point();
    R = ltc_ecc_new_point();
    R = ltc_ecc_new_point();
-   mp_init(&k);
-   mp_init(&order);
-   mp_init(&modulus);
-   mp_init(&a);
+   ltc_mp_init(&k);
+   ltc_mp_init(&order);
+   ltc_mp_init(&modulus);
+   ltc_mp_init(&a);
 
 
    for (x = 0; ltc_ecc_curves[x].prime != NULL; x++) {
    for (x = 0; ltc_ecc_curves[x].prime != NULL; x++) {
         fprintf(out, "%s\n", ltc_ecc_curves[x].OID);
         fprintf(out, "%s\n", ltc_ecc_curves[x].OID);
-        mp_set(k, 1);
+        ltc_mp_set(k, 1);
 
 
-        mp_read_radix(order,   ltc_ecc_curves[x].order, 16);
-        mp_read_radix(modulus, ltc_ecc_curves[x].prime, 16);
-        mp_read_radix(a,       ltc_ecc_curves[x].A,     16);
-        mp_read_radix(G->x,    ltc_ecc_curves[x].Gx,    16);
-        mp_read_radix(G->y,    ltc_ecc_curves[x].Gy,    16);
-        mp_set(G->z, 1);
+        ltc_mp_read_radix(order,   ltc_ecc_curves[x].order, 16);
+        ltc_mp_read_radix(modulus, ltc_ecc_curves[x].prime, 16);
+        ltc_mp_read_radix(a,       ltc_ecc_curves[x].A,     16);
+        ltc_mp_read_radix(G->x,    ltc_ecc_curves[x].Gx,    16);
+        ltc_mp_read_radix(G->y,    ltc_ecc_curves[x].Gy,    16);
+        ltc_mp_set(G->z, 1);
 
 
-        while (mp_cmp(k, order) == LTC_MP_LT) {
+        while (ltc_mp_cmp(k, order) == LTC_MP_LT) {
             ltc_mp.ecc_ptmul(k, G, R, a, modulus, 1);
             ltc_mp.ecc_ptmul(k, G, R, a, modulus, 1);
-            mp_tohex(k,    (char*)str); fprintf(out, "%s, ", (char*)str);
-            mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str);
-            mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str);
-            mp_mul_d(k, 3, k);
+            ltc_mp_tohex(k,    (char*)str); fprintf(out, "%s, ", (char*)str);
+            ltc_mp_tohex(R->x, (char*)str); fprintf(out, "%s, ", (char*)str);
+            ltc_mp_tohex(R->y, (char*)str); fprintf(out, "%s\n", (char*)str);
+            ltc_mp_mul_d(k, 3, k);
         }
         }
    }
    }
-   mp_clear_multi(k, order, modulus, a, LTC_NULL);
+   ltc_mp_deinit_multi(k, order, modulus, a, LTC_NULL);
    ltc_ecc_del_point(G);
    ltc_ecc_del_point(G);
    ltc_ecc_del_point(R);
    ltc_ecc_del_point(R);
    fclose(out);
    fclose(out);

+ 22 - 0
doc/crypt.tex

@@ -8896,6 +8896,28 @@ else()
 endif()
 endif()
 \end{verbatim}
 \end{verbatim}
 
 
+
+\mysection{Amalgamated library}
+
+LibTomCrypt can also be built as an amalgamated library, i.e. as a single C source file + the header files.
+
+A release of the library contains the amalgamation in the path \texttt{pre\_gen/tomcrypt\_amalgam.c}.
+
+To create the amalgamation one can run:
+
+\begin{verbatim}
+make pre_gen
+\end{verbatim}
+
+The makefiles also support building the amalgamated library via:
+
+\begin{verbatim}
+make CFLAGS="-DLTM_DESC" EXTRALIBS=-ltommath AMALGAM=1
+\end{verbatim}
+
+This will build the library and link against LibTomMath (which must be installed on your system).
+
+
 \mysection{Header Configuration}
 \mysection{Header Configuration}
 The file \textit{tomcrypt\_cfg.h} is what lets you control various high level macros which control the behaviour of the library.  Build options are also
 The file \textit{tomcrypt\_cfg.h} is what lets you control various high level macros which control the behaviour of the library.  Build options are also
 stored in \textit{tomcrypt\_custom.h} which allow the enabling and disabling of various algorithms.
 stored in \textit{tomcrypt\_custom.h} which allow the enabling and disabling of various algorithms.

+ 19 - 0
makefile

@@ -143,3 +143,22 @@ coverage: $(call print-help,coverage,Create code-coverage of the library - but b
 
 
 # cleans everything - coverage output and standard 'clean'
 # cleans everything - coverage output and standard 'clean'
 cleancov: cleancov-clean clean
 cleancov: cleancov-clean clean
+ifndef AMALGAM
+AMALGAM_FILTER_OUT = src/ciphers/aes/aes_enc.c src/ciphers/aes/aes_enc_desc.c
+TAB_SOURCES = src/ciphers/aes/aes_tab.c src/ciphers/safer/safer_tab.c src/hashes/whirl/whirltab.c src/stream/sober128/sober128tab.c
+SOURCES = $(filter-out $(AMALGAM_FILTER_OUT),$(OBJECTS:.o=.c))
+pre_gen/tomcrypt_amalgam.c: $(TAB_SOURCES) $(SOURCES)
+	mkdir -p pre_gen
+	printf "/*\n * This file has been auto-generated, do not edit!\n */\n\n" > $@
+	printf "#define LTC_AES_TAB_C\n" >> $@
+	printf "#define LTC_SAFER_TAB_C\n" >> $@
+	printf "#define LTC_SOBER128TAB_C\n" >> $@
+	printf "#define LTC_WHIRLTAB_C\n\n" >> $@
+	printf "#include \"tomcrypt_private.h\"\n\n" >> $@
+	cat $^ >> $@
+
+pre_gen: pre_gen/tomcrypt_amalgam.c
+
+.PHONY: pre_gen/tomcrypt_amalgam.c
+endif
+

+ 7 - 0
makefile_include.mk

@@ -210,6 +210,7 @@ library: $(call print-help,library,Builds the library) $(LIBNAME)
 
 
 
 
 # List of objects to compile (all goes to libtomcrypt.a)
 # List of objects to compile (all goes to libtomcrypt.a)
+ifndef AMALGAM
 OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_desc.o src/ciphers/aes/aes_enc.o \
 OBJECTS=src/ciphers/aes/aes.o src/ciphers/aes/aes_desc.o src/ciphers/aes/aes_enc.o \
 src/ciphers/aes/aes_enc_desc.o src/ciphers/aes/aesni.o src/ciphers/anubis.o src/ciphers/blowfish.o \
 src/ciphers/aes/aes_enc_desc.o src/ciphers/aes/aesni.o src/ciphers/anubis.o src/ciphers/blowfish.o \
 src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/idea.o src/ciphers/kasumi.o \
 src/ciphers/camellia.o src/ciphers/cast5.o src/ciphers/des.o src/ciphers/idea.o src/ciphers/kasumi.o \
@@ -401,6 +402,11 @@ src/stream/salsa20/xsalsa20_setup.o src/stream/salsa20/xsalsa20_test.o \
 src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
 src/stream/sober128/sober128_stream.o src/stream/sober128/sober128_stream_memory.o \
 src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
 src/stream/sober128/sober128_test.o src/stream/sosemanuk/sosemanuk.o \
 src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o
 src/stream/sosemanuk/sosemanuk_memory.o src/stream/sosemanuk/sosemanuk_test.o
+else
+OBJECTS=pre_gen/tomcrypt_amalgam.o
+
+LTC_CFLAGS := $(LTC_CFLAGS) -Wno-shadow -Isrc/ciphers/aes -Isrc/ciphers/safer -Isrc/ciphers/twofish -Isrc/hashes/whirl -Isrc/stream/sober128
+endif
 
 
 # List of test objects to compile (all goes to libtomcrypt_prof.a)
 # List of test objects to compile (all goes to libtomcrypt_prof.a)
 TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/bcrypt_test.o \
 TOBJECTS=tests/base16_test.o tests/base32_test.o tests/base64_test.o tests/bcrypt_test.o \
@@ -537,6 +543,7 @@ zipup: $(call print-help,zipup,Prepare the archives for a release) doc/crypt.pdf
 	-@(find libtomcrypt-$(VERSION)/ -type f | xargs grep 'FIXM[E]') && echo '############## BEWARE: the "fixme" marker was found !!! ##############' || true
 	-@(find libtomcrypt-$(VERSION)/ -type f | xargs grep 'FIXM[E]') && echo '############## BEWARE: the "fixme" marker was found !!! ##############' || true
 	mkdir -p libtomcrypt-$(VERSION)/doc
 	mkdir -p libtomcrypt-$(VERSION)/doc
 	cp doc/crypt.pdf libtomcrypt-$(VERSION)/doc/crypt.pdf
 	cp doc/crypt.pdf libtomcrypt-$(VERSION)/doc/crypt.pdf
+	$(MAKE) -C libtomcrypt-$(VERSION)/ pre_gen
 	tar -c libtomcrypt-$(VERSION)/ | xz -6e -c - > crypt-$(VERSION).tar.xz
 	tar -c libtomcrypt-$(VERSION)/ | xz -6e -c - > crypt-$(VERSION).tar.xz
 	zip -9rq crypt-$(VERSION).zip libtomcrypt-$(VERSION)
 	zip -9rq crypt-$(VERSION).zip libtomcrypt-$(VERSION)
 	rm -rf libtomcrypt-$(VERSION)
 	rm -rf libtomcrypt-$(VERSION)

+ 9 - 1
src/ciphers/aes/aes.c

@@ -62,8 +62,10 @@ const struct ltc_cipher_descriptor rijndael_enc_desc =
 
 
 #endif
 #endif
 
 
+#ifndef LTC_AES_TAB_C
 #define LTC_AES_TAB_C
 #define LTC_AES_TAB_C
 #include "aes_tab.c"
 #include "aes_tab.c"
+#endif
 
 
 static ulong32 setup_mix(ulong32 temp)
 static ulong32 setup_mix(ulong32 temp)
 {
 {
@@ -726,5 +728,11 @@ int ECB_KS(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-#endif
+#undef SETUP
+#undef ECB_ENC
+#undef ECB_DEC
+#undef ECB_DONE
+#undef ECB_TEST
+#undef ECB_KS
 
 
+#endif

+ 17 - 0
src/ciphers/anubis.c

@@ -26,6 +26,14 @@ const struct ltc_cipher_descriptor anubis_desc = {
 
 
 #define MAX_N           10
 #define MAX_N           10
 
 
+
+#define T0 anubis_T0
+#define T1 anubis_T1
+#define T2 anubis_T2
+#define T3 anubis_T3
+#define T4 anubis_T4
+#define T5 anubis_T5
+#define rc anubis_rc
 /*
 /*
  * Though Anubis is endianness-neutral, the encryption tables are listed
  * Though Anubis is endianness-neutral, the encryption tables are listed
  * in BIG-ENDIAN format, which is adopted throughout this implementation
  * in BIG-ENDIAN format, which is adopted throughout this implementation
@@ -1546,5 +1554,14 @@ int anubis_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef MAX_N
+#undef T0
+#undef T1
+#undef T2
+#undef T3
+#undef T4
+#undef T5
+#undef rc
+
 #endif
 #endif
 
 

+ 2 - 0
src/ciphers/blowfish.c

@@ -654,5 +654,7 @@ int blowfish_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef F
+
 #endif
 #endif
 
 

+ 2 - 0
src/ciphers/camellia.c

@@ -717,4 +717,6 @@ int camellia_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef loc
+
 #endif
 #endif

+ 4 - 0
src/ciphers/cast5.c

@@ -491,6 +491,7 @@ int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
 }
 }
 #endif
 #endif
 
 
+#define FI cast5_FI
 LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
 LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
 {
 {
    ulong32 I;
    ulong32 I;
@@ -702,4 +703,7 @@ int cast5_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef GB
+#undef FI
+
 #endif
 #endif

+ 3 - 0
src/ciphers/des.c

@@ -2238,5 +2238,8 @@ int des3_keysize(int *keysize)
     return CRYPT_OK;
     return CRYPT_OK;
 }
 }
 
 
+#undef EN0
+#undef DE1
+
 #endif
 #endif
 
 

+ 8 - 0
src/ciphers/idea.c

@@ -66,6 +66,7 @@ static ushort16 s_add_inv(ushort16 x)
    return LOW16(0 - x);
    return LOW16(0 - x);
 }
 }
 
 
+#define s_setup_key s_idea_setup_key
 static int s_setup_key(const unsigned char *key, symmetric_key *skey)
 static int s_setup_key(const unsigned char *key, symmetric_key *skey)
 {
 {
    int i, j;
    int i, j;
@@ -247,4 +248,11 @@ int idea_test(void)
 #endif
 #endif
 }
 }
 
 
+#undef LOW16
+#undef HIGH16
+#undef MUL
+#undef STORE16
+#undef LOAD16
+#undef s_setup_key
+
 #endif
 #endif

+ 4 - 0
src/ciphers/kasumi.c

@@ -28,6 +28,7 @@ const struct ltc_cipher_descriptor kasumi_desc = {
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 };
 
 
+#define FI kasumi_FI
 static u16 FI( u16 in, u16 subkey )
 static u16 FI( u16 in, u16 subkey )
 {
 {
    u16 nine, seven;
    u16 nine, seven;
@@ -304,4 +305,7 @@ int kasumi_test(void)
 #endif
 #endif
 }
 }
 
 
+#undef ROL16
+#undef FI
+
 #endif
 #endif

+ 2 - 0
src/ciphers/khazad.c

@@ -837,4 +837,6 @@ int khazad_keysize(int *keysize)
    return CRYPT_INVALID_KEYSIZE;
    return CRYPT_INVALID_KEYSIZE;
 }
 }
 
 
+#undef R
+
 #endif
 #endif

+ 3 - 0
src/ciphers/kseed.c

@@ -363,4 +363,7 @@ int kseed_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef G
+#undef F
+
 #endif
 #endif

+ 7 - 0
src/ciphers/noekeon.c

@@ -313,5 +313,12 @@ int noekeon_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef kTHETA
+#undef THETA
+#undef GAMMA
+#undef PI1
+#undef PI2
+#undef ROUND
+
 #endif
 #endif
 
 

+ 3 - 0
src/ciphers/rc5.c

@@ -24,6 +24,7 @@ const struct ltc_cipher_descriptor rc5_desc =
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 };
 
 
+#define stab rc5_stab
 static const ulong32 stab[50] = {
 static const ulong32 stab[50] = {
 0xb7e15163UL, 0x5618cb1cUL, 0xf45044d5UL, 0x9287be8eUL, 0x30bf3847UL, 0xcef6b200UL, 0x6d2e2bb9UL, 0x0b65a572UL,
 0xb7e15163UL, 0x5618cb1cUL, 0xf45044d5UL, 0x9287be8eUL, 0x30bf3847UL, 0xcef6b200UL, 0x6d2e2bb9UL, 0x0b65a572UL,
 0xa99d1f2bUL, 0x47d498e4UL, 0xe60c129dUL, 0x84438c56UL, 0x227b060fUL, 0xc0b27fc8UL, 0x5ee9f981UL, 0xfd21733aUL,
 0xa99d1f2bUL, 0x47d498e4UL, 0xe60c129dUL, 0x84438c56UL, 0x227b060fUL, 0xc0b27fc8UL, 0x5ee9f981UL, 0xfd21733aUL,
@@ -317,6 +318,8 @@ int rc5_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef stab
+
 #endif
 #endif
 
 
 
 

+ 4 - 2
src/ciphers/rc6.c

@@ -23,6 +23,7 @@ const struct ltc_cipher_descriptor rc6_desc =
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 };
 
 
+#define stab rc6_stab
 static const ulong32 stab[44] = {
 static const ulong32 stab[44] = {
 0xb7e15163UL, 0x5618cb1cUL, 0xf45044d5UL, 0x9287be8eUL, 0x30bf3847UL, 0xcef6b200UL, 0x6d2e2bb9UL, 0x0b65a572UL,
 0xb7e15163UL, 0x5618cb1cUL, 0xf45044d5UL, 0x9287be8eUL, 0x30bf3847UL, 0xcef6b200UL, 0x6d2e2bb9UL, 0x0b65a572UL,
 0xa99d1f2bUL, 0x47d498e4UL, 0xe60c129dUL, 0x84438c56UL, 0x227b060fUL, 0xc0b27fc8UL, 0x5ee9f981UL, 0xfd21733aUL,
 0xa99d1f2bUL, 0x47d498e4UL, 0xe60c129dUL, 0x84438c56UL, 0x227b060fUL, 0xc0b27fc8UL, 0x5ee9f981UL, 0xfd21733aUL,
@@ -319,6 +320,7 @@ int rc6_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-#endif /*LTC_RC6*/
-
+#undef RND
+#undef stab
 
 
+#endif /*LTC_RC6*/

+ 8 - 3
src/ciphers/safer/safer.c

@@ -24,8 +24,10 @@
 
 
 #ifdef LTC_SAFER
 #ifdef LTC_SAFER
 
 
+#ifndef LTC_SAFER_TAB_C
 #define LTC_SAFER_TAB_C
 #define LTC_SAFER_TAB_C
 #include "safer_tab.c"
 #include "safer_tab.c"
+#endif
 
 
 const struct ltc_cipher_descriptor safer_k64_desc = {
 const struct ltc_cipher_descriptor safer_k64_desc = {
    "safer-k64",
    "safer-k64",
@@ -478,7 +480,10 @@ int safer_sk128_test(void)
  #endif
  #endif
 }
 }
 
 
-#endif
-
-
+#undef ROL8
+#undef EXP
+#undef LOG
+#undef PHT
+#undef IPHT
 
 
+#endif

+ 11 - 2
src/ciphers/safer/saferp.c

@@ -9,8 +9,10 @@
 
 
 #ifdef LTC_SAFERP
 #ifdef LTC_SAFERP
 
 
+#ifndef LTC_SAFER_TAB_C
 #define LTC_SAFER_TAB_C
 #define LTC_SAFER_TAB_C
 #include "safer_tab.c"
 #include "safer_tab.c"
+#endif
 
 
 const struct ltc_cipher_descriptor saferp_desc =
 const struct ltc_cipher_descriptor saferp_desc =
 {
 {
@@ -562,6 +564,13 @@ int saferp_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-#endif
-
+#undef ROUND
+#undef iROUND
+#undef PHT
+#undef iPHT
+#undef SHUF
+#undef iSHUF
+#undef LT
+#undef iLT
 
 
+#endif

+ 42 - 0
src/ciphers/serpent.c

@@ -443,6 +443,7 @@ const struct ltc_cipher_descriptor serpent_desc = {
    k[(8-r)*4 + 7] = d;  \
    k[(8-r)*4 + 7] = d;  \
 }
 }
 
 
+#define s_setup_key s_serpent_setup_key
 static int s_setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
 static int s_setup_key(const unsigned char *key, int keylen, int rounds, ulong32 *k)
 {
 {
    int i;
    int i;
@@ -714,4 +715,45 @@ int serpent_test(void)
 #endif
 #endif
 }
 }
 
 
+#undef s_lt
+#undef s_ilt
+#undef s_beforeS0
+#undef s_afterS0
+#undef s_afterS1
+#undef s_afterS2
+#undef s_afterS3
+#undef s_afterS4
+#undef s_afterS5
+#undef s_afterS6
+#undef s_afterS7
+#undef s_beforeI7
+#undef s_afterI7
+#undef s_afterI6
+#undef s_afterI5
+#undef s_afterI4
+#undef s_afterI3
+#undef s_afterI2
+#undef s_afterI1
+#undef s_afterI0
+#undef s_s0
+#undef s_i0
+#undef s_s1
+#undef s_i1
+#undef s_s2
+#undef s_i2
+#undef s_s3
+#undef s_i3
+#undef s_s4
+#undef s_i4
+#undef s_s5
+#undef s_i5
+#undef s_s6
+#undef s_i6
+#undef s_s7
+#undef s_i7
+#undef s_kx
+#undef s_lk
+#undef s_sk
+#undef s_setup_key
+
 #endif
 #endif

+ 5 - 0
src/ciphers/skipjack.c

@@ -331,4 +331,9 @@ int skipjack_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef RULE_A
+#undef RULE_B
+#undef RULE_A1
+#undef RULE_B1
+
 #endif
 #endif

+ 3 - 0
src/ciphers/tea.c

@@ -205,5 +205,8 @@ int tea_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef DELTA
+#undef SUM
+
 #endif
 #endif
 
 

+ 11 - 0
src/ciphers/twofish/twofish.c

@@ -702,5 +702,16 @@ int twofish_keysize(int *keysize)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef MDS_POLY
+#undef RS_POLY
+#undef sbox
+#undef mds_column_mult
+#undef S1
+#undef S2
+#undef S3
+#undef S4
+#undef g_func
+#undef g1_func
+
 #endif
 #endif
 
 

+ 4 - 0
src/encauth/gcm/gcm_gf_mult.c

@@ -203,6 +203,10 @@ void gcm_gf_mult(const unsigned char *a, const unsigned char *b, unsigned char *
 
 
 }
 }
 
 
+#undef M
+#undef BPD
+#undef WPV
+
 #endif
 #endif
 
 
 #endif
 #endif

+ 3 - 0
src/encauth/ocb/ocb_init.c

@@ -9,6 +9,7 @@
 
 
 #ifdef LTC_OCB_MODE
 #ifdef LTC_OCB_MODE
 
 
+#define polys ocb_polys
 static const struct {
 static const struct {
     int           len;
     int           len;
     unsigned char poly_div[MAXBLOCKSIZE],
     unsigned char poly_div[MAXBLOCKSIZE],
@@ -126,4 +127,6 @@ int ocb_init(ocb_state *ocb, int cipher,
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef polys
+
 #endif
 #endif

+ 3 - 0
src/encauth/ocb3/ocb3_init.c

@@ -54,6 +54,7 @@ static void s_ocb3_int_calc_offset_zero(ocb3_state *ocb, const unsigned char *no
    }
    }
 }
 }
 
 
+#define polys ocb3_polys
 static const struct {
 static const struct {
     int           len;
     int           len;
     unsigned char poly_mul[MAXBLOCKSIZE];
     unsigned char poly_mul[MAXBLOCKSIZE];
@@ -183,4 +184,6 @@ int ocb3_init(ocb3_state *ocb, int cipher,
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef polys
+
 #endif
 #endif

+ 17 - 17
src/hashes/blake2b.c

@@ -32,18 +32,18 @@ enum blake2b_constant {
 
 
 /* param offsets */
 /* param offsets */
 enum {
 enum {
-   O_DIGEST_LENGTH = 0,
-   O_KEY_LENGTH = 1,
-   O_FANOUT = 2,
-   O_DEPTH = 3,
-   O_LEAF_LENGTH = 4,
-   O_NODE_OFFSET = 8,
-   O_XOF_LENGTH = 12,
-   O_NODE_DEPTH = 16,
-   O_INNER_LENGTH = 17,
-   O_RESERVED = 18,
-   O_SALT = 32,
-   O_PERSONAL = 48
+   BLAKE2B_O_DIGEST_LENGTH = 0,
+   BLAKE2B_O_KEY_LENGTH = 1,
+   BLAKE2B_O_FANOUT = 2,
+   BLAKE2B_O_DEPTH = 3,
+   BLAKE2B_O_LEAF_LENGTH = 4,
+   BLAKE2B_O_NODE_OFFSET = 8,
+   BLAKE2B_O_XOF_LENGTH = 12,
+   BLAKE2B_O_NODE_DEPTH = 16,
+   BLAKE2B_O_INNER_LENGTH = 17,
+   BLAKE2B_O_RESERVED = 18,
+   BLAKE2B_O_SALT = 32,
+   BLAKE2B_O_PERSONAL = 48
 };
 };
 
 
 /*
 /*
@@ -190,7 +190,7 @@ static int s_blake2b_init_param(hash_state *md, const unsigned char *P)
       md->blake2b.h[i] ^= tmp;
       md->blake2b.h[i] ^= tmp;
    }
    }
 
 
-   md->blake2b.outlen = P[O_DIGEST_LENGTH];
+   md->blake2b.outlen = P[BLAKE2B_O_DIGEST_LENGTH];
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
@@ -223,10 +223,10 @@ int blake2b_init(hash_state *md, unsigned long outlen, const unsigned char *key,
 
 
    XMEMSET(P, 0, sizeof(P));
    XMEMSET(P, 0, sizeof(P));
 
 
-   P[O_DIGEST_LENGTH] = (unsigned char)outlen;
-   P[O_KEY_LENGTH] = (unsigned char)keylen;
-   P[O_FANOUT] = 1;
-   P[O_DEPTH] = 1;
+   P[BLAKE2B_O_DIGEST_LENGTH] = (unsigned char)outlen;
+   P[BLAKE2B_O_KEY_LENGTH] = (unsigned char)keylen;
+   P[BLAKE2B_O_FANOUT] = 1;
+   P[BLAKE2B_O_DEPTH] = 1;
 
 
    err = s_blake2b_init_param(md, P);
    err = s_blake2b_init_param(md, P);
    if (err != CRYPT_OK) return err;
    if (err != CRYPT_OK) return err;

+ 16 - 16
src/hashes/blake2s.c

@@ -32,17 +32,17 @@ enum blake2s_constant {
 
 
 /* param offsets */
 /* param offsets */
 enum {
 enum {
-   O_DIGEST_LENGTH = 0,
-   O_KEY_LENGTH = 1,
-   O_FANOUT = 2,
-   O_DEPTH = 3,
-   O_LEAF_LENGTH = 4,
-   O_NODE_OFFSET = 8,
-   O_XOF_LENGTH = 12,
-   O_NODE_DEPTH = 14,
-   O_INNER_LENGTH = 15,
-   O_SALT = 16,
-   O_PERSONAL = 24
+   BLAKE2S_O_DIGEST_LENGTH = 0,
+   BLAKE2S_O_KEY_LENGTH = 1,
+   BLAKE2S_O_FANOUT = 2,
+   BLAKE2S_O_DEPTH = 3,
+   BLAKE2S_O_LEAF_LENGTH = 4,
+   BLAKE2S_O_NODE_OFFSET = 8,
+   BLAKE2S_O_XOF_LENGTH = 12,
+   BLAKE2S_O_NODE_DEPTH = 14,
+   BLAKE2S_O_INNER_LENGTH = 15,
+   BLAKE2S_O_SALT = 16,
+   BLAKE2S_O_PERSONAL = 24
 };
 };
 
 
 /*
 /*
@@ -184,7 +184,7 @@ static int s_blake2s_init_param(hash_state *md, const unsigned char *P)
       md->blake2s.h[i] ^= tmp;
       md->blake2s.h[i] ^= tmp;
    }
    }
 
 
-   md->blake2s.outlen = P[O_DIGEST_LENGTH];
+   md->blake2s.outlen = P[BLAKE2S_O_DIGEST_LENGTH];
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
@@ -217,10 +217,10 @@ int blake2s_init(hash_state *md, unsigned long outlen, const unsigned char *key,
 
 
    XMEMSET(P, 0, sizeof(P));
    XMEMSET(P, 0, sizeof(P));
 
 
-   P[O_DIGEST_LENGTH] = (unsigned char)outlen;
-   P[O_KEY_LENGTH] = (unsigned char)keylen;
-   P[O_FANOUT] = 1;
-   P[O_DEPTH] = 1;
+   P[BLAKE2S_O_DIGEST_LENGTH] = (unsigned char)outlen;
+   P[BLAKE2S_O_KEY_LENGTH] = (unsigned char)keylen;
+   P[BLAKE2S_O_FANOUT] = 1;
+   P[BLAKE2S_O_DEPTH] = 1;
 
 
    err = s_blake2s_init_param(md, P);
    err = s_blake2s_init_param(md, P);
    if (err != CRYPT_OK) return err;
    if (err != CRYPT_OK) return err;

+ 20 - 0
src/hashes/md4.c

@@ -291,6 +291,26 @@ int md4_test(void)
   #endif
   #endif
 }
 }
 
 
+#undef F
+#undef G
+#undef H
+#undef FF
+#undef GG
+#undef HH
+#undef S11
+#undef S12
+#undef S13
+#undef S14
+#undef S21
+#undef S22
+#undef S23
+#undef S24
+#undef S31
+#undef S32
+#undef S33
+#undef S34
+#undef ROTATE_LEFT
+
 #endif
 #endif
 
 
 
 

+ 9 - 2
src/hashes/md5.c

@@ -351,6 +351,13 @@ int  md5_test(void)
  #endif
  #endif
 }
 }
 
 
-#endif
-
+#undef F
+#undef G
+#undef H
+#undef I
+#undef FF
+#undef GG
+#undef HH
+#undef II
 
 
+#endif

+ 13 - 1
src/hashes/rmd128.c

@@ -392,5 +392,17 @@ int rmd128_test(void)
 #endif
 #endif
 }
 }
 
 
-#endif
+#undef F
+#undef G
+#undef H
+#undef I
+#undef FF
+#undef GG
+#undef HH
+#undef II
+#undef FFF
+#undef GGG
+#undef HHH
+#undef III
 
 
+#endif

+ 16 - 1
src/hashes/rmd160.c

@@ -451,5 +451,20 @@ int rmd160_test(void)
 #endif
 #endif
 }
 }
 
 
-#endif
+#undef F
+#undef G
+#undef H
+#undef I
+#undef J
+#undef FF
+#undef GG
+#undef HH
+#undef II
+#undef JJ
+#undef FFF
+#undef GGG
+#undef HHH
+#undef III
+#undef JJJ
 
 
+#endif

+ 13 - 0
src/hashes/rmd256.c

@@ -417,4 +417,17 @@ int rmd256_test(void)
 #endif
 #endif
 }
 }
 
 
+#undef F
+#undef G
+#undef H
+#undef I
+#undef FF
+#undef GG
+#undef HH
+#undef II
+#undef FFF
+#undef GGG
+#undef HHH
+#undef III
+
 #endif
 #endif

+ 16 - 0
src/hashes/rmd320.c

@@ -482,4 +482,20 @@ int rmd320_test(void)
 #endif
 #endif
 }
 }
 
 
+#undef F
+#undef G
+#undef H
+#undef I
+#undef J
+#undef FF
+#undef GG
+#undef HH
+#undef II
+#undef JJ
+#undef FFF
+#undef GGG
+#undef HHH
+#undef III
+#undef JJJ
+
 #endif
 #endif

+ 9 - 0
src/hashes/sha1.c

@@ -271,6 +271,15 @@ int  sha1_test(void)
   #endif
   #endif
 }
 }
 
 
+#undef F0
+#undef F1
+#undef F2
+#undef F3
+#undef FF0
+#undef FF1
+#undef FF2
+#undef FF3
+
 #endif
 #endif
 
 
 
 

+ 9 - 0
src/hashes/sha2/sha256.c

@@ -317,6 +317,15 @@ int  sha256_test(void)
  #endif
  #endif
 }
 }
 
 
+#undef Ch
+#undef Maj
+#undef S
+#undef R
+#undef Sigma0
+#undef Sigma1
+#undef Gamma0
+#undef Gamma1
+
 #endif
 #endif
 
 
 
 

+ 9 - 3
src/hashes/sha2/sha512.c

@@ -297,7 +297,13 @@ int  sha512_test(void)
   #endif
   #endif
 }
 }
 
 
-#endif
-
-
+#undef Ch
+#undef Maj
+#undef S
+#undef R
+#undef Sigma0
+#undef Sigma1
+#undef Gamma0
+#undef Gamma1
 
 
+#endif

+ 5 - 0
src/hashes/tiger.c

@@ -888,6 +888,11 @@ int tiger2_test(void)
    return s_tiger_test(1);
    return s_tiger_test(1);
 }
 }
 
 
+#undef t1
+#undef t2
+#undef t3
+#undef t4
+
 #endif
 #endif
 
 
 /*
 /*

+ 4 - 0
src/hashes/whirl/whirl.c

@@ -29,8 +29,10 @@ const struct ltc_hash_descriptor whirlpool_desc =
 };
 };
 
 
 /* the sboxes */
 /* the sboxes */
+#ifndef LTC_WHIRLTAB_C
 #define LTC_WHIRLTAB_C
 #define LTC_WHIRLTAB_C
 #include "whirltab.c"
 #include "whirltab.c"
+#endif
 
 
 /* get a_{i,j} */
 /* get a_{i,j} */
 #define GB(a,i,j) ((a[(i) & 7] >> (8 * (j))) & 255)
 #define GB(a,i,j) ((a[(i) & 7] >> (8 * (j))) & 255)
@@ -291,6 +293,8 @@ int  whirlpool_test(void)
  #endif
  #endif
 }
 }
 
 
+#undef GB
+#undef theta_pi_gamma
 
 
 #endif
 #endif
 
 

+ 3 - 3
src/headers/tomcrypt_math.h

@@ -502,9 +502,9 @@ typedef struct {
 
 
 extern ltc_math_descriptor ltc_mp;
 extern ltc_math_descriptor ltc_mp;
 
 
-int ltc_init_multi(void **a, ...) LTC_NULL_TERMINATED;
-void ltc_deinit_multi(void *a, ...) LTC_NULL_TERMINATED;
-void ltc_cleanup_multi(void **a, ...) LTC_NULL_TERMINATED;
+int ltc_mp_init_multi(void **a, ...) LTC_NULL_TERMINATED;
+void ltc_mp_deinit_multi(void *a, ...) LTC_NULL_TERMINATED;
+void ltc_mp_cleanup_multi(void **a, ...) LTC_NULL_TERMINATED;
 
 
 #ifdef LTM_DESC
 #ifdef LTM_DESC
 extern const ltc_math_descriptor ltm_desc;
 extern const ltc_math_descriptor ltm_desc;

+ 71 - 64
src/headers/tomcrypt_private.h

@@ -4,6 +4,9 @@
 #include "tomcrypt.h"
 #include "tomcrypt.h"
 #include <stdarg.h>
 #include <stdarg.h>
 
 
+#ifndef TOMCRYPT_PRIVATE_H_
+#define TOMCRYPT_PRIVATE_H_
+
 /*
 /*
  * Internal Macros
  * Internal Macros
  */
  */
@@ -105,6 +108,11 @@ typedef struct
    unsigned long key_bits;
    unsigned long key_bits;
 } pbes_arg;
 } pbes_arg;
 
 
+typedef struct {
+   const pbes_properties *data;
+   const char *oid;
+} oid_to_pbes;
+
 /*
 /*
  * Internal functions
  * Internal functions
  */
  */
@@ -175,72 +183,69 @@ int omac_vprocess(omac_state *omac, const unsigned char *in,  unsigned long inle
 
 
 #if !defined(DESC_DEF_ONLY)
 #if !defined(DESC_DEF_ONLY)
 
 
-#define MP_DIGIT_BIT                 ltc_mp.bits_per_digit
+#define LTC_MP_DIGIT_BIT                 ltc_mp.bits_per_digit
 
 
 /* some handy macros */
 /* some handy macros */
-#define mp_init(a)                   ltc_mp.init(a)
-#define mp_init_multi                ltc_init_multi
-#define mp_clear(a)                  ltc_mp.deinit(a)
-#define mp_clear_multi               ltc_deinit_multi
-#define mp_cleanup_multi             ltc_cleanup_multi
-#define mp_init_copy(a, b)           ltc_mp.init_copy(a, b)
-
-#define mp_neg(a, b)                 ltc_mp.neg(a, b)
-#define mp_copy(a, b)                ltc_mp.copy(a, b)
-
-#define mp_set(a, b)                 ltc_mp.set_int(a, b)
-#define mp_set_int(a, b)             ltc_mp.set_int(a, b)
-#define mp_get_int(a)                ltc_mp.get_int(a)
-#define mp_get_digit(a, n)           ltc_mp.get_digit(a, n)
-#define mp_get_digit_count(a)        ltc_mp.get_digit_count(a)
-#define mp_cmp(a, b)                 ltc_mp.compare(a, b)
-#define mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
-#define mp_count_bits(a)             ltc_mp.count_bits(a)
-#define mp_cnt_lsb(a)                ltc_mp.count_lsb_bits(a)
-#define mp_2expt(a, b)               ltc_mp.twoexpt(a, b)
-
-#define mp_read_radix(a, b, c)       ltc_mp.read_radix(a, b, c)
-#define mp_toradix(a, b, c)          ltc_mp.write_radix(a, b, c)
-#define mp_unsigned_bin_size(a)      ltc_mp.unsigned_size(a)
-#define mp_to_unsigned_bin(a, b)     ltc_mp.unsigned_write(a, b)
-#define mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
-
-#define mp_add(a, b, c)              ltc_mp.add(a, b, c)
-#define mp_add_d(a, b, c)            ltc_mp.addi(a, b, c)
-#define mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
-#define mp_sub_d(a, b, c)            ltc_mp.subi(a, b, c)
-#define mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
-#define mp_mul_d(a, b, c)            ltc_mp.muli(a, b, c)
-#define mp_sqr(a, b)                 ltc_mp.sqr(a, b)
-#define mp_sqrtmod_prime(a, b, c)    ltc_mp.sqrtmod_prime(a, b, c)
-#define mp_div(a, b, c, d)           ltc_mp.mpdiv(a, b, c, d)
-#define mp_div_2(a, b)               ltc_mp.div_2(a, b)
-#define mp_mod(a, b, c)              ltc_mp.mpdiv(a, b, NULL, c)
-#define mp_mod_d(a, b, c)            ltc_mp.modi(a, b, c)
-#define mp_gcd(a, b, c)              ltc_mp.gcd(a, b, c)
-#define mp_lcm(a, b, c)              ltc_mp.lcm(a, b, c)
-
-#define mp_addmod(a, b, c, d)        ltc_mp.addmod(a, b, c, d)
-#define mp_submod(a, b, c, d)        ltc_mp.submod(a, b, c, d)
-#define mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
-#define mp_sqrmod(a, b, c)           ltc_mp.sqrmod(a, b, c)
-#define mp_invmod(a, b, c)           ltc_mp.invmod(a, b, c)
-
-#define mp_montgomery_setup(a, b)    ltc_mp.montgomery_setup(a, b)
-#define mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
-#define mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
-#define mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
-
-#define mp_exptmod(a,b,c,d)          ltc_mp.exptmod(a,b,c,d)
-#define mp_prime_is_prime(a, b, c)   ltc_mp.isprime(a, b, c)
-
-#define mp_iszero(a)                 (mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
-#define mp_isodd(a)                  (mp_get_digit_count(a) > 0 ? (mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
-#define mp_exch(a, b)                do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0)
-
-#define mp_tohex(a, b)               mp_toradix(a, b, 16)
-
-#define mp_rand(a, b)                ltc_mp.rand(a, b)
+#define ltc_mp_init(a)                   ltc_mp.init(a)
+#define ltc_mp_clear(a)                  ltc_mp.deinit(a)
+#define ltc_mp_init_copy(a, b)           ltc_mp.init_copy(a, b)
+
+#define ltc_mp_neg(a, b)                 ltc_mp.neg(a, b)
+#define ltc_mp_copy(a, b)                ltc_mp.copy(a, b)
+
+#define ltc_mp_set(a, b)                 ltc_mp.set_int(a, b)
+#define ltc_mp_set_int(a, b)             ltc_mp.set_int(a, b)
+#define ltc_mp_get_int(a)                ltc_mp.get_int(a)
+#define ltc_mp_get_digit(a, n)           ltc_mp.get_digit(a, n)
+#define ltc_mp_get_digit_count(a)        ltc_mp.get_digit_count(a)
+#define ltc_mp_cmp(a, b)                 ltc_mp.compare(a, b)
+#define ltc_mp_cmp_d(a, b)               ltc_mp.compare_d(a, b)
+#define ltc_mp_count_bits(a)             ltc_mp.count_bits(a)
+#define ltc_mp_cnt_lsb(a)                ltc_mp.count_lsb_bits(a)
+#define ltc_mp_2expt(a, b)               ltc_mp.twoexpt(a, b)
+
+#define ltc_mp_read_radix(a, b, c)       ltc_mp.read_radix(a, b, c)
+#define ltc_mp_toradix(a, b, c)          ltc_mp.write_radix(a, b, c)
+#define ltc_mp_unsigned_bin_size(a)      ltc_mp.unsigned_size(a)
+#define ltc_mp_to_unsigned_bin(a, b)     ltc_mp.unsigned_write(a, b)
+#define ltc_mp_read_unsigned_bin(a, b, c) ltc_mp.unsigned_read(a, b, c)
+
+#define ltc_mp_add(a, b, c)              ltc_mp.add(a, b, c)
+#define ltc_mp_add_d(a, b, c)            ltc_mp.addi(a, b, c)
+#define ltc_mp_sub(a, b, c)              ltc_mp.sub(a, b, c)
+#define ltc_mp_sub_d(a, b, c)            ltc_mp.subi(a, b, c)
+#define ltc_mp_mul(a, b, c)              ltc_mp.mul(a, b, c)
+#define ltc_mp_mul_d(a, b, c)            ltc_mp.muli(a, b, c)
+#define ltc_mp_sqr(a, b)                 ltc_mp.sqr(a, b)
+#define ltc_mp_sqrtmod_prime(a, b, c)    ltc_mp.sqrtmod_prime(a, b, c)
+#define ltc_mp_div(a, b, c, d)           ltc_mp.mpdiv(a, b, c, d)
+#define ltc_mp_div_2(a, b)               ltc_mp.div_2(a, b)
+#define ltc_mp_mod(a, b, c)              ltc_mp.mpdiv(a, b, NULL, c)
+#define ltc_mp_mod_d(a, b, c)            ltc_mp.modi(a, b, c)
+#define ltc_mp_gcd(a, b, c)              ltc_mp.gcd(a, b, c)
+#define ltc_mp_lcm(a, b, c)              ltc_mp.lcm(a, b, c)
+
+#define ltc_mp_addmod(a, b, c, d)        ltc_mp.addmod(a, b, c, d)
+#define ltc_mp_submod(a, b, c, d)        ltc_mp.submod(a, b, c, d)
+#define ltc_mp_mulmod(a, b, c, d)        ltc_mp.mulmod(a, b, c, d)
+#define ltc_mp_sqrmod(a, b, c)           ltc_mp.sqrmod(a, b, c)
+#define ltc_mp_invmod(a, b, c)           ltc_mp.invmod(a, b, c)
+
+#define ltc_mp_montgomery_setup(a, b)    ltc_mp.montgomery_setup(a, b)
+#define ltc_mp_montgomery_normalization(a, b) ltc_mp.montgomery_normalization(a, b)
+#define ltc_mp_montgomery_reduce(a, b, c)   ltc_mp.montgomery_reduce(a, b, c)
+#define ltc_mp_montgomery_free(a)        ltc_mp.montgomery_deinit(a)
+
+#define ltc_mp_exptmod(a,b,c,d)          ltc_mp.exptmod(a,b,c,d)
+#define ltc_mp_prime_is_prime(a, b, c)   ltc_mp.isprime(a, b, c)
+
+#define ltc_mp_iszero(a)                 (ltc_mp_cmp_d(a, 0) == LTC_MP_EQ ? LTC_MP_YES : LTC_MP_NO)
+#define ltc_mp_isodd(a)                  (ltc_mp_get_digit_count(a) > 0 ? (ltc_mp_get_digit(a, 0) & 1 ? LTC_MP_YES : LTC_MP_NO) : LTC_MP_NO)
+#define ltc_mp_exch(a, b)                do { void *ABC__tmp = a; a = b; b = ABC__tmp; } while(0)
+
+#define ltc_mp_tohex(a, b)               ltc_mp_toradix(a, b, 16)
+
+#define ltc_mp_rand(a, b)                ltc_mp.rand(a, b)
 
 
 #endif
 #endif
 
 
@@ -695,3 +700,5 @@ int which ## _export(unsigned char *out, unsigned long *outlen, prng_state *prng
       #define LTC_WIN32_BCRYPT
       #define LTC_WIN32_BCRYPT
    #endif
    #endif
 #endif
 #endif
+
+#endif /* TOMCRYPT_PRIVATE_H_ */

+ 2 - 0
src/mac/pelican/pelican.c

@@ -9,10 +9,12 @@
 
 
 #ifdef LTC_PELICAN
 #ifdef LTC_PELICAN
 
 
+#ifndef LTC_AES_TAB_C
 #define LTC_AES_TAB_C
 #define LTC_AES_TAB_C
 #define ENCRYPT_ONLY
 #define ENCRYPT_ONLY
 #define PELI_TAB
 #define PELI_TAB
 #include "../../ciphers/aes/aes_tab.c"
 #include "../../ciphers/aes/aes_tab.c"
+#endif
 
 
 /**
 /**
    Initialize a Pelican state
    Initialize a Pelican state

+ 3 - 0
src/mac/pmac/pmac_init.c

@@ -9,6 +9,7 @@
 
 
 #ifdef LTC_PMAC
 #ifdef LTC_PMAC
 
 
+#define polys pmac_polys
 static const struct {
 static const struct {
     int           len;
     int           len;
     unsigned char poly_div[MAXBLOCKSIZE],
     unsigned char poly_div[MAXBLOCKSIZE],
@@ -135,4 +136,6 @@ error:
    return err;
    return err;
 }
 }
 
 
+#undef polys
+
 #endif
 #endif

+ 114 - 114
src/math/fp/ltc_ecc_fp_mulmod.c

@@ -587,7 +587,7 @@ static int s_find_hole(void)
    /* free entry z */
    /* free entry z */
    if (z >= 0 && fp_cache[z].g) {
    if (z >= 0 && fp_cache[z].g) {
       if (fp_cache[z].mu != NULL) {
       if (fp_cache[z].mu != NULL) {
-         mp_clear(fp_cache[z].mu);
+         ltc_mp_clear(fp_cache[z].mu);
          fp_cache[z].mu = NULL;
          fp_cache[z].mu = NULL;
       }
       }
       ltc_ecc_del_point(fp_cache[z].g);
       ltc_ecc_del_point(fp_cache[z].g);
@@ -607,9 +607,9 @@ static int s_find_base(ecc_point *g)
    int x;
    int x;
    for (x = 0; x < FP_ENTRIES; x++) {
    for (x = 0; x < FP_ENTRIES; x++) {
       if (fp_cache[x].g != NULL &&
       if (fp_cache[x].g != NULL &&
-          mp_cmp(fp_cache[x].g->x, g->x) == LTC_MP_EQ &&
-          mp_cmp(fp_cache[x].g->y, g->y) == LTC_MP_EQ &&
-          mp_cmp(fp_cache[x].g->z, g->z) == LTC_MP_EQ) {
+          ltc_mp_cmp(fp_cache[x].g->x, g->x) == LTC_MP_EQ &&
+          ltc_mp_cmp(fp_cache[x].g->y, g->y) == LTC_MP_EQ &&
+          ltc_mp_cmp(fp_cache[x].g->z, g->z) == LTC_MP_EQ) {
          break;
          break;
       }
       }
    }
    }
@@ -631,9 +631,9 @@ static int s_add_entry(int idx, ecc_point *g)
    }
    }
 
 
    /* copy x and y */
    /* copy x and y */
-   if ((mp_copy(g->x, fp_cache[idx].g->x) != CRYPT_OK) ||
-       (mp_copy(g->y, fp_cache[idx].g->y) != CRYPT_OK) ||
-       (mp_copy(g->z, fp_cache[idx].g->z) != CRYPT_OK)) {
+   if ((ltc_mp_copy(g->x, fp_cache[idx].g->x) != CRYPT_OK) ||
+       (ltc_mp_copy(g->y, fp_cache[idx].g->y) != CRYPT_OK) ||
+       (ltc_mp_copy(g->z, fp_cache[idx].g->z) != CRYPT_OK)) {
       ltc_ecc_del_point(fp_cache[idx].g);
       ltc_ecc_del_point(fp_cache[idx].g);
       fp_cache[idx].g = NULL;
       fp_cache[idx].g = NULL;
       return CRYPT_MEM;
       return CRYPT_MEM;
@@ -676,7 +676,7 @@ static int s_build_lut(int idx, void *a, void *modulus, void *mp, void *mu)
    }
    }
 
 
    /* get bitlen and round up to next multiple of FP_LUT */
    /* get bitlen and round up to next multiple of FP_LUT */
-   bitlen  = mp_unsigned_bin_size(modulus) << 3;
+   bitlen  = ltc_mp_unsigned_bin_size(modulus) << 3;
    x       = bitlen % FP_LUT;
    x       = bitlen % FP_LUT;
    if (x) {
    if (x) {
       bitlen += FP_LUT - x;
       bitlen += FP_LUT - x;
@@ -684,20 +684,20 @@ static int s_build_lut(int idx, void *a, void *modulus, void *mp, void *mu)
    lut_gap = bitlen / FP_LUT;
    lut_gap = bitlen / FP_LUT;
 
 
    /* init the mu */
    /* init the mu */
-   if ((err = mp_init_copy(&fp_cache[idx].mu, mu)) != CRYPT_OK) {
+   if ((err = ltc_mp_init_copy(&fp_cache[idx].mu, mu)) != CRYPT_OK) {
       goto ERR;
       goto ERR;
    }
    }
 
 
    /* copy base */
    /* copy base */
-   if ((mp_mulmod(fp_cache[idx].g->x, mu, modulus, fp_cache[idx].LUT[1]->x) != CRYPT_OK) ||
-       (mp_mulmod(fp_cache[idx].g->y, mu, modulus, fp_cache[idx].LUT[1]->y) != CRYPT_OK) ||
-       (mp_mulmod(fp_cache[idx].g->z, mu, modulus, fp_cache[idx].LUT[1]->z) != CRYPT_OK))        { goto ERR; }
+   if ((ltc_mp_mulmod(fp_cache[idx].g->x, mu, modulus, fp_cache[idx].LUT[1]->x) != CRYPT_OK) ||
+       (ltc_mp_mulmod(fp_cache[idx].g->y, mu, modulus, fp_cache[idx].LUT[1]->y) != CRYPT_OK) ||
+       (ltc_mp_mulmod(fp_cache[idx].g->z, mu, modulus, fp_cache[idx].LUT[1]->z) != CRYPT_OK))        { goto ERR; }
 
 
    /* make all single bit entries */
    /* make all single bit entries */
    for (x = 1; x < FP_LUT; x++) {
    for (x = 1; x < FP_LUT; x++) {
-      if ((mp_copy(fp_cache[idx].LUT[1<<(x-1)]->x, fp_cache[idx].LUT[1<<x]->x) != CRYPT_OK) ||
-          (mp_copy(fp_cache[idx].LUT[1<<(x-1)]->y, fp_cache[idx].LUT[1<<x]->y) != CRYPT_OK) ||
-          (mp_copy(fp_cache[idx].LUT[1<<(x-1)]->z, fp_cache[idx].LUT[1<<x]->z) != CRYPT_OK))     { goto ERR; }
+      if ((ltc_mp_copy(fp_cache[idx].LUT[1<<(x-1)]->x, fp_cache[idx].LUT[1<<x]->x) != CRYPT_OK) ||
+          (ltc_mp_copy(fp_cache[idx].LUT[1<<(x-1)]->y, fp_cache[idx].LUT[1<<x]->y) != CRYPT_OK) ||
+          (ltc_mp_copy(fp_cache[idx].LUT[1<<(x-1)]->z, fp_cache[idx].LUT[1<<x]->z) != CRYPT_OK))     { goto ERR; }
 
 
       /* now double it bitlen/FP_LUT times */
       /* now double it bitlen/FP_LUT times */
       for (y = 0; y < lut_gap; y++) {
       for (y = 0; y < lut_gap; y++) {
@@ -721,31 +721,31 @@ static int s_build_lut(int idx, void *a, void *modulus, void *mp, void *mu)
    }
    }
 
 
    /* now map all entries back to affine space to make point addition faster */
    /* now map all entries back to affine space to make point addition faster */
-   if ((err = mp_init(&tmp)) != CRYPT_OK)                                                                    { goto ERR; }
+   if ((err = ltc_mp_init(&tmp)) != CRYPT_OK)                                                                    { goto ERR; }
    for (x = 1; x < (1UL<<FP_LUT); x++) {
    for (x = 1; x < (1UL<<FP_LUT); x++) {
        /* convert z to normal from montgomery */
        /* convert z to normal from montgomery */
-       if ((err = mp_montgomery_reduce(fp_cache[idx].LUT[x]->z, modulus, mp)) != CRYPT_OK)                   { goto ERR; }
+       if ((err = ltc_mp_montgomery_reduce(fp_cache[idx].LUT[x]->z, modulus, mp)) != CRYPT_OK)                   { goto ERR; }
 
 
        /* invert it */
        /* invert it */
-       if ((err = mp_invmod(fp_cache[idx].LUT[x]->z, modulus, fp_cache[idx].LUT[x]->z)) != CRYPT_OK)         { goto ERR; }
+       if ((err = ltc_mp_invmod(fp_cache[idx].LUT[x]->z, modulus, fp_cache[idx].LUT[x]->z)) != CRYPT_OK)         { goto ERR; }
 
 
        /* now square it */
        /* now square it */
-       if ((err = mp_sqrmod(fp_cache[idx].LUT[x]->z, modulus, tmp)) != CRYPT_OK)                             { goto ERR; }
+       if ((err = ltc_mp_sqrmod(fp_cache[idx].LUT[x]->z, modulus, tmp)) != CRYPT_OK)                             { goto ERR; }
 
 
        /* fix x */
        /* fix x */
-       if ((err = mp_mulmod(fp_cache[idx].LUT[x]->x, tmp, modulus, fp_cache[idx].LUT[x]->x)) != CRYPT_OK)    { goto ERR; }
+       if ((err = ltc_mp_mulmod(fp_cache[idx].LUT[x]->x, tmp, modulus, fp_cache[idx].LUT[x]->x)) != CRYPT_OK)    { goto ERR; }
 
 
        /* get 1/z^3 */
        /* get 1/z^3 */
-       if ((err = mp_mulmod(tmp, fp_cache[idx].LUT[x]->z, modulus, tmp)) != CRYPT_OK)                        { goto ERR; }
+       if ((err = ltc_mp_mulmod(tmp, fp_cache[idx].LUT[x]->z, modulus, tmp)) != CRYPT_OK)                        { goto ERR; }
 
 
        /* fix y */
        /* fix y */
-       if ((err = mp_mulmod(fp_cache[idx].LUT[x]->y, tmp, modulus, fp_cache[idx].LUT[x]->y)) != CRYPT_OK)    { goto ERR; }
+       if ((err = ltc_mp_mulmod(fp_cache[idx].LUT[x]->y, tmp, modulus, fp_cache[idx].LUT[x]->y)) != CRYPT_OK)    { goto ERR; }
 
 
        /* free z */
        /* free z */
-       mp_clear(fp_cache[idx].LUT[x]->z);
+       ltc_mp_clear(fp_cache[idx].LUT[x]->z);
        fp_cache[idx].LUT[x]->z = NULL;
        fp_cache[idx].LUT[x]->z = NULL;
    }
    }
-   mp_clear(tmp);
+   ltc_mp_clear(tmp);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 ERR:
 ERR:
@@ -759,11 +759,11 @@ DONE:
    fp_cache[idx].g         = NULL;
    fp_cache[idx].g         = NULL;
    fp_cache[idx].lru_count = 0;
    fp_cache[idx].lru_count = 0;
    if (fp_cache[idx].mu != NULL) {
    if (fp_cache[idx].mu != NULL) {
-      mp_clear(fp_cache[idx].mu);
+      ltc_mp_clear(fp_cache[idx].mu);
       fp_cache[idx].mu = NULL;
       fp_cache[idx].mu = NULL;
    }
    }
    if (tmp != NULL) {
    if (tmp != NULL) {
-      mp_clear(tmp);
+      ltc_mp_clear(tmp);
    }
    }
    return err;
    return err;
 }
 }
@@ -777,9 +777,9 @@ static int s_accel_fp_mul(int idx, void *k, ecc_point *R, void *a, void *modulus
    void     *tk, *order;
    void     *tk, *order;
 
 
    /* if it's smaller than modulus we fine */
    /* if it's smaller than modulus we fine */
-   if (mp_unsigned_bin_size(k) > mp_unsigned_bin_size(modulus)) {
+   if (ltc_mp_unsigned_bin_size(k) > ltc_mp_unsigned_bin_size(modulus)) {
       /* find order */
       /* find order */
-      y = mp_unsigned_bin_size(modulus);
+      y = ltc_mp_unsigned_bin_size(modulus);
       for (x = 0; ltc_ecc_sets[x].size; x++) {
       for (x = 0; ltc_ecc_sets[x].size; x++) {
          if (y <= (unsigned)ltc_ecc_sets[x].size) break;
          if (y <= (unsigned)ltc_ecc_sets[x].size) break;
       }
       }
@@ -787,35 +787,35 @@ static int s_accel_fp_mul(int idx, void *k, ecc_point *R, void *a, void *modulus
       /* back off if we are on the 521 bit curve */
       /* back off if we are on the 521 bit curve */
       if (y == 66) --x;
       if (y == 66) --x;
 
 
-      if ((err = mp_init(&order)) != CRYPT_OK) {
+      if ((err = ltc_mp_init(&order)) != CRYPT_OK) {
          return err;
          return err;
       }
       }
-      if ((err = mp_read_radix(order, ltc_ecc_sets[x].order, 16)) != CRYPT_OK) {
-         mp_clear(&order);
+      if ((err = ltc_mp_read_radix(order, ltc_ecc_sets[x].order, 16)) != CRYPT_OK) {
+         ltc_mp_clear(&order);
          return err;
          return err;
       }
       }
 
 
       /* k must be less than modulus */
       /* k must be less than modulus */
-      if (mp_cmp(k, order) != LTC_MP_LT) {
-         if ((err = mp_init(&tk)) != CRYPT_OK) {
-            mp_clear(order);
+      if (ltc_mp_cmp(k, order) != LTC_MP_LT) {
+         if ((err = ltc_mp_init(&tk)) != CRYPT_OK) {
+            ltc_mp_clear(order);
             return err;
             return err;
          }
          }
-         if ((err = mp_mod(k, order, tk)) != CRYPT_OK) {
-            mp_clear(tk);
-            mp_clear(order);
+         if ((err = ltc_mp_mod(k, order, tk)) != CRYPT_OK) {
+            ltc_mp_clear(tk);
+            ltc_mp_clear(order);
             return err;
             return err;
          }
          }
       } else {
       } else {
          tk = k;
          tk = k;
       }
       }
-      mp_clear(order);
+      ltc_mp_clear(order);
    } else {
    } else {
        tk = k;
        tk = k;
    }
    }
 
 
    /* get bitlen and round up to next multiple of FP_LUT */
    /* get bitlen and round up to next multiple of FP_LUT */
-   bitlen  = mp_unsigned_bin_size(modulus) << 3;
+   bitlen  = ltc_mp_unsigned_bin_size(modulus) << 3;
    x       = bitlen % FP_LUT;
    x       = bitlen % FP_LUT;
    if (x) {
    if (x) {
       bitlen += FP_LUT - x;
       bitlen += FP_LUT - x;
@@ -823,27 +823,27 @@ static int s_accel_fp_mul(int idx, void *k, ecc_point *R, void *a, void *modulus
    lut_gap = bitlen / FP_LUT;
    lut_gap = bitlen / FP_LUT;
 
 
    /* get the k value */
    /* get the k value */
-   if (mp_unsigned_bin_size(tk) > (sizeof(kb) - 2)) {
+   if (ltc_mp_unsigned_bin_size(tk) > (sizeof(kb) - 2)) {
       if (tk != k) {
       if (tk != k) {
-         mp_clear(tk);
+         ltc_mp_clear(tk);
       }
       }
       return CRYPT_BUFFER_OVERFLOW;
       return CRYPT_BUFFER_OVERFLOW;
    }
    }
 
 
    /* store k */
    /* store k */
    zeromem(kb, sizeof(kb));
    zeromem(kb, sizeof(kb));
-   if ((err = mp_to_unsigned_bin(tk, kb)) != CRYPT_OK) {
+   if ((err = ltc_mp_to_unsigned_bin(tk, kb)) != CRYPT_OK) {
       if (tk != k) {
       if (tk != k) {
-         mp_clear(tk);
+         ltc_mp_clear(tk);
       }
       }
       return err;
       return err;
    }
    }
 
 
    /* let's reverse kb so it's little endian */
    /* let's reverse kb so it's little endian */
    x = 0;
    x = 0;
-   y = mp_unsigned_bin_size(tk) - 1;
+   y = ltc_mp_unsigned_bin_size(tk) - 1;
    if (tk != k) {
    if (tk != k) {
-      mp_clear(tk);
+      ltc_mp_clear(tk);
    }
    }
    while ((unsigned)x < y) {
    while ((unsigned)x < y) {
       z = kb[x]; kb[x] = kb[y]; kb[y] = z;
       z = kb[x]; kb[x] = kb[y]; kb[y] = z;
@@ -873,9 +873,9 @@ static int s_accel_fp_mul(int idx, void *k, ecc_point *R, void *a, void *modulus
              return err;
              return err;
           }
           }
        } else if (z) {
        } else if (z) {
-          if ((mp_copy(fp_cache[idx].LUT[z]->x, R->x) != CRYPT_OK) ||
-              (mp_copy(fp_cache[idx].LUT[z]->y, R->y) != CRYPT_OK) ||
-              (mp_copy(fp_cache[idx].mu,        R->z) != CRYPT_OK)) { return CRYPT_MEM; }
+          if ((ltc_mp_copy(fp_cache[idx].LUT[z]->x, R->x) != CRYPT_OK) ||
+              (ltc_mp_copy(fp_cache[idx].LUT[z]->y, R->y) != CRYPT_OK) ||
+              (ltc_mp_copy(fp_cache[idx].mu,        R->z) != CRYPT_OK)) { return CRYPT_MEM; }
               first = 0;
               first = 0;
        }
        }
    }
    }
@@ -902,9 +902,9 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
    void     *tka, *tkb, *order;
    void     *tka, *tkb, *order;
 
 
    /* if it's smaller than modulus we fine */
    /* if it's smaller than modulus we fine */
-   if (mp_unsigned_bin_size(kA) > mp_unsigned_bin_size(modulus)) {
+   if (ltc_mp_unsigned_bin_size(kA) > ltc_mp_unsigned_bin_size(modulus)) {
       /* find order */
       /* find order */
-      y = mp_unsigned_bin_size(modulus);
+      y = ltc_mp_unsigned_bin_size(modulus);
       for (x = 0; ltc_ecc_sets[x].size; x++) {
       for (x = 0; ltc_ecc_sets[x].size; x++) {
          if (y <= (unsigned)ltc_ecc_sets[x].size) break;
          if (y <= (unsigned)ltc_ecc_sets[x].size) break;
       }
       }
@@ -912,37 +912,37 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
       /* back off if we are on the 521 bit curve */
       /* back off if we are on the 521 bit curve */
       if (y == 66) --x;
       if (y == 66) --x;
 
 
-      if ((err = mp_init(&order)) != CRYPT_OK) {
+      if ((err = ltc_mp_init(&order)) != CRYPT_OK) {
          return err;
          return err;
       }
       }
-      if ((err = mp_read_radix(order, ltc_ecc_sets[x].order, 16)) != CRYPT_OK) {
-         mp_clear(&order);
+      if ((err = ltc_mp_read_radix(order, ltc_ecc_sets[x].order, 16)) != CRYPT_OK) {
+         ltc_mp_clear(&order);
          return err;
          return err;
       }
       }
 
 
       /* kA must be less than modulus */
       /* kA must be less than modulus */
-      if (mp_cmp(kA, order) != LTC_MP_LT) {
-         if ((err = mp_init(&tka)) != CRYPT_OK) {
-            mp_clear(order);
+      if (ltc_mp_cmp(kA, order) != LTC_MP_LT) {
+         if ((err = ltc_mp_init(&tka)) != CRYPT_OK) {
+            ltc_mp_clear(order);
             return err;
             return err;
          }
          }
-         if ((err = mp_mod(kA, order, tka)) != CRYPT_OK) {
-            mp_clear(tka);
-            mp_clear(order);
+         if ((err = ltc_mp_mod(kA, order, tka)) != CRYPT_OK) {
+            ltc_mp_clear(tka);
+            ltc_mp_clear(order);
             return err;
             return err;
          }
          }
       } else {
       } else {
          tka = kA;
          tka = kA;
       }
       }
-      mp_clear(order);
+      ltc_mp_clear(order);
    } else {
    } else {
       tka = kA;
       tka = kA;
    }
    }
 
 
    /* if it's smaller than modulus we fine */
    /* if it's smaller than modulus we fine */
-   if (mp_unsigned_bin_size(kB) > mp_unsigned_bin_size(modulus)) {
+   if (ltc_mp_unsigned_bin_size(kB) > ltc_mp_unsigned_bin_size(modulus)) {
       /* find order */
       /* find order */
-      y = mp_unsigned_bin_size(modulus);
+      y = ltc_mp_unsigned_bin_size(modulus);
       for (x = 0; ltc_ecc_sets[x].size; x++) {
       for (x = 0; ltc_ecc_sets[x].size; x++) {
          if (y <= (unsigned)ltc_ecc_sets[x].size) break;
          if (y <= (unsigned)ltc_ecc_sets[x].size) break;
       }
       }
@@ -950,35 +950,35 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
       /* back off if we are on the 521 bit curve */
       /* back off if we are on the 521 bit curve */
       if (y == 66) --x;
       if (y == 66) --x;
 
 
-      if ((err = mp_init(&order)) != CRYPT_OK) {
+      if ((err = ltc_mp_init(&order)) != CRYPT_OK) {
          return err;
          return err;
       }
       }
-      if ((err = mp_read_radix(order, ltc_ecc_sets[x].order, 16)) != CRYPT_OK) {
-         mp_clear(&order);
+      if ((err = ltc_mp_read_radix(order, ltc_ecc_sets[x].order, 16)) != CRYPT_OK) {
+         ltc_mp_clear(&order);
          return err;
          return err;
       }
       }
 
 
       /* kB must be less than modulus */
       /* kB must be less than modulus */
-      if (mp_cmp(kB, order) != LTC_MP_LT) {
-         if ((err = mp_init(&tkb)) != CRYPT_OK) {
-            mp_clear(order);
+      if (ltc_mp_cmp(kB, order) != LTC_MP_LT) {
+         if ((err = ltc_mp_init(&tkb)) != CRYPT_OK) {
+            ltc_mp_clear(order);
             return err;
             return err;
          }
          }
-         if ((err = mp_mod(kB, order, tkb)) != CRYPT_OK) {
-            mp_clear(tkb);
-            mp_clear(order);
+         if ((err = ltc_mp_mod(kB, order, tkb)) != CRYPT_OK) {
+            ltc_mp_clear(tkb);
+            ltc_mp_clear(order);
             return err;
             return err;
          }
          }
       } else {
       } else {
          tkb = kB;
          tkb = kB;
       }
       }
-      mp_clear(order);
+      ltc_mp_clear(order);
    } else {
    } else {
       tkb = kB;
       tkb = kB;
    }
    }
 
 
    /* get bitlen and round up to next multiple of FP_LUT */
    /* get bitlen and round up to next multiple of FP_LUT */
-   bitlen  = mp_unsigned_bin_size(modulus) << 3;
+   bitlen  = ltc_mp_unsigned_bin_size(modulus) << 3;
    x       = bitlen % FP_LUT;
    x       = bitlen % FP_LUT;
    if (x) {
    if (x) {
       bitlen += FP_LUT - x;
       bitlen += FP_LUT - x;
@@ -986,33 +986,33 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
    lut_gap = bitlen / FP_LUT;
    lut_gap = bitlen / FP_LUT;
 
 
    /* get the k value */
    /* get the k value */
-   if ((mp_unsigned_bin_size(tka) > (sizeof(kb[0]) - 2)) || (mp_unsigned_bin_size(tkb) > (sizeof(kb[0]) - 2))  ) {
+   if ((ltc_mp_unsigned_bin_size(tka) > (sizeof(kb[0]) - 2)) || (ltc_mp_unsigned_bin_size(tkb) > (sizeof(kb[0]) - 2))  ) {
       if (tka != kA) {
       if (tka != kA) {
-         mp_clear(tka);
+         ltc_mp_clear(tka);
       }
       }
       if (tkb != kB) {
       if (tkb != kB) {
-         mp_clear(tkb);
+         ltc_mp_clear(tkb);
       }
       }
       return CRYPT_BUFFER_OVERFLOW;
       return CRYPT_BUFFER_OVERFLOW;
    }
    }
 
 
    /* store k */
    /* store k */
    zeromem(kb, sizeof(kb));
    zeromem(kb, sizeof(kb));
-   if ((err = mp_to_unsigned_bin(tka, kb[0])) != CRYPT_OK) {
+   if ((err = ltc_mp_to_unsigned_bin(tka, kb[0])) != CRYPT_OK) {
       if (tka != kA) {
       if (tka != kA) {
-         mp_clear(tka);
+         ltc_mp_clear(tka);
       }
       }
       if (tkb != kB) {
       if (tkb != kB) {
-         mp_clear(tkb);
+         ltc_mp_clear(tkb);
       }
       }
       return err;
       return err;
    }
    }
 
 
    /* let's reverse kb so it's little endian */
    /* let's reverse kb so it's little endian */
    x = 0;
    x = 0;
-   y = mp_unsigned_bin_size(tka) - 1;
+   y = ltc_mp_unsigned_bin_size(tka) - 1;
    if (tka != kA) {
    if (tka != kA) {
-      mp_clear(tka);
+      ltc_mp_clear(tka);
    }
    }
    while ((unsigned)x < y) {
    while ((unsigned)x < y) {
       z = kb[0][x]; kb[0][x] = kb[0][y]; kb[0][y] = z;
       z = kb[0][x]; kb[0][x] = kb[0][y]; kb[0][y] = z;
@@ -1020,17 +1020,17 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
    }
    }
 
 
    /* store b */
    /* store b */
-   if ((err = mp_to_unsigned_bin(tkb, kb[1])) != CRYPT_OK) {
+   if ((err = ltc_mp_to_unsigned_bin(tkb, kb[1])) != CRYPT_OK) {
       if (tkb != kB) {
       if (tkb != kB) {
-         mp_clear(tkb);
+         ltc_mp_clear(tkb);
       }
       }
       return err;
       return err;
    }
    }
 
 
    x = 0;
    x = 0;
-   y = mp_unsigned_bin_size(tkb) - 1;
+   y = ltc_mp_unsigned_bin_size(tkb) - 1;
    if (tkb != kB) {
    if (tkb != kB) {
-      mp_clear(tkb);
+      ltc_mp_clear(tkb);
    }
    }
    while ((unsigned)x < y) {
    while ((unsigned)x < y) {
       z = kb[1][x]; kb[1][x] = kb[1][y]; kb[1][y] = z;
       z = kb[1][x]; kb[1][x] = kb[1][y]; kb[1][y] = z;
@@ -1069,9 +1069,9 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
           }
           }
        } else {
        } else {
           if (zA) {
           if (zA) {
-              if ((mp_copy(fp_cache[idx1].LUT[zA]->x, R->x) != CRYPT_OK) ||
-                 (mp_copy(fp_cache[idx1].LUT[zA]->y, R->y) != CRYPT_OK) ||
-                 (mp_copy(fp_cache[idx1].mu,        R->z) != CRYPT_OK)) { return CRYPT_MEM; }
+              if ((ltc_mp_copy(fp_cache[idx1].LUT[zA]->x, R->x) != CRYPT_OK) ||
+                 (ltc_mp_copy(fp_cache[idx1].LUT[zA]->y, R->y) != CRYPT_OK) ||
+                 (ltc_mp_copy(fp_cache[idx1].mu,        R->z) != CRYPT_OK)) { return CRYPT_MEM; }
                  first = 0;
                  first = 0;
           }
           }
           if (zB && first == 0) {
           if (zB && first == 0) {
@@ -1081,9 +1081,9 @@ static int ss_accel_fp_mul2add(int idx1, int idx2,
                 }
                 }
              }
              }
           } else if (zB && first == 1) {
           } else if (zB && first == 1) {
-              if ((mp_copy(fp_cache[idx2].LUT[zB]->x, R->x) != CRYPT_OK) ||
-                 (mp_copy(fp_cache[idx2].LUT[zB]->y, R->y) != CRYPT_OK) ||
-                 (mp_copy(fp_cache[idx2].mu,        R->z) != CRYPT_OK)) { return CRYPT_MEM; }
+              if ((ltc_mp_copy(fp_cache[idx2].LUT[zB]->x, R->x) != CRYPT_OK) ||
+                 (ltc_mp_copy(fp_cache[idx2].LUT[zB]->y, R->y) != CRYPT_OK) ||
+                 (ltc_mp_copy(fp_cache[idx2].mu,        R->z) != CRYPT_OK)) { return CRYPT_MEM; }
                  first = 0;
                  first = 0;
           }
           }
        }
        }
@@ -1151,13 +1151,13 @@ int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
       /* if it's 2 build the LUT, if it's higher just use the LUT */
       /* if it's 2 build the LUT, if it's higher just use the LUT */
       if (idx1 >= 0 && fp_cache[idx1].lru_count == 2) {
       if (idx1 >= 0 && fp_cache[idx1].lru_count == 2) {
          /* compute mp */
          /* compute mp */
-         if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
+         if ((err = ltc_mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
 
 
          /* compute mu */
          /* compute mu */
-         if ((err = mp_init(&mu)) != CRYPT_OK) {
+         if ((err = ltc_mp_init(&mu)) != CRYPT_OK) {
              goto LBL_ERR;
              goto LBL_ERR;
          }
          }
-         if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
+         if ((err = ltc_mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
             goto LBL_ERR;
             goto LBL_ERR;
          }
          }
 
 
@@ -1171,13 +1171,13 @@ int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
       if (idx2 >= 0 && fp_cache[idx2].lru_count == 2) {
       if (idx2 >= 0 && fp_cache[idx2].lru_count == 2) {
          if (mp == NULL) {
          if (mp == NULL) {
             /* compute mp */
             /* compute mp */
-            if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
+            if ((err = ltc_mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
 
 
             /* compute mu */
             /* compute mu */
-            if ((err = mp_init(&mu)) != CRYPT_OK) {
+            if ((err = ltc_mp_init(&mu)) != CRYPT_OK) {
                 goto LBL_ERR;
                 goto LBL_ERR;
             }
             }
-            if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
+            if ((err = ltc_mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
                goto LBL_ERR;
                goto LBL_ERR;
             }
             }
          }
          }
@@ -1192,7 +1192,7 @@ int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
       if (idx1 >=0 && idx2 >= 0 && fp_cache[idx1].lru_count >= 2 && fp_cache[idx2].lru_count >= 2) {
       if (idx1 >=0 && idx2 >= 0 && fp_cache[idx1].lru_count >= 2 && fp_cache[idx2].lru_count >= 2) {
          if (mp == NULL) {
          if (mp == NULL) {
             /* compute mp */
             /* compute mp */
-            if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
+            if ((err = ltc_mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
          }
          }
          err = ss_accel_fp_mul2add(idx1, idx2, kA, kB, C, a, modulus, mp);
          err = ss_accel_fp_mul2add(idx1, idx2, kA, kB, C, a, modulus, mp);
       } else {
       } else {
@@ -1201,10 +1201,10 @@ int ltc_ecc_fp_mul2add(ecc_point *A, void *kA,
 LBL_ERR:
 LBL_ERR:
     LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
     LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
     if (mp != NULL) {
     if (mp != NULL) {
-       mp_montgomery_free(mp);
+       ltc_mp_montgomery_free(mp);
     }
     }
     if (mu != NULL) {
     if (mu != NULL) {
-       mp_clear(mu);
+       ltc_mp_clear(mu);
     }
     }
     return err;
     return err;
 }
 }
@@ -1250,13 +1250,13 @@ int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulu
       /* if it's 2 build the LUT, if it's higher just use the LUT */
       /* if it's 2 build the LUT, if it's higher just use the LUT */
       if (idx >= 0 && fp_cache[idx].lru_count == 2) {
       if (idx >= 0 && fp_cache[idx].lru_count == 2) {
          /* compute mp */
          /* compute mp */
-         if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
+         if ((err = ltc_mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
 
 
          /* compute mu */
          /* compute mu */
-         if ((err = mp_init(&mu)) != CRYPT_OK) {
+         if ((err = ltc_mp_init(&mu)) != CRYPT_OK) {
              goto LBL_ERR;
              goto LBL_ERR;
          }
          }
-         if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
+         if ((err = ltc_mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
             goto LBL_ERR;
             goto LBL_ERR;
          }
          }
 
 
@@ -1269,7 +1269,7 @@ int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulu
       if (idx >= 0 && fp_cache[idx].lru_count >= 2) {
       if (idx >= 0 && fp_cache[idx].lru_count >= 2) {
          if (mp == NULL) {
          if (mp == NULL) {
             /* compute mp */
             /* compute mp */
-            if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
+            if ((err = ltc_mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) { goto LBL_ERR; }
          }
          }
          err = s_accel_fp_mul(idx, k, R, a, modulus, mp, map);
          err = s_accel_fp_mul(idx, k, R, a, modulus, mp, map);
       } else {
       } else {
@@ -1278,10 +1278,10 @@ int ltc_ecc_fp_mulmod(void *k, ecc_point *G, ecc_point *R, void *a, void *modulu
 LBL_ERR:
 LBL_ERR:
     LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
     LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
     if (mp != NULL) {
     if (mp != NULL) {
-       mp_montgomery_free(mp);
+       ltc_mp_montgomery_free(mp);
     }
     }
     if (mu != NULL) {
     if (mu != NULL) {
-       mp_clear(mu);
+       ltc_mp_clear(mu);
     }
     }
     return err;
     return err;
 }
 }
@@ -1299,7 +1299,7 @@ static void s_ltc_ecc_fp_free_cache(void)
          ltc_ecc_del_point(fp_cache[x].g);
          ltc_ecc_del_point(fp_cache[x].g);
          fp_cache[x].g         = NULL;
          fp_cache[x].g         = NULL;
          if (fp_cache[x].mu != NULL) {
          if (fp_cache[x].mu != NULL) {
-            mp_clear(fp_cache[x].mu);
+            ltc_mp_clear(fp_cache[x].mu);
             fp_cache[x].mu     = NULL;
             fp_cache[x].mu     = NULL;
          }
          }
          fp_cache[x].lru_count = 0;
          fp_cache[x].lru_count = 0;
@@ -1347,15 +1347,15 @@ ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock)
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
    /* compute mp */
    /* compute mp */
-   if ((err = mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) {
+   if ((err = ltc_mp_montgomery_setup(modulus, &mp)) != CRYPT_OK) {
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
 
 
    /* compute mu */
    /* compute mu */
-   if ((err = mp_init(&mu)) != CRYPT_OK) {
+   if ((err = ltc_mp_init(&mu)) != CRYPT_OK) {
        goto LBL_ERR;
        goto LBL_ERR;
    }
    }
-   if ((err = mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
+   if ((err = ltc_mp_montgomery_normalization(mu, modulus)) != CRYPT_OK) {
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
 
 
@@ -1368,10 +1368,10 @@ ltc_ecc_fp_add_point(ecc_point *g, void *modulus, int lock)
 LBL_ERR:
 LBL_ERR:
    LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
    LTC_MUTEX_UNLOCK(&ltc_ecc_fp_lock);
    if (mp != NULL) {
    if (mp != NULL) {
-      mp_montgomery_free(mp);
+      ltc_mp_montgomery_free(mp);
    }
    }
    if (mu != NULL) {
    if (mu != NULL) {
-      mp_clear(mu);
+      ltc_mp_clear(mu);
    }
    }
    return err;
    return err;
 }
 }
@@ -1546,14 +1546,14 @@ int ltc_ecc_fp_restore_state(unsigned char *in, unsigned long inlen)
             goto ERR_OUT;
             goto ERR_OUT;
          }
          }
          fp_cache[i].LUT[x] = p;
          fp_cache[i].LUT[x] = p;
-         if ((err = mp_init_multi(&p->x, &p->y, LTC_NULL)) != CRYPT_OK) {
+         if ((err = ltc_mp_init_multi(&p->x, &p->y, LTC_NULL)) != CRYPT_OK) {
             goto ERR_OUT;
             goto ERR_OUT;
          }
          }
          p->z = NULL;
          p->z = NULL;
          LTC_SET_ASN1(asn1_list, j++, LTC_ASN1_INTEGER, p->x, 1);
          LTC_SET_ASN1(asn1_list, j++, LTC_ASN1_INTEGER, p->x, 1);
          LTC_SET_ASN1(asn1_list, j++, LTC_ASN1_INTEGER, p->y, 1);
          LTC_SET_ASN1(asn1_list, j++, LTC_ASN1_INTEGER, p->y, 1);
       }
       }
-      if((err = mp_init(&fp_cache[i].mu)) != CRYPT_OK) {
+      if((err = ltc_mp_init(&fp_cache[i].mu)) != CRYPT_OK) {
          goto ERR_OUT;
          goto ERR_OUT;
       }
       }
       LTC_SET_ASN1(asn1_list, j++, LTC_ASN1_INTEGER, fp_cache[i].mu, 1);
       LTC_SET_ASN1(asn1_list, j++, LTC_ASN1_INTEGER, fp_cache[i].mu, 1);

+ 7 - 7
src/math/multi.c

@@ -3,7 +3,7 @@
 #include "tomcrypt_private.h"
 #include "tomcrypt_private.h"
 
 
 #ifdef LTC_MPI
 #ifdef LTC_MPI
-int ltc_init_multi(void **a, ...)
+int ltc_mp_init_multi(void **a, ...)
 {
 {
    void    **cur = a;
    void    **cur = a;
    int       np  = 0;
    int       np  = 0;
@@ -11,14 +11,14 @@ int ltc_init_multi(void **a, ...)
 
 
    va_start(args, a);
    va_start(args, a);
    while (cur != NULL) {
    while (cur != NULL) {
-       if (mp_init(cur) != CRYPT_OK) {
+       if (ltc_mp_init(cur) != CRYPT_OK) {
           /* failed */
           /* failed */
           va_list clean_list;
           va_list clean_list;
 
 
           va_start(clean_list, a);
           va_start(clean_list, a);
           cur = a;
           cur = a;
           while (np--) {
           while (np--) {
-              mp_clear(*cur);
+              ltc_mp_clear(*cur);
               cur = va_arg(clean_list, void**);
               cur = va_arg(clean_list, void**);
           }
           }
           va_end(clean_list);
           va_end(clean_list);
@@ -32,20 +32,20 @@ int ltc_init_multi(void **a, ...)
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
-void ltc_deinit_multi(void *a, ...)
+void ltc_mp_deinit_multi(void *a, ...)
 {
 {
    void     *cur = a;
    void     *cur = a;
    va_list   args;
    va_list   args;
 
 
    va_start(args, a);
    va_start(args, a);
    while (cur != NULL) {
    while (cur != NULL) {
-       mp_clear(cur);
+       ltc_mp_clear(cur);
        cur = va_arg(args, void *);
        cur = va_arg(args, void *);
    }
    }
    va_end(args);
    va_end(args);
 }
 }
 
 
-void ltc_cleanup_multi(void **a, ...)
+void ltc_mp_cleanup_multi(void **a, ...)
 {
 {
    void **cur = a;
    void **cur = a;
    va_list args;
    va_list args;
@@ -53,7 +53,7 @@ void ltc_cleanup_multi(void **a, ...)
    va_start(args, a);
    va_start(args, a);
    while (cur != NULL) {
    while (cur != NULL) {
       if (*cur != NULL) {
       if (*cur != NULL) {
-         mp_clear(*cur);
+         ltc_mp_clear(*cur);
          *cur = NULL;
          *cur = NULL;
       }
       }
       cur = va_arg(args, void**);
       cur = va_arg(args, void**);

+ 5 - 5
src/math/radix_to_bin.c

@@ -34,19 +34,19 @@ int radix_to_bin(const void *in, int radix, void *out, unsigned long *len)
    LTC_ARGCHK(in  != NULL);
    LTC_ARGCHK(in  != NULL);
    LTC_ARGCHK(len != NULL);
    LTC_ARGCHK(len != NULL);
 
 
-   if ((err = mp_init(&mpi)) != CRYPT_OK) return err;
-   if ((err = mp_read_radix(mpi, in, radix)) != CRYPT_OK) goto LBL_ERR;
+   if ((err = ltc_mp_init(&mpi)) != CRYPT_OK) return err;
+   if ((err = ltc_mp_read_radix(mpi, in, radix)) != CRYPT_OK) goto LBL_ERR;
 
 
-   if ((l = mp_unsigned_bin_size(mpi)) > *len) {
+   if ((l = ltc_mp_unsigned_bin_size(mpi)) > *len) {
       *len = l;
       *len = l;
       err = CRYPT_BUFFER_OVERFLOW;
       err = CRYPT_BUFFER_OVERFLOW;
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
    *len = l;
    *len = l;
 
 
-   if ((err = mp_to_unsigned_bin(mpi, out)) != CRYPT_OK) goto LBL_ERR;
+   if ((err = ltc_mp_to_unsigned_bin(mpi, out)) != CRYPT_OK) goto LBL_ERR;
 
 
 LBL_ERR:
 LBL_ERR:
-   mp_clear(mpi);
+   ltc_mp_clear(mpi);
    return err;
    return err;
 }
 }

+ 3 - 3
src/math/rand_bn.c

@@ -32,7 +32,7 @@ int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng)
    /* mask bits */
    /* mask bits */
    buf[0] &= mask;
    buf[0] &= mask;
    /* load value */
    /* load value */
-   if ((res = mp_read_unsigned_bin(N, buf, bytes)) != CRYPT_OK) goto cleanup;
+   if ((res = ltc_mp_read_unsigned_bin(N, buf, bytes)) != CRYPT_OK) goto cleanup;
 
 
    res = CRYPT_OK;
    res = CRYPT_OK;
 
 
@@ -54,11 +54,11 @@ int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng)
    LTC_ARGCHK(N != NULL);
    LTC_ARGCHK(N != NULL);
    LTC_ARGCHK(limit != NULL);
    LTC_ARGCHK(limit != NULL);
 
 
-   bits = mp_count_bits(limit);
+   bits = ltc_mp_count_bits(limit);
    do {
    do {
      res = rand_bn_bits(N, bits, prng, wprng);
      res = rand_bn_bits(N, bits, prng, wprng);
      if (res != CRYPT_OK) return res;
      if (res != CRYPT_OK) return res;
-   } while (mp_cmp_d(N, 0) != LTC_MP_GT || mp_cmp(N, limit) != LTC_MP_LT);
+   } while (ltc_mp_cmp_d(N, 0) != LTC_MP_GT || ltc_mp_cmp(N, limit) != LTC_MP_LT);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }

+ 2 - 2
src/math/rand_prime.c

@@ -54,13 +54,13 @@ int rand_prime(void *N, long len, prng_state *prng, int wprng)
       buf[len-1] |= 0x01 | ((type & USE_BBS) ? 0x02 : 0x00);
       buf[len-1] |= 0x01 | ((type & USE_BBS) ? 0x02 : 0x00);
 
 
       /* load value */
       /* load value */
-      if ((err = mp_read_unsigned_bin(N, buf, len)) != CRYPT_OK) {
+      if ((err = ltc_mp_read_unsigned_bin(N, buf, len)) != CRYPT_OK) {
          XFREE(buf);
          XFREE(buf);
          return err;
          return err;
       }
       }
 
 
       /* test */
       /* test */
-      if ((err = mp_prime_is_prime(N, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
+      if ((err = ltc_mp_prime_is_prime(N, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
          XFREE(buf);
          XFREE(buf);
          return err;
          return err;
       }
       }

+ 1 - 6
src/misc/pbes/pbes1.c

@@ -50,11 +50,6 @@ static const pbes_properties s_pbes1_types[] = {
    { s_pkcs_12_wrap,     "sha1",  "3des", 24, 8 },
    { s_pkcs_12_wrap,     "sha1",  "3des", 24, 8 },
 };
 };
 
 
-typedef struct {
-   const pbes_properties *data;
-   const char *oid;
-} oid_to_pbes;
-
 static const oid_to_pbes s_pbes1_list[] = {
 static const oid_to_pbes s_pbes1_list[] = {
    { &s_pbes1_types[0], "1.2.840.113549.1.5.1"    },  /* http://www.oid-info.com/get/1.2.840.113549.1.5.1    pbeWithMD2AndDES-CBC */
    { &s_pbes1_types[0], "1.2.840.113549.1.5.1"    },  /* http://www.oid-info.com/get/1.2.840.113549.1.5.1    pbeWithMD2AndDES-CBC */
    { &s_pbes1_types[1], "1.2.840.113549.1.5.4"    },  /* http://www.oid-info.com/get/1.2.840.113549.1.5.4    pbeWithMD2AndRC2-CBC */
    { &s_pbes1_types[1], "1.2.840.113549.1.5.4"    },  /* http://www.oid-info.com/get/1.2.840.113549.1.5.4    pbeWithMD2AndRC2-CBC */
@@ -109,7 +104,7 @@ int pbes1_extract(const ltc_asn1_list *s, pbes_arg *res)
     * 33:d=1  hl=4 l= 296 prim:   OCTET STRING         :bytes (== encrypted data)
     * 33:d=1  hl=4 l= 296 prim:   OCTET STRING         :bytes (== encrypted data)
     */
     */
    res->salt = s->next->child;
    res->salt = s->next->child;
-   res->iterations = mp_get_int(s->next->child->next->data);
+   res->iterations = ltc_mp_get_int(s->next->child->next->data);
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }

+ 2 - 7
src/misc/pbes/pbes2.c

@@ -39,11 +39,6 @@ static const pbes_properties s_pbes2_default_types[] = {
    { s_pkcs_5_alg2_wrap, "sha1",   "aes",  32, 0 },
    { s_pkcs_5_alg2_wrap, "sha1",   "aes",  32, 0 },
 };
 };
 
 
-typedef struct {
-   const pbes_properties *data;
-   const char* oid;
-} oid_to_pbes;
-
 static const oid_to_pbes s_pbes2_list[] = {
 static const oid_to_pbes s_pbes2_list[] = {
    { &s_pbes2_default_types[0], "1.3.14.3.2.7"            },  /* http://www.oid-info.com/get/1.3.14.3.2.7            desCBC */
    { &s_pbes2_default_types[0], "1.3.14.3.2.7"            },  /* http://www.oid-info.com/get/1.3.14.3.2.7            desCBC */
    { &s_pbes2_default_types[1], "1.2.840.113549.3.2"      },  /* http://www.oid-info.com/get/1.2.840.113549.3.2      rc2CBC */
    { &s_pbes2_default_types[1], "1.2.840.113549.3.2"      },  /* http://www.oid-info.com/get/1.2.840.113549.3.2      rc2CBC */
@@ -134,7 +129,7 @@ int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res)
    liter = lkdf->next->child->next;
    liter = lkdf->next->child->next;
    loptseq = liter->next;
    loptseq = liter->next;
    res->salt = lkdf->next->child;
    res->salt = lkdf->next->child;
-   res->iterations = mp_get_int(liter->data);
+   res->iterations = ltc_mp_get_int(liter->data);
 
 
    /* There's an optional INTEGER keyLength after the iterations, skip that if it's there.
    /* There's an optional INTEGER keyLength after the iterations, skip that if it's there.
     * c.f. RFC 2898 A.2 PBKDF2 */
     * c.f. RFC 2898 A.2 PBKDF2 */
@@ -162,7 +157,7 @@ int pbes2_extract(const ltc_asn1_list *s, pbes_arg *res)
        */
        */
       if (LTC_ASN1_IS_TYPE(lenc->next->child, LTC_ASN1_INTEGER) &&
       if (LTC_ASN1_IS_TYPE(lenc->next->child, LTC_ASN1_INTEGER) &&
           LTC_ASN1_IS_TYPE(lenc->next->child->next, LTC_ASN1_OCTET_STRING)) {
           LTC_ASN1_IS_TYPE(lenc->next->child->next, LTC_ASN1_OCTET_STRING)) {
-         klen = mp_get_int(lenc->next->child->data);
+         klen = ltc_mp_get_int(lenc->next->child->data);
          res->iv   = lenc->next->child->next;
          res->iv   = lenc->next->child->next;
          /*
          /*
           * Effective Key Bits         Encoding
           * Effective Key Bits         Encoding

+ 20 - 20
src/misc/pem/pem_ssh.c

@@ -93,7 +93,7 @@ static int s_ssh_decode_ecdsa(const unsigned char *in, unsigned long *inlen, ltc
                                      LTC_SSHDATA_STRING, groupname, &groupnamelen,
                                      LTC_SSHDATA_STRING, groupname, &groupnamelen,
                                      LTC_SSHDATA_STRING, buf0, &buf0len,
                                      LTC_SSHDATA_STRING, buf0, &buf0len,
                                      LTC_SSHDATA_STRING, buf1, &buf1len,
                                      LTC_SSHDATA_STRING, buf1, &buf1len,
-                                     LTC_SSHDATA_EOL,    NULL);
+                                     LTC_SSHDATA_EOL,    LTC_NULL);
    if (err == CRYPT_OK) {
    if (err == CRYPT_OK) {
       key = buf1;
       key = buf1;
       keylen = buf1len;
       keylen = buf1len;
@@ -137,7 +137,7 @@ static int s_ssh_decode_ed25519(const unsigned char *in, unsigned long *inlen, l
 
 
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                         LTC_SSHDATA_STRING, pubkey, &pubkeylen,
                                         LTC_SSHDATA_STRING, pubkey, &pubkeylen,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
 
 
@@ -155,7 +155,7 @@ static int s_ssh_decode_ed25519(const unsigned char *in, unsigned long *inlen, l
 
 
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                         LTC_SSHDATA_STRING, privkey, &privkeylen,
                                         LTC_SSHDATA_STRING, privkey, &privkeylen,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
    if ((err = ed25519_import_raw(privkey, privkeylen, PK_PRIVATE, &key->u.ed25519)) != CRYPT_OK) {
    if ((err = ed25519_import_raw(privkey, privkeylen, PK_PRIVATE, &key->u.ed25519)) != CRYPT_OK) {
@@ -195,10 +195,10 @@ static int s_ssh_decode_dsa(const unsigned char *in, unsigned long *inlen, ltc_p
                                         LTC_SSHDATA_MPINT, key->u.dsa.q,
                                         LTC_SSHDATA_MPINT, key->u.dsa.q,
                                         LTC_SSHDATA_MPINT, key->u.dsa.g,
                                         LTC_SSHDATA_MPINT, key->u.dsa.g,
                                         LTC_SSHDATA_MPINT, key->u.dsa.y,
                                         LTC_SSHDATA_MPINT, key->u.dsa.y,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,   LTC_NULL)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
-   key->u.dsa.qord = mp_unsigned_bin_size(key->u.dsa.q);
+   key->u.dsa.qord = ltc_mp_unsigned_bin_size(key->u.dsa.q);
    if ((err = dsa_int_validate_pqg(&key->u.dsa, &stat)) != CRYPT_OK) {
    if ((err = dsa_int_validate_pqg(&key->u.dsa, &stat)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
@@ -219,7 +219,7 @@ static int s_ssh_decode_dsa(const unsigned char *in, unsigned long *inlen, ltc_p
 
 
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                         LTC_SSHDATA_MPINT, key->u.dsa.x,
                                         LTC_SSHDATA_MPINT, key->u.dsa.x,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,   LTC_NULL)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
 
 
@@ -262,7 +262,7 @@ static int s_ssh_decode_rsa(const unsigned char *in, unsigned long *inlen, ltc_p
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                         LTC_SSHDATA_MPINT, key->u.rsa.N,
                                         LTC_SSHDATA_MPINT, key->u.rsa.N,
                                         LTC_SSHDATA_MPINT, key->u.rsa.e,
                                         LTC_SSHDATA_MPINT, key->u.rsa.e,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,   LTC_NULL)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
 
 
@@ -281,7 +281,7 @@ static int s_ssh_decode_rsa(const unsigned char *in, unsigned long *inlen, ltc_p
       goto cleanup;
       goto cleanup;
    }
    }
 
 
-   if ((err = mp_init_multi(&tmp1, &tmp2, NULL)) != CRYPT_OK) {
+   if ((err = ltc_mp_init_multi(&tmp1, &tmp2, LTC_NULL)) != CRYPT_OK) {
       goto cleanup;
       goto cleanup;
    }
    }
 
 
@@ -290,20 +290,20 @@ static int s_ssh_decode_rsa(const unsigned char *in, unsigned long *inlen, ltc_p
                                         LTC_SSHDATA_MPINT, key->u.rsa.qP,
                                         LTC_SSHDATA_MPINT, key->u.rsa.qP,
                                         LTC_SSHDATA_MPINT, key->u.rsa.p,
                                         LTC_SSHDATA_MPINT, key->u.rsa.p,
                                         LTC_SSHDATA_MPINT, key->u.rsa.q,
                                         LTC_SSHDATA_MPINT, key->u.rsa.q,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,   LTC_NULL)) != CRYPT_OK) {
       goto cleanup_tmps;
       goto cleanup_tmps;
    }
    }
 
 
-   if ((err = mp_sub_d(key->u.rsa.p, 1, tmp1)) != CRYPT_OK)                   { goto cleanup_tmps; } /* tmp1 = q-1 */
-   if ((err = mp_sub_d(key->u.rsa.q, 1, tmp2)) != CRYPT_OK)                   { goto cleanup_tmps; } /* tmp2 = p-1 */
-   if ((err = mp_mod(key->u.rsa.d, tmp1, key->u.rsa.dP)) != CRYPT_OK)         { goto cleanup_tmps; } /* dP = d mod p-1 */
-   if ((err = mp_mod(key->u.rsa.d, tmp2, key->u.rsa.dQ)) != CRYPT_OK)         { goto cleanup_tmps; } /* dQ = d mod q-1 */
+   if ((err = ltc_mp_sub_d(key->u.rsa.p, 1, tmp1)) != CRYPT_OK)                   { goto cleanup_tmps; } /* tmp1 = q-1 */
+   if ((err = ltc_mp_sub_d(key->u.rsa.q, 1, tmp2)) != CRYPT_OK)                   { goto cleanup_tmps; } /* tmp2 = p-1 */
+   if ((err = ltc_mp_mod(key->u.rsa.d, tmp1, key->u.rsa.dP)) != CRYPT_OK)         { goto cleanup_tmps; } /* dP = d mod p-1 */
+   if ((err = ltc_mp_mod(key->u.rsa.d, tmp2, key->u.rsa.dQ)) != CRYPT_OK)         { goto cleanup_tmps; } /* dQ = d mod q-1 */
 
 
    key->id = LTC_PKA_RSA;
    key->id = LTC_PKA_RSA;
    key->u.rsa.type = PK_PRIVATE;
    key->u.rsa.type = PK_PRIVATE;
 
 
 cleanup_tmps:
 cleanup_tmps:
-   mp_clear_multi(tmp2, tmp1, NULL);
+   ltc_mp_deinit_multi(tmp2, tmp1, LTC_NULL);
 cleanup:
 cleanup:
    if (err != CRYPT_OK) {
    if (err != CRYPT_OK) {
       rsa_free(&key->u.rsa);
       rsa_free(&key->u.rsa);
@@ -377,7 +377,7 @@ static int s_decode_key(const unsigned char *in, unsigned long *inlen, ltc_pka_k
       if ((err = ssh_decode_sequence_multi(p, &cur_len,
       if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                            LTC_SSHDATA_UINT32, &check1,
                                            LTC_SSHDATA_UINT32, &check1,
                                            LTC_SSHDATA_UINT32, &check2,
                                            LTC_SSHDATA_UINT32, &check2,
-                                           LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                           LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
          return err;
          return err;
       }
       }
       if (check1 != check2) {
       if (check1 != check2) {
@@ -390,7 +390,7 @@ static int s_decode_key(const unsigned char *in, unsigned long *inlen, ltc_pka_k
    }
    }
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
    if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                         LTC_SSHDATA_STRING, pka, &pkalen,
                                         LTC_SSHDATA_STRING, pka, &pkalen,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
@@ -427,7 +427,7 @@ static int s_decode_key(const unsigned char *in, unsigned long *inlen, ltc_pka_k
       }
       }
       if ((err = ssh_decode_sequence_multi(p, &cur_len,
       if ((err = ssh_decode_sequence_multi(p, &cur_len,
                                            LTC_SSHDATA_STRING, c, &commentlen,
                                            LTC_SSHDATA_STRING, c, &commentlen,
-                                           LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                           LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
          return err;
          return err;
       }
       }
       if (commentlen == 0) {
       if (commentlen == 0) {
@@ -651,7 +651,7 @@ static int s_decode_header(unsigned char *in, unsigned long *inlen, struct kdf_o
                                         LTC_SSHDATA_STRING, kdfoptions, &kdfoptionslen,
                                         LTC_SSHDATA_STRING, kdfoptions, &kdfoptionslen,
                                         LTC_SSHDATA_UINT32, &num_keys,
                                         LTC_SSHDATA_UINT32, &num_keys,
                                         LTC_SSHDATA_STRING, pubkey1, &pubkey1len,
                                         LTC_SSHDATA_STRING, pubkey1, &pubkey1len,
-                                        LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                        LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
    if (num_keys != 1) {
    if (num_keys != 1) {
@@ -680,7 +680,7 @@ static int s_decode_header(unsigned char *in, unsigned long *inlen, struct kdf_o
       if ((err = ssh_decode_sequence_multi(kdfoptions, &len,
       if ((err = ssh_decode_sequence_multi(kdfoptions, &len,
                                            LTC_SSHDATA_STRING, opts->salt, &opts->saltlen,
                                            LTC_SSHDATA_STRING, opts->salt, &opts->saltlen,
                                            LTC_SSHDATA_UINT32, &opts->num_rounds,
                                            LTC_SSHDATA_UINT32, &opts->num_rounds,
-                                           LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                           LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
          return err;
          return err;
       }
       }
       if (len != kdfoptionslen) {
       if (len != kdfoptionslen) {
@@ -754,7 +754,7 @@ retry:
 
 
       if ((err = ssh_decode_sequence_multi(p, &w,
       if ((err = ssh_decode_sequence_multi(p, &w,
                                            LTC_SSHDATA_STRING, privkey, &privkey_len,
                                            LTC_SSHDATA_STRING, privkey, &privkey_len,
-                                           LTC_SSHDATA_EOL,    NULL)) != CRYPT_OK) {
+                                           LTC_SSHDATA_EOL,    LTC_NULL)) != CRYPT_OK) {
          goto cleanup;
          goto cleanup;
       }
       }
 
 

+ 2 - 2
src/misc/ssh/ssh_decode_sequence_multi.c

@@ -135,13 +135,13 @@ int ssh_decode_sequence_multi(const unsigned char *in, unsigned long *inlen, ...
             break;
             break;
          case LTC_SSHDATA_MPINT:
          case LTC_SSHDATA_MPINT:
             if (size == 0) {
             if (size == 0) {
-               if ((err = mp_set(vdata, 0)) != CRYPT_OK)                                                { goto error; }
+               if ((err = ltc_mp_set(vdata, 0)) != CRYPT_OK)                                                { goto error; }
             } else if ((in[0] & 0x80) != 0) {
             } else if ((in[0] & 0x80) != 0) {
                /* Negative number - not supported */
                /* Negative number - not supported */
                err = CRYPT_INVALID_PACKET;
                err = CRYPT_INVALID_PACKET;
                goto error;
                goto error;
             } else {
             } else {
-               if ((err = mp_read_unsigned_bin(vdata, in, size)) != CRYPT_OK)                           { goto error; }
+               if ((err = ltc_mp_read_unsigned_bin(vdata, in, size)) != CRYPT_OK)                           { goto error; }
             }
             }
             in += size;
             in += size;
             break;
             break;

+ 7 - 7
src/misc/ssh/ssh_encode_sequence_multi.c

@@ -59,9 +59,9 @@ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
             vdata = va_arg(args, void*);
             vdata = va_arg(args, void*);
             /* Calculate size */
             /* Calculate size */
             size += 4;
             size += 4;
-            if (mp_iszero(vdata) != LTC_MP_YES) {
-               size += mp_unsigned_bin_size(vdata);
-               if ((mp_count_bits(vdata) & 7) == 0) size++; /* Zero padding if high bit set */
+            if (ltc_mp_iszero(vdata) != LTC_MP_YES) {
+               size += ltc_mp_unsigned_bin_size(vdata);
+               if ((ltc_mp_count_bits(vdata) & 7) == 0) size++; /* Zero padding if high bit set */
             }
             }
             break;
             break;
 
 
@@ -119,12 +119,12 @@ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
             break;
             break;
          case LTC_SSHDATA_MPINT:
          case LTC_SSHDATA_MPINT:
             vdata = va_arg(args, void*);
             vdata = va_arg(args, void*);
-            if (mp_iszero(vdata) == LTC_MP_YES) {
+            if (ltc_mp_iszero(vdata) == LTC_MP_YES) {
                STORE32H(0, out);
                STORE32H(0, out);
                out += 4;
                out += 4;
             } else {
             } else {
-               size = mp_unsigned_bin_size(vdata);
-               if ((mp_count_bits(vdata) & 7) == 0) {
+               size = ltc_mp_unsigned_bin_size(vdata);
+               if ((ltc_mp_count_bits(vdata) & 7) == 0) {
                   /* Zero padding if high bit set */
                   /* Zero padding if high bit set */
                   STORE32H(size+1, out);
                   STORE32H(size+1, out);
                   out += 4;
                   out += 4;
@@ -133,7 +133,7 @@ int ssh_encode_sequence_multi(unsigned char *out, unsigned long *outlen, ...)
                   STORE32H(size, out);
                   STORE32H(size, out);
                   out += 4;
                   out += 4;
                }
                }
-               if (mp_to_unsigned_bin(vdata, out) != CRYPT_OK) {
+               if (ltc_mp_to_unsigned_bin(vdata, out) != CRYPT_OK) {
                   err = CRYPT_ERROR;
                   err = CRYPT_ERROR;
                   goto error;
                   goto error;
                }
                }

+ 3 - 0
src/modes/cfb/cfb_decrypt.c

@@ -9,6 +9,8 @@
 
 
 #ifdef LTC_CFB_MODE
 #ifdef LTC_CFB_MODE
 
 
+#ifndef LTC_CFB_SHIFT1LEFT
+#define LTC_CFB_SHIFT1LEFT
 static LTC_INLINE void s_shift1left_64(unsigned char *b, unsigned char v)
 static LTC_INLINE void s_shift1left_64(unsigned char *b, unsigned char v)
 {
 {
    ulong64 bval;
    ulong64 bval;
@@ -30,6 +32,7 @@ static LTC_INLINE void s_shift1left_128(unsigned char *b, unsigned char v)
    STORE64H(bval[0], b);
    STORE64H(bval[0], b);
    STORE64H(bval[1], b + 8);
    STORE64H(bval[1], b + 8);
 }
 }
+#endif /* LTC_CFB_SHIFT1LEFT */
 
 
 /**
 /**
    CFB decrypt
    CFB decrypt

+ 3 - 0
src/modes/cfb/cfb_encrypt.c

@@ -9,6 +9,8 @@
 
 
 #ifdef LTC_CFB_MODE
 #ifdef LTC_CFB_MODE
 
 
+#ifndef LTC_CFB_SHIFT1LEFT
+#define LTC_CFB_SHIFT1LEFT
 static LTC_INLINE void s_shift1left_64(unsigned char *b, unsigned char v)
 static LTC_INLINE void s_shift1left_64(unsigned char *b, unsigned char v)
 {
 {
    ulong64 bval;
    ulong64 bval;
@@ -30,6 +32,7 @@ static LTC_INLINE void s_shift1left_128(unsigned char *b, unsigned char v)
    STORE64H(bval[0], b);
    STORE64H(bval[0], b);
    STORE64H(bval[1], b + 8);
    STORE64H(bval[1], b + 8);
 }
 }
+#endif /* LTC_CFB_SHIFT1LEFT */
 
 
 /**
 /**
   CFB encrypt
   CFB encrypt

+ 1 - 1
src/pk/asn1/der/general/der_decode_asn1_identifier.c

@@ -117,7 +117,7 @@ int der_decode_asn1_identifier(const unsigned char *in, unsigned long *inlen, lt
       }
       }
    }
    }
 
 
-   return CRYPT_OK;
+   return err;
 }
 }
 
 
 #endif
 #endif

+ 7 - 1
src/pk/asn1/der/generalizedtime/der_decode_generalizedtime.c

@@ -10,7 +10,9 @@
 
 
 #ifdef LTC_DER
 #ifdef LTC_DER
 
 
-static int s_char_to_int(unsigned char x)
+#ifndef LTC_DER_CHAR_TO_INT
+#define LTC_DER_CHAR_TO_INT
+static LTC_INLINE int s_char_to_int(unsigned char x)
 {
 {
    switch (x)  {
    switch (x)  {
       case '0': return 0;
       case '0': return 0;
@@ -26,6 +28,7 @@ static int s_char_to_int(unsigned char x)
       default:  return 100;
       default:  return 100;
    }
    }
 }
 }
+#endif
 
 
 #define DECODE_V(y, max) do {\
 #define DECODE_V(y, max) do {\
    y  = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
    y  = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
@@ -132,4 +135,7 @@ YYYYMMDDhhmmss.fs-hh'mm'
     return CRYPT_INVALID_PACKET;
     return CRYPT_INVALID_PACKET;
 }
 }
 
 
+#undef DECODE_V
+#undef DECODE_V4
+
 #endif
 #endif

+ 4 - 2
src/pk/asn1/der/generalizedtime/der_encode_generalizedtime.c

@@ -10,8 +10,6 @@
 
 
 #ifdef LTC_DER
 #ifdef LTC_DER
 
 
-static const char * const baseten = "0123456789";
-
 #define STORE_V(y) do {\
 #define STORE_V(y) do {\
     out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
     out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
     out[x++] = der_ia5_char_encode(baseten[y % 10]); \
     out[x++] = der_ia5_char_encode(baseten[y % 10]); \
@@ -34,6 +32,7 @@ static const char * const baseten = "0123456789";
 int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
 int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
                                      unsigned char       *out, unsigned long *outlen)
                                      unsigned char       *out, unsigned long *outlen)
 {
 {
+    const char * const baseten = "0123456789";
     unsigned long x, tmplen;
     unsigned long x, tmplen;
     int           err;
     int           err;
 
 
@@ -95,4 +94,7 @@ int der_encode_generalizedtime(const ltc_generalizedtime *gtime,
     return CRYPT_OK;
     return CRYPT_OK;
 }
 }
 
 
+#undef STORE_V
+#undef STORE_V4
+
 #endif
 #endif

+ 5 - 5
src/pk/asn1/der/integer/der_decode_integer.c

@@ -43,22 +43,22 @@ int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num)
    }
    }
    x += inlen;
    x += inlen;
 
 
-   if ((err = mp_read_unsigned_bin(num, (unsigned char *)in + x, y)) != CRYPT_OK) {
+   if ((err = ltc_mp_read_unsigned_bin(num, (unsigned char *)in + x, y)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
    /* see if it's negative */
    /* see if it's negative */
    if (in[x] & 0x80) {
    if (in[x] & 0x80) {
       void *tmp;
       void *tmp;
-      if (mp_init(&tmp) != CRYPT_OK) {
+      if (ltc_mp_init(&tmp) != CRYPT_OK) {
          return CRYPT_MEM;
          return CRYPT_MEM;
       }
       }
 
 
-      if (mp_2expt(tmp, mp_count_bits(num)) != CRYPT_OK || mp_sub(num, tmp, num) != CRYPT_OK) {
-         mp_clear(tmp);
+      if (ltc_mp_2expt(tmp, ltc_mp_count_bits(num)) != CRYPT_OK || ltc_mp_sub(num, tmp, num) != CRYPT_OK) {
+         ltc_mp_clear(tmp);
          return CRYPT_MEM;
          return CRYPT_MEM;
       }
       }
-      mp_clear(tmp);
+      ltc_mp_clear(tmp);
    }
    }
 
 
    return CRYPT_OK;
    return CRYPT_OK;

+ 16 - 16
src/pk/asn1/der/integer/der_encode_integer.c

@@ -37,22 +37,22 @@ int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
       return CRYPT_BUFFER_OVERFLOW;
       return CRYPT_BUFFER_OVERFLOW;
    }
    }
 
 
-   if (mp_cmp_d(num, 0) != LTC_MP_LT) {
+   if (ltc_mp_cmp_d(num, 0) != LTC_MP_LT) {
       /* we only need a leading zero if the msb of the first byte is one */
       /* we only need a leading zero if the msb of the first byte is one */
-      if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == LTC_MP_YES) {
+      if ((ltc_mp_count_bits(num) & 7) == 0 || ltc_mp_iszero(num) == LTC_MP_YES) {
          leading_zero = 1;
          leading_zero = 1;
       } else {
       } else {
          leading_zero = 0;
          leading_zero = 0;
       }
       }
 
 
       /* get length of num in bytes (plus 1 since we force the msbyte to zero) */
       /* get length of num in bytes (plus 1 since we force the msbyte to zero) */
-      y = mp_unsigned_bin_size(num) + leading_zero;
+      y = ltc_mp_unsigned_bin_size(num) + leading_zero;
    } else {
    } else {
       leading_zero = 0;
       leading_zero = 0;
-      y            = mp_count_bits(num);
+      y            = ltc_mp_count_bits(num);
       y            = y + (8 - (y & 7));
       y            = y + (8 - (y & 7));
       y            = y >> 3;
       y            = y >> 3;
-      if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --y;
+      if (((ltc_mp_cnt_lsb(num)+1)==ltc_mp_count_bits(num)) && ((ltc_mp_count_bits(num)&7)==0)) --y;
    }
    }
 
 
    /* now store initial data */
    /* now store initial data */
@@ -69,32 +69,32 @@ int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
    }
    }
 
 
    /* if it's not zero store it as big endian */
    /* if it's not zero store it as big endian */
-   if (mp_cmp_d(num, 0) == LTC_MP_GT) {
+   if (ltc_mp_cmp_d(num, 0) == LTC_MP_GT) {
       /* now store the mpint */
       /* now store the mpint */
-      if ((err = mp_to_unsigned_bin(num, out)) != CRYPT_OK) {
+      if ((err = ltc_mp_to_unsigned_bin(num, out)) != CRYPT_OK) {
           return err;
           return err;
       }
       }
-   } else if (mp_iszero(num) != LTC_MP_YES) {
+   } else if (ltc_mp_iszero(num) != LTC_MP_YES) {
       void *tmp;
       void *tmp;
 
 
       /* negative */
       /* negative */
-      if (mp_init(&tmp) != CRYPT_OK) {
+      if (ltc_mp_init(&tmp) != CRYPT_OK) {
          return CRYPT_MEM;
          return CRYPT_MEM;
       }
       }
 
 
       /* 2^roundup and subtract */
       /* 2^roundup and subtract */
-      y = mp_count_bits(num);
+      y = ltc_mp_count_bits(num);
       y = y + (8 - (y & 7));
       y = y + (8 - (y & 7));
-      if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) y -= 8;
-      if (mp_2expt(tmp, y) != CRYPT_OK || mp_add(tmp, num, tmp) != CRYPT_OK) {
-         mp_clear(tmp);
+      if (((ltc_mp_cnt_lsb(num)+1)==ltc_mp_count_bits(num)) && ((ltc_mp_count_bits(num)&7)==0)) y -= 8;
+      if (ltc_mp_2expt(tmp, y) != CRYPT_OK || ltc_mp_add(tmp, num, tmp) != CRYPT_OK) {
+         ltc_mp_clear(tmp);
          return CRYPT_MEM;
          return CRYPT_MEM;
       }
       }
-      if ((err = mp_to_unsigned_bin(tmp, out)) != CRYPT_OK) {
-         mp_clear(tmp);
+      if ((err = ltc_mp_to_unsigned_bin(tmp, out)) != CRYPT_OK) {
+         ltc_mp_clear(tmp);
          return err;
          return err;
       }
       }
-      mp_clear(tmp);
+      ltc_mp_clear(tmp);
    }
    }
 
 
    /* we good */
    /* we good */

+ 5 - 5
src/pk/asn1/der/integer/der_length_integer.c

@@ -23,24 +23,24 @@ int der_length_integer(void *num, unsigned long *outlen)
    LTC_ARGCHK(num     != NULL);
    LTC_ARGCHK(num     != NULL);
    LTC_ARGCHK(outlen  != NULL);
    LTC_ARGCHK(outlen  != NULL);
 
 
-   if (mp_cmp_d(num, 0) != LTC_MP_LT) {
+   if (ltc_mp_cmp_d(num, 0) != LTC_MP_LT) {
       /* positive */
       /* positive */
 
 
       /* we only need a leading zero if the msb of the first byte is one */
       /* we only need a leading zero if the msb of the first byte is one */
-      if ((mp_count_bits(num) & 7) == 0 || mp_iszero(num) == LTC_MP_YES) {
+      if ((ltc_mp_count_bits(num) & 7) == 0 || ltc_mp_iszero(num) == LTC_MP_YES) {
          leading_zero = 1;
          leading_zero = 1;
       } else {
       } else {
          leading_zero = 0;
          leading_zero = 0;
       }
       }
 
 
       /* size for bignum */
       /* size for bignum */
-      len = leading_zero + mp_unsigned_bin_size(num);
+      len = leading_zero + ltc_mp_unsigned_bin_size(num);
    } else {
    } else {
       /* it's negative */
       /* it's negative */
       /* find power of 2 that is a multiple of eight and greater than count bits */
       /* find power of 2 that is a multiple of eight and greater than count bits */
-      z = mp_count_bits(num);
+      z = ltc_mp_count_bits(num);
       z = z + (8 - (z & 7));
       z = z + (8 - (z & 7));
-      if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) --z;
+      if (((ltc_mp_cnt_lsb(num)+1)==ltc_mp_count_bits(num)) && ((ltc_mp_count_bits(num)&7)==0)) --z;
       len = z >> 3;
       len = z >> 3;
    }
    }
 
 

+ 1 - 1
src/pk/asn1/der/sequence/der_decode_sequence_flexi.c

@@ -149,7 +149,7 @@ static int s_der_decode_sequence_flexi(const unsigned char *in, unsigned long *i
 
 
              /* init field */
              /* init field */
              l->size = 1;
              l->size = 1;
-             if ((err = mp_init(&l->data)) != CRYPT_OK) {
+             if ((err = ltc_mp_init(&l->data)) != CRYPT_OK) {
                  goto error;
                  goto error;
              }
              }
 
 

+ 1 - 1
src/pk/asn1/der/sequence/der_sequence_free.c

@@ -39,7 +39,7 @@ void der_sequence_free(ltc_asn1_list *in)
 
 
       switch (in->type) {
       switch (in->type) {
          case LTC_ASN1_SETOF: break;
          case LTC_ASN1_SETOF: break;
-         case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); } break;
+         case LTC_ASN1_INTEGER : if (in->data != NULL) { ltc_mp_clear(in->data); } break;
          default               : if (in->data != NULL) { XFREE(in->data);    }
          default               : if (in->data != NULL) { XFREE(in->data);    }
       }
       }
 
 

+ 2 - 1
src/pk/asn1/der/set/der_encode_set.c

@@ -15,7 +15,7 @@ static int s_ltc_to_asn1(ltc_asn1_type v)
    return der_asn1_type_to_identifier_map[v];
    return der_asn1_type_to_identifier_map[v];
 }
 }
 
 
-
+#define s_qsort_helper s_set_qsort_helper
 static int s_qsort_helper(const void *a, const void *b)
 static int s_qsort_helper(const void *a, const void *b)
 {
 {
    ltc_asn1_list *A = (ltc_asn1_list *)a, *B = (ltc_asn1_list *)b;
    ltc_asn1_list *A = (ltc_asn1_list *)a, *B = (ltc_asn1_list *)b;
@@ -70,5 +70,6 @@ int der_encode_set(const ltc_asn1_list *list, unsigned long inlen,
    return err;
    return err;
 }
 }
 
 
+#undef s_qsort_helper
 
 
 #endif
 #endif

+ 3 - 0
src/pk/asn1/der/set/der_encode_setof.c

@@ -14,6 +14,7 @@ struct edge {
    unsigned long  size;
    unsigned long  size;
 };
 };
 
 
+#define s_qsort_helper s_setof_qsort_helper
 static int s_qsort_helper(const void *a, const void *b)
 static int s_qsort_helper(const void *a, const void *b)
 {
 {
    struct edge   *A = (struct edge *)a, *B = (struct edge *)b;
    struct edge   *A = (struct edge *)a, *B = (struct edge *)b;
@@ -148,4 +149,6 @@ int der_encode_setof(const ltc_asn1_list *list, unsigned long inlen,
    return CRYPT_OK;
    return CRYPT_OK;
 }
 }
 
 
+#undef s_qsort_helper
+
 #endif
 #endif

+ 6 - 1
src/pk/asn1/der/utctime/der_decode_utctime.c

@@ -9,7 +9,9 @@
 
 
 #ifdef LTC_DER
 #ifdef LTC_DER
 
 
-static int s_char_to_int(unsigned char x)
+#ifndef LTC_DER_CHAR_TO_INT
+#define LTC_DER_CHAR_TO_INT
+static LTC_INLINE int s_char_to_int(unsigned char x)
 {
 {
    switch (x)  {
    switch (x)  {
       case '0': return 0;
       case '0': return 0;
@@ -25,6 +27,7 @@ static int s_char_to_int(unsigned char x)
       default:  return 100;
       default:  return 100;
    }
    }
 }
 }
+#endif
 
 
 #define DECODE_V(y, max) \
 #define DECODE_V(y, max) \
    y  = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
    y  = s_char_to_int(buf[x])*10 + s_char_to_int(buf[x+1]); \
@@ -113,4 +116,6 @@ YYMMDDhhmmss-hh'mm'
     return CRYPT_INVALID_PACKET;
     return CRYPT_INVALID_PACKET;
 }
 }
 
 
+#undef DECODE_V
+
 #endif
 #endif

+ 3 - 2
src/pk/asn1/der/utctime/der_encode_utctime.c

@@ -9,8 +9,6 @@
 
 
 #ifdef LTC_DER
 #ifdef LTC_DER
 
 
-static const char * const baseten = "0123456789";
-
 #define STORE_V(y) \
 #define STORE_V(y) \
     out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
     out[x++] = der_ia5_char_encode(baseten[(y/10) % 10]); \
     out[x++] = der_ia5_char_encode(baseten[y % 10]);
     out[x++] = der_ia5_char_encode(baseten[y % 10]);
@@ -25,6 +23,7 @@ static const char * const baseten = "0123456789";
 int der_encode_utctime(const ltc_utctime   *utctime,
 int der_encode_utctime(const ltc_utctime   *utctime,
                              unsigned char *out,   unsigned long *outlen)
                              unsigned char *out,   unsigned long *outlen)
 {
 {
+    const char * const baseten = "0123456789";
     unsigned long x, tmplen;
     unsigned long x, tmplen;
     int           err;
     int           err;
 
 
@@ -68,4 +67,6 @@ int der_encode_utctime(const ltc_utctime   *utctime,
     return CRYPT_OK;
     return CRYPT_OK;
 }
 }
 
 
+#undef STORE_V
+
 #endif
 #endif

+ 1 - 1
src/pk/asn1/pkcs8/pkcs8_get.c

@@ -35,7 +35,7 @@ int pkcs8_get_children(const ltc_asn1_list *decoded_list, enum ltc_oid_id *pka,
           * we get an 'input too long' error but the rest is already decoded and can be
           * we get an 'input too long' error but the rest is already decoded and can be
           * handled the same as for version 0
           * handled the same as for version 0
           */
           */
-         if (mp_cmp_d(version->data, 0) != LTC_MP_EQ && mp_cmp_d(version->data, 1) != LTC_MP_EQ) {
+         if (ltc_mp_cmp_d(version->data, 0) != LTC_MP_EQ && ltc_mp_cmp_d(version->data, 1) != LTC_MP_EQ) {
             return CRYPT_INVALID_PACKET;
             return CRYPT_INVALID_PACKET;
          }
          }
          break;
          break;

+ 2 - 2
src/pk/dh/dh.c

@@ -221,7 +221,7 @@ const ltc_dh_set_type ltc_dh_sets[] = {
 int dh_get_groupsize(const dh_key *key)
 int dh_get_groupsize(const dh_key *key)
 {
 {
    if (key == NULL) return 0;
    if (key == NULL) return 0;
-   return mp_unsigned_bin_size(key->prime);
+   return ltc_mp_unsigned_bin_size(key->prime);
 }
 }
 
 
 /**
 /**
@@ -233,7 +233,7 @@ int dh_init(dh_key *key)
 {
 {
    int err;
    int err;
    LTC_ARGCHK(key != NULL);
    LTC_ARGCHK(key != NULL);
-   if ((err = mp_init_multi(&key->x, &key->y, &key->base, &key->prime, LTC_NULL)) != CRYPT_OK) {
+   if ((err = ltc_mp_init_multi(&key->x, &key->y, &key->base, &key->prime, LTC_NULL)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
    return CRYPT_OK;
    return CRYPT_OK;

+ 6 - 6
src/pk/dh/dh_check_pubkey.c

@@ -18,23 +18,23 @@ int dh_check_pubkey(const dh_key *key)
 
 
    LTC_ARGCHK(key != NULL);
    LTC_ARGCHK(key != NULL);
 
 
-   if ((err = mp_init(&p_minus1)) != CRYPT_OK) {
+   if ((err = ltc_mp_init(&p_minus1)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
    /* avoid: y <= 1 OR y >= p-1 */
    /* avoid: y <= 1 OR y >= p-1 */
-   if ((err = mp_sub_d(key->prime, 1, p_minus1)) != CRYPT_OK) {
+   if ((err = ltc_mp_sub_d(key->prime, 1, p_minus1)) != CRYPT_OK) {
       goto error;
       goto error;
    }
    }
-   if (mp_cmp(key->y, p_minus1) != LTC_MP_LT || mp_cmp_d(key->y, 1) != LTC_MP_GT) {
+   if (ltc_mp_cmp(key->y, p_minus1) != LTC_MP_LT || ltc_mp_cmp_d(key->y, 1) != LTC_MP_GT) {
       err = CRYPT_INVALID_ARG;
       err = CRYPT_INVALID_ARG;
       goto error;
       goto error;
    }
    }
 
 
    /* public key must have more than one bit set */
    /* public key must have more than one bit set */
-   digit_count = mp_get_digit_count(key->y);
+   digit_count = ltc_mp_get_digit_count(key->y);
    for (i = 0; i < digit_count && bits_set < 2; i++) {
    for (i = 0; i < digit_count && bits_set < 2; i++) {
-      digit = mp_get_digit(key->y, i);
+      digit = ltc_mp_get_digit(key->y, i);
       while (digit > 0) {
       while (digit > 0) {
          if (digit & 1) bits_set++;
          if (digit & 1) bits_set++;
          digit >>= 1;
          digit >>= 1;
@@ -48,7 +48,7 @@ int dh_check_pubkey(const dh_key *key)
    }
    }
 
 
 error:
 error:
-   mp_clear(p_minus1);
+   ltc_mp_clear(p_minus1);
    return err;
    return err;
 }
 }
 
 

+ 2 - 2
src/pk/dh/dh_export_key.c

@@ -23,7 +23,7 @@ int dh_export_key(void *out, unsigned long *outlen, int type, const dh_key *key)
    LTC_ARGCHK(key    != NULL);
    LTC_ARGCHK(key    != NULL);
 
 
    k = (type == PK_PRIVATE) ? key->x : key->y;
    k = (type == PK_PRIVATE) ? key->x : key->y;
-   len = mp_unsigned_bin_size(k);
+   len = ltc_mp_unsigned_bin_size(k);
 
 
    if (*outlen < len) {
    if (*outlen < len) {
       *outlen = len;
       *outlen = len;
@@ -31,7 +31,7 @@ int dh_export_key(void *out, unsigned long *outlen, int type, const dh_key *key)
    }
    }
    *outlen = len;
    *outlen = len;
 
 
-   return mp_to_unsigned_bin(k, out);
+   return ltc_mp_to_unsigned_bin(k, out);
 }
 }
 
 
 #endif /* LTC_MDH */
 #endif /* LTC_MDH */

+ 1 - 1
src/pk/dh/dh_free.c

@@ -12,7 +12,7 @@
 void dh_free(dh_key *key)
 void dh_free(dh_key *key)
 {
 {
    LTC_ARGCHKVD(key != NULL);
    LTC_ARGCHKVD(key != NULL);
-   mp_cleanup_multi(&key->prime, &key->base, &key->y, &key->x, LTC_NULL);
+   ltc_mp_cleanup_multi(&key->prime, &key->base, &key->y, &key->x, LTC_NULL);
 }
 }
 
 
 #endif /* LTC_MDH */
 #endif /* LTC_MDH */

+ 3 - 3
src/pk/dh/dh_generate_key.c

@@ -48,7 +48,7 @@ int dh_generate_key(prng_state *prng, int wprng, dh_key *key)
       return err;
       return err;
    }
    }
 
 
-   keysize = s_dh_groupsize_to_keysize(mp_unsigned_bin_size(key->prime));
+   keysize = s_dh_groupsize_to_keysize(ltc_mp_unsigned_bin_size(key->prime));
    if (keysize == 0) {
    if (keysize == 0) {
       err = CRYPT_INVALID_KEYSIZE;
       err = CRYPT_INVALID_KEYSIZE;
       goto freemp;
       goto freemp;
@@ -69,11 +69,11 @@ int dh_generate_key(prng_state *prng, int wprng, dh_key *key)
          goto freebuf;
          goto freebuf;
       }
       }
       /* load the x value - private key */
       /* load the x value - private key */
-      if ((err = mp_read_unsigned_bin(key->x, buf, keysize)) != CRYPT_OK) {
+      if ((err = ltc_mp_read_unsigned_bin(key->x, buf, keysize)) != CRYPT_OK) {
          goto freebuf;
          goto freebuf;
       }
       }
       /* compute the y value - public key */
       /* compute the y value - public key */
-      if ((err = mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK) {
+      if ((err = ltc_mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK) {
          goto freebuf;
          goto freebuf;
       }
       }
       err = dh_check_pubkey(key);
       err = dh_check_pubkey(key);

+ 1 - 1
src/pk/dh/dh_import.c

@@ -48,7 +48,7 @@ int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key)
             goto error;
             goto error;
          }
          }
          /* compute public key: y = (base ^ x) mod prime */
          /* compute public key: y = (base ^ x) mod prime */
-         if ((err = mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK) {
+         if ((err = ltc_mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK) {
             goto error;
             goto error;
          }
          }
       }
       }

+ 3 - 3
src/pk/dh/dh_import_pkcs8.c

@@ -22,10 +22,10 @@ int dh_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, dh_key
       return err;
       return err;
    }
    }
 
 
-   if ((err = mp_copy(alg_id->child->next->child->data, key->prime)) != CRYPT_OK) {
+   if ((err = ltc_mp_copy(alg_id->child->next->child->data, key->prime)) != CRYPT_OK) {
       goto error;
       goto error;
    }
    }
-   if ((err = mp_copy(alg_id->child->next->child->next->data, key->base)) != CRYPT_OK) {
+   if ((err = ltc_mp_copy(alg_id->child->next->child->next->data, key->base)) != CRYPT_OK) {
       goto error;
       goto error;
    }
    }
 
 
@@ -33,7 +33,7 @@ int dh_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, dh_key
       goto error;
       goto error;
    }
    }
    /* compute public key: y = (base ^ x) mod prime */
    /* compute public key: y = (base ^ x) mod prime */
-   if ((err = mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK) {
+   if ((err = ltc_mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK) {
       goto error;
       goto error;
    }
    }
    /* check public key */
    /* check public key */

+ 7 - 7
src/pk/dh/dh_set.c

@@ -30,8 +30,8 @@ int dh_set_pg(const unsigned char *p, unsigned long plen,
       return err;
       return err;
    }
    }
 
 
-   if ((err = mp_read_unsigned_bin(key->base, (unsigned char*)g, glen)) != CRYPT_OK)     { goto LBL_ERR; }
-   if ((err = mp_read_unsigned_bin(key->prime, (unsigned char*)p, plen)) != CRYPT_OK)  { goto LBL_ERR; }
+   if ((err = ltc_mp_read_unsigned_bin(key->base, (unsigned char*)g, glen)) != CRYPT_OK)     { goto LBL_ERR; }
+   if ((err = ltc_mp_read_unsigned_bin(key->prime, (unsigned char*)p, plen)) != CRYPT_OK)  { goto LBL_ERR; }
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 
 
@@ -62,8 +62,8 @@ int dh_set_pg_groupsize(int groupsize, dh_key *key)
       return err;
       return err;
    }
    }
 
 
-   if ((err = mp_read_radix(key->base, ltc_dh_sets[i].base, 16)) != CRYPT_OK)  { goto LBL_ERR; }
-   if ((err = mp_read_radix(key->prime, ltc_dh_sets[i].prime, 16)) != CRYPT_OK) { goto LBL_ERR; }
+   if ((err = ltc_mp_read_radix(key->base, ltc_dh_sets[i].base, 16)) != CRYPT_OK)  { goto LBL_ERR; }
+   if ((err = ltc_mp_read_radix(key->prime, ltc_dh_sets[i].prime, 16)) != CRYPT_OK) { goto LBL_ERR; }
 
 
    return CRYPT_OK;
    return CRYPT_OK;
 
 
@@ -92,12 +92,12 @@ int dh_set_key(const unsigned char *in, unsigned long inlen, int type, dh_key *k
 
 
    if (type == PK_PRIVATE) {
    if (type == PK_PRIVATE) {
       key->type = PK_PRIVATE;
       key->type = PK_PRIVATE;
-      if ((err = mp_read_unsigned_bin(key->x, (unsigned char*)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
-      if ((err = mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK)       { goto LBL_ERR; }
+      if ((err = ltc_mp_read_unsigned_bin(key->x, (unsigned char*)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
+      if ((err = ltc_mp_exptmod(key->base, key->x, key->prime, key->y)) != CRYPT_OK)       { goto LBL_ERR; }
    }
    }
    else {
    else {
       key->type = PK_PUBLIC;
       key->type = PK_PUBLIC;
-      if ((err = mp_read_unsigned_bin(key->y, (unsigned char*)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
+      if ((err = ltc_mp_read_unsigned_bin(key->y, (unsigned char*)in, inlen)) != CRYPT_OK) { goto LBL_ERR; }
    }
    }
 
 
    /* check public key */
    /* check public key */

+ 7 - 7
src/pk/dh/dh_shared_secret.c

@@ -31,11 +31,11 @@ int dh_shared_secret(const dh_key *private_key, const dh_key *public_key,
    }
    }
 
 
    /* same DH group? */
    /* same DH group? */
-   if (mp_cmp(private_key->prime, public_key->prime) != LTC_MP_EQ) { return CRYPT_PK_TYPE_MISMATCH; }
-   if (mp_cmp(private_key->base, public_key->base) != LTC_MP_EQ)   { return CRYPT_PK_TYPE_MISMATCH; }
+   if (ltc_mp_cmp(private_key->prime, public_key->prime) != LTC_MP_EQ) { return CRYPT_PK_TYPE_MISMATCH; }
+   if (ltc_mp_cmp(private_key->base, public_key->base) != LTC_MP_EQ)   { return CRYPT_PK_TYPE_MISMATCH; }
 
 
    /* init big numbers */
    /* init big numbers */
-   if ((err = mp_init(&tmp)) != CRYPT_OK) {
+   if ((err = ltc_mp_init(&tmp)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
@@ -45,25 +45,25 @@ int dh_shared_secret(const dh_key *private_key, const dh_key *public_key,
    }
    }
 
 
    /* compute tmp = y^x mod p */
    /* compute tmp = y^x mod p */
-   if ((err = mp_exptmod(public_key->y, private_key->x, private_key->prime, tmp)) != CRYPT_OK)  {
+   if ((err = ltc_mp_exptmod(public_key->y, private_key->x, private_key->prime, tmp)) != CRYPT_OK)  {
       goto error;
       goto error;
    }
    }
 
 
    /* enough space for output? */
    /* enough space for output? */
-   x = (unsigned long)mp_unsigned_bin_size(tmp);
+   x = (unsigned long)ltc_mp_unsigned_bin_size(tmp);
    if (*outlen < x) {
    if (*outlen < x) {
       *outlen = x;
       *outlen = x;
       err = CRYPT_BUFFER_OVERFLOW;
       err = CRYPT_BUFFER_OVERFLOW;
       goto error;
       goto error;
    }
    }
-   if ((err = mp_to_unsigned_bin(tmp, out)) != CRYPT_OK) {
+   if ((err = ltc_mp_to_unsigned_bin(tmp, out)) != CRYPT_OK) {
       goto error;
       goto error;
    }
    }
    *outlen = x;
    *outlen = x;
    err = CRYPT_OK;
    err = CRYPT_OK;
 
 
 error:
 error:
-   mp_clear(tmp);
+   ltc_mp_clear(tmp);
    return err;
    return err;
 }
 }
 
 

+ 7 - 7
src/pk/dsa/dsa_decrypt_key.c

@@ -53,12 +53,12 @@ int dsa_decrypt_key(const unsigned char *in,  unsigned long  inlen,
 
 
    /* we now have the hash! */
    /* we now have the hash! */
 
 
-   if ((err = mp_init(&g_pub)) != CRYPT_OK) {
+   if ((err = ltc_mp_init(&g_pub)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
    /* allocate memory */
    /* allocate memory */
-   expt   = XMALLOC(mp_unsigned_bin_size(key->p) + 1);
+   expt   = XMALLOC(ltc_mp_unsigned_bin_size(key->p) + 1);
    skey   = XMALLOC(MAXBLOCKSIZE);
    skey   = XMALLOC(MAXBLOCKSIZE);
    if (expt == NULL || skey == NULL) {
    if (expt == NULL || skey == NULL) {
       if (expt != NULL) {
       if (expt != NULL) {
@@ -67,7 +67,7 @@ int dsa_decrypt_key(const unsigned char *in,  unsigned long  inlen,
       if (skey != NULL) {
       if (skey != NULL) {
          XFREE(skey);
          XFREE(skey);
       }
       }
-      mp_clear(g_pub);
+      ltc_mp_clear(g_pub);
       return CRYPT_MEM;
       return CRYPT_MEM;
    }
    }
 
 
@@ -80,12 +80,12 @@ int dsa_decrypt_key(const unsigned char *in,  unsigned long  inlen,
    }
    }
 
 
    /* make shared key */
    /* make shared key */
-   x = mp_unsigned_bin_size(key->p) + 1;
+   x = ltc_mp_unsigned_bin_size(key->p) + 1;
    if ((err = dsa_shared_secret(key->x, g_pub, key, expt, &x)) != CRYPT_OK) {
    if ((err = dsa_shared_secret(key->x, g_pub, key, expt, &x)) != CRYPT_OK) {
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
 
 
-   y = mp_unsigned_bin_size(key->p) + 1;
+   y = ltc_mp_unsigned_bin_size(key->p) + 1;
    y = MIN(y, MAXBLOCKSIZE);
    y = MIN(y, MAXBLOCKSIZE);
    if ((err = hash_memory(hash, expt, x, expt, &y)) != CRYPT_OK) {
    if ((err = hash_memory(hash, expt, x, expt, &y)) != CRYPT_OK) {
       goto LBL_ERR;
       goto LBL_ERR;
@@ -113,14 +113,14 @@ int dsa_decrypt_key(const unsigned char *in,  unsigned long  inlen,
    err = CRYPT_OK;
    err = CRYPT_OK;
 LBL_ERR:
 LBL_ERR:
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
-   zeromem(expt,   mp_unsigned_bin_size(key->p) + 1);
+   zeromem(expt,   ltc_mp_unsigned_bin_size(key->p) + 1);
    zeromem(skey,   MAXBLOCKSIZE);
    zeromem(skey,   MAXBLOCKSIZE);
 #endif
 #endif
 
 
    XFREE(expt);
    XFREE(expt);
    XFREE(skey);
    XFREE(skey);
 
 
-   mp_clear(g_pub);
+   ltc_mp_clear(g_pub);
 
 
    return err;
    return err;
 }
 }

+ 7 - 7
src/pk/dsa/dsa_encrypt_key.c

@@ -50,11 +50,11 @@ int dsa_encrypt_key(const unsigned char *in,   unsigned long inlen,
     }
     }
 
 
     /* make a random key and export the public copy */
     /* make a random key and export the public copy */
-    if ((err = mp_init_multi(&g_pub, &g_priv, LTC_NULL)) != CRYPT_OK) {
+    if ((err = ltc_mp_init_multi(&g_pub, &g_priv, LTC_NULL)) != CRYPT_OK) {
        return err;
        return err;
     }
     }
 
 
-    expt       = XMALLOC(mp_unsigned_bin_size(key->p) + 1);
+    expt       = XMALLOC(ltc_mp_unsigned_bin_size(key->p) + 1);
     skey       = XMALLOC(MAXBLOCKSIZE);
     skey       = XMALLOC(MAXBLOCKSIZE);
     if (expt == NULL  || skey == NULL) {
     if (expt == NULL  || skey == NULL) {
        if (expt != NULL) {
        if (expt != NULL) {
@@ -63,7 +63,7 @@ int dsa_encrypt_key(const unsigned char *in,   unsigned long inlen,
        if (skey != NULL) {
        if (skey != NULL) {
           XFREE(skey);
           XFREE(skey);
        }
        }
-       mp_clear_multi(g_pub, g_priv, LTC_NULL);
+       ltc_mp_deinit_multi(g_pub, g_priv, LTC_NULL);
        return CRYPT_MEM;
        return CRYPT_MEM;
     }
     }
 
 
@@ -75,12 +75,12 @@ int dsa_encrypt_key(const unsigned char *in,   unsigned long inlen,
     }
     }
 
 
     /* compute y */
     /* compute y */
-    if ((err = mp_exptmod(key->g, g_priv, key->p, g_pub)) != CRYPT_OK) {
+    if ((err = ltc_mp_exptmod(key->g, g_priv, key->p, g_pub)) != CRYPT_OK) {
        goto LBL_ERR;
        goto LBL_ERR;
     }
     }
 
 
     /* make random key */
     /* make random key */
-    x        = mp_unsigned_bin_size(key->p) + 1;
+    x        = ltc_mp_unsigned_bin_size(key->p) + 1;
     if ((err = dsa_shared_secret(g_priv, key->y, key, expt, &x)) != CRYPT_OK) {
     if ((err = dsa_shared_secret(g_priv, key->y, key, expt, &x)) != CRYPT_OK) {
        goto LBL_ERR;
        goto LBL_ERR;
     }
     }
@@ -104,14 +104,14 @@ int dsa_encrypt_key(const unsigned char *in,   unsigned long inlen,
 LBL_ERR:
 LBL_ERR:
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
     /* clean up */
     /* clean up */
-    zeromem(expt,   mp_unsigned_bin_size(key->p) + 1);
+    zeromem(expt,   ltc_mp_unsigned_bin_size(key->p) + 1);
     zeromem(skey,   MAXBLOCKSIZE);
     zeromem(skey,   MAXBLOCKSIZE);
 #endif
 #endif
 
 
     XFREE(skey);
     XFREE(skey);
     XFREE(expt);
     XFREE(expt);
 
 
-    mp_clear_multi(g_pub, g_priv, LTC_NULL);
+    ltc_mp_deinit_multi(g_pub, g_priv, LTC_NULL);
     return err;
     return err;
 }
 }
 
 

+ 1 - 1
src/pk/dsa/dsa_export.c

@@ -58,7 +58,7 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, const dsa_ke
 
 
    if (type == PK_PUBLIC) {
    if (type == PK_PUBLIC) {
       if (std) {
       if (std) {
-          unsigned long tmplen = (unsigned long)(mp_count_bits(key->y) / 8) + 8;
+          unsigned long tmplen = (unsigned long)(ltc_mp_count_bits(key->y) / 8) + 8;
           unsigned char* tmp = XMALLOC(tmplen);
           unsigned char* tmp = XMALLOC(tmplen);
           ltc_asn1_list int_list[3];
           ltc_asn1_list int_list[3];
 
 

+ 1 - 1
src/pk/dsa/dsa_free.c

@@ -16,7 +16,7 @@
 void dsa_free(dsa_key *key)
 void dsa_free(dsa_key *key)
 {
 {
    LTC_ARGCHKVD(key != NULL);
    LTC_ARGCHKVD(key != NULL);
-   mp_cleanup_multi(&key->y, &key->x, &key->q, &key->g, &key->p, LTC_NULL);
+   ltc_mp_cleanup_multi(&key->y, &key->x, &key->q, &key->g, &key->p, LTC_NULL);
    key->type = key->qord = 0;
    key->type = key->qord = 0;
 }
 }
 
 

+ 1 - 1
src/pk/dsa/dsa_generate_key.c

@@ -28,7 +28,7 @@ int dsa_generate_key(prng_state *prng, int wprng, dsa_key *key)
    */
    */
   /* private key x should be from range: 1 <= x <= q-1 (see FIPS 186-4 B.1.2) */
   /* private key x should be from range: 1 <= x <= q-1 (see FIPS 186-4 B.1.2) */
   if ((err = rand_bn_upto(key->x, key->q, prng, wprng)) != CRYPT_OK)          { return err; }
   if ((err = rand_bn_upto(key->x, key->q, prng, wprng)) != CRYPT_OK)          { return err; }
-  if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK)            { return err; }
+  if ((err = ltc_mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK)            { return err; }
   key->type = PK_PRIVATE;
   key->type = PK_PRIVATE;
 
 
   return CRYPT_OK;
   return CRYPT_OK;

+ 31 - 31
src/pk/dsa/dsa_generate_pqg.c

@@ -108,14 +108,14 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
   if ((wbuf = XMALLOC((n+1)*outbytes)) == NULL)                                  { err = CRYPT_MEM; goto cleanup3; }
   if ((wbuf = XMALLOC((n+1)*outbytes)) == NULL)                                  { err = CRYPT_MEM; goto cleanup3; }
   if ((sbuf = XMALLOC(seedbytes)) == NULL)                                       { err = CRYPT_MEM; goto cleanup2; }
   if ((sbuf = XMALLOC(seedbytes)) == NULL)                                       { err = CRYPT_MEM; goto cleanup2; }
 
 
-  err = mp_init_multi(&t2L1, &t2N1, &t2q, &t2seedlen, &U, &W, &X, &c, &h, &e, &seedinc, LTC_NULL);
+  err = ltc_mp_init_multi(&t2L1, &t2N1, &t2q, &t2seedlen, &U, &W, &X, &c, &h, &e, &seedinc, LTC_NULL);
   if (err != CRYPT_OK)                                                           { goto cleanup1; }
   if (err != CRYPT_OK)                                                           { goto cleanup1; }
 
 
-  if ((err = mp_2expt(t2L1, L-1)) != CRYPT_OK)                                   { goto cleanup; }
+  if ((err = ltc_mp_2expt(t2L1, L-1)) != CRYPT_OK)                                   { goto cleanup; }
   /* t2L1 = 2^(L-1) */
   /* t2L1 = 2^(L-1) */
-  if ((err = mp_2expt(t2N1, N-1)) != CRYPT_OK)                                   { goto cleanup; }
+  if ((err = ltc_mp_2expt(t2N1, N-1)) != CRYPT_OK)                                   { goto cleanup; }
   /* t2N1 = 2^(N-1) */
   /* t2N1 = 2^(N-1) */
-  if ((err = mp_2expt(t2seedlen, seedbytes*8)) != CRYPT_OK)                      { goto cleanup; }
+  if ((err = ltc_mp_2expt(t2seedlen, seedbytes*8)) != CRYPT_OK)                      { goto cleanup; }
   /* t2seedlen = 2^seedlen */
   /* t2seedlen = 2^seedlen */
 
 
   for(found_p=0; !found_p;) {
   for(found_p=0; !found_p;) {
@@ -124,38 +124,38 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
       if (prng_descriptor[wprng].read(sbuf, seedbytes, prng) != seedbytes)       { err = CRYPT_ERROR_READPRNG; goto cleanup; }
       if (prng_descriptor[wprng].read(sbuf, seedbytes, prng) != seedbytes)       { err = CRYPT_ERROR_READPRNG; goto cleanup; }
       i = outbytes;
       i = outbytes;
       if ((err = hash_memory(hash, sbuf, seedbytes, digest, &i)) != CRYPT_OK)    { goto cleanup; }
       if ((err = hash_memory(hash, sbuf, seedbytes, digest, &i)) != CRYPT_OK)    { goto cleanup; }
-      if ((err = mp_read_unsigned_bin(U, digest, outbytes)) != CRYPT_OK)         { goto cleanup; }
-      if ((err = mp_mod(U, t2N1, U)) != CRYPT_OK)                                { goto cleanup; }
-      if ((err = mp_add(t2N1, U, q)) != CRYPT_OK)                                { goto cleanup; }
-      if (!mp_isodd(q)) mp_add_d(q, 1, q);
-      if ((err = mp_prime_is_prime(q, mr_tests_q, &res)) != CRYPT_OK)            { goto cleanup; }
+      if ((err = ltc_mp_read_unsigned_bin(U, digest, outbytes)) != CRYPT_OK)         { goto cleanup; }
+      if ((err = ltc_mp_mod(U, t2N1, U)) != CRYPT_OK)                                { goto cleanup; }
+      if ((err = ltc_mp_add(t2N1, U, q)) != CRYPT_OK)                                { goto cleanup; }
+      if (!ltc_mp_isodd(q)) ltc_mp_add_d(q, 1, q);
+      if ((err = ltc_mp_prime_is_prime(q, mr_tests_q, &res)) != CRYPT_OK)            { goto cleanup; }
       if (res == LTC_MP_YES) found_q = 1;
       if (res == LTC_MP_YES) found_q = 1;
     }
     }
 
 
     /* p */
     /* p */
-    if ((err = mp_read_unsigned_bin(seedinc, sbuf, seedbytes)) != CRYPT_OK)      { goto cleanup; }
-    if ((err = mp_add(q, q, t2q)) != CRYPT_OK)                                   { goto cleanup; }
+    if ((err = ltc_mp_read_unsigned_bin(seedinc, sbuf, seedbytes)) != CRYPT_OK)      { goto cleanup; }
+    if ((err = ltc_mp_add(q, q, t2q)) != CRYPT_OK)                                   { goto cleanup; }
     for(counter=0; counter < 4*L && !found_p; counter++) {
     for(counter=0; counter < 4*L && !found_p; counter++) {
       for(j=0; j<=n; j++) {
       for(j=0; j<=n; j++) {
-        if ((err = mp_add_d(seedinc, 1, seedinc)) != CRYPT_OK)                   { goto cleanup; }
-        if ((err = mp_mod(seedinc, t2seedlen, seedinc)) != CRYPT_OK)             { goto cleanup; }
+        if ((err = ltc_mp_add_d(seedinc, 1, seedinc)) != CRYPT_OK)                   { goto cleanup; }
+        if ((err = ltc_mp_mod(seedinc, t2seedlen, seedinc)) != CRYPT_OK)             { goto cleanup; }
         /* seedinc = (seedinc+1) % 2^seed_bitlen */
         /* seedinc = (seedinc+1) % 2^seed_bitlen */
-        if ((i = mp_unsigned_bin_size(seedinc)) > seedbytes)                     { err = CRYPT_INVALID_ARG; goto cleanup; }
+        if ((i = ltc_mp_unsigned_bin_size(seedinc)) > seedbytes)                     { err = CRYPT_INVALID_ARG; goto cleanup; }
         zeromem(sbuf, seedbytes);
         zeromem(sbuf, seedbytes);
-        if ((err = mp_to_unsigned_bin(seedinc, sbuf + seedbytes-i)) != CRYPT_OK) { goto cleanup; }
+        if ((err = ltc_mp_to_unsigned_bin(seedinc, sbuf + seedbytes-i)) != CRYPT_OK) { goto cleanup; }
         i = outbytes;
         i = outbytes;
         err = hash_memory(hash, sbuf, seedbytes, wbuf+(n-j)*outbytes, &i);
         err = hash_memory(hash, sbuf, seedbytes, wbuf+(n-j)*outbytes, &i);
         if (err != CRYPT_OK)                                                     { goto cleanup; }
         if (err != CRYPT_OK)                                                     { goto cleanup; }
       }
       }
-      if ((err = mp_read_unsigned_bin(W, wbuf, (n+1)*outbytes)) != CRYPT_OK)     { goto cleanup; }
-      if ((err = mp_mod(W, t2L1, W)) != CRYPT_OK)                                { goto cleanup; }
-      if ((err = mp_add(W, t2L1, X)) != CRYPT_OK)                                { goto cleanup; }
-      if ((err = mp_mod(X, t2q, c))  != CRYPT_OK)                                { goto cleanup; }
-      if ((err = mp_sub_d(c, 1, p))  != CRYPT_OK)                                { goto cleanup; }
-      if ((err = mp_sub(X, p, p))    != CRYPT_OK)                                { goto cleanup; }
-      if (mp_cmp(p, t2L1) != LTC_MP_LT) {
+      if ((err = ltc_mp_read_unsigned_bin(W, wbuf, (n+1)*outbytes)) != CRYPT_OK)     { goto cleanup; }
+      if ((err = ltc_mp_mod(W, t2L1, W)) != CRYPT_OK)                                { goto cleanup; }
+      if ((err = ltc_mp_add(W, t2L1, X)) != CRYPT_OK)                                { goto cleanup; }
+      if ((err = ltc_mp_mod(X, t2q, c))  != CRYPT_OK)                                { goto cleanup; }
+      if ((err = ltc_mp_sub_d(c, 1, p))  != CRYPT_OK)                                { goto cleanup; }
+      if ((err = ltc_mp_sub(X, p, p))    != CRYPT_OK)                                { goto cleanup; }
+      if (ltc_mp_cmp(p, t2L1) != LTC_MP_LT) {
         /* p >= 2^(L-1) */
         /* p >= 2^(L-1) */
-        if ((err = mp_prime_is_prime(p, mr_tests_p, &res)) != CRYPT_OK)          { goto cleanup; }
+        if ((err = ltc_mp_prime_is_prime(p, mr_tests_p, &res)) != CRYPT_OK)          { goto cleanup; }
         if (res == LTC_MP_YES) {
         if (res == LTC_MP_YES) {
           found_p = 1;
           found_p = 1;
         }
         }
@@ -172,22 +172,22 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
   *
   *
   */
   */
 
 
-  if ((err = mp_sub_d(p, 1, e)) != CRYPT_OK)                                     { goto cleanup; }
-  if ((err = mp_div(e, q, e, c)) != CRYPT_OK)                                    { goto cleanup; }
+  if ((err = ltc_mp_sub_d(p, 1, e)) != CRYPT_OK)                                     { goto cleanup; }
+  if ((err = ltc_mp_div(e, q, e, c)) != CRYPT_OK)                                    { goto cleanup; }
   /* e = (p - 1)/q */
   /* e = (p - 1)/q */
-  i = mp_count_bits(p);
+  i = ltc_mp_count_bits(p);
   do {
   do {
     do {
     do {
       if ((err = rand_bn_bits(h, i, prng, wprng)) != CRYPT_OK)                   { goto cleanup; }
       if ((err = rand_bn_bits(h, i, prng, wprng)) != CRYPT_OK)                   { goto cleanup; }
-    } while (mp_cmp(h, p) != LTC_MP_LT || mp_cmp_d(h, 2) != LTC_MP_GT);
-    if ((err = mp_sub_d(h, 1, h)) != CRYPT_OK)                                   { goto cleanup; }
+    } while (ltc_mp_cmp(h, p) != LTC_MP_LT || ltc_mp_cmp_d(h, 2) != LTC_MP_GT);
+    if ((err = ltc_mp_sub_d(h, 1, h)) != CRYPT_OK)                                   { goto cleanup; }
     /* h is randon and 1 < h < (p-1) */
     /* h is randon and 1 < h < (p-1) */
-    if ((err = mp_exptmod(h, e, p, g)) != CRYPT_OK)                              { goto cleanup; }
-  } while (mp_cmp_d(g, 1) == LTC_MP_EQ);
+    if ((err = ltc_mp_exptmod(h, e, p, g)) != CRYPT_OK)                              { goto cleanup; }
+  } while (ltc_mp_cmp_d(g, 1) == LTC_MP_EQ);
 
 
   err = CRYPT_OK;
   err = CRYPT_OK;
 cleanup:
 cleanup:
-  mp_clear_multi(t2L1, t2N1, t2q, t2seedlen, U, W, X, c, h, e, seedinc, LTC_NULL);
+  ltc_mp_deinit_multi(t2L1, t2N1, t2q, t2seedlen, U, W, X, c, h, e, seedinc, LTC_NULL);
 cleanup1:
 cleanup1:
   XFREE(sbuf);
   XFREE(sbuf);
 cleanup2:
 cleanup2:

+ 1 - 1
src/pk/dsa/dsa_import.c

@@ -118,7 +118,7 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
    }
    }
 
 
 LBL_OK:
 LBL_OK:
-   key->qord = mp_unsigned_bin_size(key->q);
+   key->qord = ltc_mp_unsigned_bin_size(key->q);
 
 
    /* quick p, q, g validation, without primality testing
    /* quick p, q, g validation, without primality testing
     * + x, y validation */
     * + x, y validation */

+ 2 - 2
src/pk/dsa/dsa_import_pkcs8.c

@@ -26,7 +26,7 @@ int dsa_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, dsa_ke
    if ((err = der_decode_integer(priv_key->data, priv_key->size, key->x)) != CRYPT_OK) {
    if ((err = der_decode_integer(priv_key->data, priv_key->size, key->x)) != CRYPT_OK) {
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
-   if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) {
+   if ((err = ltc_mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK) {
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
 
 
@@ -40,7 +40,7 @@ int dsa_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, dsa_ke
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
 
 
-   key->qord = mp_unsigned_bin_size(key->q);
+   key->qord = ltc_mp_unsigned_bin_size(key->q);
    key->type = PK_PRIVATE;
    key->type = PK_PRIVATE;
 
 
    return err;
    return err;

+ 1 - 1
src/pk/dsa/dsa_init.c

@@ -16,7 +16,7 @@ int dsa_int_init(dsa_key *key)
    LTC_ARGCHK(ltc_mp.name != NULL);
    LTC_ARGCHK(ltc_mp.name != NULL);
 
 
    /* init key */
    /* init key */
-   return mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, LTC_NULL);
+   return ltc_mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, LTC_NULL);
 }
 }
 
 
 #endif
 #endif

+ 7 - 7
src/pk/dsa/dsa_set.c

@@ -30,11 +30,11 @@ int dsa_set_pqg(const unsigned char *p,  unsigned long plen,
    /* init key */
    /* init key */
    if ((err = dsa_int_init(key)) != CRYPT_OK) return err;
    if ((err = dsa_int_init(key)) != CRYPT_OK) return err;
 
 
-   if ((err = mp_read_unsigned_bin(key->p, p , plen)) != CRYPT_OK)                  { goto LBL_ERR; }
-   if ((err = mp_read_unsigned_bin(key->g, g , glen)) != CRYPT_OK)                  { goto LBL_ERR; }
-   if ((err = mp_read_unsigned_bin(key->q, q , qlen)) != CRYPT_OK)                  { goto LBL_ERR; }
+   if ((err = ltc_mp_read_unsigned_bin(key->p, p , plen)) != CRYPT_OK)              { goto LBL_ERR; }
+   if ((err = ltc_mp_read_unsigned_bin(key->g, g , glen)) != CRYPT_OK)              { goto LBL_ERR; }
+   if ((err = ltc_mp_read_unsigned_bin(key->q, q , qlen)) != CRYPT_OK)              { goto LBL_ERR; }
 
 
-   key->qord = mp_unsigned_bin_size(key->q);
+   key->qord = ltc_mp_unsigned_bin_size(key->q);
 
 
    /* do only a quick validation, without primality testing */
    /* do only a quick validation, without primality testing */
    if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK)                        { goto LBL_ERR; }
    if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK)                        { goto LBL_ERR; }
@@ -75,12 +75,12 @@ int dsa_set_key(const unsigned char *in, unsigned long inlen, int type, dsa_key
 
 
    if (type == PK_PRIVATE) {
    if (type == PK_PRIVATE) {
       key->type = PK_PRIVATE;
       key->type = PK_PRIVATE;
-      if ((err = mp_read_unsigned_bin(key->x, in, inlen)) != CRYPT_OK)                  { goto LBL_ERR; }
-      if ((err = mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK)               { goto LBL_ERR; }
+      if ((err = ltc_mp_read_unsigned_bin(key->x, in, inlen)) != CRYPT_OK)              { goto LBL_ERR; }
+      if ((err = ltc_mp_exptmod(key->g, key->x, key->p, key->y)) != CRYPT_OK)           { goto LBL_ERR; }
    }
    }
    else {
    else {
       key->type = PK_PUBLIC;
       key->type = PK_PUBLIC;
-      if ((err = mp_read_unsigned_bin(key->y, in, inlen)) != CRYPT_OK)                  { goto LBL_ERR; }
+      if ((err = ltc_mp_read_unsigned_bin(key->y, in, inlen)) != CRYPT_OK)              { goto LBL_ERR; }
    }
    }
 
 
    if ((err = dsa_int_validate_xy(key, &stat)) != CRYPT_OK)                             { goto LBL_ERR; }
    if ((err = dsa_int_validate_xy(key, &stat)) != CRYPT_OK)                             { goto LBL_ERR; }

+ 1 - 1
src/pk/dsa/dsa_set_pqg_dsaparam.c

@@ -35,7 +35,7 @@ int dsa_set_pqg_dsaparam(const unsigned char *dsaparam, unsigned long dsaparamle
       goto LBL_ERR;
       goto LBL_ERR;
    }
    }
 
 
-   key->qord = mp_unsigned_bin_size(key->q);
+   key->qord = ltc_mp_unsigned_bin_size(key->q);
 
 
    /* quick p, q, g validation, without primality testing */
    /* quick p, q, g validation, without primality testing */
    if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK) {
    if ((err = dsa_int_validate_pqg(key, &stat)) != CRYPT_OK) {

+ 6 - 6
src/pk/dsa/dsa_shared_secret.c

@@ -32,28 +32,28 @@ int dsa_shared_secret(void          *private_key, void *base,
    LTC_ARGCHK(outlen      != NULL);
    LTC_ARGCHK(outlen      != NULL);
 
 
    /* make new point */
    /* make new point */
-   if ((err = mp_init(&res)) != CRYPT_OK) {
+   if ((err = ltc_mp_init(&res)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
-   if ((err = mp_exptmod(base, private_key, public_key->p, res)) != CRYPT_OK) {
-      mp_clear(res);
+   if ((err = ltc_mp_exptmod(base, private_key, public_key->p, res)) != CRYPT_OK) {
+      ltc_mp_clear(res);
       return err;
       return err;
    }
    }
 
 
-   x = (unsigned long)mp_unsigned_bin_size(res);
+   x = (unsigned long)ltc_mp_unsigned_bin_size(res);
    if (*outlen < x) {
    if (*outlen < x) {
       *outlen = x;
       *outlen = x;
       err = CRYPT_BUFFER_OVERFLOW;
       err = CRYPT_BUFFER_OVERFLOW;
       goto done;
       goto done;
    }
    }
    zeromem(out, x);
    zeromem(out, x);
-   if ((err = mp_to_unsigned_bin(res, out + (x - mp_unsigned_bin_size(res))))   != CRYPT_OK)          { goto done; }
+   if ((err = ltc_mp_to_unsigned_bin(res, out + (x - ltc_mp_unsigned_bin_size(res))))   != CRYPT_OK)          { goto done; }
 
 
    err     = CRYPT_OK;
    err     = CRYPT_OK;
    *outlen = x;
    *outlen = x;
 done:
 done:
-   mp_clear(res);
+   ltc_mp_clear(res);
    return err;
    return err;
 }
 }
 
 

+ 20 - 20
src/pk/dsa/dsa_sign_hash.c

@@ -13,8 +13,8 @@
   Sign a hash with DSA
   Sign a hash with DSA
   @param in       The hash to sign
   @param in       The hash to sign
   @param inlen    The length of the hash to sign
   @param inlen    The length of the hash to sign
-  @param r        The "r" integer of the signature (caller must initialize with mp_init() first)
-  @param s        The "s" integer of the signature (caller must initialize with mp_init() first)
+  @param r        The "r" integer of the signature (caller must initialize with ltc_mp_init() first)
+  @param s        The "s" integer of the signature (caller must initialize with ltc_mp_init() first)
   @param prng     An active PRNG state
   @param prng     An active PRNG state
   @param wprng    The index of the PRNG desired
   @param wprng    The index of the PRNG desired
   @param key      A private DSA key
   @param key      A private DSA key
@@ -51,45 +51,45 @@ int dsa_sign_hash_raw(const unsigned char *in,  unsigned long inlen,
    }
    }
 
 
    /* Init our temps */
    /* Init our temps */
-   if ((err = mp_init_multi(&k, &kinv, &tmp, LTC_NULL)) != CRYPT_OK)                   { goto ERRBUF; }
+   if ((err = ltc_mp_init_multi(&k, &kinv, &tmp, LTC_NULL)) != CRYPT_OK)                   { goto ERRBUF; }
 
 
-   qbits = mp_count_bits(key->q);
+   qbits = ltc_mp_count_bits(key->q);
 retry:
 retry:
 
 
    do {
    do {
       /* gen random k */
       /* gen random k */
-      if ((err = rand_bn_bits(k, qbits, prng, wprng)) != CRYPT_OK)                     { goto error; }
+      if ((err = rand_bn_bits(k, qbits, prng, wprng)) != CRYPT_OK)                         { goto error; }
 
 
       /* k should be from range: 1 <= k <= q-1 (see FIPS 186-4 B.2.2) */
       /* k should be from range: 1 <= k <= q-1 (see FIPS 186-4 B.2.2) */
-      if (mp_cmp_d(k, 0) != LTC_MP_GT || mp_cmp(k, key->q) != LTC_MP_LT)               { goto retry; }
+      if (ltc_mp_cmp_d(k, 0) != LTC_MP_GT || ltc_mp_cmp(k, key->q) != LTC_MP_LT)           { goto retry; }
 
 
       /* test gcd */
       /* test gcd */
-      if ((err = mp_gcd(k, key->q, tmp)) != CRYPT_OK)                                  { goto error; }
-   } while (mp_cmp_d(tmp, 1) != LTC_MP_EQ);
+      if ((err = ltc_mp_gcd(k, key->q, tmp)) != CRYPT_OK)                                  { goto error; }
+   } while (ltc_mp_cmp_d(tmp, 1) != LTC_MP_EQ);
 
 
    /* now find 1/k mod q */
    /* now find 1/k mod q */
-   if ((err = mp_invmod(k, key->q, kinv)) != CRYPT_OK)                                 { goto error; }
+   if ((err = ltc_mp_invmod(k, key->q, kinv)) != CRYPT_OK)                                 { goto error; }
 
 
    /* now find r = g^k mod p mod q */
    /* now find r = g^k mod p mod q */
-   if ((err = mp_exptmod(key->g, k, key->p, r)) != CRYPT_OK)                           { goto error; }
-   if ((err = mp_mod(r, key->q, r)) != CRYPT_OK)                                       { goto error; }
+   if ((err = ltc_mp_exptmod(key->g, k, key->p, r)) != CRYPT_OK)                           { goto error; }
+   if ((err = ltc_mp_mod(r, key->q, r)) != CRYPT_OK)                                       { goto error; }
 
 
-   if (mp_iszero(r) == LTC_MP_YES)                                                     { goto retry; }
+   if (ltc_mp_iszero(r) == LTC_MP_YES)                                                     { goto retry; }
 
 
    /* FIPS 186-4 4.6: use leftmost min(bitlen(q), bitlen(hash)) bits of 'hash'*/
    /* FIPS 186-4 4.6: use leftmost min(bitlen(q), bitlen(hash)) bits of 'hash'*/
    inlen = MIN(inlen, (unsigned long)(key->qord));
    inlen = MIN(inlen, (unsigned long)(key->qord));
 
 
    /* now find s = (in + xr)/k mod q */
    /* now find s = (in + xr)/k mod q */
-   if ((err = mp_read_unsigned_bin(tmp, in, inlen)) != CRYPT_OK)                       { goto error; }
-   if ((err = mp_mul(key->x, r, s)) != CRYPT_OK)                                       { goto error; }
-   if ((err = mp_add(s, tmp, s)) != CRYPT_OK)                                          { goto error; }
-   if ((err = mp_mulmod(s, kinv, key->q, s)) != CRYPT_OK)                              { goto error; }
+   if ((err = ltc_mp_read_unsigned_bin(tmp, in, inlen)) != CRYPT_OK)                       { goto error; }
+   if ((err = ltc_mp_mul(key->x, r, s)) != CRYPT_OK)                                       { goto error; }
+   if ((err = ltc_mp_add(s, tmp, s)) != CRYPT_OK)                                          { goto error; }
+   if ((err = ltc_mp_mulmod(s, kinv, key->q, s)) != CRYPT_OK)                              { goto error; }
 
 
-   if (mp_iszero(s) == LTC_MP_YES)                                                     { goto retry; }
+   if (ltc_mp_iszero(s) == LTC_MP_YES)                                                     { goto retry; }
 
 
    err = CRYPT_OK;
    err = CRYPT_OK;
 error:
 error:
-   mp_clear_multi(k, kinv, tmp, LTC_NULL);
+   ltc_mp_deinit_multi(k, kinv, tmp, LTC_NULL);
 ERRBUF:
 ERRBUF:
 #ifdef LTC_CLEAN_STACK
 #ifdef LTC_CLEAN_STACK
    zeromem(buf, LTC_MDSA_MAX_GROUP);
    zeromem(buf, LTC_MDSA_MAX_GROUP);
@@ -121,7 +121,7 @@ int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
    LTC_ARGCHK(outlen  != NULL);
    LTC_ARGCHK(outlen  != NULL);
    LTC_ARGCHK(key     != NULL);
    LTC_ARGCHK(key     != NULL);
 
 
-   if (mp_init_multi(&r, &s, LTC_NULL) != CRYPT_OK) {
+   if (ltc_mp_init_multi(&r, &s, LTC_NULL) != CRYPT_OK) {
       return CRYPT_MEM;
       return CRYPT_MEM;
    }
    }
 
 
@@ -135,7 +135,7 @@ int dsa_sign_hash(const unsigned char *in,  unsigned long inlen,
                              LTC_ASN1_EOL,     0UL, NULL);
                              LTC_ASN1_EOL,     0UL, NULL);
 
 
 error:
 error:
-   mp_clear_multi(r, s, LTC_NULL);
+   ltc_mp_deinit_multi(r, s, LTC_NULL);
    return err;
    return err;
 }
 }
 
 

+ 14 - 14
src/pk/dsa/dsa_verify_hash.c

@@ -36,12 +36,12 @@ int dsa_verify_hash_raw(         void   *r,          void   *s,
    *stat = 0;
    *stat = 0;
 
 
    /* init our variables */
    /* init our variables */
-   if ((err = mp_init_multi(&w, &v, &u1, &u2, LTC_NULL)) != CRYPT_OK) {
+   if ((err = ltc_mp_init_multi(&w, &v, &u1, &u2, LTC_NULL)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
    /* neither r or s can be null or >q*/
    /* neither r or s can be null or >q*/
-   if (mp_cmp_d(r, 0) != LTC_MP_GT || mp_cmp_d(s, 0) != LTC_MP_GT || mp_cmp(r, key->q) != LTC_MP_LT || mp_cmp(s, key->q) != LTC_MP_LT) {
+   if (ltc_mp_cmp_d(r, 0) != LTC_MP_GT || ltc_mp_cmp_d(s, 0) != LTC_MP_GT || ltc_mp_cmp(r, key->q) != LTC_MP_LT || ltc_mp_cmp(s, key->q) != LTC_MP_LT) {
       err = CRYPT_INVALID_PACKET;
       err = CRYPT_INVALID_PACKET;
       goto error;
       goto error;
    }
    }
@@ -50,29 +50,29 @@ int dsa_verify_hash_raw(         void   *r,          void   *s,
    hashlen = MIN(hashlen, (unsigned long)(key->qord));
    hashlen = MIN(hashlen, (unsigned long)(key->qord));
 
 
    /* w = 1/s mod q */
    /* w = 1/s mod q */
-   if ((err = mp_invmod(s, key->q, w)) != CRYPT_OK)                                       { goto error; }
+   if ((err = ltc_mp_invmod(s, key->q, w)) != CRYPT_OK)                                       { goto error; }
 
 
    /* u1 = m * w mod q */
    /* u1 = m * w mod q */
-   if ((err = mp_read_unsigned_bin(u1, hash, hashlen)) != CRYPT_OK)                       { goto error; }
-   if ((err = mp_mulmod(u1, w, key->q, u1)) != CRYPT_OK)                                  { goto error; }
+   if ((err = ltc_mp_read_unsigned_bin(u1, hash, hashlen)) != CRYPT_OK)                       { goto error; }
+   if ((err = ltc_mp_mulmod(u1, w, key->q, u1)) != CRYPT_OK)                                  { goto error; }
 
 
    /* u2 = r*w mod q */
    /* u2 = r*w mod q */
-   if ((err = mp_mulmod(r, w, key->q, u2)) != CRYPT_OK)                                   { goto error; }
+   if ((err = ltc_mp_mulmod(r, w, key->q, u2)) != CRYPT_OK)                                   { goto error; }
 
 
    /* v = g^u1 * y^u2 mod p mod q */
    /* v = g^u1 * y^u2 mod p mod q */
-   if ((err = mp_exptmod(key->g, u1, key->p, u1)) != CRYPT_OK)                            { goto error; }
-   if ((err = mp_exptmod(key->y, u2, key->p, u2)) != CRYPT_OK)                            { goto error; }
-   if ((err = mp_mulmod(u1, u2, key->p, v)) != CRYPT_OK)                                  { goto error; }
-   if ((err = mp_mod(v, key->q, v)) != CRYPT_OK)                                          { goto error; }
+   if ((err = ltc_mp_exptmod(key->g, u1, key->p, u1)) != CRYPT_OK)                            { goto error; }
+   if ((err = ltc_mp_exptmod(key->y, u2, key->p, u2)) != CRYPT_OK)                            { goto error; }
+   if ((err = ltc_mp_mulmod(u1, u2, key->p, v)) != CRYPT_OK)                                  { goto error; }
+   if ((err = ltc_mp_mod(v, key->q, v)) != CRYPT_OK)                                          { goto error; }
 
 
    /* if r = v then we're set */
    /* if r = v then we're set */
-   if (mp_cmp(r, v) == LTC_MP_EQ) {
+   if (ltc_mp_cmp(r, v) == LTC_MP_EQ) {
       *stat = 1;
       *stat = 1;
    }
    }
 
 
    err = CRYPT_OK;
    err = CRYPT_OK;
 error:
 error:
-   mp_clear_multi(w, v, u1, u2, LTC_NULL);
+   ltc_mp_deinit_multi(w, v, u1, u2, LTC_NULL);
    return err;
    return err;
 }
 }
 
 
@@ -98,7 +98,7 @@ int dsa_verify_hash(const unsigned char *sig,        unsigned long  siglen,
    LTC_ARGCHK(stat != NULL);
    LTC_ARGCHK(stat != NULL);
    *stat = 0; /* must be set before the first return */
    *stat = 0; /* must be set before the first return */
 
 
-   if ((err = mp_init_multi(&r, &s, LTC_NULL)) != CRYPT_OK) {
+   if ((err = ltc_mp_init_multi(&r, &s, LTC_NULL)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
 
 
@@ -119,7 +119,7 @@ int dsa_verify_hash(const unsigned char *sig,        unsigned long  siglen,
    err = dsa_verify_hash_raw(r, s, hash, hashlen, stat, key);
    err = dsa_verify_hash_raw(r, s, hash, hashlen, stat, key);
 
 
 LBL_ERR:
 LBL_ERR:
-   mp_clear_multi(r, s, LTC_NULL);
+   ltc_mp_deinit_multi(r, s, LTC_NULL);
    return err;
    return err;
 }
 }
 
 

+ 21 - 21
src/pk/dsa/dsa_verify_key.c

@@ -49,22 +49,22 @@ int dsa_int_validate_pqg(const dsa_key *key, int *stat)
 
 
    /* check q-order */
    /* check q-order */
    if ( key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
    if ( key->qord >= LTC_MDSA_MAX_GROUP || key->qord <= 15 ||
-        (unsigned long)key->qord >= mp_unsigned_bin_size(key->p) ||
-        (mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA ) {
+        (unsigned long)key->qord >= ltc_mp_unsigned_bin_size(key->p) ||
+        (ltc_mp_unsigned_bin_size(key->p) - key->qord) >= LTC_MDSA_DELTA ) {
       return CRYPT_OK;
       return CRYPT_OK;
    }
    }
 
 
    /* FIPS 186-4 chapter 4.1: 1 < g < p */
    /* FIPS 186-4 chapter 4.1: 1 < g < p */
-   if (mp_cmp_d(key->g, 1) != LTC_MP_GT || mp_cmp(key->g, key->p) != LTC_MP_LT) {
+   if (ltc_mp_cmp_d(key->g, 1) != LTC_MP_GT || ltc_mp_cmp(key->g, key->p) != LTC_MP_LT) {
       return CRYPT_OK;
       return CRYPT_OK;
    }
    }
 
 
-   if ((err = mp_init_multi(&tmp1, &tmp2, LTC_NULL)) != CRYPT_OK)    { return err; }
+   if ((err = ltc_mp_init_multi(&tmp1, &tmp2, LTC_NULL)) != CRYPT_OK)        { return err; }
 
 
    /* FIPS 186-4 chapter 4.1: q is a divisor of (p - 1) */
    /* FIPS 186-4 chapter 4.1: q is a divisor of (p - 1) */
-   if ((err = mp_sub_d(key->p, 1, tmp1)) != CRYPT_OK)                { goto error; }
-   if ((err = mp_div(tmp1, key->q, tmp1, tmp2)) != CRYPT_OK)         { goto error; }
-   if (mp_iszero(tmp2) != LTC_MP_YES) {
+   if ((err = ltc_mp_sub_d(key->p, 1, tmp1)) != CRYPT_OK)                { goto error; }
+   if ((err = ltc_mp_div(tmp1, key->q, tmp1, tmp2)) != CRYPT_OK)         { goto error; }
+   if (ltc_mp_iszero(tmp2) != LTC_MP_YES) {
       err = CRYPT_OK;
       err = CRYPT_OK;
       goto error;
       goto error;
    }
    }
@@ -72,8 +72,8 @@ int dsa_int_validate_pqg(const dsa_key *key, int *stat)
    /* FIPS 186-4 chapter 4.1: g is a generator of a subgroup of order q in
    /* FIPS 186-4 chapter 4.1: g is a generator of a subgroup of order q in
     * the multiplicative group of GF(p) - so we make sure that g^q mod p = 1
     * the multiplicative group of GF(p) - so we make sure that g^q mod p = 1
     */
     */
-   if ((err = mp_exptmod(key->g, key->q, key->p, tmp1)) != CRYPT_OK) { goto error; }
-   if (mp_cmp_d(tmp1, 1) != LTC_MP_EQ) {
+   if ((err = ltc_mp_exptmod(key->g, key->q, key->p, tmp1)) != CRYPT_OK) { goto error; }
+   if (ltc_mp_cmp_d(tmp1, 1) != LTC_MP_EQ) {
       err = CRYPT_OK;
       err = CRYPT_OK;
       goto error;
       goto error;
    }
    }
@@ -81,7 +81,7 @@ int dsa_int_validate_pqg(const dsa_key *key, int *stat)
    err   = CRYPT_OK;
    err   = CRYPT_OK;
    *stat = 1;
    *stat = 1;
 error:
 error:
-   mp_clear_multi(tmp2, tmp1, LTC_NULL);
+   ltc_mp_deinit_multi(tmp2, tmp1, LTC_NULL);
    return err;
    return err;
 }
 }
 
 
@@ -101,7 +101,7 @@ int dsa_int_validate_primes(const dsa_key *key, int *stat)
    LTC_ARGCHK(stat != NULL);
    LTC_ARGCHK(stat != NULL);
 
 
    /* key->q prime? */
    /* key->q prime? */
-   if ((err = mp_prime_is_prime(key->q, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
+   if ((err = ltc_mp_prime_is_prime(key->q, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
    if (res == LTC_MP_NO) {
    if (res == LTC_MP_NO) {
@@ -109,7 +109,7 @@ int dsa_int_validate_primes(const dsa_key *key, int *stat)
    }
    }
 
 
    /* key->p prime? */
    /* key->p prime? */
-   if ((err = mp_prime_is_prime(key->p, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
+   if ((err = ltc_mp_prime_is_prime(key->p, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
    if (res == LTC_MP_NO) {
    if (res == LTC_MP_NO) {
@@ -137,28 +137,28 @@ int dsa_int_validate_xy(const dsa_key *key, int *stat)
    LTC_ARGCHK(stat != NULL);
    LTC_ARGCHK(stat != NULL);
 
 
    /* 1 < y < p-1 */
    /* 1 < y < p-1 */
-   if ((err = mp_init(&tmp)) != CRYPT_OK) {
+   if ((err = ltc_mp_init(&tmp)) != CRYPT_OK) {
       return err;
       return err;
    }
    }
-   if ((err = mp_sub_d(key->p, 1, tmp)) != CRYPT_OK) {
+   if ((err = ltc_mp_sub_d(key->p, 1, tmp)) != CRYPT_OK) {
       goto error;
       goto error;
    }
    }
-   if (mp_cmp_d(key->y, 1) != LTC_MP_GT || mp_cmp(key->y, tmp) != LTC_MP_LT) {
+   if (ltc_mp_cmp_d(key->y, 1) != LTC_MP_GT || ltc_mp_cmp(key->y, tmp) != LTC_MP_LT) {
       err = CRYPT_OK;
       err = CRYPT_OK;
       goto error;
       goto error;
    }
    }
 
 
    if (key->type == PK_PRIVATE) {
    if (key->type == PK_PRIVATE) {
       /* FIPS 186-4 chapter 4.1: 0 < x < q */
       /* FIPS 186-4 chapter 4.1: 0 < x < q */
-      if (mp_cmp_d(key->x, 0) != LTC_MP_GT || mp_cmp(key->x, key->q) != LTC_MP_LT) {
+      if (ltc_mp_cmp_d(key->x, 0) != LTC_MP_GT || ltc_mp_cmp(key->x, key->q) != LTC_MP_LT) {
          err = CRYPT_OK;
          err = CRYPT_OK;
          goto error;
          goto error;
       }
       }
       /* FIPS 186-4 chapter 4.1: y = g^x mod p */
       /* FIPS 186-4 chapter 4.1: y = g^x mod p */
-      if ((err = mp_exptmod(key->g, key->x, key->p, tmp)) != CRYPT_OK) {
+      if ((err = ltc_mp_exptmod(key->g, key->x, key->p, tmp)) != CRYPT_OK) {
          goto error;
          goto error;
       }
       }
-      if (mp_cmp(tmp, key->y) != LTC_MP_EQ) {
+      if (ltc_mp_cmp(tmp, key->y) != LTC_MP_EQ) {
          err = CRYPT_OK;
          err = CRYPT_OK;
          goto error;
          goto error;
       }
       }
@@ -167,10 +167,10 @@ int dsa_int_validate_xy(const dsa_key *key, int *stat)
       /* with just a public key we cannot test y = g^x mod p therefore we
       /* with just a public key we cannot test y = g^x mod p therefore we
        * only test that y^q mod p = 1, which makes sure y is in g^x mod p
        * only test that y^q mod p = 1, which makes sure y is in g^x mod p
        */
        */
-      if ((err = mp_exptmod(key->y, key->q, key->p, tmp)) != CRYPT_OK) {
+      if ((err = ltc_mp_exptmod(key->y, key->q, key->p, tmp)) != CRYPT_OK) {
          goto error;
          goto error;
       }
       }
-      if (mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
+      if (ltc_mp_cmp_d(tmp, 1) != LTC_MP_EQ) {
          err = CRYPT_OK;
          err = CRYPT_OK;
          goto error;
          goto error;
       }
       }
@@ -179,7 +179,7 @@ int dsa_int_validate_xy(const dsa_key *key, int *stat)
    err   = CRYPT_OK;
    err   = CRYPT_OK;
    *stat = 1;
    *stat = 1;
 error:
 error:
-   mp_clear(tmp);
+   ltc_mp_clear(tmp);
    return err;
    return err;
 }
 }
 
 

+ 5 - 0
src/pk/ec25519/tweetnacl.c

@@ -4,6 +4,7 @@
 
 
 /* automatically generated file, do not edit */
 /* automatically generated file, do not edit */
 
 
+#define add tnacl_add
 #define FOR(i,n) for (i = 0;i < n;++i)
 #define FOR(i,n) for (i = 0;i < n;++i)
 #define sv static void
 #define sv static void
 
 
@@ -489,3 +490,7 @@ int tweetnacl_crypto_ph(u8 *out,const u8 *msg,u64 msglen)
 {
 {
   return tweetnacl_crypto_hash(out, msg, msglen);
   return tweetnacl_crypto_hash(out, msg, msglen);
 }
 }
+
+#undef add
+#undef FOR
+#undef sv

+ 6 - 6
src/pk/ecc/ecc_export_openssl.c

@@ -53,15 +53,15 @@ int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, cons
       cofactor = key->dp.cofactor;
       cofactor = key->dp.cofactor;
 
 
       /* curve param a */
       /* curve param a */
-      len_a = mp_unsigned_bin_size(a);
+      len_a = ltc_mp_unsigned_bin_size(a);
       if (len_a > sizeof(bin_a))                                   { err = CRYPT_BUFFER_OVERFLOW; goto error; }
       if (len_a > sizeof(bin_a))                                   { err = CRYPT_BUFFER_OVERFLOW; goto error; }
-      if ((err = mp_to_unsigned_bin(a, bin_a)) != CRYPT_OK)        { goto error; }
+      if ((err = ltc_mp_to_unsigned_bin(a, bin_a)) != CRYPT_OK)        { goto error; }
       if (len_a == 0) { len_a = 1; bin_a[0] = 0; } /* handle case a == 0 */
       if (len_a == 0) { len_a = 1; bin_a[0] = 0; } /* handle case a == 0 */
 
 
       /* curve param b */
       /* curve param b */
-      len_b = mp_unsigned_bin_size(b);
+      len_b = ltc_mp_unsigned_bin_size(b);
       if (len_b > sizeof(bin_b))                                   { err = CRYPT_BUFFER_OVERFLOW; goto error; }
       if (len_b > sizeof(bin_b))                                   { err = CRYPT_BUFFER_OVERFLOW; goto error; }
-      if ((err = mp_to_unsigned_bin(b, bin_b)) != CRYPT_OK)        { goto error; }
+      if ((err = ltc_mp_to_unsigned_bin(b, bin_b)) != CRYPT_OK)        { goto error; }
       if (len_b == 0) { len_b = 1; bin_b[0] = 0; } /* handle case b == 0 */
       if (len_b == 0) { len_b = 1; bin_b[0] = 0; } /* handle case b == 0 */
 
 
       /* base point - (un)compressed based on flag_com */
       /* base point - (un)compressed based on flag_com */
@@ -134,9 +134,9 @@ int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, cons
       */
       */
 
 
       /* private key */
       /* private key */
-      len_k = mp_unsigned_bin_size(key->k);
+      len_k = ltc_mp_unsigned_bin_size(key->k);
       if (len_k > sizeof(bin_k))                                        { err = CRYPT_BUFFER_OVERFLOW; goto error; }
       if (len_k > sizeof(bin_k))                                        { err = CRYPT_BUFFER_OVERFLOW; goto error; }
-      if ((err = mp_to_unsigned_bin(key->k, bin_k)) != CRYPT_OK)        { goto error; }
+      if ((err = ltc_mp_to_unsigned_bin(key->k, bin_k)) != CRYPT_OK)        { goto error; }
 
 
       LTC_SET_ASN1(&pub_xy,  0, LTC_ASN1_RAW_BIT_STRING, bin_xy, 8*len_xy);
       LTC_SET_ASN1(&pub_xy,  0, LTC_ASN1_RAW_BIT_STRING, bin_xy, 8*len_xy);
       LTC_SET_ASN1(seq_priv, 0, LTC_ASN1_SHORT_INTEGER,  &one,   1);
       LTC_SET_ASN1(seq_priv, 0, LTC_ASN1_SHORT_INTEGER,  &one,   1);

+ 1 - 1
src/pk/ecc/ecc_free.c

@@ -18,7 +18,7 @@ void ecc_free(ecc_key *key)
 {
 {
    LTC_ARGCHKVD(key != NULL);
    LTC_ARGCHKVD(key != NULL);
 
 
-   mp_cleanup_multi(&key->dp.prime, &key->dp.order,
+   ltc_mp_cleanup_multi(&key->dp.prime, &key->dp.order,
                     &key->dp.A, &key->dp.B,
                     &key->dp.A, &key->dp.B,
                     &key->dp.base.x, &key->dp.base.y, &key->dp.base.z,
                     &key->dp.base.x, &key->dp.base.y, &key->dp.base.z,
                     &key->pubkey.x, &key->pubkey.y, &key->pubkey.z,
                     &key->pubkey.x, &key->pubkey.y, &key->pubkey.z,

+ 2 - 2
src/pk/ecc/ecc_get_key.c

@@ -38,9 +38,9 @@ int ecc_get_key(unsigned char *out, unsigned long *outlen, int type, const ecc_k
          return CRYPT_BUFFER_OVERFLOW;
          return CRYPT_BUFFER_OVERFLOW;
       }
       }
       *outlen = size;
       *outlen = size;
-      if ((ksize = mp_unsigned_bin_size(key->k)) > size)                          return CRYPT_BUFFER_OVERFLOW;
+      if ((ksize = ltc_mp_unsigned_bin_size(key->k)) > size)                          return CRYPT_BUFFER_OVERFLOW;
       /* pad and store k */
       /* pad and store k */
-      if ((err = mp_to_unsigned_bin(key->k, out + (size - ksize))) != CRYPT_OK)   return err;
+      if ((err = ltc_mp_to_unsigned_bin(key->k, out + (size - ksize))) != CRYPT_OK)   return err;
       zeromem(out, size - ksize);
       zeromem(out, size - ksize);
    }
    }
    else {
    else {

+ 1 - 1
src/pk/ecc/ecc_import.c

@@ -85,7 +85,7 @@ int ecc_import_ex(const unsigned char *in, unsigned long inlen, ecc_key *key, co
    }
    }
 
 
    /* set z */
    /* set z */
-   if ((err = mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto done; }
+   if ((err = ltc_mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto done; }
 
 
    /* point on the curve + other checks */
    /* point on the curve + other checks */
    if ((err = ltc_ecc_verify_key(key)) != CRYPT_OK)  { goto done; }
    if ((err = ltc_ecc_verify_key(key)) != CRYPT_OK)  { goto done; }

Some files were not shown because too many files changed in this diff