mirror of https://github.com/skeeto/enchive.git
Tidy up.
parent
8c5f0c9d21
commit
813413d151
20
chacha.c
20
chacha.c
|
@ -6,9 +6,6 @@ Public domain.
|
|||
|
||||
#include "chacha.h"
|
||||
|
||||
#define U8C(v) (v##U)
|
||||
#define U16C(v) (v##U)
|
||||
#define U32C(v) (v##UL)
|
||||
#define U8V(v) ((u8)(v) & U8C(0xFF))
|
||||
#define U16V(v) ((u16)(v) & U16C(0xFFFF))
|
||||
#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
|
||||
|
@ -58,11 +55,6 @@ static void salsa20_wordtobyte(u8 output[64],const u32 input[16])
|
|||
for (i = 0;i < 16;++i) U32TO8_LITTLE(output + 4 * i,x[i]);
|
||||
}
|
||||
|
||||
void chacha_init(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static const char sigma[16] = "expand 32-byte k";
|
||||
static const char tau[16] = "expand 16-byte k";
|
||||
|
||||
|
@ -121,15 +113,3 @@ void chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
|
|||
m += 64;
|
||||
}
|
||||
}
|
||||
|
||||
void chacha_decrypt_bytes(chacha_ctx *x,const u8 *c,u8 *m,u32 bytes)
|
||||
{
|
||||
chacha_encrypt_bytes(x,c,m,bytes);
|
||||
}
|
||||
|
||||
void chacha_keystream_bytes(chacha_ctx *x,u8 *stream,u32 bytes)
|
||||
{
|
||||
u32 i;
|
||||
for (i = 0;i < bytes;++i) stream[i] = 0;
|
||||
chacha_encrypt_bytes(x,stream,stream,bytes);
|
||||
}
|
||||
|
|
11
chacha.h
11
chacha.h
|
@ -1,19 +1,14 @@
|
|||
#ifndef CHACHA_H
|
||||
#define CHACHA_H
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned long u32;
|
||||
#include "machine.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 input[16];
|
||||
typedef struct {
|
||||
u32 input[16];
|
||||
} chacha_ctx;
|
||||
|
||||
void chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits);
|
||||
void chacha_ivsetup(chacha_ctx *x,const u8 *iv);
|
||||
void chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes);
|
||||
void chacha_decrypt_bytes(chacha_ctx *x,const u8 *c,u8 *m,u32 bytes);
|
||||
void chacha_keystream_bytes(chacha_ctx *x,u8 *stream,u32 bytes);
|
||||
|
||||
#endif /* CHACHA_H */
|
||||
|
|
|
@ -46,11 +46,7 @@
|
|||
* from the sample implementation. */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t limb;
|
||||
#include "machine.h"
|
||||
|
||||
/* Field element representation:
|
||||
*
|
||||
|
|
42
enchive.c
42
enchive.c
|
@ -7,6 +7,8 @@
|
|||
#include "optparse.h"
|
||||
#include "chacha.h"
|
||||
|
||||
int curve25519_donna(u8 *p, const u8 *s, const u8 *b);
|
||||
|
||||
static void
|
||||
fatal(const char *fmt, ...)
|
||||
{
|
||||
|
@ -18,10 +20,6 @@ fatal(const char *fmt, ...)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int curve25519_donna(unsigned char *p,
|
||||
const unsigned char *s,
|
||||
const unsigned char *b);
|
||||
|
||||
static void
|
||||
secure_entropy(void *buf, size_t len)
|
||||
{
|
||||
|
@ -34,7 +32,7 @@ secure_entropy(void *buf, size_t len)
|
|||
}
|
||||
|
||||
static void
|
||||
generate_secret(unsigned char *s)
|
||||
generate_secret(u8 *s)
|
||||
{
|
||||
secure_entropy(s, 32);
|
||||
s[0] &= 248;
|
||||
|
@ -43,16 +41,14 @@ generate_secret(unsigned char *s)
|
|||
}
|
||||
|
||||
static void
|
||||
compute_public(unsigned char *p, const unsigned char *s)
|
||||
compute_public(u8 *p, const u8 *s)
|
||||
{
|
||||
static const unsigned char b[32] = {9};
|
||||
static const u8 b[32] = {9};
|
||||
curve25519_donna(p, s, b);
|
||||
}
|
||||
|
||||
static void
|
||||
compute_shared(unsigned char *sh,
|
||||
const unsigned char *s,
|
||||
const unsigned char *p)
|
||||
compute_shared(u8 *sh, const u8 *s, const u8 *p)
|
||||
{
|
||||
curve25519_donna(sh, s, p);
|
||||
}
|
||||
|
@ -91,7 +87,7 @@ default_secfile(void)
|
|||
}
|
||||
|
||||
static void
|
||||
load_key(const char *file, unsigned char *key)
|
||||
load_key(const char *file, u8 *key)
|
||||
{
|
||||
FILE *f = fopen(file, "rb");
|
||||
if (!f)
|
||||
|
@ -102,7 +98,7 @@ load_key(const char *file, unsigned char *key)
|
|||
}
|
||||
|
||||
static void
|
||||
write_key(const char *file, const unsigned char *key)
|
||||
write_key(const char *file, const u8 *key)
|
||||
{
|
||||
FILE *f = fopen(file, "wb");
|
||||
if (!f)
|
||||
|
@ -121,8 +117,8 @@ command_keygen(struct optparse *options)
|
|||
|
||||
const char *pubfile = default_pubfile();
|
||||
const char *secfile = default_secfile();
|
||||
unsigned char public[32];
|
||||
unsigned char secret[32];
|
||||
u8 public[32];
|
||||
u8 secret[32];
|
||||
|
||||
int option;
|
||||
while ((option = optparse_long(options, keygen, 0)) != -1) {
|
||||
|
@ -144,11 +140,11 @@ command_archive(struct optparse *options)
|
|||
};
|
||||
|
||||
const char *pubfile = default_pubfile();
|
||||
unsigned char public[32];
|
||||
unsigned char esecret[32];
|
||||
unsigned char epublic[32];
|
||||
unsigned char shared[32];
|
||||
unsigned char iv[8];
|
||||
u8 public[32];
|
||||
u8 esecret[32];
|
||||
u8 epublic[32];
|
||||
u8 shared[32];
|
||||
u8 iv[8];
|
||||
|
||||
int option;
|
||||
while ((option = optparse_long(options, archive, 0)) != -1) {
|
||||
|
@ -179,10 +175,10 @@ command_extract(struct optparse *options)
|
|||
};
|
||||
|
||||
const char *secfile = default_secfile();
|
||||
unsigned char secret[32];
|
||||
unsigned char epublic[32];
|
||||
unsigned char shared[32];
|
||||
unsigned char iv[8];
|
||||
u8 secret[32];
|
||||
u8 epublic[32];
|
||||
u8 shared[32];
|
||||
u8 iv[8];
|
||||
|
||||
int option;
|
||||
while ((option = optparse_long(options, extract, 0)) != -1) {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef MACHINE_H
|
||||
#define MACHINE_H
|
||||
#include <stdint.h>
|
||||
|
||||
#define U8C(v) (UINT8_C(v))
|
||||
#define U16C(v) (UINT16_C(v))
|
||||
#define U32C(v) (UINT32_C(v))
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
|
||||
typedef int32_t s32;
|
||||
typedef int64_t limb;
|
||||
|
||||
#endif /* MACHINE_H */
|
Loading…
Reference in New Issue