|
21 | 21 |
|
22 | 22 | hashkit_string_st *hashkit_encrypt(hashkit_st *kit, const char *source, size_t source_length) {
|
23 | 23 | #ifdef HAVE_OPENSSL_CRYPTO
|
24 |
| - return aes_encrypt((encryption_context_t *) kit->_cryptographic_context, |
| 24 | + return aes_encrypt((encryption_context_t *) kit->_key, |
25 | 25 | (const unsigned char *) source, source_length);
|
26 | 26 | #else
|
27 |
| - return aes_encrypt((aes_key_t *) kit->_cryptographic_context, source, |
| 27 | + return aes_encrypt((aes_key_t *) kit->_key, source, |
28 | 28 | source_length);
|
29 | 29 | #endif
|
30 | 30 | }
|
31 | 31 |
|
32 | 32 | hashkit_string_st *hashkit_decrypt(hashkit_st *kit, const char *source, size_t source_length) {
|
33 | 33 | #ifdef HAVE_OPENSSL_CRYPTO
|
34 |
| - return aes_decrypt((encryption_context_t *) kit->_cryptographic_context, |
| 34 | + return aes_decrypt((encryption_context_t *) kit->_key, |
35 | 35 | (const unsigned char *) source, source_length);
|
36 | 36 | #else
|
37 |
| - return aes_decrypt((aes_key_t *)kit->_cryptographic_context, source, source_length); |
| 37 | + return aes_decrypt((aes_key_t *)kit->_key, source, source_length); |
38 | 38 | #endif
|
39 | 39 | }
|
40 | 40 |
|
41 | 41 | #ifdef HAVE_OPENSSL_CRYPTO
|
42 | 42 | bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) {
|
43 |
| - kit->_cryptographic_context = (encryption_context_t *) malloc(sizeof(encryption_context_t)); |
44 |
| - ((encryption_context_t *) kit->_cryptographic_context)->encryption_context = EVP_CIPHER_CTX_new(); |
45 |
| - ((encryption_context_t *) kit->_cryptographic_context)->decryption_context = EVP_CIPHER_CTX_new(); |
46 |
| - if (((encryption_context_t *) kit->_cryptographic_context)->encryption_context == NULL |
47 |
| - || ((encryption_context_t *) kit->_cryptographic_context)->decryption_context == NULL) |
| 43 | + kit->_key = (encryption_context_t *) malloc(sizeof(encryption_context_t)); |
| 44 | + ((encryption_context_t *) kit->_key)->encryption_context = EVP_CIPHER_CTX_new(); |
| 45 | + ((encryption_context_t *) kit->_key)->decryption_context = EVP_CIPHER_CTX_new(); |
| 46 | + if (((encryption_context_t *) kit->_key)->encryption_context == NULL |
| 47 | + || ((encryption_context_t *) kit->_key)->decryption_context == NULL) |
48 | 48 | {
|
49 | 49 | return false;
|
50 | 50 | }
|
51 | 51 | return aes_initialize((const unsigned char *) key, key_length,
|
52 |
| - (encryption_context_t *) kit->_cryptographic_context); |
| 52 | + (encryption_context_t *) kit->_key); |
53 | 53 | }
|
54 | 54 | #else
|
55 | 55 | bool hashkit_key(hashkit_st *kit, const char *key, const size_t key_length) {
|
56 |
| - if (kit->_cryptographic_context) { |
57 |
| - free(kit->_cryptographic_context); |
| 56 | + if (kit->_key) { |
| 57 | + free(kit->_key); |
58 | 58 | }
|
59 | 59 |
|
60 |
| - kit->_cryptographic_context = aes_create_key(key, key_length); |
| 60 | + kit->_key = aes_create_key(key, key_length); |
61 | 61 |
|
62 |
| - return bool(kit->_cryptographic_context); |
| 62 | + return bool(kit->_key); |
63 | 63 | }
|
64 | 64 | #endif
|
0 commit comments