summaryrefslogtreecommitdiff
path: root/src/lib/crypto.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-05-03 11:17:34 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-03 20:18:04 +0200
commit689fa55d1529ad88449ca464e9107c4dcc54d1cb (patch)
treeedd1264941263f2fa25a98d61f98c87876c5b667 /src/lib/crypto.cc
parent0aabe4060ea4bad7c7caac633aef0737fccff8c2 (diff)
C++11 tidying.
Diffstat (limited to 'src/lib/crypto.cc')
-rw-r--r--src/lib/crypto.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/lib/crypto.cc b/src/lib/crypto.cc
index 494924daa..777969c10 100644
--- a/src/lib/crypto.cc
+++ b/src/lib/crypto.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,8 +18,10 @@
*/
+
/* Based on code from https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption */
+
#include "crypto.h"
#include "exceptions.h"
#include <openssl/conf.h>
@@ -28,12 +30,15 @@
#include <openssl/rand.h>
#include <boost/scoped_array.hpp>
+
using std::string;
using namespace dcpomatic;
+
/** The cipher that this code uses */
#define CIPHER EVP_aes_256_cbc()
+
dcp::ArrayData
dcpomatic::random_iv ()
{
@@ -43,10 +48,11 @@ dcpomatic::random_iv ()
return iv;
}
+
dcp::ArrayData
dcpomatic::encrypt (string plaintext, dcp::ArrayData key, dcp::ArrayData iv)
{
- EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new ();
+ auto ctx = EVP_CIPHER_CTX_new ();
if (!ctx) {
throw CryptoError ("could not create cipher context");
}
@@ -78,10 +84,11 @@ dcpomatic::encrypt (string plaintext, dcp::ArrayData key, dcp::ArrayData iv)
return ciphertext;
}
+
string
dcpomatic::decrypt (dcp::ArrayData ciphertext, dcp::ArrayData key, dcp::ArrayData iv)
{
- EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new ();
+ auto ctx = EVP_CIPHER_CTX_new ();
if (!ctx) {
throw CryptoError ("could not create cipher context");
}
@@ -115,6 +122,7 @@ dcpomatic::decrypt (dcp::ArrayData ciphertext, dcp::ArrayData key, dcp::ArrayDat
return string ((char *) plaintext.data());
}
+
int
dcpomatic::crypto_key_length ()
{