Fix bn_cmp_part_words() and move it to bn_lib.c.

This commit is contained in:
Ulf Möller 2000-12-02 07:28:43 +00:00
parent 0826c85f4c
commit 52a1bab2d9
3 changed files with 29 additions and 13 deletions

View File

@ -402,6 +402,8 @@ void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp);
void bn_sqr_comba8(BN_ULONG *r,const BN_ULONG *a); void bn_sqr_comba8(BN_ULONG *r,const BN_ULONG *a);
void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a); void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a);
int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n);
int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
int cl, int dl);
void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t); void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t);
void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,
int tn, int n,BN_ULONG *t); int tn, int n,BN_ULONG *t);

View File

@ -777,3 +777,28 @@ int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
} }
return(0); return(0);
} }
int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
int cl, int dl)
{
int n,i;
n = cl-1;
if (dl < 0)
{
for (i=-dl; i>0; i++)
{
if (b[n+i] != 0)
return -1; /* a < b */
}
}
if (dl > 0)
{
for (i=dl; i>0; i--)
{
if (a[n+i] != 0)
return 1; /* a > b */
}
}
return bn_cmp_words(a,b,cl);
}

View File

@ -61,8 +61,8 @@
#include "cryptlib.h" #include "cryptlib.h"
#include "bn_lcl.h" #include "bn_lcl.h"
/* Here follows specialised variants of bn_cmp_words(), bn_add_words() and /* Here follows specialised variants of bn_add_words() and
bn_sub_words(). They all have the property performing operations on bn_sub_words(). They have the property performing operations on
arrays of different sizes. The sizes of those arrays is expressed through arrays of different sizes. The sizes of those arrays is expressed through
cl, which is the common length ( basicall, min(len(a),len(b)) ), and dl, cl, which is the common length ( basicall, min(len(a),len(b)) ), and dl,
which is the delta between the two lengths, calculated as len(a)-len(b). which is the delta between the two lengths, calculated as len(a)-len(b).
@ -71,17 +71,6 @@
These functions should probably end up in bn_asm.c as soon as there are These functions should probably end up in bn_asm.c as soon as there are
assembler counterparts for the systems that use assembler files. */ assembler counterparts for the systems that use assembler files. */
int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
int cl, int dl)
{
if (dl < 0) /* a < b */
return -1;
if (dl > 0) /* a > b */
return 1;
return bn_cmp_words(a,b,cl);
}
BN_ULONG bn_sub_part_words(BN_ULONG *r, BN_ULONG bn_sub_part_words(BN_ULONG *r,
const BN_ULONG *a, const BN_ULONG *b, const BN_ULONG *a, const BN_ULONG *b,
int cl, int dl) int cl, int dl)