PageRenderTime 75ms CodeModel.GetById 25ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LLXORCIPHER_H
  26. #define LLXORCIPHER_H
  27. #include "llcipher.h"
  28. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. // Class LLXORCipher
  30. //
  31. // Implementation of LLCipher which encrypts using a XOR pad.
  32. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. class LLXORCipher : public LLCipher
  34. {
  35. public:
  36. LLXORCipher(const U8* pad, U32 pad_len);
  37. LLXORCipher(const LLXORCipher& cipher);
  38. virtual ~LLXORCipher();
  39. LLXORCipher& operator=(const LLXORCipher& cipher);
  40. // Cipher functions
  41. /*virtual*/ U32 encrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
  42. /*virtual*/ U32 decrypt(const U8* src, U32 src_len, U8* dst, U32 dst_len);
  43. /*virtual*/ U32 requiredEncryptionSpace(U32 src_len) const;
  44. // special syntactic-sugar since xor can be performed in place.
  45. BOOL encrypt(U8* buf, U32 len) { return encrypt((const U8*)buf, len, buf, len); }
  46. BOOL decrypt(U8* buf, U32 len) { return decrypt((const U8*)buf, len, buf, len); }
  47. #ifdef _DEBUG
  48. // This function runs tests to make sure the crc is
  49. // working. Returns TRUE if it is.
  50. static BOOL testHarness();
  51. #endif
  52. protected:
  53. void init(const U8* pad, U32 pad_len);
  54. U8* mPad;
  55. U8* mHead;
  56. U32 mPadLen;
  57. };
  58. #endif