list_t * entry (char *host, int sock, int flags) { list_t *p = xmalloc (sizeof *p); p->host = xstrdup (host); #if WITH_SSL p->ssl = flags & 1 ? SSL_new (client) : SSL_new (server); SSL_set_fd (p->ssl, sock); #else p->sock = sock; gc_cipher_open (GC_AES256, GC_STREAM, &p->cipher); mpz_t my_num; mpz_init (my_num); char *key = xcalloc (len, sizeof *key); pthread_cleanup_push (free, key); gc_random (key, len); mpz_import (my_num, len, 1, 1, 1, 0, key); mpz_t sent; mpz_init_set (sent, base); mpz_powm (sent, sent, my_num, prime); char *buff = xcalloc (len, sizeof *buff); pthread_cleanup_push (free, buff); mpz_export (buff, NULL, 1, 1, 1, 0, sent); if (send (sock, buff, len, 0) < 0) error (1, errno, "Failed to perform handshake"); if (recv (sock, buff, len, 0) < 0) error (1, errno, "Failed to perform handshake"); mpz_import (sent, len, 1, 1, 1, 0, buff); pthread_cleanup_pop (1); mpz_powm (sent, sent, my_num, prime); mpz_export (key, NULL, 1, 1, 1, 0, sent); gc_cipher_setkey (p->cipher, len, key); pthread_cleanup_pop (1); #endif /* WITH_SSL */ return p; }
int RAND_bytes (unsigned char *buf, int num) { gc_random (buf, num); return 1; }
/** * gsasl_random: * @data: output array to be filled with strong random data. * @datalen: size of output array. * * Store cryptographically strong random data of given size in the * provided buffer. * * Return value: Returns %GSASL_OK iff successful. **/ int gsasl_random (char *data, size_t datalen) { return gc_random (data, datalen); }