From edf11c62c06da27bc8689efa8edf7a2075c054ff Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 18 Jan 2011 21:16:11 +0100 Subject: [PATCH] Diffie-Hellman/Math: introduced the proposed changes by Alexander Kurpiers addmod and submod are moved to the end of the math descriptor, in order to be able to run existing software against a new version of ltc without need to rebuild the software. --- src/headers/tomcrypt_math.h | 38 +++++++++++++++++++------------------ src/math/gmp_desc.c | 6 +++--- src/math/ltm_desc.c | 7 ++++--- src/math/tfm_desc.c | 6 +++--- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/headers/tomcrypt_math.h b/src/headers/tomcrypt_math.h index 8b58f2e..caf6b52 100644 --- a/src/headers/tomcrypt_math.h +++ b/src/headers/tomcrypt_math.h @@ -258,24 +258,6 @@ typedef struct { */ int (*lcm)(void *a, void *b, void *c); - /** Modular addition - @param a The first source - @param b The second source - @param c The modulus - @param d The destination (a + b mod c) - @return CRYPT_OK on success - */ - int (*addmod)(void *a, void *b, void *c, void *d); - - /** Modular substraction - @param a The first source - @param b The second source - @param c The modulus - @param d The destination (a - b mod c) - @return CRYPT_OK on success - */ - int (*submod)(void *a, void *b, void *c, void *d); - /** Modular multiplication @param a The first source @param b The second source @@ -429,6 +411,26 @@ typedef struct { int (*rsa_me)(const unsigned char *in, unsigned long inlen, unsigned char *out, unsigned long *outlen, int which, rsa_key *key); + +/* ---- basic math continued ---- */ + + /** Modular addition + @param a The first source + @param b The second source + @param c The modulus + @param d The destination (a + b mod c) + @return CRYPT_OK on success + */ + int (*addmod)(void *a, void *b, void *c, void *d); + + /** Modular substraction + @param a The first source + @param b The second source + @param c The modulus + @param d The destination (a - b mod c) + @return CRYPT_OK on success + */ + int (*submod)(void *a, void *b, void *c, void *d); } ltc_math_descriptor; extern ltc_math_descriptor ltc_mp; diff --git a/src/math/gmp_desc.c b/src/math/gmp_desc.c index 3450e80..beab976 100644 --- a/src/math/gmp_desc.c +++ b/src/math/gmp_desc.c @@ -449,8 +449,6 @@ const ltc_math_descriptor gmp_desc = { &gcd, &lcm, - &addmod, - &submod, &mulmod, &sqrmod, &invmod, @@ -489,8 +487,10 @@ const ltc_math_descriptor gmp_desc = { &rsa_make_key, &rsa_exptmod, #else - NULL, NULL + NULL, NULL, #endif + &addmod, + &submod, }; diff --git a/src/math/ltm_desc.c b/src/math/ltm_desc.c index bc5a142..8d61af4 100644 --- a/src/math/ltm_desc.c +++ b/src/math/ltm_desc.c @@ -451,8 +451,6 @@ const ltc_math_descriptor ltm_desc = { &gcd, &lcm, - &addmod, - &submod, &mulmod, &sqrmod, &invmod, @@ -491,8 +489,11 @@ const ltc_math_descriptor ltm_desc = { &rsa_make_key, &rsa_exptmod, #else - NULL, NULL + NULL, NULL, #endif + &addmod, + &submod, + }; diff --git a/src/math/tfm_desc.c b/src/math/tfm_desc.c index 111d122..82a7353 100644 --- a/src/math/tfm_desc.c +++ b/src/math/tfm_desc.c @@ -739,8 +739,6 @@ const ltc_math_descriptor tfm_desc = { &gcd, &lcm, - &addmod, - &submod, &mulmod, &sqrmod, &invmod, @@ -784,8 +782,10 @@ const ltc_math_descriptor tfm_desc = { &rsa_make_key, &rsa_exptmod, #else - NULL, NULL + NULL, NULL, #endif + &addmod, + &submod, };