diff options
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/bigint/big_code.cpp | 4 | ||||
-rw-r--r-- | src/math/bigint/bigint.cpp | 26 | ||||
-rw-r--r-- | src/math/bigint/bigint.h | 29 | ||||
-rw-r--r-- | src/math/ec_gfp/point_gfp.h | 31 | ||||
-rw-r--r-- | src/math/numbertheory/dsa_gen.cpp | 8 | ||||
-rw-r--r-- | src/math/numbertheory/make_prm.cpp | 4 | ||||
-rw-r--r-- | src/math/numbertheory/numthry.cpp | 2 |
7 files changed, 69 insertions, 35 deletions
diff --git a/src/math/bigint/big_code.cpp b/src/math/bigint/big_code.cpp index 75a310a7c..28614c9f1 100644 --- a/src/math/bigint/big_code.cpp +++ b/src/math/bigint/big_code.cpp @@ -111,7 +111,9 @@ BigInt BigInt::decode(const byte buf[], size_t length, Base base) if(length % 2) { // Handle lack of leading 0 - const char buf0_with_leading_0[2] = { '0', buf[0] }; + const char buf0_with_leading_0[2] = + { '0', static_cast<char>(buf[0]) }; + binary = hex_decode(buf0_with_leading_0, 2); binary += hex_decode(reinterpret_cast<const char*>(&buf[1]), diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index e2e062f2d..df4414aba 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -40,23 +40,12 @@ BigInt::BigInt(Sign s, size_t size) } /* -* Construct a BigInt from a "raw" BigInt +* Copy constructor */ BigInt::BigInt(const BigInt& b) { - const size_t b_words = b.sig_words(); - - if(b_words) - { - reg.resize(round_up<size_t>(b_words, 8)); - reg.copy(b.data(), b_words); - set_sign(b.sign()); - } - else - { - reg.resize(2); - set_sign(Positive); - } + reg = b.get_reg(); + set_sign(b.sign()); } /* @@ -101,15 +90,6 @@ BigInt::BigInt(RandomNumberGenerator& rng, size_t bits) } /* -* Swap this BigInt with another -*/ -void BigInt::swap(BigInt& other) - { - reg.swap(other.reg); - std::swap(signedness, other.signedness); - } - -/* * Grow the internal storage */ void BigInt::grow_reg(size_t n) diff --git a/src/math/bigint/bigint.h b/src/math/bigint/bigint.h index 87c7cb766..57aa84528 100644 --- a/src/math/bigint/bigint.h +++ b/src/math/bigint/bigint.h @@ -438,7 +438,11 @@ class BOTAN_DLL BigInt * Swap this value with another * @param other BigInt to swap values with */ - void swap(BigInt& other); + void swap(BigInt& other) + { + reg.swap(other.reg); + std::swap(signedness, other.signedness); + } /** * Create empty BigInt @@ -500,6 +504,29 @@ class BOTAN_DLL BigInt */ BigInt(NumberType type, size_t n); + /** + * Move constructor + */ + BigInt(BigInt&& other) + { + this->swap(other); + } + + /** + * Move assignment + */ + BigInt& operator=(BigInt&& other) + { + if(this != &other) + this->swap(other); + + return (*this); + } + + /** + * Copy assignment + */ + BigInt& operator=(const BigInt&) = default; private: SecureVector<word> reg; Sign signedness; diff --git a/src/math/ec_gfp/point_gfp.h b/src/math/ec_gfp/point_gfp.h index b2b6fe2f0..546a8dd6f 100644 --- a/src/math/ec_gfp/point_gfp.h +++ b/src/math/ec_gfp/point_gfp.h @@ -59,6 +59,34 @@ class BOTAN_DLL PointGFp PointGFp(const CurveGFp& curve); /** + * Copy constructor + */ + PointGFp(const PointGFp&) = default; + + /** + * Move Constructor + */ + PointGFp(PointGFp&& other) + { + this->swap(other); + } + + /** + * Standard Assignment + */ + PointGFp& operator=(const PointGFp&) = default; + + /** + * Move Assignment + */ + PointGFp& operator=(PointGFp&& other) + { + if(this != &other) + this->swap(other); + return (*this); + } + + /** * Construct a point from its affine coordinates * @param curve the base curve * @param x affine x coordinate @@ -66,9 +94,6 @@ class BOTAN_DLL PointGFp */ PointGFp(const CurveGFp& curve, const BigInt& x, const BigInt& y); - //PointGFp(const PointGFp& other) = default; - //PointGFp& operator=(const PointGFp& other) = default; - /** * += Operator * @param rhs the PointGFp to add to the local value diff --git a/src/math/numbertheory/dsa_gen.cpp b/src/math/numbertheory/dsa_gen.cpp index 670f103da..612370804 100644 --- a/src/math/numbertheory/dsa_gen.cpp +++ b/src/math/numbertheory/dsa_gen.cpp @@ -47,15 +47,15 @@ bool generate_dsa_primes(RandomNumberGenerator& rng, if(!fips186_3_valid_size(pbits, qbits)) throw Invalid_Argument( "FIPS 186-3 does not allow DSA domain parameters of " + - to_string(pbits) + "/" + to_string(qbits) + " bits long"); + std::to_string(pbits) + "/" + std::to_string(qbits) + " bits long"); if(seed_c.size() * 8 < qbits) throw Invalid_Argument( - "Generating a DSA parameter set with a " + to_string(qbits) + + "Generating a DSA parameter set with a " + std::to_string(qbits) + "long q requires a seed at least as many bits long"); - std::auto_ptr<HashFunction> hash( - af.make_hash_function("SHA-" + to_string(qbits))); + std::unique_ptr<HashFunction> hash( + af.make_hash_function("SHA-" + std::to_string(qbits))); const size_t HASH_SIZE = hash->output_length(); diff --git a/src/math/numbertheory/make_prm.cpp b/src/math/numbertheory/make_prm.cpp index 4fb3f908c..1e8d11000 100644 --- a/src/math/numbertheory/make_prm.cpp +++ b/src/math/numbertheory/make_prm.cpp @@ -20,7 +20,7 @@ BigInt random_prime(RandomNumberGenerator& rng, { if(bits <= 1) throw Invalid_Argument("random_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); else if(bits == 2) return ((rng.next_byte() % 2) ? 2 : 3); else if(bits == 3) @@ -88,7 +88,7 @@ BigInt random_safe_prime(RandomNumberGenerator& rng, size_t bits) { if(bits <= 64) throw Invalid_Argument("random_safe_prime: Can't make a prime of " + - to_string(bits) + " bits"); + std::to_string(bits) + " bits"); BigInt p; do diff --git a/src/math/numbertheory/numthry.cpp b/src/math/numbertheory/numthry.cpp index c7896c17a..18f6ce429 100644 --- a/src/math/numbertheory/numthry.cpp +++ b/src/math/numbertheory/numthry.cpp @@ -83,7 +83,7 @@ size_t miller_rabin_test_iterations(size_t bits, size_t level) { struct mapping { size_t bits; size_t verify_iter; size_t check_iter; }; - static const mapping tests[] = { + const mapping tests[] = { { 50, 55, 25 }, { 100, 38, 22 }, { 160, 32, 18 }, |