| 66 | }; |
| 67 | |
| 68 | class Aes_ctr_encryptor { |
| 69 | public: |
| 70 | enum { |
| 71 | NONCE_LEN = 12, |
| 72 | KEY_LEN = AES_KEY_LEN, |
| 73 | BLOCK_LEN = 16, |
| 74 | MAX_CRYPT_BYTES = (1ULL<<32)*16 // Don't encrypt more than this or the CTR value will repeat itself |
| 75 | }; |
| 76 | |
| 77 | private: |
| 78 | Aes_ecb_encryptor ecb; |
| 79 | unsigned char ctr_value[BLOCK_LEN]; // Current CTR value (used as input to AES to derive pad) |
| 80 | unsigned char pad[BLOCK_LEN]; // Current encryption pad (output of AES) |
| 81 | uint32_t byte_counter; // How many bytes processed so far? |
| 82 | |
| 83 | public: |
| 84 | Aes_ctr_encryptor (const unsigned char* key, const unsigned char* nonce); |
| 85 | ~Aes_ctr_encryptor (); |
| 86 | |
| 87 | void process (const unsigned char* in, unsigned char* out, size_t len); |
| 88 | |
| 89 | // Encrypt/decrypt an entire input stream, writing to the given output stream |
| 90 | static void process_stream (std::istream& in, std::ostream& out, const unsigned char* key, const unsigned char* nonce); |
| 91 | }; |
| 92 | |
| 93 | typedef Aes_ctr_encryptor Aes_ctr_decryptor; |
| 94 |
nothing calls this directly
no outgoing calls
no test coverage detected