summaryrefslogtreecommitdiffstats
path: root/src/cryptopANT.h
blob: 8f596ff14470ff869ad62744d42566bd99e00e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* -*-  Mode:C; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
 * Copyright (C) 2004-2024 by the University of Southern California
 * $Id: c23494984e1ae44af55668feda8232282c9473d0 $
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 */


#ifndef _SCRAMBLE_CRYPT_H
#define _SCRAMBLE_CRYPT_H

#ifdef __cplusplus
extern "C" {
#endif

#define ETHER_ADDR_LEN		6
#define ETHER_VLAN_LEN		2

#define _XOR16(a, b, i)         (((uint16_t *)(a))[i] ^= ((uint16_t *)(b))[i])
#define _XOR32(a, b, i)         (((uint32_t *)(a))[i] ^= ((uint32_t *)(b))[i])

#define SCRAMBLE_ETHER_ADDR(a)  if (1) {     \
	_XOR32(a, scramble_ether_addr, 0);   \
	_XOR16(a, scramble_ether_addr, 2);   \
    }

#define SCRAMBLE_ETHER_VLAN(v)	((v) ^= scramble_ether_vlan);

#define SCRAMBLE_RANDOM_DEV	"/dev/urandom" 

typedef enum {
	SCRAMBLE_NONE		= 0x00,
	SCRAMBLE_MD5 		= 0x01,
	SCRAMBLE_BLOWFISH 	= 0x02,
	SCRAMBLE_AES 		= 0x03,
	SCRAMBLE_SHA1		= 0x04
} scramble_crypt_t;

typedef struct {
	scramble_crypt_t	c4;
	scramble_crypt_t	c6;
	u_char			*key;
	int			klen;
	u_char			*pad;
	int			plen;
	u_char			*mac;
	int			mlen;
	u_char			*iv;
	int			ivlen;	
} scramble_state_t;

/* external vars exported by mac scrambling macros */
extern uint8_t			scramble_ether_addr[ETHER_ADDR_LEN];
extern uint16_t			scramble_ether_vlan;
extern int		    	scramble_mac;		/* 0/1 */

/* public functions */
extern scramble_crypt_t scramble_crypto_ip4	(void);
extern scramble_crypt_t scramble_crypto_ip6	(void);
extern scramble_crypt_t	scramble_name2type	(const char *);
extern const char*	scramble_type2name	(scramble_crypt_t);
extern int		scramble_newkey		(u_char *, int);
extern int		scramble_newpad		(u_char *, int);
extern int		scramble_newmac		(u_char *, int);
extern int		scramble_readstate	(const char *, scramble_state_t *);
extern int		scramble_savestate	(const char *, const scramble_state_t *);
extern int		scramble_init		(const scramble_state_t *s);
extern int		scramble_init_from_file	(const char *, scramble_crypt_t, scramble_crypt_t, int *);
extern void             scramble_cleanup        ();
extern uint32_t 	scramble_ip4		(uint32_t, int);
extern uint32_t 	unscramble_ip4		(uint32_t, int);
extern void		scramble_ip6		(struct in6_addr *, int);
extern void		unscramble_ip6		(struct in6_addr *, int);

#ifdef __cplusplus
}
#endif

#endif /* _SCRAMBLE_CRYPT_H */