bignum.h revision 400422edee24dcbb377417b13ed03412cc3a226b
/** @file
* IPRT - Big Integer Numbers.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___iprt_bignum_h
#define ___iprt_bignum_h
/** @defgroup grp_rtbignum RTBigNum - Big Integer Numbers
* @ingroup grp_rt
* @{
*/
/** The big integer number element type. */
#if ARCH_BITS == 64
typedef uint64_t RTBIGNUMELEMENT;
#else
typedef uint32_t RTBIGNUMELEMENT;
#endif
/** The size (in bytes) of one array element. */
#if ARCH_BITS == 64
# define RTBIGNUM_ELEMENT_SIZE 8
#else
# define RTBIGNUM_ELEMENT_SIZE 4
#endif
/** The number of bits in one array element. */
/** Returns the bitmask corrsponding to given bit number. */
#if ARCH_BITS == 64
#else
#endif
/**
* IPRT big integer number.
*/
typedef struct RTBIGNUM
{
/** Elements array where the magnitue of the value is stored. */
/** The current number of elements we're using in the pauElements array. */
/** The current allocation size of pauElements. */
/** Reserved for future use. */
/** Set if it's a negative number, clear if positive or zero. */
/** Whether to use a the data is sensitive (RTBIGNUMINIT_F_SENSITIVE). */
/** The number is currently scrambled */
/** Bits reserved for future use. */
} RTBIGNUM;
/** @name RTBIGNUMINIT_F_XXX - RTBigNumInit flags.
* @{ */
/** The number is sensitive so use a safer allocator, scramble it when not
* in use, and apply RTMemWipeThoroughly before freeing. The RTMemSafer API
* takes care of these things.
* @note When using this flag, concurrent access is not possible! */
#define RTBIGNUMINIT_F_SENSITIVE RT_BIT(0)
/** Big endian number. */
/** Little endian number. */
/** The raw number is unsigned. */
/** The raw number is signed. */
/** @} */
/**
* The minimum number of bits require store the two's complement representation
* of the number.
*
* @returns Width in number of bits.
* @param pBigNum The big number.
*/
/**
* Converts the big number to a sign-extended big endian byte sequence.
*
* @returns IPRT status code
* @retval VERR_BUFFER_OVERFLOW if the specified buffer is too small.
* @param pBigNum The big number.
* @param pvBuf The output buffer (size is at least cbWanted).
* @param cbWanted The number of bytes wanted.
*/
/**
* Compares two numbers.
*
* @retval -1 if pLeft < pRight.
* @retval 0 if pLeft == pRight.
* @retval 1 if pLeft > pRight.
*
* @param pLeft The left side number.
* @param pRight The right side number.
*/
RTDECL(int) RTBigNumDivide(PRTBIGNUM pQuotient, PRTBIGNUM pRemainder, PCRTBIGNUM pDividend, PCRTBIGNUM pDivisor);
RTDECL(int) RTBigNumModExp(PRTBIGNUM pResult, PRTBIGNUM pBase, PRTBIGNUM pExponent, PRTBIGNUM pModulus);
/** @} */
#endif