Erich Roncarolo > Crypt-Mimetic > Crypt::Mimetic

Download:
Crypt-Mimetic-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  

NAME ^

Crypt::Mimetic - Crypt a file and mask it behind another file

SYNOPSIS ^

 use Crypt::Mimetic;
        
 Crypt::Mimetic::Mask($original_file, $mask_file, $destination_file, $algorithm);
 Crypt::Mimetic::Unmask($mimetic_file);

 Crypt::Mimetic::Main($original_file, $mask_file, $destination_file, [$algorithm]);
 Crypt::Mimetic::Main($mimetic_file);

DESCRIPTION ^

This module allows you to hide a file by encrypting in and then attaching it to another file of your choice. This mimetic file then looks and behaves like a normal file, and can be stored, used or emailed without attracting attention.

EXAMPLES ^

Here your first running example

 use Crypt::Mimetic;
 use Error;
 $Error::Debug = 1;

 &Crypt::Mimetic::Main(@ARGV);

You should already have it in your bin/ files: write mimetic and follow instructions.

How to make a test of all encryption algorithms

 use Crypt::Mimetic;

 use Error qw(:try);
 $Error::Debug = 1;

 print "\nPerforming tests for Crypt::Mimetic\n";
 print "Looking for available encryption algorithms, please wait... ";
 select((select(STDOUT), $| = 1)[0]); #flush stdout

 @algo = Crypt::Mimetic::GetEncryptionAlgorithms();
 print @algo ." algorithms found.\n\n";

 $str = "This is a test string";
 $failed = 0;
 $warn = 0;

 foreach my $algo (@algo) {

    try {

       print ''. Crypt::Mimetic::ShortDescr($algo) ."\n";
       print " Encrypting string '$str' with $algo...";
       select((select(STDOUT), $| = 1)[0]); #flush stdout

       ($enc,@info) = Crypt::Mimetic::EncryptString($str,$algo,"my stupid password");
       print " done.\n";

       print " Decrypting encrypted string with $algo...";
       select((select(STDOUT), $| = 1)[0]);

       $dec = Crypt::Mimetic::DecryptString($enc,$algo,"my stupid password",@info);
       print " '$dec'.\n";

       if ($dec eq $str) {
          print "Algorithm $algo: ok.\n\n";
       } else {
          print "Algorithm $algo: failed. Decrypted string '$dec' not equals to original string '$str'\n\n";
          $failed++;
       }#if-else

    } catch Error::Mimetic with {
       my $x = shift;

       if ($x->type() eq "error") {
          print "Algorithm $algo: error. ". $x->stringify() ."\n";
          $failed++;
       } elsif ($x->type() eq "warning") {
          print "Algorithm $algo: warning. ". $x->stringify() ."\n";
          $warn++;
       }#if-else

    }#try-catch

 }#foreach

 print @algo ." tests performed: ". (@algo - $failed) ." passed, $failed failed ($warn warnings).\n\n";
 exit $failed;

Script test.pl used by make test in this distribution do exactly the same thing.

PROCEDURAL INTERFACE ^

@array GetEncryptionAlgorithm ()

Return an array with names of encryption algorithms. Each algorithm is implemented in module Crypt::Mimetic::<algorithm>

string GetPasswd ($prompt)

Ask for a password with a given prompt (default "Password: ") and return it.

string GetConfirmedPasswd ()

Ask for a password twice and return it only if it's correct.

Throws an Error::Mimetic if passwords don't match

string ShortDescr ($algorithm)

Return a short description of $algorithm

boolean PasswdNeeded ($algorithm)

Return true if password is needed by this $algorithm, false otherwise.

($len,$blocklen,$padlen,[string]) EncryptFile ($filename,$output,$algorithm,$key,@info)

Call specific routine to encrypt $filename according to $algorithm. Return 3 int: $len - is the total output length $blocklen - length of an encrypted block (if needed) $padlen - length of last encrypted block (if needed)

If $output is null then the output is returned as string. Ask for a password if key not given.

Throws an Error::Mimetic if cannot open files or if password is not correctly given.

string EncryptString ($string,$algorithm,$key,@info)

Call specific routine to encrypt $string according to $algorithm and return an encrypted string. Ask for a password if key not given.

Throws an Error::Mimetic if password is not correctly given.

[string] DecryptFile ($filename,$output,$offset,$len,$algorithm,$key,@info)

