projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Extract common code out into kdm_for_screen()
[dcpomatic.git]
/
src
/
lib
/
crypto.cc
diff --git
a/src/lib/crypto.cc
b/src/lib/crypto.cc
index 69e041cb2cff83b70891240e46928e5152f31de8..c67fc27fa17f9c5de899076ac1c70f54b79f112a 100644
(file)
--- a/
src/lib/crypto.cc
+++ b/
src/lib/crypto.cc
@@
-29,30
+29,29
@@
#include <boost/scoped_array.hpp>
using std::string;
#include <boost/scoped_array.hpp>
using std::string;
-using boost::shared_array;
using namespace dcpomatic;
/** The cipher that this code uses */
#define CIPHER EVP_aes_256_cbc()
using namespace dcpomatic;
/** The cipher that this code uses */
#define CIPHER EVP_aes_256_cbc()
-shared_array<unsigned char>
+dcp::Data
dcpomatic::random_iv ()
{
EVP_CIPHER const * cipher = CIPHER;
dcpomatic::random_iv ()
{
EVP_CIPHER const * cipher = CIPHER;
-
shared_array<unsigned char> iv (new unsigned char[EVP_CIPHER_iv_length(cipher)]
);
- RAND_bytes (iv.
get(), EVP_CIPHER_iv_length(cipher
));
+
dcp::Data iv (EVP_CIPHER_iv_length(cipher)
);
+ RAND_bytes (iv.
data().get(), iv.size(
));
return iv;
}
return iv;
}
-
+
dcp::Data
dcp::Data
-dcpomatic::encrypt (string plaintext,
shared_array<unsigned char const> key, shared_array<unsigned char const>
iv)
+dcpomatic::encrypt (string plaintext,
dcp::Data key, dcp::Data
iv)
{
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new ();
if (!ctx) {
throw CryptoError ("could not create cipher context");
}
{
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new ();
if (!ctx) {
throw CryptoError ("could not create cipher context");
}
- int r = EVP_EncryptInit_ex (ctx, CIPHER, 0, key.
get(), iv
.get());
+ int r = EVP_EncryptInit_ex (ctx, CIPHER, 0, key.
data().get(), iv.data()
.get());
if (r != 1) {
throw CryptoError ("could not initialise cipher context for encryption");
}
if (r != 1) {
throw CryptoError ("could not initialise cipher context for encryption");
}
@@
-60,7
+59,7
@@
dcpomatic::encrypt (string plaintext, shared_array<unsigned char const> key, sha
dcp::Data ciphertext (plaintext.size() * 2);
int len;
dcp::Data ciphertext (plaintext.size() * 2);
int len;
- r = EVP_EncryptUpdate (ctx, ciphertext.data().get(), &len, (u
nsigned char
const *) plaintext.c_str(), plaintext.size());
+ r = EVP_EncryptUpdate (ctx, ciphertext.data().get(), &len, (u
int8_t
const *) plaintext.c_str(), plaintext.size());
if (r != 1) {
throw CryptoError ("could not encrypt data");
}
if (r != 1) {
throw CryptoError ("could not encrypt data");
}
@@
-80,14
+79,14
@@
dcpomatic::encrypt (string plaintext, shared_array<unsigned char const> key, sha
}
string
}
string
-dcpomatic::decrypt (dcp::Data ciphertext,
shared_array<unsigned char const> key, shared_array<unsigned char const>
iv)
+dcpomatic::decrypt (dcp::Data ciphertext,
dcp::Data key, dcp::Data
iv)
{
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new ();
if (!ctx) {
throw CryptoError ("could not create cipher context");
}
{
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new ();
if (!ctx) {
throw CryptoError ("could not create cipher context");
}
- int r = EVP_DecryptInit_ex (ctx, CIPHER, 0, key.
get(), iv
.get());
+ int r = EVP_DecryptInit_ex (ctx, CIPHER, 0, key.
data().get(), iv.data()
.get());
if (r != 1) {
throw CryptoError ("could not initialise cipher context for decryption");
}
if (r != 1) {
throw CryptoError ("could not initialise cipher context for decryption");
}
@@
-101,7
+100,7
@@
dcpomatic::decrypt (dcp::Data ciphertext, shared_array<unsigned char const> key,
}
int plaintext_len = len;
}
int plaintext_len = len;
-
+
r = EVP_DecryptFinal_ex (ctx, plaintext.data().get() + len, &len);
if (r != 1) {
throw CryptoError ("could not finish decryption");
r = EVP_DecryptFinal_ex (ctx, plaintext.data().get() + len, &len);
if (r != 1) {
throw CryptoError ("could not finish decryption");