diff --git a/ssl/bigint.c b/ssl/bigint.c index 8d52184a8..41446dde6 100644 --- a/ssl/bigint.c +++ b/ssl/bigint.c @@ -734,8 +734,8 @@ void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset) #if defined(CONFIG_BIGINT_MONTGOMERY) /* set montgomery variables */ - R = comp_left_shift(bi_clone(ctx, ctx->bi_radix), k-1); /* R */ - R2 = comp_left_shift(bi_clone(ctx, ctx->bi_radix), k*2-1); /* R^2 */ + R = comp_left_shift(bi_clone(ctx, ctx->bi_radix), k-1); /* R */ + R2 = comp_left_shift(bi_clone(ctx, ctx->bi_radix), k*2-1); /* R^2 */ ctx->bi_RR_mod_m[mod_offset] = bi_mod(ctx, R2); /* R^2 mod m */ ctx->bi_R_mod_m[mod_offset] = bi_mod(ctx, R); /* R mod m */ @@ -743,10 +743,11 @@ void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset) bi_permanent(ctx->bi_R_mod_m[mod_offset]); ctx->N0_dash[mod_offset] = modular_inverse(ctx->bi_mod[mod_offset]); + #elif defined (CONFIG_BIGINT_BARRETT) ctx->bi_mu[mod_offset] = bi_divide(ctx, comp_left_shift( - bi_clone(ctx, ctx->bi_radix), k*2-1), ctx->bi_mod[mod_offset], 0); + bi_clone(ctx, ctx->bi_radix), k*2-1), ctx->bi_mod[mod_offset], 0); bi_permanent(ctx->bi_mu[mod_offset]); #endif } @@ -1383,10 +1384,10 @@ bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp) if (!ctx->use_classical) { /* preconvert */ - bi = bi_residue(ctx, - bi_multiply(ctx, bi, ctx->bi_RR_mod_m[mod_offset])); /* x' */ + bi = bi_mont(ctx, + bi_multiply(ctx, bi, ctx->bi_RR_mod_m[mod_offset])); /* x' */ bi_free(ctx, biR); - biR = ctx->bi_R_mod_m[mod_offset]; + biR = ctx->bi_R_mod_m[mod_offset]; /* A */ } #endif diff --git a/ssl/bigint.h b/ssl/bigint.h index 2291f5c87..db3d112b9 100644 --- a/ssl/bigint.h +++ b/ssl/bigint.h @@ -29,10 +29,6 @@ #define CONFIG_SSL_CERT_VERIFICATION #endif -#if !defined(CONFIG_BIGINT_MONTGOMERY) || !defined(CONFIG_BIGINT_BARRETT) -#define CONFIG_BIGINT_CLASSICAL 1 -#endif - #include "os_port.h" #include "bigint_impl.h" diff --git a/ssl/test/Makefile b/ssl/test/Makefile index 23fcaf3bb..6420503b9 100644 --- a/ssl/test/Makefile +++ b/ssl/test/Makefile @@ -35,10 +35,10 @@ ssltesting: ../../$(STAGE)/ssltest LIBS=../../$(STAGE) CFLAGS += -I../../ssl -I../../config -../../$(STAGE)/perf_bigint: perf_bigint.o +../../$(STAGE)/perf_bigint: perf_bigint.o $(LIBS)/libaxtls.a $(CC) $(LDFLAGS) -o $@ $^ -L $(LIBS) -laxtls -../../$(STAGE)/ssltest: ssltest.o +../../$(STAGE)/ssltest: ssltest.o $(LIBS)/libaxtls.a $(CC) $(LDFLAGS) -o $@ $^ -lpthread -L $(LIBS) -laxtls else performance: ../../$(STAGE)/perf_bigint.exe diff --git a/ssl/test/ssltest.c b/ssl/test/ssltest.c index c1ac2f1fc..688e203f0 100644 --- a/ssl/test/ssltest.c +++ b/ssl/test/ssltest.c @@ -1650,37 +1650,61 @@ int main(int argc, char *argv[]) bi_ctx = bi_initialize(); if (AES_test(bi_ctx)) + { + printf("AES tests failed\n"); goto cleanup; + } TTY_FLUSH(); if (RC4_test(bi_ctx)) + { + printf("RC4 tests failed\n"); goto cleanup; + } TTY_FLUSH(); if (MD5_test(bi_ctx)) + { + printf("MD5 tests failed\n"); goto cleanup; + } TTY_FLUSH(); if (SHA1_test(bi_ctx)) + { + printf("SHA1 tests failed\n"); goto cleanup; + } TTY_FLUSH(); if (HMAC_test(bi_ctx)) + { + printf("HMAC tests failed\n"); goto cleanup; + } TTY_FLUSH(); if (BIGINT_test(bi_ctx)) + { + printf("BigInt tests failed!\n"); goto cleanup; + } TTY_FLUSH(); bi_terminate(bi_ctx); if (RSA_test()) + { + printf("RSA tests failed\n"); goto cleanup; + } TTY_FLUSH(); if (cert_tests()) + { + printf("CERT tests failed\n"); goto cleanup; + } TTY_FLUSH(); system("sh ../ssl/test/killopenssl.sh");