You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chacha20stream/include/cc20.h

54 lines
1.1 KiB

#ifndef _CC20_H
#define _CC20_H
#include <stdint.h>
#include <stddef.h>
#define KEY_SIZE 32
#define IV_SIZE 12
enum cc20_mode {
CC20_ENCRYPT,
CC20_DECRYPT,
};
typedef uint8_t cc20_key_t[KEY_SIZE];
typedef uint8_t cc20_iv_t[IV_SIZE];
typedef struct cc20_metadata {
FILE* backing;
cc20_key_t key;
cc20_iv_t iv;
enum cc20_mode mode;
} cc20_meta_t;
typedef struct cc20_sink cc20_sink_t;
int cc20_gen_meta(FILE* file,
const cc20_key_t* key,
const cc20_iv_t* iv,
enum cc20_mode mode,
struct cc20_metadata* restrict output);
cc20_sink_t* cc20_gen_sink(const struct cc20_metadata* meta);
cc20_sink_t* cc20_gen_sink_full(FILE* file,
const cc20_key_t* key,
const cc20_iv_t* iv,
enum cc20_mode mode);
FILE* cc20_wrap_full(FILE* file,
const cc20_key_t* key,
const cc20_iv_t* iv,
enum cc20_mode mode);
FILE* cc20_gen(const struct cc20_metadata* meta);
int cc20_close_sink(cc20_sink_t* sink,
struct cc20_metadata* restrict meta);
FILE* cc20_wrap_sink(cc20_sink_t* sink);
size_t cc20_write(const void* ptr, size_t size, size_t nmemb, cc20_sink_t* restrict sink);
#endif /* _CC20_H */