1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.12
4: Copyright (C) 1989-2012 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: 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:
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: logical1 somme_invalide;
614:
615: long i;
616: long longueur_chaine;
617:
618: struct_liste_chainee *l_element_courant;
619:
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;
625: unsigned char *clef;
626: unsigned char *fonction;
627: unsigned char somme[EVP_MAX_MD_SIZE];
628: unsigned char *tampon;
629: unsigned char *vecteur_initialisation;
630:
631: unsigned int longueur_bloc;
632: unsigned int longueur_somme;
633: unsigned int longueur_tampon;
634:
635: unsigned long longueur_clef;
636: unsigned long longueur_clef_attendue;
637:
638: (*s_etat_processus).erreur_execution = d_ex;
639:
640: if ((*s_etat_processus).affichage_arguments == 'Y')
641: {
642: printf("\n DIGEST ");
643:
644: if ((*s_etat_processus).langue == 'F')
645: {
646: printf("(somme d'authentification)\n\n");
647: }
648: else
649: {
650: printf("(hash algorithm)\n\n");
651: }
652:
653: printf(" 2: %s\n", d_CHN);
654: printf(" 1: %s\n", d_CHN);
655: printf("-> 1: %s\n\n", d_CHN);
656:
657: printf(" 2: %s\n", d_CHN);
658: printf(" 1: %s\n", d_LST);
659: printf("-> 1: %s\n\n", d_CHN);
660:
661: if ((*s_etat_processus).langue == 'F')
662: {
663: printf(" Algorithmes :\n\n");
664: }
665: else
666: {
667: printf(" Algorithms:\n\n");
668: }
669:
670: # ifndef OPENSSL_NO_AES
671: printf(" - AES-128-CBC\n");
672: printf(" - AES-192-CBC\n");
673: printf(" - AES-256-CBC\n");
674: # endif
675: # ifndef OPENSSL_NO_SHA
676: printf(" - DSS\n");
677: printf(" - DSS1\n");
678: printf(" - ECDSA\n");
679: # endif
680: # ifndef OPENSSL_NO_MD2
681: printf(" - MD2\n");
682: # endif
683: # ifndef OPENSSL_NO_MD4
684: printf(" - MD4\n");
685: # endif
686: # ifndef OPENSSL_NO_MD5
687: printf(" - MD5\n");
688: # endif
689: # ifndef OPENSSL_NO_MDC2
690: printf(" - MDC2\n");
691: # endif
692: # ifndef OPENSSL_NO_RIPEMD
693: printf(" - RIPEMD160\n");
694: # endif
695: # ifndef OPENSSL_NO_SHA
696: printf(" - SHA\n");
697: printf(" - SHA1\n");
698: # endif
699: # ifndef OPENSSL_NO_SHA256
700: printf(" - SHA224\n");
701: printf(" - SHA256\n");
702: # endif
703: # ifndef OPENSSL_NO_SHA512
704: printf(" - SHA384\n");
705: printf(" - SHA512\n");
706: # endif
707: # ifndef OPENSSL_NO_WHIRLPOOL
708: printf(" - WHIRLPOOL\n");
709: # endif
710:
711: printf("\n");
712:
713: if ((*s_etat_processus).langue == 'F')
714: {
715: printf(" Utilisation :\n\n");
716: }
717: else
718: {
719: printf(" Usage:\n\n");
720: }
721:
722: printf(" \"text\" \"MD5\" DIGEST\n");
723: printf(" \"text\" { \"SHA384\" \"key\" } DIGEST\n");
724: printf(" \"text\" { \"AES-128-CBC\" \"key\" } DIGEST\n");
725: return;
726: }
727: else if ((*s_etat_processus).test_instruction == 'Y')
728: {
729: (*s_etat_processus).nombre_arguments = -1;
730: return;
731: }
732:
733: if (test_cfsf(s_etat_processus, 31) == d_vrai)
734: {
735: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
736: {
737: return;
738: }
739: }
740:
741: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
742: &s_objet_argument_1) == d_erreur)
743: {
744: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
745: return;
746: }
747:
748: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
749: &s_objet_argument_2) == d_erreur)
750: {
751: liberation(s_etat_processus, s_objet_argument_1);
752:
753: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
754: return;
755: }
756:
757: if (((*s_objet_argument_1).type == CHN) &&
758: ((*s_objet_argument_2).type == CHN))
759: {
760: // Liste des sommes disponibles :
761: // - EVP_dss
762: // - EVP_dss1
763: // - EVP_ecdsa
764: // - EVP_md2
765: // - EVP_md4
766: // - EVP_md5
767: // - EVP_mdc2
768: // - EVP_ripemd160
769: // - EVP_sha
770: // - EVP_sha1
771: // - EVP_sha224
772: // - EVP_sha256
773: // - EVP_sha384
774: // - EVP_sha512
775: // - EVP_whirlpool
776:
777: if ((fonction = conversion_majuscule((unsigned char *)
778: (*s_objet_argument_1).objet)) == NULL)
779: {
780: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
781: return;
782: }
783:
784: somme_invalide = d_faux;
785:
786: switch(fonction[0])
787: {
788: case 'D':
789: {
790: switch(fonction[1])
791: {
792: case 'S': // ds
793: {
794: switch(fonction[2])
795: {
796: # ifndef OPENSSL_NO_SHA
797: case 'S': // dss
798: {
799: switch(fonction[3])
800: {
801: case d_code_fin_chaine:
802: {
803: EVP_sum = EVP_dss();
804: break;
805: }
806:
807: case '1': // dss1
808: {
809: if (fonction[4] == d_code_fin_chaine)
810: {
811: EVP_sum = EVP_dss1();
812: }
813: else
814: {
815: somme_invalide = d_vrai;
816: }
817:
818: break;
819: }
820:
821: default:
822: {
823: somme_invalide = d_vrai;
824: break;
825: }
826: }
827:
828: break;
829: }
830: # endif
831:
832: default:
833: {
834: somme_invalide = d_vrai;
835: break;
836: }
837: }
838:
839: break;
840: }
841:
842: default:
843: {
844: somme_invalide = d_vrai;
845: break;
846: }
847: }
848:
849: break;
850: }
851:
852: case 'E':
853: {
854: switch(fonction[1])
855: {
856: case 'C': // ec
857: {
858: switch(fonction[2])
859: {
860: case 'D': // ecd
861: {
862: switch(fonction[3])
863: {
864: case 'S': // ecds
865: {
866: switch(fonction[4])
867: {
868: # ifndef OPENSSL_NO_SHA
869: case 'A': // ecdsa
870: {
871: if (fonction[5] ==
872: d_code_fin_chaine)
873: {
874: EVP_sum = EVP_ecdsa();
875: }
876: else
877: {
878: somme_invalide = d_vrai;
879: }
880:
881: break;
882: }
883: # endif
884:
885: default:
886: {
887: somme_invalide = d_vrai;
888: break;
889: }
890: }
891:
892: break;
893: }
894:
895: default:
896: {
897: somme_invalide = d_vrai;
898: break;
899: }
900: }
901:
902: break;
903: }
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: case 'M':
926: {
927: switch(fonction[1])
928: {
929: case 'D': // md
930: {
931: switch(fonction[2])
932: {
933: # ifndef OPENSSL_NO_MD2
934: case '2': // md2
935: {
936: if (fonction[3] == d_code_fin_chaine)
937: {
938: EVP_sum = EVP_md2();
939: }
940: else
941: {
942: somme_invalide = d_vrai;
943: }
944:
945: break;
946: }
947: # endif
948:
949: # ifndef OPENSSL_NO_MD4
950: case '4': // md4
951: {
952: if (fonction[3] == d_code_fin_chaine)
953: {
954: EVP_sum = EVP_md4();
955: }
956: else
957: {
958: somme_invalide = d_vrai;
959: }
960:
961: break;
962: }
963: # endif
964:
965: # ifndef OPENSSL_NO_MD5
966: case '5': // md5
967: {
968: if (fonction[3] == d_code_fin_chaine)
969: {
970: EVP_sum = EVP_md5();
971: }
972: else
973: {
974: somme_invalide = d_vrai;
975: }
976:
977: break;
978: }
979: # endif
980:
981: case 'C': // mdc
982: {
983: switch(fonction[3])
984: {
985: # ifndef OPENSSL_NO_MDC2
986: case '2': // mdc2
987: {
988: if (fonction[4] == d_code_fin_chaine)
989: {
990: EVP_sum = EVP_mdc2();
991: }
992: else
993: {
994: somme_invalide = d_vrai;
995: }
996:
997: break;
998: }
999: # endif
1000:
1001: default:
1002: {
1003: somme_invalide = d_vrai;
1004: break;
1005: }
1006: }
1007:
1008: break;
1009: }
1010:
1011: default:
1012: {
1013: somme_invalide = d_vrai;
1014: break;
1015: }
1016: }
1017:
1018: break;
1019: }
1020:
1021: default:
1022: {
1023: somme_invalide = d_vrai;
1024: break;
1025: }
1026: }
1027:
1028: break;
1029: }
1030:
1031: # ifndef OPENSSL_NO_RIPEMD
1032: case 'R':
1033: {
1034: if (strcmp(fonction, "RIPEMD160") == 0)
1035: {
1036: EVP_sum = EVP_ripemd160();
1037: }
1038: else
1039: {
1040: somme_invalide = d_vrai;
1041: }
1042:
1043: break;
1044: }
1045: # endif
1046:
1047: case 'S':
1048: {
1049: switch(fonction[1])
1050: {
1051: case 'H': // sh
1052: {
1053: switch(fonction[2])
1054: {
1055: # ifndef OPENSSL_NO_SHA
1056: case 'A':
1057: {
1058: switch(fonction[3])
1059: {
1060: case d_code_fin_chaine:
1061: {
1062: EVP_sum = EVP_sha();
1063: break;
1064: }
1065:
1066: case '1': // sha1
1067: {
1068: if (fonction[4] == d_code_fin_chaine)
1069: {
1070: EVP_sum = EVP_sha1();
1071: }
1072: else
1073: {
1074: somme_invalide = d_vrai;
1075: }
1076:
1077: break;
1078: }
1079:
1080: # ifndef OPENSSL_NO_SHA256
1081: case '2': // sha2
1082: {
1083: switch(fonction[4])
1084: {
1085: case '2': // sha22
1086: {
1087: switch(fonction[5])
1088: {
1089: case '4': // sha224
1090: {
1091: if (fonction[6] ==
1092: d_code_fin_chaine)
1093: {
1094: EVP_sum =
1095: EVP_sha224();
1096: }
1097: else
1098: {
1099: somme_invalide =
1100: d_vrai;
1101: }
1102:
1103: break;
1104: }
1105:
1106: default:
1107: {
1108: somme_invalide = d_vrai;
1109: break;
1110: }
1111: }
1112:
1113: break;
1114: }
1115:
1116: case '5':
1117: {
1118: switch(fonction[5])
1119: {
1120: case '6': // sha256
1121: {
1122: if (fonction[6] ==
1123: d_code_fin_chaine)
1124: {
1125: EVP_sum =
1126: EVP_sha256();
1127: }
1128: else
1129: {
1130: somme_invalide =
1131: d_vrai;
1132: }
1133:
1134: break;
1135: }
1136:
1137: default:
1138: {
1139: somme_invalide = d_vrai;
1140: break;
1141: }
1142: }
1143:
1144: break;
1145: }
1146:
1147: default:
1148: {
1149: somme_invalide = d_vrai;
1150: break;
1151: }
1152: }
1153:
1154: break;
1155: }
1156: # endif
1157:
1158: # ifndef OPENSSL_NO_SHA512
1159: case '3': // sha3
1160: {
1161: switch(fonction[4])
1162: {
1163: case '8': // sha38
1164: {
1165: switch(fonction[5])
1166: {
1167: case '4': // sha384
1168: {
1169: if (fonction[6] ==
1170: d_code_fin_chaine)
1171: {
1172: EVP_sum =
1173: EVP_sha384();
1174: }
1175: else
1176: {
1177: somme_invalide =
1178: d_vrai;
1179: }
1180:
1181: break;
1182: }
1183:
1184: default:
1185: {
1186: somme_invalide = d_vrai;
1187: break;
1188: }
1189: }
1190:
1191: break;
1192: }
1193:
1194: default:
1195: {
1196: somme_invalide = d_vrai;
1197: break;
1198: }
1199: }
1200:
1201: break;
1202: }
1203:
1204: case '5': // sha5
1205: {
1206: switch(fonction[4])
1207: {
1208: case '1': // sha51
1209: {
1210: switch(fonction[5])
1211: {
1212: case '2': // sha512
1213: {
1214: if (fonction[6] ==
1215: d_code_fin_chaine)
1216: {
1217: EVP_sum =
1218: EVP_sha512();
1219: }
1220: else
1221: {
1222: somme_invalide =
1223: d_vrai;
1224: }
1225:
1226: break;
1227: }
1228:
1229: default:
1230: {
1231: somme_invalide = d_vrai;
1232: break;
1233: }
1234: }
1235:
1236: break;
1237: }
1238:
1239: default:
1240: {
1241: somme_invalide = d_vrai;
1242: break;
1243: }
1244: }
1245:
1246: break;
1247: }
1248: # endif
1249:
1250: default:
1251: {
1252: somme_invalide = d_vrai;
1253: break;
1254: }
1255: }
1256:
1257: break;
1258: }
1259: # endif
1260:
1261: default:
1262: {
1263: somme_invalide = d_vrai;
1264: break;
1265: }
1266: }
1267:
1268: break;
1269: }
1270:
1271: default:
1272: {
1273: somme_invalide = d_vrai;
1274: break;
1275: }
1276: }
1277:
1278: break;
1279: }
1280:
1281: # ifndef OPENSSL_NO_WHIRLPOOL
1282: case 'W':
1283: {
1284: if (strcmp(fonction, "WHIRLPOOL") == 0)
1285: {
1286: EVP_sum = EVP_whirlpool();
1287: }
1288: else
1289: {
1290: somme_invalide = d_vrai;
1291: }
1292:
1293: break;
1294: }
1295: # endif
1296:
1297: default:
1298: {
1299: somme_invalide = d_vrai;
1300: break;
1301: }
1302: }
1303:
1304: free(fonction);
1305:
1306: if (somme_invalide == d_vrai)
1307: {
1308: liberation(s_etat_processus, s_objet_argument_1);
1309: liberation(s_etat_processus, s_objet_argument_2);
1310:
1311: (*s_etat_processus).erreur_execution =
1312: d_ex_chiffrement_indisponible;
1313: return;
1314: }
1315:
1316: if (EVP_DigestInit(&contexte, EVP_sum) != 1)
1317: {
1318: EVP_MD_CTX_cleanup(&contexte);
1319:
1320: liberation(s_etat_processus, s_objet_argument_1);
1321: liberation(s_etat_processus, s_objet_argument_2);
1322:
1323: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1324: return;
1325: }
1326:
1327: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
1328: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
1329: {
1330: EVP_MD_CTX_cleanup(&contexte);
1331:
1332: liberation(s_etat_processus, s_objet_argument_1);
1333: liberation(s_etat_processus, s_objet_argument_2);
1334:
1335: return;
1336: }
1337:
1338: if (EVP_DigestUpdate(&contexte, chaine, longueur_chaine) != 1)
1339: {
1340: free(chaine);
1341: EVP_MD_CTX_cleanup(&contexte);
1342:
1343: liberation(s_etat_processus, s_objet_argument_1);
1344: liberation(s_etat_processus, s_objet_argument_2);
1345:
1346: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1347: return;
1348: }
1349:
1350: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
1351: {
1352: free(chaine);
1353: EVP_MD_CTX_cleanup(&contexte);
1354:
1355: liberation(s_etat_processus, s_objet_argument_1);
1356: liberation(s_etat_processus, s_objet_argument_2);
1357:
1358: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1359: return;
1360: }
1361:
1362: free(chaine);
1363: EVP_MD_CTX_cleanup(&contexte);
1364:
1365: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
1366: {
1367: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1368: return;
1369: }
1370:
1371: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
1372: somme, longueur_somme)) == NULL)
1373: {
1374: liberation(s_etat_processus, s_objet_argument_1);
1375: liberation(s_etat_processus, s_objet_argument_2);
1376:
1377: return;
1378: }
1379: }
1380: else if (((*s_objet_argument_1).type == LST) &&
1381: ((*s_objet_argument_2).type == CHN))
1382: {
1383: l_element_courant = (*s_objet_argument_1).objet;
1384:
1385: if ((*(*l_element_courant).donnee).type != CHN)
1386: {
1387: liberation(s_etat_processus, s_objet_argument_1);
1388: liberation(s_etat_processus, s_objet_argument_2);
1389:
1390: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1391: return;
1392: }
1393:
1394: l_element_courant = (*l_element_courant).suivant;
1395:
1396: if (l_element_courant == NULL)
1397: {
1398: liberation(s_etat_processus, s_objet_argument_1);
1399: liberation(s_etat_processus, s_objet_argument_2);
1400:
1401: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1402: return;
1403: }
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: if ((*l_element_courant).suivant != NULL)
1415: {
1416: liberation(s_etat_processus, s_objet_argument_1);
1417: liberation(s_etat_processus, s_objet_argument_2);
1418:
1419: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1420: return;
1421: }
1422:
1423: // Test du type de somme de contrôle
1424: // - les sommes classiques suivent la RFC 2104
1425: // - les autres sont formées sur des algorithmes de type CBC
1426:
1427: l_element_courant = (*s_objet_argument_1).objet;
1428:
1429: if ((fonction = conversion_majuscule((unsigned char *)
1430: (*(*l_element_courant).donnee).objet)) == NULL)
1431: {
1432: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1433: return;
1434: }
1435:
1436: somme_invalide = d_faux;
1437:
1438: switch(fonction[0])
1439: {
1440: case 'D':
1441: {
1442: switch(fonction[1])
1443: {
1444: case 'S': // ds
1445: {
1446: switch(fonction[2])
1447: {
1448: # ifndef OPENSSL_NO_SHA
1449: case 'S': // dss
1450: {
1451: switch(fonction[3])
1452: {
1453: case d_code_fin_chaine:
1454: {
1455: EVP_sum = EVP_dss();
1456: longueur_bloc = SHA_CBLOCK;
1457: break;
1458: }
1459:
1460: case '1': // dss1
1461: {
1462: if (fonction[4] == d_code_fin_chaine)
1463: {
1464: EVP_sum = EVP_dss1();
1465: longueur_bloc = SHA_CBLOCK;
1466: }
1467: else
1468: {
1469: somme_invalide = d_vrai;
1470: }
1471:
1472: break;
1473: }
1474:
1475: default:
1476: {
1477: somme_invalide = d_vrai;
1478: break;
1479: }
1480: }
1481:
1482: break;
1483: }
1484: # endif
1485:
1486: default:
1487: {
1488: somme_invalide = d_vrai;
1489: break;
1490: }
1491: }
1492:
1493: break;
1494: }
1495:
1496: default:
1497: {
1498: somme_invalide = d_vrai;
1499: break;
1500: }
1501: }
1502:
1503: break;
1504: }
1505:
1506: case 'E':
1507: {
1508: switch(fonction[1])
1509: {
1510: case 'C': // ec
1511: {
1512: switch(fonction[2])
1513: {
1514: case 'D': // ecd
1515: {
1516: switch(fonction[3])
1517: {
1518: case 'S': // ecds
1519: {
1520: switch(fonction[4])
1521: {
1522: # ifndef OPENSSL_NO_SHA
1523: case 'A': // ecdsa
1524: {
1525: if (fonction[5] ==
1526: d_code_fin_chaine)
1527: {
1528: EVP_sum = EVP_ecdsa();
1529: longueur_bloc = SHA_CBLOCK;
1530: }
1531: else
1532: {
1533: somme_invalide = d_vrai;
1534: }
1535:
1536: break;
1537: }
1538: # endif
1539:
1540: default:
1541: {
1542: somme_invalide = d_vrai;
1543: break;
1544: }
1545: }
1546:
1547: break;
1548: }
1549:
1550: default:
1551: {
1552: somme_invalide = d_vrai;
1553: break;
1554: }
1555: }
1556:
1557: break;
1558: }
1559:
1560: default:
1561: {
1562: somme_invalide = d_vrai;
1563: break;
1564: }
1565: }
1566:
1567: break;
1568: }
1569:
1570: default:
1571: {
1572: somme_invalide = d_vrai;
1573: break;
1574: }
1575: }
1576:
1577: break;
1578: }
1579:
1580: case 'M':
1581: {
1582: switch(fonction[1])
1583: {
1584: case 'D': // md
1585: {
1586: switch(fonction[2])
1587: {
1588: # ifndef OPENSSL_NO_MD2
1589: case '2': // md2
1590: {
1591: if (fonction[3] == d_code_fin_chaine)
1592: {
1593: EVP_sum = EVP_md2();
1594: longueur_bloc = MD2_BLOCK;
1595: }
1596: else
1597: {
1598: somme_invalide = d_vrai;
1599: }
1600:
1601: break;
1602: }
1603: # endif
1604:
1605: # ifndef OPENSSL_NO_MD4
1606: case '4': // md4
1607: {
1608: if (fonction[3] == d_code_fin_chaine)
1609: {
1610: EVP_sum = EVP_md4();
1611: longueur_bloc = MD4_CBLOCK;
1612: }
1613: else
1614: {
1615: somme_invalide = d_vrai;
1616: }
1617:
1618: break;
1619: }
1620: # endif
1621:
1622: # ifndef OPENSSL_NO_MD5
1623: case '5': // md5
1624: {
1625: if (fonction[3] == d_code_fin_chaine)
1626: {
1627: EVP_sum = EVP_md5();
1628: longueur_bloc = MD5_CBLOCK;
1629: }
1630: else
1631: {
1632: somme_invalide = d_vrai;
1633: }
1634:
1635: break;
1636: }
1637: # endif
1638:
1639: case 'C': // mdc
1640: {
1641: switch(fonction[3])
1642: {
1643: # ifndef OPENSSL_NO_MDC2
1644: case '2': // mdc2
1645: {
1646: if (fonction[4] == d_code_fin_chaine)
1647: {
1648: EVP_sum = EVP_mdc2();
1649: longueur_bloc = MDC2_BLOCK;
1650: }
1651: else
1652: {
1653: somme_invalide = d_vrai;
1654: }
1655:
1656: break;
1657: }
1658: # endif
1659:
1660: default:
1661: {
1662: somme_invalide = d_vrai;
1663: break;
1664: }
1665: }
1666:
1667: break;
1668: }
1669:
1670: default:
1671: {
1672: somme_invalide = d_vrai;
1673: break;
1674: }
1675: }
1676:
1677: break;
1678: }
1679:
1680: default:
1681: {
1682: somme_invalide = d_vrai;
1683: break;
1684: }
1685: }
1686:
1687: break;
1688: }
1689:
1690: # ifndef OPENSSL_NO_RIPEMD
1691: case 'R':
1692: {
1693: if (strcmp(fonction, "RIPEMD160") == 0)
1694: {
1695: EVP_sum = EVP_ripemd160();
1696: longueur_bloc = RIPEMD160_CBLOCK;
1697: }
1698: else
1699: {
1700: somme_invalide = d_vrai;
1701: }
1702:
1703: break;
1704: }
1705: # endif
1706:
1707: case 'S':
1708: {
1709: switch(fonction[1])
1710: {
1711: case 'H': // sh
1712: {
1713: switch(fonction[2])
1714: {
1715: # ifndef OPENSSL_NO_SHA
1716: case 'A':
1717: {
1718: switch(fonction[3])
1719: {
1720: case d_code_fin_chaine:
1721: {
1722: EVP_sum = EVP_sha();
1723: longueur_bloc = SHA_CBLOCK;
1724: break;
1725: }
1726:
1727: case '1': // sha1
1728: {
1729: if (fonction[4] == d_code_fin_chaine)
1730: {
1731: EVP_sum = EVP_sha1();
1732: longueur_bloc = SHA_CBLOCK;
1733: }
1734: else
1735: {
1736: somme_invalide = d_vrai;
1737: }
1738:
1739: break;
1740: }
1741:
1742: # ifndef OPENSSL_NO_SHA256
1743: case '2': // sha2
1744: {
1745: switch(fonction[4])
1746: {
1747: case '2': // sha22
1748: {
1749: switch(fonction[5])
1750: {
1751: case '4': // sha224
1752: {
1753: if (fonction[6] ==
1754: d_code_fin_chaine)
1755: {
1756: EVP_sum =
1757: EVP_sha224();
1758: longueur_bloc =
1759: SHA256_CBLOCK;
1760: }
1761: else
1762: {
1763: somme_invalide =
1764: d_vrai;
1765: }
1766:
1767: break;
1768: }
1769:
1770: default:
1771: {
1772: somme_invalide = d_vrai;
1773: break;
1774: }
1775: }
1776:
1777: break;
1778: }
1779:
1780: case '5':
1781: {
1782: switch(fonction[5])
1783: {
1784: case '6': // sha256
1785: {
1786: if (fonction[6] ==
1787: d_code_fin_chaine)
1788: {
1789: EVP_sum =
1790: EVP_sha256();
1791: longueur_bloc =
1792: SHA256_CBLOCK;
1793: }
1794: else
1795: {
1796: somme_invalide =
1797: d_vrai;
1798: }
1799:
1800: break;
1801: }
1802:
1803: default:
1804: {
1805: somme_invalide = d_vrai;
1806: break;
1807: }
1808: }
1809:
1810: break;
1811: }
1812:
1813: default:
1814: {
1815: somme_invalide = d_vrai;
1816: break;
1817: }
1818: }
1819:
1820: break;
1821: }
1822: # endif
1823:
1824: # ifndef OPENSSL_NO_SHA512
1825: case '3': // sha3
1826: {
1827: switch(fonction[4])
1828: {
1829: case '8': // sha38
1830: {
1831: switch(fonction[5])
1832: {
1833: case '4': // sha384
1834: {
1835: if (fonction[6] ==
1836: d_code_fin_chaine)
1837: {
1838: EVP_sum =
1839: EVP_sha384();
1840: longueur_bloc =
1841: SHA512_CBLOCK;
1842: }
1843: else
1844: {
1845: somme_invalide =
1846: d_vrai;
1847: }
1848:
1849: break;
1850: }
1851:
1852: default:
1853: {
1854: somme_invalide = d_vrai;
1855: break;
1856: }
1857: }
1858:
1859: break;
1860: }
1861:
1862: default:
1863: {
1864: somme_invalide = d_vrai;
1865: break;
1866: }
1867: }
1868:
1869: break;
1870: }
1871:
1872: case '5': // sha5
1873: {
1874: switch(fonction[4])
1875: {
1876: case '1': // sha51
1877: {
1878: switch(fonction[5])
1879: {
1880: case '2': // sha512
1881: {
1882: if (fonction[6] ==
1883: d_code_fin_chaine)
1884: {
1885: EVP_sum =
1886: EVP_sha512();
1887: longueur_bloc =
1888: SHA512_CBLOCK;
1889: }
1890: else
1891: {
1892: somme_invalide =
1893: d_vrai;
1894: }
1895:
1896: break;
1897: }
1898:
1899: default:
1900: {
1901: somme_invalide = d_vrai;
1902: break;
1903: }
1904: }
1905:
1906: break;
1907: }
1908:
1909: default:
1910: {
1911: somme_invalide = d_vrai;
1912: break;
1913: }
1914: }
1915:
1916: break;
1917: }
1918: # endif
1919:
1920: default:
1921: {
1922: somme_invalide = d_vrai;
1923: break;
1924: }
1925: }
1926:
1927: break;
1928: }
1929: # endif
1930:
1931: default:
1932: {
1933: somme_invalide = d_vrai;
1934: break;
1935: }
1936: }
1937:
1938: break;
1939: }
1940:
1941: default:
1942: {
1943: somme_invalide = d_vrai;
1944: break;
1945: }
1946: }
1947:
1948: break;
1949: }
1950:
1951: # ifndef OPENSSL_NO_WHIRLPOOL
1952: case 'W':
1953: {
1954: if (strcmp(fonction, "WHIRLPOOL") == 0)
1955: {
1956: EVP_sum = EVP_whirlpool();
1957: longueur_bloc = WHIRLPOOL_BBLOCK / 8;
1958: }
1959: else
1960: {
1961: somme_invalide = d_vrai;
1962: }
1963:
1964: break;
1965: }
1966: # endif
1967:
1968: default:
1969: {
1970: somme_invalide = d_vrai;
1971: break;
1972: }
1973: }
1974:
1975: if (somme_invalide == d_vrai)
1976: {
1977: // Le chiffrement est de type CBC-MAC
1978:
1979: /*
1980: * const EVP_CIPHER *EVP_des_cbc(void);
1981: * const EVP_CIPHER *EVP_des_ede_cbc(void);
1982: * const EVP_CIPHER *EVP_des_ede3_cbc(void);
1983: * const EVP_CIPHER *EVP_desx_cbc(void);
1984: * const EVP_CIPHER *EVP_dev_crypto_des_ede3_cbc(void);
1985: * const EVP_CIPHER *EVP_idea_cbc(void);
1986: * const EVP_CIPHER *EVP_rc2_cbc(void);
1987: * const EVP_CIPHER *EVP_rc2_40_cbc(void);
1988: * const EVP_CIPHER *EVP_rc2_64_cbc(void);
1989: * const EVP_CIPHER *EVP_bf_cbc(void);
1990: * const EVP_CIPHER *EVP_cast5_cbc(void);
1991: * const EVP_CIPHER *EVP_rc5_32_12_16_cbc(void);
1992: * const EVP_CIPHER *EVP_aes_128_cbc(void);
1993: * const EVP_CIPHER *EVP_aes_192_cbc(void);
1994: * const EVP_CIPHER *EVP_aes_256_cbc(void);
1995: * const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void);
1996: * const EVP_CIPHER *EVP_aes_256_cbc_hmac_sha1(void);
1997: * const EVP_CIPHER *EVP_camellia_128_cbc(void);
1998: * const EVP_CIPHER *EVP_camellia_192_cbc(void);
1999: * const EVP_CIPHER *EVP_camellia_256_cbc(void);
2000: * const EVP_CIPHER *EVP_seed_cbc(void);
2001: */
2002:
2003: if (strncmp(fonction, "AES", 3) == 0)
2004: {
2005: # ifdef OPENSSL_NO_AES
2006: free(fonction);
2007:
2008: liberation(s_etat_processus, s_objet_argument_1);
2009: liberation(s_etat_processus, s_objet_argument_2);
2010:
2011: (*s_etat_processus).erreur_execution =
2012: d_ex_chiffrement_indisponible;
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:
2045: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
2046: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
2047: {
2048: free(fonction);
2049:
2050: liberation(s_etat_processus, s_objet_argument_1);
2051: liberation(s_etat_processus, s_objet_argument_2);
2052:
2053: return;
2054: }
2055:
2056: l_element_courant = (*s_objet_argument_1).objet;
2057: l_element_courant = (*l_element_courant).suivant;
2058:
2059: if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
2060: (*(*l_element_courant).donnee).objet, &longueur_clef))
2061: == NULL)
2062: {
2063: free(fonction);
2064: free(chaine);
2065:
2066: liberation(s_etat_processus, s_objet_argument_1);
2067: liberation(s_etat_processus, s_objet_argument_2);
2068: return;
2069: }
2070:
2071: if (longueur_clef != longueur_clef_attendue)
2072: {
2073: free(fonction);
2074: free(chaine);
2075: free(clef);
2076:
2077: liberation(s_etat_processus, s_objet_argument_1);
2078: liberation(s_etat_processus, s_objet_argument_2);
2079:
2080: (*s_etat_processus).erreur_execution =
2081: d_ex_longueur_clef_chiffrement;
2082: return;
2083: }
2084:
2085: if ((vecteur_initialisation = malloc(longueur_clef *
2086: sizeof(unsigned char))) == NULL)
2087: {
2088: (*s_etat_processus).erreur_systeme =
2089: d_es_allocation_memoire;
2090: return;
2091: }
2092:
2093: memset(vecteur_initialisation, 0, longueur_clef);
2094:
2095: if ((tampon = chiffrement(EVP_chiffrement, d_vrai,
2096: chaine, longueur_chaine, clef, longueur_clef,
2097: vecteur_initialisation, longueur_clef,
2098: longueur_somme, &longueur_tampon)) == NULL)
2099: {
2100: free(fonction);
2101: free(vecteur_initialisation);
2102: free(chaine);
2103: free(clef);
2104:
2105: (*s_etat_processus).erreur_execution =
2106: d_ex_chiffrement;
2107: return;
2108: }
2109:
2110: free(vecteur_initialisation);
2111: free(chaine);
2112: free(clef);
2113:
2114: if ((s_objet_resultat = allocation(s_etat_processus, CHN))
2115: == NULL)
2116: {
2117: (*s_etat_processus).erreur_systeme =
2118: d_es_allocation_memoire;
2119: return;
2120: }
2121:
2122: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
2123: &(tampon[longueur_tampon - longueur_somme]),
2124: longueur_somme)) == NULL)
2125: {
2126: free(tampon);
2127: free(fonction);
2128:
2129: liberation(s_etat_processus, s_objet_argument_1);
2130: liberation(s_etat_processus, s_objet_argument_2);
2131: return;
2132: }
2133:
2134: free(tampon);
2135:
2136: # endif
2137: }
2138: else
2139: {
2140: free(fonction);
2141:
2142: liberation(s_etat_processus, s_objet_argument_1);
2143: liberation(s_etat_processus, s_objet_argument_2);
2144:
2145: (*s_etat_processus).erreur_execution =
2146: d_ex_chiffrement_indisponible;
2147: return;
2148: }
2149:
2150: free(fonction);
2151: }
2152: else
2153: {
2154: // Le chiffrement est de type HMAC
2155: // Le second élément de la chaîne contient la clef utilisée pour
2156: // la signature.
2157:
2158: free(fonction);
2159:
2160: l_element_courant = (*s_objet_argument_1).objet;
2161: l_element_courant = (*l_element_courant).suivant;
2162:
2163: if ((clef = formateur_flux(s_etat_processus, (unsigned char *)
2164: (*(*l_element_courant).donnee).objet, &longueur_clef))
2165: == NULL)
2166: {
2167: liberation(s_etat_processus, s_objet_argument_1);
2168: liberation(s_etat_processus, s_objet_argument_2);
2169: return;
2170: }
2171:
2172: if (longueur_clef < longueur_bloc)
2173: {
2174: longueur_tampon = longueur_clef;
2175: tampon = clef;
2176:
2177: if ((clef = malloc(longueur_bloc * sizeof(unsigned char)))
2178: == NULL)
2179: {
2180: (*s_etat_processus).erreur_systeme =
2181: d_es_allocation_memoire;
2182: return;
2183: }
2184:
2185: memset(clef, 0, longueur_bloc);
2186: memcpy(clef, tampon, longueur_tampon);
2187: longueur_clef = longueur_bloc;
2188: free(tampon);
2189: }
2190: else if (longueur_clef > longueur_bloc)
2191: {
2192: longueur_tampon = longueur_clef;
2193: tampon = clef;
2194:
2195: if ((clef = malloc(longueur_bloc * sizeof(unsigned char)))
2196: == NULL)
2197: {
2198: (*s_etat_processus).erreur_systeme =
2199: d_es_allocation_memoire;
2200: return;
2201: }
2202:
2203: memcpy(clef, tampon, longueur_bloc);
2204: longueur_clef = longueur_bloc;
2205: free(tampon);
2206: }
2207:
2208: for(i = 0; i < longueur_bloc; i++)
2209: {
2210: clef[i] ^= 0x36;
2211: }
2212:
2213: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
2214: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
2215: {
2216: EVP_MD_CTX_cleanup(&contexte);
2217:
2218: liberation(s_etat_processus, s_objet_argument_1);
2219: liberation(s_etat_processus, s_objet_argument_2);
2220:
2221: return;
2222: }
2223:
2224: if ((tampon = malloc((longueur_bloc + longueur_chaine) *
2225: sizeof(unsigned char))) == NULL)
2226: {
2227: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2228: return;
2229: }
2230:
2231: memcpy(tampon, clef, longueur_bloc);
2232: memcpy(tampon + longueur_bloc, chaine, longueur_chaine);
2233: longueur_tampon = longueur_bloc + longueur_chaine;
2234:
2235: if (EVP_DigestInit(&contexte, EVP_sum) != 1)
2236: {
2237: free(tampon);
2238: free(clef);
2239: free(chaine);
2240:
2241: EVP_MD_CTX_cleanup(&contexte);
2242:
2243: liberation(s_etat_processus, s_objet_argument_1);
2244: liberation(s_etat_processus, s_objet_argument_2);
2245:
2246: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2247: return;
2248: }
2249:
2250: if (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1)
2251: {
2252: free(tampon);
2253: free(clef);
2254: free(chaine);
2255:
2256: EVP_MD_CTX_cleanup(&contexte);
2257:
2258: liberation(s_etat_processus, s_objet_argument_1);
2259: liberation(s_etat_processus, s_objet_argument_2);
2260:
2261: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2262: return;
2263: }
2264:
2265: free(tampon);
2266:
2267: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
2268: {
2269: free(chaine);
2270: EVP_MD_CTX_cleanup(&contexte);
2271:
2272: liberation(s_etat_processus, s_objet_argument_1);
2273: liberation(s_etat_processus, s_objet_argument_2);
2274:
2275: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2276: return;
2277: }
2278:
2279: EVP_MD_CTX_cleanup(&contexte);
2280:
2281: for(i = 0; i < longueur_bloc; i++)
2282: {
2283: clef[i] ^= (0x36 ^ 0x5c);
2284: }
2285:
2286: if ((tampon = malloc((longueur_bloc + longueur_somme) *
2287: sizeof(unsigned char))) == NULL)
2288: {
2289: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2290: return;
2291: }
2292:
2293: memcpy(tampon, clef, longueur_bloc);
2294: memcpy(tampon + longueur_bloc, somme, longueur_somme);
2295: longueur_tampon = longueur_bloc + longueur_somme;
2296:
2297: if (EVP_DigestInit(&contexte, EVP_sum) != 1)
2298: {
2299: free(tampon);
2300: free(clef);
2301: free(chaine);
2302:
2303: EVP_MD_CTX_cleanup(&contexte);
2304:
2305: liberation(s_etat_processus, s_objet_argument_1);
2306: liberation(s_etat_processus, s_objet_argument_2);
2307:
2308: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2309: return;
2310: }
2311:
2312: if (EVP_DigestUpdate(&contexte, tampon, longueur_tampon) != 1)
2313: {
2314: free(tampon);
2315: free(clef);
2316: free(chaine);
2317:
2318: EVP_MD_CTX_cleanup(&contexte);
2319:
2320: liberation(s_etat_processus, s_objet_argument_1);
2321: liberation(s_etat_processus, s_objet_argument_2);
2322:
2323: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2324: return;
2325: }
2326:
2327: free(tampon);
2328:
2329: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
2330: {
2331: free(chaine);
2332: EVP_MD_CTX_cleanup(&contexte);
2333:
2334: liberation(s_etat_processus, s_objet_argument_1);
2335: liberation(s_etat_processus, s_objet_argument_2);
2336:
2337: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
2338: return;
2339: }
2340:
2341: EVP_MD_CTX_cleanup(&contexte);
2342:
2343: free(chaine);
2344: free(clef);
2345:
2346: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
2347: {
2348: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
2349: return;
2350: }
2351:
2352: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
2353: somme, longueur_somme)) == NULL)
2354: {
2355: liberation(s_etat_processus, s_objet_argument_1);
2356: liberation(s_etat_processus, s_objet_argument_2);
2357:
2358: return;
2359: }
2360: }
2361: }
2362: else
2363: {
2364: liberation(s_etat_processus, s_objet_argument_1);
2365: liberation(s_etat_processus, s_objet_argument_2);
2366:
2367: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
2368: return;
2369: }
2370:
2371: liberation(s_etat_processus, s_objet_argument_1);
2372: liberation(s_etat_processus, s_objet_argument_2);
2373:
2374: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
2375: s_objet_resultat) == d_erreur)
2376: {
2377: return;
2378: }
2379:
2380: return;
2381: }
2382:
2383: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>