* Select a driver for an asym operation. The driver must * support the necessary algorithm. The caller can constrain * which device is selected with the flags parameter. The * algorithm we use here is pretty stupid; just use the first * driver that supports the algorithms we need. If there are * multiple suitable drivers we choose the driver with the * fewest active operations. We prefer
| 1515 | * drivers to software ones when either may be used. |
| 1516 | */ |
| 1517 | static struct cryptocap * |
| 1518 | crypto_select_kdriver(const struct cryptkop *krp, int flags) |
| 1519 | { |
| 1520 | struct cryptocap *cap, *best; |
| 1521 | int match, hid; |
| 1522 | |
| 1523 | CRYPTO_DRIVER_ASSERT(); |
| 1524 | |
| 1525 | /* |
| 1526 | * Look first for hardware crypto devices if permitted. |
| 1527 | */ |
| 1528 | if (flags & CRYPTOCAP_F_HARDWARE) |
| 1529 | match = CRYPTOCAP_F_HARDWARE; |
| 1530 | else |
| 1531 | match = CRYPTOCAP_F_SOFTWARE; |
| 1532 | best = NULL; |
| 1533 | again: |
| 1534 | for (hid = 0; hid < crypto_drivers_size; hid++) { |
| 1535 | /* |
| 1536 | * If there is no driver for this slot, or the driver |
| 1537 | * is not appropriate (hardware or software based on |
| 1538 | * match), then skip. |
| 1539 | */ |
| 1540 | cap = crypto_drivers[hid]; |
| 1541 | if (cap == NULL || |
| 1542 | (cap->cc_flags & match) == 0) |
| 1543 | continue; |
| 1544 | |
| 1545 | /* verify all the algorithms are supported. */ |
| 1546 | if (kdriver_suitable(cap, krp)) { |
| 1547 | if (best == NULL || |
| 1548 | cap->cc_koperations < best->cc_koperations) |
| 1549 | best = cap; |
| 1550 | } |
| 1551 | } |
| 1552 | if (best != NULL) |
| 1553 | return best; |
| 1554 | if (match == CRYPTOCAP_F_HARDWARE && (flags & CRYPTOCAP_F_SOFTWARE)) { |
| 1555 | /* sort of an Algol 68-style for loop */ |
| 1556 | match = CRYPTOCAP_F_SOFTWARE; |
| 1557 | goto again; |
| 1558 | } |
| 1559 | return best; |
| 1560 | } |
| 1561 | |
| 1562 | /* |
| 1563 | * Choose a driver for an asymmetric crypto request. |
no test coverage detected