File:  [local] / rpl / src / instructions_d6.c
Revision 1.45: download - view: text, annotated - select for diffs - revision graph
Wed Feb 27 14:12:57 2013 UTC (11 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Ajout de la commande CIPHER pour la génération des clefs de chiffrement
et les opérations de chiffrement et déchiffrement.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.12
    4:   Copyright (C) 1989-2013 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'dupcntxt'
   29: ================================================================================
   30:   Entrées : pointeur sur une structure struct_processus
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_dupcntxt(struct_processus *s_etat_processus)
   40: {
   41:     struct_objet            *s_objet;
   42:     struct_objet            *s_pile;
   43: 
   44:     (*s_etat_processus).erreur_execution = d_ex;
   45: 
   46:     if ((*s_etat_processus).affichage_arguments == 'Y')
   47:     {
   48:         printf("\n  DUPCNTXT ");
   49: 
   50:         if ((*s_etat_processus).langue == 'F')
   51:         {
   52:             printf("(duplication du contexte)\n\n");
   53:             printf("  Aucun argument\n");
   54:         }
   55:         else
   56:         {
   57:             printf("(context duplication)\n\n");
   58:             printf("  No argument\n");
   59:         }
   60: 
   61:         return;
   62:     }
   63:     else if ((*s_etat_processus).test_instruction == 'Y')
   64:     {
   65:         (*s_etat_processus).nombre_arguments = -1;
   66:         return;
   67:     }
   68: 
   69:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
   70:     {
   71:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
   72:         {
   73:             return;
   74:         }
   75:     }
   76: 
   77:     if ((s_objet = allocation(s_etat_processus, LST)) == NULL)
   78:     {
   79:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
   80:         return;
   81:     }
   82: 
   83:     (*s_objet).objet = (*s_etat_processus).l_base_pile;
   84: 
   85:     if ((s_pile = copie_objet(s_etat_processus, s_objet, 'N')) == NULL)
   86:     {
   87:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
   88:         return;
   89:     }
   90: 
   91:     if (empilement(s_etat_processus, &((*s_etat_processus).
   92:             l_base_pile_contextes), s_objet) == d_erreur)
   93:     {
   94:         return;
   95:     }
   96: 
   97:     if ((s_objet = allocation(s_etat_processus, INT)) == NULL)
   98:     {
   99:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  100:         return;
  101:     }
  102: 
  103:     (*((integer8 *) (*s_objet).objet)) = (*s_etat_processus)
  104:             .hauteur_pile_operationnelle;
  105: 
  106:     if (empilement(s_etat_processus, &((*s_etat_processus)
  107:             .l_base_pile_taille_contextes), s_objet) == d_erreur)
  108:     {
  109:         return;
  110:     }
  111: 
  112:     /*
  113:      * Copie de la pile opérationnelle
  114:      */
  115: 
  116:     (*s_etat_processus).l_base_pile = (*s_pile).objet;
  117: 
  118:     (*s_pile).objet = NULL;
  119:     liberation(s_etat_processus, s_pile);
  120: 
  121:     return;
  122: }
  123: 
  124: 
  125: /*
  126: ================================================================================
  127:   Fonction 'dropcntxt'
  128: ================================================================================
  129:   Entrées : pointeur sur une structure struct_processus
  130: --------------------------------------------------------------------------------
  131:   Sorties :
  132: --------------------------------------------------------------------------------
  133:   Effets de bord : néant
  134: ================================================================================
  135: */
  136: 
  137: void
  138: instruction_dropcntxt(struct_processus *s_etat_processus)
  139: {
  140:     struct_objet                    *s_objet;
  141: 
  142:     (*s_etat_processus).erreur_execution = d_ex;
  143: 
  144:     if ((*s_etat_processus).affichage_arguments == 'Y')
  145:     {
  146:         printf("\n  DROPCNTXT ");
  147: 
  148:         if ((*s_etat_processus).langue == 'F')
  149:         {
  150:             printf("(effacement d'un contexte)\n\n");
  151:             printf("  Aucun argument\n");
  152:         }
  153:         else
  154:         {
  155:             printf("(drops context)\n\n");
  156:             printf("  No argument\n");
  157:         }
  158: 
  159:         return;
  160:     }
  161:     else if ((*s_etat_processus).test_instruction == 'Y')
  162:     {
  163:         (*s_etat_processus).nombre_arguments = -1;
  164:         return;
  165:     }
  166: 
  167:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  168:     {
  169:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  170:         {
  171:             return;
  172:         }
  173:     }
  174: 
  175:     if (((*s_etat_processus).l_base_pile_contextes == NULL) ||
  176:             ((*s_etat_processus).l_base_pile_taille_contextes == NULL))
  177:     {
  178:         (*s_etat_processus).erreur_execution = d_ex_contexte;
  179:         return;
  180:     }
  181: 
  182:     if (depilement(s_etat_processus, &((*s_etat_processus)
  183:             .l_base_pile_contextes), &s_objet) == d_erreur)
  184:     {
  185:         return;
  186:     }
  187: 
  188:     liberation(s_etat_processus, s_objet);
  189: 
  190:     if (depilement(s_etat_processus, &((*s_etat_processus)
  191:             .l_base_pile_taille_contextes), &s_objet) == d_erreur)
  192:     {
  193:         return;
  194:     }
  195: 
  196:     liberation(s_etat_processus, s_objet);
  197: 
  198:     return;
  199: }
  200: 
  201: 
  202: /*
  203: ================================================================================
  204:   Fonction 'dgtiz'
  205: ================================================================================
  206:   Entrées : pointeur sur une structure struct_processus
  207: --------------------------------------------------------------------------------
  208:   Sorties :
  209: --------------------------------------------------------------------------------
  210:   Effets de bord : néant
  211: ================================================================================
  212: */
  213: 
  214: void
  215: instruction_dgtiz(struct_processus *s_etat_processus)
  216: {
  217:     (*s_etat_processus).erreur_execution = d_ex;
  218: 
  219:     if ((*s_etat_processus).affichage_arguments == 'Y')
  220:     {
  221:         printf("\n  DGTIZ ");
  222: 
  223:         if ((*s_etat_processus).langue == 'F')
  224:         {
  225:             printf("(mouse support in plot functions)\n\n");
  226:             printf("  Aucun argument\n");
  227:         }
  228:         else
  229:         {
  230:             printf("(support de la souris dans les fonctions graphiques)\n\n");
  231:             printf("  No argument\n");
  232:         }
  233: 
  234:         return;
  235:     }
  236:     else if ((*s_etat_processus).test_instruction == 'Y')
  237:     {
  238:         (*s_etat_processus).nombre_arguments = -1;
  239:         return;
  240:     }
  241: 
  242:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  243:     {
  244:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  245:         {
  246:             return;
  247:         }
  248:     }
  249: 
  250:     if ((*s_etat_processus).fichiers_graphiques != NULL)
  251:     {
  252:         (*s_etat_processus).souris_active = d_vrai;
  253:         appel_gnuplot(s_etat_processus, 'N');
  254:         (*s_etat_processus).souris_active = d_faux;
  255:     }
  256: 
  257:     return;
  258: }
  259: 
  260: 
  261: /*
  262: ================================================================================
  263:   Fonction 'daemonize'
  264: ================================================================================
  265:   Entrées : pointeur sur une structure struct_processus
  266: --------------------------------------------------------------------------------
  267:   Sorties :
  268: --------------------------------------------------------------------------------
  269:   Effets de bord : néant
  270: ================================================================================
  271: */
  272: 
  273: void
  274: instruction_daemonize(struct_processus *s_etat_processus)
  275: {
  276:     (*s_etat_processus).erreur_execution = d_ex;
  277: 
  278:     if ((*s_etat_processus).affichage_arguments == 'Y')
  279:     {
  280:         printf("\n  DAEMONIZE ");
  281: 
  282:         if ((*s_etat_processus).langue == 'F')
  283:         {
  284:             printf("(basculement en mode daemon)\n\n");
  285:             printf("  Aucun argument\n");
  286:         }
  287:         else
  288:         {
  289:             printf("(convert to daemon)\n\n");
  290:             printf("  No argument\n");
  291:         }
  292: 
  293:         return;
  294:     }
  295:     else if ((*s_etat_processus).test_instruction == 'Y')
  296:     {
  297:         (*s_etat_processus).nombre_arguments = -1;
  298:         return;
  299:     }
  300: 
  301:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  302:     {
  303:         if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
  304:         {
  305:             return;
  306:         }
  307:     }
  308: 
  309:     if (((*s_etat_processus).var_volatile_processus_pere == -1) &&
  310:             ((*s_etat_processus).l_base_pile_processus == NULL))
  311:     {
  312:         lancement_daemon(s_etat_processus);
  313:     }
  314:     else
  315:     {
  316:         (*s_etat_processus).erreur_execution = d_ex_daemon;
  317:         return;
  318:     }
  319: 
  320:     return;
  321: }
  322: 
  323: 
  324: /*
  325: ================================================================================
  326:   Fonction 'diag->'
  327: ================================================================================
  328:   Entrées : pointeur sur une structure struct_processus
  329: --------------------------------------------------------------------------------
  330:   Sorties :
  331: --------------------------------------------------------------------------------
  332:   Effets de bord : néant
  333: ================================================================================
  334: */
  335: 
  336: void
  337: instruction_diag_fleche(struct_processus *s_etat_processus)
  338: {
  339:     struct_objet                *s_objet_argument;
  340:     struct_objet                *s_objet_resultat;
  341: 
  342:     unsigned long               i;
  343:     unsigned long               j;
  344: 
  345:     (*s_etat_processus).erreur_execution = d_ex;
  346: 
  347:     if ((*s_etat_processus).affichage_arguments == 'Y')
  348:     {
  349:         printf("\n  DIAG-> ");
  350: 
  351:         if ((*s_etat_processus).langue == 'F')
  352:         {
  353:             printf("(conversion d'une matrice diagonale en vecteur)\n\n");
  354:         }
  355:         else
  356:         {
  357:             printf("(diagonal matrix to vector conversion)\n\n");
  358:         }
  359: 
  360:         printf("    1: %s, %s, %s\n", d_MIN, d_MRL, d_MCX);
  361:         printf("->  1: %s, %s, %s\n", d_VIN, d_VRL, d_VCX);
  362: 
  363:         return;
  364:     }
  365:     else if ((*s_etat_processus).test_instruction == 'Y')
  366:     {
  367:         (*s_etat_processus).nombre_arguments = -1;
  368:         return;
  369:     }
  370: 
  371:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  372:     {
  373:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  374:         {
  375:             return;
  376:         }
  377:     }
  378: 
  379:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  380:             &s_objet_argument) == d_erreur)
  381:     {
  382:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  383:         return;
  384:     }
  385: 
  386:     /*
  387:      * Conversion d'une matrice
  388:      */
  389: 
  390:     if ((*s_objet_argument).type == MIN)
  391:     {
  392:         if ((*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes !=
  393:                 (*((struct_matrice *) (*s_objet_argument).objet))
  394:                 .nombre_colonnes)
  395:         {
  396:             (*s_etat_processus).erreur_execution = d_ex_dimensions_invalides;
  397: 
  398:             liberation(s_etat_processus, s_objet_argument);
  399:             return;
  400:         }
  401: 
  402:         if ((s_objet_resultat = allocation(s_etat_processus, VIN)) == NULL)
  403:         {
  404:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  405:             return;
  406:         }
  407: 
  408:         (*((struct_vecteur *) (*s_objet_resultat).objet)).taille =
  409:                 (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes;
  410: 
  411:         if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau
  412:                 = malloc((*((struct_vecteur *) (*s_objet_resultat).objet))
  413:                 .taille * sizeof(integer8))) == NULL)
  414:         {
  415:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  416:             return;
  417:         }
  418: 
  419:         for(i = 0; i < (*((struct_matrice *) (*s_objet_argument).objet))
  420:                 .nombre_lignes; i++)
  421:         {
  422:             for(j = 0; j < (*((struct_matrice *) (*s_objet_argument).objet))
  423:                     .nombre_colonnes; j++)
  424:             {
  425:                 if (i != j)
  426:                 {
  427:                     if (((integer8 **) (*((struct_matrice *) (*s_objet_argument)
  428:                             .objet)).tableau)[i][j] != 0)
  429:                     {
  430:                         liberation(s_etat_processus, s_objet_argument);
  431:                         liberation(s_etat_processus, s_objet_resultat);
  432: 
  433:                         (*s_etat_processus).erreur_execution =
  434:                                 d_ex_matrice_non_diagonale;
  435:                         return;
  436:                     }
  437:                 }
  438:                 else
  439:                 {
  440:                     ((integer8 *) (*((struct_vecteur *) (*s_objet_resultat)
  441:                             .objet)).tableau)[i] = ((integer8 **)
  442:                             (*((struct_matrice *) (*s_objet_argument)
  443:                             .objet)).tableau)[i][j];
  444:                 }
  445:             }
  446:         }
  447:     }
  448:     else if ((*s_objet_argument).type == MRL)
  449:     {
  450:         if ((*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes !=
  451:                 (*((struct_matrice *) (*s_objet_argument).objet))
  452:                 .nombre_colonnes)
  453:         {
  454:             (*s_etat_processus).erreur_execution = d_ex_dimensions_invalides;
  455: 
  456:             liberation(s_etat_processus, s_objet_argument);
  457:             return;
  458:         }
  459: 
  460:         if ((s_objet_resultat = allocation(s_etat_processus, VRL)) == NULL)
  461:         {
  462:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  463:             return;
  464:         }
  465: 
  466:         (*((struct_vecteur *) (*s_objet_resultat).objet)).taille =
  467:                 (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes;
  468: 
  469:         if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau
  470:                 = malloc((*((struct_vecteur *) (*s_objet_resultat).objet))
  471:                 .taille * sizeof(real8))) == NULL)
  472:         {
  473:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  474:             return;
  475:         }
  476: 
  477:         for(i = 0; i < (*((struct_matrice *) (*s_objet_argument).objet))
  478:                 .nombre_lignes; i++)
  479:         {
  480:             for(j = 0; j < (*((struct_matrice *) (*s_objet_argument).objet))
  481:                     .nombre_colonnes; j++)
  482:             {
  483:                 if (i != j)
  484:                 {
  485:                     if (((real8 **) (*((struct_matrice *) (*s_objet_argument)
  486:                             .objet)).tableau)[i][j] != 0)
  487:                     {
  488:                         liberation(s_etat_processus, s_objet_argument);
  489:                         liberation(s_etat_processus, s_objet_resultat);
  490: 
  491:                         (*s_etat_processus).erreur_execution =
  492:                                 d_ex_matrice_non_diagonale;
  493:                         return;
  494:                     }
  495:                 }
  496:                 else
  497:                 {
  498:                     ((real8 *) (*((struct_vecteur *) (*s_objet_resultat)
  499:                             .objet)).tableau)[i] = ((real8 **)
  500:                             (*((struct_matrice *) (*s_objet_argument)
  501:                             .objet)).tableau)[i][j];
  502:                 }
  503:             }
  504:         }
  505:     }
  506:     else if ((*s_objet_argument).type == MCX)
  507:     {
  508:         if ((*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes !=
  509:                 (*((struct_matrice *) (*s_objet_argument).objet))
  510:                 .nombre_colonnes)
  511:         {
  512:             (*s_etat_processus).erreur_execution = d_ex_dimensions_invalides;
  513: 
  514:             liberation(s_etat_processus, s_objet_argument);
  515:             return;
  516:         }
  517: 
  518:         if ((s_objet_resultat = allocation(s_etat_processus, VCX)) == NULL)
  519:         {
  520:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  521:             return;
  522:         }
  523: 
  524:         (*((struct_vecteur *) (*s_objet_resultat).objet)).taille =
  525:                 (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes;
  526: 
  527:         if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau
  528:                 = malloc((*((struct_vecteur *) (*s_objet_resultat).objet))
  529:                 .taille * sizeof(complex16))) == NULL)
  530:         {
  531:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  532:             return;
  533:         }
  534: 
  535:         for(i = 0; i < (*((struct_matrice *) (*s_objet_argument).objet))
  536:                 .nombre_lignes; i++)
  537:         {
  538:             for(j = 0; j < (*((struct_matrice *) (*s_objet_argument).objet))
  539:                     .nombre_colonnes; j++)
  540:             {
  541:                 if (i != j)
  542:                 {
  543:                     if ((((complex16 **) (*((struct_matrice *)
  544:                             (*s_objet_argument).objet)).tableau)[i][j]
  545:                             .partie_reelle != 0) ||
  546:                             (((complex16 **) (*((struct_matrice *)
  547:                             (*s_objet_argument).objet)).tableau)[i][j]
  548:                             .partie_imaginaire != 0))
  549:                     {
  550:                         liberation(s_etat_processus, s_objet_argument);
  551:                         liberation(s_etat_processus, s_objet_resultat);
  552: 
  553:                         (*s_etat_processus).erreur_execution =
  554:                                 d_ex_matrice_non_diagonale;
  555:                         return;
  556:                     }
  557:                 }
  558:                 else
  559:                 {
  560:                     ((complex16 *) (*((struct_vecteur *) (*s_objet_resultat)
  561:                             .objet)).tableau)[i] = ((complex16 **)
  562:                             (*((struct_matrice *) (*s_objet_argument)
  563:                             .objet)).tableau)[i][j];
  564:                 }
  565:             }
  566:         }
  567:     }
  568: 
  569:     /*
  570:      * Conversion impossible impossible
  571:      */
  572: 
  573:     else
  574:     {
  575:         liberation(s_etat_processus, s_objet_argument);
  576: 
  577:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  578:         return;
  579:     }
  580: 
  581:     liberation(s_etat_processus, s_objet_argument);
  582: 
  583:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  584:             s_objet_resultat) == d_erreur)
  585:     {
  586:         return;
  587:     }
  588: 
  589:     return;
  590: }
  591: 
  592: 
  593: /*
  594: ================================================================================
  595:   Fonction 'digest'
  596: ================================================================================
  597:   Entrées : pointeur sur une structure struct_processus
  598: --------------------------------------------------------------------------------
  599:   Sorties :
  600: --------------------------------------------------------------------------------
  601:   Effets de bord : néant
  602: ================================================================================
  603: */
  604: 
  605: void
  606: instruction_digest(struct_processus *s_etat_processus)
  607: {
  608:     EVP_MD_CTX                  contexte;
  609: 
  610:     const EVP_MD                *EVP_sum;
  611:     const EVP_CIPHER            *EVP_chiffrement;
  612: 
  613:     logical1                    somme_invalide;
  614: 
  615:     long                        i;
  616:     long                        longueur_chaine;
  617: 
  618:     struct_liste_chainee        *l_element_courant;
  619: 
  620:     struct_objet                *s_objet_argument_1;
  621:     struct_objet                *s_objet_argument_2;
  622:     struct_objet                *s_objet_resultat;
  623: 
  624:     unsigned char               *chaine;
  625:     unsigned char               *clef;
  626:     unsigned char               *fonction;
  627:     unsigned char               somme[EVP_MAX_MD_SIZE];
  628:     unsigned char               *tampon;
  629:     unsigned char               *vecteur_initialisation;
  630: 
  631:     unsigned int                longueur_bloc;
  632:     unsigned int                longueur_somme;
  633:     unsigned int                longueur_tampon;
  634: 
  635:     unsigned long               longueur_clef;
  636:     unsigned long               longueur_clef_attendue;
  637:     unsigned long               longueur_clef_max;
  638:     unsigned long               longueur_clef_min;
  639: 
  640:     (*s_etat_processus).erreur_execution = d_ex;
  641: 
  642:     if ((*s_etat_processus).affichage_arguments == 'Y')
  643:     {
  644:         printf("\n  DIGEST ");
  645: 
  646:         if ((*s_etat_processus).langue == 'F')
  647:         {
  648:             printf("(somme d'authentification)\n\n");
  649:         }
  650:         else
  651:         {
  652:             printf("(hash algorithm)\n\n");
  653:         }
  654: 
  655:         printf("    2: %s\n", d_CHN);
  656:         printf("    1: %s\n", d_CHN);
  657:         printf("->  1: %s\n\n", d_CHN);
  658: 
  659:         printf("    2: %s\n", d_CHN);
  660:         printf("    1: %s\n", d_LST);
  661:         printf("->  1: %s\n\n", d_CHN);
  662: 
  663:         if ((*s_etat_processus).langue == 'F')
  664:         {
  665:             printf("  Algorithmes :\n\n");
  666:         }
  667:         else
  668:         {
  669:             printf("  Algorithms:\n\n");
  670:         }
  671: 
  672: #       ifndef OPENSSL_NO_AES
  673:         printf("    - AES-128-CBC\n");
  674:         printf("    - AES-192-CBC\n");
  675:         printf("    - AES-256-CBC\n");
  676: #       endif
  677: #       ifndef OPENSSL_NO_CAMELLIA
  678:         printf("    - CAMELLIA-128-CBC\n");
  679:         printf("    - CAMELLIA-192-CBC\n");
  680:         printf("    - CAMELLIA-256-CBC\n");
  681: #       endif
  682: #       ifndef OPENSSL_NO_DES
  683:         printf("    - DES-CBC\n");
  684:         printf("    - DES-EDE-CBC\n");
  685:         printf("    - DES-EDE3-CB\n");
  686:         printf("    - DESX-CBC\n");
  687: #       endif
  688: #       ifndef OPENSSL_NO_SHA
  689:         printf("    - DSS\n");
  690:         printf("    - DSS1\n");
  691:         printf("    - ECDSA\n");
  692: #       endif
  693: #       ifndef OPENSSL_NO_IDEA
  694:         printf("    - IDEA-CBC\n");
  695: #       endif
  696: #       ifndef OPENSSL_NO_MD2
  697:         printf("    - MD2\n");
  698: #       endif
  699: #       ifndef OPENSSL_NO_MD4
  700:         printf("    - MD4\n");
  701: #       endif
  702: #       ifndef OPENSSL_NO_MD5
  703:         printf("    - MD5\n");
  704: #       endif
  705: #       ifndef OPENSSL_NO_MDC2
  706:         printf("    - MDC2\n");
  707: #       endif
  708: #       ifndef OPENSSL_NO_RC2
  709:         printf("    - RC2-CBC\n");
  710:         printf("    - RC2-40-CBC\n");
  711:         printf("    - RC2-64-CBC\n");
  712: #       endif
  713: #       ifndef OPENSSL_NO_RIPEMD
  714:         printf("    - RIPEMD160\n");
  715: #       endif
  716: #       ifndef OPENSSL_NO_SHA
  717:         printf("    - SHA\n");
  718:         printf("    - SHA1\n");
  719: #       endif
  720: #       ifndef OPENSSL_NO_SHA256
  721:         printf("    - SHA224\n");
  722:         printf("    - SHA256\n");
  723: #       endif
  724: #       ifndef OPENSSL_NO_SHA512
  725:         printf("    - SHA384\n");
  726:         printf("    - SHA512\n");
  727: #       endif
  728: #       ifndef OPENSSL_NO_WHIRLPOOL
  729:         printf("    - WHIRLPOOL\n");
  730: #       endif
  731: 
  732:         printf("\n");
  733: 
  734:         if ((*s_etat_processus).langue == 'F')
  735:         {
  736:             printf("  Utilisation :\n\n");
  737:         }
  738:         else
  739:         {
  740:             printf("  Usage:\n\n");
  741:         }
  742: 
  743:         printf("    \"text\" \"MD5\" DIGEST\n");
  744:         printf("    \"text\" { \"SHA384\" \"key\" } DIGEST\n");
  745:         printf("    \"text\" { \"AES-128-CBC\" \"key\" } DIGEST\n");
  746:         return;
  747:     }
  748:     else if ((*s_etat_processus).test_instruction == 'Y')
  749:     {
  750:         (*s_etat_processus).nombre_arguments = -1;
  751:         return;
  752:     }
  753: 
  754:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  755:     {
  756:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  757:         {
  758:             return;
  759:         }
  760:     }
  761: 
  762:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  763:             &s_objet_argument_1) == d_erreur)
  764:     {
  765:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  766:         return;
  767:     }
  768: 
  769:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  770:             &s_objet_argument_2) == d_erreur)
  771:     {
  772:         liberation(s_etat_processus, s_objet_argument_1);
  773: 
  774:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  775:         return;
  776:     }
  777: 
  778:     if (((*s_objet_argument_1).type == CHN) &&
  779:             ((*s_objet_argument_2).type == CHN))
  780:     {
  781:         // Liste des sommes disponibles :
  782:         // - EVP_dss
  783:         // - EVP_dss1
  784:         // - EVP_ecdsa
  785:         // - EVP_md2
  786:         // - EVP_md4
  787:         // - EVP_md5
  788:         // - EVP_mdc2
  789:         // - EVP_ripemd160
  790:         // - EVP_sha
  791:         // - EVP_sha1
  792:         // - EVP_sha224
  793:         // - EVP_sha256
  794:         // - EVP_sha384
  795:         // - EVP_sha512
  796:         // - EVP_whirlpool
  797: 
  798:         if ((fonction = conversion_majuscule((unsigned char *)
  799:                 (*s_objet_argument_1).objet)) == NULL)
  800:         {
  801:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  802:             return;
  803:         }
  804: 
  805:         somme_invalide = d_faux;
  806: 
  807:         switch(fonction[0])
  808:         {
  809:             case 'D':
  810:             {
  811:                 switch(fonction[1])
  812:                 {
  813:                     case 'S': // ds
  814:                     {
  815:                         switch(fonction[2])
  816:                         {
  817: #                           ifndef OPENSSL_NO_SHA
  818:                             case 'S': // dss
  819:                             {
  820:                                 switch(fonction[3])
  821:                                 {
  822:                                     case d_code_fin_chaine:
  823:                                     {
  824:                                         EVP_sum = EVP_dss();
  825:                                         break;
  826:                                     }
  827: 
  828:                                     case '1': // dss1
  829:                                     {
  830:                                         if (fonction[4] == d_code_fin_chaine)
  831:                                         {
  832:                                             EVP_sum = EVP_dss1();
  833:                                         }
  834:                                         else
  835:                                         {
  836:                                             somme_invalide = d_vrai;
  837:                                         }
  838: 
  839:                                         break;
  840:                                     }
  841: 
  842:                                     default:
  843:                                     {
  844:                                         somme_invalide = d_vrai;
  845:                                         break;
  846:                                     }
  847:                                 }
  848: 
  849:                                 break;
  850:                             }
  851: #                           endif
  852: 
  853:                             default:
  854:                             {
  855:                                 somme_invalide = d_vrai;
  856:                                 break;
  857:                             }
  858:                         }
  859: 
  860:                         break;
  861:                     }
  862: 
  863:                     default:
  864:                     {
  865:                         somme_invalide = d_vrai;
  866:                         break;
  867:                     }
  868:                 }
  869: 
  870:                 break;
  871:             }
  872: 
  873:             case 'E':
  874:             {
  875:                 switch(fonction[1])
  876:                 {
  877:                     case 'C': // ec
  878:                     {
  879:                         switch(fonction[2])
  880:                         {
  881:                             case 'D': // ecd
  882:                             {
  883:                                 switch(fonction[3])
  884:                                 {
  885:                                     case 'S': // ecds
  886:                                     {
  887:                                         switch(fonction[4])
  888:                                         {
  889: #                                           ifndef OPENSSL_NO_SHA
  890:                                             case 'A': // ecdsa
  891:                                             {
  892:                                                 if (fonction[5] ==
  893:                                                         d_code_fin_chaine)
  894:                                                 {
  895:                                                     EVP_sum = EVP_ecdsa();
  896:                                                 }
  897:                                                 else
  898:                                                 {
  899:                                                     somme_invalide = d_vrai;
  900:                                                 }
  901: 
  902:                                                 break;
  903:                                             }
  904: #                                           endif
  905: 
  906:                                             default:
  907:                                             {
  908:                                                 somme_invalide = d_vrai;
  909:                                                 break;
  910:                                             }
  911:                                         }
  912: 
  913:                                         break;
  914:                                     }
  915: 
  916:                                     default:
  917:                                     {
  918:                                         somme_invalide = d_vrai;
  919:                                         break;
  920:                                     }
  921:                                 }
  922: 
  923:                                 break;
  924:                             }
  925: 
  926:                             default:
  927:                             {
  928:                                 somme_invalide = d_vrai;
  929:                                 break;
  930:                             }
  931:                         }
  932: 
  933:                         break;
  934:                     }
  935: 
  936:                     default:
  937:                     {
  938:                         somme_invalide = d_vrai;
  939:                         break;
  940:                     }
  941:                 }
  942: 
  943:                 break;
  944:             }
  945: 
  946:             case 'M':
  947:             {
  948:                 switch(fonction[1])
  949:                 {
  950:                     case 'D': // md
  951:                     {
  952:                         switch(fonction[2])
  953:                         {
  954: #                           ifndef OPENSSL_NO_MD2
  955:                             case '2': // md2
  956:                             {
  957:                                 if (fonction[3] == d_code_fin_chaine)
  958:                                 {
  959:                                     EVP_sum = EVP_md2();
  960:                                 }
  961:                                 else
  962:                                 {
  963:                                     somme_invalide = d_vrai;
  964:                                 }
  965: 
  966:                                 break;
  967:                             }
  968: #                           endif
  969: 
  970: #                           ifndef OPENSSL_NO_MD4
  971:                             case '4': // md4
  972:                             {
  973:                                 if (fonction[3] == d_code_fin_chaine)
  974:                                 {
  975:                                     EVP_sum = EVP_md4();
  976:                                 }
  977:                                 else
  978:                                 {
  979:                                     somme_invalide = d_vrai;
  980:                                 }
  981: 
  982:                                 break;
  983:                             }
  984: #                           endif
  985: 
  986: #                           ifndef OPENSSL_NO_MD5
  987:                             case '5': // md5
  988:                             {
  989:                                 if (fonction[3] == d_code_fin_chaine)
  990:                                 {
  991:                                     EVP_sum = EVP_md5();
  992:                                 }
  993:                                 else
  994:                                 {
  995:                                     somme_invalide = d_vrai;
  996:                                 }
  997: 
  998:                                 break;
  999:                             }
 1000: #                           endif
 1001: 
 1002:                             case 'C': // mdc
 1003:                             {
 1004:                                 switch(fonction[3])
 1005:                                 {
 1006: #                                   ifndef OPENSSL_NO_MDC2
 1007:                                     case '2': // mdc2
 1008:                                     {
 1009:                                         if (fonction[4] == d_code_fin_chaine)
 1010:                                         {
 1011:                                             EVP_sum = EVP_mdc2();
 1012:                                         }
 1013:                                         else
 1014:                                         {
 1015:                                             somme_invalide = d_vrai;
 1016:                                         }
 1017: 
 1018:                                         break;
 1019:                                     }
 1020: #                                   endif
 1021: 
 1022:                                     default:
 1023:                                     {
 1024:                                         somme_invalide = d_vrai;
 1025:                                         break;
 1026:                                     }
 1027:                                 }
 1028: 
 1029:                                 break;
 1030:                             }
 1031: 
 1032:                             default:
 1033:                             {
 1034:                                 somme_invalide = d_vrai;
 1035:                                 break;
 1036:                             }
 1037:                         }
 1038: 
 1039:                         break;
 1040:                     }
 1041: 
 1042:                     default:
 1043:                     {
 1044:                         somme_invalide = d_vrai;
 1045:                         break;
 1046:                     }
 1047:                 }
 1048: 
 1049:                 break;
 1050:             }
 1051: 
 1052: #           ifndef OPENSSL_NO_RIPEMD
 1053:             case 'R':
 1054:             {
 1055:                 if (strcmp(fonction, "RIPEMD160") == 0)
 1056:                 {
 1057:                     EVP_sum = EVP_ripemd160();
 1058:                 }
 1059:                 else
 1060:                 {
 1061:                     somme_invalide = d_vrai;
 1062:                 }
 1063: 
 1064:                 break;
 1065:             }
 1066: #           endif
 1067: 
 1068:             case 'S':
 1069:             {
 1070:                 switch(fonction[1])
 1071:                 {
 1072:                     case 'H': // sh
 1073:                     {
 1074:                         switch(fonction[2])
 1075:                         {
 1076: #                           ifndef OPENSSL_NO_SHA
 1077:                             case 'A':
 1078:                             {
 1079:                                 switch(fonction[3])
 1080:                                 {
 1081:                                     case d_code_fin_chaine:
 1082:                                     {
 1083:                                         EVP_sum = EVP_sha();
 1084:                                         break;
 1085:                                     }
 1086: 
 1087:                                     case '1': // sha1
 1088:                                     {
 1089:                                         if (fonction[4] == d_code_fin_chaine)
 1090:                                         {
 1091:                                             EVP_sum = EVP_sha1();
 1092:                                         }
 1093:                                         else
 1094:                                         {
 1095:                                             somme_invalide = d_vrai;
 1096:                                         }
 1097: 
 1098:                                         break;
 1099:                                     }
 1100: 
 1101: #                                   ifndef OPENSSL_NO_SHA256
 1102:                                     case '2': // sha2
 1103:                                     {
 1104:                                         switch(fonction[4])
 1105:                                         {
 1106:                                             case '2': // sha22
 1107:                                             {
 1108:                                                 switch(fonction[5])
 1109:                                                 {
 1110:                                                     case '4': // sha224
 1111:                                                     {
 1112:                                                         if (fonction[6] ==
 1113:                                                             d_code_fin_chaine)
 1114:                                                         {
 1115:                                                             EVP_sum =
 1116:                                                                 EVP_sha224();
 1117:                                                         }
 1118:                                                         else
 1119:                                                         {
 1120:                                                             somme_invalide =
 1121:                                                                 d_vrai;
 1122:                                                         }
 1123: 
 1124:                                                         break;
 1125:                                                     }
 1126: 
 1127:                                                     default:
 1128:                                                     {
 1129:                                                         somme_invalide = d_vrai;
 1130:                                                         break;
 1131:                                                     }
 1132:                                                 }
 1133: 
 1134:                                                 break;
 1135:                                             }
 1136: 
 1137:                                             case '5':
 1138:                                             {
 1139:                                                 switch(fonction[5])
 1140:                                                 {
 1141:                                                     case '6': // sha256
 1142:                                                     {
 1143:                                                         if (fonction[6] ==
 1144:                                                             d_code_fin_chaine)
 1145:                                                         {
 1146:                                                             EVP_sum =
 1147:                                                                 EVP_sha256();
 1148:                                                         }
 1149:                                                         else
 1150:                                                         {
 1151:                                                             somme_invalide =
 1152:                                                                 d_vrai;
 1153:                                                         }
 1154: 
 1155:                                                         break;
 1156:                                                     }
 1157: 
 1158:                                                     default:
 1159:                                                     {
 1160:                                                         somme_invalide = d_vrai;
 1161:                                                         break;
 1162:                                                     }
 1163:                                                 }
 1164: 
 1165:                                                 break;
 1166:                                             }
 1167: 
 1168:                                             default:
 1169:                                             {
 1170:                                                 somme_invalide = d_vrai;
 1171:                                                 break;
 1172:                                             }
 1173:                                         }
 1174: 
 1175:                                         break;
 1176:                                     }
 1177: #                                   endif
 1178: 
 1179: #                                   ifndef OPENSSL_NO_SHA512
 1180:                                     case '3': // sha3
 1181:                                     {
 1182:                                         switch(fonction[4])
 1183:                                         {
 1184:                                             case '8': // sha38
 1185:                                             {
 1186:                                                 switch(fonction[5])
 1187:                                                 {
 1188:                                                     case '4': // sha384
 1189:                                                     {
 1190:                                                         if (fonction[6] ==
 1191:                                                             d_code_fin_chaine)
 1192:                                                         {
 1193:                                                             EVP_sum =
 1194:                                                                 EVP_sha384();
 1195:                                                         }
 1196:                                                         else
 1197:                                                         {
 1198:                                                             somme_invalide =
 1199:                                                                 d_vrai;
 1200:                                                         }
 1201: 
 1202:                                                         break;
 1203:                                                     }
 1204: 
 1205:                                                     default:
 1206:                                                     {
 1207:                                                         somme_invalide = d_vrai;
 1208:                                                         break;
 1209:                                                     }
 1210:                                                 }
 1211: 
 1212:                                                 break;
 1213:                                             }
 1214: 
 1215:                                             default:
 1216:                                             {
 1217:                                                 somme_invalide = d_vrai;
 1218:                                                 break;
 1219:                                             }
 1220:                                         }
 1221: 
 1222:                                         break;
 1223:                                     }
 1224: 
 1225:                                     case '5': // sha5
 1226:                                     {
 1227:                                         switch(fonction[4])
 1228:                                         {
 1229:                                             case '1': // sha51
 1230:                                             {
 1231:                                                 switch(fonction[5])
 1232:                                                 {
 1233:                                                     case '2': // sha512
 1234:                                                     {
 1235:                                                         if (fonction[6] ==
 1236:                                                             d_code_fin_chaine)
 1237:                                                         {
 1238:                                                             EVP_sum =
 1239:                                                                 EVP_sha512();
 1240:                                                         }
 1241:                                                         else
 1242:                                                         {
 1243:                                                             somme_invalide =
 1244:                                                                 d_vrai;
 1245:                                                         }
 1246: 
 1247:                                                         break;
 1248:                                                     }
 1249: 
 1250:                                                     default:
 1251:                                                     {
 1252:                                                         somme_invalide = d_vrai;
 1253:                                                         break;
 1254:                                                     }
 1255:                                                 }
 1256: 
 1257:                                                 break;
 1258:                                             }
 1259: 
 1260:                                             default:
 1261:                                             {
 1262:                                                 somme_invalide = d_vrai;
 1263:                                                 break;
 1264:                                             }
 1265:                                         }
 1266: 
 1267:                                         break;
 1268:                                     }
 1269: #                                   endif
 1270: 
 1271:                                     default:
 1272:                                     {
 1273:                                         somme_invalide = d_vrai;
 1274:                                         break;
 1275:                                     }
 1276:                                 }
 1277: 
 1278:                                 break;
 1279:                             }
 1280: #                           endif
 1281: 
 1282:                             default:
 1283:                             {
 1284:                                 somme_invalide = d_vrai;
 1285:                                 break;
 1286:                             }
 1287:                         }
 1288: 
 1289:                         break;
 1290:                     }
 1291: 
 1292:                     default:
 1293:                     {
 1294:                         somme_invalide = d_vrai;
 1295:                         break;
 1296:                     }
 1297:                 }
 1298: 
 1299:                 break;
 1300:             }
 1301: 
 1302: #           ifndef OPENSSL_NO_WHIRLPOOL
 1303:             case 'W':
 1304:             {
 1305:                 if (strcmp(fonction, "WHIRLPOOL") == 0)
 1306:                 {
 1307:                     EVP_sum = EVP_whirlpool();
 1308:                 }
 1309:                 else
 1310:                 {
 1311:                     somme_invalide = d_vrai;
 1312:                 }
 1313: 
 1314:                 break;
 1315:             }
 1316: #           endif
 1317: 
 1318:             default:
 1319:             {
 1320:                 somme_invalide = d_vrai;
 1321:                 break;
 1322:             }
 1323:         }
 1324: 
 1325:         free(fonction);
 1326: 
 1327:         if (somme_invalide == d_vrai)
 1328:         {
 1329:             liberation(s_etat_processus, s_objet_argument_1);
 1330:             liberation(s_etat_processus, s_objet_argument_2);
 1331: 
 1332:             (*s_etat_processus).erreur_execution =
 1333:                     d_ex_chiffrement_indisponible;
 1334:             return;
 1335:         }
 1336: 
 1337:         if (EVP_DigestInit(&contexte, EVP_sum) != 1)
 1338:         {
 1339:             EVP_MD_CTX_cleanup(&contexte);
 1340: 
 1341:             liberation(s_etat_processus, s_objet_argument_1);
 1342:             liberation(s_etat_processus, s_objet_argument_2);
 1343: 
 1344:             (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 1345:             return;
 1346:         }
 1347: 
 1348:         if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
 1349:                 (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
 1350:         {
 1351:             EVP_MD_CTX_cleanup(&contexte);
 1352: 
 1353:             liberation(s_etat_processus, s_objet_argument_1);
 1354:             liberation(s_etat_processus, s_objet_argument_2);
 1355: 
 1356:             return;
 1357:         }
 1358: 
 1359:         if (EVP_DigestUpdate(&contexte, chaine, longueur_chaine) != 1)
 1360:         {
 1361:             free(chaine);
 1362:             EVP_MD_CTX_cleanup(&contexte);
 1363: 
 1364:             liberation(s_etat_processus, s_objet_argument_1);
 1365:             liberation(s_etat_processus, s_objet_argument_2);
 1366: 
 1367:             (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 1368:             return;
 1369:         }
 1370: 
 1371:         if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
 1372:         {
 1373:             free(chaine);
 1374:             EVP_MD_CTX_cleanup(&contexte);
 1375: 
 1376:             liberation(s_etat_processus, s_objet_argument_1);
 1377:             liberation(s_etat_processus, s_objet_argument_2);
 1378: 
 1379:             (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 1380:             return;
 1381:         }
 1382: 
 1383:         free(chaine);
 1384:         EVP_MD_CTX_cleanup(&contexte);
 1385: 
 1386:         if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
 1387:         {
 1388:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1389:             return;
 1390:         }
 1391: 
 1392:         if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
 1393:                 somme, longueur_somme)) == NULL)
 1394:         {
 1395:             liberation(s_etat_processus, s_objet_argument_1);
 1396:             liberation(s_etat_processus, s_objet_argument_2);
 1397: 
 1398:             return;
 1399:         }
 1400:     }
 1401:     else if (((*s_objet_argument_1).type == LST) &&
 1402:             ((*s_objet_argument_2).type == CHN))
 1403:     {
 1404:         l_element_courant = (*s_objet_argument_1).objet;
 1405: 
 1406:         if ((*(*l_element_courant).donnee).type != CHN)
 1407:         {
 1408:             liberation(s_etat_processus, s_objet_argument_1);
 1409:             liberation(s_etat_processus, s_objet_argument_2);
 1410: 
 1411:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1412:             return;
 1413:         }
 1414: 
 1415:         l_element_courant = (*l_element_courant).suivant;
 1416: 
 1417:         if (l_element_courant == NULL)
 1418:         {
 1419:             liberation(s_etat_processus, s_objet_argument_1);
 1420:             liberation(s_etat_processus, s_objet_argument_2);
 1421: 
 1422:             (*s_etat_processus).erreur_execution = d_ex_manque_argument;
 1423:             return;
 1424:         }
 1425: 
 1426:         if ((*(*l_element_courant).donnee).type != CHN)
 1427:         {
 1428:             liberation(s_etat_processus, s_objet_argument_1);
 1429:             liberation(s_etat_processus, s_objet_argument_2);
 1430: 
 1431:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1432:             return;
 1433:         }
 1434: 
 1435:         if ((*l_element_courant).suivant != NULL)
 1436:         {
 1437:             liberation(s_etat_processus, s_objet_argument_1);
 1438:             liberation(s_etat_processus, s_objet_argument_2);
 1439: 
 1440:             (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
 1441:             return;
 1442:         }
 1443: 
 1444:         // Test du type de somme de contrôle
 1445:         // - les sommes classiques suivent la RFC 2104
 1446:         // - les autres sont formées sur des algorithmes de type CBC
 1447: 
 1448:         l_element_courant = (*s_objet_argument_1).objet;
 1449: 
 1450:         if ((fonction = conversion_majuscule((unsigned char *)
 1451:                 (*(*l_element_courant).donnee).objet)) == NULL)
 1452:         {
 1453:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1454:             return;
 1455:         }
 1456: 
 1457:         somme_invalide = d_faux;
 1458: 
 1459:         switch(fonction[0])
 1460:         {
 1461:             case 'D':
 1462:             {
 1463:                 switch(fonction[1])
 1464:                 {
 1465:                     case 'S': // ds
 1466:                     {
 1467:                         switch(fonction[2])
 1468:                         {
 1469: #                           ifndef OPENSSL_NO_SHA
 1470:                             case 'S': // dss
 1471:                             {
 1472:                                 switch(fonction[3])
 1473:                                 {
 1474:                                     case d_code_fin_chaine:
 1475:                                     {
 1476:                                         EVP_sum = EVP_dss();
 1477:                                         break;
 1478:                                     }
 1479: 
 1480:                                     case '1': // dss1
 1481:                                     {
 1482:                                         if (fonction[4] == d_code_fin_chaine)
 1483:                                         {
 1484:                                             EVP_sum = EVP_dss1();
 1485:                                         }
 1486:                                         else
 1487:                                         {
 1488:                                             somme_invalide = d_vrai;
 1489:                                         }
 1490: 
 1491:                                         break;
 1492:                                     }
 1493: 
 1494:                                     default:
 1495:                                     {
 1496:                                         somme_invalide = d_vrai;
 1497:                                         break;
 1498:                                     }
 1499:                                 }
 1500: 
 1501:                                 break;
 1502:                             }
 1503: #                           endif
 1504: 
 1505:                             default:
 1506:                             {
 1507:                                 somme_invalide = d_vrai;
 1508:                                 break;
 1509:                             }
 1510:                         }
 1511: 
 1512:                         break;
 1513:                     }
 1514: 
 1515:                     default:
 1516:                     {
 1517:                         somme_invalide = d_vrai;
 1518:                         break;
 1519:                     }
 1520:                 }
 1521: 
 1522:                 break;
 1523:             }
 1524: 
 1525:             case 'E':
 1526:             {
 1527:                 switch(fonction[1])
 1528:                 {
 1529:                     case 'C': // ec
 1530:                     {
 1531:                         switch(fonction[2])
 1532:                         {
 1533:                             case 'D': // ecd
 1534:                             {
 1535:                                 switch(fonction[3])
 1536:                                 {
 1537:                                     case 'S': // ecds
 1538:                                     {
 1539:                                         switch(fonction[4])
 1540:                                         {
 1541: #                                           ifndef OPENSSL_NO_SHA
 1542:                                             case 'A': // ecdsa
 1543:                                             {
 1544:                                                 if (fonction[5] ==
 1545:                                                         d_code_fin_chaine)
 1546:                                                 {
 1547:                                                     EVP_sum = EVP_ecdsa();
 1548:                                                 }
 1549:                                                 else
 1550:                                                 {
 1551:                                                     somme_invalide = d_vrai;
 1552:                                                 }
 1553: 
 1554:                                                 break;
 1555:                                             }
 1556: #                                           endif
 1557: 
 1558:                                             default:
 1559:                                             {
 1560:                                                 somme_invalide = d_vrai;
 1561:                                                 break;
 1562:                                             }
 1563:                                         }
 1564: 
 1565:                                         break;
 1566:                                     }
 1567: 
 1568:                                     default:
 1569:                                     {
 1570:                                         somme_invalide = d_vrai;
 1571:                                         break;
 1572:                                     }
 1573:                                 }
 1574: 
 1575:                                 break;
 1576:                             }
 1577: 
 1578:                             default:
 1579:                             {
 1580:                                 somme_invalide = d_vrai;
 1581:                                 break;
 1582:                             }
 1583:                         }
 1584: 
 1585:                         break;
 1586:                     }
 1587: 
 1588:                     default:
 1589:                     {
 1590:                         somme_invalide = d_vrai;
 1591:                         break;
 1592:                     }
 1593:                 }
 1594: 
 1595:                 break;
 1596:             }
 1597: 
 1598:             case 'M':
 1599:             {
 1600:                 switch(fonction[1])
 1601:                 {
 1602:                     case 'D': // md
 1603:                     {
 1604:                         switch(fonction[2])
 1605:                         {
 1606: #                           ifndef OPENSSL_NO_MD2
 1607:                             case '2': // md2
 1608:                             {
 1609:                                 if (fonction[3] == d_code_fin_chaine)
 1610:                                 {
 1611:                                     EVP_sum = EVP_md2();
 1612:                                 }
 1613:                                 else
 1614:                                 {
 1615:                                     somme_invalide = d_vrai;
 1616:                                 }
 1617: 
 1618:                                 break;
 1619:                             }
 1620: #                           endif
 1621: 
 1622: #                           ifndef OPENSSL_NO_MD4
 1623:                             case '4': // md4
 1624:                             {
 1625:                                 if (fonction[3] == d_code_fin_chaine)
 1626:                                 {
 1627:                                     EVP_sum = EVP_md4();
 1628:                                 }
 1629:                                 else
 1630:                                 {
 1631:                                     somme_invalide = d_vrai;
 1632:                                 }
 1633: 
 1634:                                 break;
 1635:                             }
 1636: #                           endif
 1637: 
 1638: #                           ifndef OPENSSL_NO_MD5
 1639:                             case '5': // md5
 1640:                             {
 1641:                                 if (fonction[3] == d_code_fin_chaine)
 1642:                                 {
 1643:                                     EVP_sum = EVP_md5();
 1644:                                 }
 1645:                                 else
 1646:                                 {
 1647:                                     somme_invalide = d_vrai;
 1648:                                 }
 1649: 
 1650:                                 break;
 1651:                             }
 1652: #                           endif
 1653: 
 1654:                             case 'C': // mdc
 1655:                             {
 1656:                                 switch(fonction[3])
 1657:                                 {
 1658: #                                   ifndef OPENSSL_NO_MDC2
 1659:                                     case '2': // mdc2
 1660:                                     {
 1661:                                         if (fonction[4] == d_code_fin_chaine)
 1662:                                         {
 1663:                                             EVP_sum = EVP_mdc2();
 1664:                                         }
 1665:                                         else
 1666:                                         {
 1667:                                             somme_invalide = d_vrai;
 1668:                                         }
 1669: 
 1670:                                         break;
 1671:                                     }
 1672: #                                   endif
 1673: 
 1674:                                     default:
 1675:                                     {
 1676:                                         somme_invalide = d_vrai;
 1677:                                         break;
 1678:                                     }
 1679:                                 }
 1680: 
 1681:                                 break;
 1682:                             }
 1683: 
 1684:                             default:
 1685:                             {
 1686:                                 somme_invalide = d_vrai;
 1687:                                 break;
 1688:                             }
 1689:                         }
 1690: 
 1691:                         break;
 1692:                     }
 1693: 
 1694:                     default:
 1695:                     {
 1696:                         somme_invalide = d_vrai;
 1697:                         break;
 1698:                     }
 1699:                 }
 1700: 
 1701:                 break;
 1702:             }
 1703: 
 1704: #           ifndef OPENSSL_NO_RIPEMD
 1705:             case 'R':
 1706:             {
 1707:                 if (strcmp(fonction, "RIPEMD160") == 0)
 1708:                 {
 1709:                     EVP_sum = EVP_ripemd160();
 1710:                 }
 1711:                 else
 1712:                 {
 1713:                     somme_invalide = d_vrai;
 1714:                 }
 1715: 
 1716:                 break;
 1717:             }
 1718: #           endif
 1719: 
 1720:             case 'S':
 1721:             {
 1722:                 switch(fonction[1])
 1723:                 {
 1724:                     case 'H': // sh
 1725:                     {
 1726:                         switch(fonction[2])
 1727:                         {
 1728: #                           ifndef OPENSSL_NO_SHA
 1729:                             case 'A':
 1730:                             {
 1731:                                 switch(fonction[3])
 1732:                                 {
 1733:                                     case d_code_fin_chaine:
 1734:                                     {
 1735:                                         EVP_sum = EVP_sha();
 1736:                                         break;
 1737:                                     }
 1738: 
 1739:                                     case '1': // sha1
 1740:                                     {
 1741:                                         if (fonction[4] == d_code_fin_chaine)
 1742:                                         {
 1743:                                             EVP_sum = EVP_sha1();
 1744:                                         }
 1745:                                         else
 1746:                                         {
 1747:                                             somme_invalide = d_vrai;
 1748:                                         }
 1749: 
 1750:                                         break;
 1751:                                     }
 1752: 
 1753: #                                   ifndef OPENSSL_NO_SHA256
 1754:                                     case '2': // sha2
 1755:                                     {
 1756:                                         switch(fonction[4])
 1757:                                         {
 1758:                                             case '2': // sha22
 1759:                                             {
 1760:                                                 switch(fonction[5])
 1761:                                                 {
 1762:                                                     case '4': // sha224
 1763:                                                     {
 1764:                                                         if (fonction[6] ==
 1765:                                                             d_code_fin_chaine)
 1766:                                                         {
 1767:                                                             EVP_sum =
 1768:                                                                 EVP_sha224();
 1769:                                                         }
 1770:                                                         else
 1771:                                                         {
 1772:                                                             somme_invalide =
 1773:                                                                     d_vrai;
 1774:                                                         }
 1775: 
 1776:                                                         break;
 1777:                                                     }
 1778: 
 1779:                                                     default:
 1780:                                                     {
 1781:                                                         somme_invalide = d_vrai;
 1782:                                                         break;
 1783:                                                     }
 1784:                                                 }
 1785: 
 1786:                                                 break;
 1787:                                             }
 1788: 
 1789:                                             case '5':
 1790:                                             {
 1791:                                                 switch(fonction[5])
 1792:                                                 {
 1793:                                                     case '6': // sha256
 1794:                                                     {
 1795:                                                         if (fonction[6] ==
 1796:                                                             d_code_fin_chaine)
 1797:                                                         {
 1798:                                                             EVP_sum =
 1799:                                                                 EVP_sha256();
 1800:                                                         }
 1801:                                                         else
 1802:                                                         {
 1803:                                                             somme_invalide =
 1804:                                                                     d_vrai;
 1805:                                                         }
 1806: 
 1807:                                                         break;
 1808:                                                     }
 1809: 
 1810:                                                     default:
 1811:                                                     {
 1812:                                                         somme_invalide = d_vrai;
 1813:                                                         break;
 1814:                                                     }
 1815:                                                 }
 1816: 
 1817:                                                 break;
 1818:                                             }
 1819: 
 1820:                                             default:
 1821:                                             {
 1822:                                                 somme_invalide = d_vrai;
 1823:                                                 break;
 1824:                                             }
 1825:                                         }
 1826: 
 1827:                                         break;
 1828:                                     }
 1829: #                                   endif
 1830: 
 1831: #                                   ifndef OPENSSL_NO_SHA512
 1832:                                     case '3': // sha3
 1833:                                     {
 1834:                                         switch(fonction[4])
 1835:                                         {
 1836:                                             case '8': // sha38
 1837:                                             {
 1838:                                                 switch(fonction[5])
 1839:                                                 {
 1840:                                                     case '4': // sha384
 1841:                                                     {
 1842:                                                         if (fonction[6] ==
 1843:                                                             d_code_fin_chaine)
 1844:                                                         {
 1845:                                                             EVP_sum =
 1846:                                                                 EVP_sha384();
 1847:                                                         }
 1848:                                                         else
 1849:                                                         {
 1850:                                                             somme_invalide =
 1851:                                                                     d_vrai;
 1852:                                                         }
 1853: 
 1854:                                                         break;
 1855:                                                     }
 1856: 
 1857:                                                     default:
 1858:                                                     {
 1859:                                                         somme_invalide = d_vrai;
 1860:                                                         break;
 1861:                                                     }
 1862:                                                 }
 1863: 
 1864:                                                 break;
 1865:                                             }
 1866: 
 1867:                                             default:
 1868:                                             {
 1869:                                                 somme_invalide = d_vrai;
 1870:                                                 break;
 1871:                                             }
 1872:                                         }
 1873: 
 1874:                                         break;
 1875:                                     }
 1876: 
 1877:                                     case '5': // sha5
 1878:                                     {
 1879:                                         switch(fonction[4])
 1880:                                         {
 1881:                                             case '1': // sha51
 1882:                                             {
 1883:                                                 switch(fonction[5])
 1884:                                                 {
 1885:                                                     case '2': // sha512
 1886:                                                     {
 1887:                                                         if (fonction[6] ==
 1888:                                                             d_code_fin_chaine)
 1889:                                                         {
 1890:                                                             EVP_sum =
 1891:                                                                 EVP_sha512();
 1892:                                                         }
 1893:                                                         else
 1894:                                                         {
 1895:                                                             somme_invalide =
 1896:                                                                     d_vrai;
 1897:                                                         }
 1898: 
 1899:                                                         break;
 1900:                                                     }
 1901: 
 1902:                                                     default:
 1903:                                                     {
 1904:                                                         somme_invalide = d_vrai;
 1905:                                                         break;
 1906:                                                     }
 1907:                                                 }
 1908: 
 1909:                                                 break;
 1910:                                             }
 1911: 
 1912:                                             default:
 1913:                                             {
 1914:                                                 somme_invalide = d_vrai;
 1915:                                                 break;
 1916:                                             }
 1917:                                         }
 1918: 
 1919:                                         break;
 1920:                                     }
 1921: #                                   endif
 1922: 
 1923:                                     default:
 1924:                                     {
 1925:                                         somme_invalide = d_vrai;
 1926:                                         break;
 1927:                                     }
 1928:                                 }
 1929: 
 1930:                                 break;
 1931:                             }
 1932: #                           endif
 1933: 
 1934:                             default:
 1935:                             {
 1936:                                 somme_invalide = d_vrai;
 1937:                                 break;
 1938:                             }
 1939:                         }
 1940: 
 1941:                         break;
 1942:                     }
 1943: 
 1944:                     default:
 1945:                     {
 1946:                         somme_invalide = d_vrai;
 1947:                         break;
 1948:                     }
 1949:                 }
 1950: 
 1951:                 break;
 1952:             }
 1953: 
 1954: #           ifndef OPENSSL_NO_WHIRLPOOL
 1955:             case 'W':
 1956:             {
 1957:                 if (strcmp(fonction, "WHIRLPOOL") == 0)
 1958:                 {
 1959:                     EVP_sum = EVP_whirlpool();
 1960:                 }
 1961:                 else
 1962:                 {
 1963:                     somme_invalide = d_vrai;
 1964:                 }
 1965: 
 1966:                 break;
 1967:             }
 1968: #           endif
 1969: 
 1970:             default:
 1971:             {
 1972:                 somme_invalide = d_vrai;
 1973:                 break;
 1974:             }
 1975:         }
 1976: 
 1977:         if (somme_invalide == d_vrai)
 1978:         {
 1979:             // Le chiffrement est de type CBC-MAC
 1980: 
 1981:             if (strncmp(fonction, "AES", 3) == 0)
 1982:             {
 1983: #               ifdef OPENSSL_NO_AES
 1984: 
 1985:                 free(fonction);
 1986: 
 1987:                 liberation(s_etat_processus, s_objet_argument_1);
 1988:                 liberation(s_etat_processus, s_objet_argument_2);
 1989: 
 1990:                 (*s_etat_processus).erreur_execution =
 1991:                         d_ex_chiffrement_indisponible;
 1992:                 return;
 1993: 
 1994: #               else
 1995: 
 1996:                 if (strcmp(fonction, "AES-128-CBC") == 0)
 1997:                 {
 1998:                     EVP_chiffrement = EVP_aes_128_cbc();
 1999:                 }
 2000:                 else if (strcmp(fonction, "AES-192-CBC") == 0)
 2001:                 {
 2002:                     EVP_chiffrement = EVP_aes_192_cbc();
 2003:                 }
 2004:                 else if (strcmp(fonction, "AES-256-CBC") == 0)
 2005:                 {
 2006:                     EVP_chiffrement = EVP_aes_256_cbc();
 2007:                 }
 2008:                 else
 2009:                 {
 2010:                     free(fonction);
 2011: 
 2012:                     liberation(s_etat_processus, s_objet_argument_1);
 2013:                     liberation(s_etat_processus, s_objet_argument_2);
 2014: 
 2015:                     (*s_etat_processus).erreur_execution =
 2016:                             d_ex_chiffrement_indisponible;
 2017:                     return;
 2018:                 }
 2019: 
 2020:                 longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
 2021:                 longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
 2022: 
 2023: #               endif
 2024:             }
 2025:             else if (strncmp(fonction, "DES", 3) == 0)
 2026:             {
 2027: #               ifdef OPENSSL_NO_DES
 2028: 
 2029:                 free(fonction);
 2030: 
 2031:                 liberation(s_etat_processus, s_objet_argument_1);
 2032:                 liberation(s_etat_processus, s_objet_argument_2);
 2033: 
 2034:                 (*s_etat_processus).erreur_execution =
 2035:                         d_ex_chiffrement_indisponible;
 2036:                 return;
 2037: 
 2038: #               else
 2039: 
 2040:                 if (strcmp(fonction, "DES-CBC") == 0)
 2041:                 {
 2042:                     EVP_chiffrement = EVP_des_cbc();
 2043:                 }
 2044:                 else if (strcmp(fonction, "DES-EDE-CBC") == 0)
 2045:                 {
 2046:                     EVP_chiffrement = EVP_des_ede_cbc();
 2047:                 }
 2048:                 else if (strcmp(fonction, "DES-EDE3-CBC") == 0)
 2049:                 {
 2050:                     EVP_chiffrement = EVP_des_ede3_cbc();
 2051:                 }
 2052:                 else if (strcmp(fonction, "DESX-CBC") == 0)
 2053:                 {
 2054:                     EVP_chiffrement = EVP_desx_cbc();
 2055:                 }
 2056:                 else
 2057:                 {
 2058:                     free(fonction);
 2059: 
 2060:                     liberation(s_etat_processus, s_objet_argument_1);
 2061:                     liberation(s_etat_processus, s_objet_argument_2);
 2062: 
 2063:                     (*s_etat_processus).erreur_execution =
 2064:                             d_ex_chiffrement_indisponible;
 2065:                     return;
 2066:                 }
 2067: 
 2068:                 longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
 2069:                 longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
 2070: 
 2071: #               endif
 2072:             }
 2073:             else if (strncmp(fonction, "CAMELLIA", 8) == 0)
 2074:             {
 2075: #               ifdef OPENSSL_NO_CAMELLIA
 2076: 
 2077:                 free(fonction);
 2078: 
 2079:                 liberation(s_etat_processus, s_objet_argument_1);
 2080:                 liberation(s_etat_processus, s_objet_argument_2);
 2081: 
 2082:                 (*s_etat_processus).erreur_execution =
 2083:                         d_ex_chiffrement_indisponible;
 2084:                 return;
 2085: 
 2086: #               else
 2087: 
 2088:                 if (strcmp(fonction, "CAMELLIA-128-CBC") == 0)
 2089:                 {
 2090:                     EVP_chiffrement = EVP_camellia_128_cbc();
 2091:                 }
 2092:                 else if (strcmp(fonction, "CAMELLIA-192-CBC") == 0)
 2093:                 {
 2094:                     EVP_chiffrement = EVP_camellia_192_cbc();
 2095:                 }
 2096:                 else if (strcmp(fonction, "CAMELLIA-256-CBC") == 0)
 2097:                 {
 2098:                     EVP_chiffrement = EVP_camellia_256_cbc();
 2099:                 }
 2100:                 else
 2101:                 {
 2102:                     free(fonction);
 2103: 
 2104:                     liberation(s_etat_processus, s_objet_argument_1);
 2105:                     liberation(s_etat_processus, s_objet_argument_2);
 2106: 
 2107:                     (*s_etat_processus).erreur_execution =
 2108:                             d_ex_chiffrement_indisponible;
 2109:                     return;
 2110:                 }
 2111: 
 2112:                 longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
 2113:                 longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
 2114: 
 2115: #               endif
 2116:             }
 2117:             else if (strncmp(fonction, "RC2", 3) == 0)
 2118:             {
 2119: #               ifdef OPENSSL_NO_RC2
 2120: 
 2121:                 free(fonction);
 2122: 
 2123:                 liberation(s_etat_processus, s_objet_argument_1);
 2124:                 liberation(s_etat_processus, s_objet_argument_2);
 2125: 
 2126:                 (*s_etat_processus).erreur_execution =
 2127:                         d_ex_chiffrement_indisponible;
 2128:                 return;
 2129: 
 2130: #               else
 2131: 
 2132:                 if (strcmp(fonction, "RC2-CBC") == 0)
 2133:                 {
 2134:                     EVP_chiffrement = EVP_rc2_cbc();
 2135:                 }
 2136:                 else if (strcmp(fonction, "RC2-40-CBC") == 0)
 2137:                 {
 2138:                     EVP_chiffrement = EVP_rc2_40_cbc();
 2139:                 }
 2140:                 else if (strcmp(fonction, "RC2-64-CBC") == 0)
 2141:                 {
 2142:                     EVP_chiffrement = EVP_rc2_64_cbc();
 2143:                 }
 2144:                 else
 2145:                 {
 2146:                     free(fonction);
 2147: 
 2148:                     liberation(s_etat_processus, s_objet_argument_1);
 2149:                     liberation(s_etat_processus, s_objet_argument_2);
 2150: 
 2151:                     (*s_etat_processus).erreur_execution =
 2152:                             d_ex_chiffrement_indisponible;
 2153:                     return;
 2154:                 }
 2155: 
 2156:                 longueur_clef_attendue = 0;
 2157:                 longueur_clef_min = 1;
 2158:                 longueur_clef_max = 16;
 2159:                 longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
 2160: 
 2161: #               endif
 2162:             }
 2163:             else if (strncmp(fonction, "IDEA", 4) == 0)
 2164:             {
 2165: #               ifdef OPENSSL_NO_IDEA
 2166: 
 2167:                 free(fonction);
 2168: 
 2169:                 liberation(s_etat_processus, s_objet_argument_1);
 2170:                 liberation(s_etat_processus, s_objet_argument_2);
 2171: 
 2172:                 (*s_etat_processus).erreur_execution =
 2173:                         d_ex_chiffrement_indisponible;
 2174:                 return;
 2175: 
 2176: #               else
 2177: 
 2178:                 if (strcmp(fonction, "IDEA-CBC") == 0)
 2179:                 {
 2180:                     EVP_chiffrement = EVP_idea_cbc();
 2181:                 }
 2182:                 else
 2183:                 {
 2184:                     free(fonction);
 2185: 
 2186:                     liberation(s_etat_processus, s_objet_argument_1);
 2187:                     liberation(s_etat_processus, s_objet_argument_2);
 2188: 
 2189:                     (*s_etat_processus).erreur_execution =
 2190:                             d_ex_chiffrement_indisponible;
 2191:                     return;
 2192:                 }
 2193: 
 2194:                 longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
 2195:                 longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
 2196: 
 2197: #               endif
 2198:             }
 2199:             else
 2200:             {
 2201:                 free(fonction);
 2202: 
 2203:                 liberation(s_etat_processus, s_objet_argument_1);
 2204:                 liberation(s_etat_processus, s_objet_argument_2);
 2205: 
 2206:                 (*s_etat_processus).erreur_execution =
 2207:                         d_ex_chiffrement_indisponible;
 2208:                 return;
 2209:             }
 2210: 
 2211:             if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
 2212:                     (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
 2213:             {
 2214:                 free(fonction);
 2215: 
 2216:                 liberation(s_etat_processus, s_objet_argument_1);
 2217:                 liberation(s_etat_processus, s_objet_argument_2);
 2218: 
 2219:                 return;
 2220:             }
 2221: 
 2222:             l_element_courant = (*s_objet_argument_1).objet;
 2223:             l_element_courant = (*l_element_courant).suivant;
 2224: 
 2225:             if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
 2226:                     (*(*l_element_courant).donnee).objet, &longueur_clef))
 2227:                     == NULL)
 2228:             {
 2229:                 free(fonction);
 2230:                 free(chaine);
 2231: 
 2232:                 liberation(s_etat_processus, s_objet_argument_1);
 2233:                 liberation(s_etat_processus, s_objet_argument_2);
 2234:                 return;
 2235:             }
 2236: 
 2237:             if (longueur_clef_attendue != 0)
 2238:             {
 2239:                 if (longueur_clef != longueur_clef_attendue)
 2240:                 {
 2241:                     free(fonction);
 2242:                     free(chaine);
 2243:                     free(clef);
 2244: 
 2245:                     liberation(s_etat_processus, s_objet_argument_1);
 2246:                     liberation(s_etat_processus, s_objet_argument_2);
 2247: 
 2248:                     (*s_etat_processus).erreur_execution =
 2249:                             d_ex_longueur_clef_chiffrement;
 2250:                     return;
 2251:                 }
 2252:             }
 2253:             else
 2254:             {
 2255:                 if ((longueur_clef < longueur_clef_min) &&
 2256:                         (longueur_clef > longueur_clef_max))
 2257:                 {
 2258:                     free(fonction);
 2259:                     free(chaine);
 2260:                     free(clef);
 2261: 
 2262:                     liberation(s_etat_processus, s_objet_argument_1);
 2263:                     liberation(s_etat_processus, s_objet_argument_2);
 2264: 
 2265:                     (*s_etat_processus).erreur_execution =
 2266:                             d_ex_longueur_clef_chiffrement;
 2267:                     return;
 2268:                 }
 2269:             }
 2270: 
 2271:             if ((vecteur_initialisation = malloc(longueur_clef *
 2272:                     sizeof(unsigned char))) == NULL)
 2273:             {
 2274:                 (*s_etat_processus).erreur_systeme =
 2275:                         d_es_allocation_memoire;
 2276:                 return;
 2277:             }
 2278: 
 2279:             memset(vecteur_initialisation, 0, longueur_clef);
 2280: 
 2281:             if ((tampon = chiffrement(EVP_chiffrement, d_vrai,
 2282:                     chaine, longueur_chaine, clef, longueur_clef,
 2283:                     vecteur_initialisation, &longueur_tampon)) == NULL)
 2284:             {
 2285:                 free(fonction);
 2286:                 free(vecteur_initialisation);
 2287:                 free(chaine);
 2288:                 free(clef);
 2289: 
 2290:                 (*s_etat_processus).erreur_execution =
 2291:                         d_ex_chiffrement;
 2292:                 return;
 2293:             }
 2294: 
 2295:             free(vecteur_initialisation);
 2296:             free(chaine);
 2297:             free(clef);
 2298: 
 2299:             if ((s_objet_resultat = allocation(s_etat_processus, CHN))
 2300:                     == NULL)
 2301:             {
 2302:                 (*s_etat_processus).erreur_systeme =
 2303:                         d_es_allocation_memoire;
 2304:                 return;
 2305:             }
 2306: 
 2307:             if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
 2308:                     &(tampon[longueur_tampon - longueur_somme]),
 2309:                     longueur_somme)) == NULL)
 2310:             {
 2311:                 free(tampon);
 2312:                 free(fonction);
 2313: 
 2314:                 liberation(s_etat_processus, s_objet_argument_1);
 2315:                 liberation(s_etat_processus, s_objet_argument_2);
 2316:                 return;
 2317:             }
 2318: 
 2319:             free(tampon);
 2320:             free(fonction);
 2321:         }
 2322:         else
 2323:         {
 2324:             // Le chiffrement est de type HMAC
 2325:             // Le second élément de la chaîne contient la clef utilisée pour
 2326:             // la signature.
 2327: 
 2328:             free(fonction);
 2329: 
 2330:             l_element_courant = (*s_objet_argument_1).objet;
 2331:             l_element_courant = (*l_element_courant).suivant;
 2332: 
 2333:             longueur_bloc = EVP_MD_block_size(EVP_sum);
 2334: 
 2335:             if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
 2336:                     (*(*l_element_courant).donnee).objet, &longueur_clef))
 2337:                     == NULL)
 2338:             {
 2339:                 liberation(s_etat_processus, s_objet_argument_1);
 2340:                 liberation(s_etat_processus, s_objet_argument_2);
 2341:                 return;
 2342:             }
 2343: 
 2344:             if (longueur_clef < longueur_bloc)
 2345:             {
 2346:                 longueur_tampon = longueur_clef;
 2347:                 tampon = clef;
 2348: 
 2349:                 if ((clef = malloc(longueur_bloc * sizeof(unsigned char)))
 2350:                         == NULL)
 2351:                 {
 2352:                     (*s_etat_processus).erreur_systeme =
 2353:                             d_es_allocation_memoire;
 2354:                     return;
 2355:                 }
 2356: 
 2357:                 memset(clef, 0, longueur_bloc);
 2358:                 memcpy(clef, tampon, longueur_tampon);
 2359:                 longueur_clef = longueur_bloc;
 2360:                 free(tampon);
 2361:             }
 2362:             else if (longueur_clef > longueur_bloc)
 2363:             {
 2364:                 longueur_tampon = longueur_clef;
 2365:                 tampon = clef;
 2366: 
 2367:                 if ((clef = malloc(longueur_bloc * sizeof(unsigned char)))
 2368:                         == NULL)
 2369:                 {
 2370:                     (*s_etat_processus).erreur_systeme =
 2371:                             d_es_allocation_memoire;
 2372:                     return;
 2373:                 }
 2374: 
 2375:                 memcpy(clef, tampon, longueur_bloc);
 2376:                 longueur_clef = longueur_bloc;
 2377:                 free(tampon);
 2378:             }
 2379: 
 2380:             for(i = 0; i < longueur_bloc; i++)
 2381:             {
 2382:                 clef[i] ^= 0x36;
 2383:             }
 2384: 
 2385:             if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
 2386:                     (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
 2387:             {
 2388:                 EVP_MD_CTX_cleanup(&contexte);
 2389: 
 2390:                 liberation(s_etat_processus, s_objet_argument_1);
 2391:                 liberation(s_etat_processus, s_objet_argument_2);
 2392: 
 2393:                 return;
 2394:             }
 2395: 
 2396:             if ((tampon = malloc((longueur_bloc + longueur_chaine) *
 2397:                     sizeof(unsigned char))) == NULL)
 2398:             {
 2399:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2400:                 return;
 2401:             }
 2402: 
 2403:             memcpy(tampon, clef, longueur_bloc);
 2404:             memcpy(tampon + longueur_bloc, chaine, longueur_chaine);
 2405:             longueur_tampon = longueur_bloc + longueur_chaine;
 2406: 
 2407:             if (EVP_DigestInit(&contexte, EVP_sum) != 1)
 2408:             {
 2409:                 free(tampon);
 2410:                 free(clef);
 2411:                 free(chaine);
 2412: 
 2413:                 EVP_MD_CTX_cleanup(&contexte);
 2414: 
 2415:                 liberation(s_etat_processus, s_objet_argument_1);
 2416:                 liberation(s_etat_processus, s_objet_argument_2);
 2417: 
 2418:                 (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 2419:                 return;
 2420:             }
 2421: 
 2422:             if (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1)
 2423:             {
 2424:                 free(tampon);
 2425:                 free(clef);
 2426:                 free(chaine);
 2427: 
 2428:                 EVP_MD_CTX_cleanup(&contexte);
 2429: 
 2430:                 liberation(s_etat_processus, s_objet_argument_1);
 2431:                 liberation(s_etat_processus, s_objet_argument_2);
 2432: 
 2433:                 (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 2434:                 return;
 2435:             }
 2436: 
 2437:             free(tampon);
 2438: 
 2439:             if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
 2440:             {
 2441:                 free(chaine);
 2442:                 EVP_MD_CTX_cleanup(&contexte);
 2443: 
 2444:                 liberation(s_etat_processus, s_objet_argument_1);
 2445:                 liberation(s_etat_processus, s_objet_argument_2);
 2446: 
 2447:                 (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 2448:                 return;
 2449:             }
 2450: 
 2451:             EVP_MD_CTX_cleanup(&contexte);
 2452: 
 2453:             for(i = 0; i < longueur_bloc; i++)
 2454:             {
 2455:                 clef[i] ^= (0x36 ^ 0x5c);
 2456:             }
 2457: 
 2458:             if ((tampon = malloc((longueur_bloc + longueur_somme) *
 2459:                     sizeof(unsigned char))) == NULL)
 2460:             {
 2461:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2462:                 return;
 2463:             }
 2464: 
 2465:             memcpy(tampon, clef, longueur_bloc);
 2466:             memcpy(tampon + longueur_bloc, somme, longueur_somme);
 2467:             longueur_tampon = longueur_bloc + longueur_somme;
 2468: 
 2469:             if (EVP_DigestInit(&contexte, EVP_sum) != 1)
 2470:             {
 2471:                 free(tampon);
 2472:                 free(clef);
 2473:                 free(chaine);
 2474: 
 2475:                 EVP_MD_CTX_cleanup(&contexte);
 2476: 
 2477:                 liberation(s_etat_processus, s_objet_argument_1);
 2478:                 liberation(s_etat_processus, s_objet_argument_2);
 2479: 
 2480:                 (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 2481:                 return;
 2482:             }
 2483: 
 2484:             if (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1)
 2485:             {
 2486:                 free(tampon);
 2487:                 free(clef);
 2488:                 free(chaine);
 2489: 
 2490:                 EVP_MD_CTX_cleanup(&contexte);
 2491: 
 2492:                 liberation(s_etat_processus, s_objet_argument_1);
 2493:                 liberation(s_etat_processus, s_objet_argument_2);
 2494: 
 2495:                 (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 2496:                 return;
 2497:             }
 2498: 
 2499:             free(tampon);
 2500: 
 2501:             if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
 2502:             {
 2503:                 free(chaine);
 2504:                 EVP_MD_CTX_cleanup(&contexte);
 2505: 
 2506:                 liberation(s_etat_processus, s_objet_argument_1);
 2507:                 liberation(s_etat_processus, s_objet_argument_2);
 2508: 
 2509:                 (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 2510:                 return;
 2511:             }
 2512: 
 2513:             EVP_MD_CTX_cleanup(&contexte);
 2514: 
 2515:             free(chaine);
 2516:             free(clef);
 2517: 
 2518:             if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
 2519:             {
 2520:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 2521:                 return;
 2522:             }
 2523: 
 2524:             if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
 2525:                     somme, longueur_somme)) == NULL)
 2526:             {
 2527:                 liberation(s_etat_processus, s_objet_argument_1);
 2528:                 liberation(s_etat_processus, s_objet_argument_2);
 2529: 
 2530:                 return;
 2531:             }
 2532:         }
 2533:     }
 2534:     else
 2535:     {
 2536:         liberation(s_etat_processus, s_objet_argument_1);
 2537:         liberation(s_etat_processus, s_objet_argument_2);
 2538: 
 2539:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 2540:         return;
 2541:     }
 2542: 
 2543:     liberation(s_etat_processus, s_objet_argument_1);
 2544:     liberation(s_etat_processus, s_objet_argument_2);
 2545: 
 2546:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 2547:             s_objet_resultat) == d_erreur)
 2548:     {
 2549:         return;
 2550:     }
 2551: 
 2552:     return;
 2553: }
 2554: 
 2555: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>