summaryrefslogtreecommitdiff
path: root/src/libsodium/crypto_stream/salsa2012
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsodium/crypto_stream/salsa2012')
-rw-r--r--src/libsodium/crypto_stream/salsa2012/checksum1
-rw-r--r--src/libsodium/crypto_stream/salsa2012/ref/api.h10
-rw-r--r--src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c51
-rw-r--r--src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c54
-rw-r--r--src/libsodium/crypto_stream/salsa2012/stream_salsa2012_api.c11
5 files changed, 127 insertions, 0 deletions
diff --git a/src/libsodium/crypto_stream/salsa2012/checksum b/src/libsodium/crypto_stream/salsa2012/checksum
new file mode 100644
index 0000000..f801d9e
--- /dev/null
+++ b/src/libsodium/crypto_stream/salsa2012/checksum
@@ -0,0 +1 @@
+ecc758f200061c3cc770b25797da73583548d4f90f69a967fbbe1a6d94d1705c
diff --git a/src/libsodium/crypto_stream/salsa2012/ref/api.h b/src/libsodium/crypto_stream/salsa2012/ref/api.h
new file mode 100644
index 0000000..0efe8b8
--- /dev/null
+++ b/src/libsodium/crypto_stream/salsa2012/ref/api.h
@@ -0,0 +1,10 @@
+
+#include "crypto_stream_salsa2012.h"
+
+#define crypto_stream crypto_stream_salsa2012
+#define crypto_stream_xor crypto_stream_salsa2012_xor
+#define crypto_stream_KEYBYTES crypto_stream_salsa2012_KEYBYTES
+#define crypto_stream_NONCEBYTES crypto_stream_salsa2012_NONCEBYTES
+#define crypto_stream_IMPLEMENTATION crypto_stream_salsa2012_IMPLEMENTATION
+#define crypto_stream_VERSION crypto_stream_salsa2012_VERSION
+
diff --git a/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c b/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c
new file mode 100644
index 0000000..793adaa
--- /dev/null
+++ b/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c
@@ -0,0 +1,51 @@
+/*
+version 20080913
+D. J. Bernstein
+Public domain.
+*/
+
+#include "api.h"
+#include "crypto_core_salsa2012.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_salsa2012(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_salsa2012(block,in,k,sigma);
+ for (i = 0;i < clen;++i) c[i] = block[i];
+ }
+ return 0;
+}
diff --git a/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c b/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c
new file mode 100644
index 0000000..5970ca4
--- /dev/null
+++ b/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c
@@ -0,0 +1,54 @@
+/*
+version 20080913
+D. J. Bernstein
+Public domain.
+*/
+
+#include "api.h"
+#include "crypto_core_salsa2012.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_salsa2012(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_salsa2012(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/salsa2012/stream_salsa2012_api.c b/src/libsodium/crypto_stream/salsa2012/stream_salsa2012_api.c
new file mode 100644
index 0000000..3b5685f
--- /dev/null
+++ b/src/libsodium/crypto_stream/salsa2012/stream_salsa2012_api.c
@@ -0,0 +1,11 @@
+#include "crypto_stream_salsa2012.h"
+
+size_t
+crypto_stream_salsa2012_keybytes(void) {
+ return crypto_stream_salsa2012_KEYBYTES;
+}
+
+size_t
+crypto_stream_salsa2012_noncebytes(void) {
+ return crypto_stream_salsa2012_NONCEBYTES;
+}