// Copyright 2024 Azahar Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once #include #include #include #include #include #include "common/common_types.h" #include "cryptopp/eccrypto.h" namespace HW::ECC { // All the supported 3DS ECC operations use the sect233r1 curve, // so we default to sizes for this curve only. static constexpr size_t INT_SIZE = 0x1E; using CryptoPPInteger = CryptoPP::Integer; using CryptoPPPoint = CryptoPP::EC2N::Point; using CryptoPPECCPrivateKey = CryptoPP::ECDSA::PrivateKey; using CryptoPPECCPublicKey = CryptoPP::ECDSA::PublicKey; struct PrivateKey { std::array x; CryptoPPInteger AsCryptoPPInteger() const; CryptoPPECCPrivateKey AsCryptoPPPrivateKey() const; }; union PublicKey { struct { std::array x; std::array y; }; std::array xy; CryptoPPPoint AsCryptoPPPoint() const; CryptoPPECCPublicKey AsCryptoPPPublicKey() const; }; union Signature { struct { std::array r; std::array s; }; std::array rs; }; void InitSlots(); PrivateKey CreateECCPrivateKey(std::span private_key_x, bool fix_up = false); PublicKey CreateECCPublicKey(std::span public_key_xy); Signature CreateECCSignature(std::span signature_rs); PublicKey MakePublicKey(const CryptoPPECCPrivateKey& private_key_cpp); PublicKey MakePublicKey(const PrivateKey& private_key); std::pair GenerateKeyPair(); Signature Sign(std::span data, PrivateKey private_key); bool Verify(std::span data, Signature signature, PublicKey public_key); std::vector Agree(PrivateKey private_key, PublicKey others_public_key); const PublicKey& GetRootPublicKey(); } // namespace HW::ECC