--- rpl/src/instructions_d6.c 2013/02/26 10:25:21 1.43 +++ rpl/src/instructions_d6.c 2014/04/25 07:37:31 1.54 @@ -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.18 + Copyright (C) 1989-2014 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; @@ -610,10 +610,18 @@ instruction_digest(struct_processus *s_e 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; @@ -628,15 +636,6 @@ instruction_digest(struct_processus *s_e 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; if ((*s_etat_processus).affichage_arguments == 'Y') @@ -1356,7 +1355,7 @@ 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); @@ -1474,7 +1473,6 @@ instruction_digest(struct_processus *s_e case d_code_fin_chaine: { EVP_sum = EVP_dss(); - longueur_bloc = SHA_CBLOCK; break; } @@ -1483,7 +1481,6 @@ instruction_digest(struct_processus *s_e if (fonction[4] == d_code_fin_chaine) { EVP_sum = EVP_dss1(); - longueur_bloc = SHA_CBLOCK; } else { @@ -1547,7 +1544,6 @@ instruction_digest(struct_processus *s_e d_code_fin_chaine) { EVP_sum = EVP_ecdsa(); - longueur_bloc = SHA_CBLOCK; } else { @@ -1612,7 +1608,6 @@ instruction_digest(struct_processus *s_e if (fonction[3] == d_code_fin_chaine) { EVP_sum = EVP_md2(); - longueur_bloc = MD2_BLOCK; } else { @@ -1629,7 +1624,6 @@ instruction_digest(struct_processus *s_e if (fonction[3] == d_code_fin_chaine) { EVP_sum = EVP_md4(); - longueur_bloc = MD4_CBLOCK; } else { @@ -1646,7 +1640,6 @@ instruction_digest(struct_processus *s_e if (fonction[3] == d_code_fin_chaine) { EVP_sum = EVP_md5(); - longueur_bloc = MD5_CBLOCK; } else { @@ -1667,7 +1660,6 @@ instruction_digest(struct_processus *s_e if (fonction[4] == d_code_fin_chaine) { EVP_sum = EVP_mdc2(); - longueur_bloc = MDC2_BLOCK; } else { @@ -1714,7 +1706,6 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "RIPEMD160") == 0) { EVP_sum = EVP_ripemd160(); - longueur_bloc = RIPEMD160_CBLOCK; } else { @@ -1741,7 +1732,6 @@ instruction_digest(struct_processus *s_e case d_code_fin_chaine: { EVP_sum = EVP_sha(); - longueur_bloc = SHA_CBLOCK; break; } @@ -1750,7 +1740,6 @@ instruction_digest(struct_processus *s_e if (fonction[4] == d_code_fin_chaine) { EVP_sum = EVP_sha1(); - longueur_bloc = SHA_CBLOCK; } else { @@ -1776,8 +1765,6 @@ instruction_digest(struct_processus *s_e { EVP_sum = EVP_sha224(); - longueur_bloc = - SHA256_CBLOCK; } else { @@ -1809,8 +1796,6 @@ instruction_digest(struct_processus *s_e { EVP_sum = EVP_sha256(); - longueur_bloc = - SHA256_CBLOCK; } else { @@ -1858,8 +1843,6 @@ instruction_digest(struct_processus *s_e { EVP_sum = EVP_sha384(); - longueur_bloc = - SHA512_CBLOCK; } else { @@ -1905,8 +1888,6 @@ instruction_digest(struct_processus *s_e { EVP_sum = EVP_sha512(); - longueur_bloc = - SHA512_CBLOCK; } else { @@ -1975,7 +1956,6 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "WHIRLPOOL") == 0) { EVP_sum = EVP_whirlpool(); - longueur_bloc = WHIRLPOOL_BBLOCK / 8; } else { @@ -2015,20 +1995,14 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "AES-128-CBC") == 0) { EVP_chiffrement = EVP_aes_128_cbc(); - longueur_clef_attendue = 16; - longueur_somme = AES_BLOCK_SIZE; } else if (strcmp(fonction, "AES-192-CBC") == 0) { EVP_chiffrement = EVP_aes_192_cbc(); - longueur_clef_attendue = 24; - longueur_somme = AES_BLOCK_SIZE; } else if (strcmp(fonction, "AES-256-CBC") == 0) { EVP_chiffrement = EVP_aes_256_cbc(); - longueur_clef_attendue = 32; - longueur_somme = AES_BLOCK_SIZE; } else { @@ -2042,6 +2016,9 @@ instruction_digest(struct_processus *s_e 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) @@ -2062,26 +2039,18 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "DES-CBC") == 0) { EVP_chiffrement = EVP_des_cbc(); - longueur_clef_attendue = 7; - longueur_somme = 8; } else if (strcmp(fonction, "DES-EDE-CBC") == 0) { EVP_chiffrement = EVP_des_ede_cbc(); - longueur_clef_attendue = 7; - longueur_somme = 8; } else if (strcmp(fonction, "DES-EDE3-CBC") == 0) { EVP_chiffrement = EVP_des_ede3_cbc(); - longueur_clef_attendue = 7; - longueur_somme = 8; } else if (strcmp(fonction, "DESX-CBC") == 0) { EVP_chiffrement = EVP_desx_cbc(); - longueur_clef_attendue = 7; - longueur_somme = 8; } else { @@ -2094,6 +2063,10 @@ instruction_digest(struct_processus *s_e 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) @@ -2114,20 +2087,14 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "CAMELLIA-128-CBC") == 0) { EVP_chiffrement = EVP_camellia_128_cbc(); - longueur_clef_attendue = 16; - longueur_somme = CAMELLIA_BLOCK_SIZE; } else if (strcmp(fonction, "CAMELLIA-192-CBC") == 0) { EVP_chiffrement = EVP_camellia_192_cbc(); - longueur_clef_attendue = 24; - longueur_somme = CAMELLIA_BLOCK_SIZE; } else if (strcmp(fonction, "CAMELLIA-256-CBC") == 0) { EVP_chiffrement = EVP_camellia_256_cbc(); - longueur_clef_attendue = 32; - longueur_somme = CAMELLIA_BLOCK_SIZE; } else { @@ -2140,6 +2107,10 @@ instruction_digest(struct_processus *s_e 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) @@ -2160,26 +2131,14 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "RC2-CBC") == 0) { EVP_chiffrement = EVP_rc2_cbc(); - longueur_clef_attendue = 0; - longueur_clef_min = 1; - longueur_clef_max = 16; - longueur_somme = RC2_BLOCK; } else if (strcmp(fonction, "RC2-40-CBC") == 0) { EVP_chiffrement = EVP_rc2_40_cbc(); - longueur_clef_attendue = 0; - longueur_clef_min = 1; - longueur_clef_max = 16; - longueur_somme = RC2_BLOCK; } else if (strcmp(fonction, "RC2-64-CBC") == 0) { EVP_chiffrement = EVP_rc2_64_cbc(); - longueur_clef_attendue = 0; - longueur_clef_min = 1; - longueur_clef_max = 16; - longueur_somme = RC2_BLOCK; } else { @@ -2192,6 +2151,12 @@ instruction_digest(struct_processus *s_e 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) @@ -2212,8 +2177,6 @@ instruction_digest(struct_processus *s_e if (strcmp(fonction, "IDEA-CBC") == 0) { EVP_chiffrement = EVP_idea_cbc(); - longueur_clef_attendue = 16; - longueur_somme = IDEA_BLOCK; } else { @@ -2226,6 +2189,10 @@ instruction_digest(struct_processus *s_e d_ex_chiffrement_indisponible; return; } + + longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement); + longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement); + # endif } else @@ -2300,7 +2267,7 @@ instruction_digest(struct_processus *s_e } } - if ((vecteur_initialisation = malloc(longueur_clef * + if ((vecteur_initialisation = malloc(((size_t) longueur_clef) * sizeof(unsigned char))) == NULL) { (*s_etat_processus).erreur_systeme = @@ -2308,12 +2275,11 @@ instruction_digest(struct_processus *s_e return; } - memset(vecteur_initialisation, 0, longueur_clef); + memset(vecteur_initialisation, 0, (size_t) longueur_clef); if ((tampon = chiffrement(EVP_chiffrement, d_vrai, chaine, longueur_chaine, clef, longueur_clef, - vecteur_initialisation, longueur_clef, - longueur_somme, &longueur_tampon)) == NULL) + vecteur_initialisation, &longueur_tampon)) == NULL) { free(fonction); free(vecteur_initialisation); @@ -2363,6 +2329,8 @@ instruction_digest(struct_processus *s_e 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) @@ -2377,16 +2345,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); } @@ -2395,22 +2363,22 @@ 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 *) @@ -2424,15 +2392,15 @@ instruction_digest(struct_processus *s_e 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) @@ -2450,7 +2418,8 @@ 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); @@ -2486,15 +2455,15 @@ instruction_digest(struct_processus *s_e 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) @@ -2512,7 +2481,8 @@ 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);