bn_mp_cmp_mag.cGo to the documentation of this file.00001 #include <tommath.h> 00002 #ifdef BN_MP_CMP_MAG_C 00003 /* LibTomMath, multiple-precision integer library -- Tom St Denis 00004 * 00005 * LibTomMath is a library that provides multiple-precision 00006 * integer arithmetic as well as number theoretic functionality. 00007 * 00008 * The library was designed directly after the MPI library by 00009 * Michael Fromberger but has been written from scratch with 00010 * additional optimizations in place. 00011 * 00012 * The library is free for all purposes without any express 00013 * guarantee it works. 00014 * 00015 * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com 00016 */ 00017 00018 /* compare maginitude of two ints (unsigned) */ 00019 int mp_cmp_mag (mp_int * a, mp_int * b) 00020 { 00021 int n; 00022 mp_digit *tmpa, *tmpb; 00023 00024 /* compare based on # of non-zero digits */ 00025 if (a->used > b->used) { 00026 return MP_GT; 00027 } 00028 00029 if (a->used < b->used) { 00030 return MP_LT; 00031 } 00032 00033 /* alias for a */ 00034 tmpa = a->dp + (a->used - 1); 00035 00036 /* alias for b */ 00037 tmpb = b->dp + (a->used - 1); 00038 00039 /* compare based on digits */ 00040 for (n = 0; n < a->used; ++n, --tmpa, --tmpb) { 00041 if (*tmpa > *tmpb) { 00042 return MP_GT; 00043 } 00044 00045 if (*tmpa < *tmpb) { 00046 return MP_LT; 00047 } 00048 } 00049 return MP_EQ; 00050 } 00051 #endif 00052 00053 /* $Source: /cvsroot/tcl/libtommath/bn_mp_cmp_mag.c,v $ */ 00054 /* $Revision: 1.1.1.3 $ */ 00055 /* $Date: 2006/12/01 00:08:11 $ */
Generated on Wed Mar 12 12:18:24 2008 by 1.5.1 |