mirror of
https://github.com/MariaDB/server.git
synced 2025-10-21 08:47:42 +03:00
- Replace SawTooth copyright header with MySQL's - Bug#19209 Test 'rpl_openssl' hangs on Windows - Spurious "2013 Connection to server lost" errors fixed yaSSL doesn't close socket anymore, that is left to the application extra/yassl/README: Import patch yassl.diff extra/yassl/include/buffer.hpp: Import patch yassl.diff extra/yassl/include/cert_wrapper.hpp: Import patch yassl.diff extra/yassl/include/crypto_wrapper.hpp: Import patch yassl.diff extra/yassl/include/factory.hpp: Import patch yassl.diff extra/yassl/include/handshake.hpp: Import patch yassl.diff extra/yassl/include/lock.hpp: Import patch yassl.diff extra/yassl/include/log.hpp: Import patch yassl.diff extra/yassl/include/openssl/ssl.h: Import patch yassl.diff extra/yassl/include/socket_wrapper.hpp: Import patch yassl.diff extra/yassl/include/timer.hpp: Import patch yassl.diff extra/yassl/include/yassl.hpp: Import patch yassl.diff extra/yassl/include/yassl_error.hpp: Import patch yassl.diff extra/yassl/include/yassl_imp.hpp: Import patch yassl.diff extra/yassl/include/yassl_int.hpp: Import patch yassl.diff extra/yassl/include/yassl_types.hpp: Import patch yassl.diff extra/yassl/src/buffer.cpp: Import patch yassl.diff extra/yassl/src/cert_wrapper.cpp: Import patch yassl.diff extra/yassl/src/crypto_wrapper.cpp: Import patch yassl.diff extra/yassl/src/handshake.cpp: Import patch yassl.diff extra/yassl/src/lock.cpp: Import patch yassl.diff extra/yassl/src/log.cpp: Import patch yassl.diff extra/yassl/src/socket_wrapper.cpp: Import patch yassl.diff extra/yassl/src/ssl.cpp: Import patch yassl.diff extra/yassl/src/template_instnt.cpp: Import patch yassl.diff extra/yassl/src/timer.cpp: Import patch yassl.diff extra/yassl/src/yassl.cpp: Import patch yassl.diff extra/yassl/src/yassl_error.cpp: Import patch yassl.diff extra/yassl/src/yassl_imp.cpp: Import patch yassl.diff extra/yassl/src/yassl_int.cpp: Import patch yassl.diff extra/yassl/taocrypt/include/aes.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/algebra.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/arc4.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/asn.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/block.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/blowfish.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/coding.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/des.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/dh.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/dsa.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/error.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/file.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/hash.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/hmac.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/integer.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/kernelc.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/md2.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/md4.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/md5.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/misc.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/modarith.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/modes.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/pwdbased.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/random.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/ripemd.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/rsa.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/runtime.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/sha.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/twofish.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/type_traits.hpp: Import patch yassl.diff extra/yassl/taocrypt/include/types.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/algorithm.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/helpers.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/list.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/memory.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/memory_array.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/pair.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/stdexcept.hpp: Import patch yassl.diff extra/yassl/taocrypt/mySTL/vector.hpp: Import patch yassl.diff extra/yassl/taocrypt/src/aes.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/aestables.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/algebra.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/arc4.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/asn.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/bftables.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/blowfish.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/coding.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/crypto.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/des.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/dh.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/dsa.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/file.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/hash.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/integer.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/md2.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/md4.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/md5.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/misc.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/random.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/ripemd.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/rsa.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/sha.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/template_instnt.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/tftables.cpp: Import patch yassl.diff extra/yassl/taocrypt/src/twofish.cpp: Import patch yassl.diff
166 lines
4.9 KiB
C++
166 lines
4.9 KiB
C++
/*
|
|
Copyright (C) 2000-2007 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not, write to the
|
|
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
|
MA 02110-1301 USA.
|
|
*/
|
|
|
|
|
|
/* based on Wei Dai's modarith.h from CryptoPP */
|
|
|
|
|
|
#ifndef TAO_CRYPT_MODARITH_HPP
|
|
#define TAO_CRYPT_MODARITH_HPP
|
|
|
|
#include "misc.hpp"
|
|
#include "algebra.hpp"
|
|
|
|
namespace TaoCrypt {
|
|
|
|
|
|
// ModularArithmetic
|
|
class ModularArithmetic : public AbstractRing
|
|
{
|
|
public:
|
|
|
|
typedef int RandomizationParameter;
|
|
typedef Integer Element;
|
|
|
|
ModularArithmetic(const Integer &modulus = Integer::One())
|
|
: modulus(modulus), result((word)0, modulus.reg_.size()) {}
|
|
|
|
ModularArithmetic(const ModularArithmetic &ma)
|
|
: AbstractRing(),
|
|
modulus(ma.modulus), result((word)0, modulus.reg_.size()) {}
|
|
|
|
const Integer& GetModulus() const {return modulus;}
|
|
void SetModulus(const Integer &newModulus)
|
|
{
|
|
modulus = newModulus;
|
|
result.reg_.resize(modulus.reg_.size());
|
|
}
|
|
|
|
virtual bool IsMontgomeryRepresentation() const {return false;}
|
|
|
|
virtual Integer ConvertIn(const Integer &a) const
|
|
{return a%modulus;}
|
|
|
|
virtual Integer ConvertOut(const Integer &a) const
|
|
{return a;}
|
|
|
|
const Integer& Half(const Integer &a) const;
|
|
|
|
bool Equal(const Integer &a, const Integer &b) const
|
|
{return a==b;}
|
|
|
|
const Integer& Identity() const
|
|
{return Integer::Zero();}
|
|
|
|
const Integer& Add(const Integer &a, const Integer &b) const;
|
|
|
|
Integer& Accumulate(Integer &a, const Integer &b) const;
|
|
|
|
const Integer& Inverse(const Integer &a) const;
|
|
|
|
const Integer& Subtract(const Integer &a, const Integer &b) const;
|
|
|
|
Integer& Reduce(Integer &a, const Integer &b) const;
|
|
|
|
const Integer& Double(const Integer &a) const
|
|
{return Add(a, a);}
|
|
|
|
const Integer& MultiplicativeIdentity() const
|
|
{return Integer::One();}
|
|
|
|
const Integer& Multiply(const Integer &a, const Integer &b) const
|
|
{return result1 = a*b%modulus;}
|
|
|
|
const Integer& Square(const Integer &a) const
|
|
{return result1 = a.Squared()%modulus;}
|
|
|
|
bool IsUnit(const Integer &a) const
|
|
{return Integer::Gcd(a, modulus).IsUnit();}
|
|
|
|
const Integer& MultiplicativeInverse(const Integer &a) const
|
|
{return result1 = a.InverseMod(modulus);}
|
|
|
|
const Integer& Divide(const Integer &a, const Integer &b) const
|
|
{return Multiply(a, MultiplicativeInverse(b));}
|
|
|
|
Integer CascadeExponentiate(const Integer &x, const Integer &e1,
|
|
const Integer &y, const Integer &e2) const;
|
|
|
|
void SimultaneousExponentiate(Element *results, const Element &base,
|
|
const Integer *exponents, unsigned int exponentsCount) const;
|
|
|
|
unsigned int MaxElementBitLength() const
|
|
{return (modulus-1).BitCount();}
|
|
|
|
unsigned int MaxElementByteLength() const
|
|
{return (modulus-1).ByteCount();}
|
|
|
|
|
|
static const RandomizationParameter DefaultRandomizationParameter;
|
|
|
|
protected:
|
|
Integer modulus;
|
|
mutable Integer result, result1;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! do modular arithmetics in Montgomery representation for increased speed
|
|
class MontgomeryRepresentation : public ModularArithmetic
|
|
{
|
|
public:
|
|
MontgomeryRepresentation(const Integer &modulus); // modulus must be odd
|
|
|
|
bool IsMontgomeryRepresentation() const {return true;}
|
|
|
|
Integer ConvertIn(const Integer &a) const
|
|
{return (a<<(WORD_BITS*modulus.reg_.size()))%modulus;}
|
|
|
|
Integer ConvertOut(const Integer &a) const;
|
|
|
|
const Integer& MultiplicativeIdentity() const
|
|
{return result1 = Integer::Power2(WORD_BITS*modulus.reg_.size())%modulus;}
|
|
|
|
const Integer& Multiply(const Integer &a, const Integer &b) const;
|
|
|
|
const Integer& Square(const Integer &a) const;
|
|
|
|
const Integer& MultiplicativeInverse(const Integer &a) const;
|
|
|
|
Integer CascadeExponentiate(const Integer &x, const Integer &e1,
|
|
const Integer &y, const Integer &e2) const
|
|
{return AbstractRing::CascadeExponentiate(x, e1, y, e2);}
|
|
|
|
void SimultaneousExponentiate(Element *results, const Element &base,
|
|
const Integer *exponents, unsigned int exponentsCount) const
|
|
{AbstractRing::SimultaneousExponentiate(results, base,
|
|
exponents, exponentsCount);}
|
|
|
|
private:
|
|
Integer u;
|
|
mutable AlignedWordBlock workspace;
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
#endif // TAO_CRYPT_MODARITH_HPP
|