/*
* 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 <sys/sysmacros.h>
#include <sys/machsystm.h>
#include <sys/hypervisor_api.h>
#include <rng/fips_random.h>
/* n must be a power of 2 */
/*
* Policy. ENTROPY_STARVATION is the maximum number of calls each
* FIPS instance will accept without successfully getting more
* entropy. It needs to be large enough to allow RNG operations to
* not stall because of health checks, etc. But we don't want it too
* large. FIPS 186-2 change 1 (5 October 2001) states that no more
* that 2,000,000 DSA signatures (done using this algorithm) should be
* done without reseeding. We make sure we add 64 bits of entropy at
* most every 10000 operations, hence we will have stirred in 160 bits
* of entropy at most once every 30000 operations. Normally, we stir
* in 64 bits of entropy for every number generated.
*/
int
{
int i;
int rv;
union {
} entropy = {0};
/*
* Since in the new scheme of things, the RNG latency
* will be high on reads after the first, we get just
* one word of entropy per call.
*/
sizeof (uint64_t))) != 0) {
/*
* If all rngs have failed, dispatch task to unregister
* from kcf and put the driver in an error state. If
* recoverable errors persist, a configuration retry
* will be initiated.
*/
return (EIO);
}
/* Failure with possible recovery */
}
/*
* The idea here is that a Niagara2 chip is highly
* parallel, with many strands. If we have just one
* instance of the FIPS data, then only one FIPS
* computation can happen at a time, serializeing all
* the RNG stuff. So we make N2RNG_FIPS_INSTANCES,
* and use them round-robin, with the counter being
* n2rng->n_frs.fips_round_robin_j. We increment the
* counter with an atomic op, avoiding having to have
* a global muxtex. The atomic ops are also
* significantly faster than mutexes. The mutex is
* put inside the loop, otherwise one thread reading
* many blocks could stall all other strands.
*/
/*
* If we did not get any entropy, entropyword
* is zero. We get a false positive with
* probablitity 2^-64. It's not worth a few
* extra stores and tests eliminate the false
* positive.
*/
return (EIO);
}
} else {
frsp->entropyhunger = 0;
}
/* nbytes - i is bytes to go */
}
/* Zeroize sensitive information */
return (0);
}
/*
* Initializes one FIPS RNG instance. Must be called once for each
* instance.
*/
int
{
/*
* All FIPS-approved algorithms will operate as cryptograpic
* quality PRNGs even if there is no entropy source. (In
* fact, this the only one that accepts entropy on the fly.)
* One motivation for this is that they system keeps on
* delivering cryptographic quality random numbers, even if
* the entropy source fails.
*/
int rv;
if (rv) {
return (rv);
}
frsp->entropyhunger = 0;
/* compute the first (compare only) random value */
return (0);
}
void
{
/*
* Zeroise fips data. Not really necessary, since the
* algorithm has backtracking resistance, but do it anyway.
*/
}