File: crypto.h

package info (click to toggle)
crtmpserver 1.0~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,336 kB
  • sloc: cpp: 56,354; sh: 411; makefile: 21
file content (103 lines) | stat: -rw-r--r-- 2,840 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *  Copyright (c) 2010,
 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com)
 *
 *  This file is part of crtmpserver.
 *  crtmpserver is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  crtmpserver is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _CRYPTO_H
#define	_CRYPTO_H

#include "platform/platform.h"
#include <openssl/bn.h>
#include <openssl/dh.h>
#include <openssl/rc4.h>
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/hmac.h>
#include <openssl/aes.h>
#include <openssl/engine.h>
#include <openssl/conf.h>

/*!
	@class DHWrapper
	@brief Class that handles the DH wrapper
*/
class DLLEXP DHWrapper {
private:
	int32_t _bitsCount;
	DH *_pDH;
	uint8_t *_pSharedKey;
	int32_t _sharedKeyLength;
	BIGNUM *_peerPublickey;
public:
	DHWrapper(int32_t bitsCount);
	virtual ~DHWrapper();

	/*!
		@brief Initializes the DH wrapper
	*/
	bool Initialize();

	/*!
		@brief Copies the public key.
		@param pDst - Where the copied key is stored
		@param dstLength
	*/
	bool CopyPublicKey(uint8_t *pDst, int32_t dstLength);

	/*!
		@brief Copies the private key.
		@param pDst - Where the copied key is stored
		@param dstLength
	*/
	bool CopyPrivateKey(uint8_t *pDst, int32_t dstLength);

	/*!
		@brief Creates a shared secret key
		@param pPeerPublicKey
		@param length
	*/
	bool CreateSharedKey(uint8_t *pPeerPublicKey, int32_t length);

	/*!
		@brief Copies the shared secret key.
		@param pDst - Where the copied key is stored
		@param dstLength
	*/
	bool CopySharedKey(uint8_t *pDst, int32_t dstLength);
private:
	void Cleanup();
	bool CopyKey(BIGNUM *pNum, uint8_t *pDst, int32_t dstLength);
};

DLLEXP void InitRC4Encryption(uint8_t *secretKey, uint8_t *pubKeyIn, uint8_t *pubKeyOut,
		RC4_KEY *rc4keyIn, RC4_KEY *rc4keyOut);
DLLEXP string md5(string source, bool textResult);
DLLEXP string md5(uint8_t *pBuffer, uint32_t length, bool textResult);
DLLEXP void HMACsha256(const void *pData, uint32_t dataLength, const void *pKey,
		uint32_t keyLength, void *pResult);
DLLEXP string b64(string source);
DLLEXP string b64(uint8_t *pBuffer, uint32_t length);
DLLEXP string unb64(string source);
DLLEXP string unb64(uint8_t *pBuffer, uint32_t length);
DLLEXP string unhex(string source);
DLLEXP void CleanupSSL();

#endif /* _CRYPTO_H */