From e0ceb6ffd680622b0406e239cf1f638482f45aab Mon Sep 17 00:00:00 2001 From: "Le.Beta" Date: Tue, 19 Mar 2019 10:57:28 +0800 Subject: [PATCH] Add chacha12 and chacha20 code form sectun --- encrypt.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/encrypt.cpp b/encrypt.cpp index c6f8063..de56207 100755 --- a/encrypt.cpp +++ b/encrypt.cpp @@ -1,4 +1,5 @@ #include "lib/aes-common.h" +#include "lib/chacha20.h" #include "lib/md5.h" #include "lib/pbkdf2-sha1.h" #include "lib/pbkdf2-sha256.h" @@ -28,7 +29,7 @@ unsigned char cipher_key_decrypt[cipher_key_len + 100]; //key for aes etc. unordered_map auth_mode_tostring = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_simple,"simple"},{auth_hmac_sha1,"hmac_sha1"},}; -unordered_map cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cfb,"aes128cfb"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"},}; +unordered_map cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cfb,"aes128cfb"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"},{cipher_chacha12,"chacha12"},{cipher_chacha20,"chacha20"},}; //TODO aes-gcm auth_mode_t auth_mode=auth_md5; @@ -324,6 +325,20 @@ int cipher_aes128cfb_encrypt(const char *data,char *output,int &len,char * key) AES_CFB_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv); return 0; } +int cipher_chacha12_encrypt(const char *data,char *output,int &len,char * key) +{ + ChaCha12XOR((uint8_t *) key, 1, (uint8_t *) zero_iv, + (uint8_t *) data, (uint8_t *) output, len); + //AES_CBC_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv); + return 0; +} +int cipher_chacha20_encrypt(const char *data,char *output,int &len,char * key) +{ + ChaCha20XOR((uint8_t *) key, 1, (uint8_t *) zero_iv, + (uint8_t *) data, (uint8_t *) output, len); + //AES_CBC_encrypt_buffer((unsigned char *)output,(unsigned char *)buf,len,(unsigned char *)key,(unsigned char *)zero_iv); + return 0; +} int auth_crc32_verify(const char *data,int &len) { if(len