encrypt.c 1.19 KB
Newer Older
1
2
3
4
5
6
/* encrypt.c
 *
 */

#include "encrypt.h"

Niels Möller's avatar
Niels Möller committed
7
8
static int do_encrypt(struct encrypt_processor *closure,
		      struct simple_packet *packet)
9
10
11
12
13
14
15
{
  struct simple_packet *new
    = simple_packet_alloc(packet->length + closure->mac_size);

  closure->encrypt_function(closure->encrypt_state,
			    packet->data, new->data, packet->length);

Niels Möller's avatar
Niels Möller committed
16
17
18
19
  if (closure->mac_size)
    closure->mac_function(closure->mac_state,
			  packet->data, new->data + packet->length);
  
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  simple_packet_free(packet);

  return apply_processor(closure->c->next, new);
}

struct packet_processor *
make_encrypt_processor(struct packet_processor *containing,
		       unsigned mac_size,
		       transform_function mac_function,
		       void *mac_state,
		       transform_function encrypt_function,
		       void *encrypt_state)
{
  struct pad_processor *closure = xalloc(sizeof(struct pad_processor));

Niels Möller's avatar
Niels Möller committed
35
  closure->c->p->f = (raw_processor_function) do_encrypt;
36
37
38
39
40
41
42
  closure->c->next = continuation;
  closure->mac_size = mac_size;
  closure->mac_function = mac_function;
  closure->mac_state = mac_state;
  closure->encrypt_function = encrypt_function;
  closure->encrypt_state = encrypt_state;

Niels Möller's avatar
Niels Möller committed
43
  return (struct packet_processor *) closure;
44
45
46
}