chacha20
parent
af7680f76b
commit
1ad8254ecc
3
config.h
3
config.h
|
@ -16,6 +16,9 @@
|
||||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
#define HAVE_INTTYPES_H 1
|
#define HAVE_INTTYPES_H 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||||
|
#define HAVE_LIBCRYPTO 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `curl' library (-lcurl). */
|
/* Define to 1 if you have the `curl' library (-lcurl). */
|
||||||
#define HAVE_LIBCURL 1
|
#define HAVE_LIBCURL 1
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
#undef HAVE_INTTYPES_H
|
#undef HAVE_INTTYPES_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `crypto' library (-lcrypto). */
|
||||||
|
#undef HAVE_LIBCRYPTO
|
||||||
|
|
||||||
/* Define to 1 if you have the `curl' library (-lcurl). */
|
/* Define to 1 if you have the `curl' library (-lcurl). */
|
||||||
#undef HAVE_LIBCURL
|
#undef HAVE_LIBCURL
|
||||||
|
|
||||||
/* Define to 1 if you have the `gpgme' library (-lgpgme). */
|
|
||||||
#undef HAVE_LIBGPGME
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `iniparser' library (-liniparser). */
|
/* Define to 1 if you have the `iniparser' library (-liniparser). */
|
||||||
#undef HAVE_LIBINIPARSER
|
#undef HAVE_LIBINIPARSER
|
||||||
|
|
||||||
|
|
|
@ -4204,13 +4204,14 @@ _ACEOF
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lgpgme" >&5
|
#AC_CHECK_LIB([gpgme], [main])
|
||||||
$as_echo_n "checking for main in -lgpgme... " >&6; }
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lcrypto" >&5
|
||||||
if ${ac_cv_lib_gpgme_main+:} false; then :
|
$as_echo_n "checking for main in -lcrypto... " >&6; }
|
||||||
|
if ${ac_cv_lib_crypto_main+:} false; then :
|
||||||
$as_echo_n "(cached) " >&6
|
$as_echo_n "(cached) " >&6
|
||||||
else
|
else
|
||||||
ac_check_lib_save_LIBS=$LIBS
|
ac_check_lib_save_LIBS=$LIBS
|
||||||
LIBS="-lgpgme $LIBS"
|
LIBS="-lcrypto $LIBS"
|
||||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||||
/* end confdefs.h. */
|
/* end confdefs.h. */
|
||||||
|
|
||||||
|
@ -4224,22 +4225,22 @@ return main ();
|
||||||
}
|
}
|
||||||
_ACEOF
|
_ACEOF
|
||||||
if ac_fn_c_try_link "$LINENO"; then :
|
if ac_fn_c_try_link "$LINENO"; then :
|
||||||
ac_cv_lib_gpgme_main=yes
|
ac_cv_lib_crypto_main=yes
|
||||||
else
|
else
|
||||||
ac_cv_lib_gpgme_main=no
|
ac_cv_lib_crypto_main=no
|
||||||
fi
|
fi
|
||||||
rm -f core conftest.err conftest.$ac_objext \
|
rm -f core conftest.err conftest.$ac_objext \
|
||||||
conftest$ac_exeext conftest.$ac_ext
|
conftest$ac_exeext conftest.$ac_ext
|
||||||
LIBS=$ac_check_lib_save_LIBS
|
LIBS=$ac_check_lib_save_LIBS
|
||||||
fi
|
fi
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpgme_main" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_main" >&5
|
||||||
$as_echo "$ac_cv_lib_gpgme_main" >&6; }
|
$as_echo "$ac_cv_lib_crypto_main" >&6; }
|
||||||
if test "x$ac_cv_lib_gpgme_main" = xyes; then :
|
if test "x$ac_cv_lib_crypto_main" = xyes; then :
|
||||||
cat >>confdefs.h <<_ACEOF
|
cat >>confdefs.h <<_ACEOF
|
||||||
#define HAVE_LIBGPGME 1
|
#define HAVE_LIBCRYPTO 1
|
||||||
_ACEOF
|
_ACEOF
|
||||||
|
|
||||||
LIBS="-lgpgme $LIBS"
|
LIBS="-lcrypto $LIBS"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ AC_CHECK_LIB([iniparser], [main])
|
||||||
AC_CHECK_LIB([jansson], [main])
|
AC_CHECK_LIB([jansson], [main])
|
||||||
AC_CHECK_LIB([curl], [main])
|
AC_CHECK_LIB([curl], [main])
|
||||||
AC_CHECK_LIB([ssl], [main])
|
AC_CHECK_LIB([ssl], [main])
|
||||||
AC_CHECK_LIB([gpgme], [main])
|
#AC_CHECK_LIB([gpgme], [main])
|
||||||
AC_CHECK_LIB([crypto], [main])
|
AC_CHECK_LIB([crypto], [main])
|
||||||
CFLAGS="$CFLAGS -g"
|
CFLAGS="$CFLAGS -g"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
#include"AES.h"
|
#include"AES.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
unsigned char *p_str = "82019154470699086128524248488673846867876336512717";
|
||||||
|
BIGNUM *p = BN_bin2bn(p_str, sizeof(p_str), NULL);
|
||||||
|
BN_free(p);
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
AES_any_decrypt(aes_enctype enc,unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
|
AES_any_decrypt(aes_enctype enc,unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
|
||||||
unsigned char *iv, unsigned char *plaintext)
|
unsigned char *iv, unsigned char *plaintext)
|
||||||
|
@ -95,25 +103,41 @@ AES_any_encrypt(aes_enctype enc,unsigned char *plaintext, int plaintext_len, uns
|
||||||
|
|
||||||
CREATEAESALGO(AES_256_cbc, EVP_aes_256_cbc);
|
CREATEAESALGO(AES_256_cbc, EVP_aes_256_cbc);
|
||||||
CREATEAESALGO(AES_256_ecb, EVP_aes_256_ecb);
|
CREATEAESALGO(AES_256_ecb, EVP_aes_256_ecb);
|
||||||
|
CREATEAESALGO(chacha20_poly1305,EVP_chacha20_poly1305);
|
||||||
|
|
||||||
|
void generate_rand_bytes(size_t len, unsigned char * key){
|
||||||
|
srand(time(NULL));
|
||||||
|
for(unsigned int i = len-1;i--;){
|
||||||
|
key[i] = rand() % 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int count, char ** values){
|
main(int count, char ** values){
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the key and iv. Do I need to say to not hard code these in a
|
* Set up the key and iv. Do I need to say to not hard code these in a
|
||||||
* real application? :-)
|
* real application? :-)
|
||||||
*/
|
*/
|
||||||
if(count != 5){
|
if(count != 3){
|
||||||
return fprintf(stderr,"%s msg key iv ENCType(2,4,2|4[6])\n",values[0]);
|
return fprintf(stderr,"%s msg ENCType(2,4,8 (2|4[6]),(2|4|8[14]) )\n",values[0]);
|
||||||
}
|
}
|
||||||
unsigned char key[32];
|
unsigned char key[32];
|
||||||
unsigned char iv[16];
|
unsigned char iv[16];
|
||||||
memcpy(key, values[2], sizeof(key));
|
|
||||||
memcpy(iv, values[3], sizeof(iv));
|
|
||||||
|
|
||||||
unsigned int enctype = atoi(values[4]);
|
generate_rand_bytes(sizeof(key),key);
|
||||||
|
generate_rand_bytes(sizeof(iv),iv);
|
||||||
|
|
||||||
|
printf("Key is:%s\n",key);
|
||||||
|
|
||||||
|
// memcpy(key, values[2], sizeof(key));
|
||||||
|
// memcpy(iv, values[2], sizeof(iv));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int enctype = atoi(values[2]);
|
||||||
|
|
||||||
/* A 256 bit key */
|
/* A 256 bit key */
|
||||||
// unsigned char *key = (unsigned char *)"01234567890123456789012345678901";
|
// unsigned char *key = (unsigned char *)"01234567890123456789012345678901";
|
||||||
|
@ -136,47 +160,11 @@ main(int count, char ** values){
|
||||||
unsigned char decryptedtext[128];
|
unsigned char decryptedtext[128];
|
||||||
|
|
||||||
int decryptedtext_len, ciphertext_len;
|
int decryptedtext_len, ciphertext_len;
|
||||||
|
puts("Enc");
|
||||||
|
|
||||||
if( (enctype&t_cbc) == t_cbc ){
|
CHECKTYPE(cbc,AES_256_cbc);
|
||||||
puts("t_cbc");
|
CHECKTYPE(ecb,AES_256_ecb);
|
||||||
ciphertext_len = AES_256_cbc_encrypt (plaintext, strlen ((char *)plaintext), key, iv,
|
CHECKTYPE(chacha20,chacha20_poly1305);
|
||||||
ciphertext);
|
|
||||||
/* Do something useful with the ciphertext here */
|
|
||||||
printf("Ciphertext is:\n");
|
|
||||||
BIO_dump_fp (stdout, (const char *)ciphertext, ciphertext_len);
|
|
||||||
/* Decrypt the ciphertext */
|
|
||||||
decryptedtext_len = AES_256_cbc_decrypt(ciphertext, ciphertext_len, key, iv,
|
|
||||||
decryptedtext);
|
|
||||||
/* Add a NULL terminator. We are expecting printable text */
|
|
||||||
decryptedtext[decryptedtext_len] = '\0';
|
|
||||||
/* Show the decrypted text */
|
|
||||||
printf("Decrypted text is:\n");
|
|
||||||
printf("%s\n", decryptedtext);
|
|
||||||
}
|
|
||||||
if( (enctype&t_ecb) == t_ecb ){
|
|
||||||
puts("t_ecb");
|
|
||||||
ciphertext_len = AES_256_ecb_encrypt (plaintext, strlen ((char *)plaintext), key, iv,
|
|
||||||
ciphertext);
|
|
||||||
/* Do something useful with the ciphertext here */
|
|
||||||
printf("Ciphertext is:\n");
|
|
||||||
BIO_dump_fp (stdout, (const char *)ciphertext, ciphertext_len);
|
|
||||||
/* Decrypt the ciphertext */
|
|
||||||
decryptedtext_len = AES_256_ecb_decrypt(ciphertext, ciphertext_len, key, iv,
|
|
||||||
decryptedtext);
|
|
||||||
/* Add a NULL terminator. We are expecting printable text */
|
|
||||||
decryptedtext[decryptedtext_len] = '\0';
|
|
||||||
/* Show the decrypted text */
|
|
||||||
printf("Decrypted text is:\n");
|
|
||||||
printf("%s\n", decryptedtext);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Encrypt the plaintext */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,22 @@ int prename ## _decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned
|
||||||
unsigned char *iv, unsigned char *plaintext);
|
unsigned char *iv, unsigned char *plaintext);
|
||||||
|
|
||||||
#define HANDLERRSSL() { ERR_print_errors_fp(stderr);abort(); }
|
#define HANDLERRSSL() { ERR_print_errors_fp(stderr);abort(); }
|
||||||
|
|
||||||
|
|
||||||
|
#define CHECKTYPE(whose,algo)\
|
||||||
|
if( (enctype& t_##whose ) == t_##whose ){\
|
||||||
|
puts("t_"#whose );\
|
||||||
|
ciphertext_len = algo##_encrypt (plaintext, strlen ((char *)plaintext), key, iv,\
|
||||||
|
ciphertext);\
|
||||||
|
printf("Ciphertext is:\n");\
|
||||||
|
BIO_dump_fp (stdout, (const char *)ciphertext, ciphertext_len);\
|
||||||
|
decryptedtext_len = algo##_decrypt(ciphertext, ciphertext_len, key, iv,\
|
||||||
|
decryptedtext);\
|
||||||
|
decryptedtext[decryptedtext_len] = '\0';\
|
||||||
|
printf("Decrypted text is:\n");\
|
||||||
|
printf("%s\n", decryptedtext);\
|
||||||
|
}
|
||||||
|
|
||||||
typedef const EVP_CIPHER *(*aes_enctype)(void);
|
typedef const EVP_CIPHER *(*aes_enctype)(void);
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,10 +49,15 @@ int AES_any_encrypt(aes_enctype enc,unsigned char *plaintext, int plaintext_len,
|
||||||
|
|
||||||
INITAESALGO(AES_256_cbc, EVP_aes_256_cbc);
|
INITAESALGO(AES_256_cbc, EVP_aes_256_cbc);
|
||||||
INITAESALGO(AES_256_ecb, EVP_aes_256_ecb);
|
INITAESALGO(AES_256_ecb, EVP_aes_256_ecb);
|
||||||
|
INITAESALGO(chacha20_poly1305,EVP_chacha20_poly1305);
|
||||||
|
|
||||||
|
|
||||||
|
void generate_rand_bytes(size_t len, unsigned char * key);
|
||||||
|
|
||||||
enum ENCType{
|
enum ENCType{
|
||||||
t_cbc=1<<1,
|
t_cbc=1<<1,
|
||||||
t_ecb=1<<2 // for small security operations/individual information
|
t_ecb=1<<2, // for small security operations/individual information
|
||||||
|
t_chacha20=1<<3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,3 @@ end
|
||||||
tgst = bacteria.coins['tgst']
|
tgst = bacteria.coins['tgst']
|
||||||
tdash = bacteria.coins['tdash']
|
tdash = bacteria.coins['tdash']
|
||||||
check_leak_memory(tgst,tdash)
|
check_leak_memory(tgst,tdash)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue