Recent

Author Topic: DCPcrypt: encrypting with plain key  (Read 24111 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8266
  • Programming + Glam Metal + Tae Kwon Do = Me
DCPcrypt: encrypting with plain key
« on: September 06, 2012, 02:51:48 pm »
Can anyone point me a way to encrypt (using 3DES ECB algo) with plain key? Currently, looking at the documentation, the key must be hashed (when given through .InitStr) by selecting one of the hash classes (md4, md5, sha1, etc.) while I need to use the key plainly.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: DCPcrypt: encrypting with plain key
« Reply #1 on: September 06, 2012, 03:19:02 pm »
Use .Init http://is.muni.cz/th/51468/fi_b/priloha/DCPcrypt/Docs/Ciphers.html#Init
Note that when your password is not 192 bits, the key is just padded with 0.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8266
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: DCPcrypt: encrypting with plain key
« Reply #2 on: September 06, 2012, 05:22:42 pm »
Quote
Note that when your password is not 192 bits, the key is just padded with 0.
No problem as long as it can encrypt "1234567890ABCDEF" with key "1234567890ABCDEF1234567890ABCDEF" (not the actual key of course) to "B8E929DB99FE88C0" with 3DES ECB. Seems like I have to dig the code in, the key parameter of .Init is untyped, and not really explained.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: DCPcrypt: encrypting with plain key
« Reply #3 on: September 06, 2012, 05:34:54 pm »
It is a pointer to a memory block that is copied with a move for size div 8 bytes. Something like this works:
Code: [Select]
var s:string;
begin
  s:='1234567890ABCDEF1234567890ABCDEF';
  DCP_3des1.Init(s[1],length(s)*8,nil);
...

Edit: this is assuming 1234567890ABCDEF1234567890ABCDEF is your key, not a hex representation of your key ;)
« Last Edit: September 06, 2012, 05:40:09 pm by ludob »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: DCPcrypt: encrypting with plain key
« Reply #4 on: September 06, 2012, 05:44:10 pm »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Leledumbo

  • Hero Member
  • *****
  • Posts: 8266
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: DCPcrypt: encrypting with plain key
« Reply #5 on: September 06, 2012, 06:08:39 pm »
WORKS!!! :D
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
const
  Key: array [1..16] of Byte = (
    $12,$34,$56,$78,$90,$AB,$CD,$EF,
    $12,$34,$56,$78,$90,$AB,$CD,$EF
  );
  Target: array [1..8] of Byte = (
    $12,$34,$56,$78,$90,$AB,$CD,$EF
  );
var
  Result: array [1..8] of Byte;
  S: String;
  B: Byte;
begin
  FillByte(Result[1],SizeOf(Result),0);
  DCP_3des1.Init(Key,Length(Key) * 8,nil);
  DCP_3des1.EncryptECB(Target,Result);
  S := '';
  for B in Result do
    S := S + HexStr(B,2);
  Edit1.Caption := S;
  DCP_3des1.Reset;
end;

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: DCPcrypt: encrypting with plain key
« Reply #6 on: October 03, 2013, 07:11:52 pm »
How can I reproduce  OpenSSL encryption/decryption in Lazarus?
I have tried http://www.cityinthesky.co.uk/_media/opensource/dcpdemos.zip with (DCPCrypt 2.0.4.1) package ( http://wiki.freepascal.org/DCPcrypt ) . I have use Rijndael cipher and md5 as hash. But it cannot decrypt my files, encrypted by OpenSSL (using AES_set_decrypt_key, AES_set_encrypt_key, AES_cbc_encrypt procedures).
As I see some secret string convert to it's MD5. Then AES_set_decrypt_key (MD5 ) = some 176-byte array. Then
AES_cbc_encrypt(
--pointer to encrypted data ,
--pointer to memory to recieve decrypt data,
--size of encrypted data,
--key = AES_set_decrypt_key (MD5(secret) ),
--pointer to some memory (???),
--maybe other arguments (???)
)
Can anybody help?
______
http://www.md5hashgenerator.com/index.php
WinXP SP3 Pro Russian 32-bit (5.1.2600)

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: DCPcrypt: encrypting with plain key
« Reply #7 on: October 03, 2013, 08:18:37 pm »
Well, as I see from this site http://www.disi.unige.it/person/FerranteM/delphiopenssl/
it is possible to use project with exported functions from dll by using module http://www.disi.unige.it/person/FerranteM/delphiopenssl/libeay32.pas where these functions just declared.
But on same site there is link to sources of libeay32.dll. Maybe somebody convert C++ source to lazarus?
WinXP SP3 Pro Russian 32-bit (5.1.2600)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: DCPcrypt: encrypting with plain key
« Reply #8 on: October 03, 2013, 08:38:38 pm »
...encrypted by OpenSSL...

