334
u8 * tls_connection_handshake(void *tls_ctx, struct tls_connection *conn,
335
const u8 *in_data, size_t in_len,
336
size_t *out_len, u8 **appl_data,
337
size_t *appl_data_len)
334
struct wpabuf * tls_connection_handshake(void *tls_ctx,
335
struct tls_connection *conn,
336
const struct wpabuf *in_data,
337
struct wpabuf **appl_data)
339
339
#ifdef CONFIG_TLS_INTERNAL_CLIENT
341
size_t res_len, ad_len;
340
344
if (conn->client == NULL)
348
res = tlsv1_client_handshake(conn->client,
349
in_data ? wpabuf_head(in_data) : NULL,
350
in_data ? wpabuf_len(in_data) : 0,
351
&res_len, &ad, &ad_len);
354
out = wpabuf_alloc_ext_data(res, res_len);
362
*appl_data = wpabuf_alloc_ext_data(ad, ad_len);
363
if (*appl_data == NULL)
371
#else /* CONFIG_TLS_INTERNAL_CLIENT */
373
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
377
struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
378
struct tls_connection *conn,
379
const struct wpabuf *in_data,
380
struct wpabuf **appl_data)
382
#ifdef CONFIG_TLS_INTERNAL_SERVER
387
if (conn->server == NULL)
344
391
*appl_data = NULL;
346
wpa_printf(MSG_DEBUG, "TLS: %s(in_data=%p in_len=%lu)",
347
__func__, in_data, (unsigned long) in_len);
348
return tlsv1_client_handshake(conn->client, in_data, in_len, out_len,
349
appl_data, appl_data_len);
350
#else /* CONFIG_TLS_INTERNAL_CLIENT */
352
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
356
u8 * tls_connection_server_handshake(void *tls_ctx,
357
struct tls_connection *conn,
358
const u8 *in_data, size_t in_len,
361
#ifdef CONFIG_TLS_INTERNAL_SERVER
363
if (conn->server == NULL)
366
wpa_printf(MSG_DEBUG, "TLS: %s(in_data=%p in_len=%lu)",
367
__func__, in_data, (unsigned long) in_len);
368
out = tlsv1_server_handshake(conn->server, in_data, in_len, out_len);
369
if (out == NULL && tlsv1_server_established(conn->server)) {
393
res = tlsv1_server_handshake(conn->server, wpabuf_head(in_data),
394
wpabuf_len(in_data), &res_len);
395
if (res == NULL && tlsv1_server_established(conn->server))
396
return wpabuf_alloc(0);
399
out = wpabuf_alloc_ext_data(res, res_len);
374
406
#else /* CONFIG_TLS_INTERNAL_SERVER */
380
int tls_connection_encrypt(void *tls_ctx, struct tls_connection *conn,
381
const u8 *in_data, size_t in_len,
382
u8 *out_data, size_t out_len)
412
struct wpabuf * tls_connection_encrypt(void *tls_ctx,
413
struct tls_connection *conn,
414
const struct wpabuf *in_data)
384
416
#ifdef CONFIG_TLS_INTERNAL_CLIENT
385
417
if (conn->client) {
386
return tlsv1_client_encrypt(conn->client, in_data, in_len,
420
buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
423
res = tlsv1_client_encrypt(conn->client, wpabuf_head(in_data),
431
wpabuf_put(buf, res);
389
434
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
390
435
#ifdef CONFIG_TLS_INTERNAL_SERVER
391
436
if (conn->server) {
392
return tlsv1_server_encrypt(conn->server, in_data, in_len,
439
buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
442
res = tlsv1_server_encrypt(conn->server, wpabuf_head(in_data),
450
wpabuf_put(buf, res);
395
453
#endif /* CONFIG_TLS_INTERNAL_SERVER */
400
int tls_connection_decrypt(void *tls_ctx, struct tls_connection *conn,
401
const u8 *in_data, size_t in_len,
402
u8 *out_data, size_t out_len)
458
struct wpabuf * tls_connection_decrypt(void *tls_ctx,
459
struct tls_connection *conn,
460
const struct wpabuf *in_data)
404
462
#ifdef CONFIG_TLS_INTERNAL_CLIENT
405
463
if (conn->client) {
406
return tlsv1_client_decrypt(conn->client, in_data, in_len,
466
buf = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
469
res = tlsv1_client_decrypt(conn->client, wpabuf_head(in_data),
477
wpabuf_put(buf, res);
409
480
#endif /* CONFIG_TLS_INTERNAL_CLIENT */
410
481
#ifdef CONFIG_TLS_INTERNAL_SERVER
411
482
if (conn->server) {
412
return tlsv1_server_decrypt(conn->server, in_data, in_len,
485
buf = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
488
res = tlsv1_server_decrypt(conn->server, wpabuf_head(in_data),
496
wpabuf_put(buf, res);
415
499
#endif /* CONFIG_TLS_INTERNAL_SERVER */