mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 11:18:52 +03:00
Add convenience wrappers for common uio usage
The macOS uio struct is opaque and the API must be used, this makes the smallest changes to the code for all platforms. Reviewed-by: Matt Macy <mmacy@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Jorgen Lundman <lundman@lundman.net> Closes #10412
This commit is contained in:
+26
-38
@@ -296,19 +296,15 @@ sha2_digest_update_uio(SHA2_CTX *sha2_ctx, crypto_data_t *data)
|
||||
size_t cur_len;
|
||||
|
||||
/* we support only kernel buffer */
|
||||
if (data->cd_uio->uio_segflg != UIO_SYSSPACE)
|
||||
if (uio_segflg(data->cd_uio) != UIO_SYSSPACE)
|
||||
return (CRYPTO_ARGUMENTS_BAD);
|
||||
|
||||
/*
|
||||
* Jump to the first iovec containing data to be
|
||||
* digested.
|
||||
*/
|
||||
while (vec_idx < data->cd_uio->uio_iovcnt &&
|
||||
offset >= data->cd_uio->uio_iov[vec_idx].iov_len) {
|
||||
offset -= data->cd_uio->uio_iov[vec_idx].iov_len;
|
||||
vec_idx++;
|
||||
}
|
||||
if (vec_idx == data->cd_uio->uio_iovcnt) {
|
||||
offset = uio_index_at_offset(data->cd_uio, offset, &vec_idx);
|
||||
if (vec_idx == uio_iovcnt(data->cd_uio)) {
|
||||
/*
|
||||
* The caller specified an offset that is larger than the
|
||||
* total size of the buffers it provided.
|
||||
@@ -319,18 +315,18 @@ sha2_digest_update_uio(SHA2_CTX *sha2_ctx, crypto_data_t *data)
|
||||
/*
|
||||
* Now do the digesting on the iovecs.
|
||||
*/
|
||||
while (vec_idx < data->cd_uio->uio_iovcnt && length > 0) {
|
||||
cur_len = MIN(data->cd_uio->uio_iov[vec_idx].iov_len -
|
||||
while (vec_idx < uio_iovcnt(data->cd_uio) && length > 0) {
|
||||
cur_len = MIN(uio_iovlen(data->cd_uio, vec_idx) -
|
||||
offset, length);
|
||||
|
||||
SHA2Update(sha2_ctx, (uint8_t *)data->cd_uio->
|
||||
uio_iov[vec_idx].iov_base + offset, cur_len);
|
||||
SHA2Update(sha2_ctx, (uint8_t *)uio_iovbase(data->cd_uio,
|
||||
vec_idx) + offset, cur_len);
|
||||
length -= cur_len;
|
||||
vec_idx++;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if (vec_idx == data->cd_uio->uio_iovcnt && length > 0) {
|
||||
if (vec_idx == uio_iovcnt(data->cd_uio) && length > 0) {
|
||||
/*
|
||||
* The end of the specified iovec's was reached but
|
||||
* the length requested could not be processed, i.e.
|
||||
@@ -357,19 +353,15 @@ sha2_digest_final_uio(SHA2_CTX *sha2_ctx, crypto_data_t *digest,
|
||||
uint_t vec_idx = 0;
|
||||
|
||||
/* we support only kernel buffer */
|
||||
if (digest->cd_uio->uio_segflg != UIO_SYSSPACE)
|
||||
if (uio_segflg(digest->cd_uio) != UIO_SYSSPACE)
|
||||
return (CRYPTO_ARGUMENTS_BAD);
|
||||
|
||||
/*
|
||||
* Jump to the first iovec containing ptr to the digest to
|
||||
* be returned.
|
||||
*/
|
||||
while (vec_idx < digest->cd_uio->uio_iovcnt &&
|
||||
offset >= digest->cd_uio->uio_iov[vec_idx].iov_len) {
|
||||
offset -= digest->cd_uio->uio_iov[vec_idx].iov_len;
|
||||
vec_idx++;
|
||||
}
|
||||
if (vec_idx == digest->cd_uio->uio_iovcnt) {
|
||||
offset = uio_index_at_offset(digest->cd_uio, offset, &vec_idx);
|
||||
if (vec_idx == uio_iovcnt(digest->cd_uio)) {
|
||||
/*
|
||||
* The caller specified an offset that is
|
||||
* larger than the total size of the buffers
|
||||
@@ -379,7 +371,7 @@ sha2_digest_final_uio(SHA2_CTX *sha2_ctx, crypto_data_t *digest,
|
||||
}
|
||||
|
||||
if (offset + digest_len <=
|
||||
digest->cd_uio->uio_iov[vec_idx].iov_len) {
|
||||
uio_iovlen(digest->cd_uio, vec_idx)) {
|
||||
/*
|
||||
* The computed SHA2 digest will fit in the current
|
||||
* iovec.
|
||||
@@ -395,12 +387,12 @@ sha2_digest_final_uio(SHA2_CTX *sha2_ctx, crypto_data_t *digest,
|
||||
*/
|
||||
SHA2Final(digest_scratch, sha2_ctx);
|
||||
|
||||
bcopy(digest_scratch, (uchar_t *)digest->
|
||||
cd_uio->uio_iov[vec_idx].iov_base + offset,
|
||||
bcopy(digest_scratch, (uchar_t *)uio_iovbase(digest->
|
||||
cd_uio, vec_idx) + offset,
|
||||
digest_len);
|
||||
} else {
|
||||
SHA2Final((uchar_t *)digest->
|
||||
cd_uio->uio_iov[vec_idx].iov_base + offset,
|
||||
SHA2Final((uchar_t *)uio_iovbase(digest->
|
||||
cd_uio, vec_idx) + offset,
|
||||
sha2_ctx);
|
||||
|
||||
}
|
||||
@@ -418,12 +410,12 @@ sha2_digest_final_uio(SHA2_CTX *sha2_ctx, crypto_data_t *digest,
|
||||
|
||||
SHA2Final(digest_tmp, sha2_ctx);
|
||||
|
||||
while (vec_idx < digest->cd_uio->uio_iovcnt && length > 0) {
|
||||
while (vec_idx < uio_iovcnt(digest->cd_uio) && length > 0) {
|
||||
cur_len =
|
||||
MIN(digest->cd_uio->uio_iov[vec_idx].iov_len -
|
||||
MIN(uio_iovlen(digest->cd_uio, vec_idx) -
|
||||
offset, length);
|
||||
bcopy(digest_tmp + scratch_offset,
|
||||
digest->cd_uio->uio_iov[vec_idx].iov_base + offset,
|
||||
uio_iovbase(digest->cd_uio, vec_idx) + offset,
|
||||
cur_len);
|
||||
|
||||
length -= cur_len;
|
||||
@@ -432,7 +424,7 @@ sha2_digest_final_uio(SHA2_CTX *sha2_ctx, crypto_data_t *digest,
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if (vec_idx == digest->cd_uio->uio_iovcnt && length > 0) {
|
||||
if (vec_idx == uio_iovcnt(digest->cd_uio) && length > 0) {
|
||||
/*
|
||||
* The end of the specified iovec's was reached but
|
||||
* the length requested could not be processed, i.e.
|
||||
@@ -1259,16 +1251,12 @@ sha2_mac_verify_atomic(crypto_provider_handle_t provider,
|
||||
size_t cur_len;
|
||||
|
||||
/* we support only kernel buffer */
|
||||
if (mac->cd_uio->uio_segflg != UIO_SYSSPACE)
|
||||
if (uio_segflg(mac->cd_uio) != UIO_SYSSPACE)
|
||||
return (CRYPTO_ARGUMENTS_BAD);
|
||||
|
||||
/* jump to the first iovec containing the expected digest */
|
||||
while (vec_idx < mac->cd_uio->uio_iovcnt &&
|
||||
offset >= mac->cd_uio->uio_iov[vec_idx].iov_len) {
|
||||
offset -= mac->cd_uio->uio_iov[vec_idx].iov_len;
|
||||
vec_idx++;
|
||||
}
|
||||
if (vec_idx == mac->cd_uio->uio_iovcnt) {
|
||||
offset = uio_index_at_offset(mac->cd_uio, offset, &vec_idx);
|
||||
if (vec_idx == uio_iovcnt(mac->cd_uio)) {
|
||||
/*
|
||||
* The caller specified an offset that is
|
||||
* larger than the total size of the buffers
|
||||
@@ -1279,12 +1267,12 @@ sha2_mac_verify_atomic(crypto_provider_handle_t provider,
|
||||
}
|
||||
|
||||
/* do the comparison of computed digest vs specified one */
|
||||
while (vec_idx < mac->cd_uio->uio_iovcnt && length > 0) {
|
||||
cur_len = MIN(mac->cd_uio->uio_iov[vec_idx].iov_len -
|
||||
while (vec_idx < uio_iovcnt(mac->cd_uio) && length > 0) {
|
||||
cur_len = MIN(uio_iovlen(mac->cd_uio, vec_idx) -
|
||||
offset, length);
|
||||
|
||||
if (bcmp(digest + scratch_offset,
|
||||
mac->cd_uio->uio_iov[vec_idx].iov_base + offset,
|
||||
uio_iovbase(mac->cd_uio, vec_idx) + offset,
|
||||
cur_len) != 0) {
|
||||
ret = CRYPTO_INVALID_MAC;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user