PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llxorcipher.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 67 lines | 25 code | 9 blank | 33 comment | 0 complexity | b65907c7574cb8a32a7695b172f9998b MD5 | raw file
 1/** 
 2 * @file llxorcipher.h
 3 *
 4 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
 5 * Second Life Viewer Source Code
 6 * Copyright (C) 2010, Linden Research, Inc.
 7 * 
 8 * This library is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation;
11 * version 2.1 of the License only.
12 * 
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 * 
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 * 
22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
23 * $/LicenseInfo$
24 */
25
26#ifndef LLXORCIPHER_H
27#define LLXORCIPHER_H
28
29#include "llcipher.h"
30
31//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32// Class LLXORCipher
33//
34// Implementation of LLCipher which encrypts using a XOR pad.
35//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37class LLXORCipher : public LLCipher
38{
39public:
40	LLXORCipher(const U8* pad, U32 pad_len);
41	LLXORCipher(const LLXORCipher& cipher);
42	virtual ~LLXORCipher();
43	LLXORCipher& operator=(const LLXORCipher& cipher);
44
45	// Cipher functions
46	/*virtual*/ U32 encrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
47	/*virtual*/ U32 decrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
48	/*virtual*/ U32 requiredEncryptionSpace(U32 src_len) const;
49
50	// special syntactic-sugar since xor can be performed in place.
51	BOOL encrypt(U8* buf, U32 len) { return encrypt((const U8*)buf, len, buf, len); }
52	BOOL decrypt(U8* buf, U32 len) { return decrypt((const U8*)buf, len, buf, len); }
53
54#ifdef _DEBUG
55	// This function runs tests to make sure the crc is
56	// working. Returns TRUE if it is.
57	static BOOL testHarness();
58#endif
59
60protected:
61	void init(const U8* pad, U32 pad_len);
62	U8* mPad;
63	U8* mHead;
64	U32 mPadLen;
65};
66
67#endif