raw
mpi-genesis             1 /* mpiutil.ac  -  Utility functions for MPI
mpi_second_cut 2 * Modified by No Such Labs. (C) 2015. See README.
mpi-genesis 3 *
mpi_second_cut 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
mpi_second_cut 5 * SHA256(gnupg-1.4.10.tar.gz):
mpi_second_cut 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
mpi_second_cut 7 * (C) 1994-2005 Free Software Foundation, Inc.
mpi-genesis 8 *
mpi_second_cut 9 * This program is free software: you can redistribute it and/or modify
mpi-genesis 10 * it under the terms of the GNU General Public License as published by
mpi_second_cut 11 * the Free Software Foundation, either version 3 of the License, or
mpi-genesis 12 * (at your option) any later version.
mpi-genesis 13 *
mpi_second_cut 14 * This program is distributed in the hope that it will be useful,
mpi-genesis 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis 17 * GNU General Public License for more details.
mpi-genesis 18 *
mpi-genesis 19 * You should have received a copy of the GNU General Public License
mpi_second_cut 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
mpi-genesis 21 */
mpi-genesis 22
mpi-genesis 23 #include <stdio.h>
mpi-genesis 24 #include <stdlib.h>
mpi-genesis 25 #include <string.h>
mpi-genesis 26 #include <assert.h>
mpi-genesis 27
mpi_second_cut 28 #include "knobs.h"
mpi-genesis 29 #include "mpi.h"
mpi-genesis 30 #include "mpi-internal.h"
mpi-genesis 31 #include "memory.h"
mpi-genesis 32 #include "util.h"
mpi-genesis 33
mpi-genesis 34
mpi-genesis 35 #ifdef M_DEBUG
mpi-genesis 36 #undef mpi_alloc
mpi-genesis 37 #undef mpi_alloc_secure
mpi-genesis 38 #undef mpi_free
mpi-genesis 39 #endif
mpi-genesis 40
mpi-genesis 41 /****************
mpi-genesis 42 * Note: It was a bad idea to use the number of limbs to allocate
mpi-genesis 43 * because on a alpha the limbs are large but we normally need
mpi-genesis 44 * integers of n bits - So we should chnage this to bits (or bytes).
mpi-genesis 45 *
mpi-genesis 46 * But mpi_alloc is used in a lot of places :-)
mpi-genesis 47 */
mpi-genesis 48 MPI
mpi-genesis 49 #ifdef M_DEBUG
mpi-genesis 50 mpi_debug_alloc( unsigned nlimbs, const char *info )
mpi-genesis 51 #else
mpi-genesis 52 mpi_alloc( unsigned nlimbs )
mpi-genesis 53 #endif
mpi-genesis 54 {
mpi-genesis 55 MPI a;
mpi-genesis 56
mpi-genesis 57 if( DBG_MEMORY )
mpi-genesis 58 log_debug("mpi_alloc(%u)\n", nlimbs*BITS_PER_MPI_LIMB );
mpi-genesis 59 #ifdef M_DEBUG
mpi-genesis 60 a = m_debug_alloc( sizeof *a, info );
mpi-genesis 61 a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 0, info ) : NULL;
mpi-genesis 62 #else
mpi-genesis 63 a = xmalloc( sizeof *a );
mpi-genesis 64 a->d = nlimbs? mpi_alloc_limb_space( nlimbs, 0 ) : NULL;
mpi-genesis 65 #endif
mpi-genesis 66 a->alloced = nlimbs;
mpi-genesis 67 a->nlimbs = 0;
mpi-genesis 68 a->sign = 0;
mpi-genesis 69 a->flags = 0;
mpi-genesis 70 a->nbits = 0;
mpi-genesis 71 return a;
mpi-genesis 72 }
mpi-genesis 73
mpi-genesis 74 void
mpi-genesis 75 mpi_m_check( MPI a )
mpi-genesis 76 {
mpi-genesis 77 m_check(a);
mpi-genesis 78 m_check(a->d);
mpi-genesis 79 }
mpi-genesis 80
mpi-genesis 81 MPI
mpi-genesis 82 #ifdef M_DEBUG
mpi-genesis 83 mpi_debug_alloc_secure( unsigned nlimbs, const char *info )
mpi-genesis 84 #else
mpi-genesis 85 mpi_alloc_secure( unsigned nlimbs )
mpi-genesis 86 #endif
mpi-genesis 87 {
mpi-genesis 88 MPI a;
mpi-genesis 89
mpi-genesis 90 if( DBG_MEMORY )
mpi-genesis 91 log_debug("mpi_alloc_secure(%u)\n", nlimbs*BITS_PER_MPI_LIMB );
mpi-genesis 92 #ifdef M_DEBUG
mpi-genesis 93 a = m_debug_alloc( sizeof *a, info );
mpi-genesis 94 a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 1, info ) : NULL;
mpi-genesis 95 #else
mpi-genesis 96 a = xmalloc( sizeof *a );
mpi-genesis 97 a->d = nlimbs? mpi_alloc_limb_space( nlimbs, 1 ) : NULL;
mpi-genesis 98 #endif
mpi-genesis 99 a->alloced = nlimbs;
mpi-genesis 100 a->flags = 1;
mpi-genesis 101 a->nlimbs = 0;
mpi-genesis 102 a->sign = 0;
mpi-genesis 103 a->nbits = 0;
mpi-genesis 104 return a;
mpi-genesis 105 }
mpi-genesis 106
mpi-genesis 107
mpi-genesis 108 #if 0
mpi-genesis 109 static void *unused_limbs_5;
mpi-genesis 110 static void *unused_limbs_32;
mpi-genesis 111 static void *unused_limbs_64;
mpi-genesis 112 #endif
mpi-genesis 113
mpi-genesis 114 mpi_ptr_t
mpi-genesis 115 #ifdef M_DEBUG
mpi-genesis 116 mpi_debug_alloc_limb_space( unsigned nlimbs, int secure, const char *info )
mpi-genesis 117 #else
mpi-genesis 118 mpi_alloc_limb_space( unsigned nlimbs, int secure )
mpi-genesis 119 #endif
mpi-genesis 120 {
mpi-genesis 121 size_t len = nlimbs * sizeof(mpi_limb_t);
mpi-genesis 122 mpi_ptr_t p;
mpi-genesis 123
mpi-genesis 124 if( DBG_MEMORY )
mpi-genesis 125 log_debug("mpi_alloc_limb_space(%u)\n", (unsigned)len*8 );
mpi-genesis 126 #if 0
mpi-genesis 127 if( !secure ) {
mpi-genesis 128 if( nlimbs == 5 && unused_limbs_5 ) { /* DSA 160 bits */
mpi-genesis 129 p = unused_limbs_5;
mpi-genesis 130 unused_limbs_5 = *p;
mpi-genesis 131 return p;
mpi-genesis 132 }
mpi-genesis 133 else if( nlimbs == 32 && unused_limbs_32 ) { /* DSA 1024 bits */
mpi-genesis 134 p = unused_limbs_32;
mpi-genesis 135 unused_limbs_32 = *p;
mpi-genesis 136 return p;
mpi-genesis 137 }
mpi-genesis 138 else if( nlimbs == 64 && unused_limbs_64 ) { /* DSA 2*1024 bits */
mpi-genesis 139 p = unused_limbs_64;
mpi-genesis 140 unused_limbs_64 = *p;
mpi-genesis 141 return p;
mpi-genesis 142 }
mpi-genesis 143 }
mpi-genesis 144 #endif
mpi-genesis 145
mpi-genesis 146 #ifdef M_DEBUG
mpi-genesis 147 p = secure? m_debug_alloc_secure(len, info):m_debug_alloc( len, info );
mpi-genesis 148 #else
mpi-genesis 149 p = secure? xmalloc_secure( len ):xmalloc( len );
mpi-genesis 150 #endif
mpi-genesis 151
mpi-genesis 152 return p;
mpi-genesis 153 }
mpi-genesis 154
mpi-genesis 155 void
mpi-genesis 156 #ifdef M_DEBUG
mpi-genesis 157 mpi_debug_free_limb_space( mpi_ptr_t a, const char *info )
mpi-genesis 158 #else
mpi-genesis 159 mpi_free_limb_space( mpi_ptr_t a )
mpi-genesis 160 #endif
mpi-genesis 161 {
mpi-genesis 162 if( !a )
mpi-genesis 163 return;
mpi-genesis 164 if( DBG_MEMORY )
mpi-genesis 165 log_debug("mpi_free_limb_space of size %lu\n", (ulong)m_size(a)*8 );
mpi-genesis 166
mpi-genesis 167 #if 0
mpi-genesis 168 if( !m_is_secure(a) ) {
mpi-genesis 169 size_t nlimbs = m_size(a) / 4 ;
mpi-genesis 170 void *p = a;
mpi-genesis 171
mpi-genesis 172 if( nlimbs == 5 ) { /* DSA 160 bits */
mpi-genesis 173 *a = unused_limbs_5;
mpi-genesis 174 unused_limbs_5 = a;
mpi-genesis 175 return;
mpi-genesis 176 }
mpi-genesis 177 else if( nlimbs == 32 ) { /* DSA 1024 bits */
mpi-genesis 178 *a = unused_limbs_32;
mpi-genesis 179 unused_limbs_32 = a;
mpi-genesis 180 return;
mpi-genesis 181 }
mpi-genesis 182 else if( nlimbs == 64 ) { /* DSA 2*1024 bits */
mpi-genesis 183 *a = unused_limbs_64;
mpi-genesis 184 unused_limbs_64 = a;
mpi-genesis 185 return;
mpi-genesis 186 }
mpi-genesis 187 }
mpi-genesis 188 #endif
mpi-genesis 189
mpi-genesis 190 xfree(a);
mpi-genesis 191 }
mpi-genesis 192
mpi-genesis 193
mpi-genesis 194 void
mpi-genesis 195 mpi_assign_limb_space( MPI a, mpi_ptr_t ap, unsigned nlimbs )
mpi-genesis 196 {
mpi-genesis 197 mpi_free_limb_space(a->d);
mpi-genesis 198 a->d = ap;
mpi-genesis 199 a->alloced = nlimbs;
mpi-genesis 200 }
mpi-genesis 201
mpi-genesis 202
mpi-genesis 203
mpi-genesis 204 /****************
mpi-genesis 205 * Resize the array of A to NLIMBS. the additional space is cleared
mpi-genesis 206 * (set to 0) [done by xrealloc()]
mpi-genesis 207 */
mpi-genesis 208 void
mpi-genesis 209 #ifdef M_DEBUG
mpi-genesis 210 mpi_debug_resize( MPI a, unsigned nlimbs, const char *info )
mpi-genesis 211 #else
mpi-genesis 212 mpi_resize( MPI a, unsigned nlimbs )
mpi-genesis 213 #endif
mpi-genesis 214 {
mpi-genesis 215 if( nlimbs <= a->alloced )
mpi-genesis 216 return; /* no need to do it */
mpi-genesis 217 /* Note: a->secure is not used - instead the realloc functions
mpi-genesis 218 * take care of it. Maybe we should drop a->secure completely
mpi-genesis 219 * and rely on a mpi_is_secure function, which would be
mpi-genesis 220 * a wrapper around m_is_secure
mpi-genesis 221 */
mpi-genesis 222 #ifdef M_DEBUG
mpi-genesis 223 if( a->d )
mpi-genesis 224 a->d = m_debug_realloc(a->d, nlimbs * sizeof(mpi_limb_t), info );
mpi-genesis 225 else
mpi-genesis 226 a->d = m_debug_alloc_clear( nlimbs * sizeof(mpi_limb_t), info );
mpi-genesis 227 #else
mpi-genesis 228 if( a->d )
mpi-genesis 229 a->d = xrealloc(a->d, nlimbs * sizeof(mpi_limb_t) );
mpi-genesis 230 else
mpi-genesis 231 a->d = xmalloc_clear( nlimbs * sizeof(mpi_limb_t) );
mpi-genesis 232 #endif
mpi-genesis 233 a->alloced = nlimbs;
mpi-genesis 234 }
mpi-genesis 235
mpi-genesis 236 void
mpi-genesis 237 mpi_clear( MPI a )
mpi-genesis 238 {
mpi-genesis 239 a->nlimbs = 0;
mpi-genesis 240 a->nbits = 0;
mpi-genesis 241 a->flags = 0;
mpi-genesis 242 }
mpi-genesis 243
mpi-genesis 244
mpi-genesis 245 void
mpi-genesis 246 #ifdef M_DEBUG
mpi-genesis 247 mpi_debug_free( MPI a, const char *info )
mpi-genesis 248 #else
mpi-genesis 249 mpi_free( MPI a )
mpi-genesis 250 #endif
mpi-genesis 251 {
mpi-genesis 252 if( !a )
mpi-genesis 253 return;
mpi-genesis 254 if( DBG_MEMORY )
mpi-genesis 255 log_debug("mpi_free\n" );
mpi-genesis 256 if( a->flags & 4 )
mpi-genesis 257 xfree( a->d );
mpi-genesis 258 else {
mpi-genesis 259 #ifdef M_DEBUG
mpi-genesis 260 mpi_debug_free_limb_space(a->d, info);
mpi-genesis 261 #else
mpi-genesis 262 mpi_free_limb_space(a->d);
mpi-genesis 263 #endif
mpi-genesis 264 }
mpi-genesis 265 if( a->flags & ~7 )
mpi-genesis 266 log_bug("invalid flag value in mpi\n");
mpi-genesis 267 xfree(a);
mpi-genesis 268 }
mpi-genesis 269
mpi-genesis 270
mpi-genesis 271 void
mpi-genesis 272 mpi_set_secure( MPI a )
mpi-genesis 273 {
mpi-genesis 274 mpi_ptr_t ap, bp;
mpi-genesis 275
mpi-genesis 276 if( (a->flags & 1) )
mpi-genesis 277 return;
mpi-genesis 278 a->flags |= 1;
mpi-genesis 279 ap = a->d;
mpi-genesis 280 if( !a->nlimbs ) {
mpi-genesis 281 assert(!ap);
mpi-genesis 282 return;
mpi-genesis 283 }
mpi-genesis 284 #ifdef M_DEBUG
mpi-genesis 285 bp = mpi_debug_alloc_limb_space( a->nlimbs, 1, "set_secure" );
mpi-genesis 286 #else
mpi-genesis 287 bp = mpi_alloc_limb_space( a->nlimbs, 1 );
mpi-genesis 288 #endif
mpi-genesis 289 MPN_COPY( bp, ap, a->nlimbs );
mpi-genesis 290 a->d = bp;
mpi-genesis 291 #ifdef M_DEBUG
mpi-genesis 292 mpi_debug_free_limb_space(ap, "set_secure");
mpi-genesis 293 #else
mpi-genesis 294 mpi_free_limb_space(ap);
mpi-genesis 295 #endif
mpi-genesis 296 }
mpi-genesis 297
mpi-genesis 298
mpi-genesis 299 MPI
mpi-genesis 300 mpi_set_opaque( MPI a, void *p, unsigned int len )
mpi-genesis 301 {
mpi-genesis 302 if( !a ) {
mpi-genesis 303 #ifdef M_DEBUG
mpi-genesis 304 a = mpi_debug_alloc(0,"alloc_opaque");
mpi-genesis 305 #else
mpi-genesis 306 a = mpi_alloc(0);
mpi-genesis 307 #endif
mpi-genesis 308 }
mpi-genesis 309
mpi-genesis 310 if( a->flags & 4 )
mpi-genesis 311 xfree( a->d );
mpi-genesis 312 else {
mpi-genesis 313 #ifdef M_DEBUG
mpi-genesis 314 mpi_debug_free_limb_space(a->d, "alloc_opaque");
mpi-genesis 315 #else
mpi-genesis 316 mpi_free_limb_space(a->d);
mpi-genesis 317 #endif
mpi-genesis 318 }
mpi-genesis 319
mpi-genesis 320 a->d = p;
mpi-genesis 321 a->alloced = 0;
mpi-genesis 322 a->nlimbs = 0;
mpi-genesis 323 a->nbits = len;
mpi-genesis 324 a->flags = 4;
mpi-genesis 325 return a;
mpi-genesis 326 }
mpi-genesis 327
mpi-genesis 328
mpi-genesis 329 void *
mpi-genesis 330 mpi_get_opaque( MPI a, unsigned int *len )
mpi-genesis 331 {
mpi-genesis 332 if( !(a->flags & 4) )
mpi-genesis 333 log_bug("mpi_get_opaque on normal mpi\n");
mpi-genesis 334 if( len )
mpi-genesis 335 *len = a->nbits;
mpi-genesis 336 return a->d;
mpi-genesis 337 }
mpi-genesis 338
mpi-genesis 339
mpi-genesis 340 /****************
mpi-genesis 341 * Note: This copy function should not interpret the MPI
mpi-genesis 342 * but copy it transparently.
mpi-genesis 343 */
mpi-genesis 344 MPI
mpi-genesis 345 #ifdef M_DEBUG
mpi-genesis 346 mpi_debug_copy( MPI a, const char *info )
mpi-genesis 347 #else
mpi-genesis 348 mpi_copy( MPI a )
mpi-genesis 349 #endif
mpi-genesis 350 {
mpi-genesis 351 int i;
mpi-genesis 352 MPI b;
mpi-genesis 353
mpi-genesis 354 if( a && (a->flags & 4) ) {
mpi-genesis 355 void *p = m_is_secure(a->d)? xmalloc_secure( a->nbits )
mpi-genesis 356 : xmalloc( a->nbits );
mpi-genesis 357 memcpy( p, a->d, a->nbits );
mpi-genesis 358 b = mpi_set_opaque( NULL, p, a->nbits );
mpi-genesis 359 }
mpi-genesis 360 else if( a ) {
mpi-genesis 361 #ifdef M_DEBUG
mpi-genesis 362 b = mpi_is_secure(a)? mpi_debug_alloc_secure( a->nlimbs, info )
mpi-genesis 363 : mpi_debug_alloc( a->nlimbs, info );
mpi-genesis 364 #else
mpi-genesis 365 b = mpi_is_secure(a)? mpi_alloc_secure( a->nlimbs )
mpi-genesis 366 : mpi_alloc( a->nlimbs );
mpi-genesis 367 #endif
mpi-genesis 368 b->nlimbs = a->nlimbs;
mpi-genesis 369 b->sign = a->sign;
mpi-genesis 370 b->flags = a->flags;
mpi-genesis 371 b->nbits = a->nbits;
mpi-genesis 372 for(i=0; i < b->nlimbs; i++ )
mpi-genesis 373 b->d[i] = a->d[i];
mpi-genesis 374 }
mpi-genesis 375 else
mpi-genesis 376 b = NULL;
mpi-genesis 377 return b;
mpi-genesis 378 }
mpi-genesis 379
mpi-genesis 380
mpi-genesis 381 /****************
mpi-genesis 382 * This function allocates an MPI which is optimized to hold
mpi-genesis 383 * a value as large as the one given in the argument and allocates it
mpi-genesis 384 * with the same flags as A.
mpi-genesis 385 */
mpi-genesis 386 MPI
mpi-genesis 387 #ifdef M_DEBUG
mpi-genesis 388 mpi_debug_alloc_like( MPI a, const char *info )
mpi-genesis 389 #else
mpi-genesis 390 mpi_alloc_like( MPI a )
mpi-genesis 391 #endif
mpi-genesis 392 {
mpi-genesis 393 MPI b;
mpi-genesis 394
mpi-genesis 395 if( a && (a->flags & 4) ) {
mpi-genesis 396 void *p = m_is_secure(a->d)? xmalloc_secure( a->nbits )
mpi-genesis 397 : xmalloc( a->nbits );
mpi-genesis 398 memcpy( p, a->d, a->nbits );
mpi-genesis 399 b = mpi_set_opaque( NULL, p, a->nbits );
mpi-genesis 400 }
mpi-genesis 401 else if( a ) {
mpi-genesis 402 #ifdef M_DEBUG
mpi-genesis 403 b = mpi_is_secure(a)? mpi_debug_alloc_secure( a->nlimbs, info )
mpi-genesis 404 : mpi_debug_alloc( a->nlimbs, info );
mpi-genesis 405 #else
mpi-genesis 406 b = mpi_is_secure(a)? mpi_alloc_secure( a->nlimbs )
mpi-genesis 407 : mpi_alloc( a->nlimbs );
mpi-genesis 408 #endif
mpi-genesis 409 b->nlimbs = 0;
mpi-genesis 410 b->sign = 0;
mpi-genesis 411 b->flags = a->flags;
mpi-genesis 412 b->nbits = 0;
mpi-genesis 413 }
mpi-genesis 414 else
mpi-genesis 415 b = NULL;
mpi-genesis 416 return b;
mpi-genesis 417 }
mpi-genesis 418
mpi-genesis 419
mpi-genesis 420 void
mpi-genesis 421 mpi_set( MPI w, MPI u)
mpi-genesis 422 {
mpi-genesis 423 mpi_ptr_t wp, up;
mpi-genesis 424 mpi_size_t usize = u->nlimbs;
mpi-genesis 425 int usign = u->sign;
mpi-genesis 426
mpi-genesis 427 RESIZE_IF_NEEDED(w, usize);
mpi-genesis 428 wp = w->d;
mpi-genesis 429 up = u->d;
mpi-genesis 430 MPN_COPY( wp, up, usize );
mpi-genesis 431 w->nlimbs = usize;
mpi-genesis 432 w->nbits = u->nbits;
mpi-genesis 433 w->flags = u->flags;
mpi-genesis 434 w->sign = usign;
mpi-genesis 435 }
mpi-genesis 436
mpi-genesis 437
mpi-genesis 438 void
mpi-genesis 439 mpi_set_ui( MPI w, unsigned long u)
mpi-genesis 440 {
mpi-genesis 441 RESIZE_IF_NEEDED(w, 1);
mpi-genesis 442 w->d[0] = u;
mpi-genesis 443 w->nlimbs = u? 1:0;
mpi-genesis 444 w->sign = 0;
mpi-genesis 445 w->nbits = 0;
mpi-genesis 446 w->flags = 0;
mpi-genesis 447 }
mpi-genesis 448
mpi-genesis 449
mpi-genesis 450 MPI
mpi-genesis 451 mpi_alloc_set_ui( unsigned long u)
mpi-genesis 452 {
mpi-genesis 453 #ifdef M_DEBUG
mpi-genesis 454 MPI w = mpi_debug_alloc(1,"alloc_set_ui");
mpi-genesis 455 #else
mpi-genesis 456 MPI w = mpi_alloc(1);
mpi-genesis 457 #endif
mpi-genesis 458 w->d[0] = u;
mpi-genesis 459 w->nlimbs = u? 1:0;
mpi-genesis 460 w->sign = 0;
mpi-genesis 461 return w;
mpi-genesis 462 }
mpi-genesis 463
mpi-genesis 464
mpi-genesis 465 void
mpi-genesis 466 mpi_swap( MPI a, MPI b)
mpi-genesis 467 {
mpi-genesis 468 struct gcry_mpi tmp;
mpi-genesis 469
mpi-genesis 470 tmp = *a; *a = *b; *b = tmp;
mpi-genesis 471 }
mpi-genesis 472
mpi-genesis 473
mpi-genesis 474 int
mpi-genesis 475 mpi_get_nlimbs (MPI a)
mpi-genesis 476 {
mpi-genesis 477 return a->nlimbs;
mpi-genesis 478 }
mpi-genesis 479
mpi-genesis 480
mpi-genesis 481 int
mpi-genesis 482 mpi_is_neg (MPI a)
mpi-genesis 483 {
mpi-genesis 484 return a->sign;
mpi-genesis 485 }
mpi-genesis 486
mpi-genesis 487
mpi-genesis 488 /* Return the number of limbs to store an MPI which is specified by
mpi-genesis 489 the number of bytes to represent it. */
mpi-genesis 490 unsigned int
mpi-genesis 491 mpi_nlimb_hint_from_nbytes (unsigned int nbytes)
mpi-genesis 492 {
mpi-genesis 493 return (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB;
mpi-genesis 494 }
mpi-genesis 495
mpi-genesis 496 /* Return the number of limbs to store an MPI which is specified by
mpi-genesis 497 the number of bytes to represent it. */
mpi-genesis 498 unsigned int
mpi-genesis 499 mpi_nlimb_hint_from_nbits (unsigned int nbits)
mpi-genesis 500 {
mpi-genesis 501 return (nbits+BITS_PER_MPI_LIMB-1) / BITS_PER_MPI_LIMB;
mpi-genesis 502 }
mpi-genesis 503
mpi-genesis 504 unsigned int
mpi-genesis 505 mpi_get_flags (MPI a)
mpi-genesis 506 {
mpi-genesis 507 return a->flags;
mpi-genesis 508 }