summaryrefslogtreecommitdiffstats
path: root/ncr-pk.h
blob: 11800175c3b49c37728be0400b48d7ef449a88f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef NCR_PK_H
# define NCR_PK_H

#include <tomcrypt.h>

struct ncr_pk_ctx {
	ncr_algorithm_t algorithm; /* algorithm */
	
	ncr_algorithm_t sign_hash; /* for verification */
	
	ncr_algorithm_t oaep_hash;
	int salt_len; /* for RSA-PSS signatures */
	
	int type; /* libtomcrypt type */
	int init; /* non zero if initialized */
	
	struct key_item_st * key;
};

/* PK */
void ncr_pk_clear(struct key_item_st* key);
int ncr_pk_generate(ncr_algorithm_t algo,
	struct ncr_key_generate_params_st * params,
	struct key_item_st* private, struct key_item_st* public);
int ncr_pk_pack( const struct key_item_st * key, uint8_t * packed, uint32_t * packed_size);
int ncr_pk_unpack( struct key_item_st * key, const void * packed, size_t packed_size);


int ncr_pk_queue_init(void);
void ncr_pk_queue_deinit(void);

/* encryption/decryption */
int ncr_pk_cipher_init(ncr_algorithm_t algo, 
	struct ncr_pk_ctx* ctx, struct ncr_key_params_st* params,
	struct key_item_st *key);
void ncr_pk_cipher_deinit(struct ncr_pk_ctx* ctx);
int ncr_pk_cipher_encrypt(const struct ncr_pk_ctx* ctx, const void* input, 
	size_t input_size, void* output, size_t *output_size);
int ncr_pk_cipher_decrypt(const struct ncr_pk_ctx* ctx, const void* input, 
	size_t input_size, void* output, size_t *output_size);
int ncr_pk_cipher_sign(const struct ncr_pk_ctx* ctx, const void* input, 
	size_t input_size, void* output, size_t *output_size);

int ncr_pk_cipher_verify(const struct ncr_pk_ctx* ctx, 
	const void* signature, size_t signature_size, 
	const void* hash, size_t hash_size, ncr_error_t*);

#endif