--- gvpe/src/util.h 2003/04/02 05:15:00 1.6 +++ gvpe/src/util.h 2004/05/10 20:13:10 1.12 @@ -2,7 +2,7 @@ util.h -- process management and other utility functions Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003 Marc Lehmannn + 2003 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,8 +22,12 @@ #ifndef UTIL_H__ #define UTIL_H__ +#include + +#include "gettext.h" + +#include "slog.h" #include "iom.h" -#include "device.h" /* * check for an existing vped for this net, and write pid to pidfile @@ -41,29 +45,17 @@ extern int detach (int do_detach); /* - * Set all files and paths according to netname - */ -extern void make_names (void); - -/* * check wether the given path is an absolute pathname */ #define ABSOLUTE_PATH(c) ((c)[0] == '/') -static inline void -id2mac (unsigned int id, void *m) -{ - mac &p = *(mac *)m; +/*****************************************************************************/ - p[0] = 0xfe; - p[1] = 0xfd; - p[2] = 0x80; - p[3] = 0x00; - p[4] = id >> 8; - p[5] = id; -} +typedef u8 mac[6]; -#define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5]) +extern void id2mac (unsigned int id, void *m); + +#define mac2id(p) ((p)[0] & 0x01 ? 0 : ((p)[4] << 8) | (p)[5]) struct sliding_window { u32 v[(WINDOWSIZE + 31) / 32]; @@ -120,5 +112,31 @@ // run a shell script (or actually an external program). void run_script (const run_script_cb &cb, bool wait); +#if ENABLE_HTTP_PROXY +u8 *base64_encode (const u8 *data, unsigned int len); +#endif + +/*****************************************************************************/ + +typedef u8 rsaclear[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data; +typedef u8 rsacrypt[RSA_KEYLEN]; // encrypted challenge + +static inline void +rsa_encrypt (RSA *key, const rsaclear &chg, rsacrypt &encr) +{ + if (RSA_public_encrypt (sizeof chg, + (unsigned char *)&chg, (unsigned char *)&encr, + key, RSA_PKCS1_OAEP_PADDING) < 0) + fatal ("RSA_public_encrypt error"); +} + +static inline bool +rsa_decrypt (RSA *key, const rsacrypt &encr, rsaclear &chg) +{ + return RSA_private_decrypt (sizeof encr, + (unsigned char *)&encr, (unsigned char *)&chg, + key, RSA_PKCS1_OAEP_PADDING) > 0; +} + #endif