1 #include <sys/time.h>
2 #include <time.h>
3 #include <stdint.h>
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <assert.h>
8
9 #include "inc.h"
10 #include "util.h"
11 #include "tcpcrypt_ctl.h"
12 #include "tcpcrypt.h"
13 #include "tcpcryptd.h"
14 #include "crypto.h"
15
16 static struct cipher_list _ciphers;
17
crypt_cipher_list(void)18 struct cipher_list *crypt_cipher_list(void)
19 {
20 return _ciphers.c_next;
21 }
22
crypt_init(int sz)23 struct crypt *crypt_init(int sz)
24 {
25 struct crypt *c = xmalloc(sizeof(*c));
26 memset(c, 0, sizeof(*c));
27
28 if (sz) {
29 c->c_priv = xmalloc(sz);
30 memset(c->c_priv, 0, sz);
31 }
32
33 return c;
34 }
35
crypt_register(int type,uint8_t id,crypt_ctr ctr)36 void crypt_register(int type, uint8_t id, crypt_ctr ctr)
37 {
38 struct cipher_list *c = xmalloc(sizeof(*c));
39
40 c->c_type = type;
41 c->c_id = id;
42 c->c_ctr = ctr;
43 c->c_next = _ciphers.c_next;
44 _ciphers.c_next = c;
45 }
46
crypt_find_cipher(int type,unsigned int id)47 struct cipher_list *crypt_find_cipher(int type, unsigned int id)
48 {
49 struct cipher_list *c = _ciphers.c_next;
50
51 while (c) {
52 if (c->c_type == type && c->c_id == id)
53 return c;
54
55 c = c->c_next;
56 }
57
58 return NULL;
59 }
60