Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/mpi: headers cleanup

MPI headers contain definitions for huge number of non-existing
functions.

Most part of these functions was removed in 2012 by Dmitry Kasatkin
- 7cf4206a99d1 ("Remove unused code from MPI library")
- 9e235dcaf4f6 ("Revert "crypto: GnuPG based MPI lib - additional ...")
- bc95eeadf5c6 ("lib/mpi: removed unused functions")
however headers wwere not updated properly.

Also I deleted some unused macros.

Link: http://lkml.kernel.org/r/fb2fc1ef-1185-f0a3-d8d0-173d2f97bbaf@virtuozzo.com
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Dmitry Kasatkin <dmitry.kasatkin@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Vasily Averin and committed by
Linus Torvalds
cbdc61ae 804209d8

+5 -131
-61
include/linux/mpi.h
··· 53 53 typedef struct gcry_mpi *MPI; 54 54 55 55 #define mpi_get_nlimbs(a) ((a)->nlimbs) 56 - #define mpi_is_neg(a) ((a)->sign) 57 56 58 57 /*-- mpiutil.c --*/ 59 58 MPI mpi_alloc(unsigned nlimbs); 60 - MPI mpi_alloc_secure(unsigned nlimbs); 61 - MPI mpi_alloc_like(MPI a); 62 59 void mpi_free(MPI a); 63 60 int mpi_resize(MPI a, unsigned nlimbs); 64 - int mpi_copy(MPI *copy, const MPI a); 65 - void mpi_clear(MPI a); 66 - int mpi_set(MPI w, MPI u); 67 - int mpi_set_ui(MPI w, ulong u); 68 - MPI mpi_alloc_set_ui(unsigned long u); 69 - void mpi_m_check(MPI a); 70 - void mpi_swap(MPI a, MPI b); 71 61 72 62 /*-- mpicoder.c --*/ 73 - MPI do_encode_md(const void *sha_buffer, unsigned nbits); 74 63 MPI mpi_read_raw_data(const void *xbuffer, size_t nbytes); 75 64 MPI mpi_read_from_buffer(const void *buffer, unsigned *ret_nread); 76 65 MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int len); 77 - int mpi_fromstr(MPI val, const char *str); 78 - u32 mpi_get_keyid(MPI a, u32 *keyid); 79 66 void *mpi_get_buffer(MPI a, unsigned *nbytes, int *sign); 80 67 int mpi_read_buffer(MPI a, uint8_t *buf, unsigned buf_len, unsigned *nbytes, 81 68 int *sign); 82 - void *mpi_get_secure_buffer(MPI a, unsigned *nbytes, int *sign); 83 69 int mpi_write_to_sgl(MPI a, struct scatterlist *sg, unsigned nbytes, 84 70 int *sign); 85 71 86 - #define log_mpidump g10_log_mpidump 87 - 88 - /*-- mpi-add.c --*/ 89 - int mpi_add_ui(MPI w, MPI u, ulong v); 90 - int mpi_add(MPI w, MPI u, MPI v); 91 - int mpi_addm(MPI w, MPI u, MPI v, MPI m); 92 - int mpi_sub_ui(MPI w, MPI u, ulong v); 93 - int mpi_sub(MPI w, MPI u, MPI v); 94 - int mpi_subm(MPI w, MPI u, MPI v, MPI m); 95 - 96 - /*-- mpi-mul.c --*/ 97 - int mpi_mul_ui(MPI w, MPI u, ulong v); 98 - int mpi_mul_2exp(MPI w, MPI u, ulong cnt); 99 - int mpi_mul(MPI w, MPI u, MPI v); 100 - int mpi_mulm(MPI w, MPI u, MPI v, MPI m); 101 - 102 - /*-- mpi-div.c --*/ 103 - ulong mpi_fdiv_r_ui(MPI rem, MPI dividend, ulong divisor); 104 - int mpi_fdiv_r(MPI rem, MPI dividend, MPI divisor); 105 - int mpi_fdiv_q(MPI quot, MPI dividend, MPI divisor); 106 - int mpi_fdiv_qr(MPI quot, MPI rem, MPI dividend, MPI divisor); 107 - int mpi_tdiv_r(MPI rem, MPI num, MPI den); 108 - int mpi_tdiv_qr(MPI quot, MPI rem, MPI num, MPI den); 109 - int mpi_tdiv_q_2exp(MPI w, MPI u, unsigned count); 110 - int mpi_divisible_ui(const MPI dividend, ulong divisor); 111 - 112 - /*-- mpi-gcd.c --*/ 113 - int mpi_gcd(MPI g, const MPI a, const MPI b); 114 - 115 72 /*-- mpi-pow.c --*/ 116 - int mpi_pow(MPI w, MPI u, MPI v); 117 73 int mpi_powm(MPI res, MPI base, MPI exp, MPI mod); 118 - 119 - /*-- mpi-mpow.c --*/ 120 - int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI mod); 121 74 122 75 /*-- mpi-cmp.c --*/ 123 76 int mpi_cmp_ui(MPI u, ulong v); 124 77 int mpi_cmp(MPI u, MPI v); 125 78 126 - /*-- mpi-scan.c --*/ 127 - int mpi_getbyte(MPI a, unsigned idx); 128 - void mpi_putbyte(MPI a, unsigned idx, int value); 129 - unsigned mpi_trailing_zeros(MPI a); 130 - 131 79 /*-- mpi-bit.c --*/ 132 80 void mpi_normalize(MPI a); 133 81 unsigned mpi_get_nbits(MPI a); 134 - int mpi_test_bit(MPI a, unsigned n); 135 - int mpi_set_bit(MPI a, unsigned n); 136 - int mpi_set_highbit(MPI a, unsigned n); 137 - void mpi_clear_highbit(MPI a, unsigned n); 138 - void mpi_clear_bit(MPI a, unsigned n); 139 - int mpi_rshift(MPI x, MPI a, unsigned n); 140 - 141 - /*-- mpi-inv.c --*/ 142 - int mpi_invm(MPI x, MPI u, MPI v); 143 82 144 83 /* inline functions */ 145 84
+5 -70
lib/mpi/mpi-internal.h
··· 65 65 typedef mpi_limb_t *mpi_ptr_t; /* pointer to a limb */ 66 66 typedef int mpi_size_t; /* (must be a signed type) */ 67 67 68 - static inline int RESIZE_IF_NEEDED(MPI a, unsigned b) 69 - { 70 - if (a->alloced < b) 71 - return mpi_resize(a, b); 72 - return 0; 73 - } 74 - 75 68 /* Copy N limbs from S to D. */ 76 69 #define MPN_COPY(d, s, n) \ 77 - do { \ 78 - mpi_size_t _i; \ 79 - for (_i = 0; _i < (n); _i++) \ 80 - (d)[_i] = (s)[_i]; \ 81 - } while (0) 82 - 83 - #define MPN_COPY_INCR(d, s, n) \ 84 70 do { \ 85 71 mpi_size_t _i; \ 86 72 for (_i = 0; _i < (n); _i++) \ ··· 97 111 } \ 98 112 } while (0) 99 113 100 - #define MPN_NORMALIZE_NOT_ZERO(d, n) \ 101 - do { \ 102 - for (;;) { \ 103 - if ((d)[(n)-1]) \ 104 - break; \ 105 - (n)--; \ 106 - } \ 107 - } while (0) 108 - 109 114 #define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \ 110 115 do { \ 111 116 if ((size) < KARATSUBA_THRESHOLD) \ ··· 105 128 mul_n(prodp, up, vp, size, tspace); \ 106 129 } while (0); 107 130 108 - /* Divide the two-limb number in (NH,,NL) by D, with DI being the largest 109 - * limb not larger than (2**(2*BITS_PER_MP_LIMB))/D - (2**BITS_PER_MP_LIMB). 110 - * If this would yield overflow, DI should be the largest possible number 111 - * (i.e., only ones). For correct operation, the most significant bit of D 112 - * has to be set. Put the quotient in Q and the remainder in R. 113 - */ 114 - #define UDIV_QRNND_PREINV(q, r, nh, nl, d, di) \ 115 - do { \ 116 - mpi_limb_t _q, _ql, _r; \ 117 - mpi_limb_t _xh, _xl; \ 118 - umul_ppmm(_q, _ql, (nh), (di)); \ 119 - _q += (nh); /* DI is 2**BITS_PER_MPI_LIMB too small */ \ 120 - umul_ppmm(_xh, _xl, _q, (d)); \ 121 - sub_ddmmss(_xh, _r, (nh), (nl), _xh, _xl); \ 122 - if (_xh) { \ 123 - sub_ddmmss(_xh, _r, _xh, _r, 0, (d)); \ 124 - _q++; \ 125 - if (_xh) { \ 126 - sub_ddmmss(_xh, _r, _xh, _r, 0, (d)); \ 127 - _q++; \ 128 - } \ 129 - } \ 130 - if (_r >= (d)) { \ 131 - _r -= (d); \ 132 - _q++; \ 133 - } \ 134 - (r) = _r; \ 135 - (q) = _q; \ 136 - } while (0) 137 - 138 131 /*-- mpiutil.c --*/ 139 132 mpi_ptr_t mpi_alloc_limb_space(unsigned nlimbs); 140 133 void mpi_free_limb_space(mpi_ptr_t a); 141 134 void mpi_assign_limb_space(MPI a, mpi_ptr_t ap, unsigned nlimbs); 142 135 143 - /*-- mpi-bit.c --*/ 144 - void mpi_rshift_limbs(MPI a, unsigned int count); 145 - int mpi_lshift_limbs(MPI a, unsigned int count); 146 - 147 - /*-- mpihelp-add.c --*/ 148 136 static inline mpi_limb_t mpihelp_add_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 149 137 mpi_size_t s1_size, mpi_limb_t s2_limb); 150 138 mpi_limb_t mpihelp_add_n(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, ··· 117 175 static inline mpi_limb_t mpihelp_add(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size, 118 176 mpi_ptr_t s2_ptr, mpi_size_t s2_size); 119 177 120 - /*-- mpihelp-sub.c --*/ 121 178 static inline mpi_limb_t mpihelp_sub_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 122 179 mpi_size_t s1_size, mpi_limb_t s2_limb); 123 180 mpi_limb_t mpihelp_sub_n(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, ··· 124 183 static inline mpi_limb_t mpihelp_sub(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size, 125 184 mpi_ptr_t s2_ptr, mpi_size_t s2_size); 126 185 127 - /*-- mpihelp-cmp.c --*/ 186 + /*-- mpih-cmp.c --*/ 128 187 int mpihelp_cmp(mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size); 129 188 130 - /*-- mpihelp-mul.c --*/ 189 + /*-- mpih-mul.c --*/ 131 190 132 191 struct karatsuba_ctx { 133 192 struct karatsuba_ctx *next; ··· 143 202 mpi_size_t s1_size, mpi_limb_t s2_limb); 144 203 mpi_limb_t mpihelp_submul_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 145 204 mpi_size_t s1_size, mpi_limb_t s2_limb); 146 - int mpihelp_mul_n(mpi_ptr_t prodp, mpi_ptr_t up, mpi_ptr_t vp, mpi_size_t size); 147 205 int mpihelp_mul(mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t usize, 148 206 mpi_ptr_t vp, mpi_size_t vsize, mpi_limb_t *_result); 149 207 void mpih_sqr_n_basecase(mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t size); ··· 154 214 mpi_ptr_t vp, mpi_size_t vsize, 155 215 struct karatsuba_ctx *ctx); 156 216 157 - /*-- mpihelp-mul_1.c (or xxx/cpu/ *.S) --*/ 217 + /*-- generic_mpih-mul1.c --*/ 158 218 mpi_limb_t mpihelp_mul_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, 159 219 mpi_size_t s1_size, mpi_limb_t s2_limb); 160 220 161 - /*-- mpihelp-div.c --*/ 162 - mpi_limb_t mpihelp_mod_1(mpi_ptr_t dividend_ptr, mpi_size_t dividend_size, 163 - mpi_limb_t divisor_limb); 221 + /*-- mpih-div.c --*/ 164 222 mpi_limb_t mpihelp_divrem(mpi_ptr_t qp, mpi_size_t qextra_limbs, 165 223 mpi_ptr_t np, mpi_size_t nsize, 166 224 mpi_ptr_t dp, mpi_size_t dsize); 167 - mpi_limb_t mpihelp_divmod_1(mpi_ptr_t quot_ptr, 168 - mpi_ptr_t dividend_ptr, mpi_size_t dividend_size, 169 - mpi_limb_t divisor_limb); 170 225 171 - /*-- mpihelp-shift.c --*/ 226 + /*-- generic_mpih-[lr]shift.c --*/ 172 227 mpi_limb_t mpihelp_lshift(mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize, 173 228 unsigned cnt); 174 229 mpi_limb_t mpihelp_rshift(mpi_ptr_t wp, mpi_ptr_t up, mpi_size_t usize,