I'm not sure of what you mean really with that. But if your question is how to use OpenSSL for AES cyphering, here is a quick sample attached.

You'll have to add the corresponding windows DLL (i.e. "libeay32.dll" and "ssleay32.dll") in the same directory of the project, 'cause I've statically linked these DLLs for a simplification: unless they are already installed else where in your path.

**EDIT ** BTW, if you need them, you can always get the latest (currently 1.0.1e) OpenSSL windows DLL at the Fulgan Indy Site: http://indy.fulgan.com/SSL/
« Last Edit: October 03, 2013, 09:00:25 pm by ChrisF »

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: DCPcrypt: encrypting with plain key
« Reply #9 on: October 04, 2013, 05:40:26 am »
...encrypted by OpenSSL...

I'm not sure of what you mean really with that. But if your question is how to use OpenSSL for AES cyphering, here is a quick sample attached.

You'll have to add the corresponding windows DLL (i.e. "libeay32.dll" and "ssleay32.dll") in the same directory of the project, 'cause I've statically linked these DLLs for a simplification: unless they are already installed else where in your path.

**EDIT ** BTW, if you need them, you can always get the latest (currently 1.0.1e) OpenSSL windows DLL at the Fulgan Indy Site: http://indy.fulgan.com/SSL/
Thanks. But I want single project executable, not hundred of files (many files is inconvenient). Besices I need only AES_set_decrypt_key, AES_set_encrypt_key, AES_cbc_encrypt , not whole DLL .
Here ftp://ftp.openssl.org/source/ is the sources of libeay32 (I need ver.1.0.0g). Can you convert C++ to working Pascal-code?
Code: [Select]
[font=Courier New]

