Commit 6b970606 authored by Niels Möller's avatar Niels Möller
Browse files

New files

Rev: src/abstract_crypto.h:1.1
Rev: src/read_data.c:1.1
Rev: src/read_data.h:1.1
parent 2d5ab5ac
/* abstract_crypto.h
*
* Interface to block cryptos and hash functions */
#ifndef LSH_ABSTRACT_CRYPTO_H_INCLUDED
#define LSH_ABSTRACT_CRYPTO_H_INCLUDED
struct crypto_instance
{
UINT32 block_size;
/* Length must be a multiple of the block size */
void (*crypt)(struct crypto_instance *self,
UINT32 length, UINT8 *dst, UINT8 *src);
};
#define CRYPT(instance, length, src, dst) \
((instance)->crypt((instance), (length), (src), (dst)))
struct crypto_algorithm
{
UINT32 block_size;
UINT32 key_size;
struct crypto_instance *make_encrypt(struct crypto_algorithm *self,
UINT8 *key);
struct crypto_instance *make_decrypt(struct crypto_algorithm *self,
UINT8 *key);
};
struct hash_instance
{
UINT32 hash_size;
void (*update)(struct hash_instance *self,
UINT32 length, UINT8 *data);
void (*digest)(struct hash_instance *self,
UINT8 *result);
struct hash_instance (*copy)(struct hash_instance *self);
};
#define UPDATE(instance, length, data) \
((instance)->update((instance), (length), (data)))
#define DIGEST(instance, result) \
((instance)->digest((instance), (result)))
/* Used for both hash functions ad macs */
#define mac_instance hash_instance
#define mac_size hash_size
struct hash_algorithm
{
UINT32 block_size;
UINT32 hash_size;
struct hash_instance (*make_hash)(struct hash_algorithm *self);
};
struct mac_algorithm
{
UINT32 hash_size;
UINT32 key_size;
struct mac_instance (*make_mac)(struct mac_algorithm *self,
UINT8 *key);
};
#endif /* LSH_ABSTRACT_CRYPTO_H_INCLUDED */
/* read_data.c
*
*/
#include "read_data.h"
static struct read_handler *do_read_data(struct read_data *closure,
struct abstract_read *read)
{
while(1)
{
struct lsh_string packet = lsh_string_alloc(closure->block_size);
int n = A_READ(read, packet->data, packet->length);
switch(n)
{
case 0:
lsh_string_free(packet);
break;
case A_FAIL:
werror("do_read_data: read() failed, %s\n", strerror(errno));
/* Fall through */
case A_EOF:
CALLBACK(closure->close_callback)
return 0;
default:
packet->length = n;
A_WRITE(closure->handler, packet);
break;
}
}
}
/* read_data.h
*
* A read handler for application data.
*/
#ifndef LSH_READ_DATA_H_INCLUDED
#define LSH_READ_DATA_H_INCLUDED
#include "abstract_read.h"
struct read_data
{
struct read_handler super; /* Super type */
UINT32 block_size;
/* Where to send the data */
struct abstract_write *handler;
struct callback *close_callback;
};
#endif /* LSH_READ_DATA_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment