CryptMT  1.0
cryptmt.h
説明を見る。
1 #pragma once
2 #ifndef CRYPTMT_H
3 #define CRYPTMT_H
4 
43 #include <stdint.h>
44 #include <exception>
45 #include <stdexcept>
46 
50 namespace cryptmt {
59  void *aligned_alloc(size_t size);
60 
67  void aligned_free(void * ptr);
68 
78  uint32_t maxKeySize();
79 
89  uint32_t keySizeUnit();
90 
95  class CryptMT {
96  public:
100  class stage_exception : std::runtime_error {
101  public:
105  explicit stage_exception(const char *message) :
106  std::runtime_error(message) {}
107  }
108 
122  explicit CryptMT(const uint8_t * key,
123  int keysize,
124  int ivsize)
125  throw(std::bad_alloc,std::invalid_argument);
126 
127  ~CryptMT();
128 
136  void IVSetUp(const uint8_t * iv);
137 
154  void encrypt(const uint8_t * plaintext,
155  uint8_t * ciphertext,
156  uint64_t msglen)
157  throw(stage_exception);
158 
176  void decrypt(const uint8_t * ciphertext,
177  uint8_t * plaintext,
178  uint64_t msglen)
179  throw(stage_exception)
180  {
181  encrypt(ciphertext, plaintext, msglen);
182  }
183 
200  void encryptPacket(const uint8_t * iv,
201  const uint8_t * plaintext,
202  uint8_t * ciphertext,
203  uint64_t msglen)
204  {
205  IVSetUp(iv);
206  encrypt(plaintext, ciphertext, msglen);
207  }
208 
225  void decryptPacket(const uint8_t * iv,
226  const uint8_t * ciphertext,
227  uint8_t * plaintext,
228  uint64_t msglen)
229  {
230  encryptPacket(iv, ciphertext, plaintext, msglen);
231  }
232 
246  void encryptBlocks(const uint8_t * plaintext,
247  uint8_t * ciphertext,
248  uint32_t blocks)
249  throw(stage_exception);
250 
264  void decryptBlocks(const uint8_t * ciphertext,
265  uint8_t * plaintext,
266  uint32_t blocks)
267  throw(stage_exception)
268  {
269  encryptBlocks(ciphertext, plaintext, blocks);
270  }
271 
277  uint32_t blockLength();
278 #if defined(DEBUG)
279  void debug_print();
280 #endif
281  private:
282  class Impl;
283  Impl * impl;
284  CryptMT(const CryptMT&);
285  void operator=(const CryptMT&);
286  };
287 }
288 #endif /* CRYPTMT_H */