static CryptoNone crypto_none;
static CryptoAES crypto_aes;
-CryptoHandler *CryptoManager::get_crypto(int type)
+CryptoHandler *get_crypto_handler(int type)
{
switch (type) {
case CEPH_CRYPTO_NONE:
}
}
-CryptoManager ceph_crypto_mgr;
-
-
// ---------------------------------------------------
int CryptoKey::set_secret(int type, bufferptr& s)
this->type = type;
created = g_clock.now();
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(type);
+ CryptoHandler *h = get_crypto_handler(type);
if (!h)
return -EOPNOTSUPP;
int ret = h->validate_secret(s);
type = t;
created = g_clock.now();
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(type);
+ CryptoHandler *h = get_crypto_handler(type);
if (!h)
return -EOPNOTSUPP;
return h->create(secret);
int CryptoKey::encrypt(const bufferlist& in, bufferlist& out) const
{
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(type);
+ CryptoHandler *h = get_crypto_handler(type);
if (!h)
return -EOPNOTSUPP;
return h->encrypt(this->secret, in, out);
int CryptoKey::decrypt(const bufferlist& in, bufferlist& out) const
{
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(type);
+ CryptoHandler *h = get_crypto_handler(type);
if (!h)
return -EOPNOTSUPP;
return h->decrypt(this->secret, in, out);
::testing::Environment* const crypto_env = ::testing::AddGlobalTestEnvironment(new CryptoEnvironment);
TEST(AES, ValidateSecret) {
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(CEPH_CRYPTO_AES);
+ CryptoHandler *h = get_crypto_handler(CEPH_CRYPTO_AES);
int l;
for (l=0; l<16; l++) {
}
TEST(AES, Encrypt) {
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(CEPH_CRYPTO_AES);
+ CryptoHandler *h = get_crypto_handler(CEPH_CRYPTO_AES);
char secret_s[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
}
TEST(AES, Decrypt) {
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(CEPH_CRYPTO_AES);
+ CryptoHandler *h = get_crypto_handler(CEPH_CRYPTO_AES);
char secret_s[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
for (int i=0; i<10000; i++) {
bufferlist cipher;
{
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(CEPH_CRYPTO_AES);
+ CryptoHandler *h = get_crypto_handler(CEPH_CRYPTO_AES);
int success;
success = h->encrypt(secret, plaintext, cipher);
plaintext.clear();
{
- CryptoHandler *h = ceph_crypto_mgr.get_crypto(CEPH_CRYPTO_AES);
+ CryptoHandler *h = get_crypto_handler(CEPH_CRYPTO_AES);
int err;
err = h->decrypt(secret, cipher, plaintext);
ASSERT_EQ((int)sizeof(orig_plaintext_s), err);