CryptMT3  1.0
cryptmt.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef CRYPTMT_H
3 #define CRYPTMT_H
4 
62 #include <stdint.h>
63 #include <exception>
64 #include <stdexcept>
65 
69 namespace cryptmt {
80  void *aligned_alloc(size_t size);
81 
89  void aligned_free(void * ptr);
90 
95  uint32_t maxKeySize();
96 
104  uint32_t keySizeUnit();
105 
110  class CryptMT {
111  public:
115  class stage_exception : std::runtime_error {
116  public:
120  explicit stage_exception(const char *message) :
121  std::runtime_error(message) {}
122  };
123 
139  explicit CryptMT(const uint8_t * key,
140  int keysize,
141  int ivsize)
142  throw(std::bad_alloc,std::invalid_argument);
143 
144  ~CryptMT();
145 
153  void IVSetUp(const uint8_t * iv);
154 
170  void encrypt(const uint8_t * plaintext,
171  uint8_t * ciphertext,
172  uint64_t msglen)
173  throw(stage_exception);
174 
190  void decrypt(const uint8_t * ciphertext,
191  uint8_t * plaintext,
192  uint64_t msglen)
193  throw(stage_exception)
194  {
195  encrypt(ciphertext, plaintext, msglen);
196  }
197 
213  void encryptPacket(const uint8_t * iv,
214  const uint8_t * plaintext,
215  uint8_t * ciphertext,
216  uint64_t msglen)
217  {
218  IVSetUp(iv);
219  encrypt(plaintext, ciphertext, msglen);
220  }
221 
237  void decryptPacket(const uint8_t * iv,
238  const uint8_t * ciphertext,
239  uint8_t * plaintext,
240  uint64_t msglen)
241  {
242  encryptPacket(iv, ciphertext, plaintext, msglen);
243  }
244 
256  void encryptBlocks(const uint8_t * plaintext,
257  uint8_t * ciphertext,
258  uint32_t blocks) throw(stage_exception);
259 
271  void decryptBlocks(const uint8_t * ciphertext,
272  uint8_t * plaintext,
273  uint32_t blocks)
274  throw(stage_exception)
275  {
276  encryptBlocks(ciphertext, plaintext, blocks);
277  }
278 
283  uint32_t blockLength();
284 #if defined(DEBUG)
285  void debug_print();
286 #endif
287  private:
288  class Impl;
289  Impl * impl;
290  CryptMT(const CryptMT&);
291  void operator=(const CryptMT&);
292  };
293 }
294 #endif /* CRYPTMT_H */