Lines Matching refs:ctx

48 ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length,  in ccm_mode_encrypt_contiguous_blocks()  argument
67 if (length + ctx->ccm_remainder_len < block_size) { in ccm_mode_encrypt_contiguous_blocks()
70 (uint8_t *)ctx->ccm_remainder + ctx->ccm_remainder_len, in ccm_mode_encrypt_contiguous_blocks()
72 ctx->ccm_remainder_len += length; in ccm_mode_encrypt_contiguous_blocks()
73 ctx->ccm_copy_to = datap; in ccm_mode_encrypt_contiguous_blocks()
77 lastp = (uint8_t *)ctx->ccm_cb; in ccm_mode_encrypt_contiguous_blocks()
81 mac_buf = (uint8_t *)ctx->ccm_mac_buf; in ccm_mode_encrypt_contiguous_blocks()
85 if (ctx->ccm_remainder_len > 0) { in ccm_mode_encrypt_contiguous_blocks()
86 need = block_size - ctx->ccm_remainder_len; in ccm_mode_encrypt_contiguous_blocks()
91 bcopy(datap, &((uint8_t *)ctx->ccm_remainder) in ccm_mode_encrypt_contiguous_blocks()
92 [ctx->ccm_remainder_len], need); in ccm_mode_encrypt_contiguous_blocks()
94 blockp = (uint8_t *)ctx->ccm_remainder; in ccm_mode_encrypt_contiguous_blocks()
106 encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf); in ccm_mode_encrypt_contiguous_blocks()
109 encrypt_block(ctx->ccm_keysched, (uint8_t *)ctx->ccm_cb, in ccm_mode_encrypt_contiguous_blocks()
110 (uint8_t *)ctx->ccm_tmp); in ccm_mode_encrypt_contiguous_blocks()
112 lastp = (uint8_t *)ctx->ccm_tmp; in ccm_mode_encrypt_contiguous_blocks()
118 counter = ntohll(ctx->ccm_cb[1] & ctx->ccm_counter_mask); in ccm_mode_encrypt_contiguous_blocks()
120 counter &= ctx->ccm_counter_mask; in ccm_mode_encrypt_contiguous_blocks()
121 ctx->ccm_cb[1] = in ccm_mode_encrypt_contiguous_blocks()
122 (ctx->ccm_cb[1] & ~(ctx->ccm_counter_mask)) | counter; in ccm_mode_encrypt_contiguous_blocks()
129 ctx->ccm_processed_data_len += block_size; in ccm_mode_encrypt_contiguous_blocks()
132 if (ctx->ccm_remainder_len > 0) { in ccm_mode_encrypt_contiguous_blocks()
133 bcopy(blockp, ctx->ccm_copy_to, in ccm_mode_encrypt_contiguous_blocks()
134 ctx->ccm_remainder_len); in ccm_mode_encrypt_contiguous_blocks()
135 bcopy(blockp + ctx->ccm_remainder_len, datap, in ccm_mode_encrypt_contiguous_blocks()
158 if (ctx->ccm_remainder_len != 0) { in ccm_mode_encrypt_contiguous_blocks()
160 ctx->ccm_remainder_len = 0; in ccm_mode_encrypt_contiguous_blocks()
169 bcopy(datap, ctx->ccm_remainder, remainder); in ccm_mode_encrypt_contiguous_blocks()
170 ctx->ccm_remainder_len = remainder; in ccm_mode_encrypt_contiguous_blocks()
171 ctx->ccm_copy_to = datap; in ccm_mode_encrypt_contiguous_blocks()
174 ctx->ccm_copy_to = NULL; in ccm_mode_encrypt_contiguous_blocks()
183 calculate_ccm_mac(ccm_ctx_t *ctx, uint8_t *ccm_mac, in calculate_ccm_mac() argument
190 mac_buf = (uint8_t *)ctx->ccm_mac_buf; in calculate_ccm_mac()
194 ctx->ccm_cb[1] = (ctx->ccm_cb[1] & ~(ctx->ccm_counter_mask)) | counter; in calculate_ccm_mac()
196 counterp = (uint8_t *)ctx->ccm_tmp; in calculate_ccm_mac()
197 encrypt_block(ctx->ccm_keysched, (uint8_t *)ctx->ccm_cb, counterp); in calculate_ccm_mac()
200 for (i = 0; i < ctx->ccm_mac_len; i++) { in calculate_ccm_mac()
207 ccm_encrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size, in ccm_encrypt_final() argument
219 if (out->cd_length < (ctx->ccm_remainder_len + ctx->ccm_mac_len)) { in ccm_encrypt_final()
229 if ((ctx->ccm_processed_data_len + ctx->ccm_remainder_len) in ccm_encrypt_final()
230 != (ctx->ccm_data_len)) { in ccm_encrypt_final()
234 mac_buf = (uint8_t *)ctx->ccm_mac_buf; in ccm_encrypt_final()
236 if (ctx->ccm_remainder_len > 0) { in ccm_encrypt_final()
239 macp = (uint8_t *)ctx->ccm_mac_input_buf; in ccm_encrypt_final()
243 bcopy(ctx->ccm_remainder, macp, ctx->ccm_remainder_len); in ccm_encrypt_final()
247 encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf); in ccm_encrypt_final()
250 lastp = (uint8_t *)ctx->ccm_tmp; in ccm_encrypt_final()
251 encrypt_block(ctx->ccm_keysched, (uint8_t *)ctx->ccm_cb, lastp); in ccm_encrypt_final()
254 for (i = 0; i < ctx->ccm_remainder_len; i++) { in ccm_encrypt_final()
257 ctx->ccm_processed_data_len += ctx->ccm_remainder_len; in ccm_encrypt_final()
261 ccm_mac_p = (uint8_t *)ctx->ccm_tmp; in ccm_encrypt_final()
262 calculate_ccm_mac(ctx, ccm_mac_p, encrypt_block); in ccm_encrypt_final()
267 ctx->ccm_remainder_len + ctx->ccm_mac_len); in ccm_encrypt_final()
269 if (ctx->ccm_remainder_len > 0) { in ccm_encrypt_final()
274 bcopy(macp, out_data_1, ctx->ccm_remainder_len); in ccm_encrypt_final()
275 bcopy(ccm_mac_p, out_data_1 + ctx->ccm_remainder_len, in ccm_encrypt_final()
276 ctx->ccm_mac_len); in ccm_encrypt_final()
279 if (out_data_1_len < ctx->ccm_remainder_len) { in ccm_encrypt_final()
285 data_2_len_used = ctx->ccm_remainder_len in ccm_encrypt_final()
291 ctx->ccm_mac_len); in ccm_encrypt_final()
294 if (out_data_1_len == ctx->ccm_remainder_len) { in ccm_encrypt_final()
297 ctx->ccm_mac_len); in ccm_encrypt_final()
300 ctx->ccm_remainder_len; in ccm_encrypt_final()
307 out_data_1 + ctx->ccm_remainder_len, in ccm_encrypt_final()
311 ctx->ccm_mac_len - len_not_used); in ccm_encrypt_final()
324 out->cd_offset += ctx->ccm_remainder_len + ctx->ccm_mac_len; in ccm_encrypt_final()
325 ctx->ccm_remainder_len = 0; in ccm_encrypt_final()
334 ccm_decrypt_incomplete_block(ccm_ctx_t *ctx, in ccm_decrypt_incomplete_block() argument
340 datap = (uint8_t *)ctx->ccm_remainder; in ccm_decrypt_incomplete_block()
341 outp = &((ctx->ccm_pt_buf)[ctx->ccm_processed_data_len]); in ccm_decrypt_incomplete_block()
343 counterp = (uint8_t *)ctx->ccm_tmp; in ccm_decrypt_incomplete_block()
344 encrypt_block(ctx->ccm_keysched, (uint8_t *)ctx->ccm_cb, counterp); in ccm_decrypt_incomplete_block()
347 for (i = 0; i < ctx->ccm_remainder_len; i++) { in ccm_decrypt_incomplete_block()
359 ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *ctx, char *data, size_t length, in ccm_mode_decrypt_contiguous_blocks() argument
375 pm_len = ctx->ccm_processed_mac_len; in ccm_mode_decrypt_contiguous_blocks()
383 if ((pm_len + length) > ctx->ccm_mac_len) { in ccm_mode_decrypt_contiguous_blocks()
386 tmp = (uint8_t *)ctx->ccm_mac_input_buf; in ccm_mode_decrypt_contiguous_blocks()
390 ctx->ccm_processed_mac_len += length; in ccm_mode_decrypt_contiguous_blocks()
398 pd_len = ctx->ccm_processed_data_len; in ccm_mode_decrypt_contiguous_blocks()
399 total_decrypted_len = pd_len + length + ctx->ccm_remainder_len; in ccm_mode_decrypt_contiguous_blocks()
402 (ctx->ccm_data_len + ctx->ccm_mac_len)) { in ccm_mode_decrypt_contiguous_blocks()
406 pt_len = ctx->ccm_data_len; in ccm_mode_decrypt_contiguous_blocks()
416 size_t pt_part = pt_len - pd_len - ctx->ccm_remainder_len; in ccm_mode_decrypt_contiguous_blocks()
420 ctx->ccm_processed_mac_len = mac_len; in ccm_mode_decrypt_contiguous_blocks()
421 bcopy(data + pt_part, ctx->ccm_mac_input_buf, mac_len); in ccm_mode_decrypt_contiguous_blocks()
423 if (pt_part + ctx->ccm_remainder_len < block_size) { in ccm_mode_decrypt_contiguous_blocks()
428 bcopy(datap, &((uint8_t *)ctx->ccm_remainder) in ccm_mode_decrypt_contiguous_blocks()
429 [ctx->ccm_remainder_len], pt_part); in ccm_mode_decrypt_contiguous_blocks()
430 ctx->ccm_remainder_len += pt_part; in ccm_mode_decrypt_contiguous_blocks()
431 ccm_decrypt_incomplete_block(ctx, encrypt_block); in ccm_mode_decrypt_contiguous_blocks()
432 ctx->ccm_processed_data_len += ctx->ccm_remainder_len; in ccm_mode_decrypt_contiguous_blocks()
433 ctx->ccm_remainder_len = 0; in ccm_mode_decrypt_contiguous_blocks()
439 } else if (length + ctx->ccm_remainder_len < block_size) { in ccm_mode_decrypt_contiguous_blocks()
442 (uint8_t *)ctx->ccm_remainder + ctx->ccm_remainder_len, in ccm_mode_decrypt_contiguous_blocks()
444 ctx->ccm_remainder_len += length; in ccm_mode_decrypt_contiguous_blocks()
445 ctx->ccm_copy_to = datap; in ccm_mode_decrypt_contiguous_blocks()
451 if (ctx->ccm_remainder_len > 0) { in ccm_mode_decrypt_contiguous_blocks()
452 need = block_size - ctx->ccm_remainder_len; in ccm_mode_decrypt_contiguous_blocks()
457 bcopy(datap, &((uint8_t *)ctx->ccm_remainder) in ccm_mode_decrypt_contiguous_blocks()
458 [ctx->ccm_remainder_len], need); in ccm_mode_decrypt_contiguous_blocks()
460 blockp = (uint8_t *)ctx->ccm_remainder; in ccm_mode_decrypt_contiguous_blocks()
466 cbp = (uint8_t *)ctx->ccm_tmp; in ccm_mode_decrypt_contiguous_blocks()
467 encrypt_block(ctx->ccm_keysched, (uint8_t *)ctx->ccm_cb, cbp); in ccm_mode_decrypt_contiguous_blocks()
473 counter = ntohll(ctx->ccm_cb[1] & ctx->ccm_counter_mask); in ccm_mode_decrypt_contiguous_blocks()
475 counter &= ctx->ccm_counter_mask; in ccm_mode_decrypt_contiguous_blocks()
476 ctx->ccm_cb[1] = in ccm_mode_decrypt_contiguous_blocks()
477 (ctx->ccm_cb[1] & ~(ctx->ccm_counter_mask)) | counter; in ccm_mode_decrypt_contiguous_blocks()
483 resultp = (uint8_t *)ctx->ccm_pt_buf + in ccm_mode_decrypt_contiguous_blocks()
484 ctx->ccm_processed_data_len; in ccm_mode_decrypt_contiguous_blocks()
487 ctx->ccm_processed_data_len += block_size; in ccm_mode_decrypt_contiguous_blocks()
489 ctx->ccm_lastp = blockp; in ccm_mode_decrypt_contiguous_blocks()
492 if (ctx->ccm_remainder_len != 0) { in ccm_mode_decrypt_contiguous_blocks()
494 ctx->ccm_remainder_len = 0; in ccm_mode_decrypt_contiguous_blocks()
503 bcopy(datap, ctx->ccm_remainder, remainder); in ccm_mode_decrypt_contiguous_blocks()
504 ctx->ccm_remainder_len = remainder; in ccm_mode_decrypt_contiguous_blocks()
505 ctx->ccm_copy_to = datap; in ccm_mode_decrypt_contiguous_blocks()
506 if (ctx->ccm_processed_mac_len > 0) { in ccm_mode_decrypt_contiguous_blocks()
511 ccm_decrypt_incomplete_block(ctx, in ccm_mode_decrypt_contiguous_blocks()
513 ctx->ccm_processed_data_len += remainder; in ccm_mode_decrypt_contiguous_blocks()
514 ctx->ccm_remainder_len = 0; in ccm_mode_decrypt_contiguous_blocks()
518 ctx->ccm_copy_to = NULL; in ccm_mode_decrypt_contiguous_blocks()
527 ccm_decrypt_final(ccm_ctx_t *ctx, crypto_data_t *out, size_t block_size, in ccm_decrypt_final() argument
536 pt_len = ctx->ccm_data_len; in ccm_decrypt_final()
543 pt = ctx->ccm_pt_buf; in ccm_decrypt_final()
544 mac_remain = ctx->ccm_processed_data_len; in ccm_decrypt_final()
545 mac_buf = (uint8_t *)ctx->ccm_mac_buf; in ccm_decrypt_final()
547 macp = (uint8_t *)ctx->ccm_tmp; in ccm_decrypt_final()
563 encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf); in ccm_decrypt_final()
567 ccm_mac_p = (uint8_t *)ctx->ccm_tmp; in ccm_decrypt_final()
568 calculate_ccm_mac((ccm_ctx_t *)ctx, ccm_mac_p, encrypt_block); in ccm_decrypt_final()
571 if (bcmp(ctx->ccm_mac_input_buf, ccm_mac_p, ctx->ccm_mac_len)) { in ccm_decrypt_final()
575 rv = crypto_put_output_data(ctx->ccm_pt_buf, out, pt_len); in ccm_decrypt_final()
770 ccm_init(ccm_ctx_t *ctx, unsigned char *nonce, size_t nonce_len, in ccm_init() argument
780 mac_buf = (uint8_t *)&(ctx->ccm_mac_buf); in ccm_init()
790 auth_data_len, mac_buf, ctx); in ccm_init()
793 ivp = (uint8_t *)ctx->ccm_tmp; in ccm_init()
799 encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf); in ccm_init()
811 authp = (uint8_t *)ctx->ccm_tmp; in ccm_init()
822 encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf); in ccm_init()
846 encrypt_block(ctx->ccm_keysched, mac_buf, mac_buf); in ccm_init()