aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llcrypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmessage/llcrypto.h')
-rw-r--r--linden/indra/llmessage/llcrypto.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llcrypto.h b/linden/indra/llmessage/llcrypto.h
new file mode 100644
index 0000000..b142d25
--- /dev/null
+++ b/linden/indra/llmessage/llcrypto.h
@@ -0,0 +1,111 @@
1/**
2 * @file llcrypto.h
3 * @brief llcrypto library module header. For now, all crypto classes
4 * are here, and as we grow the library, we can split these things
5 * out.
6 *
7 * Copyright (c) 2003-2007, Linden Research, Inc.
8 *
9 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement
12 * ("Other License"), formally executed by you and Linden Lab. Terms of
13 * the GPL can be found in doc/GPL-license.txt in this distribution, or
14 * online at http://secondlife.com/developers/opensource/gplv2
15 *
16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlife.com/developers/opensource/flossexception
20 *
21 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above,
23 * and agree to abide by those obligations.
24 *
25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
27 * COMPLETENESS OR PERFORMANCE.
28 */
29
30#ifndef LL_LLCRYPTO_H
31#define LL_LLCRYPTO_H
32
33//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34// Class LLCipher
35//
36// Abstract base class for a cipher object.
37//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38
39class LLCipher
40{
41public:
42 virtual ~LLCipher() {}
43
44 // encrypt src and place result into dst. returns TRUE if
45 // encryption was successful, otherwise FALSE.
46 virtual BOOL encrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len) = 0;
47
48 // decrypt src and place result into dst. returns TRUE if
49 // encryption was successful, otherwise FALSE.
50 virtual BOOL decrpyt(const U8* src, U32 src_len, U8* dst, U32 dst_len) = 0;
51
52 // returns the space required to encrypt for a unencrypted source
53 // buffer of length len.
54 virtual U32 requiredEncryptionSpace(U32 src_len) const = 0 ;
55};
56
57
58//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59// Class LLNullCipher
60//
61// A class which implements LLCipher, but does not transform src
62// during encryption.
63//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64
65class LLNullCipher
66{
67public:
68 LLNullCipher() {}
69 virtual ~LLNullCipher() {}
70 virtual BOOL encrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
71 virtual BOOL decrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
72 virtual U32 requiredEncryptionSpace(U32 src_len);
73};
74
75//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76// Class LLXORCipher
77//
78// Implementation of LLCipher which encrypts using a XOR pad.
79//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
81class LLXORCipher
82{
83public:
84 LLXORCipher(const U8* pad, U32 pad_len);
85 LLXORCipher(const LLXORCipher& cipher);
86 virtual ~LLXORCipher();
87 LLXORCipher& operator=(const LLXORCipher& cipher);
88
89 // Cipher functions
90 virtual BOOL encrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
91 virtual BOOL decrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
92 virtual U32 requiredEncryptionSpace(U32 src_len);
93
94 // special syntactic-sugar since xor can be performed in place.
95 BOOL encrypt(U8* buf, U32 len) { return encrypt((const U8*)buf, len, buf, len); }
96 BOOL decrypt(U8* buf, U32 len) { return decrypt((const U8*)buf, len, buf, len); }
97
98#ifdef _DEBUG
99 // This function runs tests to make sure the crc is
100 // working. Returns TRUE if it is.
101 static BOOL testHarness();
102#endif
103
104protected:
105 void init(const U8* pad, U32 pad_len);
106 U8* mPad;
107 U8* mHead;
108 U32 mPadLen;
109};
110
111#endif // LL_LLCRYPTO_H