p_lib.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * Copyright 1995-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. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include "internal/refcount.h"
  12. #include <openssl/bn.h>
  13. #include <openssl/err.h>
  14. #include <openssl/objects.h>
  15. #include <openssl/evp.h>
  16. #include <openssl/x509.h>
  17. #include <openssl/rsa.h>
  18. #include <openssl/dsa.h>
  19. #include <openssl/dh.h>
  20. #include <openssl/cmac.h>
  21. #include <openssl/engine.h>
  22. #include "internal/asn1_int.h"
  23. #include "internal/evp_int.h"
  24. static void EVP_PKEY_free_it(EVP_PKEY *x);
  25. int EVP_PKEY_bits(const EVP_PKEY *pkey)
  26. {
  27. if (pkey && pkey->ameth && pkey->ameth->pkey_bits)
  28. return pkey->ameth->pkey_bits(pkey);
  29. return 0;
  30. }
  31. int EVP_PKEY_security_bits(const EVP_PKEY *pkey)
  32. {
  33. if (pkey == NULL)
  34. return 0;
  35. if (!pkey->ameth || !pkey->ameth->pkey_security_bits)
  36. return -2;
  37. return pkey->ameth->pkey_security_bits(pkey);
  38. }
  39. int EVP_PKEY_size(EVP_PKEY *pkey)
  40. {
  41. if (pkey && pkey->ameth && pkey->ameth->pkey_size)
  42. return pkey->ameth->pkey_size(pkey);
  43. return 0;
  44. }
  45. int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
  46. {
  47. #ifndef OPENSSL_NO_DSA
  48. if (pkey->type == EVP_PKEY_DSA) {
  49. int ret = pkey->save_parameters;
  50. if (mode >= 0)
  51. pkey->save_parameters = mode;
  52. return ret;
  53. }
  54. #endif
  55. #ifndef OPENSSL_NO_EC
  56. if (pkey->type == EVP_PKEY_EC) {
  57. int ret = pkey->save_parameters;
  58. if (mode >= 0)
  59. pkey->save_parameters = mode;
  60. return ret;
  61. }
  62. #endif
  63. return 0;
  64. }
  65. int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
  66. {
  67. if (to->type == EVP_PKEY_NONE) {
  68. if (EVP_PKEY_set_type(to, from->type) == 0)
  69. return 0;
  70. } else if (to->type != from->type) {
  71. EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);
  72. goto err;
  73. }
  74. if (EVP_PKEY_missing_parameters(from)) {
  75. EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_MISSING_PARAMETERS);
  76. goto err;
  77. }
  78. if (!EVP_PKEY_missing_parameters(to)) {
  79. if (EVP_PKEY_cmp_parameters(to, from) == 1)
  80. return 1;
  81. EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_PARAMETERS);
  82. return 0;
  83. }
  84. if (from->ameth && from->ameth->param_copy)
  85. return from->ameth->param_copy(to, from);
  86. err:
  87. return 0;
  88. }
  89. int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)
  90. {
  91. if (pkey->ameth && pkey->ameth->param_missing)
  92. return pkey->ameth->param_missing(pkey);
  93. return 0;
  94. }
  95. int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
  96. {
  97. if (a->type != b->type)
  98. return -1;
  99. if (a->ameth && a->ameth->param_cmp)
  100. return a->ameth->param_cmp(a, b);
  101. return -2;
  102. }
  103. int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
  104. {
  105. if (a->type != b->type)
  106. return -1;
  107. if (a->ameth) {
  108. int ret;
  109. /* Compare parameters if the algorithm has them */
  110. if (a->ameth->param_cmp) {
  111. ret = a->ameth->param_cmp(a, b);
  112. if (ret <= 0)
  113. return ret;
  114. }
  115. if (a->ameth->pub_cmp)
  116. return a->ameth->pub_cmp(a, b);
  117. }
  118. return -2;
  119. }
  120. EVP_PKEY *EVP_PKEY_new(void)
  121. {
  122. EVP_PKEY *ret = OPENSSL_zalloc(sizeof(*ret));
  123. if (ret == NULL) {
  124. EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE);
  125. return NULL;
  126. }
  127. ret->type = EVP_PKEY_NONE;
  128. ret->save_type = EVP_PKEY_NONE;
  129. ret->references = 1;
  130. ret->save_parameters = 1;
  131. ret->lock = CRYPTO_THREAD_lock_new();
  132. if (ret->lock == NULL) {
  133. EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE);
  134. OPENSSL_free(ret);
  135. return NULL;
  136. }
  137. return ret;
  138. }
  139. int EVP_PKEY_up_ref(EVP_PKEY *pkey)
  140. {
  141. int i;
  142. if (CRYPTO_UP_REF(&pkey->references, &i, pkey->lock) <= 0)
  143. return 0;
  144. REF_PRINT_COUNT("EVP_PKEY", pkey);
  145. REF_ASSERT_ISNT(i < 2);
  146. return ((i > 1) ? 1 : 0);
  147. }
  148. /*
  149. * Setup a public key ASN1 method and ENGINE from a NID or a string. If pkey
  150. * is NULL just return 1 or 0 if the algorithm exists.
  151. */
  152. static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str,
  153. int len)
  154. {
  155. const EVP_PKEY_ASN1_METHOD *ameth;
  156. ENGINE **eptr = (e == NULL) ? &e : NULL;
  157. if (pkey) {
  158. if (pkey->pkey.ptr)
  159. EVP_PKEY_free_it(pkey);
  160. /*
  161. * If key type matches and a method exists then this lookup has
  162. * succeeded once so just indicate success.
  163. */
  164. if ((type == pkey->save_type) && pkey->ameth)
  165. return 1;
  166. #ifndef OPENSSL_NO_ENGINE
  167. /* If we have ENGINEs release them */
  168. ENGINE_finish(pkey->engine);
  169. pkey->engine = NULL;
  170. ENGINE_finish(pkey->pmeth_engine);
  171. pkey->pmeth_engine = NULL;
  172. #endif
  173. }
  174. if (str)
  175. ameth = EVP_PKEY_asn1_find_str(eptr, str, len);
  176. else
  177. ameth = EVP_PKEY_asn1_find(eptr, type);
  178. #ifndef OPENSSL_NO_ENGINE
  179. if (pkey == NULL && eptr != NULL)
  180. ENGINE_finish(e);
  181. #endif
  182. if (ameth == NULL) {
  183. EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM);
  184. return 0;
  185. }
  186. if (pkey) {
  187. pkey->ameth = ameth;
  188. pkey->engine = e;
  189. pkey->type = pkey->ameth->pkey_id;
  190. pkey->save_type = type;
  191. }
  192. return 1;
  193. }
  194. EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
  195. const unsigned char *priv,
  196. size_t len)
  197. {
  198. EVP_PKEY *ret = EVP_PKEY_new();
  199. if (ret == NULL
  200. || !pkey_set_type(ret, e, type, NULL, -1)) {
  201. /* EVPerr already called */
  202. goto err;
  203. }
  204. if (ret->ameth->set_priv_key == NULL) {
  205. EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY,
  206. EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  207. goto err;
  208. }
  209. if (!ret->ameth->set_priv_key(ret, priv, len)) {
  210. EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PRIVATE_KEY, EVP_R_KEY_SETUP_FAILED);
  211. goto err;
  212. }
  213. return ret;
  214. err:
  215. EVP_PKEY_free(ret);
  216. return NULL;
  217. }
  218. EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
  219. const unsigned char *pub,
  220. size_t len)
  221. {
  222. EVP_PKEY *ret = EVP_PKEY_new();
  223. if (ret == NULL
  224. || !pkey_set_type(ret, e, type, NULL, -1)) {
  225. /* EVPerr already called */
  226. goto err;
  227. }
  228. if (ret->ameth->set_pub_key == NULL) {
  229. EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY,
  230. EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  231. goto err;
  232. }
  233. if (!ret->ameth->set_pub_key(ret, pub, len)) {
  234. EVPerr(EVP_F_EVP_PKEY_NEW_RAW_PUBLIC_KEY, EVP_R_KEY_SETUP_FAILED);
  235. goto err;
  236. }
  237. return ret;
  238. err:
  239. EVP_PKEY_free(ret);
  240. return NULL;
  241. }
  242. EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
  243. size_t len, const EVP_CIPHER *cipher)
  244. {
  245. #ifndef OPENSSL_NO_CMAC
  246. EVP_PKEY *ret = EVP_PKEY_new();
  247. CMAC_CTX *cmctx = CMAC_CTX_new();
  248. if (ret == NULL
  249. || cmctx == NULL
  250. || !pkey_set_type(ret, e, EVP_PKEY_CMAC, NULL, -1)) {
  251. /* EVPerr already called */
  252. goto err;
  253. }
  254. if (!CMAC_Init(cmctx, priv, len, cipher, e)) {
  255. EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY, EVP_R_KEY_SETUP_FAILED);
  256. goto err;
  257. }
  258. ret->pkey.ptr = cmctx;
  259. return ret;
  260. err:
  261. EVP_PKEY_free(ret);
  262. CMAC_CTX_free(cmctx);
  263. return NULL;
  264. #else
  265. EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY,
  266. EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
  267. return NULL;
  268. #endif
  269. }
  270. int EVP_PKEY_set_type(EVP_PKEY *pkey, int type)
  271. {
  272. return pkey_set_type(pkey, NULL, type, NULL, -1);
  273. }
  274. int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len)
  275. {
  276. return pkey_set_type(pkey, NULL, EVP_PKEY_NONE, str, len);
  277. }
  278. #ifndef OPENSSL_NO_ENGINE
  279. int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e)
  280. {
  281. if (e != NULL) {
  282. if (!ENGINE_init(e)) {
  283. EVPerr(EVP_F_EVP_PKEY_SET1_ENGINE, ERR_R_ENGINE_LIB);
  284. return 0;
  285. }
  286. if (ENGINE_get_pkey_meth(e, pkey->type) == NULL) {
  287. ENGINE_finish(e);
  288. EVPerr(EVP_F_EVP_PKEY_SET1_ENGINE, EVP_R_UNSUPPORTED_ALGORITHM);
  289. return 0;
  290. }
  291. }
  292. ENGINE_finish(pkey->pmeth_engine);
  293. pkey->pmeth_engine = e;
  294. return 1;
  295. }
  296. #endif
  297. int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key)
  298. {
  299. if (pkey == NULL || !EVP_PKEY_set_type(pkey, type))
  300. return 0;
  301. pkey->pkey.ptr = key;
  302. return (key != NULL);
  303. }
  304. void *EVP_PKEY_get0(const EVP_PKEY *pkey)
  305. {
  306. return pkey->pkey.ptr;
  307. }
  308. const unsigned char *EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len)
  309. {
  310. ASN1_OCTET_STRING *os = NULL;
  311. if (pkey->type != EVP_PKEY_HMAC) {
  312. EVPerr(EVP_F_EVP_PKEY_GET0_HMAC, EVP_R_EXPECTING_AN_HMAC_KEY);
  313. return NULL;
  314. }
  315. os = EVP_PKEY_get0(pkey);
  316. *len = os->length;
  317. return os->data;
  318. }
  319. #ifndef OPENSSL_NO_POLY1305
  320. const unsigned char *EVP_PKEY_get0_poly1305(const EVP_PKEY *pkey, size_t *len)
  321. {
  322. ASN1_OCTET_STRING *os = NULL;
  323. if (pkey->type != EVP_PKEY_POLY1305) {
  324. EVPerr(EVP_F_EVP_PKEY_GET0_POLY1305, EVP_R_EXPECTING_A_POLY1305_KEY);
  325. return NULL;
  326. }
  327. os = EVP_PKEY_get0(pkey);
  328. *len = os->length;
  329. return os->data;
  330. }
  331. #endif
  332. #ifndef OPENSSL_NO_SIPHASH
  333. const unsigned char *EVP_PKEY_get0_siphash(const EVP_PKEY *pkey, size_t *len)
  334. {
  335. ASN1_OCTET_STRING *os = NULL;
  336. if (pkey->type != EVP_PKEY_SIPHASH) {
  337. EVPerr(EVP_F_EVP_PKEY_GET0_SIPHASH, EVP_R_EXPECTING_A_SIPHASH_KEY);
  338. return NULL;
  339. }
  340. os = EVP_PKEY_get0(pkey);
  341. *len = os->length;
  342. return os->data;
  343. }
  344. #endif
  345. #ifndef OPENSSL_NO_RSA
  346. int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key)
  347. {
  348. int ret = EVP_PKEY_assign_RSA(pkey, key);
  349. if (ret)
  350. RSA_up_ref(key);
  351. return ret;
  352. }
  353. RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
  354. {
  355. if (pkey->type != EVP_PKEY_RSA) {
  356. EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);
  357. return NULL;
  358. }
  359. return pkey->pkey.rsa;
  360. }
  361. RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
  362. {
  363. RSA *ret = EVP_PKEY_get0_RSA(pkey);
  364. if (ret != NULL)
  365. RSA_up_ref(ret);
  366. return ret;
  367. }
  368. #endif
  369. #ifndef OPENSSL_NO_DSA
  370. int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
  371. {
  372. int ret = EVP_PKEY_assign_DSA(pkey, key);
  373. if (ret)
  374. DSA_up_ref(key);
  375. return ret;
  376. }
  377. DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
  378. {
  379. if (pkey->type != EVP_PKEY_DSA) {
  380. EVPerr(EVP_F_EVP_PKEY_GET0_DSA, EVP_R_EXPECTING_A_DSA_KEY);
  381. return NULL;
  382. }
  383. return pkey->pkey.dsa;
  384. }
  385. DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
  386. {
  387. DSA *ret = EVP_PKEY_get0_DSA(pkey);
  388. if (ret != NULL)
  389. DSA_up_ref(ret);
  390. return ret;
  391. }
  392. #endif
  393. #ifndef OPENSSL_NO_EC
  394. int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
  395. {
  396. int ret = EVP_PKEY_assign_EC_KEY(pkey, key);
  397. if (ret)
  398. EC_KEY_up_ref(key);
  399. return ret;
  400. }
  401. EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
  402. {
  403. if (pkey->type != EVP_PKEY_EC) {
  404. EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
  405. return NULL;
  406. }
  407. return pkey->pkey.ec;
  408. }
  409. EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
  410. {
  411. EC_KEY *ret = EVP_PKEY_get0_EC_KEY(pkey);
  412. if (ret != NULL)
  413. EC_KEY_up_ref(ret);
  414. return ret;
  415. }
  416. #endif
  417. #ifndef OPENSSL_NO_DH
  418. int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
  419. {
  420. int ret = EVP_PKEY_assign_DH(pkey, key);
  421. if (ret)
  422. DH_up_ref(key);
  423. return ret;
  424. }
  425. DH *EVP_PKEY_get0_DH(EVP_PKEY *pkey)
  426. {
  427. if (pkey->type != EVP_PKEY_DH && pkey->type != EVP_PKEY_DHX) {
  428. EVPerr(EVP_F_EVP_PKEY_GET0_DH, EVP_R_EXPECTING_A_DH_KEY);
  429. return NULL;
  430. }
  431. return pkey->pkey.dh;
  432. }
  433. DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
  434. {
  435. DH *ret = EVP_PKEY_get0_DH(pkey);
  436. if (ret != NULL)
  437. DH_up_ref(ret);
  438. return ret;
  439. }
  440. #endif
  441. int EVP_PKEY_type(int type)
  442. {
  443. int ret;
  444. const EVP_PKEY_ASN1_METHOD *ameth;
  445. ENGINE *e;
  446. ameth = EVP_PKEY_asn1_find(&e, type);
  447. if (ameth)
  448. ret = ameth->pkey_id;
  449. else
  450. ret = NID_undef;
  451. #ifndef OPENSSL_NO_ENGINE
  452. ENGINE_finish(e);
  453. #endif
  454. return ret;
  455. }
  456. int EVP_PKEY_id(const EVP_PKEY *pkey)
  457. {
  458. return pkey->type;
  459. }
  460. int EVP_PKEY_base_id(const EVP_PKEY *pkey)
  461. {
  462. return EVP_PKEY_type(pkey->type);
  463. }
  464. void EVP_PKEY_free(EVP_PKEY *x)
  465. {
  466. int i;
  467. if (x == NULL)
  468. return;
  469. CRYPTO_DOWN_REF(&x->references, &i, x->lock);
  470. REF_PRINT_COUNT("EVP_PKEY", x);
  471. if (i > 0)
  472. return;
  473. REF_ASSERT_ISNT(i < 0);
  474. EVP_PKEY_free_it(x);
  475. CRYPTO_THREAD_lock_free(x->lock);
  476. sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
  477. OPENSSL_free(x);
  478. }
  479. static void EVP_PKEY_free_it(EVP_PKEY *x)
  480. {
  481. /* internal function; x is never NULL */
  482. if (x->ameth && x->ameth->pkey_free) {
  483. x->ameth->pkey_free(x);
  484. x->pkey.ptr = NULL;
  485. }
  486. #ifndef OPENSSL_NO_ENGINE
  487. ENGINE_finish(x->engine);
  488. x->engine = NULL;
  489. ENGINE_finish(x->pmeth_engine);
  490. x->pmeth_engine = NULL;
  491. #endif
  492. }
  493. static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,
  494. const char *kstr)
  495. {
  496. BIO_indent(out, indent, 128);
  497. BIO_printf(out, "%s algorithm \"%s\" unsupported\n",
  498. kstr, OBJ_nid2ln(pkey->type));
  499. return 1;
  500. }
  501. int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
  502. int indent, ASN1_PCTX *pctx)
  503. {
  504. if (pkey->ameth && pkey->ameth->pub_print)
  505. return pkey->ameth->pub_print(out, pkey, indent, pctx);
  506. return unsup_alg(out, pkey, indent, "Public Key");
  507. }
  508. int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
  509. int indent, ASN1_PCTX *pctx)
  510. {
  511. if (pkey->ameth && pkey->ameth->priv_print)
  512. return pkey->ameth->priv_print(out, pkey, indent, pctx);
  513. return unsup_alg(out, pkey, indent, "Private Key");
  514. }
  515. int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
  516. int indent, ASN1_PCTX *pctx)
  517. {
  518. if (pkey->ameth && pkey->ameth->param_print)
  519. return pkey->ameth->param_print(out, pkey, indent, pctx);
  520. return unsup_alg(out, pkey, indent, "Parameters");
  521. }
  522. static int evp_pkey_asn1_ctrl(EVP_PKEY *pkey, int op, int arg1, void *arg2)
  523. {
  524. if (pkey->ameth == NULL || pkey->ameth->pkey_ctrl == NULL)
  525. return -2;
  526. return pkey->ameth->pkey_ctrl(pkey, op, arg1, arg2);
  527. }
  528. int EVP_PKEY_get_default_digest_nid(EVP_PKEY *pkey, int *pnid)
  529. {
  530. return evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_DEFAULT_MD_NID, 0, pnid);
  531. }
  532. int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
  533. const unsigned char *pt, size_t ptlen)
  534. {
  535. if (ptlen > INT_MAX)
  536. return 0;
  537. if (evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_SET1_TLS_ENCPT, ptlen,
  538. (void *)pt) <= 0)
  539. return 0;
  540. return 1;
  541. }
  542. size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt)
  543. {
  544. int rv;
  545. rv = evp_pkey_asn1_ctrl(pkey, ASN1_PKEY_CTRL_GET1_TLS_ENCPT, 0, ppt);
  546. if (rv <= 0)
  547. return 0;
  548. return rv;
  549. }