mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-10 06:24:57 +00:00
Make salsa20 dependency a c project instead of c++
This commit is contained in:
parent
5b97aee87f
commit
fb3b62fa69
@ -5,7 +5,7 @@ Public domain.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "salsa20.h"
|
#include "salsa20.h"
|
||||||
#include <cassert>
|
#include <assert.h>
|
||||||
|
|
||||||
#define U8V(v) ((uint8_t)(v) & 0xFFu)
|
#define U8V(v) ((uint8_t)(v) & 0xFFu)
|
||||||
#define U16V(v) ((uint16_t)(v) & 0xFFFFu)
|
#define U16V(v) ((uint16_t)(v) & 0xFFFFu)
|
||||||
@ -88,7 +88,7 @@ static void Salsa20_WordToByte(uint8_t output[64], const uint32_t input[16])
|
|||||||
static const char* sigma = "expand 32-byte k";
|
static const char* sigma = "expand 32-byte k";
|
||||||
static const char* tau = "expand 16-byte k";
|
static const char* tau = "expand 16-byte k";
|
||||||
|
|
||||||
void Salsa20_KeySetup(salsa20_ctx* ctx, const uint8_t* key, const uint32_t keySize)
|
void Salsa20_KeySetup(salsa20_ctx_t* ctx, const uint8_t* key, const uint32_t keySize)
|
||||||
{
|
{
|
||||||
const char* constants;
|
const char* constants;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ void Salsa20_KeySetup(salsa20_ctx* ctx, const uint8_t* key, const uint32_t keySi
|
|||||||
ctx->m_input[15] = U8TO32_LITTLE(constants + 12);
|
ctx->m_input[15] = U8TO32_LITTLE(constants + 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Salsa20_IVSetup(salsa20_ctx* ctx, const uint8_t* iv)
|
void Salsa20_IVSetup(salsa20_ctx_t* ctx, const uint8_t* iv)
|
||||||
{
|
{
|
||||||
ctx->m_input[6] = U8TO32_LITTLE(iv + 0);
|
ctx->m_input[6] = U8TO32_LITTLE(iv + 0);
|
||||||
ctx->m_input[7] = U8TO32_LITTLE(iv + 4);
|
ctx->m_input[7] = U8TO32_LITTLE(iv + 4);
|
||||||
@ -127,7 +127,7 @@ void Salsa20_IVSetup(salsa20_ctx* ctx, const uint8_t* iv)
|
|||||||
ctx->m_input[9] = 0;
|
ctx->m_input[9] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Salsa20_Encrypt_Bytes(salsa20_ctx* ctx, const uint8_t* plainText, uint8_t* cipherText, uint32_t msgLen)
|
void Salsa20_Encrypt_Bytes(salsa20_ctx_t* ctx, const uint8_t* plainText, uint8_t* cipherText, uint32_t msgLen)
|
||||||
{
|
{
|
||||||
uint8_t output[64];
|
uint8_t output[64];
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -154,7 +154,7 @@ void Salsa20_Encrypt_Bytes(salsa20_ctx* ctx, const uint8_t* plainText, uint8_t*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Salsa20_Decrypt_Bytes(salsa20_ctx* ctx, const uint8_t* cipherText, uint8_t* plainText, const uint32_t msgLen)
|
void Salsa20_Decrypt_Bytes(salsa20_ctx_t* ctx, const uint8_t* cipherText, uint8_t* plainText, const uint32_t msgLen)
|
||||||
{
|
{
|
||||||
Salsa20_Encrypt_Bytes(ctx, cipherText, plainText, msgLen);
|
Salsa20_Encrypt_Bytes(ctx, cipherText, plainText, msgLen);
|
||||||
}
|
}
|
14
thirdparty/salsa20/salsa20.h
vendored
14
thirdparty/salsa20/salsa20.h
vendored
@ -6,12 +6,12 @@ Public domain.
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <stdint.h>
|
||||||
|
|
||||||
struct salsa20_ctx
|
typedef struct salsa20_ctx
|
||||||
{
|
{
|
||||||
uint32_t m_input[16];
|
uint32_t m_input[16];
|
||||||
};
|
} salsa20_ctx_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the context with the chosen key.
|
* Initializes the context with the chosen key.
|
||||||
@ -20,7 +20,7 @@ struct salsa20_ctx
|
|||||||
* key: A pointer to the key bytes.
|
* key: A pointer to the key bytes.
|
||||||
* keySize: The length of the key in bits. Has to be 128 or 256.
|
* keySize: The length of the key in bits. Has to be 128 or 256.
|
||||||
*/
|
*/
|
||||||
void Salsa20_KeySetup(salsa20_ctx* ctx, const uint8_t* key, uint32_t keySize);
|
void Salsa20_KeySetup(salsa20_ctx_t* ctx, const uint8_t* key, uint32_t keySize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes or changes the IV of the context.
|
* Initializes or changes the IV of the context.
|
||||||
@ -29,7 +29,7 @@ void Salsa20_KeySetup(salsa20_ctx* ctx, const uint8_t* key, uint32_t keySize);
|
|||||||
* ctx: The context to initialize.
|
* ctx: The context to initialize.
|
||||||
* iv: A pointer to the IV bytes. Must be 64 bits long.
|
* iv: A pointer to the IV bytes. Must be 64 bits long.
|
||||||
*/
|
*/
|
||||||
void Salsa20_IVSetup(salsa20_ctx* ctx, const uint8_t* iv);
|
void Salsa20_IVSetup(salsa20_ctx_t* ctx, const uint8_t* iv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encrypts the specified amount of plain text and writes it to the cipher text buffer.
|
* Encrypts the specified amount of plain text and writes it to the cipher text buffer.
|
||||||
@ -40,7 +40,7 @@ void Salsa20_IVSetup(salsa20_ctx* ctx, const uint8_t* iv);
|
|||||||
* plainText: A pointer to the plain text buffer which must at least be msgLen bytes.
|
* plainText: A pointer to the plain text buffer which must at least be msgLen bytes.
|
||||||
* msgLen: The amount of bytes to encrypt.
|
* msgLen: The amount of bytes to encrypt.
|
||||||
*/
|
*/
|
||||||
void Salsa20_Encrypt_Bytes(salsa20_ctx* ctx, const uint8_t* plainText, uint8_t* cipherText, uint32_t msgLen);
|
void Salsa20_Encrypt_Bytes(salsa20_ctx_t* ctx, const uint8_t* plainText, uint8_t* cipherText, uint32_t msgLen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decrypts the specified amount of cipher text and writes it to the plain text buffer.
|
* Decrypts the specified amount of cipher text and writes it to the plain text buffer.
|
||||||
@ -52,4 +52,4 @@ void Salsa20_Encrypt_Bytes(salsa20_ctx* ctx, const uint8_t* plainText, uint8_t*
|
|||||||
* plainText: A pointer to the plain text buffer which must at least be msgLen bytes.
|
* plainText: A pointer to the plain text buffer which must at least be msgLen bytes.
|
||||||
* msgLen: The amount of bytes to decrypt.
|
* msgLen: The amount of bytes to decrypt.
|
||||||
*/
|
*/
|
||||||
void Salsa20_Decrypt_Bytes(salsa20_ctx* ctx, const uint8_t* cipherText, uint8_t* plainText, uint32_t msgLen);
|
void Salsa20_Decrypt_Bytes(salsa20_ctx_t* ctx, const uint8_t* cipherText, uint8_t* plainText, uint32_t msgLen);
|
Loading…
x
Reference in New Issue
Block a user