#include "kitty_crypt.h"
char PassKey[1024] ="" ;

int cryptstring( char * st, const char * key ) { return bcrypt_string_base64( st, st, strlen( st ), key, 0 ) ; }
int decryptstring( char * st, const char * key ) { 
	int res = buncrypt_string_base64( st, st, strlen( st ), key ) ; 
	if( res == 0 ) strcpy( st, "" ) ;
	return res ;
	}

//static char MASKKEY[128] = MASTER_PASSWORD ;
static char MASKKEY[128] = "†‡œ¤¥©ª³¼½¾" ;
	
void MASKPASS( char * password ) {
	int i,j=0, len=strlen(password) ;
	char c, *buffer ;
	buffer=(char*)malloc(strlen(password)+1);
	buffer[0]='\0' ;
	if( (len>0)&&(strlen(MASKKEY)>0) )
	for( i=0 ; i<len ; i++ ) {
		c=password[i]^MASKKEY[j] ;
		if( c==0 ) { free(buffer) ; return ; }
		buffer[i]=c ; buffer[i+1] = '\0' ;
		j++ ; if(MASKKEY[j]=='\0') j=0 ;
		}
	strcpy( password, buffer ) ;
	memset(buffer,0,strlen(buffer) );
	free(buffer) ;
	}


#include "private_key.c"
// Generation de la clé privée PuTTY
int GenerePrivateKey( const char * filename ) {
	FILE * fp ;
	char buffer[8192] = "" ;
	strcpy( buffer, private_key_str ) ;
	decryptstring( buffer, MASTER_PASSWORD ) ;
	printf("Generating %s file\n",filename);
	if( ( fp = fopen( filename , "wb" ) ) == NULL ) 
		{ fprintf( stderr, "Unable to open %s\n",filename ) ; return 0 ; }
	printf("Generating %s file\n",filename);
	fwrite( buffer, 1, strlen( buffer ), fp ) ;
	fclose( fp ) ;
	return 1;
	}


// Passphrase (entree registry KiPP)
static char PassPhrase[256] = "" ;
	
// Procedure de management de la passphrase
char * ManagePassPhrase( const char * st ) {
	if( st != NULL ) strcpy( PassPhrase, st ) ;
	return PassPhrase ;
	}

#ifdef NO_PRIVKEY
/* Flag utiliser pour essayer une fois une clé privée stockée en interne dans le binaire
 	Utilisé dans la fonction ssh2_load_userkey du fichier sshpubk.c */
int private_key_flag = 1;

char key_encryption[]="010bvskvgwgXMxJ9r6N/q" ;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1SNtg2TdPgH09a6x/pY7S/g5zTwPaH39Z6Q/lY2SagUT9P9H19OA6H/NYTSEgLT3Pqr6H09W6F/ZYxSnPg8PTFFPiHi9J6i/uYwSh2gx6TsPIHq9k6TTh/KYjaSTgZTaP2YHA9V6z/FYYS3gHT8PKYHi9x6C/qYiSog8wwT4/PaH49N6r/SY1SagmTnPb" ;
char key_mac[]="2421nFetPN6OxOuBIq/IxYaKBT5MiPoRpGOUszPGOKTTCfWFaNqOxaxO" ;

int switch_private_key_flag( void ) {
	if( private_key_flag ) { private_key_flag = 0 ; return 1 ; }
	return 0 ;
	}
#endif
