tree checksum vpatch file split hunks
all signers: asciilifeform diana_coman
antecedents: mpi_second_cut
press order:
mpi-genesis | asciilifeform diana_coman |
mpi_second_cut | asciilifeform diana_coman |
sane_mpi_eucrypt | diana_coman |
patch:
(1 . 5)(1 . 6)
5 /* mpi-scan.c - MPI functions
6 * Modified by No Such Labs. (C) 2015. See README.
7 * Modified by S.MG 2017 (removed code that is not used by eucrypt and at the same time so ugly it needs rewrite anyway)
8 *
9 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
10 * SHA256(gnupg-1.4.10.tar.gz):
(27 . 97)(28 . 10)
12 #include "mpi-internal.h"
13 #include "longlong.h"
14
15 /****************
16 * Scan through an mpi and return byte for byte. a -1 is returned to indicate
17 * the end of the mpi. Scanning is done from the lsb to the msb, returned
18 * values are in the range of 0 .. 255.
19 *
20 * FIXME: This code is VERY ugly!
21 */
22 #if 0 /* Code is not used */
23 int
24 mpi_getbyte( MPI a, unsigned idx )
25 {
26 int i, j;
27 unsigned n;
28 mpi_ptr_t ap;
29 mpi_limb_t limb;
30
31 ap = a->d;
32 for(n=0,i=0; i < a->nlimbs; i++ ) {
33 limb = ap[i];
34 for( j=0; j < BYTES_PER_MPI_LIMB; j++, n++ )
35 if( n == idx )
36 return (limb >> j*8) & 0xff;
37 }
38 return -1;
39 }
40 #endif /* Code is not used */
41
42
43 /****************
44 * Put a value at position IDX into A. idx counts from lsb to msb
45 */
46 /* FIXME: There is a problem with the long constants which should have
47 a LL prefix or better the macros we use at other places. */
48 #if 0 /* Code is not used */
49 void
50 mpi_putbyte( MPI a, unsigned idx, int xc )
51 {
52
53 int i, j;
54 unsigned n;
55 mpi_ptr_t ap;
56 mpi_limb_t limb, c;
57
58 c = xc & 0xff;
59 ap = a->d;
60 for(n=0,i=0; i < a->alloced; i++ ) {
61 limb = ap[i];
62 for( j=0; j < BYTES_PER_MPI_LIMB; j++, n++ )
63 if( n == idx ) {
64 #if BYTES_PER_MPI_LIMB == 4
65 if( j == 0 )
66 limb = (limb & 0xffffff00) | c;
67 else if( j == 1 )
68 limb = (limb & 0xffff00ff) | (c<<8);
69 else if( j == 2 )
70 limb = (limb & 0xff00ffff) | (c<<16);
71 else
72 limb = (limb & 0x00ffffff) | (c<<24);
73 #elif BYTES_PER_MPI_LIMB == 8
74 if( j == 0 )
75 limb = (limb & 0xffffffffffffff00) | c;
76 else if( j == 1 )
77 limb = (limb & 0xffffffffffff00ff) | (c<<8);
78 else if( j == 2 )
79 limb = (limb & 0xffffffffff00ffff) | (c<<16);
80 else if( j == 3 )
81 limb = (limb & 0xffffffff00ffffff) | (c<<24);
82 else if( j == 4 )
83 limb = (limb & 0xffffff00ffffffff) | (c<<32);
84 else if( j == 5 )
85 limb = (limb & 0xffff00ffffffffff) | (c<<40);
86 else if( j == 6 )
87 limb = (limb & 0xff00ffffffffffff) | (c<<48);
88 else
89 limb = (limb & 0x00ffffffffffffff) | (c<<56);
90 #else
91 #error please enhance this function, its ugly - i know.
92 #endif
93 if( a->nlimbs <= i )
94 a->nlimbs = i+1;
95 ap[i] = limb;
96 return;
97 }
98 }
99 abort(); /* index out of range */
100 }
101 #endif /* Code is not used */
102
103
104 /****************
105 * Count the number of zerobits at the low end of A
106 * This is used currently by eucrypt's primality tests.
107 */
108 unsigned int
109 mpi_trailing_zeros( MPI a )