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!
=== D programming example === This [[D (programming language)|D]] program will multiply numbers in Rijndael's finite field and generate a [[Netpbm format#PGM example|PGM]] image: <syntaxhighlight lang="D"> /** Multiply two numbers in the GF(2^8) finite field defined by the polynomial x^8 + x^4 + x^3 + x + 1. */ ubyte gMul(ubyte a, ubyte b) pure nothrow { ubyte p = 0; foreach (immutable ubyte counter; 0 .. 8) { p ^= -(b & 1) & a; auto mask = -((a >> 7) & 1); // 0b1_0001_1011 is x^8 + x^4 + x^3 + x + 1. a = cast(ubyte)((a << 1) ^ (0b1_0001_1011 & mask)); b >>= 1; } return p; } void main() { import std.stdio, std.conv; enum width = ubyte.max + 1, height = width; auto f = File("rijndael_finite_field_multiplication.pgm", "wb"); f.writefln("P5\n%d %d\n255", width, height); foreach (immutable y; 0 .. height) foreach (immutable x; 0 .. width) { immutable char c = gMul(x.to!ubyte, y.to!ubyte); f.write(c); } }</syntaxhighlight> This example does not use any branches or table lookups in order to avoid side channels and is therefore 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)