| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include "gf.h" |
| 14 |
|
| 15 |
#include "crypto_int32.h" |
| 16 |
|
| 17 |
|
| 18 |
gf gf_iszero(gf a) |
| 19 |
{ |
| 20 |
return crypto_int32_zero_mask(a) & GFMASK; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
static gf gf_sq(gf in) |
| 26 |
{ |
| 27 |
const uint32_t B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF}; |
| 28 |
|
| 29 |
uint32_t x = in; |
| 30 |
uint32_t t; |
| 31 |
|
| 32 |
x = (x | crypto_int32_shlmod(x,8)) & B[3]; |
| 33 |
x = (x | crypto_int32_shlmod(x,4)) & B[2]; |
| 34 |
x = (x | crypto_int32_shlmod(x,2)) & B[1]; |
| 35 |
x = (x | crypto_int32_shlmod(x,1)) & B[0]; |
| 36 |
|
| 37 |
t = x & 0x7FC000; |
| 38 |
x ^= t >> 9; |
| 39 |
x ^= t >> 12; |
| 40 |
|
| 41 |
t = x & 0x3000; |
| 42 |
x ^= t >> 9; |
| 43 |
x ^= t >> 12; |
| 44 |
|
| 45 |
return x & GFMASK; |
| 46 |
} |
| 47 |
|
| 48 |
gf gf_inv(gf in) |
| 49 |
{ |
| 50 |
gf tmp_11; |
| 51 |
gf tmp_1111; |
| 52 |
|
| 53 |
gf out = in; |
| 54 |
|
| 55 |
out = gf_sq(out); |
| 56 |
tmp_11 = gf_mul(out, in); |
| 57 |
|
| 58 |
out = gf_sq(tmp_11); |
| 59 |
out = gf_sq(out); |
| 60 |
tmp_1111 = gf_mul(out, tmp_11); |
| 61 |
|
| 62 |
out = gf_sq(tmp_1111); |
| 63 |
out = gf_sq(out); |
| 64 |
out = gf_sq(out); |
| 65 |
out = gf_sq(out); |
| 66 |
out = gf_mul(out, tmp_1111); |
| 67 |
|
| 68 |
out = gf_sq(out); |
| 69 |
out = gf_sq(out); |
| 70 |
out = gf_mul(out, tmp_11); |
| 71 |
|
| 72 |
out = gf_sq(out); |
| 73 |
out = gf_mul(out, in); |
| 74 |
|
| 75 |
return gf_sq(out); |
| 76 |
} |
| 77 |
|