mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-14 19:27:08 +12:00
* Fix typo (#680) Co-authored-by: Noumi <139501014+noumidev@users.noreply.github.com> * More PTM stuff Co-Authored-By: Noumi <139501014+noumidev@users.noreply.github.com> * Make system language configurable * Fix building crypto++ for x64 target on Apple silicon MacOS * Attempt to switch to M1 runners again * Prevent selecting Vulkan renderer in Qt frontend and present a message * Libretro: Add system language option * Only enable audio by default on libretro for now * CMake: Bump version * Store configuration file in AppData root if not in working directory (#693) * Store configuration file in AppData root if not in working directory This fixes MacOS app bundles, as the emulator cannot write the config file into the app bundle. * Remove duplicate fs calls * I'm an idiot sandwich --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> * GL: Add usingGLES to driverInfo struct (#694) * Wayland fixes part 1 * Support GLES on desktop * Qt: Fix Wayland support Qt will only create a Wayland surface when show() is called on the main window and on the ScreenWidget. Thus, call the function before creating the GL context. Doesn't cause regressions on XWayland, untested in other platforms. Fixes #586 * No need to call screen->show() twice * Fix disabling Wayland & building on some distros (#700) * GLES: Properly stub out logic ops * Fix git versioning * Android_Build: Implement ccache (#703) * Android_Build: Implement ccache * Update Android_Build.yml * Update Android_Build.yml --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> * Removed dead Citra link in readme (#706) * CRO: Lighter icache flushes * Implement Luma icache SVCs * Add missing SVC logs * GPU: Add sw texture copies * Use vk::detail::DynamicLoader instead of vk::DynamicLoader (#710) * Use vk::detail::DynamicLoader instead of vk::DynamicLoader * Update renderer_vk.cpp * Vk: Fix typo * Vk: Lock CI runners to SDK version 1.3.301 temporarily * Vk: Fixing CI pt 2 * Vulkan: Fixing CI pt 3 * Vk: Fix typo * Temporarily give 80MB to all processes (#715) * Try to cross-compile Libretro core for arm64 (#717) * Try to cross-compile Libretro core for arm64 * Bonk * Update Hydra_Build.yml * [WIP] Libretro: Add audio support (#714) * Libretro: Add audio support * Adding audio interface part 1 * Audio device pt 2 * More audio device * More audio device * Morea uudi odevice * More audio device * More audio device * More audio device --------- Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> * Libretro audio device: Fix frame count * Mark audio devices as final * Add toggle for libretro audio device (#719) * Very important work (#720) * Very important work * Most important fix * Add more HLE service calls for eshop (#721) * CI: Fix Vulkan SDK action (#723) * GPU registers: Fix writes to some registers ignoring the mask (#725) Co-authored-by: henry <23128103+atem2069@users.noreply.github.com> * OLED theme * OLED theme config fix (#736) Co-authored-by: smiRaphi <neogt404@gmail.com> * Adding Swedish translation * Fix Metal renderer compilation on iOS * [Core] Improve iOS compilation workflow * [Qt] Hook Swedish to UI * AppDataDocumentProvider: Typo (#740) * More iOS work * More iOS progress * More iOS work * AppDataDocumentProvider: Add missing ``COLUMN_FLAGS`` in the default document projectation (#741) Fixes unable to copy files from device to app's internal storage problem * More iOS work * ios: Simplify MTKView interface (still doesn't work though) * ios: Pass CAMetalLayer instead of void* to Obj-C++ bridging header * Fix bridging cast * FINALLY IOS GRAPHICS * ios: Remove printf spam * Metal: Reimplement some texture formats on iOS * metal: implement texture decoder * metal: check for format support * metal: implement texture swizzling * metal: remove unused texture functions * Shadergen types: Add Metal & MSL * Format * Undo submodule changes * Readme: Add Chonkystation 3 * Metal: Use std::unique_ptr for texture decode * AppDataDocumentProvider: Allow to remove documents (#744) * AppDataDocumentProvider: Allow to remove documents * Typo * Metal renderer fixes for iOS * iOS driver: Add doc comments * iOS: Add frontend & frontend build files (#746) * iOS: Add SwiftUI part to repo * Add iOS build script * Update SDL2 submodule * Fix iOS build script * CI: Update xcode tools for iOS * Update iOS_Build.yml * Update iOS build * Lower XCode version * A * Update project.pbxproj * Update iOS_Build.yml * Update iOS_Build.yml * Update build.sh * iOS: Fail on build error * iOS: Add file picker (#747) * iOS: Add file picker * Fix lock placement * Qt: Add runpog icon (#752) * Update discord-rpc submodule (#753) * Remove cryptoppwin submodule (#754) * Add optional texture hashing * Fix build on new Vk SDK (#757) Co-authored-by: Nadia Holmquist Pedersen <893884+nadiaholmquist@users.noreply.github.com> * CI: Use new Vulkan SDK --------- Co-authored-by: Noumi <139501014+noumidev@users.noreply.github.com> Co-authored-by: Thomas <thomas@thomasw.dev> Co-authored-by: Thomas <twvd@users.noreply.github.com> Co-authored-by: Daniel López Guimaraes <danielectra@outlook.com> Co-authored-by: Jonian Guveli <jonian@hardpixel.eu> Co-authored-by: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Co-authored-by: Auxy6858 <71662994+Auxy6858@users.noreply.github.com> Co-authored-by: Paris Oplopoios <parisoplop@gmail.com> Co-authored-by: henry <23128103+atem2069@users.noreply.github.com> Co-authored-by: smiRaphi <neogt404@gmail.com> Co-authored-by: smiRaphi <87574679+smiRaphi@users.noreply.github.com> Co-authored-by: Daniel Nylander <po@danielnylander.se> Co-authored-by: Samuliak <samuliak77@gmail.com> Co-authored-by: Albert <45282415+ggrtk@users.noreply.github.com> Co-authored-by: Nadia Holmquist Pedersen <893884+nadiaholmquist@users.noreply.github.com>
275 lines
12 KiB
C++
275 lines
12 KiB
C++
// dh.h - originally written and placed in the public domain by Wei Dai
|
|
|
|
/// \file dh.h
|
|
/// \brief Classes for Diffie-Hellman key exchange
|
|
|
|
#ifndef CRYPTOPP_DH_H
|
|
#define CRYPTOPP_DH_H
|
|
|
|
#include "cryptlib.h"
|
|
#include "gfpcrypt.h"
|
|
#include "algebra.h"
|
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
/// \brief Diffie-Hellman domain
|
|
/// \tparam GROUP_PARAMETERS group parameters
|
|
/// \tparam COFACTOR_OPTION cofactor multiplication option
|
|
/// \details A Diffie-Hellman domain is a set of parameters that must be shared
|
|
/// by two parties in a key agreement protocol, along with the algorithms
|
|
/// for generating key pairs and deriving agreed values.
|
|
/// \details For COFACTOR_OPTION, see CofactorMultiplicationOption.
|
|
/// \sa DL_SimpleKeyAgreementDomainBase
|
|
/// \since Crypto++ 1.0
|
|
template <class GROUP_PARAMETERS, class COFACTOR_OPTION = typename GROUP_PARAMETERS::DefaultCofactorOption>
|
|
class DH_Domain : public DL_SimpleKeyAgreementDomainBase<typename GROUP_PARAMETERS::Element>
|
|
{
|
|
typedef DL_SimpleKeyAgreementDomainBase<typename GROUP_PARAMETERS::Element> Base;
|
|
|
|
public:
|
|
typedef GROUP_PARAMETERS GroupParameters;
|
|
typedef typename GroupParameters::Element Element;
|
|
typedef DL_KeyAgreementAlgorithm_DH<Element, COFACTOR_OPTION> DH_Algorithm;
|
|
typedef DH_Domain<GROUP_PARAMETERS, COFACTOR_OPTION> Domain;
|
|
|
|
virtual ~DH_Domain() {}
|
|
|
|
/// \brief Construct a Diffie-Hellman domain
|
|
DH_Domain() {}
|
|
|
|
/// \brief Construct a Diffie-Hellman domain
|
|
/// \param params group parameters and options
|
|
DH_Domain(const GroupParameters ¶ms)
|
|
: m_groupParameters(params) {}
|
|
|
|
/// \brief Construct a Diffie-Hellman domain
|
|
/// \param bt BufferedTransformation with group parameters and options
|
|
DH_Domain(BufferedTransformation &bt)
|
|
{m_groupParameters.BERDecode(bt);}
|
|
|
|
/// \brief Create a Diffie-Hellman domain
|
|
/// \tparam T2 template parameter used as a constructor parameter
|
|
/// \param v1 RandomNumberGenerator derived class
|
|
/// \param v2 second parameter
|
|
/// \details v1 and v2 are passed directly to the GROUP_PARAMETERS object.
|
|
template <class T2>
|
|
DH_Domain(RandomNumberGenerator &v1, const T2 &v2)
|
|
{m_groupParameters.Initialize(v1, v2);}
|
|
|
|
/// \brief Create a Diffie-Hellman domain
|
|
/// \tparam T2 template parameter used as a constructor parameter
|
|
/// \tparam T3 template parameter used as a constructor parameter
|
|
/// \param v1 RandomNumberGenerator derived class
|
|
/// \param v2 second parameter
|
|
/// \param v3 third parameter
|
|
/// \details v1, v2 and v3 are passed directly to the GROUP_PARAMETERS object.
|
|
template <class T2, class T3>
|
|
DH_Domain(RandomNumberGenerator &v1, const T2 &v2, const T3 &v3)
|
|
{m_groupParameters.Initialize(v1, v2, v3);}
|
|
|
|
/// \brief Create a Diffie-Hellman domain
|
|
/// \tparam T2 template parameter used as a constructor parameter
|
|
/// \tparam T3 template parameter used as a constructor parameter
|
|
/// \tparam T4 template parameter used as a constructor parameter
|
|
/// \param v1 RandomNumberGenerator derived class
|
|
/// \param v2 second parameter
|
|
/// \param v3 third parameter
|
|
/// \param v4 fourth parameter
|
|
/// \details v1, v2, v3 and v4 are passed directly to the GROUP_PARAMETERS object.
|
|
template <class T2, class T3, class T4>
|
|
DH_Domain(RandomNumberGenerator &v1, const T2 &v2, const T3 &v3, const T4 &v4)
|
|
{m_groupParameters.Initialize(v1, v2, v3, v4);}
|
|
|
|
/// \brief Construct a Diffie-Hellman domain
|
|
/// \tparam T1 template parameter used as a constructor parameter
|
|
/// \tparam T2 template parameter used as a constructor parameter
|
|
/// \param v1 first parameter
|
|
/// \param v2 second parameter
|
|
/// \details v1 and v2 are passed directly to the GROUP_PARAMETERS object.
|
|
template <class T1, class T2>
|
|
DH_Domain(const T1 &v1, const T2 &v2)
|
|
{m_groupParameters.Initialize(v1, v2);}
|
|
|
|
/// \brief Construct a Diffie-Hellman domain
|
|
/// \tparam T1 template parameter used as a constructor parameter
|
|
/// \tparam T2 template parameter used as a constructor parameter
|
|
/// \tparam T3 template parameter used as a constructor parameter
|
|
/// \param v1 first parameter
|
|
/// \param v2 second parameter
|
|
/// \param v3 third parameter
|
|
/// \details v1, v2 and v3 are passed directly to the GROUP_PARAMETERS object.
|
|
template <class T1, class T2, class T3>
|
|
DH_Domain(const T1 &v1, const T2 &v2, const T3 &v3)
|
|
{m_groupParameters.Initialize(v1, v2, v3);}
|
|
|
|
/// \brief Construct a Diffie-Hellman domain
|
|
/// \tparam T1 template parameter used as a constructor parameter
|
|
/// \tparam T2 template parameter used as a constructor parameter
|
|
/// \tparam T3 template parameter used as a constructor parameter
|
|
/// \tparam T4 template parameter used as a constructor parameter
|
|
/// \param v1 first parameter
|
|
/// \param v2 second parameter
|
|
/// \param v3 third parameter
|
|
/// \param v4 fourth parameter
|
|
/// \details v1, v2, v3 and v4 are passed directly to the GROUP_PARAMETERS object.
|
|
template <class T1, class T2, class T3, class T4>
|
|
DH_Domain(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
|
|
{m_groupParameters.Initialize(v1, v2, v3, v4);}
|
|
|
|
/// \brief Retrieves the group parameters for this domain
|
|
/// \return the group parameters for this domain as a const reference
|
|
const GroupParameters & GetGroupParameters() const {return m_groupParameters;}
|
|
/// \brief Retrieves the group parameters for this domain
|
|
/// \return the group parameters for this domain as a non-const reference
|
|
GroupParameters & AccessGroupParameters() {return m_groupParameters;}
|
|
|
|
/// \brief Generate a public key from a private key in this domain
|
|
/// \param rng RandomNumberGenerator derived class
|
|
/// \param privateKey byte buffer with the previously generated private key
|
|
/// \param publicKey byte buffer for the generated public key in this domain
|
|
/// \details If using a FIPS 140-2 validated library on Windows, then this class will perform
|
|
/// a self test to ensure the key pair is pairwise consistent. Non-FIPS and non-Windows
|
|
/// builds of the library do not provide FIPS validated cryptography, so the code should be
|
|
/// removed by the optimizer.
|
|
/// \pre <tt>COUNTOF(publicKey) == PublicKeyLength()</tt>
|
|
void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const
|
|
{
|
|
Base::GeneratePublicKey(rng, privateKey, publicKey);
|
|
|
|
if (FIPS_140_2_ComplianceEnabled())
|
|
{
|
|
SecByteBlock privateKey2(this->PrivateKeyLength());
|
|
this->GeneratePrivateKey(rng, privateKey2);
|
|
|
|
SecByteBlock publicKey2(this->PublicKeyLength());
|
|
Base::GeneratePublicKey(rng, privateKey2, publicKey2);
|
|
|
|
SecByteBlock agreedValue(this->AgreedValueLength()), agreedValue2(this->AgreedValueLength());
|
|
bool agreed1 = this->Agree(agreedValue, privateKey, publicKey2);
|
|
bool agreed2 = this->Agree(agreedValue2, privateKey2, publicKey);
|
|
|
|
if (!agreed1 || !agreed2 || agreedValue != agreedValue2)
|
|
throw SelfTestFailure(this->AlgorithmName() + ": pairwise consistency test failed");
|
|
}
|
|
}
|
|
|
|
static std::string CRYPTOPP_API StaticAlgorithmName()
|
|
{return GroupParameters::StaticAlgorithmNamePrefix() + DH_Algorithm::StaticAlgorithmName();}
|
|
std::string AlgorithmName() const {return StaticAlgorithmName();}
|
|
|
|
private:
|
|
const DL_KeyAgreementAlgorithm<Element> & GetKeyAgreementAlgorithm() const
|
|
{return Singleton<DH_Algorithm>().Ref();}
|
|
DL_GroupParameters<Element> & AccessAbstractGroupParameters()
|
|
{return m_groupParameters;}
|
|
|
|
GroupParameters m_groupParameters;
|
|
};
|
|
|
|
CRYPTOPP_DLL_TEMPLATE_CLASS DH_Domain<DL_GroupParameters_GFP_DefaultSafePrime>;
|
|
|
|
/// \brief Diffie-Hellman in GF(p)
|
|
/// \details DH() class is a typedef of DH_Domain(). The documentation that follows
|
|
/// does not exist. Rather the documentation was created in response to <a href="https://github.com/weidai11/cryptopp/issues/328">Issue
|
|
/// 328, Diffie-Hellman example code not compiling</a>.
|
|
/// \details Generally speaking, a DH() object is ephemeral and is intended to execute one instance of the Diffie-Hellman protocol. The
|
|
/// private and public key parts are not intended to be set or persisted. Rather, a new set of domain parameters are generated each
|
|
/// time an object is created.
|
|
/// \details Once a DH() object is created, once can retrieve the ephemeral public key for the other party with code similar to the
|
|
/// following.
|
|
/// <pre> AutoSeededRandomPool prng;
|
|
/// Integer p, q, g;
|
|
/// PrimeAndGenerator pg;
|
|
///
|
|
/// pg.Generate(1, prng, 512, 511);
|
|
/// p = pg.Prime();
|
|
/// q = pg.SubPrime();
|
|
/// g = pg.Generator();
|
|
///
|
|
/// DH dh(p, q, g);
|
|
/// SecByteBlock t1(dh.PrivateKeyLength()), t2(dh.PublicKeyLength());
|
|
/// dh.GenerateKeyPair(prng, t1, t2);
|
|
/// Integer k1(t1, t1.size()), k2(t2, t2.size());
|
|
///
|
|
/// cout << "Private key:\n";
|
|
/// cout << hex << k1 << endl;
|
|
///
|
|
/// cout << "Public key:\n";
|
|
/// cout << hex << k2 << endl;</pre>
|
|
///
|
|
/// \details Output of the program above will be similar to the following.
|
|
/// <pre> $ ./cryptest.exe
|
|
/// Private key:
|
|
/// 72b45a42371545e9d4880f48589aefh
|
|
/// Public key:
|
|
/// 45fdb13f97b1840626f0250cec1dba4a23b894100b51fb5d2dd13693d789948f8bfc88f9200014b2
|
|
/// ba8dd8a6debc471c69ef1e2326c61184a2eca88ec866346bh</pre>
|
|
/// \sa <a href="http://www.cryptopp.com/wiki/Diffie-Hellman">Diffie-Hellman on the Crypto++ wiki</a> and
|
|
/// <a href="http://www.weidai.com/scan-mirror/ka.html#DH">Diffie-Hellman</a> in GF(p) with key validation
|
|
/// \since Crypto++ 1.0
|
|
#if defined(CRYPTOPP_DOXYGEN_PROCESSING)
|
|
struct DH : public DH_Domain<DL_GroupParameters_GFP_DefaultSafePrime>
|
|
{
|
|
typedef DH_Domain<DL_GroupParameters_GFP_DefaultSafePrime> GroupParameters;
|
|
typedef GroupParameters::Element Element;
|
|
|
|
virtual ~DH() {}
|
|
|
|
/// \brief Create an uninitialized Diffie-Hellman object
|
|
DH() : DH_Domain() {}
|
|
|
|
/// \brief Initialize a Diffie-Hellman object
|
|
/// \param bt BufferedTransformation with group parameters and options
|
|
DH(BufferedTransformation &bt) : DH_Domain(bt) {}
|
|
|
|
/// \brief Initialize a Diffie-Hellman object
|
|
/// \param params group parameters and options
|
|
DH(const GroupParameters ¶ms) : DH_Domain(params) {}
|
|
|
|
/// \brief Create a Diffie-Hellman object
|
|
/// \param rng a RandomNumberGenerator derived class
|
|
/// \param modulusBits the size of the modulus, in bits
|
|
/// \details This function overload of Initialize() creates a new Diffie-Hellman object because it
|
|
/// takes a RandomNumberGenerator() as a parameter.
|
|
DH(RandomNumberGenerator &rng, unsigned int modulusBits) : DH_Domain(rng, modulusBits) {}
|
|
|
|
/// \brief Initialize a Diffie-Hellman object
|
|
/// \param p the modulus
|
|
/// \param g the generator
|
|
DH(const Integer &p, const Integer &g) : DH_Domain(p, g) {}
|
|
|
|
/// \brief Initialize a Diffie-Hellman object
|
|
/// \param p the modulus
|
|
/// \param q the subgroup order
|
|
/// \param g the generator
|
|
DH(const Integer &p, const Integer &q, const Integer &g) : DH_Domain(p, q, g) {}
|
|
|
|
/// \brief Creates a Diffie-Hellman object
|
|
/// \param rng a RandomNumberGenerator derived class
|
|
/// \param modulusBits the size of the modulus, in bits
|
|
/// \details This function overload of Initialize() creates a new Diffie-Hellman object because it
|
|
/// takes a RandomNumberGenerator() as a parameter.
|
|
void Initialize(RandomNumberGenerator &rng, unsigned int modulusBits)
|
|
{AccessGroupParameters().Initialize(rng, modulusBits);}
|
|
|
|
/// \brief Initialize a Diffie-Hellman object
|
|
/// \param p the modulus
|
|
/// \param g the generator
|
|
void Initialize(const Integer &p, const Integer &g)
|
|
{AccessGroupParameters().Initialize(p, g);}
|
|
|
|
/// \brief Initialize a Diffie-Hellman object
|
|
/// \param p the modulus
|
|
/// \param q the subgroup order
|
|
/// \param g the generator
|
|
void Initialize(const Integer &p, const Integer &q, const Integer &g)
|
|
{AccessGroupParameters().Initialize(p, q, g);}
|
|
};
|
|
#else
|
|
// The real DH class is a typedef.
|
|
typedef DH_Domain<DL_GroupParameters_GFP_DefaultSafePrime> DH;
|
|
#endif
|
|
|
|
NAMESPACE_END
|
|
|
|
#endif
|