IBR-DTNSuite
0.8
|
00001 #ifndef AES128STREAM_H_ 00002 #define AES128STREAM_H_ 00003 00004 #include <streambuf> 00005 #include <ostream> 00006 #include <sys/types.h> 00007 #include "ibrcommon/ssl/CipherStream.h" 00008 #include "ibrcommon/ssl/gcm/gcm.h" 00009 00010 namespace ibrcommon 00011 { 00020 class AES128Stream : public ibrcommon::CipherStream 00021 { 00022 public: 00024 static const size_t key_size_in_bytes = 16; 00026 static const size_t salt_len = sizeof(u_int32_t); 00028 static const size_t iv_len = 8; 00030 static const size_t tag_len = 16; 00032 static const size_t BUFF_SIZE = 2048; 00033 00050 AES128Stream(const CipherMode mode, std::ostream& output, const unsigned char key[key_size_in_bytes], const u_int32_t salt); 00051 AES128Stream(const CipherMode mode, std::ostream& output, const unsigned char key[key_size_in_bytes], const u_int32_t salt, const unsigned char iv[iv_len]); 00052 00054 virtual ~AES128Stream(); 00055 00060 void getIV(unsigned char (&to_iv)[iv_len]) const; 00061 00066 void getTag(unsigned char (&to_tag)[tag_len]); 00067 00071 bool verify(const unsigned char (&verify_tag)[tag_len]); 00072 00073 protected: 00074 virtual void encrypt(char *buf, const size_t size); 00075 virtual void decrypt(char *buf, const size_t size); 00076 00077 private: 00082 typedef struct { 00083 u_int32_t salt; 00084 unsigned char initialisation_vector[iv_len]; 00085 } gcm_iv; 00086 00088 gcm_iv _gcm_iv; 00089 00091 gcm_ctx _ctx; 00092 00096 unsigned char _used_initialisation_vector[iv_len]; 00097 }; 00098 } 00099 00100 #endif /* AES128STREAM_H_ */