Ga naar inhoud


Aanbevolen berichten

Geplaatst:

Dit vond ik ergens op een upload service. Misschien is dit relevant:

 

Salut

Recuperer sur Foro Estudios Digtales

 

Algorithme Seca2

 

Auteur du message

FERES

 

24/09/02

 

Pour ce que je me suis informer ceci est l'algo utiliser par le Seca2

Je m'en suis mis jusqu'aux narines a l'analizer pour le tester

J'aimerais partager cette information avec quelqu'un qui si entend plus que moi et qui pourrais me donner un coup de main

En y jetant un coup d'oeil rapide il me semble que ces l'algo utiliser par Seca1 mais je n'en suis pas sur

On va voir si on ressort quelque chose

 

J'ai simplifier l'algorithme tous en maintenant son fonctionnement j'ai utiliser M_K_F pour verifier que l'algo continu a marcher comme l'original

 

Il en est resorti un code source beaucoup plus simple et qui est equivalant a l'original. Le resultat est que maintenant on peut comprendre et dire que

il est facile de voir la relation entre l' encryption et la desencryption et que la desencryption est le processus inverse de l'encryption

 

Note: pour moi il est evident que l'algo se dessine originalement suivant les pas que je vais d'ecrire plus bas et que c'est pas son vraiment simple

L'apparante complexite de l'algo decrit par John Mackdonald se doit au processus de reverse ingenering et qu'il a ete publier tel quel sans voir ce qu'il y avait au fond de cet algo.

 

Description

Dans cet algo il y a deux routines publiees la routine encrypt et la routine decrypt, pretendu une l'inverse de l'autre

ces routines recevant comme premier parametre une clees de 16 bits puis le second parametre une de 8 bits codifie/decodifie

La premiere chose que fontt ces routines sont de preparees la clee le processus est le meme dans chaque routine

Cette preparation se base a obtenir a partir de la clee de 16 bit une nouvelle clee de 64 bit cette clee et celle utilisee pour encrypter/desencrypter

Pour ceci dans le code plus bas la clee doit se situer dans les premier 16 bit d'un buffer de 80 bit

la preparation de la clee utilisera les 64 bit restants du buffer

 

Note: a partir de maintenant je nommerais 'clave' les 64 bits

 

//-----------------------------------------------

void encript(unsigned char *k,unsigned char *d)

{

prepara_clave(k);//a partir de 16bit, genere 64.

k += 16; //note le commencement de la clee 64 bits.

for(int i=0 ; i menor_que 16 ; ++ i) { //parcours les 64 bits de 4 en 4

nucleo(k, d);

swap_4bytes(d);

k += 4;

}

swap_4bytes(d); //casse l'ultime swap

}

//-----------------------------------------------

void decript(unsigned char *k,unsigned char *d)

{

prepara_clave(k); //a partir de 16bit, genere 64.

k += 80; //note le commencement de la clee 64 bits

for(int i=0 ; i menor_que 16 ; ++ i) { //parcours les 64 bits de 4 en 4

k -= 4;

nucleo(k, d);

swap_4bytes(d);

}

swap_4bytes(d); //casse l'ultime swap

}

//-----------------------------------------------

 

 

Comme vous pouvez le voir dans le code la preparation de la clee est indentique ( meme fonction ) dans chaque routines

L'application de la clee est tres similere pour encrypter se recupere du debut de la clee jusqu'a la fin pour desencrypter de la fin de la clee jusqu'au debut

Dans chaque cas il y a 16 iteracion et dans chaque iteration s'utilise 4bits de la clee

On voit clairement qu'un processus et l'inverse de l'autre

Autant pour encrypter que pour desencrypter dans chaque pas ça s'applique sur la sequence de 8bits ( DW ou CW respectivement) la fonction 'nucleo'

et apres s'interchange les quatre bit haut et les quatre bit bas de la dite sequence (function swap_4bytes)

 

Note: maintenant j'appelerais 'dato' les 8byts de la sequence CW ou DW

 

La premiere chose qui attire l'attention c'est que la fonction 'nucleo' est la meme

autant pour encrypter que pour desencrypter d'ou l'on peut deduire que la fonction 'nucleo' appliquer deux fois sur un 'dato'

revient au meme 'dato'

 

Si nucleo(A)=B alors nucleo(B)=A

 

Mais dans chaque pas apres 'nucleo' se fait un swap ceci provoque que le dato evolue A1 -> A2-> A3

Ou bien si l'on dit que nucleo(A1)=B1 et swap(B1)=A2,......

ça donnerais A1->B1->A2->B2->A3->B3->A4->B4->,.....

C'est a dire :

paso 1: A1->B1->A2

paso 2: A2->B2->A3

 

.........

 

Comme dans le dernier pas il ne se fait pas le swap (plus concretement se fait et ce defait) l'operation se termine avec B16 (non avec A17)

Donc au decrypt : nucleo(B16)=A16 et swap(A16)=B15,.....

le chemin inverse jusqu'a A1

 

Si on met le code d'encrypt et decrypt a la suite l'un de l'autre

(considerant prepare la clee) on voit que les 16 pas de decrypt sont exactement les memes pas que l'encrypt pris a l'envers

 

//---------------------------------

for(i=0; i menor_que 16 ; ++ i) {

nucleo(k, d);

swap_4bytes(d);

k += 4;

}

 

swap_4bytes(d);

 

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

nucleo(k, d);

swap_4bytes(d);

}

//---------------------------------

 

Voyons la fonction nucleo cette fonction transforme une donne de 8bit, utilisant une clee (une portion de clee) de quatre bit

 

Plus concretement la fonction nucleo utilise les quatres bit haut de la donnee et les quatre bits de la clee pour modifier

les quatre bits bas de la donnee

La fonction clee ne modifie pas les quatre bits haut de la donnee

 

 

//-----------------------------------------------------

static void nucleo(unsigned char *k, unsigned char *d)

{

unsigned int D[4];

 

D[0] = T1[d[4] ^ k[0] ];

D[1] = T1[d[5] ^ k[1]];

D[2] = T1[d[6] ^ k[2]];

D[3] = T1[d[7] ^ k[3]];

 

D[0] ^= D[3];

D[2] = T2[sN(D[3])+D[2]];

 

D[3] ^= D[2];

D[1] = T2[sN(D[2])+D[1]];

 

D[2] ^= D[1];

D[0] = T2[sN(D[1])+D[0] ];

 

D[1] ^= D[0] ;

D[3] = T1[sN(D[0] )+D[3]];

 

D[0] ^= D[3];

D[2] = T1[sN(D[3])+D[2]];

 

D[3] ^= D[2];

D[1] = T1[sN(D[2])+D[1]];

 

D[2] ^= D[1];

D[1] ^= D[0] ;

 

d[0] ^= T2[D[1]];

d[1] ^= T2[D[3]];

d[2] ^= T2[D[0] ];

d[3] ^= T2[D[2]];

}

//----------------------------------------------------

 

Comme l'on voit la fonction modifie seulement d[0]....... d[3]

et le fait dans les quatres derniere instruction avec un xor

 

Mais on sait que si XOR(A)=B donc XOR(B)=A

et ceci est indispensable pour que la fonction clee soit reversible

 

Si on reecrit la fonction nucleo ainsi:

 

void nucleo(unsigned char *k, unsigned char *d)

{

d[0] ^= f1(k,d[4-7]);

d[1] ^= f2(k,d[4-7]);

d[2] ^= f3(k,d[4-7]);

d[3] ^= f4(k,d[4-7]);

}

 

L'algorithme fonctionnera bien les fonctions encrypt et decrypt seront chacune l'inverse de l'autre

independament de la nature des fonctions f1..f4

 

De ceci nous deduisons que le contenue de T1 etT2 nous importe peu ni si l'existence de ces tables est necessaire

Quelque soit l'algo qui combine quatre bit de la clee et quatre bit de la donnee et obtient a partir de cela quatre autre bit

est un processus pseudoaleatoire ( apparament aleatoire mais reproductible) aurait la meme effectivite et serait pratiquement inataquable

 

Pour completer l'information j'ai copie les codes des fonctions auxiliaires

 

//-----------------------------------------------

#define SN(B) (((b shift_der 4)&15) | ((b shift_izq 4)&15))