/**
 * Expand the cipher key into the encryption key schedule.
 */
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key) {

u32 *rk;
    int i = 0;
u32 temp;

if (!userKey || !key)
return -1;
if (bits != 128 && bits != 192 && bits != 256)
return -2;

rk = key->rd_key;

if (bits==128)
key->rounds = 10;
else if (bits==192)
key->rounds = 12;
else
key->rounds = 14;

rk[0] = GETU32(userKey     );
rk[1] = GETU32(userKey +  4);
rk[2] = GETU32(userKey +  8);
rk[3] = GETU32(userKey + 12);
if (bits == 128) {
while (1) {
temp  = rk[3];
rk[4] = rk[0] ^
(Te2[(temp >> 16) & 0xff] & 0xff000000) ^
(Te3[(temp >>  8) & 0xff] & 0x00ff0000) ^
(Te0[(temp      ) & 0xff] & 0x0000ff00) ^
(Te1[(temp >> 24)       ] & 0x000000ff) ^
rcon[i];
rk[5] = rk[1] ^ rk[4];
rk[6] = rk[2] ^ rk[5];
rk[7] = rk[3] ^ rk[6];
if (++i == 10) {
return 0;
}
rk += 4;
}
}
rk[4] = GETU32(userKey + 16);
rk[5] = GETU32(userKey + 20);
if (bits == 192) {
while (1) {
temp = rk[ 5];
rk[ 6] = rk[ 0] ^
(Te2[(temp >> 16) & 0xff] & 0xff000000) ^
(Te3[(temp >>  8) & 0xff] & 0x00ff0000) ^
(Te0[(temp      ) & 0xff] & 0x0000ff00) ^
(Te1[(temp >> 24)       ] & 0x000000ff) ^
rcon[i];
rk[ 7] = rk[ 1] ^ rk[ 6];
rk[ 8] = rk[ 2] ^ rk[ 7];
rk[ 9] = rk[ 3] ^ rk[ 8];
if (++i == 8) {
return 0;
}
rk[10] = rk[ 4] ^ rk[ 9];
rk[11] = rk[ 5] ^ rk[10];
rk += 6;
}
}
rk[6] = GETU32(userKey + 24);
rk[7] = GETU32(userKey + 28);
if (bits == 256) {
while (1) {
temp = rk[ 7];
rk[ 8] = rk[ 0] ^
(Te2[(temp >> 16) & 0xff] & 0xff000000) ^
(Te3[(temp >>  8) & 0xff] & 0x00ff0000) ^
(Te0[(temp      ) & 0xff] & 0x0000ff00) ^
(Te1[(temp >> 24)       ] & 0x000000ff) ^
rcon[i];
rk[ 9] = rk[ 1] ^ rk[ 8];
rk[10] = rk[ 2] ^ rk[ 9];
rk[11] = rk[ 3] ^ rk[10];
if (++i == 7) {
return 0;
}
temp = rk[11];
rk[12] = rk[ 4] ^
(Te2[(temp >> 24)       ] & 0xff000000) ^
(Te3[(temp >> 16) & 0xff] & 0x00ff0000) ^
(Te0[(temp >>  8) & 0xff] & 0x0000ff00) ^
(Te1[(temp      ) & 0xff] & 0x000000ff);
rk[13] = rk[ 5] ^ rk[12];
rk[14] = rk[ 6] ^ rk[13];
rk[15] = rk[ 7] ^ rk[14];

rk += 8;
        }
}
return 0;
}

/**
 * Expand the cipher key into the decryption key schedule.
 */
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
AES_KEY *key) {

        u32 *rk;
int i, j, status;
u32 temp;

/* first, start with an encryption schedule */
status = AES_set_encrypt_key(userKey, bits, key);
if (status < 0)
return status;

rk = key->rd_key;

/* invert the order of the round keys: */
for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
temp = rk[i    ]; rk[i    ] = rk[j    ]; rk[j    ] = temp;
temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
}
/* apply the inverse MixColumn transform to all round keys but the first and the last: */
for (i = 1; i < (key->rounds); i++) {
rk += 4;
rk[0] =
Td0[Te1[(rk[0] >> 24)       ] & 0xff] ^
Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] ^
Td2[Te1[(rk[0] >>  8) & 0xff] & 0xff] ^
Td3[Te1[(rk[0]      ) & 0xff] & 0xff];
rk[1] =
Td0[Te1[(rk[1] >> 24)       ] & 0xff] ^
Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] ^
Td2[Te1[(rk[1] >>  8) & 0xff] & 0xff] ^
Td3[Te1[(rk[1]      ) & 0xff] & 0xff];
rk[2] =
Td0[Te1[(rk[2] >> 24)       ] & 0xff] ^
Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] ^
Td2[Te1[(rk[2] >>  8) & 0xff] & 0xff] ^
Td3[Te1[(rk[2]      ) & 0xff] & 0xff];
rk[3] =
Td0[Te1[(rk[3] >> 24)       ] & 0xff] ^
Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] ^
Td2[Te1[(rk[3] >>  8) & 0xff] & 0xff] ^
Td3[Te1[(rk[3]      ) & 0xff] & 0xff];
}
return 0;
}

/*
 * Encrypt a single block
 * in and out can overlap
 */
