XRootD
Loading...
Searching...
No Matches
XrdCryptoCipher.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d C r y p t o C i p h e r . c c */
4/* */
5/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* Produced by Gerri Ganis for CERN */
7/* */
8/* This file is part of the XRootD software suite. */
9/* */
10/* XRootD is free software: you can redistribute it and/or modify it under */
11/* the terms of the GNU Lesser General Public License as published by the */
12/* Free Software Foundation, either version 3 of the License, or (at your */
13/* option) any later version. */
14/* */
15/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
16/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
17/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
18/* License for more details. */
19/* */
20/* You should have received a copy of the GNU Lesser General Public License */
21/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
22/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* The copyright holder's institutional names and contributor's names may not */
25/* be used to endorse or promote products derived from this software without */
26/* specific prior written permission of the institution or contributor. */
27/******************************************************************************/
28
29/* ************************************************************************** */
30/* */
31/* Generic interface to a cipher class */
32/* Allows to plug-in modules based on different crypto implementation */
33/* (OpenSSL, Botan, ...) */
34/* */
35/* ************************************************************************** */
36
37#include <cstring>
38
41
42//_____________________________________________________________________________
43bool XrdCryptoCipher::Finalize(bool, char *, int, const char *)
44{
45 // Finalize key computation (key agreement)
46 ABSTRACTMETHOD("XrdCryptoCipher::Finalize");
47 return 0;
48}
49
50//_____________________________________________________________________________
52{
53 // Check key validity
54 ABSTRACTMETHOD("XrdCryptoCipher::IsValid");
55 return 0;
56}
57
58//____________________________________________________________________________
59void XrdCryptoCipher::SetIV(int l, const char *iv)
60{
61 // Set IV from l bytes at iv. If !iv, sets the IV length.
62
63 ABSTRACTMETHOD("XrdCryptoCipher::SetIV");
64}
65
66//____________________________________________________________________________
68{
69 // Regenerate IV and return it
70
71 ABSTRACTMETHOD("XrdCryptoCipher::RefreshIV");
72 return 0;
73}
74
75//____________________________________________________________________________
76char *XrdCryptoCipher::IV(int &l) const
77{
78 // Get IV
79
80 ABSTRACTMETHOD("XrdCryptoCipher::IV");
81 return 0;
82}
83
84//____________________________________________________________________________
86{
87 // Getter for public part during key agreement
88
89 ABSTRACTMETHOD("XrdCryptoCipher::Public");
90 return 0;
91}
92
93//_____________________________________________________________________________
95{
96 // Return pointer to a bucket created using the internal information
97 // serialized
98
99 ABSTRACTMETHOD("XrdCryptoCipher::AsBucket");
100 return 0;
101}
102//____________________________________________________________________________
103int XrdCryptoCipher::Encrypt(const char *, int, char *)
104{
105 // Encrypt lin bytes at in with local cipher.
106
107 ABSTRACTMETHOD("XrdCryptoCipher::Encrypt");
108 return 0;
109}
110
111//____________________________________________________________________________
112int XrdCryptoCipher::Decrypt(const char *, int, char *)
113{
114 // Decrypt lin bytes at in with local cipher.
115
116 ABSTRACTMETHOD("XrdCryptoCipher::Decrypt");
117 return 0;
118}
119
120//____________________________________________________________________________
122{
123 // Required buffer size for encrypting l bytes
124
125 ABSTRACTMETHOD("XrdCryptoCipher::EncOutLength");
126 return 0;
127}
128
129//____________________________________________________________________________
131{
132 // Required buffer size for decrypting l bytes
133
134 ABSTRACTMETHOD("XrdCryptoCipher::DecOutLength");
135 return 0;
136}
137
138//____________________________________________________________________________
140{
141 // Test if cipher length is the default one
142
143 ABSTRACTMETHOD("XrdCryptoCipher::IsDefaultLength");
144 return 0;
145}
146
147//____________________________________________________________________________
149{
150 // Return the max cipher IV length
151
152 ABSTRACTMETHOD("XrdCryptoCipher::MaxIVLength");
153 return 0;
154}
155
156//____________________________________________________________________________
158{
159 // Encrypt bucket bck with local cipher
160 // Return size of encoded bucket or -1 in case of error
161 int snew = -1;
162
163 int liv = 0;
164 char *iv = 0;
165 if (useiv) {
166 iv = RefreshIV(liv);
167 if (!iv) return snew;
168 }
169
170 int sz = EncOutLength(bck.size) + liv;
171 char *newbck = new char[sz];
172 if (newbck) {
173 memset(newbck, 0, sz);
174 if (liv > 0) memcpy(newbck, iv, liv);
175 snew = Encrypt(bck.buffer,bck.size,newbck+liv);
176 if (snew > -1)
177 bck.Update(newbck,snew + liv);
178 }
179 return snew;
180}
181
182//____________________________________________________________________________
184{
185 // Decrypt bucket bck with local cipher
186 // Return size of encoded bucket or -1 in case of error
187 int snew = -1;
188
189 int liv = (useiv) ? MaxIVLength() : 0;
190
191 int sz = DecOutLength(bck.size - liv);
192 char *newbck = new char[sz];
193 if (newbck) {
194
195 if (useiv) {
196 char *iv = new char[liv];
197 if (iv) {
198 memcpy(iv,bck.buffer,liv);
199 SetIV(liv, iv);
200 delete[] iv;
201 } else {
202 return snew;
203 }
204 }
205 memset(newbck, 0, sz);
206 snew = Decrypt(bck.buffer + liv, bck.size - liv, newbck);
207 if (snew > -1)
208 bck.Update(newbck,snew);
209 }
210 return snew;
211}
#define ABSTRACTMETHOD(x)
virtual bool IsDefaultLength() const
virtual void SetIV(int l, const char *iv)
virtual int Decrypt(const char *in, int lin, char *out)
virtual int DecOutLength(int l)
virtual char * RefreshIV(int &l)
virtual int Encrypt(const char *in, int lin, char *out)
virtual int MaxIVLength() const
virtual XrdSutBucket * AsBucket()
virtual char * Public(int &lpub)
virtual char * IV(int &l) const
virtual bool IsValid()
virtual int EncOutLength(int l)
virtual bool Finalize(bool padded, char *pub, int lpub, const char *t)
kXR_int32 size
void Update(char *nb=0, int ns=0, int ty=0)