Go to the documentation of this file.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
00056 if (cipher == NULL)
00057 throw YAPETException (_ ("Unable to get cipher") );
00058
00059
00060 EVP_CIPHER_CTX ctx;
00061 EVP_CIPHER_CTX_init (&ctx);
00062 int retval = EVP_CipherInit_ex (&ctx, cipher, NULL, NULL, NULL, 0);
00063
00064 if (retval == 0) {
00065 EVP_CIPHER_CTX_cleanup (&ctx);
00066 throw YAPETException (_ ("Error initializing cipher") );
00067 }
00068
00069 retval = EVP_CIPHER_CTX_set_key_length (&ctx, key.size() );
00070
00071 if (retval == 0) {
00072 EVP_CIPHER_CTX_cleanup (&ctx);
00073 throw YAPETException (_ ("Error setting the key length") );
00074 }
00075
00076 iv_length = EVP_CIPHER_CTX_iv_length (&ctx);
00077 key_length = EVP_CIPHER_CTX_key_length (&ctx);
00078 EVP_CIPHER_CTX_cleanup (&ctx);
00079 }
00080
00081 Crypt::Crypt (const Crypt& c) : cipher (c.cipher),
00082 iv_length (c.iv_length),
00083 key_length (c.key_length),
00084 key (c.key) {
00085 }
00086
00087 const Crypt&
00088 Crypt::operator= (const Crypt & c) {
00089 if (this == &c) return *this;
00090
00091 iv_length = c.iv_length;
00092 key_length = c.key_length;
00093 cipher = c.cipher;
00094 key = c.key;
00095 return *this;
00096 }