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

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

CVSweb interface <joel.bertrand@systella.fr>