static char * _device_name( const char * mapper,char * ( *function )( const char * ) ) { tc_api_task task ; char * e = NULL ; char device[ PATH_MAX + 1 ] = { '\0' } ; mapper = mapper + StringLastIndexOfChar_1( mapper,'/' ) + 1 ; if( tc_api_initialize() ){ if( tc_api_task_initialize( &task,"info_mapped" ) ){ tc_api_task_set( task,"map_name",mapper ) ; tc_api_task_do( task ) ; tc_api_task_info_get( task,"device",sizeof( device ),device ) ; tc_api_task_uninit( task ) ; e = function( device ) ; } tc_api_uninit() ; } return e ; }
int zuluCryptModifyTcryptHeader( const info_t * info ) { tc_api_task task ; int r = !TC_OK ; const char * sys_device = NULL ; string_t st = StringVoid ; if( tc_api_init( 0 ) == TC_OK ){ task = tc_api_task_init( "modify" ) ; if( task != 0 ){ if( StringsAreEqual( info->opt,"sys" ) ){ tc_api_task_set( task,"dev",info->device ) ; st = _root_device( info->device,&sys_device ) ; tc_api_task_set( task,"sys",sys_device ) ; }else if( StringsAreEqual( info->opt,"fde" ) ){ st = _root_device( info->device,&sys_device ) ; tc_api_task_set( task,"dev",sys_device ) ; tc_api_task_set( task,"fde",TRUE ) ; }else{ tc_api_task_set( task,"dev",info->device ) ; } tc_api_task_set( task,"hidden_size_bytes",( u_int64_t )0 ) ; /* * below line may look like one of the following two lines: * tc_api_task_set( task,"header_from_file","/home/ink/tc.headerbackup" ) ; * tc_api_task_set( task,"save_header_to_file","/home/ink/tc.headerbackup" ) ; */ tc_api_task_set( task,info->header_source,info->tmp_path ) ; /* * below line may look like one of the following two lines: * tc_api_task_set( task,"passphrase","xxx" ) ; * tc_api_task_set( task,"keyfiles","/home/ink/keyfile" ) ; */ tc_api_task_set( task,info->header_key_source,info->header_key ) ; /* * below line may look like one of the following two lines: * tc_api_task_set( task,"new_passphrase","xxx" ) ; * tc_api_task_set( task,"new_keyfiles","/home/ink/keyfile" ) ; */ tc_api_task_set( task,info->header_new_key_source,info->header_key ) ; if( StringsAreEqual( info->rng,"/dev/urandom" ) ){ tc_api_task_set( task,"weak_keys_and_salt",TRUE ) ; }else{ tc_api_task_set( task,"weak_keys_and_salt",FALSE ) ; } r = tc_api_task_do( task ) ; tc_api_task_uninit( task ) ; } tc_api_uninit() ; } StringDelete( &st ) ; return r ; }
/* * tcplay >= 1.0.0 < 2.0,0 */ static int _create_volume( const tcrypt_t * info ) { int r = !TC_OK ; tc_api_opts api_opts ; const char * keyfiles[ 2 ] = { NULL,NULL } ; const char * keyfiles_h[ 2 ] = { NULL,NULL } ; if( tc_api_init( 0 ) == TC_OK ){ memset( &api_opts,'\0',sizeof( api_opts ) ) ; api_opts.tc_device = info->device ; api_opts.tc_cipher = "AES-256-XTS"; api_opts.tc_prf_hash = "RIPEMD160" ; api_opts.tc_no_secure_erase = 1 ; if( info->weak_keys_and_salt ){ api_opts.tc_use_weak_keys = 1 ; } if( info->key_source == TCRYPT_PASSPHRASE ){ api_opts.tc_passphrase = info->key ; }else{ keyfiles[ 0 ] = info->key ; api_opts.tc_keyfiles = keyfiles ; } if( info->hidden_volume_size > 0 ){ api_opts.tc_size_hidden_in_bytes = info->hidden_volume_size ; api_opts.tc_cipher_hidden = "AES-256-XTS"; api_opts.tc_prf_hash_hidden = "RIPEMD160" ; if( info->key_source_h == TCRYPT_PASSPHRASE ){ api_opts.tc_passphrase_hidden = info->key_h ; }else{ keyfiles_h[ 0 ] = info->key_h ; api_opts.tc_keyfiles_hidden = keyfiles_h ; } } r = tc_api_create_volume( &api_opts ) ; tc_api_uninit() ; } return r ; }
static int _create_volume( const tcrypt_t * info ) { tc_api_task task ; int r = !TC_OK ; if( tc_api_init( 0 ) == TC_OK ){ task = tc_api_task_init( "create" ) ; if( task != 0 ){ tc_api_task_set( task,"dev",info->device ) ; tc_api_task_set( task,"secure_erase",FALSE ) ; tc_api_task_set( task,"prf_algo","RIPEMD160" ) ; tc_api_task_set( task,"cipher_chain","AES-256-XTS" ) ; tc_api_task_set( task,info->key_source_1,info->key ) ; if( info->weak_keys_and_salt ){ tc_api_task_set( task,"weak_keys_and_salt",TRUE ) ; }else{ tc_api_task_set( task,"weak_keys_and_salt",FALSE ) ; } if( info->hidden_volume_size > 0 ){ tc_api_task_set( task,"hidden_size_bytes",info->hidden_volume_size ) ; tc_api_task_set( task,"h_prf_algo","RIPEMD160" ) ; tc_api_task_set( task,"h_cipher_chain","AES-256-XTS" ) ; tc_api_task_set( task,info->key_source_h_1,info->key_h ) ; } r = tc_api_task_do( task ) ; tc_api_task_uninit( task ) ; } tc_api_uninit() ; } return r ; }
static string_t _get_crypto_info_from_tcplay( const char * mapper ) { int key_size ; int ro ; int64_t offset ; tc_api_task task ; char buff[ SIZE ] ; char * buffer = buff ; const char * z ; string_t p = StringVoid ; string_t q ; if( tc_api_initialize() ){ if( tc_api_task_initialize( &task,"info_mapped" ) ){ p = String( mapper ) ; mapper = mapper + StringLastIndexOfChar_1( mapper,'/' ) + 1 ; tc_api_task_set( task,"map_name",mapper ) ; tc_api_task_do( task ) ; tc_api_task_info_get( task,"status",sizeof( buff ),buff ) ; StringMultipleAppend( p," is ",buff,".",NULL ) ; if( StringAtLeastOneMatch_1( buff,"active","active and is in use",NULL ) ){ tc_api_task_info_get( task,"type",sizeof( buff ),buff ) ; q = String( buff ) ; StringMultipleAppend( p," \n type: \t",StringToLowerCase( q ),NULL ) ; StringDelete( &q ) ; tc_api_task_info_get( task,"cipher",sizeof( buff ),buff ) ; /* * zuluCryptConvertCipher() is defined in create_tcrypt.c */ StringMultipleAppend( p,"\n cipher:\t",zuluCryptConvertCipher( buff ),"-xts-plain64",NULL ) ; tc_api_task_info_get( task,"key_bits",sizeof( key_size ),&key_size ) ; z = StringIntToString_1( buffer,SIZE,key_size ) ; StringMultipleAppend( p,"\n keysize:\t",z," bits",NULL ) ; tc_api_task_info_get( task,"iv_offset",sizeof( offset ),&offset ) ; z = StringIntToString_1( buffer,SIZE,offset / 512 ) ; StringMultipleAppend( p,"\n offset:\t",z," sectors",NULL ) ; zuluCryptFormatSize( offset,buffer,SIZE ) ; StringMultipleAppend( p," / ",buffer,NULL ) ; tc_api_task_info_get( task,"device",sizeof( buff ),buff ) ; _device_info( p,buff ) ; tc_api_task_info_get( task,"mode",sizeof( ro ),&ro ) ; if( ro ){ StringAppend( p,"\n mode: \tread only" ) ; }else{ StringAppend( p,"\n mode: \tread and write" ) ; } StringAppend( p,"\n active slots:\tNil" ) ; } tc_api_task_uninit( task ) ; } tc_api_uninit() ; } return p ; }
static int _open_tcrypt_volume( const char * device,const open_struct_t * opts ) { tc_api_task task ; int r = !TC_OK ; size_t i ; size_t k ; const char * const * z ; const char * e ; string_t st = StringVoid ; if( tc_api_initialize() ){ task = tc_api_task_init( "map" ) ; if( tc_api_task_initialized( task ) ){ tc_api_task_set( task,"veracrypt_mode",opts->veraCrypt_volume ) ; tc_api_task_set( task,"map_name",opts->mapper_name ) ; if( StringHasComponent( opts->m_opts,"ro" ) ){ tc_api_task_set( task,"read_only" ) ; } if( opts->tcrypt_system ){ if( StringPrefixEqual( device,"/dev/sd" ) || StringPrefixEqual( device,"/dev/hd" ) ){ st = String( device ) ; e = StringRemoveDigits( st ) ; tc_api_task_set( task,"dev",e ) ; tc_api_task_set( task,"sys",e ) ; }else{ tc_api_task_set( task,"dev",device ) ; tc_api_task_set( task,"sys",device ) ; } }else{ tc_api_task_set( task,"dev",device ) ; } k = opts->tcrypt_keyfiles_count ; z = opts->tcrypt_keyfiles ; tc_api_task_set( task,"passphrase",opts->key ) ; for( i = 0 ; i < k ; i++ ){ tc_api_task_set( task,"keyfiles",*( z + i ) ) ; } r = tc_api_task_do( task ) ; tc_api_task_uninit( task ) ; StringDelete( &st ) ; } tc_api_uninit() ; } return r ; }