Line 0
Link Here
|
|
|
1 |
--- liboriutil/oricrypt.cc.orig 2018-10-13 04:42:24 UTC |
2 |
+++ liboriutil/oricrypt.cc |
3 |
@@ -155,12 +155,12 @@ OriCrypt_Encrypt(const string &plaintext, const string |
4 |
unsigned char keyData[32]; |
5 |
unsigned char ivData[32]; |
6 |
unsigned char *buf; |
7 |
- EVP_CIPHER_CTX ctx; |
8 |
+ EVP_CIPHER_CTX *ctx = NULL; |
9 |
string ciphertext; |
10 |
|
11 |
// Generate random salt and prepend it |
12 |
// XXX: PKCS#5 implementation in OpenSSL uses RAND_pseudo_bytes |
13 |
- RAND_pseudo_bytes(salt, PKCS5_SALT_LEN); |
14 |
+ RAND_bytes(salt, PKCS5_SALT_LEN); |
15 |
ciphertext.assign((const char *)&salt, PKCS5_SALT_LEN); |
16 |
|
17 |
bits = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha256(), salt, |
18 |
@@ -173,13 +173,13 @@ OriCrypt_Encrypt(const string &plaintext, const string |
19 |
clen = plaintext.size() + AES_BLOCK_SIZE; |
20 |
buf = new unsigned char[clen]; |
21 |
|
22 |
- EVP_CIPHER_CTX_init(&ctx); |
23 |
- EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, keyData, ivData); |
24 |
- EVP_EncryptUpdate(&ctx, buf, &clen, |
25 |
+ EVP_CIPHER_CTX_init(ctx); |
26 |
+ EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, keyData, ivData); |
27 |
+ EVP_EncryptUpdate(ctx, buf, &clen, |
28 |
(const unsigned char *)plaintext.data(), |
29 |
plaintext.size()); |
30 |
- EVP_EncryptFinal_ex(&ctx, buf+clen, &flen); |
31 |
- EVP_CIPHER_CTX_cleanup(&ctx); |
32 |
+ EVP_EncryptFinal_ex(ctx, buf+clen, &flen); |
33 |
+ EVP_CIPHER_CTX_free(ctx); |
34 |
|
35 |
ciphertext.append((const char *)buf, clen+flen); |
36 |
delete buf; |
37 |
@@ -199,7 +199,7 @@ OriCrypt_Decrypt(const string &ciphertext, const strin |
38 |
unsigned char keyData[32]; |
39 |
unsigned char ivData[32]; |
40 |
unsigned char *buf; |
41 |
- EVP_CIPHER_CTX ctx; |
42 |
+ EVP_CIPHER_CTX *ctx = NULL; |
43 |
string plaintext; |
44 |
|
45 |
if (ciphertext.size() <= PKCS5_SALT_LEN) |
46 |
@@ -217,13 +217,13 @@ OriCrypt_Decrypt(const string &ciphertext, const strin |
47 |
plen = ciphertext.size() + AES_BLOCK_SIZE; |
48 |
buf = new unsigned char[plen]; |
49 |
|
50 |
- EVP_CIPHER_CTX_init(&ctx); |
51 |
- EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, keyData, ivData); |
52 |
- EVP_DecryptUpdate(&ctx, buf, &plen, |
53 |
+ EVP_CIPHER_CTX_init(ctx); |
54 |
+ EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, keyData, ivData); |
55 |
+ EVP_DecryptUpdate(ctx, buf, &plen, |
56 |
(const unsigned char *)ciphertext.data() + PKCS5_SALT_LEN, |
57 |
ciphertext.size() - PKCS5_SALT_LEN); |
58 |
- EVP_DecryptFinal_ex(&ctx, buf+plen, &flen); |
59 |
- EVP_CIPHER_CTX_cleanup(&ctx); |
60 |
+ EVP_DecryptFinal_ex(ctx, buf+plen, &flen); |
61 |
+ EVP_CIPHER_CTX_free(ctx); |
62 |
|
63 |
plaintext.assign((const char *)buf, plen+flen); |
64 |
delete buf; |