Commit 639c106d23ea155c3498aaade127b3583a94cc6c

Authored by KMG
1 parent e0d79287
Exists in master and in 4 other branches v1, v2, v3, wip-18092

Build failed... It was because the some headers were in the wrong place.

It was working for me because the headers were installed in /usr/local/include
on my Linux box.
include/gf_general.h 0 โ†’ 100644
... ... @@ -0,0 +1,61 @@
  1 +/*
  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.
  5 + *
  6 + * gf_general.h
  7 + *
  8 + * This file has helper routines for doing basic GF operations with any
  9 + * legal value of w. The problem is that w <= 32, w=64 and w=128 all have
  10 + * different data types, which is a pain. The procedures in this file try
  11 + * to alleviate that pain. They are used in gf_unit and gf_time.
  12 + */
  13 +
  14 +#pragma once
  15 +
  16 +#include <stdio.h>
  17 +#include <getopt.h>
  18 +#include <stdint.h>
  19 +#include <string.h>
  20 +#include <stdlib.h>
  21 +#include <time.h>
  22 +
  23 +#include "gf_complete.h"
  24 +
  25 +typedef union {
  26 + uint32_t w32;
  27 + uint64_t w64;
  28 + uint64_t w128[2];
  29 +} gf_general_t;
  30 +
  31 +void gf_general_set_zero(gf_general_t *v, int w);
  32 +void gf_general_set_one(gf_general_t *v, int w);
  33 +void gf_general_set_two(gf_general_t *v, int w);
  34 +
  35 +int gf_general_is_zero(gf_general_t *v, int w);
  36 +int gf_general_is_one(gf_general_t *v, int w);
  37 +int gf_general_are_equal(gf_general_t *v1, gf_general_t *v2, int w);
  38 +
  39 +void gf_general_val_to_s(gf_general_t *v, int w, char *s, int hex);
  40 +int gf_general_s_to_val(gf_general_t *v, int w, char *s, int hex);
  41 +
  42 +void gf_general_set_random(gf_general_t *v, int w, int zero_ok);
  43 +
  44 +void gf_general_add(gf_t *gf, gf_general_t *a, gf_general_t *b, gf_general_t *c);
  45 +void gf_general_multiply(gf_t *gf, gf_general_t *a, gf_general_t *b, gf_general_t *c);
  46 +void gf_general_divide(gf_t *gf, gf_general_t *a, gf_general_t *b, gf_general_t *c);
  47 +void gf_general_inverse(gf_t *gf, gf_general_t *a, gf_general_t *b);
  48 +
  49 +void gf_general_do_region_multiply(gf_t *gf, gf_general_t *a,
  50 + void *ra, void *rb,
  51 + int bytes, int xor);
  52 +
  53 +void gf_general_do_region_check(gf_t *gf, gf_general_t *a,
  54 + void *orig_a, void *orig_target, void *final_target,
  55 + int bytes, int xor);
  56 +
  57 +
  58 +/* Which is M, D or I for multiply, divide or inverse. */
  59 +
  60 +void gf_general_set_up_single_timing_test(int w, void *ra, void *rb, int size);
  61 +int gf_general_do_single_timing_test(gf_t *gf, void *ra, void *rb, int size, char which);
