]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/icp/algs/modes/ccm.c
Remove bcopy(), bzero(), bcmp()
[mirror_zfs.git] / module / icp / algs / modes / ccm.c
index a41cbc395fd6628b75e3970a707358c5dc5965b4..9fde2684a7c494afb1a00cb147e5e03cc4148433 100644 (file)
@@ -59,8 +59,8 @@ ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
 
        if (length + ctx->ccm_remainder_len < block_size) {
                /* accumulate bytes here and return */
-               bcopy(datap,
-                   (uint8_t *)ctx->ccm_remainder + ctx->ccm_remainder_len,
+               memcpy((uint8_t *)ctx->ccm_remainder + ctx->ccm_remainder_len,
+                   datap,
                    length);
                ctx->ccm_remainder_len += length;
                ctx->ccm_copy_to = datap;
@@ -80,8 +80,8 @@ ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
                        if (need > remainder)
                                return (CRYPTO_DATA_LEN_RANGE);
 
-                       bcopy(datap, &((uint8_t *)ctx->ccm_remainder)
-                           [ctx->ccm_remainder_len], need);
+                       memcpy(&((uint8_t *)ctx->ccm_remainder)
+                           [ctx->ccm_remainder_len], datap, need);
 
                        blockp = (uint8_t *)ctx->ccm_remainder;
                } else {
@@ -132,10 +132,10 @@ ccm_mode_encrypt_contiguous_blocks(ccm_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);
                        }
                }
