CppCMS

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

crypto.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_CRYPTO_H
9 #define CPPCMS_CRYPTO_H
10
11 #include <cppcms/defs.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/auto_ptr_inc.h>
15 #include <string>
16
17 namespace cppcms {
27 namespace crypto {
34 class CPPCMS_API key {
35 public:
39 key();
43 key(key const &other);
47 key const &operator=(key const &);
51 ~key();
55 key(void const *data,size_t length);
59 explicit key(char const *s);
63 explicit key(std::string const &);
67 char const *data() const;
71 size_t size() const;
72
76 void reset();
77
81 void set(void const *ptr,size_t len);
85 void set_hex(char const *ptr,size_t len);
86
91 void read_from_file(std::string const &file_name);
92
93 private:
94 static unsigned from_hex(char c);
95 char *data_;
96 size_t size_;
97 };
101 class CPPCMS_API message_digest : public booster::noncopyable {
102 protected:
104 message_digest()
105 {
106 }
107 public:
108 virtual ~message_digest()
109 {
110 }
111
115 virtual unsigned digest_size() const = 0;
119 virtual unsigned block_size() const = 0;
120
124 virtual void append(void const *ptr,size_t size) = 0;
129 virtual void readout(void *ptr) = 0;
130
135 virtual message_digest *clone() const = 0;
136
140 virtual char const *name() const = 0;
141
145 static std::auto_ptr<message_digest> md5();
149 static std::auto_ptr<message_digest> sha1();
154 static std::auto_ptr<message_digest> create_by_name(std::string const &name);
155 };
156
160 class CPPCMS_API hmac : public booster::noncopyable {
161 public:
165 hmac(std::auto_ptr<message_digest> digest,key const &k);
169 hmac(std::string const &name,key const &k);
170 ~hmac();
171
175 unsigned digest_size() const;
176
180 void append(void const *ptr,size_t size);
181
188 void readout(void *ptr);
189 private:
190 void init();
191 struct data_;
192 booster::hold_ptr<data_> d;
193 std::auto_ptr<message_digest> md_,md_opad_;
194 key key_;
195 };
196
202 class CPPCMS_API cbc : public booster::noncopyable {
203 public:
207 typedef enum {
208 aes128 = 0,
209 aes192 = 1,
210 aes256 = 2
211 } cbc_type;
212
218 static std::auto_ptr<cbc> create(cbc_type type);
227 static std::auto_ptr<cbc> create(std::string const &name);
228
232 virtual unsigned block_size() const = 0;
236 virtual unsigned key_size() const = 0;
237
241 virtual void set_key(key const &) = 0;
245 virtual void set_iv(void const *ptr,size_t size) = 0;
249 virtual void set_nonce_iv() = 0;
253 virtual void encrypt(void const *in,void *out,unsigned len) = 0;
257 virtual void decrypt(void const *in,void *out,unsigned len) = 0;
258
259 virtual ~cbc()
260 {
261 }
262
263 };
264
265 } // crypto
266
267 } // cppcms
268
269
270
271 #endif
booster::hold_ptr< data_ >
cppcms::crypto::message_digest
this class provides an API to calculate various cryptographic hash functions
Definition: crypto.h:101
cppcms::crypto::hmac
This object calculates the HMAC signature for the input data.
Definition: crypto.h:160
cppcms::crypto::cbc
Cipher-block chaining encryption and decryption cryptographic service.
Definition: crypto.h:202
cppcms
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
cppcms::crypto::cbc::cbc_type
cbc_type
Definition: crypto.h:207
cppcms::crypto::message_digest::message_digest
message_digest()
It should be implemented in derived classes.
Definition: crypto.h:104
cppcms::crypto::key
Key object, holds the string that represents the binary key.
Definition: crypto.h:34
booster::noncopyable
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15