From 2e59f9740a29439df7c7a56cf0ae83dec3081d31 Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Mon, 11 Aug 2014 13:49:21 -0400 Subject: initial import of debian version from mentors --- src/libsodium/crypto_stream/salsa208/checksum | 1 + src/libsodium/crypto_stream/salsa208/ref/api.h | 9 ++++ .../crypto_stream/salsa208/ref/stream_salsa208.c | 51 ++++++++++++++++++++ .../crypto_stream/salsa208/ref/xor_salsa208.c | 54 ++++++++++++++++++++++ .../crypto_stream/salsa208/stream_salsa208_api.c | 11 +++++ 5 files changed, 126 insertions(+) create mode 100644 src/libsodium/crypto_stream/salsa208/checksum create mode 100644 src/libsodium/crypto_stream/salsa208/ref/api.h create mode 100644 src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c create mode 100644 src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c create mode 100644 src/libsodium/crypto_stream/salsa208/stream_salsa208_api.c (limited to 'src/libsodium/crypto_stream/salsa208') diff --git a/src/libsodium/crypto_stream/salsa208/checksum b/src/libsodium/crypto_stream/salsa208/checksum new file mode 100644 index 0000000..c87364e --- /dev/null +++ b/src/libsodium/crypto_stream/salsa208/checksum @@ -0,0 +1 @@ +05f32b0647417aaa446b0b3127318133cf9af32b771869eab267000bf02710cd diff --git a/src/libsodium/crypto_stream/salsa208/ref/api.h b/src/libsodium/crypto_stream/salsa208/ref/api.h new file mode 100644 index 0000000..14b4a77 --- /dev/null +++ b/src/libsodium/crypto_stream/salsa208/ref/api.h @@ -0,0 +1,9 @@ + +#include "crypto_stream_salsa208.h" + +#define crypto_stream crypto_stream_salsa208 +#define crypto_stream_xor crypto_stream_salsa208_xor +#define crypto_stream_KEYBYTES crypto_stream_salsa208_KEYBYTES +#define crypto_stream_NONCEBYTES crypto_stream_salsa208_NONCEBYTES +#define crypto_stream_IMPLEMENTATION crypto_stream_salsa208_IMPLEMENTATION +#define crypto_stream_VERSION crypto_stream_salsa208_VERSION diff --git a/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c b/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c new file mode 100644 index 0000000..0889002 --- /dev/null +++ b/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c @@ -0,0 +1,51 @@ +/* +version 20080913 +D. J. Bernstein +Public domain. +*/ + +#include "api.h" +#include "crypto_core_salsa208.h" + +typedef unsigned int uint32; + +static const unsigned char sigma[16] = { + 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k' +}; + +int crypto_stream( + unsigned char *c,unsigned long long clen, + const unsigned char *n, + const unsigned char *k +) +{ + unsigned char in[16]; + unsigned char block[64]; + unsigned long long i; + unsigned int u; + + if (!clen) return 0; + + for (i = 0;i < 8;++i) in[i] = n[i]; + for (i = 8;i < 16;++i) in[i] = 0; + + while (clen >= 64) { + crypto_core_salsa208(c,in,k,sigma); + + u = 1; + for (i = 8;i < 16;++i) { + u += (unsigned int) in[i]; + in[i] = u; + u >>= 8; + } + + clen -= 64; + c += 64; + } + + if (clen) { + crypto_core_salsa208(block,in,k,sigma); + for (i = 0;i < clen;++i) c[i] = block[i]; + } + return 0; +} diff --git a/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c b/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c new file mode 100644 index 0000000..9f6dac5 --- /dev/null +++ b/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c @@ -0,0 +1,54 @@ +/* +version 20080913 +D. J. Bernstein +Public domain. +*/ + +#include "api.h" +#include "crypto_core_salsa208.h" + +typedef unsigned int uint32; + +static const unsigned char sigma[16] = { + 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k' +}; + +int crypto_stream_xor( + unsigned char *c, + const unsigned char *m,unsigned long long mlen, + const unsigned char *n, + const unsigned char *k +) +{ + unsigned char in[16]; + unsigned char block[64]; + unsigned long long i; + unsigned int u; + + if (!mlen) return 0; + + for (i = 0;i < 8;++i) in[i] = n[i]; + for (i = 8;i < 16;++i) in[i] = 0; + + while (mlen >= 64) { + crypto_core_salsa208(block,in,k,sigma); + for (i = 0;i < 64;++i) c[i] = m[i] ^ block[i]; + + u = 1; + for (i = 8;i < 16;++i) { + u += (unsigned int) in[i]; + in[i] = u; + u >>= 8; + } + + mlen -= 64; + c += 64; + m += 64; + } + + if (mlen) { + crypto_core_salsa208(block,in,k,sigma); + for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i]; + } + return 0; +} diff --git a/src/libsodium/crypto_stream/salsa208/stream_salsa208_api.c b/src/libsodium/crypto_stream/salsa208/stream_salsa208_api.c new file mode 100644 index 0000000..640a8b2 --- /dev/null +++ b/src/libsodium/crypto_stream/salsa208/stream_salsa208_api.c @@ -0,0 +1,11 @@ +#include "crypto_stream_salsa208.h" + +size_t +crypto_stream_salsa208_keybytes(void) { + return crypto_stream_salsa208_KEYBYTES; +} + +size_t +crypto_stream_salsa208_noncebytes(void) { + return crypto_stream_salsa208_NONCEBYTES; +} -- cgit v1.2.3