@@ -154,7 +154,7 @@ ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
 
                /* Incomplete last block. */
                if (remainder > 0 && remainder < block_size) {
-                       bcopy(datap, ctx->ccm_remainder, remainder);
+                       memcpy(ctx->ccm_remainder, datap, remainder);
                        ctx->ccm_remainder_len = remainder;
                        ctx->ccm_copy_to = datap;
                        goto out;
@@ -224,10 +224,10 @@ ccm_encrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
 
                /* ccm_mac_input_buf is not used for encryption */
                macp = (uint8_t *)ctx->ccm_mac_input_buf;
-               bzero(macp, block_size);
+               memset(macp, 0, block_size);
 
                /* copy remainder to temporary buffer */
-               bcopy(ctx->ccm_remainder, macp, ctx->ccm_remainder_len);
+               memcpy(macp, ctx->ccm_remainder, ctx->ccm_remainder_len);
 
                /* calculate the CBC MAC */
                xor_block(macp, mac_buf);
@@ -254,33 +254,32 @@ ccm_encrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
            ctx->ccm_remainder_len + ctx->ccm_mac_len);
 
        if (ctx->ccm_remainder_len > 0) {
-
                /* copy temporary block to where it belongs */
                if (out_data_2 == NULL) {
                        /* everything will fit in out_data_1 */
-                       bcopy(macp, out_data_1, ctx->ccm_remainder_len);
-                       bcopy(ccm_mac_p, out_data_1 + ctx->ccm_remainder_len,
+                       memcpy(out_data_1, macp, ctx->ccm_remainder_len);
+                       memcpy(out_data_1 + ctx->ccm_remainder_len, ccm_mac_p,
                            ctx->ccm_mac_len);
                } else {
-
                        if (out_data_1_len < ctx->ccm_remainder_len) {
-
                                size_t data_2_len_used;
 
-                               bcopy(macp, out_data_1, out_data_1_len);
+                               memcpy(out_data_1, macp, out_data_1_len);
 
                                data_2_len_used = ctx->ccm_remainder_len
                                    - out_data_1_len;
 
-                               bcopy((uint8_t *)macp + out_data_1_len,
-                                   out_data_2, data_2_len_used);
-                               bcopy(ccm_mac_p, out_data_2 + data_2_len_used,
+                               memcpy(out_data_2,
+                                   (uint8_t *)macp + out_data_1_len,
+                                   data_2_len_used);
+                               memcpy(out_data_2 + data_2_len_used,
+                                   ccm_mac_p,
                                    ctx->ccm_mac_len);
                        } else {
-                               bcopy(macp, out_data_1, out_data_1_len);
+                               memcpy(out_data_1, macp, out_data_1_len);
                                if (out_data_1_len == ctx->ccm_remainder_len) {
                                        /* mac will be in out_data_2 */
-                                       bcopy(ccm_mac_p, out_data_2,
+                                       memcpy(out_data_2, ccm_mac_p,
                                            ctx->ccm_mac_len);
                                } else {
                                        size_t len_not_used = out_data_1_len -
@@ -290,11 +289,11 @@ ccm_encrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
                                         * out_data_1, part of the mac will be
                                         * in out_data_2
                                         */
-                                       bcopy(ccm_mac_p,
-                                           out_data_1 + ctx->ccm_remainder_len,
-                                           len_not_used);
-                                       bcopy(ccm_mac_p + len_not_used,
-                                           out_data_2,
+                                       memcpy(out_data_1 +
+                                           ctx->ccm_remainder_len,
+                                           ccm_mac_p, len_not_used);
+                                       memcpy(out_data_2,
+                                           ccm_mac_p + len_not_used,
                                            ctx->ccm_mac_len - len_not_used);
 
                                }
@@ -302,9 +301,9 @@ ccm_encrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
                }
        } else {
                /* copy block to where it belongs */
-               bcopy(ccm_mac_p, out_data_1, out_data_1_len);
+               memcpy(out_data_1, ccm_mac_p, out_data_1_len);
                if (out_data_2 != NULL) {
-                       bcopy(ccm_mac_p + out_data_1_len, out_data_2,
+                       memcpy(out_data_2, ccm_mac_p + out_data_1_len,
                            block_size - out_data_1_len);
                }
        }
@@ -372,7 +371,7 @@ ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
                }
                tmp = (uint8_t *)ctx->ccm_mac_input_buf;
 
-               bcopy(datap, tmp + pm_len, length);
+               memcpy(tmp + pm_len, datap, length);
 
                ctx->ccm_processed_mac_len += length;
                return (CRYPTO_SUCCESS);
@@ -405,15 +404,15 @@ ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
                mac_len = length - pt_part;
 
                ctx->ccm_processed_mac_len = mac_len;
-               bcopy(data + pt_part, ctx->ccm_mac_input_buf, mac_len);
+               memcpy(ctx->ccm_mac_input_buf, data + pt_part, mac_len);
 
                if (pt_part + ctx->ccm_remainder_len < block_size) {
                        /*
                         * since this is last of the ciphertext, will
                         * just decrypt with it here
                         */
-                       bcopy(datap, &((uint8_t *)ctx->ccm_remainder)
-                           [ctx->ccm_remainder_len], pt_part);
+                       memcpy(&((uint8_t *)ctx->ccm_remainder)
+                           [ctx->ccm_remainder_len], datap, pt_part);
                        ctx->ccm_remainder_len += pt_part;
                        ccm_decrypt_incomplete_block(ctx, encrypt_block);
                        ctx->ccm_processed_data_len += ctx->ccm_remainder_len;
@@ -424,9 +423,9 @@ ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
                        length = pt_part;
                }
        } else if (length + ctx->ccm_remainder_len < block_size) {
-                       /* accumulate bytes here and return */
-               bcopy(datap,
-                   (uint8_t *)ctx->ccm_remainder + ctx->ccm_remainder_len,
+               /* accumulate bytes here and return */
+               memcpy((uint8_t *)ctx->ccm_remainder + ctx->ccm_remainder_len,
+                   datap,
                    length);
                ctx->ccm_remainder_len += length;
                ctx->ccm_copy_to = datap;
@@ -441,8 +440,8 @@ ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
                        if (need > remainder)
                                return (CRYPTO_ENCRYPTED_DATA_LEN_RANGE);
 
-                       bcopy(datap, &((uint8_t *)ctx->ccm_remainder)
-                           [ctx->ccm_remainder_len], need);
+                       memcpy(&((uint8_t *)ctx->ccm_remainder)
+                           [ctx->ccm_remainder_len], datap, need);
 
                        blockp = (uint8_t *)ctx->ccm_remainder;
                } else {
@@ -492,7 +491,7 @@ ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,
 
                /* Incomplete last block */
                if (remainder > 0 && remainder < block_size) {
-                       bcopy(datap, ctx->ccm_remainder, remainder);
+                       memcpy(ctx->ccm_remainder, datap, remainder);
                        ctx->ccm_remainder_len = remainder;
                        ctx->ccm_copy_to = datap;
                        if (ctx->ccm_processed_mac_len > 0) {
@@ -539,10 +538,9 @@ ccm_decrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
        macp = (uint8_t *)ctx->ccm_tmp;
 
        while (mac_remain > 0) {
-
                if (mac_remain < block_size) {
-                       bzero(macp, block_size);
-                       bcopy(pt, macp, mac_remain);
+                       memset(macp, 0, block_size);
+                       memcpy(macp, pt, mac_remain);
                        mac_remain = 0;
                } else {
                        copy_block(pt, macp);
@@ -560,7 +558,7 @@ ccm_decrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size,
        calculate_ccm_mac((ccm_ctx_t *)ctx, ccm_mac_p, encrypt_block);
 
        /* compare the input CCM MAC value with what we calculated */
-       if (bcmp(ctx->ccm_mac_input_buf, ccm_mac_p, ctx->ccm_mac_len)) {
+       if (memcmp(ctx->ccm_mac_input_buf, ccm_mac_p, ctx->ccm_mac_len)) {
                /* They don't match */
                return (CRYPTO_INVALID_MAC);
        } else {
@@ -654,10 +652,10 @@ ccm_format_initial_blocks(uchar_t *nonce, ulong_t nonceSize,
        b0[0] = (have_adata << 6) | (((t - 2)  / 2) << 3) | (q - 1);
 
        /* copy the nonce value into b0 */
-       bcopy(nonce, &(b0[1]), nonceSize);
+       memcpy(&(b0[1]), nonce, nonceSize);
 
        /* store the length of the payload into b0 */
-       bzero(&(b0[1+nonceSize]), q);
+       memset(&(b0[1+nonceSize]), 0, q);
 
        payloadSize = aes_ctx->ccm_data_len;
        limit = 8 < q ? 8 : q;
@@ -673,9 +671,9 @@ ccm_format_initial_blocks(uchar_t *nonce, ulong_t nonceSize,
        cb[0] = 0x07 & (q-1); /* first byte */
 
        /* copy the nonce value into the counter block */
-       bcopy(nonce, &(cb[1]), nonceSize);
+       memcpy(&(cb[1]), nonce, nonceSize);
 
-       bzero(&(cb[1+nonceSize]), q);
+       memset(&(cb[1+nonceSize]), 0, q);
 
        /* Create the mask for the counter field based on the size of nonce */
        q <<= 3;
@@ -782,7 +780,7 @@ ccm_init(ccm_ctx_t *ctx, unsigned char *nonce, size_t nonce_len,
 
        /* The IV for CBC MAC for AES CCM mode is always zero */
        ivp = (uint8_t *)ctx->ccm_tmp;
-       bzero(ivp, block_size);
+       memset(ivp, 0, block_size);
 
        xor_block(ivp, mac_buf);
 
@@ -800,14 +798,14 @@ ccm_init(ccm_ctx_t *ctx, unsigned char *nonce, size_t nonce_len,
 
        /* 1st block: it contains encoded associated data, and some data */
        authp = (uint8_t *)ctx->ccm_tmp;
-       bzero(authp, block_size);
-       bcopy(encoded_a, authp, encoded_a_len);
+       memset(authp, 0, block_size);
+       memcpy(authp, encoded_a, encoded_a_len);
        processed = block_size - encoded_a_len;
        if (processed > auth_data_len) {
                /* in case auth_data is very small */
                processed = auth_data_len;
        }
-       bcopy(auth_data, authp+encoded_a_len, processed);
+       memcpy(authp+encoded_a_len, auth_data, processed);
        /* xor with previous buffer */
        xor_block(authp, mac_buf);
        encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf);
@@ -823,8 +821,8 @@ ccm_init(ccm_ctx_t *ctx, unsigned char *nonce, size_t nonce_len,
                         * There's not a block full of data, pad rest of
                         * buffer with zero
                         */
-                       bzero(authp, block_size);
-                       bcopy(&(auth_data[processed]), authp, remainder);
+                       memset(authp, 0, block_size);
+                       memcpy(authp, &(auth_data[processed]), remainder);
                        datap = (uint8_t *)authp;
                        remainder = 0;
                } else {