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 00410 BEECRYPTAPI 00411 void mpand(size_t, mpw*, const mpw*); 00412 00413 BEECRYPTAPI 00414 void mpor(size_t, mpw*, const mpw*); 00415 00416 BEECRYPTAPI 00417 void mpxor(size_t, mpw*, const mpw*); 00418 00424 BEECRYPTAPI 00425 void mpnot(size_t size, mpw* data); 00426 00435 BEECRYPTAPI 00436 void mpsetw(size_t size, mpw* xdata, mpw y); 00437 00447 void mpsetx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata); 00448 00457 BEECRYPTAPI 00458 int mpaddw(size_t size, mpw* xdata, mpw y); 00459 00468 BEECRYPTAPI 00469 int mpadd (size_t size, mpw* xdata, const mpw* ydata); 00470 00480 BEECRYPTAPI 00481 int mpaddx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata); 00482 00491 BEECRYPTAPI 00492 int mpsubw(size_t size, mpw* xdata, mpw y); 00493 00502 BEECRYPTAPI 00503 int mpsub (size_t size, mpw* xdata, const mpw* ydata); 00504 00514 BEECRYPTAPI 00515 int mpsubx(size_t xsize, mpw* xdata, size_t ysize, const mpw* ydata); 00516 00517 BEECRYPTAPI 00518 int mpmultwo(size_t size, mpw* data); 00519 00520 BEECRYPTAPI 00521 void mpneg(size_t size, mpw* data); 00522 00523 BEECRYPTAPI 00524 size_t mpsize(size_t size, const mpw* data); 00525 00526 BEECRYPTAPI 00527 size_t mpbits(size_t size, const mpw* data); 00528 00529 BEECRYPTAPI 00530 size_t mpmszcnt(size_t size, const mpw* data); 00531 00532 BEECRYPTAPI 00533 size_t mplszcnt(size_t size, const mpw* data); 00534 00535 BEECRYPTAPI 00536 void mplshift(size_t size, mpw* data, size_t count); 00537 00538 BEECRYPTAPI 00539 void mprshift(size_t size, mpw* data, size_t count); 00540 00541 BEECRYPTAPI 00542 size_t mprshiftlsz(size_t size, mpw* data); 00543 00544 BEECRYPTAPI 00545 size_t mpnorm(size_t size, mpw* data); 00546 00547 BEECRYPTAPI 00548 void mpdivtwo (size_t size, mpw* data); 00549 00550 BEECRYPTAPI 00551 void mpsdivtwo(size_t size, mpw* data); 00552 00567 BEECRYPTAPI 00568 mpw mpsetmul (size_t size, mpw* result, const mpw* data, mpw y); 00569 00583 BEECRYPTAPI 00584 mpw mpaddmul (size_t size, mpw* result, const mpw* data, mpw y); 00585 00590 BEECRYPTAPI 00591 void mpaddsqrtrc(size_t, mpw*, const mpw*); 00592 00596 BEECRYPTAPI 00597 void mpmul(mpw*, size_t, const mpw*, size_t, const mpw*); 00601 BEECRYPTAPI 00602 void mpsqr(mpw*, size_t, const mpw*); 00603 00604 BEECRYPTAPI 00605 void mpgcd_w(size_t, const mpw*, const mpw*, mpw*, mpw*); 00606 BEECRYPTAPI 00607 int mpextgcd_w(size_t, const mpw*, const mpw*, mpw*, mpw*); 00608 00609 BEECRYPTAPI 00610 mpw mppndiv(mpw, mpw, mpw); 00611 00612 BEECRYPTAPI 00613 void mpnmod(mpw*, size_t, const mpw*, size_t, const mpw*, mpw*); 00614 00615 BEECRYPTAPI 00616 void mpmod (mpw*, size_t, const mpw*, size_t, const mpw*, mpw*); 00617 00618 BEECRYPTAPI 00619 void mpndivmod(mpw*, size_t, const mpw*, size_t, const mpw*, mpw*); 00620 00621 /* 00622 * Output Routines 00623 */ 00624 00625 BEECRYPTAPI 00626 void mpprint(size_t size, const mpw* data); 00627 00628 BEECRYPTAPI 00629 void mpprintln(size_t size, const mpw* data); 00630 00631 BEECRYPTAPI 00632 void mpfprint(FILE* f, size_t size, const mpw* data); 00633 00634 BEECRYPTAPI 00635 void mpfprintln(FILE* f, size_t size, const mpw* data); 00636 00637 /* 00638 * Conversion Routines 00639 */ 00640 00641 BEECRYPTAPI 00642 int os2ip(mpw*, size_t, const byte*, size_t); 00643 00644 BEECRYPTAPI 00645 int i2osp(byte*, size_t, const mpw*, size_t); 00646 00647 BEECRYPTAPI 00648 int hs2ip(mpw*, size_t, const char*, size_t); 00649 00650 #ifdef __cplusplus 00651 } 00652 #endif 00653 00654 #endif

Generated on Sun Jun 20 22:57:54 2004 for BeeCrypt by doxygen 1.3.7