MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ktls_ocf_try

Function ktls_ocf_try

freebsd/opencrypto/ktls_ocf.c:557–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557static int
558ktls_ocf_try(struct socket *so, struct ktls_session *tls, int direction)
559{
560 struct crypto_session_params csp, mac_csp;
561 struct ocf_session *os;
562 int error, mac_len;
563
564 memset(&csp, 0, sizeof(csp));
565 memset(&mac_csp, 0, sizeof(mac_csp));
566 mac_csp.csp_mode = CSP_MODE_NONE;
567 mac_len = 0;
568
569 switch (tls->params.cipher_algorithm) {
570 case CRYPTO_AES_NIST_GCM_16:
571 switch (tls->params.cipher_key_len) {
572 case 128 / 8:
573 case 256 / 8:
574 break;
575 default:
576 return (EINVAL);
577 }
578
579 /* Only TLS 1.2 and 1.3 are supported. */
580 if (tls->params.tls_vmajor != TLS_MAJOR_VER_ONE ||
581 tls->params.tls_vminor < TLS_MINOR_VER_TWO ||
582 tls->params.tls_vminor > TLS_MINOR_VER_THREE)
583 return (EPROTONOSUPPORT);
584
585 /* TLS 1.3 is not yet supported for receive. */
586 if (direction == KTLS_RX &&
587 tls->params.tls_vminor == TLS_MINOR_VER_THREE)
588 return (EPROTONOSUPPORT);
589
590 csp.csp_flags |= CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD;
591 csp.csp_mode = CSP_MODE_AEAD;
592 csp.csp_cipher_alg = CRYPTO_AES_NIST_GCM_16;
593 csp.csp_cipher_key = tls->params.cipher_key;
594 csp.csp_cipher_klen = tls->params.cipher_key_len;
595 csp.csp_ivlen = AES_GCM_IV_LEN;
596 break;
597 case CRYPTO_AES_CBC:
598 switch (tls->params.cipher_key_len) {
599 case 128 / 8:
600 case 256 / 8:
601 break;
602 default:
603 return (EINVAL);
604 }
605
606 switch (tls->params.auth_algorithm) {
607 case CRYPTO_SHA1_HMAC:
608 mac_len = SHA1_HASH_LEN;
609 break;
610 case CRYPTO_SHA2_256_HMAC:
611 mac_len = SHA2_256_HASH_LEN;
612 break;
613 case CRYPTO_SHA2_384_HMAC:
614 mac_len = SHA2_384_HASH_LEN;

Callers

nothing calls this directly

Calls 7

memsetFunction · 0.85
mallocFunction · 0.85
crypto_newsessionFunction · 0.85
crypto_freesessionFunction · 0.85
mtx_initFunction · 0.85
freeFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected