Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

mp.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002, 2003 Bob Deblier
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  */
00019 
00041 #ifndef _MP_H
00042 #define _MP_H
00043 
00044 #include "beecrypt.api.h"
00045 #include "mpopt.h"
00046 
00047 #define MP_HWBITS   (MP_WBITS >> 1)
00048 #define MP_WBYTES   (MP_WBITS >> 3)
00049 #define MP_WNIBBLES (MP_WBITS >> 2)
00050 
00051 #if (MP_WBITS == 64)
00052 # define MP_WORDS_TO_BITS(x)    ((x) << 6)
00053 # define MP_WORDS_TO_NIBBLES(x) ((x) << 4)
00054 # define MP_WORDS_TO_BYTES(x)   ((x) << 3)
00055 # define MP_BITS_TO_WORDS(x)    ((x) >> 6)
00056 # define MP_NIBBLES_TO_WORDS(x) ((x) >> 4)
00057 # define MP_BYTES_TO_WORDS(x)   ((x) >> 3)
00058 #elif (MP_WBITS == 32)
00059 # define MP_WORDS_TO_BITS(x)    ((x) << 5)
00060 # define MP_WORDS_TO_NIBBLES(x) ((x) << 3)
00061 # define MP_WORDS_TO_BYTES(x)   ((x) << 2)
00062 # define MP_BITS_TO_WORDS(x)    ((x) >> 5) 
00063 # define MP_NIBBLES_TO_WORDS(x) ((x) >> 3)
00064 # define MP_BYTES_TO_WORDS(x)   ((x) >> 2)
00065 #else
00066 # error
00067 #endif
00068 
00069 #define MP_MSBMASK  (((mpw) 0x1) << (MP_WBITS-1))
00070 #define MP_LSBMASK   ((mpw) 0x1)
00071 #define MP_ALLMASK  ~((mpw) 0x0)
00072 
00073 #ifdef __cplusplus
00074 extern "C" {
00075 #endif
00076 
00077 #ifndef ASM_MPCOPY
00078 # define mpcopy(size, dst, src) memcpy(dst, src, MP_WORDS_TO_BYTES(size))
00079 #else
00080 BEECRYPTAPI
00081 void mpcopy(size_t size, mpw* dest, const mpw* src);
00082 #endif
00083 
00084 #ifndef ASM_MPMOVE
00085 # define mpmove(size, dst, src) memmove(dst, src, MP_WORDS_TO_BYTES(size))
00086 #else
00087 BEECRYPTAPI
00088 void mpmove(size_t size, mpw* dest, const mpw* src);
00089 #endif
00090 
00096 BEECRYPTAPI
00097 void mpzero(size_t size, mpw* data);
00098 
00106 BEECRYPTAPI
00107 void mpfill(size_t size, mpw* data, mpw fill);
00108 
00116 BEECRYPTAPI
00117 int mpodd (size_t size, const mpw* data);
00118 
00126 BEECRYPTAPI
00127 int mpeven(size_t size, const mpw* data);
00128 
00136 BEECRYPTAPI
00137 int mpz  (size_t size, const mpw* data);
00138 
00146 BEECRYPTAPI
00147 int mpnz (size_t size, const mpw* data);
00148 
00158 BEECRYPTAPI
00159 int mpeq (size_t size, const mpw* xdata, const mpw* ydata);
00160 
00170 BEECRYPTAPI
00171 int mpne (size_t size, const mpw* xdata, const mpw* ydata);
00172 
00183 BEECRYPTAPI
00184 int mpgt (size_t size, const mpw* xdata, const mpw* ydata);
00185 
00196 BEECRYPTAPI
00197 int mplt (size_t size, const mpw* xdata, const mpw* ydata);
00198 
00209 BEECRYPTAPI
00210 int mpge (size_t size, const mpw* xdata, const mpw* ydata);
00211 
00222 BEECRYPTAPI
00223 int mple (size_t size, const mpw* xdata, const mpw* ydata);
00224 
00235 BEECRYPTAPI
00236 int mpeqx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00237 
00248 BEECRYPTAPI
00249 int mpnex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00250 
00262 BEECRYPTAPI
00263 int mpgtx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00264 
00276 BEECRYPTAPI
00277 int mpltx(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00278 
00290 BEECRYPTAPI
00291 int mpgex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00292 
00304 BEECRYPTAPI
00305 int mplex(size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00306 
00315 BEECRYPTAPI
00316 int mpisone(size_t size, const mpw* data);
00317 
00326 BEECRYPTAPI
00327 int mpistwo(size_t size, const mpw* data);
00328 
00337 BEECRYPTAPI
00338 int mpleone(size_t size, const mpw* data);
00339 
00349 BEECRYPTAPI
00350 int mpeqmone(size_t size, const mpw* xdata, const mpw* ydata);
00351 
00360 BEECRYPTAPI
00361 int mpmsbset(size_t size, const mpw* data);
00362 
00371 BEECRYPTAPI
00372 int mplsbset(size_t size, const mpw* data);
00373 
00380 BEECRYPTAPI
00381 void mpsetmsb(size_t size, mpw* data);
00382 
00389 BEECRYPTAPI
00390 void mpsetlsb(size_t size, mpw* data);
00391 
00398 BEECRYPTAPI
00399 void mpclrmsb(size_t size, mpw* data);
00400 
00407 BEECRYPTAPI
00408 void mpclrlsb(size_t size, mpw* data);
00409 
00417 BEECRYPTAPI
00418 void mpand(size_t size, mpw* xdata, const mpw* ydata);
00419 
00427 BEECRYPTAPI
00428 void mpor(size_t size, mpw* xdata, const mpw* ydata);
00429 
00437 BEECRYPTAPI
00438 void mpxor(size_t size, mpw* xdata, const mpw* ydata);
00439 
00445 BEECRYPTAPI
00446 void mpnot(size_t size, mpw* data);
00447 
00456 BEECRYPTAPI
00457 void mpsetw(size_t size, mpw* xdata, mpw y);
00458 
00468 void mpsetx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata);
00469 
00478 BEECRYPTAPI
00479 int mpaddw(size_t size, mpw* xdata, mpw y);
00480 
00489 BEECRYPTAPI
00490 int mpadd (size_t size, mpw* xdata, const mpw* ydata);
00491 
00501 BEECRYPTAPI
00502 int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata);
00503 
00512 BEECRYPTAPI
00513 int mpsubw(size_t size, mpw* xdata, mpw y);
00514 
00523 BEECRYPTAPI
00524 int mpsub (size_t size, mpw* xdata, const mpw* ydata);
00525 
00535 BEECRYPTAPI
00536 int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata);
00537 
00538 BEECRYPTAPI
00539 int mpmultwo(size_t size, mpw* data);
00540 
00546 BEECRYPTAPI
00547 void mpneg(size_t size, mpw* data);
00548 
00555 BEECRYPTAPI
00556 size_t mpsize(size_t size, const mpw* data);
00557 
00564 BEECRYPTAPI
00565 size_t mpbits(size_t size, const mpw* data);
00566 
00567 BEECRYPTAPI
00568 size_t mpmszcnt(size_t size, const mpw* data);
00569 
00570 BEECRYPTAPI
00571 size_t mplszcnt(size_t size, const mpw* data);
00572 
00573 BEECRYPTAPI
00574 void mplshift(size_t size, mpw* data, size_t count);
00575 
00576 BEECRYPTAPI
00577 void mprshift(size_t size, mpw* data, size_t count);
00578 
00579 BEECRYPTAPI
00580 size_t mprshiftlsz(size_t size, mpw* data);
00581 
00582 BEECRYPTAPI
00583 size_t mpnorm(size_t size, mpw* data);
00584 
00585 BEECRYPTAPI
00586 void mpdivtwo (size_t size, mpw* data);
00587 
00588 BEECRYPTAPI
00589 void mpsdivtwo(size_t size, mpw* data);
00590 
00605 BEECRYPTAPI
00606 mpw mpsetmul   (size_t size, mpw* result, const mpw* data, mpw y);
00607 
00621 BEECRYPTAPI
00622 mpw mpaddmul   (size_t size, mpw* result, const mpw* data, mpw y);
00623 
00628 BEECRYPTAPI
00629 void mpaddsqrtrc(size_t size, mpw* result, const mpw* data);
00630 
00634 BEECRYPTAPI
00635 void mpmul(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata);
00636 
00640 BEECRYPTAPI
00641 void mpsqr(mpw* result, size_t size, const mpw* data);
00642 
00643 BEECRYPTAPI
00644 void mpgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* wksp);
00645 
00646 BEECRYPTAPI
00647 int  mpextgcd_w(size_t size, const mpw* xdata, const mpw* ydata, mpw* result, mpw* wksp);
00648 
00649 BEECRYPTAPI
00650 mpw mppndiv(mpw xhi, mpw xlo, mpw y);
00651 
00652 BEECRYPTAPI
00653 void mpmod (mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw*ydata, mpw* wksp);
00654 
00655 BEECRYPTAPI
00656 void mpndivmod(mpw* result, size_t xsize, const mpw* xdata, size_t ysize, const mpw* ydata, mpw* wksp);
00657 
00658 /*
00659  * Output Routines
00660  */
00661 
00662 BEECRYPTAPI
00663 void mpprint(size_t size, const mpw* data);
00664 
00665 BEECRYPTAPI
00666 void mpprintln(size_t size, const mpw* data);
00667 
00668 BEECRYPTAPI
00669 void mpfprint(FILE* f, size_t size, const mpw* data);
00670 
00671 BEECRYPTAPI
00672 void mpfprintln(FILE* f, size_t size, const mpw* data);
00673 
00674 /*
00675  * Conversion Routines
00676  */
00677 
00678 BEECRYPTAPI
00679 int os2ip(mpw* idata, size_t isize, const byte* osdata, size_t ossize);
00680 
00681 BEECRYPTAPI
00682 int i2osp(byte* osdata, size_t ossize, const mpw* idata, size_t isize);
00683 
00684 BEECRYPTAPI
00685 int hs2ip(mpw* idata, size_t isize, const char* hsdata, size_t hssize);
00686 
00687 #ifdef __cplusplus
00688 }
00689 #endif
00690 
00691 #endif

Generated on Wed Mar 24 13:56:53 2004 for BeeCrypt by doxygen 1.3.6