diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/kdf/hkdf.c | 352 | ||||
| -rw-r--r-- | src/lib/libcrypto/kdf/kdf.h | 97 | ||||
| -rw-r--r-- | src/lib/libcrypto/kdf/kdf_err.c | 67 | ||||
| -rw-r--r-- | src/lib/libcrypto/kdf/kdferr.h | 55 |
4 files changed, 571 insertions, 0 deletions
diff --git a/src/lib/libcrypto/kdf/hkdf.c b/src/lib/libcrypto/kdf/hkdf.c new file mode 100644 index 0000000000..25bf4b729f --- /dev/null +++ b/src/lib/libcrypto/kdf/hkdf.c | |||
| @@ -0,0 +1,352 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. | ||
| 3 | * | ||
| 4 | * Licensed under the OpenSSL license (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 | #include <stdlib.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <openssl/hmac.h> | ||
| 13 | #include <openssl/kdf.h> | ||
| 14 | #include <openssl/evp.h> | ||
| 15 | #include "internal/cryptlib.h" | ||
| 16 | #include "crypto/evp.h" | ||
| 17 | |||
| 18 | #define HKDF_MAXBUF 1024 | ||
| 19 | |||
| 20 | static unsigned char *HKDF(const EVP_MD *evp_md, | ||
| 21 | const unsigned char *salt, size_t salt_len, | ||
| 22 | const unsigned char *key, size_t key_len, | ||
| 23 | const unsigned char *info, size_t info_len, | ||
| 24 | unsigned char *okm, size_t okm_len); | ||
| 25 | |||
| 26 | static unsigned char *HKDF_Extract(const EVP_MD *evp_md, | ||
| 27 | const unsigned char *salt, size_t salt_len, | ||
| 28 | const unsigned char *key, size_t key_len, | ||
| 29 | unsigned char *prk, size_t *prk_len); | ||
| 30 | |||
| 31 | static unsigned char *HKDF_Expand(const EVP_MD *evp_md, | ||
| 32 | const unsigned char *prk, size_t prk_len, | ||
| 33 | const unsigned char *info, size_t info_len, | ||
| 34 | unsigned char *okm, size_t okm_len); | ||
| 35 | |||
| 36 | typedef struct { | ||
| 37 | int mode; | ||
| 38 | const EVP_MD *md; | ||
| 39 | unsigned char *salt; | ||
| 40 | size_t salt_len; | ||
| 41 | unsigned char *key; | ||
| 42 | size_t key_len; | ||
| 43 | unsigned char info[HKDF_MAXBUF]; | ||
| 44 | size_t info_len; | ||
| 45 | } HKDF_PKEY_CTX; | ||
| 46 | |||
| 47 | static int pkey_hkdf_init(EVP_PKEY_CTX *ctx) | ||
| 48 | { | ||
| 49 | HKDF_PKEY_CTX *kctx; | ||
| 50 | |||
| 51 | if ((kctx = OPENSSL_zalloc(sizeof(*kctx))) == NULL) { | ||
| 52 | KDFerr(KDF_F_PKEY_HKDF_INIT, ERR_R_MALLOC_FAILURE); | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | ctx->data = kctx; | ||
| 57 | |||
| 58 | return 1; | ||
| 59 | } | ||
| 60 | |||
| 61 | static void pkey_hkdf_cleanup(EVP_PKEY_CTX *ctx) | ||
| 62 | { | ||
| 63 | HKDF_PKEY_CTX *kctx = ctx->data; | ||
| 64 | OPENSSL_clear_free(kctx->salt, kctx->salt_len); | ||
| 65 | OPENSSL_clear_free(kctx->key, kctx->key_len); | ||
| 66 | OPENSSL_cleanse(kctx->info, kctx->info_len); | ||
| 67 | OPENSSL_free(kctx); | ||
| 68 | } | ||
| 69 | |||
| 70 | static int pkey_hkdf_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) | ||
| 71 | { | ||
| 72 | HKDF_PKEY_CTX *kctx = ctx->data; | ||
| 73 | |||
| 74 | switch (type) { | ||
| 75 | case EVP_PKEY_CTRL_HKDF_MD: | ||
| 76 | if (p2 == NULL) | ||
| 77 | return 0; | ||
| 78 | |||
| 79 | kctx->md = p2; | ||
| 80 | return 1; | ||
| 81 | |||
| 82 | case EVP_PKEY_CTRL_HKDF_MODE: | ||
| 83 | kctx->mode = p1; | ||
| 84 | return 1; | ||
| 85 | |||
| 86 | case EVP_PKEY_CTRL_HKDF_SALT: | ||
| 87 | if (p1 == 0 || p2 == NULL) | ||
| 88 | return 1; | ||
| 89 | |||
| 90 | if (p1 < 0) | ||
| 91 | return 0; | ||
| 92 | |||
| 93 | if (kctx->salt != NULL) | ||
| 94 | OPENSSL_clear_free(kctx->salt, kctx->salt_len); | ||
| 95 | |||
| 96 | kctx->salt = OPENSSL_memdup(p2, p1); | ||
| 97 | if (kctx->salt == NULL) | ||
| 98 | return 0; | ||
| 99 | |||
| 100 | kctx->salt_len = p1; | ||
| 101 | return 1; | ||
| 102 | |||
| 103 | case EVP_PKEY_CTRL_HKDF_KEY: | ||
| 104 | if (p1 < 0) | ||
| 105 | return 0; | ||
| 106 | |||
| 107 | if (kctx->key != NULL) | ||
| 108 | OPENSSL_clear_free(kctx->key, kctx->key_len); | ||
| 109 | |||
| 110 | kctx->key = OPENSSL_memdup(p2, p1); | ||
| 111 | if (kctx->key == NULL) | ||
| 112 | return 0; | ||
| 113 | |||
| 114 | kctx->key_len = p1; | ||
| 115 | return 1; | ||
| 116 | |||
| 117 | case EVP_PKEY_CTRL_HKDF_INFO: | ||
| 118 | if (p1 == 0 || p2 == NULL) | ||
| 119 | return 1; | ||
| 120 | |||
| 121 | if (p1 < 0 || p1 > (int)(HKDF_MAXBUF - kctx->info_len)) | ||
| 122 | return 0; | ||
| 123 | |||
| 124 | memcpy(kctx->info + kctx->info_len, p2, p1); | ||
| 125 | kctx->info_len += p1; | ||
| 126 | return 1; | ||
| 127 | |||
| 128 | default: | ||
| 129 | return -2; | ||
| 130 | |||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | static int pkey_hkdf_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, | ||
| 135 | const char *value) | ||
| 136 | { | ||
| 137 | if (strcmp(type, "mode") == 0) { | ||
| 138 | int mode; | ||
| 139 | |||
| 140 | if (strcmp(value, "EXTRACT_AND_EXPAND") == 0) | ||
| 141 | mode = EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND; | ||
| 142 | else if (strcmp(value, "EXTRACT_ONLY") == 0) | ||
| 143 | mode = EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY; | ||
| 144 | else if (strcmp(value, "EXPAND_ONLY") == 0) | ||
| 145 | mode = EVP_PKEY_HKDEF_MODE_EXPAND_ONLY; | ||
| 146 | else | ||
| 147 | return 0; | ||
| 148 | |||
| 149 | return EVP_PKEY_CTX_hkdf_mode(ctx, mode); | ||
| 150 | } | ||
| 151 | |||
| 152 | if (strcmp(type, "md") == 0) | ||
| 153 | return EVP_PKEY_CTX_md(ctx, EVP_PKEY_OP_DERIVE, | ||
| 154 | EVP_PKEY_CTRL_HKDF_MD, value); | ||
| 155 | |||
| 156 | if (strcmp(type, "salt") == 0) | ||
| 157 | return EVP_PKEY_CTX_str2ctrl(ctx, EVP_PKEY_CTRL_HKDF_SALT, value); | ||
| 158 | |||
| 159 | if (strcmp(type, "hexsalt") == 0) | ||
| 160 | return EVP_PKEY_CTX_hex2ctrl(ctx, EVP_PKEY_CTRL_HKDF_SALT, value); | ||
| 161 | |||
| 162 | if (strcmp(type, "key") == 0) | ||
| 163 | return EVP_PKEY_CTX_str2ctrl(ctx, EVP_PKEY_CTRL_HKDF_KEY, value); | ||
| 164 | |||
| 165 | if (strcmp(type, "hexkey") == 0) | ||
| 166 | return EVP_PKEY_CTX_hex2ctrl(ctx, EVP_PKEY_CTRL_HKDF_KEY, value); | ||
| 167 | |||
| 168 | if (strcmp(type, "info") == 0) | ||
| 169 | return EVP_PKEY_CTX_str2ctrl(ctx, EVP_PKEY_CTRL_HKDF_INFO, value); | ||
| 170 | |||
| 171 | if (strcmp(type, "hexinfo") == 0) | ||
| 172 | return EVP_PKEY_CTX_hex2ctrl(ctx, EVP_PKEY_CTRL_HKDF_INFO, value); | ||
| 173 | |||
| 174 | KDFerr(KDF_F_PKEY_HKDF_CTRL_STR, KDF_R_UNKNOWN_PARAMETER_TYPE); | ||
| 175 | return -2; | ||
| 176 | } | ||
| 177 | |||
| 178 | static int pkey_hkdf_derive_init(EVP_PKEY_CTX *ctx) | ||
| 179 | { | ||
| 180 | HKDF_PKEY_CTX *kctx = ctx->data; | ||
| 181 | |||
| 182 | OPENSSL_clear_free(kctx->key, kctx->key_len); | ||
| 183 | OPENSSL_clear_free(kctx->salt, kctx->salt_len); | ||
| 184 | OPENSSL_cleanse(kctx->info, kctx->info_len); | ||
| 185 | memset(kctx, 0, sizeof(*kctx)); | ||
| 186 | |||
| 187 | return 1; | ||
| 188 | } | ||
| 189 | |||
| 190 | static int pkey_hkdf_derive(EVP_PKEY_CTX *ctx, unsigned char *key, | ||
| 191 | size_t *keylen) | ||
| 192 | { | ||
| 193 | HKDF_PKEY_CTX *kctx = ctx->data; | ||
| 194 | |||
| 195 | if (kctx->md == NULL) { | ||
| 196 | KDFerr(KDF_F_PKEY_HKDF_DERIVE, KDF_R_MISSING_MESSAGE_DIGEST); | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | if (kctx->key == NULL) { | ||
| 200 | KDFerr(KDF_F_PKEY_HKDF_DERIVE, KDF_R_MISSING_KEY); | ||
| 201 | return 0; | ||
| 202 | } | ||
| 203 | |||
| 204 | switch (kctx->mode) { | ||
| 205 | case EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND: | ||
| 206 | return HKDF(kctx->md, kctx->salt, kctx->salt_len, kctx->key, | ||
| 207 | kctx->key_len, kctx->info, kctx->info_len, key, | ||
| 208 | *keylen) != NULL; | ||
| 209 | |||
| 210 | case EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY: | ||
| 211 | if (key == NULL) { | ||
| 212 | *keylen = EVP_MD_size(kctx->md); | ||
| 213 | return 1; | ||
| 214 | } | ||
| 215 | return HKDF_Extract(kctx->md, kctx->salt, kctx->salt_len, kctx->key, | ||
| 216 | kctx->key_len, key, keylen) != NULL; | ||
| 217 | |||
| 218 | case EVP_PKEY_HKDEF_MODE_EXPAND_ONLY: | ||
| 219 | return HKDF_Expand(kctx->md, kctx->key, kctx->key_len, kctx->info, | ||
| 220 | kctx->info_len, key, *keylen) != NULL; | ||
| 221 | |||
| 222 | default: | ||
| 223 | return 0; | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | const EVP_PKEY_METHOD hkdf_pkey_meth = { | ||
| 228 | EVP_PKEY_HKDF, | ||
| 229 | 0, | ||
| 230 | pkey_hkdf_init, | ||
| 231 | 0, | ||
| 232 | pkey_hkdf_cleanup, | ||
| 233 | |||
| 234 | 0, 0, | ||
| 235 | 0, 0, | ||
| 236 | |||
| 237 | 0, | ||
| 238 | 0, | ||
| 239 | |||
| 240 | 0, | ||
| 241 | 0, | ||
| 242 | |||
| 243 | 0, 0, | ||
| 244 | |||
| 245 | 0, 0, 0, 0, | ||
| 246 | |||
| 247 | 0, 0, | ||
| 248 | |||
| 249 | 0, 0, | ||
| 250 | |||
| 251 | pkey_hkdf_derive_init, | ||
| 252 | pkey_hkdf_derive, | ||
| 253 | pkey_hkdf_ctrl, | ||
| 254 | pkey_hkdf_ctrl_str | ||
| 255 | }; | ||
| 256 | |||
| 257 | static unsigned char *HKDF(const EVP_MD *evp_md, | ||
| 258 | const unsigned char *salt, size_t salt_len, | ||
| 259 | const unsigned char *key, size_t key_len, | ||
| 260 | const unsigned char *info, size_t info_len, | ||
| 261 | unsigned char *okm, size_t okm_len) | ||
| 262 | { | ||
| 263 | unsigned char prk[EVP_MAX_MD_SIZE]; | ||
| 264 | unsigned char *ret; | ||
| 265 | size_t prk_len; | ||
| 266 | |||
| 267 | if (!HKDF_Extract(evp_md, salt, salt_len, key, key_len, prk, &prk_len)) | ||
| 268 | return NULL; | ||
| 269 | |||
| 270 | ret = HKDF_Expand(evp_md, prk, prk_len, info, info_len, okm, okm_len); | ||
| 271 | OPENSSL_cleanse(prk, sizeof(prk)); | ||
| 272 | |||
| 273 | return ret; | ||
| 274 | } | ||
| 275 | |||
| 276 | static unsigned char *HKDF_Extract(const EVP_MD *evp_md, | ||
| 277 | const unsigned char *salt, size_t salt_len, | ||
| 278 | const unsigned char *key, size_t key_len, | ||
| 279 | unsigned char *prk, size_t *prk_len) | ||
| 280 | { | ||
| 281 | unsigned int tmp_len; | ||
| 282 | |||
| 283 | if (!HMAC(evp_md, salt, salt_len, key, key_len, prk, &tmp_len)) | ||
| 284 | return NULL; | ||
| 285 | |||
| 286 | *prk_len = tmp_len; | ||
| 287 | return prk; | ||
| 288 | } | ||
| 289 | |||
| 290 | static unsigned char *HKDF_Expand(const EVP_MD *evp_md, | ||
| 291 | const unsigned char *prk, size_t prk_len, | ||
| 292 | const unsigned char *info, size_t info_len, | ||
| 293 | unsigned char *okm, size_t okm_len) | ||
| 294 | { | ||
| 295 | HMAC_CTX *hmac; | ||
| 296 | unsigned char *ret = NULL; | ||
| 297 | |||
| 298 | unsigned int i; | ||
| 299 | |||
| 300 | unsigned char prev[EVP_MAX_MD_SIZE]; | ||
| 301 | |||
| 302 | size_t done_len = 0, dig_len = EVP_MD_size(evp_md); | ||
| 303 | |||
| 304 | size_t n = okm_len / dig_len; | ||
| 305 | if (okm_len % dig_len) | ||
| 306 | n++; | ||
| 307 | |||
| 308 | if (n > 255 || okm == NULL) | ||
| 309 | return NULL; | ||
| 310 | |||
| 311 | if ((hmac = HMAC_CTX_new()) == NULL) | ||
| 312 | return NULL; | ||
| 313 | |||
| 314 | if (!HMAC_Init_ex(hmac, prk, prk_len, evp_md, NULL)) | ||
| 315 | goto err; | ||
| 316 | |||
| 317 | for (i = 1; i <= n; i++) { | ||
| 318 | size_t copy_len; | ||
| 319 | const unsigned char ctr = i; | ||
| 320 | |||
| 321 | if (i > 1) { | ||
| 322 | if (!HMAC_Init_ex(hmac, NULL, 0, NULL, NULL)) | ||
| 323 | goto err; | ||
| 324 | |||
| 325 | if (!HMAC_Update(hmac, prev, dig_len)) | ||
| 326 | goto err; | ||
| 327 | } | ||
| 328 | |||
| 329 | if (!HMAC_Update(hmac, info, info_len)) | ||
| 330 | goto err; | ||
| 331 | |||
| 332 | if (!HMAC_Update(hmac, &ctr, 1)) | ||
| 333 | goto err; | ||
| 334 | |||
| 335 | if (!HMAC_Final(hmac, prev, NULL)) | ||
| 336 | goto err; | ||
| 337 | |||
| 338 | copy_len = (done_len + dig_len > okm_len) ? | ||
| 339 | okm_len - done_len : | ||
| 340 | dig_len; | ||
| 341 | |||
| 342 | memcpy(okm + done_len, prev, copy_len); | ||
| 343 | |||
| 344 | done_len += copy_len; | ||
| 345 | } | ||
| 346 | ret = okm; | ||
| 347 | |||
| 348 | err: | ||
| 349 | OPENSSL_cleanse(prev, sizeof(prev)); | ||
| 350 | HMAC_CTX_free(hmac); | ||
| 351 | return ret; | ||
| 352 | } | ||
diff --git a/src/lib/libcrypto/kdf/kdf.h b/src/lib/libcrypto/kdf/kdf.h new file mode 100644 index 0000000000..5abd4c3714 --- /dev/null +++ b/src/lib/libcrypto/kdf/kdf.h | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. | ||
| 3 | * | ||
| 4 | * Licensed under the OpenSSL license (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 HEADER_KDF_H | ||
| 11 | # define HEADER_KDF_H | ||
| 12 | |||
| 13 | # include <openssl/kdferr.h> | ||
| 14 | #ifdef __cplusplus | ||
| 15 | extern "C" { | ||
| 16 | #endif | ||
| 17 | |||
| 18 | # define EVP_PKEY_CTRL_TLS_MD (EVP_PKEY_ALG_CTRL) | ||
| 19 | # define EVP_PKEY_CTRL_TLS_SECRET (EVP_PKEY_ALG_CTRL + 1) | ||
| 20 | # define EVP_PKEY_CTRL_TLS_SEED (EVP_PKEY_ALG_CTRL + 2) | ||
| 21 | # define EVP_PKEY_CTRL_HKDF_MD (EVP_PKEY_ALG_CTRL + 3) | ||
| 22 | # define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 4) | ||
| 23 | # define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 5) | ||
| 24 | # define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 6) | ||
| 25 | # define EVP_PKEY_CTRL_HKDF_MODE (EVP_PKEY_ALG_CTRL + 7) | ||
| 26 | # define EVP_PKEY_CTRL_PASS (EVP_PKEY_ALG_CTRL + 8) | ||
| 27 | # define EVP_PKEY_CTRL_SCRYPT_SALT (EVP_PKEY_ALG_CTRL + 9) | ||
| 28 | # define EVP_PKEY_CTRL_SCRYPT_N (EVP_PKEY_ALG_CTRL + 10) | ||
| 29 | # define EVP_PKEY_CTRL_SCRYPT_R (EVP_PKEY_ALG_CTRL + 11) | ||
| 30 | # define EVP_PKEY_CTRL_SCRYPT_P (EVP_PKEY_ALG_CTRL + 12) | ||
| 31 | # define EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES (EVP_PKEY_ALG_CTRL + 13) | ||
| 32 | |||
| 33 | # define EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND 0 | ||
| 34 | # define EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY 1 | ||
| 35 | # define EVP_PKEY_HKDEF_MODE_EXPAND_ONLY 2 | ||
| 36 | |||
| 37 | # define EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) \ | ||
| 38 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 39 | EVP_PKEY_CTRL_TLS_MD, 0, (void *)(md)) | ||
| 40 | |||
| 41 | # define EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, seclen) \ | ||
| 42 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 43 | EVP_PKEY_CTRL_TLS_SECRET, seclen, (void *)(sec)) | ||
| 44 | |||
| 45 | # define EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed, seedlen) \ | ||
| 46 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 47 | EVP_PKEY_CTRL_TLS_SEED, seedlen, (void *)(seed)) | ||
| 48 | |||
| 49 | # define EVP_PKEY_CTX_set_hkdf_md(pctx, md) \ | ||
| 50 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 51 | EVP_PKEY_CTRL_HKDF_MD, 0, (void *)(md)) | ||
| 52 | |||
| 53 | # define EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, saltlen) \ | ||
| 54 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 55 | EVP_PKEY_CTRL_HKDF_SALT, saltlen, (void *)(salt)) | ||
| 56 | |||
| 57 | # define EVP_PKEY_CTX_set1_hkdf_key(pctx, key, keylen) \ | ||
| 58 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 59 | EVP_PKEY_CTRL_HKDF_KEY, keylen, (void *)(key)) | ||
| 60 | |||
| 61 | # define EVP_PKEY_CTX_add1_hkdf_info(pctx, info, infolen) \ | ||
| 62 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 63 | EVP_PKEY_CTRL_HKDF_INFO, infolen, (void *)(info)) | ||
| 64 | |||
| 65 | # define EVP_PKEY_CTX_hkdf_mode(pctx, mode) \ | ||
| 66 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 67 | EVP_PKEY_CTRL_HKDF_MODE, mode, NULL) | ||
| 68 | |||
| 69 | # define EVP_PKEY_CTX_set1_pbe_pass(pctx, pass, passlen) \ | ||
| 70 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 71 | EVP_PKEY_CTRL_PASS, passlen, (void *)(pass)) | ||
| 72 | |||
| 73 | # define EVP_PKEY_CTX_set1_scrypt_salt(pctx, salt, saltlen) \ | ||
| 74 | EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 75 | EVP_PKEY_CTRL_SCRYPT_SALT, saltlen, (void *)(salt)) | ||
| 76 | |||
| 77 | # define EVP_PKEY_CTX_set_scrypt_N(pctx, n) \ | ||
| 78 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 79 | EVP_PKEY_CTRL_SCRYPT_N, n) | ||
| 80 | |||
| 81 | # define EVP_PKEY_CTX_set_scrypt_r(pctx, r) \ | ||
| 82 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 83 | EVP_PKEY_CTRL_SCRYPT_R, r) | ||
| 84 | |||
| 85 | # define EVP_PKEY_CTX_set_scrypt_p(pctx, p) \ | ||
| 86 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 87 | EVP_PKEY_CTRL_SCRYPT_P, p) | ||
| 88 | |||
| 89 | # define EVP_PKEY_CTX_set_scrypt_maxmem_bytes(pctx, maxmem_bytes) \ | ||
| 90 | EVP_PKEY_CTX_ctrl_uint64(pctx, -1, EVP_PKEY_OP_DERIVE, \ | ||
| 91 | EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES, maxmem_bytes) | ||
| 92 | |||
| 93 | |||
| 94 | # ifdef __cplusplus | ||
| 95 | } | ||
| 96 | # endif | ||
| 97 | #endif | ||
diff --git a/src/lib/libcrypto/kdf/kdf_err.c b/src/lib/libcrypto/kdf/kdf_err.c new file mode 100644 index 0000000000..1627c0a394 --- /dev/null +++ b/src/lib/libcrypto/kdf/kdf_err.c | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /* | ||
| 2 | * Generated by util/mkerr.pl DO NOT EDIT | ||
| 3 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | ||
| 4 | * | ||
| 5 | * Licensed under the OpenSSL license (the "License"). You may not use | ||
| 6 | * this file except in compliance with the License. You can obtain a copy | ||
| 7 | * in the file LICENSE in the source distribution or at | ||
| 8 | * https://www.openssl.org/source/license.html | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <openssl/err.h> | ||
| 12 | #include <openssl/kdferr.h> | ||
| 13 | |||
| 14 | #ifndef OPENSSL_NO_ERR | ||
| 15 | |||
| 16 | static const ERR_STRING_DATA KDF_str_functs[] = { | ||
| 17 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_HKDF_CTRL_STR, 0), "pkey_hkdf_ctrl_str"}, | ||
| 18 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_HKDF_DERIVE, 0), "pkey_hkdf_derive"}, | ||
| 19 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_HKDF_INIT, 0), "pkey_hkdf_init"}, | ||
| 20 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_CTRL_STR, 0), | ||
| 21 | "pkey_scrypt_ctrl_str"}, | ||
| 22 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_CTRL_UINT64, 0), | ||
| 23 | "pkey_scrypt_ctrl_uint64"}, | ||
| 24 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_DERIVE, 0), "pkey_scrypt_derive"}, | ||
| 25 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_INIT, 0), "pkey_scrypt_init"}, | ||
| 26 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_SCRYPT_SET_MEMBUF, 0), | ||
| 27 | "pkey_scrypt_set_membuf"}, | ||
| 28 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_TLS1_PRF_CTRL_STR, 0), | ||
| 29 | "pkey_tls1_prf_ctrl_str"}, | ||
| 30 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_TLS1_PRF_DERIVE, 0), | ||
| 31 | "pkey_tls1_prf_derive"}, | ||
| 32 | {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_TLS1_PRF_INIT, 0), "pkey_tls1_prf_init"}, | ||
| 33 | {ERR_PACK(ERR_LIB_KDF, KDF_F_TLS1_PRF_ALG, 0), "tls1_prf_alg"}, | ||
| 34 | {0, NULL} | ||
| 35 | }; | ||
| 36 | |||
| 37 | static const ERR_STRING_DATA KDF_str_reasons[] = { | ||
| 38 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_INVALID_DIGEST), "invalid digest"}, | ||
| 39 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_ITERATION_COUNT), | ||
| 40 | "missing iteration count"}, | ||
| 41 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_KEY), "missing key"}, | ||
| 42 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_MESSAGE_DIGEST), | ||
| 43 | "missing message digest"}, | ||
| 44 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_PARAMETER), "missing parameter"}, | ||
| 45 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_PASS), "missing pass"}, | ||
| 46 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_SALT), "missing salt"}, | ||
| 47 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_SECRET), "missing secret"}, | ||
| 48 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_SEED), "missing seed"}, | ||
| 49 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_UNKNOWN_PARAMETER_TYPE), | ||
| 50 | "unknown parameter type"}, | ||
| 51 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_VALUE_ERROR), "value error"}, | ||
| 52 | {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_VALUE_MISSING), "value missing"}, | ||
| 53 | {0, NULL} | ||
| 54 | }; | ||
| 55 | |||
| 56 | #endif | ||
| 57 | |||
| 58 | int ERR_load_KDF_strings(void) | ||
| 59 | { | ||
| 60 | #ifndef OPENSSL_NO_ERR | ||
| 61 | if (ERR_func_error_string(KDF_str_functs[0].error) == NULL) { | ||
| 62 | ERR_load_strings_const(KDF_str_functs); | ||
| 63 | ERR_load_strings_const(KDF_str_reasons); | ||
| 64 | } | ||
| 65 | #endif | ||
| 66 | return 1; | ||
| 67 | } | ||
diff --git a/src/lib/libcrypto/kdf/kdferr.h b/src/lib/libcrypto/kdf/kdferr.h new file mode 100644 index 0000000000..3f51bd0228 --- /dev/null +++ b/src/lib/libcrypto/kdf/kdferr.h | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | /* | ||
| 2 | * Generated by util/mkerr.pl DO NOT EDIT | ||
| 3 | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. | ||
| 4 | * | ||
| 5 | * Licensed under the OpenSSL license (the "License"). You may not use | ||
| 6 | * this file except in compliance with the License. You can obtain a copy | ||
| 7 | * in the file LICENSE in the source distribution or at | ||
| 8 | * https://www.openssl.org/source/license.html | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef HEADER_KDFERR_H | ||
| 12 | # define HEADER_KDFERR_H | ||
| 13 | |||
| 14 | # ifndef HEADER_SYMHACKS_H | ||
| 15 | # include <openssl/symhacks.h> | ||
| 16 | # endif | ||
| 17 | |||
| 18 | # ifdef __cplusplus | ||
| 19 | extern "C" | ||
| 20 | # endif | ||
| 21 | int ERR_load_KDF_strings(void); | ||
| 22 | |||
| 23 | /* | ||
| 24 | * KDF function codes. | ||
| 25 | */ | ||
| 26 | # define KDF_F_PKEY_HKDF_CTRL_STR 103 | ||
| 27 | # define KDF_F_PKEY_HKDF_DERIVE 102 | ||
| 28 | # define KDF_F_PKEY_HKDF_INIT 108 | ||
| 29 | # define KDF_F_PKEY_SCRYPT_CTRL_STR 104 | ||
| 30 | # define KDF_F_PKEY_SCRYPT_CTRL_UINT64 105 | ||
| 31 | # define KDF_F_PKEY_SCRYPT_DERIVE 109 | ||
| 32 | # define KDF_F_PKEY_SCRYPT_INIT 106 | ||
| 33 | # define KDF_F_PKEY_SCRYPT_SET_MEMBUF 107 | ||
| 34 | # define KDF_F_PKEY_TLS1_PRF_CTRL_STR 100 | ||
| 35 | # define KDF_F_PKEY_TLS1_PRF_DERIVE 101 | ||
| 36 | # define KDF_F_PKEY_TLS1_PRF_INIT 110 | ||
| 37 | # define KDF_F_TLS1_PRF_ALG 111 | ||
| 38 | |||
| 39 | /* | ||
| 40 | * KDF reason codes. | ||
| 41 | */ | ||
| 42 | # define KDF_R_INVALID_DIGEST 100 | ||
| 43 | # define KDF_R_MISSING_ITERATION_COUNT 109 | ||
| 44 | # define KDF_R_MISSING_KEY 104 | ||
| 45 | # define KDF_R_MISSING_MESSAGE_DIGEST 105 | ||
| 46 | # define KDF_R_MISSING_PARAMETER 101 | ||
| 47 | # define KDF_R_MISSING_PASS 110 | ||
| 48 | # define KDF_R_MISSING_SALT 111 | ||
| 49 | # define KDF_R_MISSING_SECRET 107 | ||
| 50 | # define KDF_R_MISSING_SEED 106 | ||
| 51 | # define KDF_R_UNKNOWN_PARAMETER_TYPE 103 | ||
| 52 | # define KDF_R_VALUE_ERROR 108 | ||
| 53 | # define KDF_R_VALUE_MISSING 102 | ||
| 54 | |||
| 55 | #endif | ||
