Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

612 строки
16 KiB

  1. /* Copyright (c) 2015, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <openssl/ssl.h>
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <openssl/bn.h>
  18. #include <openssl/bytestring.h>
  19. #include <openssl/curve25519.h>
  20. #include <openssl/ec.h>
  21. #include <openssl/err.h>
  22. #include <openssl/mem.h>
  23. #include <openssl/newhope.h>
  24. #include <openssl/nid.h>
  25. #include "internal.h"
  26. /* |EC_POINT| implementation. */
  27. static void ssl_ec_point_cleanup(SSL_ECDH_CTX *ctx) {
  28. BIGNUM *private_key = (BIGNUM *)ctx->data;
  29. BN_clear_free(private_key);
  30. }
  31. static int ssl_ec_point_offer(SSL_ECDH_CTX *ctx, CBB *out) {
  32. assert(ctx->data == NULL);
  33. BIGNUM *private_key = BN_new();
  34. if (private_key == NULL) {
  35. return 0;
  36. }
  37. ctx->data = private_key;
  38. /* Set up a shared |BN_CTX| for all operations. */
  39. BN_CTX *bn_ctx = BN_CTX_new();
  40. if (bn_ctx == NULL) {
  41. return 0;
  42. }
  43. BN_CTX_start(bn_ctx);
  44. int ret = 0;
  45. EC_POINT *public_key = NULL;
  46. EC_GROUP *group = EC_GROUP_new_by_curve_name(ctx->method->nid);
  47. if (group == NULL) {
  48. goto err;
  49. }
  50. /* Generate a private key. */
  51. if (!BN_rand_range_ex(private_key, 1, EC_GROUP_get0_order(group))) {
  52. goto err;
  53. }
  54. /* Compute the corresponding public key and serialize it. */
  55. public_key = EC_POINT_new(group);
  56. if (public_key == NULL ||
  57. !EC_POINT_mul(group, public_key, private_key, NULL, NULL, bn_ctx) ||
  58. !EC_POINT_point2cbb(out, group, public_key, POINT_CONVERSION_UNCOMPRESSED,
  59. bn_ctx)) {
  60. goto err;
  61. }
  62. ret = 1;
  63. err:
  64. EC_GROUP_free(group);
  65. EC_POINT_free(public_key);
  66. BN_CTX_end(bn_ctx);
  67. BN_CTX_free(bn_ctx);
  68. return ret;
  69. }
  70. static int ssl_ec_point_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
  71. size_t *out_secret_len, uint8_t *out_alert,
  72. const uint8_t *peer_key, size_t peer_key_len) {
  73. BIGNUM *private_key = (BIGNUM *)ctx->data;
  74. assert(private_key != NULL);
  75. *out_alert = SSL_AD_INTERNAL_ERROR;
  76. /* Set up a shared |BN_CTX| for all operations. */
  77. BN_CTX *bn_ctx = BN_CTX_new();
  78. if (bn_ctx == NULL) {
  79. return 0;
  80. }
  81. BN_CTX_start(bn_ctx);
  82. int ret = 0;
  83. EC_GROUP *group = EC_GROUP_new_by_curve_name(ctx->method->nid);
  84. EC_POINT *peer_point = NULL, *result = NULL;
  85. uint8_t *secret = NULL;
  86. if (group == NULL) {
  87. goto err;
  88. }
  89. /* Compute the x-coordinate of |peer_key| * |private_key|. */
  90. peer_point = EC_POINT_new(group);
  91. result = EC_POINT_new(group);
  92. if (peer_point == NULL || result == NULL) {
  93. goto err;
  94. }
  95. BIGNUM *x = BN_CTX_get(bn_ctx);
  96. if (x == NULL) {
  97. goto err;
  98. }
  99. if (!EC_POINT_oct2point(group, peer_point, peer_key, peer_key_len, bn_ctx)) {
  100. *out_alert = SSL_AD_DECODE_ERROR;
  101. goto err;
  102. }
  103. if (!EC_POINT_mul(group, result, NULL, peer_point, private_key, bn_ctx) ||
  104. !EC_POINT_get_affine_coordinates_GFp(group, result, x, NULL, bn_ctx)) {
  105. goto err;
  106. }
  107. /* Encode the x-coordinate left-padded with zeros. */
  108. size_t secret_len = (EC_GROUP_get_degree(group) + 7) / 8;
  109. secret = OPENSSL_malloc(secret_len);
  110. if (secret == NULL || !BN_bn2bin_padded(secret, secret_len, x)) {
  111. goto err;
  112. }
  113. *out_secret = secret;
  114. *out_secret_len = secret_len;
  115. secret = NULL;
  116. ret = 1;
  117. err:
  118. EC_GROUP_free(group);
  119. EC_POINT_free(peer_point);
  120. EC_POINT_free(result);
  121. BN_CTX_end(bn_ctx);
  122. BN_CTX_free(bn_ctx);
  123. OPENSSL_free(secret);
  124. return ret;
  125. }
  126. static int ssl_ec_point_accept(SSL_ECDH_CTX *ctx, CBB *out_public_key,
  127. uint8_t **out_secret, size_t *out_secret_len,
  128. uint8_t *out_alert, const uint8_t *peer_key,
  129. size_t peer_key_len) {
  130. *out_alert = SSL_AD_INTERNAL_ERROR;
  131. if (!ssl_ec_point_offer(ctx, out_public_key) ||
  132. !ssl_ec_point_finish(ctx, out_secret, out_secret_len, out_alert, peer_key,
  133. peer_key_len)) {
  134. return 0;
  135. }
  136. return 1;
  137. }
  138. /* X25119 implementation. */
  139. static void ssl_x25519_cleanup(SSL_ECDH_CTX *ctx) {
  140. if (ctx->data == NULL) {
  141. return;
  142. }
  143. OPENSSL_cleanse(ctx->data, 32);
  144. OPENSSL_free(ctx->data);
  145. }
  146. static int ssl_x25519_offer(SSL_ECDH_CTX *ctx, CBB *out) {
  147. assert(ctx->data == NULL);
  148. ctx->data = OPENSSL_malloc(32);
  149. if (ctx->data == NULL) {
  150. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  151. return 0;
  152. }
  153. uint8_t public_key[32];
  154. X25519_keypair(public_key, (uint8_t *)ctx->data);
  155. return CBB_add_bytes(out, public_key, sizeof(public_key));
  156. }
  157. static int ssl_x25519_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
  158. size_t *out_secret_len, uint8_t *out_alert,
  159. const uint8_t *peer_key, size_t peer_key_len) {
  160. assert(ctx->data != NULL);
  161. *out_alert = SSL_AD_INTERNAL_ERROR;
  162. uint8_t *secret = OPENSSL_malloc(32);
  163. if (secret == NULL) {
  164. return 0;
  165. }
  166. if (peer_key_len != 32 ||
  167. !X25519(secret, (uint8_t *)ctx->data, peer_key)) {
  168. OPENSSL_free(secret);
  169. *out_alert = SSL_AD_DECODE_ERROR;
  170. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
  171. return 0;
  172. }
  173. *out_secret = secret;
  174. *out_secret_len = 32;
  175. return 1;
  176. }
  177. static int ssl_x25519_accept(SSL_ECDH_CTX *ctx, CBB *out_public_key,
  178. uint8_t **out_secret, size_t *out_secret_len,
  179. uint8_t *out_alert, const uint8_t *peer_key,
  180. size_t peer_key_len) {
  181. *out_alert = SSL_AD_INTERNAL_ERROR;
  182. if (!ssl_x25519_offer(ctx, out_public_key) ||
  183. !ssl_x25519_finish(ctx, out_secret, out_secret_len, out_alert, peer_key,
  184. peer_key_len)) {
  185. return 0;
  186. }
  187. return 1;
  188. }
  189. /* Combined X25119 + New Hope (post-quantum) implementation. */
  190. typedef struct {
  191. uint8_t x25519_key[32];
  192. NEWHOPE_POLY *newhope_sk;
  193. } cecpq1_data;
  194. #define CECPQ1_OFFERMSG_LENGTH (32 + NEWHOPE_OFFERMSG_LENGTH)
  195. #define CECPQ1_ACCEPTMSG_LENGTH (32 + NEWHOPE_ACCEPTMSG_LENGTH)
  196. #define CECPQ1_SECRET_LENGTH (32 + SHA256_DIGEST_LENGTH)
  197. static void ssl_cecpq1_cleanup(SSL_ECDH_CTX *ctx) {
  198. if (ctx->data == NULL) {
  199. return;
  200. }
  201. cecpq1_data *data = ctx->data;
  202. NEWHOPE_POLY_free(data->newhope_sk);
  203. OPENSSL_cleanse(data, sizeof(cecpq1_data));
  204. OPENSSL_free(data);
  205. }
  206. static int ssl_cecpq1_offer(SSL_ECDH_CTX *ctx, CBB *out) {
  207. assert(ctx->data == NULL);
  208. cecpq1_data *data = OPENSSL_malloc(sizeof(cecpq1_data));
  209. if (data == NULL) {
  210. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  211. return 0;
  212. }
  213. ctx->data = data;
  214. data->newhope_sk = NEWHOPE_POLY_new();
  215. if (data->newhope_sk == NULL) {
  216. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  217. return 0;
  218. }
  219. uint8_t x25519_public_key[32];
  220. X25519_keypair(x25519_public_key, data->x25519_key);
  221. uint8_t newhope_offermsg[NEWHOPE_OFFERMSG_LENGTH];
  222. NEWHOPE_offer(newhope_offermsg, data->newhope_sk);
  223. if (!CBB_add_bytes(out, x25519_public_key, sizeof(x25519_public_key)) ||
  224. !CBB_add_bytes(out, newhope_offermsg, sizeof(newhope_offermsg))) {
  225. return 0;
  226. }
  227. return 1;
  228. }
  229. static int ssl_cecpq1_accept(SSL_ECDH_CTX *ctx, CBB *cbb, uint8_t **out_secret,
  230. size_t *out_secret_len, uint8_t *out_alert,
  231. const uint8_t *peer_key, size_t peer_key_len) {
  232. if (peer_key_len != CECPQ1_OFFERMSG_LENGTH) {
  233. *out_alert = SSL_AD_DECODE_ERROR;
  234. return 0;
  235. }
  236. *out_alert = SSL_AD_INTERNAL_ERROR;
  237. assert(ctx->data == NULL);
  238. cecpq1_data *data = OPENSSL_malloc(sizeof(cecpq1_data));
  239. if (data == NULL) {
  240. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  241. return 0;
  242. }
  243. data->newhope_sk = NULL;
  244. ctx->data = data;
  245. uint8_t *secret = OPENSSL_malloc(CECPQ1_SECRET_LENGTH);
  246. if (secret == NULL) {
  247. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  248. return 0;
  249. }
  250. /* Generate message to server, and secret key, at once. */
  251. uint8_t x25519_public_key[32];
  252. X25519_keypair(x25519_public_key, data->x25519_key);
  253. if (!X25519(secret, data->x25519_key, peer_key)) {
  254. *out_alert = SSL_AD_DECODE_ERROR;
  255. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
  256. goto err;
  257. }
  258. uint8_t newhope_acceptmsg[NEWHOPE_ACCEPTMSG_LENGTH];
  259. if (!NEWHOPE_accept(secret + 32, newhope_acceptmsg, peer_key + 32,
  260. NEWHOPE_OFFERMSG_LENGTH)) {
  261. *out_alert = SSL_AD_DECODE_ERROR;
  262. goto err;
  263. }
  264. if (!CBB_add_bytes(cbb, x25519_public_key, sizeof(x25519_public_key)) ||
  265. !CBB_add_bytes(cbb, newhope_acceptmsg, sizeof(newhope_acceptmsg))) {
  266. goto err;
  267. }
  268. *out_secret = secret;
  269. *out_secret_len = CECPQ1_SECRET_LENGTH;
  270. return 1;
  271. err:
  272. OPENSSL_cleanse(secret, CECPQ1_SECRET_LENGTH);
  273. OPENSSL_free(secret);
  274. return 0;
  275. }
  276. static int ssl_cecpq1_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
  277. size_t *out_secret_len, uint8_t *out_alert,
  278. const uint8_t *peer_key, size_t peer_key_len) {
  279. if (peer_key_len != CECPQ1_ACCEPTMSG_LENGTH) {
  280. *out_alert = SSL_AD_DECODE_ERROR;
  281. return 0;
  282. }
  283. *out_alert = SSL_AD_INTERNAL_ERROR;
  284. assert(ctx->data != NULL);
  285. cecpq1_data *data = ctx->data;
  286. uint8_t *secret = OPENSSL_malloc(CECPQ1_SECRET_LENGTH);
  287. if (secret == NULL) {
  288. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  289. return 0;
  290. }
  291. if (!X25519(secret, data->x25519_key, peer_key)) {
  292. *out_alert = SSL_AD_DECODE_ERROR;
  293. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
  294. goto err;
  295. }
  296. if (!NEWHOPE_finish(secret + 32, data->newhope_sk, peer_key + 32,
  297. NEWHOPE_ACCEPTMSG_LENGTH)) {
  298. *out_alert = SSL_AD_DECODE_ERROR;
  299. goto err;
  300. }
  301. *out_secret = secret;
  302. *out_secret_len = CECPQ1_SECRET_LENGTH;
  303. return 1;
  304. err:
  305. OPENSSL_cleanse(secret, CECPQ1_SECRET_LENGTH);
  306. OPENSSL_free(secret);
  307. return 0;
  308. }
  309. /* Legacy DHE-based implementation. */
  310. static void ssl_dhe_cleanup(SSL_ECDH_CTX *ctx) {
  311. DH_free((DH *)ctx->data);
  312. }
  313. static int ssl_dhe_offer(SSL_ECDH_CTX *ctx, CBB *out) {
  314. DH *dh = (DH *)ctx->data;
  315. /* The group must have been initialized already, but not the key. */
  316. assert(dh != NULL);
  317. assert(dh->priv_key == NULL);
  318. /* Due to a bug in yaSSL, the public key must be zero padded to the size of
  319. * the prime. */
  320. return DH_generate_key(dh) &&
  321. BN_bn2cbb_padded(out, BN_num_bytes(dh->p), dh->pub_key);
  322. }
  323. static int ssl_dhe_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
  324. size_t *out_secret_len, uint8_t *out_alert,
  325. const uint8_t *peer_key, size_t peer_key_len) {
  326. DH *dh = (DH *)ctx->data;
  327. assert(dh != NULL);
  328. assert(dh->priv_key != NULL);
  329. *out_alert = SSL_AD_INTERNAL_ERROR;
  330. int secret_len = 0;
  331. uint8_t *secret = NULL;
  332. BIGNUM *peer_point = BN_bin2bn(peer_key, peer_key_len, NULL);
  333. if (peer_point == NULL) {
  334. goto err;
  335. }
  336. secret = OPENSSL_malloc(DH_size(dh));
  337. if (secret == NULL) {
  338. goto err;
  339. }
  340. secret_len = DH_compute_key(secret, peer_point, dh);
  341. if (secret_len <= 0) {
  342. goto err;
  343. }
  344. *out_secret = secret;
  345. *out_secret_len = (size_t)secret_len;
  346. BN_free(peer_point);
  347. return 1;
  348. err:
  349. if (secret_len > 0) {
  350. OPENSSL_cleanse(secret, (size_t)secret_len);
  351. }
  352. OPENSSL_free(secret);
  353. BN_free(peer_point);
  354. return 0;
  355. }
  356. static int ssl_dhe_accept(SSL_ECDH_CTX *ctx, CBB *out_public_key,
  357. uint8_t **out_secret, size_t *out_secret_len,
  358. uint8_t *out_alert, const uint8_t *peer_key,
  359. size_t peer_key_len) {
  360. *out_alert = SSL_AD_INTERNAL_ERROR;
  361. if (!ssl_dhe_offer(ctx, out_public_key) ||
  362. !ssl_dhe_finish(ctx, out_secret, out_secret_len, out_alert, peer_key,
  363. peer_key_len)) {
  364. return 0;
  365. }
  366. return 1;
  367. }
  368. static const SSL_ECDH_METHOD kDHEMethod = {
  369. NID_undef, 0, "",
  370. ssl_dhe_cleanup,
  371. ssl_dhe_offer,
  372. ssl_dhe_accept,
  373. ssl_dhe_finish,
  374. CBS_get_u16_length_prefixed,
  375. CBB_add_u16_length_prefixed,
  376. };
  377. static const SSL_ECDH_METHOD kCECPQ1Method = {
  378. NID_undef, 0, "",
  379. ssl_cecpq1_cleanup,
  380. ssl_cecpq1_offer,
  381. ssl_cecpq1_accept,
  382. ssl_cecpq1_finish,
  383. CBS_get_u16_length_prefixed,
  384. CBB_add_u16_length_prefixed,
  385. };
  386. static const SSL_ECDH_METHOD kMethods[] = {
  387. {
  388. NID_X9_62_prime256v1,
  389. SSL_CURVE_SECP256R1,
  390. "P-256",
  391. ssl_ec_point_cleanup,
  392. ssl_ec_point_offer,
  393. ssl_ec_point_accept,
  394. ssl_ec_point_finish,
  395. CBS_get_u8_length_prefixed,
  396. CBB_add_u8_length_prefixed,
  397. },
  398. {
  399. NID_secp384r1,
  400. SSL_CURVE_SECP384R1,
  401. "P-384",
  402. ssl_ec_point_cleanup,
  403. ssl_ec_point_offer,
  404. ssl_ec_point_accept,
  405. ssl_ec_point_finish,
  406. CBS_get_u8_length_prefixed,
  407. CBB_add_u8_length_prefixed,
  408. },
  409. {
  410. NID_secp521r1,
  411. SSL_CURVE_SECP521R1,
  412. "P-521",
  413. ssl_ec_point_cleanup,
  414. ssl_ec_point_offer,
  415. ssl_ec_point_accept,
  416. ssl_ec_point_finish,
  417. CBS_get_u8_length_prefixed,
  418. CBB_add_u8_length_prefixed,
  419. },
  420. {
  421. NID_X25519,
  422. SSL_CURVE_X25519,
  423. "X25519",
  424. ssl_x25519_cleanup,
  425. ssl_x25519_offer,
  426. ssl_x25519_accept,
  427. ssl_x25519_finish,
  428. CBS_get_u8_length_prefixed,
  429. CBB_add_u8_length_prefixed,
  430. },
  431. };
  432. static const SSL_ECDH_METHOD *method_from_group_id(uint16_t group_id) {
  433. size_t i;
  434. for (i = 0; i < sizeof(kMethods) / sizeof(kMethods[0]); i++) {
  435. if (kMethods[i].group_id == group_id) {
  436. return &kMethods[i];
  437. }
  438. }
  439. return NULL;
  440. }
  441. static const SSL_ECDH_METHOD *method_from_nid(int nid) {
  442. size_t i;
  443. for (i = 0; i < sizeof(kMethods) / sizeof(kMethods[0]); i++) {
  444. if (kMethods[i].nid == nid) {
  445. return &kMethods[i];
  446. }
  447. }
  448. return NULL;
  449. }
  450. const char* SSL_get_curve_name(uint16_t group_id) {
  451. const SSL_ECDH_METHOD *method = method_from_group_id(group_id);
  452. if (method == NULL) {
  453. return NULL;
  454. }
  455. return method->name;
  456. }
  457. int ssl_nid_to_group_id(uint16_t *out_group_id, int nid) {
  458. const SSL_ECDH_METHOD *method = method_from_nid(nid);
  459. if (method == NULL) {
  460. return 0;
  461. }
  462. *out_group_id = method->group_id;
  463. return 1;
  464. }
  465. int SSL_ECDH_CTX_init(SSL_ECDH_CTX *ctx, uint16_t group_id) {
  466. SSL_ECDH_CTX_cleanup(ctx);
  467. const SSL_ECDH_METHOD *method = method_from_group_id(group_id);
  468. if (method == NULL) {
  469. OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
  470. return 0;
  471. }
  472. ctx->method = method;
  473. return 1;
  474. }
  475. void SSL_ECDH_CTX_init_for_dhe(SSL_ECDH_CTX *ctx, DH *params) {
  476. SSL_ECDH_CTX_cleanup(ctx);
  477. ctx->method = &kDHEMethod;
  478. ctx->data = params;
  479. }
  480. void SSL_ECDH_CTX_init_for_cecpq1(SSL_ECDH_CTX *ctx) {
  481. SSL_ECDH_CTX_cleanup(ctx);
  482. ctx->method = &kCECPQ1Method;
  483. }
  484. void SSL_ECDH_CTX_cleanup(SSL_ECDH_CTX *ctx) {
  485. if (ctx->method == NULL) {
  486. return;
  487. }
  488. ctx->method->cleanup(ctx);
  489. ctx->method = NULL;
  490. ctx->data = NULL;
  491. }
  492. uint16_t SSL_ECDH_CTX_get_id(const SSL_ECDH_CTX *ctx) {
  493. return ctx->method->group_id;
  494. }
  495. int SSL_ECDH_CTX_get_key(SSL_ECDH_CTX *ctx, CBS *cbs, CBS *out) {
  496. if (ctx->method == NULL) {
  497. return 0;
  498. }
  499. return ctx->method->get_key(cbs, out);
  500. }
  501. int SSL_ECDH_CTX_add_key(SSL_ECDH_CTX *ctx, CBB *cbb, CBB *out_contents) {
  502. if (ctx->method == NULL) {
  503. return 0;
  504. }
  505. return ctx->method->add_key(cbb, out_contents);
  506. }
  507. int SSL_ECDH_CTX_offer(SSL_ECDH_CTX *ctx, CBB *out_public_key) {
  508. return ctx->method->offer(ctx, out_public_key);
  509. }
  510. int SSL_ECDH_CTX_accept(SSL_ECDH_CTX *ctx, CBB *out_public_key,
  511. uint8_t **out_secret, size_t *out_secret_len,
  512. uint8_t *out_alert, const uint8_t *peer_key,
  513. size_t peer_key_len) {
  514. return ctx->method->accept(ctx, out_public_key, out_secret, out_secret_len,
  515. out_alert, peer_key, peer_key_len);
  516. }
  517. int SSL_ECDH_CTX_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
  518. size_t *out_secret_len, uint8_t *out_alert,
  519. const uint8_t *peer_key, size_t peer_key_len) {
  520. return ctx->method->finish(ctx, out_secret, out_secret_len, out_alert,
  521. peer_key, peer_key_len);
  522. }