mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-26 11:47:13 +09:00
Make crypto_stream_chacha20 modular like the rest
In preparation for optimized implementations
This commit is contained in:
@@ -93,7 +93,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\scalarmult_curve25519.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_sign\ed25519\ref10\obsolete.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\stream_salsa20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\xor_salsa20_ref.c" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_generichash\blake2\ref\blake2b-load-sse2.h" />
|
||||
|
||||
@@ -961,7 +961,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\ref10\fe_tobytes_curve25519_ref10.c">
|
||||
<Filter>src\crypto_scalarmult\curve25519\ref10</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c">
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c">
|
||||
<Filter>src\crypto_stream\chacha20</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c">
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\scalarmult_curve25519.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_sign\ed25519\ref10\obsolete.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\stream_salsa20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\xor_salsa20_ref.c" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_generichash\blake2\ref\blake2b-load-sse2.h" />
|
||||
|
||||
@@ -961,7 +961,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\ref10\fe_tobytes_curve25519_ref10.c">
|
||||
<Filter>src\crypto_scalarmult\curve25519\ref10</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c">
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c">
|
||||
<Filter>src\crypto_stream\chacha20</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c">
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\scalarmult_curve25519.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_sign\ed25519\ref10\obsolete.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\stream_salsa20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\xor_salsa20_ref.c" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_generichash\blake2\ref\blake2b-load-sse2.h" />
|
||||
|
||||
@@ -961,7 +961,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\ref10\fe_tobytes_curve25519_ref10.c">
|
||||
<Filter>src\crypto_scalarmult\curve25519\ref10</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c">
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c">
|
||||
<Filter>src\crypto_stream\chacha20</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c">
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_scalarmult\curve25519\scalarmult_curve25519.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_sign\ed25519\ref10\obsolete.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\stream_salsa20_ref.c" />
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\salsa20\ref\xor_salsa20_ref.c" />
|
||||
<ClInclude Include="..\..\..\..\src\libsodium\crypto_generichash\blake2\ref\blake2b-load-sse2.h" />
|
||||
@@ -325,4 +325,4 @@
|
||||
<Xml Include="..\..\..\..\packaging\nuget\package.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -925,7 +925,7 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c">
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\stream_chacha20.c">
|
||||
<Filter>src\crypto_stream\chacha20</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\..\src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c">
|
||||
@@ -998,4 +998,4 @@
|
||||
<Filter>src\crypto_sign\ed25519\ref10</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
+2
-2
@@ -501,7 +501,7 @@
|
||||
<ClCompile Include="src\libsodium\crypto_stream\aes128ctr\portable\xor_afternm_aes128ctr.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\aes128ctr\stream_aes128ctr_api.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\chacha20\stream_chacha20.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\crypto_stream.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\salsa2012\ref\stream_salsa2012.c" />
|
||||
<ClCompile Include="src\libsodium\crypto_stream\salsa2012\ref\xor_salsa2012.c" />
|
||||
@@ -535,4 +535,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -566,7 +566,7 @@
|
||||
<ClCompile Include="src\libsodium\crypto_pwhash\scryptsalsa208sha256\sse\pwhash_scryptsalsa208sha256_sse.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\libsodium\crypto_stream\chacha20\stream_chacha20_api.c">
|
||||
<ClCompile Include="src\libsodium\crypto_stream\chacha20\stream_chacha20.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\libsodium\crypto_stream\chacha20\ref\stream_chacha20_ref.c">
|
||||
@@ -656,4 +656,4 @@
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -122,7 +122,8 @@ libsodium_la_SOURCES = \
|
||||
crypto_sign/ed25519/ref10/sign.c \
|
||||
crypto_sign/ed25519/ref10/sqrtm1.h \
|
||||
crypto_stream/crypto_stream.c \
|
||||
crypto_stream/chacha20/stream_chacha20_api.c \
|
||||
crypto_stream/chacha20/stream_chacha20.c \
|
||||
crypto_stream/chacha20/stream_chacha20.h \
|
||||
crypto_stream/chacha20/ref/stream_chacha20_ref.h \
|
||||
crypto_stream/chacha20/ref/stream_chacha20_ref.c \
|
||||
crypto_stream/salsa20/stream_salsa20_api.c \
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "crypto_stream_chacha20.h"
|
||||
#include "stream_chacha20_ref.h"
|
||||
#include "utils.h"
|
||||
#include "../stream_chacha20.h"
|
||||
|
||||
struct chacha_ctx {
|
||||
uint32_t input[16];
|
||||
@@ -238,9 +239,9 @@ chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, unsigned long long bytes
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
crypto_stream_chacha20_ref(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
static int
|
||||
stream_ref(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
{
|
||||
struct chacha_ctx ctx;
|
||||
|
||||
@@ -257,9 +258,9 @@ crypto_stream_chacha20_ref(unsigned char *c, unsigned long long clen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_stream_chacha20_ietf_ref(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
static int
|
||||
stream_ietf_ref(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
{
|
||||
struct chacha_ctx ctx;
|
||||
|
||||
@@ -279,11 +280,11 @@ crypto_stream_chacha20_ietf_ref(unsigned char *c, unsigned long long clen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_stream_chacha20_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
static int
|
||||
stream_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
{
|
||||
struct chacha_ctx ctx;
|
||||
uint8_t ic_bytes[8];
|
||||
@@ -307,11 +308,11 @@ crypto_stream_chacha20_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_stream_chacha20_ietf_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint32_t ic,
|
||||
const unsigned char *k)
|
||||
static int
|
||||
stream_ietf_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint32_t ic,
|
||||
const unsigned char *k)
|
||||
{
|
||||
struct chacha_ctx ctx;
|
||||
uint8_t ic_bytes[4];
|
||||
@@ -328,3 +329,11 @@ crypto_stream_chacha20_ietf_ref_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct crypto_stream_chacha20_implementation
|
||||
crypto_stream_chacha20_ref_implementation = {
|
||||
SODIUM_C99(.stream =) stream_ref,
|
||||
SODIUM_C99(.stream_ietf =) stream_ietf_ref,
|
||||
SODIUM_C99(.stream_xor_ic =) stream_ref_xor_ic,
|
||||
SODIUM_C99(.stream_ietf_xor_ic =) stream_ietf_ref_xor_ic
|
||||
};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
|
||||
#include "crypto_stream_chacha20.h"
|
||||
|
||||
extern struct crypto_stream_chacha20_implementation
|
||||
crypto_stream_chacha20_ref_implementation;
|
||||
|
||||
int
|
||||
crypto_stream_chacha20_ref(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k);
|
||||
|
||||
+11
-6
@@ -1,6 +1,11 @@
|
||||
#include "crypto_stream_chacha20.h"
|
||||
#include "stream_chacha20.h"
|
||||
#include "runtime.h"
|
||||
#include "ref/stream_chacha20_ref.h"
|
||||
|
||||
static const crypto_stream_chacha20_implementation *implementation =
|
||||
&crypto_stream_chacha20_ref_implementation;
|
||||
|
||||
size_t
|
||||
crypto_stream_chacha20_keybytes(void) {
|
||||
return crypto_stream_chacha20_KEYBYTES;
|
||||
@@ -20,14 +25,14 @@ int
|
||||
crypto_stream_chacha20(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
{
|
||||
return crypto_stream_chacha20_ref(c, clen, n, k);
|
||||
return implementation->stream(c, clen, n, k);
|
||||
}
|
||||
|
||||
int
|
||||
crypto_stream_chacha20_ietf(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k)
|
||||
{
|
||||
return crypto_stream_chacha20_ietf_ref(c, clen, n, k);
|
||||
return implementation->stream_ietf(c, clen, n, k);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -36,7 +41,7 @@ crypto_stream_chacha20_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k)
|
||||
{
|
||||
return crypto_stream_chacha20_ref_xor_ic(c, m, mlen, n, ic, k);
|
||||
return implementation->stream_xor_ic(c, m, mlen, n, ic, k);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -45,7 +50,7 @@ crypto_stream_chacha20_ietf_xor_ic(unsigned char *c, const unsigned char *m,
|
||||
const unsigned char *n, uint32_t ic,
|
||||
const unsigned char *k)
|
||||
{
|
||||
return crypto_stream_chacha20_ietf_ref_xor_ic(c, m, mlen, n, ic, k);
|
||||
return implementation->stream_ietf_xor_ic(c, m, mlen, n, ic, k);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -53,7 +58,7 @@ crypto_stream_chacha20_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
{
|
||||
return crypto_stream_chacha20_ref_xor_ic(c, m, mlen, n, 0U, k);
|
||||
return implementation->stream_xor_ic(c, m, mlen, n, 0U, k);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -61,5 +66,5 @@ crypto_stream_chacha20_ietf_xor(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen, const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
{
|
||||
return crypto_stream_chacha20_ietf_ref_xor_ic(c, m, mlen, n, 0U, k);
|
||||
return implementation->stream_ietf_xor_ic(c, m, mlen, n, 0U, k);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
#ifndef stream_chacha20_H
|
||||
#define stream_chacha20_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct crypto_stream_chacha20_implementation {
|
||||
int (*stream)(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k);
|
||||
int (*stream_ietf)(unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *n, const unsigned char *k);
|
||||
int (*stream_xor_ic)(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint64_t ic,
|
||||
const unsigned char *k);
|
||||
int (*stream_ietf_xor_ic)(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n, uint32_t ic,
|
||||
const unsigned char *k);
|
||||
} crypto_stream_chacha20_implementation;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user