Ident, reuse COMPILER_ASSERT

This commit is contained in:
Frank Denis
2017-02-23 10:37:57 +01:00
parent 14d54b9d22
commit 68466a7ed7
5 changed files with 24 additions and 22 deletions
@@ -42,7 +42,6 @@ crypto_stream_salsa2012_xor(unsigned char *c, const unsigned char *m,
in[i] = u;
u >>= 8;
}
mlen -= 64;
c += 64;
m += 64;
@@ -39,7 +39,6 @@ crypto_stream_salsa208(unsigned char *c, unsigned long long clen,
in[i] = u;
u >>= 8;
}
clen -= 64;
c += 64;
}
@@ -42,7 +42,6 @@ crypto_stream_salsa208_xor(unsigned char *c, const unsigned char *m,
in[i] = u;
u >>= 8;
}
mlen -= 64;
c += 64;
m += 64;
@@ -4,15 +4,18 @@
#include "crypto_core_hchacha20.h"
#include "crypto_stream_chacha20.h"
#include "crypto_stream_xchacha20.h"
#include "private/common.h"
#include "randombytes.h"
size_t
crypto_stream_xchacha20_keybytes(void) {
crypto_stream_xchacha20_keybytes(void)
{
return crypto_stream_xchacha20_KEYBYTES;
}
size_t
crypto_stream_xchacha20_noncebytes(void) {
crypto_stream_xchacha20_noncebytes(void)
{
return crypto_stream_xchacha20_NONCEBYTES;
}
@@ -23,38 +26,38 @@ crypto_stream_xchacha20(unsigned char *c, unsigned long long clen,
unsigned char k2[crypto_core_hchacha20_OUTPUTBYTES];
crypto_core_hchacha20(k2, n, k, NULL);
(void) sizeof(int[crypto_stream_chacha20_KEYBYTES <= sizeof k2 ? 1 : -1]);
(void) sizeof(int[crypto_stream_chacha20_NONCEBYTES ==
crypto_stream_xchacha20_NONCEBYTES -
crypto_core_hchacha20_INPUTBYTES ? 1 : -1]);
return crypto_stream_chacha20(c, clen,
n + crypto_core_hchacha20_INPUTBYTES, k2);
COMPILER_ASSERT(crypto_stream_chacha20_KEYBYTES <= sizeof k2);
COMPILER_ASSERT(crypto_stream_chacha20_NONCEBYTES ==
crypto_stream_xchacha20_NONCEBYTES -
crypto_core_hchacha20_INPUTBYTES);
return crypto_stream_chacha20(c, clen, n + crypto_core_hchacha20_INPUTBYTES,
k2);
}
int
crypto_stream_xchacha20_xor_ic(unsigned char *c, const unsigned char *m,
unsigned long long mlen,
const unsigned char *n, uint64_t ic,
const unsigned char *k)
unsigned long long mlen, const unsigned char *n,
uint64_t ic, const unsigned char *k)
{
unsigned char k2[crypto_core_hchacha20_OUTPUTBYTES];
crypto_core_hchacha20(k2, n, k, NULL);
return crypto_stream_chacha20_xor_ic(c, m, mlen,
n + crypto_core_hchacha20_INPUTBYTES,
ic, k2);
return crypto_stream_chacha20_xor_ic(
c, m, mlen, n + crypto_core_hchacha20_INPUTBYTES, ic, k2);
}
int
crypto_stream_xchacha20_xor(unsigned char *c, const unsigned char *m,
unsigned long long mlen, const unsigned char *n,
const unsigned char *k)
unsigned long long mlen, const unsigned char *n,
const unsigned char *k)
{
return crypto_stream_xchacha20_xor_ic(c, m, mlen, n, 0U, k);
}
void
crypto_stream_xchacha20_keygen(unsigned char k[crypto_stream_xchacha20_KEYBYTES])
crypto_stream_xchacha20_keygen(
unsigned char k[crypto_stream_xchacha20_KEYBYTES])
{
randombytes_buf(k, crypto_stream_xchacha20_KEYBYTES);
}
@@ -42,12 +42,14 @@ crypto_stream_xsalsa20_xor(unsigned char *c, const unsigned char *m,
}
size_t
crypto_stream_xsalsa20_keybytes(void) {
crypto_stream_xsalsa20_keybytes(void)
{
return crypto_stream_xsalsa20_KEYBYTES;
}
size_t
crypto_stream_xsalsa20_noncebytes(void) {
crypto_stream_xsalsa20_noncebytes(void)
{
return crypto_stream_xsalsa20_NONCEBYTES;
}