Subversion Repositories tpanel

Rev

Rev 475 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 475 Rev 476
Line 39... Line 39...
39
#define CHUNK_SIZE          1024
39
#define CHUNK_SIZE          1024
40
#define OSSL_SUCCESS        1
40
#define OSSL_SUCCESS        1
41
#define OSSL_ERROR          0
41
#define OSSL_ERROR          0
42
static unsigned long ssl_errno;
42
static unsigned long ssl_errno;
43
 
43
 
-
 
44
/*
-
 
45
 * Internally used helper functions
-
 
46
 */
44
void _print_ssl_error(unsigned long eno)
47
void _print_ssl_error(unsigned long eno)
45
{
48
{
46
    char msg[1024];
49
    char msg[1024];
47
 
50
 
48
    ERR_error_string_n(eno, msg, sizeof(msg));
51
    ERR_error_string_n(eno, msg, sizeof(msg));
Line 55... Line 58...
55
 
58
 
56
    ERR_error_string_n(ssl_errno, msg, sizeof(msg));
59
    ERR_error_string_n(ssl_errno, msg, sizeof(msg));
57
    return string(msg);
60
    return string(msg);
58
}
61
}
59
 
62
 
-
 
63
/* -------------------------------------------------------------------------
-
 
64
 * Implementaion of methods from class TScramble
-
 
65
 * -------------------------------------------------------------------------*/
60
TScramble::TScramble()
66
TScramble::TScramble()
61
{
67
{
62
    DECL_TRACER("TScramble::TScramble()");
68
    DECL_TRACER("TScramble::TScramble()");
63
 
69
 
64
    mCtx = EVP_CIPHER_CTX_new();
70
    mCtx = EVP_CIPHER_CTX_new();
Line 76... Line 82...
76
        EVP_CIPHER_CTX_cleanup(mCtx);
82
        EVP_CIPHER_CTX_cleanup(mCtx);
77
        EVP_CIPHER_CTX_free(mCtx);
83
        EVP_CIPHER_CTX_free(mCtx);
78
    }
84
    }
79
}
85
}
80
 
86
 
81
bool TScramble::aesInit(const string& key, const string& salt, bool encrypt)
87
bool TScramble::aesInit(const string& key, const string& salt)
82
{
88
{
83
    DECL_TRACER("TScramble::aesInit(const string& key, const string& salt, bool encrypt)");
89
    DECL_TRACER("TScramble::aesInit(const string& key, const string& salt)");
84
 
90
 
85
    if (mAesInitialized)
91
    if (mAesInitialized)
86
        return true;
92
        return true;
87
 
93
 
88
    if (!mCtx)
94
    if (!mCtx)
Line 122... Line 128...
122
 
128
 
123
    if (keySize == AES128_KEY_SIZE)
129
    if (keySize == AES128_KEY_SIZE)
124
    {
130
    {
125
        EVP_CIPHER_CTX_init(mCtx);
131
        EVP_CIPHER_CTX_init(mCtx);
126
 
132
 
127
        if (encrypt)
133
        if ((ssl_errno = EVP_DecryptInit_ex(mCtx, pCipher, nullptr, mAesKey, mAesIV)) != OSSL_SUCCESS)
128
        {
134
        {
129
            if ((ssl_errno = EVP_EncryptInit_ex(mCtx, pCipher, nullptr, mAesKey, mAesIV)) != OSSL_SUCCESS)
-
 
130
            {
-
 
131
                MSG_ERROR("Error initializing: " << _get_ssl_error());
135
            MSG_ERROR("Error initializing: " << _get_ssl_error());
132
                return false;
136
            return false;
133
            }
-
 
134
        }
137
        }
135
        else
-
 
136
        {
-
 
137
            if ((ssl_errno = EVP_DecryptInit_ex(mCtx, pCipher, nullptr, mAesKey, mAesIV)) != OSSL_SUCCESS)
-
 
138
            {
-
 
139
                MSG_ERROR("Error initializing: " << _get_ssl_error());
-
 
140
                return false;
-
 
141
            }
-
 
142
        }
-
 
143
 
138
 
144
        EVP_CIPHER_CTX_set_key_length(mCtx, AES128_KEY_SIZE);
139
        EVP_CIPHER_CTX_set_key_length(mCtx, AES128_KEY_SIZE);
145
    }
140
    }
146
    else
141
    else
147
    {
142
    {
148
        MSG_ERROR("Key size is " << (keySize * 8) << " bits - should be 128 bits");
143
        MSG_ERROR("Key size is " << (keySize * 8) << " bits - should be 128 bits");