2016-10-28 06:16:58 +09:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
//multi-precision arithmetic
|
|
|
|
//warning: each size is quadratically more expensive than the size before it!
|
|
|
|
|
2023-05-03 14:53:49 +09:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2016-10-28 06:16:58 +09:00
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
#include <nall/string.hpp>
|
|
|
|
#include <nall/range.hpp>
|
|
|
|
#include <nall/traits.hpp>
|
|
|
|
|
|
|
|
#include <nall/arithmetic/unsigned.hpp>
|
|
|
|
|
2018-10-04 19:11:23 +09:00
|
|
|
namespace nall {
|
2021-02-08 18:11:00 +09:00
|
|
|
template<u32 Bits> struct ArithmeticNatural;
|
|
|
|
template<> struct ArithmeticNatural< 8> { using type = u8; };
|
|
|
|
template<> struct ArithmeticNatural< 16> { using type = u16; };
|
|
|
|
template<> struct ArithmeticNatural< 32> { using type = u32; };
|
|
|
|
template<> struct ArithmeticNatural< 64> { using type = u64; };
|
2021-09-21 23:33:34 +09:00
|
|
|
#if defined(__SIZEOF_INT128__)
|
2021-02-08 18:11:00 +09:00
|
|
|
template<> struct ArithmeticNatural<128> { using type = u128; };
|
2018-10-04 19:11:23 +09:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-21 23:33:34 +09:00
|
|
|
#if !defined(__SIZEOF_INT128__)
|
2016-10-28 06:16:58 +09:00
|
|
|
#define PairBits 128
|
|
|
|
#define TypeBits 64
|
|
|
|
#define HalfBits 32
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PairBits 256
|
|
|
|
#define TypeBits 128
|
|
|
|
#define HalfBits 64
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
|
|
|
|
|
|
|
#define PairBits 512
|
|
|
|
#define TypeBits 256
|
|
|
|
#define HalfBits 128
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
|
|
|
|
|
|
|
#define PairBits 1024
|
|
|
|
#define TypeBits 512
|
|
|
|
#define HalfBits 256
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
|
|
|
|
|
|
|
#define PairBits 2048
|
|
|
|
#define TypeBits 1024
|
|
|
|
#define HalfBits 512
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
|
|
|
|
|
|
|
#define PairBits 4096
|
|
|
|
#define TypeBits 2048
|
|
|
|
#define HalfBits 1024
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
|
|
|
|
|
|
|
#define PairBits 8192
|
|
|
|
#define TypeBits 4096
|
|
|
|
#define HalfBits 2048
|
|
|
|
#include <nall/arithmetic/natural.hpp>
|
|
|
|
#undef PairBits
|
|
|
|
#undef TypeBits
|
|
|
|
#undef HalfBits
|
2018-09-02 23:06:41 +09:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
//TODO: these types are for expressing smaller bit ranges in class interfaces
|
|
|
|
//for instance, XChaCha20 taking a 192-bit nonce
|
|
|
|
//however, they still allow more bits than expressed ...
|
|
|
|
//some sort of wrapper needs to be devised to ensure these sizes are masked and wrap appropriately
|
|
|
|
|
2021-02-08 18:11:00 +09:00
|
|
|
using u192 = u256;
|
2018-09-02 23:06:41 +09:00
|
|
|
}
|