* Apply a symmetric encryption/decryption algorithm. */
| 98 | * Apply a symmetric encryption/decryption algorithm. |
| 99 | */ |
| 100 | static int |
| 101 | swcr_encdec(struct swcr_session *ses, struct cryptop *crp) |
| 102 | { |
| 103 | unsigned char iv[EALG_MAX_BLOCK_LEN], blk[EALG_MAX_BLOCK_LEN]; |
| 104 | unsigned char *ivp, *nivp, iv2[EALG_MAX_BLOCK_LEN]; |
| 105 | const struct crypto_session_params *csp; |
| 106 | struct swcr_encdec *sw; |
| 107 | struct enc_xform *exf; |
| 108 | int i, blks, inlen, ivlen, outlen, resid; |
| 109 | struct crypto_buffer_cursor cc_in, cc_out; |
| 110 | const unsigned char *inblk; |
| 111 | unsigned char *outblk; |
| 112 | int error; |
| 113 | bool encrypting; |
| 114 | |
| 115 | error = 0; |
| 116 | |
| 117 | sw = &ses->swcr_encdec; |
| 118 | exf = sw->sw_exf; |
| 119 | ivlen = exf->ivsize; |
| 120 | |
| 121 | if (exf->native_blocksize == 0) { |
| 122 | /* Check for non-padded data */ |
| 123 | if ((crp->crp_payload_length % exf->blocksize) != 0) |
| 124 | return (EINVAL); |
| 125 | |
| 126 | blks = exf->blocksize; |
| 127 | } else |
| 128 | blks = exf->native_blocksize; |
| 129 | |
| 130 | if (exf == &enc_xform_aes_icm && |
| 131 | (crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0) |
| 132 | return (EINVAL); |
| 133 | |
| 134 | if (crp->crp_cipher_key != NULL) { |
| 135 | csp = crypto_get_params(crp->crp_session); |
| 136 | error = exf->setkey(sw->sw_kschedule, |
| 137 | crp->crp_cipher_key, csp->csp_cipher_klen); |
| 138 | if (error) |
| 139 | return (error); |
| 140 | } |
| 141 | |
| 142 | crypto_read_iv(crp, iv); |
| 143 | |
| 144 | if (exf->reinit) { |
| 145 | /* |
| 146 | * xforms that provide a reinit method perform all IV |
| 147 | * handling themselves. |
| 148 | */ |
| 149 | exf->reinit(sw->sw_kschedule, iv); |
| 150 | } |
| 151 | |
| 152 | ivp = iv; |
| 153 | |
| 154 | crypto_cursor_init(&cc_in, &crp->crp_buf); |
| 155 | crypto_cursor_advance(&cc_in, crp->crp_payload_start); |
| 156 | inlen = crypto_cursor_seglen(&cc_in); |
| 157 | inblk = crypto_cursor_segbase(&cc_in); |
no test coverage detected