@@ -55,58 +55,60 @@ bool aes_initialize(const unsigned char *key, const size_t key_length,
55
55
56
56
hashkit_string_st *aes_encrypt (encryption_context_t *crypto_context, const unsigned char *source,
57
57
size_t source_length) {
58
- EVP_CIPHER_CTX *encryption_context = crypto_context->encryption_context ;
59
- int cipher_length = source_length + EVP_CIPHER_CTX_block_size (encryption_context);
60
- int final_length = 0 ;
61
- unsigned char *cipher_text = (unsigned char *) malloc (cipher_length);
62
- if (cipher_text == NULL ) {
63
- return NULL ;
64
- }
65
- if (EVP_EncryptInit_ex (encryption_context, NULL , NULL , NULL , NULL ) != 1
66
- || EVP_EncryptUpdate (encryption_context, cipher_text, &cipher_length, source, source_length)
67
- != 1
68
- || EVP_EncryptFinal_ex (encryption_context, cipher_text + cipher_length, &final_length) != 1 )
69
- {
70
- free (cipher_text);
71
- return NULL ;
72
- }
58
+ EVP_CIPHER_CTX *encryption_context = crypto_context->encryption_context ;
59
+ int cipher_length = source_length + EVP_CIPHER_CTX_block_size (encryption_context);
60
+ int final_length = 0 ;
61
+ unsigned char *cipher_text = (unsigned char *) malloc (cipher_length);
62
+ if (cipher_text == NULL ) {
63
+ return NULL ;
64
+ }
65
+ if (EVP_EncryptInit_ex (encryption_context, NULL , NULL , NULL , NULL ) != 1
66
+ || EVP_EncryptUpdate (encryption_context, cipher_text, &cipher_length, source, source_length)
67
+ != 1
68
+ || EVP_EncryptFinal_ex (encryption_context, cipher_text + cipher_length, &final_length) != 1 )
69
+ {
70
+ free (cipher_text);
71
+ return NULL ;
72
+ }
73
73
74
- hashkit_string_st *destination = hashkit_string_create (cipher_length + final_length);
75
- if (destination == NULL ) {
76
- return NULL ;
77
- }
78
- char *dest = hashkit_string_c_str_mutable (destination);
79
- memcpy (dest, cipher_text, cipher_length + final_length);
80
- hashkit_string_set_length (destination, cipher_length + final_length);
81
- return destination;
74
+ hashkit_string_st *destination = hashkit_string_create (cipher_length + final_length);
75
+ if (destination == NULL ) {
76
+ return NULL ;
77
+ }
78
+ char *dest = hashkit_string_c_str_mutable (destination);
79
+ memcpy (dest, cipher_text, cipher_length + final_length);
80
+ hashkit_string_set_length (destination, cipher_length + final_length);
81
+ return destination;
82
82
}
83
83
84
84
hashkit_string_st *aes_decrypt (encryption_context_t *crypto_context, const unsigned char *source,
85
85
size_t source_length) {
86
- EVP_CIPHER_CTX *decryption_context = crypto_context->decryption_context ;
87
- int plain_text_length = source_length;
88
- int final_length = 0 ;
89
- unsigned char *plain_text = (unsigned char *) malloc (plain_text_length);
90
- if (plain_text == NULL ) {
91
- return NULL ;
92
- }
93
- if (EVP_DecryptInit_ex (decryption_context, NULL , NULL , NULL , NULL ) != 1
94
- || EVP_DecryptUpdate (decryption_context, plain_text, &plain_text_length, source, source_length)
95
- != 1
96
- || EVP_DecryptFinal_ex (decryption_context, plain_text + plain_text_length, &final_length) != 1 )
97
- {
98
- free (plain_text);
99
- return NULL ;
100
- }
86
+ EVP_CIPHER_CTX *decryption_context = crypto_context->decryption_context ;
87
+ int plain_text_length = source_length;
88
+ int final_length = 0 ;
89
+ unsigned char *plain_text = (unsigned char *) malloc (plain_text_length);
90
+ if (plain_text == NULL ) {
91
+ return NULL ;
92
+ }
93
+ if (EVP_DecryptInit_ex (decryption_context, NULL , NULL , NULL , NULL ) != 1
94
+ || EVP_DecryptUpdate (decryption_context, plain_text, &plain_text_length, source,
95
+ source_length)
96
+ != 1
97
+ || EVP_DecryptFinal_ex (decryption_context, plain_text + plain_text_length, &final_length)
98
+ != 1 )
99
+ {
100
+ free (plain_text);
101
+ return NULL ;
102
+ }
101
103
102
- hashkit_string_st *destination = hashkit_string_create (plain_text_length + final_length);
103
- if (destination == NULL ) {
104
- return NULL ;
105
- }
106
- char *dest = hashkit_string_c_str_mutable (destination);
107
- memcpy (dest, plain_text, plain_text_length + final_length);
108
- hashkit_string_set_length (destination, plain_text_length + final_length);
109
- return destination;
104
+ hashkit_string_st *destination = hashkit_string_create (plain_text_length + final_length);
105
+ if (destination == NULL ) {
106
+ return NULL ;
107
+ }
108
+ char *dest = hashkit_string_c_str_mutable (destination);
109
+ memcpy (dest, plain_text, plain_text_length + final_length);
110
+ hashkit_string_set_length (destination, plain_text_length + final_length);
111
+ return destination;
110
112
}
111
113
112
114
encryption_context_t *aes_clone_cryptographic_context (encryption_context_t *source) {
0 commit comments