1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.22
4: Copyright (C) 1989-2015 Dr. BERTRAND Joël
5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #include "rpl-conv.h"
24:
25:
26: /*
27: ================================================================================
28: Fonction 'dupcntxt'
29: ================================================================================
30: Entrées : pointeur sur une structure struct_processus
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_dupcntxt(struct_processus *s_etat_processus)
40: {
41: struct_objet *s_objet;
42: struct_objet *s_pile;
43:
44: (*s_etat_processus).erreur_execution = d_ex;
45:
46: if ((*s_etat_processus).affichage_arguments == 'Y')
47: {
48: printf("\n DUPCNTXT ");
49:
50: if ((*s_etat_processus).langue == 'F')
51: {
52: printf("(duplication du contexte)\n\n");
53: printf(" Aucun argument\n");
54: }
55: else
56: {
57: printf("(context duplication)\n\n");
58: printf(" No argument\n");
59: }
60:
61: return;
62: }
63: else if ((*s_etat_processus).test_instruction == 'Y')
64: {
65: (*s_etat_processus).nombre_arguments = -1;
66: return;
67: }
68:
69: if (test_cfsf(s_etat_processus, 31) == d_vrai)
70: {
71: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
72: {
73: return;
74: }
75: }
76:
77: if ((s_objet = allocation(s_etat_processus, LST)) == NULL)
78: {
79: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
80: return;
81: }
82:
83: (*s_objet).objet = (*s_etat_processus).l_base_pile;
84:
85: if ((s_pile = copie_objet(s_etat_processus, s_objet, 'N')) == NULL)
86: {
87: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
88: return;
89: }
90:
91: if (empilement(s_etat_processus, &((*s_etat_processus).
92: l_base_pile_contextes), s_objet) == d_erreur)
93: {
94: return;
95: }
96:
97: if ((s_objet = allocation(s_etat_processus, INT)) == NULL)
98: {
99: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
100: return;
101: }
102:
103: (*((integer8 *) (*s_objet).objet)) = (*s_etat_processus)
104: .hauteur_pile_operationnelle;
105:
106: if (empilement(s_etat_processus, &((*s_etat_processus)
107: .l_base_pile_taille_contextes), s_objet) == d_erreur)
108: {
109: return;
110: }
111:
112: /*
113: * Copie de la pile opérationnelle
114: */
115:
116: (*s_etat_processus).l_base_pile = (*s_pile).objet;
117:
118: (*s_pile).objet = NULL;
119: liberation(s_etat_processus, s_pile);
120:
121: return;
122: }
123:
124:
125: /*
126: ================================================================================
127: Fonction 'dropcntxt'
128: ================================================================================
129: Entrées : pointeur sur une structure struct_processus
130: --------------------------------------------------------------------------------
131: Sorties :
132: --------------------------------------------------------------------------------
133: Effets de bord : néant
134: ================================================================================
135: */
136:
137: void
138: instruction_dropcntxt(struct_processus *s_etat_processus)
139: {
140: struct_objet *s_objet;
141:
142: (*s_etat_processus).erreur_execution = d_ex;
143:
144: if ((*s_etat_processus).affichage_arguments == 'Y')
145: {
146: printf("\n DROPCNTXT ");
147:
148: if ((*s_etat_processus).langue == 'F')
149: {
150: printf("(effacement d'un contexte)\n\n");
151: printf(" Aucun argument\n");
152: }
153: else
154: {
155: printf("(drops context)\n\n");
156: printf(" No argument\n");
157: }
158:
159: return;
160: }
161: else if ((*s_etat_processus).test_instruction == 'Y')
162: {
163: (*s_etat_processus).nombre_arguments = -1;
164: return;
165: }
166:
167: if (test_cfsf(s_etat_processus, 31) == d_vrai)
168: {
169: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
170: {
171: return;
172: }
173: }
174:
175: if (((*s_etat_processus).l_base_pile_contextes == NULL) ||
176: ((*s_etat_processus).l_base_pile_taille_contextes == NULL))
177: {
178: (*s_etat_processus).erreur_execution = d_ex_contexte;
179: return;
180: }
181:
182: if (depilement(s_etat_processus, &((*s_etat_processus)
183: .l_base_pile_contextes), &s_objet) == d_erreur)
184: {
185: return;
186: }
187:
188: liberation(s_etat_processus, s_objet);
189:
190: if (depilement(s_etat_processus, &((*s_etat_processus)
191: .l_base_pile_taille_contextes), &s_objet) == d_erreur)
192: {
193: return;
194: }
195:
196: liberation(s_etat_processus, s_objet);
197:
198: return;
199: }
200:
201:
202: /*
203: ================================================================================
204: Fonction 'dgtiz'
205: ================================================================================
206: Entrées : pointeur sur une structure struct_processus
207: --------------------------------------------------------------------------------
208: Sorties :
209: --------------------------------------------------------------------------------
210: Effets de bord : néant
211: ================================================================================
212: */
213:
214: void
215: instruction_dgtiz(struct_processus *s_etat_processus)
216: {
217: (*s_etat_processus).erreur_execution = d_ex;
218:
219: if ((*s_etat_processus).affichage_arguments == 'Y')
220: {
221: printf("\n DGTIZ ");
222:
223: if ((*s_etat_processus).langue == 'F')
224: {
225: printf("(mouse support in plot functions)\n\n");
226: printf(" Aucun argument\n");
227: }
228: else
229: {
230: printf("(support de la souris dans les fonctions graphiques)\n\n");
231: printf(" No argument\n");
232: }
233:
234: return;
235: }
236: else if ((*s_etat_processus).test_instruction == 'Y')
237: {
238: (*s_etat_processus).nombre_arguments = -1;
239: return;
240: }
241:
242: if (test_cfsf(s_etat_processus, 31) == d_vrai)
243: {
244: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
245: {
246: return;
247: }
248: }
249:
250: if ((*s_etat_processus).fichiers_graphiques != NULL)
251: {
252: (*s_etat_processus).souris_active = d_vrai;
253: appel_gnuplot(s_etat_processus, 'N');
254: (*s_etat_processus).souris_active = d_faux;
255: }
256:
257: return;
258: }
259:
260:
261: /*
262: ================================================================================
263: Fonction 'daemonize'
264: ================================================================================
265: Entrées : pointeur sur une structure struct_processus
266: --------------------------------------------------------------------------------
267: Sorties :
268: --------------------------------------------------------------------------------
269: Effets de bord : néant
270: ================================================================================
271: */
272:
273: void
274: instruction_daemonize(struct_processus *s_etat_processus)
275: {
276: (*s_etat_processus).erreur_execution = d_ex;
277:
278: if ((*s_etat_processus).affichage_arguments == 'Y')
279: {
280: printf("\n DAEMONIZE ");
281:
282: if ((*s_etat_processus).langue == 'F')
283: {
284: printf("(basculement en mode daemon)\n\n");
285: printf(" Aucun argument\n");
286: }
287: else
288: {
289: printf("(convert to daemon)\n\n");
290: printf(" No argument\n");
291: }
292:
293: return;
294: }
295: else if ((*s_etat_processus).test_instruction == 'Y')
296: {
297: (*s_etat_processus).nombre_arguments = -1;
298: return;
299: }
300:
301: if (test_cfsf(s_etat_processus, 31) == d_vrai)
302: {
303: if (empilement_pile_last(s_etat_processus, 0) == d_erreur)
304: {
305: return;
306: }
307: }
308:
309: if (((*s_etat_processus).var_volatile_processus_pere == -1) &&
310: ((*s_etat_processus).l_base_pile_processus == NULL))
311: {
312: lancement_daemon(s_etat_processus);
313: }
314: else
315: {
316: (*s_etat_processus).erreur_execution = d_ex_daemon;
317: return;
318: }
319:
320: return;
321: }
322:
323:
324: /*
325: ================================================================================
326: Fonction 'diag->'
327: ================================================================================
328: Entrées : pointeur sur une structure struct_processus
329: --------------------------------------------------------------------------------
330: Sorties :
331: --------------------------------------------------------------------------------
332: Effets de bord : néant
333: ================================================================================
334: */
335:
336: void
337: instruction_diag_fleche(struct_processus *s_etat_processus)
338: {
339: struct_objet *s_objet_argument;
340: struct_objet *s_objet_resultat;
341:
342: integer8 i;
343: integer8 j;
344:
345: (*s_etat_processus).erreur_execution = d_ex;
346:
347: if ((*s_etat_processus).affichage_arguments == 'Y')
348: {
349: printf("\n DIAG-> ");
350:
351: if ((*s_etat_processus).langue == 'F')
352: {
353: printf("(conversion d'une matrice diagonale en vecteur)\n\n");
354: }
355: else
356: {
357: printf("(diagonal matrix to vector conversion)\n\n");
358: }
359:
360: printf(" 1: %s, %s, %s\n", d_MIN, d_MRL, d_MCX);
361: printf("-> 1: %s, %s, %s\n", d_VIN, d_VRL, d_VCX);
362:
363: return;
364: }
365: else if ((*s_etat_processus).test_instruction == 'Y')
366: {
367: (*s_etat_processus).nombre_arguments = -1;
368: return;
369: }
370:
371: if (test_cfsf(s_etat_processus, 31) == d_vrai)
372: {
373: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
374: {
375: return;
376: }
377: }
378:
379: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
380: &s_objet_argument) == d_erreur)
381: {
382: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
383: return;
384: }
385:
386: /*
387: * Conversion d'une matrice
388: */
389:
390: if ((*s_objet_argument).type == MIN)
391: {
392: if ((*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes !=
393: (*((struct_matrice *) (*s_objet_argument).objet))
394: .nombre_colonnes)
395: {
396: (*s_etat_processus).erreur_execution = d_ex_dimensions_invalides;
397:
398: liberation(s_etat_processus, s_objet_argument);
399: return;
400: }
401:
402: if ((s_objet_resultat = allocation(s_etat_processus, VIN)) == NULL)
403: {
404: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
405: return;
406: }
407:
408: (*((struct_vecteur *) (*s_objet_resultat).objet)).taille =
409: (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes;
410:
411: if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau
412: = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat)
413: .objet)).taille) * sizeof(integer8))) == NULL)
414: {
415: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
416: return;
417: }
418:
419: for(i = 0; i < (*((struct_matrice *) (*s_objet_argument).objet))
420: .nombre_lignes; i++)
421: {
422: for(j = 0; j < (*((struct_matrice *) (*s_objet_argument).objet))
423: .nombre_colonnes; j++)
424: {
425: if (i != j)
426: {
427: if (((integer8 **) (*((struct_matrice *) (*s_objet_argument)
428: .objet)).tableau)[i][j] != 0)
429: {
430: liberation(s_etat_processus, s_objet_argument);
431: liberation(s_etat_processus, s_objet_resultat);
432:
433: (*s_etat_processus).erreur_execution =
434: d_ex_matrice_non_diagonale;
435: return;
436: }
437: }
438: else
439: {
440: ((integer8 *) (*((struct_vecteur *) (*s_objet_resultat)
441: .objet)).tableau)[i] = ((integer8 **)
442: (*((struct_matrice *) (*s_objet_argument)
443: .objet)).tableau)[i][j];
444: }
445: }
446: }
447: }
448: else if ((*s_objet_argument).type == MRL)
449: {
450: if ((*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes !=
451: (*((struct_matrice *) (*s_objet_argument).objet))
452: .nombre_colonnes)
453: {
454: (*s_etat_processus).erreur_execution = d_ex_dimensions_invalides;
455:
456: liberation(s_etat_processus, s_objet_argument);
457: return;
458: }
459:
460: if ((s_objet_resultat = allocation(s_etat_processus, VRL)) == NULL)
461: {
462: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
463: return;
464: }
465:
466: (*((struct_vecteur *) (*s_objet_resultat).objet)).taille =
467: (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes;
468:
469: if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau
470: = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat)
471: .objet)).taille) * sizeof(real8))) == NULL)
472: {
473: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
474: return;
475: }
476:
477: for(i = 0; i < (*((struct_matrice *) (*s_objet_argument).objet))
478: .nombre_lignes; i++)
479: {
480: for(j = 0; j < (*((struct_matrice *) (*s_objet_argument).objet))
481: .nombre_colonnes; j++)
482: {
483: if (i != j)
484: {
485: if (((real8 **) (*((struct_matrice *) (*s_objet_argument)
486: .objet)).tableau)[i][j] != 0)
487: {
488: liberation(s_etat_processus, s_objet_argument);
489: liberation(s_etat_processus, s_objet_resultat);
490:
491: (*s_etat_processus).erreur_execution =
492: d_ex_matrice_non_diagonale;
493: return;
494: }
495: }
496: else
497: {
498: ((real8 *) (*((struct_vecteur *) (*s_objet_resultat)
499: .objet)).tableau)[i] = ((real8 **)
500: (*((struct_matrice *) (*s_objet_argument)
501: .objet)).tableau)[i][j];
502: }
503: }
504: }
505: }
506: else if ((*s_objet_argument).type == MCX)
507: {
508: if ((*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes !=
509: (*((struct_matrice *) (*s_objet_argument).objet))
510: .nombre_colonnes)
511: {
512: (*s_etat_processus).erreur_execution = d_ex_dimensions_invalides;
513:
514: liberation(s_etat_processus, s_objet_argument);
515: return;
516: }
517:
518: if ((s_objet_resultat = allocation(s_etat_processus, VCX)) == NULL)
519: {
520: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
521: return;
522: }
523:
524: (*((struct_vecteur *) (*s_objet_resultat).objet)).taille =
525: (*((struct_matrice *) (*s_objet_argument).objet)).nombre_lignes;
526:
527: if (((*((struct_vecteur *) (*s_objet_resultat).objet)).tableau
528: = malloc(((size_t) (*((struct_vecteur *) (*s_objet_resultat)
529: .objet)).taille) * sizeof(complex16))) == NULL)
530: {
531: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
532: return;
533: }
534:
535: for(i = 0; i < (*((struct_matrice *) (*s_objet_argument).objet))
536: .nombre_lignes; i++)
537: {
538: for(j = 0; j < (*((struct_matrice *) (*s_objet_argument).objet))
539: .nombre_colonnes; j++)
540: {
541: if (i != j)
542: {
543: if ((((complex16 **) (*((struct_matrice *)
544: (*s_objet_argument).objet)).tableau)[i][j]
545: .partie_reelle != 0) ||
546: (((complex16 **) (*((struct_matrice *)
547: (*s_objet_argument).objet)).tableau)[i][j]
548: .partie_imaginaire != 0))
549: {
550: liberation(s_etat_processus, s_objet_argument);
551: liberation(s_etat_processus, s_objet_resultat);
552:
553: (*s_etat_processus).erreur_execution =
554: d_ex_matrice_non_diagonale;
555: return;
556: }
557: }
558: else
559: {
560: ((complex16 *) (*((struct_vecteur *) (*s_objet_resultat)
561: .objet)).tableau)[i] = ((complex16 **)
562: (*((struct_matrice *) (*s_objet_argument)
563: .objet)).tableau)[i][j];
564: }
565: }
566: }
567: }
568:
569: /*
570: * Conversion impossible impossible
571: */
572:
573: else
574: {
575: liberation(s_etat_processus, s_objet_argument);
576:
577: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
578: return;
579: }
580:
581: liberation(s_etat_processus, s_objet_argument);
582:
583: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
584: s_objet_resultat) == d_erreur)
585: {
586: return;
587: }
588:
589: return;
590: }
591:
592:
593: /*
594: ================================================================================
595: Fonction 'digest'
596: ================================================================================
597: Entrées : pointeur sur une structure struct_processus
598: --------------------------------------------------------------------------------
599: Sorties :
600: --------------------------------------------------------------------------------
601: Effets de bord : néant
602: ================================================================================
603: */
604:
605: void
606: instruction_digest(struct_processus *s_etat_processus)
607: {
608: EVP_MD_CTX contexte;
609:
610: const EVP_MD *EVP_sum;
611: const EVP_CIPHER *EVP_chiffrement;
612:
613: int i;
614: int longueur_bloc;
615: int longueur_somme;
616:
617: integer8 longueur_chaine;
618: integer8 longueur_clef;
619: integer8 longueur_clef_attendue;
620: integer8 longueur_clef_max;
621: integer8 longueur_clef_min;
622: integer8 longueur_tampon;
623:
624: logical1 somme_invalide;
625:
626: struct_liste_chainee *l_element_courant;
627:
628: struct_objet *s_objet_argument_1;
629: struct_objet *s_objet_argument_2;
630: struct_objet *s_objet_resultat;
631:
632: unsigned char *chaine;
633: unsigned char *clef;
634: unsigned char *fonction;
635: unsigned char somme[EVP_MAX_MD_SIZE];
636: unsigned char *tampon;
637: unsigned char *vecteur_initialisation;
638:
639: (*s_etat_processus).erreur_execution = d_ex;
640:
641: if ((*s_etat_processus).affichage_arguments == 'Y')
642: {
643: printf("\n DIGEST ");
644:
645: if ((*s_etat_processus).langue == 'F')
646: {
647: printf("(somme d'authentification)\n\n");
648: }
649: else
650: {
651: printf("(hash algorithm)\n\n");
652: }
653:
654: printf(" 2: %s\n", d_CHN);
655: printf(" 1: %s\n", d_CHN);
656: printf("-> 1: %s\n\n", d_CHN);
657:
658: printf(" 2: %s\n", d_CHN);
659: printf(" 1: %s\n", d_LST);
660: printf("-> 1: %s\n\n", d_CHN);
661:
662: if ((*s_etat_processus).langue == 'F')
663: {
664: printf(" Algorithmes :\n\n");
665: }
666: else
667: {
668: printf(" Algorithms:\n\n");
669: }
670:
671: # ifndef OPENSSL_NO_AES
672: printf(" - AES-128-CBC\n");
673: printf(" - AES-192-CBC\n");
674: printf(" - AES-256-CBC\n");
675: # endif
676: # ifndef OPENSSL_NO_CAMELLIA
677: printf(" - CAMELLIA-128-CBC\n");
678: printf(" - CAMELLIA-192-CBC\n");
679: printf(" - CAMELLIA-256-CBC\n");
680: # endif
681: # ifndef OPENSSL_NO_DES
682: printf(" - DES-CBC\n");
683: printf(" - DES-EDE-CBC\n");
684: printf(" - DES-EDE3-CB\n");
685: printf(" - DESX-CBC\n");
686: # endif
687: # ifndef OPENSSL_NO_SHA
688: printf(" - DSS\n");
689: printf(" - DSS1\n");
690: printf(" - ECDSA\n");
691: # endif
692: # ifndef OPENSSL_NO_IDEA
693: printf(" - IDEA-CBC\n");
694: # endif
695: # ifndef OPENSSL_NO_MD2
696: printf(" - MD2\n");
697: # endif
698: # ifndef OPENSSL_NO_MD4
699: printf(" - MD4\n");
700: # endif
701: # ifndef OPENSSL_NO_MD5
702: printf(" - MD5\n");
703: # endif
704: # ifndef OPENSSL_NO_MDC2
705: printf(" - MDC2\n");
706: # endif
707: # ifndef OPENSSL_NO_RC2
708: printf(" - RC2-CBC\n");
709: printf(" - RC2-40-CBC\n");
710: printf(" - RC2-64-CBC\n");
711: # endif
712: # ifndef OPENSSL_NO_RIPEMD
713: printf(" - RIPEMD160\n");
714: # endif
715: # ifndef OPENSSL_NO_SHA
716: printf(" - SHA\n");
717: printf(" - SHA1\n");
718: # endif
719: # ifndef OPENSSL_NO_SHA256
720: printf(" - SHA224\n");
721: printf(" - SHA256\n");
722: # endif
723: # ifndef OPENSSL_NO_SHA512
724: printf(" - SHA384\n");
725: printf(" - SHA512\n");
726: # endif
727: # ifndef OPENSSL_NO_WHIRLPOOL
728: printf(" - WHIRLPOOL\n");
729: # endif
730:
731: printf("\n");
732:
733: if ((*s_etat_processus).langue == 'F')
734: {
735: printf(" Utilisation :\n\n");
736: }
737: else
738: {
739: printf(" Usage:\n\n");
740: }
741:
742: printf(" \"text\" \"MD5\" DIGEST\n");
743: printf(" \"text\" { \"SHA384\" \"key\" } DIGEST\n");
744: printf(" \"text\" { \"AES-128-CBC\" \"key\" } DIGEST\n");
745: return;
746: }
747: else if ((*s_etat_processus).test_instruction == 'Y')
748: {
749: (*s_etat_processus).nombre_arguments = -1;
750: return;
751: }
752:
753: if (test_cfsf(s_etat_processus, 31) == d_vrai)
754: {
755: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
756: {
757: return;
758: }
759: }
760:
761: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
762: &s_objet_argument_1) == d_erreur)
763: {
764: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
765: return;
766: }
767:
768: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
769: &s_objet_argument_2) == d_erreur)
770: {
771: liberation(s_etat_processus, s_objet_argument_1);
772:
773: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
774: return;
775: }
776:
777: if (((*s_objet_argument_1).type == CHN) &&
778: ((*s_objet_argument_2).type == CHN))
779: {
780: // Liste des sommes disponibles :
781: // - EVP_dss
782: // - EVP_dss1
783: // - EVP_ecdsa
784: // - EVP_md2
785: // - EVP_md4
786: // - EVP_md5
787: // - EVP_mdc2
788: // - EVP_ripemd160
789: // - EVP_sha
790: // - EVP_sha1
791: // - EVP_sha224
792: // - EVP_sha256
793: // - EVP_sha384
794: // - EVP_sha512
795: // - EVP_whirlpool
796:
797: if ((fonction = conversion_majuscule(s_etat_processus,
798: (unsigned char *) (*s_objet_argument_1).objet)) == NULL)
799: {
800: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
801: return;
802: }
803:
804: somme_invalide = d_faux;
805:
806: switch(fonction[0])
807: {
808: case 'D':
809: {
810: switch(fonction[1])
811: {
812: case 'S': // ds
813: {
814: switch(fonction[2])
815: {
816: # ifndef OPENSSL_NO_SHA
817: case 'S': // dss
818: {
819: switch(fonction[3])
820: {
821: case d_code_fin_chaine:
822: {
823: EVP_sum = EVP_dss();
824: break;
825: }
826:
827: case '1': // dss1
828: {
829: if (fonction[4] == d_code_fin_chaine)
830: {
831: EVP_sum = EVP_dss1();
832: }
833: else
834: {
835: somme_invalide = d_vrai;
836: }
837:
838: break;
839: }
840:
841: default:
842: {
843: somme_invalide = d_vrai;
844: break;
845: }
846: }
847:
848: break;
849: }
850: # endif
851:
852: default:
853: {
854: somme_invalide = d_vrai;
855: break;
856: }
857: }
858:
859: break;
860: }
861:
862: default:
863: {
864: somme_invalide = d_vrai;
865: break;
866: }
867: }
868:
869: break;
870: }
871:
872: case 'E':
873: {
874: switch(fonction[1])
875: {
876: case 'C': // ec
877: {
878: switch(fonction[2])
879: {
880: case 'D': // ecd
881: {
882: switch(fonction[3])
883: {
884: case 'S': // ecds
885: {
886: switch(fonction[4])
887: {
888: # ifndef OPENSSL_NO_SHA
889: case 'A': // ecdsa
890: {
891: if (fonction[5] ==
892: d_code_fin_chaine)
893: {
894: EVP_sum = EVP_ecdsa();
895: }
896: else
897: {
898: somme_invalide = d_vrai;
899: }
900:
901: break;
902: }
903: # endif
904:
905: default:
906: {
907: somme_invalide = d_vrai;
908: break;
909: }
910: }
911:
912: break;
913: }
914:
915: default:
916: {
917: somme_invalide = d_vrai;
918: break;
919: }
920: }
921:
922: break;
923: }
924:
925: default:
926: {
927: somme_invalide = d_vrai;
928: break;
929: }
930: }
931:
932: break;
933: }
934:
935: default:
936: {
937: somme_invalide = d_vrai;
938: break;
939: }
940: }
941:
942: break;
943: }
944:
945: case 'M':
946: {
947: switch(fonction[1])
948: {
949: case 'D': // md
950: {
951: switch(fonction[2])
952: {
953: # ifndef OPENSSL_NO_MD2
954: case '2': // md2
955: {
956: if (fonction[3] == d_code_fin_chaine)
957: {
958: EVP_sum = EVP_md2();
959: }
960: else
961: {
962: somme_invalide = d_vrai;
963: }
964:
965: break;
966: }
967: # endif
968:
969: # ifndef OPENSSL_NO_MD4
970: case '4': // md4
971: {
972: if (fonction[3] == d_code_fin_chaine)
973: {
974: EVP_sum = EVP_md4();
975: }
976: else
977: {
978: somme_invalide = d_vrai;
979: }
980:
981: break;
982: }
983: # endif
984:
985: # ifndef OPENSSL_NO_MD5
986: case '5': // md5
987: {
988: if (fonction[3] == d_code_fin_chaine)
989: {
990: EVP_sum = EVP_md5();
991: }
992: else
993: {
994: somme_invalide = d_vrai;
995: }
996:
997: break;
998: }
999: # endif
1000:
1001: case 'C': // mdc
1002: {
1003: switch(fonction[3])
1004: {
1005: # ifndef OPENSSL_NO_MDC2
1006: case '2': // mdc2
1007: {
1008: if (fonction[4] == d_code_fin_chaine)
1009: {
1010: EVP_sum = EVP_mdc2();
1011: }
1012: else
1013: {
1014: somme_invalide = d_vrai;
1015: }
1016:
1017: break;
1018: }
1019: # endif
1020:
1021: default:
1022: {
1023: somme_invalide = d_vrai;
1024: break;
1025: }
1026: }
1027:
1028: break;
1029: }
1030:
1031: default:
1032: {
1033: somme_invalide = d_vrai;
1034: break;
1035: }
1036: }
1037:
1038: break;
1039: }
1040:
1041: default:
1042: {
1043: somme_invalide = d_vrai;
1044: break;
1045: }
1046: }
1047:
1048: break;
1049: }
1050:
1051: # ifndef OPENSSL_NO_RIPEMD
1052: case 'R':
1053: {
1054: if (strcmp(fonction, "RIPEMD160") == 0)
1055: {
1056: EVP_sum = EVP_ripemd160();
1057: }
1058: else
1059: {
1060: somme_invalide = d_vrai;
1061: }
1062:
1063: break;
1064: }
1065: # endif
1066:
1067: case 'S':
1068: {
1069: switch(fonction[1])
1070: {
1071: case 'H': // sh
1072: {
1073: switch(fonction[2])
1074: {
1075: # ifndef OPENSSL_NO_SHA
1076: case 'A':
1077: {
1078: switch(fonction[3])
1079: {
1080: case d_code_fin_chaine:
1081: {
1082: EVP_sum = EVP_sha();
1083: break;
1084: }
1085:
1086: case '1': // sha1
1087: {
1088: if (fonction[4] == d_code_fin_chaine)
1089: {
1090: EVP_sum = EVP_sha1();
1091: }
1092: else
1093: {
1094: somme_invalide = d_vrai;
1095: }
1096:
1097: break;
1098: }
1099:
1100: # ifndef OPENSSL_NO_SHA256
1101: case '2': // sha2
1102: {
1103: switch(fonction[4])
1104: {
1105: case '2': // sha22
1106: {
1107: switch(fonction[5])
1108: {
1109: case '4': // sha224
1110: {
1111: if (fonction[6] ==
1112: d_code_fin_chaine)
1113: {
1114: EVP_sum =
1115: EVP_sha224();
1116: }
1117: else
1118: {
1119: somme_invalide =
1120: d_vrai;
1121: }
1122:
1123: break;
1124: }
1125:
1126: default:
1127: {
1128: somme_invalide = d_vrai;
1129: break;
1130: }
1131: }
1132:
1133: break;
1134: }
1135:
1136: case '5':
1137: {
1138: switch(fonction[5])
1139: {
1140: case '6': // sha256
1141: {
1142: if (fonction[6] ==
1143: d_code_fin_chaine)
1144: {
1145: EVP_sum =
1146: EVP_sha256();
1147: }
1148: else
1149: {
1150: somme_invalide =
1151: d_vrai;
1152: }
1153:
1154: break;
1155: }
1156:
1157: default:
1158: {
1159: somme_invalide = d_vrai;
1160: break;
1161: }
1162: }
1163:
1164: break;
1165: }
1166:
1167: default:
1168: {
1169: somme_invalide = d_vrai;
1170: break;
1171: }
1172: }
1173:
1174: break;
1175: }
1176: # endif
1177:
1178: # ifndef OPENSSL_NO_SHA512
1179: case '3': // sha3
1180: {
1181: switch(fonction[4])
1182: {
1183: case '8': // sha38
1184: {
1185: switch(fonction[5])
1186: {
1187: case '4': // sha384
1188: {
1189: if (fonction[6] ==
1190: d_code_fin_chaine)
1191: {
1192: EVP_sum =
1193: EVP_sha384();
1194: }
1195: else
1196: {
1197: somme_invalide =
1198: d_vrai;
1199: }
1200:
1201: break;
1202: }
1203:
1204: default:
1205: {
1206: somme_invalide = d_vrai;
1207: break;
1208: }
1209: }
1210:
1211: break;
1212: }
1213:
1214: default:
1215: {
1216: somme_invalide = d_vrai;
1217: break;
1218: }
1219: }
1220:
1221: break;
1222: }
1223:
1224: case '5': // sha5
1225: {
1226: switch(fonction[4])
1227: {
1228: case '1': // sha51
1229: {
1230: switch(fonction[5])
1231: {
1232: case '2': // sha512
1233: {
1234: if (fonction[6] ==
1235: d_code_fin_chaine)
1236: {
1237: EVP_sum =
1238: EVP_sha512();
1239: }
1240: else
1241: {
1242: somme_invalide =
1243: d_vrai;
1244: }
1245:
1246: break;
1247: }
1248:
1249: default:
1250: {
1251: somme_invalide = d_vrai;
1252: break;
1253: }
1254: }
1255:
1256: break;
1257: }
1258:
1259: default:
1260: {
1261: somme_invalide = d_vrai;
1262: break;
1263: }
1264: }
1265:
1266: break;
1267: }
1268: # endif
1269:
1270: default:
1271: {
1272: somme_invalide = d_vrai;
1273: break;
1274: }
1275: }
1276:
1277: break;
1278: }
1279: # endif
1280:
1281: default:
1282: {
1283: somme_invalide = d_vrai;
1284: break;
1285: }
1286: }
1287:
1288: break;
1289: }
1290:
1291: default:
1292: {
1293: somme_invalide = d_vrai;
1294: break;
1295: }
1296: }
1297:
1298: break;
1299: }
1300:
1301: # ifndef OPENSSL_NO_WHIRLPOOL
1302: case 'W':
1303: {
1304: if (strcmp(fonction, "WHIRLPOOL") == 0)
1305: {
1306: EVP_sum = EVP_whirlpool();
1307: }
1308: else
1309: {
1310: somme_invalide = d_vrai;
1311: }
1312:
1313: break;
1314: }
1315: # endif
1316:
1317: default:
1318: {
1319: somme_invalide = d_vrai;
1320: break;
1321: }
1322: }
1323:
1324: free(fonction);
1325:
1326: if (somme_invalide == d_vrai)
1327: {
1328: liberation(s_etat_processus, s_objet_argument_1);
1329: liberation(s_etat_processus, s_objet_argument_2);
1330:
1331: (*s_etat_processus).erreur_execution =
1332: d_ex_chiffrement_indisponible;
1333: return;
1334: }
1335:
1336: if (EVP_DigestInit(&contexte, EVP_sum) != 1)
1337: {
1338: EVP_MD_CTX_cleanup(&contexte);
1339:
1340: liberation(s_etat_processus, s_objet_argument_1);
1341: liberation(s_etat_processus, s_objet_argument_2);
1342:
1343: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1344: return;
1345: }
1346:
1347: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
1348: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
1349: {
1350: EVP_MD_CTX_cleanup(&contexte);
1351:
1352: liberation(s_etat_processus, s_objet_argument_1);
1353: liberation(s_etat_processus, s_objet_argument_2);
1354:
1355: return;
1356: }
1357:
1358: if (EVP_DigestUpdate(&contexte, chaine, (size_t) longueur_chaine) != 1)
1359: {
1360: free(chaine);
1361: EVP_MD_CTX_cleanup(&contexte);
1362:
1363: liberation(s_etat_processus, s_objet_argument_1);
1364: liberation(s_etat_processus, s_objet_argument_2);
1365:
1366: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1367: return;
1368: }
1369:
1370: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
1371: {
1372: free(chaine);
1373: EVP_MD_CTX_cleanup(&contexte);
1374:
1375: liberation(s_etat_processus, s_objet_argument_1);
1376: liberation(s_etat_processus, s_objet_argument_2);
1377:
1378: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1379: return;
1380: }
1381:
1382: free(chaine);
1383: EVP_MD_CTX_cleanup(&contexte);
1384:
1385: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
1386: {
1387: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1388: return;
1389: }
1390:
1391: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
1392: somme, longueur_somme)) == NULL)
1393: {
1394: liberation(s_etat_processus, s_objet_argument_1);
1395: liberation(s_etat_processus, s_objet_argument_2);
1396:
1397: return;
1398: }
1399: }
1400: else if (((*s_objet_argument_1).type == LST) &&
1401: ((*s_objet_argument_2).type == CHN))
1402: {
1403: l_element_courant = (*s_objet_argument_1).objet;
1404:
1405: if ((*(*l_element_courant).donnee).type != CHN)
1406: {
1407: liberation(s_etat_processus, s_objet_argument_1);
1408: liberation(s_etat_processus, s_objet_argument_2);
1409:
1410: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1411: return;
1412: }
1413:
1414: l_element_courant = (*l_element_courant).suivant;
1415:
1416: if (l_element_courant == NULL)
1417: {
1418: liberation(s_etat_processus, s_objet_argument_1);
1419: liberation(s_etat_processus, s_objet_argument_2);
1420:
1421: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1422: return;
1423: }
1424:
1425: if ((*(*l_element_courant).donnee).type != CHN)
1426: {
1427: liberation(s_etat_processus, s_objet_argument_1);
1428: liberation(s_etat_processus, s_objet_argument_2);
1429:
1430: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1431: return;
1432: }
1433:
1434: if ((*l_element_courant).suivant != NULL)
1435: {
1436: liberation(s_etat_processus, s_objet_argument_1);
1437: liberation(s_etat_processus, s_objet_argument_2);
1438:
1439: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1440: return;
1441: }
1442:
1443: // Test du type de somme de contrôle
1444: // - les sommes classiques suivent la RFC 2104
1445: // - les autres sont formées sur des algorithmes de type CBC
1446:
1447: l_element_courant = (*s_objet_argument_1).objet;
1448:
1449: if ((fonction = conversion_majuscule(s_etat_processus,
1450: (unsigned char *) (*(*l_element_courant).donnee).objet))
1451: == NULL)
1452: {
1453: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1454: return;
1455: }
1456:
1457: somme_invalide = d_faux;
1458:
1459: switch(fonction[0])
1460: {
1461: case 'D':
1462: {
1463: switch(fonction[1])
1464: {
1465: case 'S': // ds
1466: {
1467: switch(fonction[2])
1468: {
1469: # ifndef OPENSSL_NO_SHA
1470: case 'S': // dss
1471: {
1472: switch(fonction[3])
1473: {
1474: case d_code_fin_chaine:
1475: {
1476: EVP_sum = EVP_dss();
1477: break;
1478: }
1479:
1480: case '1': // dss1
1481: {
1482: if (fonction[4] == d_code_fin_chaine)
1483: {
1484: EVP_sum = EVP_dss1();
1485: }
1486: else
1487: {
1488: somme_invalide = d_vrai;
1489: }
1490:
1491: break;
1492: }
1493:
1494: default:
1495: {
1496: somme_invalide = d_vrai;
1497: break;
1498: }
1499: }
1500:
1501: break;
1502: }
1503: # endif
1504:
1505: default:
1506: {
1507: somme_invalide = d_vrai;
1508: break;
1509: }
1510: }
1511:
1512: break;
1513: }
1514:
1515: default:
1516: {
1517: somme_invalide = d_vrai;
1518: break;
1519: }
1520: }
1521:
1522: break;
1523: }
1524:
1525: case 'E':
1526: {
1527: switch(fonction[1])
1528: {
1529: case 'C': // ec
1530: {
1531: switch(fonction[2])
1532: {
1533: case 'D': // ecd
1534: {
1535: switch(fonction[3])
1536: {
1537: case 'S': // ecds
1538: {
1539: switch(fonction[4])
1540: {
1541: # ifndef OPENSSL_NO_SHA
1542: case 'A': // ecdsa
1543: {
1544: if (fonction[5] ==
1545: d_code_fin_chaine)
1546: {
1547: EVP_sum = EVP_ecdsa();
1548: }
1549: else
1550: {
1551: somme_invalide = d_vrai;
1552: }
1553:
1554: break;
1555: }
1556: # endif
1557:
1558: default:
1559: {
1560: somme_invalide = d_vrai;
1561: break;
1562: }
1563: }
1564:
1565: break;
1566: }
1567:
1568: default:
1569: {
1570: somme_invalide = d_vrai;
1571: break;
1572: }
1573: }
1574:
1575: break;
1576: }
1577:
1578: default:
1579: {
1580: somme_invalide = d_vrai;
1581: break;
1582: }
1583: }
1584:
1585: break;
1586: }
1587:
1588: default:
1589: {
1590: somme_invalide = d_vrai;
1591: break;
1592: }
1593: }
1594:
1595: break;
1596: }
1597:
1598: case 'M':
1599: {
1600: switch(fonction[1])
1601: {
1602: case 'D': // md
1603: {
1604: switch(fonction[2])
1605: {
1606: # ifndef OPENSSL_NO_MD2
1607: case '2': // md2
1608: {
1609: if (fonction[3] == d_code_fin_chaine)
1610: {
1611: EVP_sum = EVP_md2();
1612: }
1613: else
1614: {
1615: somme_invalide = d_vrai;
1616: }
1617:
1618: break;
1619: }
1620: # endif
1621:
1622: # ifndef OPENSSL_NO_MD4
1623: case '4': // md4
1624: {
1625: if (fonction[3] == d_code_fin_chaine)
1626: {
1627: EVP_sum = EVP_md4();
1628: }
1629: else
1630: {
1631: somme_invalide = d_vrai;
1632: }
1633:
1634: break;
1635: }
1636: # endif
1637:
1638: # ifndef OPENSSL_NO_MD5
1639: case '5': // md5
1640: {
1641: if (fonction[3] == d_code_fin_chaine)
1642: {
1643: EVP_sum = EVP_md5();
1644: }
1645: else
1646: {
1647: somme_invalide = d_vrai;
1648: }
1649:
1650: break;
1651: }
1652: # endif
1653:
1654: case 'C': // mdc
1655: {
1656: switch(fonction[3])
1657: {
1658: # ifndef OPENSSL_NO_MDC2
1659: case '2': // mdc2
1660: {
1661: if (fonction[4] == d_code_fin_chaine)
1662: {
1663: EVP_sum = EVP_mdc2();
1664: }
1665: else
1666: {
1667: somme_invalide = d_vrai;
1668: }
1669:
1670: break;
1671: }
1672: # endif
1673:
1674: default:
1675: {
1676: somme_invalide = d_vrai;
1677: break;
1678: }
1679: }
1680:
1681: break;
1682: }
1683:
1684: default:
1685: {
1686: somme_invalide = d_vrai;
1687: break;
1688: }
1689: }
1690:
1691: break;
1692: }
1693:
1694: default:
1695: {
1696: somme_invalide = d_vrai;
1697: break;
1698: }
1699: }
1700:
1701: break;
1702: }
1703:
1704: # ifndef OPENSSL_NO_RIPEMD
1705: case 'R':
1706: {
1707: if (strcmp(fonction, "RIPEMD160") == 0)
1708: {
1709: EVP_sum = EVP_ripemd160();
1710: }
1711: else
1712: {
1713: somme_invalide = d_vrai;
1714: }
1715:
1716: break;
1717: }
1718: # endif
1719:
1720: case 'S':
1721: {
1722: switch(fonction[1])
1723: {
1724: case 'H': // sh
1725: {
1726: switch(fonction[2])
1727: {
1728: # ifndef OPENSSL_NO_SHA
1729: case 'A':
1730: {
1731: switch(fonction[3])
1732: {
1733: case d_code_fin_chaine:
1734: {
1735: EVP_sum = EVP_sha();
1736: break;
1737: }
1738:
1739: case '1': // sha1
1740: {
1741: if (fonction[4] == d_code_fin_chaine)
1742: {
1743: EVP_sum = EVP_sha1();
1744: }
1745: else
1746: {
1747: somme_invalide = d_vrai;
1748: }
1749:
1750: break;
1751: }
1752:
1753: # ifndef OPENSSL_NO_SHA256
1754: case '2': // sha2
1755: {
1756: switch(fonction[4])
1757: {
1758: case '2': // sha22
1759: {
1760: switch(fonction[5])
1761: {
1762: case '4': // sha224
1763: {
1764: if (fonction[6] ==
1765: d_code_fin_chaine)
1766: {
1767: EVP_sum =
1768: EVP_sha224();
1769: }
1770: else
1771: {
1772: somme_invalide =
1773: d_vrai;
1774: }
1775:
1776: break;
1777: }
1778:
1779: default:
1780: {
1781: somme_invalide = d_vrai;
1782: break;
1783: }
1784: }
1785:
1786: break;
1787: }
1788:
1789: case '5':
1790: {
1791: switch(fonction[5])
1792: {
1793: case '6': // sha256
1794: {
1795: if (fonction[6] ==
1796: d_code_fin_chaine)
1797: {
1798: EVP_sum =
1799: EVP_sha256();
1800: }
1801: else
1802: {
1803: somme_invalide =
1804: d_vrai;
1805: }
1806:
1807: break;
1808: }
1809:
1810: default:
1811: {
1812: somme_invalide = d_vrai;
1813: break;
1814: }
1815: }
1816:
1817: break;
1818: }
1819:
1820: default:
1821: {
1822: somme_invalide = d_vrai;
1823: break;
1824: }
1825: }
1826:
1827: break;
1828: }
1829: # endif
1830:
1831: # ifndef OPENSSL_NO_SHA512
1832: case '3': // sha3
1833: {
1834: switch(fonction[4])
1835: {
1836: case '8': // sha38
1837: {
1838: switch(fonction[5])
1839: {
1840: case '4': // sha384
1841: {
1842: if (fonction[6] ==
1843: d_code_fin_chaine)
1844: {
1845: EVP_sum =
1846: EVP_sha384();
1847: }
1848: else
1849: {
1850: somme_invalide =
1851: d_vrai;
1852: }
1853:
1854: break;
1855: }
1856:
1857: default:
1858: {
1859: somme_invalide = d_vrai;
1860: break;
1861: }
1862: }
1863:
1864: break;
1865: }
1866:
1867: default:
1868: {
1869: somme_invalide = d_vrai;
1870: break;
1871: }
1872: }
1873:
1874: break;
1875: }
1876:
1877: case '5': // sha5
1878: {
1879: switch(fonction[4])
1880: {
1881: case '1': // sha51
1882: {
1883: switch(fonction[5])
1884: {
1885: case '2': // sha512
1886: {
1887: if (fonction[6] ==
1888: d_code_fin_chaine)
1889: {
1890: EVP_sum =
1891: EVP_sha512();
1892: }
1893: else
1894: {
1895: somme_invalide =
1896: d_vrai;
1897: }
1898:
1899: break;
1900: }
1901:
1902: default:
1903: {
1904: somme_invalide = d_vrai;
1905: break;
1906: }
1907: }
1908:
1909: break;
1910: }
1911:
1912: default:
1913: {
1914: somme_invalide = d_vrai;
1915: break;
1916: }
1917: }
1918:
1919: break;
1920: }
1921: # endif
1922:
1923: default:
1924: {
1925: somme_invalide = d_vrai;
1926: break;
1927: }
1928: }
1929:
1930: break;
1931: }
1932: # endif
1933:
1934: default:
1935: {
1936: somme_invalide = d_vrai;
1937: break;
1938: }
1939: }
1940:
1941: break;
1942: }
1943:
1944: default:
1945: {
1946: somme_invalide = d_vrai;
1947: break;
1948: }
1949: }
1950:
1951: break;
1952: }
1953:
1954: # ifndef OPENSSL_NO_WHIRLPOOL
1955: case 'W':
1956: {
1957: if (strcmp(fonction, "WHIRLPOOL") == 0)
1958: {
1959: EVP_sum = EVP_whirlpool();
1960: }
1961: else
1962: {
1963: somme_invalide = d_vrai;
1964: }
1965:
1966: break;
1967: }
1968: # endif
1969:
1970: default:
1971: {
1972: somme_invalide = d_vrai;
1973: break;
1974: }
1975: }
1976:
1977: if (somme_invalide == d_vrai)
1978: {
1979: // Le chiffrement est de type CBC-MAC
1980:
1981: if (strncmp(fonction, "AES", 3) == 0)
1982: {
1983: # ifdef OPENSSL_NO_AES
1984:
1985: free(fonction);
1986:
1987: liberation(s_etat_processus, s_objet_argument_1);
1988: liberation(s_etat_processus, s_objet_argument_2);
1989:
1990: (*s_etat_processus).erreur_execution =
1991: d_ex_chiffrement_indisponible;
1992: return;
1993:
1994: # else
1995:
1996: if (strcmp(fonction, "AES-128-CBC") == 0)
1997: {
1998: EVP_chiffrement = EVP_aes_128_cbc();
1999: }
2000: else if (strcmp(fonction, "AES-192-CBC") == 0)
2001: {
2002: EVP_chiffrement = EVP_aes_192_cbc();
2003: }
2004: else if (strcmp(fonction, "AES-256-CBC") == 0)
2005: {
2006: EVP_chiffrement = EVP_aes_256_cbc();
2007: }
2008: else
2009: {
2010: free(fonction);
2011:
2012: liberation(s_etat_processus, s_objet_argument_1);
2013: liberation(s_etat_processus, s_objet_argument_2);
2014:
2015: (*s_etat_processus).erreur_execution =
2016: d_ex_chiffrement_indisponible;
2017: return;
2018: }
2019:
2020: longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
2021: longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
2022:
2023: # endif
2024: }
2025: else if (strncmp(fonction, "DES", 3) == 0)
2026: {
2027: # ifdef OPENSSL_NO_DES
2028:
2029: free(fonction);
2030:
2031: liberation(s_etat_processus, s_objet_argument_1);
2032: liberation(s_etat_processus, s_objet_argument_2);
2033:
2034: (*s_etat_processus).erreur_execution =
2035: d_ex_chiffrement_indisponible;
2036: return;
2037:
2038: # else
2039:
2040: if (strcmp(fonction, "DES-CBC") == 0)
2041: {
2042: EVP_chiffrement = EVP_des_cbc();
2043: }
2044: else if (strcmp(fonction, "DES-EDE-CBC") == 0)
2045: {
2046: EVP_chiffrement = EVP_des_ede_cbc();
2047: }
2048: else if (strcmp(fonction, "DES-EDE3-CBC") == 0)
2049: {
2050: EVP_chiffrement = EVP_des_ede3_cbc();
2051: }
2052: else if (strcmp(fonction, "DESX-CBC") == 0)
2053: {
2054: EVP_chiffrement = EVP_desx_cbc();
2055: }
2056: else
2057: {
2058: free(fonction);
2059:
2060: liberation(s_etat_processus, s_objet_argument_1);
2061: liberation(s_etat_processus, s_objet_argument_2);
2062:
2063: (*s_etat_processus).erreur_execution =
2064: d_ex_chiffrement_indisponible;
2065: return;
2066: }
2067:
2068: longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
2069: longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
2070:
2071: # endif
2072: }
2073: else if (strncmp(fonction, "CAMELLIA", 8) == 0)
2074: {
2075: # ifdef OPENSSL_NO_CAMELLIA
2076:
2077: free(fonction);
2078:
2079: liberation(s_etat_processus, s_objet_argument_1);
2080: liberation(s_etat_processus, s_objet_argument_2);
2081:
2082: (*s_etat_processus).erreur_execution =
2083: d_ex_chiffrement_indisponible;
2084: return;
2085:
2086: # else
2087:
2088: if (strcmp(fonction, "CAMELLIA-128-CBC") == 0)
2089: {
2090: EVP_chiffrement = EVP_camellia_128_cbc();
2091: }
2092: else if (strcmp(fonction, "CAMELLIA-192-CBC") == 0)
2093: {
2094: EVP_chiffrement = EVP_camellia_192_cbc();
2095: }
2096: else if (strcmp(fonction, "CAMELLIA-256-CBC") == 0)
2097: {
2098: EVP_chiffrement = EVP_camellia_256_cbc();
2099: }
2100: else
2101: {
2102: free(fonction);
2103:
2104: liberation(s_etat_processus, s_objet_argument_1);
2105: liberation(s_etat_processus, s_objet_argument_2);
2106:
2107: (*s_etat_processus).erreur_execution =
2108: d_ex_chiffrement_indisponible;
2109: return;
2110: }
2111:
2112: longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
2113: longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
2114:
2115: # endif
2116: }
2117: else if (strncmp(fonction, "RC2", 3) == 0)
2118: {
2119: # ifdef OPENSSL_NO_RC2
2120:
2121: free(fonction);
2122:
2123: liberation(s_etat_processus, s_objet_argument_1);
2124: liberation(s_etat_processus, s_objet_argument_2);
2125:
2126: (*s_etat_processus).erreur_execution =
2127: d_ex_chiffrement_indisponible;
2128: return;
2129:
2130: # else
2131:
2132: if (strcmp(fonction, "RC2-CBC") == 0)
2133: {
2134: EVP_chiffrement = EVP_rc2_cbc();
2135: }
2136: else if (strcmp(fonction, "RC2-40-CBC") == 0)
2137: {
2138: EVP_chiffrement = EVP_rc2_40_cbc();
2139: }
2140: else if (strcmp(fonction, "RC2-64-CBC") == 0)
2141: {
2142: EVP_chiffrement = EVP_rc2_64_cbc();
2143: }
2144: else
2145: {
2146: free(fonction);
2147:
2148: liberation(s_etat_processus, s_objet_argument_1);
2149: liberation(s_etat_processus, s_objet_argument_2);
2150:
2151: (*s_etat_processus).erreur_execution =
2152: d_ex_chiffrement_indisponible;
2153: return;
2154: }
2155:
2156: longueur_clef_attendue = 0;
2157: longueur_clef_min = 1;
2158: longueur_clef_max = 16;
2159: longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
2160:
2161: # endif
2162: }
2163: else if (strncmp(fonction, "IDEA", 4) == 0)
2164: {
2165: # ifdef OPENSSL_NO_IDEA
2166:
2167: free(fonction);
2168:
2169: liberation(s_etat_processus, s_objet_argument_1);
2170: liberation(s_etat_processus, s_objet_argument_2);
2171:
2172: (*s_etat_processus).erreur_execution =
2173: d_ex_chiffrement_indisponible;
2174: return;
2175:
2176: # else
2177:
2178: if (strcmp(fonction, "IDEA-CBC") == 0)
2179: {
2180: EVP_chiffrement = EVP_idea_cbc();
2181: }
2182: else
2183: {
2184: free(fonction);
2185:
2186: liberation(s_etat_processus, s_objet_argument_1);
2187: liberation(s_etat_processus, s_objet_argument_2);
2188:
2189: (*s_etat_processus).erreur_execution =
2190: d_ex_chiffrement_indisponible;
2191: return;
2192: }
2193:
2194: longueur_clef_attendue = EVP_CIPHER_key_length(EVP_chiffrement);
2195: longueur_somme = EVP_CIPHER_block_size(EVP_chiffrement);
2196:
2197: # endif
2198: }
2199: else
2200: {
2201: free(fonction);
2202:
2203: liberation(s_etat_processus, s_objet_argument_1);
2204: liberation(s_etat_processus, s_objet_argument_2);
2205:
2206: (*s_etat_processus).erreur_execution =
2207: d_ex_chiffrement_indisponible;
2208: return;
2209: }
2210:
2211: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
2212: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
2213: {
2214: free(fonction);
2215:
2216: liberation(s_etat_processus, s_objet_argument_1);
2217: liberation(s_etat_processus, s_objet_argument_2);
2218:
2219: return;
2220: }
2221:
2222: l_element_courant = (*s_objet_argument_1).objet;
2223: l_element_courant = (*l_element_courant).suivant;
2224:
2225: if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
2226: (*(*l_element_courant).donnee).objet, &longueur_clef))
2227: == NULL)
2228: {
2229: free(fonction);
2230: free(chaine);
2231:
2232: liberation(s_etat_processus, s_objet_argument_1);
2233: liberation(s_etat_processus, s_objet_argument_2);
2234: return;
2235: }
2236:
2237: if (longueur_clef_attendue != 0)
2238: {
2239: if (longueur_clef != longueur_clef_attendue)
2240: {
2241: free(fonction);
2242: free(chaine);
2243: free(clef);
2244:
2245: liberation(s_etat_processus, s_objet_argument_1);
2246: liberation(s_etat_processus, s_objet_argument_2);
2247:
2248: (*s_etat_processus).erreur_execution =
2249: d_ex_longueur_clef_chiffrement;
2250: return;
2251: }
2252: }
2253: else
2254: {
2255: if ((longueur_clef < longueur_clef_min) &&
2256: (longueur_clef > longueur_clef_max))
2257: {
2258: free(fonction);
2259: free(chaine);
2260: free(clef);
2261:
2262: liberation(s_etat_processus, s_objet_argument_1);
2263: liberation(s_etat_processus, s_objet_argument_2);
2264:
2265: (*s_etat_processus).erreur_execution =
2266: d_ex_longueur_clef_chiffrement;
2267: return;
2268: }
2269: }
2270:
2271: if ((vecteur_initialisation = malloc(((size_t) longueur_clef) *
2272: sizeof(unsigned char))) == NULL)
2273: {
2274: (*s_etat_processus).erreur_systeme =
2275: d_es_allocation_memoire;
2276: return;
2277: }
2278:
2279: memset(vecteur_initialisation, 0, (size_t) longueur_clef);
2280:
2281: if ((tampon = chiffrement(s_etat_processus, EVP_chiffrement, d_vrai,
2282: chaine, longueur_chaine, clef, longueur_clef,
2283: vecteur_initialisation, &longueur_tampon)) == NULL)
2284: {
2285: free(fonction);
2286: free(vecteur_initialisation);
2287: free(chaine);
2288: free(clef);
2289:
2290: (*s_etat_processus).erreur_execution =
2291: d_ex_chiffrement;
2292: return;
2293: }
2294:
2295: free(vecteur_initialisation);
2296: free(chaine);
2297: free(clef);
2298:
2299: if ((s_objet_resultat = allocation(s_etat_processus, CHN))
2300: == NULL)
2301: {
2302: (*s_etat_processus).erreur_systeme =
2303: d_es_allocation_memoire;
2304: return;
2305: }
2306:
2307: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
2308: &(tampon[longueur_tampon - longueur_somme]),
2309: longueur_somme)) == NULL)
2310: {
2311: free(tampon);
2312: free(fonction);
2313:
2314: liberation(s_etat_processus, s_objet_argument_1);
2315: liberation(s_etat_processus, s_objet_argument_2);
2316: return;
2317: }
2318:
2319: free(tampon);
2320: free(fonction);
2321: }
2322: else
2323: {
2324: // Le chiffrement est de type HMAC
2325: // Le second élément de la chaîne contient la clef utilisée pour
2326: // la signature.
2327:
2328: free(fonction);
2329:
2330: l_element_courant = (*s_objet_argument_1).objet;
2331: l_element_courant = (*l_element_courant).suivant;
2332:
2333: longueur_bloc = EVP_MD_block_size(EVP_sum);
2334:
2335: if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
2336: (*(*l_element_courant).donnee).objet, &longueur_clef))
2337: == NULL)
2338: {
2339: liberation(s_etat_processus, s_objet_argument_1);
2340: liberation(s_etat_processus, s_objet_argument_2);
2341: return;
2342: }
2343:
2344: if (longueur_clef < longueur_bloc)
2345: {
2346: longueur_tampon = longueur_clef;
2347: tampon = clef;
2348:
2349: if ((clef = malloc(((size_t) longueur_bloc) *
2350: sizeof(unsigned char))) == NULL)
2351: {
2352: (*s_etat_processus).erreur_systeme =
2353: d_es_allocation_memoire;
2354: return;
2355: }
2356:
2357: memset(clef, 0, (size_t) longueur_bloc);
2358: memcpy(clef, tampon, (size_t) longueur_tampon);
2359: longueur_clef = longueur_bloc;
2360: free(tampon);
2361: }
2362: else if (longueur_clef > longueur_bloc)
2363: {
2364: longueur_tampon = longueur_clef;
2365: tampon = clef;
2366:
2367: if ((clef = malloc(((size_t) longueur_bloc) *
2368: sizeof(unsigned char))) == NULL)
2369: {
2370: (*s_etat_processus).erreur_systeme =
2371: d_es_allocation_memoire;
2372: return;
2373: }
2374:
2375: memcpy(clef, tampon, (size_t) longueur_bloc);
2376: longueur_clef = longueur_bloc;
2377: free(tampon);
2378: }
2379:
2380: for(i = 0; i < longueur_bloc; i++)
2381: {
2382: clef[i] ^= (unsigned char) 0x36;
2383: }
2384:
2385: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
2386: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
2387: {
2388: EVP_MD_CTX_cleanup(&contexte);
2389:
2390: liberation(s_etat_processus, s_objet_argument_1);
2391: liberation(s_etat_processus, s_objet_argument_2);
2392:
2393: return;
2394: }
2395:
2396: if ((tampon = malloc(((size_t) (longueur_bloc + longueur_chaine)) *
2397: sizeof(unsigned char))) == NULL)
2398: {
2399: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2400: return;
2401: }
2402:
2403: memcpy(tampon, clef, (size_t) longueur_bloc);
2404: memcpy(tampon + longueur_bloc, chaine, (size_t) longueur_chaine);
2405: longueur_tampon = longueur_bloc + longueur_chaine;
2406:
2407: if (EVP_DigestInit(&contexte, EVP_sum) != 1)
2408: {
2409: free(tampon);
2410: free(clef);
2411: free(chaine);
2412:
2413: EVP_MD_CTX_cleanup(&contexte);
2414:
2415: liberation(s_etat_processus, s_objet_argument_1);
2416: liberation(s_etat_processus, s_objet_argument_2);
2417:
2418: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2419: return;
2420: }
2421:
2422: if (EVP_DigestUpdate(&contexte, tampon, (size_t) longueur_tampon)
2423: != 1)
2424: {
2425: free(tampon);
2426: free(clef);
2427: free(chaine);
2428:
2429: EVP_MD_CTX_cleanup(&contexte);
2430:
2431: liberation(s_etat_processus, s_objet_argument_1);
2432: liberation(s_etat_processus, s_objet_argument_2);
2433:
2434: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2435: return;
2436: }
2437:
2438: free(tampon);
2439:
2440: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
2441: {
2442: free(chaine);
2443: EVP_MD_CTX_cleanup(&contexte);
2444:
2445: liberation(s_etat_processus, s_objet_argument_1);
2446: liberation(s_etat_processus, s_objet_argument_2);
2447:
2448: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2449: return;
2450: }
2451:
2452: EVP_MD_CTX_cleanup(&contexte);
2453:
2454: for(i = 0; i < longueur_bloc; i++)
2455: {
2456: clef[i] ^= (0x36 ^ 0x5c);
2457: }
2458:
2459: if ((tampon = malloc(((size_t) (longueur_bloc + longueur_somme)) *
2460: sizeof(unsigned char))) == NULL)
2461: {
2462: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2463: return;
2464: }
2465:
2466: memcpy(tampon, clef, (size_t) longueur_bloc);
2467: memcpy(tampon + longueur_bloc, somme, (size_t) longueur_somme);
2468: longueur_tampon = longueur_bloc + longueur_somme;
2469:
2470: if (EVP_DigestInit(&contexte, EVP_sum) != 1)
2471: {
2472: free(tampon);
2473: free(clef);
2474: free(chaine);
2475:
2476: EVP_MD_CTX_cleanup(&contexte);
2477:
2478: liberation(s_etat_processus, s_objet_argument_1);
2479: liberation(s_etat_processus, s_objet_argument_2);
2480:
2481: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2482: return;
2483: }
2484:
2485: if (EVP_DigestUpdate(&contexte, tampon, (size_t) longueur_tampon)
2486: != 1)
2487: {
2488: free(tampon);
2489: free(clef);
2490: free(chaine);
2491:
2492: EVP_MD_CTX_cleanup(&contexte);
2493:
2494: liberation(s_etat_processus, s_objet_argument_1);
2495: liberation(s_etat_processus, s_objet_argument_2);
2496:
2497: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2498: return;
2499: }
2500:
2501: free(tampon);
2502:
2503: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
2504: {
2505: free(chaine);
2506: EVP_MD_CTX_cleanup(&contexte);
2507:
2508: liberation(s_etat_processus, s_objet_argument_1);
2509: liberation(s_etat_processus, s_objet_argument_2);
2510:
2511: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2512: return;
2513: }
2514:
2515: EVP_MD_CTX_cleanup(&contexte);
2516:
2517: free(chaine);
2518: free(clef);
2519:
2520: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
2521: {
2522: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2523: return;
2524: }
2525:
2526: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
2527: somme, longueur_somme)) == NULL)
2528: {
2529: liberation(s_etat_processus, s_objet_argument_1);
2530: liberation(s_etat_processus, s_objet_argument_2);
2531:
2532: return;
2533: }
2534: }
2535: }
2536: else
2537: {
2538: liberation(s_etat_processus, s_objet_argument_1);
2539: liberation(s_etat_processus, s_objet_argument_2);
2540:
2541: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2542: return;
2543: }
2544:
2545: liberation(s_etat_processus, s_objet_argument_1);
2546: liberation(s_etat_processus, s_objet_argument_2);
2547:
2548: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2549: s_objet_resultat) == d_erreur)
2550: {
2551: return;
2552: }
2553:
2554: return;
2555: }
2556:
2557: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>