diff options
author | Jorgen Lundman <[email protected]> | 2020-06-15 02:09:55 +0900 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-14 10:09:55 -0700 |
commit | 883a40fff427d200be41d3faabab1dca9a84b353 (patch) | |
tree | ce4521d15b4abcb6712baf0de6a840bfa884fd20 /module/icp/io | |
parent | 4f73576ea15fcf38b344b008eaf355480a08bbff (diff) |
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 <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Jorgen Lundman <[email protected]>
Closes #10412
Diffstat (limited to 'module/icp/io')
-rw-r--r-- | module/icp/io/sha1_mod.c | 62 | ||||
-rw-r--r-- | module/icp/io/sha2_mod.c | 64 | ||||
-rw-r--r-- | module/icp/io/skein_mod.c | 42 |
3 files changed, 68 insertions, 100 deletions
diff --git a/module/icp/io/sha1_mod.c b/module/icp/io/sha1_mod.c index e7c38542a..d0b23cb78 100644 --- a/module/icp/io/sha1_mod.c +++ b/module/icp/io/sha1_mod.c @@ -270,19 +270,15 @@ sha1_digest_update_uio(SHA1_CTX *sha1_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. @@ -293,12 +289,12 @@ sha1_digest_update_uio(SHA1_CTX *sha1_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); SHA1Update(sha1_ctx, - (uint8_t *)data->cd_uio->uio_iov[vec_idx].iov_base + offset, + (uint8_t *)uio_iovbase(data->cd_uio, vec_idx) + offset, cur_len); length -= cur_len; @@ -306,7 +302,7 @@ sha1_digest_update_uio(SHA1_CTX *sha1_ctx, crypto_data_t *data) 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. @@ -333,19 +329,15 @@ sha1_digest_final_uio(SHA1_CTX *sha1_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 @@ -355,7 +347,7 @@ sha1_digest_final_uio(SHA1_CTX *sha1_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 SHA1 digest will fit in the current * iovec. @@ -367,12 +359,12 @@ sha1_digest_final_uio(SHA1_CTX *sha1_ctx, crypto_data_t *digest, * the user only what was requested. */ SHA1Final(digest_scratch, sha1_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 { - SHA1Final((uchar_t *)digest-> - cd_uio->uio_iov[vec_idx].iov_base + offset, + SHA1Final((uchar_t *)uio_iovbase(digest-> + cd_uio, vec_idx) + offset, sha1_ctx); } } else { @@ -389,11 +381,11 @@ sha1_digest_final_uio(SHA1_CTX *sha1_ctx, crypto_data_t *digest, SHA1Final(digest_tmp, sha1_ctx); - while (vec_idx < digest->cd_uio->uio_iovcnt && length > 0) { - cur_len = MIN(digest->cd_uio->uio_iov[vec_idx].iov_len - + while (vec_idx < uio_iovcnt(digest->cd_uio) && length > 0) { + cur_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; @@ -402,7 +394,7 @@ sha1_digest_final_uio(SHA1_CTX *sha1_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. @@ -1103,16 +1095,12 @@ sha1_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 @@ -1123,12 +1111,12 @@ sha1_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; diff --git a/module/icp/io/sha2_mod.c b/module/icp/io/sha2_mod.c index 3254f5597..a4a5c6041 100644 --- a/module/icp/io/sha2_mod.c +++ b/module/icp/io/sha2_mod.c @@ -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; diff --git a/module/icp/io/skein_mod.c b/module/icp/io/skein_mod.c index afd7f5680..621fa6158 100644 --- a/module/icp/io/skein_mod.c +++ b/module/icp/io/skein_mod.c @@ -271,22 +271,18 @@ skein_digest_update_uio(skein_ctx_t *ctx, const crypto_data_t *data) size_t length = data->cd_length; uint_t vec_idx = 0; size_t cur_len; - const uio_t *uio = data->cd_uio; + uio_t *uio = data->cd_uio; /* we support only kernel buffer */ - if (uio->uio_segflg != UIO_SYSSPACE) + if (uio_segflg(uio) != UIO_SYSSPACE) return (CRYPTO_ARGUMENTS_BAD); /* * Jump to the first iovec containing data to be * digested. */ - while (vec_idx < uio->uio_iovcnt && - offset >= uio->uio_iov[vec_idx].iov_len) { - offset -= uio->uio_iov[vec_idx].iov_len; - vec_idx++; - } - if (vec_idx == uio->uio_iovcnt) { + offset = uio_index_at_offset(uio, offset, &vec_idx); + if (vec_idx == uio_iovcnt(uio)) { /* * The caller specified an offset that is larger than the * total size of the buffers it provided. @@ -297,16 +293,16 @@ skein_digest_update_uio(skein_ctx_t *ctx, const crypto_data_t *data) /* * Now do the digesting on the iovecs. */ - while (vec_idx < uio->uio_iovcnt && length > 0) { - cur_len = MIN(uio->uio_iov[vec_idx].iov_len - offset, length); - SKEIN_OP(ctx, Update, (uint8_t *)uio->uio_iov[vec_idx].iov_base + while (vec_idx < uio_iovcnt(uio) && length > 0) { + cur_len = MIN(uio_iovlen(uio, vec_idx) - offset, length); + SKEIN_OP(ctx, Update, (uint8_t *)uio_iovbase(uio, vec_idx) + offset, cur_len); length -= cur_len; vec_idx++; offset = 0; } - if (vec_idx == uio->uio_iovcnt && length > 0) { + if (vec_idx == uio_iovcnt(uio) && length > 0) { /* * The end of the specified iovec's was reached but * the length requested could not be processed, i.e. @@ -330,18 +326,14 @@ skein_digest_final_uio(skein_ctx_t *ctx, crypto_data_t *digest, uio_t *uio = digest->cd_uio; /* we support only kernel buffer */ - if (uio->uio_segflg != UIO_SYSSPACE) + if (uio_segflg(uio) != UIO_SYSSPACE) return (CRYPTO_ARGUMENTS_BAD); /* * Jump to the first iovec containing ptr to the digest to be returned. */ - while (vec_idx < uio->uio_iovcnt && - offset >= uio->uio_iov[vec_idx].iov_len) { - offset -= uio->uio_iov[vec_idx].iov_len; - vec_idx++; - } - if (vec_idx == uio->uio_iovcnt) { + offset = uio_index_at_offset(uio, offset, &vec_idx); + if (vec_idx == uio_iovcnt(uio)) { /* * The caller specified an offset that is larger than the * total size of the buffers it provided. @@ -349,10 +341,10 @@ skein_digest_final_uio(skein_ctx_t *ctx, crypto_data_t *digest, return (CRYPTO_DATA_LEN_RANGE); } if (offset + CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen) <= - uio->uio_iov[vec_idx].iov_len) { + uio_iovlen(uio, vec_idx)) { /* The computed digest will fit in the current iovec. */ SKEIN_OP(ctx, Final, - (uchar_t *)uio->uio_iov[vec_idx].iov_base + offset); + (uchar_t *)uio_iovbase(uio, vec_idx) + offset); } else { uint8_t *digest_tmp; off_t scratch_offset = 0; @@ -364,11 +356,11 @@ skein_digest_final_uio(skein_ctx_t *ctx, crypto_data_t *digest, if (digest_tmp == NULL) return (CRYPTO_HOST_MEMORY); SKEIN_OP(ctx, Final, digest_tmp); - while (vec_idx < uio->uio_iovcnt && length > 0) { - cur_len = MIN(uio->uio_iov[vec_idx].iov_len - offset, + while (vec_idx < uio_iovcnt(uio) && length > 0) { + cur_len = MIN(uio_iovlen(uio, vec_idx) - offset, length); bcopy(digest_tmp + scratch_offset, - uio->uio_iov[vec_idx].iov_base + offset, cur_len); + uio_iovbase(uio, vec_idx) + offset, cur_len); length -= cur_len; vec_idx++; @@ -377,7 +369,7 @@ skein_digest_final_uio(skein_ctx_t *ctx, crypto_data_t *digest, } kmem_free(digest_tmp, CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen)); - if (vec_idx == uio->uio_iovcnt && length > 0) { + if (vec_idx == uio_iovcnt(uio) && length > 0) { /* * The end of the specified iovec's was reached but * the length requested could not be processed, i.e. |