-
+ D86FF3ED23FF796D0C35B550F60142DD5A7242343DCAE7CA74558C30B5FEC1749AAF6A0207F4BF39DF464BCC60FF37A6495965D3E7DAD5AD70C0AEB7A7C2A46C
smg_comms/mpi/include/mpi.h
(0 . 0)(1 . 152)
2375 /* mpi.h - Multi Precision Integers
2376 * Modified by No Such Labs. (C) 2015. See README.
2377 * Modified by S.MG, 2018. Added mpi_get_alloced, function for retrieving currently allocated number of limbs.
2378 *
2379 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
2380 * SHA256(gnupg-1.4.10.tar.gz):
2381 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
2382 * (C) 1994-2005 Free Software Foundation, Inc.
2383 *
2384 * This program is free software: you can redistribute it and/or modify
2385 * it under the terms of the GNU General Public License as published by
2386 * the Free Software Foundation, either version 3 of the License, or
2387 * (at your option) any later version.
2388 *
2389 * This program is distributed in the hope that it will be useful,
2390 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2391 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2392 * GNU General Public License for more details.
2393 *
2394 * You should have received a copy of the GNU General Public License
2395 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2396 */
2397
2398 #ifndef G10_MPI_H
2399 #define G10_MPI_H
2400
2401 #include <stdio.h>
2402 #include "knobs.h"
2403 #include "types.h"
2404 #include "memory.h"
2405
2406 #ifndef EXTERN_UNLESS_MAIN_MODULE
2407 #define EXTERN_UNLESS_MAIN_MODULE
2408 #endif
2409
2410 #define DBG_MPI mpi_debug_mode
2411 EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode;
2412
2413
2414 struct gcry_mpi;
2415 typedef struct gcry_mpi *MPI;
2416
2417
2418 /*-- mpiutil.c --*/
2419
2420 #ifdef M_DEBUG
2421 #define mpi_alloc(n) mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
2422 #define mpi_alloc_secure(n) mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
2423 #define mpi_alloc_like(n) mpi_debug_alloc_like((n), M_DBGINFO( __LINE__ ) )
2424 #define mpi_free(a) mpi_debug_free((a), M_DBGINFO(__LINE__) )
2425 #define mpi_resize(a,b) mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
2426 #define mpi_copy(a) mpi_debug_copy((a), M_DBGINFO(__LINE__) )
2427 MPI mpi_debug_alloc( unsigned nlimbs, const char *info );
2428 MPI mpi_debug_alloc_secure( unsigned nlimbs, const char *info );
2429 MPI mpi_debug_alloc_like( MPI a, const char *info );
2430 void mpi_debug_free( MPI a, const char *info );
2431 void mpi_debug_resize( MPI a, unsigned nlimbs, const char *info );
2432 MPI mpi_debug_copy( MPI a, const char *info );
2433 #else
2434 MPI mpi_alloc( unsigned nlimbs );
2435 MPI mpi_alloc_secure( unsigned nlimbs );
2436 MPI mpi_alloc_like( MPI a );
2437 void mpi_free( MPI a );
2438 void mpi_resize( MPI a, unsigned nlimbs );
2439 MPI mpi_copy( MPI a );
2440 #endif
2441 #define mpi_is_opaque(a) ((a) && (mpi_get_flags (a)&4))
2442 MPI mpi_set_opaque( MPI a, void *p, unsigned int len );
2443 void *mpi_get_opaque( MPI a, unsigned int *len );
2444 #define mpi_is_secure(a) ((a) && (mpi_get_flags (a)&1))
2445 void mpi_set_secure( MPI a );
2446 void mpi_clear( MPI a );
2447 void mpi_set( MPI w, MPI u);
2448 void mpi_set_ui( MPI w, ulong u);
2449 MPI mpi_alloc_set_ui( unsigned long u);
2450 void mpi_m_check( MPI a );
2451 void mpi_swap( MPI a, MPI b);
2452 int mpi_get_nlimbs (MPI a);
2453 int mpi_get_alloced (MPI a); /* returns the allocated memory space for this MPI, in number of limbs */
2454 int mpi_is_neg (MPI a);
2455 unsigned int mpi_nlimb_hint_from_nbytes (unsigned int nbytes);
2456 unsigned int mpi_nlimb_hint_from_nbits (unsigned int nbits);
2457 unsigned int mpi_get_flags (MPI a);
2458
2459 /*-- mpicoder.c --*/
2460 MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure);
2461 int mpi_fromstr(MPI val, const char *str);
2462 int mpi_print( FILE *fp, MPI a, int mode );
2463 //void g10_log_mpidump( const char *text, MPI a );
2464 byte *mpi_get_buffer( MPI a, unsigned *nbytes, int *sign );
2465 byte *mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign );
2466 void mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign );
2467
2468 #define log_mpidump g10_log_mpidump
2469
2470 /*-- mpi-add.c --*/
2471 void mpi_add_ui(MPI w, MPI u, ulong v );
2472 void mpi_add(MPI w, MPI u, MPI v);
2473 void mpi_addm(MPI w, MPI u, MPI v, MPI m);
2474 void mpi_sub_ui(MPI w, MPI u, ulong v );
2475 void mpi_sub( MPI w, MPI u, MPI v);
2476 void mpi_subm( MPI w, MPI u, MPI v, MPI m);
2477
2478 /*-- mpi-mul.c --*/
2479 void mpi_mul_ui(MPI w, MPI u, ulong v );
2480 void mpi_mul_2exp( MPI w, MPI u, ulong cnt);
2481 void mpi_mul( MPI w, MPI u, MPI v);
2482 void mpi_mulm( MPI w, MPI u, MPI v, MPI m);
2483
2484 /*-- mpi-div.c --*/
2485 ulong mpi_fdiv_r_ui( MPI rem, MPI dividend, ulong divisor );
2486 void mpi_fdiv_r( MPI rem, MPI dividend, MPI divisor );
2487 void mpi_fdiv_q( MPI quot, MPI dividend, MPI divisor );
2488 void mpi_fdiv_qr( MPI quot, MPI rem, MPI dividend, MPI divisor );
2489 void mpi_tdiv_r( MPI rem, MPI num, MPI den);
2490 void mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den);
2491 void mpi_tdiv_q_2exp( MPI w, MPI u, unsigned count );
2492 int mpi_divisible_ui(MPI dividend, ulong divisor );
2493
2494 /*-- mpi-gcd.c --*/
2495 int mpi_gcd( MPI g, MPI a, MPI b );
2496
2497 /*-- mpi-pow.c --*/
2498 void mpi_pow( MPI w, MPI u, MPI v);
2499 void mpi_powm( MPI res, MPI base, MPI exponent, MPI mod);
2500
2501 /*-- mpi-mpow.c --*/
2502 void mpi_mulpowm( MPI res, MPI *basearray, MPI *exparray, MPI mod);
2503
2504 /*-- mpi-cmp.c --*/
2505 int mpi_cmp_ui( MPI u, ulong v );
2506 int mpi_cmp( MPI u, MPI v );
2507
2508 /*-- mpi-scan.c --*/
2509 int mpi_getbyte( MPI a, unsigned idx );
2510 void mpi_putbyte( MPI a, unsigned idx, int value );
2511 unsigned mpi_trailing_zeros( MPI a );
2512
2513 /*-- mpi-bit.c --*/
2514 void mpi_normalize( MPI a );
2515 unsigned mpi_get_nbits( MPI a );
2516 int mpi_test_bit( MPI a, unsigned n );
2517 void mpi_set_bit( MPI a, unsigned n );
2518 void mpi_set_highbit( MPI a, unsigned n );
2519 void mpi_clear_highbit( MPI a, unsigned n );
2520 void mpi_clear_bit( MPI a, unsigned n );
2521 void mpi_rshift( MPI x, MPI a, unsigned n );
2522
2523 /*-- mpi-inv.c --*/
2524 void mpi_invm( MPI x, MPI u, MPI v );
2525
2526 #endif /*G10_MPI_H*/