diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-07-23 16:43:57 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-07-23 16:43:57 +0000 |
commit | dd6bb6c6b8298ebeff2d1882becb36580b969d6f (patch) | |
tree | 3d922a5791e7e34e2b041ea5f3489360bfa798e1 /src/libbiguint | |
parent | 122f9363682e5de8ce4056c4c05c1eaf8935cf19 (diff) | |
download | skalibs-dd6bb6c6b8298ebeff2d1882becb36580b969d6f.tar.xz |
New 2.11.0.0 branch with several modifications
- libbiguint removed
- cdb_make changed to cdbmake (because different ui)
- cdb redesigned
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libbiguint')
28 files changed, 0 insertions, 486 deletions
diff --git a/src/libbiguint/bu_addc.c b/src/libbiguint/bu_addc.c deleted file mode 100644 index b6d1ccb..0000000 --- a/src/libbiguint/bu_addc.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_addc (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, int carry) -{ - unsigned int i = 0 ; - for (; i < cn ; i++) - { - uint32_t ai = (i < an) ? a[i] : 0 ; - uint32_t bi = (i < bn) ? b[i] : 0 ; - uint32_t ci = ai + bi + carry ; - carry = (carry || bi) && (ci < ai) ; - c[i] = ci ; - } - return carry ? (errno = EOVERFLOW, 0) : 1 ; -} diff --git a/src/libbiguint/bu_addmod.c b/src/libbiguint/bu_addmod.c deleted file mode 100644 index 4ebe2f7..0000000 --- a/src/libbiguint/bu_addmod.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_addmod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) -{ - if (!bu_add(c, cn, a, an, b, bn)) return 0 ; - if (bu_cmp(c, cn, m, mn) >= 0) bu_sub(c, cn, c, cn, m, mn) ; - return 1 ; -} diff --git a/src/libbiguint/bu_cmp.c b/src/libbiguint/bu_cmp.c deleted file mode 100644 index 0c87e92..0000000 --- a/src/libbiguint/bu_cmp.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_cmp (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - an = bu_len(a, an) ; - bn = bu_len(b, bn) ; - if (an < bn) return -1 ; - if (an > bn) return 1 ; - while (bn--) - { - if (a[bn] < b[bn]) return -1 ; - if (a[bn] > b[bn]) return 1 ; - } - return 0 ; -} diff --git a/src/libbiguint/bu_copy.c b/src/libbiguint/bu_copy.c deleted file mode 100644 index 0c64417..0000000 --- a/src/libbiguint/bu_copy.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_copy (uint32_t *b, unsigned int bn, uint32_t const *a, unsigned int an) -{ - unsigned int alen = bu_len(a, an) ; - if (bn < alen) - { - bu_copy_internal(b, a, bn) ; - return (errno = EOVERFLOW, 0) ; - } - bu_copy_internal(b, a, alen) ; - bu_zero(b + alen, bn - alen) ; - return 1 ; -} diff --git a/src/libbiguint/bu_copy_internal.c b/src/libbiguint/bu_copy_internal.c deleted file mode 100644 index 8de4d5e..0000000 --- a/src/libbiguint/bu_copy_internal.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -void bu_copy_internal (uint32_t *b, uint32_t const *a, unsigned int n) -{ - while (n--) b[n] = a[n] ; -} diff --git a/src/libbiguint/bu_div.c b/src/libbiguint/bu_div.c deleted file mode 100644 index a5b6986..0000000 --- a/src/libbiguint/bu_div.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_div (uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn, uint32_t *r, unsigned int rn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - if (!blen) return (errno = EDOM, 0) ; - else - { - uint32_t qq[alen] ; - uint32_t rr[alen] ; - int qh, rh ; - bu_copy_internal(rr, a, alen) ; - bu_div_internal(rr, alen, b, blen, qq, alen) ; - qh = bu_copy(q, qn, qq, alen) ; - rh = bu_copy(r, rn, rr, alen) ; - return qh && rh ; - } -} diff --git a/src/libbiguint/bu_div_internal.c b/src/libbiguint/bu_div_internal.c deleted file mode 100644 index 0765a99..0000000 --- a/src/libbiguint/bu_div_internal.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -/* - q = a/b, a = a mod b. Assumes b != 0 and qn >= alen - blen + 1. -*/ - -void bu_div_internal (uint32_t *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t *q, unsigned int qn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - bu_zero(q, qn) ; - if (alen < blen) return ; - { - uint32_t bb[alen + 1] ; - unsigned int i = 1 + ((alen - blen) << 5) ; - bu_zero(bb, alen - blen) ; - bu_copy_internal(bb + alen - blen, b, blen) ; - bb[alen] = 0 ; - - while (bu_cmp(a, alen, bb, alen+1) >= 0) - { - bu_slb(bb + alen - blen, blen + 1) ; - i++ ; - } - while (i && (bu_cmp(a, alen, bb, alen+1) < 0)) - { - bu_srb(bb, alen + 1) ; - i-- ; - } - - while (i--) - { - bu_slb(q, alen - blen + 1) ; - if (bu_cmp(a, alen, bb, alen) >= 0) - { - bu_sub(a, alen, a, alen, bb, alen) ; - q[0] |= 1 ; - } - bu_srb(bb, alen) ; - } - } -} diff --git a/src/libbiguint/bu_divmod.c b/src/libbiguint/bu_divmod.c deleted file mode 100644 index 17b6b7b..0000000 --- a/src/libbiguint/bu_divmod.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/biguint.h> - -/* - q = y/x mod m. -*/ - -int bu_divmod (uint32_t *q, unsigned int qn, uint32_t const *y, unsigned int yn, uint32_t const *x, unsigned int xn, uint32_t const *m, unsigned int mn) -{ - unsigned int ylen = bu_len(y, yn) ; - unsigned int xlen = bu_len(x, xn) ; - unsigned int mlen = bu_len(m, mn) ; - unsigned int n = ylen ; - if (n < xlen) n = xlen ; - if (n < mlen) n = mlen ; - if (!n) return (errno = EDOM, 0) ; - { - uint32_t yy[n] ; - uint32_t xx[n] ; - uint32_t mm[n] ; - bu_gcd(xx, n, x, xlen, m, mlen) ; - if ((xx[0] != 1) || (bu_len(xx, n) != 1)) return (errno = EDOM, 0) ; - bu_copy_internal(yy, y, ylen) ; bu_zero(yy+ylen, n-ylen) ; - bu_copy_internal(xx, x, xlen) ; bu_zero(xx+xlen, n-xlen) ; - bu_copy_internal(mm, m, mlen) ; bu_zero(mm+mlen, n-mlen) ; - bu_divmod_internal(yy, xx, mm, n) ; - return bu_copy(q, qn, yy, n) ; - } -} diff --git a/src/libbiguint/bu_divmod_internal.c b/src/libbiguint/bu_divmod_internal.c deleted file mode 100644 index afb8ccc..0000000 --- a/src/libbiguint/bu_divmod_internal.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -/* - u = u/a mod m. a and m must be relatively prime - otherwise, infinite loop. - a is not immutable. - Original idea by Sheueling Chang Shantz of Sun Research. -*/ - -void bu_divmod_internal (uint32_t *u, uint32_t *a, uint32_t const *m, unsigned int n) -{ - uint32_t bb[n] ; uint32_t *b = bb ; - uint32_t vv[n] ; uint32_t *v = vv ; - bu_copy_internal(b, m, n) ; - bu_zero(v, n) ; - - /*** XXX: this iterates like mad, should probably be optimized more */ - for (;;) - { - while (!(a[0] & 1)) - { - bu_srb(a, n) ; - if (u[0] & 1) bu_add(u, n, u, n, m, n) ; - bu_srb(u, n) ; - } - if ((a[0] == 1) && (bu_len(a, n) == 1)) break ; - if (bu_cmp(a, n, b, n) < 0) - { - uint32_t *t = a ; a = b ; b = t ; - t = u ; u = v ; v = t ; - } - bu_add(a, n, a, n, b, n) ; - bu_add(u, n, u, n, v, n) ; - } -} diff --git a/src/libbiguint/bu_fmt.c b/src/libbiguint/bu_fmt.c deleted file mode 100644 index 9402621..0000000 --- a/src/libbiguint/bu_fmt.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -size_t bu_fmt (char *s, uint32_t const *x, unsigned int n) -{ - size_t len = 0 ; - while (n--) - { - char fmt[8] ; - size_t i = uint32_xfmt(fmt, x[n]) ; - memcpy(s+len, "00000000", 8-i) ; - memcpy(s+len+8-i, fmt, i) ; - len += 8 ; - } - return len ; -} diff --git a/src/libbiguint/bu_gcd.c b/src/libbiguint/bu_gcd.c deleted file mode 100644 index 738091e..0000000 --- a/src/libbiguint/bu_gcd.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_gcd (uint32_t *r, unsigned int rn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - if (bu_cmp(a, an, b, bn) < 0) - { - uint32_t const *t = a ; - unsigned int tn = an ; - a = b ; an = bn ; - b = t ; bn = tn ; - } - { - uint32_t trash[an] ; - uint32_t aa[an] ; - uint32_t bb[an] ; - uint32_t *aaa = aa, *bbb = bb ; - bu_copy_internal(aa, a, an) ; - bu_copy_internal(bb, b, bn) ; - bu_zero(bb+bn, an-bn) ; - - while (bu_len(bbb, an)) - { - uint32_t *ttt = aaa ; - bu_div_internal(aaa, an, bbb, an, trash, an) ; - aaa = bbb ; - bbb = ttt ; - } - return bu_copy(r, rn, aaa, an) ; - } -} diff --git a/src/libbiguint/bu_invmod.c b/src/libbiguint/bu_invmod.c deleted file mode 100644 index f9ae9e2..0000000 --- a/src/libbiguint/bu_invmod.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -/* x^-1 mod m. */ - -int bu_invmod (uint32_t *x, unsigned int xn, uint32_t const *m, unsigned int mn) -{ - uint32_t const one = 1 ; - return bu_divmod(x, xn, &one, 1, x, xn, m, mn) ; -} diff --git a/src/libbiguint/bu_len.c b/src/libbiguint/bu_len.c deleted file mode 100644 index 6e66b17..0000000 --- a/src/libbiguint/bu_len.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -unsigned int bu_len (uint32_t const *a, unsigned int n) -{ - while (n--) if (a[n]) return n+1 ; - return 0 ; -} diff --git a/src/libbiguint/bu_mod.c b/src/libbiguint/bu_mod.c deleted file mode 100644 index ca16af0..0000000 --- a/src/libbiguint/bu_mod.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_mod (uint32_t *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - uint32_t q[an] ; - return bu_div(a, an, b, bn, q, an, a, an) ; -} diff --git a/src/libbiguint/bu_mul.c b/src/libbiguint/bu_mul.c deleted file mode 100644 index 16043fd..0000000 --- a/src/libbiguint/bu_mul.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ISC license. */ - -#include <stdint.h> -#include <skalibs/uint64.h> -#include <skalibs/biguint.h> - - /* No Karatsuba. Keep it simple, stupid. */ - -int bu_mul (uint32_t *x, unsigned int xn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - uint32_t c[alen + blen] ; - unsigned int i = 0 ; - bu_zero(c, alen + blen) ; - for (; i < alen ; i++) - { - uint32_t carry = 0 ; - unsigned int j = 0 ; - for (; j < blen ; j++) - { - uint64_t t = a[i] ; - t *= b[j] ; - t += c[i+j] ; - t += carry ; - c[i+j] = (uint32_t)t ; - carry = (uint32_t)(t >> 32) ; - } - c[i+j] += carry ; - } - return bu_copy(x, xn, c, alen+blen) ; -} diff --git a/src/libbiguint/bu_mulmod.c b/src/libbiguint/bu_mulmod.c deleted file mode 100644 index 59ed3fc..0000000 --- a/src/libbiguint/bu_mulmod.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - - /* Nope, no Montgomery either. */ - -int bu_mulmod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) -{ - unsigned int alen = bu_len(a, an) ; - unsigned int blen = bu_len(b, bn) ; - uint32_t x[alen+blen] ; - if (!bu_mul(x, alen+blen, a, alen, b, blen)) return 0 ; - if (!bu_mod(x, alen+blen, m, mn)) return 0 ; - return bu_copy(c, cn, x, mn) ; -} diff --git a/src/libbiguint/bu_pack.c b/src/libbiguint/bu_pack.c deleted file mode 100644 index b43ab04..0000000 --- a/src/libbiguint/bu_pack.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_pack (char *s, uint32_t const *a, unsigned int n) -{ - while (n--) uint32_pack(s + (n<<2), a[n]) ; -} diff --git a/src/libbiguint/bu_pack_big.c b/src/libbiguint/bu_pack_big.c deleted file mode 100644 index caca082..0000000 --- a/src/libbiguint/bu_pack_big.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_pack_big (char *s, uint32_t const *a, unsigned int n) -{ - unsigned int i = 0 ; - for (; i < n ; i++) uint32_pack_big(s + (i<<2), a[n-1-i]) ; -} diff --git a/src/libbiguint/bu_scan.c b/src/libbiguint/bu_scan.c deleted file mode 100644 index 8d4ecd0..0000000 --- a/src/libbiguint/bu_scan.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/bitarray.h> -#include <skalibs/biguint.h> - -int bu_scan (char const *s, size_t len, uint32_t *x, unsigned int xn, size_t zeron) -{ - size_t n = bitarray_div8(zeron) ; - if (xn < n) return (errno = EOVERFLOW, 0) ; - bu_scan_internal(s, len, x) ; - bu_zero(x + n, xn - n) ; - return 1 ; -} diff --git a/src/libbiguint/bu_scan_internal.c b/src/libbiguint/bu_scan_internal.c deleted file mode 100644 index d7a75b6..0000000 --- a/src/libbiguint/bu_scan_internal.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_scan_internal (char const *s, size_t len, uint32_t *x) -{ - char fmt[9] = "\0\0\0\0\0\0\0\0" ; - size_t i = 0 ; - if (len & 7) - { - memcpy(fmt, s, len & 7) ; - uint32_xscan(fmt, x + (len >> 3)) ; - } - for (; i < (len >> 3) ; i++) - { - memcpy(fmt, s + len - 8 - (i << 3), 8) ; - uint32_xscan(fmt, x + i) ; - } -} diff --git a/src/libbiguint/bu_scanlen.c b/src/libbiguint/bu_scanlen.c deleted file mode 100644 index ed93fa3..0000000 --- a/src/libbiguint/bu_scanlen.c +++ /dev/null @@ -1,12 +0,0 @@ -/* ISC license. */ - -#include <skalibs/fmtscan.h> -#include <skalibs/biguint.h> - -size_t bu_scanlen (char const *s, size_t *zeron) -{ - size_t n = ucharn_findlen(s) ; - *zeron = n ; - while (*s == '0') { s++ ; (*zeron)-- ; } - return n ; -} diff --git a/src/libbiguint/bu_slbc.c b/src/libbiguint/bu_slbc.c deleted file mode 100644 index 13d9b6d..0000000 --- a/src/libbiguint/bu_slbc.c +++ /dev/null @@ -1,16 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_slbc (uint32_t *a, unsigned int n, int carry) -{ - unsigned int i = 0 ; - carry = !!carry ; - for (; i < n ; i++) - { - int c = a[i] >> 31 ; - a[i] = (a[i] << 1) | carry ; - carry = c ; - } - return carry ; -} diff --git a/src/libbiguint/bu_srbc.c b/src/libbiguint/bu_srbc.c deleted file mode 100644 index b23186b..0000000 --- a/src/libbiguint/bu_srbc.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -int bu_srbc (uint32_t *a, unsigned int n, int carry) -{ - while (n--) - { - int c = a[n] & 1 ; - a[n] = (a[n] >> 1) | (carry ? 0x80000000U : 0) ; - carry = c ; - } - return carry ; -} diff --git a/src/libbiguint/bu_subc.c b/src/libbiguint/bu_subc.c deleted file mode 100644 index 63147b0..0000000 --- a/src/libbiguint/bu_subc.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ISC license. */ - -#include <skalibs/bsdsnowflake.h> -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_subc (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, int carry) -{ - unsigned int i = 0 ; - for (; i < cn ; i++) - { - uint32_t ai = (i < an) ? a[i] : 0 ; - uint32_t bi = (i < bn) ? b[i] : 0 ; - uint32_t ci = ai - bi - carry ; - carry = (carry || bi) && (ci > ai) ; - c[i] = ci ; - } - return carry ? (errno = EOVERFLOW, 0) : 1 ; -} diff --git a/src/libbiguint/bu_submod.c b/src/libbiguint/bu_submod.c deleted file mode 100644 index 98048e1..0000000 --- a/src/libbiguint/bu_submod.c +++ /dev/null @@ -1,11 +0,0 @@ -/* ISC license. */ - -#include <errno.h> -#include <skalibs/biguint.h> - -int bu_submod (uint32_t *c, unsigned int cn, uint32_t const *a, unsigned int an, uint32_t const *b, unsigned int bn, uint32_t const *m, unsigned int mn) -{ - if (!bu_sub(c, cn, a, an, b, bn) && bu_add(c, cn, c, cn, m, mn)) - return (errno = EDOM, 0) ; - return 1 ; -} diff --git a/src/libbiguint/bu_unpack.c b/src/libbiguint/bu_unpack.c deleted file mode 100644 index 0c93277..0000000 --- a/src/libbiguint/bu_unpack.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_unpack (char const *s, uint32_t *a, unsigned int n) -{ - while (n--) uint32_unpack(s + (n<<2), a + n) ; -} diff --git a/src/libbiguint/bu_unpack_big.c b/src/libbiguint/bu_unpack_big.c deleted file mode 100644 index 97f37cf..0000000 --- a/src/libbiguint/bu_unpack_big.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ISC license. */ - -#include <skalibs/uint32.h> -#include <skalibs/biguint.h> - -void bu_unpack_big (char const *s, uint32_t *a, unsigned int n) -{ - unsigned int i = 0 ; - for (; i < n ; i++) uint32_unpack_big(s + (i<<2), a + n - 1 - i) ; -} diff --git a/src/libbiguint/bu_zero.c b/src/libbiguint/bu_zero.c deleted file mode 100644 index ab87752..0000000 --- a/src/libbiguint/bu_zero.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ISC license. */ - -#include <skalibs/biguint.h> - -void bu_zero (uint32_t *z, unsigned int n) -{ - while (n--) z[n] = 0 ; -} |