summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gf.c4
-rw-r--r--src/gf_w128.c9
-rw-r--r--src/gf_w16.c5
-rw-r--r--src/gf_w32.c18
-rw-r--r--src/gf_w64.c23
-rw-r--r--src/gf_wgen.c36
-rwxr-xr-xtest-driver127
9 files changed, 45 insertions, 180 deletions
diff --git a/.gitignore b/.gitignore
index 6dfcd89..c455d23 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,6 +51,7 @@ ltmain.sh
m4/libtool.m4
m4/ltversion.m4
src/.dirstamp
+test-driver
examples/gf_example_1
examples/gf_example_2
diff --git a/src/Makefile.am b/src/Makefile.am
index 240c1fe..a3bd37a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@
AUTOMAKE_OPTIONS = subdir-objects
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = -O3 $(SIMD_FLAGS) -fPIC
+AM_CFLAGS = -O3 $(SIMD_FLAGS) -fPIC -Wsign-compare
lib_LTLIBRARIES = libgf_complete.la
libgf_complete_la_SOURCES = gf.c gf_method.c gf_wgen.c gf_w4.c gf_w8.c gf_w16.c gf_w32.c \
diff --git a/src/gf.c b/src/gf.c
index 01a385b..835fb12 100644
--- a/src/gf.c
+++ b/src/gf.c
@@ -119,7 +119,7 @@ void gf_error()
uint64_t gf_composite_get_default_poly(gf_t *base)
{
gf_internal_t *h;
- int rv;
+ uint64_t rv;
h = (gf_internal_t *) base->scratch;
if (h->w == 4) {
@@ -584,7 +584,7 @@ uint32_t gf_bitmatrix_inverse(uint32_t y, int w, uint32_t pp)
uint32_t mat[32], inv[32], mask;
int i;
- mask = (w == 32) ? 0xffffffff : (1 << w) - 1;
+ mask = (w == 32) ? 0xffffffff : ((uint32_t)1 << w) - 1;
for (i = 0; i < w; i++) {
mat[i] = y;
diff --git a/src/gf_w128.c b/src/gf_w128.c
index 190f6b0..b1e3d92 100644
--- a/src/gf_w128.c
+++ b/src/gf_w128.c
@@ -49,7 +49,7 @@ void
gf_w128_multiply_region_from_single(gf_t *gf, void *src, void *dest, gf_val_128_t val, int bytes,
int xor)
{
- int i;
+ uint32_t i;
gf_val_128_t s128;
gf_val_128_t d128;
uint64_t c128[2];
@@ -87,7 +87,7 @@ void
gf_w128_clm_multiply_region_from_single(gf_t *gf, void *src, void *dest, gf_val_128_t val, int bytes,
int xor)
{
- int i;
+ uint32_t i;
gf_val_128_t s128;
gf_val_128_t d128;
gf_region_data rd;
@@ -1724,7 +1724,6 @@ int gf_w128_scratch_size(int mult_type, int region_type, int divide_type, int ar
int gf_w128_init(gf_t *gf)
{
gf_internal_t *h;
- int no_default_flag = 0;
h = (gf_internal_t *) gf->scratch;
@@ -1737,10 +1736,6 @@ int gf_w128_init(gf_t *gf)
} else {
h->prim_poly = 0x87; /* Omitting the leftmost 1 as in w=32 */
}
- if (no_default_flag == 1) {
- fprintf(stderr,"Code contains no default irreducible polynomial for given base field\n");
- return 0;
- }
}
gf->multiply.w128 = NULL;
diff --git a/src/gf_w16.c b/src/gf_w16.c
index ce47849..4e026b2 100644
--- a/src/gf_w16.c
+++ b/src/gf_w16.c
@@ -1218,7 +1218,7 @@ int gf_w16_split_init(gf_t *gf)
struct gf_w16_split_8_8_data *d8;
int i, j, exp, issse3;
int isneon = 0;
- uint32_t p, basep;
+ uint32_t p, basep, tmp;
h = (gf_internal_t *) gf->scratch;
@@ -1253,7 +1253,8 @@ int gf_w16_split_init(gf_t *gf)
if (j&1) {
d8->tables[exp][i][j] = d8->tables[exp][i][j^1] ^ p;
} else {
- d8->tables[exp][i][j] = GF_MULTBY_TWO(d8->tables[exp][i][j>>1]);
+ tmp = d8->tables[exp][i][j>>1];
+ d8->tables[exp][i][j] = GF_MULTBY_TWO(tmp);
}
}
}
diff --git a/src/gf_w32.c b/src/gf_w32.c
index 2e187fd..854a6e4 100644
--- a/src/gf_w32.c
+++ b/src/gf_w32.c
@@ -50,7 +50,7 @@ void
gf_w32_multiply_region_from_single(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int
xor)
{
- int i;
+ uint32_t i;
uint32_t *s32;
uint32_t *d32;
@@ -75,7 +75,7 @@ void
gf_w32_clm_multiply_region_from_single_2(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor)
{
- int i;
+ uint32_t i;
uint32_t *s32;
uint32_t *d32;
@@ -125,7 +125,7 @@ void
gf_w32_clm_multiply_region_from_single_3(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor)
{
- int i;
+ uint32_t i;
uint32_t *s32;
uint32_t *d32;
@@ -178,7 +178,7 @@ static
void
gf_w32_clm_multiply_region_from_single_4(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor)
{
- int i;
+ uint32_t i;
uint32_t *s32;
uint32_t *d32;
@@ -389,7 +389,7 @@ void
gf_w32_cfmgk_multiply_region_from_single(gf_t *gf, void *src, void *dest, uint32_t val, int bytes, int xor)
{
- int i;
+ uint32_t i;
uint32_t *s32;
uint32_t *d32;
@@ -666,12 +666,12 @@ static
void
gf_w32_group_set_shift_tables(uint32_t *shift, uint32_t val, gf_internal_t *h)
{
- int i;
+ uint32_t i;
uint32_t j;
shift[0] = 0;
- for (i = 1; i < (1 << h->arg1); i <<= 1) {
+ for (i = 1; i < ((uint32_t)1 << h->arg1); i <<= 1) {
for (j = 0; j < i; j++) shift[i|j] = shift[j]^val;
if (val & GF_FIRST_BIT) {
val <<= 1;
@@ -2375,7 +2375,7 @@ int gf_w32_group_init(gf_t *gf)
uint32_t i, j, p, index;
struct gf_w32_group_data *gd;
gf_internal_t *h = (gf_internal_t *) gf->scratch;
- int g_r, g_s;
+ uint32_t g_r, g_s;
g_s = h->arg1;
g_r = h->arg2;
@@ -2393,7 +2393,7 @@ int gf_w32_group_init(gf_t *gf)
gd->tshift = ((gd->tshift-1)/g_r) * g_r;
gd->reduce[0] = 0;
- for (i = 0; i < (1 << g_r); i++) {
+ for (i = 0; i < ((uint32_t)1 << g_r); i++) {
p = 0;
index = 0;
for (j = 0; j < g_r; j++) {
diff --git a/src/gf_w64.c b/src/gf_w64.c
index 6e75f5e..eae31e6 100644
--- a/src/gf_w64.c
+++ b/src/gf_w64.c
@@ -35,7 +35,7 @@ void
gf_w64_multiply_region_from_single(gf_t *gf, void *src, void *dest, gf_val_64_t val, int bytes, int
xor)
{
- int i;
+ uint32_t i;
gf_val_64_t *s64;
gf_val_64_t *d64;
@@ -733,7 +733,7 @@ static
void
gf_w64_group_set_shift_tables(uint64_t *shift, uint64_t val, gf_internal_t *h)
{
- int i;
+ uint64_t i;
uint64_t j;
uint64_t one = 1;
int g_s;
@@ -741,7 +741,7 @@ gf_w64_group_set_shift_tables(uint64_t *shift, uint64_t val, gf_internal_t *h)
g_s = h->arg1;
shift[0] = 0;
- for (i = 1; i < (1 << g_s); i <<= 1) {
+ for (i = 1; i < ((uint64_t)1 << g_s); i <<= 1) {
for (j = 0; j < i; j++) shift[i|j] = shift[j]^val;
if (val & (one << 63)) {
val <<= 1;
@@ -767,7 +767,7 @@ gf_w64_group_multiply(gf_t *gf, gf_val_64_t a, gf_val_64_t b)
gd = (struct gf_w64_group_data *) h->private;
gf_w64_group_set_shift_tables(gd->shift, b, h);
- mask = ((1 << g_s) - 1);
+ mask = (((uint64_t)1 << g_s) - 1);
top = 0;
bot = gd->shift[a&mask];
a >>= g_s;
@@ -791,7 +791,7 @@ gf_w64_group_multiply(gf_t *gf, gf_val_64_t a, gf_val_64_t b)
lshift = ((lshift-1) / g_r) * g_r;
rshift = 64 - lshift;
- mask = (1 << g_r) - 1;
+ mask = ((uint64_t)1 << g_r) - 1;
while (lshift >= 0) {
tp = gd->reduce[(top >> lshift) & mask];
top ^= (tp >> rshift);
@@ -840,8 +840,8 @@ void gf_w64_group_multiply_region(gf_t *gf, void *src, void *dest, gf_val_64_t v
d64 = (uint64_t *) rd.d_start;
dtop = (uint64_t *) rd.d_top;
- smask = (1 << g_s) - 1;
- rmask = (1 << g_r) - 1;
+ smask = ((uint64_t)1 << g_s) - 1;
+ rmask = ((uint64_t)1 << g_r) - 1;
while (d64 < dtop) {
a64 = *s64;
@@ -984,7 +984,7 @@ int gf_w64_group_init(gf_t *gf)
uint64_t i, j, p, index;
struct gf_w64_group_data *gd;
gf_internal_t *h = (gf_internal_t *) gf->scratch;
- int g_r, g_s;
+ uint64_t g_r, g_s;
g_s = h->arg1;
g_r = h->arg2;
@@ -994,7 +994,7 @@ int gf_w64_group_init(gf_t *gf)
gd->reduce = gd->shift + (1 << g_s);
gd->reduce[0] = 0;
- for (i = 0; i < (1 << g_r); i++) {
+ for (i = 0; i < ((uint64_t)1 << g_r); i++) {
p = 0;
index = 0;
for (j = 0; j < g_r; j++) {
@@ -2153,7 +2153,6 @@ int gf_w64_scratch_size(int mult_type, int region_type, int divide_type, int arg
int gf_w64_init(gf_t *gf)
{
gf_internal_t *h;
- int no_default_flag = 0;
h = (gf_internal_t *) gf->scratch;
@@ -2168,10 +2167,6 @@ int gf_w64_init(gf_t *gf)
} else {
h->prim_poly = 0x1b;
}
- if (no_default_flag == 1) {
- fprintf(stderr,"Code contains no default irreducible polynomial for given base field\n");
- return 0;
- }
}
gf->multiply.w64 = NULL;
diff --git a/src/gf_wgen.c b/src/gf_wgen.c
index 06f7993..ebc50a5 100644
--- a/src/gf_wgen.c
+++ b/src/gf_wgen.c
@@ -166,10 +166,10 @@ gf_wgen_shift_multiply (gf_t *gf, uint32_t a32, uint32_t b32)
product = 0;
- for (i = 0; i < h->w; i++) {
+ for (i = 0; i < (uint64_t)h->w; i++) {
if (a & (one << i)) product ^= (b << i);
}
- for (i = h->w*2-1; i >= h->w; i--) {
+ for (i = h->w*2-1; i >= (uint64_t)h->w; i--) {
if (product & (one << i)) product ^= (pp << (i-h->w));
}
return product;
@@ -256,7 +256,7 @@ static
void
gf_wgen_group_set_shift_tables(uint32_t *shift, uint32_t val, gf_internal_t *h)
{
- int i;
+ uint32_t i;
uint32_t j;
int g_s;
@@ -268,7 +268,7 @@ gf_wgen_group_set_shift_tables(uint32_t *shift, uint32_t val, gf_internal_t *h)
shift[0] = 0;
- for (i = 1; i < (1 << g_s); i <<= 1) {
+ for (i = 1; i < ((uint32_t)1 << g_s); i <<= 1) {
for (j = 0; j < i; j++) shift[i|j] = shift[j]^val;
if (val & (1 << (h->w-1))) {
val <<= 1;
@@ -417,7 +417,7 @@ int gf_wgen_group_init(gf_t *gf)
uint32_t i, j, p, index;
struct gf_wgen_group_data *gd;
gf_internal_t *h = (gf_internal_t *) gf->scratch;
- int g_s, g_r;
+ uint32_t g_s, g_r;
if (h->mult_type == GF_MULT_DEFAULT) {
g_s = 2;
@@ -440,7 +440,7 @@ int gf_wgen_group_init(gf_t *gf)
gd->tshift = ((gd->tshift-1)/g_r) * g_r;
gd->reduce[0] = 0;
- for (i = 0; i < (1 << g_r); i++) {
+ for (i = 0; i < ((uint32_t)1 << g_r); i++) {
p = 0;
index = 0;
for (j = 0; j < g_r; j++) {
@@ -504,15 +504,15 @@ int gf_wgen_table_8_init(gf_t *gf)
std->mult = &(std->base);
std->div = std->mult + ((1<<h->w)*(1<<h->w));
- for (a = 0; a < (1 << w); a++) {
+ for (a = 0; a < ((uint32_t)1 << w); a++) {
std->mult[a] = 0;
std->mult[a<<w] = 0;
std->div[a] = 0;
std->div[a<<w] = 0;
}
- for (a = 1; a < (1 << w); a++) {
- for (b = 1; b < (1 << w); b++) {
+ for (a = 1; a < ((uint32_t)1 << w); a++) {
+ for (b = 1; b < ((uint32_t)1 << w); b++) {
p = gf_wgen_shift_multiply(gf, a, b);
std->mult[(a<<w)|b] = p;
std->div[(p<<w)|a] = b;
@@ -565,15 +565,15 @@ int gf_wgen_table_16_init(gf_t *gf)
std->mult = &(std->base);
std->div = std->mult + ((1<<h->w)*(1<<h->w));
- for (a = 0; a < (1 << w); a++) {
+ for (a = 0; a < ((uint32_t)1 << w); a++) {
std->mult[a] = 0;
std->mult[a<<w] = 0;
std->div[a] = 0;
std->div[a<<w] = 0;
}
- for (a = 1; a < (1 << w); a++) {
- for (b = 1; b < (1 << w); b++) {
+ for (a = 1; a < ((uint32_t)1 << w); a++) {
+ for (b = 1; b < ((uint32_t)1 << w); b++) {
p = gf_wgen_shift_multiply(gf, a, b);
std->mult[(a<<w)|b] = p;
std->div[(p<<w)|a] = b;
@@ -649,11 +649,11 @@ int gf_wgen_log_8_init(gf_t *gf)
std->anti = std->log + (1<<h->w);
std->danti = std->anti + (1<<h->w)-1;
- for (i = 0; i < (1 << w); i++)
+ for (i = 0; i < ((uint32_t)1 << w); i++)
std->log[i] = 0;
a = 1;
- for(i=0; i < (1<<w)-1; i++)
+ for(i=0; i < ((uint32_t)1<<w)-1; i++)
{
if (std->log[a] != 0) check = 1;
std->log[a] = i;
@@ -724,11 +724,11 @@ int gf_wgen_log_16_init(gf_t *gf)
std->anti = std->log + (1<<h->w);
std->danti = std->anti + (1<<h->w)-1;
- for (i = 0; i < (1 << w); i++)
+ for (i = 0; i < ((uint32_t)1 << w); i++)
std->log[i] = 0;
a = 1;
- for(i=0; i < (1<<w)-1; i++)
+ for(i=0; i < ((uint32_t)1<<w)-1; i++)
{
if (std->log[a] != 0) check = 1;
std->log[a] = i;
@@ -800,11 +800,11 @@ int gf_wgen_log_32_init(gf_t *gf)
std->anti = std->log + (1<<h->w);
std->danti = std->anti + (1<<h->w)-1;
- for (i = 0; i < (1 << w); i++)
+ for (i = 0; i < ((uint32_t)1 << w); i++)
std->log[i] = 0;
a = 1;
- for(i=0; i < (1<<w)-1; i++)
+ for(i=0; i < ((uint32_t)1<<w)-1; i++)
{
if (std->log[a] != 0) check = 1;
std->log[a] = i;
diff --git a/test-driver b/test-driver
deleted file mode 100755
index 32bf39e..0000000
--- a/test-driver
+++ /dev/null
@@ -1,127 +0,0 @@
-#! /bin/sh
-# test-driver - basic testsuite driver script.
-
-scriptversion=2012-06-27.10; # UTC
-
-# Copyright (C) 2011-2013 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# This file is maintained in Automake, please report
-# bugs to <bug-automake@gnu.org> or send patches to
-# <automake-patches@gnu.org>.
-
-# Make unconditional expansion of undefined variables an error. This
-# helps a lot in preventing typo-related bugs.
-set -u
-
-usage_error ()
-{
- echo "$0: $*" >&2
- print_usage >&2
- exit 2
-}
-
-print_usage ()
-{
- cat <<END
-Usage:
- test-driver --test-name=NAME --log-file=PATH --trs-file=PATH
- [--expect-failure={yes|no}] [--color-tests={yes|no}]
- [--enable-hard-errors={yes|no}] [--] TEST-SCRIPT
-The '--test-name', '--log-file' and '--trs-file' options are mandatory.
-END
-}
-
-# TODO: better error handling in option parsing (in particular, ensure
-# TODO: $log_file, $trs_file and $test_name are defined).
-test_name= # Used for reporting.
-log_file= # Where to save the output of the test script.
-trs_file= # Where to save the metadata of the test run.
-expect_failure=no
-color_tests=no
-enable_hard_errors=yes
-while test $# -gt 0; do
- case $1 in
- --help) print_usage; exit $?;;
- --version) echo "test-driver $scriptversion"; exit $?;;
- --test-name) test_name=$2; shift;;
- --log-file) log_file=$2; shift;;
- --trs-file) trs_file=$2; shift;;
- --color-tests) color_tests=$2; shift;;
- --expect-failure) expect_failure=$2; shift;;
- --enable-hard-errors) enable_hard_errors=$2; shift;;
- --) shift; break;;
- -*) usage_error "invalid option: '$1'";;
- esac
- shift
-done
-
-if test $color_tests = yes; then
- # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
- red='' # Red.
- grn='' # Green.
- lgn='' # Light green.
- blu='' # Blue.
- mgn='' # Magenta.
- std='' # No color.
-else
- red= grn= lgn= blu= mgn= std=
-fi
-
-do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
-trap "st=129; $do_exit" 1
-trap "st=130; $do_exit" 2
-trap "st=141; $do_exit" 13
-trap "st=143; $do_exit" 15
-
-# Test script is run here.
-"$@" >$log_file 2>&1
-estatus=$?
-if test $enable_hard_errors = no && test $estatus -eq 99; then
- estatus=1
-fi
-
-case $estatus:$expect_failure in
- 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
- 0:*) col=$grn res=PASS recheck=no gcopy=no;;
- 77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
- 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
- *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
- *:*) col=$red res=FAIL recheck=yes gcopy=yes;;
-esac
-
-# Report outcome to console.
-echo "${col}${res}${std}: $test_name"
-
-# Register the test result, and other relevant metadata.
-echo ":test-result: $res" > $trs_file
-echo ":global-test-result: $res" >> $trs_file
-echo ":recheck: $recheck" >> $trs_file
-echo ":copy-in-global-log: $gcopy" >> $trs_file
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End: