예제 #1
0
int
kcf_rnd_get_bytes(uint8_t *ptr, size_t len, boolean_t noblock)
{
	extract_type_t how;
	int error;

	how = noblock ? NONBLOCK_EXTRACT : BLOCKING_EXTRACT;
	mutex_enter(&rndpool_lock);
	if ((error = rnd_get_bytes(ptr, len, how)) != 0)
		return (error);

	BUMP_RND_STATS(rs_rndOut, len);
	return (0);
}
예제 #2
0
int dc_wipe_init(wipe_ctx *ctx, void *hook, int max_size, int method, int cipher)
{
	char key[32];
	int  resl;

	do
	{
		zeroauto(ctx, sizeof(wipe_ctx));
		
		if (method > sizeof(wipe_modes) / sizeof(wipe_mode)) {
			resl = ST_INV_WIPE_MODE; break;
		}
		ctx->mode = wipe_modes[method];
		resl      = ST_NOMEM;

		if (ctx->mode != NULL) 
		{
			if ( (ctx->buff = mm_alloc(max_size, MEM_SECURE)) == NULL ) {
				break;
			}
			if ( (ctx->key = mm_alloc(sizeof(xts_key), MEM_SECURE)) == NULL ) {
				break;
			}
			/* generate random key */
			rnd_get_bytes(key, sizeof(key));
			xts_set_key(key, cipher, ctx->key);
		}
		ctx->hook = hook;
		ctx->size = max_size;
		resl      = ST_OK;
	} while (0);

	/* prevent leaks */
	zeroauto(key, sizeof(key));

	if (resl != ST_OK) {
		if (ctx->buff != NULL) { mm_free(ctx->buff); }
		if (ctx->key != NULL)  { mm_free(ctx->key); }
	}
	return resl;
}