/*
* 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 <string.h>
#include <fcntl.h>
#include <errno.h>
#include <locale.h>
#include <cryptoutil.h>
/*
* Read file into buffer. Used to read raw key data or initialization
* vector data. Buffer must be freed by caller using free().
*
* If file is a regular file, entire file is read and dlen is set
* to the number of bytes read. Otherwise, dlen should first be set
* to the number of bytes requested and will be reset to actual number
* of bytes returned.
*
* Return 0 on success and errno on error.
*/
int
{
int ret = 0;
return (-1);
goto error;
}
goto error;
}
/* read the entire regular file */
plain_file = B_TRUE;
} else {
/* read requested bytes from special file */
}
if (filesize == 0) {
/*
* for decrypt this is an error; for digest this is ok;
* make it ok here but also set dbuf = NULL and dlen = 0
* to indicate there was no data to read and caller can
* retranslate that to an error if it wishes.
*/
*dlen = 0;
return (0);
}
goto error;
}
if (plain_file) {
/* either it got read or it didn't */
goto error;
}
} else {
/* reading from special file may need some coaxing */
/* keep reading it's going well */
errno = 0;
continue;
}
/* might have to be good enough for caller */
break;
/* anything else is an error */
if (errno) {
gettext("error reading file %s: %s"),
goto error;
}
}
/* reset to actual number of bytes read */
}
return (0);
}
if (fd != -1)
return (ret);
}