00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "../intl.h"
00021
00022 #include "crypt.h"
00023
00024 using namespace YAPET;
00025
00039 Crypt::Crypt(const Key& k) throw(YAPETException) : cipher(NULL),
00040 iv_length(0),
00041 key_length(0),
00042 key(k){
00043 cipher = EVP_bf_cbc();
00044 if (cipher == NULL)
00045 throw YAPETException(_("Unable to get cipher"));
00046
00047
00048 EVP_CIPHER_CTX ctx;
00049 EVP_CIPHER_CTX_init(&ctx);
00050
00051 int retval = EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, NULL, 0);
00052 if (retval == 0) {
00053 EVP_CIPHER_CTX_cleanup(&ctx);
00054 throw YAPETException(_("Error initializing cipher"));
00055 }
00056
00057 retval = EVP_CIPHER_CTX_set_key_length(&ctx, key.size());
00058 if (retval == 0) {
00059 EVP_CIPHER_CTX_cleanup(&ctx);
00060 throw YAPETException(_("Error setting the key length"));
00061 }
00062
00063 iv_length = EVP_CIPHER_CTX_iv_length(&ctx);
00064 key_length = EVP_CIPHER_CTX_key_length(&ctx);
00065
00066 EVP_CIPHER_CTX_cleanup(&ctx);
00067 }
00068
00069 Crypt::Crypt(const Crypt& c) : cipher(c.cipher),
00070 iv_length(c.iv_length),
00071 key_length(c.key_length),
00072 key(c.key) {
00073 }
00074
00075 const Crypt&
00076 Crypt::operator=(const Crypt& c) {
00077 if (this == &c) return *this;
00078
00079 iv_length = c.iv_length;
00080 key_length = c.key_length;
00081 cipher = c.cipher;
00082 key = c.key;
00083
00084 return *this;
00085 }