1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

Fixed issue which stopped Montgomery & Classical reduction from being used

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@41 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich 2006-11-27 05:52:33 +00:00
parent c98ded2eca
commit 3c59f849dd
4 changed files with 33 additions and 12 deletions

View File

@ -734,8 +734,8 @@ void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset)
#if defined(CONFIG_BIGINT_MONTGOMERY) #if defined(CONFIG_BIGINT_MONTGOMERY)
/* set montgomery variables */ /* set montgomery variables */
R = comp_left_shift(bi_clone(ctx, ctx->bi_radix), k-1); /* R */ 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 */ 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_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 */ 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]); bi_permanent(ctx->bi_R_mod_m[mod_offset]);
ctx->N0_dash[mod_offset] = modular_inverse(ctx->bi_mod[mod_offset]); ctx->N0_dash[mod_offset] = modular_inverse(ctx->bi_mod[mod_offset]);
#elif defined (CONFIG_BIGINT_BARRETT) #elif defined (CONFIG_BIGINT_BARRETT)
ctx->bi_mu[mod_offset] = ctx->bi_mu[mod_offset] =
bi_divide(ctx, comp_left_shift( 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]); bi_permanent(ctx->bi_mu[mod_offset]);
#endif #endif
} }
@ -1383,10 +1384,10 @@ bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp)
if (!ctx->use_classical) if (!ctx->use_classical)
{ {
/* preconvert */ /* preconvert */
bi = bi_residue(ctx, bi = bi_mont(ctx,
bi_multiply(ctx, bi, ctx->bi_RR_mod_m[mod_offset])); /* x' */ bi_multiply(ctx, bi, ctx->bi_RR_mod_m[mod_offset])); /* x' */
bi_free(ctx, biR); bi_free(ctx, biR);
biR = ctx->bi_R_mod_m[mod_offset]; biR = ctx->bi_R_mod_m[mod_offset]; /* A */
} }
#endif #endif

View File

@ -29,10 +29,6 @@
#define CONFIG_SSL_CERT_VERIFICATION #define CONFIG_SSL_CERT_VERIFICATION
#endif #endif
#if !defined(CONFIG_BIGINT_MONTGOMERY) || !defined(CONFIG_BIGINT_BARRETT)
#define CONFIG_BIGINT_CLASSICAL 1
#endif
#include "os_port.h" #include "os_port.h"
#include "bigint_impl.h" #include "bigint_impl.h"

View File

@ -35,10 +35,10 @@ ssltesting: ../../$(STAGE)/ssltest
LIBS=../../$(STAGE) LIBS=../../$(STAGE)
CFLAGS += -I../../ssl -I../../config 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 $(CC) $(LDFLAGS) -o $@ $^ -L $(LIBS) -laxtls
../../$(STAGE)/ssltest: ssltest.o ../../$(STAGE)/ssltest: ssltest.o $(LIBS)/libaxtls.a
$(CC) $(LDFLAGS) -o $@ $^ -lpthread -L $(LIBS) -laxtls $(CC) $(LDFLAGS) -o $@ $^ -lpthread -L $(LIBS) -laxtls
else else
performance: ../../$(STAGE)/perf_bigint.exe performance: ../../$(STAGE)/perf_bigint.exe

View File

@ -1650,37 +1650,61 @@ int main(int argc, char *argv[])
bi_ctx = bi_initialize(); bi_ctx = bi_initialize();
if (AES_test(bi_ctx)) if (AES_test(bi_ctx))
{
printf("AES tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
if (RC4_test(bi_ctx)) if (RC4_test(bi_ctx))
{
printf("RC4 tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
if (MD5_test(bi_ctx)) if (MD5_test(bi_ctx))
{
printf("MD5 tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
if (SHA1_test(bi_ctx)) if (SHA1_test(bi_ctx))
{
printf("SHA1 tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
if (HMAC_test(bi_ctx)) if (HMAC_test(bi_ctx))
{
printf("HMAC tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
if (BIGINT_test(bi_ctx)) if (BIGINT_test(bi_ctx))
{
printf("BigInt tests failed!\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
bi_terminate(bi_ctx); bi_terminate(bi_ctx);
if (RSA_test()) if (RSA_test())
{
printf("RSA tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
if (cert_tests()) if (cert_tests())
{
printf("CERT tests failed\n");
goto cleanup; goto cleanup;
}
TTY_FLUSH(); TTY_FLUSH();
system("sh ../ssl/test/killopenssl.sh"); system("sh ../ssl/test/killopenssl.sh");