curve: move taia related functions into own header
[netsniff-ng.git] / curve.h
blobc5ad8e88de7478dfb6e7c3ad98db8525a20e1954
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2011 - 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #ifndef CURVE_H
8 #define CURVE_H
10 #include <stdint.h>
11 #include <sys/time.h>
13 #include "locking.h"
14 #include "built_in.h"
15 #include "ioops.h"
16 #include "rnd.h"
17 #include "taia.h"
18 #include "crypto.h"
20 static struct taia tolerance_taia = {
21 .sec.x = 0,
22 .nano = 700000000ULL,
23 .atto = 0,
26 struct curve25519_proto {
27 unsigned char enonce[crypto_box_noncebytes] __aligned_16;
28 unsigned char dnonce[crypto_box_noncebytes] __aligned_16;
29 unsigned char key[crypto_box_noncebytes] __aligned_16;
32 struct curve25519_struct {
33 unsigned char *enc_buf;
34 unsigned char *dec_buf;
35 size_t enc_buf_size;
36 size_t dec_buf_size;
37 struct spinlock enc_lock;
38 struct spinlock dec_lock;
41 extern void curve25519_selftest(void);
42 extern void curve25519_alloc_or_maybe_die(struct curve25519_struct *curve);
43 extern void curve25519_free(void *curve);
44 extern int curve25519_pubkey_hexparse_32(unsigned char *bin, size_t blen, const char *ascii, size_t alen);
45 extern int curve25519_proto_init(struct curve25519_proto *proto, unsigned char *pubkey_remote, size_t len,
46 char *home, int server);
47 extern ssize_t curve25519_encode(struct curve25519_struct *curve, struct curve25519_proto *proto,
48 unsigned char *plaintext, size_t size, unsigned char **chipertext);
49 extern ssize_t curve25519_decode(struct curve25519_struct *curve, struct curve25519_proto *proto,
50 unsigned char *chipertext, size_t size, unsigned char **plaintext,
51 struct taia *arrival_taia);
53 static inline int is_good_taia(struct taia *arrival_taia, struct taia *packet_taia)
55 int is_ts_good = 0;
56 struct taia sub_res;
58 if (taia_less(arrival_taia, packet_taia)) {
59 taia_sub(&sub_res, packet_taia, arrival_taia);
60 if (taia_less(&sub_res, &tolerance_taia))
61 is_ts_good = 1;
62 else
63 is_ts_good = 0;
64 } else {
65 taia_sub(&sub_res, arrival_taia, packet_taia);
66 if (taia_less(&sub_res, &tolerance_taia))
67 is_ts_good = 1;
68 else
69 is_ts_good = 0;
72 return is_ts_good;
75 #endif /* CURVE_H */