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