--- rpl/src/instructions_c8.c 2013/02/26 19:56:13 1.2 +++ rpl/src/instructions_c8.c 2022/09/07 13:40:34 1.36 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.12 - Copyright (C) 1989-2013 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.34 + Copyright (C) 1989-2021 Dr. BERTRAND Joël This file is part of RPL/2. @@ -41,10 +41,17 @@ instruction_cipher(struct_processus *s_e const EVP_CIPHER *EVP_chiffrement; 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; - logical1 somme_invalide; + logical1 encodage; logical1 generation_clef; + logical1 somme_invalide; logical8 sel; @@ -55,13 +62,17 @@ instruction_cipher(struct_processus *s_e struct_objet *s_objet_resultat_1; struct_objet *s_objet_resultat_2; - unsigned char *chiffrement; + unsigned char *algorithme_chiffrement; unsigned char *clef; + unsigned char *clef_binaire; unsigned char *controle; unsigned char *direction; unsigned char *fonction; unsigned char *instruction; unsigned char *iv; + unsigned char *iv_binaire; + unsigned char *message; + unsigned char *message_chiffre; unsigned char *tampon; if ((*s_etat_processus).affichage_arguments == 'Y') @@ -77,20 +88,153 @@ instruction_cipher(struct_processus *s_e printf("(cryptographic operations)\n\n"); } - printf(" 2: %s \"password\"\n", d_CHN); - printf(" 1: %s { \"KEY\" \"cipher type\" \"digest type\" " - "salt nround }\n", d_LST); - printf("-> 1: %s { \"generated key\" \"iv\" }\n\n", d_LST); - - printf(" 2: %s \"text\"\n", d_CHN); - printf(" 1: %s { \"cipher type\" \"direction\" \"key\" \"iv\" }\n", - d_LST); - printf("-> 2: %s \"encrypted or decrypted text\"\n", d_CHN); - printf(" 1: %s { \"cipher type\" \"direction\" \"key\" " + printf(" 2: \"password\"\n", d_CHN); + printf(" 1: { \"KEY\" \"cipher type\" \"digest type\" " + "salt nround }\n"); + printf("-> 1: { \"cipher type\" \"generated key\" \"iv\" }\n\n"); + + printf(" 2: \"text\"\n", d_CHN); + printf(" 1: { \"direction\" \"cipher type\" \"key\" \"iv\" }\n"); + printf("-> 2: \"encrypted or decrypted text\"\n", d_CHN); + printf(" 1: { \"direction\" \"cipher type\" \"key\" " "\"updated iv\" }\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') + { printf(" Algorithmes de signature :\n\n"); } else @@ -98,11 +242,6 @@ instruction_cipher(struct_processus *s_e printf(" Digest algorithms:\n\n"); } -# ifndef OPENSSL_NO_SHA - printf(" - DSS\n"); - printf(" - DSS1\n"); - printf(" - ECDSA\n"); -# endif # ifndef OPENSSL_NO_MD2 printf(" - MD2\n"); # endif @@ -118,18 +257,11 @@ instruction_cipher(struct_processus *s_e # ifndef OPENSSL_NO_RIPEMD printf(" - RIPEMD160\n"); # endif -# ifndef OPENSSL_NO_SHA - printf(" - SHA\n"); printf(" - SHA1\n"); -# endif -# ifndef OPENSSL_NO_SHA256 printf(" - SHA224\n"); printf(" - SHA256\n"); -# endif -# ifndef OPENSSL_NO_SHA512 printf(" - SHA384\n"); printf(" - SHA512\n"); -# endif # ifndef OPENSSL_NO_WHIRLPOOL printf(" - WHIRLPOOL\n"); # endif @@ -145,10 +277,11 @@ instruction_cipher(struct_processus *s_e printf(" Usage:\n\n"); } - printf(" \"password\" { \"key\" \"SHA1\" # 0h 3 } CIPHER\n"); - printf(" \"text\" { \"AES-128-CBC\" \"DECRYPT\" \"key\" " + printf(" \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" " + "# 0h 3 } CIPHER\n"); + printf(" \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" " "\"iv\" } CIPHER\n"); - printf(" \"text\" { \"AES-128-EBC\" \"ENCRYPT\" \"key\" " + printf(" \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" " "\"iv\" } CIPHER\n"); return; } @@ -205,8 +338,9 @@ instruction_cipher(struct_processus *s_e return; } - if ((instruction = conversion_majuscule((unsigned char *) - (*(*l_element_courant).donnee).objet)) == NULL) + if ((instruction = conversion_majuscule(s_etat_processus, + (unsigned char *) (*(*l_element_courant).donnee).objet)) + == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -241,7 +375,7 @@ instruction_cipher(struct_processus *s_e return; } - chiffrement = (unsigned char *) (*(*l_element_courant) + algorithme_chiffrement = (unsigned char *) (*(*l_element_courant) .donnee).objet; if ((l_element_courant = (*l_element_courant).suivant) == NULL) @@ -267,68 +401,10 @@ instruction_cipher(struct_processus *s_e 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. - if ((fonction = conversion_majuscule(controle)) == NULL) + if ((fonction = conversion_majuscule(s_etat_processus, controle)) + == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -338,144 +414,6 @@ instruction_cipher(struct_processus *s_e 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': { switch(fonction[1]) @@ -607,17 +545,10 @@ instruction_cipher(struct_processus *s_e { switch(fonction[2]) { -# ifndef OPENSSL_NO_SHA case 'A': { switch(fonction[3]) { - case d_code_fin_chaine: - { - EVP_sum = EVP_sha(); - break; - } - case '1': // sha1 { if (fonction[4] == @@ -633,7 +564,6 @@ instruction_cipher(struct_processus *s_e break; } -# ifndef OPENSSL_NO_SHA256 case '2': // sha2 { switch(fonction[4]) @@ -711,9 +641,7 @@ instruction_cipher(struct_processus *s_e break; } -# endif -# ifndef OPENSSL_NO_SHA512 case '3': // sha3 { switch(fonction[4]) @@ -805,7 +733,6 @@ instruction_cipher(struct_processus *s_e break; } -# endif default: { @@ -816,7 +743,6 @@ instruction_cipher(struct_processus *s_e break; } -# endif default: { @@ -873,13 +799,74 @@ instruction_cipher(struct_processus *s_e 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; } else { // Chiffrement ou déchiffrement d'un message - chiffrement = fonction; + direction = instruction; l_element_courant = (*l_element_courant).suivant; @@ -892,7 +879,7 @@ instruction_cipher(struct_processus *s_e return; } - // On attend la direction. + // On attend le type de chiffrement. if ((*(*l_element_courant).donnee).type != CHN) { @@ -904,7 +891,7 @@ instruction_cipher(struct_processus *s_e return; } - direction = (unsigned char *) (*(*l_element_courant) + algorithme_chiffrement = (unsigned char *) (*(*l_element_courant) .donnee).objet; // On attend la clef. @@ -943,6 +930,8 @@ instruction_cipher(struct_processus *s_e (*s_etat_processus).erreur_execution = d_ex_argument_invalide; return; } + + generation_clef = d_faux; } } else @@ -954,27 +943,736 @@ instruction_cipher(struct_processus *s_e 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; 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); 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 { + // 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)) == 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; + (*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_binaire, longueur_iv_binaire)) == NULL) + { + return; + } + + free(iv_binaire); + + 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; }