Annotation of rpl/src/instructions_c8.c, revision 1.34

1.1       bertrand    1: /*
                      2: ================================================================================
1.33      bertrand    3:   RPL/2 (R) version 4.1.32
1.34    ! bertrand    4:   Copyright (C) 1989-2020 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: 
                     23: #include "rpl-conv.h"
                     24: 
                     25: 
                     26: /*
                     27: ================================================================================
                     28:   Fonction 'cipher'
                     29: ================================================================================
                     30:   Entrées :
                     31: --------------------------------------------------------------------------------
                     32:   Sorties :
                     33: --------------------------------------------------------------------------------
                     34:   Effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: void
                     39: instruction_cipher(struct_processus *s_etat_processus)
                     40: {
                     41:    const EVP_CIPHER                *EVP_chiffrement;
                     42:    const EVP_MD                    *EVP_sum;
                     43: 
1.3       bertrand   44:    int                             longueur_clef;
                     45: 
1.7       bertrand   46:    integer8                        longueur_clef_binaire;
                     47:    integer8                        longueur_iv_binaire;
                     48:    integer8                        longueur_message;
                     49:    integer8                        longueur_message_chiffre;
1.1       bertrand   50:    integer8                        nombre_cycles;
                     51: 
1.3       bertrand   52:    logical1                        encodage;
                     53:    logical1                        generation_clef;
1.1       bertrand   54:    logical1                        somme_invalide;
                     55: 
                     56:    logical8                        sel;
                     57: 
                     58:    struct_liste_chainee            *l_element_courant;
                     59: 
                     60:    struct_objet                    *s_objet_argument_1;
                     61:    struct_objet                    *s_objet_argument_2;
                     62:    struct_objet                    *s_objet_resultat_1;
                     63:    struct_objet                    *s_objet_resultat_2;
                     64: 
1.3       bertrand   65:    unsigned char                   *algorithme_chiffrement;
1.1       bertrand   66:    unsigned char                   *clef;
1.3       bertrand   67:    unsigned char                   *clef_binaire;
1.1       bertrand   68:    unsigned char                   *controle;
                     69:    unsigned char                   *direction;
                     70:    unsigned char                   *fonction;
                     71:    unsigned char                   *instruction;
                     72:    unsigned char                   *iv;
1.3       bertrand   73:    unsigned char                   *iv_binaire;
                     74:    unsigned char                   *message;
                     75:    unsigned char                   *message_chiffre;
1.1       bertrand   76:    unsigned char                   *tampon;
                     77: 
                     78:    if ((*s_etat_processus).affichage_arguments == 'Y')
                     79:    {
                     80:        printf("\n  CIPHER ");
                     81: 
                     82:        if ((*s_etat_processus).langue == 'F')
                     83:        {
                     84:            printf("(opérations de chiffrement)\n\n");
                     85:        }
                     86:        else
                     87:        {
                     88:            printf("(cryptographic operations)\n\n");
                     89:        }
                     90: 
1.3       bertrand   91:        printf("    2: \"password\"\n", d_CHN);
                     92:        printf("    1: { \"KEY\" \"cipher type\" \"digest type\" "
                     93:                "salt nround }\n");
                     94:        printf("->  1: { \"cipher type\" \"generated key\" \"iv\" }\n\n");
1.1       bertrand   95: 
1.3       bertrand   96:        printf("    2: \"text\"\n", d_CHN);
1.14      bertrand   97:        printf("    1: { \"direction\" \"cipher type\" \"key\" \"iv\" }\n");
1.3       bertrand   98:        printf("->  2: \"encrypted or decrypted text\"\n", d_CHN);
                     99:        printf("    1: { \"direction\" \"cipher type\" \"key\" "
1.1       bertrand  100:                "\"updated iv\" }\n\n", d_LST);
                    101: 
                    102:        if ((*s_etat_processus).langue == 'F')
                    103:        {
1.3       bertrand  104:            printf("  Algorithmes de chiffrement :\n\n");
                    105:        }
                    106:        else
                    107:        {
                    108:            printf("  Chipher algorithms:\n\n");
                    109:        }
                    110: 
                    111: #      ifndef OPENSSL_NO_AES
                    112:        printf("    - AES-128-CBC\n");
                    113:        printf("    - AES-128-CCM\n");
                    114:        printf("    - AES-128-CFB1\n");
                    115:        printf("    - AES-128-CFB8\n");
                    116:        printf("    - AES-128-CFB128\n");
                    117:        printf("    - AES-128-CTR\n");
                    118:        printf("    - AES-128-ECB\n");
                    119:        printf("    - AES-128-GCM\n");
                    120:        printf("    - AES-128-OFB\n");
                    121:        printf("    - AES-128-XTS\n");
                    122:        printf("    - AES-192-CBC\n");
                    123:        printf("    - AES-192-CCM\n");
                    124:        printf("    - AES-192-CFB1\n");
                    125:        printf("    - AES-192-CFB8\n");
                    126:        printf("    - AES-192-CFB128\n");
                    127:        printf("    - AES-192-CTR\n");
                    128:        printf("    - AES-192-ECB\n");
                    129:        printf("    - AES-192-GCM\n");
                    130:        printf("    - AES-192-OFB\n");
                    131:        printf("    - AES-256-CBC\n");
                    132:        printf("    - AES-256-CCM\n");
                    133:        printf("    - AES-256-CFB1\n");
                    134:        printf("    - AES-256-CFB8\n");
                    135:        printf("    - AES-256-CFB128\n");
                    136:        printf("    - AES-256-CTR\n");
                    137:        printf("    - AES-256-ECB\n");
                    138:        printf("    - AES-256-GCM\n");
                    139:        printf("    - AES-256-OFB\n");
                    140:        printf("    - AES-256-XTS\n");
                    141: #      endif
                    142: 
                    143: #      ifndef OPENSSL_NO_BF
                    144:        printf("    - BF-CBC\n");
                    145:        printf("    - BF-CFB64\n");
                    146:        printf("    - BF-ECB\n");
                    147:        printf("    - BF-OFB\n");
                    148: #      endif
                    149: 
                    150: #      ifndef OPENSSL_NO_CAMELLIA
                    151:        printf("    - CAMELLIA-128-CBC\n");
                    152:        printf("    - CAMELLIA-128-CFB1\n");
                    153:        printf("    - CAMELLIA-128-CFB8\n");
                    154:        printf("    - CAMELLIA-128-CFB128\n");
                    155:        printf("    - CAMELLIA-128-ECB\n");
                    156:        printf("    - CAMELLIA-128-OFB\n");
                    157:        printf("    - CAMELLIA-192-CBC\n");
                    158:        printf("    - CAMELLIA-192-CFB1\n");
                    159:        printf("    - CAMELLIA-192-CFB8\n");
                    160:        printf("    - CAMELLIA-192-CFB128\n");
                    161:        printf("    - CAMELLIA-192-ECB\n");
                    162:        printf("    - CAMELLIA-192-OFB\n");
                    163:        printf("    - CAMELLIA-256-CBC\n");
                    164:        printf("    - CAMELLIA-256-CFB1\n");
                    165:        printf("    - CAMELLIA-256-CFB8\n");
                    166:        printf("    - CAMELLIA-256-CFB128\n");
                    167:        printf("    - CAMELLIA-256-ECB\n");
                    168:        printf("    - CAMELLIA-256-OFB\n");
                    169: #      endif
                    170: 
                    171: #      ifndef OPENSSL_NO_CAST
                    172:        printf("    - CAST5-CBC\n");
                    173:        printf("    - CAST5-ECB\n");
                    174:        printf("    - CAST5-CFB64\n");
                    175:        printf("    - CAST5-OFB\n");
                    176: #      endif
                    177: 
                    178: #      ifndef OPENSSL_NO_DES
                    179:        printf("    - DES-CBC\n");
                    180:        printf("    - DES-CFB1\n");
                    181:        printf("    - DES-CFB8\n");
                    182:        printf("    - DES-CFB64\n");
                    183:        printf("    - DES-ECB\n");
                    184:        printf("    - DES-EDE\n");
                    185:        printf("    - DES-EDE-CBC\n");
                    186:        printf("    - DES-EDE-CFB1\n");
                    187:        printf("    - DES-EDE-CFB8\n");
                    188:        printf("    - DES-EDE-CFB64\n");
                    189:        printf("    - DES-EDE-ECB\n");
                    190:        printf("    - DES-EDE-OFB\n");
                    191:        printf("    - DES-EDE3\n");
                    192:        printf("    - DES-EDE3-CBC\n");
                    193:        printf("    - DES-EDE3-ECB\n");
                    194:        printf("    - DES-EDE3-OFB\n");
                    195:        printf("    - DES-OFB\n");
                    196:        printf("    - DESX-CBC\n");
                    197: #      endif
                    198: 
                    199: #      ifndef OPENSSL_NO_IDEA
                    200:        printf("    - IDEA-CBC\n");
                    201:        printf("    - IDEA-CFB64\n");
                    202:        printf("    - IDEA-ECB\n");
                    203:        printf("    - IDEA-OFB\n");
                    204: #      endif
                    205: 
                    206: #      ifndef OPENSSL_NO_RC2
                    207:        printf("    - RC2-CBC\n");
                    208:        printf("    - RC2-CFB64\n");
                    209:        printf("    - RC2-ECB\n");
                    210:        printf("    - RC2-OFB\n");
                    211:        printf("    - RC2-40-CBC\n");
                    212:        printf("    - RC2-64-CBC\n");
                    213: #      endif
                    214: 
                    215: #      ifndef OPENSSL_NO_RC4
                    216:        printf("    - RC4\n");
                    217:        printf("    - RC4-40\n");
                    218: #      endif
                    219: 
                    220: #      ifndef OPENSSL_NO_RC5
                    221:        printf("    - RC5-32-12-16-CBC\n");
                    222:        printf("    - RC5-32-12-16-CFB64\n");
                    223:        printf("    - RC5-32-12-16-ECB\n");
                    224:        printf("    - RC5-32-12-16-OFB\n");
                    225: #      endif
                    226: 
                    227: #      ifndef OPENSSL_NO_SEED
                    228:        printf("    - SEED-CBC\n");
                    229:        printf("    - SEED-CFB128\n");
                    230:        printf("    - SEED-ECB\n");
                    231:        printf("    - SEED-OFB\n");
                    232: #      endif
                    233: 
                    234:        printf("\n");
                    235: 
                    236:        if ((*s_etat_processus).langue == 'F')
                    237:        {
1.1       bertrand  238:            printf("  Algorithmes de signature :\n\n");
                    239:        }
                    240:        else
                    241:        {
                    242:            printf("  Digest algorithms:\n\n");
                    243:        }
                    244: 
                    245: #      ifndef OPENSSL_NO_MD2
                    246:        printf("    - MD2\n");
                    247: #      endif
                    248: #      ifndef OPENSSL_NO_MD4
                    249:        printf("    - MD4\n");
                    250: #      endif
                    251: #      ifndef OPENSSL_NO_MD5
                    252:        printf("    - MD5\n");
                    253: #      endif
                    254: #      ifndef OPENSSL_NO_MDC2
                    255:        printf("    - MDC2\n");
                    256: #      endif
                    257: #      ifndef OPENSSL_NO_RIPEMD
                    258:        printf("    - RIPEMD160\n");
                    259: #      endif
                    260:        printf("    - SHA1\n");
                    261:        printf("    - SHA224\n");
                    262:        printf("    - SHA256\n");
                    263:        printf("    - SHA384\n");
                    264:        printf("    - SHA512\n");
                    265: #      ifndef OPENSSL_NO_WHIRLPOOL
                    266:        printf("    - WHIRLPOOL\n");
                    267: #      endif
                    268: 
                    269:        printf("\n");
                    270: 
                    271:        if ((*s_etat_processus).langue == 'F')
                    272:        {
                    273:            printf("  Utilisation :\n\n");
                    274:        }
                    275:        else
                    276:        {
                    277:            printf("  Usage:\n\n");
                    278:        }
                    279: 
1.4       bertrand  280:        printf("    \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" "
1.3       bertrand  281:                "# 0h 3 } CIPHER\n");
                    282:        printf("    \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" "
1.1       bertrand  283:                "\"iv\" } CIPHER\n");
1.3       bertrand  284:        printf("    \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" "
1.1       bertrand  285:                "\"iv\" } CIPHER\n");
                    286:        return;
                    287:    }
                    288:    else if ((*s_etat_processus).test_instruction == 'Y')
                    289:    {
                    290:        (*s_etat_processus).nombre_arguments = -1;
                    291:        return;
                    292:    }
                    293: 
                    294:    if (test_cfsf(s_etat_processus, 31) == d_vrai)
                    295:    {
                    296:        if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
                    297:        {
                    298:            return;
                    299:        }
                    300:    }
                    301: 
                    302:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    303:            &s_objet_argument_1) == d_erreur)
                    304:    {
                    305:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    306:        return;
                    307:    }
                    308: 
                    309:    if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    310:            &s_objet_argument_2) == d_erreur)
                    311:    {
                    312:        liberation(s_etat_processus, s_objet_argument_1);
                    313: 
                    314:        (*s_etat_processus).erreur_execution = d_ex_manque_argument;
                    315:        return;
                    316:    }
                    317: 
                    318:    if (((*s_objet_argument_1).type == LST) &&
                    319:            ((*s_objet_argument_2).type == CHN))
                    320:    {
                    321:        l_element_courant = (*s_objet_argument_1).objet;
                    322: 
                    323:        if (l_element_courant == NULL)
                    324:        {
                    325:            liberation(s_etat_processus, s_objet_argument_1);
                    326:            liberation(s_etat_processus, s_objet_argument_2);
                    327: 
                    328:            (*s_etat_processus).erreur_execution = d_ex_argument_invalide; 
                    329:            return;
                    330:        }
                    331: 
                    332:        if ((*(*l_element_courant).donnee).type != CHN)
                    333:        {
                    334:            liberation(s_etat_processus, s_objet_argument_1);
                    335:            liberation(s_etat_processus, s_objet_argument_2);
                    336: 
                    337:            (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    338:            return;
                    339:        }
                    340: 
1.18      bertrand  341:        if ((instruction = conversion_majuscule(s_etat_processus,
                    342:                (unsigned char *) (*(*l_element_courant).donnee).objet))
                    343:                == NULL)
1.1       bertrand  344:        {
                    345:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    346:            return;
                    347:        }
                    348: 
                    349:        if (strcmp(instruction, "KEY") == 0)
                    350:        {
                    351:            // Dérivation d'une clef
                    352: 
                    353:            free(instruction);
                    354: 
                    355:            l_element_courant = (*l_element_courant).suivant;
                    356: 
                    357:            if (l_element_courant == NULL)
                    358:            {
                    359:                liberation(s_etat_processus, s_objet_argument_1);
                    360:                liberation(s_etat_processus, s_objet_argument_2);
                    361: 
                    362:                (*s_etat_processus).erreur_execution = d_ex_manque_argument; 
                    363:                return;
                    364:            }
                    365: 
                    366:            // On attend l'algorithme de chiffrement.
                    367: 
                    368:            if ((*(*l_element_courant).donnee).type != CHN)
                    369:            {
                    370:                liberation(s_etat_processus, s_objet_argument_1);
                    371:                liberation(s_etat_processus, s_objet_argument_2);
                    372: 
                    373:                (*s_etat_processus).erreur_execution =
                    374:                        d_ex_erreur_type_argument;
                    375:                return;
                    376:            }
                    377: 
1.3       bertrand  378:            algorithme_chiffrement = (unsigned char *) (*(*l_element_courant)
1.1       bertrand  379:                    .donnee).objet;
                    380: 
                    381:            if ((l_element_courant = (*l_element_courant).suivant) == NULL)
                    382:            {
                    383:                liberation(s_etat_processus, s_objet_argument_1);
                    384:                liberation(s_etat_processus, s_objet_argument_2);
                    385: 
                    386:                (*s_etat_processus).erreur_execution = d_ex_manque_argument; 
                    387:                return;
                    388:            }   
                    389: 
                    390:            // On attend la somme de contrôle.
                    391: 
                    392:            if ((*(*l_element_courant).donnee).type != CHN)
                    393:            {
                    394:                liberation(s_etat_processus, s_objet_argument_1);
                    395:                liberation(s_etat_processus, s_objet_argument_2);
                    396: 
                    397:                (*s_etat_processus).erreur_execution =
                    398:                        d_ex_erreur_type_argument;
                    399:                return;
                    400:            }
                    401: 
                    402:            controle = (unsigned char *) (*(*l_element_courant).donnee).objet;
                    403: 
                    404:            // Test de la validité de la somme de contrôle.
                    405: 
1.18      bertrand  406:            if ((fonction = conversion_majuscule(s_etat_processus, controle))
                    407:                    == NULL)
1.1       bertrand  408:            {
                    409:                (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    410:                return;
                    411:            }
                    412: 
                    413:            somme_invalide = d_faux;
                    414: 
                    415:            switch(fonction[0])
                    416:            {
                    417:                case 'M':
                    418:                {
                    419:                    switch(fonction[1])
                    420:                    {
                    421:                        case 'D': // md
                    422:                        {
                    423:                            switch(fonction[2])
                    424:                            {
                    425: #                              ifndef OPENSSL_NO_MD2
                    426:                                case '2': // md2
                    427:                                {
                    428:                                    if (fonction[3] == d_code_fin_chaine)
                    429:                                    {
                    430:                                        EVP_sum = EVP_md2();
                    431:                                    }
                    432:                                    else
                    433:                                    {
                    434:                                        somme_invalide = d_vrai;
                    435:                                    }
                    436: 
                    437:                                    break;
                    438:                                }
                    439: #                              endif
                    440: 
                    441: #                              ifndef OPENSSL_NO_MD4
                    442:                                case '4': // md4
                    443:                                {
                    444:                                    if (fonction[3] == d_code_fin_chaine)
                    445:                                    {
                    446:                                        EVP_sum = EVP_md4();
                    447:                                    }
                    448:                                    else
                    449:                                    {
                    450:                                        somme_invalide = d_vrai;
                    451:                                    }
                    452: 
                    453:                                    break;
                    454:                                }
                    455: #                              endif
                    456: 
                    457: #                              ifndef OPENSSL_NO_MD5
                    458:                                case '5': // md5
                    459:                                {
                    460:                                    if (fonction[3] == d_code_fin_chaine)
                    461:                                    {
                    462:                                        EVP_sum = EVP_md5();
                    463:                                    }
                    464:                                    else
                    465:                                    {
                    466:                                        somme_invalide = d_vrai;
                    467:                                    }
                    468: 
                    469:                                    break;
                    470:                                }
                    471: #                              endif
                    472: 
                    473:                                case 'C': // mdc
                    474:                                {
                    475:                                    switch(fonction[3])
                    476:                                    {
                    477: #                                      ifndef OPENSSL_NO_MDC2
                    478:                                        case '2': // mdc2
                    479:                                        {
                    480:                                            if (fonction[4] ==
                    481:                                                    d_code_fin_chaine)
                    482:                                            {
                    483:                                                EVP_sum = EVP_mdc2();
                    484:                                            }
                    485:                                            else
                    486:                                            {
                    487:                                                somme_invalide = d_vrai;
                    488:                                            }
                    489: 
                    490:                                            break;
                    491:                                        }
                    492: #                                      endif
                    493: 
                    494:                                        default:
                    495:                                        {
                    496:                                            somme_invalide = d_vrai;
                    497:                                            break;
                    498:                                        }
                    499:                                    }
                    500: 
                    501:                                    break;
                    502:                                }
                    503: 
                    504:                                default:
                    505:                                {
                    506:                                    somme_invalide = d_vrai;
                    507:                                    break;
                    508:                                }
                    509:                            }
                    510: 
                    511:                            break;
                    512:                        }
                    513: 
                    514:                        default:
                    515:                        {
                    516:                            somme_invalide = d_vrai;
                    517:                            break;
                    518:                        }
                    519:                    }
                    520: 
                    521:                    break;
                    522:                }
                    523: 
                    524: #              ifndef OPENSSL_NO_RIPEMD
                    525:                case 'R':
                    526:                {
                    527:                    if (strcmp(fonction, "RIPEMD160") == 0)
                    528:                    {
                    529:                        EVP_sum = EVP_ripemd160();
                    530:                    }
                    531:                    else
                    532:                    {
                    533:                        somme_invalide = d_vrai;
                    534:                    }
                    535: 
                    536:                    break;
                    537:                }
                    538: #              endif
                    539: 
                    540:                case 'S':
                    541:                {
                    542:                    switch(fonction[1])
                    543:                    {
                    544:                        case 'H': // sh
                    545:                        {
                    546:                            switch(fonction[2])
                    547:                            {
                    548:                                case 'A':
                    549:                                {
                    550:                                    switch(fonction[3])
                    551:                                    {
                    552:                                        case '1': // sha1
                    553:                                        {
                    554:                                            if (fonction[4] ==
                    555:                                                    d_code_fin_chaine)
                    556:                                            {
                    557:                                                EVP_sum = EVP_sha1();
                    558:                                            }
                    559:                                            else
                    560:                                            {
                    561:                                                somme_invalide = d_vrai;
                    562:                                            }
                    563: 
                    564:                                            break;
                    565:                                        }
                    566: 
                    567:                                        case '2': // sha2
                    568:                                        {
                    569:                                            switch(fonction[4])
                    570:                                            {
                    571:                                                case '2': // sha22
                    572:                                                {
                    573:                                                    switch(fonction[5])
                    574:                                                    {
                    575:                                                        case '4': // sha224
                    576:                                                        {
                    577:                                                            if (fonction[6] ==
                    578:                                                            d_code_fin_chaine)
                    579:                                                            {
                    580:                                                                EVP_sum =
                    581:                                                                EVP_sha224();
                    582:                                                            }
                    583:                                                            else
                    584:                                                            {
                    585:                                                                somme_invalide =
                    586:                                                                        d_vrai;
                    587:                                                            }
                    588: 
                    589:                                                            break;
                    590:                                                        }
                    591: 
                    592:                                                        default:
                    593:                                                        {
                    594:                                                            somme_invalide =
                    595:                                                                    d_vrai;
                    596:                                                            break;
                    597:                                                        }
                    598:                                                    }
                    599: 
                    600:                                                    break;
                    601:                                                }
                    602: 
                    603:                                                case '5':
                    604:                                                {
                    605:                                                    switch(fonction[5])
                    606:                                                    {
                    607:                                                        case '6': // sha256
                    608:                                                        {
                    609:                                                            if (fonction[6] ==
                    610:                                                            d_code_fin_chaine)
                    611:                                                            {
                    612:                                                                EVP_sum =
                    613:                                                                EVP_sha256();
                    614:                                                            }
                    615:                                                            else
                    616:                                                            {
                    617:                                                                somme_invalide =
                    618:                                                                        d_vrai;
                    619:                                                            }
                    620: 
                    621:                                                            break;
                    622:                                                        }
                    623: 
                    624:                                                        default:
                    625:                                                        {
                    626:                                                            somme_invalide =
                    627:                                                                    d_vrai;
                    628:                                                            break;
                    629:                                                        }
                    630:                                                    }
                    631: 
                    632:                                                    break;
                    633:                                                }
                    634: 
                    635:                                                default:
                    636:                                                {
                    637:                                                    somme_invalide = d_vrai;
                    638:                                                    break;
                    639:                                                }
                    640:                                            }
                    641: 
                    642:                                            break;
                    643:                                        }
                    644: 
                    645:                                        case '3': // sha3
                    646:                                        {
                    647:                                            switch(fonction[4])
                    648:                                            {
                    649:                                                case '8': // sha38
                    650:                                                {
                    651:                                                    switch(fonction[5])
                    652:                                                    {
                    653:                                                        case '4': // sha384
                    654:                                                        {
                    655:                                                            if (fonction[6] ==
                    656:                                                            d_code_fin_chaine)
                    657:                                                            {
                    658:                                                                EVP_sum =
                    659:                                                                EVP_sha384();
                    660:                                                            }
                    661:                                                            else
                    662:                                                            {
                    663:                                                                somme_invalide =
                    664:                                                                        d_vrai;
                    665:                                                            }
                    666: 
                    667:                                                            break;
                    668:                                                        }
                    669: 
                    670:                                                        default:
                    671:                                                        {
                    672:                                                            somme_invalide =
                    673:                                                                    d_vrai;
                    674:                                                            break;
                    675:                                                        }
                    676:                                                    }
                    677: 
                    678:                                                    break;
                    679:                                                }
                    680: 
                    681:                                                default:
                    682:                                                {
                    683:                                                    somme_invalide = d_vrai;
                    684:                                                    break;
                    685:                                                }
                    686:                                            }
                    687: 
                    688:                                            break;
                    689:                                        }
                    690: 
                    691:                                        case '5': // sha5
                    692:                                        {
                    693:                                            switch(fonction[4])
                    694:                                            {
                    695:                                                case '1': // sha51
                    696:                                                {
                    697:                                                    switch(fonction[5])
                    698:                                                    {
                    699:                                                        case '2': // sha512
                    700:                                                        {
                    701:                                                            if (fonction[6] ==
                    702:                                                            d_code_fin_chaine)
                    703:                                                            {
                    704:                                                                EVP_sum =
                    705:                                                                EVP_sha512();
                    706:                                                            }
                    707:                                                            else
                    708:                                                            {
                    709:                                                                somme_invalide =
                    710:                                                                        d_vrai;
                    711:                                                            }
                    712: 
                    713:                                                            break;
                    714:                                                        }
                    715: 
                    716:                                                        default:
                    717:                                                        {
                    718:                                                            somme_invalide =
                    719:                                                                    d_vrai;
                    720:                                                            break;
                    721:                                                        }
                    722:                                                    }
                    723: 
                    724:                                                    break;
                    725:                                                }
                    726: 
                    727:                                                default:
                    728:                                                {
                    729:                                                    somme_invalide = d_vrai;
                    730:                                                    break;
                    731:                                                }
                    732:                                            }
                    733: 
                    734:                                            break;
                    735:                                        }
                    736: 
                    737:                                        default:
                    738:                                        {
                    739:                                            somme_invalide = d_vrai;
                    740:                                            break;
                    741:                                        }
                    742:                                    }
                    743: 
                    744:                                    break;
                    745:                                }
                    746: 
                    747:                                default:
                    748:                                {
                    749:                                    somme_invalide = d_vrai;
                    750:                                    break;
                    751:                                }
                    752:                            }
                    753: 
                    754:                            break;
                    755:                        }
                    756: 
                    757:                        default:
                    758:                        {
                    759:                            somme_invalide = d_vrai;
                    760:                            break;
                    761:                        }
                    762:                    }
                    763: 
                    764:                    break;
                    765:                }
                    766: 
                    767: #              ifndef OPENSSL_NO_WHIRLPOOL
                    768:                case 'W':
                    769:                {
                    770:                    if (strcmp(fonction, "WHIRLPOOL") == 0)
                    771:                    {
                    772:                        EVP_sum = EVP_whirlpool();
                    773:                    }
                    774:                    else
                    775:                    {
                    776:                        somme_invalide = d_vrai;
                    777:                    }
                    778: 
                    779:                    break;
                    780:                }
                    781: #              endif
                    782: 
                    783:                default:
                    784:                {
                    785:                    somme_invalide = d_vrai;
                    786:                    break;
                    787:                }
                    788:            }
                    789: 
                    790:            free(fonction);
                    791: 
                    792:            if (somme_invalide == d_vrai)
                    793:            {
                    794:                liberation(s_etat_processus, s_objet_argument_1);
                    795:                liberation(s_etat_processus, s_objet_argument_2);
                    796: 
                    797:                (*s_etat_processus).erreur_execution =
                    798:                        d_ex_chiffrement_indisponible;
                    799:                return;
                    800:            }
                    801: 
1.3       bertrand  802:            if ((l_element_courant = (*l_element_courant).suivant) == NULL)
                    803:            {
                    804:                liberation(s_etat_processus, s_objet_argument_1);
                    805:                liberation(s_etat_processus, s_objet_argument_2);
                    806: 
                    807:                (*s_etat_processus).erreur_execution = d_ex_manque_argument; 
                    808:                return;
                    809:            }   
                    810: 
                    811:            // On attend le sel, donc un entier binaire de 64 bits.
                    812: 
                    813:            if ((*(*l_element_courant).donnee).type != BIN)
                    814:            {
                    815:                liberation(s_etat_processus, s_objet_argument_1);
                    816:                liberation(s_etat_processus, s_objet_argument_2);
                    817: 
                    818:                (*s_etat_processus).erreur_execution =
                    819:                        d_ex_erreur_type_argument;
                    820:                return;
                    821:            }
                    822: 
                    823:            sel = (*((logical8 *) (*(*l_element_courant).donnee).objet));
                    824: 
                    825:            if ((l_element_courant = (*l_element_courant).suivant) == NULL)
                    826:            {
                    827:                liberation(s_etat_processus, s_objet_argument_1);
                    828:                liberation(s_etat_processus, s_objet_argument_2);
                    829: 
                    830:                (*s_etat_processus).erreur_execution = d_ex_manque_argument; 
                    831:                return;
                    832:            }   
                    833: 
                    834:            // On attend le nombre de cycles.
                    835: 
                    836:            if ((*(*l_element_courant).donnee).type != INT)
                    837:            {
                    838:                liberation(s_etat_processus, s_objet_argument_1);
                    839:                liberation(s_etat_processus, s_objet_argument_2);
                    840: 
                    841:                (*s_etat_processus).erreur_execution =
                    842:                        d_ex_erreur_type_argument;
                    843:                return;
                    844:            }
                    845: 
                    846:            nombre_cycles = (*((integer8 *) (*(*l_element_courant)
                    847:                    .donnee).objet));
                    848: 
                    849:            // On a dû atteindre la fin de la liste.
                    850: 
                    851:            if ((*l_element_courant).suivant != NULL)
                    852:            {
                    853:                liberation(s_etat_processus, s_objet_argument_1);
                    854:                liberation(s_etat_processus, s_objet_argument_2);
                    855: 
                    856:                (*s_etat_processus).erreur_execution = d_ex_argument_invalide; 
                    857:                return;
                    858:            }
                    859: 
                    860:            clef = NULL;
                    861:            iv = NULL;
                    862: 
1.1       bertrand  863:            generation_clef = d_vrai;
                    864:        }
                    865:        else
                    866:        {
                    867:            // Chiffrement ou déchiffrement d'un message
                    868: 
1.3       bertrand  869:            direction = instruction;
1.1       bertrand  870: 
                    871:            l_element_courant = (*l_element_courant).suivant;
                    872: 
                    873:            if (l_element_courant == NULL)
                    874:            {
                    875:                liberation(s_etat_processus, s_objet_argument_1);
                    876:                liberation(s_etat_processus, s_objet_argument_2);
                    877: 
                    878:                (*s_etat_processus).erreur_execution = d_ex_manque_argument; 
                    879:                return;
                    880:            }
                    881: 
1.3       bertrand  882:            // On attend le type de chiffrement.
1.1       bertrand  883: 
                    884:            if ((*(*l_element_courant).donnee).type != CHN)
                    885:            {
                    886:                liberation(s_etat_processus, s_objet_argument_1);
                    887:                liberation(s_etat_processus, s_objet_argument_2);
                    888: 
                    889:                (*s_etat_processus).erreur_execution =
                    890:                        d_ex_erreur_type_argument;
                    891:                return;
                    892:            }
                    893: 
1.3       bertrand  894:            algorithme_chiffrement = (unsigned char *) (*(*l_element_courant)
1.1       bertrand  895:                    .donnee).objet;
                    896: 
                    897:            // On attend la clef.
                    898: 
                    899:            if ((l_element_courant = (*l_element_courant).suivant) == NULL)
                    900:            {
                    901:                liberation(s_etat_processus, s_objet_argument_1);
                    902:                liberation(s_etat_processus, s_objet_argument_2);
                    903: 
                    904:                (*s_etat_processus).erreur_execution =
                    905:                        d_ex_manque_argument;
                    906:                return;
                    907:            }
                    908: 
                    909:            clef = (unsigned char *) (*(*l_element_courant).donnee).objet;
                    910: 
                    911:            // On attend le vecteur d'initialisation.
                    912: 
                    913:            if ((l_element_courant = (*l_element_courant).suivant) == NULL)
                    914:            {
                    915:                liberation(s_etat_processus, s_objet_argument_1);
                    916:                liberation(s_etat_processus, s_objet_argument_2);
                    917: 
                    918:                (*s_etat_processus).erreur_execution =
                    919:                        d_ex_manque_argument;
                    920:                return;
                    921:            }
                    922: 
                    923:            iv = (unsigned char *) (*(*l_element_courant).donnee).objet;
                    924: 
                    925:            if ((*l_element_courant).suivant != NULL)
                    926:            {
                    927:                liberation(s_etat_processus, s_objet_argument_1);
                    928:                liberation(s_etat_processus, s_objet_argument_2);
                    929: 
                    930:                (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
                    931:                return;
                    932:            }
1.3       bertrand  933: 
                    934:            generation_clef = d_faux;
1.1       bertrand  935:        }
                    936:    }
                    937:    else
                    938:    {
                    939:        liberation(s_etat_processus, s_objet_argument_1);
                    940:        liberation(s_etat_processus, s_objet_argument_2);
                    941: 
                    942:        (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
                    943:        return;
                    944:    }
                    945: 
1.18      bertrand  946:    if ((tampon = conversion_majuscule(s_etat_processus,
                    947:            algorithme_chiffrement)) == NULL)
1.1       bertrand  948:    {
                    949:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                    950:        return;
                    951:    }
                    952: 
1.3       bertrand  953: #  define TEST_CIPHER(string, value) \
                    954:            if (strcmp(tampon, string) == 0) EVP_chiffrement = value();
                    955: 
                    956:    if (strncmp(tampon, "DES", 3) == 0)
                    957:    {
                    958: #      ifndef OPENSSL_NO_DES
                    959:            TEST_CIPHER("DES-ECB", EVP_des_ecb)
                    960:            else TEST_CIPHER("DES-EDE", EVP_des_ede)
                    961:            else TEST_CIPHER("DES-EDE3", EVP_des_ede3)
                    962:            else TEST_CIPHER("DES-EDE-ECB", EVP_des_ede_ecb)
                    963:            else TEST_CIPHER("DES-EDE3-ECB", EVP_des_ede3_ecb)
                    964:            else TEST_CIPHER("DES-CFB64", EVP_des_cfb64)
                    965:            else TEST_CIPHER("DES-CFB1", EVP_des_cfb1)
                    966:            else TEST_CIPHER("DES-CFB8", EVP_des_cfb8)
                    967:            else TEST_CIPHER("DES-EDE-CFB64", EVP_des_ede_cfb64)
                    968:            else TEST_CIPHER("DES-EDE3-CFB64", EVP_des_ede3_cfb64)
                    969:            else TEST_CIPHER("DES-EDE3-CFB1", EVP_des_ede3_cfb1)
                    970:            else TEST_CIPHER("DES-EDE3-CFB8", EVP_des_ede3_cfb8)
                    971:            else TEST_CIPHER("DES-OFB", EVP_des_ofb)
                    972:            else TEST_CIPHER("DES-EDE-OFB", EVP_des_ede_ofb)
                    973:            else TEST_CIPHER("DES-EDE3-OFB", EVP_des_ede3_ofb)
                    974:            else TEST_CIPHER("DES-CBC", EVP_des_cbc)
                    975:            else TEST_CIPHER("DES-EDE-CBC", EVP_des_ede_cbc)
                    976:            else TEST_CIPHER("DES-EDE3-CBC", EVP_des_ede3_cbc)
                    977:            else TEST_CIPHER("DESX-CBC", EVP_desx_cbc)
                    978:            else
                    979:            {
                    980:                free(tampon);
                    981: 
                    982:                liberation(s_etat_processus, s_objet_argument_1);
                    983:                liberation(s_etat_processus, s_objet_argument_2);
                    984: 
                    985:                (*s_etat_processus).erreur_execution =
                    986:                        d_ex_chiffrement_indisponible;
                    987:                return;
                    988:            }
                    989: #      else
                    990:            free(tampon);
                    991: 
                    992:            liberation(s_etat_processus, s_objet_argument_1);
                    993:            liberation(s_etat_processus, s_objet_argument_2);
                    994: 
                    995:            (*s_etat_processus).erreur_execution =
                    996:                    d_ex_chiffrement_indisponible;
                    997:            return;
                    998: #      endif
                    999:    }
                   1000:    else if (strncmp(tampon, "RC4", 3) == 0)
                   1001:    {
                   1002: #      ifndef OPENSSL_NO_RC4
                   1003:            TEST_CIPHER("RC4", EVP_rc4)
                   1004:            else TEST_CIPHER("RC4-40", EVP_rc4_40)
                   1005:            else
                   1006:            {
                   1007:                free(tampon);
                   1008: 
                   1009:                liberation(s_etat_processus, s_objet_argument_1);
                   1010:                liberation(s_etat_processus, s_objet_argument_2);
                   1011: 
                   1012:                (*s_etat_processus).erreur_execution =
                   1013:                        d_ex_chiffrement_indisponible;
                   1014:                return;
                   1015:            }
                   1016: #      else
                   1017:            free(tampon);
                   1018: 
                   1019:            liberation(s_etat_processus, s_objet_argument_1);
                   1020:            liberation(s_etat_processus, s_objet_argument_2);
                   1021: 
                   1022:            (*s_etat_processus).erreur_execution =
                   1023:                    d_ex_chiffrement_indisponible;
                   1024:            return;
                   1025: #      endif
                   1026:    }
                   1027:    else if (strncmp(tampon, "IDEA", 4) == 0)
                   1028:    {
                   1029: #      ifndef OPENSSL_NO_IDEA
                   1030:            TEST_CIPHER("IDEA-ECB", EVP_idea_ecb)
                   1031:            else TEST_CIPHER("IDEA-CFB64", EVP_idea_cfb64)
                   1032:            else TEST_CIPHER("IDEA-OFB", EVP_idea_ofb)
                   1033:            else TEST_CIPHER("IDEA-CBC", EVP_idea_cbc)
                   1034:            else
                   1035:            {
                   1036:                free(tampon);
                   1037: 
                   1038:                liberation(s_etat_processus, s_objet_argument_1);
                   1039:                liberation(s_etat_processus, s_objet_argument_2);
                   1040: 
                   1041:                (*s_etat_processus).erreur_execution =
                   1042:                        d_ex_chiffrement_indisponible;
                   1043:                return;
                   1044:            }
                   1045: #      else
                   1046:            free(tampon);
                   1047: 
                   1048:            liberation(s_etat_processus, s_objet_argument_1);
                   1049:            liberation(s_etat_processus, s_objet_argument_2);
                   1050: 
                   1051:            (*s_etat_processus).erreur_execution =
                   1052:                    d_ex_chiffrement_indisponible;
                   1053:            return;
                   1054: #      endif
                   1055:    }
                   1056:    else if (strncmp(tampon, "RC2", 3) == 0)
1.1       bertrand 1057:    {
1.3       bertrand 1058: #      ifndef OPENSSL_NO_RC2
                   1059:            TEST_CIPHER("RC2-ECB", EVP_rc2_ecb)
                   1060:            else TEST_CIPHER("RC2-CBC", EVP_rc2_cbc)
                   1061:            else TEST_CIPHER("RC2-40-CBC", EVP_rc2_40_cbc)
                   1062:            else TEST_CIPHER("RC2-64-CBC", EVP_rc2_64_cbc)
                   1063:            else TEST_CIPHER("RC2-CFB64", EVP_rc2_cfb64)
                   1064:            else TEST_CIPHER("RC2-OFB", EVP_rc2_ofb)
                   1065:            else
                   1066:            {
                   1067:                free(tampon);
                   1068: 
                   1069:                liberation(s_etat_processus, s_objet_argument_1);
                   1070:                liberation(s_etat_processus, s_objet_argument_2);
                   1071: 
                   1072:                (*s_etat_processus).erreur_execution =
                   1073:                        d_ex_chiffrement_indisponible;
                   1074:                return;
                   1075:            }
                   1076: #      else
                   1077:            free(tampon);
                   1078: 
                   1079:            liberation(s_etat_processus, s_objet_argument_1);
                   1080:            liberation(s_etat_processus, s_objet_argument_2);
                   1081: 
                   1082:            (*s_etat_processus).erreur_execution =
                   1083:                    d_ex_chiffrement_indisponible;
                   1084:            return;
                   1085: #      endif
1.1       bertrand 1086:    }
1.3       bertrand 1087:    else if (strncmp(tampon, "BF", 2) == 0)
                   1088:    {
                   1089: #      ifndef OPENSSL_NO_BF
                   1090:            TEST_CIPHER("BF-ECB", EVP_bf_ecb)
                   1091:            else TEST_CIPHER("BF-CBC", EVP_bf_cbc)
                   1092:            else TEST_CIPHER("BF-CFB64", EVP_bf_cfb64)
                   1093:            else TEST_CIPHER("BF-OFB", EVP_bf_ofb)
                   1094:            else
                   1095:            {
                   1096:                free(tampon);
                   1097: 
                   1098:                liberation(s_etat_processus, s_objet_argument_1);
                   1099:                liberation(s_etat_processus, s_objet_argument_2);
                   1100: 
                   1101:                (*s_etat_processus).erreur_execution =
                   1102:                        d_ex_chiffrement_indisponible;
                   1103:                return;
                   1104:            }
                   1105: #      else
                   1106:            free(tampon);
1.1       bertrand 1107: 
1.3       bertrand 1108:            liberation(s_etat_processus, s_objet_argument_1);
                   1109:            liberation(s_etat_processus, s_objet_argument_2);
1.1       bertrand 1110: 
1.3       bertrand 1111:            (*s_etat_processus).erreur_execution =
                   1112:                    d_ex_chiffrement_indisponible;
                   1113:            return;
                   1114: #      endif
                   1115:    }
                   1116:    else if (strncmp(tampon, "CAST5", 5) == 0)
1.1       bertrand 1117:    {
1.3       bertrand 1118: #      ifndef OPENSSL_NO_CAST
                   1119:            TEST_CIPHER("CAST5-ECB", EVP_cast5_ecb)
                   1120:            else TEST_CIPHER("CAST5-CBC", EVP_cast5_cbc)
                   1121:            else TEST_CIPHER("CAST5-CFB64", EVP_cast5_cfb64)
                   1122:            else TEST_CIPHER("CAST5-OFB", EVP_cast5_ofb)
                   1123:            else
                   1124:            {
                   1125:                free(tampon);
                   1126: 
                   1127:                liberation(s_etat_processus, s_objet_argument_1);
                   1128:                liberation(s_etat_processus, s_objet_argument_2);
                   1129: 
                   1130:                (*s_etat_processus).erreur_execution =
                   1131:                        d_ex_chiffrement_indisponible;
                   1132:                return;
                   1133:            }
                   1134: #      else
                   1135:            free(tampon);
                   1136: 
                   1137:            liberation(s_etat_processus, s_objet_argument_1);
                   1138:            liberation(s_etat_processus, s_objet_argument_2);
                   1139: 
                   1140:            (*s_etat_processus).erreur_execution =
                   1141:                    d_ex_chiffrement_indisponible;
                   1142:            return;
                   1143: #      endif
1.1       bertrand 1144:    }
1.3       bertrand 1145:    else if (strncmp(tampon, "RC5", 3) == 0)
1.1       bertrand 1146:    {
1.3       bertrand 1147: #      ifndef OPENSSL_NO_RC5
                   1148:            TEST_CIPHER("RC5-32-12-16-ECB", EVP_rc5_32_12_16_ebc)
                   1149:            else TEST_CIPHER("RC5-32-12-16-CBC", EVP_rc5_32_12_16_cbc)
                   1150:            else TEST_CIPHER("RC5-32-12-16-CFB64", EVP_rc5_32_12_16_cfb64)
                   1151:            else TEST_CIPHER("RC5-32-12-16-OFB", EVP_rc5_32_12_16_ofb)
                   1152:            else
                   1153:            {
                   1154:                free(tampon);
                   1155: 
                   1156:                liberation(s_etat_processus, s_objet_argument_1);
                   1157:                liberation(s_etat_processus, s_objet_argument_2);
                   1158: 
                   1159:                (*s_etat_processus).erreur_execution =
                   1160:                        d_ex_chiffrement_indisponible;
                   1161:                return;
                   1162:            }
                   1163: #      else
                   1164:            free(tampon);
                   1165: 
                   1166:            liberation(s_etat_processus, s_objet_argument_1);
                   1167:            liberation(s_etat_processus, s_objet_argument_2);
                   1168: 
                   1169:            (*s_etat_processus).erreur_execution =
                   1170:                    d_ex_chiffrement_indisponible;
                   1171:            return;
                   1172: #      endif
                   1173:    }
                   1174:    else if (strncmp(tampon, "AES", 3) == 0)
                   1175:    {
                   1176: #      ifndef OPENSSL_NO_AES
                   1177:            TEST_CIPHER("AES-128-ECB", EVP_aes_128_ecb)
                   1178:            else TEST_CIPHER("AES-128-CBC", EVP_aes_128_cbc)
                   1179:            else TEST_CIPHER("AES-128-CFB1", EVP_aes_128_cfb1)
                   1180:            else TEST_CIPHER("AES-128-CFB8", EVP_aes_128_cfb8)
                   1181:            else TEST_CIPHER("AES-128-CFB128", EVP_aes_128_cfb128)
                   1182:            else TEST_CIPHER("AES-128-OFB", EVP_aes_128_ofb)
                   1183:            else TEST_CIPHER("AES-128-CTR", EVP_aes_128_ctr)
                   1184:            else TEST_CIPHER("AES-128-CCM", EVP_aes_128_ccm)
                   1185:            else TEST_CIPHER("AES-128-GCM", EVP_aes_128_gcm)
                   1186:            else TEST_CIPHER("AES-128-XTS", EVP_aes_128_xts)
                   1187:            else TEST_CIPHER("AES-192-ECB", EVP_aes_192_ecb)
                   1188:            else TEST_CIPHER("AES-192-CBC", EVP_aes_192_cbc)
                   1189:            else TEST_CIPHER("AES-192-CFB1", EVP_aes_192_cfb1)
                   1190:            else TEST_CIPHER("AES-192-CFB8", EVP_aes_192_cfb8)
                   1191:            else TEST_CIPHER("AES-192-CFB128", EVP_aes_192_cfb128)
                   1192:            else TEST_CIPHER("AES-192-OFB", EVP_aes_192_ofb)
                   1193:            else TEST_CIPHER("AES-192-CTR", EVP_aes_192_ctr)
                   1194:            else TEST_CIPHER("AES-192-CCM", EVP_aes_192_ccm)
                   1195:            else TEST_CIPHER("AES-192-GCM", EVP_aes_192_gcm)
                   1196:            else TEST_CIPHER("AES-256-ECB", EVP_aes_256_ecb)
                   1197:            else TEST_CIPHER("AES-256-CBC", EVP_aes_256_cbc)
                   1198:            else TEST_CIPHER("AES-256-CFB1", EVP_aes_256_cfb1)
                   1199:            else TEST_CIPHER("AES-256-CFB8", EVP_aes_256_cfb8)
                   1200:            else TEST_CIPHER("AES-256-CFB128", EVP_aes_256_cfb128)
                   1201:            else TEST_CIPHER("AES-256-OFB", EVP_aes_256_ofb)
                   1202:            else TEST_CIPHER("AES-256-CTR", EVP_aes_256_ctr)
                   1203:            else TEST_CIPHER("AES-256-CCM", EVP_aes_256_ccm)
                   1204:            else TEST_CIPHER("AES-256-GCM", EVP_aes_256_gcm)
                   1205:            else TEST_CIPHER("AES-256-XTS", EVP_aes_256_xts)
                   1206:            else
                   1207:            {
                   1208:                free(tampon);
                   1209: 
                   1210:                liberation(s_etat_processus, s_objet_argument_1);
                   1211:                liberation(s_etat_processus, s_objet_argument_2);
                   1212: 
                   1213:                (*s_etat_processus).erreur_execution =
                   1214:                        d_ex_chiffrement_indisponible;
                   1215:                return;
                   1216:            }
                   1217: #      else
                   1218:            free(tampon);
                   1219: 
                   1220:            liberation(s_etat_processus, s_objet_argument_1);
                   1221:            liberation(s_etat_processus, s_objet_argument_2);
                   1222: 
                   1223:            (*s_etat_processus).erreur_execution =
                   1224:                    d_ex_chiffrement_indisponible;
                   1225:            return;
                   1226: #      endif
                   1227:    }
                   1228:    else if (strncmp(tampon, "CAMELLIA", 8) == 0)
                   1229:    {
                   1230: #      ifndef OPENSSL_NO_CAMELLIA
                   1231:            TEST_CIPHER("CAMELLIA-128-ECB", EVP_camellia_128_ecb)
                   1232:            else TEST_CIPHER("CAMELLIA-128-CBC", EVP_camellia_128_cbc)
                   1233:            else TEST_CIPHER("CAMELLIA-128-CFB1", EVP_camellia_128_cfb1)
                   1234:            else TEST_CIPHER("CAMELLIA-128-CFB8", EVP_camellia_128_cfb8)
                   1235:            else TEST_CIPHER("CAMELLIA-128-CFB128", EVP_camellia_128_cfb128)
                   1236:            else TEST_CIPHER("CAMELLIA-128-OFB", EVP_camellia_128_ofb)
                   1237:            else TEST_CIPHER("CAMELLIA-192-ECB", EVP_camellia_128_ecb)
                   1238:            else TEST_CIPHER("CAMELLIA-192-CBC", EVP_camellia_192_cbc)
                   1239:            else TEST_CIPHER("CAMELLIA-192-CFB1", EVP_camellia_192_cfb1)
                   1240:            else TEST_CIPHER("CAMELLIA-192-CFB8", EVP_camellia_192_cfb8)
                   1241:            else TEST_CIPHER("CAMELLIA-192-CFB128", EVP_camellia_192_cfb128)
                   1242:            else TEST_CIPHER("CAMELLIA-192-OFB", EVP_camellia_192_ofb)
                   1243:            else TEST_CIPHER("CAMELLIA-256-ECB", EVP_camellia_256_ecb)
                   1244:            else TEST_CIPHER("CAMELLIA-256-CBC", EVP_camellia_256_cbc)
                   1245:            else TEST_CIPHER("CAMELLIA-256-CFB1", EVP_camellia_256_cfb1)
                   1246:            else TEST_CIPHER("CAMELLIA-256-CFB8", EVP_camellia_256_cfb8)
                   1247:            else TEST_CIPHER("CAMELLIA-256-CFB128", EVP_camellia_256_cfb128)
                   1248:            else TEST_CIPHER("CAMELLIA-256-OFB", EVP_camellia_256_ofb)
                   1249:            else
                   1250:            {
                   1251:                free(tampon);
                   1252: 
                   1253:                liberation(s_etat_processus, s_objet_argument_1);
                   1254:                liberation(s_etat_processus, s_objet_argument_2);
                   1255: 
                   1256:                (*s_etat_processus).erreur_execution =
                   1257:                        d_ex_chiffrement_indisponible;
                   1258:                return;
                   1259:            }
                   1260: #      else
                   1261:            free(tampon);
                   1262: 
                   1263:            liberation(s_etat_processus, s_objet_argument_1);
                   1264:            liberation(s_etat_processus, s_objet_argument_2);
                   1265: 
                   1266:            (*s_etat_processus).erreur_execution =
                   1267:                    d_ex_chiffrement_indisponible;
                   1268:            return;
                   1269: #      endif
                   1270:    }
                   1271:    else if (strncmp(tampon, "SEED", 4) == 0)
                   1272:    {
                   1273: #      ifndef OPENSSL_NO_SEED
                   1274:            TEST_CIPHER("SEED-ECB", EVP_seed_ecb)
                   1275:            else TEST_CIPHER("SEED-CBC", EVP_seed_cbc)
                   1276:            else TEST_CIPHER("SEED-CFB128", EVP_seed_cfb128)
                   1277:            else TEST_CIPHER("SEED-OFB", EVP_seed_ofb)
                   1278:            else
                   1279:            {
                   1280:                free(tampon);
                   1281: 
                   1282:                liberation(s_etat_processus, s_objet_argument_1);
                   1283:                liberation(s_etat_processus, s_objet_argument_2);
                   1284: 
                   1285:                (*s_etat_processus).erreur_execution =
                   1286:                        d_ex_chiffrement_indisponible;
                   1287:                return;
                   1288:            }
                   1289: #      else
                   1290:            free(tampon);
                   1291: 
                   1292:            liberation(s_etat_processus, s_objet_argument_1);
                   1293:            liberation(s_etat_processus, s_objet_argument_2);
                   1294: 
                   1295:            (*s_etat_processus).erreur_execution =
                   1296:                    d_ex_chiffrement_indisponible;
                   1297:            return;
                   1298: #      endif
                   1299:    }
                   1300:    else
                   1301:    {
                   1302:        free(tampon);
                   1303: 
                   1304:        liberation(s_etat_processus, s_objet_argument_1);
                   1305:        liberation(s_etat_processus, s_objet_argument_2);
                   1306: 
                   1307:        (*s_etat_processus).erreur_execution = d_ex_chiffrement_indisponible;
                   1308:        return;
                   1309:    }
                   1310: 
                   1311:    free(tampon);
                   1312: 
                   1313:    if (generation_clef == d_vrai)
                   1314:    {
1.7       bertrand 1315:        if ((iv = malloc(((size_t) EVP_CIPHER_iv_length(EVP_chiffrement))
1.3       bertrand 1316:                * sizeof(unsigned char))) == NULL)
                   1317:        {
                   1318:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1319:            return;
                   1320:        }
                   1321: 
1.7       bertrand 1322:        if ((clef = malloc(((size_t) EVP_CIPHER_key_length(EVP_chiffrement))
1.3       bertrand 1323:                * sizeof(unsigned char))) == NULL)
                   1324:        {
                   1325:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1326:            return;
                   1327:        }
                   1328: 
                   1329:        longueur_clef = EVP_BytesToKey(EVP_chiffrement, EVP_sum,
                   1330:                (unsigned char *) &sel, (unsigned char *)
1.7       bertrand 1331:                (*s_objet_argument_2).objet,
                   1332:                (int) longueur_chaine(s_etat_processus,
1.3       bertrand 1333:                (unsigned char *) (*s_objet_argument_2).objet),
1.7       bertrand 1334:                (int) nombre_cycles, clef, iv);
1.3       bertrand 1335: 
                   1336:        if (longueur_clef != EVP_CIPHER_key_length(EVP_chiffrement))
                   1337:        {
                   1338:            free(iv);
                   1339:            free(clef);
                   1340: 
                   1341:            liberation(s_etat_processus, s_objet_argument_1);
                   1342:            liberation(s_etat_processus, s_objet_argument_2);
                   1343: 
                   1344:            (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   1345:            return;
                   1346:        }
                   1347: 
                   1348:        if ((s_objet_resultat_1 = allocation(s_etat_processus, LST)) == NULL)
                   1349:        {
                   1350:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1351:            return;
                   1352:        }
                   1353: 
                   1354:        if (((*s_objet_resultat_1).objet = allocation_maillon(s_etat_processus))
                   1355:                == NULL)
                   1356:        {
                   1357:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1358:            return;
                   1359:        }
                   1360: 
                   1361:        l_element_courant = (*s_objet_resultat_1).objet;
                   1362: 
                   1363:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1364:                == NULL)
                   1365:        {
                   1366:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1367:            return;
                   1368:        }
                   1369: 
                   1370:        if (((*(*l_element_courant).donnee).objet = malloc(
                   1371:                (strlen(algorithme_chiffrement) + 1) * sizeof(unsigned char)))
                   1372:                == NULL)
                   1373:        {
                   1374:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1375:            return;
                   1376:        }
                   1377: 
                   1378:        strcpy((*(*l_element_courant).donnee).objet, algorithme_chiffrement);
                   1379: 
                   1380:        if (((*l_element_courant).suivant = allocation_maillon(
                   1381:                s_etat_processus)) == NULL)
                   1382:        {
                   1383:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1384:            return;
                   1385:        }
                   1386: 
                   1387:        l_element_courant = (*l_element_courant).suivant;
                   1388: 
                   1389:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1390:                == NULL)
                   1391:        {
                   1392:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1393:            return;
                   1394:        }
                   1395: 
                   1396:        if (((*(*l_element_courant).donnee).objet = analyse_flux(
                   1397:                s_etat_processus, clef,
                   1398:                EVP_CIPHER_key_length(EVP_chiffrement))) == NULL)
                   1399:        {
                   1400:            return;
                   1401:        }
                   1402: 
                   1403:        free(clef);
                   1404: 
                   1405:        if (((*l_element_courant).suivant = allocation_maillon(
                   1406:                s_etat_processus)) == NULL)
                   1407:        {
                   1408:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1409:            return;
                   1410:        }
                   1411: 
                   1412:        l_element_courant = (*l_element_courant).suivant;
                   1413:        (*l_element_courant).suivant = NULL;
                   1414: 
                   1415:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1416:                == NULL)
                   1417:        {
                   1418:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1419:            return;
                   1420:        }
                   1421: 
                   1422:        if (((*(*l_element_courant).donnee).objet = analyse_flux(
                   1423:                s_etat_processus, iv,
                   1424:                EVP_CIPHER_iv_length(EVP_chiffrement))) == NULL)
                   1425:        {
                   1426:            return;
                   1427:        }
                   1428: 
                   1429:        free(iv);
                   1430: 
                   1431:        liberation(s_etat_processus, s_objet_argument_1);
                   1432:        liberation(s_etat_processus, s_objet_argument_2);
                   1433: 
                   1434:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1435:                s_objet_resultat_1) == d_erreur)
                   1436:        {
                   1437:            return;
                   1438:        }
                   1439:    }
                   1440:    else
                   1441:    {
                   1442:        // Chiffrement ou déchiffrement
                   1443: 
                   1444:        if (strcmp(direction, "ENCRYPT") == 0)
                   1445:        {
                   1446:            encodage = d_vrai;
                   1447:        }
                   1448:        else if (strcmp(direction, "DECRYPT") == 0)
                   1449:        {
                   1450:            encodage = d_faux;
                   1451:        }
                   1452:        else
                   1453:        {
                   1454:            free(direction);
                   1455:            liberation(s_etat_processus, s_objet_argument_1);
                   1456:            liberation(s_etat_processus, s_objet_argument_2);
                   1457: 
                   1458:            (*s_etat_processus).erreur_execution =
                   1459:                    d_ex_argument_invalide;
                   1460:            return;
                   1461:        }
                   1462: 
                   1463:        free(direction);
                   1464: 
                   1465:        // Conversion des clefs
                   1466: 
                   1467:        if ((clef_binaire = formateur_flux(s_etat_processus, clef,
                   1468:                &longueur_clef_binaire)) == NULL)
                   1469:        {
                   1470:            return;
                   1471:        }
                   1472: 
                   1473:        if ((iv_binaire = formateur_flux(s_etat_processus, iv,
                   1474:                &longueur_iv_binaire)) == NULL)
                   1475:        {
                   1476:            return;
                   1477:        }
                   1478: 
                   1479:        // Vérification de la longueur des clef et vecteur d'initialisation
                   1480: 
                   1481:        if (longueur_clef_binaire != EVP_CIPHER_key_length(EVP_chiffrement))
                   1482:        {
                   1483:            free(clef_binaire);
                   1484:            free(iv_binaire);
                   1485: 
                   1486:            liberation(s_etat_processus, s_objet_argument_1);
                   1487:            liberation(s_etat_processus, s_objet_argument_2);
                   1488: 
                   1489:            (*s_etat_processus).erreur_execution =
                   1490:                    d_ex_longueur_clef_chiffrement;
                   1491:            return;
                   1492:        }
                   1493: 
                   1494:        if (longueur_iv_binaire != EVP_CIPHER_iv_length(EVP_chiffrement))
                   1495:        {
                   1496:            free(clef_binaire);
                   1497:            free(iv_binaire);
                   1498: 
                   1499:            liberation(s_etat_processus, s_objet_argument_1);
                   1500:            liberation(s_etat_processus, s_objet_argument_2);
                   1501: 
                   1502:            (*s_etat_processus).erreur_execution =
                   1503:                    d_ex_longueur_clef_chiffrement;
                   1504:            return;
                   1505:        }
                   1506: 
                   1507:        if ((message = formateur_flux(s_etat_processus, (unsigned char *)
                   1508:                (*s_objet_argument_2).objet, &longueur_message)) == NULL)
                   1509:        {
                   1510:            return;
                   1511:        }
                   1512: 
1.18      bertrand 1513:        if ((message_chiffre = chiffrement(s_etat_processus,
                   1514:                EVP_chiffrement, encodage, message,
1.3       bertrand 1515:                longueur_message, clef_binaire, longueur_clef_binaire,
                   1516:                iv_binaire, &longueur_message_chiffre)) == NULL)
                   1517:        {
                   1518:            free(clef_binaire);
                   1519:            free(iv_binaire);
                   1520:            free(message);
                   1521: 
                   1522:            liberation(s_etat_processus, s_objet_argument_1);
                   1523:            liberation(s_etat_processus, s_objet_argument_2);
                   1524: 
                   1525:            (*s_etat_processus).erreur_execution = d_ex_chiffrement;
                   1526:            return;
                   1527:        }
                   1528: 
                   1529:        free(clef_binaire);
                   1530:        free(message);
                   1531: 
                   1532:        if ((s_objet_resultat_2 = allocation(s_etat_processus, CHN)) == NULL)
                   1533:        {
                   1534:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1535:            return;
                   1536:        }
                   1537: 
                   1538:        if (((*s_objet_resultat_2).objet = analyse_flux(s_etat_processus,
                   1539:                message_chiffre, longueur_message_chiffre)) == NULL)
                   1540:        {
                   1541:            return;
                   1542:        }
                   1543: 
                   1544:        free(message_chiffre);
                   1545: 
                   1546:        if ((s_objet_resultat_1 = allocation(s_etat_processus, LST)) == NULL)
                   1547:        {
                   1548:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1549:            return;
                   1550:        }
                   1551: 
                   1552:        if (((*s_objet_resultat_1).objet = allocation_maillon(s_etat_processus))
                   1553:                == NULL)
                   1554:        {
                   1555:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1556:            return;
                   1557:        }
                   1558: 
                   1559:        l_element_courant = (*s_objet_resultat_1).objet;
                   1560: 
                   1561:        // Direction
                   1562: 
                   1563:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1564:                == NULL)
                   1565:        {
                   1566:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1567:            return;
                   1568:        }
                   1569: 
                   1570:        if (((*(*l_element_courant).donnee).objet =
                   1571:                malloc(8 * sizeof(unsigned char))) == NULL)
                   1572:        {
                   1573:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1574:            return;
                   1575:        }
                   1576: 
                   1577:        strcpy((*(*l_element_courant).donnee).objet,
                   1578:                (encodage == d_vrai) ? "ENCRYPT" : "DECRYPT");
                   1579: 
                   1580:        // Type de chiffrement
                   1581: 
                   1582:        if (((*l_element_courant).suivant = allocation_maillon(
                   1583:                s_etat_processus)) == NULL)
                   1584:        {
                   1585:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1586:            return;
                   1587:        }
                   1588: 
                   1589:        l_element_courant = (*l_element_courant).suivant;
                   1590: 
                   1591:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1592:                == NULL)
                   1593:        {
                   1594:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1595:            return;
                   1596:        }
                   1597: 
1.5       bertrand 1598:        if (((*(*l_element_courant).donnee).objet =
1.18      bertrand 1599:                conversion_majuscule(s_etat_processus, algorithme_chiffrement))
                   1600:                == NULL)
1.3       bertrand 1601:        {
                   1602:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1603:            return;
                   1604:        }
                   1605: 
                   1606:        // Clef
                   1607: 
                   1608:        if (((*l_element_courant).suivant = allocation_maillon(
                   1609:                s_etat_processus)) == NULL)
                   1610:        {
                   1611:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1612:            return;
                   1613:        }
                   1614: 
                   1615:        l_element_courant = (*l_element_courant).suivant;
                   1616: 
                   1617:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1618:                == NULL)
                   1619:        {
                   1620:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1621:            return;
                   1622:        }
                   1623: 
                   1624:        if (((*(*l_element_courant).donnee).objet =
                   1625:                malloc((strlen(clef) + 1) * sizeof(unsigned char))) == NULL)
                   1626:        {
                   1627:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1628:            return;
                   1629:        }
                   1630: 
                   1631:        strcpy((*(*l_element_courant).donnee).objet, clef);
                   1632: 
                   1633:        // Vecteur d'initialisation
                   1634: 
                   1635:        if (((*l_element_courant).suivant = allocation_maillon(
                   1636:                s_etat_processus)) == NULL)
                   1637:        {
                   1638:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1639:            return;
                   1640:        }
                   1641: 
                   1642:        l_element_courant = (*l_element_courant).suivant;
                   1643:        (*l_element_courant).suivant = NULL;
                   1644: 
                   1645:        if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
                   1646:                == NULL)
                   1647:        {
                   1648:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1649:            return;
                   1650:        }
                   1651: 
                   1652:        if (((*(*l_element_courant).donnee).objet = analyse_flux(
                   1653:                s_etat_processus, iv_binaire, longueur_iv_binaire)) == NULL)
                   1654:        {
                   1655:            return;
                   1656:        }
                   1657:        
                   1658:        free(iv_binaire);
                   1659: 
                   1660:        liberation(s_etat_processus, s_objet_argument_1);
                   1661:        liberation(s_etat_processus, s_objet_argument_2);
                   1662: 
                   1663:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1664:                s_objet_resultat_2) == d_erreur)
                   1665:        {
                   1666:            return;
                   1667:        }
                   1668: 
                   1669:        if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                   1670:                s_objet_resultat_1) == d_erreur)
                   1671:        {
                   1672:            return;
                   1673:        }
1.1       bertrand 1674:    }
                   1675: 
                   1676:    return;
                   1677: }
                   1678: 
                   1679: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>