RSA/AES algorithm
Refs: #2799, #2800
Change-Id: I6aeb1ea2d7b3431d4569fb5b2cc3ce214ee6fca3
diff --git a/src/algo/aes.cpp b/src/algo/aes.cpp
new file mode 100644
index 0000000..07cb788
--- /dev/null
+++ b/src/algo/aes.cpp
@@ -0,0 +1,111 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include "aes.hpp"
+
+namespace ndn {
+namespace gep {
+namespace algo {
+
+using namespace CryptoPP;
+
+Buffer
+crypt(CipherModeBase* cipher, const Buffer& data);
+
+DecryptKey<Aes>
+Aes::generateKey(RandomNumberGenerator& rng, AesKeyParams& params)
+{
+ SecByteBlock key(0x00, params.getKeySize() >> 3); // Converting key bit-size to byte-size.
+ rng.GenerateBlock(key.data(), key.size());
+
+ DecryptKey<Aes> decryptKey(std::move(Buffer(key.data(), key.size())));
+ return decryptKey;
+}
+
+EncryptKey<Aes>
+Aes::deriveEncryptKey(const Buffer& keyBits)
+{
+ Buffer copy = keyBits;
+ EncryptKey<Aes> encryptKey(std::move(copy));
+ return encryptKey;
+}
+
+Buffer
+Aes::decrypt(const Buffer& keyBits, const Buffer& encryptedData, const EncryptParams& params)
+{
+ switch (params.getEncryptMode()) {
+ case ENCRYPT_MODE_ECB_AES:
+ {
+ ECB_Mode<AES>::Decryption ecbDecryption(keyBits.get(), keyBits.size());
+ return crypt(&ecbDecryption, encryptedData);
+ }
+
+ case ENCRYPT_MODE_CBC_AES:
+ {
+ Buffer initVector = params.getIV();
+ if (initVector.size() != static_cast<size_t>(AES::BLOCKSIZE))
+ throw Error("incorrect initial vector size");
+
+ CBC_Mode<AES>::Decryption cbcDecryption(keyBits.get(), keyBits.size(), initVector.get());
+ return crypt(&cbcDecryption, encryptedData);
+ }
+
+ default:
+ throw Error("unsupported encryption mode");
+ }
+}
+
+Buffer
+Aes::encrypt(const Buffer& keyBits, const Buffer& plainData, const EncryptParams& params)
+{
+ switch (params.getEncryptMode()) {
+ case ENCRYPT_MODE_ECB_AES:
+ {
+ ECB_Mode<AES>::Encryption ecbEncryption(keyBits.get(), keyBits.size());
+ return crypt(&ecbEncryption, plainData);
+ }
+
+ case ENCRYPT_MODE_CBC_AES:
+ {
+ Buffer initVector = params.getIV();
+ if (initVector.size() != static_cast<size_t>(AES::BLOCKSIZE))
+ throw Error("incorrect initial vector size");
+
+ CBC_Mode<AES>::Encryption cbcEncryption(keyBits.get(), keyBits.size(), initVector.get());
+ return crypt(&cbcEncryption, plainData);
+ }
+
+ default:
+ throw Error("unsupported encryption mode");
+ }
+}
+
+Buffer
+crypt(CipherModeBase* cipher, const Buffer& data)
+{
+ OBufferStream obuf;
+ StringSource pipe(data.get(), data.size(), true,
+ new StreamTransformationFilter(*cipher, new FileSink(obuf)));
+ return *(obuf.buf());
+}
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
diff --git a/src/algo/aes.hpp b/src/algo/aes.hpp
new file mode 100644
index 0000000..931b28d
--- /dev/null
+++ b/src/algo/aes.hpp
@@ -0,0 +1,56 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_ALGO_AES_HPP
+#define NDN_GEP_ALGO_AES_HPP
+
+#include <ndn-cxx/security/key-params.hpp>
+#include "random-number-generator.hpp"
+#include "algo/encrypt-params.hpp"
+#include "decrypt-key.hpp"
+#include "error.hpp"
+
+namespace ndn {
+namespace gep {
+namespace algo {
+
+class Aes
+{
+public:
+ static DecryptKey<Aes>
+ generateKey(RandomNumberGenerator& rng, AesKeyParams& params);
+
+ static EncryptKey<Aes>
+ deriveEncryptKey(const Buffer& keyBits);
+
+ static Buffer
+ decrypt(const Buffer& keyBits, const Buffer& encryptedData, const EncryptParams& params);
+
+ static Buffer
+ encrypt(const Buffer& keyBits, const Buffer& plainData, const EncryptParams& params);
+};
+
+typedef DecryptKey<Aes> AesEncryptKey;
+typedef EncryptKey<Aes> AesDecryptKey;
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_ALGO_AES_ECB_HPP
diff --git a/src/algo/encrypt-params.cpp b/src/algo/encrypt-params.cpp
new file mode 100644
index 0000000..296cb22
--- /dev/null
+++ b/src/algo/encrypt-params.cpp
@@ -0,0 +1,76 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "random-number-generator.hpp"
+#include "encrypt-params.hpp"
+
+namespace ndn {
+namespace gep {
+namespace algo {
+
+EncryptParams::EncryptParams(EncryptionMode encryptMode, PaddingScheme paddingScheme, uint8_t ivLength = 0)
+ : m_encryptMode(encryptMode)
+ , m_paddingScheme(paddingScheme)
+{
+ if (ivLength != 0){
+ RandomNumberGenerator rng;
+ m_iv.resize(ivLength);
+ rng.GenerateBlock(m_iv.buf(), m_iv.size());
+ }
+}
+
+void
+EncryptParams::setIV(const Buffer& iv)
+{
+ m_iv = iv;
+}
+
+void
+EncryptParams::setEncryptMode(const EncryptionMode& encryptMode)
+{
+ m_encryptMode = encryptMode;
+}
+
+void
+EncryptParams::setPaddingScheme(const PaddingScheme& paddingScheme)
+{
+ m_paddingScheme = paddingScheme;
+}
+
+Buffer
+EncryptParams::getIV() const
+{
+ return m_iv;
+}
+
+EncryptionMode
+EncryptParams::getEncryptMode() const
+{
+ return m_encryptMode;
+}
+
+PaddingScheme
+EncryptParams::getPaddingScheme() const
+{
+ return m_paddingScheme;
+}
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
\ No newline at end of file
diff --git a/src/algo/encrypt-params.hpp b/src/algo/encrypt-params.hpp
new file mode 100644
index 0000000..2be5d99
--- /dev/null
+++ b/src/algo/encrypt-params.hpp
@@ -0,0 +1,61 @@
+#ifndef NDN_GEP_ENCRYPT_PARAMS_HPP
+#define NDN_GEP_ENCRYPT_PARAMS_HPP
+
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+
+namespace ndn {
+namespace gep {
+
+enum EncryptionMode {
+ ENCRYPT_MODE_ECB_AES,
+ ENCRYPT_MODE_CBC_AES,
+ ENCRYPT_MODE_RSA
+};
+
+enum PaddingScheme {
+ PADDING_SCHEME_PKCS7,
+ PADDING_SCHEME_PKCS1v15,
+ PADDING_SCHEME_OAEP_SHA
+};
+
+namespace algo {
+
+class EncryptParams
+{
+public:
+ EncryptParams(EncryptionMode encryptMode, PaddingScheme paddingScheme, uint8_t ivLength);
+
+ virtual
+ ~EncryptParams()
+ {
+ }
+
+ void
+ setIV(const Buffer& iv);
+
+ void
+ setEncryptMode(const EncryptionMode& encryptMode);
+
+ void
+ setPaddingScheme(const PaddingScheme& paddingScheme);
+
+ Buffer
+ getIV() const;
+
+ EncryptionMode
+ getEncryptMode() const;
+
+ PaddingScheme
+ getPaddingScheme() const;
+
+private:
+ EncryptionMode m_encryptMode;
+ PaddingScheme m_paddingScheme;
+ Buffer m_iv;
+};
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_ENCRYPT_PARAMS_HPP
diff --git a/src/algo/error.hpp b/src/algo/error.hpp
new file mode 100644
index 0000000..4cb46b1
--- /dev/null
+++ b/src/algo/error.hpp
@@ -0,0 +1,43 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_ALGO_ERROR_HPP
+#define NDN_GEP_ALGO_ERROR_HPP
+
+#include <stdexcept>
+
+namespace ndn {
+namespace gep {
+namespace algo {
+
+class Error : public std::runtime_error
+{
+public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
+};
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_ALGO_ERROR_HPP
diff --git a/src/algo/rsa.cpp b/src/algo/rsa.cpp
new file mode 100644
index 0000000..66361fb
--- /dev/null
+++ b/src/algo/rsa.cpp
@@ -0,0 +1,135 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include "rsa.hpp"
+
+namespace ndn {
+namespace gep {
+namespace algo {
+
+using namespace CryptoPP;
+
+Buffer
+crypt(SimpleProxyFilter* filter, const Buffer& data);
+
+DecryptKey<Rsa>
+Rsa::generateKey(RandomNumberGenerator& rng, RsaKeyParams& params)
+{
+ RSA::PrivateKey privateKey;
+ privateKey.GenerateRandomWithKeySize(rng, params.getKeySize());
+
+ OBufferStream obuf;
+ privateKey.Save(FileSink(obuf).Ref());
+
+ DecryptKey<Rsa> decryptKey(std::move(*obuf.buf()));
+ return decryptKey;
+}
+
+EncryptKey<Rsa>
+Rsa::deriveEncryptKey(const Buffer& keyBits)
+{
+ RSA::PrivateKey privateKey;
+
+ ByteQueue keyQueue;
+ keyQueue.LazyPut(keyBits.get(), keyBits.size());
+ privateKey.Load(keyQueue);
+
+ RSA::PublicKey publicKey(privateKey);
+
+ OBufferStream obuf;
+ publicKey.Save(FileSink(obuf).Ref());
+
+ EncryptKey<Rsa> encryptKey(std::move(*obuf.buf()));
+ return encryptKey;
+}
+
+Buffer
+Rsa::decrypt(const Buffer& keyBits, const Buffer& encryptedData, const EncryptParams& params)
+{
+ AutoSeededRandomPool rng;
+ RSA::PrivateKey privateKey;
+
+ ByteQueue keyQueue;
+ keyQueue.LazyPut(keyBits.data(), keyBits.size());
+ privateKey.Load(keyQueue);
+
+ switch (params.getPaddingScheme()) {
+ case PADDING_SCHEME_PKCS1v15:
+ {
+ RSAES_PKCS1v15_Decryptor decryptor_pkcs1v15(privateKey);
+ PK_DecryptorFilter* filter_pkcs1v15 = new PK_DecryptorFilter(rng, decryptor_pkcs1v15);
+ return crypt(filter_pkcs1v15, encryptedData);
+ }
+
+ case PADDING_SCHEME_OAEP_SHA:
+ {
+ RSAES_OAEP_SHA_Decryptor decryptor_oaep_sha(privateKey);
+ PK_DecryptorFilter* filter_oaep_sha = new PK_DecryptorFilter(rng, decryptor_oaep_sha);
+ return crypt(filter_oaep_sha, encryptedData);
+ }
+
+ default:
+ throw Error("unsupported padding scheme");
+ }
+}
+
+Buffer
+Rsa::encrypt(const Buffer& keyBits, const Buffer& plainData, const EncryptParams& params)
+{
+ AutoSeededRandomPool rng;
+ RSA::PublicKey publicKey;
+
+ ByteQueue keyQueue;
+ keyQueue.LazyPut(keyBits.data(), keyBits.size());
+ publicKey.Load(keyQueue);
+
+ switch (params.getPaddingScheme()) {
+ case PADDING_SCHEME_PKCS1v15:
+ {
+ RSAES_PKCS1v15_Encryptor encryptor_pkcs1v15(publicKey);
+ PK_EncryptorFilter* filter_pkcs1v15 = new PK_EncryptorFilter(rng, encryptor_pkcs1v15);
+ return crypt(filter_pkcs1v15, plainData);
+ }
+
+ case PADDING_SCHEME_OAEP_SHA:
+ {
+ RSAES_OAEP_SHA_Encryptor encryptor_oaep_sha(publicKey);
+ PK_EncryptorFilter* filter_oaep_sha = new PK_EncryptorFilter(rng, encryptor_oaep_sha);
+ return crypt(filter_oaep_sha, plainData);
+ }
+
+ default:
+ throw Error("unsupported padding scheme");
+ }
+}
+
+Buffer
+crypt(SimpleProxyFilter* filter, const Buffer& data)
+{
+ OBufferStream obuf;
+ filter->Attach(new FileSink(obuf));
+
+ StringSource pipe(data.get(), data.size(), true, filter);
+ return *(obuf.buf());
+}
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
diff --git a/src/algo/rsa.hpp b/src/algo/rsa.hpp
new file mode 100644
index 0000000..7d4567b
--- /dev/null
+++ b/src/algo/rsa.hpp
@@ -0,0 +1,57 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * gep is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_ALGO_RSA_HPP
+#define NDN_GEP_ALGO_RSA_HPP
+
+#include <ndn-cxx/security/key-params.hpp>
+
+#include "random-number-generator.hpp"
+#include "algo/encrypt-params.hpp"
+#include "decrypt-key.hpp"
+#include "error.hpp"
+
+namespace ndn {
+namespace gep {
+namespace algo {
+
+class Rsa
+{
+public:
+ static DecryptKey<Rsa>
+ generateKey(RandomNumberGenerator& rng, RsaKeyParams& params);
+
+ static EncryptKey<Rsa>
+ deriveEncryptKey(const Buffer& keyBits);
+
+ static Buffer
+ decrypt(const Buffer& keyBits, const Buffer& encryptedData, const EncryptParams& params);
+
+ static Buffer
+ encrypt(const Buffer& keyBits, const Buffer& plainData, const EncryptParams& params);
+};
+
+typedef DecryptKey<Rsa> RsaPrivateKey;
+typedef EncryptKey<Rsa> RsaPublicKey;
+
+} // namespace algo
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_ALGO_RSA_HPP
diff --git a/src/cryptopp.hpp b/src/cryptopp.hpp
new file mode 100644
index 0000000..a7a1ae8
--- /dev/null
+++ b/src/cryptopp.hpp
@@ -0,0 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_CRYPTOPP_HPP
+#define NDN_GEP_CRYPTOPP_HPP
+
+// suppress CryptoPP warnings
+#pragma GCC system_header
+#pragma clang system_header
+
+#include <cryptopp/asn.h>
+#include <cryptopp/base64.h>
+#include <cryptopp/des.h>
+#include <cryptopp/files.h>
+#include <cryptopp/filters.h>
+#include <cryptopp/hex.h>
+#include <cryptopp/modes.h>
+#include <cryptopp/osrng.h>
+#include <cryptopp/pssr.h>
+#include <cryptopp/pwdbased.h>
+#include <cryptopp/rsa.h>
+#include <cryptopp/sha.h>
+#include <cryptopp/eccrypto.h>
+#include <cryptopp/oids.h>
+#include <cryptopp/dsa.h>
+#include <cryptopp/cryptlib.h>
+
+#endif // NDN_GEP_CRYPTOPP_HPP
diff --git a/src/decrypt-key.hpp b/src/decrypt-key.hpp
new file mode 100644
index 0000000..fdccea7
--- /dev/null
+++ b/src/decrypt-key.hpp
@@ -0,0 +1,62 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_DECRYPT_KEY_HPP
+#define NDN_GEP_DECRYPT_KEY_HPP
+
+#include "encrypt-key.hpp"
+
+namespace ndn {
+namespace gep {
+
+template<class Algorithm>
+class DecryptKey
+{
+public:
+ DecryptKey(Buffer&& keyBits)
+ : m_keyBits(keyBits)
+ {
+ }
+
+ EncryptKey<Algorithm>
+ deriveEncryptKey()
+ {
+ return Algorithm::deriveEncryptKey(m_keyBits);
+ }
+
+ Buffer
+ decrypt(const Buffer& encryptedData)
+ {
+ return Algorithm::decrypt(m_keyBits, encryptedData);
+ }
+
+ const Buffer&
+ getKeyBits()
+ {
+ return m_keyBits;
+ }
+
+private:
+ Buffer m_keyBits;
+};
+
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_DECRYPT_KEY_HPP
diff --git a/src/encrypt-key.hpp b/src/encrypt-key.hpp
new file mode 100644
index 0000000..ba0d778
--- /dev/null
+++ b/src/encrypt-key.hpp
@@ -0,0 +1,56 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_ENCRYPT_KEY_HPP
+#define NDN_GEP_ENCRYPT_KEY_HPP
+
+#include "common.hpp"
+
+namespace ndn {
+namespace gep {
+
+template<class Algorithm>
+class EncryptKey
+{
+public:
+ EncryptKey(Buffer&& keyBits)
+ : m_keyBits(keyBits)
+ {
+ }
+
+ Buffer
+ encrypt(const Buffer& plainData)
+ {
+ return Algorithm::encrypt(m_keyBits, plainData);
+ }
+
+ const Buffer&
+ getKeyBits() const
+ {
+ return m_keyBits;
+ }
+
+private:
+ Buffer m_keyBits;
+};
+
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_ENCRYPT_KEY_HPP
diff --git a/src/random-number-generator.hpp b/src/random-number-generator.hpp
new file mode 100644
index 0000000..0d74f47
--- /dev/null
+++ b/src/random-number-generator.hpp
@@ -0,0 +1,33 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NDN_GEP_RANDOM_NUMBER_GENERATOR_HPP
+#define NDN_GEP_RANDOM_NUMBER_GENERATOR_HPP
+
+#include "cryptopp.hpp"
+
+namespace ndn {
+namespace gep {
+
+typedef CryptoPP::AutoSeededRandomPool RandomNumberGenerator;
+
+} // namespace gep
+} // namespace ndn
+
+#endif // NDN_GEP_RANDOM_NUMBER_GENERATOR_HPP