|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include <openssl/evp.h>
- #include <stdint.h>
- #include <string.h>
-
- uint32_t ecb_decrypt( const unsigned char* i_stream,
- const uint32_t i_stream_size,
- const unsigned char* i_pass,
- const uint32_t i_pass_size,
- unsigned char* o_buff)
- {
- int ret, ret_fin;
- ret=ret_fin=0;
- EVP_CIPHER_CTX ctx;
-
- EVP_DecryptInit(&ctx, EVP_aes_128_ecb(), NULL, NULL);
- EVP_CIPHER_CTX_set_key_length(&ctx, i_pass_size);
- EVP_DecryptInit (&ctx, NULL, i_pass, NULL);
- EVP_DecryptUpdate(&ctx, o_buff, &ret, i_stream, i_stream_size);
- EVP_DecryptFinal (&ctx, o_buff+ret, &ret_fin);
- return ret+ret_fin;
- }
-
-
- uint32_t ecb_encrypt( const unsigned char* i_stream,
- const uint32_t i_stream_size,
- const unsigned char* i_pass,
- const uint32_t i_pass_size,
- unsigned char* o_buff)
- {
- int ret, ret_fin;
- ret=ret_fin=0;
- EVP_CIPHER_CTX ctx;
-
- EVP_DecryptInit(&ctx, EVP_aes_128_ecb(), NULL, NULL);
- EVP_CIPHER_CTX_set_key_length(&ctx, i_pass_size);
- EVP_EncryptInit (&ctx, NULL, i_pass, NULL);
- EVP_EncryptUpdate(&ctx, o_buff, &ret, i_stream, i_stream_size);
- EVP_EncryptFinal (&ctx, o_buff+ret, &ret_fin);
- return ret+ret_fin;
- }
-
- // checks if there are identical blocks in the i_textline
- int same_blocks(const char* i_textline, const int i_bs, int* first_block, int* second_block)
- {
- int chunk_nb = strlen(i_textline)/i_bs;
- for(int i=0; i<chunk_nb-1; i++)
- {
- for(int j=i+1; j<chunk_nb; j++)
- {
- if(memcmp(&i_textline[i*i_bs], &i_textline[j*i_bs],i_bs)==0)
- {
- *first_block = i+1;
- *second_block = j+1;
- return 1;
- }
- }
- }
- return 0;
- }
|