2 * GF-Complete: A Comprehensive Open Source Library for Galois Field Arithmetic
3 * James S. Plank, Ethan L. Miller, Kevin M. Greenan,
4 * Benjamin A. Arnold, John A. Burnum, Adam W. Disney, Allen C. McBride.
8 * Demonstrates using the procedures for examples in GF(2^w) for w <= 32.
18 #include "gf_complete.h"
23 fprintf(stderr, "usage: gf_example_2 w - w must be between 1 and 32\n");
27 int main(int argc, char **argv)
36 if (argc != 2) usage(NULL);
38 if (w <= 0 || w > 32) usage("Bad w");
40 /* Get two random numbers in a and b */
43 a = MOA_Random_W(w, 0);
44 b = MOA_Random_W(w, 0);
46 /* Create the proper instance of the gf_t object using defaults: */
50 /* And multiply a and b using the galois field: */
52 c = gf.multiply.w32(&gf, a, b);
53 printf("%u * %u = %u\n", a, b, c);
55 /* Divide the product by a and b */
57 printf("%u / %u = %u\n", c, a, gf.divide.w32(&gf, c, a));
58 printf("%u / %u = %u\n", c, b, gf.divide.w32(&gf, c, b));
60 /* If w is 4, 8, 16 or 32, do a very small region operation */
62 if (w == 4 || w == 8 || w == 16 || w == 32) {
63 r1 = (uint8_t *) malloc(16);
64 r2 = (uint8_t *) malloc(16);
66 if (w == 4 || w == 8) {
68 for (i = 1; i < 16; i++) r1[i] = MOA_Random_W(8, 1);
70 r16 = (uint16_t *) r1;
72 for (i = 1; i < 8; i++) r16[i] = MOA_Random_W(16, 1);
74 r32 = (uint32_t *) r1;
76 for (i = 1; i < 4; i++) r32[i] = MOA_Random_W(32, 1);
79 gf.multiply_region.w32(&gf, r1, r2, a, 16, 0);
81 printf("\nmultiply_region by 0x%x (%u)\n\n", a, a);
82 printf("R1 (the source): ");
84 for (i = 0; i < 16; i++) printf(" %x %x", r1[i] >> 4, r1[i] & 0xf);
86 for (i = 0; i < 16; i++) printf(" %02x", r1[i]);
88 for (i = 0; i < 8; i++) printf(" %04x", r16[i]);
90 for (i = 0; i < 4; i++) printf(" %08x", r32[i]);
92 printf("\nR2 (the product): ");
94 for (i = 0; i < 16; i++) printf(" %x %x", r2[i] >> 4, r2[i] & 0xf);
96 for (i = 0; i < 16; i++) printf(" %02x", r2[i]);
98 r16 = (uint16_t *) r2;
99 for (i = 0; i < 8; i++) printf(" %04x", r16[i]);
100 } else if (w == 32) {
101 r32 = (uint32_t *) r2;
102 for (i = 0; i < 4; i++) printf(" %08x", r32[i]);