1/* $NetBSD$ */ 2 3#include <tommath.h> 4#ifdef BN_MP_GET_INT_C 5/* LibTomMath, multiple-precision integer library -- Tom St Denis 6 * 7 * LibTomMath is a library that provides multiple-precision 8 * integer arithmetic as well as number theoretic functionality. 9 * 10 * The library was designed directly after the MPI library by 11 * Michael Fromberger but has been written from scratch with 12 * additional optimizations in place. 13 * 14 * The library is free for all purposes without any express 15 * guarantee it works. 16 * 17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 18 */ 19 20/* get the lower 32-bits of an mp_int */ 21unsigned long mp_get_int(mp_int * a) 22{ 23 int i; 24 unsigned long res; 25 26 if (a->used == 0) { 27 return 0; 28 } 29 30 /* get number of digits of the lsb we have to read */ 31 i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1; 32 33 /* get most significant digit of result */ 34 res = DIGIT(a,i); 35 36 while (--i >= 0) { 37 res = (res << DIGIT_BIT) | DIGIT(a,i); 38 } 39 40 /* force result to 32-bits always so it is consistent on non 32-bit platforms */ 41 return res & 0xFFFFFFFFUL; 42} 43#endif 44 45/* Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v */ 46/* Revision: 1.4 */ 47/* Date: 2006/12/28 01:25:13 */ 48