-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced plugins for crypto and isal implementation.
Added submodule for isa-l_crypto Fixed problem with uninitialised var. Enable to use crypto plugin if available. Now isal crypto plugin compiles only on intel. Signed-off-by: Adam Kupczyk <[email protected]>
- Loading branch information
Adam Kupczyk
committed
Apr 5, 2017
1 parent
a1d1905
commit dbbf052
Showing
12 changed files
with
321 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule isa-l_crypto
added at
7a7bac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
set(isal_dir ${CMAKE_SOURCE_DIR}/src/isa-l_crypto) | ||
|
||
set(isal_crypto_plugin_srcs | ||
isal_crypto_accel.cc | ||
isal_crypto_plugin.cc | ||
${isal_dir}/aes/cbc_pre.c | ||
${isal_dir}/aes/cbc_multibinary.asm | ||
${isal_dir}/aes/keyexp_128.asm | ||
${isal_dir}/aes/keyexp_192.asm | ||
${isal_dir}/aes/keyexp_256.asm | ||
${isal_dir}/aes/keyexp_multibinary.asm | ||
${isal_dir}/aes/cbc_dec_128_x4_sse.asm | ||
${isal_dir}/aes/cbc_dec_128_x8_avx.asm | ||
${isal_dir}/aes/cbc_dec_192_x4_sse.asm | ||
${isal_dir}/aes/cbc_dec_192_x8_avx.asm | ||
${isal_dir}/aes/cbc_dec_256_x4_sse.asm | ||
${isal_dir}/aes/cbc_dec_256_x8_avx.asm | ||
${isal_dir}/aes/cbc_enc_128_x4_sb.asm | ||
${isal_dir}/aes/cbc_enc_128_x8_sb.asm | ||
${isal_dir}/aes/cbc_enc_192_x4_sb.asm | ||
${isal_dir}/aes/cbc_enc_192_x8_sb.asm | ||
${isal_dir}/aes/cbc_enc_256_x4_sb.asm | ||
${isal_dir}/aes/cbc_enc_256_x8_sb.asm) | ||
|
||
add_library(isal_crypto_plugin_objs OBJECT ${isal_crypto_plugin_srcs}) | ||
target_include_directories(isal_crypto_plugin_objs PRIVATE ${isal_dir}/include) | ||
set(isal_crypto_plugin_dir ${CMAKE_INSTALL_PKGLIBDIR}/crypto) | ||
|
||
add_custom_target(crypto_plugins) | ||
if(HAVE_GOOD_YASM_ELF64) | ||
add_dependencies(crypto_plugins ceph_crypto_isal) | ||
endif(HAVE_GOOD_YASM_ELF64) | ||
|
||
add_library(ceph_crypto_isal SHARED ${isal_crypto_plugin_srcs}) | ||
target_include_directories(ceph_crypto_isal PRIVATE ${isal_dir}/include) | ||
add_dependencies(ceph_crypto_isal ${CMAKE_SOURCE_DIR}/src/ceph_ver.h) | ||
set_target_properties(ceph_crypto_isal PROPERTIES VERSION 1.0.0 SOVERSION 1) | ||
install(TARGETS ceph_crypto_isal DESTINATION ${isal_crypto_plugin_dir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2016 Mirantis, Inc. | ||
* | ||
* Author: Adam Kupczyk <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
*/ | ||
|
||
#ifndef CRYPTO_ACCEL_H | ||
#define CRYPTO_ACCEL_H | ||
#include <cstddef> | ||
#include "include/Context.h" | ||
|
||
class CryptoAccel; | ||
typedef ceph::shared_ptr<CryptoAccel> CryptoAccelRef; | ||
|
||
class CryptoAccel { | ||
public: | ||
CryptoAccel() {} | ||
virtual ~CryptoAccel() {} | ||
|
||
static const int AES_256_IVSIZE = 128/8; | ||
static const int AES_256_KEYSIZE = 256/8; | ||
virtual bool cbc_encrypt(unsigned char* out, const unsigned char* in, size_t size, | ||
const unsigned char (&iv)[AES_256_IVSIZE], | ||
const unsigned char (&key)[AES_256_KEYSIZE]) = 0; | ||
virtual bool cbc_decrypt(unsigned char* out, const unsigned char* in, size_t size, | ||
const unsigned char (&iv)[AES_256_IVSIZE], | ||
const unsigned char (&key)[AES_256_KEYSIZE]) = 0; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2016 Mirantis, Inc. | ||
* | ||
* Author: Adam Kupczyk <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
*/ | ||
|
||
#ifndef CRYPTO_PLUGIN_H | ||
#define CRYPTO_PLUGIN_H | ||
|
||
// ----------------------------------------------------------------------------- | ||
#include "include/memory.h" | ||
#include "common/PluginRegistry.h" | ||
#include "ostream" | ||
|
||
#include "../isa-l_crypto_plugin/crypto_accel.h" | ||
// ----------------------------------------------------------------------------- | ||
|
||
class CryptoPlugin : public Plugin { | ||
|
||
public: | ||
explicit CryptoPlugin(CephContext* cct) : Plugin(cct) | ||
{} | ||
~CryptoPlugin() | ||
{} | ||
virtual int factory(CryptoAccelRef *cs, | ||
std::ostream *ss) = 0; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2016 Mirantis, Inc. | ||
* | ||
* Author: Adam Kupczyk <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
*/ | ||
|
||
#include "../isa-l_crypto_plugin/isal_crypto_accel.h" | ||
|
||
#include <isa-l_crypto/include/aes_cbc.h> | ||
|
||
bool ISALCryptoAccel::cbc_encrypt(unsigned char* out, const unsigned char* in, size_t size, | ||
const unsigned char (&iv)[AES_256_IVSIZE], | ||
const unsigned char (&key)[AES_256_KEYSIZE]) | ||
{ | ||
if ((size % AES_256_IVSIZE) != 0) { | ||
return false; | ||
} | ||
struct cbc_key_data *keys_blk = (struct cbc_key_data*) memalign(16, sizeof(struct cbc_key_data)); | ||
aes_cbc_precomp(const_cast<unsigned char*>(&key[0]), AES_256_KEYSIZE, keys_blk); | ||
aes_cbc_enc_256(const_cast<unsigned char*>(in), | ||
const_cast<unsigned char*>(&iv[0]), keys_blk->enc_keys, out, size); | ||
free(keys_blk); | ||
return true; | ||
} | ||
bool ISALCryptoAccel::cbc_decrypt(unsigned char* out, const unsigned char* in, size_t size, | ||
const unsigned char (&iv)[AES_256_IVSIZE], | ||
const unsigned char (&key)[AES_256_KEYSIZE]) | ||
{ | ||
if ((size % AES_256_IVSIZE) != 0) { | ||
return false; | ||
} | ||
struct cbc_key_data *keys_blk = (struct cbc_key_data*) memalign(16, sizeof(struct cbc_key_data)); | ||
aes_cbc_precomp(const_cast<unsigned char*>(&key[0]), AES_256_KEYSIZE, keys_blk); | ||
aes_cbc_dec_256(const_cast<unsigned char*>(in), const_cast<unsigned char*>(&iv[0]), keys_blk->dec_keys, out, size); | ||
free(keys_blk); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2016 Mirantis, Inc. | ||
* | ||
* Author: Adam Kupczyk <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
*/ | ||
|
||
#ifndef ISAL_CRYPTO_ACCEL_H | ||
#define ISAL_CRYPTO_ACCEL_H | ||
#include "../isa-l_crypto_plugin/crypto_accel.h" | ||
|
||
|
||
class ISALCryptoAccel : public CryptoAccel { | ||
public: | ||
ISALCryptoAccel() {} | ||
virtual ~ISALCryptoAccel() {} | ||
|
||
bool cbc_encrypt(unsigned char* out, const unsigned char* in, size_t size, | ||
const unsigned char (&iv)[AES_256_IVSIZE], | ||
const unsigned char (&key)[AES_256_KEYSIZE]) override; | ||
bool cbc_decrypt(unsigned char* out, const unsigned char* in, size_t size, | ||
const unsigned char (&iv)[AES_256_IVSIZE], | ||
const unsigned char (&key)[AES_256_KEYSIZE]) override; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2016 Mirantis, Inc. | ||
* | ||
* Author: Adam Kupczyk <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
*/ | ||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
#include "../isa-l_crypto_plugin/isal_crypto_plugin.h" | ||
|
||
#include "ceph_ver.h" | ||
// ----------------------------------------------------------------------------- | ||
|
||
const char *__ceph_plugin_version() | ||
{ | ||
return CEPH_GIT_NICE_VER; | ||
} | ||
|
||
int __ceph_plugin_init(CephContext *cct, | ||
const std::string& type, | ||
const std::string& name) | ||
{ | ||
PluginRegistry *instance = cct->get_plugin_registry(); | ||
|
||
return instance->add(type, name, new ISALCryptoPlugin(cct)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Ceph - scalable distributed file system | ||
* | ||
* Copyright (C) 2016 Mirantis, Inc. | ||
* | ||
* Author: Adam Kupczyk <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
*/ | ||
|
||
#ifndef ISAL_CRYPTO_PLUGIN_H | ||
#define ISAL_CRYPTO_PLUGIN_H | ||
// ----------------------------------------------------------------------------- | ||
#include "../isa-l_crypto_plugin/crypto_plugin.h" | ||
#include "../isa-l_crypto_plugin/isal_crypto_accel.h" | ||
// ----------------------------------------------------------------------------- | ||
|
||
|
||
class ISALCryptoPlugin : public CryptoPlugin { | ||
|
||
CryptoAccelRef cryptoaccel; | ||
public: | ||
|
||
explicit ISALCryptoPlugin(CephContext* cct) : CryptoPlugin(cct) | ||
{} | ||
~ISALCryptoPlugin() | ||
{} | ||
virtual int factory(CryptoAccelRef *cs, | ||
ostream *ss) | ||
{ | ||
if (cryptoaccel == nullptr) | ||
{ | ||
cryptoaccel = CryptoAccelRef(new ISALCryptoAccel); | ||
} | ||
*cs = cryptoaccel; | ||
return 0; | ||
} | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.