mpi-genesis~ 1
mpi-genesis~ 2 * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc.
mpi-genesis~ 3 *
mpi-genesis~ 4 * This file is part of GnuPG.
mpi-genesis~ 5 *
mpi-genesis~ 6 * GnuPG is free software; you can redistribute it and/or modify
mpi-genesis~ 7 * it under the terms of the GNU General Public License as published by
mpi-genesis~ 8 * the Free Software Foundation; either version 3 of the License, or
mpi-genesis~ 9 * (at your option) any later version.
mpi-genesis~ 10 *
mpi-genesis~ 11 * GnuPG is distributed in the hope that it will be useful,
mpi-genesis~ 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mpi-genesis~ 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mpi-genesis~ 14 * GNU General Public License for more details.
mpi-genesis~ 15 *
mpi-genesis~ 16 * You should have received a copy of the GNU General Public License
mpi-genesis~ 17 * along with this program; if not, see <http:
mpi-genesis~ 18 */
mpi-genesis~ 19
mpi-genesis~ 20 #include <config.h>
mpi-genesis~ 21 #include <stdio.h>
mpi-genesis~ 22 #include <string.h>
mpi-genesis~ 23 #include <stdlib.h>
mpi-genesis~ 24 #include <assert.h>
mpi-genesis~ 25
mpi-genesis~ 26 #include "mpi.h"
mpi-genesis~ 27 #include "mpi-internal.h"
mpi-genesis~ 28 #include "iobuf.h"
mpi-genesis~ 29 #include "memory.h"
mpi-genesis~ 30 #include "util.h"
mpi-genesis~ 31
mpi-genesis~ 32 #ifdef M_DEBUG
mpi-genesis~ 33 #undef mpi_read
mpi-genesis~ 34 #endif
mpi-genesis~ 35
mpi-genesis~ 36 #define MAX_EXTERN_MPI_BITS 16384
mpi-genesis~ 37
mpi-genesis~ 38
mpi-genesis~ 39 * write an mpi to out.
mpi-genesis~ 40 */
mpi-genesis~ 41 int
mpi-genesis~ 42 mpi_write( IOBUF out, MPI a )
mpi-genesis~ 43 {
mpi-genesis~ 44 int rc;
mpi-genesis~ 45 unsigned nbits = mpi_get_nbits(a);
mpi-genesis~ 46 byte *p, *buf;
mpi-genesis~ 47 unsigned n;
mpi-genesis~ 48
mpi-genesis~ 49 if( nbits > MAX_EXTERN_MPI_BITS )
mpi-genesis~ 50 log_bug("mpi_encode: mpi too large (%u bits)\n", nbits);
mpi-genesis~ 51
mpi-genesis~ 52 iobuf_put(out, (nbits >>8) );
mpi-genesis~ 53 iobuf_put(out, (nbits) );
mpi-genesis~ 54
mpi-genesis~ 55 p = buf = mpi_get_buffer( a, &n, NULL );
mpi-genesis~ 56 rc = iobuf_write( out, p, n );
mpi-genesis~ 57 xfree(buf);
mpi-genesis~ 58 return rc;
mpi-genesis~ 59 }
mpi-genesis~ 60
mpi-genesis~ 61
mpi-genesis~ 62
mpi-genesis~ 63 * Read an external representation of an mpi and return the MPI
mpi-genesis~ 64 * The external format is a 16 bit unsigned value stored in network byte order,
mpi-genesis~ 65 * giving the number of bits for the following integer. The integer is stored
mpi-genesis~ 66 * with MSB first (left padded with zeroes to align on a byte boundary).
mpi-genesis~ 67 */
mpi-genesis~ 68 MPI
mpi-genesis~ 69 #ifdef M_DEBUG
mpi-genesis~ 70 mpi_debug_read(IOBUF inp, unsigned *ret_nread, int secure, const char *info)
mpi-genesis~ 71 #else
mpi-genesis~ 72 mpi_read(IOBUF inp, unsigned *ret_nread, int secure)
mpi-genesis~ 73 #endif
mpi-genesis~ 74 {
mpi-genesis~ 75 int c, i, j;
mpi-genesis~ 76 unsigned int nmax = *ret_nread;
mpi-genesis~ 77 unsigned nbits, nbytes, nlimbs, nread=0;
mpi-genesis~ 78 mpi_limb_t a;
mpi-genesis~ 79 MPI val = NULL;
mpi-genesis~ 80
mpi-genesis~ 81 if (nread == nmax)
mpi-genesis~ 82 goto overflow;
mpi-genesis~ 83 if( (c = iobuf_get(inp)) == -1 )
mpi-genesis~ 84 goto leave;
mpi-genesis~ 85 nread++;
mpi-genesis~ 86 nbits = c << 8;
mpi-genesis~ 87
mpi-genesis~ 88 if (nread == nmax)
mpi-genesis~ 89 goto overflow;
mpi-genesis~ 90 if( (c = iobuf_get(inp)) == -1 )
mpi-genesis~ 91 goto leave;
mpi-genesis~ 92 nread++;
mpi-genesis~ 93 nbits |= c;
mpi-genesis~ 94
mpi-genesis~ 95 if( nbits > MAX_EXTERN_MPI_BITS ) {
mpi-genesis~ 96 log_error("mpi too large for this implementation (%u bits)\n", nbits);
mpi-genesis~ 97 goto leave;
mpi-genesis~ 98 }
mpi-genesis~ 99
mpi-genesis~ 100 nbytes = (nbits+7) / 8;
mpi-genesis~ 101 nlimbs = (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB;
mpi-genesis~ 102 #ifdef M_DEBUG
mpi-genesis~ 103 val = secure? mpi_debug_alloc_secure( nlimbs, info )
mpi-genesis~ 104 : mpi_debug_alloc( nlimbs, info );
mpi-genesis~ 105 #else
mpi-genesis~ 106 val = secure? mpi_alloc_secure( nlimbs )
mpi-genesis~ 107 : mpi_alloc( nlimbs );
mpi-genesis~ 108 #endif
mpi-genesis~ 109 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
mpi-genesis~ 110 i %= BYTES_PER_MPI_LIMB;
mpi-genesis~ 111 val->nbits = nbits;
mpi-genesis~ 112 j= val->nlimbs = nlimbs;
mpi-genesis~ 113 val->sign = 0;
mpi-genesis~ 114 for( ; j > 0; j-- ) {
mpi-genesis~ 115 a = 0;
mpi-genesis~ 116 for(; i < BYTES_PER_MPI_LIMB; i++ ) {
mpi-genesis~ 117 if (nread == nmax) {
mpi-genesis~ 118 #ifdef M_DEBUG
mpi-genesis~ 119 mpi_debug_free (val);
mpi-genesis~ 120 #else
mpi-genesis~ 121 mpi_free (val);
mpi-genesis~ 122 #endif
mpi-genesis~ 123 val = NULL;
mpi-genesis~ 124 goto overflow;
mpi-genesis~ 125 }
mpi-genesis~ 126 a <<= 8;
mpi-genesis~ 127 a |= iobuf_get(inp) & 0xff; nread++;
mpi-genesis~ 128 }
mpi-genesis~ 129 i = 0;
mpi-genesis~ 130 val->d[j-1] = a;
mpi-genesis~ 131 }
mpi-genesis~ 132
mpi-genesis~ 133 leave:
mpi-genesis~ 134 *ret_nread = nread;
mpi-genesis~ 135 return val;
mpi-genesis~ 136 overflow:
mpi-genesis~ 137 log_error ("mpi larger than indicated length (%u bytes)\n", nmax);
mpi-genesis~ 138 *ret_nread = nread;
mpi-genesis~ 139 return val;
mpi-genesis~ 140 }
mpi-genesis~ 141
mpi-genesis~ 142
mpi-genesis~ 143 MPI
mpi-genesis~ 144 mpi_read_from_buffer(byte *buffer, unsigned int *ret_nread, int secure)
mpi-genesis~ 145 {
mpi-genesis~ 146 int i, j;
mpi-genesis~ 147 unsigned nbits, nbytes, nlimbs, nread=0;
mpi-genesis~ 148 mpi_limb_t a;
mpi-genesis~ 149 MPI val = NULL;
mpi-genesis~ 150
mpi-genesis~ 151 if( *ret_nread < 2 )
mpi-genesis~ 152 goto leave;
mpi-genesis~ 153 nbits = buffer[0] << 8 | buffer[1];
mpi-genesis~ 154 if( nbits > MAX_EXTERN_MPI_BITS ) {
mpi-genesis~ 155 log_info ("mpi too large (%u bits)\n", nbits);
mpi-genesis~ 156 goto leave;
mpi-genesis~ 157 }
mpi-genesis~ 158 buffer += 2;
mpi-genesis~ 159 nread = 2;
mpi-genesis~ 160
mpi-genesis~ 161 nbytes = (nbits+7) / 8;
mpi-genesis~ 162 nlimbs = (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB;
mpi-genesis~ 163 val = secure? mpi_alloc_secure( nlimbs )
mpi-genesis~ 164 : mpi_alloc( nlimbs );
mpi-genesis~ 165 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
mpi-genesis~ 166 i %= BYTES_PER_MPI_LIMB;
mpi-genesis~ 167 val->nbits = nbits;
mpi-genesis~ 168 j= val->nlimbs = nlimbs;
mpi-genesis~ 169 val->sign = 0;
mpi-genesis~ 170 for( ; j > 0; j-- ) {
mpi-genesis~ 171 a = 0;
mpi-genesis~ 172 for(; i < BYTES_PER_MPI_LIMB; i++ ) {
mpi-genesis~ 173 if( ++nread > *ret_nread ) {
mpi-genesis~ 174
mpi-genesis~ 175 happen if we use this function to parse a decrypted
mpi-genesis~ 176 MPI which didn't turn out to be a real MPI - possible
mpi-genesis~ 177 because the supplied key was wrong but the OpenPGP
mpi-genesis~ 178 checksum didn't caught it. */
mpi-genesis~ 179 log_info ("mpi larger than buffer\n");
mpi-genesis~ 180 mpi_free (val);
mpi-genesis~ 181 val = NULL;
mpi-genesis~ 182 goto leave;
mpi-genesis~ 183 }
mpi-genesis~ 184 a <<= 8;
mpi-genesis~ 185 a |= *buffer++;
mpi-genesis~ 186 }
mpi-genesis~ 187 i = 0;
mpi-genesis~ 188 val->d[j-1] = a;
mpi-genesis~ 189 }
mpi-genesis~ 190
mpi-genesis~ 191 leave:
mpi-genesis~ 192 *ret_nread = nread;
mpi-genesis~ 193 return val;
mpi-genesis~ 194 }
mpi-genesis~ 195
mpi-genesis~ 196
mpi-genesis~ 197
mpi-genesis~ 198 * Make an mpi from a character string.
mpi-genesis~ 199 */
mpi-genesis~ 200 int
mpi-genesis~ 201 mpi_fromstr(MPI val, const char *str)
mpi-genesis~ 202 {
mpi-genesis~ 203 int hexmode=0, sign=0, prepend_zero=0, i, j, c, c1, c2;
mpi-genesis~ 204 unsigned nbits, nbytes, nlimbs;
mpi-genesis~ 205 mpi_limb_t a;
mpi-genesis~ 206
mpi-genesis~ 207 if( *str == '-' ) {
mpi-genesis~ 208 sign = 1;
mpi-genesis~ 209 str++;
mpi-genesis~ 210 }
mpi-genesis~ 211 if( *str == '0' && str[1] == 'x' )
mpi-genesis~ 212 hexmode = 1;
mpi-genesis~ 213 else
mpi-genesis~ 214 return 1;
mpi-genesis~ 215 str += 2;
mpi-genesis~ 216
mpi-genesis~ 217 nbits = strlen(str)*4;
mpi-genesis~ 218 if( nbits % 8 )
mpi-genesis~ 219 prepend_zero = 1;
mpi-genesis~ 220 nbytes = (nbits+7) / 8;
mpi-genesis~ 221 nlimbs = (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB;
mpi-genesis~ 222 if( val->alloced < nlimbs )
mpi-genesis~ 223 mpi_resize(val, nlimbs );
mpi-genesis~ 224 i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
mpi-genesis~ 225 i %= BYTES_PER_MPI_LIMB;
mpi-genesis~ 226 j= val->nlimbs = nlimbs;
mpi-genesis~ 227 val->sign = sign;
mpi-genesis~ 228 for( ; j > 0; j-- ) {
mpi-genesis~ 229 a = 0;
mpi-genesis~ 230 for(; i < BYTES_PER_MPI_LIMB; i++ ) {
mpi-genesis~ 231 if( prepend_zero ) {
mpi-genesis~ 232 c1 = '0';
mpi-genesis~ 233 prepend_zero = 0;
mpi-genesis~ 234 }
mpi-genesis~ 235 else
mpi-genesis~ 236 c1 = *str++;
mpi-genesis~ 237 assert(c1);
mpi-genesis~ 238 c2 = *str++;
mpi-genesis~ 239 assert(c2);
mpi-genesis~ 240 if( c1 >= '0' && c1 <= '9' )
mpi-genesis~ 241 c = c1 - '0';
mpi-genesis~ 242 else if( c1 >= 'a' && c1 <= 'f' )
mpi-genesis~ 243 c = c1 - 'a' + 10;
mpi-genesis~ 244 else if( c1 >= 'A' && c1 <= 'F' )
mpi-genesis~ 245 c = c1 - 'A' + 10;
mpi-genesis~ 246 else {
mpi-genesis~ 247 mpi_clear(val);
mpi-genesis~ 248 return 1;
mpi-genesis~ 249 }
mpi-genesis~ 250 c <<= 4;
mpi-genesis~ 251 if( c2 >= '0' && c2 <= '9' )
mpi-genesis~ 252 c |= c2 - '0';
mpi-genesis~ 253 else if( c2 >= 'a' && c2 <= 'f' )
mpi-genesis~ 254 c |= c2 - 'a' + 10;
mpi-genesis~ 255 else if( c2 >= 'A' && c2 <= 'F' )
mpi-genesis~ 256 c |= c2 - 'A' + 10;
mpi-genesis~ 257 else {
mpi-genesis~ 258 mpi_clear(val);
mpi-genesis~ 259 return 1;
mpi-genesis~ 260 }
mpi-genesis~ 261 a <<= 8;
mpi-genesis~ 262 a |= c;
mpi-genesis~ 263 }
mpi-genesis~ 264 i = 0;
mpi-genesis~ 265 val->d[j-1] = a;
mpi-genesis~ 266 }
mpi-genesis~ 267
mpi-genesis~ 268 return 0;
mpi-genesis~ 269 }
mpi-genesis~ 270
mpi-genesis~ 271
mpi-genesis~ 272
mpi-genesis~ 273 * print an MPI to the given stream and return the number of characters
mpi-genesis~ 274 * printed.
mpi-genesis~ 275 */
mpi-genesis~ 276 int
mpi-genesis~ 277 mpi_print( FILE *fp, MPI a, int mode )
mpi-genesis~ 278 {
mpi-genesis~ 279 int i, n=0;
mpi-genesis~ 280
mpi-genesis~ 281 if( a == NULL )
mpi-genesis~ 282 return fprintf(fp, "[MPI_NULL]");
mpi-genesis~ 283 if( !mode ) {
mpi-genesis~ 284 unsigned int n1;
mpi-genesis~ 285
mpi-genesis~ 286 n1 = mpi_get_nbits(a);
mpi-genesis~ 287 n += fprintf(fp, "[%u bits]", n1);
mpi-genesis~ 288 }
mpi-genesis~ 289 else {
mpi-genesis~ 290 if( a->sign )
mpi-genesis~ 291 putc('-', fp);
mpi-genesis~ 292 #if BYTES_PER_MPI_LIMB == 2
mpi-genesis~ 293 #define X "4"
mpi-genesis~ 294 #elif BYTES_PER_MPI_LIMB == 4
mpi-genesis~ 295 #define X "8"
mpi-genesis~ 296 #elif BYTES_PER_MPI_LIMB == 8
mpi-genesis~ 297 #define X "16"
mpi-genesis~ 298 #else
mpi-genesis~ 299 #error please define the format here
mpi-genesis~ 300 #endif
mpi-genesis~ 301 for(i=a->nlimbs; i > 0 ; i-- ) {
mpi-genesis~ 302 n += fprintf(fp, i!=a->nlimbs? "%0" X "lX":"%lX", (ulong)a->d[i-1]);
mpi-genesis~ 303 #undef X
mpi-genesis~ 304 }
mpi-genesis~ 305 if( !a->nlimbs )
mpi-genesis~ 306 putc('0', fp );
mpi-genesis~ 307 }
mpi-genesis~ 308 return n;
mpi-genesis~ 309 }
mpi-genesis~ 310
mpi-genesis~ 311
mpi-genesis~ 312 void
mpi-genesis~ 313 g10_log_mpidump( const char *text, MPI a )
mpi-genesis~ 314 {
mpi-genesis~ 315 FILE *fp = log_stream();
mpi-genesis~ 316
mpi-genesis~ 317 g10_log_print_prefix(text);
mpi-genesis~ 318 mpi_print(fp, a, 1 );
mpi-genesis~ 319 fputc('\n', fp);
mpi-genesis~ 320 }
mpi-genesis~ 321
mpi-genesis~ 322
mpi-genesis~ 323 * Special function to get the low 8 bytes from an mpi.
mpi-genesis~ 324 * This can be used as a keyid; KEYID is an 2 element array.
mpi-genesis~ 325 * Return the low 4 bytes.
mpi-genesis~ 326 */
mpi-genesis~ 327 u32
mpi-genesis~ 328 mpi_get_keyid( MPI a, u32 *keyid )
mpi-genesis~ 329 {
mpi-genesis~ 330 #if BYTES_PER_MPI_LIMB == 4
mpi-genesis~ 331 if( keyid ) {
mpi-genesis~ 332 keyid[0] = a->nlimbs >= 2? a->d[1] : 0;
mpi-genesis~ 333 keyid[1] = a->nlimbs >= 1? a->d[0] : 0;
mpi-genesis~ 334 }
mpi-genesis~ 335 return a->nlimbs >= 1? a->d[0] : 0;
mpi-genesis~ 336 #elif BYTES_PER_MPI_LIMB == 8
mpi-genesis~ 337 if( keyid ) {
mpi-genesis~ 338 keyid[0] = a->nlimbs? (u32)(a->d[0] >> 32) : 0;
mpi-genesis~ 339 keyid[1] = a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0;
mpi-genesis~ 340 }
mpi-genesis~ 341 return a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0;
mpi-genesis~ 342 #else
mpi-genesis~ 343 #error Make this function work with other LIMB sizes
mpi-genesis~ 344 #endif
mpi-genesis~ 345 }
mpi-genesis~ 346
mpi-genesis~ 347
mpi-genesis~ 348
mpi-genesis~ 349 * Return an xmalloced buffer with the MPI (msb first).
mpi-genesis~ 350 * NBYTES receives the length of this buffer. Caller must free the
mpi-genesis~ 351 * return string (This function does return a 0 byte buffer with NBYTES
mpi-genesis~ 352 * set to zero if the value of A is zero. If sign is not NULL, it will
mpi-genesis~ 353 * be set to the sign of the A.
mpi-genesis~ 354 */
mpi-genesis~ 355 static byte *
mpi-genesis~ 356 do_get_buffer( MPI a, unsigned *nbytes, int *sign, int force_secure )
mpi-genesis~ 357 {
mpi-genesis~ 358 byte *p, *buffer;
mpi-genesis~ 359 mpi_limb_t alimb;
mpi-genesis~ 360 int i;
mpi-genesis~ 361 unsigned int n;
mpi-genesis~ 362
mpi-genesis~ 363 if( sign )
mpi-genesis~ 364 *sign = a->sign;
mpi-genesis~ 365 *nbytes = n = a->nlimbs * BYTES_PER_MPI_LIMB;
mpi-genesis~ 366 if (!n)
mpi-genesis~ 367 n++;
mpi-genesis~ 368 p = buffer = force_secure || mpi_is_secure(a) ? xmalloc_secure(n)
mpi-genesis~ 369 : xmalloc(n);
mpi-genesis~ 370
mpi-genesis~ 371 for(i=a->nlimbs-1; i >= 0; i-- ) {
mpi-genesis~ 372 alimb = a->d[i];
mpi-genesis~ 373 #if BYTES_PER_MPI_LIMB == 4
mpi-genesis~ 374 *p++ = alimb >> 24;
mpi-genesis~ 375 *p++ = alimb >> 16;
mpi-genesis~ 376 *p++ = alimb >> 8;
mpi-genesis~ 377 *p++ = alimb ;
mpi-genesis~ 378 #elif BYTES_PER_MPI_LIMB == 8
mpi-genesis~ 379 *p++ = alimb >> 56;
mpi-genesis~ 380 *p++ = alimb >> 48;
mpi-genesis~ 381 *p++ = alimb >> 40;
mpi-genesis~ 382 *p++ = alimb >> 32;
mpi-genesis~ 383 *p++ = alimb >> 24;
mpi-genesis~ 384 *p++ = alimb >> 16;
mpi-genesis~ 385 *p++ = alimb >> 8;
mpi-genesis~ 386 *p++ = alimb ;
mpi-genesis~ 387 #else
mpi-genesis~ 388 #error please implement for this limb size.
mpi-genesis~ 389 #endif
mpi-genesis~ 390 }
mpi-genesis~ 391
mpi-genesis~ 392
mpi-genesis~ 393 * because the caller has to free the returned buffer */
mpi-genesis~ 394 for(p=buffer; !*p && *nbytes; p++, --*nbytes )
mpi-genesis~ 395 ;
mpi-genesis~ 396 if( p != buffer )
mpi-genesis~ 397 memmove(buffer,p, *nbytes);
mpi-genesis~ 398
mpi-genesis~ 399 return buffer;
mpi-genesis~ 400 }
mpi-genesis~ 401
mpi-genesis~ 402
mpi-genesis~ 403 byte *
mpi-genesis~ 404 mpi_get_buffer( MPI a, unsigned *nbytes, int *sign )
mpi-genesis~ 405 {
mpi-genesis~ 406 return do_get_buffer( a, nbytes, sign, 0 );
mpi-genesis~ 407 }
mpi-genesis~ 408
mpi-genesis~ 409 byte *
mpi-genesis~ 410 mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign )
mpi-genesis~ 411 {
mpi-genesis~ 412 return do_get_buffer( a, nbytes, sign, 1 );
mpi-genesis~ 413 }
mpi-genesis~ 414
mpi-genesis~ 415
mpi-genesis~ 416 * Use BUFFER to update MPI.
mpi-genesis~ 417 */
mpi-genesis~ 418 void
mpi-genesis~ 419 mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign )
mpi-genesis~ 420 {
mpi-genesis~ 421 const byte *p;
mpi-genesis~ 422 mpi_limb_t alimb;
mpi-genesis~ 423 int nlimbs;
mpi-genesis~ 424 int i;
mpi-genesis~ 425
mpi-genesis~ 426 nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB;
mpi-genesis~ 427 RESIZE_IF_NEEDED(a, nlimbs);
mpi-genesis~ 428 a->sign = sign;
mpi-genesis~ 429
mpi-genesis~ 430 for(i=0, p = buffer+nbytes-1; p >= buffer+BYTES_PER_MPI_LIMB; ) {
mpi-genesis~ 431 #if BYTES_PER_MPI_LIMB == 4
mpi-genesis~ 432 alimb = (mpi_limb_t)*p-- ;
mpi-genesis~ 433 alimb |= (mpi_limb_t)*p-- << 8 ;
mpi-genesis~ 434 alimb |= (mpi_limb_t)*p-- << 16 ;
mpi-genesis~ 435 alimb |= (mpi_limb_t)*p-- << 24 ;
mpi-genesis~ 436 #elif BYTES_PER_MPI_LIMB == 8
mpi-genesis~ 437 alimb = (mpi_limb_t)*p-- ;
mpi-genesis~ 438 alimb |= (mpi_limb_t)*p-- << 8 ;
mpi-genesis~ 439 alimb |= (mpi_limb_t)*p-- << 16 ;
mpi-genesis~ 440 alimb |= (mpi_limb_t)*p-- << 24 ;
mpi-genesis~ 441 alimb |= (mpi_limb_t)*p-- << 32 ;
mpi-genesis~ 442 alimb |= (mpi_limb_t)*p-- << 40 ;
mpi-genesis~ 443 alimb |= (mpi_limb_t)*p-- << 48 ;
mpi-genesis~ 444 alimb |= (mpi_limb_t)*p-- << 56 ;
mpi-genesis~ 445 #else
mpi-genesis~ 446 #error please implement for this limb size.
mpi-genesis~ 447 #endif
mpi-genesis~ 448 a->d[i++] = alimb;
mpi-genesis~ 449 }
mpi-genesis~ 450 if( p >= buffer ) {
mpi-genesis~ 451 #if BYTES_PER_MPI_LIMB == 4
mpi-genesis~ 452 alimb = *p-- ;
mpi-genesis~ 453 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 8 ;
mpi-genesis~ 454 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 16 ;
mpi-genesis~ 455 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 24 ;
mpi-genesis~ 456 #elif BYTES_PER_MPI_LIMB == 8
mpi-genesis~ 457 alimb = (mpi_limb_t)*p-- ;
mpi-genesis~ 458 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 8 ;
mpi-genesis~ 459 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 16 ;
mpi-genesis~ 460 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 24 ;
mpi-genesis~ 461 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 32 ;
mpi-genesis~ 462 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 40 ;
mpi-genesis~ 463 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 48 ;
mpi-genesis~ 464 if( p >= buffer ) alimb |= (mpi_limb_t)*p-- << 56 ;
mpi-genesis~ 465 #else
mpi-genesis~ 466 #error please implement for this limb size.
mpi-genesis~ 467 #endif
mpi-genesis~ 468 a->d[i++] = alimb;
mpi-genesis~ 469 }
mpi-genesis~ 470 a->nlimbs = i;
mpi-genesis~ 471 assert( i == nlimbs );
mpi-genesis~ 472 }