aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/chacha.c
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-12-07 13:27:11 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-12-25 19:28:03 +0000
commit1e5491e942d0a372ebebe9ef3d40941fc4a4fbb6 (patch)
treed13f404893c3994db28935da90947fbea1fc7cd5 /src/crypto/chacha.c
parentMerge pull request #2936 (diff)
downloadmonero-1e5491e942d0a372ebebe9ef3d40941fc4a4fbb6.tar.xz
Add a chacha20 variant to go with chacha8
Diffstat (limited to '')
-rw-r--r--src/crypto/chacha.c (renamed from src/crypto/chacha8.c)16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/crypto/chacha8.c b/src/crypto/chacha.c
index df135af59..f573083be 100644
--- a/src/crypto/chacha8.c
+++ b/src/crypto/chacha.c
@@ -8,7 +8,7 @@ Public domain.
#include <stdio.h>
#include <sys/param.h>
-#include "chacha8.h"
+#include "chacha.h"
#include "common/int-util.h"
#include "warnings.h"
@@ -40,7 +40,7 @@ static const char sigma[] = "expand 32-byte k";
DISABLE_GCC_AND_CLANG_WARNING(strict-aliasing)
-void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) {
+static void chacha(unsigned rounds, const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) {
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
char* ctarget = 0;
@@ -89,7 +89,7 @@ void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t*
x13 = j13;
x14 = j14;
x15 = j15;
- for (i = 8;i > 0;i -= 2) {
+ for (i = rounds;i > 0;i -= 2) {
QUARTERROUND( x0, x4, x8,x12)
QUARTERROUND( x1, x5, x9,x13)
QUARTERROUND( x2, x6,x10,x14)
@@ -168,3 +168,13 @@ void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t*
data = (uint8_t*)data + 64;
}
}
+
+void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher)
+{
+ chacha(8, data, length, key, iv, cipher);
+}
+
+void chacha20(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher)
+{
+ chacha(20, data, length, key, iv, cipher);
+}