added a sip hash function

This commit is contained in:
hyung-hwan 2020-07-03 06:36:43 +00:00
parent 5fdf4f780d
commit 74b93843f4
7 changed files with 393 additions and 8 deletions

View File

@ -46,3 +46,9 @@ mio_t04_SOURCES = t04.c
mio_t04_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) mio_t04_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
mio_t04_LDFLAGS = $(LDFLAGS_LIB_COMMON) mio_t04_LDFLAGS = $(LDFLAGS_LIB_COMMON)
mio_t04_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) mio_t04_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
bin_PROGRAMS += mio-t05
mio_t05_SOURCES = t05.c
mio_t05_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
mio_t05_LDFLAGS = $(LDFLAGS_LIB_COMMON)
mio_t05_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)

View File

@ -89,7 +89,7 @@ POST_UNINSTALL = :
build_triplet = @build@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
bin_PROGRAMS = mio-execd$(EXEEXT) mio-t01$(EXEEXT) mio-t02$(EXEEXT) \ bin_PROGRAMS = mio-execd$(EXEEXT) mio-t01$(EXEEXT) mio-t02$(EXEEXT) \
mio-t03$(EXEEXT) mio-t04$(EXEEXT) mio-t03$(EXEEXT) mio-t04$(EXEEXT) mio-t05$(EXEEXT)
subdir = bin subdir = bin
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
@ -148,6 +148,13 @@ mio_t04_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
mio_t04_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ mio_t04_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(mio_t04_LDFLAGS) $(LDFLAGS) -o $@ $(mio_t04_LDFLAGS) $(LDFLAGS) -o $@
am_mio_t05_OBJECTS = mio_t05-t05.$(OBJEXT)
mio_t05_OBJECTS = $(am_mio_t05_OBJECTS)
mio_t05_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
mio_t05_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(mio_t05_LDFLAGS) $(LDFLAGS) -o $@
AM_V_P = $(am__v_P_@AM_V@) AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false am__v_P_0 = false
@ -165,7 +172,8 @@ depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__maybe_remake_depfiles = depfiles am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/mio_execd-execd.Po \ am__depfiles_remade = ./$(DEPDIR)/mio_execd-execd.Po \
./$(DEPDIR)/mio_t01-t01.Po ./$(DEPDIR)/mio_t02-t02.Po \ ./$(DEPDIR)/mio_t01-t01.Po ./$(DEPDIR)/mio_t02-t02.Po \
./$(DEPDIR)/mio_t03-t03.Po ./$(DEPDIR)/mio_t04-t04.Po ./$(DEPDIR)/mio_t03-t03.Po ./$(DEPDIR)/mio_t04-t04.Po \
./$(DEPDIR)/mio_t05-t05.Po
am__mv = mv -f am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@ -186,9 +194,10 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 = am__v_CCLD_1 =
SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) $(mio_t02_SOURCES) \ SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) $(mio_t02_SOURCES) \
$(mio_t03_SOURCES) $(mio_t04_SOURCES) $(mio_t03_SOURCES) $(mio_t04_SOURCES) $(mio_t05_SOURCES)
DIST_SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) \ DIST_SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) \
$(mio_t02_SOURCES) $(mio_t03_SOURCES) $(mio_t04_SOURCES) $(mio_t02_SOURCES) $(mio_t03_SOURCES) $(mio_t04_SOURCES) \
$(mio_t05_SOURCES)
am__can_run_installinfo = \ am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \ case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \ n|no|NO) false;; \
@ -398,6 +407,10 @@ mio_t04_SOURCES = t04.c
mio_t04_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) mio_t04_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
mio_t04_LDFLAGS = $(LDFLAGS_LIB_COMMON) mio_t04_LDFLAGS = $(LDFLAGS_LIB_COMMON)
mio_t04_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS) mio_t04_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
mio_t05_SOURCES = t05.c
mio_t05_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
mio_t05_LDFLAGS = $(LDFLAGS_LIB_COMMON)
mio_t05_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:
@ -501,6 +514,10 @@ mio-t04$(EXEEXT): $(mio_t04_OBJECTS) $(mio_t04_DEPENDENCIES) $(EXTRA_mio_t04_DEP
@rm -f mio-t04$(EXEEXT) @rm -f mio-t04$(EXEEXT)
$(AM_V_CCLD)$(mio_t04_LINK) $(mio_t04_OBJECTS) $(mio_t04_LDADD) $(LIBS) $(AM_V_CCLD)$(mio_t04_LINK) $(mio_t04_OBJECTS) $(mio_t04_LDADD) $(LIBS)
mio-t05$(EXEEXT): $(mio_t05_OBJECTS) $(mio_t05_DEPENDENCIES) $(EXTRA_mio_t05_DEPENDENCIES)
@rm -f mio-t05$(EXEEXT)
$(AM_V_CCLD)$(mio_t05_LINK) $(mio_t05_OBJECTS) $(mio_t05_LDADD) $(LIBS)
mostlyclean-compile: mostlyclean-compile:
-rm -f *.$(OBJEXT) -rm -f *.$(OBJEXT)
@ -512,6 +529,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t02-t02.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t02-t02.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t03-t03.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t03-t03.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t04-t04.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t04-t04.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t05-t05.Po@am__quote@ # am--include-marker
$(am__depfiles_remade): $(am__depfiles_remade):
@$(MKDIR_P) $(@D) @$(MKDIR_P) $(@D)
@ -613,6 +631,20 @@ mio_t04-t04.obj: t04.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t04_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t04-t04.obj `if test -f 't04.c'; then $(CYGPATH_W) 't04.c'; else $(CYGPATH_W) '$(srcdir)/t04.c'; fi` @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t04_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t04-t04.obj `if test -f 't04.c'; then $(CYGPATH_W) 't04.c'; else $(CYGPATH_W) '$(srcdir)/t04.c'; fi`
mio_t05-t05.o: t05.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t05_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_t05-t05.o -MD -MP -MF $(DEPDIR)/mio_t05-t05.Tpo -c -o mio_t05-t05.o `test -f 't05.c' || echo '$(srcdir)/'`t05.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_t05-t05.Tpo $(DEPDIR)/mio_t05-t05.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t05.c' object='mio_t05-t05.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t05_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t05-t05.o `test -f 't05.c' || echo '$(srcdir)/'`t05.c
mio_t05-t05.obj: t05.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t05_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_t05-t05.obj -MD -MP -MF $(DEPDIR)/mio_t05-t05.Tpo -c -o mio_t05-t05.obj `if test -f 't05.c'; then $(CYGPATH_W) 't05.c'; else $(CYGPATH_W) '$(srcdir)/t05.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_t05-t05.Tpo $(DEPDIR)/mio_t05-t05.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t05.c' object='mio_t05-t05.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t05_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t05-t05.obj `if test -f 't05.c'; then $(CYGPATH_W) 't05.c'; else $(CYGPATH_W) '$(srcdir)/t05.c'; fi`
mostlyclean-libtool: mostlyclean-libtool:
-rm -f *.lo -rm -f *.lo
@ -751,6 +783,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/mio_t02-t02.Po -rm -f ./$(DEPDIR)/mio_t02-t02.Po
-rm -f ./$(DEPDIR)/mio_t03-t03.Po -rm -f ./$(DEPDIR)/mio_t03-t03.Po
-rm -f ./$(DEPDIR)/mio_t04-t04.Po -rm -f ./$(DEPDIR)/mio_t04-t04.Po
-rm -f ./$(DEPDIR)/mio_t05-t05.Po
-rm -f Makefile -rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \ distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags distclean-tags
@ -801,6 +834,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/mio_t02-t02.Po -rm -f ./$(DEPDIR)/mio_t02-t02.Po
-rm -f ./$(DEPDIR)/mio_t03-t03.Po -rm -f ./$(DEPDIR)/mio_t03-t03.Po
-rm -f ./$(DEPDIR)/mio_t04-t04.Po -rm -f ./$(DEPDIR)/mio_t04-t04.Po
-rm -f ./$(DEPDIR)/mio_t05-t05.Po
-rm -f Makefile -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic maintainer-clean-am: distclean-am maintainer-clean-generic

116
mio/bin/t05.c Normal file
View File

@ -0,0 +1,116 @@
#include <mio-utl.h>
#include <string.h>
#include <stdio.h>
/* https://131002.net/siphash/siphash24.c */
/*
SipHash-2-4 output with
k = 00 01 02 ...
and
in = (empty string)
in = 00 (1 byte)
in = 00 01 (2 bytes)
in = 00 01 02 (3 bytes)
...
in = 00 01 02 ... 3e (63 bytes)
*/
mio_uint8_t vectors[64][8] =
{
{ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
{ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
{ 0x5a, 0x4f, 0xa9, 0xd9, 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0x35, 0xf9, },
{ 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
{ 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
{ 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
{ 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
{ 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
{ 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
{ 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
{ 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
{ 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
{ 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
{ 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
{ 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
{ 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
{ 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
{ 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
{ 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
{ 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
{ 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
{ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, }
};
int test_vectors()
{
#define MAXLEN 64
mio_uint8_t in[MAXLEN], out[8], k[16];
int i;
int ok = 1;
for( i = 0; i < 16; ++i ) k[i] = i;
for( i = 0; i < MAXLEN; ++i )
{
in[i] = i;
mio_sip_hash_24(k, in, i, out);
if ( memcmp( out, vectors[i], 8 ) )
{
printf( "test vector failed for %d bytes\n", i );
ok = 0;
}
}
return ok;
}
int main()
{
if (test_vectors()) printf( "test vectors ok\n" );
return 0;
}

View File

@ -82,7 +82,8 @@ libmio_la_SOURCES = \
uch-prop.h \ uch-prop.h \
tmr.c \ tmr.c \
utf8.c \ utf8.c \
utl.c utl.c \
utl-siph.c
libmio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libmio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)

View File

@ -148,7 +148,7 @@ am__libmio_la_SOURCES_DIST = chr.c dns.c dns-cli.c ecs.c ecs-imp.h \
http-svr.c http-thr.c http-txt.c json.c mio-prv.h mio.c nwif.c \ http-svr.c http-thr.c http-txt.c json.c mio-prv.h mio.c nwif.c \
path.c pipe.c pro.c sck.c skad.c sys.c sys-ass.c sys-err.c \ path.c pipe.c pro.c sck.c skad.c sys.c sys-ass.c sys-err.c \
sys-log.c sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h \ sys-log.c sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h \
uch-prop.h tmr.c utf8.c utl.c mar.c mar-cli.c uch-prop.h tmr.c utf8.c utl.c utl-siph.c mar.c mar-cli.c
@ENABLE_MARIADB_TRUE@am__objects_1 = libmio_la-mar.lo \ @ENABLE_MARIADB_TRUE@am__objects_1 = libmio_la-mar.lo \
@ENABLE_MARIADB_TRUE@ libmio_la-mar-cli.lo @ENABLE_MARIADB_TRUE@ libmio_la-mar-cli.lo
am_libmio_la_OBJECTS = libmio_la-chr.lo libmio_la-dns.lo \ am_libmio_la_OBJECTS = libmio_la-chr.lo libmio_la-dns.lo \
@ -162,7 +162,7 @@ am_libmio_la_OBJECTS = libmio_la-chr.lo libmio_la-dns.lo \
libmio_la-sys.lo libmio_la-sys-ass.lo libmio_la-sys-err.lo \ libmio_la-sys.lo libmio_la-sys-ass.lo libmio_la-sys-err.lo \
libmio_la-sys-log.lo libmio_la-sys-mux.lo libmio_la-sys-tim.lo \ libmio_la-sys-log.lo libmio_la-sys-mux.lo libmio_la-sys-tim.lo \
libmio_la-thr.lo libmio_la-tmr.lo libmio_la-utf8.lo \ libmio_la-thr.lo libmio_la-tmr.lo libmio_la-utf8.lo \
libmio_la-utl.lo $(am__objects_1) libmio_la-utl.lo libmio_la-utl-siph.lo $(am__objects_1)
libmio_la_OBJECTS = $(am_libmio_la_OBJECTS) libmio_la_OBJECTS = $(am_libmio_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -209,6 +209,7 @@ am__depfiles_remade = ./$(DEPDIR)/libmio_la-chr.Plo \
./$(DEPDIR)/libmio_la-sys-tim.Plo \ ./$(DEPDIR)/libmio_la-sys-tim.Plo \
./$(DEPDIR)/libmio_la-sys.Plo ./$(DEPDIR)/libmio_la-thr.Plo \ ./$(DEPDIR)/libmio_la-sys.Plo ./$(DEPDIR)/libmio_la-thr.Plo \
./$(DEPDIR)/libmio_la-tmr.Plo ./$(DEPDIR)/libmio_la-utf8.Plo \ ./$(DEPDIR)/libmio_la-tmr.Plo ./$(DEPDIR)/libmio_la-utf8.Plo \
./$(DEPDIR)/libmio_la-utl-siph.Plo \
./$(DEPDIR)/libmio_la-utl.Plo ./$(DEPDIR)/libmio_la-utl.Plo
am__mv = mv -f am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@ -441,7 +442,7 @@ libmio_la_SOURCES = chr.c dns.c dns-cli.c ecs.c ecs-imp.h err.c fmt.c \
http-thr.c http-txt.c json.c mio-prv.h mio.c nwif.c path.c \ http-thr.c http-txt.c json.c mio-prv.h mio.c nwif.c path.c \
pipe.c pro.c sck.c skad.c sys.c sys-ass.c sys-err.c sys-log.c \ pipe.c pro.c sck.c skad.c sys.c sys-ass.c sys-err.c sys-log.c \
sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h \ sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h \
tmr.c utf8.c utl.c $(am__append_2) tmr.c utf8.c utl.c utl-siph.c $(am__append_2)
libmio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libmio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
libmio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_3) libmio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_3)
libmio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS) $(SOCKET_LIBS) \ libmio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS) $(SOCKET_LIBS) \
@ -573,6 +574,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-thr.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-thr.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-tmr.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-tmr.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-utf8.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-utf8.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-utl-siph.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-utl.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-utl.Plo@am__quote@ # am--include-marker
$(am__depfiles_remade): $(am__depfiles_remade):
@ -829,6 +831,13 @@ libmio_la-utl.lo: utl.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c
libmio_la-utl-siph.lo: utl-siph.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-utl-siph.lo -MD -MP -MF $(DEPDIR)/libmio_la-utl-siph.Tpo -c -o libmio_la-utl-siph.lo `test -f 'utl-siph.c' || echo '$(srcdir)/'`utl-siph.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-utl-siph.Tpo $(DEPDIR)/libmio_la-utl-siph.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utl-siph.c' object='libmio_la-utl-siph.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-utl-siph.lo `test -f 'utl-siph.c' || echo '$(srcdir)/'`utl-siph.c
libmio_la-mar.lo: mar.c libmio_la-mar.lo: mar.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-mar.lo -MD -MP -MF $(DEPDIR)/libmio_la-mar.Tpo -c -o libmio_la-mar.lo `test -f 'mar.c' || echo '$(srcdir)/'`mar.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-mar.lo -MD -MP -MF $(DEPDIR)/libmio_la-mar.Tpo -c -o libmio_la-mar.lo `test -f 'mar.c' || echo '$(srcdir)/'`mar.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-mar.Tpo $(DEPDIR)/libmio_la-mar.Plo @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-mar.Tpo $(DEPDIR)/libmio_la-mar.Plo
@ -1031,6 +1040,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libmio_la-thr.Plo -rm -f ./$(DEPDIR)/libmio_la-thr.Plo
-rm -f ./$(DEPDIR)/libmio_la-tmr.Plo -rm -f ./$(DEPDIR)/libmio_la-tmr.Plo
-rm -f ./$(DEPDIR)/libmio_la-utf8.Plo -rm -f ./$(DEPDIR)/libmio_la-utf8.Plo
-rm -f ./$(DEPDIR)/libmio_la-utl-siph.Plo
-rm -f ./$(DEPDIR)/libmio_la-utl.Plo -rm -f ./$(DEPDIR)/libmio_la-utl.Plo
-rm -f Makefile -rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \ distclean-am: clean-am distclean-compile distclean-generic \
@ -1111,6 +1121,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libmio_la-thr.Plo -rm -f ./$(DEPDIR)/libmio_la-thr.Plo
-rm -f ./$(DEPDIR)/libmio_la-tmr.Plo -rm -f ./$(DEPDIR)/libmio_la-tmr.Plo
-rm -f ./$(DEPDIR)/libmio_la-utf8.Plo -rm -f ./$(DEPDIR)/libmio_la-utf8.Plo
-rm -f ./$(DEPDIR)/libmio_la-utl-siph.Plo
-rm -f ./$(DEPDIR)/libmio_la-utl.Plo -rm -f ./$(DEPDIR)/libmio_la-utl.Plo
-rm -f Makefile -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic maintainer-clean-am: distclean-am maintainer-clean-generic

View File

@ -970,6 +970,16 @@ static MIO_INLINE mio_uint128_t mio_bswap128 (mio_uint128_t x)
#endif #endif
/* =========================================================================
* SIP-HASH-PRF
* ========================================================================= */
MIO_EXPORT void mio_sip_hash_24 (
const mio_uint8_t key[16],
mio_uint8_t* dptr,
mio_oow_t dlen,
mio_uint8_t out[8]
);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

207
mio/lib/utl-siph.c Normal file
View File

@ -0,0 +1,207 @@
#include <mio-utl.h>
/*
* This code is based on https://github.com/emboss/siphash-c/blob/master/src/siphash.c
*
* See https://131002.net/siphash/siphash24.c for a reference implementation by the inventor.
*/
#define U8TO32_LE(p) (((mio_uint32_t)((p)[0])) | ((mio_uint32_t)((p)[1]) << 8) | ((mio_uint32_t)((p)[2]) << 16) | ((mio_uint32_t)((p)[3]) << 24))
#define U32TO8_LE(p, v) do { \
(p)[0] = (mio_uint8_t)((v)); \
(p)[1] = (mio_uint8_t)((v) >> 8); \
(p)[2] = (mio_uint8_t)((v) >> 16); \
(p)[3] = (mio_uint8_t)((v) >> 24); \
} while (0)
#if (MIO_SIZEOF_UINT64_T > 0)
typedef mio_uint64_t sip_uint64_t;
#define U8TO64_LE(p) ((mio_uint64_t)U8TO32_LE(p) | ((mio_uint64_t)U8TO32_LE((p) + 4)) << 32 )
#define U64TO8_LE(p, v) do { \
U32TO8_LE((p), (mio_uint32_t)((v))); \
U32TO8_LE((p) + 4, (mio_uint32_t)((v) >> 32)); \
} while (0)
#define ROTATE_LEFT_64(v, s) ((v) << (s)) | ((v) >> (64 - (s)))
#define ROTATE_LEFT_64_TO(v, s) ((v) = ROTATE_LEFT_64((v), (s)))
#define ADD64_TO(v, s) ((v) += (s))
#define XOR64_TO(v, s) ((v) ^= (s))
#define XOR64_INT(v, x) ((v) ^= (x))
#else /* (MIO_SIZEOF_UINT64_T > 0) */
struct sip_uint64_t
{
mio_uint32_t _u32[2];
};
typedef struct sip_uint64_t sip_uint64_t;
#if defined(MIO_ENDIAN_LITTLE)
# define lo _u32[0]
# define hi _u32[1]
#elif defined(MIO_ENDIAN_BIG)
# define hi _u32[0]
# define lo _u32[1]
#else
# error UNKNOWN ENDIAN
#endif
#define U8TO64_LE(p) u8to64_le(p)
static MIO_INLINE sip_uint64_t u8to64_le (const mio_uint8_t* p)
{
sip_uint64_t ret;
ret.lo = U8TO32_LE(p);
ret.hi = U8TO32_LE(p + 4);
return ret;
}
#define U64TO8_LE(p, v) u64to8_le(p, v)
static MIO_INLINE void u64to8_le (mio_uint8_t* p, sip_uint64_t v)
{
U32TO8_LE (p, v.lo);
U32TO8_LE (p + 4, v.hi);
}
#define ROTATE_LEFT_64_TO(v, s) \
((s) > 32? rotl64_swap(rotl64_to(&(v), (s) - 32)) : \
(s) == 32? rotl64_swap(&(v)): rotl64_to(&(v), (s)))
static MIO_INLINE sip_uint64_t* rotl64_to (sip_uint64_t* v, unsigned int s)
{
mio_uint32_t uhi = (v->hi << s) | (v->lo >> (32 - s));
mio_uint32_t ulo = (v->lo << s) | (v->hi >> (32 - s));
v->hi = uhi;
v->lo = ulo;
return v;
}
static MIO_INLINE sip_uint64_t* rotl64_swap (sip_uint64_t *v)
{
mio_uint32_t t = v->lo;
v->lo = v->hi;
v->hi = t;
return v;
}
#define ADD64_TO(v, s) add64_to(&(v), (s))
static MIO_INLINE sip_uint64_t* add64_to (sip_uint64_t* v, sip_uint64_t s)
{
v->lo += s.lo;
v->hi += s.hi;
if (v->lo < s.lo) v->hi++;
return v;
}
#define XOR64_TO(v, s) xor64_to(&(v), (s))
static MIO_INLINE sip_uint64_t* xor64_to (sip_uint64_t* v, sip_uint64_t s)
{
v->lo ^= s.lo;
v->hi ^= s.hi;
return v;
}
#define XOR64_INT(v, x) ((v).lo ^= (x))
#endif /* (MIO_SIZEOF_UINT64_T > 0) */
static const char sip_init_state_bin[] = "uespemos""modnarod""arenegyl""setybdet";
#define sip_init_state (*(sip_uint64_t(*)[4])sip_init_state_bin)
#define SIP_COMPRESS(v0, v1, v2, v3) do {\
ADD64_TO((v0), (v1)); \
ADD64_TO((v2), (v3)); \
ROTATE_LEFT_64_TO((v1), 13); \
ROTATE_LEFT_64_TO((v3), 16); \
XOR64_TO((v1), (v0)); \
XOR64_TO((v3), (v2)); \
ROTATE_LEFT_64_TO((v0), 32); \
ADD64_TO((v2), (v1)); \
ADD64_TO((v0), (v3)); \
ROTATE_LEFT_64_TO((v1), 17); \
ROTATE_LEFT_64_TO((v3), 21); \
XOR64_TO((v1), (v2)); \
XOR64_TO((v3), (v0)); \
ROTATE_LEFT_64_TO((v2), 32); \
} while(0)
#define SIP_2_ROUND(m, v0, v1, v2, v3) do { \
XOR64_TO((v3), (m)); \
SIP_COMPRESS(v0, v1, v2, v3); \
SIP_COMPRESS(v0, v1, v2, v3); \
XOR64_TO((v0), (m)); \
} while (0)
void mio_sip_hash_24 (const mio_uint8_t key[16], mio_uint8_t *dptr, mio_oow_t dlen, mio_uint8_t out[8])
{
sip_uint64_t k0, k1;
sip_uint64_t v0, v1, v2, v3;
sip_uint64_t m, last;
mio_oow_t rem;
mio_uint8_t* end;
rem = dlen & 7; /* dlen % 8 */
end = dptr + dlen - rem;
k0 = U8TO64_LE(key);
k1 = U8TO64_LE(key + 8);
v0 = k0; XOR64_TO(v0, sip_init_state[0]);
v1 = k1; XOR64_TO(v1, sip_init_state[1]);
v2 = k0; XOR64_TO(v2, sip_init_state[2]);
v3 = k1; XOR64_TO(v3, sip_init_state[3]);
for (; dptr != end; dptr += 8)
{
m = U8TO64_LE(dptr);
SIP_2_ROUND(m, v0, v1, v2, v3);
}
#if (MIO_SIZEOF_UINT64_T > 0)
last = dlen << 56;
#define OR_BYTE(n) (last |= ((mio_uint64_t)end[n]) << ((n) * 8))
#else
last.hi = dlen << 24;
last.lo = 0;
#define OR_BYTE(n) do { \
if (n >= 4) last.hi |= ((mio_uint32_t)end[n]) << ((n) >= 4 ? (n) * 8 - 32 : 0); \
else last.lo |= ((mio_uint32_t)end[n]) << ((n) >= 4 ? 0 : (n) * 8); \
} while (0)
#endif
switch (rem)
{
case 7: OR_BYTE (6);
case 6: OR_BYTE (5);
case 5: OR_BYTE (4);
case 4: OR_BYTE(3);
case 3: OR_BYTE(2);
case 2: OR_BYTE(1);
case 1: OR_BYTE(0);
case 0: break;
}
SIP_2_ROUND(last, v0, v1, v2, v3);
XOR64_INT(v2, 0xff);
SIP_COMPRESS (v0, v1, v2, v3);
SIP_COMPRESS (v0, v1, v2, v3);
SIP_COMPRESS (v0, v1, v2, v3);
SIP_COMPRESS (v0, v1, v2, v3);
XOR64_TO (v0, v1);
XOR64_TO (v0, v2);
XOR64_TO (v0, v3);
U64TO8_LE (out, v0);
}