| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
#ifndef OPS_CRYPTO_H |
|---|
| 5 |
#define OPS_CRYPTO_H |
|---|
| 6 |
|
|---|
| 7 |
#include "util.h" |
|---|
| 8 |
#include "packet.h" |
|---|
| 9 |
#include "packet-parse.h" |
|---|
| 10 |
|
|---|
| 11 |
#define OPS_MAX_HASH_SIZE 64 |
|---|
| 12 |
#define OPS_MIN_HASH_SIZE 16 |
|---|
| 13 |
|
|---|
| 14 |
typedef void ops_hash_init_t(ops_hash_t *hash); |
|---|
| 15 |
typedef void ops_hash_add_t(ops_hash_t *hash,const unsigned char *data, |
|---|
| 16 |
unsigned length); |
|---|
| 17 |
typedef unsigned ops_hash_finish_t(ops_hash_t *hash,unsigned char *out); |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
struct _ops_hash_t |
|---|
| 21 |
{ |
|---|
| 22 |
ops_hash_algorithm_t algorithm; |
|---|
| 23 |
const char *name; |
|---|
| 24 |
ops_hash_init_t *init; |
|---|
| 25 |
ops_hash_add_t *add; |
|---|
| 26 |
ops_hash_finish_t *finish; |
|---|
| 27 |
void *data; |
|---|
| 28 |
}; |
|---|
| 29 |
|
|---|
| 30 |
typedef void ops_decrypt_set_iv_t(ops_decrypt_t *decrypt, |
|---|
| 31 |
const unsigned char *iv); |
|---|
| 32 |
typedef void ops_decrypt_set_key_t(ops_decrypt_t *decrypt, |
|---|
| 33 |
const unsigned char *key); |
|---|
| 34 |
typedef void ops_decrypt_init_t(ops_decrypt_t *decrypt); |
|---|
| 35 |
typedef void ops_decrypt_resync_t(ops_decrypt_t *decrypt); |
|---|
| 36 |
typedef size_t ops_decrypt_decrypt_t(ops_decrypt_t *decrypt,void *out, |
|---|
| 37 |
const void *in,int count); |
|---|
| 38 |
typedef void ops_decrypt_finish_t(ops_decrypt_t *decrypt); |
|---|
| 39 |
|
|---|
| 40 |
struct _ops_decrypt_t |
|---|
| 41 |
{ |
|---|
| 42 |
ops_symmetric_algorithm_t algorithm; |
|---|
| 43 |
size_t blocksize; |
|---|
| 44 |
size_t keysize; |
|---|
| 45 |
ops_decrypt_set_iv_t *set_iv; |
|---|
| 46 |
ops_decrypt_set_iv_t *set_key; |
|---|
| 47 |
ops_decrypt_init_t *init; |
|---|
| 48 |
ops_decrypt_resync_t *resync; |
|---|
| 49 |
ops_decrypt_decrypt_t *decrypt; |
|---|
| 50 |
ops_decrypt_finish_t *finish; |
|---|
| 51 |
unsigned char iv[OPS_MAX_BLOCK_SIZE]; |
|---|
| 52 |
unsigned char civ[OPS_MAX_BLOCK_SIZE]; |
|---|
| 53 |
unsigned char siv[OPS_MAX_BLOCK_SIZE]; |
|---|
| 54 |
unsigned char key[OPS_MAX_KEY_SIZE]; |
|---|
| 55 |
int num; |
|---|
| 56 |
void *data; |
|---|
| 57 |
}; |
|---|
| 58 |
|
|---|
| 59 |
void ops_crypto_init(void); |
|---|
| 60 |
void ops_crypto_finish(void); |
|---|
| 61 |
void ops_hash_md5(ops_hash_t *hash); |
|---|
| 62 |
void ops_hash_sha1(ops_hash_t *hash); |
|---|
| 63 |
void ops_hash_any(ops_hash_t *hash,ops_hash_algorithm_t alg); |
|---|
| 64 |
ops_hash_algorithm_t ops_hash_algorithm_from_text(const char *hash); |
|---|
| 65 |
const char *ops_text_from_hash(ops_hash_t *hash); |
|---|
| 66 |
unsigned ops_hash_size(ops_hash_algorithm_t alg); |
|---|
| 67 |
unsigned ops_hash(unsigned char *out,ops_hash_algorithm_t alg,const void *in, |
|---|
| 68 |
size_t length); |
|---|
| 69 |
|
|---|
| 70 |
void ops_hash_add_int(ops_hash_t *hash,unsigned n,unsigned length); |
|---|
| 71 |
|
|---|
| 72 |
ops_boolean_t ops_dsa_verify(const unsigned char *hash,size_t hash_length, |
|---|
| 73 |
const ops_dsa_signature_t *sig, |
|---|
| 74 |
const ops_dsa_public_key_t *dsa); |
|---|
| 75 |
int ops_rsa_public_decrypt(unsigned char *out,const unsigned char *in, |
|---|
| 76 |
size_t length,const ops_rsa_public_key_t *rsa); |
|---|
| 77 |
int ops_rsa_private_encrypt(unsigned char *out,const unsigned char *in, |
|---|
| 78 |
size_t length,const ops_rsa_secret_key_t *srsa, |
|---|
| 79 |
const ops_rsa_public_key_t *rsa); |
|---|
| 80 |
|
|---|
| 81 |
unsigned ops_block_size(ops_symmetric_algorithm_t alg); |
|---|
| 82 |
unsigned ops_key_size(ops_symmetric_algorithm_t alg); |
|---|
| 83 |
|
|---|
| 84 |
int ops_decrypt_data(ops_region_t *region,ops_parse_info_t *parse_info); |
|---|
| 85 |
|
|---|
| 86 |
void ops_decrypt_any(ops_decrypt_t *decrypt,ops_symmetric_algorithm_t alg); |
|---|
| 87 |
|
|---|
| 88 |
void ops_reader_push_decrypt(ops_parse_info_t *pinfo,ops_decrypt_t *decrypt, |
|---|
| 89 |
ops_region_t *region); |
|---|
| 90 |
void ops_reader_pop_decrypt(ops_parse_info_t *pinfo); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
void ops_reader_push_hash(ops_parse_info_t *pinfo,ops_hash_t *hash); |
|---|
| 94 |
void ops_reader_pop_hash(ops_parse_info_t *pinfo); |
|---|
| 95 |
|
|---|
| 96 |
#endif |
|---|
| 97 |
|
|---|