Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Finite field arithmetic
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== C programming example === Here is some [[C (programming language)|C]] code which will add and multiply numbers in the characteristic 2 finite field of order 2<sup>8</sup>, used for example by Rijndael algorithm or Reed–Solomon, using the [[Ancient Egyptian multiplication#Russian peasant multiplication|Russian peasant multiplication algorithm]]: <syntaxhighlight lang="c"> /* Add two numbers in the GF(2^8) finite field */ uint8_t gadd(uint8_t a, uint8_t b) { return a ^ b; } /* Multiply two numbers in the GF(2^8) finite field defined * by the modulo polynomial relation x^8 + x^4 + x^3 + x + 1 = 0 * (the other way being to do carryless multiplication followed by a modular reduction) */ uint8_t gmul(uint8_t a, uint8_t b) { uint8_t p = 0; /* accumulator for the product of the multiplication */ while (a != 0 && b != 0) { if (b & 1) /* if the polynomial for b has a constant term, add the corresponding a to p */ p ^= a; /* addition in GF(2^m) is an XOR of the polynomial coefficients */ if (a & 0x80) /* GF modulo: if a has a nonzero term x^7, then must be reduced when it becomes x^8 */ a = (a << 1) ^ 0x11b; /* subtract (XOR) the primitive polynomial x^8 + x^4 + x^3 + x + 1 (0b1_0001_1011) – you can change it but it must be irreducible */ else a <<= 1; /* equivalent to a*x */ b >>= 1; } return p; } </syntaxhighlight> This example has [[Timing attack|cache, timing, and branch prediction side-channel]] leaks, and is not suitable for use in cryptography.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)