openssl c sha-128-cbc

From eeew, 10 Years ago, written in C, viewed 874 times.
URL https://paste.godclan.hu/view/mf2QASdR Embed
Download Paste or View Raw
  1. //#include <openssl/md5.h>
  2. #include <openssl/aes.h>
  3. #include <openssl/evp.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. int main(){
  8.     unsigned char* data = malloc(128);
  9.     size_t datalen = 0;
  10.     const char* password = "krumpli";
  11.     EVP_CIPHER_CTX encx;
  12.  
  13.     unsigned char plaintext[] = "kecske\n";
  14.  
  15.     //unsigned char salt[] = "nemrandom";
  16.     unsigned char salt[8];
  17.     RAND_pseudo_bytes(salt, sizeof salt);
  18.     unsigned char iv[32];
  19.     unsigned char key[32];
  20.     unsigned char* ciphertext;
  21.     int plaintext_len = strlen(plaintext), ciphertext_len = 0;
  22.  
  23.  
  24.     EVP_BytesToKey(EVP_aes_128_cbc(), EVP_md5(), salt, password, strlen(password), 1, key, iv);
  25.  
  26.     int len1, len2;
  27.     len1 = plaintext_len + AES_BLOCK_SIZE;
  28.     ciphertext = malloc(len1);
  29.  
  30.     EVP_EncryptInit_ex(&encx, EVP_aes_128_cbc(), NULL, key, iv);
  31.     EVP_EncryptUpdate(&encx, ciphertext, &len1, plaintext, plaintext_len);
  32.     EVP_EncryptFinal(&encx, ciphertext + len1, &len2);
  33.     ciphertext_len = len1 + len2;
  34.  
  35.     fwrite("Salted__", 1, 8, stdout);
  36.     fwrite(salt, 1, 8, stdout);
  37.     fwrite(ciphertext, 1, ciphertext_len, stdout);
  38.  
  39.     fputs("hurra.", stderr);
  40.     return 0;
  41. }
  42.  

Reply to "openssl c sha-128-cbc"

Here you can reply to the paste above