Merge branch 'dev' into amndmntAes

This commit is contained in:
Logan oos Even
2020-08-31 02:36:01 +05:45
committed by GitHub
13 changed files with 227 additions and 235 deletions
-7
View File
@@ -83,14 +83,12 @@
#define N2N_CAN_NAME_IFACE 1
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <net/if_arp.h>
#include <net/if.h>
#include <linux/if_tun.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#define GRND_NONBLOCK 1
#endif /* #ifdef __linux__ */
#ifdef __FreeBSD__
@@ -100,10 +98,6 @@
#include <syslog.h>
#include <sys/wait.h>
#if defined (__RDRND__) || defined (__RDSEED__)
#include <immintrin.h>
#endif
#define ETH_ADDR_LEN 6
struct ether_hdr
@@ -135,7 +129,6 @@ typedef struct ether_hdr ether_hdr_t;
#include <openssl/crypto.h>
#endif
#define closesocket(a) close(a)
#endif /* #ifndef WIN32 */
-3
View File
@@ -51,9 +51,6 @@
#define TIME_STAMP_JITTER 0x0000000027100000LL /* we allow a packet to arrive 160 ms (== 0x27100 us) before another
* set to 0x0000000000000000LL if increasing (or equal) time stamps allowed only */
/* parameter for random number generation */
#define RND_RETRIES 1000 /* syscall and inquiring random number from hardware generators might fail, so we will retry */
/* N2N compression indicators. */
/* Compression is disabled by default for outgoing packets if no cli
* option is given. All edges are built with decompression support so
+38 -8
View File
@@ -16,19 +16,46 @@
*
*/
/* The WIN32 code is still untested and thus commented
#ifndef RND_H
#define RND_H
#include <stdint.h>
#include <stddef.h>
#include <time.h> // time, clock
#include "n2n.h" // traceEvent
// syscall and inquiring random number from hardware generators might fail, so we will retry
#define RND_RETRIES 1000
#if defined (__linux__)
#include <sys/syscall.h> // syscall, SYS_getrandom
#ifdef SYS_getrandom
#define GRND_NONBLOCK 1
#include <errno.h> // errno, EAGAIN
#endif
#endif
#if defined (__RDRND__) || defined (__RDSEED__)
#include <immintrin.h> // _rdrand64_step, rdseed4_step
#endif
/* The WIN32 code is still untested and thus commented, also see random_numbers.c
#if defined (WIN32)
#include <Wincrypt.h>
#endif
#include <Wincrypt.h> // HCTYPTPROV, Crypt*-functions
#endif
*/
struct rn_generator_state_t {
uint64_t a, b;
};
struct splitmix64_state_t {
typedef struct rn_generator_state_t {
uint64_t a, b;
} rn_generator_state_t;
typedef struct splitmix64_state_t {
uint64_t s;
};
} splitmix64_state_t;
int n2n_srand (uint64_t seed);
@@ -36,3 +63,6 @@ int n2n_srand (uint64_t seed);
uint64_t n2n_rand ();
uint64_t n2n_seed ();
#endif // RND_H
+35 -12
View File
@@ -1,3 +1,22 @@
/**
* (C) 2007-20 - ntop.org and contributors
*
* 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 3 of the License, 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 see <http://www.gnu.org/licenses/>
*
*/
// cipher SPECK -- 128 bit block size -- 256 bit key size
// taken from (and modified: removed pure crypto-stream generation and seperated key expansion)
// https://github.com/nsacyber/simon-speck-supercop/blob/master/crypto_stream/speck128256ctr/
@@ -7,13 +26,20 @@
#define SPECK_H
#include <stdint.h>
#include <stdlib.h>
#include "portable_endian.h"
#define u32 uint32_t
#define u64 uint64_t
#define N2N_SPECK_IVEC_SIZE 16
#define SPECK_KEY_BYTES (256/8)
#if defined (__AVX2__)
#define SPECK_ALIGNED_CTX 32
#include <immintrin.h>
#define SPECK_ALIGNED_CTX 32
#define u256 __m256i
typedef struct {
u256 rk[34];
@@ -22,9 +48,9 @@ typedef struct {
#elif defined (__SSE4_2__)
#include <immintrin.h>
#define SPECK_ALIGNED_CTX 16
#define SPECK_CTX_BYVAL 1
#include <immintrin.h>
#define u128 __m128i
typedef struct {
u128 rk[34];
@@ -48,33 +74,30 @@ typedef struct {
#endif
// -----
int speck_ctr (unsigned char *out, const unsigned char *in, unsigned long long inlen,
const unsigned char *n,
#if defined (SPECK_CTX_BYVAL)
speck_context_t ctx);
#else
speck_context_t *ctx);
#endif
speck_context_t *ctx);
int speck_init (const unsigned char *k, speck_context_t **ctx);
int speck_expand_key (const unsigned char *k, speck_context_t *ctx);
int speck_deinit (speck_context_t *ctx);
// -----
int speck_he (unsigned char *out, const unsigned char *in, unsigned long long inlen,
const unsigned char *n, speck_context_t *ctx);
int speck_expand_key_he (const unsigned char *k, speck_context_t *ctx);
// -----
int speck_he_iv_encrypt (unsigned char *inout, speck_context_t *ctx);
int speck_he_iv_decrypt (unsigned char *inout, speck_context_t *ctx);
int speck_expand_key_he_iv (const unsigned char *k, speck_context_t *ctx);
#endif
#endif // SPECK_H
+3
View File
@@ -53,6 +53,7 @@ THE SOFTWARE.
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "portable_endian.h"
#define TF_BLOCK_SIZE 16
@@ -78,5 +79,7 @@ int tf_cbc_decrypt (unsigned char *out, const unsigned char *in, size_t in_len,
int tf_init (const unsigned char *key, size_t key_size, tf_context_t **ctx);
int tf_deinit (tf_context_t *ctx);
#endif // TF_H