Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case AES_CTR:
- {
- size_t bytes_to_copy = ctx->mode.ctr.last_block_stop;
- size_t bytes_offset = AES_BLOCK_SIZE - bytes_to_copy;
- // xor remaining bytes from last encrypt operation into new plaintext
- if(bytes_to_copy){
- memcpy(out, in, bytes_offset);
- xor_buf(&ctx->mode.ctr.last_block[bytes_to_copy], out, bytes_offset);
- }
- blocks = ((in_len - bytes_offset) / AES_BLOCK_SIZE);
- // encrypt message in CTR mode
- for(idx = 0; idx <= blocks; idx++){
- bytes_to_copy = MIN(AES_BLOCK_SIZE, in_len - (idx * AES_BLOCK_SIZE));
- //bytes_to_pad = AES_BLOCK_SIZE-bytes_to_copy;
- memcpy(&out[idx*AES_BLOCK_SIZE], &in[idx*AES_BLOCK_SIZE], bytes_to_copy);
- // memset(&buf[bytes_to_copy], 0, bytes_to_pad);
- // if bytes_to_copy is less than blocksize, do nothing, since msg is truncated anyway
- aes_encrypt_block(iv, buf, ctx);
- xor_buf(buf, &out[idx*AES_BLOCK_SIZE], bytes_to_copy);
- increment_iv(iv, ctx->mode.ctr.counter_len); // increment iv for continued use
- if(idx==blocks){
- memcpy(ctx->mode.ctr.last_block, buf, AES_BLOCK_SIZE);
- ctx->mode.ctr.last_block_stop = bytes_to_copy;
- }
- }
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement