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

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

CVSweb interface <joel.bertrand@systella.fr>