00001 #ifndef __XRDCRYPTOLITE_H__ 00002 #define __XRDCRYPTOLITE_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d C r y p t o L i t e . h h */ 00006 /* */ 00007 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 // This abstract class defines a very simple interface to encryption methods. 00034 // CryptoLite provides a naive interface to stream cryptographic algorithms 00035 // that include decryption validation. Use XrdCryptoBasic and it's derived 00036 // classes for full-featured cryptogrophy. 00037 // 00038 00039 class XrdCryptoLite 00040 { 00041 public: 00042 00043 // Create() creates a new CryptoLite object that implements the specified 00044 // cryptography (see below). It returns a pointer to the object or a 00045 // null pointer if not successful (e.g., unsupported). When creating a 00046 // crypto object you may associate an arbitrary type code with an 00047 // instance of that object which Type() will simply echo back. 00048 00049 // Supported names: 00050 // bf32 Blowfish with CRC32 validation. 00051 // 00052 static XrdCryptoLite * 00053 Create(int &rc, // errno when Create(...) == 0 00054 const char *Name, // Crypto name 00055 const char Type='\0'); // Crypto type (assigned) 00056 00057 // Decrypt() decrypts src and, if successful, returns the number of bytes 00058 // placed in dst. Otherwise, -errno is returned (which may be 0). 00059 // Requirements: srclen >= dstlen > 0 00060 // 00061 virtual int Decrypt(const char *key, // Decryption key 00062 int keyLen, // Decryption key byte length 00063 const char *src, // Buffer to be decrypted 00064 int srcLen, // Bytes length of src buffer 00065 char *dst, // Buffer to hold decrypted result 00066 int dstLen)=0;// Bytes length of dst buffer 00067 00068 // Encrypt() encrypts src and, if successful, returns the number of bytes 00069 // placed in dst. Otherwise, -errno is returned (which may be 0). 00070 // Requirements: 0 < srclen <= (dstlen + Overhead()) 00071 // 00072 virtual int Encrypt(const char *key, // Encryption key 00073 int keyLen, // Encryption key byte length 00074 const char *src, // Buffer to be encrypted 00075 int srcLen, // Bytes length of src buffer 00076 char *dst, // Buffer to hold encrypted result 00077 int dstLen)=0;// Bytes length of dst buffer 00078 00079 // Overhead() returns the number of *extra* bytes required for the dst buffer, 00080 // as specified when the actual implementation was instantiated. 00081 // Hence, we can provide an implementation for this method. 00082 // 00083 virtual int Overhead() {return Extra;} 00084 00085 // Type() simply returns the encyption type code assigned to this object when 00086 // its actual implementation was instantiated. Hence, we can provide an 00087 // implementation for this method. 00088 // 00089 virtual char Type() {return myType;} 00090 00091 XrdCryptoLite(char deType, int ovhd=8) : Extra(ovhd),myType(deType) {} 00092 virtual ~XrdCryptoLite() {} 00093 00094 protected: 00095 00096 int Extra; 00097 char myType; 00098 }; 00099 #endif