Botan: Botan::GMP_MPZ Class Reference

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | List of all members
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 GMP_MPZ &)
| GMP_MPZ (const BigInt &=0)
| GMP_MPZ (const byte[], size_t)
GMP_MPZ & | operator= (const GMP_MPZ &)
BigInt | to_bigint () const
SecureVector< byte > | to_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

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

Definition at line 44 of file gmp_wrap.cpp.

References value.

Referenced by to_bytes().

45 {
46 mpz_init_set(value, other.value);
47 }
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22

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

Definition at line 25 of file gmp_wrap.cpp.

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

26 {
27 mpz_init(value);
28 if(in != 0)
29 mpz_import(value, in.sig_words(), -1, sizeof(word), 0, 0, in.data());
30 }
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22

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

Definition at line 35 of file gmp_wrap.cpp.

References value.

36 {
37 mpz_init(value);
38 mpz_import(value, length, 1, 1, 0, 0, in);
39 }
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22

Botan::GMP_MPZ::~GMP_MPZ | ( |  | ) |

Definition at line 52 of file gmp_wrap.cpp.

References value.

Referenced by to_bytes().

53 {
54 mpz_clear(value);
55 }
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22

## Member Function Documentation

size_t Botan::GMP_MPZ::bytes | ( |  | ) | const

Definition at line 78 of file gmp_wrap.cpp.

References value.

Referenced by encode(), and to_bigint().

79 {
80 return ((mpz_sizeinbase(value, 2) + 7) / 8);
81 }
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22

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

Definition at line 69 of file gmp_wrap.cpp.

References bytes(), and value.

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

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

Definition at line 60 of file gmp_wrap.cpp.

References value.

Referenced by to_bytes().

61 {
62 mpz_set(value, other.value);
63 return (*this);
64 }
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22

BigInt Botan::GMP_MPZ::to_bigint | ( |  | ) | const

Definition at line 86 of file gmp_wrap.cpp.

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

Referenced by to_bytes().

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 }
Botan::BigInt::Positive
Definition: bigint.h:33
Botan::GMP_MPZ::value
mpz_t value
Definition: gmp_wrap.h:22
Botan::GMP_MPZ::bytes
size_t bytes() const
Definition: gmp_wrap.cpp:78

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

Definition at line 28 of file gmp_wrap.h.

References Botan::BigInt::encode(), GMP_MPZ(), operator=(), to_bigint(), and ~GMP_MPZ().

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

## Member Data Documentation

mpz_t Botan::GMP_MPZ::value

Definition at line 22 of file gmp_wrap.h.

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

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

- src/engine/gnump/gmp_wrap.h
- src/engine/gnump/gmp_wrap.cpp