master
wipedlife 2021-06-21 18:37:12 +03:00
parent af7680f76b
commit 1ad8254ecc
7 changed files with 75 additions and 71 deletions

View File

@ -16,6 +16,9 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#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 HAVE_LIBCURL 1

6
config.h.in vendored
View File

@ -15,12 +15,12 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#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). */
#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). */
#undef HAVE_LIBINIPARSER

23
configure vendored
View File

@ -4204,13 +4204,14 @@ _ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lgpgme" >&5
$as_echo_n "checking for main in -lgpgme... " >&6; }
if ${ac_cv_lib_gpgme_main+:} false; then :
#AC_CHECK_LIB([gpgme], [main])
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lcrypto" >&5
$as_echo_n "checking for main in -lcrypto... " >&6; }
if ${ac_cv_lib_crypto_main+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lgpgme $LIBS"
LIBS="-lcrypto $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@ -4224,22 +4225,22 @@ return main ();
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_gpgme_main=yes
ac_cv_lib_crypto_main=yes
else
ac_cv_lib_gpgme_main=no
ac_cv_lib_crypto_main=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gpgme_main" >&5
$as_echo "$ac_cv_lib_gpgme_main" >&6; }
if test "x$ac_cv_lib_gpgme_main" = xyes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_main" >&5
$as_echo "$ac_cv_lib_crypto_main" >&6; }
if test "x$ac_cv_lib_crypto_main" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBGPGME 1
#define HAVE_LIBCRYPTO 1
_ACEOF
LIBS="-lgpgme $LIBS"
LIBS="-lcrypto $LIBS"
fi

2
configure.ac vendored
View File

@ -18,7 +18,7 @@ AC_CHECK_LIB([iniparser], [main])
AC_CHECK_LIB([jansson], [main])
AC_CHECK_LIB([curl], [main])
AC_CHECK_LIB([ssl], [main])
AC_CHECK_LIB([gpgme], [main])
#AC_CHECK_LIB([gpgme], [main])
AC_CHECK_LIB([crypto], [main])
CFLAGS="$CFLAGS -g"

View File

@ -1,5 +1,13 @@
#include"AES.h"
/*
unsigned char *p_str = "82019154470699086128524248488673846867876336512717";
BIGNUM *p = BN_bin2bn(p_str, sizeof(p_str), NULL);
BN_free(p);
*/
int
AES_any_decrypt(aes_enctype enc,unsigned char *ciphertext, int ciphertext_len, unsigned char *key,
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_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
main(int count, char ** values){
/*
* Set up the key and iv. Do I need to say to not hard code these in a
* real application? :-)
*/
if(count != 5){
return fprintf(stderr,"%s msg key iv ENCType(2,4,2|4[6])\n",values[0]);
if(count != 3){
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 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 */
// unsigned char *key = (unsigned char *)"01234567890123456789012345678901";
@ -136,47 +160,11 @@ main(int count, char ** values){
unsigned char decryptedtext[128];
int decryptedtext_len, ciphertext_len;
puts("Enc");
if( (enctype&t_cbc) == t_cbc ){
puts("t_cbc");
ciphertext_len = AES_256_cbc_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_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 */
CHECKTYPE(cbc,AES_256_cbc);
CHECKTYPE(ecb,AES_256_ecb);
CHECKTYPE(chacha20,chacha20_poly1305);
return 0;

View File

@ -22,6 +22,22 @@ int prename ## _decrypt(unsigned char *ciphertext, int ciphertext_len, unsigned
unsigned char *iv, unsigned char *plaintext);
#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);
@ -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_ecb, EVP_aes_256_ecb);
INITAESALGO(chacha20_poly1305,EVP_chacha20_poly1305);
void generate_rand_bytes(size_t len, unsigned char * key);
enum ENCType{
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
};

View File

@ -26,12 +26,3 @@ end
tgst = bacteria.coins['tgst']
tdash = bacteria.coins['tdash']
check_leak_memory(tgst,tdash)