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:
612: logical1 somme_invalide;
613:
614: long longueur_chaine;
615:
616: struct_objet *s_objet_argument_1;
617: struct_objet *s_objet_argument_2;
618: struct_objet *s_objet_resultat;
619:
620: unsigned char *chaine;
621: unsigned char *fonction;
622: unsigned char somme[EVP_MAX_MD_SIZE];
623:
624: unsigned int longueur_somme;
625:
626: (*s_etat_processus).erreur_execution = d_ex;
627:
628: if ((*s_etat_processus).affichage_arguments == 'Y')
629: {
630: printf("\n DIGEST ");
631:
632: if ((*s_etat_processus).langue == 'F')
633: {
634: printf("(somme d'authentification)\n\n");
635: }
636: else
637: {
638: printf("(hash algorithm)\n\n");
639: }
640:
641: printf(" 2: %s\n", d_CHN);
642: printf(" 1: %s\n", d_CHN);
643: printf("-> 1: %s\n\n", d_CHN);
644:
645: printf(" 2: %s\n", d_CHN);
646: printf(" 1: %s\n", d_LST);
647: printf("-> 1: %s\n\n", d_CHN);
648:
649: if ((*s_etat_processus).langue == 'F')
650: {
651: printf(" Algorithmes :\n\n");
652: }
653: else
654: {
655: printf(" Algorithms:\n\n");
656: }
657:
658: # ifndef OPENSSL_NO_SHA
659: printf(" - DSS\n");
660: printf(" - DSS1\n");
661: printf(" - ECDSA\n");
662: # endif
663: # ifndef OPENSSL_NO_MD2
664: printf(" - MD2\n");
665: # endif
666: # ifndef OPENSSL_NO_MD4
667: printf(" - MD4\n");
668: # endif
669: # ifndef OPENSSL_NO_MD5
670: printf(" - MD5\n");
671: # endif
672: # ifndef OPENSSL_NO_SHA
673: printf(" - SHA\n");
674: printf(" - SHA1\n");
675: # endif
676:
677: return;
678: }
679: else if ((*s_etat_processus).test_instruction == 'Y')
680: {
681: (*s_etat_processus).nombre_arguments = -1;
682: return;
683: }
684:
685: if (test_cfsf(s_etat_processus, 31) == d_vrai)
686: {
687: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
688: {
689: return;
690: }
691: }
692:
693: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
694: &s_objet_argument_1) == d_erreur)
695: {
696: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
697: return;
698: }
699:
700: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
701: &s_objet_argument_2) == d_erreur)
702: {
703: liberation(s_etat_processus, s_objet_argument_1);
704:
705: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
706: return;
707: }
708:
709: if (((*s_objet_argument_1).type == CHN) &&
710: ((*s_objet_argument_2).type == CHN))
711: {
712: // Liste des sommes disponibles :
713: // - EVP_dss
714: // - EVP_dss1
715: // - EVP_ecdsa
716: // - EVP_md2
717: // - EVP_md4
718: // - EVP_md5
719: // - EVP_mdc2
720: // - EVP_ripemd160
721: // - EVP_sha
722: // - EVP_sha1
723: // - EVP_sha224
724: // - EVP_sha256
725: // - EVP_sha384
726: // - EVP_sha512
727: // - EVP_whirlpool
728:
729: if ((fonction = conversion_majuscule((unsigned char *)
730: (*s_objet_argument_1).objet)) == NULL)
731: {
732: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
733: return;
734: }
735:
736: somme_invalide = d_faux;
737:
738: switch(fonction[0])
739: {
740: case 'D':
741: {
742: switch(fonction[1])
743: {
744: case 'S': // ds
745: {
746: switch(fonction[2])
747: {
748: # ifndef OPENSSL_NO_SHA
749: case 'S': // dss
750: {
751: switch(fonction[3])
752: {
753: case d_code_fin_chaine:
754: {
755: EVP_sum = EVP_dss;
756: break;
757: }
758:
759: case '1': // dss1
760: {
761: if (fonction[4] == d_code_fin_chaine)
762: {
763: EVP_sum = EVP_dss1;
764: }
765: else
766: {
767: somme_invalide = d_vrai;
768: }
769:
770: break;
771: }
772:
773: default:
774: {
775: somme_invalide = d_vrai;
776: break;
777: }
778: }
779:
780: break;
781: }
782: # endif
783:
784: default:
785: {
786: somme_invalide = d_vrai;
787: break;
788: }
789: }
790:
791: break;
792: }
793:
794: default:
795: {
796: somme_invalide = d_vrai;
797: break;
798: }
799: }
800:
801: break;
802: }
803:
804: case 'E':
805: {
806: switch(fonction[1])
807: {
808: case 'C': // ec
809: {
810: switch(fonction[2])
811: {
812: case 'D': // ecd
813: {
814: switch(fonction[3])
815: {
816: case 'S': // ecds
817: {
818: switch(fonction[4])
819: {
820: # ifndef OPENSSL_NO_SHA
821: case 'A': // ecdsa
822: {
823: if (fonction[5] ==
824: d_code_fin_chaine)
825: {
826: EVP_sum = EVP_ecdsa;
827: }
828: else
829: {
830: somme_invalide = d_vrai;
831: }
832:
833: break;
834: }
835: # endif
836:
837: default:
838: {
839: somme_invalide = d_vrai;
840: break;
841: }
842: }
843:
844: break;
845: }
846:
847: default:
848: {
849: somme_invalide = d_vrai;
850: break;
851: }
852: }
853:
854: break;
855: }
856:
857: default:
858: {
859: somme_invalide = d_vrai;
860: break;
861: }
862: }
863:
864: break;
865: }
866:
867: default:
868: {
869: somme_invalide = d_vrai;
870: break;
871: }
872: }
873:
874: break;
875: }
876:
877: case 'M':
878: {
879: switch(fonction[1])
880: {
881: case 'D': // md
882: {
883: switch(fonction[2])
884: {
885: # ifndef OPENSSL_NO_MD2
886: case '2': // md2
887: {
888: if (fonction[3] == d_code_fin_chaine)
889: {
890: EVP_sum = EVP_md2;
891: }
892: else
893: {
894: somme_invalide = d_vrai;
895: }
896:
897: break;
898: }
899: # endif
900:
901: # ifndef OPENSSL_NO_MD4
902: case '4': // md4
903: {
904: if (fonction[3] == d_code_fin_chaine)
905: {
906: EVP_sum = EVP_md4;
907: }
908: else
909: {
910: somme_invalide = d_vrai;
911: }
912:
913: break;
914: }
915: # endif
916:
917: # ifndef OPENSSL_NO_MD4
918: case '5': // md5
919: {
920: if (fonction[3] == d_code_fin_chaine)
921: {
922: EVP_sum = EVP_md5;
923: }
924: else
925: {
926: somme_invalide = d_vrai;
927: }
928:
929: break;
930: }
931: # endif
932:
933: case 'C': // mdc
934: {
935: switch(fonction[3])
936: {
937: # ifndef OPENSSL_NO_MDC2
938: case '2': // mdc2
939: {
940: if (fonction[4] == d_code_fin_chaine)
941: {
942: EVP_sum = EVP_mdc2;
943: }
944: else
945: {
946: somme_invalide = d_vrai;
947: }
948:
949: break;
950: }
951: # endif
952:
953: default:
954: {
955: somme_invalide = d_vrai;
956: break;
957: }
958: }
959:
960: break;
961: }
962:
963: default:
964: {
965: somme_invalide = d_vrai;
966: break;
967: }
968: }
969:
970: break;
971: }
972:
973: default:
974: {
975: somme_invalide = d_vrai;
976: break;
977: }
978: }
979:
980: break;
981: }
982:
983: # ifndef OPENSSL_NO_RIPEMD
984: case 'R':
985: {
986: if (strcmp(fonction, "RIPEMD160") == 0)
987: {
988: EVP_sum = EVP_ripemd160;
989: }
990: else
991: {
992: somme_invalide = d_vrai;
993: }
994:
995: break;
996: }
997: # endif
998:
999: case 'S':
1000: {
1001: switch(fonction[1])
1002: {
1003: case 'H': // sh
1004: {
1005: switch(fonction[2])
1006: {
1007: # ifndef OPENSSL_NO_SHA
1008: case 'A':
1009: {
1010: switch(fonction[3])
1011: {
1012: case d_code_fin_chaine:
1013: {
1014: EVP_sum = EVP_sha;
1015: break;
1016: }
1017:
1018: case '1': // sha1
1019: {
1020: if (fonction[4] == d_code_fin_chaine)
1021: {
1022: EVP_sum = EVP_sha1;
1023: }
1024: else
1025: {
1026: somme_invalide = d_vrai;
1027: }
1028:
1029: break;
1030: }
1031:
1032: # ifndef OPENSSL_NO_SHA256
1033: case '2': // sha2
1034: {
1035: switch(fonction[4])
1036: {
1037: case '2': // sha22
1038: {
1039: switch(fonction[5])
1040: {
1041: case '4': // sha224
1042: {
1043: if (fonction[6] ==
1044: d_code_fin_chaine)
1045: {
1046: EVP_sum =
1047: EVP_sha224;
1048: }
1049: else
1050: {
1051: somme_invalide =
1052: d_vrai;
1053: }
1054:
1055: break;
1056: }
1057:
1058: default:
1059: {
1060: somme_invalide = d_vrai;
1061: break;
1062: }
1063: }
1064:
1065: break;
1066: }
1067:
1068: case '5':
1069: {
1070: switch(fonction[5])
1071: {
1072: case '6': // sha256
1073: {
1074: if (fonction[6] ==
1075: d_code_fin_chaine)
1076: {
1077: EVP_sum =
1078: EVP_sha256;
1079: }
1080: else
1081: {
1082: somme_invalide =
1083: d_vrai;
1084: }
1085:
1086: break;
1087: }
1088:
1089: default:
1090: {
1091: somme_invalide = d_vrai;
1092: break;
1093: }
1094: }
1095:
1096: break;
1097: }
1098:
1099: default:
1100: {
1101: somme_invalide = d_vrai;
1102: break;
1103: }
1104: }
1105:
1106: break;
1107: }
1108: # endif
1109:
1110: # ifndef OPENSSL_NO_SHA512
1111: case '3': // sha3
1112: {
1113: switch(fonction[4])
1114: {
1115: case '8': // sha38
1116: {
1117: switch(fonction[5])
1118: {
1119: case '4': // sha384
1120: {
1121: if (fonction[6] ==
1122: d_code_fin_chaine)
1123: {
1124: EVP_sum =
1125: EVP_sha384;
1126: }
1127: else
1128: {
1129: somme_invalide =
1130: d_vrai;
1131: }
1132:
1133: break;
1134: }
1135:
1136: default:
1137: {
1138: somme_invalide = d_vrai;
1139: break;
1140: }
1141: }
1142:
1143: break;
1144: }
1145:
1146: default:
1147: {
1148: somme_invalide = d_vrai;
1149: break;
1150: }
1151: }
1152:
1153: break;
1154: }
1155:
1156: case '5': // sha5
1157: {
1158: switch(fonction[4])
1159: {
1160: case '1': // sha51
1161: {
1162: switch(fonction[5])
1163: {
1164: case '2': // sha512
1165: {
1166: if (fonction[6] ==
1167: d_code_fin_chaine)
1168: {
1169: EVP_sum =
1170: EVP_sha512;
1171: }
1172: else
1173: {
1174: somme_invalide =
1175: d_vrai;
1176: }
1177:
1178: break;
1179: }
1180:
1181: default:
1182: {
1183: somme_invalide = d_vrai;
1184: break;
1185: }
1186: }
1187:
1188: break;
1189: }
1190:
1191: default:
1192: {
1193: somme_invalide = d_vrai;
1194: break;
1195: }
1196: }
1197:
1198: break;
1199: }
1200: # endif
1201:
1202: default:
1203: {
1204: somme_invalide = d_vrai;
1205: break;
1206: }
1207: }
1208:
1209: break;
1210: }
1211: # endif
1212:
1213: default:
1214: {
1215: somme_invalide = d_vrai;
1216: break;
1217: }
1218: }
1219:
1220: break;
1221: }
1222:
1223: default:
1224: {
1225: somme_invalide = d_vrai;
1226: break;
1227: }
1228: }
1229:
1230: break;
1231: }
1232:
1233: # ifndef OPENSSL_NO_WHIRLPOOL
1234: case 'W':
1235: {
1236: if (strcmp(fonction, "WHIRLPOOL") == 0)
1237: {
1238: EVP_sum = EVP_whirlpool;
1239: }
1240: else
1241: {
1242: somme_invalide = d_vrai;
1243: }
1244:
1245: break;
1246: }
1247: # endif
1248:
1249: default:
1250: {
1251: somme_invalide = d_vrai;
1252: break;
1253: }
1254: }
1255:
1256: free(fonction);
1257:
1258: if (somme_invalide == d_vrai)
1259: {
1260: liberation(s_etat_processus, s_objet_argument_1);
1261: liberation(s_etat_processus, s_objet_argument_2);
1262:
1263: (*s_etat_processus).erreur_execution =
1264: d_ex_chiffrement_indisponible;
1265: return;
1266: }
1267:
1268: if (EVP_DigestInit(&contexte, EVP_sum()) != 1)
1269: {
1270: EVP_MD_CTX_cleanup(&contexte);
1271:
1272: liberation(s_etat_processus, s_objet_argument_1);
1273: liberation(s_etat_processus, s_objet_argument_2);
1274:
1275: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1276: return;
1277: }
1278:
1279: if ((chaine = formateur_flux(s_etat_processus, (unsigned char *)
1280: (*s_objet_argument_2).objet, &longueur_chaine)) == NULL)
1281: {
1282: EVP_MD_CTX_cleanup(&contexte);
1283:
1284: liberation(s_etat_processus, s_objet_argument_1);
1285: liberation(s_etat_processus, s_objet_argument_2);
1286:
1287: return;
1288: }
1289:
1290: if (EVP_DigestUpdate(&contexte, chaine, longueur_chaine) != 1)
1291: {
1292: free(chaine);
1293: EVP_MD_CTX_cleanup(&contexte);
1294:
1295: liberation(s_etat_processus, s_objet_argument_1);
1296: liberation(s_etat_processus, s_objet_argument_2);
1297:
1298: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1299: return;
1300: }
1301:
1302: if (EVP_DigestFinal_ex(&contexte, somme, &longueur_somme) != 1)
1303: {
1304: free(chaine);
1305: EVP_MD_CTX_cleanup(&contexte);
1306:
1307: liberation(s_etat_processus, s_objet_argument_1);
1308: liberation(s_etat_processus, s_objet_argument_2);
1309:
1310: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1311: return;
1312: }
1313:
1314: free(chaine);
1315: EVP_MD_CTX_cleanup(&contexte);
1316:
1317: if ((s_objet_resultat = allocation(s_etat_processus, CHN)) == NULL)
1318: {
1319: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1320: return;
1321: }
1322:
1323: if (((*s_objet_resultat).objet = analyse_flux(s_etat_processus,
1324: somme, longueur_somme)) == NULL)
1325: {
1326: liberation(s_etat_processus, s_objet_argument_1);
1327: liberation(s_etat_processus, s_objet_argument_2);
1328:
1329: return;
1330: }
1331: }
1332: else if (((*s_objet_argument_1).type == CHN) &&
1333: ((*s_objet_argument_2).type == LST))
1334: {
1335: BUG(1, uprintf("Oops\n"));
1336: s_objet_resultat = NULL;
1337: }
1338: else
1339: {
1340: liberation(s_etat_processus, s_objet_argument_1);
1341: liberation(s_etat_processus, s_objet_argument_2);
1342:
1343: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1344: return;
1345: }
1346:
1347: liberation(s_etat_processus, s_objet_argument_1);
1348: liberation(s_etat_processus, s_objet_argument_2);
1349:
1350: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1351: s_objet_resultat) == d_erreur)
1352: {
1353: return;
1354: }
1355:
1356: return;
1357: }
1358:
1359: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>