Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/openzfs/module/icp/io/skein_mod.c
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
static int | static int | ||||
skein_digest_update_uio(skein_ctx_t *ctx, const crypto_data_t *data) | skein_digest_update_uio(skein_ctx_t *ctx, const crypto_data_t *data) | ||||
{ | { | ||||
off_t offset = data->cd_offset; | off_t offset = data->cd_offset; | ||||
size_t length = data->cd_length; | size_t length = data->cd_length; | ||||
uint_t vec_idx = 0; | uint_t vec_idx = 0; | ||||
size_t cur_len; | size_t cur_len; | ||||
uio_t *uio = data->cd_uio; | zfs_uio_t *uio = data->cd_uio; | ||||
/* we support only kernel buffer */ | /* we support only kernel buffer */ | ||||
if (uio_segflg(uio) != UIO_SYSSPACE) | if (zfs_uio_segflg(uio) != UIO_SYSSPACE) | ||||
return (CRYPTO_ARGUMENTS_BAD); | return (CRYPTO_ARGUMENTS_BAD); | ||||
/* | /* | ||||
* Jump to the first iovec containing data to be | * Jump to the first iovec containing data to be | ||||
* digested. | * digested. | ||||
*/ | */ | ||||
offset = uio_index_at_offset(uio, offset, &vec_idx); | offset = zfs_uio_index_at_offset(uio, offset, &vec_idx); | ||||
if (vec_idx == uio_iovcnt(uio)) { | if (vec_idx == zfs_uio_iovcnt(uio)) { | ||||
/* | /* | ||||
* The caller specified an offset that is larger than the | * The caller specified an offset that is larger than the | ||||
* total size of the buffers it provided. | * total size of the buffers it provided. | ||||
*/ | */ | ||||
return (CRYPTO_DATA_LEN_RANGE); | return (CRYPTO_DATA_LEN_RANGE); | ||||
} | } | ||||
/* | /* | ||||
* Now do the digesting on the iovecs. | * Now do the digesting on the iovecs. | ||||
*/ | */ | ||||
while (vec_idx < uio_iovcnt(uio) && length > 0) { | while (vec_idx < zfs_uio_iovcnt(uio) && length > 0) { | ||||
cur_len = MIN(uio_iovlen(uio, vec_idx) - offset, length); | cur_len = MIN(zfs_uio_iovlen(uio, vec_idx) - offset, length); | ||||
SKEIN_OP(ctx, Update, (uint8_t *)uio_iovbase(uio, vec_idx) | SKEIN_OP(ctx, Update, (uint8_t *)zfs_uio_iovbase(uio, vec_idx) | ||||
+ offset, cur_len); | + offset, cur_len); | ||||
length -= cur_len; | length -= cur_len; | ||||
vec_idx++; | vec_idx++; | ||||
offset = 0; | offset = 0; | ||||
} | } | ||||
if (vec_idx == uio_iovcnt(uio) && length > 0) { | if (vec_idx == zfs_uio_iovcnt(uio) && length > 0) { | ||||
/* | /* | ||||
* The end of the specified iovec's was reached but | * The end of the specified iovec's was reached but | ||||
* the length requested could not be processed, i.e. | * the length requested could not be processed, i.e. | ||||
* The caller requested to digest more data than it provided. | * The caller requested to digest more data than it provided. | ||||
*/ | */ | ||||
return (CRYPTO_DATA_LEN_RANGE); | return (CRYPTO_DATA_LEN_RANGE); | ||||
} | } | ||||
return (CRYPTO_SUCCESS); | return (CRYPTO_SUCCESS); | ||||
} | } | ||||
/* | /* | ||||
* Performs a Final on a context and writes to a uio digest output. | * Performs a Final on a context and writes to a uio digest output. | ||||
*/ | */ | ||||
static int | static int | ||||
skein_digest_final_uio(skein_ctx_t *ctx, crypto_data_t *digest, | skein_digest_final_uio(skein_ctx_t *ctx, crypto_data_t *digest, | ||||
crypto_req_handle_t req) | crypto_req_handle_t req) | ||||
{ | { | ||||
off_t offset = digest->cd_offset; | off_t offset = digest->cd_offset; | ||||
uint_t vec_idx = 0; | uint_t vec_idx = 0; | ||||
uio_t *uio = digest->cd_uio; | zfs_uio_t *uio = digest->cd_uio; | ||||
/* we support only kernel buffer */ | /* we support only kernel buffer */ | ||||
if (uio_segflg(uio) != UIO_SYSSPACE) | if (zfs_uio_segflg(uio) != UIO_SYSSPACE) | ||||
return (CRYPTO_ARGUMENTS_BAD); | return (CRYPTO_ARGUMENTS_BAD); | ||||
/* | /* | ||||
* Jump to the first iovec containing ptr to the digest to be returned. | * Jump to the first iovec containing ptr to the digest to be returned. | ||||
*/ | */ | ||||
offset = uio_index_at_offset(uio, offset, &vec_idx); | offset = zfs_uio_index_at_offset(uio, offset, &vec_idx); | ||||
if (vec_idx == uio_iovcnt(uio)) { | if (vec_idx == zfs_uio_iovcnt(uio)) { | ||||
/* | /* | ||||
* The caller specified an offset that is larger than the | * The caller specified an offset that is larger than the | ||||
* total size of the buffers it provided. | * total size of the buffers it provided. | ||||
*/ | */ | ||||
return (CRYPTO_DATA_LEN_RANGE); | return (CRYPTO_DATA_LEN_RANGE); | ||||
} | } | ||||
if (offset + CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen) <= | if (offset + CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen) <= | ||||
uio_iovlen(uio, vec_idx)) { | zfs_uio_iovlen(uio, vec_idx)) { | ||||
/* The computed digest will fit in the current iovec. */ | /* The computed digest will fit in the current iovec. */ | ||||
SKEIN_OP(ctx, Final, | SKEIN_OP(ctx, Final, | ||||
(uchar_t *)uio_iovbase(uio, vec_idx) + offset); | (uchar_t *)zfs_uio_iovbase(uio, vec_idx) + offset); | ||||
} else { | } else { | ||||
uint8_t *digest_tmp; | uint8_t *digest_tmp; | ||||
off_t scratch_offset = 0; | off_t scratch_offset = 0; | ||||
size_t length = CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen); | size_t length = CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen); | ||||
size_t cur_len; | size_t cur_len; | ||||
digest_tmp = kmem_alloc(CRYPTO_BITS2BYTES( | digest_tmp = kmem_alloc(CRYPTO_BITS2BYTES( | ||||
ctx->sc_digest_bitlen), crypto_kmflag(req)); | ctx->sc_digest_bitlen), crypto_kmflag(req)); | ||||
if (digest_tmp == NULL) | if (digest_tmp == NULL) | ||||
return (CRYPTO_HOST_MEMORY); | return (CRYPTO_HOST_MEMORY); | ||||
SKEIN_OP(ctx, Final, digest_tmp); | SKEIN_OP(ctx, Final, digest_tmp); | ||||
while (vec_idx < uio_iovcnt(uio) && length > 0) { | while (vec_idx < zfs_uio_iovcnt(uio) && length > 0) { | ||||
cur_len = MIN(uio_iovlen(uio, vec_idx) - offset, | cur_len = MIN(zfs_uio_iovlen(uio, vec_idx) - offset, | ||||
length); | length); | ||||
bcopy(digest_tmp + scratch_offset, | bcopy(digest_tmp + scratch_offset, | ||||
uio_iovbase(uio, vec_idx) + offset, cur_len); | zfs_uio_iovbase(uio, vec_idx) + offset, cur_len); | ||||
length -= cur_len; | length -= cur_len; | ||||
vec_idx++; | vec_idx++; | ||||
scratch_offset += cur_len; | scratch_offset += cur_len; | ||||
offset = 0; | offset = 0; | ||||
} | } | ||||
kmem_free(digest_tmp, CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen)); | kmem_free(digest_tmp, CRYPTO_BITS2BYTES(ctx->sc_digest_bitlen)); | ||||
if (vec_idx == uio_iovcnt(uio) && length > 0) { | if (vec_idx == zfs_uio_iovcnt(uio) && length > 0) { | ||||
/* | /* | ||||
* The end of the specified iovec's was reached but | * The end of the specified iovec's was reached but | ||||
* the length requested could not be processed, i.e. | * the length requested could not be processed, i.e. | ||||
* The caller requested to digest more data than it | * The caller requested to digest more data than it | ||||
* provided. | * provided. | ||||
*/ | */ | ||||
return (CRYPTO_DATA_LEN_RANGE); | return (CRYPTO_DATA_LEN_RANGE); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 348 Lines • Show Last 20 Lines |