Author Topic: Linux - Encrypt & Decrypt Files With One-Time Pads Using the SSE Architecture  (Read 13829 times)

Offline Zefferon

  • Jr. Member
  • *
  • Posts: 13
Swimming in a sea of numbers.
One stood out.
It was a mirror.

Encryption with one-time pads is basically uncrackble.

The Shallizar Nasm Linux Collection program for this is Nightshade.
http://www.shallizar.com/nasmcollection/Linux/Shallizar/Apps/Encrypt/Nightshade.html

Nightshade is one of the fastest encrypters available for
32-bit platforms.

Max file size: NO LIMIT
Max pad size: NO LIMIT

Nightshade will encrypt anything. It doesn't matter how big it is.

The size of the file and the size of the pad are completely independent.
If you want to encrypt a 6-gig file with a 2 megabyte pad, Nightshade will do it.
If you want to encrypt a 6-gig file with a 6 gigabyte pad, Nightshade will do it.

Nightshade's default pad size is 1 megabyte. If a pad is used smaller than this,
Nightshade will dupe it in its pad buffer out to a megabyte, and use its
blitzer algorythm. If a pad is larger than a megabyte, Nightshade will true-encrypt
using its buffer chopper.

INSTALLATION

Nightshade is part of the Nasm Linux Collection tarball:
http://www.shallizar.com/nasmcollection/Linux/nasmcoldnldlinux.html
It installs the same as the other programs.

Nightshade is also available as its own seperate tarball:
http://www.shallizar.com/nasmcollection/Linux/Shallizar/Apps/Encrypt/Nightshade.zip
(attached)

USAGE

The basic command is
./Nightshade MyFile.ext
This will create a one-time pad named "MyFile.ext.pad", and the encrypted
file will be named "MyFile.ext.enc".

The pad should be made seperately.
The command for this is
./Nightshade -pTwoMeg.pad 2097152
which will make a pad named "TwoMeg.pad" of 2 megabytes.

You should obfuscate your filenames and file sizes.
A file named "checks.ods" of size 1266400 and a paf named "spreadsheet.pad"
 of size 1266400 is kinda obvious.

Nightshade is a console application. It can be used in scripts.

The pad making algorythm and the encryption algorythm are seperate modules,
"Padmake.asm" & "EncryptSSE.asm".

Yo - Rob, - Frank ....
You can call these babes from c.
They'll answer alllll night long:

Sample c program for calling Padmake:
Code: [Select]
/*
;>>>>> MakePad.c <CONSOLE APP>
*/
#include <stdio.h>

extern int _Padmake_MakePadFile(char *stg, long long size, int roundup);
extern char* _Padmake_PropErrMsg(void);

int main(int argc, char *argv[])
{
long long PadSize; //INT64 READ FROM COMMAND LINE
int ReturnCode; //RETURN CODE FROM Padmake MODULE

char *MsgPtr; //MESSAGE POINTER RETURNED FROM Padmake MODULE

//TEST _Padmake_PropErrMsg
char test1[16] = "/home/junk/mmm"; //DIR junk DOESN'T EXIST
ReturnCode = _Padmake_MakePadFile(test1, 1000, 0);
if (ReturnCode < 0) {MsgPtr = _Padmake_PropErrMsg();
     printf("   Padmake ERROR: %s\n", MsgPtr);
     }

if (argc<3)
{printf("   ERROR: COMMAND LINE: MISSING SIZE\n\n");
printf("   USAGE:\n      PadMake padfilename size\n");
return 0;
}

PadSize = atoi(argv[2]);
printf("   MakePad:  %s   OF SIZE: %i\n", argv[1], PadSize);

ReturnCode = _Padmake_MakePadFile(argv[1], PadSize, 0);
if (ReturnCode < 0) {MsgPtr = _Padmake_PropErrMsg();
     printf("   ERROR MAKING PAD: %i\n", ReturnCode);
     printf("Padmake ERROR: %s\n", MsgPtr);
     }
else {printf("   PAD MADE: %s - %i BYTES\n", argv[1], PadSize);}

return 0;
}


Sample c program for calling EncryptSSE:
Code: [Select]
/*
;>>>>> EncryptFile.c <CONSOLE APP>
*/
#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>

