finished implementing decryption routines. Still needs fixing compilation

This commit is contained in:
csoler 2015-10-01 23:37:50 -04:00
parent 6626538cab
commit 1c12178874
5 changed files with 260 additions and 86 deletions

View file

@ -42,6 +42,36 @@
class GxsSecurity
{
public:
/*!
* \brief The MultiEncryptionContext struct
*
* This structure is used to store encryption keys generated when encrypting for multiple keys at once, so that
* the client doesn't need to know about all the libcrypto variables involved.
* Typically, the client will first ask to init a MultiEncryptionContext by providing several GXS ids,
* and then pass the structure as a parameter to encrypt some data with the same key.
*/
class MultiEncryptionContext
{
public:
MultiEncryptionContext() { ekl = NULL; ek=NULL; nk=0 ; }
~MultiEncryptionContext() { clear() ;}
void clear() ;
// The functions below give access to the encrypted symmetric key to be used.
//
int n_encrypted_keys() const ;
RsGxsId encrypted_key_id (int i) ;
unsigned char *encrypted_key_data(int i) ;
int encrypted_key_size(int i) ;
protected:
int *ekl ; // array of encrypted keys length
unsigned char **ek ; // array of encrypted keys
int nk ; // number of encrypted keys
EVP_CIPHER_CTX ctx; // EVP encryption context
unsigned char iv[EVP_MAX_IV_LENGTH]; // initialization vector of the cipher.
};
/*!
* Extracts a public key from a private key.
*/
@ -65,6 +95,16 @@ class GxsSecurity
*/
static bool encrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvSecurityKey& key) ;
/*!
* Encrypts/decrypt data using envelope encryption using the key pre-computed in the encryption context passed as
* parameter.
*/
static bool initEncryption(MultiEncryptionContext& encryption_context, const std::list<RsTlvSecurityKey> &keys) ;
static bool initDecryption(MultiEncryptionContext& encryption_context, const RsTlvSecurityKey& key, unsigned char *IV, uint32_t IV_size, unsigned char *encrypted_session_key, uint32_t encrypted_session_key_size) ;
static bool encrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, MultiEncryptionContext& encryption_context) ;
static bool decrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, MultiEncryptionContext& encryption_context) ;
/**
* Decrypts data using evelope decryption (taken from open ssl's evp_sealinit )
* only full publish key holders can decrypt data for a group