1f9f848faSopenharmony_ci/*-
2f9f848faSopenharmony_ci * Copyright (c) 2000-2015 Mark R V Murray
3f9f848faSopenharmony_ci * All rights reserved.
4f9f848faSopenharmony_ci *
5f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without
6f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions
7f9f848faSopenharmony_ci * are met:
8f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
9f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer
10f9f848faSopenharmony_ci *    in this position and unchanged.
11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
12f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
13f9f848faSopenharmony_ci *    documentation and/or other materials provided with the distribution.
14f9f848faSopenharmony_ci *
15f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16f9f848faSopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17f9f848faSopenharmony_ci * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18f9f848faSopenharmony_ci * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19f9f848faSopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20f9f848faSopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21f9f848faSopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22f9f848faSopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23f9f848faSopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24f9f848faSopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25f9f848faSopenharmony_ci */
26f9f848faSopenharmony_ci
27f9f848faSopenharmony_ci#ifndef SYS_DEV_RANDOM_HASH_H_INCLUDED
28f9f848faSopenharmony_ci#define	SYS_DEV_RANDOM_HASH_H_INCLUDED
29f9f848faSopenharmony_ci
30f9f848faSopenharmony_ci#include <dev/random/uint128.h>
31f9f848faSopenharmony_ci
32f9f848faSopenharmony_ci#ifndef _KERNEL
33f9f848faSopenharmony_ci#define	__read_frequently
34f9f848faSopenharmony_ci#endif
35f9f848faSopenharmony_ci
36f9f848faSopenharmony_ci/* Keys are formed from cipher blocks */
37f9f848faSopenharmony_ci#define	RANDOM_KEYSIZE		32	/* (in bytes) == 256 bits */
38f9f848faSopenharmony_ci#define	RANDOM_KEYSIZE_WORDS	(RANDOM_KEYSIZE/sizeof(uint32_t))
39f9f848faSopenharmony_ci#define	RANDOM_BLOCKSIZE	16	/* (in bytes) == 128 bits */
40f9f848faSopenharmony_ci#define	RANDOM_BLOCKSIZE_WORDS	(RANDOM_BLOCKSIZE/sizeof(uint32_t))
41f9f848faSopenharmony_ci#define	RANDOM_KEYS_PER_BLOCK	(RANDOM_KEYSIZE/RANDOM_BLOCKSIZE)
42f9f848faSopenharmony_ci
43f9f848faSopenharmony_ci/* The size of the zero block portion used to form H_d(m) */
44f9f848faSopenharmony_ci#define	RANDOM_ZERO_BLOCKSIZE	64	/* (in bytes) == 512 zero bits */
45f9f848faSopenharmony_ci
46f9f848faSopenharmony_cistruct randomdev_hash {
47f9f848faSopenharmony_ci	SHA256_CTX	sha;
48f9f848faSopenharmony_ci};
49f9f848faSopenharmony_ci
50f9f848faSopenharmony_cistruct randomdev_key {
51f9f848faSopenharmony_ci	keyInstance key;	/* Key schedule */
52f9f848faSopenharmony_ci	cipherInstance cipher;	/* Rijndael internal */
53f9f848faSopenharmony_ci};
54f9f848faSopenharmony_ci
55f9f848faSopenharmony_ci
56f9f848faSopenharmony_ciextern bool random_chachamode;
57f9f848faSopenharmony_ci
58f9f848faSopenharmony_civoid randomdev_hash_init(struct randomdev_hash *);
59f9f848faSopenharmony_civoid randomdev_hash_iterate(struct randomdev_hash *, const void *, size_t);
60f9f848faSopenharmony_civoid randomdev_hash_finish(struct randomdev_hash *, void *);
61f9f848faSopenharmony_civoid randomdev_encrypt_init(struct randomdev_key *, const void *);
62f9f848faSopenharmony_civoid randomdev_encrypt(struct randomdev_key *context, const void *, void *, u_int);
63f9f848faSopenharmony_ci
64f9f848faSopenharmony_ci#endif /* SYS_DEV_RANDOM_HASH_H_INCLUDED */
65