Merge pull request #476 from libtom/fix/474

Fix issue #474
This commit is contained in:
Steffen Jaeckel 2019-04-10 17:05:59 +02:00 committed by GitHub
commit e8afa13d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 87 additions and 49 deletions

View File

@ -80,7 +80,7 @@ make clean &>/dev/null
EXTRALIBS="$5"
echo $2 | grep -q GMP && EXTRALIBS="$EXTRALIBS -lgmp"
echo $* | grep -q GMP && EXTRALIBS="$EXTRALIBS -lgmp"
if [ -z "$(echo $CC | grep "clang")" ]; then
run_gcc "$1" "$2" "$3" "$4" "$EXTRALIBS"
@ -90,11 +90,11 @@ fi
make clean &>/dev/null
bash .ci/testbuild.sh "NOTEST" "-DLTC_NO_TEST" "$3" "$4" "$5"
bash .ci/testbuild.sh "NOTEST" "-DLTC_NO_TEST" "$3" "$4" "$EXTRALIBS"
make clean &>/dev/null
bash .ci/testbuild.sh "NOFILE" "-DLTC_NO_FILE" "$3" "$4" "$5"
bash .ci/testbuild.sh "NOFILE" "-DLTC_NO_FILE" "$3" "$4" "$EXTRALIBS"
make clean &>/dev/null

View File

@ -14,7 +14,7 @@ echo "$1 (Build Only, $2, $3)..."
make clean 1>/dev/null 2>/dev/null
echo -n "building..."
touch testok.txt
CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" make -j$MAKE_JOBS -f $3 test tv_gen 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && rm -f testok.txt && exit 1)
make -j$MAKE_JOBS -f $3 test tv_gen CFLAGS="$2 $CFLAGS $4" EXTRALIBS="$5" 1>gcc_1.txt 2>gcc_2.txt || (echo "build $1 failed see gcc_2.txt for more information" && cat gcc_2.txt && rm -f testok.txt && exit 1)
if find testok.txt -type f 1>/dev/null 2>/dev/null ; then
echo "successful"
exit 0

View File

@ -34,8 +34,8 @@ compiler:
- gcc
- clang
script:
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile V=1" "-DUSE_LTM -DLTM_DESC" "-ltommath"
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "${BUILDOPTIONS}" "makefile.shared V=1" "-DUSE_TFM -DTFM_DESC" "-ltfm"
- bash "${BUILDSCRIPT}" "${BUILDNAME}" "-DUSE_LTM -DLTM_DESC" "makefile V=1" "${BUILDOPTIONS}" "-ltommath" &&
bash "${BUILDSCRIPT}" "${BUILDNAME}" "-DUSE_TFM -DTFM_DESC" "makefile.shared V=1" "${BUILDOPTIONS}" "-ltfm"
env:
- |
BUILDSCRIPT=".ci/meta_builds.sh"
@ -49,6 +49,10 @@ env:
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="STOCK"
BUILDOPTIONS=" "
- |
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="STOCK-MPI"
BUILDOPTIONS="-ULTM_DESC -UTFM_DESC -UUSE_LTM -UUSE_TFM"
- |
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="EASY"
@ -109,6 +113,22 @@ env:
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="CLEANSTACK+NOTABLES+SMALL+NO_ASM+NO_TIMING_RESISTANCE+LTC_FORTUNA_RESEED_RATELIMIT_STATIC+PTHREAD"
BUILDOPTIONS="-DLTC_CLEAN_STACK -DLTC_NO_TABLES -DLTC_SMALL_CODE -DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING -DLTC_FORTUNA_RESEED_RATELIMIT_STATIC -DLTC_PTHREAD"
- |
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="STOCK+ARGTYPE=1"
BUILDOPTIONS="-DARGTYPE=1"
- |
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="STOCK+ARGTYPE=2"
BUILDOPTIONS="-DARGTYPE=2"
- |
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="STOCK+ARGTYPE=3"
BUILDOPTIONS="-DARGTYPE=3"
- |
BUILDSCRIPT=".ci/run.sh"
BUILDNAME="STOCK+ARGTYPE=4"
BUILDOPTIONS="-DARGTYPE=4"
after_failure:
- cat test_std.txt

View File

