XRootD
Loading...
Searching...
No Matches
XrdCryptoLite_bf32 Class Reference
Inheritance diagram for XrdCryptoLite_bf32:
Collaboration diagram for XrdCryptoLite_bf32:

Public Member Functions

 XrdCryptoLite_bf32 (const char deType)
 ~XrdCryptoLite_bf32 ()
virtual int Decrypt (const char *key, int keyLen, const char *src, int srcLen, char *dst, int dstLen)
virtual int Encrypt (const char *key, int keyLen, const char *src, int srcLen, char *dst, int dstLen)
Public Member Functions inherited from XrdCryptoLite
 XrdCryptoLite (char deType, int ovhd=8)
virtual ~XrdCryptoLite ()
virtual int Overhead ()
virtual char Type ()

Additional Inherited Members

Static Public Member Functions inherited from XrdCryptoLite
static XrdCryptoLiteCreate (int &rc, const char *Name, const char Type='\0')
Protected Attributes inherited from XrdCryptoLite
int Extra
char myType

Detailed Description

Definition at line 54 of file XrdCryptoLite_bf32.cc.

Constructor & Destructor Documentation

◆ XrdCryptoLite_bf32()

XrdCryptoLite_bf32::XrdCryptoLite_bf32 ( const char deType)
inline

Definition at line 72 of file XrdCryptoLite_bf32.cc.

72: XrdCryptoLite(deType, 4) {}
XrdCryptoLite(char deType, int ovhd=8)

References XrdCryptoLite::XrdCryptoLite().

Here is the call graph for this function:

◆ ~XrdCryptoLite_bf32()

XrdCryptoLite_bf32::~XrdCryptoLite_bf32 ( )
inline

Definition at line 73 of file XrdCryptoLite_bf32.cc.

73{}

Member Function Documentation

◆ Decrypt()

int XrdCryptoLite_bf32::Decrypt ( const char * key,
int keyLen,
const char * src,
int srcLen,
char * dst,
int dstLen )
virtual

Implements XrdCryptoLite.

Definition at line 80 of file XrdCryptoLite_bf32.cc.

86{
87 unsigned char ivec[8] = {0,0,0,0,0,0,0,0};
88 unsigned int crc32;
89 int wLen;
90 int dLen = srcLen - sizeof(crc32);
91
92// Make sure we have data
93//
94 if (dstLen <= (int)sizeof(crc32) || dstLen < srcLen) return -EINVAL;
95
96// Decrypt
97//
98 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
99 EVP_DecryptInit_ex(ctx, EVP_bf_cfb64(), NULL, NULL, NULL);
100 EVP_CIPHER_CTX_set_padding(ctx, 0);
101 EVP_CIPHER_CTX_set_key_length(ctx, keyLen);
102 EVP_DecryptInit_ex(ctx, NULL, NULL, (unsigned char *)key, ivec);
103 EVP_DecryptUpdate(ctx, (unsigned char *)dst, &wLen,
104 (unsigned char *)src, srcLen);
105 EVP_DecryptFinal_ex(ctx, (unsigned char *)dst, &wLen);
106 EVP_CIPHER_CTX_free(ctx);
107
108// Perform the CRC check to verify we have valid data here
109//
110 memcpy(&crc32, dst+dLen, sizeof(crc32));
111 crc32 = ntohl(crc32);
112 if (crc32 != XrdOucCRC::CRC32((const unsigned char *)dst, dLen))
113 return -EPROTO;
114
115// Return success
116//
117 return dLen;
118}
static uint32_t CRC32(const unsigned char *data, int count)
Definition XrdOucCRC.cc:171

References XrdOucCRC::CRC32().

Here is the call graph for this function:

◆ Encrypt()

int XrdCryptoLite_bf32::Encrypt ( const char * key,
int keyLen,
const char * src,
int srcLen,
char * dst,
int dstLen )
virtual

Implements XrdCryptoLite.

Definition at line 124 of file XrdCryptoLite_bf32.cc.

130{
131 unsigned char buff[4096], *bP, *mP = 0, ivec[8] = {0,0,0,0,0,0,0,0};
132 unsigned int crc32;
133 int wLen;
134 int dLen = srcLen + sizeof(crc32);
135
136// Make sure that the destination if at least 4 bytes larger and we have data
137//
138 if (dstLen-srcLen < (int)sizeof(crc32) || srcLen <= 0) return -EINVAL;
139
140// Normally, the msg is 4k or less but if more, get a new buffer
141//
142 if (dLen <= (int)sizeof(buff)) bP = buff;
143 else {if (!(mP = (unsigned char *)malloc(dLen))) return -ENOMEM;
144 else bP = mP;
145 }
146
147// Append a crc
148//
149 memcpy(bP, src, srcLen);
150 crc32 = XrdOucCRC::CRC32(bP, srcLen);
151 crc32 = htonl(crc32);
152 memcpy((bP+srcLen), &crc32, sizeof(crc32));
153
154// Encrypt
155//
156 EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
157 EVP_EncryptInit_ex(ctx, EVP_bf_cfb64(), NULL, NULL, NULL);
158 EVP_CIPHER_CTX_set_padding(ctx, 0);
159 EVP_CIPHER_CTX_set_key_length(ctx, keyLen);
160 EVP_EncryptInit_ex(ctx, NULL, NULL, (unsigned char *)key, ivec);
161 EVP_EncryptUpdate(ctx, (unsigned char *)dst, &wLen, bP, dLen);
162 EVP_EncryptFinal_ex(ctx, (unsigned char *)dst, &wLen);
163 EVP_CIPHER_CTX_free(ctx);
164
165// Free temp buffer and return success
166//
167 if (mP) free(mP);
168 return dLen;
169}

References XrdOucCRC::CRC32().

Here is the call graph for this function:

The documentation for this class was generated from the following file: