]>
Commit | Line | Data |
---|---|---|
1eff3485 | 1 | /* |
6738bf14 | 2 | * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. |
1eff3485 | 3 | * |
48f4ad77 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | |
1eff3485 DSH |
8 | */ |
9 | ||
10 | #ifndef HEADER_KDF_H | |
11 | # define HEADER_KDF_H | |
12 | ||
5a285add | 13 | # include <openssl/ossl_typ.h> |
52df25cf | 14 | # include <openssl/kdferr.h> |
5a285add | 15 | # ifdef __cplusplus |
1eff3485 | 16 | extern "C" { |
5a285add DM |
17 | # endif |
18 | ||
19 | # define EVP_KDF_PBKDF2 NID_id_pbkdf2 | |
20 | # define EVP_KDF_SCRYPT NID_id_scrypt | |
21 | # define EVP_KDF_TLS1_PRF NID_tls1_prf | |
22 | # define EVP_KDF_HKDF NID_hkdf | |
23 | ||
24 | EVP_KDF_CTX *EVP_KDF_CTX_new_id(int id); | |
25 | void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx); | |
26 | ||
27 | void EVP_KDF_reset(EVP_KDF_CTX *ctx); | |
28 | int EVP_KDF_ctrl(EVP_KDF_CTX *ctx, int cmd, ...); | |
29 | int EVP_KDF_vctrl(EVP_KDF_CTX *ctx, int cmd, va_list args); | |
30 | int EVP_KDF_ctrl_str(EVP_KDF_CTX *ctx, const char *type, const char *value); | |
31 | size_t EVP_KDF_size(EVP_KDF_CTX *ctx); | |
32 | int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen); | |
33 | ||
34 | ||
35 | # define EVP_KDF_CTRL_SET_PASS 0x01 /* unsigned char *, size_t */ | |
36 | # define EVP_KDF_CTRL_SET_SALT 0x02 /* unsigned char *, size_t */ | |
37 | # define EVP_KDF_CTRL_SET_ITER 0x03 /* int */ | |
38 | # define EVP_KDF_CTRL_SET_MD 0x04 /* EVP_MD * */ | |
39 | # define EVP_KDF_CTRL_SET_KEY 0x05 /* unsigned char *, size_t */ | |
40 | # define EVP_KDF_CTRL_SET_MAXMEM_BYTES 0x06 /* uint64_t */ | |
41 | # define EVP_KDF_CTRL_SET_TLS_SECRET 0x07 /* unsigned char *, size_t */ | |
42 | # define EVP_KDF_CTRL_RESET_TLS_SEED 0x08 | |
43 | # define EVP_KDF_CTRL_ADD_TLS_SEED 0x09 /* unsigned char *, size_t */ | |
44 | # define EVP_KDF_CTRL_RESET_HKDF_INFO 0x0a | |
45 | # define EVP_KDF_CTRL_ADD_HKDF_INFO 0x0b /* unsigned char *, size_t */ | |
46 | # define EVP_KDF_CTRL_SET_HKDF_MODE 0x0c /* int */ | |
47 | # define EVP_KDF_CTRL_SET_SCRYPT_N 0x0d /* uint64_t */ | |
48 | # define EVP_KDF_CTRL_SET_SCRYPT_R 0x0e /* uint32_t */ | |
49 | # define EVP_KDF_CTRL_SET_SCRYPT_P 0x0f /* uint32_t */ | |
50 | ||
51 | # define EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND 0 | |
52 | # define EVP_KDF_HKDF_MODE_EXTRACT_ONLY 1 | |
53 | # define EVP_KDF_HKDF_MODE_EXPAND_ONLY 2 | |
54 | ||
55 | ||
56 | /**** The legacy PKEY-based KDF API follows. ****/ | |
1eff3485 | 57 | |
d2139cf8 MC |
58 | # define EVP_PKEY_CTRL_TLS_MD (EVP_PKEY_ALG_CTRL) |
59 | # define EVP_PKEY_CTRL_TLS_SECRET (EVP_PKEY_ALG_CTRL + 1) | |
60 | # define EVP_PKEY_CTRL_TLS_SEED (EVP_PKEY_ALG_CTRL + 2) | |
61 | # define EVP_PKEY_CTRL_HKDF_MD (EVP_PKEY_ALG_CTRL + 3) | |
62 | # define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 4) | |
63 | # define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 5) | |
64 | # define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 6) | |
65 | # define EVP_PKEY_CTRL_HKDF_MODE (EVP_PKEY_ALG_CTRL + 7) | |
cefa762e JB |
66 | # define EVP_PKEY_CTRL_PASS (EVP_PKEY_ALG_CTRL + 8) |
67 | # define EVP_PKEY_CTRL_SCRYPT_SALT (EVP_PKEY_ALG_CTRL + 9) | |
68 | # define EVP_PKEY_CTRL_SCRYPT_N (EVP_PKEY_ALG_CTRL + 10) | |
69 | # define EVP_PKEY_CTRL_SCRYPT_R (EVP_PKEY_ALG_CTRL + 11) | |
70 | # define EVP_PKEY_CTRL_SCRYPT_P (EVP_PKEY_ALG_CTRL + 12) | |
71 | # define EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES (EVP_PKEY_ALG_CTRL + 13) | |
d2139cf8 | 72 | |
5a285add DM |
73 | # define EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND \ |
74 | EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND | |
75 | # define EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY \ | |
76 | EVP_KDF_HKDF_MODE_EXTRACT_ONLY | |
77 | # define EVP_PKEY_HKDEF_MODE_EXPAND_ONLY \ | |
78 | EVP_KDF_HKDF_MODE_EXPAND_ONLY | |
1eff3485 DSH |
79 | |
80 | # define EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) \ | |
81 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 82 | EVP_PKEY_CTRL_TLS_MD, 0, (void *)(md)) |
1eff3485 DSH |
83 | |
84 | # define EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, seclen) \ | |
85 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 86 | EVP_PKEY_CTRL_TLS_SECRET, seclen, (void *)(sec)) |
1eff3485 DSH |
87 | |
88 | # define EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seedlen) \ | |
89 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 90 | EVP_PKEY_CTRL_TLS_SEED, seedlen, (void *)(seed)) |
1eff3485 | 91 | |
aacfb134 AG |
92 | # define EVP_PKEY_CTX_set_hkdf_md(pctx, md) \ |
93 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 94 | EVP_PKEY_CTRL_HKDF_MD, 0, (void *)(md)) |
aacfb134 AG |
95 | |
96 | # define EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, saltlen) \ | |
97 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 98 | EVP_PKEY_CTRL_HKDF_SALT, saltlen, (void *)(salt)) |
aacfb134 AG |
99 | |
100 | # define EVP_PKEY_CTX_set1_hkdf_key(pctx, key, keylen) \ | |
101 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 102 | EVP_PKEY_CTRL_HKDF_KEY, keylen, (void *)(key)) |
aacfb134 AG |
103 | |
104 | # define EVP_PKEY_CTX_add1_hkdf_info(pctx, info, infolen) \ | |
105 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
37659ea4 | 106 | EVP_PKEY_CTRL_HKDF_INFO, infolen, (void *)(info)) |
aacfb134 | 107 | |
d2139cf8 MC |
108 | # define EVP_PKEY_CTX_hkdf_mode(pctx, mode) \ |
109 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
110 | EVP_PKEY_CTRL_HKDF_MODE, mode, NULL) | |
cefa762e JB |
111 | |
112 | # define EVP_PKEY_CTX_set1_pbe_pass(pctx, pass, passlen) \ | |
113 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
114 | EVP_PKEY_CTRL_PASS, passlen, (void *)(pass)) | |
115 | ||
116 | # define EVP_PKEY_CTX_set1_scrypt_salt(pctx, salt, saltlen) \ | |
117 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
118 | EVP_PKEY_CTRL_SCRYPT_SALT, saltlen, (void *)(salt)) | |
119 | ||
120 | # define EVP_PKEY_CTX_set_scrypt_N(pctx, n) \ | |
121 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
122 | EVP_PKEY_CTRL_SCRYPT_N, n) | |
123 | ||
124 | # define EVP_PKEY_CTX_set_scrypt_r(pctx, r) \ | |
125 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
126 | EVP_PKEY_CTRL_SCRYPT_R, r) | |
127 | ||
128 | # define EVP_PKEY_CTX_set_scrypt_p(pctx, p) \ | |
129 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
130 | EVP_PKEY_CTRL_SCRYPT_P, p) | |
131 | ||
132 | # define EVP_PKEY_CTX_set_scrypt_maxmem_bytes(pctx, maxmem_bytes) \ | |
133 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | |
134 | EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES, maxmem_bytes) | |
135 | ||
3e30fa0a | 136 | |
5a285add | 137 | # ifdef __cplusplus |
1eff3485 | 138 | } |
0cd0a820 | 139 | # endif |
1eff3485 | 140 | #endif |