### Blame view

examples/gf_example_3.c 1.86 KB
 `1` ``````/* `````` ```2 3 4 5``` `````` * GF-Complete: A Comprehensive Open Source Library for Galois Field Arithmetic * James S. Plank, Ethan L. Miller, Kevin M. Greenan, * Benjamin A. Arnold, John A. Burnum, Adam W. Disney, Allen C. McBride. * `````` ```6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48``` `````` * gf_example_3.c * * Identical to example_2 except it works in GF(2^64) */ #include #include #include #include #include #include #include "gf_complete.h" #include "gf_rand.h" void usage(char *s) { fprintf(stderr, "usage: gf_example_3\n"); exit(1); } int main(int argc, char **argv) { uint64_t a, b, c; uint64_t *r1, *r2; int i; gf_t gf; if (argc != 1) usage(NULL); /* Get two random numbers in a and b */ MOA_Seed(time(0)); a = MOA_Random_64(); b = MOA_Random_64(); /* Create the proper instance of the gf_t object using defaults: */ gf_init_easy(&gf, 64); /* And multiply a and b using the galois field: */ c = gf.multiply.w64(&gf, a, b); `````` `49` `````` printf("%llx * %llx = %llx\n", (long long unsigned int) a, (long long unsigned int) b, (long long unsigned int) c); `````` ```50 51 52``` `````` /* Divide the product by a and b */ `````` ```53 54``` `````` printf("%llx / %llx = %llx\n", (long long unsigned int) c, (long long unsigned int) a, (long long unsigned int) gf.divide.w64(&gf, c, a)); printf("%llx / %llx = %llx\n", (long long unsigned int) c, (long long unsigned int) b, (long long unsigned int) gf.divide.w64(&gf, c, b)); `````` ```55 56 57 58 59 60 61 62 63 64``` `````` r1 = (uint64_t *) malloc(32); r2 = (uint64_t *) malloc(32); r1 = b; for (i = 1; i < 4; i++) r1[i] = MOA_Random_64(); gf.multiply_region.w64(&gf, r1, r2, a, 32, 0); `````` `65` `````` printf("\nmultiply_region by %llx\n\n", (long long unsigned int) a); `````` `66` `````` printf("R1 (the source): "); `````` `67` `````` for (i = 0; i < 4; i++) printf(" %016llx", (long long unsigned int) r1[i]); `````` ```68 69``` `````` printf("\nR2 (the product): "); `````` `70` `````` for (i = 0; i < 4; i++) printf(" %016llx", (long long unsigned int) r2[i]); `````` ```71 72 73 74``` `````` printf("\n"); exit(0); } ``````