ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.C
(Generate patch)

Comparing gvpe/src/util.C (file contents):
Revision 1.25 by root, Tue Mar 8 17:33:31 2011 UTC vs.
Revision 1.28 by root, Thu Jan 9 08:15:05 2014 UTC

48 48
49#if ENABLE_PTHREADS 49#if ENABLE_PTHREADS
50# include <pthread.h> 50# include <pthread.h>
51#endif 51#endif
52 52
53#include <openssl/rand.h>
54
53#include "netcompat.h" 55#include "netcompat.h"
54 56
55#include "gettext.h" 57#include "gettext.h"
56#include "pidfile.h" 58#include "pidfile.h"
57#include "dropin.h" 59#include "dropin.h"
292 294
293#endif 295#endif
294 296
295/*****************************************************************************/ 297/*****************************************************************************/
296 298
299void hexdump (const char *header, void *data, int len)
300{
301 u8 *p = (u8 *)data;
302
303 printf ("%s:", header);
304
305 while (len--)
306 printf (" %02x", *p++);
307
308 printf ("\n");
309}
310
311/*****************************************************************************/
312
297#if ENABLE_HTTP_PROXY 313#if ENABLE_HTTP_PROXY
298// works like strdup 314// works like strdup
299u8 * 315u8 *
300base64_encode (const u8 *data, unsigned int len) 316base64_encode (const u8 *data, unsigned int len)
301{ 317{
340 356
341 return res; 357 return res;
342} 358}
343#endif 359#endif
344 360
361bool
362slow_memeq (const void *a, const void *b, int len)
363{
364 volatile const u8 *pa = (const u8 *)a;
365 volatile const u8 *pb = (const u8 *)b;
366 u8 diff = 0;
367
368 while (len--)
369 diff |= *pa++ ^ *pb++;
370
371 return !diff;
372}
373
345void 374void
346id2mac (unsigned int id, void *m) 375id2mac (unsigned int id, void *m)
347{ 376{
348 mac &p = *(mac *)m; 377 mac &p = *(mac *)m;
349 378
365 p[4] = 0xff; 394 p[4] = 0xff;
366 p[5] = 0xff; 395 p[5] = 0xff;
367 } 396 }
368} 397}
369 398
399/*****************************************************************************/
400
401void rand_fill (void *data, int len)
402{
403 int l = RAND_bytes ((unsigned char *)data, len);
404
405 if (l > 0)
406 return;
407 else if (l == 0)
408 slog (L_WARN, _("Not enough random entropy to generate secure keys. Using weaker pseudo-random session keys."));
409 else
410 fatal (_("RAND_bytes failed, aborting."));
411}
412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines