xrootd
XrdCryptosslCipher.hh
Go to the documentation of this file.
1 // $Id$
2 #ifndef __CRYPTO_SSLCIPHER_H__
3 #define __CRYPTO_SSLCIPHER_H__
4 /******************************************************************************/
5 /* */
6 /* X r d C r y p t o S s l C i p h e r . h h */
7 /* */
8 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
9 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
10 /* Produced by Andrew Hanushevsky for Stanford University under contract */
11 /* DE-AC03-76-SFO0515 with the Department of Energy */
12 /******************************************************************************/
13 
14 /* ************************************************************************** */
15 /* */
16 /* OpenSSL implementation of XrdCryptoCipher */
17 /* */
18 /* ************************************************************************** */
19 
21 
22 #include <openssl/evp.h>
23 #include <openssl/dh.h>
24 
25 #define kDHMINBITS 128
26 
27 // ---------------------------------------------------------------------------//
28 //
29 // OpenSSL Cipher Implementation
30 //
31 // ---------------------------------------------------------------------------//
33 {
34 private:
35  char *fIV;
36  int lIV;
37  const EVP_CIPHER *cipher;
38  EVP_CIPHER_CTX ctx;
39  DH *fDH;
40  bool deflength;
41  bool valid;
42 
43  void GenerateIV();
44  int EncDec(int encdec, const char *bin, int lin, char *out);
45  void PrintPublic(BIGNUM *pub);
46  int Publen();
47 
48 public:
49  XrdCryptosslCipher(const char *t, int l = 0);
50  XrdCryptosslCipher(const char *t, int l, const char *k,
51  int liv, const char *iv);
53  XrdCryptosslCipher(int len, char *pub, int lpub, const char *t);
55  virtual ~XrdCryptosslCipher();
56 
57  // Finalize key computation (key agreement)
58  bool Finalize(char *pub, int lpub, const char *t);
59  void Cleanup();
60 
61  // Validity
62  bool IsValid() { return valid; }
63 
64  // Support
65  static bool IsSupported(const char *cip);
66 
67  // Required buffer size for encrypt / decrypt operations on l bytes
68  int EncOutLength(int l);
69  int DecOutLength(int l);
70  char *Public(int &lpub);
71 
72  // Additional getter
74  char *IV(int &l) const { l = lIV; return fIV; }
75  bool IsDefaultLength() const { return deflength; }
76 
77  // Additional setter
78  void SetIV(int l, const char *iv);
79 
80  // Additional methods
81  int Encrypt(const char *bin, int lin, char *out);
82  int Decrypt(const char *bin, int lin, char *out);
83  char *RefreshIV(int &l);
84 };
85 #endif