4 ms·
Nice comment! Some nits. > Any division by Foo is equivalent to multiplying by (1/Foo), which might be faster that's not just a weird property you can use fo
by nullc 5y ago
Nice comment! Some nits.
> Any division by Foo is equivalent to multiplying by (1/Foo), which might be faster
that's not just a weird property you can use for performance, standard grade-school division doesn't work in fields because the results are outside of the field.
So division is redefined using the modular inverse-- which has a natural definition the modular inverse a of element x is the value that makes the product ax equal the identity.
The "cool optimization" though is that since modular inverses are kinda expensive, you can rewrite your arithmetic to keep things in fractional form as long as possible and get a big speed-up.
[This also applies to ordinary numbers with division: E.g. use newton's method to compute square roots but don't do any division, keep everything as fractions -- with that trick you can compute pretty accurate square roots in your head! ... seems people don't get taught this kind of thing any more because of access to calculator :) ]
> And again, this is most important for GF(2^32), aka the 32-bit number field that's common on today's computers.
This makes it sound like you're saying that regular computer arithmetic is GF(2^32). :)
In my experience GF(2^32) arithmetic is fairly uncommon! Work in GF(2^8) is extremely common, e.g. it's used all over in error correcting codes. The field size is common because it's perfectly reasonable to implement multiplication using a log and inverse log table.
For 2^32 you really want a CLMUL instruction if you want high performance. Though once you have one you can easily go to 64-bits if it's useful for your application.
You won't find a lot of binary extension field (GF(2^n)) stuff in crypto these days except sometimes hidden deep inside a block cipher (like the AES sbox) because the extensions create a lot of additional and surprising algebraic structure. E.g. in these fields (x + y)^2 == (x^2 + y^2)! ( https://en.wikipedia.org/wiki/Freshman%27s_dream https://en.wikipedia.org/wiki/Freshman%27s_dream ) Unless you're doing something where the structure is useful, it's better to not have it.
Error correcting codes, CRCs, hashes, and related stuff-- however, has lots of it.