Merge pull request #9 from BrownBear2/phoenix
added romix kdf and cfb for aes
This commit is contained in:
commit
71759891f1
3 changed files with 50 additions and 0 deletions
|
|
@ -132,6 +132,7 @@ set( fc_sources
|
|||
src/crypto/elliptic.cpp
|
||||
src/crypto/salsa20.cpp
|
||||
src/crypto/scrypt.cpp
|
||||
src/crypto/romix.cpp
|
||||
src/network/tcp_socket.cpp
|
||||
src/network/udp_socket.cpp
|
||||
src/network/http/http_connection.cpp
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ namespace fc {
|
|||
unsigned char *iv, unsigned char *ciphertext);
|
||||
int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
|
||||
unsigned char *iv, unsigned char *plaintext);
|
||||
int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
|
||||
unsigned char *iv, unsigned char *plaintext);
|
||||
|
||||
std::vector<char> aes_encrypt( const fc::sha512& key, const std::vector<char>& plain_text );
|
||||
std::vector<char> aes_decrypt( const fc::sha512& key, const std::vector<char>& cipher_text );
|
||||
|
|
|
|||
|
|
@ -248,7 +248,54 @@ int aes_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *ke
|
|||
return plaintext_len;
|
||||
}
|
||||
|
||||
int aes_cfb_decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
|
||||
unsigned char *iv, unsigned char *plaintext)
|
||||
{
|
||||
evp_cipher_ctx ctx( EVP_CIPHER_CTX_new() );
|
||||
int len = 0;
|
||||
int plaintext_len = 0;
|
||||
|
||||
/* Create and initialise the context */
|
||||
if(!ctx)
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error allocating evp cipher context",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
/* Initialise the decryption operation. IMPORTANT - ensure you use a key
|
||||
* * and IV size appropriate for your cipher
|
||||
* * In this example we are using 256 bit AES (i.e. a 256 bit key). The
|
||||
* * IV size for *most* modes is the same as the block size. For AES this
|
||||
* * is 128 bits */
|
||||
if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cfb128(), NULL, key, iv))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt init",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
/* Provide the message to be decrypted, and obtain the plaintext output.
|
||||
* * EVP_DecryptUpdate can be called multiple times if necessary
|
||||
* */
|
||||
if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt update",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
|
||||
plaintext_len = len;
|
||||
|
||||
/* Finalise the decryption. Further plaintext bytes may be written at
|
||||
* * this stage.
|
||||
* */
|
||||
if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len))
|
||||
{
|
||||
FC_THROW_EXCEPTION( exception, "error durring aes 256 cbc decrypt final",
|
||||
("s", ERR_error_string( ERR_get_error(), nullptr) ) );
|
||||
}
|
||||
plaintext_len += len;
|
||||
|
||||
return plaintext_len;
|
||||
}
|
||||
|
||||
std::vector<char> aes_encrypt( const fc::sha512& key, const std::vector<char>& plain_text )
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue