version 1.1, 2013/02/26 19:53:48
|
version 1.41, 2025/04/15 10:17:52
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.12 |
RPL/2 (R) version 4.1.36 |
Copyright (C) 1989-2012 Dr. BERTRAND Joël |
Copyright (C) 1989-2025 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 41 instruction_cipher(struct_processus *s_e
|
Line 41 instruction_cipher(struct_processus *s_e
|
const EVP_CIPHER *EVP_chiffrement; |
const EVP_CIPHER *EVP_chiffrement; |
const EVP_MD *EVP_sum; |
const EVP_MD *EVP_sum; |
|
|
|
int longueur_clef; |
|
|
|
integer8 longueur_clef_binaire; |
|
integer8 longueur_iv_binaire; |
|
integer8 longueur_message; |
|
integer8 longueur_message_chiffre; |
integer8 nombre_cycles; |
integer8 nombre_cycles; |
|
|
logical1 somme_invalide; |
logical1 encodage; |
logical1 generation_clef; |
logical1 generation_clef; |
|
logical1 somme_invalide; |
|
|
logical8 sel; |
logical8 sel; |
|
|
Line 52 instruction_cipher(struct_processus *s_e
|
Line 59 instruction_cipher(struct_processus *s_e
|
|
|
struct_objet *s_objet_argument_1; |
struct_objet *s_objet_argument_1; |
struct_objet *s_objet_argument_2; |
struct_objet *s_objet_argument_2; |
|
struct_objet *s_objet_padding; |
struct_objet *s_objet_resultat_1; |
struct_objet *s_objet_resultat_1; |
struct_objet *s_objet_resultat_2; |
struct_objet *s_objet_resultat_2; |
|
|
unsigned char *chiffrement; |
unsigned char *algorithme_chiffrement; |
unsigned char *clef; |
unsigned char *clef; |
|
unsigned char *clef_binaire; |
unsigned char *controle; |
unsigned char *controle; |
unsigned char *direction; |
unsigned char *direction; |
unsigned char *fonction; |
unsigned char *fonction; |
unsigned char *instruction; |
unsigned char *instruction; |
unsigned char *iv; |
unsigned char *iv; |
|
unsigned char *iv_binaire; |
|
unsigned char *message; |
|
unsigned char *message_chiffre; |
|
unsigned char padding; |
unsigned char *tampon; |
unsigned char *tampon; |
|
|
if ((*s_etat_processus).affichage_arguments == 'Y') |
if ((*s_etat_processus).affichage_arguments == 'Y') |
Line 77 instruction_cipher(struct_processus *s_e
|
Line 90 instruction_cipher(struct_processus *s_e
|
printf("(cryptographic operations)\n\n"); |
printf("(cryptographic operations)\n\n"); |
} |
} |
|
|
printf(" 2: %s \"password\"\n", d_CHN); |
printf(" 2: \"password\"\n", d_CHN); |
printf(" 1: %s { \"KEY\" \"cipher type\" \"digest type\" " |
printf(" 1: { \"KEY\" \"cipher type\" \"digest type\" " |
"salt nround }\n", d_LST); |
"salt nround }\n"); |
printf("-> 1: %s { \"generated key\" \"iv\" }\n\n", d_LST); |
printf("-> 1: { \"cipher type\" \"generated key\" \"iv\" }\n\n"); |
|
|
printf(" 2: %s \"text\"\n", d_CHN); |
printf(" 2: \"text\"\n", d_CHN); |
printf(" 1: %s { \"cipher type\" \"direction\" \"key\" \"iv\" }\n", |
printf(" 1: { \"direction\" \"cipher type\" \"key\" \"iv\" " |
d_LST); |
"padding }\n"); |
printf("-> 2: %s \"encrypted or decrypted text\"\n", d_CHN); |
printf("-> 2: \"encrypted or decrypted text\"\n", d_CHN); |
printf(" 1: %s { \"cipher type\" \"direction\" \"key\" " |
printf(" 1: { \"direction\" \"cipher type\" \"key\" " |
"\"updated iv\" }\n\n", d_LST); |
"\"updated iv\" padding }\n\n", d_LST); |
|
|
|
if ((*s_etat_processus).langue == 'F') |
|
{ |
|
printf(" Algorithmes de chiffrement :\n\n"); |
|
} |
|
else |
|
{ |
|
printf(" Chipher algorithms:\n\n"); |
|
} |
|
|
|
# ifndef OPENSSL_NO_AES |
|
printf(" - AES-128-CBC\n"); |
|
printf(" - AES-128-CCM\n"); |
|
printf(" - AES-128-CFB1\n"); |
|
printf(" - AES-128-CFB8\n"); |
|
printf(" - AES-128-CFB128\n"); |
|
printf(" - AES-128-CTR\n"); |
|
printf(" - AES-128-ECB\n"); |
|
printf(" - AES-128-GCM\n"); |
|
printf(" - AES-128-OFB\n"); |
|
printf(" - AES-128-XTS\n"); |
|
printf(" - AES-192-CBC\n"); |
|
printf(" - AES-192-CCM\n"); |
|
printf(" - AES-192-CFB1\n"); |
|
printf(" - AES-192-CFB8\n"); |
|
printf(" - AES-192-CFB128\n"); |
|
printf(" - AES-192-CTR\n"); |
|
printf(" - AES-192-ECB\n"); |
|
printf(" - AES-192-GCM\n"); |
|
printf(" - AES-192-OFB\n"); |
|
printf(" - AES-256-CBC\n"); |
|
printf(" - AES-256-CCM\n"); |
|
printf(" - AES-256-CFB1\n"); |
|
printf(" - AES-256-CFB8\n"); |
|
printf(" - AES-256-CFB128\n"); |
|
printf(" - AES-256-CTR\n"); |
|
printf(" - AES-256-ECB\n"); |
|
printf(" - AES-256-GCM\n"); |
|
printf(" - AES-256-OFB\n"); |
|
printf(" - AES-256-XTS\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_BF |
|
printf(" - BF-CBC\n"); |
|
printf(" - BF-CFB64\n"); |
|
printf(" - BF-ECB\n"); |
|
printf(" - BF-OFB\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_CAMELLIA |
|
printf(" - CAMELLIA-128-CBC\n"); |
|
printf(" - CAMELLIA-128-CFB1\n"); |
|
printf(" - CAMELLIA-128-CFB8\n"); |
|
printf(" - CAMELLIA-128-CFB128\n"); |
|
printf(" - CAMELLIA-128-ECB\n"); |
|
printf(" - CAMELLIA-128-OFB\n"); |
|
printf(" - CAMELLIA-192-CBC\n"); |
|
printf(" - CAMELLIA-192-CFB1\n"); |
|
printf(" - CAMELLIA-192-CFB8\n"); |
|
printf(" - CAMELLIA-192-CFB128\n"); |
|
printf(" - CAMELLIA-192-ECB\n"); |
|
printf(" - CAMELLIA-192-OFB\n"); |
|
printf(" - CAMELLIA-256-CBC\n"); |
|
printf(" - CAMELLIA-256-CFB1\n"); |
|
printf(" - CAMELLIA-256-CFB8\n"); |
|
printf(" - CAMELLIA-256-CFB128\n"); |
|
printf(" - CAMELLIA-256-ECB\n"); |
|
printf(" - CAMELLIA-256-OFB\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_CAST |
|
printf(" - CAST5-CBC\n"); |
|
printf(" - CAST5-ECB\n"); |
|
printf(" - CAST5-CFB64\n"); |
|
printf(" - CAST5-OFB\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_DES |
|
printf(" - DES-CBC\n"); |
|
printf(" - DES-CFB1\n"); |
|
printf(" - DES-CFB8\n"); |
|
printf(" - DES-CFB64\n"); |
|
printf(" - DES-ECB\n"); |
|
printf(" - DES-EDE\n"); |
|
printf(" - DES-EDE-CBC\n"); |
|
printf(" - DES-EDE-CFB1\n"); |
|
printf(" - DES-EDE-CFB8\n"); |
|
printf(" - DES-EDE-CFB64\n"); |
|
printf(" - DES-EDE-ECB\n"); |
|
printf(" - DES-EDE-OFB\n"); |
|
printf(" - DES-EDE3\n"); |
|
printf(" - DES-EDE3-CBC\n"); |
|
printf(" - DES-EDE3-ECB\n"); |
|
printf(" - DES-EDE3-OFB\n"); |
|
printf(" - DES-OFB\n"); |
|
printf(" - DESX-CBC\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_IDEA |
|
printf(" - IDEA-CBC\n"); |
|
printf(" - IDEA-CFB64\n"); |
|
printf(" - IDEA-ECB\n"); |
|
printf(" - IDEA-OFB\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_RC2 |
|
printf(" - RC2-CBC\n"); |
|
printf(" - RC2-CFB64\n"); |
|
printf(" - RC2-ECB\n"); |
|
printf(" - RC2-OFB\n"); |
|
printf(" - RC2-40-CBC\n"); |
|
printf(" - RC2-64-CBC\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_RC4 |
|
printf(" - RC4\n"); |
|
printf(" - RC4-40\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_RC5 |
|
printf(" - RC5-32-12-16-CBC\n"); |
|
printf(" - RC5-32-12-16-CFB64\n"); |
|
printf(" - RC5-32-12-16-ECB\n"); |
|
printf(" - RC5-32-12-16-OFB\n"); |
|
# endif |
|
|
|
# ifndef OPENSSL_NO_SEED |
|
printf(" - SEED-CBC\n"); |
|
printf(" - SEED-CFB128\n"); |
|
printf(" - SEED-ECB\n"); |
|
printf(" - SEED-OFB\n"); |
|
# endif |
|
|
|
printf("\n"); |
|
|
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
{ |
{ |
Line 98 instruction_cipher(struct_processus *s_e
|
Line 245 instruction_cipher(struct_processus *s_e
|
printf(" Digest algorithms:\n\n"); |
printf(" Digest algorithms:\n\n"); |
} |
} |
|
|
# ifndef OPENSSL_NO_SHA |
|
printf(" - DSS\n"); |
|
printf(" - DSS1\n"); |
|
printf(" - ECDSA\n"); |
|
# endif |
|
# ifndef OPENSSL_NO_MD2 |
# ifndef OPENSSL_NO_MD2 |
printf(" - MD2\n"); |
printf(" - MD2\n"); |
# endif |
# endif |
Line 118 instruction_cipher(struct_processus *s_e
|
Line 260 instruction_cipher(struct_processus *s_e
|
# ifndef OPENSSL_NO_RIPEMD |
# ifndef OPENSSL_NO_RIPEMD |
printf(" - RIPEMD160\n"); |
printf(" - RIPEMD160\n"); |
# endif |
# endif |
# ifndef OPENSSL_NO_SHA |
|
printf(" - SHA\n"); |
|
printf(" - SHA1\n"); |
printf(" - SHA1\n"); |
# endif |
|
# ifndef OPENSSL_NO_SHA256 |
|
printf(" - SHA224\n"); |
printf(" - SHA224\n"); |
printf(" - SHA256\n"); |
printf(" - SHA256\n"); |
# endif |
|
# ifndef OPENSSL_NO_SHA512 |
|
printf(" - SHA384\n"); |
printf(" - SHA384\n"); |
printf(" - SHA512\n"); |
printf(" - SHA512\n"); |
# endif |
|
# ifndef OPENSSL_NO_WHIRLPOOL |
# ifndef OPENSSL_NO_WHIRLPOOL |
printf(" - WHIRLPOOL\n"); |
printf(" - WHIRLPOOL\n"); |
# endif |
# endif |
Line 145 instruction_cipher(struct_processus *s_e
|
Line 280 instruction_cipher(struct_processus *s_e
|
printf(" Usage:\n\n"); |
printf(" Usage:\n\n"); |
} |
} |
|
|
printf(" \"password\" { \"key\" \"SHA1\" # 0h 3 } CIPHER\n"); |
printf(" \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" " |
printf(" \"text\" { \"AES-128-CBC\" \"DECRYPT\" \"key\" " |
"# 0h 3 } CIPHER\n"); |
"\"iv\" } CIPHER\n"); |
printf(" \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" " |
printf(" \"text\" { \"AES-128-EBC\" \"ENCRYPT\" \"key\" " |
"\"iv\" \"PADDING\" } CIPHER\n"); |
"\"iv\" } CIPHER\n"); |
printf(" \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" " |
|
"\"iv\" \"NO PADDING\" } CIPHER\n"); |
return; |
return; |
} |
} |
else if ((*s_etat_processus).test_instruction == 'Y') |
else if ((*s_etat_processus).test_instruction == 'Y') |
Line 205 instruction_cipher(struct_processus *s_e
|
Line 341 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
if ((instruction = conversion_majuscule((unsigned char *) |
if ((instruction = conversion_majuscule(s_etat_processus, |
(*(*l_element_courant).donnee).objet)) == NULL) |
(unsigned char *) (*(*l_element_courant).donnee).objet)) |
|
== NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
Line 218 instruction_cipher(struct_processus *s_e
|
Line 355 instruction_cipher(struct_processus *s_e
|
|
|
free(instruction); |
free(instruction); |
|
|
|
s_objet_padding = NULL; |
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
|
|
if (l_element_courant == NULL) |
if (l_element_courant == NULL) |
Line 241 instruction_cipher(struct_processus *s_e
|
Line 379 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
chiffrement = (unsigned char *) (*(*l_element_courant) |
algorithme_chiffrement = (unsigned char *) (*(*l_element_courant) |
.donnee).objet; |
.donnee).objet; |
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
Line 267 instruction_cipher(struct_processus *s_e
|
Line 405 instruction_cipher(struct_processus *s_e
|
|
|
controle = (unsigned char *) (*(*l_element_courant).donnee).objet; |
controle = (unsigned char *) (*(*l_element_courant).donnee).objet; |
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_manque_argument; |
|
return; |
|
} |
|
|
|
|
|
// On attend le sel, donc un entier binaire de 64 bits. |
|
|
|
if ((*(*l_element_courant).donnee).type != BIN) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_erreur_type_argument; |
|
return; |
|
} |
|
|
|
sel = (*((logical8 *) (*(*l_element_courant).donnee).objet)); |
|
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_manque_argument; |
|
return; |
|
} |
|
|
|
// On attend le nombre de cycles. |
|
|
|
if ((*(*l_element_courant).donnee).type != INT) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_erreur_type_argument; |
|
return; |
|
} |
|
|
|
nombre_cycles = (*((integer8 *) (*(*l_element_courant) |
|
.donnee).objet)); |
|
|
|
// On a dû atteindre la fin de la liste. |
|
|
|
if ((*l_element_courant).suivant != NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_argument_invalide; |
|
return; |
|
} |
|
|
|
// Test de la validité de la somme de contrôle. |
// Test de la validité de la somme de contrôle. |
|
|
if ((fonction = conversion_majuscule(controle)) == NULL) |
if ((fonction = conversion_majuscule(s_etat_processus, controle)) |
|
== NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
Line 338 instruction_cipher(struct_processus *s_e
|
Line 418 instruction_cipher(struct_processus *s_e
|
|
|
switch(fonction[0]) |
switch(fonction[0]) |
{ |
{ |
case 'D': |
|
{ |
|
switch(fonction[1]) |
|
{ |
|
case 'S': // ds |
|
{ |
|
switch(fonction[2]) |
|
{ |
|
# ifndef OPENSSL_NO_SHA |
|
case 'S': // dss |
|
{ |
|
switch(fonction[3]) |
|
{ |
|
case d_code_fin_chaine: |
|
{ |
|
EVP_sum = EVP_dss(); |
|
break; |
|
} |
|
|
|
case '1': // dss1 |
|
{ |
|
if (fonction[4] == |
|
d_code_fin_chaine) |
|
{ |
|
EVP_sum = EVP_dss1(); |
|
} |
|
else |
|
{ |
|
somme_invalide = d_vrai; |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
# endif |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
case 'E': |
|
{ |
|
switch(fonction[1]) |
|
{ |
|
case 'C': // ec |
|
{ |
|
switch(fonction[2]) |
|
{ |
|
case 'D': // ecd |
|
{ |
|
switch(fonction[3]) |
|
{ |
|
case 'S': // ecds |
|
{ |
|
switch(fonction[4]) |
|
{ |
|
# ifndef OPENSSL_NO_SHA |
|
case 'A': // ecdsa |
|
{ |
|
if (fonction[5] == |
|
d_code_fin_chaine) |
|
{ |
|
EVP_sum = EVP_ecdsa(); |
|
} |
|
else |
|
{ |
|
somme_invalide = d_vrai; |
|
} |
|
|
|
break; |
|
} |
|
# endif |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
case 'M': |
case 'M': |
{ |
{ |
switch(fonction[1]) |
switch(fonction[1]) |
Line 607 instruction_cipher(struct_processus *s_e
|
Line 549 instruction_cipher(struct_processus *s_e
|
{ |
{ |
switch(fonction[2]) |
switch(fonction[2]) |
{ |
{ |
# ifndef OPENSSL_NO_SHA |
|
case 'A': |
case 'A': |
{ |
{ |
switch(fonction[3]) |
switch(fonction[3]) |
{ |
{ |
case d_code_fin_chaine: |
|
{ |
|
EVP_sum = EVP_sha(); |
|
break; |
|
} |
|
|
|
case '1': // sha1 |
case '1': // sha1 |
{ |
{ |
if (fonction[4] == |
if (fonction[4] == |
Line 633 instruction_cipher(struct_processus *s_e
|
Line 568 instruction_cipher(struct_processus *s_e
|
break; |
break; |
} |
} |
|
|
# ifndef OPENSSL_NO_SHA256 |
|
case '2': // sha2 |
case '2': // sha2 |
{ |
{ |
switch(fonction[4]) |
switch(fonction[4]) |
Line 711 instruction_cipher(struct_processus *s_e
|
Line 645 instruction_cipher(struct_processus *s_e
|
|
|
break; |
break; |
} |
} |
# endif |
|
|
|
# ifndef OPENSSL_NO_SHA512 |
|
case '3': // sha3 |
case '3': // sha3 |
{ |
{ |
switch(fonction[4]) |
switch(fonction[4]) |
Line 805 instruction_cipher(struct_processus *s_e
|
Line 737 instruction_cipher(struct_processus *s_e
|
|
|
break; |
break; |
} |
} |
# endif |
|
|
|
default: |
default: |
{ |
{ |
Line 816 instruction_cipher(struct_processus *s_e
|
Line 747 instruction_cipher(struct_processus *s_e
|
|
|
break; |
break; |
} |
} |
# endif |
|
|
|
default: |
default: |
{ |
{ |
Line 873 instruction_cipher(struct_processus *s_e
|
Line 803 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_manque_argument; |
|
return; |
|
} |
|
|
|
// On attend le sel, donc un entier binaire de 64 bits. |
|
|
|
if ((*(*l_element_courant).donnee).type != BIN) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_erreur_type_argument; |
|
return; |
|
} |
|
|
|
sel = (*((logical8 *) (*(*l_element_courant).donnee).objet)); |
|
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_manque_argument; |
|
return; |
|
} |
|
|
|
// On attend le nombre de cycles. |
|
|
|
if ((*(*l_element_courant).donnee).type != INT) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_erreur_type_argument; |
|
return; |
|
} |
|
|
|
nombre_cycles = (*((integer8 *) (*(*l_element_courant) |
|
.donnee).objet)); |
|
|
|
// On a dû atteindre la fin de la liste. |
|
|
|
if ((*l_element_courant).suivant != NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_argument_invalide; |
|
return; |
|
} |
|
|
|
clef = NULL; |
|
iv = NULL; |
|
|
generation_clef = d_vrai; |
generation_clef = d_vrai; |
} |
} |
else |
else |
{ |
{ |
// Chiffrement ou déchiffrement d'un message |
// Chiffrement ou déchiffrement d'un message |
|
|
chiffrement = fonction; |
direction = instruction; |
|
|
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
|
|
Line 892 instruction_cipher(struct_processus *s_e
|
Line 883 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
// On attend la direction. |
// On attend le type de chiffrement. |
|
|
if ((*(*l_element_courant).donnee).type != CHN) |
if ((*(*l_element_courant).donnee).type != CHN) |
{ |
{ |
Line 904 instruction_cipher(struct_processus *s_e
|
Line 895 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
direction = (unsigned char *) (*(*l_element_courant) |
algorithme_chiffrement = (unsigned char *) (*(*l_element_courant) |
.donnee).objet; |
.donnee).objet; |
|
|
// On attend la clef. |
// On attend la clef. |
Line 935 instruction_cipher(struct_processus *s_e
|
Line 926 instruction_cipher(struct_processus *s_e
|
|
|
iv = (unsigned char *) (*(*l_element_courant).donnee).objet; |
iv = (unsigned char *) (*(*l_element_courant).donnee).objet; |
|
|
|
// On attend le drapeau concernant le padding. |
|
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_manque_argument; |
|
return; |
|
} |
|
|
|
if ((*(*l_element_courant).donnee).type != CHN) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_erreur_type_argument; |
|
return; |
|
} |
|
|
|
tampon = conversion_majuscule(s_etat_processus, |
|
(unsigned char *) (*(*l_element_courant).donnee).objet); |
|
|
|
if (strcmp(tampon, "PADDING") == 0) |
|
{ |
|
padding = 'Y'; |
|
} |
|
else if (strcmp(tampon, "NO PADDING") == 0) |
|
{ |
|
padding = 'N'; |
|
} |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_argument_invalide; |
|
return; |
|
} |
|
|
|
free(tampon); |
|
|
|
s_objet_padding = copie_objet(s_etat_processus, |
|
(*l_element_courant).donnee, 'P'); |
|
|
if ((*l_element_courant).suivant != NULL) |
if ((*l_element_courant).suivant != NULL) |
{ |
{ |
liberation(s_etat_processus, s_objet_argument_1); |
liberation(s_etat_processus, s_objet_argument_1); |
Line 943 instruction_cipher(struct_processus *s_e
|
Line 983 instruction_cipher(struct_processus *s_e
|
(*s_etat_processus).erreur_execution = d_ex_argument_invalide; |
(*s_etat_processus).erreur_execution = d_ex_argument_invalide; |
return; |
return; |
} |
} |
|
|
|
generation_clef = d_faux; |
} |
} |
} |
} |
else |
else |
Line 954 instruction_cipher(struct_processus *s_e
|
Line 996 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
if ((tampon = conversion_majuscule(chiffrement)) == NULL) |
if ((tampon = conversion_majuscule(s_etat_processus, |
|
algorithme_chiffrement)) == NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
} |
} |
|
|
if (strncmp(tampon, "AES", 3) == 0) |
# define TEST_CIPHER(string, value) \ |
|
if (strcmp(tampon, string) == 0) EVP_chiffrement = value(); |
|
|
|
if (strncmp(tampon, "DES", 3) == 0) |
{ |
{ |
|
# ifndef OPENSSL_NO_DES |
|
TEST_CIPHER("DES-ECB", EVP_des_ecb) |
|
else TEST_CIPHER("DES-EDE", EVP_des_ede) |
|
else TEST_CIPHER("DES-EDE3", EVP_des_ede3) |
|
else TEST_CIPHER("DES-EDE-ECB", EVP_des_ede_ecb) |
|
else TEST_CIPHER("DES-EDE3-ECB", EVP_des_ede3_ecb) |
|
else TEST_CIPHER("DES-CFB64", EVP_des_cfb64) |
|
else TEST_CIPHER("DES-CFB1", EVP_des_cfb1) |
|
else TEST_CIPHER("DES-CFB8", EVP_des_cfb8) |
|
else TEST_CIPHER("DES-EDE-CFB64", EVP_des_ede_cfb64) |
|
else TEST_CIPHER("DES-EDE3-CFB64", EVP_des_ede3_cfb64) |
|
else TEST_CIPHER("DES-EDE3-CFB1", EVP_des_ede3_cfb1) |
|
else TEST_CIPHER("DES-EDE3-CFB8", EVP_des_ede3_cfb8) |
|
else TEST_CIPHER("DES-OFB", EVP_des_ofb) |
|
else TEST_CIPHER("DES-EDE-OFB", EVP_des_ede_ofb) |
|
else TEST_CIPHER("DES-EDE3-OFB", EVP_des_ede3_ofb) |
|
else TEST_CIPHER("DES-CBC", EVP_des_cbc) |
|
else TEST_CIPHER("DES-EDE-CBC", EVP_des_ede_cbc) |
|
else TEST_CIPHER("DES-EDE3-CBC", EVP_des_ede3_cbc) |
|
else TEST_CIPHER("DESX-CBC", EVP_desx_cbc) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "RC4", 3) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_RC4 |
|
TEST_CIPHER("RC4", EVP_rc4) |
|
else TEST_CIPHER("RC4-40", EVP_rc4_40) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "IDEA", 4) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_IDEA |
|
TEST_CIPHER("IDEA-ECB", EVP_idea_ecb) |
|
else TEST_CIPHER("IDEA-CFB64", EVP_idea_cfb64) |
|
else TEST_CIPHER("IDEA-OFB", EVP_idea_ofb) |
|
else TEST_CIPHER("IDEA-CBC", EVP_idea_cbc) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "RC2", 3) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_RC2 |
|
TEST_CIPHER("RC2-ECB", EVP_rc2_ecb) |
|
else TEST_CIPHER("RC2-CBC", EVP_rc2_cbc) |
|
else TEST_CIPHER("RC2-40-CBC", EVP_rc2_40_cbc) |
|
else TEST_CIPHER("RC2-64-CBC", EVP_rc2_64_cbc) |
|
else TEST_CIPHER("RC2-CFB64", EVP_rc2_cfb64) |
|
else TEST_CIPHER("RC2-OFB", EVP_rc2_ofb) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "BF", 2) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_BF |
|
TEST_CIPHER("BF-ECB", EVP_bf_ecb) |
|
else TEST_CIPHER("BF-CBC", EVP_bf_cbc) |
|
else TEST_CIPHER("BF-CFB64", EVP_bf_cfb64) |
|
else TEST_CIPHER("BF-OFB", EVP_bf_ofb) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "CAST5", 5) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_CAST |
|
TEST_CIPHER("CAST5-ECB", EVP_cast5_ecb) |
|
else TEST_CIPHER("CAST5-CBC", EVP_cast5_cbc) |
|
else TEST_CIPHER("CAST5-CFB64", EVP_cast5_cfb64) |
|
else TEST_CIPHER("CAST5-OFB", EVP_cast5_ofb) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "RC5", 3) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_RC5 |
|
TEST_CIPHER("RC5-32-12-16-ECB", EVP_rc5_32_12_16_ebc) |
|
else TEST_CIPHER("RC5-32-12-16-CBC", EVP_rc5_32_12_16_cbc) |
|
else TEST_CIPHER("RC5-32-12-16-CFB64", EVP_rc5_32_12_16_cfb64) |
|
else TEST_CIPHER("RC5-32-12-16-OFB", EVP_rc5_32_12_16_ofb) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "AES", 3) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_AES |
|
TEST_CIPHER("AES-128-ECB", EVP_aes_128_ecb) |
|
else TEST_CIPHER("AES-128-CBC", EVP_aes_128_cbc) |
|
else TEST_CIPHER("AES-128-CFB1", EVP_aes_128_cfb1) |
|
else TEST_CIPHER("AES-128-CFB8", EVP_aes_128_cfb8) |
|
else TEST_CIPHER("AES-128-CFB128", EVP_aes_128_cfb128) |
|
else TEST_CIPHER("AES-128-OFB", EVP_aes_128_ofb) |
|
else TEST_CIPHER("AES-128-CTR", EVP_aes_128_ctr) |
|
else TEST_CIPHER("AES-128-CCM", EVP_aes_128_ccm) |
|
else TEST_CIPHER("AES-128-GCM", EVP_aes_128_gcm) |
|
else TEST_CIPHER("AES-128-XTS", EVP_aes_128_xts) |
|
else TEST_CIPHER("AES-192-ECB", EVP_aes_192_ecb) |
|
else TEST_CIPHER("AES-192-CBC", EVP_aes_192_cbc) |
|
else TEST_CIPHER("AES-192-CFB1", EVP_aes_192_cfb1) |
|
else TEST_CIPHER("AES-192-CFB8", EVP_aes_192_cfb8) |
|
else TEST_CIPHER("AES-192-CFB128", EVP_aes_192_cfb128) |
|
else TEST_CIPHER("AES-192-OFB", EVP_aes_192_ofb) |
|
else TEST_CIPHER("AES-192-CTR", EVP_aes_192_ctr) |
|
else TEST_CIPHER("AES-192-CCM", EVP_aes_192_ccm) |
|
else TEST_CIPHER("AES-192-GCM", EVP_aes_192_gcm) |
|
else TEST_CIPHER("AES-256-ECB", EVP_aes_256_ecb) |
|
else TEST_CIPHER("AES-256-CBC", EVP_aes_256_cbc) |
|
else TEST_CIPHER("AES-256-CFB1", EVP_aes_256_cfb1) |
|
else TEST_CIPHER("AES-256-CFB8", EVP_aes_256_cfb8) |
|
else TEST_CIPHER("AES-256-CFB128", EVP_aes_256_cfb128) |
|
else TEST_CIPHER("AES-256-OFB", EVP_aes_256_ofb) |
|
else TEST_CIPHER("AES-256-CTR", EVP_aes_256_ctr) |
|
else TEST_CIPHER("AES-256-CCM", EVP_aes_256_ccm) |
|
else TEST_CIPHER("AES-256-GCM", EVP_aes_256_gcm) |
|
else TEST_CIPHER("AES-256-XTS", EVP_aes_256_xts) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "CAMELLIA", 8) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_CAMELLIA |
|
TEST_CIPHER("CAMELLIA-128-ECB", EVP_camellia_128_ecb) |
|
else TEST_CIPHER("CAMELLIA-128-CBC", EVP_camellia_128_cbc) |
|
else TEST_CIPHER("CAMELLIA-128-CFB1", EVP_camellia_128_cfb1) |
|
else TEST_CIPHER("CAMELLIA-128-CFB8", EVP_camellia_128_cfb8) |
|
else TEST_CIPHER("CAMELLIA-128-CFB128", EVP_camellia_128_cfb128) |
|
else TEST_CIPHER("CAMELLIA-128-OFB", EVP_camellia_128_ofb) |
|
else TEST_CIPHER("CAMELLIA-192-ECB", EVP_camellia_128_ecb) |
|
else TEST_CIPHER("CAMELLIA-192-CBC", EVP_camellia_192_cbc) |
|
else TEST_CIPHER("CAMELLIA-192-CFB1", EVP_camellia_192_cfb1) |
|
else TEST_CIPHER("CAMELLIA-192-CFB8", EVP_camellia_192_cfb8) |
|
else TEST_CIPHER("CAMELLIA-192-CFB128", EVP_camellia_192_cfb128) |
|
else TEST_CIPHER("CAMELLIA-192-OFB", EVP_camellia_192_ofb) |
|
else TEST_CIPHER("CAMELLIA-256-ECB", EVP_camellia_256_ecb) |
|
else TEST_CIPHER("CAMELLIA-256-CBC", EVP_camellia_256_cbc) |
|
else TEST_CIPHER("CAMELLIA-256-CFB1", EVP_camellia_256_cfb1) |
|
else TEST_CIPHER("CAMELLIA-256-CFB8", EVP_camellia_256_cfb8) |
|
else TEST_CIPHER("CAMELLIA-256-CFB128", EVP_camellia_256_cfb128) |
|
else TEST_CIPHER("CAMELLIA-256-OFB", EVP_camellia_256_ofb) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else if (strncmp(tampon, "SEED", 4) == 0) |
|
{ |
|
# ifndef OPENSSL_NO_SEED |
|
TEST_CIPHER("SEED-ECB", EVP_seed_ecb) |
|
else TEST_CIPHER("SEED-CBC", EVP_seed_cbc) |
|
else TEST_CIPHER("SEED-CFB128", EVP_seed_cfb128) |
|
else TEST_CIPHER("SEED-OFB", EVP_seed_ofb) |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
} |
|
# else |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_chiffrement_indisponible; |
|
return; |
|
# endif |
|
} |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_chiffrement_indisponible; |
|
return; |
} |
} |
|
|
free(tampon); |
free(tampon); |
|
|
if (generation_clef == d_vrai) |
if (generation_clef == d_vrai) |
{ |
{ |
|
if ((iv = malloc(((size_t) EVP_CIPHER_iv_length(EVP_chiffrement)) |
|
* sizeof(unsigned char))) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if ((clef = malloc(((size_t) EVP_CIPHER_key_length(EVP_chiffrement)) |
|
* sizeof(unsigned char))) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
longueur_clef = EVP_BytesToKey(EVP_chiffrement, EVP_sum, |
|
(unsigned char *) &sel, (unsigned char *) |
|
(*s_objet_argument_2).objet, |
|
(int) longueur_chaine(s_etat_processus, |
|
(unsigned char *) (*s_objet_argument_2).objet), |
|
(int) nombre_cycles, clef, iv); |
|
|
|
if (longueur_clef != EVP_CIPHER_key_length(EVP_chiffrement)) |
|
{ |
|
free(iv); |
|
free(clef); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_chiffrement; |
|
return; |
|
} |
|
|
|
if ((s_objet_resultat_1 = allocation(s_etat_processus, LST)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*s_objet_resultat_1).objet = allocation_maillon(s_etat_processus)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*s_objet_resultat_1).objet; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = malloc( |
|
(strlen(algorithme_chiffrement) + 1) * sizeof(unsigned char))) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
strcpy((*(*l_element_courant).donnee).objet, algorithme_chiffrement); |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = analyse_flux( |
|
s_etat_processus, clef, |
|
EVP_CIPHER_key_length(EVP_chiffrement))) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
free(clef); |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
(*l_element_courant).suivant = NULL; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = analyse_flux( |
|
s_etat_processus, iv, |
|
EVP_CIPHER_iv_length(EVP_chiffrement))) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
free(iv); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
|
s_objet_resultat_1) == d_erreur) |
|
{ |
|
return; |
|
} |
} |
} |
else |
else |
{ |
{ |
|
// Chiffrement ou déchiffrement |
|
|
|
if (strcmp(direction, "ENCRYPT") == 0) |
|
{ |
|
encodage = d_vrai; |
|
} |
|
else if (strcmp(direction, "DECRYPT") == 0) |
|
{ |
|
encodage = d_faux; |
|
} |
|
else |
|
{ |
|
free(direction); |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_argument_invalide; |
|
return; |
|
} |
|
|
|
free(direction); |
|
|
|
// Conversion des clefs |
|
|
|
if ((clef_binaire = formateur_flux(s_etat_processus, clef, |
|
&longueur_clef_binaire)) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
if ((iv_binaire = formateur_flux(s_etat_processus, iv, |
|
&longueur_iv_binaire)) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
// Vérification de la longueur des clef et vecteur d'initialisation |
|
|
|
if (longueur_clef_binaire != EVP_CIPHER_key_length(EVP_chiffrement)) |
|
{ |
|
free(clef_binaire); |
|
free(iv_binaire); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_longueur_clef_chiffrement; |
|
return; |
|
} |
|
|
|
if (longueur_iv_binaire != EVP_CIPHER_iv_length(EVP_chiffrement)) |
|
{ |
|
free(clef_binaire); |
|
free(iv_binaire); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_longueur_clef_chiffrement; |
|
return; |
|
} |
|
|
|
if ((message = formateur_flux(s_etat_processus, (unsigned char *) |
|
(*s_objet_argument_2).objet, &longueur_message)) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
if ((message_chiffre = chiffrement(s_etat_processus, |
|
EVP_chiffrement, encodage, message, |
|
longueur_message, clef_binaire, longueur_clef_binaire, |
|
iv_binaire, &longueur_message_chiffre, padding)) == NULL) |
|
{ |
|
free(clef_binaire); |
|
free(iv_binaire); |
|
free(message); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_chiffrement; |
|
return; |
|
} |
|
|
|
free(clef_binaire); |
|
free(message); |
|
|
|
if ((s_objet_resultat_2 = allocation(s_etat_processus, CHN)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*s_objet_resultat_2).objet = analyse_flux(s_etat_processus, |
|
message_chiffre, longueur_message_chiffre)) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
free(message_chiffre); |
|
|
|
if ((s_objet_resultat_1 = allocation(s_etat_processus, LST)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*s_objet_resultat_1).objet = allocation_maillon(s_etat_processus)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*s_objet_resultat_1).objet; |
|
|
|
// Direction |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = |
|
malloc(8 * sizeof(unsigned char))) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
strcpy((*(*l_element_courant).donnee).objet, |
|
(encodage == d_vrai) ? "ENCRYPT" : "DECRYPT"); |
|
|
|
// Type de chiffrement |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = |
|
conversion_majuscule(s_etat_processus, algorithme_chiffrement)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
// Clef |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = |
|
malloc((strlen(clef) + 1) * sizeof(unsigned char))) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
strcpy((*(*l_element_courant).donnee).objet, clef); |
|
|
|
// Vecteur d'initialisation |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
|
== NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (((*(*l_element_courant).donnee).objet = analyse_flux( |
|
s_etat_processus, iv_binaire, longueur_iv_binaire)) == NULL) |
|
{ |
|
return; |
|
} |
|
|
|
free(iv_binaire); |
|
|
|
// Padding |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
(*l_element_courant).donnee = s_objet_padding; |
|
(*l_element_courant).suivant = NULL; |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
|
s_objet_resultat_2) == d_erreur) |
|
{ |
|
return; |
|
} |
|
|
|
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
|
s_objet_resultat_1) == d_erreur) |
|
{ |
|
return; |
|
} |
} |
} |
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
return; |
return; |
} |
} |
|
|