--- rpl/src/instructions_d6.c 2013/02/25 11:24:02 1.41 +++ rpl/src/instructions_d6.c 2013/02/27 14:12:57 1.45 @@ -1,7 +1,7 @@ /* ================================================================================ RPL/2 (R) version 4.1.12 - Copyright (C) 1989-2012 Dr. BERTRAND Joël + Copyright (C) 1989-2013 Dr. BERTRAND Joël This file is part of RPL/2. @@ -607,7 +607,8 @@ instruction_digest(struct_processus *s_e { EVP_MD_CTX contexte; - const EVP_MD * (*EVP_sum)(); + const EVP_MD *EVP_sum; + const EVP_CIPHER *EVP_chiffrement; logical1 somme_invalide; @@ -625,12 +626,16 @@ instruction_digest(struct_processus *s_e unsigned char *fonction; unsigned char somme[EVP_MAX_MD_SIZE]; unsigned char *tampon; + unsigned char *vecteur_initialisation; unsigned int longueur_bloc; unsigned int longueur_somme; unsigned int longueur_tampon; unsigned long longueur_clef; + unsigned long longueur_clef_attendue; + unsigned long longueur_clef_max; + unsigned long longueur_clef_min; (*s_etat_processus).erreur_execution = d_ex; @@ -664,11 +669,30 @@ instruction_digest(struct_processus *s_e printf(" Algorithms:\n\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_SHA printf(" - DSS\n"); printf(" - DSS1\n"); printf(" - ECDSA\n"); # endif +# ifndef OPENSSL_NO_IDEA + printf(" - IDEA-CBC\n"); +# endif # ifndef OPENSSL_NO_MD2 printf(" - MD2\n"); # endif @@ -681,6 +705,11 @@ 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 @@ -713,7 +742,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') @@ -792,7 +821,7 @@ instruction_digest(struct_processus *s_e { case d_code_fin_chaine: { - EVP_sum = EVP_dss; + EVP_sum = EVP_dss(); break; } @@ -800,7 +829,7 @@ instruction_digest(struct_processus *s_e { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_dss1; + EVP_sum = EVP_dss1(); } else { @@ -863,7 +892,7 @@ instruction_digest(struct_processus *s_e if (fonction[5] == d_code_fin_chaine) { - EVP_sum = EVP_ecdsa; + EVP_sum = EVP_ecdsa(); } else { @@ -927,7 +956,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 +972,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 +988,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 +1008,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 +1054,7 @@ instruction_digest(struct_processus *s_e { if (strcmp(fonction, "RIPEMD160") == 0) { - EVP_sum = EVP_ripemd160; + EVP_sum = EVP_ripemd160(); } else { @@ -1051,7 +1080,7 @@ instruction_digest(struct_processus *s_e { case d_code_fin_chaine: { - EVP_sum = EVP_sha; + EVP_sum = EVP_sha(); break; } @@ -1059,7 +1088,7 @@ instruction_digest(struct_processus *s_e { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_sha1; + EVP_sum = EVP_sha1(); } else { @@ -1084,12 +1113,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 +1144,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; @@ -1162,12 +1191,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 +1236,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; @@ -1275,7 +1304,7 @@ instruction_digest(struct_processus *s_e { if (strcmp(fonction, "WHIRLPOOL") == 0) { - EVP_sum = EVP_whirlpool; + EVP_sum = EVP_whirlpool(); } else { @@ -1305,7 +1334,7 @@ instruction_digest(struct_processus *s_e return; } - if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + if (EVP_DigestInit(&contexte, EVP_sum) != 1) { EVP_MD_CTX_cleanup(&contexte); @@ -1444,8 +1473,7 @@ instruction_digest(struct_processus *s_e { case d_code_fin_chaine: { - EVP_sum = EVP_dss; - longueur_bloc = SHA_CBLOCK; + EVP_sum = EVP_dss(); break; } @@ -1453,8 +1481,7 @@ instruction_digest(struct_processus *s_e { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_dss1; - longueur_bloc = SHA_CBLOCK; + EVP_sum = EVP_dss1(); } else { @@ -1517,8 +1544,7 @@ instruction_digest(struct_processus *s_e if (fonction[5] == d_code_fin_chaine) { - EVP_sum = EVP_ecdsa; - longueur_bloc = SHA_CBLOCK; + EVP_sum = EVP_ecdsa(); } else { @@ -1582,8 +1608,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 +1624,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 +1640,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 +1660,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 +1706,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 { @@ -1711,8 +1732,7 @@ instruction_digest(struct_processus *s_e { case d_code_fin_chaine: { - EVP_sum = EVP_sha; - longueur_bloc = SHA_CBLOCK; + EVP_sum = EVP_sha(); break; } @@ -1720,8 +1740,7 @@ instruction_digest(struct_processus *s_e { if (fonction[4] == d_code_fin_chaine) { - EVP_sum = EVP_sha1; - longueur_bloc = SHA_CBLOCK; + EVP_sum = EVP_sha1(); } else { @@ -1746,9 +1765,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha224; - longueur_bloc = - SHA256_CBLOCK; + EVP_sha224(); } else { @@ -1779,9 +1796,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha256; - longueur_bloc = - SHA256_CBLOCK; + EVP_sha256(); } else { @@ -1828,9 +1843,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha384; - longueur_bloc = - SHA512_CBLOCK; + EVP_sha384(); } else { @@ -1875,9 +1888,7 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = - EVP_sha512; - longueur_bloc = - SHA512_CBLOCK; + EVP_sha512(); } else { @@ -1945,8 +1956,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 +1974,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(longueur_clef * + sizeof(unsigned char))) == NULL) + { + (*s_etat_processus).erreur_systeme = + d_es_allocation_memoire; + return; + } + + memset(vecteur_initialisation, 0, longueur_clef); + + if ((tampon = chiffrement(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 +2325,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) @@ -2053,7 +2404,7 @@ instruction_digest(struct_processus *s_e memcpy(tampon + longueur_bloc, chaine, longueur_chaine); longueur_tampon = longueur_bloc + longueur_chaine; - if (EVP_DigestInit(&contexte, EVP_sum()) != 1) + if (EVP_DigestInit(&contexte, EVP_sum) != 1) { free(tampon); free(clef); @@ -2115,7 +2466,7 @@ instruction_digest(struct_processus *s_e memcpy(tampon + longueur_bloc, somme, 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);