Botan 1.10.17
Botan::GMP_MPZ Class Reference

#include <gmp_wrap.h>

Public Member Functions

size_t bytes () const
void encode (byte[], size_t) const
 GMP_MPZ (const BigInt &=0)
 GMP_MPZ (const byte[], size_t)
 GMP_MPZ (const GMP_MPZ &)
GMP_MPZoperator= (const GMP_MPZ &)
BigInt to_bigint () const
SecureVector< byteto_bytes () const
 ~GMP_MPZ ()

Public Attributes

mpz_t value

Detailed Description

Lightweight GMP mpz_t wrapper. For internal use only.

Definition at line 19 of file gmp_wrap.h.

Constructor & Destructor Documentation

◆ GMP_MPZ() [1/3]

Botan::GMP_MPZ::GMP_MPZ ( const GMP_MPZ & other)

Definition at line 44 of file gmp_wrap.cpp.

45 {
46 mpz_init_set(value, other.value);
47 }

References GMP_MPZ(), and value.

Referenced by GMP_MPZ(), and operator=().

◆ GMP_MPZ() [2/3]

Botan::GMP_MPZ::GMP_MPZ ( const BigInt & in = 0)

Definition at line 25 of file gmp_wrap.cpp.

26 {
27 mpz_init(value);
28 if(in != 0)
29 mpz_import(value, in.sig_words(), -1, sizeof(word), 0, 0, in.data());
30 }

References Botan::BigInt::data(), Botan::BigInt::sig_words(), and value.

◆ GMP_MPZ() [3/3]

Botan::GMP_MPZ::GMP_MPZ ( const byte in[],
size_t length )

Definition at line 35 of file gmp_wrap.cpp.

36 {
37 mpz_init(value);
38 mpz_import(value, length, 1, 1, 0, 0, in);
39 }

References value.

◆ ~GMP_MPZ()

Botan::GMP_MPZ::~GMP_MPZ ( )

Definition at line 52 of file gmp_wrap.cpp.

53 {
54 mpz_clear(value);
55 }

References value.

Member Function Documentation

◆ bytes()

size_t Botan::GMP_MPZ::bytes ( ) const

Definition at line 78 of file gmp_wrap.cpp.

79 {
80 return ((mpz_sizeinbase(value, 2) + 7) / 8);
81 }

References value.

Referenced by encode(), and to_bigint().

◆ encode()

void Botan::GMP_MPZ::encode ( byte out[],
size_t length ) const

Definition at line 69 of file gmp_wrap.cpp.

70 {
71 size_t dummy = 0;
72 mpz_export(out + (length - bytes()), &dummy, 1, 1, 0, 0, value);
73 }
size_t bytes() const
Definition gmp_wrap.cpp:78

References bytes(), and value.

◆ operator=()

GMP_MPZ & Botan::GMP_MPZ::operator= ( const GMP_MPZ & other)

Definition at line 60 of file gmp_wrap.cpp.

61 {
62 mpz_set(value, other.value);
63 return (*this);
64 }

References GMP_MPZ(), and value.

◆ to_bigint()

BigInt Botan::GMP_MPZ::to_bigint ( ) const

Definition at line 86 of file gmp_wrap.cpp.

87 {
88 BigInt out(BigInt::Positive, (bytes() + sizeof(word) - 1) / sizeof(word));
89 size_t dummy = 0;
90 mpz_export(out.get_reg(), &dummy, -1, sizeof(word), 0, 0, value);
91
92 if(mpz_sgn(value) < 0)
93 out.flip_sign();
94
95 return out;
96 }

References bytes(), Botan::BigInt::flip_sign(), Botan::BigInt::get_reg(), Botan::BigInt::Positive, and value.

Referenced by to_bytes().

◆ to_bytes()

SecureVector< byte > Botan::GMP_MPZ::to_bytes ( ) const
inline

Definition at line 28 of file gmp_wrap.h.

29 { return BigInt::encode(to_bigint()); }
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition big_code.cpp:64
BigInt to_bigint() const
Definition gmp_wrap.cpp:86

References Botan::BigInt::encode(), and to_bigint().

Member Data Documentation

◆ value

mpz_t Botan::GMP_MPZ::value

Definition at line 22 of file gmp_wrap.h.

Referenced by bytes(), encode(), GMP_MPZ(), GMP_MPZ(), GMP_MPZ(), operator=(), to_bigint(), and ~GMP_MPZ().


The documentation for this class was generated from the following files: