--- gvpe/src/util.h 2003/10/16 14:12:00 1.10 +++ gvpe/src/util.h 2005/03/18 01:53:05 1.14 @@ -2,9 +2,11 @@ util.h -- process management and other utility functions Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003 Marc Lehmann + 2003 Marc Lehmann - This program is free software; you can redistribute it and/or modify + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -15,14 +17,14 @@ 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 + along with gvpe; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef UTIL_H__ #define UTIL_H__ -#include "gettext.h" +#include #include "slog.h" #include "iom.h" @@ -43,15 +45,12 @@ 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] == '/') +/*****************************************************************************/ + typedef u8 mac[6]; extern void id2mac (unsigned int id, void *m); @@ -117,5 +116,27 @@ 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