Call specific routine to decrypt $filename according to $algorithm. Return decrypted file as string if $output is not given, void otherwise. Ask for a password if key not given.

Throws an Error::Mimetic if cannot open files or if password is not given

string DecryptString ($string,$algorithm,$key,@info)

Call specific routine to decrypt $string according to $algorithm and return a decrypted string. Ask for a password if key not given.

Throws an Error::Mimetic if password is not correctly given.

string Sign ($original_file,$mask_file,$dlen,$algorithm,$key,@info)

Create following sign (all on the same line): Mimetic\0 version\0 mask_file_name\0 mask_file_length\0 original_file_name\0 encrypted_file_length\0 @info

than encrypt it and calculate length of encrypted sign. Return a string composed by concatenation of encrypted sign, algorithm (32 bytes null padding string) and its length (8 bytes hex number).

(string,int) GetSignInfo ($mimetic_file)

Return the algorithm and the length of the sing read from last 40 bytes of $mimetic_file.

Throws an Error::Mimetic if cannot open file

($Mimetic,$version,$mask_file,$mlen,$original_file,$olen,@pinfo) = ParseSign ($mimetic_file,$slen,$algorithm,$key,@info);

Extract information from sign of $mimetic_file. You can obtain $slen and $algorithm from GetSignInfo($mimetic_file) and key from GetPasswd(void) This sub returns an array: $Mimetic - constant string "Mimetic" $version - version of the module $mask_file - mask file's name $mlen - mask file's length $original_file - original file's name $olen - original file's length @pinfo - specific encryption algorithm information

Throws an Error::Mimetic if cannot open file

void WriteMaskFile ($mimetic_file,$len,$mask_file)

Extract the mask file from $mimetic_file and save it in $mask_file.

Throws an Error::Mimetic if cannot open files

void Mask ($original_file,$mask_file,$destination_file,$algorithm,$key,@info)

Mask the $original_file with a $mask_file and put everything in $destination_file, according $algorithm and @info instruction. Return true on success, false otherwise.

Throws an Error::Mimetic if cannot open files or password not correctly given

boolean Unmask ($mimetic_file,$algorithm,$key,@info)

Unmask a $mimetic file splitting it in 2 files: 1. mask file 2. original file

Throws an Error::Mimetic if cannot open files or password not given

void Main (@arguments)

A demo main to use this module Usage: to camouflage a file with a mask Main($original_file, $mask_file, $destination_file, [$algorithm]); to split camouflaged file in original file and mask Main($mimetic_file);

About errors

Some subroutines in this module throw errors. You can learn more about this reading documentation about Error::Mimetic(3).

ENCRYPTION ALGORITHMS ^

Implementing new algorithm

To implement a new encryption algorithm, let's say Foo, you should write a module with name Crypt::Mimetic::Foo that has following subroutines:

string ShortDescr ()

Return a short description of algorithm

boolean PasswdNeeded ()

Return true if password is needed by this algorithm, false otherwise.

($len,$blocklen,$padlen,[string]) EncryptFile ($filename,$output,$algorithm,$key,@info)

Encrypt a file with Foo algorithm. See Crypt::Mimetic::EncryptFile.

string EncryptString ($string,$algorithm,$key,@info)

Encrypt a string with Foo algorithm. See Crypt::Mimetic::EncryptString.

[string] DecryptFile ($filename,$output,$offset,$len,$algorithm,$key,@info)

Decrypt a file with Foo algorithm. See Crypt::Mimetic::DecryptFile.

string DecryptString ($string,$algorithm,$key,@info)

Decrypt a string with Foo algorithm. See Crypt::Mimetic::DecryptString.

Installing new algorithms

To install a new mimetic encryption algorithm that you wrote (or downloaded) you should only install it as a normal Perl module; Crypt::Mimetic module will be able to find it (and use it) automagically if it's in one of the directories listed in @INC.

Obviously if you send me your algorithm I'll include it in the new release of Crypt::Mimetic

NEEDED MODULES ^

This module needs: Error Error::Mimetic Term::ReadKey File::Copy File::Find

SEE ALSO ^

Crypt::Mimetic::None(3), Crypt::Mimetic::TEA(3), Crypt::Mimetic::CipherSaber(3)

LICENSE ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself (Artistic/GPL2).

AUTHOR ^

Erich Roncarolo <erich-roncarolo@users.sourceforge.net>

syntax highlighting: