aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/openssl/bn_wrap.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-28 19:29:24 +0000
committerlloyd <[email protected]>2008-09-28 19:29:24 +0000
commit9bcfe627321ddc81691b835dffaa6324ac4684a4 (patch)
treefe5e8ae9813b853549558b59833022e87e83981b /src/engine/openssl/bn_wrap.cpp
parent9822a701516396b7de4e41339faecd48ff8dc8ff (diff)
Move all modules into src/ directory
Diffstat (limited to 'src/engine/openssl/bn_wrap.cpp')
-rw-r--r--src/engine/openssl/bn_wrap.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/engine/openssl/bn_wrap.cpp b/src/engine/openssl/bn_wrap.cpp
new file mode 100644
index 000000000..4f7ea0078
--- /dev/null
+++ b/src/engine/openssl/bn_wrap.cpp
@@ -0,0 +1,114 @@
+/*************************************************
+* OpenSSL BN Wrapper Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/bn_wrap.h>
+
+namespace Botan {
+
+/*************************************************
+* OSSL_BN Constructor *
+*************************************************/
+OSSL_BN::OSSL_BN(const BigInt& in)
+ {
+ value = BN_new();
+ SecureVector<byte> encoding = BigInt::encode(in);
+ if(in != 0)
+ BN_bin2bn(encoding, encoding.size(), value);
+ }
+
+/*************************************************
+* OSSL_BN Constructor *
+*************************************************/
+OSSL_BN::OSSL_BN(const byte in[], u32bit length)
+ {
+ value = BN_new();
+ BN_bin2bn(in, length, value);
+ }
+
+/*************************************************
+* OSSL_BN Copy Constructor *
+*************************************************/
+OSSL_BN::OSSL_BN(const OSSL_BN& other)
+ {
+ value = BN_dup(other.value);
+ }
+
+/*************************************************
+* OSSL_BN Destructor *
+*************************************************/
+OSSL_BN::~OSSL_BN()
+ {
+ BN_clear_free(value);
+ }
+
+/*************************************************
+* OSSL_BN Assignment Operator *
+*************************************************/
+OSSL_BN& OSSL_BN::operator=(const OSSL_BN& other)
+ {
+ BN_copy(value, other.value);
+ return (*this);
+ }
+
+/*************************************************
+* Export the BIGNUM as a bytestring *
+*************************************************/
+void OSSL_BN::encode(byte out[], u32bit length) const
+ {
+ BN_bn2bin(value, out + (length - bytes()));
+ }
+
+/*************************************************
+* Return the number of significant bytes *
+*************************************************/
+u32bit OSSL_BN::bytes() const
+ {
+ return BN_num_bytes(value);
+ }
+
+/*************************************************
+* OpenSSL to BigInt Conversions *
+*************************************************/
+BigInt OSSL_BN::to_bigint() const
+ {
+ SecureVector<byte> out(bytes());
+ BN_bn2bin(value, out);
+ return BigInt::decode(out);
+ }
+
+/*************************************************
+* OSSL_BN_CTX Constructor *
+*************************************************/
+OSSL_BN_CTX::OSSL_BN_CTX()
+ {
+ value = BN_CTX_new();
+ }
+
+/*************************************************
+* OSSL_BN_CTX Copy Constructor *
+*************************************************/
+OSSL_BN_CTX::OSSL_BN_CTX(const OSSL_BN_CTX&)
+ {
+ value = BN_CTX_new();
+ }
+
+/*************************************************
+* OSSL_BN_CTX Destructor *
+*************************************************/
+OSSL_BN_CTX::~OSSL_BN_CTX()
+ {
+ BN_CTX_free(value);
+ }
+
+/*************************************************
+* OSSL_BN_CTX Assignment Operator *
+*************************************************/
+OSSL_BN_CTX& OSSL_BN_CTX::operator=(const OSSL_BN_CTX&)
+ {
+ value = BN_CTX_new();
+ return (*this);
+ }
+
+}