xrootd
XrdCryptoLite.hh
Go to the documentation of this file.
1 #ifndef __XRDCRYPTOLITE_H__
2 #define __XRDCRYPTOLITE_H__
3 /******************************************************************************/
4 /* */
5 /* X r d C r y p t o L i t e . h h */
6 /* */
7 /* (c) 2008 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 // This abstract class defines a very simple interface to encryption methods.
16 // CryptoLite provides a naive interface to stream cryptographic algorithms
17 // that include decryption validation. Use XrdCryptoBasic and it's derived
18 // classes for full-featured cryptogrophy.
19 //
20 
22 {
23 public:
24 
25 // Create() creates a new CryptoLite object that implements the specified
26 // cryptography (see below). It returns a pointer to the object or a
27 // null pointer if not successful (e.g., unsupported). When creating a
28 // crypto object you may associate an arbitrary type code with an
29 // instance of that object which Type() will simply echo back.
30 
31 // Supported names:
32 // bf32 Blowfish with CRC32 validation.
33 //
34 static XrdCryptoLite *
35  Create(int &rc, // errno when Create(...) == 0
36  const char *Name, // Crypto name
37  const char Type='\0'); // Crypto type (assigned)
38 
39 // Decrypt() decrypts src and, if successful, returns the number of bytes
40 // placed in dst. Otherwise, -errno is returned (which may be 0).
41 // Requirements: srclen >= dstlen > 0
42 //
43 virtual int Decrypt(const char *key, // Decryption key
44  int keyLen, // Decryption key byte length
45  const char *src, // Buffer to be decrypted
46  int srcLen, // Bytes length of src buffer
47  char *dst, // Buffer to hold decrypted result
48  int dstLen)=0;// Bytes length of dst buffer
49 
50 // Encrypt() encrypts src and, if successful, returns the number of bytes
51 // placed in dst. Otherwise, -errno is returned (which may be 0).
52 // Requirements: 0 < srclen <= (dstlen + Overhead())
53 //
54 virtual int Encrypt(const char *key, // Encryption key
55  int keyLen, // Encryption key byte length
56  const char *src, // Buffer to be encrypted
57  int srcLen, // Bytes length of src buffer
58  char *dst, // Buffer to hold encrypted result
59  int dstLen)=0;// Bytes length of dst buffer
60 
61 // Overhead() returns the number of *extra* bytes required for the dst buffer,
62 // as specified when the actual implementation was instantiated.
63 // Hence, we can provide an implementation for this method.
64 //
65 virtual int Overhead() {return Extra;}
66 
67 // Type() simply returns the encyption type code assigned to this object when
68 // its actual implementation was instantiated. Hence, we can provide an
69 // implementation for this method.
70 //
71 virtual char Type() {return myType;}
72 
73  XrdCryptoLite(char deType, int ovhd=8) : Extra(ovhd),myType(deType) {}
74 virtual ~XrdCryptoLite() {}
75 
76 protected:
77 
78 int Extra;
79 char myType;
80 };
81 #endif