/* -*-  Mode:C; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
/*
 * Copyright (C) 2004-2005 by the University of Southern California
 * $Id: scramble_crypt.h,v 1.1 2005/09/19 22:17:18 yuri Exp $
 *
 * 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

#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 (scramble_mac) {				\
					_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" /* XXX better use /dev/random */

typedef enum {
	SCRAMBLE_NONE		= 0x00,
	SCRAMBLE_MD5 		= 0x01,
	SCRAMBLE_BLOWFISH 	= 0x02,
	SCRAMBLE_AES 		= 0x03,
	SCRAMBLE_SHA		= 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;
} 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 uint32_t 	scramble_ip4		(uint32_t, int);
extern void		scramble_ip6		(struct in6_addr *, int);


#endif /* _SCRAMBLE_CRYPT_H */
