/* If we don't have gnutls_rnd(), we will generate a less cryptographically
* strong master buf from /dev/urandom.
*/
- if ((ret = virRandomBytes(buf, nbytes)) < 0) {
+ if ((ret = virRandomBytes(buf, nbytes))) {
virReportSystemError(ret, "%s", _("failed to generate byte stream"));
VIR_FREE(buf);
return NULL;
*
* Generate a stream of random bytes from /dev/urandom
* into @buf of size @buflen
+ *
+ * Returns 0 on success or an errno on failure
*/
int
virRandomBytes(unsigned char *buf,
VIR_ALLOC_N(iv, ivlen) < 0)
goto cleanup;
- if (virRandomBytes(enckey, enckeylen) < 0 ||
- virRandomBytes(iv, ivlen) < 0)
+ if (virRandomBytes(enckey, enckeylen) ||
+ virRandomBytes(iv, ivlen)) {
+ fprintf(stderr, "Failed to generate random bytes\n");
goto cleanup;
+ }
if (virCryptoEncryptData(data->algorithm, enckey, enckeylen, iv, ivlen,
data->input, data->inputlen,
if (VIR_ALLOC_N(data, datalen) < 0)
return -1;
- if (virRandomBytes(data, datalen) < 0) {
+ if (virRandomBytes(data, datalen)) {
fprintf(stderr, "Failed to generate random bytes");
goto cleanup;
}