更新libclamav库1.0.0版本
This commit is contained in:
46
clamav/libclamav/tomsfastmath/bit/fp_cnt_lsb.c
Normal file
46
clamav/libclamav/tomsfastmath/bit/fp_cnt_lsb.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
static const int lnz[16] = {
|
||||
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
|
||||
};
|
||||
|
||||
/* Counts the number of lsbs which are zero before the first zero bit */
|
||||
int fp_cnt_lsb(fp_int *a)
|
||||
{
|
||||
int x;
|
||||
fp_digit q, qq;
|
||||
|
||||
/* easy out */
|
||||
if (fp_iszero(a) == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* scan lower digits until non-zero */
|
||||
for (x = 0; x < a->used && a->dp[x] == 0; x++);
|
||||
q = a->dp[x];
|
||||
x *= DIGIT_BIT;
|
||||
|
||||
/* now scan this digit until a 1 is found */
|
||||
if ((q & 1) == 0) {
|
||||
do {
|
||||
qq = q & 15;
|
||||
x += lnz[qq];
|
||||
q >>= 4;
|
||||
} while (qq == 0);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
36
clamav/libclamav/tomsfastmath/bit/fp_count_bits.c
Normal file
36
clamav/libclamav/tomsfastmath/bit/fp_count_bits.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
int fp_count_bits (fp_int * a)
|
||||
{
|
||||
int r;
|
||||
fp_digit q;
|
||||
|
||||
/* shortcut */
|
||||
if (a->used == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get number of digits and add that */
|
||||
r = (a->used - 1) * DIGIT_BIT;
|
||||
|
||||
/* take the last digit and count the bits in it */
|
||||
q = a->dp[a->used - 1];
|
||||
while (q > ((fp_digit) 0)) {
|
||||
++r;
|
||||
q >>= ((fp_digit) 1);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
53
clamav/libclamav/tomsfastmath/bit/fp_div_2.c
Normal file
53
clamav/libclamav/tomsfastmath/bit/fp_div_2.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
/* b = a/2 */
|
||||
void fp_div_2(fp_int * a, fp_int * b)
|
||||
{
|
||||
int x, oldused;
|
||||
|
||||
oldused = b->used;
|
||||
b->used = a->used;
|
||||
{
|
||||
register fp_digit r, rr, *tmpa, *tmpb;
|
||||
|
||||
/* source alias */
|
||||
tmpa = a->dp + b->used - 1;
|
||||
|
||||
/* dest alias */
|
||||
tmpb = b->dp + b->used - 1;
|
||||
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = b->used - 1; x >= 0; x--) {
|
||||
/* get the carry for the next iteration */
|
||||
rr = *tmpa & 1;
|
||||
|
||||
/* shift the current digit, add in carry and store */
|
||||
*tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
|
||||
|
||||
/* forward carry to next iteration */
|
||||
r = rr;
|
||||
}
|
||||
|
||||
/* zero excess digits */
|
||||
tmpb = b->dp + b->used;
|
||||
for (x = b->used; x < oldused; x++) {
|
||||
*tmpb++ = 0;
|
||||
}
|
||||
}
|
||||
b->sign = a->sign;
|
||||
fp_clamp (b);
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
79
clamav/libclamav/tomsfastmath/bit/fp_div_2d.c
Normal file
79
clamav/libclamav/tomsfastmath/bit/fp_div_2d.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
/* c = a / 2**b */
|
||||
void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d)
|
||||
{
|
||||
fp_digit D, r, rr;
|
||||
int x;
|
||||
fp_int t;
|
||||
|
||||
/* if the shift count is <= 0 then we do no work */
|
||||
if (b <= 0) {
|
||||
fp_copy (a, c);
|
||||
if (d != NULL) {
|
||||
fp_zero (d);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
fp_init(&t);
|
||||
|
||||
/* get the remainder */
|
||||
if (d != NULL) {
|
||||
fp_mod_2d (a, b, &t);
|
||||
}
|
||||
|
||||
/* copy */
|
||||
fp_copy(a, c);
|
||||
|
||||
/* shift by as many digits in the bit count */
|
||||
if (b >= (int)DIGIT_BIT) {
|
||||
fp_rshd (c, b / DIGIT_BIT);
|
||||
}
|
||||
|
||||
/* shift any bit count < DIGIT_BIT */
|
||||
D = (fp_digit) (b % DIGIT_BIT);
|
||||
if (D != 0) {
|
||||
register fp_digit *tmpc, mask, shift;
|
||||
|
||||
/* mask */
|
||||
mask = (((fp_digit)1) << D) - 1;
|
||||
|
||||
/* shift for lsb */
|
||||
shift = DIGIT_BIT - D;
|
||||
|
||||
/* alias */
|
||||
tmpc = c->dp + (c->used - 1);
|
||||
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = c->used - 1; x >= 0; x--) {
|
||||
/* get the lower bits of this word in a temp */
|
||||
rr = *tmpc & mask;
|
||||
|
||||
/* shift the current word and mix in the carry bits from the previous word */
|
||||
*tmpc = (*tmpc >> D) | (r << shift);
|
||||
--tmpc;
|
||||
|
||||
/* set the carry to the carry bits of the current word found above */
|
||||
r = rr;
|
||||
}
|
||||
}
|
||||
fp_clamp (c);
|
||||
if (d != NULL) {
|
||||
fp_copy (&t, d);
|
||||
}
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
38
clamav/libclamav/tomsfastmath/bit/fp_lshd.c
Normal file
38
clamav/libclamav/tomsfastmath/bit/fp_lshd.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
void fp_lshd(fp_int *a, int x)
|
||||
{
|
||||
int y;
|
||||
|
||||
/* move up and truncate as required */
|
||||
y = MIN(a->used + x - 1, (int)(FP_SIZE-1));
|
||||
|
||||
/* store new size */
|
||||
a->used = y + 1;
|
||||
|
||||
/* move digits */
|
||||
for (; y >= x; y--) {
|
||||
a->dp[y] = a->dp[y-x];
|
||||
}
|
||||
|
||||
/* zero lower digits */
|
||||
for (; y >= 0; y--) {
|
||||
a->dp[y] = 0;
|
||||
}
|
||||
|
||||
/* clamp digits */
|
||||
fp_clamp(a);
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
42
clamav/libclamav/tomsfastmath/bit/fp_mod_2d.c
Normal file
42
clamav/libclamav/tomsfastmath/bit/fp_mod_2d.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
/* c = a mod 2**d */
|
||||
void fp_mod_2d(fp_int *a, int b, fp_int *c)
|
||||
{
|
||||
int x;
|
||||
|
||||
/* zero if count less than or equal to zero */
|
||||
if (b <= 0) {
|
||||
fp_zero(c);
|
||||
return;
|
||||
}
|
||||
|
||||
/* get copy of input */
|
||||
fp_copy(a, c);
|
||||
|
||||
/* if 2**d is larger than we just return */
|
||||
if (b >= (DIGIT_BIT * a->used)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* zero digits above the last digit of the modulus */
|
||||
for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) {
|
||||
c->dp[x] = 0;
|
||||
}
|
||||
/* clear the digit that is not completely outside/inside the modulus */
|
||||
c->dp[b / DIGIT_BIT] &= ~((fp_digit)0) >> (DIGIT_BIT - b);
|
||||
fp_clamp (c);
|
||||
}
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
40
clamav/libclamav/tomsfastmath/bit/fp_rshd.c
Normal file
40
clamav/libclamav/tomsfastmath/bit/fp_rshd.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm_private.h>
|
||||
|
||||
void fp_rshd(fp_int *a, int x)
|
||||
{
|
||||
int y;
|
||||
|
||||
/* too many digits just zero and return */
|
||||
if (x >= a->used) {
|
||||
fp_zero(a);
|
||||
return;
|
||||
}
|
||||
|
||||
/* shift */
|
||||
for (y = 0; y < a->used - x; y++) {
|
||||
a->dp[y] = a->dp[y+x];
|
||||
}
|
||||
|
||||
/* zero rest */
|
||||
for (; y < a->used; y++) {
|
||||
a->dp[y] = 0;
|
||||
}
|
||||
|
||||
/* decrement count */
|
||||
a->used -= x;
|
||||
fp_clamp(a);
|
||||
}
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
Reference in New Issue
Block a user