... ...
include/gf_int.h 0 โ†’ 100644
... ... @@ -0,0 +1,201 @@
  1 +/*
  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.
  5 + *
  6 + * gf_int.h
  7 + *
  8 + * Internal code for Galois field routines. This is not meant for
  9 + * users to include, but for the internal GF files to use.
  10 + */
  11 +
  12 +#pragma once
  13 +
  14 +#include "gf_complete.h"
  15 +
  16 +#include <string.h>
  17 +
  18 +extern void timer_start (double *t);
  19 +extern double timer_split (const double *t);
  20 +extern void galois_fill_random (void *buf, int len, unsigned int seed);
  21 +
  22 +typedef struct {
  23 + int mult_type;
  24 + int region_type;
  25 + int divide_type;
  26 + int w;
  27 + uint64_t prim_poly;
  28 + int free_me;
  29 + int arg1;
  30 + int arg2;
  31 + gf_t *base_gf;
  32 + void *private;
  33 +} gf_internal_t;
  34 +
  35 +extern int gf_w4_init (gf_t *gf);
  36 +extern int gf_w4_scratch_size(int mult_type, int region_type, int divide_type, int arg1, int arg2);
  37 +
  38 +extern int gf_w8_init (gf_t *gf);
  39 +extern int gf_w8_scratch_size(int mult_type, int region_type, int divide_type, int arg1, int arg2);
  40 +
  41 +extern int gf_w16_init (gf_t *gf);
  42 +extern int gf_w16_scratch_size(int mult_type, int region_type, int divide_type, int arg1, int arg2);
  43 +
  44 +extern int gf_w32_init (gf_t *gf);
  45 +extern int gf_w32_scratch_size(int mult_type, int region_type, int divide_type, int arg1, int arg2);
  46 +
  47 +extern int gf_w64_init (gf_t *gf);
  48 +extern int gf_w64_scratch_size(int mult_type, int region_type, int divide_type, int arg1, int arg2);
  49 +
  50 +extern int gf_w128_init (gf_t *gf);
  51 +extern int gf_w128_scratch_size(int mult_type, int region_type, int divide_type, int arg1, int arg2);
  52 +
  53 +extern int gf_wgen_init (gf_t *gf);
  54 +extern int gf_wgen_scratch_size(int w, int mult_type, int region_type, int divide_type, int arg1, int arg2);
  55 +
  56 +void gf_wgen_cauchy_region(gf_t *gf, void *src, void *dest, gf_val_32_t val, int bytes, int xor);
  57 +gf_val_32_t gf_wgen_extract_word(gf_t *gf, void *start, int bytes, int index);
  58 +
  59 +extern void gf_alignment_error(char *s, int a);
  60 +
  61 +extern uint32_t gf_bitmatrix_inverse(uint32_t y, int w, uint32_t pp);
  62 +
  63 +/* This returns the correct default for prim_poly when base is used as the base
  64 + field for COMPOSITE. It returns 0 if we don't have a default prim_poly. */
  65 +
  66 +extern uint64_t gf_composite_get_default_poly(gf_t *base);
  67 +
  68 +/* This structure lets you define a region multiply. It helps because you can handle
  69 + unaligned portions of the data with the procedures below, which really cleans
  70 + up the code. */
  71 +
  72 +typedef struct {
  73 + gf_t *gf;
  74 + void *src;
  75 + void *dest;
  76 + int bytes;
  77 + uint64_t val;
  78 + int xor;
  79 + int align; /* The number of bytes to which to align. */
  80 + void *s_start; /* The start and the top of the aligned region. */
  81 + void *d_start;
  82 + void *s_top;
  83 + void *d_top;
  84 +} gf_region_data;
  85 +
  86 +/* This lets you set up one of these in one call. It also sets the start/top pointers. */
  87 +
  88 +void gf_set_region_data(gf_region_data *rd,
  89 + gf_t *gf,
  90 + void *src,
  91 + void *dest,
  92 + int bytes,
  93 + uint64_t val,
  94 + int xor,
  95 + int align);
  96 +
  97 +/* This performs gf->multiply.32() on all of the unaligned bytes in the beginning of the region */
  98 +
  99 +extern void gf_do_initial_region_alignment(gf_region_data *rd);
  100 +
  101 +/* This performs gf->multiply.32() on all of the unaligned bytes in the end of the region */
  102 +
  103 +extern void gf_do_final_region_alignment(gf_region_data *rd);
  104 +
  105 +extern void gf_two_byte_region_table_multiply(gf_region_data *rd, uint16_t *base);
  106 +
  107 +extern void gf_multby_zero(void *dest, int bytes, int xor);
  108 +extern void gf_multby_one(void *src, void *dest, int bytes, int xor);
  109 +
  110 +typedef enum {GF_E_MDEFDIV, /* Dev != Default && Mult == Default */
  111 + GF_E_MDEFREG, /* Reg != Default && Mult == Default */
  112 + GF_E_MDEFARG, /* Args != Default && Mult == Default */
  113 + GF_E_DIVCOMP, /* Mult == Composite && Div != Default */
  114 + GF_E_CAUCOMP, /* Mult == Composite && Reg == CAUCHY */
  115 + GF_E_DOUQUAD, /* Reg == DOUBLE && Reg == QUAD */
  116 + GF_E_SSE__NO, /* Reg == SSE && Reg == NOSSE */
  117 + GF_E_CAUCHYB, /* Reg == CAUCHY && Other Reg */
  118 + GF_E_CAUGT32, /* Reg == CAUCHY && w > 32*/
  119 + GF_E_ARG1SET, /* Arg1 != 0 && Mult \notin COMPOSITE/SPLIT/GROUP */
  120 + GF_E_ARG2SET, /* Arg2 != 0 && Mult \notin SPLIT/GROUP */
  121 + GF_E_MATRIXW, /* Div == MATRIX && w > 32 */
  122 + GF_E_BAD___W, /* Illegal w */
  123 + GF_E_DOUBLET, /* Reg == DOUBLE && Mult != TABLE */
  124 + GF_E_DOUBLEW, /* Reg == DOUBLE && w \notin {4,8} */
  125 + GF_E_DOUBLEJ, /* Reg == DOUBLE && other Reg */
  126 + GF_E_DOUBLEL, /* Reg == DOUBLE & LAZY but w = 4 */
  127 + GF_E_QUAD__T, /* Reg == QUAD && Mult != TABLE */
  128 + GF_E_QUAD__W, /* Reg == QUAD && w != 4 */
  129 + GF_E_QUAD__J, /* Reg == QUAD && other Reg */
  130 + GF_E_LAZY__X, /* Reg == LAZY && not DOUBLE or QUAD*/
  131 + GF_E_ALTSHIF, /* Mult == Shift && Reg == ALTMAP */
  132 + GF_E_SSESHIF, /* Mult == Shift && Reg == SSE|NOSSE */
  133 + GF_E_ALT_CFM, /* Mult == CARRY_FREE && Reg == ALTMAP */
  134 + GF_E_SSE_CFM, /* Mult == CARRY_FREE && Reg == SSE|NOSSE */
  135 + GF_E_PCLMULX, /* Mult == Carry_Free && No PCLMUL */
  136 + GF_E_ALT_BY2, /* Mult == Bytwo_x && Reg == ALTMAP */
  137 + GF_E_BY2_SSE, /* Mult == Bytwo_x && Reg == SSE && No SSE2 */
  138 + GF_E_LOGBADW, /* Mult == LOGx, w too big*/
  139 + GF_E_LOG___J, /* Mult == LOGx, && Reg == SSE|ALTMAP|NOSSE */
  140 + GF_E_ZERBADW, /* Mult == LOG_ZERO, w \notin {8,16} */
  141 + GF_E_ZEXBADW, /* Mult == LOG_ZERO_EXT, w != 8 */
  142 + GF_E_LOGPOLY, /* Mult == LOG & poly not primitive */
  143 + GF_E_GR_ARGX, /* Mult == GROUP, Bad arg1/2 */
  144 + GF_E_GR_W_48, /* Mult == GROUP, w \in { 4, 8 } */
  145 + GF_E_GR_W_16, /* Mult == GROUP, w == 16, arg1 != 4 || arg2 != 4 */
  146 + GF_E_GR_128A, /* Mult == GROUP, w == 128, bad args */
  147 + GF_E_GR_SSE4, /* Mult == GROUP, w == 128, No SSE4 */
  148 + GF_E_GR_A_27, /* Mult == GROUP, either arg > 27 */
  149 + GF_E_GR_AR_W, /* Mult == GROUP, either arg > w */
  150 + GF_E_GR____J, /* Mult == GROUP, Reg == SSE|ALTMAP|NOSSE */
  151 + GF_E_TABLE_W, /* Mult == TABLE, w too big */
  152 + GF_E_TAB_SSE, /* Mult == TABLE, SSE|NOSSE only apply to w == 4 */
  153 + GF_E_TABSSE3, /* Mult == TABLE, Need SSSE3 for SSE */
  154 + GF_E_TAB_ALT, /* Mult == TABLE, Reg == ALTMAP */
  155 + GF_E_SP128AR, /* Mult == SPLIT, w=128, Bad arg1/arg2 */
  156 + GF_E_SP128AL, /* Mult == SPLIT, w=128, SSE requires ALTMAP */
  157 + GF_E_SP128AS, /* Mult == SPLIT, w=128, ALTMAP requires SSE */
  158 + GF_E_SP128_A, /* Mult == SPLIT, w=128, SSE only with 4/128 */
  159 + GF_E_SP128_S, /* Mult == SPLIT, w=128, ALTMAP only with 4/128 */
  160 + GF_E_SPLIT_W, /* Mult == SPLIT, Bad w (8, 16, 32, 64, 128) */
  161 + GF_E_SP_16AR, /* Mult == SPLIT, w=16, Bad arg1/arg2 */
  162 + GF_E_SP_16_A, /* Mult == SPLIT, w=16, ALTMAP only with 4/16 */
  163 + GF_E_SP_16_S, /* Mult == SPLIT, w=16, SSE only with 4/16 */
  164 + GF_E_SP_32AR, /* Mult == SPLIT, w=32, Bad arg1/arg2 */
  165 + GF_E_SP_32AS, /* Mult == SPLIT, w=32, ALTMAP requires SSE */
  166 + GF_E_SP_32_A, /* Mult == SPLIT, w=32, ALTMAP only with 4/32 */
  167 + GF_E_SP_32_S, /* Mult == SPLIT, w=32, SSE only with 4/32 */
  168 + GF_E_SP_64AR, /* Mult == SPLIT, w=64, Bad arg1/arg2 */
  169 + GF_E_SP_64AS, /* Mult == SPLIT, w=64, ALTMAP requires SSE */
  170 + GF_E_SP_64_A, /* Mult == SPLIT, w=64, ALTMAP only with 4/64 */
  171 + GF_E_SP_64_S, /* Mult == SPLIT, w=64, SSE only with 4/64 */
  172 + GF_E_SP_8_AR, /* Mult == SPLIT, w=8, Bad arg1/arg2 */
  173 + GF_E_SP_8__A, /* Mult == SPLIT, w=8, no ALTMAP */
  174 + GF_E_SP_SSE3, /* Mult == SPLIT, Need SSSE3 for SSE */
  175 + GF_E_COMP_A2, /* Mult == COMP, arg1 must be = 2 */
  176 + GF_E_COMP_SS, /* Mult == COMP, SSE|NOSSE */
  177 + GF_E_COMP__W, /* Mult == COMP, Bad w. */
  178 + GF_E_UNKFLAG, /* Unknown flag in create_from.... */
  179 + GF_E_UNKNOWN, /* Unknown mult_type. */
  180 + GF_E_UNK_REG, /* Unknown region_type. */
  181 + GF_E_UNK_DIV, /* Unknown divide_type. */
  182 + GF_E_CFM___W, /* Mult == CFM, Bad w. */
  183 + GF_E_CFM4POL, /* Mult == CFM & Prim Poly has high bits set. */
  184 + GF_E_CFM8POL, /* Mult == CFM & Prim Poly has high bits set. */
  185 + GF_E_CF16POL, /* Mult == CFM & Prim Poly has high bits set. */
  186 + GF_E_CF32POL, /* Mult == CFM & Prim Poly has high bits set. */
  187 + GF_E_CF64POL, /* Mult == CFM & Prim Poly has high bits set. */
  188 + GF_E_FEWARGS, /* Too few args in argc/argv. */
  189 + GF_E_BADPOLY, /* Bad primitive polynomial -- too many bits set. */
  190 + GF_E_COMP_PP, /* Bad primitive polynomial -- bigger than sub-field. */
  191 + GF_E_COMPXPP, /* Can't derive a default pp for composite field. */
  192 + GF_E_BASE__W, /* Composite -- Base field is the wrong size. */
  193 + GF_E_TWOMULT, /* In create_from... two -m's. */
  194 + GF_E_TWO_DIV, /* In create_from... two -d's. */
  195 + GF_E_POLYSPC, /* Bad numbera after -p. */
  196 + GF_E_SPLITAR, /* Ran out of arguments in SPLIT */
  197 + GF_E_SPLITNU, /* Arguments not integers in SPLIT. */
  198 + GF_E_GROUPAR, /* Ran out of arguments in GROUP */
  199 + GF_E_GROUPNU, /* Arguments not integers in GROUP. */
  200 + GF_E_DEFAULT } gf_error_type_t;
  201 +
... ...
include/gf_rand.h 0 โ†’ 100644
... ... @@ -0,0 +1,22 @@
  1 +/*
  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.
  5 + *
  6 + * gf_rand.h
  7 + *
  8 + * Random number generation, using the "Mother of All" random number generator. */
  9 +
  10 +#pragma once
  11 +#include <stdint.h>
  12 +#include <stdio.h>
  13 +#include <stdlib.h>
  14 +
  15 +/* These are all pretty self-explanatory */
  16 +uint32_t MOA_Random_32();
  17 +uint64_t MOA_Random_64();
  18 +void MOA_Random_128(uint64_t *x);
  19 +uint32_t MOA_Random_W(int w, int zero_ok);
  20 +void MOA_Fill_Random_Region (void *reg, int size); /* reg should be aligned to 4 bytes, but
  21 + size can be anything. */
  22 +void MOA_Seed(uint32_t seed);
... ...