diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2016-10-20 16:18:38 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2016-10-20 16:18:38 +0200 |
commit | 25663e04c3ab01ef8dc9f906608282319cfea2db (patch) | |
tree | a0ca5e70f66d74dbe552c996a4f3a285cdfc35e4 /src/libstrongswan/plugins/chapoly | |
parent | bf372706c469764d59e9f29c39e3ecbebd72b8d2 (diff) | |
download | vyos-strongswan-25663e04c3ab01ef8dc9f906608282319cfea2db.tar.gz vyos-strongswan-25663e04c3ab01ef8dc9f906608282319cfea2db.zip |
New upstream version 5.5.1
Diffstat (limited to 'src/libstrongswan/plugins/chapoly')
-rw-r--r-- | src/libstrongswan/plugins/chapoly/Makefile.am | 3 | ||||
-rw-r--r-- | src/libstrongswan/plugins/chapoly/Makefile.in | 11 | ||||
-rw-r--r-- | src/libstrongswan/plugins/chapoly/chapoly_plugin.c | 3 | ||||
-rw-r--r-- | src/libstrongswan/plugins/chapoly/chapoly_xof.c | 173 | ||||
-rw-r--r-- | src/libstrongswan/plugins/chapoly/chapoly_xof.h | 49 |
5 files changed, 233 insertions, 6 deletions
diff --git a/src/libstrongswan/plugins/chapoly/Makefile.am b/src/libstrongswan/plugins/chapoly/Makefile.am index 1753de0c7..d6d577c86 100644 --- a/src/libstrongswan/plugins/chapoly/Makefile.am +++ b/src/libstrongswan/plugins/chapoly/Makefile.am @@ -15,7 +15,8 @@ libstrongswan_chapoly_la_SOURCES = \ chapoly_plugin.h chapoly_plugin.c \ chapoly_drv.h chapoly_drv.c \ chapoly_drv_portable.h chapoly_drv_portable.c \ - chapoly_aead.h chapoly_aead.c + chapoly_aead.h chapoly_aead.c \ + chapoly_xof.h chapoly_xof.c noinst_LTLIBRARIES += libchapoly-drv-ssse3.la libchapoly_drv_ssse3_la_SOURCES = chapoly_drv_ssse3.h chapoly_drv_ssse3.c diff --git a/src/libstrongswan/plugins/chapoly/Makefile.in b/src/libstrongswan/plugins/chapoly/Makefile.in index d5b77a990..c0de9d83d 100644 --- a/src/libstrongswan/plugins/chapoly/Makefile.in +++ b/src/libstrongswan/plugins/chapoly/Makefile.in @@ -152,7 +152,7 @@ libchapoly_drv_ssse3_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(LDFLAGS) -o $@ libstrongswan_chapoly_la_DEPENDENCIES = libchapoly-drv-ssse3.la am_libstrongswan_chapoly_la_OBJECTS = chapoly_plugin.lo chapoly_drv.lo \ - chapoly_drv_portable.lo chapoly_aead.lo + chapoly_drv_portable.lo chapoly_aead.lo chapoly_xof.lo libstrongswan_chapoly_la_OBJECTS = \ $(am_libstrongswan_chapoly_la_OBJECTS) libstrongswan_chapoly_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ @@ -365,7 +365,6 @@ clearsilver_LIBS = @clearsilver_LIBS@ cmd_plugins = @cmd_plugins@ datadir = @datadir@ datarootdir = @datarootdir@ -dbusservicedir = @dbusservicedir@ dev_headers = @dev_headers@ docdir = @docdir@ dvidir = @dvidir@ @@ -399,8 +398,6 @@ libiptc_LIBS = @libiptc_LIBS@ linux_headers = @linux_headers@ localedir = @localedir@ localstatedir = @localstatedir@ -maemo_CFLAGS = @maemo_CFLAGS@ -maemo_LIBS = @maemo_LIBS@ manager_plugins = @manager_plugins@ mandir = @mandir@ medsrv_plugins = @medsrv_plugins@ @@ -454,6 +451,8 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +tss2_CFLAGS = @tss2_CFLAGS@ +tss2_LIBS = @tss2_LIBS@ urandom_device = @urandom_device@ xml_CFLAGS = @xml_CFLAGS@ xml_LIBS = @xml_LIBS@ @@ -469,7 +468,8 @@ libstrongswan_chapoly_la_SOURCES = \ chapoly_plugin.h chapoly_plugin.c \ chapoly_drv.h chapoly_drv.c \ chapoly_drv_portable.h chapoly_drv_portable.c \ - chapoly_aead.h chapoly_aead.c + chapoly_aead.h chapoly_aead.c \ + chapoly_xof.h chapoly_xof.c libchapoly_drv_ssse3_la_SOURCES = chapoly_drv_ssse3.h chapoly_drv_ssse3.c @USE_X86X64_TRUE@libchapoly_drv_ssse3_la_CFLAGS = $(PLUGIN_CFLAGS) -mssse3 @@ -573,6 +573,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chapoly_drv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chapoly_drv_portable.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chapoly_plugin.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chapoly_xof.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libchapoly_drv_ssse3_la-chapoly_drv_ssse3.Plo@am__quote@ .c.o: diff --git a/src/libstrongswan/plugins/chapoly/chapoly_plugin.c b/src/libstrongswan/plugins/chapoly/chapoly_plugin.c index 02e7121d6..447960bd0 100644 --- a/src/libstrongswan/plugins/chapoly/chapoly_plugin.c +++ b/src/libstrongswan/plugins/chapoly/chapoly_plugin.c @@ -15,6 +15,7 @@ #include "chapoly_plugin.h" #include "chapoly_aead.h" +#include "chapoly_xof.h" #include <library.h> @@ -43,6 +44,8 @@ METHOD(plugin_t, get_features, int, static plugin_feature_t f[] = { PLUGIN_REGISTER(AEAD, chapoly_aead_create), PLUGIN_PROVIDE(AEAD, ENCR_CHACHA20_POLY1305, 32), + PLUGIN_REGISTER(XOF, chapoly_xof_create), + PLUGIN_PROVIDE(XOF, XOF_CHACHA20), }; *features = f; return countof(f); diff --git a/src/libstrongswan/plugins/chapoly/chapoly_xof.c b/src/libstrongswan/plugins/chapoly/chapoly_xof.c new file mode 100644 index 000000000..2740a55b4 --- /dev/null +++ b/src/libstrongswan/plugins/chapoly/chapoly_xof.c @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2016 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +#include "chapoly_xof.h" +#include "chapoly_drv.h" + +typedef struct private_chapoly_xof_t private_chapoly_xof_t; + +/** + * Private data of an chapoly_xof_t object. + */ +struct private_chapoly_xof_t { + + /** + * Public chapoly_xof_t interface. + */ + chapoly_xof_t public; + + /** + * Latest block of the ChaCha20 stream. + */ + uint8_t stream[CHACHA_BLOCK_SIZE]; + + /** + * Index pointing to the current position in the stream + */ + u_int stream_index; + + /** + * Driver backend + */ + chapoly_drv_t *drv; +}; + +METHOD(xof_t, get_type, ext_out_function_t, + private_chapoly_xof_t *this) +{ + return XOF_CHACHA20; +} + +METHOD(xof_t, get_bytes, bool, + private_chapoly_xof_t *this, size_t out_len, uint8_t *buffer) +{ + size_t index = 0, len, blocks; + + /* empty the stream buffer first */ + len = min(out_len, CHACHA_BLOCK_SIZE - this->stream_index); + if (len) + { + memcpy(buffer, this->stream + this->stream_index, len); + index += len; + this->stream_index += len; + } + + /* copy whole stream blocks directly to output buffer */ + blocks = (out_len - index) / CHACHA_BLOCK_SIZE; + while (blocks--) + { + if (!this->drv->chacha(this->drv, buffer + index)) + { + return FALSE; + } + index += CHACHA_BLOCK_SIZE; + } + + /* refill the stream buffer if some more output bytes are needed */ + len = out_len - index; + if (len) + { + if (!this->drv->chacha(this->drv, this->stream)) + { + return FALSE; + } + memcpy(buffer + index, this->stream, len); + this->stream_index = len; + } + + return TRUE; +} + +METHOD(xof_t, allocate_bytes, bool, + private_chapoly_xof_t *this, size_t out_len, chunk_t *chunk) +{ + *chunk = chunk_alloc(out_len); + + if (!get_bytes(this, out_len, chunk->ptr)) + { + chunk_free(chunk); + return FALSE; + } + + return TRUE; +} + +METHOD(xof_t, get_block_size, size_t, + private_chapoly_xof_t *this) +{ + return CHACHA_BLOCK_SIZE; +} + +METHOD(xof_t, get_seed_size, size_t, + private_chapoly_xof_t *this) +{ + return CHACHA_KEY_SIZE + CHACHA_SALT_SIZE + CHACHA_IV_SIZE; +} + +METHOD(xof_t, set_seed, bool, + private_chapoly_xof_t *this, chunk_t seed) +{ + this->stream_index = CHACHA_BLOCK_SIZE; + + return seed.len == get_seed_size(this) && + this->drv->set_key(this->drv, "expand 32-byte k", + seed.ptr, seed.ptr + CHACHA_KEY_SIZE) && + this->drv->init(this->drv, + seed.ptr + CHACHA_KEY_SIZE + CHACHA_SALT_SIZE); +} + +METHOD(xof_t, destroy, void, + private_chapoly_xof_t *this) +{ + this->drv->destroy(this->drv); + free(this); +} + +/** + * See header + */ +chapoly_xof_t *chapoly_xof_create(ext_out_function_t algorithm) +{ + private_chapoly_xof_t *this; + chapoly_drv_t *drv; + + if (algorithm != XOF_CHACHA20) + { + return NULL; + } + + drv = chapoly_drv_probe(); + if (!drv) + { + return NULL; + } + + INIT(this, + .public = { + .xof_interface = { + .get_type = _get_type, + .get_bytes = _get_bytes, + .allocate_bytes = _allocate_bytes, + .get_block_size = _get_block_size, + .get_seed_size = _get_seed_size, + .set_seed = _set_seed, + .destroy = _destroy, + }, + }, + .drv = drv, + ); + + return &this->public; +} diff --git a/src/libstrongswan/plugins/chapoly/chapoly_xof.h b/src/libstrongswan/plugins/chapoly/chapoly_xof.h new file mode 100644 index 000000000..cd0586fad --- /dev/null +++ b/src/libstrongswan/plugins/chapoly/chapoly_xof.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * 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 of the License, or (at your + * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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. + */ + +/** + * @defgroup chapoly_xof chapoly_xof + * @{ @ingroup chapoly + */ + +#ifndef CHAPOLY_XOF_H_ +#define CHAPOLY_XOF_H_ + +#include <crypto/aead.h> + +typedef struct chapoly_xof_t chapoly_xof_t; + +/** + * ChaCha20 XOF implementation + * + * Based on RFC 7539 ChaCha20 stream initialized with block counter = 1 + */ +struct chapoly_xof_t { + + /** + * Generic xof_t interface for this Extended Output Function (XOF). + */ + xof_t xof_interface; +}; + +/** + * Create a chapoly_xof instance. + * + * @param algorithm XOF_CHACHA20 + * @return chapoly_xof_t object, NULL if not supported + */ +chapoly_xof_t *chapoly_xof_create(ext_out_function_t algorithm); + +#endif /** CHAPOLY_XOF_H_ @}*/ |