File Index
Files and directories
Sign in
FILE

drbg.h

File preview with syntax highlighting.

linux-6.19.14/include/crypto/internal/drbg.h C
 1/* SPDX-License-Identifier: GPL-2.0 */
 2
 3/*
 4 * NIST SP800-90A DRBG derivation function
 5 *
 6 * Copyright (C) 2014, Stephan Mueller <smueller@chronox.de>
 7 */
 8
 9#ifndef _INTERNAL_DRBG_H
10#define _INTERNAL_DRBG_H
11
12/*
13 * Convert an integer into a byte representation of this integer.
14 * The byte representation is big-endian
15 *
16 * @val value to be converted
17 * @buf buffer holding the converted integer -- caller must ensure that
18 *      buffer size is at least 32 bit
19 */
20static inline void drbg_cpu_to_be32(__u32 val, unsigned char *buf)
21{
22	struct s {
23		__be32 conv;
24	};
25	struct s *conversion = (struct s *)buf;
26
27	conversion->conv = cpu_to_be32(val);
28}
29
30/*
31 * Concatenation Helper and string operation helper
32 *
33 * SP800-90A requires the concatenation of different data. To avoid copying
34 * buffers around or allocate additional memory, the following data structure
35 * is used to point to the original memory with its size. In addition, it
36 * is used to build a linked list. The linked list defines the concatenation
37 * of individual buffers. The order of memory block referenced in that
38 * linked list determines the order of concatenation.
39 */
40struct drbg_string {
41	const unsigned char *buf;
42	size_t len;
43	struct list_head list;
44};
45
46static inline void drbg_string_fill(struct drbg_string *string,
47				    const unsigned char *buf, size_t len)
48{
49	string->buf = buf;
50	string->len = len;
51	INIT_LIST_HEAD(&string->list);
52}
53
54#endif //_INTERNAL_DRBG_H
~/ Read-only file preview.