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

Function crypto_newsession

freebsd/opencrypto/crypto.c:909–963  ·  view source on GitHub ↗

* Create a new session. The crid argument specifies a crypto * driver to use or constraints on a driver to select (hardware * only, software only, either). Whatever driver is selected * must be capable of the requested crypto algorithms. */

Source from the content-addressed store, hash-verified

907 * must be capable of the requested crypto algorithms.
908 */
909int
910crypto_newsession(crypto_session_t *cses,
911 const struct crypto_session_params *csp, int crid)
912{
913 static uint64_t sessid = 0;
914 crypto_session_t res;
915 struct cryptocap *cap;
916 int err;
917
918 if (!check_csp(csp))
919 return (EINVAL);
920
921 res = NULL;
922
923 CRYPTO_DRIVER_LOCK();
924 if ((crid & (CRYPTOCAP_F_HARDWARE | CRYPTOCAP_F_SOFTWARE)) == 0) {
925 /*
926 * Use specified driver; verify it is capable.
927 */
928 cap = crypto_checkdriver(crid);
929 if (cap != NULL && CRYPTODEV_PROBESESSION(cap->cc_dev, csp) > 0)
930 cap = NULL;
931 } else {
932 /*
933 * No requested driver; select based on crid flags.
934 */
935 cap = crypto_select_driver(csp, crid);
936 }
937 if (cap == NULL) {
938 CRYPTO_DRIVER_UNLOCK();
939 CRYPTDEB("no driver");
940 return (EOPNOTSUPP);
941 }
942 cap_ref(cap);
943 cap->cc_sessions++;
944 CRYPTO_DRIVER_UNLOCK();
945
946 /* Allocate a single block for the generic session and driver softc. */
947 res = malloc(sizeof(*res) + cap->cc_session_size, M_CRYPTO_DATA,
948 M_WAITOK | M_ZERO);
949 res->cap = cap;
950 res->csp = *csp;
951 res->id = atomic_fetchadd_64(&sessid, 1);
952
953 /* Call the driver initialization routine. */
954 err = CRYPTODEV_NEWSESSION(cap->cc_dev, res, csp);
955 if (err != 0) {
956 CRYPTDEB("dev newsession failed: %d", err);
957 crypto_deletesession(res);
958 return (err);
959 }
960
961 *cses = res;
962 return (0);
963}
964
965/*
966 * Delete an existing session (or a reserved session on an unregistered

Callers 7

freebsd_crypt_newsessionFunction · 0.85
cse_createFunction · 0.85
crypto_invokeFunction · 0.85
ktls_ocf_tryFunction · 0.85
ipcomp_initFunction · 0.85
ah_initFunction · 0.85
esp_initFunction · 0.85

Calls 7

check_cspFunction · 0.85
crypto_checkdriverFunction · 0.85
crypto_select_driverFunction · 0.85
cap_refFunction · 0.85
mallocFunction · 0.85
crypto_deletesessionFunction · 0.85
atomic_fetchadd_64Function · 0.50

Tested by

no test coverage detected