00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "../intl.h"
00032
00033 #include "crypt.h"
00034
00035 using namespace YAPET;
00036
00050 Crypt::Crypt(const Key& k) throw(YAPETException) : cipher(NULL),
00051 iv_length(0),
00052 key_length(0),
00053 key(k){
00054 cipher = EVP_bf_cbc();
00055 if (cipher == NULL)
00056 throw YAPETException(_("Unable to get cipher"));
00057
00058
00059 EVP_CIPHER_CTX ctx;
00060 EVP_CIPHER_CTX_init(&ctx);
00061
00062 int retval = EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, NULL, 0);
00063 if (retval == 0) {
00064 EVP_CIPHER_CTX_cleanup(&ctx);
00065 throw YAPETException(_("Error initializing cipher"));
00066 }
00067
00068 retval = EVP_CIPHER_CTX_set_key_length(&ctx, key.size());
00069 if (retval == 0) {
00070 EVP_CIPHER_CTX_cleanup(&ctx);
00071 throw YAPETException(_("Error setting the key length"));
00072 }
00073
00074 iv_length = EVP_CIPHER_CTX_iv_length(&ctx);
00075 key_length = EVP_CIPHER_CTX_key_length(&ctx);
00076
00077 EVP_CIPHER_CTX_cleanup(&ctx);
00078 }
00079
00080 Crypt::Crypt(const Crypt& c) : cipher(c.cipher),
00081 iv_length(c.iv_length),
00082 key_length(c.key_length),
00083 key(c.key) {
00084 }
00085
00086 const Crypt&
00087 Crypt::operator=(const Crypt& c) {
00088 if (this == &c) return *this;
00089
00090 iv_length = c.iv_length;
00091 key_length = c.key_length;
00092 cipher = c.cipher;
00093 key = c.key;
00094
00095 return *this;
00096 }