crypto(9): Use a more specific error code when a capable driver is not found

When crypto_newsession() is given a request for an unsupported capability,
raise a more specific error than EINVAL.

This allows cryptotest.py to skip some HMAC tests that a driver does not
support.

Reviewed by:	jhb, rlibby
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D12451
This commit is contained in:
Conrad Meyer 2017-09-26 01:31:49 +00:00
parent 996a93432a
commit a317fb03c2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=323999
2 changed files with 10 additions and 3 deletions

View File

@ -460,7 +460,7 @@ crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int crid)
CRYPTDEB("dev newsession failed");
} else {
CRYPTDEB("no driver");
err = EINVAL;
err = EOPNOTSUPP;
}
CRYPTO_DRIVER_UNLOCK();
return err;

View File

@ -30,6 +30,7 @@
#
from __future__ import print_function
import errno
import cryptodev
import itertools
import os
@ -284,8 +285,14 @@ def runSHA1HMAC(self, fname):
if len(key) > blocksize:
continue
c = Crypto(mac=alg, mackey=key,
crid=crid)
try:
c = Crypto(mac=alg, mackey=key,
crid=crid)
except EnvironmentError, e:
# Can't test hashes the driver does not support.
if e.errno != errno.EOPNOTSUPP:
raise
continue
_, r = c.encrypt(msg, iv="")