Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
payload_aes128.hpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Simple Geolocalization and Course Transmission Protocol (SGCTP)
5  * Copyright (C) 2014 Cedric Dufour <http://cedric.dufour.name>
6  *
7  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
8  * free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
13  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License for more details.
18  */
19 
20 #ifndef SGCTP_CPAYLOAD_AES128_HPP
21 #define SGCTP_CPAYLOAD_AES128_HPP
22 
23 #ifdef __SGCTP_USE_OPENSSL__
24 
25 // OpenSSL
26 #include "openssl/evp.h"
27 
28 #else // __SGCTP_USE_OPENSSL__
29 
30 // GCrypt
31 #include "gcrypt.h"
32 
33 #endif // NOT __SGCTP_USE_OPENSSL__
34 
35 // SGCTP
36 #include "sgctp/payload.hpp"
37 
38 
39 // SGCTP namespace
40 namespace SGCTP
41 {
42 
44 
48  class CPayload_AES128: public CPayload
49  {
50 
51  //----------------------------------------------------------------------
52  // CONSTANTS / STATIC
53  //----------------------------------------------------------------------
54 
55  public:
56 #ifdef __SGCTP_USE_OPENSSL__
57  static const EVP_CIPHER* CRYPTO_CIPHER;
58 #else //__SGCTP_USE_OPENSSL__
59  static const int CRYPTO_CIPHER = GCRY_CIPHER_AES128;
60  static const int CRYPTO_MODE = GCRY_CIPHER_MODE_CBC;
61 #endif //__SGCTP_USE_OPENSSL__
62  static const uint16_t CRYPTO_BLOCK_SIZE = 16;
63  static const uint16_t CRYPTO_NONCE_SIZE = 16;
64  static const uint16_t CRYPTO_KEY_SIZE = 16;
65  static const uint16_t CRYPTO_KEY_ITER = 16384;
66  static const uint16_t CRYPTO_SEAL_SIZE = 4;
67 
68  public:
70 
75  static int makeCryptoNonce( unsigned char *_pucNonce );
76 
77  private:
79 
82  static int initCryptoEngine();
83 
84  //----------------------------------------------------------------------
85  // FIELDS
86  //----------------------------------------------------------------------
87 
88  private:
90  unsigned char *pucBufferTmp;
97 
98 
99  //----------------------------------------------------------------------
100  // CONSTRUCTORS / DESTRUCTOR
101  //----------------------------------------------------------------------
102 
103  public:
104  CPayload_AES128();
105  virtual ~CPayload_AES128();
106 
107 
108  //----------------------------------------------------------------------
109  // METHODS: CPayload (implement/override)
110  //----------------------------------------------------------------------
111 
112  public:
113  virtual int alloc();
114 
115  virtual int serialize( unsigned char *_pucBuffer,
116  const CData &_roData );
117 
118  virtual int unserialize( CData *_poData,
119  const unsigned char *_pucBuffer,
120  uint16_t _ui16tBufferSize );
121 
122  virtual void free();
123 
124 
125  //----------------------------------------------------------------------
126  // METHODS
127  //----------------------------------------------------------------------
128 
129  public:
131 
138  int makeCryptoKey( const unsigned char *_pucPassword,
139  int _iPasswordLength,
140  const unsigned char *_pucNonce );
141 
143 
146  int incrCryptoKey();
147 
148  };
149 
150 }
151 
152 #endif // SGCTP_CPAYLOAD_AES128_HPP
int makeCryptoKey(const unsigned char *_pucPassword, int _iPasswordLength, const unsigned char *_pucNonce)
Create cryptographic key (and seal)
int incrCryptoKey()
Increment cryptographic key (and seal)
static const uint16_t CRYPTO_KEY_ITER
virtual int alloc()
Allocate resources for payload (un-)serialization.
static const uint16_t CRYPTO_SEAL_SIZE
static const uint16_t CRYPTO_KEY_SIZE
static const uint16_t CRYPTO_NONCE_SIZE
SGCTP data container.
Definition: data.hpp:44
unsigned char pucCryptoKey[CRYPTO_BLOCK_SIZE]
Cryptographic key (used for encryption/decryption)
static const int CRYPTO_CIPHER
unsigned char pucCryptoSeal[CRYPTO_SEAL_SIZE]
Cryptographic seal (used to check valid decryption)
static int initCryptoEngine()
Initialize cryptographic engine.
(Raw) SGCTP payload
Definition: payload.hpp:41
static int makeCryptoNonce(unsigned char *_pucNonce)
Create cryptographic nonce.
virtual int unserialize(CData *_poData, const unsigned char *_pucBuffer, uint16_t _ui16tBufferSize)
Unserialize the SGCTP data from the given payload buffer.
virtual int serialize(unsigned char *_pucBuffer, const CData &_roData)
Serialize the given SGCTP data into the given payload buffer.
static const uint16_t CRYPTO_BLOCK_SIZE
unsigned char * pucBufferTmp
Payload temporary import/export buffer.
AES128-encrypted SGCTP payload.
virtual void free()
Free resources for payload (un-)serialization.
static const int CRYPTO_MODE
unsigned char pucCryptoNonce[CRYPTO_NONCE_SIZE]
Cryptographic nonce (used for cryptographic hashing)