Annotation of rpl/src/instructions_d6.c, revision 1.52

1.1       bertrand    1: /*
                      2: ================================================================================
1.52    ! bertrand    3:   RPL/2 (R) version 4.1.17
1.44      bertrand    4:   Copyright (C) 1989-2013 Dr. BERTRAND Joël
1.1       bertrand    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: 
1.11      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   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: 
1.48      bertrand  342:    integer8                    i;
                    343:    integer8                    j;
1.1       bertrand  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
1.48      bertrand  412:                = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat)
                    413:                .objet)).taille) * sizeof(integer8))) == NULL)
1.1       bertrand  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
1.48      bertrand  470:                = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat)
                    471:                .objet)).taille) * sizeof(real8))) == NULL)
1.1       bertrand  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
1.48      bertrand  528:                = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat)
                    529:                .objet)).taille) * sizeof(complex16))) == NULL)
1.1       bertrand  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: 
1.39      bertrand  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: 
1.42      bertrand  610:    const EVP_MD                *EVP_sum;
                    611:    const EVP_CIPHER            *EVP_chiffrement;
1.39      bertrand  612: 
1.48      bertrand  613:    int                         i;
                    614:    int                         longueur_bloc;
                    615:    int                         longueur_somme;
                    616: 
                    617:    integer8                    longueur_chaine;
                    618:    integer8                    longueur_clef;
                    619:    integer8                    longueur_clef_attendue;
                    620:    integer8                    longueur_clef_max;
                    621:    integer8                    longueur_clef_min;
                    622:    integer8                    longueur_tampon;
                    623: 
1.39      bertrand  624:    logical1                    somme_invalide;
                    625: 
1.41      bertrand  626:    struct_liste_chainee        *l_element_courant;
                    627: 
1.39      bertrand  628:    struct_objet                *s_objet_argument_1;
                    629:    struct_objet                *s_objet_argument_2;
                    630:    struct_objet                *s_objet_resultat;
                    631: 
                    632:    unsigned char               *chaine;
1.41      bertrand  633:    unsigned char               *clef;
1.39      bertrand  634:    unsigned char               *fonction;
                    635:    unsigned char               somme[EVP_MAX_MD_SIZE];
1.41      bertrand  636:    unsigned char               *tampon;
1.42      bertrand  637:    unsigned char               *vecteur_initialisation;
1.39      bertrand  638: 
                    639:    (*s_etat_processus).erreur_execution = d_ex;
                    640: 
                    641:    if ((*s_etat_processus).affichage_arguments == 'Y')
                    642:    {
                    643:        printf("\n  DIGEST ");
                    644: 
                    645:        if ((*s_etat_processus).langue == 'F')
                    646:        {
                    647:            printf("(somme d'authentification)\n\n");
                    648:        }
                    649:        else
                    650:        {
                    651:            printf("(hash algorithm)\n\n");
                    652:        }
                    653: 
                    654:        printf("    2: %s\n", d_CHN);
                    655:        printf("    1: %s\n", d_CHN);
                    656:        printf("->  1: %s\n\n", d_CHN);
                    657: 
                    658:        printf("    2: %s\n", d_CHN);
                    659:        printf("    1: %s\n", d_LST);
                    660:        printf("->  1: %s\n\n", d_CHN);
                    661: 
                    662:        if ((*s_etat_processus).langue == 'F')
                    663:        {
                    664:            printf("  Algorithmes :\n\n");
                    665:        }
                    666:        else
                    667:        {
                    668:            printf("  Algorithms:\n\n");
                    669:        }
                    670: 
1.42      bertrand  671: #      ifndef OPENSSL_NO_AES
                    672:        printf("    - AES-128-CBC\n");
                    673:        printf("    - AES-192-CBC\n");
                    674:        printf("    - AES-256-CBC\n");
                    675: #      endif
1.43      bertrand  676: #      ifndef OPENSSL_NO_CAMELLIA
                    677:        printf("    - CAMELLIA-128-CBC\n");
                    678:        printf("    - CAMELLIA-192-CBC\n");
                    679:        printf("    - CAMELLIA-256-CBC\n");
                    680: #      endif
                    681: #      ifndef OPENSSL_NO_DES
                    682:        printf("    - DES-CBC\n");
                    683:        printf("    - DES-EDE-CBC\n");
                    684:        printf("    - DES-EDE3-CB\n");
                    685:        printf("    - DESX-CBC\n");
                    686: #      endif
1.39      bertrand  687: #      ifndef OPENSSL_NO_SHA
                    688:        printf("    - DSS\n");
                    689:        printf("    - DSS1\n");
                    690:        printf("    - ECDSA\n");
                    691: #      endif
1.43      bertrand  692: #      ifndef OPENSSL_NO_IDEA
                    693:        printf("    - IDEA-CBC\n");
                    694: #      endif
1.39      bertrand  695: #      ifndef OPENSSL_NO_MD2
                    696:        printf("    - MD2\n");
                    697: #      endif
                    698: #      ifndef OPENSSL_NO_MD4
                    699:        printf("    - MD4\n");
                    700: #      endif
                    701: #      ifndef OPENSSL_NO_MD5
                    702:        printf("    - MD5\n");
                    703: #      endif
1.40      bertrand  704: #      ifndef OPENSSL_NO_MDC2
                    705:        printf("    - MDC2\n");
                    706: #      endif
1.43      bertrand  707: #      ifndef OPENSSL_NO_RC2
                    708:        printf("    - RC2-CBC\n");
                    709:        printf("    - RC2-40-CBC\n");
                    710:        printf("    - RC2-64-CBC\n");
                    711: #      endif
1.40      bertrand  712: #      ifndef OPENSSL_NO_RIPEMD
                    713:        printf("    - RIPEMD160\n");
                    714: #      endif
1.39      bertrand  715: #      ifndef OPENSSL_NO_SHA
                    716:        printf("    - SHA\n");
                    717:        printf("    - SHA1\n");
                    718: #      endif
1.40      bertrand  719: #      ifndef OPENSSL_NO_SHA256
                    720:        printf("    - SHA224\n");
                    721:        printf("    - SHA256\n");
                    722: #      endif
                    723: #      ifndef OPENSSL_NO_SHA512
                    724:        printf("    - SHA384\n");
                    725:        printf("    - SHA512\n");
                    726: #      endif
                    727: #      ifndef OPENSSL_NO_WHIRLPOOL
                    728:        printf("    - WHIRLPOOL\n");
                    729: #      endif
1.39      bertrand  730: 
1.41      bertrand  731:        printf("\n");
                    732: 
                    733:        if ((*s_etat_processus).langue == 'F')
                    734:        {
                    735:            printf("  Utilisation :\n\n");
                    736:        }
                    737:        else
                    738:        {
                    739:            printf("  Usage:\n\n");
                    740:        }
                    741: 
                    742:        printf("    \"text\" \"MD5\" DIGEST\n");
                    743:        printf("    \"text\" { \"SHA384\" \"key\" } DIGEST\n");
1.42      bertrand  744:        printf("    \"text\" { \"AES-128-CBC\" \"key\" } DIGEST\n");
1.39      bertrand  745:        return;
                    746:    }
                    747:    else if ((*s_etat_processus).test_instruction == 'Y')
                    748:    {
                    749:        (*s_etat_processus).nombre_arguments = -1;
                    750:        return;
                    751:    }
                    752: 
                    753:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    754:    {
                    755:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    756:        {
                    757:            return;
                    758:        }
                    759:    }
                    760: 
                    761:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    762:            &s_objet_argument_1) == d_erreur)
                    763:    {
                    764:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    765:        return;
                    766:    }
                    767: 
                    768:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    769:            &s_objet_argument_2) == d_erreur)
                    770:    {
                    771:        liberation(s_etat_processus, s_objet_argument_1);
                    772: 
                    773:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    774:        return;
                    775:    }
                    776: 
                    777:    if (((*s_objet_argument_1).type == CHN) &&
                    778:            ((*s_objet_argument_2).type == CHN))
                    779:    {
                    780:        // Liste des sommes disponibles :
                    781:        // - EVP_dss
                    782:        // - EVP_dss1
                    783:        // - EVP_ecdsa
                    784:        // - EVP_md2
                    785:        // - EVP_md4
                    786:        // - EVP_md5
                    787:        // - EVP_mdc2
                    788:        // - EVP_ripemd160
                    789:        // - EVP_sha
                    790:        // - EVP_sha1
                    791:        // - EVP_sha224
                    792:        // - EVP_sha256
                    793:        // - EVP_sha384
                    794:        // - EVP_sha512
                    795:        // - EVP_whirlpool
                    796: 
                    797:        if ((fonction = conversion_majuscule((unsigned char *)
                    798:                (*s_objet_argument_1).objet)) == NULL)
                    799:        {
                    800:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    801:            return;
                    802:        }
                    803: 
                    804:        somme_invalide = d_faux;
                    805: 
                    806:        switch(fonction[0])
                    807:        {
                    808:            case 'D':
                    809:            {
                    810:                switch(fonction[1])
                    811:                {
                    812:                    case 'S': // ds
                    813:                    {
                    814:                        switch(fonction[2])
                    815:                        {
                    816: #                          ifndef OPENSSL_NO_SHA
                    817:                            case 'S': // dss
                    818:                            {
                    819:                                switch(fonction[3])
                    820:                                {
                    821:                                    case d_code_fin_chaine:
                    822:                                    {
1.42      bertrand  823:                                        EVP_sum = EVP_dss();
1.39      bertrand  824:                                        break;
                    825:                                    }
                    826: 
                    827:                                    case '1': // dss1
                    828:                                    {
                    829:                                        if (fonction[4] == d_code_fin_chaine)
                    830:                                        {
1.42      bertrand  831:                                            EVP_sum = EVP_dss1();
1.39      bertrand  832:                                        }
                    833:                                        else
                    834:                                        {
                    835:                                            somme_invalide = d_vrai;
                    836:                                        }
                    837: 
                    838:                                        break;
                    839:                                    }
                    840: 
                    841:                                    default:
                    842:                                    {
                    843:                                        somme_invalide = d_vrai;
                    844:                                        break;
                    845:                                    }
                    846:                                }
                    847: 
                    848:                                break;
                    849:                            }
                    850: #                          endif
                    851: 
                    852:                            default:
                    853:                            {
                    854:                                somme_invalide = d_vrai;
                    855:                                break;
                    856:                            }
                    857:                        }
                    858: 
                    859:                        break;
                    860:                    }
                    861: 
                    862:                    default:
                    863:                    {
                    864:                        somme_invalide = d_vrai;
                    865:                        break;
                    866:                    }
                    867:                }
                    868: 
                    869:                break;
                    870:            }
                    871: 
                    872:            case 'E':
                    873:            {
                    874:                switch(fonction[1])
                    875:                {
                    876:                    case 'C': // ec
                    877:                    {
                    878:                        switch(fonction[2])
                    879:                        {
                    880:                            case 'D': // ecd
                    881:                            {
                    882:                                switch(fonction[3])
                    883:                                {
                    884:                                    case 'S': // ecds
                    885:                                    {
                    886:                                        switch(fonction[4])
                    887:                                        {
                    888: #                                          ifndef OPENSSL_NO_SHA
                    889:                                            case 'A': // ecdsa
                    890:                                            {
                    891:                                                if (fonction[5] ==
                    892:                                                        d_code_fin_chaine)
                    893:                                                {
1.42      bertrand  894:                                                    EVP_sum = EVP_ecdsa();
1.39      bertrand  895:                                                }
                    896:                                                else
                    897:                                                {
                    898:                                                    somme_invalide = d_vrai;
                    899:                                                }
                    900: 
                    901:                                                break;
                    902:                                            }
                    903: #                                          endif
                    904: 
                    905:                                            default:
                    906:                                            {
                    907:                                                somme_invalide = d_vrai;
                    908:                                                break;
                    909:                                            }
                    910:                                        }
                    911: 
                    912:                                        break;
                    913:                                    }
                    914: 
                    915:                                    default:
                    916:                                    {
                    917:                                        somme_invalide = d_vrai;
                    918:                                        break;
                    919:                                    }
                    920:                                }
                    921: 
                    922:                                break;
                    923:                            }
                    924: 
                    925:                            default:
                    926:                            {
                    927:                                somme_invalide = d_vrai;
                    928:                                break;
                    929:                            }
                    930:                        }
                    931: 
                    932:                        break;
                    933:                    }
                    934: 
                    935:                    default:
                    936:                    {
                    937:                        somme_invalide = d_vrai;
                    938:                        break;
                    939:                    }
                    940:                }
                    941: 
                    942:                break;
                    943:            }
                    944: 
                    945:            case 'M':
                    946:            {
                    947:                switch(fonction[1])
                    948:                {
                    949:                    case 'D': // md
                    950:                    {
                    951:                        switch(fonction[2])
                    952:                        {
                    953: #                          ifndef OPENSSL_NO_MD2
                    954:                            case '2': // md2
                    955:                            {
                    956:                                if (fonction[3] == d_code_fin_chaine)
                    957:                                {
1.42      bertrand  958:                                    EVP_sum = EVP_md2();
1.39      bertrand  959:                                }
                    960:                                else
                    961:                                {
                    962:                                    somme_invalide = d_vrai;
                    963:                                }
                    964: 
                    965:                                break;
                    966:                            }
                    967: #                          endif
                    968: 
                    969: #                          ifndef OPENSSL_NO_MD4
                    970:                            case '4': // md4
                    971:                            {
                    972:                                if (fonction[3] == d_code_fin_chaine)
                    973:                                {
1.42      bertrand  974:                                    EVP_sum = EVP_md4();
1.39      bertrand  975:                                }
                    976:                                else
                    977:                                {
                    978:                                    somme_invalide = d_vrai;
                    979:                                }
                    980: 
                    981:                                break;
                    982:                            }
                    983: #                          endif
                    984: 
1.41      bertrand  985: #                          ifndef OPENSSL_NO_MD5
1.39      bertrand  986:                            case '5': // md5
                    987:                            {
                    988:                                if (fonction[3] == d_code_fin_chaine)
                    989:                                {
1.42      bertrand  990:                                    EVP_sum = EVP_md5();
1.39      bertrand  991:                                }
                    992:                                else
                    993:                                {
                    994:                                    somme_invalide = d_vrai;
                    995:                                }
                    996: 
                    997:                                break;
                    998:                            }
                    999: #                          endif
                   1000: 
                   1001:                            case 'C': // mdc
                   1002:                            {
                   1003:                                switch(fonction[3])
                   1004:                                {
                   1005: #                                  ifndef OPENSSL_NO_MDC2
                   1006:                                    case '2': // mdc2
                   1007:                                    {
                   1008:                                        if (fonction[4] == d_code_fin_chaine)
                   1009:                                        {
1.42      bertrand 1010:                                            EVP_sum = EVP_mdc2();
1.39      bertrand 1011:                                        }
                   1012:                                        else
                   1013:                                        {
                   1014:                                            somme_invalide = d_vrai;
                   1015:                                        }
                   1016: 
                   1017:                                        break;
                   1018:                                    }
                   1019: #                                  endif
                   1020: 
                   1021:                                    default:
                   1022:                                    {
                   1023:                                        somme_invalide = d_vrai;
                   1024:                                        break;
                   1025:                                    }
                   1026:                                }
                   1027: 
                   1028:                                break;
                   1029:                            }
                   1030: 
                   1031:                            default:
                   1032:                            {
                   1033:                                somme_invalide = d_vrai;
                   1034:                                break;
                   1035:                            }
                   1036:                        }
                   1037: 
                   1038:                        break;
                   1039:                    }
                   1040: 
                   1041:                    default:
                   1042:                    {
                   1043:                        somme_invalide = d_vrai;
                   1044:                        break;
                   1045:                    }
                   1046:                }
                   1047: 
                   1048:                break;
                   1049:            }
                   1050: 
                   1051: #          ifndef OPENSSL_NO_RIPEMD
                   1052:            case 'R':
                   1053:            {
                   1054:                if (strcmp(fonction, "RIPEMD160") == 0)
                   1055:                {
1.42      bertrand 1056:                    EVP_sum = EVP_ripemd160();
1.39      bertrand 1057:                }
                   1058:                else
                   1059:                {
                   1060:                    somme_invalide = d_vrai;
                   1061:                }
                   1062: 
                   1063:                break;
                   1064:            }
                   1065: #          endif
                   1066: 
                   1067:            case 'S':
                   1068:            {
                   1069:                switch(fonction[1])
                   1070:                {
                   1071:                    case 'H': // sh
                   1072:                    {
                   1073:                        switch(fonction[2])
                   1074:                        {
                   1075: #                          ifndef OPENSSL_NO_SHA
                   1076:                            case 'A':
                   1077:                            {
                   1078:                                switch(fonction[3])
                   1079:                                {
                   1080:                                    case d_code_fin_chaine:
                   1081:                                    {
1.42      bertrand 1082:                                        EVP_sum = EVP_sha();
1.39      bertrand 1083:                                        break;
                   1084:                                    }
                   1085: 
                   1086:                                    case '1': // sha1
                   1087:                                    {
                   1088:                                        if (fonction[4] == d_code_fin_chaine)
                   1089:                                        {
1.42      bertrand 1090:                                            EVP_sum = EVP_sha1();
1.39      bertrand 1091:                                        }
                   1092:                                        else
                   1093:                                        {
                   1094:                                            somme_invalide = d_vrai;
                   1095:                                        }
                   1096: 
                   1097:                                        break;
                   1098:                                    }
                   1099: 
                   1100: #                                  ifndef OPENSSL_NO_SHA256
                   1101:                                    case '2': // sha2
                   1102:                                    {
                   1103:                                        switch(fonction[4])
                   1104:                                        {
                   1105:                                            case '2': // sha22
                   1106:                                            {
                   1107:                                                switch(fonction[5])
                   1108:                                                {
                   1109:                                                    case '4': // sha224
                   1110:                                                    {
                   1111:                                                        if (fonction[6] ==
                   1112:                                                            d_code_fin_chaine)
                   1113:                                                        {
                   1114:                                                            EVP_sum =
1.42      bertrand 1115:                                                                EVP_sha224();
1.39      bertrand 1116:                                                        }
                   1117:                                                        else
                   1118:                                                        {
                   1119:                                                            somme_invalide =
1.42      bertrand 1120:                                                                d_vrai;
1.39      bertrand 1121:                                                        }
                   1122: 
                   1123:                                                        break;
                   1124:                                                    }
                   1125: 
                   1126:                                                    default:
                   1127:                                                    {
                   1128:                                                        somme_invalide = d_vrai;
                   1129:                                                        break;
                   1130:                                                    }
                   1131:                                                }
                   1132: 
                   1133:                                                break;
                   1134:                                            }
                   1135: 
                   1136:                                            case '5':
                   1137:                                            {
                   1138:                                                switch(fonction[5])
                   1139:                                                {
                   1140:                                                    case '6': // sha256
                   1141:                                                    {
                   1142:                                                        if (fonction[6] ==
                   1143:                                                            d_code_fin_chaine)
                   1144:                                                        {
                   1145:                                                            EVP_sum =
1.42      bertrand 1146:                                                                EVP_sha256();
1.39      bertrand 1147:                                                        }
                   1148:                                                        else
                   1149:                                                        {
                   1150:                                                            somme_invalide =
1.42      bertrand 1151:                                                                d_vrai;
1.39      bertrand 1152:                                                        }
                   1153: 
                   1154:                                                        break;
                   1155:                                                    }
                   1156: 
                   1157:                                                    default:
                   1158:                                                    {
                   1159:                                                        somme_invalide = d_vrai;
                   1160:                                                        break;
                   1161:                                                    }
                   1162:                                                }
                   1163: 
                   1164:                                                break;
                   1165:                                            }
                   1166: 
                   1167:                                            default:
                   1168:                                            {
                   1169:                                                somme_invalide = d_vrai;
                   1170:                                                break;
                   1171:                                            }
                   1172:                                        }
                   1173: 
                   1174:                                        break;
                   1175:                                    }
                   1176: #                                  endif
                   1177: 
                   1178: #                                  ifndef OPENSSL_NO_SHA512
                   1179:                                    case '3': // sha3
                   1180:                                    {
                   1181:                                        switch(fonction[4])
                   1182:                                        {
                   1183:                                            case '8': // sha38
                   1184:                                            {
                   1185:                                                switch(fonction[5])
                   1186:                                                {
                   1187:                                                    case '4': // sha384
                   1188:                                                    {
                   1189:                                                        if (fonction[6] ==
                   1190:                                                            d_code_fin_chaine)
                   1191:                                                        {
                   1192:                                                            EVP_sum =
1.42      bertrand 1193:                                                                EVP_sha384();
1.39      bertrand 1194:                                                        }
                   1195:                                                        else
                   1196:                                                        {
                   1197:                                                            somme_invalide =
1.42      bertrand 1198:                                                                d_vrai;
1.39      bertrand 1199:                                                        }
                   1200: 
                   1201:                                                        break;
                   1202:                                                    }
                   1203: 
                   1204:                                                    default:
                   1205:                                                    {
                   1206:                                                        somme_invalide = d_vrai;
                   1207:                                                        break;
                   1208:                                                    }
                   1209:                                                }
                   1210: 
                   1211:                                                break;
                   1212:                                            }
                   1213: 
                   1214:                                            default:
                   1215:                                            {
                   1216:                                                somme_invalide = d_vrai;
                   1217:                                                break;
                   1218:                                            }
                   1219:                                        }
                   1220: 
                   1221:                                        break;
                   1222:                                    }
                   1223: 
                   1224:                                    case '5': // sha5
                   1225:                                    {
                   1226:                                        switch(fonction[4])
                   1227:                                        {
                   1228:                                            case '1': // sha51
                   1229:                                            {
                   1230:                                                switch(fonction[5])
                   1231:                                                {
                   1232:                                                    case '2': // sha512
                   1233:                                                    {
                   1234:                                                        if (fonction[6] ==
                   1235:                                                            d_code_fin_chaine)
                   1236:                                                        {
                   1237:                                                            EVP_sum =
1.42      bertrand 1238:                                                                EVP_sha512();
1.39      bertrand 1239:                                                        }
                   1240:                                                        else
                   1241:                                                        {
                   1242:                                                            somme_invalide =
1.42      bertrand 1243:                                                                d_vrai;
1.39      bertrand 1244:                                                        }
                   1245: 
                   1246:                                                        break;
                   1247:                                                    }
                   1248: 
                   1249:                                                    default:
                   1250:                                                    {
                   1251:                                                        somme_invalide = d_vrai;
                   1252:                                                        break;
                   1253:                                                    }
                   1254:                                                }
                   1255: 
                   1256:                                                break;
                   1257:                                            }
                   1258: 
                   1259:                                            default:
                   1260:                                            {
                   1261:                                                somme_invalide = d_vrai;
                   1262:                                                break;
                   1263:                                            }
                   1264:                                        }
                   1265: 
                   1266:                                        break;
                   1267:                                    }
                   1268: #                                  endif
                   1269: 
                   1270:                                    default:
                   1271:                                    {
                   1272:                                        somme_invalide = d_vrai;
                   1273:                                        break;
                   1274:                                    }
                   1275:                                }
                   1276: 
                   1277:                                break;
                   1278:                            }
                   1279: #                          endif
                   1280: 
                   1281:                            default:
                   1282:                            {
                   1283:                                somme_invalide = d_vrai;
                   1284:                                break;
                   1285:                            }
                   1286:                        }
                   1287: 
                   1288:                        break;
                   1289:                    }
                   1290: 
                   1291:                    default:
                   1292:                    {
                   1293:                        somme_invalide = d_vrai;
                   1294:                        break;
                   1295:                    }
                   1296:                }
                   1297: 
                   1298:                break;
                   1299:            }
                   1300: 
                   1301: #          ifndef OPENSSL_NO_WHIRLPOOL
                   1302:            case 'W':
                   1303:            {
                   1304:                if (strcmp(fonction, "WHIRLPOOL") == 0)
                   1305:                {
1.42      bertrand 1306:                    EVP_sum = EVP_whirlpool();
1.39      bertrand 1307:                }
                   1308:                else
                   1309:                {
                   1310:                    somme_invalide = d_vrai;
                   1311:                }
                   1312: 
                   1313:                break;
                   1314:            }
                   1315: #          endif
                   1316: 
                   1317:            default:
                   1318:            {
                   1319:                somme_invalide = d_vrai;
                   1320:                break;
                   1321:            }
                   1322:        }
                   1323: 
                   1324:        free(fonction);
                   1325: 
                   1326:        if (somme_invalide == d_vrai)
                   1327:        {
                   1328:            liberation(s_etat_processus, s_objet_argument_1);
                   1329:            liberation(s_etat_processus, s_objet_argument_2);
                   1330: 
                   1331:            (*s_etat_processus).erreur_execution =
                   1332:                    d_ex_chiffrement_indisponible;
                   1333:            return;
                   1334:        }
                   1335: 
1.42      bertrand 1336:        if (EVP_DigestInit(&contexte, EVP_sum) != 1)
1.39      bertrand 1337:        {
                   1338:            EVP_MD_CTX_cleanup(&contexte);
                   1339: 
                   1340:            liberation(s_etat_processus, s_objet_argument_1);
                   1341:            liberation(s_etat_processus, s_objet_argument_2);
                   1342: 
                   1343:            (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   1344:            return;
                   1345:        }
                   1346: 
                   1347:        if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
                   1348:                (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
                   1349:        {
                   1350:            EVP_MD_CTX_cleanup(&contexte);
                   1351: 
                   1352:            liberation(s_etat_processus, s_objet_argument_1);
                   1353:            liberation(s_etat_processus, s_objet_argument_2);
                   1354: 
                   1355:            return;
                   1356:        }
                   1357: 
1.48      bertrand 1358:        if (EVP_DigestUpdate(&contexte, chaine, (size_t) longueur_chaine) != 1)
1.39      bertrand 1359:        {
                   1360:            free(chaine);
                   1361:            EVP_MD_CTX_cleanup(&contexte);
                   1362: 
                   1363:            liberation(s_etat_processus, s_objet_argument_1);
                   1364:            liberation(s_etat_processus, s_objet_argument_2);
                   1365: 
                   1366:            (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   1367:            return;
                   1368:        }
                   1369: 
                   1370:        if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
                   1371:        {
                   1372:            free(chaine);
                   1373:            EVP_MD_CTX_cleanup(&contexte);
                   1374: 
                   1375:            liberation(s_etat_processus, s_objet_argument_1);
                   1376:            liberation(s_etat_processus, s_objet_argument_2);
                   1377: 
                   1378:            (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   1379:            return;
                   1380:        }
                   1381: 
                   1382:        free(chaine);
                   1383:        EVP_MD_CTX_cleanup(&contexte);
                   1384: 
                   1385:        if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
                   1386:        {
                   1387:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1388:            return;
                   1389:        }
                   1390: 
                   1391:        if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
                   1392:                somme, longueur_somme)) == NULL)
                   1393:        {
                   1394:            liberation(s_etat_processus, s_objet_argument_1);
                   1395:            liberation(s_etat_processus, s_objet_argument_2);
                   1396: 
                   1397:            return;
                   1398:        }
                   1399:    }
1.41      bertrand 1400:    else if (((*s_objet_argument_1).type == LST) &&
                   1401:            ((*s_objet_argument_2).type == CHN))
1.39      bertrand 1402:    {
1.41      bertrand 1403:        l_element_courant = (*s_objet_argument_1).objet;
                   1404: 
                   1405:        if ((*(*l_element_courant).donnee).type != CHN)
                   1406:        {
                   1407:            liberation(s_etat_processus, s_objet_argument_1);
                   1408:            liberation(s_etat_processus, s_objet_argument_2);
                   1409: 
                   1410:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1411:            return;
                   1412:        }
                   1413: 
                   1414:        l_element_courant = (*l_element_courant).suivant;
                   1415: 
                   1416:        if (l_element_courant == NULL)
                   1417:        {
                   1418:            liberation(s_etat_processus, s_objet_argument_1);
                   1419:            liberation(s_etat_processus, s_objet_argument_2);
                   1420: 
                   1421:            (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                   1422:            return;
                   1423:        }
                   1424: 
                   1425:        if ((*(*l_element_courant).donnee).type != CHN)
                   1426:        {
                   1427:            liberation(s_etat_processus, s_objet_argument_1);
                   1428:            liberation(s_etat_processus, s_objet_argument_2);
                   1429: 
                   1430:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   1431:            return;
                   1432:        }
                   1433: 
                   1434:        if ((*l_element_courant).suivant != NULL)
                   1435:        {
                   1436:            liberation(s_etat_processus, s_objet_argument_1);
                   1437:            liberation(s_etat_processus, s_objet_argument_2);
                   1438: 
                   1439:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                   1440:            return;
                   1441:        }
                   1442: 
                   1443:        // Test du type de somme de contrôle
                   1444:        // - les sommes classiques suivent la RFC 2104
                   1445:        // - les autres sont formées sur des algorithmes de type CBC
                   1446: 
                   1447:        l_element_courant = (*s_objet_argument_1).objet;
                   1448: 
                   1449:        if ((fonction = conversion_majuscule((unsigned char *)
                   1450:                (*(*l_element_courant).donnee).objet)) == NULL)
                   1451:        {
                   1452:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1453:            return;
                   1454:        }
                   1455: 
                   1456:        somme_invalide = d_faux;
                   1457: 
                   1458:        switch(fonction[0])
                   1459:        {
                   1460:            case 'D':
                   1461:            {
                   1462:                switch(fonction[1])
                   1463:                {
                   1464:                    case 'S': // ds
                   1465:                    {
                   1466:                        switch(fonction[2])
                   1467:                        {
                   1468: #                          ifndef OPENSSL_NO_SHA
                   1469:                            case 'S': // dss
                   1470:                            {
                   1471:                                switch(fonction[3])
                   1472:                                {
                   1473:                                    case d_code_fin_chaine:
                   1474:                                    {
1.42      bertrand 1475:                                        EVP_sum = EVP_dss();
1.41      bertrand 1476:                                        break;
                   1477:                                    }
                   1478: 
                   1479:                                    case '1': // dss1
                   1480:                                    {
                   1481:                                        if (fonction[4] == d_code_fin_chaine)
                   1482:                                        {
1.42      bertrand 1483:                                            EVP_sum = EVP_dss1();
1.41      bertrand 1484:                                        }
                   1485:                                        else
                   1486:                                        {
                   1487:                                            somme_invalide = d_vrai;
                   1488:                                        }
                   1489: 
                   1490:                                        break;
                   1491:                                    }
                   1492: 
                   1493:                                    default:
                   1494:                                    {
                   1495:                                        somme_invalide = d_vrai;
                   1496:                                        break;
                   1497:                                    }
                   1498:                                }
                   1499: 
                   1500:                                break;
                   1501:                            }
                   1502: #                          endif
                   1503: 
                   1504:                            default:
                   1505:                            {
                   1506:                                somme_invalide = d_vrai;
                   1507:                                break;
                   1508:                            }
                   1509:                        }
                   1510: 
                   1511:                        break;
                   1512:                    }
                   1513: 
                   1514:                    default:
                   1515:                    {
                   1516:                        somme_invalide = d_vrai;
                   1517:                        break;
                   1518:                    }
                   1519:                }
                   1520: 
                   1521:                break;
                   1522:            }
                   1523: 
                   1524:            case 'E':
                   1525:            {
                   1526:                switch(fonction[1])
                   1527:                {
                   1528:                    case 'C': // ec
                   1529:                    {
                   1530:                        switch(fonction[2])
                   1531:                        {
                   1532:                            case 'D': // ecd
                   1533:                            {
                   1534:                                switch(fonction[3])
                   1535:                                {
                   1536:                                    case 'S': // ecds
                   1537:                                    {
                   1538:                                        switch(fonction[4])
                   1539:                                        {
                   1540: #                                          ifndef OPENSSL_NO_SHA
                   1541:                                            case 'A': // ecdsa
                   1542:                                            {
                   1543:                                                if (fonction[5] ==
                   1544:                                                        d_code_fin_chaine)
                   1545:                                                {
1.42      bertrand 1546:                                                    EVP_sum = EVP_ecdsa();
1.41      bertrand 1547:                                                }
                   1548:                                                else
                   1549:                                                {
                   1550:                                                    somme_invalide = d_vrai;
                   1551:                                                }
                   1552: 
                   1553:                                                break;
                   1554:                                            }
                   1555: #                                          endif
                   1556: 
                   1557:                                            default:
                   1558:                                            {
                   1559:                                                somme_invalide = d_vrai;
                   1560:                                                break;
                   1561:                                            }
                   1562:                                        }
                   1563: 
                   1564:                                        break;
                   1565:                                    }
                   1566: 
                   1567:                                    default:
                   1568:                                    {
                   1569:                                        somme_invalide = d_vrai;
                   1570:                                        break;
                   1571:                                    }
                   1572:                                }
                   1573: 
                   1574:                                break;
                   1575:                            }
                   1576: 
                   1577:                            default:
                   1578:                            {
                   1579:                                somme_invalide = d_vrai;
                   1580:                                break;
                   1581:                            }
                   1582:                        }
                   1583: 
                   1584:                        break;
                   1585:                    }
                   1586: 
                   1587:                    default:
                   1588:                    {
                   1589:                        somme_invalide = d_vrai;
                   1590:                        break;
                   1591:                    }
                   1592:                }
                   1593: 
                   1594:                break;
                   1595:            }
                   1596: 
                   1597:            case 'M':
                   1598:            {
                   1599:                switch(fonction[1])
                   1600:                {
                   1601:                    case 'D': // md
                   1602:                    {
                   1603:                        switch(fonction[2])
                   1604:                        {
                   1605: #                          ifndef OPENSSL_NO_MD2
                   1606:                            case '2': // md2
                   1607:                            {
                   1608:                                if (fonction[3] == d_code_fin_chaine)
                   1609:                                {
1.42      bertrand 1610:                                    EVP_sum = EVP_md2();
1.41      bertrand 1611:                                }
                   1612:                                else
                   1613:                                {
                   1614:                                    somme_invalide = d_vrai;
                   1615:                                }
                   1616: 
                   1617:                                break;
                   1618:                            }
                   1619: #                          endif
                   1620: 
                   1621: #                          ifndef OPENSSL_NO_MD4
                   1622:                            case '4': // md4
                   1623:                            {
                   1624:                                if (fonction[3] == d_code_fin_chaine)
                   1625:                                {
1.42      bertrand 1626:                                    EVP_sum = EVP_md4();
1.41      bertrand 1627:                                }
                   1628:                                else
                   1629:                                {
                   1630:                                    somme_invalide = d_vrai;
                   1631:                                }
                   1632: 
                   1633:                                break;
                   1634:                            }
                   1635: #                          endif
                   1636: 
                   1637: #                          ifndef OPENSSL_NO_MD5
                   1638:                            case '5': // md5
                   1639:                            {
                   1640:                                if (fonction[3] == d_code_fin_chaine)
                   1641:                                {
1.42      bertrand 1642:                                    EVP_sum = EVP_md5();
1.41      bertrand 1643:                                }
                   1644:                                else
                   1645:                                {
                   1646:                                    somme_invalide = d_vrai;
                   1647:                                }
                   1648: 
                   1649:                                break;
                   1650:                            }
                   1651: #                          endif
                   1652: 
                   1653:                            case 'C': // mdc
                   1654:                            {
                   1655:                                switch(fonction[3])
                   1656:                                {
                   1657: #                                  ifndef OPENSSL_NO_MDC2
                   1658:                                    case '2': // mdc2
                   1659:                                    {
                   1660:                                        if (fonction[4] == d_code_fin_chaine)
                   1661:                                        {
1.42      bertrand 1662:                                            EVP_sum = EVP_mdc2();
1.41      bertrand 1663:                                        }
                   1664:                                        else
                   1665:                                        {
                   1666:                                            somme_invalide = d_vrai;
                   1667:                                        }
                   1668: 
                   1669:                                        break;
                   1670:                                    }
                   1671: #                                  endif
                   1672: 
                   1673:                                    default:
                   1674:                                    {
                   1675:                                        somme_invalide = d_vrai;
                   1676:                                        break;
                   1677:                                    }
                   1678:                                }
                   1679: 
                   1680:                                break;
                   1681:                            }
                   1682: 
                   1683:                            default:
                   1684:                            {
                   1685:                                somme_invalide = d_vrai;
                   1686:                                break;
                   1687:                            }
                   1688:                        }
                   1689: 
                   1690:                        break;
                   1691:                    }
                   1692: 
                   1693:                    default:
                   1694:                    {
                   1695:                        somme_invalide = d_vrai;
                   1696:                        break;
                   1697:                    }
                   1698:                }
                   1699: 
                   1700:                break;
                   1701:            }
                   1702: 
                   1703: #          ifndef OPENSSL_NO_RIPEMD
                   1704:            case 'R':
                   1705:            {
                   1706:                if (strcmp(fonction, "RIPEMD160") == 0)
                   1707:                {
1.42      bertrand 1708:                    EVP_sum = EVP_ripemd160();
1.41      bertrand 1709:                }
                   1710:                else
                   1711:                {
                   1712:                    somme_invalide = d_vrai;
                   1713:                }
                   1714: 
                   1715:                break;
                   1716:            }
                   1717: #          endif
                   1718: 
                   1719:            case 'S':
                   1720:            {
                   1721:                switch(fonction[1])
                   1722:                {
                   1723:                    case 'H': // sh
                   1724:                    {
                   1725:                        switch(fonction[2])
                   1726:                        {
                   1727: #                          ifndef OPENSSL_NO_SHA
                   1728:                            case 'A':
                   1729:                            {
                   1730:                                switch(fonction[3])
                   1731:                                {
                   1732:                                    case d_code_fin_chaine:
                   1733:                                    {
1.42      bertrand 1734:                                        EVP_sum = EVP_sha();
1.41      bertrand 1735:                                        break;
                   1736:                                    }
                   1737: 
                   1738:                                    case '1': // sha1
                   1739:                                    {
                   1740:                                        if (fonction[4] == d_code_fin_chaine)
                   1741:                                        {
1.42      bertrand 1742:                                            EVP_sum = EVP_sha1();
1.41      bertrand 1743:                                        }
                   1744:                                        else
                   1745:                                        {
                   1746:                                            somme_invalide = d_vrai;
                   1747:                                        }
                   1748: 
                   1749:                                        break;
                   1750:                                    }
                   1751: 
                   1752: #                                  ifndef OPENSSL_NO_SHA256
                   1753:                                    case '2': // sha2
                   1754:                                    {
                   1755:                                        switch(fonction[4])
                   1756:                                        {
                   1757:                                            case '2': // sha22
                   1758:                                            {
                   1759:                                                switch(fonction[5])
                   1760:                                                {
                   1761:                                                    case '4': // sha224
                   1762:                                                    {
                   1763:                                                        if (fonction[6] ==
                   1764:                                                            d_code_fin_chaine)
                   1765:                                                        {
                   1766:                                                            EVP_sum =
1.42      bertrand 1767:                                                                EVP_sha224();
1.41      bertrand 1768:                                                        }
                   1769:                                                        else
                   1770:                                                        {
                   1771:                                                            somme_invalide =
                   1772:                                                                    d_vrai;
                   1773:                                                        }
                   1774: 
                   1775:                                                        break;
                   1776:                                                    }
                   1777: 
                   1778:                                                    default:
                   1779:                                                    {
                   1780:                                                        somme_invalide = d_vrai;
                   1781:                                                        break;
                   1782:                                                    }
                   1783:                                                }
                   1784: 
                   1785:                                                break;
                   1786:                                            }
                   1787: 
                   1788:                                            case '5':
                   1789:                                            {
                   1790:                                                switch(fonction[5])
                   1791:                                                {
                   1792:                                                    case '6': // sha256
                   1793:                                                    {
                   1794:                                                        if (fonction[6] ==
                   1795:                                                            d_code_fin_chaine)
                   1796:                                                        {
                   1797:                                                            EVP_sum =
1.42      bertrand 1798:                                                                EVP_sha256();
1.41      bertrand 1799:                                                        }
                   1800:                                                        else
                   1801:                                                        {
                   1802:                                                            somme_invalide =
                   1803:                                                                    d_vrai;
                   1804:                                                        }
                   1805: 
                   1806:                                                        break;
                   1807:                                                    }
                   1808: 
                   1809:                                                    default:
                   1810:                                                    {
                   1811:                                                        somme_invalide = d_vrai;
                   1812:                                                        break;
                   1813:                                                    }
                   1814:                                                }
                   1815: 
                   1816:                                                break;
                   1817:                                            }
                   1818: 
                   1819:                                            default:
                   1820:                                            {
                   1821:                                                somme_invalide = d_vrai;
                   1822:                                                break;
                   1823:                                            }
                   1824:                                        }
                   1825: 
                   1826:                                        break;
                   1827:                                    }
                   1828: #                                  endif
                   1829: 
                   1830: #                                  ifndef OPENSSL_NO_SHA512
                   1831:                                    case '3': // sha3
                   1832:                                    {
                   1833:                                        switch(fonction[4])
                   1834:                                        {
                   1835:                                            case '8': // sha38
                   1836:                                            {
                   1837:                                                switch(fonction[5])
                   1838:                                                {
                   1839:                                                    case '4': // sha384
                   1840:                                                    {
                   1841:                                                        if (fonction[6] ==
                   1842:                                                            d_code_fin_chaine)
                   1843:                                                        {
                   1844:                                                            EVP_sum =
1.42      bertrand 1845:                                                                EVP_sha384();
1.41      bertrand 1846:                                                        }
                   1847:                                                        else
                   1848:                                                        {
                   1849:                                                            somme_invalide =
                   1850:                                                                    d_vrai;
                   1851:                                                        }
                   1852: 
                   1853:                                                        break;
                   1854:                                                    }
                   1855: 
                   1856:                                                    default:
                   1857:                                                    {
                   1858:                                                        somme_invalide = d_vrai;
                   1859:                                                        break;
                   1860:                                                    }
                   1861:                                                }
                   1862: 
                   1863:                                                break;
                   1864:                                            }
                   1865: 
                   1866:                                            default:
                   1867:                                            {
                   1868:                                                somme_invalide = d_vrai;
                   1869:                                                break;
                   1870:                                            }
                   1871:                                        }
                   1872: 
                   1873:                                        break;
                   1874:                                    }
                   1875: 
                   1876:                                    case '5': // sha5
                   1877:                                    {
                   1878:                                        switch(fonction[4])
                   1879:                                        {
                   1880:                                            case '1': // sha51
                   1881:                                            {
                   1882:                                                switch(fonction[5])
                   1883:                                                {
                   1884:                                                    case '2': // sha512
                   1885:                                                    {
                   1886:                                                        if (fonction[6] ==
                   1887:                                                            d_code_fin_chaine)
                   1888:                                                        {
                   1889:                                                            EVP_sum =
1.42      bertrand 1890:                                                                EVP_sha512();
1.41      bertrand 1891:                                                        }
                   1892:                                                        else
                   1893:                                                        {
                   1894:                                                            somme_invalide =
                   1895:                                                                    d_vrai;
                   1896:                                                        }
                   1897: 
                   1898:                                                        break;
                   1899:                                                    }
                   1900: 
                   1901:                                                    default:
                   1902:                                                    {
                   1903:                                                        somme_invalide = d_vrai;
                   1904:                                                        break;
                   1905:                                                    }
                   1906:                                                }
                   1907: 
                   1908:                                                break;
                   1909:                                            }
                   1910: 
                   1911:                                            default:
                   1912:                                            {
                   1913:                                                somme_invalide = d_vrai;
                   1914:                                                break;
                   1915:                                            }
                   1916:                                        }
                   1917: 
                   1918:                                        break;
                   1919:                                    }
                   1920: #                                  endif
                   1921: 
                   1922:                                    default:
                   1923:                                    {
                   1924:                                        somme_invalide = d_vrai;
                   1925:                                        break;
                   1926:                                    }
                   1927:                                }
                   1928: 
                   1929:                                break;
                   1930:                            }
                   1931: #                          endif
                   1932: 
                   1933:                            default:
                   1934:                            {
                   1935:                                somme_invalide = d_vrai;
                   1936:                                break;
                   1937:                            }
                   1938:                        }
                   1939: 
                   1940:                        break;
                   1941:                    }
                   1942: 
                   1943:                    default:
                   1944:                    {
                   1945:                        somme_invalide = d_vrai;
                   1946:                        break;
                   1947:                    }
                   1948:                }
                   1949: 
                   1950:                break;
                   1951:            }
                   1952: 
                   1953: #          ifndef OPENSSL_NO_WHIRLPOOL
                   1954:            case 'W':
                   1955:            {
                   1956:                if (strcmp(fonction, "WHIRLPOOL") == 0)
                   1957:                {
1.42      bertrand 1958:                    EVP_sum = EVP_whirlpool();
1.41      bertrand 1959:                }
                   1960:                else
                   1961:                {
                   1962:                    somme_invalide = d_vrai;
                   1963:                }
                   1964: 
                   1965:                break;
                   1966:            }
                   1967: #          endif
                   1968: 
                   1969:            default:
                   1970:            {
                   1971:                somme_invalide = d_vrai;
                   1972:                break;
                   1973:            }
                   1974:        }
                   1975: 
                   1976:        if (somme_invalide == d_vrai)
                   1977:        {
                   1978:            // Le chiffrement est de type CBC-MAC
1.42      bertrand 1979: 
                   1980:            if (strncmp(fonction, "AES", 3) == 0)
                   1981:            {
                   1982: #              ifdef OPENSSL_NO_AES
1.43      bertrand 1983: 
1.42      bertrand 1984:                free(fonction);
                   1985: 
                   1986:                liberation(s_etat_processus, s_objet_argument_1);
                   1987:                liberation(s_etat_processus, s_objet_argument_2);
                   1988: 
                   1989:                (*s_etat_processus).erreur_execution =
                   1990:                        d_ex_chiffrement_indisponible;
1.43      bertrand 1991:                return;
                   1992: 
1.42      bertrand 1993: #              else
                   1994: 
                   1995:                if (strcmp(fonction, "AES-128-CBC") == 0)
                   1996:                {
                   1997:                    EVP_chiffrement = EVP_aes_128_cbc();
                   1998:                }
                   1999:                else if (strcmp(fonction, "AES-192-CBC") == 0)
                   2000:                {
                   2001:                    EVP_chiffrement = EVP_aes_192_cbc();
                   2002:                }
                   2003:                else if (strcmp(fonction, "AES-256-CBC") == 0)
                   2004:                {
                   2005:                    EVP_chiffrement = EVP_aes_256_cbc();
                   2006:                }
                   2007:                else
                   2008:                {
                   2009:                    free(fonction);
                   2010: 
                   2011:                    liberation(s_etat_processus, s_objet_argument_1);
                   2012:                    liberation(s_etat_processus, s_objet_argument_2);
                   2013: 
                   2014:                    (*s_etat_processus).erreur_execution =
                   2015:                            d_ex_chiffrement_indisponible;
                   2016:                    return;
                   2017:                }
                   2018: 
1.45      bertrand 2019:                longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
                   2020:                longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
                   2021: 
1.43      bertrand 2022: #              endif
                   2023:            }
                   2024:            else if (strncmp(fonction, "DES", 3) == 0)
                   2025:            {
                   2026: #              ifdef OPENSSL_NO_DES
                   2027: 
                   2028:                free(fonction);
                   2029: 
                   2030:                liberation(s_etat_processus, s_objet_argument_1);
                   2031:                liberation(s_etat_processus, s_objet_argument_2);
                   2032: 
                   2033:                (*s_etat_processus).erreur_execution =
                   2034:                        d_ex_chiffrement_indisponible;
                   2035:                return;
                   2036: 
                   2037: #              else
                   2038: 
                   2039:                if (strcmp(fonction, "DES-CBC") == 0)
                   2040:                {
                   2041:                    EVP_chiffrement = EVP_des_cbc();
                   2042:                }
                   2043:                else if (strcmp(fonction, "DES-EDE-CBC") == 0)
                   2044:                {
                   2045:                    EVP_chiffrement = EVP_des_ede_cbc();
                   2046:                }
                   2047:                else if (strcmp(fonction, "DES-EDE3-CBC") == 0)
                   2048:                {
                   2049:                    EVP_chiffrement = EVP_des_ede3_cbc();
                   2050:                }
                   2051:                else if (strcmp(fonction, "DESX-CBC") == 0)
                   2052:                {
                   2053:                    EVP_chiffrement = EVP_desx_cbc();
                   2054:                }
                   2055:                else
1.42      bertrand 2056:                {
                   2057:                    free(fonction);
                   2058: 
                   2059:                    liberation(s_etat_processus, s_objet_argument_1);
                   2060:                    liberation(s_etat_processus, s_objet_argument_2);
                   2061: 
1.43      bertrand 2062:                    (*s_etat_processus).erreur_execution =
                   2063:                            d_ex_chiffrement_indisponible;
1.42      bertrand 2064:                    return;
                   2065:                }
1.45      bertrand 2066: 
                   2067:                longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
                   2068:                longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
                   2069: 
1.43      bertrand 2070: #              endif
                   2071:            }
                   2072:            else if (strncmp(fonction, "CAMELLIA", 8) == 0)
                   2073:            {
                   2074: #              ifdef OPENSSL_NO_CAMELLIA
                   2075: 
                   2076:                free(fonction);
1.42      bertrand 2077: 
1.43      bertrand 2078:                liberation(s_etat_processus, s_objet_argument_1);
                   2079:                liberation(s_etat_processus, s_objet_argument_2);
1.42      bertrand 2080: 
1.43      bertrand 2081:                (*s_etat_processus).erreur_execution =
                   2082:                        d_ex_chiffrement_indisponible;
                   2083:                return;
                   2084: 
                   2085: #              else
                   2086: 
                   2087:                if (strcmp(fonction, "CAMELLIA-128-CBC") == 0)
                   2088:                {
                   2089:                    EVP_chiffrement = EVP_camellia_128_cbc();
                   2090:                }
                   2091:                else if (strcmp(fonction, "CAMELLIA-192-CBC") == 0)
                   2092:                {
                   2093:                    EVP_chiffrement = EVP_camellia_192_cbc();
                   2094:                }
                   2095:                else if (strcmp(fonction, "CAMELLIA-256-CBC") == 0)
                   2096:                {
                   2097:                    EVP_chiffrement = EVP_camellia_256_cbc();
                   2098:                }
                   2099:                else
1.42      bertrand 2100:                {
                   2101:                    free(fonction);
                   2102: 
                   2103:                    liberation(s_etat_processus, s_objet_argument_1);
                   2104:                    liberation(s_etat_processus, s_objet_argument_2);
1.43      bertrand 2105: 
                   2106:                    (*s_etat_processus).erreur_execution =
                   2107:                            d_ex_chiffrement_indisponible;
1.42      bertrand 2108:                    return;
                   2109:                }
1.45      bertrand 2110: 
                   2111:                longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
                   2112:                longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
                   2113: 
1.43      bertrand 2114: #              endif
                   2115:            }
                   2116:            else if (strncmp(fonction, "RC2", 3) == 0)
                   2117:            {
                   2118: #              ifdef OPENSSL_NO_RC2
1.42      bertrand 2119: 
1.43      bertrand 2120:                free(fonction);
                   2121: 
                   2122:                liberation(s_etat_processus, s_objet_argument_1);
                   2123:                liberation(s_etat_processus, s_objet_argument_2);
                   2124: 
                   2125:                (*s_etat_processus).erreur_execution =
                   2126:                        d_ex_chiffrement_indisponible;
                   2127:                return;
                   2128: 
                   2129: #              else
                   2130: 
                   2131:                if (strcmp(fonction, "RC2-CBC") == 0)
                   2132:                {
                   2133:                    EVP_chiffrement = EVP_rc2_cbc();
                   2134:                }
                   2135:                else if (strcmp(fonction, "RC2-40-CBC") == 0)
                   2136:                {
                   2137:                    EVP_chiffrement = EVP_rc2_40_cbc();
                   2138:                }
                   2139:                else if (strcmp(fonction, "RC2-64-CBC") == 0)
                   2140:                {
                   2141:                    EVP_chiffrement = EVP_rc2_64_cbc();
                   2142:                }
                   2143:                else
1.42      bertrand 2144:                {
                   2145:                    free(fonction);
                   2146: 
                   2147:                    liberation(s_etat_processus, s_objet_argument_1);
                   2148:                    liberation(s_etat_processus, s_objet_argument_2);
                   2149: 
                   2150:                    (*s_etat_processus).erreur_execution =
1.43      bertrand 2151:                            d_ex_chiffrement_indisponible;
1.42      bertrand 2152:                    return;
                   2153:                }
1.45      bertrand 2154: 
                   2155:                longueur_clef_attendue = 0;
                   2156:                longueur_clef_min = 1;
                   2157:                longueur_clef_max = 16;
                   2158:                longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
                   2159: 
1.43      bertrand 2160: #              endif
                   2161:            }
                   2162:            else if (strncmp(fonction, "IDEA", 4) == 0)
                   2163:            {
                   2164: #              ifdef OPENSSL_NO_IDEA
                   2165: 
                   2166:                free(fonction);
1.42      bertrand 2167: 
1.43      bertrand 2168:                liberation(s_etat_processus, s_objet_argument_1);
                   2169:                liberation(s_etat_processus, s_objet_argument_2);
                   2170: 
                   2171:                (*s_etat_processus).erreur_execution =
                   2172:                        d_ex_chiffrement_indisponible;
                   2173:                return;
                   2174: 
                   2175: #              else
                   2176: 
                   2177:                if (strcmp(fonction, "IDEA-CBC") == 0)
1.42      bertrand 2178:                {
1.43      bertrand 2179:                    EVP_chiffrement = EVP_idea_cbc();
1.42      bertrand 2180:                }
1.43      bertrand 2181:                else
1.42      bertrand 2182:                {
                   2183:                    free(fonction);
1.43      bertrand 2184: 
                   2185:                    liberation(s_etat_processus, s_objet_argument_1);
                   2186:                    liberation(s_etat_processus, s_objet_argument_2);
1.42      bertrand 2187: 
                   2188:                    (*s_etat_processus).erreur_execution =
1.43      bertrand 2189:                            d_ex_chiffrement_indisponible;
1.42      bertrand 2190:                    return;
                   2191:                }
1.45      bertrand 2192: 
                   2193:                longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
                   2194:                longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
                   2195: 
1.43      bertrand 2196: #              endif
                   2197:            }
                   2198:            else
                   2199:            {
                   2200:                free(fonction);
                   2201: 
                   2202:                liberation(s_etat_processus, s_objet_argument_1);
                   2203:                liberation(s_etat_processus, s_objet_argument_2);
                   2204: 
                   2205:                (*s_etat_processus).erreur_execution =
                   2206:                        d_ex_chiffrement_indisponible;
                   2207:                return;
                   2208:            }
                   2209: 
                   2210:            if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
                   2211:                    (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
                   2212:            {
                   2213:                free(fonction);
1.42      bertrand 2214: 
1.43      bertrand 2215:                liberation(s_etat_processus, s_objet_argument_1);
                   2216:                liberation(s_etat_processus, s_objet_argument_2);
                   2217: 
                   2218:                return;
                   2219:            }
                   2220: 
                   2221:            l_element_courant = (*s_objet_argument_1).objet;
                   2222:            l_element_courant = (*l_element_courant).suivant;
                   2223: 
                   2224:            if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
                   2225:                    (*(*l_element_courant).donnee).objet, &longueur_clef))
                   2226:                    == NULL)
                   2227:            {
                   2228:                free(fonction);
1.42      bertrand 2229:                free(chaine);
                   2230: 
1.43      bertrand 2231:                liberation(s_etat_processus, s_objet_argument_1);
                   2232:                liberation(s_etat_processus, s_objet_argument_2);
                   2233:                return;
                   2234:            }
                   2235: 
                   2236:            if (longueur_clef_attendue != 0)
                   2237:            {
                   2238:                if (longueur_clef != longueur_clef_attendue)
1.42      bertrand 2239:                {
1.43      bertrand 2240:                    free(fonction);
                   2241:                    free(chaine);
                   2242:                    free(clef);
                   2243: 
                   2244:                    liberation(s_etat_processus, s_objet_argument_1);
                   2245:                    liberation(s_etat_processus, s_objet_argument_2);
                   2246: 
                   2247:                    (*s_etat_processus).erreur_execution =
                   2248:                            d_ex_longueur_clef_chiffrement;
1.42      bertrand 2249:                    return;
                   2250:                }
1.43      bertrand 2251:            }
                   2252:            else
                   2253:            {
                   2254:                if ((longueur_clef < longueur_clef_min) &&
                   2255:                        (longueur_clef > longueur_clef_max))
1.42      bertrand 2256:                {
                   2257:                    free(fonction);
1.43      bertrand 2258:                    free(chaine);
                   2259:                    free(clef);
1.42      bertrand 2260: 
                   2261:                    liberation(s_etat_processus, s_objet_argument_1);
                   2262:                    liberation(s_etat_processus, s_objet_argument_2);
1.43      bertrand 2263: 
                   2264:                    (*s_etat_processus).erreur_execution =
                   2265:                            d_ex_longueur_clef_chiffrement;
1.42      bertrand 2266:                    return;
                   2267:                }
1.43      bertrand 2268:            }
                   2269: 
1.48      bertrand 2270:            if ((vecteur_initialisation = malloc(((size_t) longueur_clef) *
1.43      bertrand 2271:                    sizeof(unsigned char))) == NULL)
                   2272:            {
                   2273:                (*s_etat_processus).erreur_systeme =
                   2274:                        d_es_allocation_memoire;
                   2275:                return;
                   2276:            }
                   2277: 
1.48      bertrand 2278:            memset(vecteur_initialisation, 0, (size_t) longueur_clef);
1.42      bertrand 2279: 
1.43      bertrand 2280:            if ((tampon = chiffrement(EVP_chiffrement, d_vrai,
                   2281:                    chaine, longueur_chaine, clef, longueur_clef,
1.45      bertrand 2282:                    vecteur_initialisation, &longueur_tampon)) == NULL)
1.43      bertrand 2283:            {
                   2284:                free(fonction);
                   2285:                free(vecteur_initialisation);
                   2286:                free(chaine);
                   2287:                free(clef);
                   2288: 
                   2289:                (*s_etat_processus).erreur_execution =
                   2290:                        d_ex_chiffrement;
                   2291:                return;
                   2292:            }
                   2293: 
                   2294:            free(vecteur_initialisation);
                   2295:            free(chaine);
                   2296:            free(clef);
1.42      bertrand 2297: 
1.43      bertrand 2298:            if ((s_objet_resultat = allocation(s_etat_processus, CHN))
                   2299:                    == NULL)
                   2300:            {
                   2301:                (*s_etat_processus).erreur_systeme =
                   2302:                        d_es_allocation_memoire;
                   2303:                return;
1.42      bertrand 2304:            }
1.43      bertrand 2305: 
                   2306:            if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
                   2307:                    &(tampon[longueur_tampon - longueur_somme]),
                   2308:                    longueur_somme)) == NULL)
1.42      bertrand 2309:            {
1.43      bertrand 2310:                free(tampon);
1.42      bertrand 2311:                free(fonction);
                   2312: 
                   2313:                liberation(s_etat_processus, s_objet_argument_1);
                   2314:                liberation(s_etat_processus, s_objet_argument_2);
                   2315:                return;
                   2316:            }
                   2317: 
1.43      bertrand 2318:            free(tampon);
1.42      bertrand 2319:            free(fonction);
1.41      bertrand 2320:        }
                   2321:        else
                   2322:        {
                   2323:            // Le chiffrement est de type HMAC
                   2324:            // Le second élément de la chaîne contient la clef utilisée pour
                   2325:            // la signature.
                   2326: 
1.42      bertrand 2327:            free(fonction);
                   2328: 
1.41      bertrand 2329:            l_element_courant = (*s_objet_argument_1).objet;
                   2330:            l_element_courant = (*l_element_courant).suivant;
                   2331: 
1.45      bertrand 2332:            longueur_bloc = EVP_MD_block_size(EVP_sum);
                   2333: 
1.41      bertrand 2334:            if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
                   2335:                    (*(*l_element_courant).donnee).objet, &longueur_clef))
                   2336:                    == NULL)
                   2337:            {
                   2338:                liberation(s_etat_processus, s_objet_argument_1);
                   2339:                liberation(s_etat_processus, s_objet_argument_2);
                   2340:                return;
                   2341:            }
                   2342: 
                   2343:            if (longueur_clef < longueur_bloc)
                   2344:            {
                   2345:                longueur_tampon = longueur_clef;
                   2346:                tampon = clef;
                   2347: 
1.48      bertrand 2348:                if ((clef = malloc(((size_t) longueur_bloc) *
                   2349:                        sizeof(unsigned char))) == NULL)
1.41      bertrand 2350:                {
                   2351:                    (*s_etat_processus).erreur_systeme =
                   2352:                            d_es_allocation_memoire;
                   2353:                    return;
                   2354:                }
                   2355: 
1.48      bertrand 2356:                memset(clef, 0, (size_t) longueur_bloc);
                   2357:                memcpy(clef, tampon, (size_t) longueur_tampon);
1.41      bertrand 2358:                longueur_clef = longueur_bloc;
                   2359:                free(tampon);
                   2360:            }
                   2361:            else if (longueur_clef > longueur_bloc)
                   2362:            {
                   2363:                longueur_tampon = longueur_clef;
                   2364:                tampon = clef;
                   2365: 
1.48      bertrand 2366:                if ((clef = malloc(((size_t) longueur_bloc) *
                   2367:                        sizeof(unsigned char))) == NULL)
1.41      bertrand 2368:                {
                   2369:                    (*s_etat_processus).erreur_systeme =
                   2370:                            d_es_allocation_memoire;
                   2371:                    return;
                   2372:                }
                   2373: 
1.48      bertrand 2374:                memcpy(clef, tampon, (size_t) longueur_bloc);
1.41      bertrand 2375:                longueur_clef = longueur_bloc;
                   2376:                free(tampon);
                   2377:            }
                   2378: 
                   2379:            for(i = 0; i < longueur_bloc; i++)
                   2380:            {
1.48      bertrand 2381:                clef[i] ^= (unsigned char) 0x36;
1.41      bertrand 2382:            }
                   2383: 
                   2384:            if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
                   2385:                    (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
                   2386:            {
                   2387:                EVP_MD_CTX_cleanup(&contexte);
                   2388: 
                   2389:                liberation(s_etat_processus, s_objet_argument_1);
                   2390:                liberation(s_etat_processus, s_objet_argument_2);
                   2391: 
                   2392:                return;
                   2393:            }
                   2394: 
1.48      bertrand 2395:            if ((tampon = malloc(((size_t) (longueur_bloc + longueur_chaine)) *
1.41      bertrand 2396:                    sizeof(unsigned char))) == NULL)
                   2397:            {
                   2398:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2399:                return;
                   2400:            }
                   2401: 
1.48      bertrand 2402:            memcpy(tampon, clef, (size_t) longueur_bloc);
                   2403:            memcpy(tampon + longueur_bloc, chaine, (size_t) longueur_chaine);
1.41      bertrand 2404:            longueur_tampon = longueur_bloc + longueur_chaine;
                   2405: 
1.42      bertrand 2406:            if (EVP_DigestInit(&contexte, EVP_sum) != 1)
1.41      bertrand 2407:            {
                   2408:                free(tampon);
                   2409:                free(clef);
                   2410:                free(chaine);
                   2411: 
                   2412:                EVP_MD_CTX_cleanup(&contexte);
                   2413: 
                   2414:                liberation(s_etat_processus, s_objet_argument_1);
                   2415:                liberation(s_etat_processus, s_objet_argument_2);
                   2416: 
                   2417:                (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   2418:                return;
                   2419:            }
                   2420: 
1.48      bertrand 2421:            if (EVP_DigestUpdate(&contexte, tampon, (size_t) longueur_tampon)
                   2422:                    != 1)
1.41      bertrand 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: 
1.48      bertrand 2458:            if ((tampon = malloc(((size_t) (longueur_bloc + longueur_somme)) *
1.41      bertrand 2459:                    sizeof(unsigned char))) == NULL)
                   2460:            {
                   2461:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2462:                return;
                   2463:            }
                   2464: 
1.48      bertrand 2465:            memcpy(tampon, clef, (size_t) longueur_bloc);
                   2466:            memcpy(tampon + longueur_bloc, somme, (size_t) longueur_somme);
1.41      bertrand 2467:            longueur_tampon = longueur_bloc + longueur_somme;
                   2468: 
1.42      bertrand 2469:            if (EVP_DigestInit(&contexte, EVP_sum) != 1)
1.41      bertrand 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: 
1.48      bertrand 2484:            if (EVP_DigestUpdate(&contexte, tampon, (size_t) longueur_tampon)
                   2485:                    != 1)
1.41      bertrand 2486:            {
                   2487:                free(tampon);
                   2488:                free(clef);
                   2489:                free(chaine);
                   2490: 
                   2491:                EVP_MD_CTX_cleanup(&contexte);
                   2492: 
                   2493:                liberation(s_etat_processus, s_objet_argument_1);
                   2494:                liberation(s_etat_processus, s_objet_argument_2);
                   2495: 
                   2496:                (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   2497:                return;
                   2498:            }
                   2499: 
                   2500:            free(tampon);
                   2501: 
                   2502:            if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
                   2503:            {
                   2504:                free(chaine);
                   2505:                EVP_MD_CTX_cleanup(&contexte);
                   2506: 
                   2507:                liberation(s_etat_processus, s_objet_argument_1);
                   2508:                liberation(s_etat_processus, s_objet_argument_2);
                   2509: 
                   2510:                (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   2511:                return;
                   2512:            }
                   2513: 
                   2514:            EVP_MD_CTX_cleanup(&contexte);
                   2515: 
                   2516:            free(chaine);
                   2517:            free(clef);
                   2518: 
                   2519:            if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
                   2520:            {
                   2521:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2522:                return;
                   2523:            }
                   2524: 
                   2525:            if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
                   2526:                    somme, longueur_somme)) == NULL)
                   2527:            {
                   2528:                liberation(s_etat_processus, s_objet_argument_1);
                   2529:                liberation(s_etat_processus, s_objet_argument_2);
                   2530: 
                   2531:                return;
                   2532:            }
                   2533:        }
1.39      bertrand 2534:    }
                   2535:    else
                   2536:    {
                   2537:        liberation(s_etat_processus, s_objet_argument_1);
                   2538:        liberation(s_etat_processus, s_objet_argument_2);
                   2539: 
                   2540:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                   2541:        return;
                   2542:    }
                   2543: 
                   2544:    liberation(s_etat_processus, s_objet_argument_1);
                   2545:    liberation(s_etat_processus, s_objet_argument_2);
                   2546: 
                   2547:    if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   2548:            s_objet_resultat) == d_erreur)
                   2549:    {
                   2550:        return;
                   2551:    }
                   2552: 
                   2553:    return;
                   2554: }
                   2555: 
1.1       bertrand 2556: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>