diff options
Diffstat (limited to 'lib/mpi/mpiutil.c')
| -rw-r--r-- | lib/mpi/mpiutil.c | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/lib/mpi/mpiutil.c b/lib/mpi/mpiutil.c index 26e4ed31e256..657979f71bef 100644 --- a/lib/mpi/mpiutil.c +++ b/lib/mpi/mpiutil.c | |||
| @@ -106,13 +106,6 @@ int mpi_resize(MPI a, unsigned nlimbs) | |||
| 106 | return 0; | 106 | return 0; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | void mpi_clear(MPI a) | ||
| 110 | { | ||
| 111 | a->nlimbs = 0; | ||
| 112 | a->nbits = 0; | ||
| 113 | a->flags = 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | void mpi_free(MPI a) | 109 | void mpi_free(MPI a) |
| 117 | { | 110 | { |
| 118 | if (!a) | 111 | if (!a) |
| @@ -128,84 +121,3 @@ void mpi_free(MPI a) | |||
| 128 | kfree(a); | 121 | kfree(a); |
| 129 | } | 122 | } |
| 130 | EXPORT_SYMBOL_GPL(mpi_free); | 123 | EXPORT_SYMBOL_GPL(mpi_free); |
| 131 | |||
| 132 | /**************** | ||
| 133 | * Note: This copy function should not interpret the MPI | ||
| 134 | * but copy it transparently. | ||
| 135 | */ | ||
| 136 | int mpi_copy(MPI *copied, const MPI a) | ||
| 137 | { | ||
| 138 | size_t i; | ||
| 139 | MPI b; | ||
| 140 | |||
| 141 | *copied = NULL; | ||
| 142 | |||
| 143 | if (a) { | ||
| 144 | b = mpi_alloc(a->nlimbs); | ||
| 145 | if (!b) | ||
| 146 | return -ENOMEM; | ||
| 147 | |||
| 148 | b->nlimbs = a->nlimbs; | ||
| 149 | b->sign = a->sign; | ||
| 150 | b->flags = a->flags; | ||
| 151 | b->nbits = a->nbits; | ||
| 152 | |||
| 153 | for (i = 0; i < b->nlimbs; i++) | ||
| 154 | b->d[i] = a->d[i]; | ||
| 155 | |||
| 156 | *copied = b; | ||
| 157 | } | ||
| 158 | |||
| 159 | return 0; | ||
| 160 | } | ||
| 161 | |||
| 162 | int mpi_set(MPI w, const MPI u) | ||
| 163 | { | ||
| 164 | mpi_ptr_t wp, up; | ||
| 165 | mpi_size_t usize = u->nlimbs; | ||
| 166 | int usign = u->sign; | ||
| 167 | |||
| 168 | if (RESIZE_IF_NEEDED(w, (size_t) usize) < 0) | ||
| 169 | return -ENOMEM; | ||
| 170 | |||
| 171 | wp = w->d; | ||
| 172 | up = u->d; | ||
| 173 | MPN_COPY(wp, up, usize); | ||
| 174 | w->nlimbs = usize; | ||
| 175 | w->nbits = u->nbits; | ||
| 176 | w->flags = u->flags; | ||
| 177 | w->sign = usign; | ||
| 178 | return 0; | ||
| 179 | } | ||
| 180 | |||
| 181 | int mpi_set_ui(MPI w, unsigned long u) | ||
| 182 | { | ||
| 183 | if (RESIZE_IF_NEEDED(w, 1) < 0) | ||
| 184 | return -ENOMEM; | ||
| 185 | w->d[0] = u; | ||
| 186 | w->nlimbs = u ? 1 : 0; | ||
| 187 | w->sign = 0; | ||
| 188 | w->nbits = 0; | ||
| 189 | w->flags = 0; | ||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | |||
| 193 | MPI mpi_alloc_set_ui(unsigned long u) | ||
| 194 | { | ||
| 195 | MPI w = mpi_alloc(1); | ||
| 196 | if (!w) | ||
| 197 | return w; | ||
| 198 | w->d[0] = u; | ||
| 199 | w->nlimbs = u ? 1 : 0; | ||
| 200 | w->sign = 0; | ||
| 201 | return w; | ||
| 202 | } | ||
| 203 | |||
| 204 | void mpi_swap(MPI a, MPI b) | ||
| 205 | { | ||
| 206 | struct gcry_mpi tmp; | ||
| 207 | |||
| 208 | tmp = *a; | ||
| 209 | *a = *b; | ||
| 210 | *b = tmp; | ||
| 211 | } | ||
