--- rpl/src/instructions_d6.c 2013/02/25 11:24:02 1.41 +++ rpl/src/instructions_d6.c 2016/09/27 15:29:35 1.65 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.12 - Copyright (C) 1989-2012 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.26 + Copyright (C) 1989-2016 Dr. BERTRAND Joël This file is part of RPL/2. @@ -339,8 +339,8 @@ instruction_diag_fleche(struct_processus struct_objet *s_objet_argument; struct_objet *s_objet_resultat; - unsigned long i; - unsigned long j; + integer8 i; + integer8 j; (*s_etat_processus).erreur_execution = d_ex; @@ -409,8 +409,8 @@ instruction_diag_fleche(struct_processus (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes; if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau - = malloc((*((struct_vecteur *) (*s_objet_resultat).objet)) - .taille * sizeof(integer8))) == NULL) + = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat) + .objet)).taille) * sizeof(integer8))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -467,8 +467,8 @@ instruction_diag_fleche(struct_processus (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes; if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau - = malloc((*((struct_vecteur *) (*s_objet_resultat).objet)) - .taille * sizeof(real8))) == NULL) + = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat) + .objet)).taille) * sizeof(real8))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -525,8 +525,8 @@ instruction_diag_fleche(struct_processus (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes; if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau - = malloc((*((struct_vecteur *) (*s_objet_resultat).objet)) - .taille * sizeof(complex16))) == NULL) + = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat) + .objet)).taille) * sizeof(complex16))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -605,14 +605,23 @@ instruction_diag_fleche(struct_processus void instruction_digest(struct_processus *s_etat_processus) { - EVP_MD_CTX contexte; + EVP_MD_CTX *contexte; - const EVP_MD * (*EVP_sum)(); + const EVP_MD *EVP_sum; + const EVP_CIPHER *EVP_chiffrement; - logical1 somme_invalide; + int i; + int longueur_bloc; + int longueur_somme; + + integer8 longueur_chaine; + integer8 longueur_clef; + integer8 longueur_clef_attendue; + integer8 longueur_clef_max; + integer8 longueur_clef_min; + integer8 longueur_tampon; - long i; - long longueur_chaine; + logical1 somme_invalide; struct_liste_chainee *l_element_courant; @@ -625,12 +634,7 @@ instruction_digest(struct_processus *s_e 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; + unsigned char *vecteur_initialisation; (*s_etat_processus).erreur_execution = d_ex; @@ -664,10 +668,24 @@ instruction_digest(struct_processus *s_e printf(" Algorithms:\n\n"); } -# ifndef OPENSSL_NO_SHA - printf(" - DSS\n"); - printf(" - DSS1\n"); - printf(" - ECDSA\n"); +# ifndef OPENSSL_NO_AES + printf(" - AES-128-CBC\n"); + printf(" - AES-192-CBC\n"); + printf(" - AES-256-CBC\n"); +# endif +# ifndef OPENSSL_NO_CAMELLIA + printf(" - CAMELLIA-128-CBC\n"); + printf(" - CAMELLIA-192-CBC\n"); + printf(" - CAMELLIA-256-CBC\n"); +# endif +# ifndef OPENSSL_NO_DES + printf(" - DES-CBC\n"); + printf(" - DES-EDE-CBC\n"); + printf(" - DES-EDE3-CB\n"); + printf(" - DESX-CBC\n"); +# endif +# ifndef OPENSSL_NO_IDEA + printf(" - IDEA-CBC\n"); # endif # ifndef OPENSSL_NO_MD2 printf(" - MD2\n"); @@ -681,21 +699,19 @@ instruction_digest(struct_processus *s_e # ifndef OPENSSL_NO_MDC2 printf(" - MDC2\n"); # endif +# ifndef OPENSSL_NO_RC2 + printf(" - RC2-CBC\n"); + printf(" - RC2-40-CBC\n"); + printf(" - RC2-64-CBC\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 @@ -713,7 +729,7 @@ instruction_digest(struct_processus *s_e printf(" \"text\" \"MD5\" DIGEST\n"); printf(" \"text\" { \"SHA384\" \"key\" } DIGEST\n"); - printf(" \"text\" { \"AES-CBC\" \"key\" } DIGEST\n"); + printf(" \"text\" { \"AES-128-CBC\" \"key\" } DIGEST\n"); return; } else if ((*s_etat_processus).test_instruction == 'Y') @@ -750,15 +766,11 @@ instruction_digest(struct_processus *s_e ((*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 @@ -766,8 +778,8 @@ instruction_digest(struct_processus *s_e // - EVP_sha512 // - EVP_whirlpool - if ((fonction = conversion_majuscule((unsigned char *) - (*s_objet_argument_1).objet)) == NULL) + if ((fonction = conversion_majuscule(s_etat_processus, + (unsigned char *) (*s_objet_argument_1).objet)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -777,143 +789,6 @@ instruction_digest(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]) @@ -927,7 +802,7 @@ instruction_digest(struct_processus *s_e { if (fonction[3] == d_code_fin_chaine) { - EVP_sum = EVP_md2; + EVP_sum = EVP_md2(); } else { @@ -943,7 +818,7 @@ instruction_digest(struct_processus *s_e { if (fonction[3] == d_code_fin_chaine) { - EVP_sum = EVP_md4; + EVP_sum = EVP_md4(); } else { @@ -959,7 +834,7 @@ instruction_digest(struct_processus *s_e { if (fonction[3] == d_code_fin_chaine) { - EVP_sum = EVP_md5; + EVP_sum = EVP_md5(); } else { @@ -979,7 +854,7 @@ instruction_digest(struct_processus *s_e { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_mdc2; + EVP_sum = EVP_mdc2(); } else { @@ -1025,7 +900,7 @@ instruction_digest(struct_processus *s_e { if (strcmp(fonction, "RIPEMD160") == 0) { - EVP_sum = EVP_ripemd160; + EVP_sum = EVP_ripemd160(); } else { @@ -1044,22 +919,15 @@ instruction_digest(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] == d_code_fin_chaine) { - EVP_sum = EVP_sha1; + EVP_sum = EVP_sha1(); } else { @@ -1069,7 +937,6 @@ instruction_digest(struct_processus *s_e break; } -# ifndef OPENSSL_NO_SHA256 case '2': // sha2 { switch(fonction[4]) @@ -1084,12 +951,12 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha224; + EVP_sha224(); } else { somme_invalide = - d_vrai; + d_vrai; } break; @@ -1115,12 +982,12 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha256; + EVP_sha256(); } else { somme_invalide = - d_vrai; + d_vrai; } break; @@ -1145,9 +1012,7 @@ instruction_digest(struct_processus *s_e break; } -# endif -# ifndef OPENSSL_NO_SHA512 case '3': // sha3 { switch(fonction[4]) @@ -1162,12 +1027,12 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha384; + EVP_sha384(); } else { somme_invalide = - d_vrai; + d_vrai; } break; @@ -1207,12 +1072,12 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha512; + EVP_sha512(); } else { somme_invalide = - d_vrai; + d_vrai; } break; @@ -1237,7 +1102,6 @@ instruction_digest(struct_processus *s_e break; } -# endif default: { @@ -1248,7 +1112,6 @@ instruction_digest(struct_processus *s_e break; } -# endif default: { @@ -1275,7 +1138,7 @@ instruction_digest(struct_processus *s_e { if (strcmp(fonction, "WHIRLPOOL") == 0) { - EVP_sum = EVP_whirlpool; + EVP_sum = EVP_whirlpool(); } else { @@ -1305,9 +1168,18 @@ instruction_digest(struct_processus *s_e return; } - if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + if ((contexte = EVP_MD_CTX_new()) == NULL) { - 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_systeme = d_es_allocation_memoire; + return; + } + + if (EVP_DigestInit(contexte, EVP_sum) != 1) + { + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -1319,7 +1191,7 @@ instruction_digest(struct_processus *s_e if ((chaine = formateur_flux(s_etat_processus, (unsigned char *) (*s_objet_argument_2).objet, &longueur_chaine)) == NULL) { - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -1327,10 +1199,10 @@ instruction_digest(struct_processus *s_e return; } - if (EVP_DigestUpdate(&contexte, chaine, longueur_chaine) != 1) + if (EVP_DigestUpdate(contexte, chaine, (size_t) longueur_chaine) != 1) { free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -1339,10 +1211,10 @@ instruction_digest(struct_processus *s_e return; } - if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + if (EVP_DigestFinal_ex(contexte, somme, &longueur_somme) != 1) { free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -1352,7 +1224,7 @@ instruction_digest(struct_processus *s_e } free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL) { @@ -1418,8 +1290,9 @@ instruction_digest(struct_processus *s_e l_element_courant = (*s_objet_argument_1).objet; - if ((fonction = conversion_majuscule((unsigned char *) - (*(*l_element_courant).donnee).objet)) == NULL) + if ((fonction = conversion_majuscule(s_etat_processus, + (unsigned char *) (*(*l_element_courant).donnee).objet)) + == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -1429,146 +1302,6 @@ instruction_digest(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; - 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]) @@ -1582,8 +1315,7 @@ instruction_digest(struct_processus *s_e { if (fonction[3] == d_code_fin_chaine) { - EVP_sum = EVP_md2; - longueur_bloc = MD2_BLOCK; + EVP_sum = EVP_md2(); } else { @@ -1599,8 +1331,7 @@ instruction_digest(struct_processus *s_e { if (fonction[3] == d_code_fin_chaine) { - EVP_sum = EVP_md4; - longueur_bloc = MD4_CBLOCK; + EVP_sum = EVP_md4(); } else { @@ -1616,8 +1347,7 @@ instruction_digest(struct_processus *s_e { if (fonction[3] == d_code_fin_chaine) { - EVP_sum = EVP_md5; - longueur_bloc = MD5_CBLOCK; + EVP_sum = EVP_md5(); } else { @@ -1637,8 +1367,7 @@ instruction_digest(struct_processus *s_e { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_mdc2; - longueur_bloc = MDC2_BLOCK; + EVP_sum = EVP_mdc2(); } else { @@ -1684,8 +1413,7 @@ instruction_digest(struct_processus *s_e { if (strcmp(fonction, "RIPEMD160") == 0) { - EVP_sum = EVP_ripemd160; - longueur_bloc = RIPEMD160_CBLOCK; + EVP_sum = EVP_ripemd160(); } else { @@ -1704,24 +1432,15 @@ instruction_digest(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; - longueur_bloc = SHA_CBLOCK; - break; - } - case '1': // sha1 { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_sha1; - longueur_bloc = SHA_CBLOCK; + EVP_sum = EVP_sha1(); } else { @@ -1731,7 +1450,6 @@ instruction_digest(struct_processus *s_e break; } -# ifndef OPENSSL_NO_SHA256 case '2': // sha2 { switch(fonction[4]) @@ -1746,9 +1464,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha224; - longueur_bloc = - SHA256_CBLOCK; + EVP_sha224(); } else { @@ -1779,9 +1495,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha256; - longueur_bloc = - SHA256_CBLOCK; + EVP_sha256(); } else { @@ -1811,9 +1525,7 @@ instruction_digest(struct_processus *s_e break; } -# endif -# ifndef OPENSSL_NO_SHA512 case '3': // sha3 { switch(fonction[4]) @@ -1828,9 +1540,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha384; - longueur_bloc = - SHA512_CBLOCK; + EVP_sha384(); } else { @@ -1875,9 +1585,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha512; - longueur_bloc = - SHA512_CBLOCK; + EVP_sha512(); } else { @@ -1907,7 +1615,6 @@ instruction_digest(struct_processus *s_e break; } -# endif default: { @@ -1918,7 +1625,6 @@ instruction_digest(struct_processus *s_e break; } -# endif default: { @@ -1945,8 +1651,7 @@ instruction_digest(struct_processus *s_e { if (strcmp(fonction, "WHIRLPOOL") == 0) { - EVP_sum = EVP_whirlpool; - longueur_bloc = WHIRLPOOL_BBLOCK / 8; + EVP_sum = EVP_whirlpool(); } else { @@ -1964,13 +1669,350 @@ instruction_digest(struct_processus *s_e } } - free(fonction); - if (somme_invalide == d_vrai) { // Le chiffrement est de type CBC-MAC - BUG(1, uprintf("Oops!")); - exit(0); + + if (strncmp(fonction, "AES", 3) == 0) + { +# ifdef OPENSSL_NO_AES + + free(fonction); + + 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 + + if (strcmp(fonction, "AES-128-CBC") == 0) + { + EVP_chiffrement = EVP_aes_128_cbc(); + } + else if (strcmp(fonction, "AES-192-CBC") == 0) + { + EVP_chiffrement = EVP_aes_192_cbc(); + } + else if (strcmp(fonction, "AES-256-CBC") == 0) + { + EVP_chiffrement = EVP_aes_256_cbc(); + } + else + { + free(fonction); + + 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; + } + + longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement); + longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement); + +# endif + } + else if (strncmp(fonction, "DES", 3) == 0) + { +# ifdef OPENSSL_NO_DES + + free(fonction); + + 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 + + if (strcmp(fonction, "DES-CBC") == 0) + { + EVP_chiffrement = EVP_des_cbc(); + } + else if (strcmp(fonction, "DES-EDE-CBC") == 0) + { + EVP_chiffrement = EVP_des_ede_cbc(); + } + else if (strcmp(fonction, "DES-EDE3-CBC") == 0) + { + EVP_chiffrement = EVP_des_ede3_cbc(); + } + else if (strcmp(fonction, "DESX-CBC") == 0) + { + EVP_chiffrement = EVP_desx_cbc(); + } + else + { + free(fonction); + + 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; + } + + longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement); + longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement); + +# endif + } + else if (strncmp(fonction, "CAMELLIA", 8) == 0) + { +# ifdef OPENSSL_NO_CAMELLIA + + free(fonction); + + 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 + + if (strcmp(fonction, "CAMELLIA-128-CBC") == 0) + { + EVP_chiffrement = EVP_camellia_128_cbc(); + } + else if (strcmp(fonction, "CAMELLIA-192-CBC") == 0) + { + EVP_chiffrement = EVP_camellia_192_cbc(); + } + else if (strcmp(fonction, "CAMELLIA-256-CBC") == 0) + { + EVP_chiffrement = EVP_camellia_256_cbc(); + } + else + { + free(fonction); + + 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; + } + + longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement); + longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement); + +# endif + } + else if (strncmp(fonction, "RC2", 3) == 0) + { +# ifdef OPENSSL_NO_RC2 + + free(fonction); + + 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 + + if (strcmp(fonction, "RC2-CBC") == 0) + { + EVP_chiffrement = EVP_rc2_cbc(); + } + else if (strcmp(fonction, "RC2-40-CBC") == 0) + { + EVP_chiffrement = EVP_rc2_40_cbc(); + } + else if (strcmp(fonction, "RC2-64-CBC") == 0) + { + EVP_chiffrement = EVP_rc2_64_cbc(); + } + else + { + free(fonction); + + 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; + } + + longueur_clef_attendue = 0; + longueur_clef_min = 1; + longueur_clef_max = 16; + longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement); + +# endif + } + else if (strncmp(fonction, "IDEA", 4) == 0) + { +# ifdef OPENSSL_NO_IDEA + + free(fonction); + + 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 + + if (strcmp(fonction, "IDEA-CBC") == 0) + { + EVP_chiffrement = EVP_idea_cbc(); + } + else + { + free(fonction); + + 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; + } + + longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement); + longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement); + +# endif + } + else + { + free(fonction); + + 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 ((chaine = formateur_flux(s_etat_processus, (unsigned char *) + (*s_objet_argument_2).objet, &longueur_chaine)) == NULL) + { + free(fonction); + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + return; + } + + 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) + { + free(fonction); + free(chaine); + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + return; + } + + if (longueur_clef_attendue != 0) + { + if (longueur_clef != longueur_clef_attendue) + { + free(fonction); + free(chaine); + 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_longueur_clef_chiffrement; + return; + } + } + else + { + if ((longueur_clef < longueur_clef_min) && + (longueur_clef > longueur_clef_max)) + { + free(fonction); + free(chaine); + 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_longueur_clef_chiffrement; + return; + } + } + + if ((vecteur_initialisation = malloc(((size_t) longueur_clef) * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return; + } + + memset(vecteur_initialisation, 0, (size_t) longueur_clef); + + if ((tampon = chiffrement(s_etat_processus, EVP_chiffrement, d_vrai, + chaine, longueur_chaine, clef, longueur_clef, + vecteur_initialisation, &longueur_tampon)) == NULL) + { + free(fonction); + free(vecteur_initialisation); + free(chaine); + free(clef); + + (*s_etat_processus).erreur_execution = + d_ex_chiffrement; + return; + } + + free(vecteur_initialisation); + 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, + &(tampon[longueur_tampon - longueur_somme]), + longueur_somme)) == NULL) + { + free(tampon); + free(fonction); + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + return; + } + + free(tampon); + free(fonction); } else { @@ -1978,9 +2020,13 @@ instruction_digest(struct_processus *s_e // Le second élément de la chaîne contient la clef utilisée pour // la signature. + free(fonction); + l_element_courant = (*s_objet_argument_1).objet; l_element_courant = (*l_element_courant).suivant; + longueur_bloc = EVP_MD_block_size(EVP_sum); + if ((clef = formateur_flux(s_etat_processus, (unsigned char *) (*(*l_element_courant).donnee).objet, &longueur_clef)) == NULL) @@ -1995,16 +2041,16 @@ instruction_digest(struct_processus *s_e longueur_tampon = longueur_clef; tampon = clef; - if ((clef = malloc(longueur_bloc * sizeof(unsigned char))) - == NULL) + if ((clef = malloc(((size_t) 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); + memset(clef, 0, (size_t) longueur_bloc); + memcpy(clef, tampon, (size_t) longueur_tampon); longueur_clef = longueur_bloc; free(tampon); } @@ -2013,53 +2059,60 @@ instruction_digest(struct_processus *s_e longueur_tampon = longueur_clef; tampon = clef; - if ((clef = malloc(longueur_bloc * sizeof(unsigned char))) - == NULL) + if ((clef = malloc(((size_t) longueur_bloc) * + sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; } - memcpy(clef, tampon, longueur_bloc); + memcpy(clef, tampon, (size_t) longueur_bloc); longueur_clef = longueur_bloc; free(tampon); } for(i = 0; i < longueur_bloc; i++) { - clef[i] ^= 0x36; + clef[i] ^= (unsigned char) 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) * + if ((tampon = malloc(((size_t) (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); + memcpy(tampon, clef, (size_t) longueur_bloc); + memcpy(tampon + longueur_bloc, chaine, (size_t) longueur_chaine); longueur_tampon = longueur_bloc + longueur_chaine; - if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + if ((contexte = EVP_MD_CTX_new()) == NULL) + { + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + + (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; + return; + } + + if (EVP_DigestInit(contexte, EVP_sum) != 1) { free(tampon); free(clef); free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -2068,13 +2121,14 @@ instruction_digest(struct_processus *s_e return; } - if (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1) + if (EVP_DigestUpdate(contexte, tampon, (size_t) longueur_tampon) + != 1) { free(tampon); free(clef); free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -2085,10 +2139,10 @@ instruction_digest(struct_processus *s_e free(tampon); - if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + if (EVP_DigestFinal_ex(contexte, somme, &longueur_somme) != 1) { free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -2097,31 +2151,31 @@ instruction_digest(struct_processus *s_e return; } - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_reset(contexte); for(i = 0; i < longueur_bloc; i++) { clef[i] ^= (0x36 ^ 0x5c); } - if ((tampon = malloc((longueur_bloc + longueur_somme) * + if ((tampon = malloc(((size_t) (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); + memcpy(tampon, clef, (size_t) longueur_bloc); + memcpy(tampon + longueur_bloc, somme, (size_t) longueur_somme); longueur_tampon = longueur_bloc + longueur_somme; - if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + if (EVP_DigestInit(contexte, EVP_sum) != 1) { free(tampon); free(clef); free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -2130,13 +2184,14 @@ instruction_digest(struct_processus *s_e return; } - if (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1) + if (EVP_DigestUpdate(contexte, tampon, (size_t) longueur_tampon) + != 1) { free(tampon); free(clef); free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -2147,10 +2202,10 @@ instruction_digest(struct_processus *s_e free(tampon); - if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1) + if (EVP_DigestFinal_ex(contexte, somme, &longueur_somme) != 1) { free(chaine); - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); liberation(s_etat_processus, s_objet_argument_1); liberation(s_etat_processus, s_objet_argument_2); @@ -2159,7 +2214,7 @@ instruction_digest(struct_processus *s_e return; } - EVP_MD_CTX_cleanup(&contexte); + EVP_MD_CTX_free(contexte); free(chaine); free(clef);