1 | /*
|
---|
2 | * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use
|
---|
5 | * this file except in compliance with the License. You can obtain a copy
|
---|
6 | * in the file LICENSE in the source distribution or at
|
---|
7 | * https://www.openssl.org/source/license.html
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef OPENSSL_KDF_H
|
---|
11 | # define OPENSSL_KDF_H
|
---|
12 | # pragma once
|
---|
13 |
|
---|
14 | # include <openssl/macros.h>
|
---|
15 | # ifndef OPENSSL_NO_DEPRECATED_3_0
|
---|
16 | # define HEADER_KDF_H
|
---|
17 | # endif
|
---|
18 |
|
---|
19 | # include <stdarg.h>
|
---|
20 | # include <stddef.h>
|
---|
21 | # include <openssl/types.h>
|
---|
22 | # include <openssl/core.h>
|
---|
23 |
|
---|
24 | # ifdef __cplusplus
|
---|
25 | extern "C" {
|
---|
26 | # endif
|
---|
27 |
|
---|
28 | int EVP_KDF_up_ref(EVP_KDF *kdf);
|
---|
29 | void EVP_KDF_free(EVP_KDF *kdf);
|
---|
30 | EVP_KDF *EVP_KDF_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
|
---|
31 | const char *properties);
|
---|
32 |
|
---|
33 | EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf);
|
---|
34 | void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
|
---|
35 | EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
|
---|
36 | const char *EVP_KDF_get0_description(const EVP_KDF *kdf);
|
---|
37 | int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
|
---|
38 | const char *EVP_KDF_get0_name(const EVP_KDF *kdf);
|
---|
39 | const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
|
---|
40 | const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
|
---|
41 |
|
---|
42 | void EVP_KDF_CTX_reset(EVP_KDF_CTX *ctx);
|
---|
43 | size_t EVP_KDF_CTX_get_kdf_size(EVP_KDF_CTX *ctx);
|
---|
44 | int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen,
|
---|
45 | const OSSL_PARAM params[]);
|
---|
46 | int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
|
---|
47 | int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
|
---|
48 | int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
|
---|
49 | const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
|
---|
50 | const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf);
|
---|
51 | const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf);
|
---|
52 | const OSSL_PARAM *EVP_KDF_CTX_gettable_params(EVP_KDF_CTX *ctx);
|
---|
53 | const OSSL_PARAM *EVP_KDF_CTX_settable_params(EVP_KDF_CTX *ctx);
|
---|
54 |
|
---|
55 | void EVP_KDF_do_all_provided(OSSL_LIB_CTX *libctx,
|
---|
56 | void (*fn)(EVP_KDF *kdf, void *arg),
|
---|
57 | void *arg);
|
---|
58 | int EVP_KDF_names_do_all(const EVP_KDF *kdf,
|
---|
59 | void (*fn)(const char *name, void *data),
|
---|
60 | void *data);
|
---|
61 |
|
---|
62 | # define EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND 0
|
---|
63 | # define EVP_KDF_HKDF_MODE_EXTRACT_ONLY 1
|
---|
64 | # define EVP_KDF_HKDF_MODE_EXPAND_ONLY 2
|
---|
65 |
|
---|
66 | #define EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV 65
|
---|
67 | #define EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI 66
|
---|
68 | #define EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV 67
|
---|
69 | #define EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI 68
|
---|
70 | #define EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV 69
|
---|
71 | #define EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI 70
|
---|
72 |
|
---|
73 | /**** The legacy PKEY-based KDF API follows. ****/
|
---|
74 |
|
---|
75 | # define EVP_PKEY_CTRL_TLS_MD (EVP_PKEY_ALG_CTRL)
|
---|
76 | # define EVP_PKEY_CTRL_TLS_SECRET (EVP_PKEY_ALG_CTRL + 1)
|
---|
77 | # define EVP_PKEY_CTRL_TLS_SEED (EVP_PKEY_ALG_CTRL + 2)
|
---|
78 | # define EVP_PKEY_CTRL_HKDF_MD (EVP_PKEY_ALG_CTRL + 3)
|
---|
79 | # define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 4)
|
---|
80 | # define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 5)
|
---|
81 | # define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 6)
|
---|
82 | # define EVP_PKEY_CTRL_HKDF_MODE (EVP_PKEY_ALG_CTRL + 7)
|
---|
83 | # define EVP_PKEY_CTRL_PASS (EVP_PKEY_ALG_CTRL + 8)
|
---|
84 | # define EVP_PKEY_CTRL_SCRYPT_SALT (EVP_PKEY_ALG_CTRL + 9)
|
---|
85 | # define EVP_PKEY_CTRL_SCRYPT_N (EVP_PKEY_ALG_CTRL + 10)
|
---|
86 | # define EVP_PKEY_CTRL_SCRYPT_R (EVP_PKEY_ALG_CTRL + 11)
|
---|
87 | # define EVP_PKEY_CTRL_SCRYPT_P (EVP_PKEY_ALG_CTRL + 12)
|
---|
88 | # define EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES (EVP_PKEY_ALG_CTRL + 13)
|
---|
89 |
|
---|
90 | # define EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND \
|
---|
91 | EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND
|
---|
92 | # define EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY \
|
---|
93 | EVP_KDF_HKDF_MODE_EXTRACT_ONLY
|
---|
94 | # define EVP_PKEY_HKDEF_MODE_EXPAND_ONLY \
|
---|
95 | EVP_KDF_HKDF_MODE_EXPAND_ONLY
|
---|
96 |
|
---|
97 | int EVP_PKEY_CTX_set_tls1_prf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
|
---|
98 |
|
---|
99 | int EVP_PKEY_CTX_set1_tls1_prf_secret(EVP_PKEY_CTX *pctx,
|
---|
100 | const unsigned char *sec, int seclen);
|
---|
101 |
|
---|
102 | int EVP_PKEY_CTX_add1_tls1_prf_seed(EVP_PKEY_CTX *pctx,
|
---|
103 | const unsigned char *seed, int seedlen);
|
---|
104 |
|
---|
105 | int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
|
---|
106 |
|
---|
107 | int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *ctx,
|
---|
108 | const unsigned char *salt, int saltlen);
|
---|
109 |
|
---|
110 | int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *ctx,
|
---|
111 | const unsigned char *key, int keylen);
|
---|
112 |
|
---|
113 | int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *ctx,
|
---|
114 | const unsigned char *info, int infolen);
|
---|
115 |
|
---|
116 | int EVP_PKEY_CTX_set_hkdf_mode(EVP_PKEY_CTX *ctx, int mode);
|
---|
117 | # define EVP_PKEY_CTX_hkdf_mode EVP_PKEY_CTX_set_hkdf_mode
|
---|
118 |
|
---|
119 | int EVP_PKEY_CTX_set1_pbe_pass(EVP_PKEY_CTX *ctx, const char *pass,
|
---|
120 | int passlen);
|
---|
121 |
|
---|
122 | int EVP_PKEY_CTX_set1_scrypt_salt(EVP_PKEY_CTX *ctx,
|
---|
123 | const unsigned char *salt, int saltlen);
|
---|
124 |
|
---|
125 | int EVP_PKEY_CTX_set_scrypt_N(EVP_PKEY_CTX *ctx, uint64_t n);
|
---|
126 |
|
---|
127 | int EVP_PKEY_CTX_set_scrypt_r(EVP_PKEY_CTX *ctx, uint64_t r);
|
---|
128 |
|
---|
129 | int EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX *ctx, uint64_t p);
|
---|
130 |
|
---|
131 | int EVP_PKEY_CTX_set_scrypt_maxmem_bytes(EVP_PKEY_CTX *ctx,
|
---|
132 | uint64_t maxmem_bytes);
|
---|
133 |
|
---|
134 |
|
---|
135 | # ifdef __cplusplus
|
---|
136 | }
|
---|
137 | # endif
|
---|
138 | #endif
|
---|