random.c revision 41cf421d9c6400a15b7c05a8f75a59121e759f6c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <locale.h>
#include <stdarg.h>
#include <cryptoutil.h>
#include <pthread.h>
static int random_fd = -1;
static int urandom_fd = -1;
static int random_seed_fd = -1;
static int urandom_seed_fd = -1;
/*
* Equivalent of open(2) insulated from EINTR.
* Also sets close-on-exec.
*/
int
{
int fd;
do {
break;
}
/* errno definitely set by failed open() */
return (fd);
}
/*
* Equivalent of read(2) insulated from EINTR.
*/
{
nread = 0;
continue;
}
break;
} else if (nread == 0) {
break;
}
}
}
/*
* Equivalent of write(2) insulated from EINTR.
*/
{
nwrite = 0;
continue;
}
break;
} else if (nwrite == 0) {
break;
}
}
}
/*
* Opens the random number generator devices if not already open.
* Always returns the opened fd of the device, or error.
*/
static int
{
(void) pthread_mutex_lock(mtx);
if (*fd < 0)
(void) pthread_mutex_unlock(mtx);
return (*fd);
}
static int
pkcs11_open_random(void)
{
}
static int
pkcs11_open_urandom(void)
{
}
static int
pkcs11_open_random_seed(void)
{
}
static int
pkcs11_open_urandom_seed(void)
{
}
/*
* Close the random number generator devices if already open.
*/
static void
{
(void) pthread_mutex_lock(mtx);
*fd = -1;
(void) pthread_mutex_unlock(mtx);
}
void
pkcs11_close_random(void)
{
}
void
pkcs11_close_urandom(void)
{
}
static void
pkcs11_close_random_seed(void)
{
}
void
{
}
/*
* Read from the random number generator devices.
*/
static size_t
{
size_t n;
(void) pthread_mutex_lock(mtx);
(void) pthread_mutex_unlock(mtx);
return (n);
}
static size_t
{
}
static size_t
{
}
/*
* Write to the random number generator devices.
*/
static size_t
{
size_t n;
(void) pthread_mutex_lock(mtx);
(void) pthread_mutex_unlock(mtx);
return (n);
}
static size_t
{
}
static size_t
{
}
/*
*/
int
{
int rv;
return (0);
/* Seeding error could mean it's not supported (errno = EACCES) */
if (pkcs11_open_random_seed() < 0)
return (-1);
rv = -1;
rv = 0;
return (rv);
}
/*
*/
int
{
int rv;
return (0);
/* Seeding error could mean it's not supported (errno = EACCES) */
if (pkcs11_open_urandom_seed() < 0)
return (-1);
rv = -1;
rv = 0;
return (rv);
}
/*
* Put the requested amount of random data into a preallocated buffer.
* Good for token key data, persistent objects.
*/
int
{
return (0);
if (pkcs11_open_random() < 0)
return (-1);
return (0);
return (-1);
}
/*
* Put the requested amount of random data into a preallocated buffer.
* Good for passphrase salts, initialization vectors.
*/
int
{
return (0);
if (pkcs11_open_urandom() < 0)
return (-1);
return (0);
return (-1);
}
/*
* Same as pkcs11_get_urandom but ensures non zero data.
*/
int
{
char extrarand[32];
size_t i = 0;
/* Start with some random data */
return (-1);
/* Walk through data replacing any 0 bytes with more random data */
while (i < dlen) {
if (((char *)dbuf)[i] != 0) {
i++;
continue;
}
if (bytesleft == 0) {
return (-1);
}
bytesleft--;
}
return (0);
}