--- rpl/src/instructions_c8.c 2015/11/26 11:44:34 1.22 +++ rpl/src/instructions_c8.c 2025/04/15 10:17:52 1.41 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.24 - Copyright (C) 1989-2015 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.36 + Copyright (C) 1989-2025 Dr. BERTRAND Joël This file is part of RPL/2. @@ -59,6 +59,7 @@ instruction_cipher(struct_processus *s_e struct_objet *s_objet_argument_1; struct_objet *s_objet_argument_2; + struct_objet *s_objet_padding; struct_objet *s_objet_resultat_1; struct_objet *s_objet_resultat_2; @@ -73,6 +74,7 @@ instruction_cipher(struct_processus *s_e unsigned char *iv_binaire; unsigned char *message; unsigned char *message_chiffre; + unsigned char padding; unsigned char *tampon; if ((*s_etat_processus).affichage_arguments == 'Y') @@ -94,10 +96,11 @@ instruction_cipher(struct_processus *s_e printf("-> 1: { \"cipher type\" \"generated key\" \"iv\" }\n\n"); printf(" 2: \"text\"\n", d_CHN); - printf(" 1: { \"direction\" \"cipher type\" \"key\" \"iv\" }\n"); + printf(" 1: { \"direction\" \"cipher type\" \"key\" \"iv\" " + "padding }\n"); printf("-> 2: \"encrypted or decrypted text\"\n", d_CHN); 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') { @@ -242,11 +245,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 @@ -262,18 +260,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 @@ -292,9 +283,9 @@ instruction_cipher(struct_processus *s_e printf(" \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" " "# 0h 3 } CIPHER\n"); printf(" \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" " - "\"iv\" } CIPHER\n"); + "\"iv\" \"PADDING\" } CIPHER\n"); printf(" \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" " - "\"iv\" } CIPHER\n"); + "\"iv\" \"NO PADDING\" } CIPHER\n"); return; } else if ((*s_etat_processus).test_instruction == 'Y') @@ -364,6 +355,7 @@ instruction_cipher(struct_processus *s_e free(instruction); + s_objet_padding = NULL; l_element_courant = (*l_element_courant).suivant; if (l_element_courant == NULL) @@ -426,144 +418,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]) @@ -695,17 +549,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] == @@ -721,7 +568,6 @@ instruction_cipher(struct_processus *s_e break; } -# ifndef OPENSSL_NO_SHA256 case '2': // sha2 { switch(fonction[4]) @@ -799,9 +645,7 @@ instruction_cipher(struct_processus *s_e break; } -# endif -# ifndef OPENSSL_NO_SHA512 case '3': // sha3 { switch(fonction[4]) @@ -893,7 +737,6 @@ instruction_cipher(struct_processus *s_e break; } -# endif default: { @@ -904,7 +747,6 @@ instruction_cipher(struct_processus *s_e break; } -# endif default: { @@ -1084,6 +926,55 @@ instruction_cipher(struct_processus *s_e 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) { liberation(s_etat_processus, s_objet_argument_1); @@ -1675,7 +1566,7 @@ instruction_cipher(struct_processus *s_e if ((message_chiffre = chiffrement(s_etat_processus, EVP_chiffrement, encodage, message, longueur_message, clef_binaire, longueur_clef_binaire, - iv_binaire, &longueur_message_chiffre)) == NULL) + iv_binaire, &longueur_message_chiffre, padding)) == NULL) { free(clef_binaire); free(iv_binaire); @@ -1802,7 +1693,6 @@ instruction_cipher(struct_processus *s_e } l_element_courant = (*l_element_courant).suivant; - (*l_element_courant).suivant = NULL; if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) == NULL) @@ -1819,6 +1709,19 @@ instruction_cipher(struct_processus *s_e 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);