| 17 | } |
| 18 | |
| 19 | void aes256_ctr(AES *ctx, uint8_t *input, const size_t input_len, const uint8_t *iv) |
| 20 | { |
| 21 | uint8_t nonce[16], buf[16]; |
| 22 | memcpy(nonce, iv, sizeof(nonce)); |
| 23 | |
| 24 | size_t count = 0; |
| 25 | while (count + 16 <= input_len) |
| 26 | { |
| 27 | memcpy(buf, nonce, sizeof(nonce)); |
| 28 | ctx->encrypt(buf, buf); |
| 29 | aes256_xor(&input[count], buf, sizeof(buf)); |
| 30 | |
| 31 | aes256_ctr_increment_nonce(nonce); |
| 32 | count += 16; |
| 33 | } |
| 34 | |
| 35 | size_t rem = input_len - count; |
| 36 | if (rem > 0) |
| 37 | { |
| 38 | ctx->encrypt(nonce, nonce); |
| 39 | aes256_xor(&input[count], nonce, rem); |
| 40 | } |
| 41 | } |
no test coverage detected