static void prepara_clave(unsigned char * k)

{

int i, C;

 

for(C=0 ; C menor_que 16 ; ++C ){

for(i=4;i--

{

k[16] = k[0] ^ T1[k[15] ^ k[1] ^ C];

k += 1;

}

}

}

void swap_4bytes(unsigned char *d)

{

unsigned char temp[4];

memcpy(temp, d, 4);

memcpy(d, d + 4, 4);

memcpy(d + 4, temp, 4);

}

//-----------------------------------------------

 

De plus a la fonction nucleo il faut ajouter un & 255

avant d'indexer les tables T1 etT2

 

... T2[(SN(D[3])+D[2]) & 255];

... T2[(SN(D[2])+D[1]) & 255];

........

 

Avec ça ces codes sont parfaitement utilisable

 

A partir du document original de john macdonnald

 

//////////////////////////////////////////////////////

// DECLARACIONES

//////////////////////////////////////////////////////

 

/*

MODULO SECAES,

desarrollado por:

gabino gabinoes : Junio 2002.

 

Modulo para encriptar y desencriptar a alta velocidad.

 

Usa este módulo tal cual está, no realices ningún cambio

sin comprobar cómo afecta a la velocidad.

 

Compila con Visual C++

 

Usa las siguientes opciones de compilación:

 

- Optimiza velocidad Maximize speed (por defecto en Release).

- Inline expansion: Any Suitable (no la pone por defecto)

- Excepcion handling: Disable (no la pone por defecto)

 

*/

#ifndef _SECAES_H_

#define _SECAES_H_

 

/*____________________________________________________________

rutina que inicializa tablas

 

Llama a esta rutina una sola vez, al comienzo del programa.

*/

void initabs();

 

/*____________________________________________________________

rutina de encriptacion

k=clave de 128 bits (16 bytes), no modifica la clave

d=datos de 64 bits (8 bytes) (entrada y salida)

 

ATENCION : el array que contine la clave debe tener

un tamaño mínimo de 80 bytes, en los 16

primeros se situa la clave, el resto son

usados por esta funcion.

 

ATENCION : el array que contine la CW/DW debe tener

un tamaño mínimo de 80 bytes, en los 8

primeros se situa la CW/DW, el resto son

usados por esta funcion.

 

unsigned char k[80] => clave primaria+secundaria

unsigned char d[80] => en la llamada DW, tras el retorno CW

*/

void encript(unsigned char *k,unsigned char *d);

 

/*____________________________________________________________

rutina de desencriptado

k=clave de 128 bits (16 bytes), deja la clave intacta

d=datos de 64 bits (8 bytes) (entrada y salida)

 

ATENCION : el array que contine la clave debe tener

un tamaño mínimo de 80 bytes, en los 16

primeros se situa la clave, el resto son

usados por esta funcion.

 

ATENCION : el array que contine CW/DW debe tener

un tamaño mínimo de 80 bytes, en los 8

primeros se situa la CW/DW, el resto son

usados por esta funcion.

 

unsigned char k[80] => clave primaria+resundaria

unsigned char d[80] => en la llamada CW, tras el retorno DW

*/

void decript(unsigned char *k,unsigned char *d);

 

/*____________________________________________________________

rutina de encriptado doble

k=clave de 128 bits (16 bytes), deja la clave intacta

d=datos de 64 bits (8 bytes) (entrada y salida)

 

ATENCION : el array que contine la clave debe tener

un tamaño mínimo de 80 bytes, en los 16

primeros se situa la clave, el resto son

usados por esta funcion.

 

ATENCION : el array que contine la CW/DW debe tener

un tamaño mínimo de 80 bytes, en los 8

primeros se situa la CW/DW, el resto son

usados por esta funcion.

 

unsigned char k[80] => clave primaria+resundaria

unsigned char d[80] => en la llamada DW, tras el retorno CW

*/

void encript2(unsigned char *k,unsigned char *d);

 

/*____________________________________________________________

rutina de desencriptado doble

k=clave de 128 bits (16 bytes), deja la clave intacta

d=datos de 64 bits (8 bytes) (entrada y salida)

 

ATENCION : el array que contine la clave debe tener

un tamaño mínimo de 80 bytes, en los 16

primeros se situa la clave, el resto son

usados por esta funcion.

 

ATENCION : el array que contine la CW/DW debe tener

un tamaño mínimo de 80 bytes, en los 8

primeros se situa la CW/DW, el resto son

usados por esta funcion.

 

unsigned char k[80] => clave primaria+resundaria

unsigned char d[80] => en la llamada CW, tras el retorno DW

*/

void decript2(unsigned char *k,unsigned char *d);

 

#endif //_SECAES_H_

 

 

 

//////////////////////////////////////////////////////

// IMPLEMENTACION

//////////////////////////////////////////////////////

#include "stdafx.h"

#include "secaes.h"

 

//---------------------------------------------------

// IMPLEMENTACION

 

//SN solo se aplica sobre unsigned char

//#define SN(B) ((b shift_der 4) | (b shift_izq 4))

#define SN© tab_sn[c]

 

//no usado, de momento.

void initabs()

{

}

/*

ATENCION:

 

La funcion swap nibles (SN) usa

una tabla de 256 bytes. Esto evita tener que

usar los desplazamientos de bits, que son

bastante lentos.

 

Las tablas T1 y T2 se encuentrán

aquí duplicadas. Es decir que cada tabla contine

512 bytes, siendo los primeros 256 bytes iguales

a los siguientes 256. Esto se hace así para

ahorrar operaciones & 0xFF]

 

*/

 

static const unsigned char tab_sn[]={

0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,

0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,

0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,

0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,

0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,

0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,

0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,

0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,

0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,

0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,

0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,

0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,

0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,

0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,

0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,

0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,

0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,

0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,

0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,

0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,

0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,

0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,

0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,

0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,

0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,

0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,

0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,

0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,

0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,

0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,

0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,

0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF

};

//*/

static const unsigned char T1[]={

0x2a,0xe1,0x0b,0x13,0x3e,0x6e,0x32,0x48,

0xd3,0x31,0x08,0x8c,0x8f,0x95,0xbd,0xd0,

0xe4,0x6d,0x50,0x81,0x20,0x30,0xbb,0x75,

0xf5,0xd4,0x7c,0x87,0x2c,0x4e,0xe8,0xf4,

0xbe,0x24,0x9e,0x4d,0x80,0x37,0xd2,0x5f,

0xdb,0x04,0x7a,0x3f,0x14,0x72,0x67,0x2d,

0xcd,0x15,0xa6,0x4c,0x2e,0x3b,0x0c,0x41,

0x62,0xfa,0xee,0x83,0x1e,0xa2,0x01,0x0e,

0x7f,0x59,0xc9,0xb9,0xc4,0x9d,0x9b,0x1b,

0x9c,0xca,0xaf,0x3c,0x73,0x1a,0x65,0xb1,

0x76,0x84,0x39,0x98,0xe9,0x53,0x94,0xba,

0x1d,0x29,0xcf,0xb4,0x0d,0x05,0x7d,0xd1,

0xd7,0x0a,0xa0,0x5c,0x91,0x71,0x92,0x88,

0xab,0x93,0x11,0x8a,0xd6,0x5a,0x77,0xb5,

0xc3,0x19,0xc1,0xc7,0x8e,0xf9,0xec,0x35,

0x4b,0xcc,0xd9,0x4a,0x18,0x23,0x9f,0x52,

0xdd,0xe3,0xad,0x7b,0x47,0x97,0x60,0x10,

0x43,0xef,0x07,0xa5,0x49,0xc6,0xb3,0x55,

0x28,0x51,0x5d,0x64,0x66,0xfc,0x44,0x42,

0xbc,0x26,0x09,0x74,0x6f,0xf7,0x6b,0x4f,

0x2f,0xf0,0xea,0xb8,0xae,0xf3,0x63,0x6a,

0x56,0xb2,0x02,0xd8,0x34,0xa4,0x00,0xe6,

0x58,0xeb,0xa3,0x82,0x85,0x45,0xe0,0x89,

0x7e,0xfd,0xf2,0x3a,0x36,0x57,0xff,0x06,

0x69,0x54,0x79,0x9a,0xb6,0x6c,0xdc,0x8b,

0xa7,0x1f,0x90,0x03,0x17,0x1c,0xed,0xd5,

0xaa,0x5e,0xfe,0xda,0x78,0xb0,0xbf,0x12,

0xa8,0x22,0x21,0x3d,0xc2,0xc0,0xb7,0xa9,

0xe7,0x33,0xfb,0xf1,0x70,0xe5,0x17,0x96,

0xf8,0x8d,0x46,0xa1,0x86,0xe2,0x40,0x38,

0xf6,0x68,0x25,0x16,0xac,0x61,0x27,0xcb,

0x5b,0xc8,0x2b,0x0f,0x99,0xde,0xce,0xc5,

// repetimos

0x2a,0xe1,0x0b,0x13,0x3e,0x6e,0x32,0x48,

0xd3,0x31,0x08,0x8c,0x8f,0x95,0xbd,0xd0,

0xe4,0x6d,0x50,0x81,0x20,0x30,0xbb,0x75,

0xf5,0xd4,0x7c,0x87,0x2c,0x4e,0xe8,0xf4,

0xbe,0x24,0x9e,0x4d,0x80,0x37,0xd2,0x5f,

0xdb,0x04,0x7a,0x3f,0x14,0x72,0x67,0x2d,

0xcd,0x15,0xa6,0x4c,0x2e,0x3b,0x0c,0x41,

0x62,0xfa,0xee,0x83,0x1e,0xa2,0x01,0x0e,

0x7f,0x59,0xc9,0xb9,0xc4,0x9d,0x9b,0x1b,

0x9c,0xca,0xaf,0x3c,0x73,0x1a,0x65,0xb1,

0x76,0x84,0x39,0x98,0xe9,0x53,0x94,0xba,

0x1d,0x29,0xcf,0xb4,0x0d,0x05,0x7d,0xd1,

0xd7,0x0a,0xa0,0x5c,0x91,0x71,0x92,0x88,

0xab,0x93,0x11,0x8a,0xd6,0x5a,0x77,0xb5,

0xc3,0x19,0xc1,0xc7,0x8e,0xf9,0xec,0x35,

0x4b,0xcc,0xd9,0x4a,0x18,0x23,0x9f,0x52,

0xdd,0xe3,0xad,0x7b,0x47,0x97,0x60,0x10,

0x43,0xef,0x07,0xa5,0x49,0xc6,0xb3,0x55,

0x28,0x51,0x5d,0x64,0x66,0xfc,0x44,0x42,

0xbc,0x26,0x09,0x74,0x6f,0xf7,0x6b,0x4f,

0x2f,0xf0,0xea,0xb8,0xae,0xf3,0x63,0x6a,

0x56,0xb2,0x02,0xd8,0x34,0xa4,0x00,0xe6,

0x58,0xeb,0xa3,0x82,0x85,0x45,0xe0,0x89,

0x7e,0xfd,0xf2,0x3a,0x36,0x57,0xff,0x06,

0x69,0x54,0x79,0x9a,0xb6,0x6c,0xdc,0x8b,

0xa7,0x1f,0x90,0x03,0x17,0x1c,0xed,0xd5,

0xaa,0x5e,0xfe,0xda,0x78,0xb0,0xbf,0x12,

0xa8,0x22,0x21,0x3d,0xc2,0xc0,0xb7,0xa9,

0xe7,0x33,0xfb,0xf1,0x70,0xe5,0x17,0x96,

0xf8,0x8d,0x46,0xa1,0x86,0xe2,0x40,0x38,

0xf6,0x68,0x25,0x16,0xac,0x61,0x27,0xcb,

0x5b,0xc8,0x2b,0x0f,0x99,0xde,0xce,0xc5

};

static const unsigned char T2[]={

0xbf,0x11,0x6d,0xfa,0x26,0x7f,0xf3,0xc8,

0x9e,0xdd,0x3f,0x16,0x97,0xbd,0x08,0x80,

0x51,0x42,0x93,0x49,0x5b,0x64,0x9b,0x25,

0xf5,0x0f,0x24,0x34,0x44,0xb8,0xee,0x2e,

0xda,0x8f,0x31,0xcc,0xc0,0x5e,0x8a,0x61,

0xa1,0x63,0xc7,0xb2,0x58,0x09,0x4d,0x46,

0x81,0x82,0x68,0x4b,0xf6,0xbc,0x9d,0x03,

0xac,0x91,0xe8,0x3d,0x94,0x37,0xa0,0xbb,

0xce,0xeb,0x98,0xd8,0x38,0x56,0xe9,0x6b,

0x28,0xfd,0x84,0xc6,0xcd,0x5f,0x6e,0xb6,

0x32,0xf7,0x0e,0xf1,0xf8,0x54,0xc1,0x53,

0xf0,0xa7,0x95,0x7b,0x19,0x21,0x23,0x7d,

0xe1,0xa9,0x75,0x3e,0xd6,0xed,0x8e,0x6f,

0xdb,0xb7,0x07,0x41,0x05,0x77,0xb4,0x2d,

0x45,0xdf,0x29,0x22,0x43,0x89,0x83,0xfc,

0xd5,0xa4,0x88,0xd1,0xf4,0x55,0x4f,0x78,

0x62,0x1e,0x1d,0xb9,0xe0,0x2f,0x01,0x13,

0x15,0xe6,0x17,0x6a,0x8d,0x0c,0x96,0x7e,

0x86,0x27,0xa6,0x0d,0xb5,0x73,0x71,0xaa,

0x36,0xd0,0x06,0x66,0xdc,0xb1,0x2a,0x5a,

0x72,0xbe,0x3a,0xc5,0x40,0x65,0x1b,0x02,

0x10,0x9f,0x3b,0xf9,0x2b,0x18,0x5c,0xd7,

0x12,0x47,0xef,0x1a,0x87,0xd2,0xc2,0x8b,

0x99,0x9c,0xd3,0x57,0xe4,0x76,0x67,0xca,

0x3c,0xfb,0x90,0x20,0x14,0x48,0xc9,0x60,

0xb0,0x70,0x4e,0xa2,0xad,0x35,0xea,0xc4,

0x74,0xcb,0x39,0xde,0xe7,0xd4,0xa3,0xa5,

0x04,0x92,0x8c,0xd9,0x7c,0x1c,0x7a,0xa8,

0x52,0x79,0xf2,0x33,0xba,0x1f,0x30,0x9a,

0x00,0x50,0x4c,0xff,0xe5,0xcf,0x59,0xc3,

0xe3,0x0a,0x85,0xb3,0xae,0xec,0x0b,0xfe,

0xe2,0xab,0x4a,0xaf,0x69,0x6c,0x2c,0x5d,

// repetimos

0xbf,0x11,0x6d,0xfa,0x26,0x7f,0xf3,0xc8,

0x9e,0xdd,0x3f,0x16,0x97,0xbd,0x08,0x80,

0x51,0x42,0x93,0x49,0x5b,0x64,0x9b,0x25,

0xf5,0x0f,0x24,0x34,0x44,0xb8,0xee,0x2e,

0xda,0x8f,0x31,0xcc,0xc0,0x5e,0x8a,0x61,

0xa1,0x63,0xc7,0xb2,0x58,0x09,0x4d,0x46,

0x81,0x82,0x68,0x4b,0xf6,0xbc,0x9d,0x03,

0xac,0x91,0xe8,0x3d,0x94,0x37,0xa0,0xbb,

0xce,0xeb,0x98,0xd8,0x38,0x56,0xe9,0x6b,

0x28,0xfd,0x84,0xc6,0xcd,0x5f,0x6e,0xb6,

0x32,0xf7,0x0e,0xf1,0xf8,0x54,0xc1,0x53,

0xf0,0xa7,0x95,0x7b,0x19,0x21,0x23,0x7d,

0xe1,0xa9,0x75,0x3e,0xd6,0xed,0x8e,0x6f,

0xdb,0xb7,0x07,0x41,0x05,0x77,0xb4,0x2d,

0x45,0xdf,0x29,0x22,0x43,0x89,0x83,0xfc,

0xd5,0xa4,0x88,0xd1,0xf4,0x55,0x4f,0x78,

0x62,0x1e,0x1d,0xb9,0xe0,0x2f,0x01,0x13,

0x15,0xe6,0x17,0x6a,0x8d,0x0c,0x96,0x7e,

0x86,0x27,0xa6,0x0d,0xb5,0x73,0x71,0xaa,

0x36,0xd0,0x06,0x66,0xdc,0xb1,0x2a,0x5a,

0x72,0xbe,0x3a,0xc5,0x40,0x65,0x1b,0x02,

0x10,0x9f,0x3b,0xf9,0x2b,0x18,0x5c,0xd7,

0x12,0x47,0xef,0x1a,0x87,0xd2,0xc2,0x8b,

0x99,0x9c,0xd3,0x57,0xe4,0x76,0x67,0xca,

0x3c,0xfb,0x90,0x20,0x14,0x48,0xc9,0x60,

0xb0,0x70,0x4e,0xa2,0xad,0x35,0xea,0xc4,

0x74,0xcb,0x39,0xde,0xe7,0xd4,0xa3,0xa5,

0x04,0x92,0x8c,0xd9,0x7c,0x1c,0x7a,0xa8,

0x52,0x79,0xf2,0x33,0xba,0x1f,0x30,0x9a,

0x00,0x50,0x4c,0xff,0xe5,0xcf,0x59,0xc3,

0xe3,0x0a,0x85,0xb3,0xae,0xec,0x0b,0xfe,

0xe2,0xab,0x4a,0xaf,0x69,0x6c,0x2c,0x5d

};

//---------------------------------------------------------

//Esto te va a parecer raro, pero así es más rápido, esta

//curiosa division de funciones ayuda a la optimización que

//hace Visual C++, V6 (no se ha probado con otras versiones)

//---------------------------------------------------------

// modifica 4 bytes en D con 4 bytes de clave en k

static unsigned int D[4];

static void fase()

{

D[0] ^= D[3];

 

D[3] ^= D[2] = T2[sN(D[3])+D[2]];

D[2] ^= D[1] = T2[sN(D[2])+D[1]];

D[1] ^= D[0] = T2[sN(D[1])+D[0]];

 

D[0] ^= D[3] = T1[sN(D[0])+D[3]];

D[3] ^= D[2] = T1[sN(D[3])+D[2]];

D[2] ^= D[1] = T1[sN(D[2])+D[1]];

 

D[1] ^= D[0];

}

 

static void fase(unsigned char *k, unsigned int *D, unsigned char *d)

{

D[0] = T1[d[4] ^ k[0]];

D[1] = T1[d[5] ^ k[1]];

D[2] = T1[d[6] ^ k[2]];

D[3] = T1[d[7] ^ k[3]];

 

fase();

 

d[8] = d[0] ^ T2[D[1]];

d[9] = d[1] ^ T2[D[3]];

d[10] = d[2] ^ T2[D[0]];

d[11] = d[3] ^ T2[D[2]];

}

 

static void fase(unsigned char *k,unsigned char *d)

{

fase(k, D, d);

}

//-----------------------------------------------

//trabaja sobre un buffer de 80 bytes, usa la

//clave de 16 bytes para generar otra de 64

static void prepara_clave(unsigned char * k)

{

int i, C;

 

for(C = 0 ; C menor_que 16 ; ++C)

{

for(i=4;i--

{

k[16] = k[0] ^ T1[k[15] ^ k[1] ^ C];

k += 1;

}

}

}

//-----------------------------------------------

//funcion pública

void encript(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k);

k += 16;

for(i=0 ; i menor_que 16 ; ++ i) {

fase(k, d);

k += 4;

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

 

//-----------------------------------------------

//funcion pública

void decript(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k);

k += 80;

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

fase(k, d);

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

//-----------------------------------------------

//funcion pública

void decript2(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k); //solo una vez !

 

k += 80;

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

fase(k, d);

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

 

k += 64;

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

fase(k, d);

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

//-----------------------------------------------

//funcion pública

void encript2(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k); //solo una vez !

k += 16;

 

for(i=0 ; i menor_que 16 ; ++ i) {

fase(k, d);

k += 4;

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

 

k -= 64;

for(i=0 ; i menor_que 16 ; ++ i) {

fase(k, d);

k += 4;

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

 

 

Traduit a la volee, des fois je me melange les pinceaux entre les deux langues Sorry

A+

Mabuse

 

Wilde dit niet vertalen aangezien dit de code eventueel kan beschadigen...

 

Groetjes,

 

Nightshad


Geplaatst:

Wat dacht je van zelf de text omzetten naar engels maar niet aan de nummertjes komen.

Ik vind het een wijze beslissing die genomen is door het origineel te laten.

Kan ik de url in mijn pm krijgen?

 

gr cb1

Geplaatst:

Voor de geïnteresseerden, ik wil de vertaling deze voormiddag wel doen.

 

 

Geplaatst:

@Freelord,

 

Dit betekend dus Sourcecode .... het is verstandig deze text niet in zijn geheel door een vertaal machine te halen daar anders de source code verkloot zal worden, ik hoop dat azazel hier snel eens naar kan kijken, echter ben ik bang dat zonder de includes en headers er weinig mee te doen is ....

Geplaatst:

Ok hier volgt al het eerste deel:

 

Er is toch wel degelijk iemand geïnteresseerd in de vertaling ? Zoniet moet ik de rest niet meer vertalen. <img src="/ubbthreads/images/icons/cool.gif" alt="" />

 

Salut

Recuperer sur Foro Estudios Digtales

*Gehaald van ….

Algorithme Seca2

 

Auteur du message

*Auteur van het bericht

FERES

 

24/09/02

 

Pour ce que je me suis informer ceci est l'algo utiliser par le Seca2

Je m'en suis mis jusqu'aux narines a l'analizer pour le tester

J'aimerais partager cette information avec quelqu'un qui si entend plus que moi et qui pourrais me donner un coup de main

En y jetant un coup d'oeil rapide il me semble que ces l'algo utiliser par Seca1 mais je n'en suis pas sur

On va voir si on ressort quelque chose

 

*Voor zover ik ingelicht ben, is dit de algo gebruikt door Seca2

Ik heb mij uitgesloofd om te analiseren en te testen maar ik wil deze info delen zodat iemand met meer kennis mij een handje kan toesteken. Op het eerste zicht lijkt mij dit de algo van seca1, maar ik ben er niet zeker van.

We zien wel of er iets van komt.

 

J'ai simplifier l'algorithme tous en maintenant son fonctionnement j'ai utiliser M_K_F pour verifier que l'algo continu a marcher comme l'original

*Ik heb het algo vereenvoudigd met behoud van de werking. Ik heb M_K_F gebruikt

om te verifiëren of het algo blijft werken zoals het origineel.

 

Il en est resorti un code source beaucoup plus simple et qui est equivalant a l'original. Le resultat est que maintenant on peut comprendre et dire que

il est facile de voir la relation entre l' encryption et la desencryption et que la desencryption est le processus inverse de l'encryption

*Het resultaat is een broncode die veel eenvoudiger is en equivalent aan het

origineel. Het resultaat is dat we nu begrijpen en kunnen zeggen dat het

gemakkelijk is om de relatie tussen de encryptie en de desencryptie en dat de

desencryptie is het omgekeerde proces van de encryptie.

 

Note: pour moi il est evident que l'algo se dessine originalement suivant les pas que je vais d'ecrire plus bas et que c'est pas son vraiment simple

L'apparante complexite de l'algo decrit par John Mackdonald se doit au processus de reverse ingenering et qu'il a ete publier tel quel sans voir ce qu'il y avait au fond de cet algo.

*Opmerking : voor mij is het overduidelijk dat het algo zich ontwikkelt volgens

onderstaande stappen en deze stappen zijn echt simpel. De schijnbare complexiteit

van het algo zoals beschreven door John Mackdonald is te wijten aan het proces van

reverse enginering en was gepubliceerd zonder te kijken wat er aan de basis van het

algo ligt.

 

 

Description

Dans cet algo il y a deux routines publiees la routine encrypt et la routine decrypt, pretendu une l'inverse de l'autre

ces routines recevant comme premier parametre une clees de 16 bits puis le second parametre une de 8 bits codifie/decodifie

La premiere chose que fontt ces routines sont de preparees la clee le processus est le meme dans chaque routine

Cette preparation se base a obtenir a partir de la clee de 16 bit une nouvelle clee de 64 bit cette clee et celle utilisee pour encrypter/desencrypter

Pour ceci dans le code plus bas la clee doit se situer dans les premier 16 bit d'un buffer de 80 bit la preparation de la clee utilisera les 64 bit restants du buffer

Note: a partir de maintenant je nommerais 'clave' les 64 bits

 

*Beschrijving :

In dit algo worden 2 routines beschreven, de encryptie routine en de decryptie routine. Zoals beweerd dat het ene de inversie van het andere is, krijgen deze routines als eerste parameter een key van 16 bits en dan de tweede parameter een van 8 gecodeerde/gedecodeerde bits.

Het eerste wat die routines doen is de key voorbereiden. Het proces is hetzelfde voor elke routine

Deze voorbereiding baseert zich op het verkrijgen van de key van 16 bit een een nieuwe key van 64 bit. Deze key wordt gebruikt voor de encryptie/decryptie

In de onderstaande code de key situeert zich dus in de 16 bit van een buffer van 80 bit. De voorbereiding van de key zal dus de 64 resterende bit gebruiken.

Opmerking : vanaf nu zal ik de 64bit de CODE noemen

 

 

Rest volgt

 

Geplaatst:

Hallo satvrienden,

 

Tsjonge, tsjonge... dit gaat supersnel.

Ik heb dit pas gepost op 'foro estudios digitales' en 'feres' is een van mijn nicks, die gebruik ik op die forum.

Ik zou zeggen kom gerust even een kijkje nemen op estudios digitales, daar vind je meerdere 'collegas' van ons team. Deze forum gebruiken we ook als bron van communicatie onder ons. Dus er zijn zeker interessante dingen te vinden daar.

 

Nu even serieus...

 

@Freeloard, dit is inderdaad zoals Imagica al zegt Sourcecode, maar zoals ik al opmerkte lijkt dit verdacht veel op die van seca1. Ben nog steeds bezig met de studie, en het is flink wat worstelen als ik eerlijk ben.

Overigens dit is maar een klein gedeelte van de gehele 'tekst'.

 

@Imagica, heb wel enige includes en headers van de sourcecode, maar heb er nog niet veel uit kunnen halen. Ook 'collegas' zijn druk doende hiermee, maar zoals je ziet zijn er een aantal onbekende data waar we niet uit komen.

 

Ik heb overigens gedeeltes van algo reeds uitgelegd hier op het forum, zie berichten 19-09 algo seca2, en samenvatting uitleg.....

 

@PhilteDino, ga vooral door met de vertaling! Het zal voor een aantal mensen zeer interessant zijn om ook hier een studie naar te doen.

Als ik zie dat er serieus mee gewerkt gaat worden en dat er zeker interesse is, zal ik hierin wat dieper op ingaan en meerdere data vrijgeven.

Ps. bedankt als je het wil vertalen, bespaart mij in ieder geval zeer kostbare tijd.

 

Op 'estudios digitales' heb ik ook gevraagd naar mensen met ervaring hiermee, om een steentje bij te dragen hierin. Ook hier wil ik dezelfde vraag stellen. Gezien de vele pm'tjes die ik krijg zal ik wat betreft dit onderwerp alleen op serieuze en interessante vragen, ideen, etc.. antwoord kunnen geven.... Hoop dat jullie daar begrip voor hebben.

 

Als laatste, nogmaals, vele handen maken het werk lichter, alleen kan ik dit niet en gezien dat er hier veel mensen zijn die heel wat kennis hebben.......

 

 

Saludos!

 

'Azazel miembro del equipo RAIDEN, la resistencia.'

 

 

[color:"red"] LLORAMOS JUNTOS, GANAREMOS JUNTOS! [/color]
Geplaatst:

OEPS...... bijna vergeten...

 

Met dank aan asslab!!

 

 

Saludos!

 

'Azazel miembro del equipo RAIDEN, la resistencia.'

[color:"red"] LLORAMOS JUNTOS, GANAREMOS JUNTOS! [/color]
Geplaatst:

Zal ik helpen met de vertaling ?

Of is deze ondertussen al af ?

 

Kwestie dat we geen twee keer hetzelfde werk doen !

 

Geplaatst:

Hier dus effe de gehele vertaling helaas aleen in het engels maar dat kunnen de meesten wel lezen.

 

Hello

Recuperer on Foro Estudios Digtales

 

Seca2 algorithm

 

Author of the message

FERES

 

24/09/02

 

For what I am to inform this is the algo to use by Seca2

I put myself some to the nostrils has the analizer to test it

I would like to share this information with somebody who if hears more than me and who could give me a blow of hand

By there throwing a fast glance it seems to to me that the these algo to use by Seca1 but I am not on

One will see whether something is arisen

 

I have to simplify the algorithm all by maintaining his operation I have to use M_K_F for verifier that algo continuous A to walk like the original

 

It is resorti a source code much simpler and which is being equivalent the original has. The result is that now one can understand and say that

it is easy to see the relation between the encryption and the desencryption and that the desencryption is the opposite process of the encryption

 

Note: for me it is obvious that the algo takes shape in an original manner according to the steps which I will write low and who it is not his really simple

The apparante complexite of the algo decrit by John Mackdonald must with the process of reverse ingenering and which it has ete to publish just as it is without seeing what there was at the bottom of this algo.

 

Description

In this algo there are two routines publiees the routine encrypt and the routine decrypt, pretendu reverse of the other

these routines receiving like first parameter a clees of 16 bits then the second parameter one of 8 bits codifie/decodifie

The premiere thing that fontt these routines are of preparees the clee the process is the same one in each routine

This preparation is based has to obtain from the clee of 16 bit a news clee of 64 bit this clee and that utilisee for encrypter/desencrypter

For this in the lower code the clee must be located in the first 16 bit of a buffer of 80 bit

the preparation of the clee will use the 64 bit remainders of the buffer

 

Note: from now I would name ' clave' the 64 bits

 

/

void encript(unsigned tank * K, unsigned tank * d)

{

prepara_clave(k);//a to start from 16bit, genere 64.

K + = 16; note the beginning of the clee 64 bits.

for(int i=0; I menor_que 16; ++ i) {// course 64 bits of 4 in 4

nucleo(k, d);

swap_4bytes(d);

K + = 4;

}

swap_4bytes(d); breakage ultimate the swap

}

/

void decript(unsigned tank * K, unsigned tank * d)

{

prepara_clave(k); from 16bit, genere 64.

K + = 80; note the beginning of the clee 64 bits

for(int i=0; I menor_que 16; ++ i) {// course 64 bits of 4 in 4

K - = 4;

nucleo(k, d);

swap_4bytes(d);

}

swap_4bytes(d); breakage ultimate the swap

}

/

 

 

As you can see it in the code the preparation of the clee is indentic (same function) in each routines

The application of the clee is very similere for encrypter recupere beginning of the clee until A the end for desencrypter of the end of the clee until the beginning

In each case there is 16 iteracion and in each iteration 4bits clee is used

It is seen clearly that a process and the reverse of the other

As much for encrypter that for desencrypter in each step that applies to the sequence of 8bits (DW or CW respectively) the function ' nucleo'

and after interchanges the four high bit and the four low bit of the known as sequence (function swap_4bytes)

 

Note: now I appelerais ' dato' the 8byts of the sequence CW or DW

 

The premiere thing which draws the attention it is that the function ' nucleo' is the same one

as much for encrypter that for desencrypter of or one can deduire that the function ' nucleo' to twice apply to a ' dato'

returns to same ' the dato'

 

If nucleo(A)=B then nucleo(B)=A

 

But in each step after ' nucleo' a swap this is made causes that the dato evolves/moves A1 - > A2- > A3

Or if it is said that nucleo(A1)=B1 and swap(B1)=A2......

that would give A1- > B1- > A2- > B2- > A3- > B3- > A4- > B4- >.....

It is has to say:

paso 1: A1- > B1- > A2

paso 2: A2- > B2- > A3

 

.........

 

As in the last step it is not made the swap (more concretely is done and this defait) the operation finishes with B16 (not with A17)

Thus with the decrypt: nucleo(B16)=A16 and swap(A16)=B15.....

the way reverses until A A1

 

If one puts the code of encrypt and decrypt the continuation one of the other has

(considerant prepare the clee) it is seen that the 16 steps of decrypt are exactly the same steps that the encrypt taken has back

 

/

for(i=0; I menor_que 16; ++ i) {

nucleo(k, d);

swap_4bytes(d);

K + = 4;

}

 

swap_4bytes(d);

 

for(i=0; I menor_que 16; ++ i) {

K - = 4;

nucleo(k, d);

swap_4bytes(d);

}

/

 

Let us see the function nucleo this function transforms one gives 8bit, using a clee (a portion of clee) of four bit

 

More concretely the function nucleo uses the quatres high bit of the donnee and the four bits of the clee to modify

four low bits of the donnee

The function clee does not modify the four bits high of the donnee

 

 

/

static void nucleo(unsigned tank * K, unsigned tank * d)

{

unsigned int D[4 ];

 

D[0 ] = T1[d[4 ] ^ k[0 ] ];

D[1 ] = T1[d[5 ] ^ k[1 ] ];

D[2 ] = T1[d[6 ] ^ k[2 ] ];

D[3 ] = T1[d[7 ] ^ k[3 ] ];

 

D[0 ] ^ = D[3 ];

D[2 ] = T2[sN(D[3])+D[2 ] ];

 

D[3 ] ^ = D[2 ];

D[1 ] = T2[sN(D[2])+D[1 ] ];

 

D[2 ] ^ = D[1 ];

D[0 ] = T2[sN(D[1])+D[0 ] ];

 

D[1 ] ^ = D[0 ];

D[3 ] = T1[sN(D[0 ])+D[3 ] ];

 

D[0 ] ^ = D[3 ];

D[2 ] = T1[sN(D[3])+D[2 ] ];

 

D[3 ] ^ = D[2 ];

D[1 ] = T1[sN(D[2])+D[1 ] ];

 

D[2 ] ^ = D[1 ];

D[1 ] ^ = D[0 ];

 

d[0 ] ^ = T2[D[1 ] ];

d[1 ] ^ = T2[D[3 ] ];

d[2 ] ^ = T2[D[0 ] ];

d[3 ] ^ = T2[D[2 ] ];

}

/

 

As one sees the function modifies only d[0 ]....... d[3 ]

and the fact in the quatres derniere instruction with a xor

 

But it is known that if XOR(A)=B thus XOR(B)=A

and this is essential so that the function clee is reversible

 

If one reecrit the function nucleo as follows:

 

void nucleo(unsigned tank * K, unsigned tank * d)

{

d[0 ] ^ = f1(k, d[4-7 ]);

d[1 ] ^ = f2(k, d[4-7 ]);

d[2 ] ^ = f3(k, d[4-7 ]);

d[3 ] ^ = f4(k, d[4-7 ]);

}

 

The algorithm will function well the functions encrypt and decrypt will be each one the reverse of the other

independament of the nature of the functions f1..f4

 

Of this we deduisons that contained T1 etT2 imports us little nor if the existence of these tables is necessary

Some is the algo which combines four bit of the clee and four bit of the donnee and obtains from that four another bit

is a process pseudoaleatoire (apparament random but reproducible) would have same the effectivite and would be practically inataquable

 

To supplement information I have copy the codes of the auxiliary functions

 

/

# define SN(B) (((B shift_der 4) & 15) | ((B shift_izq 4) & 15))

static void prepara_clave(unsigned tank * K)

{

int I, C;

 

for(C=0; C menor_que 16; ++C) {

for(i=4;i --

{

k[16 ] = k[0 ] ^ T1[k[15 ] ^ k[1 ] ^ C ];

K + = 1;

}

}

}

void swap_4bytes(unsigned tank * d)

{

unsigned tank temp[4 ];

memcpy(temp, D, 4);

memcpy(d, D + 4, 4);

memcpy(d + 4, temp, 4);

}

/

 

Moreover the function nucleo it has is necessary to add one & 255

before indexing tables T1 etT2

 

... T2[(SN(D[3])+D[2 ]) & 255 ];

... T2[(SN(D[2])+D[1 ]) & 255 ];

........

 

With that these codes are perfectly usable

 

From the original document of John macdonnald

 

/

// DECLARACIONES

/

 

/*

MODULO SECAES,

desarrollado por:

gabino gabinoes: Junio 2002.

 

Modulo para encriptar y desencriptar has Alta velocidad.

 

The USA este módulo tal cual está, No realices ningún cambio

sin comprobar cómo afecta has the velocidad.

 

Idiot Visual C++ compiled

 

The USA mow siguientes opciones of compilación:

 

- Optimiza velocidad Maximize speed (por defecto in Release).

- Inline expansion: Any Suitable (No the pone por defecto)

- Excepcion handling: Sayable (No the pone por defecto)

 

*/

# ifndef _ SECAES_H _

# define _ SECAES_H _

 

/*____________________________________________________________

rutina that inicializa counted

 

Llama has esta rutina una sola vez, Al comienzo LED programa.

*/

void initabs();

 

/*____________________________________________________________

rutina of encriptacion

k=clave of 128 bits (16 bytes), No modifica the clave

d=datos of 64 bits (8 bytes) (entrada y salida)

 

ATENCION: el array that contine the clave debe tener

a tamaño mínimo of 80 bytes, in los 16

primeros was located the clave, el restaurant sound

usados por esta funcion.

 

ATENCION: el array that contine the CW/DW debe tener

a tamaño mínimo of 80 bytes, in los 8

primeros was located the CW/DW, el restaurant sound

usados por esta funcion.

 

unsigned tank k[80 ] = > clave primaria+secundaria

unsigned tank d[80 ] = > in llamada DW, will tras el retorno CW

*/

void encript(unsigned tank * K, unsigned tank * d);

 

/*____________________________________________________________

rutina of desencriptado

k=clave of 128 bits (16 bytes), already the clave intacta

d=datos of 64 bits (8 bytes) (entrada y salida)

 

ATENCION: el array that contine the clave debe tener

a tamaño mínimo of 80 bytes, in los 16

primeros was located the clave, el restaurant sound

usados por esta funcion.

 

ATENCION: el array that contine CW/DW debe tener

a tamaño mínimo of 80 bytes, in los 8

primeros was located the CW/DW, el restaurant sound

usados por esta funcion.

 

unsigned tank k[80 ] = > clave primaria+resundaria

unsigned tank d[80 ] = > in the llamada CW, will tras el retorno DW

*/

void decript(unsigned tank * K, unsigned tank * d);

 

/*____________________________________________________________

rutina of encriptado doble

k=clave of 128 bits (16 bytes), already the clave intacta

d=datos of 64 bits (8 bytes) (entrada y salida)

 

ATENCION: el array that contine the clave debe tener

a tamaño mínimo of 80 bytes, in los 16

primeros was located the clave, el restaurant sound

usados por esta funcion.

 

ATENCION: el array that contine the CW/DW debe tener

a tamaño mínimo of 80 bytes, in los 8

primeros was located the CW/DW, el restaurant sound

usados por esta funcion.

 

unsigned tank k[80 ] = > clave primaria+resundaria

unsigned C *** TRANSLATION ENDS HERE ***har d[80] => en la llamada DW, tras el retorno CW

*/

void encript2(unsigned char *k,unsigned char *d);

 

/*____________________________________________________________

rutina de desencriptado doble

k=clave de 128 bits (16 bytes), deja la clave intacta

d=datos de 64 bits (8 bytes) (entrada y salida)

 

ATENCION : el array que contine la clave debe tener

un tamaño mínimo de 80 bytes, en los 16

primeros se situa la clave, el resto son

usados por esta funcion.

 

ATENCION : el array que contine la CW/DW debe tener

un tamaño mínimo de 80 bytes, en los 8

primeros se situa la CW/DW, el resto son

usados por esta funcion.

 

unsigned char k[80] = > clave primaria+resundaria

unsigned char d[80] = > en la llamada CW, tras el retorno DW

*/

void decript2(unsigned char *k,unsigned char *d);

 

#endif //_SECAES_H_

 

 

 

//////////////////////////////////////////////////////

// IMPLEMENTACION

//////////////////////////////////////////////////////

#include "stdafx.h"

#include "secaes.h"

 

//---------------------------------------------------

// IMPLEMENTACION

 

//SN solo se aplica sobre unsigned char

//#define SN(B) ((b shift_der 4) | (b shift_izq 4))

#define SN© tab_sn[c]

 

//no usado, de momento.

void initabs()

{

}

/*

ATENCION:

 

La funcion swap nibles (SN) usa

una tabla de 256 bytes. Esto evita tener que

usar los desplazamientos de bits, que son

bastante lentos.

 

Las tablas T1 y T2 se encuentrán

aquí duplicadas. Es decir que cada tabla contine

512 bytes, siendo los primeros 256 bytes iguales

a los siguientes 256. Esto se hace así para

ahorrar operaciones & 0xFF]

 

*/

 

static const unsigned char tab_sn[]={

0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,

0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,

0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,

0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,

0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,

0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,

0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,

0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,

0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,

0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,

0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,

0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,

0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,

0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,

0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,

0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,

0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,

0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,

0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,

0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,

0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,

0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,

0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,

0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,

0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,

0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,

0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,

0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,

0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,

0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,

0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,

0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF

};

//*/

static const unsigned char T1[]={

0x2a,0xe1,0x0b,0x13,0x3e,0x6e,0x32,0x48,

0xd3,0x31,0x08,0x8c,0x8f,0x95,0xbd,0xd0,

0xe4,0x6d,0x50,0x81,0x20,0x30,0xbb,0x75,

0xf5,0xd4,0x7c,0x87,0x2c,0x4e,0xe8,0xf4,

0xbe,0x24,0x9e,0x4d,0x80,0x37,0xd2,0x5f,

0xdb,0x04,0x7a,0x3f,0x14,0x72,0x67,0x2d,

0xcd,0x15,0xa6,0x4c,0x2e,0x3b,0x0c,0x41,

0x62,0xfa,0xee,0x83,0x1e,0xa2,0x01,0x0e,

0x7f,0x59,0xc9,0xb9,0xc4,0x9d,0x9b,0x1b,

0x9c,0xca,0xaf,0x3c,0x73,0x1a,0x65,0xb1,

0x76,0x84,0x39,0x98,0xe9,0x53,0x94,0xba,

0x1d,0x29,0xcf,0xb4,0x0d,0x05,0x7d,0xd1,

0xd7,0x0a,0xa0,0x5c,0x91,0x71,0x92,0x88,

0xab,0x93,0x11,0x8a,0xd6,0x5a,0x77,0xb5,

0xc3,0x19,0xc1,0xc7,0x8e,0xf9,0xec,0x35,

0x4b,0xcc,0xd9,0x4a,0x18,0x23,0x9f,0x52,

0xdd,0xe3,0xad,0x7b,0x47,0x97,0x60,0x10,

0x43,0xef,0x07,0xa5,0x49,0xc6,0xb3,0x55,

0x28,0x51,0x5d,0x64,0x66,0xfc,0x44,0x42,

0xbc,0x26,0x09,0x74,0x6f,0xf7,0x6b,0x4f,

0x2f,0xf0,0xea,0xb8,0xae,0xf3,0x63,0x6a,

0x56,0xb2,0x02,0xd8,0x34,0xa4,0x00,0xe6,

0x58,0xeb,0xa3,0x82,0x85,0x45,0xe0,0x89,

0x7e,0xfd,0xf2,0x3a,0x36,0x57,0xff,0x06,

0x69,0x54,0x79,0x9a,0xb6,0x6c,0xdc,0x8b,

0xa7,0x1f,0x90,0x03,0x17,0x1c,0xed,0xd5,

0xaa,0x5e,0xfe,0xda,0x78,0xb0,0xbf,0x12,

0xa8,0x22,0x21,0x3d,0xc2,0xc0,0xb7,0xa9,

0xe7,0x33,0xfb,0xf1,0x70,0xe5,0x17,0x96,

0xf8,0x8d,0x46,0xa1,0x86,0xe2,0x40,0x38,

0xf6,0x68,0x25,0x16,0xac,0x61,0x27,0xcb,

0x5b,0xc8,0x2b,0x0f,0x99,0xde,0xce,0xc5,

// repetimos

0x2a,0xe1,0x0b,0x13,0x3e,0x6e,0x32,0x48,

0xd3,0x31,0x08,0x8c,0x8f,0x95,0xbd,0xd0,

0xe4,0x6d,0x50,0x81,0x20,0x30,0xbb,0x75,

0xf5,0xd4,0x7c,0x87,0x2c,0x4e,0xe8,0xf4,

0xbe,0x24,0x9e,0x4d,0x80,0x37,0xd2,0x5f,

0xdb,0x04,0x7a,0x3f,0x14,0x72,0x67,0x2d,

0xcd,0x15,0xa6,0x4c,0x2e,0x3b,0x0c,0x41,

0x62,0xfa,0xee,0x83,0x1e,0xa2,0x01,0x0e,

0x7f,0x59,0xc9,0xb9,0xc4,0x9d,0x9b,0x1b,

0x9c,0xca,0xaf,0x3c,0x73,0x1a,0x65,0xb1,

0x76,0x84,0x39,0x98,0xe9,0x53,0x94,0xba,

0x1d,0x29,0xcf,0xb4,0x0d,0x05,0x7d,0xd1,

0xd7,0x0a,0xa0,0x5c,0x91,0x71,0x92,0x88,

0xab,0x93,0x11,0x8a,0xd6,0x5a,0x77,0xb5,

0xc3,0x19,0xc1,0xc7,0x8e,0xf9,0xec,0x35,

0x4b,0xcc,0xd9,0x4a,0x18,0x23,0x9f,0x52,

0xdd,0xe3,0xad,0x7b,0x47,0x97,0x60,0x10,

0x43,0xef,0x07,0xa5,0x49,0xc6,0xb3,0x55,

0x28,0x51,0x5d,0x64,0x66,0xfc,0x44,0x42,

0xbc,0x26,0x09,0x74,0x6f,0xf7,0x6b,0x4f,

0x2f,0xf0,0xea,0xb8,0xae,0xf3,0x63,0x6a,

0x56,0xb2,0x02,0xd8,0x34,0xa4,0x00,0xe6,

0x58,0xeb,0xa3,0x82,0x85,0x45,0xe0,0x89,

0x7e,0xfd,0xf2,0x3a,0x36,0x57,0xff,0x06,

0x69,0x54,0x79,0x9a,0xb6,0x6c,0xdc,0x8b,

0xa7,0x1f,0x90,0x03,0x17,0x1c,0xed,0xd5,

0xaa,0x5e,0xfe,0xda,0x78,0xb0,0xbf,0x12,

0xa8,0x22,0x21,0x3d,0xc2,0xc0,0xb7,0xa9,

0xe7,0x33,0xfb,0xf1,0x70,0xe5,0x17,0x96,

0xf8,0x8d,0x46,0xa1,0x86,0xe2,0x40,0x38,

0xf6,0x68,0x25,0x16,0xac,0x61,0x27,0xcb,

0x5b,0xc8,0x2b,0x0f,0x99,0xde,0xce,0xc5

};

static const unsigned char T2[]={

0xbf,0x11,0x6d,0xfa,0x26,0x7f,0xf3,0xc8,

0x9e,0xdd,0x3f,0x16,0x97,0xbd,0x08,0x80,

0x51,0x42,0x93,0x49,0x5b,0x64,0x9b,0x25,

0xf5,0x0f,0x24,0x34,0x44,0xb8,0xee,0x2e,

0xda,0x8f,0x31,0xcc,0xc0,0x5e,0x8a,0x61,

0xa1,0x63,0xc7,0xb2,0x58,0x09,0x4d,0x46,

0x81,0x82,0x68,0x4b,0xf6,0xbc,0x9d,0x03,

0xac,0x91,0xe8,0x3d,0x94,0x37,0xa0,0xbb,

0xce,0xeb,0x98,0xd8,0x38,0x56,0xe9,0x6b,

0x28,0xfd,0x84,0xc6,0xcd,0x5f,0x6e,0xb6,

0x32,0xf7,0x0e,0xf1,0xf8,0x54,0xc1,0x53,

0xf0,0xa7,0x95,0x7b,0x19,0x21,0x23,0x7d,

0xe1,0xa9,0x75,0x3e,0xd6,0xed,0x8e,0x6f,

0xdb,0xb7,0x07,0x41,0x05,0x77,0xb4,0x2d,

0x45,0xdf,0x29,0x22,0x43,0x89,0x83,0xfc,

0xd5,0xa4,0x88,0xd1,0xf4,0x55,0x4f,0x78,

0x62,0x1e,0x1d,0xb9,0xe0,0x2f,0x01,0x13,

0x15,0xe6,0x17,0x6a,0x8d,0x0c,0x96,0x7e,

0x86,0x27,0xa6,0x0d,0xb5,0x73,0x71,0xaa,

0x36,0xd0,0x06,0x66,0xdc,0xb1,0x2a,0x5a,

0x72,0xbe,0x3a,0xc5,0x40,0x65,0x1b,0x02,

0x10,0x9f,0x3b,0xf9,0x2b,0x18,0x5c,0xd7,

0x12,0x47,0xef,0x1a,0x87,0xd2,0xc2,0x8b,

0x99,0x9c,0xd3,0x57,0xe4,0x76,0x67,0xca,

0x3c,0xfb,0x90,0x20,0x14,0x48,0xc9,0x60,

0xb0,0x70,0x4e,0xa2,0xad,0x35,0xea,0xc4,

0x74,0xcb,0x39,0xde,0xe7,0xd4,0xa3,0xa5,

0x04,0x92,0x8c,0xd9,0x7c,0x1c,0x7a,0xa8,

0x52,0x79,0xf2,0x33,0xba,0x1f,0x30,0x9a,

0x00,0x50,0x4c,0xff,0xe5,0xcf,0x59,0xc3,

0xe3,0x0a,0x85,0xb3,0xae,0xec,0x0b,0xfe,

0xe2,0xab,0x4a,0xaf,0x69,0x6c,0x2c,0x5d,

// repetimos

0xbf,0x11,0x6d,0xfa,0x26,0x7f,0xf3,0xc8,

0x9e,0xdd,0x3f,0x16,0x97,0xbd,0x08,0x80,

0x51,0x42,0x93,0x49,0x5b,0x64,0x9b,0x25,

0xf5,0x0f,0x24,0x34,0x44,0xb8,0xee,0x2e,

0xda,0x8f,0x31,0xcc,0xc0,0x5e,0x8a,0x61,

0xa1,0x63,0xc7,0xb2,0x58,0x09,0x4d,0x46,

0x81,0x82,0x68,0x4b,0xf6,0xbc,0x9d,0x03,

0xac,0x91,0xe8,0x3d,0x94,0x37,0xa0,0xbb,

0xce,0xeb,0x98,0xd8,0x38,0x56,0xe9,0x6b,

0x28,0xfd,0x84,0xc6,0xcd,0x5f,0x6e,0xb6,

0x32,0xf7,0x0e,0xf1,0xf8,0x54,0xc1,0x53,

0xf0,0xa7,0x95,0x7b,0x19,0x21,0x23,0x7d,

0xe1,0xa9,0x75,0x3e,0xd6,0xed,0x8e,0x6f,

0xdb,0xb7,0x07,0x41,0x05,0x77,0xb4,0x2d,

0x45,0xdf,0x29,0x22,0x43,0x89,0x83,0xfc,

0xd5,0xa4,0x88,0xd1,0xf4,0x55,0x4f,0x78,

0x62,0x1e,0x1d,0xb9,0xe0,0x2f,0x01,0x13,

0x15,0xe6,0x17,0x6a,0x8d,0x0c,0x96,0x7e,

0x86,0x27,0xa6,0x0d,0xb5,0x73,0x71,0xaa,

0x36,0xd0,0x06,0x66,0xdc,0xb1,0x2a,0x5a,

0x72,0xbe,0x3a,0xc5,0x40,0x65,0x1b,0x02,

0x10,0x9f,0x3b,0xf9,0x2b,0x18,0x5c,0xd7,

0x12,0x47,0xef,0x1a,0x87,0xd2,0xc2,0x8b,

0x99,0x9c,0xd3,0x57,0xe4,0x76,0x67,0xca,

0x3c,0xfb,0x90,0x20,0x14,0x48,0xc9,0x60,

0xb0,0x70,0x4e,0xa2,0xad,0x35,0xea,0xc4,

0x74,0xcb,0x39,0xde,0xe7,0xd4,0xa3,0xa5,

0x04,0x92,0x8c,0xd9,0x7c,0x1c,0x7a,0xa8,

0x52,0x79,0xf2,0x33,0xba,0x1f,0x30,0x9a,

0x00,0x50,0x4c,0xff,0xe5,0xcf,0x59,0xc3,

0xe3,0x0a,0x85,0xb3,0xae,0xec,0x0b,0xfe,

0xe2,0xab,0x4a,0xaf,0x69,0x6c,0x2c,0x5d

};

//---------------------------------------------------------

//Esto te va a parecer raro, pero así es más rápido, esta

//curiosa division de funciones ayuda a la optimización que

//hace Visual C++, V6 (no se ha probado con otras versiones)

//---------------------------------------------------------

// modifica 4 bytes en D con 4 bytes de clave en k

static unsigned int D[4];

static void fase()

{

D[0] ^= D[3];

 

D[3] ^= D[2] = T2[sN(D[3])+D[2]];

D[2] ^= D[1] = T2[sN(D[2])+D[1]];

D[1] ^= D[0] = T2[sN(D[1])+D[0]];

 

D[0] ^= D[3] = T1[sN(D[0])+D[3]];

D[3] ^= D[2] = T1[sN(D[3])+D[2]];

D[2] ^= D[1] = T1[sN(D[2])+D[1]];

 

D[1] ^= D[0];

}

 

static void fase(unsigned char *k, unsigned int *D, unsigned char *d)

{

D[0] = T1[d[4] ^ k[0]];

D[1] = T1[d[5] ^ k[1]];

D[2] = T1[d[6] ^ k[2]];

D[3] = T1[d[7] ^ k[3]];

 

fase();

 

d[8] = d[0] ^ T2[D[1]];

d[9] = d[1] ^ T2[D[3]];

d[10] = d[2] ^ T2[D[0]];

d[11] = d[3] ^ T2[D[2]];

}

 

static void fase(unsigned char *k,unsigned char *d)

{

fase(k, D, d);

}

//-----------------------------------------------

//trabaja sobre un buffer de 80 bytes, usa la

//clave de 16 bytes para generar otra de 64

static void prepara_clave(unsigned char * k)

{

int i, C;

 

for(C = 0 ; C menor_que 16 ; ++C)

{

for(i=4;i--

{

k[16] = k[0] ^ T1[k[15] ^ k[1] ^ C];

k += 1;

}

}

}

//-----------------------------------------------

//funcion pública

void encript(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k);

k += 16;

for(i=0 ; i menor_que 16 ; ++ i) {

fase(k, d);

k += 4;

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

 

//-----------------------------------------------

//funcion pública

void decript(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k);

k += 80;

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

fase(k, d);

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

//-----------------------------------------------

//funcion pública

void decript2(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k); //solo una vez !

 

k += 80;

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

fase(k, d);

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

 

k += 64;

for(i=0 ; i menor_que 16 ; ++ i) {

k -= 4;

fase(k, d);

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

//-----------------------------------------------

//funcion pública

void encript2(unsigned char *k,unsigned char *d)

{

int i;

 

prepara_clave(k); //solo una vez !

k += 16;

 

for(i=0 ; i menor_que 16 ; ++ i) {

fase(k, d);

k += 4;

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

 

k -= 64;

for(i=0 ; i menor_que 16 ; ++ i) {

fase(k, d);

k += 4;

d += 4;

}

d -= 64;

((DWORD*)d)[0] = ((DWORD*)d)[0x11];

((DWORD*)d)[1] = ((DWORD*)d)[0x10];

}

 

Maak een account aan of log in om te reageren

Je moet een lid zijn om een reactie te kunnen achterlaten

Account aanmaken

Registreer voor een nieuwe account in onze community. Het is erg gemakkelijk!

Registreer een nieuwe account

Inloggen

Heb je reeds een account? Log hier in.

Nu inloggen
  • Wie is er online   0 leden

    • Er zijn geen geregistreerde gebruikers deze pagina aan het bekijken
×
×
  • Nieuwe aanmaken...