Allow for bn_mul_mont assembler.
authorAndy Polyakov <appro@openssl.org>
Tue, 24 Jul 2007 15:07:51 +0000 (15:07 +0000)
committerAndy Polyakov <appro@openssl.org>
Tue, 24 Jul 2007 15:07:51 +0000 (15:07 +0000)
Configure
crypto/bn/Makefile
crypto/bn/bn_lcl.h
crypto/bn/bn_mont.c

index d5a046c4a986143580ba320a3f3a3808edba6565..de32ac08bce2ce19b0ddfd86c466571bf38565c4 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -1248,6 +1248,8 @@ $bn_obj = $bn_asm unless $bn_obj ne "";
 $cflags.=" -DOPENSSL_BN_ASM_PART_WORDS" if ($bn_obj =~ /bn86/);
 $cflags.=" -DOPENSSL_IA32_SSE2" if (!$no_sse2 && $bn_obj =~ /bn86/);
 
+$cflags.=" -DOPENSSL_BN_ASM_MONT" if ($bn_obj =~ /\-mont|mo86\-/);
+
 if ($fips)
        {
        $openssl_other_defines.="#define OPENSSL_FIPS\n";
index 5f11fa8e86c4847d124aab7a4db3b3a263cc31a8..bdec23092e2f1cffdac1f0aa981290e296f1a796 100644 (file)
@@ -67,16 +67,22 @@ bn86-elf.s: asm/bn-586.pl ../perlasm/x86asm.pl
        (cd asm; $(PERL) bn-586.pl elf $(CFLAGS) > ../$@)
 co86-elf.s:    asm/co-586.pl ../perlasm/x86asm.pl
        (cd asm; $(PERL) co-586.pl elf $(CFLAGS) > ../$@)
+mo86-elf.s:    asm/x86-mont.pl ../perlasm/x86asm.pl
+       (cd asm; $(PERL) x86-mont.pl elf $(CFLAGS) > ../$@)
 # COFF
 bn86-cof.s: asm/bn-586.pl ../perlasm/x86asm.pl
        (cd asm; $(PERL) bn-586.pl coff $(CFLAGS) > ../$@)
 co86-cof.s: asm/co-586.pl ../perlasm/x86asm.pl
        (cd asm; $(PERL) co-586.pl coff $(CFLAGS) > ../$@)
+mo86-cof.s: asm/x86-mont.pl ../perlasm/x86asm.pl
+       (cd asm; $(PERL) x86-mont.pl coff $(CFLAGS) > ../$@)
 # a.out
 bn86-out.s: asm/bn-586.pl ../perlasm/x86asm.pl
        (cd asm; $(PERL) bn-586.pl a.out $(CFLAGS) > ../$@)
 co86-out.s: asm/co-586.pl ../perlasm/x86asm.pl
        (cd asm; $(PERL) co-586.pl a.out $(CFLAGS) > ../$@)
+mo86-out.s: asm/x86-mont.pl ../perlasm/x86asm.pl
+       (cd asm; $(PERL) x86-mont.pl a.out $(CFLAGS) > ../$@)
 
 sparcv8.o:     asm/sparcv8.S
        $(CC) $(CFLAGS) -c asm/sparcv8.S
@@ -91,6 +97,8 @@ bn-mips3.o:   asm/mips3.s
 
 x86_64-gcc.o:  asm/x86_64-gcc.c
        $(CC) $(CFLAGS) -c -o $@ asm/x86_64-gcc.c
+x86_64-mont.s: asm/x86_64-mont.pl
+       $(PERL) asm/x86_64-mont.pl $@
 
 bn-ia64.s:     asm/ia64.S
        $(CC) $(CFLAGS) -E asm/ia64.S > $@
@@ -112,6 +120,9 @@ aix_ppc32.s: asm/ppc.pl;    $(PERL) asm/ppc.pl $@
 aix_ppc64.s: asm/ppc.pl;       $(PERL) asm/ppc.pl $@
 osx_ppc32.s: asm/ppc.pl;       $(PERL) $< $@
 
+# GNU make "catch all"
+%-mont.s:      asm/%-mont.pl;  $(PERL) $< $(CFLAGS) > $@
+
 files:
        $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
 
index ad4ca7ff305a8e9c274464c8c67f37b7a86edabd..27ac4397a15172016e093f924e9d9b7ab997442a 100644 (file)
@@ -481,6 +481,7 @@ BN_ULONG bn_add_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
        int cl, int dl);
 BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
        int cl, int dl);
+int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);
 
 #ifdef  __cplusplus
 }
index 30bdeabcd5d58486fe0c9276d3b7e219ecc92a55..a8ec134145acf6abb8774a15b870a680a6fb53f5 100644 (file)
@@ -127,6 +127,21 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
        {
        BIGNUM *tmp;
        int ret=0;
+#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)
+       int num = mont->N.top;
+
+       if (num>1 && a->top==num && b->top==num)
+               {
+               if (bn_wexpand(r,num) == NULL) return(0);
+               if (bn_mul_mont(r->d,a->d,b->d,mont->N.d,&mont->n0,num))
+                       {
+                       r->neg = a->neg^b->neg;
+                       r->top = num;
+                       bn_correct_top(r);
+                       return(1);
+                       }
+               }
+#endif
 
        BN_CTX_start(ctx);
        tmp = BN_CTX_get(ctx);