diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2010-07-09 12:32:17 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2010-07-09 12:32:17 +0200 |
commit | 6c027b4de25a529908be895e7ff19236f4002a57 (patch) | |
tree | f70d3a400bbb9ba8a83e9d4ffcaa4b6e367fc8bb /crypto_buffer.h | |
download | crypto-6c027b4de25a529908be895e7ff19236f4002a57.zip crypto-6c027b4de25a529908be895e7ff19236f4002a57.tar.gz |
initial commit, resurrect one of my realy old projects
Diffstat (limited to 'crypto_buffer.h')
-rw-r--r-- | crypto_buffer.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/crypto_buffer.h b/crypto_buffer.h new file mode 100644 index 0000000..51e233e --- /dev/null +++ b/crypto_buffer.h @@ -0,0 +1,77 @@ +#ifndef CRYPTO_BUFFER_H +#define CRYPTO_BUFFER_H + +#include "uint.h" +#include "blowfish.h" +#include "twofish.h" +#include "aes.h" +#include "des.h" + +struct info{ + u32 strlen; /* number of uint8 of clear data */ + u32 bytes; /* number of bytes of encrypted data */ +}; +#define ENCRYPT 0x0000 +#define DECRYPT 0x0001 +#define BLOWFISH 0x0002 +#define TWOFISH 0x0004 +#define AES 0x0008 +#define DES 0x0010 +#define DES3_EDE 0x0020 + +typedef int (*operation)(int ,u8* ,u32); + +typedef struct crypto_buffer { + u8 *c_buffer; /* clear data buffer */ + u8* c_ptr; /* clear data to read */ + u8* c_end; /* end of c_buffer */ + u8 *e_buffer; /* encrypted data buffer */ + u8* e_ptr; /* encrypted data to read */ + u8* e_end; /* end of e_buffer */ + u32 e_len; /* length of e_buffer */ + u32 block_size; /* size of blocks used by cipher */ + struct info *e_data; /* pointer for write operations */ + struct info data_st; /* info structure for read and write operations */ + int fd; /* file descriptor */ + operation op; /* read/write operation */ + void (*cipher)(void*, u8 *, const u8 *); /* encryption/decryption function */ + union{ /* cipher ctx */ + struct blowfish_ctx bf_cxt; + struct twofish_ctx tf_cxt; + }ctx; +} crypto_buffer; + + +/* initialize a buffer for read or write operation + * buffer struct + * file descriptor + * read or write operation + * number of blocks in buffer + * type of cipher (BLOWFISH/TWOFISH/AES | ENCRYPT/DECRYPT) + * encryption key + * length of encryption key + */ +int crypto_buffer_init(crypto_buffer *b, int fd, operation op, u32 blocks, int type, u8 *key, u32 k_len); + + +/* force write on fd */ +int crypto_buffer_flush(crypto_buffer *b); + +/* read data from buffer */ +int crypto_buffer_get(crypto_buffer *b, u8 *s, u32 len); + +/* add data to buffer */ +int crypto_buffer_put(crypto_buffer *b, const u8 *s, u32 len); + +/* add data to buffer then force write on fd */ +int crypto_buffer_putflush(crypto_buffer *b, const u8 *s, u32 len); + +/* read/write to fd */ +int u8_unix_read(int fd, u8 *s, u32 len); +int u8_unix_write(int fd, u8 *s, u32 len); +/* not really usefull read/write also work */ +int u8_tcp_read(int sd, u8 *s, u32 len); +int u8_tcp_write(int sd, u8 *s, u32 len); + + +#endif |