11#include <botan/internal/gf2m_small_m.h>
12#include <botan/exceptn.h>
40std::vector<gf2m> gf_exp_table(
size_t deg,
gf2m prime_poly)
44 std::vector<gf2m> tab((
static_cast<size_t>(1) << deg) + 1);
47 for(
size_t i = 1; i < tab.size(); ++i)
49 const gf2m overflow = tab[i-1] >> (deg - 1);
50 tab[i] = (tab[i-1] << 1) ^ (overflow * prime_poly);
56const std::vector<gf2m>& exp_table(
size_t deg)
61 throw Invalid_Argument(
"GF2m_Field does not support degree " + std::to_string(deg));
64 tabs[deg] = gf_exp_table(deg, prim_poly[deg]);
69std::vector<gf2m> gf_log_table(
size_t deg,
const std::vector<gf2m>& exp)
71 std::vector<gf2m> tab(
static_cast<size_t>(1) << deg);
73 tab[0] =
static_cast<gf2m>((
static_cast<gf2m>(1) << deg) - 1);
74 for(
size_t i = 0; i < tab.size(); ++i)
76 tab[exp[i]] =
static_cast<gf2m>(i);
81const std::vector<gf2m>& log_table(
size_t deg)
86 throw Invalid_Argument(
"GF2m_Field does not support degree " + std::to_string(deg));
89 tabs[deg] = gf_log_table(deg, exp_table(deg));
99 mem[1] = to_enc & 0xFF;
100 return sizeof(to_enc);
106 result = mem[0] << 8;
112 m_gf_multiplicative_order((1 << extdeg) - 1),
113 m_gf_log_table(log_table(m_gf_extension_degree)),
114 m_gf_exp_table(exp_table(m_gf_extension_degree))
120 const int32_t sub_res =
static_cast<int32_t
>(
gf_log(x) -
static_cast<int32_t
>(
gf_log(
y)));
121 const gf2m modq_res = _gf_modq_1(sub_res);
122 const int32_t div_res =
static_cast<int32_t
>(x) ?
static_cast<int32_t
>(
gf_exp(modq_res)) : 0;
123 return static_cast<gf2m>(div_res);
gf2m gf_div(gf2m x, gf2m y) const
GF2m_Field(size_t extdeg)
gf2m gf_exp(gf2m i) const
gf2m gf_log(gf2m i) const
gf2m decode_gf2m(const uint8_t *mem)
uint32_t encode_gf2m(gf2m to_enc, uint8_t *mem)