2 * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file crypt.h Public crypto interface. */
10 /** \cond used to distinguish between loading of private/public key */
11 #define LOAD_PUBLIC_KEY 0
12 #define LOAD_PRIVATE_KEY 1
13 #define CHALLENGE_SIZE 64
16 /* asymetric (public key) crypto */
18 /** Opaque structure for public and private keys. */
19 struct asymmetric_key
;
21 int pub_encrypt(struct asymmetric_key
*pub
, unsigned char *inbuf
,
22 unsigned len
, unsigned char *outbuf
);
23 int priv_decrypt(const char *key_file
, unsigned char *outbuf
,
24 unsigned char *inbuf
, int inlen
);
25 int get_asymmetric_key(const char *key_file
, int private,
26 struct asymmetric_key
**result
);
27 void free_asymmetric_key(struct asymmetric_key
*key
);
30 void get_random_bytes_or_die(unsigned char *buf
, int num
);
31 void init_random_seed_or_die(void);
33 /* stream cipher declarations and prototypes */
35 /** Opaque structure for stream ciphers. */
37 /** Number of bytes of the session key for stream ciphers. */
38 #define SESSION_KEY_LEN 32
40 * Used for client-server communication encryption.
42 * The traffic between (the forked child of) para_server and the remote client
43 * process is crypted by a symmetric session key. This structure contains the
44 * keys for the stream cipher and the file descriptor for which these keys
47 struct stream_cipher_context
{
48 /** The socket file descriptor. */
50 /** Key used for receiving data. */
51 struct stream_cipher
*recv
;
52 /** Key used for sending data. */
53 struct stream_cipher
*send
;
55 struct stream_cipher
*sc_new(const unsigned char *data
, int len
);
56 void sc_free(struct stream_cipher
*sc
);
57 int sc_send_bin_buffer(struct stream_cipher_context
*scc
, const char *buf
,
59 int sc_send_buffer(struct stream_cipher_context
*scc
, const char *buf
);
60 __printf_2_3
int sc_send_va_buffer(struct stream_cipher_context
*scc
,
61 const char *fmt
, ...);
62 int sc_recv_bin_buffer(struct stream_cipher_context
*scc
, char *buf
,
64 int sc_recv_buffer(struct stream_cipher_context
*scc
, char *buf
, size_t size
);
68 /** Size of the hash value in bytes. */
71 void hash_function(const char *data
, unsigned long len
, unsigned char *hash
);
72 void hash_to_asc(unsigned char *hash
, char *asc
);
73 int hash_compare(unsigned char *h1
, unsigned char *h2
);