xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdCryptosslCipher.hh
Go to the documentation of this file.
1 #ifndef __CRYPTO_SSLCIPHER_H__
2 #define __CRYPTO_SSLCIPHER_H__
3 /******************************************************************************/
4 /* */
5 /* X r d C r y p t o S s l C i p h e r . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Gerri Ganis for CERN */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 /* ************************************************************************** */
32 /* */
33 /* OpenSSL implementation of XrdCryptoCipher */
34 /* */
35 /* ************************************************************************** */
36 
38 
39 #include <openssl/evp.h>
40 #include <openssl/dh.h>
41 
42 #define kDHMINBITS 512
43 
44 // ---------------------------------------------------------------------------//
45 //
46 // OpenSSL Cipher Implementation
47 //
48 // ---------------------------------------------------------------------------//
50 {
51 private:
52  char *fIV;
53  int lIV;
54  const EVP_CIPHER *cipher;
55  EVP_CIPHER_CTX *ctx;
56  DH *fDH;
57  bool deflength;
58  bool valid;
59 
60  void GenerateIV();
61  int EncDec(int encdec, const char *bin, int lin, char *out);
62  void PrintPublic(BIGNUM *pub);
63  int Publen();
64 
65 public:
66  XrdCryptosslCipher(const char *t, int l = 0);
67  XrdCryptosslCipher(const char *t, int l, const char *k,
68  int liv, const char *iv);
70  XrdCryptosslCipher(bool padded, int len, char *pub, int lpub, const char *t);
72  virtual ~XrdCryptosslCipher();
73 
74  // Finalize key computation (key agreement)
75  bool Finalize(bool padded, char *pub, int lpub, const char *t);
76  void Cleanup();
77 
78  // Validity
79  bool IsValid() { return valid; }
80 
81  // Support
82  static bool IsSupported(const char *cip);
83 
84  // Required buffer size for encrypt / decrypt operations on l bytes
85  int EncOutLength(int l);
86  int DecOutLength(int l);
87  char *Public(int &lpub);
88 
89  // Additional getter
91  char *IV(int &l) const { l = lIV; return fIV; }
92  bool IsDefaultLength() const { return deflength; }
93  int MaxIVLength() const;
94 
95  // Additional setter
96  void SetIV(int l, const char *iv);
97 
98  // Additional methods
99  int Encrypt(const char *bin, int lin, char *out);
100  int Decrypt(const char *bin, int lin, char *out);
101  char *RefreshIV(int &l);
102 };
103 #endif
virtual ~XrdCryptosslCipher()
Definition: XrdCryptoCipher.hh:47
bool IsValid()
Definition: XrdCryptosslCipher.hh:79
const EVP_CIPHER * cipher
Definition: openssl3/XrdCryptosslCipher.hh:54
XrdSutBucket * AsBucket()
char * Public(int &lpub)
int EncOutLength(int l)
Definition: openssl3/XrdCryptosslCipher.hh:49
void PrintPublic(BIGNUM *pub)
int EncDec(int encdec, const char *bin, int lin, char *out)
int Encrypt(const char *bin, int lin, char *out)
bool Finalize(bool padded, char *pub, int lpub, const char *t)
int MaxIVLength() const
bool valid
Definition: openssl3/XrdCryptosslCipher.hh:58
bool IsDefaultLength() const
Definition: XrdCryptosslCipher.hh:92
char * fIV
Definition: openssl3/XrdCryptosslCipher.hh:52
EVP_CIPHER_CTX * ctx
Definition: openssl3/XrdCryptosslCipher.hh:55
static bool IsSupported(const char *cip)
int DecOutLength(int l)
void SetIV(int l, const char *iv)
int Decrypt(const char *bin, int lin, char *out)
char * IV(int &l) const
Definition: XrdCryptosslCipher.hh:91
char * RefreshIV(int &l)
int lIV
Definition: openssl3/XrdCryptosslCipher.hh:53
XrdCryptosslCipher(const char *t, int l=0)
DH * fDH
Definition: XrdCryptosslCipher.hh:56
Definition: XrdSutBucket.hh:43
bool deflength
Definition: openssl3/XrdCryptosslCipher.hh:57