![]() ![]() | ![]() |
1.1 bertrand 1: /*
2: ================================================================================
1.10 ! bertrand 3: RPL/2 (R) version 4.1.16
1.2 bertrand 4: Copyright (C) 1989-2013 Dr. BERTRAND Joël
1.1 bertrand 5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #include "rpl-conv.h"
24:
25:
26: /*
27: ================================================================================
28: Fonction 'cipher'
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: void
39: instruction_cipher(struct_processus *s_etat_processus)
40: {
41: const EVP_CIPHER *EVP_chiffrement;
42: const EVP_MD *EVP_sum;
43:
1.3 bertrand 44: int longueur_clef;
45:
1.7 bertrand 46: integer8 longueur_clef_binaire;
47: integer8 longueur_iv_binaire;
48: integer8 longueur_message;
49: integer8 longueur_message_chiffre;
1.1 bertrand 50: integer8 nombre_cycles;
51:
1.3 bertrand 52: logical1 encodage;
53: logical1 generation_clef;
1.1 bertrand 54: logical1 somme_invalide;
55:
56: logical8 sel;
57:
58: struct_liste_chainee *l_element_courant;
59:
60: struct_objet *s_objet_argument_1;
61: struct_objet *s_objet_argument_2;
62: struct_objet *s_objet_resultat_1;
63: struct_objet *s_objet_resultat_2;
64:
1.3 bertrand 65: unsigned char *algorithme_chiffrement;
1.1 bertrand 66: unsigned char *clef;
1.3 bertrand 67: unsigned char *clef_binaire;
1.1 bertrand 68: unsigned char *controle;
69: unsigned char *direction;
70: unsigned char *fonction;
71: unsigned char *instruction;
72: unsigned char *iv;
1.3 bertrand 73: unsigned char *iv_binaire;
74: unsigned char *message;
75: unsigned char *message_chiffre;
1.1 bertrand 76: unsigned char *tampon;
77:
78: if ((*s_etat_processus).affichage_arguments == 'Y')
79: {
80: printf("\n CIPHER ");
81:
82: if ((*s_etat_processus).langue == 'F')
83: {
84: printf("(opérations de chiffrement)\n\n");
85: }
86: else
87: {
88: printf("(cryptographic operations)\n\n");
89: }
90:
1.3 bertrand 91: printf(" 2: \"password\"\n", d_CHN);
92: printf(" 1: { \"KEY\" \"cipher type\" \"digest type\" "
93: "salt nround }\n");
94: printf("-> 1: { \"cipher type\" \"generated key\" \"iv\" }\n\n");
1.1 bertrand 95:
1.3 bertrand 96: printf(" 2: \"text\"\n", d_CHN);
97: printf(" 1: %s { \"direction\" \"cipher type\" \"key\" \"iv\" }\n",
1.1 bertrand 98: d_LST);
1.3 bertrand 99: printf("-> 2: \"encrypted or decrypted text\"\n", d_CHN);
100: printf(" 1: { \"direction\" \"cipher type\" \"key\" "
1.1 bertrand 101: "\"updated iv\" }\n\n", d_LST);
102:
103: if ((*s_etat_processus).langue == 'F')
104: {
1.3 bertrand 105: printf(" Algorithmes de chiffrement :\n\n");
106: }
107: else
108: {
109: printf(" Chipher algorithms:\n\n");
110: }
111:
112: # ifndef OPENSSL_NO_AES
113: printf(" - AES-128-CBC\n");
114: printf(" - AES-128-CCM\n");
115: printf(" - AES-128-CFB1\n");
116: printf(" - AES-128-CFB8\n");
117: printf(" - AES-128-CFB128\n");
118: printf(" - AES-128-CTR\n");
119: printf(" - AES-128-ECB\n");
120: printf(" - AES-128-GCM\n");
121: printf(" - AES-128-OFB\n");
122: printf(" - AES-128-XTS\n");
123: printf(" - AES-192-CBC\n");
124: printf(" - AES-192-CCM\n");
125: printf(" - AES-192-CFB1\n");
126: printf(" - AES-192-CFB8\n");
127: printf(" - AES-192-CFB128\n");
128: printf(" - AES-192-CTR\n");
129: printf(" - AES-192-ECB\n");
130: printf(" - AES-192-GCM\n");
131: printf(" - AES-192-OFB\n");
132: printf(" - AES-256-CBC\n");
133: printf(" - AES-256-CCM\n");
134: printf(" - AES-256-CFB1\n");
135: printf(" - AES-256-CFB8\n");
136: printf(" - AES-256-CFB128\n");
137: printf(" - AES-256-CTR\n");
138: printf(" - AES-256-ECB\n");
139: printf(" - AES-256-GCM\n");
140: printf(" - AES-256-OFB\n");
141: printf(" - AES-256-XTS\n");
142: # endif
143:
144: # ifndef OPENSSL_NO_BF
145: printf(" - BF-CBC\n");
146: printf(" - BF-CFB64\n");
147: printf(" - BF-ECB\n");
148: printf(" - BF-OFB\n");
149: # endif
150:
151: # ifndef OPENSSL_NO_CAMELLIA
152: printf(" - CAMELLIA-128-CBC\n");
153: printf(" - CAMELLIA-128-CFB1\n");
154: printf(" - CAMELLIA-128-CFB8\n");
155: printf(" - CAMELLIA-128-CFB128\n");
156: printf(" - CAMELLIA-128-ECB\n");
157: printf(" - CAMELLIA-128-OFB\n");
158: printf(" - CAMELLIA-192-CBC\n");
159: printf(" - CAMELLIA-192-CFB1\n");
160: printf(" - CAMELLIA-192-CFB8\n");
161: printf(" - CAMELLIA-192-CFB128\n");
162: printf(" - CAMELLIA-192-ECB\n");
163: printf(" - CAMELLIA-192-OFB\n");
164: printf(" - CAMELLIA-256-CBC\n");
165: printf(" - CAMELLIA-256-CFB1\n");
166: printf(" - CAMELLIA-256-CFB8\n");
167: printf(" - CAMELLIA-256-CFB128\n");
168: printf(" - CAMELLIA-256-ECB\n");
169: printf(" - CAMELLIA-256-OFB\n");
170: # endif
171:
172: # ifndef OPENSSL_NO_CAST
173: printf(" - CAST5-CBC\n");
174: printf(" - CAST5-ECB\n");
175: printf(" - CAST5-CFB64\n");
176: printf(" - CAST5-OFB\n");
177: # endif
178:
179: # ifndef OPENSSL_NO_DES
180: printf(" - DES-CBC\n");
181: printf(" - DES-CFB1\n");
182: printf(" - DES-CFB8\n");
183: printf(" - DES-CFB64\n");
184: printf(" - DES-ECB\n");
185: printf(" - DES-EDE\n");
186: printf(" - DES-EDE-CBC\n");
187: printf(" - DES-EDE-CFB1\n");
188: printf(" - DES-EDE-CFB8\n");
189: printf(" - DES-EDE-CFB64\n");
190: printf(" - DES-EDE-ECB\n");
191: printf(" - DES-EDE-OFB\n");
192: printf(" - DES-EDE3\n");
193: printf(" - DES-EDE3-CBC\n");
194: printf(" - DES-EDE3-ECB\n");
195: printf(" - DES-EDE3-OFB\n");
196: printf(" - DES-OFB\n");
197: printf(" - DESX-CBC\n");
198: # endif
199:
200: # ifndef OPENSSL_NO_IDEA
201: printf(" - IDEA-CBC\n");
202: printf(" - IDEA-CFB64\n");
203: printf(" - IDEA-ECB\n");
204: printf(" - IDEA-OFB\n");
205: # endif
206:
207: # ifndef OPENSSL_NO_RC2
208: printf(" - RC2-CBC\n");
209: printf(" - RC2-CFB64\n");
210: printf(" - RC2-ECB\n");
211: printf(" - RC2-OFB\n");
212: printf(" - RC2-40-CBC\n");
213: printf(" - RC2-64-CBC\n");
214: # endif
215:
216: # ifndef OPENSSL_NO_RC4
217: printf(" - RC4\n");
218: printf(" - RC4-40\n");
219: # endif
220:
221: # ifndef OPENSSL_NO_RC5
222: printf(" - RC5-32-12-16-CBC\n");
223: printf(" - RC5-32-12-16-CFB64\n");
224: printf(" - RC5-32-12-16-ECB\n");
225: printf(" - RC5-32-12-16-OFB\n");
226: # endif
227:
228: # ifndef OPENSSL_NO_SEED
229: printf(" - SEED-CBC\n");
230: printf(" - SEED-CFB128\n");
231: printf(" - SEED-ECB\n");
232: printf(" - SEED-OFB\n");
233: # endif
234:
235: printf("\n");
236:
237: if ((*s_etat_processus).langue == 'F')
238: {
1.1 bertrand 239: printf(" Algorithmes de signature :\n\n");
240: }
241: else
242: {
243: printf(" Digest algorithms:\n\n");
244: }
245:
246: # ifndef OPENSSL_NO_SHA
247: printf(" - DSS\n");
248: printf(" - DSS1\n");
249: printf(" - ECDSA\n");
250: # endif
251: # ifndef OPENSSL_NO_MD2
252: printf(" - MD2\n");
253: # endif
254: # ifndef OPENSSL_NO_MD4
255: printf(" - MD4\n");
256: # endif
257: # ifndef OPENSSL_NO_MD5
258: printf(" - MD5\n");
259: # endif
260: # ifndef OPENSSL_NO_MDC2
261: printf(" - MDC2\n");
262: # endif
263: # ifndef OPENSSL_NO_RIPEMD
264: printf(" - RIPEMD160\n");
265: # endif
266: # ifndef OPENSSL_NO_SHA
267: printf(" - SHA\n");
268: printf(" - SHA1\n");
269: # endif
270: # ifndef OPENSSL_NO_SHA256
271: printf(" - SHA224\n");
272: printf(" - SHA256\n");
273: # endif
274: # ifndef OPENSSL_NO_SHA512
275: printf(" - SHA384\n");
276: printf(" - SHA512\n");
277: # endif
278: # ifndef OPENSSL_NO_WHIRLPOOL
279: printf(" - WHIRLPOOL\n");
280: # endif
281:
282: printf("\n");
283:
284: if ((*s_etat_processus).langue == 'F')
285: {
286: printf(" Utilisation :\n\n");
287: }
288: else
289: {
290: printf(" Usage:\n\n");
291: }
292:
1.4 bertrand 293: printf(" \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" "
1.3 bertrand 294: "# 0h 3 } CIPHER\n");
295: printf(" \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" "
1.1 bertrand 296: "\"iv\" } CIPHER\n");
1.3 bertrand 297: printf(" \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" "
1.1 bertrand 298: "\"iv\" } CIPHER\n");
299: return;
300: }
301: else if ((*s_etat_processus).test_instruction == 'Y')
302: {
303: (*s_etat_processus).nombre_arguments = -1;
304: return;
305: }
306:
307: if (test_cfsf(s_etat_processus, 31) == d_vrai)
308: {
309: if (empilement_pile_last(s_etat_processus, 2) == d_erreur)
310: {
311: return;
312: }
313: }
314:
315: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
316: &s_objet_argument_1) == d_erreur)
317: {
318: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
319: return;
320: }
321:
322: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
323: &s_objet_argument_2) == d_erreur)
324: {
325: liberation(s_etat_processus, s_objet_argument_1);
326:
327: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
328: return;
329: }
330:
331: if (((*s_objet_argument_1).type == LST) &&
332: ((*s_objet_argument_2).type == CHN))
333: {
334: l_element_courant = (*s_objet_argument_1).objet;
335:
336: if (l_element_courant == NULL)
337: {
338: liberation(s_etat_processus, s_objet_argument_1);
339: liberation(s_etat_processus, s_objet_argument_2);
340:
341: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
342: return;
343: }
344:
345: if ((*(*l_element_courant).donnee).type != CHN)
346: {
347: liberation(s_etat_processus, s_objet_argument_1);
348: liberation(s_etat_processus, s_objet_argument_2);
349:
350: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
351: return;
352: }
353:
354: if ((instruction = conversion_majuscule((unsigned char *)
355: (*(*l_element_courant).donnee).objet)) == NULL)
356: {
357: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
358: return;
359: }
360:
361: if (strcmp(instruction, "KEY") == 0)
362: {
363: // Dérivation d'une clef
364:
365: free(instruction);
366:
367: l_element_courant = (*l_element_courant).suivant;
368:
369: if (l_element_courant == NULL)
370: {
371: liberation(s_etat_processus, s_objet_argument_1);
372: liberation(s_etat_processus, s_objet_argument_2);
373:
374: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
375: return;
376: }
377:
378: // On attend l'algorithme de chiffrement.
379:
380: if ((*(*l_element_courant).donnee).type != CHN)
381: {
382: liberation(s_etat_processus, s_objet_argument_1);
383: liberation(s_etat_processus, s_objet_argument_2);
384:
385: (*s_etat_processus).erreur_execution =
386: d_ex_erreur_type_argument;
387: return;
388: }
389:
1.3 bertrand 390: algorithme_chiffrement = (unsigned char *) (*(*l_element_courant)
1.1 bertrand 391: .donnee).objet;
392:
393: if ((l_element_courant = (*l_element_courant).suivant) == NULL)
394: {
395: liberation(s_etat_processus, s_objet_argument_1);
396: liberation(s_etat_processus, s_objet_argument_2);
397:
398: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
399: return;
400: }
401:
402: // On attend la somme de contrôle.
403:
404: if ((*(*l_element_courant).donnee).type != CHN)
405: {
406: liberation(s_etat_processus, s_objet_argument_1);
407: liberation(s_etat_processus, s_objet_argument_2);
408:
409: (*s_etat_processus).erreur_execution =
410: d_ex_erreur_type_argument;
411: return;
412: }
413:
414: controle = (unsigned char *) (*(*l_element_courant).donnee).objet;
415:
416: // Test de la validité de la somme de contrôle.
417:
418: if ((fonction = conversion_majuscule(controle)) == NULL)
419: {
420: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
421: return;
422: }
423:
424: somme_invalide = d_faux;
425:
426: switch(fonction[0])
427: {
428: case 'D':
429: {
430: switch(fonction[1])
431: {
432: case 'S': // ds
433: {
434: switch(fonction[2])
435: {
436: # ifndef OPENSSL_NO_SHA
437: case 'S': // dss
438: {
439: switch(fonction[3])
440: {
441: case d_code_fin_chaine:
442: {
443: EVP_sum = EVP_dss();
444: break;
445: }
446:
447: case '1': // dss1
448: {
449: if (fonction[4] ==
450: d_code_fin_chaine)
451: {
452: EVP_sum = EVP_dss1();
453: }
454: else
455: {
456: somme_invalide = d_vrai;
457: }
458:
459: break;
460: }
461:
462: default:
463: {
464: somme_invalide = d_vrai;
465: break;
466: }
467: }
468:
469: break;
470: }
471: # endif
472:
473: default:
474: {
475: somme_invalide = d_vrai;
476: break;
477: }
478: }
479:
480: break;
481: }
482:
483: default:
484: {
485: somme_invalide = d_vrai;
486: break;
487: }
488: }
489:
490: break;
491: }
492:
493: case 'E':
494: {
495: switch(fonction[1])
496: {
497: case 'C': // ec
498: {
499: switch(fonction[2])
500: {
501: case 'D': // ecd
502: {
503: switch(fonction[3])
504: {
505: case 'S': // ecds
506: {
507: switch(fonction[4])
508: {
509: # ifndef OPENSSL_NO_SHA
510: case 'A': // ecdsa
511: {
512: if (fonction[5] ==
513: d_code_fin_chaine)
514: {
515: EVP_sum = EVP_ecdsa();
516: }
517: else
518: {
519: somme_invalide = d_vrai;
520: }
521:
522: break;
523: }
524: # endif
525:
526: default:
527: {
528: somme_invalide = d_vrai;
529: break;
530: }
531: }
532:
533: break;
534: }
535:
536: default:
537: {
538: somme_invalide = d_vrai;
539: break;
540: }
541: }
542:
543: break;
544: }
545:
546: default:
547: {
548: somme_invalide = d_vrai;
549: break;
550: }
551: }
552:
553: break;
554: }
555:
556: default:
557: {
558: somme_invalide = d_vrai;
559: break;
560: }
561: }
562:
563: break;
564: }
565:
566: case 'M':
567: {
568: switch(fonction[1])
569: {
570: case 'D': // md
571: {
572: switch(fonction[2])
573: {
574: # ifndef OPENSSL_NO_MD2
575: case '2': // md2
576: {
577: if (fonction[3] == d_code_fin_chaine)
578: {
579: EVP_sum = EVP_md2();
580: }
581: else
582: {
583: somme_invalide = d_vrai;
584: }
585:
586: break;
587: }
588: # endif
589:
590: # ifndef OPENSSL_NO_MD4
591: case '4': // md4
592: {
593: if (fonction[3] == d_code_fin_chaine)
594: {
595: EVP_sum = EVP_md4();
596: }
597: else
598: {
599: somme_invalide = d_vrai;
600: }
601:
602: break;
603: }
604: # endif
605:
606: # ifndef OPENSSL_NO_MD5
607: case '5': // md5
608: {
609: if (fonction[3] == d_code_fin_chaine)
610: {
611: EVP_sum = EVP_md5();
612: }
613: else
614: {
615: somme_invalide = d_vrai;
616: }
617:
618: break;
619: }
620: # endif
621:
622: case 'C': // mdc
623: {
624: switch(fonction[3])
625: {
626: # ifndef OPENSSL_NO_MDC2
627: case '2': // mdc2
628: {
629: if (fonction[4] ==
630: d_code_fin_chaine)
631: {
632: EVP_sum = EVP_mdc2();
633: }
634: else
635: {
636: somme_invalide = d_vrai;
637: }
638:
639: break;
640: }
641: # endif
642:
643: default:
644: {
645: somme_invalide = d_vrai;
646: break;
647: }
648: }
649:
650: break;
651: }
652:
653: default:
654: {
655: somme_invalide = d_vrai;
656: break;
657: }
658: }
659:
660: break;
661: }
662:
663: default:
664: {
665: somme_invalide = d_vrai;
666: break;
667: }
668: }
669:
670: break;
671: }
672:
673: # ifndef OPENSSL_NO_RIPEMD
674: case 'R':
675: {
676: if (strcmp(fonction, "RIPEMD160") == 0)
677: {
678: EVP_sum = EVP_ripemd160();
679: }
680: else
681: {
682: somme_invalide = d_vrai;
683: }
684:
685: break;
686: }
687: # endif
688:
689: case 'S':
690: {
691: switch(fonction[1])
692: {
693: case 'H': // sh
694: {
695: switch(fonction[2])
696: {
697: # ifndef OPENSSL_NO_SHA
698: case 'A':
699: {
700: switch(fonction[3])
701: {
702: case d_code_fin_chaine:
703: {
704: EVP_sum = EVP_sha();
705: break;
706: }
707:
708: case '1': // sha1
709: {
710: if (fonction[4] ==
711: d_code_fin_chaine)
712: {
713: EVP_sum = EVP_sha1();
714: }
715: else
716: {
717: somme_invalide = d_vrai;
718: }
719:
720: break;
721: }
722:
723: # ifndef OPENSSL_NO_SHA256
724: case '2': // sha2
725: {
726: switch(fonction[4])
727: {
728: case '2': // sha22
729: {
730: switch(fonction[5])
731: {
732: case '4': // sha224
733: {
734: if (fonction[6] ==
735: d_code_fin_chaine)
736: {
737: EVP_sum =
738: EVP_sha224();
739: }
740: else
741: {
742: somme_invalide =
743: d_vrai;
744: }
745:
746: break;
747: }
748:
749: default:
750: {
751: somme_invalide =
752: d_vrai;
753: break;
754: }
755: }
756:
757: break;
758: }
759:
760: case '5':
761: {
762: switch(fonction[5])
763: {
764: case '6': // sha256
765: {
766: if (fonction[6] ==
767: d_code_fin_chaine)
768: {
769: EVP_sum =
770: EVP_sha256();
771: }
772: else
773: {
774: somme_invalide =
775: d_vrai;
776: }
777:
778: break;
779: }
780:
781: default:
782: {
783: somme_invalide =
784: d_vrai;
785: break;
786: }
787: }
788:
789: break;
790: }
791:
792: default:
793: {
794: somme_invalide = d_vrai;
795: break;
796: }
797: }
798:
799: break;
800: }
801: # endif
802:
803: # ifndef OPENSSL_NO_SHA512
804: case '3': // sha3
805: {
806: switch(fonction[4])
807: {
808: case '8': // sha38
809: {
810: switch(fonction[5])
811: {
812: case '4': // sha384
813: {
814: if (fonction[6] ==
815: d_code_fin_chaine)
816: {
817: EVP_sum =
818: EVP_sha384();
819: }
820: else
821: {
822: somme_invalide =
823: d_vrai;
824: }
825:
826: break;
827: }
828:
829: default:
830: {
831: somme_invalide =
832: d_vrai;
833: break;
834: }
835: }
836:
837: break;
838: }
839:
840: default:
841: {
842: somme_invalide = d_vrai;
843: break;
844: }
845: }
846:
847: break;
848: }
849:
850: case '5': // sha5
851: {
852: switch(fonction[4])
853: {
854: case '1': // sha51
855: {
856: switch(fonction[5])
857: {
858: case '2': // sha512
859: {
860: if (fonction[6] ==
861: d_code_fin_chaine)
862: {
863: EVP_sum =
864: EVP_sha512();
865: }
866: else
867: {
868: somme_invalide =
869: d_vrai;
870: }
871:
872: break;
873: }
874:
875: default:
876: {
877: somme_invalide =
878: d_vrai;
879: break;
880: }
881: }
882:
883: break;
884: }
885:
886: default:
887: {
888: somme_invalide = d_vrai;
889: break;
890: }
891: }
892:
893: break;
894: }
895: # endif
896:
897: default:
898: {
899: somme_invalide = d_vrai;
900: break;
901: }
902: }
903:
904: break;
905: }
906: # endif
907:
908: default:
909: {
910: somme_invalide = d_vrai;
911: break;
912: }
913: }
914:
915: break;
916: }
917:
918: default:
919: {
920: somme_invalide = d_vrai;
921: break;
922: }
923: }
924:
925: break;
926: }
927:
928: # ifndef OPENSSL_NO_WHIRLPOOL
929: case 'W':
930: {
931: if (strcmp(fonction, "WHIRLPOOL") == 0)
932: {
933: EVP_sum = EVP_whirlpool();
934: }
935: else
936: {
937: somme_invalide = d_vrai;
938: }
939:
940: break;
941: }
942: # endif
943:
944: default:
945: {
946: somme_invalide = d_vrai;
947: break;
948: }
949: }
950:
951: free(fonction);
952:
953: if (somme_invalide == d_vrai)
954: {
955: liberation(s_etat_processus, s_objet_argument_1);
956: liberation(s_etat_processus, s_objet_argument_2);
957:
958: (*s_etat_processus).erreur_execution =
959: d_ex_chiffrement_indisponible;
960: return;
961: }
962:
1.3 bertrand 963: if ((l_element_courant = (*l_element_courant).suivant) == NULL)
964: {
965: liberation(s_etat_processus, s_objet_argument_1);
966: liberation(s_etat_processus, s_objet_argument_2);
967:
968: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
969: return;
970: }
971:
972: // On attend le sel, donc un entier binaire de 64 bits.
973:
974: if ((*(*l_element_courant).donnee).type != BIN)
975: {
976: liberation(s_etat_processus, s_objet_argument_1);
977: liberation(s_etat_processus, s_objet_argument_2);
978:
979: (*s_etat_processus).erreur_execution =
980: d_ex_erreur_type_argument;
981: return;
982: }
983:
984: sel = (*((logical8 *) (*(*l_element_courant).donnee).objet));
985:
986: if ((l_element_courant = (*l_element_courant).suivant) == NULL)
987: {
988: liberation(s_etat_processus, s_objet_argument_1);
989: liberation(s_etat_processus, s_objet_argument_2);
990:
991: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
992: return;
993: }
994:
995: // On attend le nombre de cycles.
996:
997: if ((*(*l_element_courant).donnee).type != INT)
998: {
999: liberation(s_etat_processus, s_objet_argument_1);
1000: liberation(s_etat_processus, s_objet_argument_2);
1001:
1002: (*s_etat_processus).erreur_execution =
1003: d_ex_erreur_type_argument;
1004: return;
1005: }
1006:
1007: nombre_cycles = (*((integer8 *) (*(*l_element_courant)
1008: .donnee).objet));
1009:
1010: // On a dû atteindre la fin de la liste.
1011:
1012: if ((*l_element_courant).suivant != NULL)
1013: {
1014: liberation(s_etat_processus, s_objet_argument_1);
1015: liberation(s_etat_processus, s_objet_argument_2);
1016:
1017: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1018: return;
1019: }
1020:
1021: clef = NULL;
1022: iv = NULL;
1023:
1.1 bertrand 1024: generation_clef = d_vrai;
1025: }
1026: else
1027: {
1028: // Chiffrement ou déchiffrement d'un message
1029:
1.3 bertrand 1030: direction = instruction;
1.1 bertrand 1031:
1032: l_element_courant = (*l_element_courant).suivant;
1033:
1034: if (l_element_courant == NULL)
1035: {
1036: liberation(s_etat_processus, s_objet_argument_1);
1037: liberation(s_etat_processus, s_objet_argument_2);
1038:
1039: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
1040: return;
1041: }
1042:
1.3 bertrand 1043: // On attend le type de chiffrement.
1.1 bertrand 1044:
1045: if ((*(*l_element_courant).donnee).type != CHN)
1046: {
1047: liberation(s_etat_processus, s_objet_argument_1);
1048: liberation(s_etat_processus, s_objet_argument_2);
1049:
1050: (*s_etat_processus).erreur_execution =
1051: d_ex_erreur_type_argument;
1052: return;
1053: }
1054:
1.3 bertrand 1055: algorithme_chiffrement = (unsigned char *) (*(*l_element_courant)
1.1 bertrand 1056: .donnee).objet;
1057:
1058: // On attend la clef.
1059:
1060: if ((l_element_courant = (*l_element_courant).suivant) == NULL)
1061: {
1062: liberation(s_etat_processus, s_objet_argument_1);
1063: liberation(s_etat_processus, s_objet_argument_2);
1064:
1065: (*s_etat_processus).erreur_execution =
1066: d_ex_manque_argument;
1067: return;
1068: }
1069:
1070: clef = (unsigned char *) (*(*l_element_courant).donnee).objet;
1071:
1072: // On attend le vecteur d'initialisation.
1073:
1074: if ((l_element_courant = (*l_element_courant).suivant) == NULL)
1075: {
1076: liberation(s_etat_processus, s_objet_argument_1);
1077: liberation(s_etat_processus, s_objet_argument_2);
1078:
1079: (*s_etat_processus).erreur_execution =
1080: d_ex_manque_argument;
1081: return;
1082: }
1083:
1084: iv = (unsigned char *) (*(*l_element_courant).donnee).objet;
1085:
1086: if ((*l_element_courant).suivant != NULL)
1087: {
1088: liberation(s_etat_processus, s_objet_argument_1);
1089: liberation(s_etat_processus, s_objet_argument_2);
1090:
1091: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1092: return;
1093: }
1.3 bertrand 1094:
1095: generation_clef = d_faux;
1.1 bertrand 1096: }
1097: }
1098: else
1099: {
1100: liberation(s_etat_processus, s_objet_argument_1);
1101: liberation(s_etat_processus, s_objet_argument_2);
1102:
1103: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
1104: return;
1105: }
1106:
1.3 bertrand 1107: if ((tampon = conversion_majuscule(algorithme_chiffrement)) == NULL)
1.1 bertrand 1108: {
1109: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1110: return;
1111: }
1112:
1.3 bertrand 1113: # define TEST_CIPHER(string, value) \
1114: if (strcmp(tampon, string) == 0) EVP_chiffrement = value();
1115:
1116: if (strncmp(tampon, "DES", 3) == 0)
1117: {
1118: # ifndef OPENSSL_NO_DES
1119: TEST_CIPHER("DES-ECB", EVP_des_ecb)
1120: else TEST_CIPHER("DES-EDE", EVP_des_ede)
1121: else TEST_CIPHER("DES-EDE3", EVP_des_ede3)
1122: else TEST_CIPHER("DES-EDE-ECB", EVP_des_ede_ecb)
1123: else TEST_CIPHER("DES-EDE3-ECB", EVP_des_ede3_ecb)
1124: else TEST_CIPHER("DES-CFB64", EVP_des_cfb64)
1125: else TEST_CIPHER("DES-CFB1", EVP_des_cfb1)
1126: else TEST_CIPHER("DES-CFB8", EVP_des_cfb8)
1127: else TEST_CIPHER("DES-EDE-CFB64", EVP_des_ede_cfb64)
1128: else TEST_CIPHER("DES-EDE3-CFB64", EVP_des_ede3_cfb64)
1129: else TEST_CIPHER("DES-EDE3-CFB1", EVP_des_ede3_cfb1)
1130: else TEST_CIPHER("DES-EDE3-CFB8", EVP_des_ede3_cfb8)
1131: else TEST_CIPHER("DES-OFB", EVP_des_ofb)
1132: else TEST_CIPHER("DES-EDE-OFB", EVP_des_ede_ofb)
1133: else TEST_CIPHER("DES-EDE3-OFB", EVP_des_ede3_ofb)
1134: else TEST_CIPHER("DES-CBC", EVP_des_cbc)
1135: else TEST_CIPHER("DES-EDE-CBC", EVP_des_ede_cbc)
1136: else TEST_CIPHER("DES-EDE3-CBC", EVP_des_ede3_cbc)
1137: else TEST_CIPHER("DESX-CBC", EVP_desx_cbc)
1138: else
1139: {
1140: free(tampon);
1141:
1142: liberation(s_etat_processus, s_objet_argument_1);
1143: liberation(s_etat_processus, s_objet_argument_2);
1144:
1145: (*s_etat_processus).erreur_execution =
1146: d_ex_chiffrement_indisponible;
1147: return;
1148: }
1149: # else
1150: free(tampon);
1151:
1152: liberation(s_etat_processus, s_objet_argument_1);
1153: liberation(s_etat_processus, s_objet_argument_2);
1154:
1155: (*s_etat_processus).erreur_execution =
1156: d_ex_chiffrement_indisponible;
1157: return;
1158: # endif
1159: }
1160: else if (strncmp(tampon, "RC4", 3) == 0)
1161: {
1162: # ifndef OPENSSL_NO_RC4
1163: TEST_CIPHER("RC4", EVP_rc4)
1164: else TEST_CIPHER("RC4-40", EVP_rc4_40)
1165: else
1166: {
1167: free(tampon);
1168:
1169: liberation(s_etat_processus, s_objet_argument_1);
1170: liberation(s_etat_processus, s_objet_argument_2);
1171:
1172: (*s_etat_processus).erreur_execution =
1173: d_ex_chiffrement_indisponible;
1174: return;
1175: }
1176: # else
1177: free(tampon);
1178:
1179: liberation(s_etat_processus, s_objet_argument_1);
1180: liberation(s_etat_processus, s_objet_argument_2);
1181:
1182: (*s_etat_processus).erreur_execution =
1183: d_ex_chiffrement_indisponible;
1184: return;
1185: # endif
1186: }
1187: else if (strncmp(tampon, "IDEA", 4) == 0)
1188: {
1189: # ifndef OPENSSL_NO_IDEA
1190: TEST_CIPHER("IDEA-ECB", EVP_idea_ecb)
1191: else TEST_CIPHER("IDEA-CFB64", EVP_idea_cfb64)
1192: else TEST_CIPHER("IDEA-OFB", EVP_idea_ofb)
1193: else TEST_CIPHER("IDEA-CBC", EVP_idea_cbc)
1194: else
1195: {
1196: free(tampon);
1197:
1198: liberation(s_etat_processus, s_objet_argument_1);
1199: liberation(s_etat_processus, s_objet_argument_2);
1200:
1201: (*s_etat_processus).erreur_execution =
1202: d_ex_chiffrement_indisponible;
1203: return;
1204: }
1205: # else
1206: free(tampon);
1207:
1208: liberation(s_etat_processus, s_objet_argument_1);
1209: liberation(s_etat_processus, s_objet_argument_2);
1210:
1211: (*s_etat_processus).erreur_execution =
1212: d_ex_chiffrement_indisponible;
1213: return;
1214: # endif
1215: }
1216: else if (strncmp(tampon, "RC2", 3) == 0)
1.1 bertrand 1217: {
1.3 bertrand 1218: # ifndef OPENSSL_NO_RC2
1219: TEST_CIPHER("RC2-ECB", EVP_rc2_ecb)
1220: else TEST_CIPHER("RC2-CBC", EVP_rc2_cbc)
1221: else TEST_CIPHER("RC2-40-CBC", EVP_rc2_40_cbc)
1222: else TEST_CIPHER("RC2-64-CBC", EVP_rc2_64_cbc)
1223: else TEST_CIPHER("RC2-CFB64", EVP_rc2_cfb64)
1224: else TEST_CIPHER("RC2-OFB", EVP_rc2_ofb)
1225: else
1226: {
1227: free(tampon);
1228:
1229: liberation(s_etat_processus, s_objet_argument_1);
1230: liberation(s_etat_processus, s_objet_argument_2);
1231:
1232: (*s_etat_processus).erreur_execution =
1233: d_ex_chiffrement_indisponible;
1234: return;
1235: }
1236: # else
1237: free(tampon);
1238:
1239: liberation(s_etat_processus, s_objet_argument_1);
1240: liberation(s_etat_processus, s_objet_argument_2);
1241:
1242: (*s_etat_processus).erreur_execution =
1243: d_ex_chiffrement_indisponible;
1244: return;
1245: # endif
1.1 bertrand 1246: }
1.3 bertrand 1247: else if (strncmp(tampon, "BF", 2) == 0)
1248: {
1249: # ifndef OPENSSL_NO_BF
1250: TEST_CIPHER("BF-ECB", EVP_bf_ecb)
1251: else TEST_CIPHER("BF-CBC", EVP_bf_cbc)
1252: else TEST_CIPHER("BF-CFB64", EVP_bf_cfb64)
1253: else TEST_CIPHER("BF-OFB", EVP_bf_ofb)
1254: else
1255: {
1256: free(tampon);
1257:
1258: liberation(s_etat_processus, s_objet_argument_1);
1259: liberation(s_etat_processus, s_objet_argument_2);
1260:
1261: (*s_etat_processus).erreur_execution =
1262: d_ex_chiffrement_indisponible;
1263: return;
1264: }
1265: # else
1266: free(tampon);
1.1 bertrand 1267:
1.3 bertrand 1268: liberation(s_etat_processus, s_objet_argument_1);
1269: liberation(s_etat_processus, s_objet_argument_2);
1.1 bertrand 1270:
1.3 bertrand 1271: (*s_etat_processus).erreur_execution =
1272: d_ex_chiffrement_indisponible;
1273: return;
1274: # endif
1275: }
1276: else if (strncmp(tampon, "CAST5", 5) == 0)
1.1 bertrand 1277: {
1.3 bertrand 1278: # ifndef OPENSSL_NO_CAST
1279: TEST_CIPHER("CAST5-ECB", EVP_cast5_ecb)
1280: else TEST_CIPHER("CAST5-CBC", EVP_cast5_cbc)
1281: else TEST_CIPHER("CAST5-CFB64", EVP_cast5_cfb64)
1282: else TEST_CIPHER("CAST5-OFB", EVP_cast5_ofb)
1283: else
1284: {
1285: free(tampon);
1286:
1287: liberation(s_etat_processus, s_objet_argument_1);
1288: liberation(s_etat_processus, s_objet_argument_2);
1289:
1290: (*s_etat_processus).erreur_execution =
1291: d_ex_chiffrement_indisponible;
1292: return;
1293: }
1294: # else
1295: free(tampon);
1296:
1297: liberation(s_etat_processus, s_objet_argument_1);
1298: liberation(s_etat_processus, s_objet_argument_2);
1299:
1300: (*s_etat_processus).erreur_execution =
1301: d_ex_chiffrement_indisponible;
1302: return;
1303: # endif
1.1 bertrand 1304: }
1.3 bertrand 1305: else if (strncmp(tampon, "RC5", 3) == 0)
1.1 bertrand 1306: {
1.3 bertrand 1307: # ifndef OPENSSL_NO_RC5
1308: TEST_CIPHER("RC5-32-12-16-ECB", EVP_rc5_32_12_16_ebc)
1309: else TEST_CIPHER("RC5-32-12-16-CBC", EVP_rc5_32_12_16_cbc)
1310: else TEST_CIPHER("RC5-32-12-16-CFB64", EVP_rc5_32_12_16_cfb64)
1311: else TEST_CIPHER("RC5-32-12-16-OFB", EVP_rc5_32_12_16_ofb)
1312: else
1313: {
1314: free(tampon);
1315:
1316: liberation(s_etat_processus, s_objet_argument_1);
1317: liberation(s_etat_processus, s_objet_argument_2);
1318:
1319: (*s_etat_processus).erreur_execution =
1320: d_ex_chiffrement_indisponible;
1321: return;
1322: }
1323: # else
1324: free(tampon);
1325:
1326: liberation(s_etat_processus, s_objet_argument_1);
1327: liberation(s_etat_processus, s_objet_argument_2);
1328:
1329: (*s_etat_processus).erreur_execution =
1330: d_ex_chiffrement_indisponible;
1331: return;
1332: # endif
1333: }
1334: else if (strncmp(tampon, "AES", 3) == 0)
1335: {
1336: # ifndef OPENSSL_NO_AES
1337: TEST_CIPHER("AES-128-ECB", EVP_aes_128_ecb)
1338: else TEST_CIPHER("AES-128-CBC", EVP_aes_128_cbc)
1339: else TEST_CIPHER("AES-128-CFB1", EVP_aes_128_cfb1)
1340: else TEST_CIPHER("AES-128-CFB8", EVP_aes_128_cfb8)
1341: else TEST_CIPHER("AES-128-CFB128", EVP_aes_128_cfb128)
1342: else TEST_CIPHER("AES-128-OFB", EVP_aes_128_ofb)
1343: else TEST_CIPHER("AES-128-CTR", EVP_aes_128_ctr)
1344: else TEST_CIPHER("AES-128-CCM", EVP_aes_128_ccm)
1345: else TEST_CIPHER("AES-128-GCM", EVP_aes_128_gcm)
1346: else TEST_CIPHER("AES-128-XTS", EVP_aes_128_xts)
1347: else TEST_CIPHER("AES-192-ECB", EVP_aes_192_ecb)
1348: else TEST_CIPHER("AES-192-CBC", EVP_aes_192_cbc)
1349: else TEST_CIPHER("AES-192-CFB1", EVP_aes_192_cfb1)
1350: else TEST_CIPHER("AES-192-CFB8", EVP_aes_192_cfb8)
1351: else TEST_CIPHER("AES-192-CFB128", EVP_aes_192_cfb128)
1352: else TEST_CIPHER("AES-192-OFB", EVP_aes_192_ofb)
1353: else TEST_CIPHER("AES-192-CTR", EVP_aes_192_ctr)
1354: else TEST_CIPHER("AES-192-CCM", EVP_aes_192_ccm)
1355: else TEST_CIPHER("AES-192-GCM", EVP_aes_192_gcm)
1356: else TEST_CIPHER("AES-256-ECB", EVP_aes_256_ecb)
1357: else TEST_CIPHER("AES-256-CBC", EVP_aes_256_cbc)
1358: else TEST_CIPHER("AES-256-CFB1", EVP_aes_256_cfb1)
1359: else TEST_CIPHER("AES-256-CFB8", EVP_aes_256_cfb8)
1360: else TEST_CIPHER("AES-256-CFB128", EVP_aes_256_cfb128)
1361: else TEST_CIPHER("AES-256-OFB", EVP_aes_256_ofb)
1362: else TEST_CIPHER("AES-256-CTR", EVP_aes_256_ctr)
1363: else TEST_CIPHER("AES-256-CCM", EVP_aes_256_ccm)
1364: else TEST_CIPHER("AES-256-GCM", EVP_aes_256_gcm)
1365: else TEST_CIPHER("AES-256-XTS", EVP_aes_256_xts)
1366: else
1367: {
1368: free(tampon);
1369:
1370: liberation(s_etat_processus, s_objet_argument_1);
1371: liberation(s_etat_processus, s_objet_argument_2);
1372:
1373: (*s_etat_processus).erreur_execution =
1374: d_ex_chiffrement_indisponible;
1375: return;
1376: }
1377: # else
1378: free(tampon);
1379:
1380: liberation(s_etat_processus, s_objet_argument_1);
1381: liberation(s_etat_processus, s_objet_argument_2);
1382:
1383: (*s_etat_processus).erreur_execution =
1384: d_ex_chiffrement_indisponible;
1385: return;
1386: # endif
1387: }
1388: else if (strncmp(tampon, "CAMELLIA", 8) == 0)
1389: {
1390: # ifndef OPENSSL_NO_CAMELLIA
1391: TEST_CIPHER("CAMELLIA-128-ECB", EVP_camellia_128_ecb)
1392: else TEST_CIPHER("CAMELLIA-128-CBC", EVP_camellia_128_cbc)
1393: else TEST_CIPHER("CAMELLIA-128-CFB1", EVP_camellia_128_cfb1)
1394: else TEST_CIPHER("CAMELLIA-128-CFB8", EVP_camellia_128_cfb8)
1395: else TEST_CIPHER("CAMELLIA-128-CFB128", EVP_camellia_128_cfb128)
1396: else TEST_CIPHER("CAMELLIA-128-OFB", EVP_camellia_128_ofb)
1397: else TEST_CIPHER("CAMELLIA-192-ECB", EVP_camellia_128_ecb)
1398: else TEST_CIPHER("CAMELLIA-192-CBC", EVP_camellia_192_cbc)
1399: else TEST_CIPHER("CAMELLIA-192-CFB1", EVP_camellia_192_cfb1)
1400: else TEST_CIPHER("CAMELLIA-192-CFB8", EVP_camellia_192_cfb8)
1401: else TEST_CIPHER("CAMELLIA-192-CFB128", EVP_camellia_192_cfb128)
1402: else TEST_CIPHER("CAMELLIA-192-OFB", EVP_camellia_192_ofb)
1403: else TEST_CIPHER("CAMELLIA-256-ECB", EVP_camellia_256_ecb)
1404: else TEST_CIPHER("CAMELLIA-256-CBC", EVP_camellia_256_cbc)
1405: else TEST_CIPHER("CAMELLIA-256-CFB1", EVP_camellia_256_cfb1)
1406: else TEST_CIPHER("CAMELLIA-256-CFB8", EVP_camellia_256_cfb8)
1407: else TEST_CIPHER("CAMELLIA-256-CFB128", EVP_camellia_256_cfb128)
1408: else TEST_CIPHER("CAMELLIA-256-OFB", EVP_camellia_256_ofb)
1409: else
1410: {
1411: free(tampon);
1412:
1413: liberation(s_etat_processus, s_objet_argument_1);
1414: liberation(s_etat_processus, s_objet_argument_2);
1415:
1416: (*s_etat_processus).erreur_execution =
1417: d_ex_chiffrement_indisponible;
1418: return;
1419: }
1420: # else
1421: free(tampon);
1422:
1423: liberation(s_etat_processus, s_objet_argument_1);
1424: liberation(s_etat_processus, s_objet_argument_2);
1425:
1426: (*s_etat_processus).erreur_execution =
1427: d_ex_chiffrement_indisponible;
1428: return;
1429: # endif
1430: }
1431: else if (strncmp(tampon, "SEED", 4) == 0)
1432: {
1433: # ifndef OPENSSL_NO_SEED
1434: TEST_CIPHER("SEED-ECB", EVP_seed_ecb)
1435: else TEST_CIPHER("SEED-CBC", EVP_seed_cbc)
1436: else TEST_CIPHER("SEED-CFB128", EVP_seed_cfb128)
1437: else TEST_CIPHER("SEED-OFB", EVP_seed_ofb)
1438: else
1439: {
1440: free(tampon);
1441:
1442: liberation(s_etat_processus, s_objet_argument_1);
1443: liberation(s_etat_processus, s_objet_argument_2);
1444:
1445: (*s_etat_processus).erreur_execution =
1446: d_ex_chiffrement_indisponible;
1447: return;
1448: }
1449: # else
1450: free(tampon);
1451:
1452: liberation(s_etat_processus, s_objet_argument_1);
1453: liberation(s_etat_processus, s_objet_argument_2);
1454:
1455: (*s_etat_processus).erreur_execution =
1456: d_ex_chiffrement_indisponible;
1457: return;
1458: # endif
1459: }
1460: else
1461: {
1462: free(tampon);
1463:
1464: liberation(s_etat_processus, s_objet_argument_1);
1465: liberation(s_etat_processus, s_objet_argument_2);
1466:
1467: (*s_etat_processus).erreur_execution = d_ex_chiffrement_indisponible;
1468: return;
1469: }
1470:
1471: free(tampon);
1472:
1473: if (generation_clef == d_vrai)
1474: {
1.7 bertrand 1475: if ((iv = malloc(((size_t) EVP_CIPHER_iv_length(EVP_chiffrement))
1.3 bertrand 1476: * sizeof(unsigned char))) == NULL)
1477: {
1478: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1479: return;
1480: }
1481:
1.7 bertrand 1482: if ((clef = malloc(((size_t) EVP_CIPHER_key_length(EVP_chiffrement))
1.3 bertrand 1483: * sizeof(unsigned char))) == NULL)
1484: {
1485: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1486: return;
1487: }
1488:
1489: longueur_clef = EVP_BytesToKey(EVP_chiffrement, EVP_sum,
1490: (unsigned char *) &sel, (unsigned char *)
1.7 bertrand 1491: (*s_objet_argument_2).objet,
1492: (int) longueur_chaine(s_etat_processus,
1.3 bertrand 1493: (unsigned char *) (*s_objet_argument_2).objet),
1.7 bertrand 1494: (int) nombre_cycles, clef, iv);
1.3 bertrand 1495:
1496: if (longueur_clef != EVP_CIPHER_key_length(EVP_chiffrement))
1497: {
1498: free(iv);
1499: free(clef);
1500:
1501: liberation(s_etat_processus, s_objet_argument_1);
1502: liberation(s_etat_processus, s_objet_argument_2);
1503:
1504: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1505: return;
1506: }
1507:
1508: if ((s_objet_resultat_1 = allocation(s_etat_processus, LST)) == NULL)
1509: {
1510: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1511: return;
1512: }
1513:
1514: if (((*s_objet_resultat_1).objet = allocation_maillon(s_etat_processus))
1515: == NULL)
1516: {
1517: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1518: return;
1519: }
1520:
1521: l_element_courant = (*s_objet_resultat_1).objet;
1522:
1523: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1524: == NULL)
1525: {
1526: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1527: return;
1528: }
1529:
1530: if (((*(*l_element_courant).donnee).objet = malloc(
1531: (strlen(algorithme_chiffrement) + 1) * sizeof(unsigned char)))
1532: == NULL)
1533: {
1534: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1535: return;
1536: }
1537:
1538: strcpy((*(*l_element_courant).donnee).objet, algorithme_chiffrement);
1539:
1540: if (((*l_element_courant).suivant = allocation_maillon(
1541: s_etat_processus)) == NULL)
1542: {
1543: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1544: return;
1545: }
1546:
1547: l_element_courant = (*l_element_courant).suivant;
1548:
1549: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1550: == NULL)
1551: {
1552: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1553: return;
1554: }
1555:
1556: if (((*(*l_element_courant).donnee).objet = analyse_flux(
1557: s_etat_processus, clef,
1558: EVP_CIPHER_key_length(EVP_chiffrement))) == NULL)
1559: {
1560: return;
1561: }
1562:
1563: free(clef);
1564:
1565: if (((*l_element_courant).suivant = allocation_maillon(
1566: s_etat_processus)) == NULL)
1567: {
1568: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1569: return;
1570: }
1571:
1572: l_element_courant = (*l_element_courant).suivant;
1573: (*l_element_courant).suivant = NULL;
1574:
1575: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1576: == NULL)
1577: {
1578: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1579: return;
1580: }
1581:
1582: if (((*(*l_element_courant).donnee).objet = analyse_flux(
1583: s_etat_processus, iv,
1584: EVP_CIPHER_iv_length(EVP_chiffrement))) == NULL)
1585: {
1586: return;
1587: }
1588:
1589: free(iv);
1590:
1591: liberation(s_etat_processus, s_objet_argument_1);
1592: liberation(s_etat_processus, s_objet_argument_2);
1593:
1594: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1595: s_objet_resultat_1) == d_erreur)
1596: {
1597: return;
1598: }
1599: }
1600: else
1601: {
1602: // Chiffrement ou déchiffrement
1603:
1604: if (strcmp(direction, "ENCRYPT") == 0)
1605: {
1606: encodage = d_vrai;
1607: }
1608: else if (strcmp(direction, "DECRYPT") == 0)
1609: {
1610: encodage = d_faux;
1611: }
1612: else
1613: {
1614: free(direction);
1615: liberation(s_etat_processus, s_objet_argument_1);
1616: liberation(s_etat_processus, s_objet_argument_2);
1617:
1618: (*s_etat_processus).erreur_execution =
1619: d_ex_argument_invalide;
1620: return;
1621: }
1622:
1623: free(direction);
1624:
1625: // Conversion des clefs
1626:
1627: if ((clef_binaire = formateur_flux(s_etat_processus, clef,
1628: &longueur_clef_binaire)) == NULL)
1629: {
1630: return;
1631: }
1632:
1633: if ((iv_binaire = formateur_flux(s_etat_processus, iv,
1634: &longueur_iv_binaire)) == NULL)
1635: {
1636: return;
1637: }
1638:
1639: // Vérification de la longueur des clef et vecteur d'initialisation
1640:
1641: if (longueur_clef_binaire != EVP_CIPHER_key_length(EVP_chiffrement))
1642: {
1643: free(clef_binaire);
1644: free(iv_binaire);
1645:
1646: liberation(s_etat_processus, s_objet_argument_1);
1647: liberation(s_etat_processus, s_objet_argument_2);
1648:
1649: (*s_etat_processus).erreur_execution =
1650: d_ex_longueur_clef_chiffrement;
1651: return;
1652: }
1653:
1654: if (longueur_iv_binaire != EVP_CIPHER_iv_length(EVP_chiffrement))
1655: {
1656: free(clef_binaire);
1657: free(iv_binaire);
1658:
1659: liberation(s_etat_processus, s_objet_argument_1);
1660: liberation(s_etat_processus, s_objet_argument_2);
1661:
1662: (*s_etat_processus).erreur_execution =
1663: d_ex_longueur_clef_chiffrement;
1664: return;
1665: }
1666:
1667: if ((message = formateur_flux(s_etat_processus, (unsigned char *)
1668: (*s_objet_argument_2).objet, &longueur_message)) == NULL)
1669: {
1670: return;
1671: }
1672:
1673: if ((message_chiffre = chiffrement(EVP_chiffrement, encodage, message,
1674: longueur_message, clef_binaire, longueur_clef_binaire,
1675: iv_binaire, &longueur_message_chiffre)) == NULL)
1676: {
1677: free(clef_binaire);
1678: free(iv_binaire);
1679: free(message);
1680:
1681: liberation(s_etat_processus, s_objet_argument_1);
1682: liberation(s_etat_processus, s_objet_argument_2);
1683:
1684: (*s_etat_processus).erreur_execution = d_ex_chiffrement;
1685: return;
1686: }
1687:
1688: free(clef_binaire);
1689: free(message);
1690:
1691: if ((s_objet_resultat_2 = allocation(s_etat_processus, CHN)) == NULL)
1692: {
1693: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1694: return;
1695: }
1696:
1697: if (((*s_objet_resultat_2).objet = analyse_flux(s_etat_processus,
1698: message_chiffre, longueur_message_chiffre)) == NULL)
1699: {
1700: return;
1701: }
1702:
1703: free(message_chiffre);
1704:
1705: if ((s_objet_resultat_1 = allocation(s_etat_processus, LST)) == NULL)
1706: {
1707: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1708: return;
1709: }
1710:
1711: if (((*s_objet_resultat_1).objet = allocation_maillon(s_etat_processus))
1712: == NULL)
1713: {
1714: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1715: return;
1716: }
1717:
1718: l_element_courant = (*s_objet_resultat_1).objet;
1719:
1720: // Direction
1721:
1722: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1723: == NULL)
1724: {
1725: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1726: return;
1727: }
1728:
1729: if (((*(*l_element_courant).donnee).objet =
1730: malloc(8 * sizeof(unsigned char))) == NULL)
1731: {
1732: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1733: return;
1734: }
1735:
1736: strcpy((*(*l_element_courant).donnee).objet,
1737: (encodage == d_vrai) ? "ENCRYPT" : "DECRYPT");
1738:
1739: // Type de chiffrement
1740:
1741: if (((*l_element_courant).suivant = allocation_maillon(
1742: s_etat_processus)) == NULL)
1743: {
1744: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1745: return;
1746: }
1747:
1748: l_element_courant = (*l_element_courant).suivant;
1749:
1750: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1751: == NULL)
1752: {
1753: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1754: return;
1755: }
1756:
1.5 bertrand 1757: if (((*(*l_element_courant).donnee).objet =
1758: conversion_majuscule(algorithme_chiffrement)) == NULL)
1.3 bertrand 1759: {
1760: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1761: return;
1762: }
1763:
1764: // Clef
1765:
1766: if (((*l_element_courant).suivant = allocation_maillon(
1767: s_etat_processus)) == NULL)
1768: {
1769: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1770: return;
1771: }
1772:
1773: l_element_courant = (*l_element_courant).suivant;
1774:
1775: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1776: == NULL)
1777: {
1778: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1779: return;
1780: }
1781:
1782: if (((*(*l_element_courant).donnee).objet =
1783: malloc((strlen(clef) + 1) * sizeof(unsigned char))) == NULL)
1784: {
1785: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1786: return;
1787: }
1788:
1789: strcpy((*(*l_element_courant).donnee).objet, clef);
1790:
1791: // Vecteur d'initialisation
1792:
1793: if (((*l_element_courant).suivant = allocation_maillon(
1794: s_etat_processus)) == NULL)
1795: {
1796: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1797: return;
1798: }
1799:
1800: l_element_courant = (*l_element_courant).suivant;
1801: (*l_element_courant).suivant = NULL;
1802:
1803: if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN))
1804: == NULL)
1805: {
1806: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1807: return;
1808: }
1809:
1810: if (((*(*l_element_courant).donnee).objet = analyse_flux(
1811: s_etat_processus, iv_binaire, longueur_iv_binaire)) == NULL)
1812: {
1813: return;
1814: }
1815:
1816: free(iv_binaire);
1817:
1818: liberation(s_etat_processus, s_objet_argument_1);
1819: liberation(s_etat_processus, s_objet_argument_2);
1820:
1821: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1822: s_objet_resultat_2) == d_erreur)
1823: {
1824: return;
1825: }
1826:
1827: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1828: s_objet_resultat_1) == d_erreur)
1829: {
1830: return;
1831: }
1.1 bertrand 1832: }
1833:
1834: return;
1835: }
1836:
1837: // vim: ts=4