summaryrefslogtreecommitdiffabout
path: root/pwmanager/libcrypt/mpi/generic
Unidiff
Diffstat (limited to 'pwmanager/libcrypt/mpi/generic') (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/libcrypt/mpi/generic/Manifest29
-rw-r--r--pwmanager/libcrypt/mpi/generic/distfiles11
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpi-asm-defs.h10
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-add1.c65
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-lshift.c68
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-mul1.c62
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-mul2.c68
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-mul3.c68
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-rshift.c67
-rw-r--r--pwmanager/libcrypt/mpi/generic/mpih-sub1.c66
-rw-r--r--pwmanager/libcrypt/mpi/generic/udiv-w-sdiv.c133
11 files changed, 647 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/mpi/generic/Manifest b/pwmanager/libcrypt/mpi/generic/Manifest
new file mode 100644
index 0000000..c429fde
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/Manifest
@@ -0,0 +1,29 @@
1# Manifest - checksums
2# Copyright 2003 Free Software Foundation, Inc.
3#
4# This file is part of Libgcrypt.
5#
6# Libgcrypt is free software; you can redistribute it and/or modify
7# it under the terms of the GNU Lesser general Public License as
8# published by the Free Software Foundation; either version 2.1 of
9# the License, or (at your option) any later version.
10#
11# Libgcrypt is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
20mpih-add1.c iQCVAwUAP+Lj2DE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fzQDFqYuT0ayuteoOR4B5NICbE==nLSh
diff --git a/pwmanager/libcrypt/mpi/generic/distfiles b/pwmanager/libcrypt/mpi/generic/distfiles
new file mode 100644
index 0000000..9810eef
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/distfiles
@@ -0,0 +1,11 @@
1Manifest
2mpih-add1.c
3mpih-mul1.c
4mpih-mul2.c
5mpih-mul3.c
6mpih-lshift.c
7mpih-rshift.c
8mpih-sub1.c
9udiv-w-sdiv.c
10mpi-asm-defs.h
11
diff --git a/pwmanager/libcrypt/mpi/generic/mpi-asm-defs.h b/pwmanager/libcrypt/mpi/generic/mpi-asm-defs.h
new file mode 100644
index 0000000..13424e2
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpi-asm-defs.h
@@ -0,0 +1,10 @@
1/* This file defines some basic constants for the MPI machinery. We
2 * need to define the types on a per-CPU basis, so it is done with
3 * this file here. */
4#define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG)
5
6
7
8
9
10
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-add1.c b/pwmanager/libcrypt/mpi/generic/mpih-add1.c
new file mode 100644
index 0000000..4a84df6
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-add1.c
@@ -0,0 +1,65 @@
1/* mpihelp-add_1.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1997, 1998,
3 * 2000, 2002 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 *
21 * Note: This code is heavily based on the GNU MP Library.
22 * Actually it's the same code with only minor changes in the
23 * way the data is stored; this is to support the abstraction
24 * of an optional secure memory allocation which may be used
25 * to avoid revealing of sensitive data due to paging etc.
26 */
27
28#include <config.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "mpi-internal.h"
32#include "longlong.h"
33
34mpi_limb_t
35_gcry_mpih_add_n (mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
36 mpi_ptr_t s2_ptr, mpi_size_t size)
37{
38 mpi_limb_t x, y, cy;
39 mpi_size_t j;
40
41 /* The loop counter and index J goes from -SIZE to -1. This way
42 the loop becomes faster. */
43 j = -size;
44
45 /* Offset the base pointers to compensate for the negative indices. */
46 s1_ptr -= j;
47 s2_ptr -= j;
48 res_ptr -= j;
49
50 cy = 0;
51 do
52 {
53 y = s2_ptr[j];
54 x = s1_ptr[j];
55 y += cy; /* add previous carry to one addend */
56 cy = y < cy; /* get out carry from that addition */
57 y += x; /* add other addend */
58 cy += y < x; /* get out carry from that add, combine */
59 res_ptr[j] = y;
60 }
61 while ( ++j );
62
63 return cy;
64}
65
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-lshift.c b/pwmanager/libcrypt/mpi/generic/mpih-lshift.c
new file mode 100644
index 0000000..f48c12c
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-lshift.c
@@ -0,0 +1,68 @@
1/* mpi-lshift.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1998, 2001, 2002 Free Software Foundation, Inc.
3 *
4 * This file is part of Libgcrypt.
5 *
6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 *
20 * Note: This code is heavily based on the GNU MP Library.
21 * Actually it's the same code with only minor changes in the
22 * way the data is stored; this is to support the abstraction
23 * of an optional secure memory allocation which may be used
24 * to avoid revealing of sensitive data due to paging etc.
25 */
26
27#include <config.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include "mpi-internal.h"
31
32/* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
33 * and store the USIZE least significant digits of the result at WP.
34 * Return the bits shifted out from the most significant digit.
35 *
36 * Argument constraints:
37 * 1. 0 < CNT < BITS_PER_MP_LIMB
38 * 2. If the result is to be written over the input, WP must be >= UP.
39 */
40
41mpi_limb_t
42_gcry_mpih_lshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,
43 unsigned int cnt)
44{
45 mpi_limb_t high_limb, low_limb;
46 unsigned sh_1, sh_2;
47 mpi_size_t i;
48 mpi_limb_t retval;
49
50 sh_1 = cnt;
51 wp += 1;
52 sh_2 = BITS_PER_MPI_LIMB - sh_1;
53 i = usize - 1;
54 low_limb = up[i];
55 retval = low_limb >> sh_2;
56 high_limb = low_limb;
57 while ( --i >= 0 )
58 {
59 low_limb = up[i];
60 wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
61 high_limb = low_limb;
62 }
63 wp[i] = high_limb << sh_1;
64
65 return retval;
66}
67
68
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-mul1.c b/pwmanager/libcrypt/mpi/generic/mpih-mul1.c
new file mode 100644
index 0000000..0e8197d
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-mul1.c
@@ -0,0 +1,62 @@
1/* mpihelp-mul_1.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1997, 1998, 2001,
3 * 2002 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 *
21 * Note: This code is heavily based on the GNU MP Library.
22 * Actually it's the same code with only minor changes in the
23 * way the data is stored; this is to support the abstraction
24 * of an optional secure memory allocation which may be used
25 * to avoid revealing of sensitive data due to paging etc.
26 */
27
28#include <config.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "mpi-internal.h"
32#include "longlong.h"
33
34mpi_limb_t
35_gcry_mpih_mul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
36 mpi_limb_t s2_limb)
37{
38 mpi_limb_t cy_limb;
39 mpi_size_t j;
40 mpi_limb_t prod_high, prod_low;
41
42 /* The loop counter and index J goes from -S1_SIZE to -1. This way
43 * the loop becomes faster. */
44 j = -s1_size;
45
46 /* Offset the base pointers to compensate for the negative indices. */
47 s1_ptr -= j;
48 res_ptr -= j;
49
50 cy_limb = 0;
51 do
52 {
53 umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb );
54 prod_low += cy_limb;
55 cy_limb = (prod_low < cy_limb?1:0) + prod_high;
56 res_ptr[j] = prod_low;
57 }
58 while( ++j );
59
60 return cy_limb;
61}
62
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-mul2.c b/pwmanager/libcrypt/mpi/generic/mpih-mul2.c
new file mode 100644
index 0000000..3b75496
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-mul2.c
@@ -0,0 +1,68 @@
1/* mpih-mul2.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1997, 1998, 2001,
3 * 2002 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 *
21 * Note: This code is heavily based on the GNU MP Library.
22 * Actually it's the same code with only minor changes in the
23 * way the data is stored; this is to support the abstraction
24 * of an optional secure memory allocation which may be used
25 * to avoid revealing of sensitive data due to paging etc.
26 */
27
28#include <config.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "mpi-internal.h"
32#include "longlong.h"
33
34
35mpi_limb_t
36_gcry_mpih_addmul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
37 mpi_size_t s1_size, mpi_limb_t s2_limb)
38{
39 mpi_limb_t cy_limb;
40 mpi_size_t j;
41 mpi_limb_t prod_high, prod_low;
42 mpi_limb_t x;
43
44 /* The loop counter and index J goes from -SIZE to -1. This way
45 * the loop becomes faster. */
46 j = -s1_size;
47 res_ptr -= j;
48 s1_ptr -= j;
49
50 cy_limb = 0;
51 do
52 {
53 umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb );
54
55 prod_low += cy_limb;
56 cy_limb = (prod_low < cy_limb?1:0) + prod_high;
57
58 x = res_ptr[j];
59 prod_low = x + prod_low;
60 cy_limb += prod_low < x?1:0;
61 res_ptr[j] = prod_low;
62 }
63 while ( ++j );
64
65 return cy_limb;
66}
67
68
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-mul3.c b/pwmanager/libcrypt/mpi/generic/mpih-mul3.c
new file mode 100644
index 0000000..5e84f94
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-mul3.c
@@ -0,0 +1,68 @@
1/* mpih-mul3.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1997, 1998, 2001,
3 * 2002 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 *
21 * Note: This code is heavily based on the GNU MP Library.
22 * Actually it's the same code with only minor changes in the
23 * way the data is stored; this is to support the abstraction
24 * of an optional secure memory allocation which may be used
25 * to avoid revealing of sensitive data due to paging etc.
26 */
27
28#include <config.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "mpi-internal.h"
32#include "longlong.h"
33
34
35mpi_limb_t
36_gcry_mpih_submul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
37 mpi_size_t s1_size, mpi_limb_t s2_limb)
38{
39 mpi_limb_t cy_limb;
40 mpi_size_t j;
41 mpi_limb_t prod_high, prod_low;
42 mpi_limb_t x;
43
44 /* The loop counter and index J goes from -SIZE to -1. This way
45 * the loop becomes faster. */
46 j = -s1_size;
47 res_ptr -= j;
48 s1_ptr -= j;
49
50 cy_limb = 0;
51 do
52 {
53 umul_ppmm( prod_high, prod_low, s1_ptr[j], s2_limb);
54
55 prod_low += cy_limb;
56 cy_limb = (prod_low < cy_limb?1:0) + prod_high;
57
58 x = res_ptr[j];
59 prod_low = x - prod_low;
60 cy_limb += prod_low > x?1:0;
61 res_ptr[j] = prod_low;
62 }
63 while( ++j );
64
65 return cy_limb;
66}
67
68
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-rshift.c b/pwmanager/libcrypt/mpi/generic/mpih-rshift.c
new file mode 100644
index 0000000..e40794f
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-rshift.c
@@ -0,0 +1,67 @@
1/* mpih-rshift.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1998, 1999,
3 * 2000, 2001, 2002 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 *
21 * Note: This code is heavily based on the GNU MP Library.
22 * Actually it's the same code with only minor changes in the
23 * way the data is stored; this is to support the abstraction
24 * of an optional secure memory allocation which may be used
25 * to avoid revealing of sensitive data due to paging etc.
26 */
27
28#include <config.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "mpi-internal.h"
32
33
34/* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
35 * and store the USIZE least significant limbs of the result at WP.
36 * The bits shifted out to the right are returned.
37 *
38 * Argument constraints:
39 * 1. 0 < CNT < BITS_PER_MP_LIMB
40 * 2. If the result is to be written over the input, WP must be <= UP.
41 */
42
43mpi_limb_t
44_gcry_mpih_rshift( mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, unsigned cnt)
45{
46 mpi_limb_t high_limb, low_limb;
47 unsigned sh_1, sh_2;
48 mpi_size_t i;
49 mpi_limb_t retval;
50
51 sh_1 = cnt;
52 wp -= 1;
53 sh_2 = BITS_PER_MPI_LIMB - sh_1;
54 high_limb = up[0];
55 retval = high_limb << sh_2;
56 low_limb = high_limb;
57 for (i=1; i < usize; i++)
58 {
59 high_limb = up[i];
60 wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
61 low_limb = high_limb;
62 }
63 wp[i] = low_limb >> sh_1;
64
65 return retval;
66}
67
diff --git a/pwmanager/libcrypt/mpi/generic/mpih-sub1.c b/pwmanager/libcrypt/mpi/generic/mpih-sub1.c
new file mode 100644
index 0000000..e88821b
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/mpih-sub1.c
@@ -0,0 +1,66 @@
1/* mpihelp-add_2.c - MPI helper functions
2 * Copyright (C) 1994, 1996, 1997, 1998, 2001,
3 * 2002 Free Software Foundation, Inc.
4 *
5 * This file is part of Libgcrypt.
6 *
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 *
21 * Note: This code is heavily based on the GNU MP Library.
22 * Actually it's the same code with only minor changes in the
23 * way the data is stored; this is to support the abstraction
24 * of an optional secure memory allocation which may be used
25 * to avoid revealing of sensitive data due to paging etc.
26 */
27
28#include <config.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include "mpi-internal.h"
32#include "longlong.h"
33
34mpi_limb_t
35_gcry_mpih_sub_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
36 mpi_ptr_t s2_ptr, mpi_size_t size)
37{
38 mpi_limb_t x, y, cy;
39 mpi_size_t j;
40
41 /* The loop counter and index J goes from -SIZE to -1. This way
42 the loop becomes faster. */
43 j = -size;
44
45 /* Offset the base pointers to compensate for the negative indices. */
46 s1_ptr -= j;
47 s2_ptr -= j;
48 res_ptr -= j;
49
50 cy = 0;
51 do
52 {
53 y = s2_ptr[j];
54 x = s1_ptr[j];
55 y += cy; /* add previous carry to subtrahend */
56 cy = y < cy; /* get out carry from that addition */
57 y = x - y; /* main subtract */
58 cy += y > x; /* get out carry from the subtract, combine */
59 res_ptr[j] = y;
60 }
61 while( ++j );
62
63 return cy;
64}
65
66
diff --git a/pwmanager/libcrypt/mpi/generic/udiv-w-sdiv.c b/pwmanager/libcrypt/mpi/generic/udiv-w-sdiv.c
new file mode 100644
index 0000000..e80d98b
--- a/dev/null
+++ b/pwmanager/libcrypt/mpi/generic/udiv-w-sdiv.c
@@ -0,0 +1,133 @@
1/* mpih-w-sdiv -- implement udiv_qrnnd on machines with only signed
2 * division.
3 * Copyright (C) 1992, 1994, 1996, 1998, 2002 Free Software Foundation, Inc.
4 * Contributed by Peter L. Montgomery.
5 *
6 * This file is part of Libgcrypt.
7 *
8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * Libgcrypt is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 */
22
23#include <config.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include "mpi-internal.h"
27#include "longlong.h"
28
29
30#if 0 /* not yet ported to MPI */
31
32mpi_limb_t
33mpihelp_udiv_w_sdiv( mpi_limp_t *rp,
34 mpi_limp_t *a1,
35 mpi_limp_t *a0,
36 mpi_limp_t *d )
37{
38 mp_limb_t q, r;
39 mp_limb_t c0, c1, b1;
40
41 if ((mpi_limb_signed_t) d >= 0)
42 {
43 if (a1 < d - a1 - (a0 >> (BITS_PER_MP_LIMB - 1)))
44 {
45 /* dividend, divisor, and quotient are nonnegative */
46 sdiv_qrnnd (q, r, a1, a0, d);
47 }
48 else
49 {
50 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
51 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (BITS_PER_MP_LIMB - 1));
52 /* Divide (c1*2^32 + c0) by d */
53 sdiv_qrnnd (q, r, c1, c0, d);
54 /* Add 2^31 to quotient */
55 q += (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1);
56 }
57 }
58 else
59 {
60 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
61 c1 = a1 >> 1; /* A/2 */
62 c0 = (a1 << (BITS_PER_MP_LIMB - 1)) + (a0 >> 1);
63
64 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
65 {
66 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
67
68 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
69 if ((d & 1) != 0)
70 {
71 if (r >= q)
72 r = r - q;
73 else if (q - r <= d)
74 {
75 r = r - q + d;
76 q--;
77 }
78 else
79 {
80 r = r - q + 2*d;
81 q -= 2;
82 }
83 }
84 }
85 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
86 {
87 c1 = (b1 - 1) - c1;
88 c0 = ~c0; /* logical NOT */
89
90 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
91
92 q = ~q; /* (A/2)/b1 */
93 r = (b1 - 1) - r;
94
95 r = 2*r + (a0 & 1); /* A/(2*b1) */
96
97 if ((d & 1) != 0)
98 {
99 if (r >= q)
100 r = r - q;
101 else if (q - r <= d)
102 {
103 r = r - q + d;
104 q--;
105 }
106 else
107 {
108 r = r - q + 2*d;
109 q -= 2;
110 }
111 }
112 }
113 else /* Implies c1 = b1 */
114 { /* Hence a1 = d - 1 = 2*b1 - 1 */
115 if (a0 >= -d)
116 {
117 q = -1;
118 r = a0 + d;
119 }
120 else
121 {
122 q = -2;
123 r = a0 + 2*d;
124 }
125 }
126 }
127
128 *rp = r;
129 return q;
130}
131
132#endif
133