Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/openzfs/module/icp/core/kcf_prov_lib.c
Show All 34 Lines | |||||
/* | /* | ||||
* Utility routine to apply the command, 'cmd', to the | * Utility routine to apply the command, 'cmd', to the | ||||
* data in the uio structure. | * data in the uio structure. | ||||
*/ | */ | ||||
int | int | ||||
crypto_uio_data(crypto_data_t *data, uchar_t *buf, int len, cmd_type_t cmd, | crypto_uio_data(crypto_data_t *data, uchar_t *buf, int len, cmd_type_t cmd, | ||||
void *digest_ctx, void (*update)(void)) | void *digest_ctx, void (*update)(void)) | ||||
{ | { | ||||
uio_t *uiop = data->cd_uio; | zfs_uio_t *uiop = data->cd_uio; | ||||
off_t offset = data->cd_offset; | off_t offset = data->cd_offset; | ||||
size_t length = len; | size_t length = len; | ||||
uint_t vec_idx; | uint_t vec_idx; | ||||
size_t cur_len; | size_t cur_len; | ||||
uchar_t *datap; | uchar_t *datap; | ||||
ASSERT(data->cd_format == CRYPTO_DATA_UIO); | ASSERT(data->cd_format == CRYPTO_DATA_UIO); | ||||
if (uio_segflg(uiop) != UIO_SYSSPACE) { | if (zfs_uio_segflg(uiop) != 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 | ||||
* processed. | * processed. | ||||
*/ | */ | ||||
offset = uio_index_at_offset(uiop, offset, &vec_idx); | offset = zfs_uio_index_at_offset(uiop, offset, &vec_idx); | ||||
if (vec_idx == uio_iovcnt(uiop) && length > 0) { | if (vec_idx == zfs_uio_iovcnt(uiop) && length > 0) { | ||||
/* | /* | ||||
* The caller specified an offset that is larger than | * The caller specified an offset that is larger than | ||||
* the total size of the buffers it provided. | * the total size of the buffers it provided. | ||||
*/ | */ | ||||
return (CRYPTO_DATA_LEN_RANGE); | return (CRYPTO_DATA_LEN_RANGE); | ||||
} | } | ||||
while (vec_idx < uio_iovcnt(uiop) && length > 0) { | while (vec_idx < zfs_uio_iovcnt(uiop) && length > 0) { | ||||
cur_len = MIN(uio_iovlen(uiop, vec_idx) - | cur_len = MIN(zfs_uio_iovlen(uiop, vec_idx) - | ||||
offset, length); | offset, length); | ||||
datap = (uchar_t *)(uio_iovbase(uiop, vec_idx) + offset); | datap = (uchar_t *)(zfs_uio_iovbase(uiop, vec_idx) + offset); | ||||
switch (cmd) { | switch (cmd) { | ||||
case COPY_FROM_DATA: | case COPY_FROM_DATA: | ||||
bcopy(datap, buf, cur_len); | bcopy(datap, buf, cur_len); | ||||
buf += cur_len; | buf += cur_len; | ||||
break; | break; | ||||
case COPY_TO_DATA: | case COPY_TO_DATA: | ||||
bcopy(buf, datap, cur_len); | bcopy(buf, datap, cur_len); | ||||
buf += cur_len; | buf += cur_len; | ||||
Show All 10 Lines | case GHASH_DATA: | ||||
return (CRYPTO_ARGUMENTS_BAD); | return (CRYPTO_ARGUMENTS_BAD); | ||||
} | } | ||||
length -= cur_len; | length -= cur_len; | ||||
vec_idx++; | vec_idx++; | ||||
offset = 0; | offset = 0; | ||||
} | } | ||||
if (vec_idx == uio_iovcnt(uiop) && length > 0) { | if (vec_idx == zfs_uio_iovcnt(uiop) && 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. | * the length requested could not be processed. | ||||
*/ | */ | ||||
switch (cmd) { | switch (cmd) { | ||||
case COPY_TO_DATA: | case COPY_TO_DATA: | ||||
data->cd_length = len; | data->cd_length = len; | ||||
return (CRYPTO_BUFFER_TOO_SMALL); | return (CRYPTO_BUFFER_TOO_SMALL); | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int | int | ||||
crypto_update_uio(void *ctx, crypto_data_t *input, crypto_data_t *output, | crypto_update_uio(void *ctx, crypto_data_t *input, crypto_data_t *output, | ||||
int (*cipher)(void *, caddr_t, size_t, crypto_data_t *), | int (*cipher)(void *, caddr_t, size_t, crypto_data_t *), | ||||
void (*copy_block)(uint8_t *, uint64_t *)) | void (*copy_block)(uint8_t *, uint64_t *)) | ||||
{ | { | ||||
common_ctx_t *common_ctx = ctx; | common_ctx_t *common_ctx = ctx; | ||||
uio_t *uiop = input->cd_uio; | zfs_uio_t *uiop = input->cd_uio; | ||||
off_t offset = input->cd_offset; | off_t offset = input->cd_offset; | ||||
size_t length = input->cd_length; | size_t length = input->cd_length; | ||||
uint_t vec_idx; | uint_t vec_idx; | ||||
size_t cur_len; | size_t cur_len; | ||||
ASSERT(input != output); | ASSERT(input != output); | ||||
if (input->cd_miscdata != NULL) { | if (input->cd_miscdata != NULL) { | ||||
copy_block((uint8_t *)input->cd_miscdata, | copy_block((uint8_t *)input->cd_miscdata, | ||||
&common_ctx->cc_iv[0]); | &common_ctx->cc_iv[0]); | ||||
} | } | ||||
if (uio_segflg(input->cd_uio) != UIO_SYSSPACE) { | if (zfs_uio_segflg(input->cd_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 | ||||
* processed. | * processed. | ||||
*/ | */ | ||||
offset = uio_index_at_offset(uiop, offset, &vec_idx); | offset = zfs_uio_index_at_offset(uiop, offset, &vec_idx); | ||||
if (vec_idx == uio_iovcnt(uiop) && length > 0) { | if (vec_idx == zfs_uio_iovcnt(uiop) && length > 0) { | ||||
/* | /* | ||||
* 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 process the iovecs. | * Now process the iovecs. | ||||
*/ | */ | ||||
while (vec_idx < uio_iovcnt(uiop) && length > 0) { | while (vec_idx < zfs_uio_iovcnt(uiop) && length > 0) { | ||||
cur_len = MIN(uio_iovlen(uiop, vec_idx) - | cur_len = MIN(zfs_uio_iovlen(uiop, vec_idx) - | ||||
offset, length); | offset, length); | ||||
int rv = (cipher)(ctx, uio_iovbase(uiop, vec_idx) + offset, | int rv = (cipher)(ctx, zfs_uio_iovbase(uiop, vec_idx) + offset, | ||||
cur_len, output); | cur_len, output); | ||||
if (rv != CRYPTO_SUCCESS) { | if (rv != CRYPTO_SUCCESS) { | ||||
return (rv); | return (rv); | ||||
} | } | ||||
length -= cur_len; | length -= cur_len; | ||||
vec_idx++; | vec_idx++; | ||||
offset = 0; | offset = 0; | ||||
} | } | ||||
if (vec_idx == uio_iovcnt(uiop) && length > 0) { | if (vec_idx == zfs_uio_iovcnt(uiop) && 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); | ||||
} | } |