* 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. */
| 907 | * must be capable of the requested crypto algorithms. |
| 908 | */ |
| 909 | int |
| 910 | crypto_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 |
no test coverage detected