-
+ 295FF95B636878675CDC74B113EE282AFB19CABCAE79FDA85E80DE853604148265E1D150697EAA9AA727B02BC4ACE33D98C2242FA4122107CD3F5B0DBF3B6BB8
eucrypt/mpi/include/mpi.h
(0 . 0)(1 . 150)
1642 /* mpi.h - Multi Precision Integers
1643 * Modified by No Such Labs. (C) 2015. See README.
1644 *
1645 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
1646 * SHA256(gnupg-1.4.10.tar.gz):
1647 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
1648 * (C) 1994-2005 Free Software Foundation, Inc.
1649 *
1650 * This program is free software: you can redistribute it and/or modify
1651 * it under the terms of the GNU General Public License as published by
1652 * the Free Software Foundation, either version 3 of the License, or
1653 * (at your option) any later version.
1654 *
1655 * This program is distributed in the hope that it will be useful,
1656 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1657 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658 * GNU General Public License for more details.
1659 *
1660 * You should have received a copy of the GNU General Public License
1661 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1662 */
1663
1664 #ifndef G10_MPI_H
1665 #define G10_MPI_H
1666
1667 #include <stdio.h>
1668 #include "knobs.h"
1669 #include "types.h"
1670 #include "memory.h"
1671
1672 #ifndef EXTERN_UNLESS_MAIN_MODULE
1673 #define EXTERN_UNLESS_MAIN_MODULE
1674 #endif
1675
1676 #define DBG_MPI mpi_debug_mode
1677 EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode;
1678
1679
1680 struct gcry_mpi;
1681 typedef struct gcry_mpi *MPI;
1682
1683
1684 /*-- mpiutil.c --*/
1685
1686 #ifdef M_DEBUG
1687 #define mpi_alloc(n) mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
1688 #define mpi_alloc_secure(n) mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
1689 #define mpi_alloc_like(n) mpi_debug_alloc_like((n), M_DBGINFO( __LINE__ ) )
1690 #define mpi_free(a) mpi_debug_free((a), M_DBGINFO(__LINE__) )
1691 #define mpi_resize(a,b) mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
1692 #define mpi_copy(a) mpi_debug_copy((a), M_DBGINFO(__LINE__) )
1693 MPI mpi_debug_alloc( unsigned nlimbs, const char *info );
1694 MPI mpi_debug_alloc_secure( unsigned nlimbs, const char *info );
1695 MPI mpi_debug_alloc_like( MPI a, const char *info );
1696 void mpi_debug_free( MPI a, const char *info );
1697 void mpi_debug_resize( MPI a, unsigned nlimbs, const char *info );
1698 MPI mpi_debug_copy( MPI a, const char *info );
1699 #else
1700 MPI mpi_alloc( unsigned nlimbs );
1701 MPI mpi_alloc_secure( unsigned nlimbs );
1702 MPI mpi_alloc_like( MPI a );
1703 void mpi_free( MPI a );
1704 void mpi_resize( MPI a, unsigned nlimbs );
1705 MPI mpi_copy( MPI a );
1706 #endif
1707 #define mpi_is_opaque(a) ((a) && (mpi_get_flags (a)&4))
1708 MPI mpi_set_opaque( MPI a, void *p, unsigned int len );
1709 void *mpi_get_opaque( MPI a, unsigned int *len );
1710 #define mpi_is_secure(a) ((a) && (mpi_get_flags (a)&1))
1711 void mpi_set_secure( MPI a );
1712 void mpi_clear( MPI a );
1713 void mpi_set( MPI w, MPI u);
1714 void mpi_set_ui( MPI w, ulong u);
1715 MPI mpi_alloc_set_ui( unsigned long u);
1716 void mpi_m_check( MPI a );
1717 void mpi_swap( MPI a, MPI b);
1718 int mpi_get_nlimbs (MPI a);
1719 int mpi_is_neg (MPI a);
1720 unsigned int mpi_nlimb_hint_from_nbytes (unsigned int nbytes);
1721 unsigned int mpi_nlimb_hint_from_nbits (unsigned int nbits);
1722 unsigned int mpi_get_flags (MPI a);
1723
1724 /*-- mpicoder.c --*/
1725 MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure);
1726 int mpi_fromstr(MPI val, const char *str);
1727 int mpi_print( FILE *fp, MPI a, int mode );
1728 //void g10_log_mpidump( const char *text, MPI a );
1729 byte *mpi_get_buffer( MPI a, unsigned *nbytes, int *sign );
1730 byte *mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign );
1731 void mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign );
1732
1733 #define log_mpidump g10_log_mpidump
1734
1735 /*-- mpi-add.c --*/
1736 void mpi_add_ui(MPI w, MPI u, ulong v );
1737 void mpi_add(MPI w, MPI u, MPI v);
1738 void mpi_addm(MPI w, MPI u, MPI v, MPI m);
1739 void mpi_sub_ui(MPI w, MPI u, ulong v );
1740 void mpi_sub( MPI w, MPI u, MPI v);
1741 void mpi_subm( MPI w, MPI u, MPI v, MPI m);
1742
1743 /*-- mpi-mul.c --*/
1744 void mpi_mul_ui(MPI w, MPI u, ulong v );
1745 void mpi_mul_2exp( MPI w, MPI u, ulong cnt);
1746 void mpi_mul( MPI w, MPI u, MPI v);
1747 void mpi_mulm( MPI w, MPI u, MPI v, MPI m);
1748
1749 /*-- mpi-div.c --*/
1750 ulong mpi_fdiv_r_ui( MPI rem, MPI dividend, ulong divisor );
1751 void mpi_fdiv_r( MPI rem, MPI dividend, MPI divisor );
1752 void mpi_fdiv_q( MPI quot, MPI dividend, MPI divisor );
1753 void mpi_fdiv_qr( MPI quot, MPI rem, MPI dividend, MPI divisor );
1754 void mpi_tdiv_r( MPI rem, MPI num, MPI den);
1755 void mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den);
1756 void mpi_tdiv_q_2exp( MPI w, MPI u, unsigned count );
1757 int mpi_divisible_ui(MPI dividend, ulong divisor );
1758
1759 /*-- mpi-gcd.c --*/
1760 int mpi_gcd( MPI g, MPI a, MPI b );
1761
1762 /*-- mpi-pow.c --*/
1763 void mpi_pow( MPI w, MPI u, MPI v);
1764 void mpi_powm( MPI res, MPI base, MPI exponent, MPI mod);
1765
1766 /*-- mpi-mpow.c --*/
1767 void mpi_mulpowm( MPI res, MPI *basearray, MPI *exparray, MPI mod);
1768
1769 /*-- mpi-cmp.c --*/
1770 int mpi_cmp_ui( MPI u, ulong v );
1771 int mpi_cmp( MPI u, MPI v );
1772
1773 /*-- mpi-scan.c --*/
1774 int mpi_getbyte( MPI a, unsigned idx );
1775 void mpi_putbyte( MPI a, unsigned idx, int value );
1776 unsigned mpi_trailing_zeros( MPI a );
1777
1778 /*-- mpi-bit.c --*/
1779 void mpi_normalize( MPI a );
1780 unsigned mpi_get_nbits( MPI a );
1781 int mpi_test_bit( MPI a, unsigned n );
1782 void mpi_set_bit( MPI a, unsigned n );
1783 void mpi_set_highbit( MPI a, unsigned n );
1784 void mpi_clear_highbit( MPI a, unsigned n );
1785 void mpi_clear_bit( MPI a, unsigned n );
1786 void mpi_rshift( MPI x, MPI a, unsigned n );
1787
1788 /*-- mpi-inv.c --*/
1789 void mpi_invm( MPI x, MPI u, MPI v );
1790
1791 #endif /*G10_MPI_H*/