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