extern int _Padmake_MakePadFile(const char *stg, long long size, int roundup);
extern char* _Padmake_PropErrMsg(void);
extern int _EncryptSSE_EncryptFile(const char *Src, const char *Pad, const char *Crypt );
extern char* _EncryptSSE_PropErrMsg(void);
extern char* _EncryptSSE_PropErrDesc(void);

int main(int argc, char *argv[])
{
char SourceFile[257];
char PadFile[257];
char EncryptFile[257];

//ARGS FOR FileStat
long long FSIZE; __time_t Cdate; __time_t Mdate; int DirFlag;

int ReturnCode;


if ( argc == 4 ) {
strcpy( SourceFile, argv[1] );
strcpy( PadFile, argv[2] );
strcpy( EncryptFile, argv[3] );
if ( _EncryptSSE_EncryptFile( SourceFile, PadFile, EncryptFile ) == -1 )
{ printf( "ERROR ENCRYPTING FILE: %s%s\n", _EncryptSSE_PropErrMsg(), _EncryptSSE_PropErrDesc() );
  return -1; }
else
{ printf( "ENCRYPTED %s TO %s WITH %s\n", SourceFile, EncryptFile, PadFile );
  return 0; }
}

else if ( argc == 3 ) {
strcpy( SourceFile, argv[1] );
strcpy( PadFile, argv[2] );
strcpy( EncryptFile, SourceFile );
strcat( EncryptFile, ".enc" );
if ( _EncryptSSE_EncryptFile( SourceFile, PadFile, EncryptFile ) == -1 )
{ printf( "ERROR ENCRYPTING FILE: %s%s\n", _EncryptSSE_PropErrMsg(), _EncryptSSE_PropErrDesc() );
  return -1; }
else
{ printf( "ENCRYPTED %s TO %s WITH %s\n", SourceFile, EncryptFile, PadFile );
  return 0; }
}

else if ( argc == 2 )
{ strcpy( SourceFile, argv[1] );
  if ( FileStat( argv[1], &FSIZE, &Cdate, &Mdate, &DirFlag ) == -1 )
{ printf( "CANNOT STAT %s\n", argv[1] );
  return -1; }
  if ( DirFlag == 1 ) { printf("ARG IS A DIR"); return -1; }
  strcpy( PadFile, SourceFile );
  strcat( PadFile, ".pad" );
  strcpy( EncryptFile, SourceFile );
  strcat( EncryptFile, ".enc" );
printf("SourceFile: %s\nPadFile: %s\nEncryptFile: %s\n", SourceFile, PadFile, EncryptFile );
  if ( _Padmake_MakePadFile( PadFile, FSIZE, 1 ) == -1 )
{ printf( "ERRRO MAKING PAD: %s\n", _Padmake_PropErrMsg() );
  return -1; }
  if ( _EncryptSSE_EncryptFile( SourceFile, PadFile, EncryptFile ) == -1 )
{ printf( "ERROR ENCRYPTING FILE: %s%s\n", _EncryptSSE_PropErrMsg(), _EncryptSSE_PropErrDesc() );
  return -1; }
  else { printf( "ENCRYPTED %s TO %s WITH %s\n", SourceFile, PadFile, EncryptFile ); }
}

return 0;
}


// c VERSION OF FileStat
int FileStat( char Filename[], \
long long* Fsize, \
__time_t* DateCreated, \
__time_t* DateLastModified, \
int* IsDir)
{
struct stat64 Struc64;
struct tm *MetaDate;

char TimeStg[20];

int rtn;

//INIT DATES TO null
*DateCreated = 0;
*DateLastModified = 0;

rtn = stat64( Filename, &Struc64 );
if( rtn != 0 )
{ return -1; }
else
{ *Fsize = Struc64.st_size;
  *DateCreated = Struc64.st_ctime;
  *DateLastModified = Struc64.st_mtime;
  *IsDir = Struc64.st_mode & __S_IFDIR;

  MetaDate = localtime( &Struc64.st_ctime );
  rtn = strftime( TimeStg, 20, "%Y-%m-%d_%H%M%S\n", MetaDate );
  printf( "DateCreated: %s", TimeStg );

  MetaDate = localtime( &Struc64.st_mtime );
  rtn = strftime( TimeStg, 20, "%Y-%m-%d_%H%M%S\n", MetaDate );
  printf( "DateLastModified: %s", TimeStg );
}
return 0;
}

Have fun, boys.
« Last Edit: June 13, 2015, 05:41:36 PM by Zefferon »