b963d1055894fa2a5919db7c6bd3b49b19ed878c
[paraslash.git] / crypt.h
1 /*
2 * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file crypt.h Prototypes for paraslash crypto functions. */
8
9 /** Opaque structure for public and private keys. */
10 struct asymmetric_key;
11
12 int pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf,
13 unsigned len, unsigned char *outbuf);
14 int priv_decrypt(const char *key_file, unsigned char *outbuf,
15 unsigned char *inbuf, int inlen);
16 int get_asymmetric_key(const char *key_file, int private,
17 struct asymmetric_key **result);
18 void free_asymmetric_key(struct asymmetric_key *key);
19
20 void get_random_bytes_or_die(unsigned char *buf, int num);
21 void init_random_seed_or_die(void);
22
23 struct stream_cipher;
24
25 /**
26 * Used on the server-side for client-server communication encryption.
27 *
28 * The traffic between (the forked child of) para_server and the remote client
29 * process is crypted by a symmetric session key. This structure contains the
30 * keys for the stream cipher and the file descriptor for which these keys
31 * should be used.
32 */
33 struct stream_cipher_context {
34 /** The socket file descriptor. */
35 int fd;
36 /** Key used for receiving data. */
37 struct stream_cipher *recv;
38 /** Key used for sending data. */
39 struct stream_cipher *send;
40 };
41
42 struct stream_cipher *sc_new(const unsigned char *data, int len);
43 void sc_free(struct stream_cipher *sc);
44
45 int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf,
46 size_t len);
47 int sc_send_buffer(struct stream_cipher_context *scc, const char *buf);
48 __printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
49 const char *fmt, ...);
50 int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf,
51 size_t size);
52 int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size);
53
54 /** \cond used to distinguish between loading of private/public key */
55 #define LOAD_PUBLIC_KEY 0
56 #define LOAD_PRIVATE_KEY 1
57 #define CHALLENGE_SIZE 64
58 /** \endcond **/