mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-26 04:07:45 +03:00
Remove bcopy(), bzero(), bcmp()
bcopy() has a confusing argument order and is actually a move, not a copy; they're all deprecated since POSIX.1-2001 and removed in -2008, and we shim them out to mem*() on Linux anyway Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12996
This commit is contained in:
+43
-43
@@ -108,8 +108,8 @@ gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
|
||||
|
||||
if (length + ctx->gcm_remainder_len < block_size) {
|
||||
/* accumulate bytes here and return */
|
||||
bcopy(datap,
|
||||
(uint8_t *)ctx->gcm_remainder + ctx->gcm_remainder_len,
|
||||
memcpy((uint8_t *)ctx->gcm_remainder + ctx->gcm_remainder_len,
|
||||
datap,
|
||||
length);
|
||||
ctx->gcm_remainder_len += length;
|
||||
if (ctx->gcm_copy_to == NULL) {
|
||||
@@ -130,8 +130,8 @@ gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
|
||||
if (need > remainder)
|
||||
return (CRYPTO_DATA_LEN_RANGE);
|
||||
|
||||
bcopy(datap, &((uint8_t *)ctx->gcm_remainder)
|
||||
[ctx->gcm_remainder_len], need);
|
||||
memcpy(&((uint8_t *)ctx->gcm_remainder)
|
||||
[ctx->gcm_remainder_len], datap, need);
|
||||
|
||||
blockp = (uint8_t *)ctx->gcm_remainder;
|
||||
} else {
|
||||
@@ -162,10 +162,10 @@ gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
|
||||
if (out_data_1_len == block_size) {
|
||||
copy_block(lastp, out_data_1);
|
||||
} else {
|
||||
bcopy(lastp, out_data_1, out_data_1_len);
|
||||
memcpy(out_data_1, lastp, out_data_1_len);
|
||||
if (out_data_2 != NULL) {
|
||||
bcopy(lastp + out_data_1_len,
|
||||
out_data_2,
|
||||
memcpy(out_data_2,
|
||||
lastp + out_data_1_len,
|
||||
block_size - out_data_1_len);
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
|
||||
|
||||
/* Incomplete last block. */
|
||||
if (remainder > 0 && remainder < block_size) {
|
||||
bcopy(datap, ctx->gcm_remainder, remainder);
|
||||
memcpy(ctx->gcm_remainder, datap, remainder);
|
||||
ctx->gcm_remainder_len = remainder;
|
||||
ctx->gcm_copy_to = datap;
|
||||
goto out;
|
||||
@@ -245,7 +245,7 @@ gcm_encrypt_final(gcm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
|
||||
(uint8_t *)ctx->gcm_tmp);
|
||||
|
||||
macp = (uint8_t *)ctx->gcm_remainder;
|
||||
bzero(macp + ctx->gcm_remainder_len,
|
||||
memset(macp + ctx->gcm_remainder_len, 0,
|
||||
block_size - ctx->gcm_remainder_len);
|
||||
|
||||
/* XOR with counter block */
|
||||
@@ -309,8 +309,8 @@ gcm_decrypt_incomplete_block(gcm_ctx_t *ctx, size_t block_size, size_t index,
|
||||
counterp = (uint8_t *)ctx->gcm_tmp;
|
||||
|
||||
/* authentication tag */
|
||||
bzero((uint8_t *)ctx->gcm_tmp, block_size);
|
||||
bcopy(datap, (uint8_t *)ctx->gcm_tmp, ctx->gcm_remainder_len);
|
||||
memset((uint8_t *)ctx->gcm_tmp, 0, block_size);
|
||||
memcpy((uint8_t *)ctx->gcm_tmp, datap, ctx->gcm_remainder_len);
|
||||
|
||||
/* add ciphertext to the hash */
|
||||
GHASH(ctx, ctx->gcm_tmp, ctx->gcm_ghash, gcm_impl_get_ops());
|
||||
@@ -350,7 +350,7 @@ gcm_mode_decrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
|
||||
}
|
||||
|
||||
if (ctx->gcm_pt_buf != NULL) {
|
||||
bcopy(ctx->gcm_pt_buf, new, ctx->gcm_pt_buf_len);
|
||||
memcpy(new, ctx->gcm_pt_buf, ctx->gcm_pt_buf_len);
|
||||
vmem_free(ctx->gcm_pt_buf, ctx->gcm_pt_buf_len);
|
||||
} else {
|
||||
ASSERT0(ctx->gcm_pt_buf_len);
|
||||
@@ -358,7 +358,7 @@ gcm_mode_decrypt_contiguous_blocks(gcm_ctx_t *ctx, char *data, size_t length,
|
||||
|
||||
ctx->gcm_pt_buf = new;
|
||||
ctx->gcm_pt_buf_len = new_len;
|
||||
bcopy(data, &ctx->gcm_pt_buf[ctx->gcm_processed_data_len],
|
||||
memcpy(&ctx->gcm_pt_buf[ctx->gcm_processed_data_len], data,
|
||||
length);
|
||||
ctx->gcm_processed_data_len += length;
|
||||
}
|
||||
@@ -397,7 +397,7 @@ gcm_decrypt_final(gcm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
|
||||
while (remainder > 0) {
|
||||
/* Incomplete last block */
|
||||
if (remainder < block_size) {
|
||||
bcopy(blockp, ctx->gcm_remainder, remainder);
|
||||
memcpy(ctx->gcm_remainder, blockp, remainder);
|
||||
ctx->gcm_remainder_len = remainder;
|
||||
/*
|
||||
* not expecting anymore ciphertext, just
|
||||
@@ -438,7 +438,7 @@ out:
|
||||
xor_block((uint8_t *)ctx->gcm_J0, ghash);
|
||||
|
||||
/* compare the input authentication tag with what we calculated */
|
||||
if (bcmp(&ctx->gcm_pt_buf[pt_len], ghash, ctx->gcm_tag_len)) {
|
||||
if (memcmp(&ctx->gcm_pt_buf[pt_len], ghash, ctx->gcm_tag_len)) {
|
||||
/* They don't match */
|
||||
return (CRYPTO_INVALID_MAC);
|
||||
} else {
|
||||
@@ -495,7 +495,7 @@ gcm_format_initial_blocks(uchar_t *iv, ulong_t iv_len,
|
||||
ghash = (uint8_t *)ctx->gcm_ghash;
|
||||
cb = (uint8_t *)ctx->gcm_cb;
|
||||
if (iv_len == 12) {
|
||||
bcopy(iv, cb, 12);
|
||||
memcpy(cb, iv, 12);
|
||||
cb[12] = 0;
|
||||
cb[13] = 0;
|
||||
cb[14] = 0;
|
||||
@@ -506,8 +506,8 @@ gcm_format_initial_blocks(uchar_t *iv, ulong_t iv_len,
|
||||
/* GHASH the IV */
|
||||
do {
|
||||
if (remainder < block_size) {
|
||||
bzero(cb, block_size);
|
||||
bcopy(&(iv[processed]), cb, remainder);
|
||||
memset(cb, 0, block_size);
|
||||
memcpy(cb, &(iv[processed]), remainder);
|
||||
datap = (uint8_t *)cb;
|
||||
remainder = 0;
|
||||
} else {
|
||||
@@ -539,7 +539,7 @@ gcm_init(gcm_ctx_t *ctx, unsigned char *iv, size_t iv_len,
|
||||
size_t remainder, processed;
|
||||
|
||||
/* encrypt zero block to get subkey H */
|
||||
bzero(ctx->gcm_H, sizeof (ctx->gcm_H));
|
||||
memset(ctx->gcm_H, 0, sizeof (ctx->gcm_H));
|
||||
encrypt_block(ctx->gcm_keysched, (uint8_t *)ctx->gcm_H,
|
||||
(uint8_t *)ctx->gcm_H);
|
||||
|
||||
@@ -549,8 +549,8 @@ gcm_init(gcm_ctx_t *ctx, unsigned char *iv, size_t iv_len,
|
||||
gops = gcm_impl_get_ops();
|
||||
authp = (uint8_t *)ctx->gcm_tmp;
|
||||
ghash = (uint8_t *)ctx->gcm_ghash;
|
||||
bzero(authp, block_size);
|
||||
bzero(ghash, block_size);
|
||||
memset(authp, 0, block_size);
|
||||
memset(ghash, 0, block_size);
|
||||
|
||||
processed = 0;
|
||||
remainder = auth_data_len;
|
||||
@@ -562,9 +562,9 @@ gcm_init(gcm_ctx_t *ctx, unsigned char *iv, size_t iv_len,
|
||||
*/
|
||||
|
||||
if (auth_data != NULL) {
|
||||
bzero(authp, block_size);
|
||||
bcopy(&(auth_data[processed]),
|
||||
authp, remainder);
|
||||
memset(authp, 0, block_size);
|
||||
memcpy(authp, &(auth_data[processed]),
|
||||
remainder);
|
||||
} else {
|
||||
ASSERT0(remainder);
|
||||
}
|
||||
@@ -1139,10 +1139,10 @@ gcm_simd_get_htab_size(boolean_t simd_mode)
|
||||
static inline void
|
||||
gcm_clear_ctx(gcm_ctx_t *ctx)
|
||||
{
|
||||
bzero(ctx->gcm_remainder, sizeof (ctx->gcm_remainder));
|
||||
bzero(ctx->gcm_H, sizeof (ctx->gcm_H));
|
||||
bzero(ctx->gcm_J0, sizeof (ctx->gcm_J0));
|
||||
bzero(ctx->gcm_tmp, sizeof (ctx->gcm_tmp));
|
||||
memset(ctx->gcm_remainder, 0, sizeof (ctx->gcm_remainder));
|
||||
memset(ctx->gcm_H, 0, sizeof (ctx->gcm_H));
|
||||
memset(ctx->gcm_J0, 0, sizeof (ctx->gcm_J0));
|
||||
memset(ctx->gcm_tmp, 0, sizeof (ctx->gcm_tmp));
|
||||
}
|
||||
|
||||
/* Increment the GCM counter block by n. */
|
||||
@@ -1187,8 +1187,8 @@ gcm_mode_encrypt_contiguous_blocks_avx(gcm_ctx_t *ctx, char *data,
|
||||
need = block_size - ctx->gcm_remainder_len;
|
||||
if (length < need) {
|
||||
/* Accumulate bytes here and return. */
|
||||
bcopy(datap, (uint8_t *)ctx->gcm_remainder +
|
||||
ctx->gcm_remainder_len, length);
|
||||
memcpy((uint8_t *)ctx->gcm_remainder +
|
||||
ctx->gcm_remainder_len, datap, length);
|
||||
|
||||
ctx->gcm_remainder_len += length;
|
||||
if (ctx->gcm_copy_to == NULL) {
|
||||
@@ -1197,8 +1197,8 @@ gcm_mode_encrypt_contiguous_blocks_avx(gcm_ctx_t *ctx, char *data,
|
||||
return (CRYPTO_SUCCESS);
|
||||
} else {
|
||||
/* Complete incomplete block. */
|
||||
bcopy(datap, (uint8_t *)ctx->gcm_remainder +
|
||||
ctx->gcm_remainder_len, need);
|
||||
memcpy((uint8_t *)ctx->gcm_remainder +
|
||||
ctx->gcm_remainder_len, datap, need);
|
||||
|
||||
ctx->gcm_copy_to = NULL;
|
||||
}
|
||||
@@ -1276,7 +1276,7 @@ gcm_mode_encrypt_contiguous_blocks_avx(gcm_ctx_t *ctx, char *data,
|
||||
/* Less than GCM_AVX_MIN_ENCRYPT_BYTES remain, operate on blocks. */
|
||||
while (bleft > 0) {
|
||||
if (bleft < block_size) {
|
||||
bcopy(datap, ctx->gcm_remainder, bleft);
|
||||
memcpy(ctx->gcm_remainder, datap, bleft);
|
||||
ctx->gcm_remainder_len = bleft;
|
||||
ctx->gcm_copy_to = datap;
|
||||
goto out;
|
||||
@@ -1335,7 +1335,7 @@ gcm_encrypt_final_avx(gcm_ctx_t *ctx, crypto_data_t *out, size_t block_size)
|
||||
const uint32_t *cb = (uint32_t *)ctx->gcm_cb;
|
||||
|
||||
aes_encrypt_intel(keysched, aes_rounds, cb, (uint32_t *)tmp);
|
||||
bzero(remainder + rem_len, block_size - rem_len);
|
||||
memset(remainder + rem_len, 0, block_size - rem_len);
|
||||
for (int i = 0; i < rem_len; i++) {
|
||||
remainder[i] ^= tmp[i];
|
||||
}
|
||||
@@ -1431,8 +1431,8 @@ gcm_decrypt_final_avx(gcm_ctx_t *ctx, crypto_data_t *out, size_t block_size)
|
||||
if (bleft < block_size) {
|
||||
uint8_t *lastb = (uint8_t *)ctx->gcm_remainder;
|
||||
|
||||
bzero(lastb, block_size);
|
||||
bcopy(datap, lastb, bleft);
|
||||
memset(lastb, 0, block_size);
|
||||
memcpy(lastb, datap, bleft);
|
||||
/* The GCM processing. */
|
||||
GHASH_AVX(ctx, lastb, block_size);
|
||||
aes_encrypt_intel(key->encr_ks.ks32, key->nr, cb, tmp);
|
||||
@@ -1468,7 +1468,7 @@ gcm_decrypt_final_avx(gcm_ctx_t *ctx, crypto_data_t *out, size_t block_size)
|
||||
kfpu_end();
|
||||
|
||||
/* Compare the input authentication tag with what we calculated. */
|
||||
if (bcmp(&ctx->gcm_pt_buf[pt_len], ghash, ctx->gcm_tag_len)) {
|
||||
if (memcmp(&ctx->gcm_pt_buf[pt_len], ghash, ctx->gcm_tag_len)) {
|
||||
/* They don't match. */
|
||||
return (CRYPTO_INVALID_MAC);
|
||||
}
|
||||
@@ -1500,8 +1500,8 @@ gcm_init_avx(gcm_ctx_t *ctx, unsigned char *iv, size_t iv_len,
|
||||
ASSERT(block_size == GCM_BLOCK_LEN);
|
||||
|
||||
/* Init H (encrypt zero block) and create the initial counter block. */
|
||||
bzero(ctx->gcm_ghash, sizeof (ctx->gcm_ghash));
|
||||
bzero(H, sizeof (ctx->gcm_H));
|
||||
memset(ctx->gcm_ghash, 0, sizeof (ctx->gcm_ghash));
|
||||
memset(H, 0, sizeof (ctx->gcm_H));
|
||||
kfpu_begin();
|
||||
aes_encrypt_intel(keysched, aes_rounds,
|
||||
(const uint32_t *)H, (uint32_t *)H);
|
||||
@@ -1509,13 +1509,13 @@ gcm_init_avx(gcm_ctx_t *ctx, unsigned char *iv, size_t iv_len,
|
||||
gcm_init_htab_avx(ctx->gcm_Htable, H);
|
||||
|
||||
if (iv_len == 12) {
|
||||
bcopy(iv, cb, 12);
|
||||
memcpy(cb, iv, 12);
|
||||
cb[12] = 0;
|
||||
cb[13] = 0;
|
||||
cb[14] = 0;
|
||||
cb[15] = 1;
|
||||
/* We need the ICB later. */
|
||||
bcopy(cb, ctx->gcm_J0, sizeof (ctx->gcm_J0));
|
||||
memcpy(ctx->gcm_J0, cb, sizeof (ctx->gcm_J0));
|
||||
} else {
|
||||
/*
|
||||
* Most consumers use 12 byte IVs, so it's OK to use the
|
||||
@@ -1553,8 +1553,8 @@ gcm_init_avx(gcm_ctx_t *ctx, unsigned char *iv, size_t iv_len,
|
||||
/* Zero pad and hash incomplete last block. */
|
||||
uint8_t *authp = (uint8_t *)ctx->gcm_tmp;
|
||||
|
||||
bzero(authp, block_size);
|
||||
bcopy(datap, authp, incomp);
|
||||
memset(authp, 0, block_size);
|
||||
memcpy(authp, datap, incomp);
|
||||
GHASH_AVX(ctx, authp, block_size);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user