Botan 1.10.17
bn_wrap.cpp
Go to the documentation of this file.
1/*
2* OpenSSL BN Wrapper
3* (C) 1999-2007 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#include <botan/internal/bn_wrap.h>
9
10namespace Botan {
11
12/*
13* OSSL_BN Constructor
14*/
16 {
17 value = BN_new();
19 if(in != 0)
20 BN_bin2bn(encoding, encoding.size(), value);
21 }
22
23/*
24* OSSL_BN Constructor
25*/
26OSSL_BN::OSSL_BN(const byte in[], size_t length)
27 {
28 value = BN_new();
29 BN_bin2bn(in, length, value);
30 }
31
32/*
33* OSSL_BN Copy Constructor
34*/
36 {
37 value = BN_dup(other.value);
38 }
39
40/*
41* OSSL_BN Destructor
42*/
44 {
45 BN_clear_free(value);
46 }
47
48/*
49* OSSL_BN Assignment Operator
50*/
52 {
53 BN_copy(value, other.value);
54 return (*this);
55 }
56
57/*
58* Export the BIGNUM as a bytestring
59*/
60void OSSL_BN::encode(byte out[], size_t length) const
61 {
62 BN_bn2bin(value, out + (length - bytes()));
63 }
64
65/*
66* Return the number of significant bytes
67*/
68size_t OSSL_BN::bytes() const
69 {
70 return BN_num_bytes(value);
71 }
72
73/*
74* OpenSSL to BigInt Conversions
75*/
77 {
79 BN_bn2bin(value, out);
80 return BigInt::decode(out);
81 }
82
83/*
84* OSSL_BN_CTX Constructor
85*/
87 {
88 value = BN_CTX_new();
89 }
90
91/*
92* OSSL_BN_CTX Copy Constructor
93*/
95 {
96 value = BN_CTX_new();
97 }
98
99/*
100* OSSL_BN_CTX Destructor
101*/
103 {
104 BN_CTX_free(value);
105 }
106
107/*
108* OSSL_BN_CTX Assignment Operator
109*/
111 {
112 value = BN_CTX_new();
113 return (*this);
114 }
115
116}
static BigInt decode(const byte buf[], size_t length, Base base=Binary)
Definition big_code.cpp:102
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition big_code.cpp:64
size_t size() const
Definition secmem.h:29
BN_CTX * value
Definition bn_wrap.h:45
OSSL_BN_CTX & operator=(const OSSL_BN_CTX &)
Definition bn_wrap.cpp:110
size_t bytes() const
Definition bn_wrap.cpp:68
BigInt to_bigint() const
Definition bn_wrap.cpp:76
void encode(byte[], size_t) const
Definition bn_wrap.cpp:60
OSSL_BN(const OSSL_BN &)
Definition bn_wrap.cpp:35
BIGNUM * value
Definition bn_wrap.h:22
OSSL_BN & operator=(const OSSL_BN &)
Definition bn_wrap.cpp:51