aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-01-14 17:23:21 +0100
committerJakub Jelen <jjelen@redhat.com>2020-01-23 09:48:11 +0100
commit8670fb101bcb2600ae1dac4b9a8f2c3f04aba078 (patch)
treec284b85e69d67937af60eadb86c975ae0e65dd47 /src
parente31e7b0406f4c2b85831bf7ad90d57d660646108 (diff)
downloadlibssh-8670fb101bcb2600ae1dac4b9a8f2c3f04aba078.tar.gz
libssh-8670fb101bcb2600ae1dac4b9a8f2c3f04aba078.tar.xz
libssh-8670fb101bcb2600ae1dac4b9a8f2c3f04aba078.zip
chacha: Create common file to avoid code duplication
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/chachapoly.c10
-rw-r--r--src/libgcrypt.c16
2 files changed, 4 insertions, 22 deletions
diff --git a/src/chachapoly.c b/src/chachapoly.c
index 820e7f6e..c90a1e97 100644
--- a/src/chachapoly.c
+++ b/src/chachapoly.c
@@ -26,9 +26,8 @@
#include "libssh/chacha.h"
#include "libssh/poly1305.h"
#include "libssh/misc.h"
+#include "libssh/chacha20-poly1305-common.h"
-/* size of the keys k1 and k2 as defined in specs */
-#define CHACHA20_KEYLEN 32
struct chacha20_poly1305_keysched {
/* key used for encrypting the length field*/
struct chacha_ctx k1;
@@ -36,13 +35,6 @@ struct chacha20_poly1305_keysched {
struct chacha_ctx k2;
};
-#pragma pack(push, 1)
-struct ssh_packet_header {
- uint32_t length;
- uint8_t payload[];
-};
-#pragma pack(pop)
-
static const uint8_t zero_block_counter[8] = {0, 0, 0, 0, 0, 0, 0, 0};
static const uint8_t payload_block_counter[8] = {1, 0, 0, 0, 0, 0, 0, 0};
diff --git a/src/libgcrypt.c b/src/libgcrypt.c
index 53de4653..85d47c3f 100644
--- a/src/libgcrypt.c
+++ b/src/libgcrypt.c
@@ -33,18 +33,15 @@
#include "libssh/wrapper.h"
#include "libssh/string.h"
#include "libssh/misc.h"
+#ifdef HAVE_GCRYPT_CHACHA_POLY
+#include "libssh/chacha20-poly1305-common.h"
+#endif
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#ifdef HAVE_GCRYPT_CHACHA_POLY
-#define CHACHA20_BLOCKSIZE 64
-#define CHACHA20_KEYLEN 32
-
-#define POLY1305_TAGLEN 16
-#define POLY1305_KEYLEN 32
-
struct chacha20_poly1305_keysched {
bool initialized;
/* cipher handle used for encrypting the packets */
@@ -55,13 +52,6 @@ struct chacha20_poly1305_keysched {
gcry_mac_hd_t mac_hd;
};
-#pragma pack(push, 1)
-struct ssh_packet_header {
- uint32_t length;
- uint8_t payload[];
-};
-#pragma pack(pop)
-
static const uint8_t zero_block[CHACHA20_BLOCKSIZE] = {0};
#endif /* HAVE_GCRYPT_CHACHA_POLY */