source: tools/traceanon/Anon.h @ 684a21c

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformance
Last change on this file since 684a21c was cb075c5, checked in by Shane Alcock <salcock@…>, 5 years ago

Fix bug where traceanon would not build with newer versions
of libssl (>= 1.1.0).

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26
27
28#ifndef WDCAP_ANON_H
29#define WDCAP_ANON_H
30
31#include "config.h"
32#include <sys/types.h>
33#include <inttypes.h>
34
35
36class Anonymiser {
37public:
38    Anonymiser();
39    virtual ~Anonymiser()  {};
40
41    virtual uint32_t anonIPv4(uint32_t orig) = 0;
42    virtual void anonIPv6(uint8_t *orig, uint8_t *result) = 0;
43
44};
45
46class PrefixSub: public Anonymiser {
47public:
48    PrefixSub(const char *ipv4_key, const char *ipv6_key);
49    ~PrefixSub();
50    uint32_t anonIPv4(uint32_t orig);
51    void anonIPv6(uint8_t *orig, uint8_t *result);
52
53private:
54    uint32_t ipv4_prefix;
55    uint32_t ipv4_mask;
56
57    uint8_t ipv6_prefix[16];
58    uint8_t ipv6_mask[16];
59
60};
61
62#ifdef HAVE_LIBCRYPTO
63#include <openssl/evp.h>
64#include <map>
65
66typedef std::map<uint32_t, uint32_t> IPv4AnonCache;
67typedef std::map<uint64_t, uint64_t> IPv6AnonCache;
68
69class CryptoAnon : public Anonymiser {
70public:
71    CryptoAnon(uint8_t *key, uint8_t len, uint8_t cachebits);
72    ~CryptoAnon();
73
74    uint32_t anonIPv4(uint32_t orig);
75    void anonIPv6(uint8_t *orig, uint8_t *result);
76
77
78private:
79    uint8_t padding[16];
80    uint8_t key[16];
81    uint8_t cachebits;
82
83    IPv4AnonCache *ipv4_cache;
84    IPv6AnonCache *ipv6_cache;
85
86    uint32_t recent_ipv4_cache[2][2];
87    const EVP_CIPHER *cipher;
88    EVP_CIPHER_CTX *ctx;
89
90    uint32_t encrypt32Bits(uint32_t orig, uint8_t start, uint8_t stop,
91            uint32_t res);
92    uint64_t encrypt64Bits(uint64_t orig); 
93    uint32_t lookupv4Cache(uint32_t prefix);
94    uint64_t lookupv6Cache(uint64_t prefix);
95
96};
97#endif
98
99#endif
100// vim: set sw=4 tabstop=4 softtabstop=4 expandtab :
Note: See TracBrowser for help on using the repository browser.