11558Srgrimes/*	$NetBSD: bn_mp_reduce_is_2k_l.c,v 1.2 2017/01/28 21:31:47 christos Exp $	*/
21558Srgrimes
31558Srgrimes#include <tommath.h>
41558Srgrimes#ifdef BN_MP_REDUCE_IS_2K_L_C
51558Srgrimes/* LibTomMath, multiple-precision integer library -- Tom St Denis
61558Srgrimes *
71558Srgrimes * LibTomMath is a library that provides multiple-precision
81558Srgrimes * integer arithmetic as well as number theoretic functionality.
91558Srgrimes *
101558Srgrimes * The library was designed directly after the MPI library by
111558Srgrimes * Michael Fromberger but has been written from scratch with
121558Srgrimes * additional optimizations in place.
131558Srgrimes *
141558Srgrimes * The library is free for all purposes without any express
151558Srgrimes * guarantee it works.
161558Srgrimes *
171558Srgrimes * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
181558Srgrimes */
191558Srgrimes
201558Srgrimes/* determines if reduce_2k_l can be used */
211558Srgrimesint mp_reduce_is_2k_l(mp_int *a)
221558Srgrimes{
231558Srgrimes   int ix, iy;
241558Srgrimes
251558Srgrimes   if (a->used == 0) {
261558Srgrimes      return MP_NO;
271558Srgrimes   } else if (a->used == 1) {
281558Srgrimes      return MP_YES;
291558Srgrimes   } else if (a->used > 1) {
301558Srgrimes      /* if more than half of the digits are -1 we're sold */
311558Srgrimes      for (iy = ix = 0; ix < a->used; ix++) {
321558Srgrimes          if (a->dp[ix] == MP_MASK) {
331558Srgrimes              ++iy;
341558Srgrimes          }
351558Srgrimes      }
361558Srgrimes      return (iy >= (a->used/2)) ? MP_YES : MP_NO;
371558Srgrimes
381558Srgrimes   }
391558Srgrimes   return MP_NO;
4037906Scharnier}
4123685Speter
4237906Scharnier#endif
4337906Scharnier
4450476Speter/* Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v  */
451558Srgrimes/* Revision: 1.4  */
461558Srgrimes/* Date: 2006/12/28 01:25:13  */
471558Srgrimes