--- rpl/src/instructions_d6.c 2010/09/23 15:27:37 1.14 +++ rpl/src/instructions_d6.c 2013/02/25 11:24:02 1.41 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.0.20 - Copyright (C) 1989-2010 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.12 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -582,6 +582,1618 @@ instruction_diag_fleche(struct_processus if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) + { + return; + } + + return; +} + + +/* +================================================================================ + Fonction 'digest' +================================================================================ + Entrées : pointeur sur une structure struct_processus +-------------------------------------------------------------------------------- + Sorties : +-------------------------------------------------------------------------------- + Effets de bord : néant +================================================================================ +*/ + +void +instruction_digest(struct_processus *s_etat_processus) +{ + EVP_MD_CTX contexte; + + const EVP_MD * (*EVP_sum)(); + + logical1 somme_invalide; + + long i; + long longueur_chaine; + + struct_liste_chainee *l_element_courant; + + struct_objet *s_objet_argument_1; + struct_objet *s_objet_argument_2; + struct_objet *s_objet_resultat; + + unsigned char *chaine; + unsigned char *clef; + unsigned char *fonction; + unsigned char somme[EVP_MAX_MD_SIZE]; + unsigned char *tampon; + + unsigned int longueur_bloc; + unsigned int longueur_somme; + unsigned int longueur_tampon; + + unsigned long longueur_clef; + + (*s_etat_processus).erreur_execution = d_ex; + + if ((*s_etat_processus).affichage_arguments == 'Y') + { + printf("\n DIGEST "); + + if ((*s_etat_processus).langue == 'F') + { + printf("(somme d'authentification)\n\n"); + } + else + { + printf("(hash algorithm)\n\n"); + } + + printf(" 2: %s\n", d_CHN); + printf(" 1: %s\n", d_CHN); + printf("-> 1: %s\n\n", d_CHN); + + printf(" 2: %s\n", d_CHN); + printf(" 1: %s\n", d_LST); + printf("-> 1: %s\n\n", d_CHN); + + if ((*s_etat_processus).langue == 'F') + { + printf(" Algorithmes :\n\n"); + } + else + { + printf(" 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 +# ifndef OPENSSL_NO_MD4 + printf(" - MD4\n"); +# endif +# ifndef OPENSSL_NO_MD5 + printf(" - MD5\n"); +# endif +# ifndef OPENSSL_NO_MDC2 + printf(" - MDC2\n"); +# endif +# 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 + + printf("\n"); + + if ((*s_etat_processus).langue == 'F') + { + printf(" Utilisation :\n\n"); + } + else + { + printf(" Usage:\n\n"); + } + + printf(" \"text\" \"MD5\" DIGEST\n"); + printf(" \"text\" { \"SHA384\" \"key\" } DIGEST\n"); + printf(" \"text\" { \"AES-CBC\" \"key\" } DIGEST\n"); + return; + } + else if ((*s_etat_processus).test_instruction == 'Y') + { + (*s_etat_processus).nombre_arguments = -1; + return; + } + + if (test_cfsf(s_etat_processus, 31) == d_vrai) + { + if (empilement_pile_last(s_etat_processus, 2) == d_erreur) + { + return; + } + } + + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument_1) == d_erreur) + { + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument_2) == d_erreur) + { + liberation(s_etat_processus, s_objet_argument_1); + + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if (((*s_objet_argument_1).type == CHN) && + ((*s_objet_argument_2).type == CHN)) + { + // Liste des sommes disponibles : + // - EVP_dss + // - EVP_dss1 + // - EVP_ecdsa + // - EVP_md2 + // - EVP_md4 + // - EVP_md5 + // - EVP_mdc2 + // - EVP_ripemd160 + // - EVP_sha + // - EVP_sha1 + // - EVP_sha224 + // - EVP_sha256 + // - EVP_sha384 + // - EVP_sha512 + // - EVP_whirlpool + + if ((fonction = conversion_majuscule((unsigned char *) + (*s_objet_argument_1).objet)) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + somme_invalide = d_faux; + + 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]) + { + case 'D': // md + { + switch(fonction[2]) + { +# ifndef OPENSSL_NO_MD2 + case '2': // md2 + { + if (fonction[3] == d_code_fin_chaine) + { + EVP_sum = EVP_md2; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + +# ifndef OPENSSL_NO_MD4 + case '4': // md4 + { + if (fonction[3] == d_code_fin_chaine) + { + EVP_sum = EVP_md4; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + +# ifndef OPENSSL_NO_MD5 + case '5': // md5 + { + if (fonction[3] == d_code_fin_chaine) + { + EVP_sum = EVP_md5; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + + case 'C': // mdc + { + switch(fonction[3]) + { +# ifndef OPENSSL_NO_MDC2 + case '2': // mdc2 + { + if (fonction[4] == d_code_fin_chaine) + { + EVP_sum = EVP_mdc2; + } + 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; + } + +# ifndef OPENSSL_NO_RIPEMD + case 'R': + { + if (strcmp(fonction, "RIPEMD160") == 0) + { + EVP_sum = EVP_ripemd160; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + + case 'S': + { + switch(fonction[1]) + { + case 'H': // sh + { + 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] == d_code_fin_chaine) + { + EVP_sum = EVP_sha1; + } + else + { + somme_invalide = d_vrai; + } + + break; + } + +# ifndef OPENSSL_NO_SHA256 + case '2': // sha2 + { + switch(fonction[4]) + { + case '2': // sha22 + { + switch(fonction[5]) + { + case '4': // sha224 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha224; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + case '5': + { + switch(fonction[5]) + { + case '6': // sha256 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha256; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } +# endif + +# ifndef OPENSSL_NO_SHA512 + case '3': // sha3 + { + switch(fonction[4]) + { + case '8': // sha38 + { + switch(fonction[5]) + { + case '4': // sha384 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha384; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + case '5': // sha5 + { + switch(fonction[4]) + { + case '1': // sha51 + { + switch(fonction[5]) + { + case '2': // sha512 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha512; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } +# endif + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } +# endif + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + +# ifndef OPENSSL_NO_WHIRLPOOL + case 'W': + { + if (strcmp(fonction, "WHIRLPOOL") == 0) + { + EVP_sum = EVP_whirlpool; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + + default: + { + somme_invalide = d_vrai; + break; + } + } + + free(fonction); + + if (somme_invalide == d_vrai) + { + 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; + } + + if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + { + EVP_MD_CTX_cleanup(&contexte); + + 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 ((chaine = formateur_flux(s_etat_processus, (unsigned char *) + (*s_objet_argument_2).objet, &longueur_chaine)) == NULL) + { + EVP_MD_CTX_cleanup(&contexte); + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + return; + } + + if (EVP_DigestUpdate(&contexte, chaine, longueur_chaine) != 1) + { + free(chaine); + EVP_MD_CTX_cleanup(&contexte); + + 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 (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + { + free(chaine); + EVP_MD_CTX_cleanup(&contexte); + + 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(chaine); + EVP_MD_CTX_cleanup(&contexte); + + if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus, + somme, longueur_somme)) == NULL) + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + return; + } + } + else if (((*s_objet_argument_1).type == LST) && + ((*s_objet_argument_2).type == CHN)) + { + l_element_courant = (*s_objet_argument_1).objet; + + 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; + } + + l_element_courant = (*l_element_courant).suivant; + + if (l_element_courant == 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; + } + + 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 du type de somme de contrôle + // - les sommes classiques suivent la RFC 2104 + // - les autres sont formées sur des algorithmes de type CBC + + l_element_courant = (*s_objet_argument_1).objet; + + if ((fonction = conversion_majuscule((unsigned char *) + (*(*l_element_courant).donnee).objet)) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + somme_invalide = d_faux; + + 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; + longueur_bloc = SHA_CBLOCK; + break; + } + + case '1': // dss1 + { + if (fonction[4] == d_code_fin_chaine) + { + EVP_sum = EVP_dss1; + longueur_bloc = SHA_CBLOCK; + } + 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; + longueur_bloc = SHA_CBLOCK; + } + 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]) + { + case 'D': // md + { + switch(fonction[2]) + { +# ifndef OPENSSL_NO_MD2 + case '2': // md2 + { + if (fonction[3] == d_code_fin_chaine) + { + EVP_sum = EVP_md2; + longueur_bloc = MD2_BLOCK; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + +# ifndef OPENSSL_NO_MD4 + case '4': // md4 + { + if (fonction[3] == d_code_fin_chaine) + { + EVP_sum = EVP_md4; + longueur_bloc = MD4_CBLOCK; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + +# ifndef OPENSSL_NO_MD5 + case '5': // md5 + { + if (fonction[3] == d_code_fin_chaine) + { + EVP_sum = EVP_md5; + longueur_bloc = MD5_CBLOCK; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + + case 'C': // mdc + { + switch(fonction[3]) + { +# ifndef OPENSSL_NO_MDC2 + case '2': // mdc2 + { + if (fonction[4] == d_code_fin_chaine) + { + EVP_sum = EVP_mdc2; + longueur_bloc = MDC2_BLOCK; + } + 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; + } + +# ifndef OPENSSL_NO_RIPEMD + case 'R': + { + if (strcmp(fonction, "RIPEMD160") == 0) + { + EVP_sum = EVP_ripemd160; + longueur_bloc = RIPEMD160_CBLOCK; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + + case 'S': + { + switch(fonction[1]) + { + case 'H': // sh + { + switch(fonction[2]) + { +# ifndef OPENSSL_NO_SHA + case 'A': + { + switch(fonction[3]) + { + case d_code_fin_chaine: + { + EVP_sum = EVP_sha; + longueur_bloc = SHA_CBLOCK; + break; + } + + case '1': // sha1 + { + if (fonction[4] == d_code_fin_chaine) + { + EVP_sum = EVP_sha1; + longueur_bloc = SHA_CBLOCK; + } + else + { + somme_invalide = d_vrai; + } + + break; + } + +# ifndef OPENSSL_NO_SHA256 + case '2': // sha2 + { + switch(fonction[4]) + { + case '2': // sha22 + { + switch(fonction[5]) + { + case '4': // sha224 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha224; + longueur_bloc = + SHA256_CBLOCK; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + case '5': + { + switch(fonction[5]) + { + case '6': // sha256 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha256; + longueur_bloc = + SHA256_CBLOCK; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } +# endif + +# ifndef OPENSSL_NO_SHA512 + case '3': // sha3 + { + switch(fonction[4]) + { + case '8': // sha38 + { + switch(fonction[5]) + { + case '4': // sha384 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha384; + longueur_bloc = + SHA512_CBLOCK; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + case '5': // sha5 + { + switch(fonction[4]) + { + case '1': // sha51 + { + switch(fonction[5]) + { + case '2': // sha512 + { + if (fonction[6] == + d_code_fin_chaine) + { + EVP_sum = + EVP_sha512; + longueur_bloc = + SHA512_CBLOCK; + } + else + { + somme_invalide = + d_vrai; + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } +# endif + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } +# endif + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + + default: + { + somme_invalide = d_vrai; + break; + } + } + + break; + } + +# ifndef OPENSSL_NO_WHIRLPOOL + case 'W': + { + if (strcmp(fonction, "WHIRLPOOL") == 0) + { + EVP_sum = EVP_whirlpool; + longueur_bloc = WHIRLPOOL_BBLOCK / 8; + } + else + { + somme_invalide = d_vrai; + } + + break; + } +# endif + + default: + { + somme_invalide = d_vrai; + break; + } + } + + free(fonction); + + if (somme_invalide == d_vrai) + { + // Le chiffrement est de type CBC-MAC + BUG(1, uprintf("Oops!")); + exit(0); + } + else + { + // Le chiffrement est de type HMAC + // Le second élément de la chaîne contient la clef utilisée pour + // la signature. + + l_element_courant = (*s_objet_argument_1).objet; + l_element_courant = (*l_element_courant).suivant; + + if ((clef = formateur_flux(s_etat_processus, (unsigned char *) + (*(*l_element_courant).donnee).objet, &longueur_clef)) + == NULL) + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + return; + } + + if (longueur_clef < longueur_bloc) + { + longueur_tampon = longueur_clef; + tampon = clef; + + if ((clef = malloc(longueur_bloc * sizeof(unsigned char))) + == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return; + } + + memset(clef, 0, longueur_bloc); + memcpy(clef, tampon, longueur_tampon); + longueur_clef = longueur_bloc; + free(tampon); + } + else if (longueur_clef > longueur_bloc) + { + longueur_tampon = longueur_clef; + tampon = clef; + + if ((clef = malloc(longueur_bloc * sizeof(unsigned char))) + == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return; + } + + memcpy(clef, tampon, longueur_bloc); + longueur_clef = longueur_bloc; + free(tampon); + } + + for(i = 0; i < longueur_bloc; i++) + { + clef[i] ^= 0x36; + } + + if ((chaine = formateur_flux(s_etat_processus, (unsigned char *) + (*s_objet_argument_2).objet, &longueur_chaine)) == NULL) + { + EVP_MD_CTX_cleanup(&contexte); + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + return; + } + + if ((tampon = malloc((longueur_bloc + longueur_chaine) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + memcpy(tampon, clef, longueur_bloc); + memcpy(tampon + longueur_bloc, chaine, longueur_chaine); + longueur_tampon = longueur_bloc + longueur_chaine; + + if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + { + free(tampon); + free(clef); + free(chaine); + + EVP_MD_CTX_cleanup(&contexte); + + 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 (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1) + { + free(tampon); + free(clef); + free(chaine); + + EVP_MD_CTX_cleanup(&contexte); + + 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(tampon); + + if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + { + free(chaine); + EVP_MD_CTX_cleanup(&contexte); + + 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; + } + + EVP_MD_CTX_cleanup(&contexte); + + for(i = 0; i < longueur_bloc; i++) + { + clef[i] ^= (0x36 ^ 0x5c); + } + + if ((tampon = malloc((longueur_bloc + longueur_somme) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + memcpy(tampon, clef, longueur_bloc); + memcpy(tampon + longueur_bloc, somme, longueur_somme); + longueur_tampon = longueur_bloc + longueur_somme; + + if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + { + free(tampon); + free(clef); + free(chaine); + + EVP_MD_CTX_cleanup(&contexte); + + 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 (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1) + { + free(tampon); + free(clef); + free(chaine); + + EVP_MD_CTX_cleanup(&contexte); + + 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(tampon); + + if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + { + free(chaine); + EVP_MD_CTX_cleanup(&contexte); + + 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; + } + + EVP_MD_CTX_cleanup(&contexte); + + free(chaine); + free(clef); + + if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL) + { + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus, + somme, longueur_somme)) == NULL) + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + return; + } + } + } + else + { + 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; + } + + 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) == d_erreur) { return; }