File:  [local] / rpl / src / instructions_d6.c
Revision 1.40: download - view: text, annotated - select for diffs - revision graph
Sat Feb 23 18:51:43 2013 UTC (11 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Correction de l'aide de DIGEST.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.12
    4:   Copyright (C) 1989-2012 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: 
  612:     logical1                    somme_invalide;
  613: 
  614:     long                        longueur_chaine;
  615: 
  616:     struct_objet                *s_objet_argument_1;
  617:     struct_objet                *s_objet_argument_2;
  618:     struct_objet                *s_objet_resultat;
  619: 
  620:     unsigned char               *chaine;
  621:     unsigned char               *fonction;
  622:     unsigned char               somme[EVP_MAX_MD_SIZE];
  623: 
  624:     unsigned int                longueur_somme;
  625: 
  626:     (*s_etat_processus).erreur_execution = d_ex;
  627: 
  628:     if ((*s_etat_processus).affichage_arguments == 'Y')
  629:     {
  630:         printf("\n  DIGEST ");
  631: 
  632:         if ((*s_etat_processus).langue == 'F')
  633:         {
  634:             printf("(somme d'authentification)\n\n");
  635:         }
  636:         else
  637:         {
  638:             printf("(hash algorithm)\n\n");
  639:         }
  640: 
  641:         printf("    2: %s\n", d_CHN);
  642:         printf("    1: %s\n", d_CHN);
  643:         printf("->  1: %s\n\n", d_CHN);
  644: 
  645:         printf("    2: %s\n", d_CHN);
  646:         printf("    1: %s\n", d_LST);
  647:         printf("->  1: %s\n\n", d_CHN);
  648: 
  649:         if ((*s_etat_processus).langue == 'F')
  650:         {
  651:             printf("  Algorithmes :\n\n");
  652:         }
  653:         else
  654:         {
  655:             printf("  Algorithms:\n\n");
  656:         }
  657: 
  658: #       ifndef OPENSSL_NO_SHA
  659:         printf("    - DSS\n");
  660:         printf("    - DSS1\n");
  661:         printf("    - ECDSA\n");
  662: #       endif
  663: #       ifndef OPENSSL_NO_MD2
  664:         printf("    - MD2\n");
  665: #       endif
  666: #       ifndef OPENSSL_NO_MD4
  667:         printf("    - MD4\n");
  668: #       endif
  669: #       ifndef OPENSSL_NO_MD5
  670:         printf("    - MD5\n");
  671: #       endif
  672: #       ifndef OPENSSL_NO_MDC2
  673:         printf("    - MDC2\n");
  674: #       endif
  675: #       ifndef OPENSSL_NO_RIPEMD
  676:         printf("    - RIPEMD160\n");
  677: #       endif
  678: #       ifndef OPENSSL_NO_SHA
  679:         printf("    - SHA\n");
  680:         printf("    - SHA1\n");
  681: #       endif
  682: #       ifndef OPENSSL_NO_SHA256
  683:         printf("    - SHA224\n");
  684:         printf("    - SHA256\n");
  685: #       endif
  686: #       ifndef OPENSSL_NO_SHA512
  687:         printf("    - SHA384\n");
  688:         printf("    - SHA512\n");
  689: #       endif
  690: #       ifndef OPENSSL_NO_WHIRLPOOL
  691:         printf("    - WHIRLPOOL\n");
  692: #       endif
  693: 
  694:         return;
  695:     }
  696:     else if ((*s_etat_processus).test_instruction == 'Y')
  697:     {
  698:         (*s_etat_processus).nombre_arguments = -1;
  699:         return;
  700:     }
  701: 
  702:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  703:     {
  704:         if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
  705:         {
  706:             return;
  707:         }
  708:     }
  709: 
  710:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  711:             &s_objet_argument_1) == d_erreur)
  712:     {
  713:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  714:         return;
  715:     }
  716: 
  717:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  718:             &s_objet_argument_2) == d_erreur)
  719:     {
  720:         liberation(s_etat_processus, s_objet_argument_1);
  721: 
  722:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  723:         return;
  724:     }
  725: 
  726:     if (((*s_objet_argument_1).type == CHN) &&
  727:             ((*s_objet_argument_2).type == CHN))
  728:     {
  729:         // Liste des sommes disponibles :
  730:         // - EVP_dss
  731:         // - EVP_dss1
  732:         // - EVP_ecdsa
  733:         // - EVP_md2
  734:         // - EVP_md4
  735:         // - EVP_md5
  736:         // - EVP_mdc2
  737:         // - EVP_ripemd160
  738:         // - EVP_sha
  739:         // - EVP_sha1
  740:         // - EVP_sha224
  741:         // - EVP_sha256
  742:         // - EVP_sha384
  743:         // - EVP_sha512
  744:         // - EVP_whirlpool
  745: 
  746:         if ((fonction = conversion_majuscule((unsigned char *)
  747:                 (*s_objet_argument_1).objet)) == NULL)
  748:         {
  749:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  750:             return;
  751:         }
  752: 
  753:         somme_invalide = d_faux;
  754: 
  755:         switch(fonction[0])
  756:         {
  757:             case 'D':
  758:             {
  759:                 switch(fonction[1])
  760:                 {
  761:                     case 'S': // ds
  762:                     {
  763:                         switch(fonction[2])
  764:                         {
  765: #                           ifndef OPENSSL_NO_SHA
  766:                             case 'S': // dss
  767:                             {
  768:                                 switch(fonction[3])
  769:                                 {
  770:                                     case d_code_fin_chaine:
  771:                                     {
  772:                                         EVP_sum = EVP_dss;
  773:                                         break;
  774:                                     }
  775: 
  776:                                     case '1': // dss1
  777:                                     {
  778:                                         if (fonction[4] == d_code_fin_chaine)
  779:                                         {
  780:                                             EVP_sum = EVP_dss1;
  781:                                         }
  782:                                         else
  783:                                         {
  784:                                             somme_invalide = d_vrai;
  785:                                         }
  786: 
  787:                                         break;
  788:                                     }
  789: 
  790:                                     default:
  791:                                     {
  792:                                         somme_invalide = d_vrai;
  793:                                         break;
  794:                                     }
  795:                                 }
  796: 
  797:                                 break;
  798:                             }
  799: #                           endif
  800: 
  801:                             default:
  802:                             {
  803:                                 somme_invalide = d_vrai;
  804:                                 break;
  805:                             }
  806:                         }
  807: 
  808:                         break;
  809:                     }
  810: 
  811:                     default:
  812:                     {
  813:                         somme_invalide = d_vrai;
  814:                         break;
  815:                     }
  816:                 }
  817: 
  818:                 break;
  819:             }
  820: 
  821:             case 'E':
  822:             {
  823:                 switch(fonction[1])
  824:                 {
  825:                     case 'C': // ec
  826:                     {
  827:                         switch(fonction[2])
  828:                         {
  829:                             case 'D': // ecd
  830:                             {
  831:                                 switch(fonction[3])
  832:                                 {
  833:                                     case 'S': // ecds
  834:                                     {
  835:                                         switch(fonction[4])
  836:                                         {
  837: #                                           ifndef OPENSSL_NO_SHA
  838:                                             case 'A': // ecdsa
  839:                                             {
  840:                                                 if (fonction[5] ==
  841:                                                         d_code_fin_chaine)
  842:                                                 {
  843:                                                     EVP_sum = EVP_ecdsa;
  844:                                                 }
  845:                                                 else
  846:                                                 {
  847:                                                     somme_invalide = d_vrai;
  848:                                                 }
  849: 
  850:                                                 break;
  851:                                             }
  852: #                                           endif
  853: 
  854:                                             default:
  855:                                             {
  856:                                                 somme_invalide = d_vrai;
  857:                                                 break;
  858:                                             }
  859:                                         }
  860: 
  861:                                         break;
  862:                                     }
  863: 
  864:                                     default:
  865:                                     {
  866:                                         somme_invalide = d_vrai;
  867:                                         break;
  868:                                     }
  869:                                 }
  870: 
  871:                                 break;
  872:                             }
  873: 
  874:                             default:
  875:                             {
  876:                                 somme_invalide = d_vrai;
  877:                                 break;
  878:                             }
  879:                         }
  880: 
  881:                         break;
  882:                     }
  883: 
  884:                     default:
  885:                     {
  886:                         somme_invalide = d_vrai;
  887:                         break;
  888:                     }
  889:                 }
  890: 
  891:                 break;
  892:             }
  893: 
  894:             case 'M':
  895:             {
  896:                 switch(fonction[1])
  897:                 {
  898:                     case 'D': // md
  899:                     {
  900:                         switch(fonction[2])
  901:                         {
  902: #                           ifndef OPENSSL_NO_MD2
  903:                             case '2': // md2
  904:                             {
  905:                                 if (fonction[3] == d_code_fin_chaine)
  906:                                 {
  907:                                     EVP_sum = EVP_md2;
  908:                                 }
  909:                                 else
  910:                                 {
  911:                                     somme_invalide = d_vrai;
  912:                                 }
  913: 
  914:                                 break;
  915:                             }
  916: #                           endif
  917: 
  918: #                           ifndef OPENSSL_NO_MD4
  919:                             case '4': // md4
  920:                             {
  921:                                 if (fonction[3] == d_code_fin_chaine)
  922:                                 {
  923:                                     EVP_sum = EVP_md4;
  924:                                 }
  925:                                 else
  926:                                 {
  927:                                     somme_invalide = d_vrai;
  928:                                 }
  929: 
  930:                                 break;
  931:                             }
  932: #                           endif
  933: 
  934: #                           ifndef OPENSSL_NO_MD4
  935:                             case '5': // md5
  936:                             {
  937:                                 if (fonction[3] == d_code_fin_chaine)
  938:                                 {
  939:                                     EVP_sum = EVP_md5;
  940:                                 }
  941:                                 else
  942:                                 {
  943:                                     somme_invalide = d_vrai;
  944:                                 }
  945: 
  946:                                 break;
  947:                             }
  948: #                           endif
  949: 
  950:                             case 'C': // mdc
  951:                             {
  952:                                 switch(fonction[3])
  953:                                 {
  954: #                                   ifndef OPENSSL_NO_MDC2
  955:                                     case '2': // mdc2
  956:                                     {
  957:                                         if (fonction[4] == d_code_fin_chaine)
  958:                                         {
  959:                                             EVP_sum = EVP_mdc2;
  960:                                         }
  961:                                         else
  962:                                         {
  963:                                             somme_invalide = d_vrai;
  964:                                         }
  965: 
  966:                                         break;
  967:                                     }
  968: #                                   endif
  969: 
  970:                                     default:
  971:                                     {
  972:                                         somme_invalide = d_vrai;
  973:                                         break;
  974:                                     }
  975:                                 }
  976: 
  977:                                 break;
  978:                             }
  979: 
  980:                             default:
  981:                             {
  982:                                 somme_invalide = d_vrai;
  983:                                 break;
  984:                             }
  985:                         }
  986: 
  987:                         break;
  988:                     }
  989: 
  990:                     default:
  991:                     {
  992:                         somme_invalide = d_vrai;
  993:                         break;
  994:                     }
  995:                 }
  996: 
  997:                 break;
  998:             }
  999: 
 1000: #           ifndef OPENSSL_NO_RIPEMD
 1001:             case 'R':
 1002:             {
 1003:                 if (strcmp(fonction, "RIPEMD160") == 0)
 1004:                 {
 1005:                     EVP_sum = EVP_ripemd160;
 1006:                 }
 1007:                 else
 1008:                 {
 1009:                     somme_invalide = d_vrai;
 1010:                 }
 1011: 
 1012:                 break;
 1013:             }
 1014: #           endif
 1015: 
 1016:             case 'S':
 1017:             {
 1018:                 switch(fonction[1])
 1019:                 {
 1020:                     case 'H': // sh
 1021:                     {
 1022:                         switch(fonction[2])
 1023:                         {
 1024: #                           ifndef OPENSSL_NO_SHA
 1025:                             case 'A':
 1026:                             {
 1027:                                 switch(fonction[3])
 1028:                                 {
 1029:                                     case d_code_fin_chaine:
 1030:                                     {
 1031:                                         EVP_sum = EVP_sha;
 1032:                                         break;
 1033:                                     }
 1034: 
 1035:                                     case '1': // sha1
 1036:                                     {
 1037:                                         if (fonction[4] == d_code_fin_chaine)
 1038:                                         {
 1039:                                             EVP_sum = EVP_sha1;
 1040:                                         }
 1041:                                         else
 1042:                                         {
 1043:                                             somme_invalide = d_vrai;
 1044:                                         }
 1045: 
 1046:                                         break;
 1047:                                     }
 1048: 
 1049: #                                   ifndef OPENSSL_NO_SHA256
 1050:                                     case '2': // sha2
 1051:                                     {
 1052:                                         switch(fonction[4])
 1053:                                         {
 1054:                                             case '2': // sha22
 1055:                                             {
 1056:                                                 switch(fonction[5])
 1057:                                                 {
 1058:                                                     case '4': // sha224
 1059:                                                     {
 1060:                                                         if (fonction[6] ==
 1061:                                                             d_code_fin_chaine)
 1062:                                                         {
 1063:                                                             EVP_sum =
 1064:                                                                     EVP_sha224;
 1065:                                                         }
 1066:                                                         else
 1067:                                                         {
 1068:                                                             somme_invalide =
 1069:                                                                     d_vrai;
 1070:                                                         }
 1071: 
 1072:                                                         break;
 1073:                                                     }
 1074: 
 1075:                                                     default:
 1076:                                                     {
 1077:                                                         somme_invalide = d_vrai;
 1078:                                                         break;
 1079:                                                     }
 1080:                                                 }
 1081: 
 1082:                                                 break;
 1083:                                             }
 1084: 
 1085:                                             case '5':
 1086:                                             {
 1087:                                                 switch(fonction[5])
 1088:                                                 {
 1089:                                                     case '6': // sha256
 1090:                                                     {
 1091:                                                         if (fonction[6] ==
 1092:                                                             d_code_fin_chaine)
 1093:                                                         {
 1094:                                                             EVP_sum =
 1095:                                                                     EVP_sha256;
 1096:                                                         }
 1097:                                                         else
 1098:                                                         {
 1099:                                                             somme_invalide =
 1100:                                                                     d_vrai;
 1101:                                                         }
 1102: 
 1103:                                                         break;
 1104:                                                     }
 1105: 
 1106:                                                     default:
 1107:                                                     {
 1108:                                                         somme_invalide = d_vrai;
 1109:                                                         break;
 1110:                                                     }
 1111:                                                 }
 1112: 
 1113:                                                 break;
 1114:                                             }
 1115: 
 1116:                                             default:
 1117:                                             {
 1118:                                                 somme_invalide = d_vrai;
 1119:                                                 break;
 1120:                                             }
 1121:                                         }
 1122: 
 1123:                                         break;
 1124:                                     }
 1125: #                                   endif
 1126: 
 1127: #                                   ifndef OPENSSL_NO_SHA512
 1128:                                     case '3': // sha3
 1129:                                     {
 1130:                                         switch(fonction[4])
 1131:                                         {
 1132:                                             case '8': // sha38
 1133:                                             {
 1134:                                                 switch(fonction[5])
 1135:                                                 {
 1136:                                                     case '4': // sha384
 1137:                                                     {
 1138:                                                         if (fonction[6] ==
 1139:                                                             d_code_fin_chaine)
 1140:                                                         {
 1141:                                                             EVP_sum =
 1142:                                                                     EVP_sha384;
 1143:                                                         }
 1144:                                                         else
 1145:                                                         {
 1146:                                                             somme_invalide =
 1147:                                                                     d_vrai;
 1148:                                                         }
 1149: 
 1150:                                                         break;
 1151:                                                     }
 1152: 
 1153:                                                     default:
 1154:                                                     {
 1155:                                                         somme_invalide = d_vrai;
 1156:                                                         break;
 1157:                                                     }
 1158:                                                 }
 1159: 
 1160:                                                 break;
 1161:                                             }
 1162: 
 1163:                                             default:
 1164:                                             {
 1165:                                                 somme_invalide = d_vrai;
 1166:                                                 break;
 1167:                                             }
 1168:                                         }
 1169: 
 1170:                                         break;
 1171:                                     }
 1172: 
 1173:                                     case '5': // sha5
 1174:                                     {
 1175:                                         switch(fonction[4])
 1176:                                         {
 1177:                                             case '1': // sha51
 1178:                                             {
 1179:                                                 switch(fonction[5])
 1180:                                                 {
 1181:                                                     case '2': // sha512
 1182:                                                     {
 1183:                                                         if (fonction[6] ==
 1184:                                                             d_code_fin_chaine)
 1185:                                                         {
 1186:                                                             EVP_sum =
 1187:                                                                     EVP_sha512;
 1188:                                                         }
 1189:                                                         else
 1190:                                                         {
 1191:                                                             somme_invalide =
 1192:                                                                     d_vrai;
 1193:                                                         }
 1194: 
 1195:                                                         break;
 1196:                                                     }
 1197: 
 1198:                                                     default:
 1199:                                                     {
 1200:                                                         somme_invalide = d_vrai;
 1201:                                                         break;
 1202:                                                     }
 1203:                                                 }
 1204: 
 1205:                                                 break;
 1206:                                             }
 1207: 
 1208:                                             default:
 1209:                                             {
 1210:                                                 somme_invalide = d_vrai;
 1211:                                                 break;
 1212:                                             }
 1213:                                         }
 1214: 
 1215:                                         break;
 1216:                                     }
 1217: #                                   endif
 1218: 
 1219:                                     default:
 1220:                                     {
 1221:                                         somme_invalide = d_vrai;
 1222:                                         break;
 1223:                                     }
 1224:                                 }
 1225: 
 1226:                                 break;
 1227:                             }
 1228: #                           endif
 1229: 
 1230:                             default:
 1231:                             {
 1232:                                 somme_invalide = d_vrai;
 1233:                                 break;
 1234:                             }
 1235:                         }
 1236: 
 1237:                         break;
 1238:                     }
 1239: 
 1240:                     default:
 1241:                     {
 1242:                         somme_invalide = d_vrai;
 1243:                         break;
 1244:                     }
 1245:                 }
 1246: 
 1247:                 break;
 1248:             }
 1249: 
 1250: #           ifndef OPENSSL_NO_WHIRLPOOL
 1251:             case 'W':
 1252:             {
 1253:                 if (strcmp(fonction, "WHIRLPOOL") == 0)
 1254:                 {
 1255:                     EVP_sum = EVP_whirlpool;
 1256:                 }
 1257:                 else
 1258:                 {
 1259:                     somme_invalide = d_vrai;
 1260:                 }
 1261: 
 1262:                 break;
 1263:             }
 1264: #           endif
 1265: 
 1266:             default:
 1267:             {
 1268:                 somme_invalide = d_vrai;
 1269:                 break;
 1270:             }
 1271:         }
 1272: 
 1273:         free(fonction);
 1274: 
 1275:         if (somme_invalide == d_vrai)
 1276:         {
 1277:             liberation(s_etat_processus, s_objet_argument_1);
 1278:             liberation(s_etat_processus, s_objet_argument_2);
 1279: 
 1280:             (*s_etat_processus).erreur_execution =
 1281:                     d_ex_chiffrement_indisponible;
 1282:             return;
 1283:         }
 1284: 
 1285:         if (EVP_DigestInit(&contexte, EVP_sum()) != 1)
 1286:         {
 1287:             EVP_MD_CTX_cleanup(&contexte);
 1288: 
 1289:             liberation(s_etat_processus, s_objet_argument_1);
 1290:             liberation(s_etat_processus, s_objet_argument_2);
 1291: 
 1292:             (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 1293:             return;
 1294:         }
 1295: 
 1296:         if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
 1297:                 (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
 1298:         {
 1299:             EVP_MD_CTX_cleanup(&contexte);
 1300: 
 1301:             liberation(s_etat_processus, s_objet_argument_1);
 1302:             liberation(s_etat_processus, s_objet_argument_2);
 1303: 
 1304:             return;
 1305:         }
 1306: 
 1307:         if (EVP_DigestUpdate(&contexte, chaine, longueur_chaine) != 1)
 1308:         {
 1309:             free(chaine);
 1310:             EVP_MD_CTX_cleanup(&contexte);
 1311: 
 1312:             liberation(s_etat_processus, s_objet_argument_1);
 1313:             liberation(s_etat_processus, s_objet_argument_2);
 1314: 
 1315:             (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 1316:             return;
 1317:         }
 1318: 
 1319:         if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
 1320:         {
 1321:             free(chaine);
 1322:             EVP_MD_CTX_cleanup(&contexte);
 1323: 
 1324:             liberation(s_etat_processus, s_objet_argument_1);
 1325:             liberation(s_etat_processus, s_objet_argument_2);
 1326: 
 1327:             (*s_etat_processus).erreur_execution = d_ex_chiffrement;
 1328:             return;
 1329:         }
 1330: 
 1331:         free(chaine);
 1332:         EVP_MD_CTX_cleanup(&contexte);
 1333: 
 1334:         if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
 1335:         {
 1336:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1337:             return;
 1338:         }
 1339: 
 1340:         if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
 1341:                 somme, longueur_somme)) == NULL)
 1342:         {
 1343:             liberation(s_etat_processus, s_objet_argument_1);
 1344:             liberation(s_etat_processus, s_objet_argument_2);
 1345: 
 1346:             return;
 1347:         }
 1348:     }
 1349:     else if (((*s_objet_argument_1).type == CHN) &&
 1350:             ((*s_objet_argument_2).type == LST))
 1351:     {
 1352:         BUG(1, uprintf("Oops\n"));
 1353:         s_objet_resultat = NULL;
 1354:     }
 1355:     else
 1356:     {
 1357:         liberation(s_etat_processus, s_objet_argument_1);
 1358:         liberation(s_etat_processus, s_objet_argument_2);
 1359: 
 1360:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
 1361:         return;
 1362:     }
 1363: 
 1364:     liberation(s_etat_processus, s_objet_argument_1);
 1365:     liberation(s_etat_processus, s_objet_argument_2);
 1366: 
 1367:     if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
 1368:             s_objet_resultat) == d_erreur)
 1369:     {
 1370:         return;
 1371:     }
 1372: 
 1373:     return;
 1374: }
 1375: 
 1376: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>