11 #include <botan/gf2m_small_m.h>
12 #include <botan/exceptn.h>
17 #define MAX_EXT_DEG 16
41 std::vector<gf2m> gf_exp_table(
size_t deg,
gf2m prime_poly)
45 std::vector<gf2m> tab((1 << deg) + 1);
48 for(
size_t i = 1; i < tab.size(); ++i)
50 const bool overflow = tab[i - 1] >> (deg - 1);
51 tab[i] = (tab[i-1] << 1) ^ (overflow ? prime_poly : 0);
57 const std::vector<gf2m>& exp_table(
size_t deg)
62 throw Exception(
"GF2m_Field does not support degree " +
std::to_string(deg));
65 tabs[deg] = gf_exp_table(deg, prim_poly[deg]);
70 std::vector<gf2m> gf_log_table(
size_t deg,
const std::vector<gf2m>& exp)
72 std::vector<gf2m> tab(1 << deg);
74 tab[0] = (1 << deg) - 1;
75 for (
size_t i = 0; i < tab.size(); ++i)
82 const std::vector<gf2m>& log_table(
size_t deg)
87 throw Exception(
"GF2m_Field does not support degree " +
std::to_string(deg));
90 tabs[deg] = gf_log_table(deg, exp_table(deg));
100 mem[1] = to_enc & 0xFF;
101 return sizeof(to_enc);
107 result = mem[0] << 8;
113 m_gf_multiplicative_order((1 << extdeg) - 1),
114 m_gf_log_table(log_table(m_gf_extension_degree)),
115 m_gf_exp_table(exp_table(m_gf_extension_degree))
121 const int32_t sub_res =
static_cast<int32_t
>(
gf_log(x) -
static_cast<int32_t
>(
gf_log(y)));
122 const int32_t modq_res =
static_cast<int32_t
>(_gf_modq_1(sub_res));
123 const int32_t div_res =
static_cast<int32_t
>(x) ? static_cast<int32_t>(
gf_exp(modq_res)) : 0;
124 return static_cast<gf2m>(div_res);
GF2m_Field(size_t extdeg)
gf2m get_extension_degree() const
gf2m decode_gf2m(const uint8_t *mem)
std::string to_string(const BER_Object &obj)
gf2m gf_log(gf2m i) const
gf2m gf_pow(gf2m x, int i) const
uint32_t encode_gf2m(gf2m to_enc, uint8_t *mem)
gf2m gf_exp(gf2m i) const
gf2m gf_div(gf2m x, gf2m y) const