-/* crypto/bio/bf_nbio.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
#include <stdio.h>
#include <errno.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
#include <openssl/rand.h>
#include <openssl/bio.h>
{
NBIO_TEST *nt;
- if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST))))
+ if ((nt = OPENSSL_zalloc(sizeof(*nt))) == NULL)
return (0);
nt->lrn = -1;
nt->lwn = -1;
bi->ptr = (char *)nt;
bi->init = 1;
- bi->flags = 0;
return (1);
}
{
if (a == NULL)
return (0);
- if (a->ptr != NULL)
- OPENSSL_free(a->ptr);
+ OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;
a->flags = 0;
static int nbiof_read(BIO *b, char *out, int outl)
{
int ret = 0;
-#if 1
int num;
unsigned char n;
-#endif
if (out == NULL)
return (0);
return (0);
BIO_clear_retry_flags(b);
-#if 1
- RAND_pseudo_bytes(&n, 1);
+ if (RAND_bytes(&n, 1) <= 0)
+ return -1;
num = (n & 0x07);
if (outl > num)
if (num == 0) {
ret = -1;
BIO_set_retry_read(b);
- } else
-#endif
- {
+ } else {
ret = BIO_read(b->next_bio, out, outl);
if (ret < 0)
BIO_copy_next_retry(b);
BIO_clear_retry_flags(b);
-#if 1
if (nt->lwn > 0) {
num = nt->lwn;
nt->lwn = 0;
} else {
- RAND_pseudo_bytes(&n, 1);
+ if (RAND_bytes(&n, 1) <= 0)
+ return -1;
num = (n & 7);
}
if (num == 0) {
ret = -1;
BIO_set_retry_write(b);
- } else
-#endif
- {
+ } else {
ret = BIO_write(b->next_bio, in, inl);
if (ret < 0) {
BIO_copy_next_retry(b);