void AES_encrypt(const unsigned char *in, unsigned char *out,
const AES_KEY *key) {

const u32 *rk;
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
#endif /* ?FULL_UNROLL */

assert(in && out && key);
rk = key->rd_key;

/*
* map byte array block to cipher state
* and add initial round key:
*/
s0 = GETU32(in     ) ^ rk[0];
s1 = GETU32(in +  4) ^ rk[1];
s2 = GETU32(in +  8) ^ rk[2];
s3 = GETU32(in + 12) ^ rk[3];
#ifdef FULL_UNROLL
/* round 1: */
    t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4];
    t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5];
    t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6];
    t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7];
    /* round 2: */
    s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8];
    s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9];
    s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10];
    s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11];
/* round 3: */
    t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12];
    t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13];
    t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14];
    t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15];
    /* round 4: */
    s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16];
    s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17];
    s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18];
    s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19];
/* round 5: */
    t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20];
    t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21];
    t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22];
    t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23];
    /* round 6: */
    s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24];
    s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25];
    s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26];
    s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27];
/* round 7: */
    t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28];
    t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29];
    t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30];
    t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31];
    /* round 8: */
    s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32];
    s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33];
    s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34];
    s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35];
/* round 9: */
    t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36];
    t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37];
    t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38];
    t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39];
    if (key->rounds > 10) {
        /* round 10: */
        s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40];
        s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41];
        s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42];
        s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43];
        /* round 11: */
        t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44];
        t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45];
        t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46];
        t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47];
        if (key->rounds > 12) {
            /* round 12: */
            s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48];
            s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49];
            s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50];
            s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51];
            /* round 13: */
            t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52];
            t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53];
            t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54];
            t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55];
        }
    }
    rk += key->rounds << 2;
#else  /* !FULL_UNROLL */
    /*
     * Nr - 1 full rounds:
     */
    r = key->rounds >> 1;
    for (;;) {
        t0 =
            Te0[(s0 >> 24)       ] ^
            Te1[(s1 >> 16) & 0xff] ^
            Te2[(s2 >>  8) & 0xff] ^
            Te3[(s3      ) & 0xff] ^
            rk[4];
        t1 =
            Te0[(s1 >> 24)       ] ^
            Te1[(s2 >> 16) & 0xff] ^
            Te2[(s3 >>  8) & 0xff] ^
            Te3[(s0      ) & 0xff] ^
            rk[5];
        t2 =
            Te0[(s2 >> 24)       ] ^
            Te1[(s3 >> 16) & 0xff] ^
            Te2[(s0 >>  8) & 0xff] ^
            Te3[(s1      ) & 0xff] ^
            rk[6];
        t3 =
            Te0[(s3 >> 24)       ] ^
            Te1[(s0 >> 16) & 0xff] ^
            Te2[(s1 >>  8) & 0xff] ^
            Te3[(s2      ) & 0xff] ^
            rk[7];

        rk += 8;
        if (--r == 0) {
            break;
        }

        s0 =
            Te0[(t0 >> 24)       ] ^
            Te1[(t1 >> 16) & 0xff] ^
            Te2[(t2 >>  8) & 0xff] ^
            Te3[(t3      ) & 0xff] ^
            rk[0];
        s1 =
            Te0[(t1 >> 24)       ] ^
            Te1[(t2 >> 16) & 0xff] ^
            Te2[(t3 >>  8) & 0xff] ^
            Te3[(t0      ) & 0xff] ^
            rk[1];
        s2 =
            Te0[(t2 >> 24)       ] ^
            Te1[(t3 >> 16) & 0xff] ^
            Te2[(t0 >>  8) & 0xff] ^
            Te3[(t1      ) & 0xff] ^
            rk[2];
        s3 =
            Te0[(t3 >> 24)       ] ^
            Te1[(t0 >> 16) & 0xff] ^
            Te2[(t1 >>  8) & 0xff] ^
            Te3[(t2      ) & 0xff] ^
            rk[3];
    }