@ -37,6 +37,7 @@
@param out The output file
@param taglen The MAC tag length
@param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
@param res [out] Result of the operation, 1==valid, 0==invalid
@return CRYPT_OK on success
*/
int gcm_file( int cipher,
@ -56,6 +57,8 @@ int gcm_file( int cipher,
LTC_ARGCHK(out != NULL);
LTC_ARGCHK(res != NULL);
*res = 0;
f_in = fopen(in, "rb");
if (f_in == NULL) {
err = CRYPT_FILE_NOTFOUND;

View File

@ -55,6 +55,7 @@
@param out The output file
@param taglen The MAC tag length
@param direction Encrypt or Decrypt mode (GCM_ENCRYPT or GCM_DECRYPT)
@param res [out] Result of the operation, 1==valid, 0==invalid
@return CRYPT_OK on success
*/
int gcm_filehandle( int cipher,

View File

@ -18,7 +18,7 @@
#include <tomcrypt.h>
static int NORETURN usage(char *name)
static int LTC_NORETURN usage(char *name)
{
int x;

View File

@ -786,9 +786,6 @@ int main(void)
#elif defined(EXT_MATH_LIB)
extern ltc_math_descriptor EXT_MATH_LIB;
ltc_mp = EXT_MATH_LIB;
#else
fprintf(stderr, "No MPI provider available\n");
exit(EXIT_FAILURE);
#endif
printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n");
@ -816,8 +813,10 @@ int main(void)
printf("Generating GCM vectors..."); fflush(stdout); gcm_gen(); printf("done\n");
#endif
printf("Generating BASE64 vectors..."); fflush(stdout); base64_gen(); printf("done\n");
printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n");
printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n");
if (ltc_mp.name != NULL) {
printf("Generating MATH vectors..."); fflush(stdout); math_gen(); printf("done\n");
printf("Generating ECC vectors..."); fflush(stdout); ecc_gen(); printf("done\n");
}
#ifdef LTC_LRW_MODE
printf("Generating LRW vectors..."); fflush(stdout); lrw_gen(); printf("done\n");
#endif

View File

@ -71,7 +71,7 @@ $(1): $(call print-help,$(1),Builds the library and the '$(1)' demo) demos/$(1).
ifneq ($V,1)
@echo " * $${CC} $$@"
endif
$${silent} $$(CC) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $(1)
$${silent} $$(CC) $$(LTC_LDFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(LTC_EXTRALIBS) -o $(1)
endef
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

View File

@ -9,18 +9,13 @@
/* Defines the LTC_ARGCHK macro used within the library */
/* ARGTYPE is defined in tomcrypt_cfg.h */
/* ARGTYPE is per default defined to 0 */
#if ARGTYPE == 0
#include <signal.h>
/* this is the default LibTomCrypt macro */
#if defined(__clang__) || defined(__GNUC_MINOR__)
#define NORETURN __attribute__ ((noreturn))
#else
#define NORETURN
#endif
void crypt_argchk(const char *v, const char *s, int d) NORETURN;
void crypt_argchk(const char *v, const char *s, int d) LTC_NORETURN;
#define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
#define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
@ -37,7 +32,7 @@ void crypt_argchk(const char *v, const char *s, int d) NORETURN;
#elif ARGTYPE == 3
#define LTC_ARGCHK(x)
#define LTC_ARGCHK(x) LTC_UNUSED_PARAM(x)
#define LTC_ARGCHKVD(x) LTC_ARGCHK(x)
#elif ARGTYPE == 4

View File

@ -61,6 +61,14 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
#define LTC_INLINE
#endif
#if defined(__clang__) || defined(__GNUC_MINOR__)
#define LTC_NORETURN __attribute__ ((noreturn))
#elif defined(_MSC_VER)
#define LTC_NORETURN __declspec(noreturn)
#else
#define LTC_NORETURN
#endif
/* type of argument checking, 0=default, 1=fatal and 2=error+continue, 3=nothing */
#ifndef ARGTYPE
#define ARGTYPE 0

View File

@ -554,7 +554,7 @@
#endif
#endif
#if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA)
#if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_SSH)
/* Include the MPI functionality? (required by the PK algorithms) */
#define LTC_MPI

View File

@ -412,9 +412,7 @@ static int isprime(void *a, int b, int *c)
int err;
LTC_ARGCHK(a != NULL);
LTC_ARGCHK(c != NULL);
if (b == 0) {
b = LTC_MILLER_RABIN_REPS;
} /* if */
b = mp_prime_rabin_miller_trials(mp_count_bits(a));
err = mpi_to_ltc_error(mp_prime_is_prime(a, b, c));
*c = (*c == MP_YES) ? LTC_MP_YES : LTC_MP_NO;
return err;

View File

@ -18,7 +18,7 @@
#ifdef LTC_XSALSA20
#ifdef LTC_SHA256
#if defined(LTC_SHA256) && defined(LTC_TEST)
static int _sha256(unsigned char *hash, const unsigned char *data, const int datalen) {
hash_state md;
sha256_init(&md);

View File

@ -296,10 +296,9 @@ static int _ecc_test_mp(void)
void *a, *modulus, *order;
ecc_point *G, *GG;
int i, err, primality;
char buf[4096];
if ((err = mp_init_multi(&modulus, &order, &a, NULL)) != CRYPT_OK) {
return err;
}
DO(mp_init_multi(&modulus, &order, &a, NULL));
G = ltc_ecc_new_point();
GG = ltc_ecc_new_point();
@ -310,34 +309,40 @@ static int _ecc_test_mp(void)
return CRYPT_MEM;
}
err = CRYPT_OK;
for (i = 0; ltc_ecc_curves[i].prime != NULL; i++) {
if ((err = mp_read_radix(a, (char *)ltc_ecc_curves[i].A, 16)) != CRYPT_OK) { goto done; }
if ((err = mp_read_radix(modulus, (char *)ltc_ecc_curves[i].prime, 16)) != CRYPT_OK) { goto done; }
if ((err = mp_read_radix(order, (char *)ltc_ecc_curves[i].order, 16)) != CRYPT_OK) { goto done; }
DO(mp_read_radix(a, (char *)ltc_ecc_curves[i].A, 16));
DO(mp_read_radix(modulus, (char *)ltc_ecc_curves[i].prime, 16));
DO(mp_read_radix(order, (char *)ltc_ecc_curves[i].order, 16));
/* is prime actually prime? */
if ((err = mp_prime_is_prime(modulus, 8, &primality)) != CRYPT_OK) { goto done; }
DO(mp_prime_is_prime(modulus, 8, &primality));
if (primality == 0) {
err = CRYPT_FAIL_TESTVECTOR;
goto done;
mp_tohex(modulus, buf);
printf("Modulus failed prime check: %s\n", buf);
}
/* is order prime ? */
if ((err = mp_prime_is_prime(order, 8, &primality)) != CRYPT_OK) { goto done; }
DO(mp_prime_is_prime(order, 8, &primality));
if (primality == 0) {
err = CRYPT_FAIL_TESTVECTOR;
goto done;
mp_tohex(order, buf);
printf("Order failed prime check: %s\n", buf);
}
if ((err = mp_read_radix(G->x, (char *)ltc_ecc_curves[i].Gx, 16)) != CRYPT_OK) { goto done; }
if ((err = mp_read_radix(G->y, (char *)ltc_ecc_curves[i].Gy, 16)) != CRYPT_OK) { goto done; }
DO(mp_read_radix(G->x, (char *)ltc_ecc_curves[i].Gx, 16));
DO(mp_read_radix(G->y, (char *)ltc_ecc_curves[i].Gy, 16));
mp_set(G->z, 1);
/* then we should have G == (order + 1)G */
if ((err = mp_add_d(order, 1, order)) != CRYPT_OK) { goto done; }
if ((err = ltc_mp.ecc_ptmul(order, G, GG, a, modulus, 1)) != CRYPT_OK) { goto done; }
DO(mp_add_d(order, 1, order));
DO(ltc_mp.ecc_ptmul(order, G, GG, a, modulus, 1));
if (mp_cmp(G->x, GG->x) != LTC_MP_EQ || mp_cmp(G->y, GG->y) != LTC_MP_EQ) {
err = CRYPT_FAIL_TESTVECTOR;
}
if (err != CRYPT_OK) {
goto done;
}
}

View File

@ -35,7 +35,7 @@ int misc_test(void)
DO(crc32_test());
#endif
#ifdef LTC_SSH
DO(ssh_test());
ssh_test();
#endif
return 0;
}

View File

@ -163,10 +163,15 @@ static const struct ltc_prng_descriptor no_prng_desc =
struct ltc_prng_descriptor* no_prng_desc_get(void)
{
int ret;
no_prng_desc_t* no_prng = XMALLOC(sizeof(*no_prng));
LTC_ARGCHK(no_prng != NULL);
if (no_prng == NULL) return NULL;
XMEMCPY(&no_prng->desc, &no_prng_desc, sizeof(no_prng_desc));
LTC_ARGCHK(snprintf(no_prng->name, sizeof(no_prng->name), "no_prng@%p", no_prng) < (int)sizeof(no_prng->name));
ret = snprintf(no_prng->name, sizeof(no_prng->name), "no_prng@%p", no_prng);
if((ret >= (int)sizeof(no_prng->name)) || (ret == -1)) {
XFREE(no_prng);
return NULL;
}
no_prng->desc.name = no_prng->name;
return &no_prng->desc;
}
@ -174,8 +179,8 @@ struct ltc_prng_descriptor* no_prng_desc_get(void)
void no_prng_desc_free(struct ltc_prng_descriptor* prng)
{
no_prng_desc_t *no_prng = (no_prng_desc_t*) prng;
LTC_ARGCHK(no_prng != NULL);
LTC_ARGCHK(no_prng->name == (char*)no_prng + offsetof(no_prng_desc_t, name));
LTC_ARGCHKVD(no_prng != NULL);
LTC_ARGCHKVD(no_prng->name == (char*)no_prng + offsetof(no_prng_desc_t, name));
XFREE(no_prng);
}

View File

@ -294,13 +294,20 @@ static int _ssh_decoding_test(void)
*/
int ssh_test(void)
{
if (ltc_mp.name == NULL) return CRYPT_NOP;
DO(_ssh_encoding_test());
DO(_ssh_decoding_test());
return CRYPT_OK;
}
#else
int ssh_test(void)
{
return CRYPT_NOP;
}
#endif

View File

@ -44,10 +44,7 @@ int multi_test(void);
int prng_test(void);
int mpi_test(void);
int padding_test(void);
#ifdef LTC_SSH
int ssh_test(void);
#endif
#ifdef LTC_PKCS_1
struct ltc_prng_descriptor* no_prng_desc_get(void);