| 1 |
// 20240809 djb: split out of gf.c |
| 2 |
|
| 3 |
// linker define gf_mul |
| 4 |
|
| 5 |
#include "gf.h" |
| 6 |
#include "crypto_int32.h" |
| 7 |
|
| 8 |
/* field multiplication: returns in0 * in1 */ |
| 9 |
gf gf_mul(gf in0, gf in1) |
| 10 |
{ |
| 11 |
int i; |
| 12 |
|
| 13 |
uint32_t tmp; |
| 14 |
uint32_t t0; |
| 15 |
uint32_t t1; |
| 16 |
uint32_t t; |
| 17 |
|
| 18 |
t0 = in0; |
| 19 |
t1 = in1; |
| 20 |
|
| 21 |
tmp = t0 & crypto_int32_bottombit_mask(t1); |
| 22 |
|
| 23 |
for (i = 1; i < GFBITS; i++) { |
| 24 |
t0 <<= 1; |
| 25 |
t1 >>= 1; |
| 26 |
tmp ^= t0 & crypto_int32_bottombit_mask(t1); |
| 27 |
} |
| 28 |
|
| 29 |
// |
| 30 |
|
| 31 |
t = tmp & 0x1FF0000; |
| 32 |
tmp ^= (t >> 9) ^ (t >> 10) ^ (t >> 12) ^ (t >> 13); |
| 33 |
|
| 34 |
t = tmp & 0x000E000; |
| 35 |
tmp ^= (t >> 9) ^ (t >> 10) ^ (t >> 12) ^ (t >> 13); |
| 36 |
|
| 37 |
return tmp & GFMASK; |
| 38 |
} |
| 39 |
|