#endif /* ?FULL_UNROLL */
    /*
* apply last round and
* map cipher state to byte array block:
*/
s0 =
(Te2[(t0 >> 24)       ] & 0xff000000) ^
(Te3[(t1 >> 16) & 0xff] & 0x00ff0000) ^
(Te0[(t2 >>  8) & 0xff] & 0x0000ff00) ^
(Te1[(t3      ) & 0xff] & 0x000000ff) ^
rk[0];
PUTU32(out     , s0);
s1 =
(Te2[(t1 >> 24)       ] & 0xff000000) ^
(Te3[(t2 >> 16) & 0xff] & 0x00ff0000) ^
(Te0[(t3 >>  8) & 0xff] & 0x0000ff00) ^
(Te1[(t0      ) & 0xff] & 0x000000ff) ^
rk[1];
PUTU32(out +  4, s1);
s2 =
(Te2[(t2 >> 24)       ] & 0xff000000) ^
(Te3[(t3 >> 16) & 0xff] & 0x00ff0000) ^
(Te0[(t0 >>  8) & 0xff] & 0x0000ff00) ^
(Te1[(t1      ) & 0xff] & 0x000000ff) ^
rk[2];
PUTU32(out +  8, s2);
s3 =
(Te2[(t3 >> 24)       ] & 0xff000000) ^
(Te3[(t0 >> 16) & 0xff] & 0x00ff0000) ^
(Te0[(t1 >>  8) & 0xff] & 0x0000ff00) ^
(Te1[(t2      ) & 0xff] & 0x000000ff) ^
rk[3];
PUTU32(out + 12, s3);
}


[/font]
« Last Edit: October 04, 2013, 05:58:15 am by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: DCPcrypt: encrypting with plain key
« Reply #10 on: October 04, 2013, 06:15:11 am »
errm forget it try to make the cooperation with dcpcrypt and openssl work or change the embedded library to something else there are 2 other libraries for encryption that I know of but I do not know how well they cooperate with openssl or if they are compatible with freepascal/lazarus for that matter.

1) TurboPower LockBox https://sourceforge.net/projects/tplockbox
2) Open StreamSec Tools 2.1.x http://sourceforge.net/projects/openstrsecii/

as far as I understand the problems between cooperation in libraries come from the password it self rather than differences in the encryption / decryption algorithms. For example in one library the if the password size is different from the expected then null characters are appended and on the other library a hash is calculated for the given password and part of it or all is used.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: DCPcrypt: encrypting with plain key
« Reply #11 on: October 04, 2013, 06:25:32 am »
errm forget it try to make the cooperation with dcpcrypt and openssl work ...
The task is in next. I have some encrypted files by some third-party application. I need decrypt them programmatically (I can do this by hands). By decompiling and reversing third-party application by OllyDBG, I learned decryption by hends and   I  made work my project with libeay32.dll . But as I said I need not full libeay32.dll. So this library just fill harddrive by 95%. Besides , many binary files is VERY VERY inconvenient. Single executable is best!

errm forget it
Why I must forget it? Conversion is possible.
« Last Edit: October 04, 2013, 06:29:37 am by anna »
WinXP SP3 Pro Russian 32-bit (5.1.2600)

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: DCPcrypt: encrypting with plain key
« Reply #12 on: October 04, 2013, 06:51:59 am »
try one of the other libraries I posted I think that your best bet for openssl compatibility is the sreamsec library.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

anna

  • Sr. Member
  • ****
  • Posts: 426
Re: DCPcrypt: encrypting with plain key
« Reply #13 on: October 05, 2013, 02:04:18 pm »
... sreamsec library.

Inside zip-archive only one file of 3kB StrSecInit.pas whith no implementation of any function. Of course, it does not even compiled. So what should I do with it?
WinXP SP3 Pro Russian 32-bit (5.1.2600)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: DCPcrypt: encrypting with plain key
« Reply #14 on: October 05, 2013, 02:56:12 pm »
Inside zip-archive only one file of 3kB StrSecInit.pas whith no implementation of any function. Of course, it does not even compiled. So what should I do with it?

You've downloaded only the patch.

 

TinyPortal © 2005-2018