version 1.4, 2013/02/27 15:44:15
|
version 1.41, 2025/04/15 10:17:52
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.12 |
RPL/2 (R) version 4.1.36 |
Copyright (C) 1989-2013 Dr. BERTRAND Joël |
Copyright (C) 1989-2025 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 43 instruction_cipher(struct_processus *s_e
|
Line 43 instruction_cipher(struct_processus *s_e
|
|
|
int longueur_clef; |
int longueur_clef; |
|
|
|
integer8 longueur_clef_binaire; |
|
integer8 longueur_iv_binaire; |
|
integer8 longueur_message; |
|
integer8 longueur_message_chiffre; |
integer8 nombre_cycles; |
integer8 nombre_cycles; |
|
|
logical1 encodage; |
logical1 encodage; |
Line 51 instruction_cipher(struct_processus *s_e
|
Line 55 instruction_cipher(struct_processus *s_e
|
|
|
logical8 sel; |
logical8 sel; |
|
|
long longueur_clef_binaire; |
|
long longueur_iv_binaire; |
|
long longueur_message; |
|
|
|
struct_liste_chainee *l_element_courant; |
struct_liste_chainee *l_element_courant; |
|
|
struct_objet *s_objet_argument_1; |
struct_objet *s_objet_argument_1; |
struct_objet *s_objet_argument_2; |
struct_objet *s_objet_argument_2; |
|
struct_objet *s_objet_padding; |
struct_objet *s_objet_resultat_1; |
struct_objet *s_objet_resultat_1; |
struct_objet *s_objet_resultat_2; |
struct_objet *s_objet_resultat_2; |
|
|
Line 73 instruction_cipher(struct_processus *s_e
|
Line 74 instruction_cipher(struct_processus *s_e
|
unsigned char *iv_binaire; |
unsigned char *iv_binaire; |
unsigned char *message; |
unsigned char *message; |
unsigned char *message_chiffre; |
unsigned char *message_chiffre; |
|
unsigned char padding; |
unsigned char *tampon; |
unsigned char *tampon; |
|
|
unsigned int longueur_message_chiffre; |
|
|
|
if ((*s_etat_processus).affichage_arguments == 'Y') |
if ((*s_etat_processus).affichage_arguments == 'Y') |
{ |
{ |
printf("\n CIPHER "); |
printf("\n CIPHER "); |
Line 96 instruction_cipher(struct_processus *s_e
|
Line 96 instruction_cipher(struct_processus *s_e
|
printf("-> 1: { \"cipher type\" \"generated key\" \"iv\" }\n\n"); |
printf("-> 1: { \"cipher type\" \"generated key\" \"iv\" }\n\n"); |
|
|
printf(" 2: \"text\"\n", d_CHN); |
printf(" 2: \"text\"\n", d_CHN); |
printf(" 1: %s { \"direction\" \"cipher type\" \"key\" \"iv\" }\n", |
printf(" 1: { \"direction\" \"cipher type\" \"key\" \"iv\" " |
d_LST); |
"padding }\n"); |
printf("-> 2: \"encrypted or decrypted text\"\n", d_CHN); |
printf("-> 2: \"encrypted or decrypted text\"\n", d_CHN); |
printf(" 1: { \"direction\" \"cipher type\" \"key\" " |
printf(" 1: { \"direction\" \"cipher type\" \"key\" " |
"\"updated iv\" }\n\n", d_LST); |
"\"updated iv\" padding }\n\n", d_LST); |
|
|
if ((*s_etat_processus).langue == 'F') |
if ((*s_etat_processus).langue == 'F') |
{ |
{ |
Line 245 instruction_cipher(struct_processus *s_e
|
Line 245 instruction_cipher(struct_processus *s_e
|
printf(" Digest algorithms:\n\n"); |
printf(" Digest algorithms:\n\n"); |
} |
} |
|
|
# ifndef OPENSSL_NO_SHA |
|
printf(" - DSS\n"); |
|
printf(" - DSS1\n"); |
|
printf(" - ECDSA\n"); |
|
# endif |
|
# ifndef OPENSSL_NO_MD2 |
# ifndef OPENSSL_NO_MD2 |
printf(" - MD2\n"); |
printf(" - MD2\n"); |
# endif |
# endif |
Line 265 instruction_cipher(struct_processus *s_e
|
Line 260 instruction_cipher(struct_processus *s_e
|
# ifndef OPENSSL_NO_RIPEMD |
# ifndef OPENSSL_NO_RIPEMD |
printf(" - RIPEMD160\n"); |
printf(" - RIPEMD160\n"); |
# endif |
# endif |
# ifndef OPENSSL_NO_SHA |
|
printf(" - SHA\n"); |
|
printf(" - SHA1\n"); |
printf(" - SHA1\n"); |
# endif |
|
# ifndef OPENSSL_NO_SHA256 |
|
printf(" - SHA224\n"); |
printf(" - SHA224\n"); |
printf(" - SHA256\n"); |
printf(" - SHA256\n"); |
# endif |
|
# ifndef OPENSSL_NO_SHA512 |
|
printf(" - SHA384\n"); |
printf(" - SHA384\n"); |
printf(" - SHA512\n"); |
printf(" - SHA512\n"); |
# endif |
|
# ifndef OPENSSL_NO_WHIRLPOOL |
# ifndef OPENSSL_NO_WHIRLPOOL |
printf(" - WHIRLPOOL\n"); |
printf(" - WHIRLPOOL\n"); |
# endif |
# endif |
Line 295 instruction_cipher(struct_processus *s_e
|
Line 283 instruction_cipher(struct_processus *s_e
|
printf(" \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" " |
printf(" \"password\" { \"KEY\" \"DES-EDE-OFB\" \"SHA1\" " |
"# 0h 3 } CIPHER\n"); |
"# 0h 3 } CIPHER\n"); |
printf(" \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" " |
printf(" \"text\" { \"ENCRYPT\" \"AES-128-CBC\" \"key\" " |
"\"iv\" } CIPHER\n"); |
"\"iv\" \"PADDING\" } CIPHER\n"); |
printf(" \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" " |
printf(" \"text\" { \"DECRYPT\" \"AES-128-EBC\" \"key\" " |
"\"iv\" } CIPHER\n"); |
"\"iv\" \"NO PADDING\" } CIPHER\n"); |
return; |
return; |
} |
} |
else if ((*s_etat_processus).test_instruction == 'Y') |
else if ((*s_etat_processus).test_instruction == 'Y') |
Line 353 instruction_cipher(struct_processus *s_e
|
Line 341 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
if ((instruction = conversion_majuscule((unsigned char *) |
if ((instruction = conversion_majuscule(s_etat_processus, |
(*(*l_element_courant).donnee).objet)) == NULL) |
(unsigned char *) (*(*l_element_courant).donnee).objet)) |
|
== NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
Line 366 instruction_cipher(struct_processus *s_e
|
Line 355 instruction_cipher(struct_processus *s_e
|
|
|
free(instruction); |
free(instruction); |
|
|
|
s_objet_padding = NULL; |
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
|
|
if (l_element_courant == NULL) |
if (l_element_courant == NULL) |
Line 417 instruction_cipher(struct_processus *s_e
|
Line 407 instruction_cipher(struct_processus *s_e
|
|
|
// Test de la validité de la somme de contrôle. |
// Test de la validité de la somme de contrôle. |
|
|
if ((fonction = conversion_majuscule(controle)) == NULL) |
if ((fonction = conversion_majuscule(s_etat_processus, controle)) |
|
== NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
Line 427 instruction_cipher(struct_processus *s_e
|
Line 418 instruction_cipher(struct_processus *s_e
|
|
|
switch(fonction[0]) |
switch(fonction[0]) |
{ |
{ |
case 'D': |
|
{ |
|
switch(fonction[1]) |
|
{ |
|
case 'S': // ds |
|
{ |
|
switch(fonction[2]) |
|
{ |
|
# ifndef OPENSSL_NO_SHA |
|
case 'S': // dss |
|
{ |
|
switch(fonction[3]) |
|
{ |
|
case d_code_fin_chaine: |
|
{ |
|
EVP_sum = EVP_dss(); |
|
break; |
|
} |
|
|
|
case '1': // dss1 |
|
{ |
|
if (fonction[4] == |
|
d_code_fin_chaine) |
|
{ |
|
EVP_sum = EVP_dss1(); |
|
} |
|
else |
|
{ |
|
somme_invalide = d_vrai; |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
# endif |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
case 'E': |
|
{ |
|
switch(fonction[1]) |
|
{ |
|
case 'C': // ec |
|
{ |
|
switch(fonction[2]) |
|
{ |
|
case 'D': // ecd |
|
{ |
|
switch(fonction[3]) |
|
{ |
|
case 'S': // ecds |
|
{ |
|
switch(fonction[4]) |
|
{ |
|
# ifndef OPENSSL_NO_SHA |
|
case 'A': // ecdsa |
|
{ |
|
if (fonction[5] == |
|
d_code_fin_chaine) |
|
{ |
|
EVP_sum = EVP_ecdsa(); |
|
} |
|
else |
|
{ |
|
somme_invalide = d_vrai; |
|
} |
|
|
|
break; |
|
} |
|
# endif |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
default: |
|
{ |
|
somme_invalide = d_vrai; |
|
break; |
|
} |
|
} |
|
|
|
break; |
|
} |
|
|
|
case 'M': |
case 'M': |
{ |
{ |
switch(fonction[1]) |
switch(fonction[1]) |
Line 696 instruction_cipher(struct_processus *s_e
|
Line 549 instruction_cipher(struct_processus *s_e
|
{ |
{ |
switch(fonction[2]) |
switch(fonction[2]) |
{ |
{ |
# ifndef OPENSSL_NO_SHA |
|
case 'A': |
case 'A': |
{ |
{ |
switch(fonction[3]) |
switch(fonction[3]) |
{ |
{ |
case d_code_fin_chaine: |
|
{ |
|
EVP_sum = EVP_sha(); |
|
break; |
|
} |
|
|
|
case '1': // sha1 |
case '1': // sha1 |
{ |
{ |
if (fonction[4] == |
if (fonction[4] == |
Line 722 instruction_cipher(struct_processus *s_e
|
Line 568 instruction_cipher(struct_processus *s_e
|
break; |
break; |
} |
} |
|
|
# ifndef OPENSSL_NO_SHA256 |
|
case '2': // sha2 |
case '2': // sha2 |
{ |
{ |
switch(fonction[4]) |
switch(fonction[4]) |
Line 800 instruction_cipher(struct_processus *s_e
|
Line 645 instruction_cipher(struct_processus *s_e
|
|
|
break; |
break; |
} |
} |
# endif |
|
|
|
# ifndef OPENSSL_NO_SHA512 |
|
case '3': // sha3 |
case '3': // sha3 |
{ |
{ |
switch(fonction[4]) |
switch(fonction[4]) |
Line 894 instruction_cipher(struct_processus *s_e
|
Line 737 instruction_cipher(struct_processus *s_e
|
|
|
break; |
break; |
} |
} |
# endif |
|
|
|
default: |
default: |
{ |
{ |
Line 905 instruction_cipher(struct_processus *s_e
|
Line 747 instruction_cipher(struct_processus *s_e
|
|
|
break; |
break; |
} |
} |
# endif |
|
|
|
default: |
default: |
{ |
{ |
Line 1085 instruction_cipher(struct_processus *s_e
|
Line 926 instruction_cipher(struct_processus *s_e
|
|
|
iv = (unsigned char *) (*(*l_element_courant).donnee).objet; |
iv = (unsigned char *) (*(*l_element_courant).donnee).objet; |
|
|
|
// On attend le drapeau concernant le padding. |
|
|
|
if ((l_element_courant = (*l_element_courant).suivant) == NULL) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_manque_argument; |
|
return; |
|
} |
|
|
|
if ((*(*l_element_courant).donnee).type != CHN) |
|
{ |
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = |
|
d_ex_erreur_type_argument; |
|
return; |
|
} |
|
|
|
tampon = conversion_majuscule(s_etat_processus, |
|
(unsigned char *) (*(*l_element_courant).donnee).objet); |
|
|
|
if (strcmp(tampon, "PADDING") == 0) |
|
{ |
|
padding = 'Y'; |
|
} |
|
else if (strcmp(tampon, "NO PADDING") == 0) |
|
{ |
|
padding = 'N'; |
|
} |
|
else |
|
{ |
|
free(tampon); |
|
|
|
liberation(s_etat_processus, s_objet_argument_1); |
|
liberation(s_etat_processus, s_objet_argument_2); |
|
|
|
(*s_etat_processus).erreur_execution = d_ex_argument_invalide; |
|
return; |
|
} |
|
|
|
free(tampon); |
|
|
|
s_objet_padding = copie_objet(s_etat_processus, |
|
(*l_element_courant).donnee, 'P'); |
|
|
if ((*l_element_courant).suivant != NULL) |
if ((*l_element_courant).suivant != NULL) |
{ |
{ |
liberation(s_etat_processus, s_objet_argument_1); |
liberation(s_etat_processus, s_objet_argument_1); |
Line 1106 instruction_cipher(struct_processus *s_e
|
Line 996 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
if ((tampon = conversion_majuscule(algorithme_chiffrement)) == NULL) |
if ((tampon = conversion_majuscule(s_etat_processus, |
|
algorithme_chiffrement)) == NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
Line 1474 instruction_cipher(struct_processus *s_e
|
Line 1365 instruction_cipher(struct_processus *s_e
|
|
|
if (generation_clef == d_vrai) |
if (generation_clef == d_vrai) |
{ |
{ |
if ((iv = malloc(EVP_CIPHER_iv_length(EVP_chiffrement) |
if ((iv = malloc(((size_t) EVP_CIPHER_iv_length(EVP_chiffrement)) |
* sizeof(unsigned char))) == NULL) |
* sizeof(unsigned char))) == NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
} |
} |
|
|
if ((clef = malloc(EVP_CIPHER_key_length(EVP_chiffrement) |
if ((clef = malloc(((size_t) EVP_CIPHER_key_length(EVP_chiffrement)) |
* sizeof(unsigned char))) == NULL) |
* sizeof(unsigned char))) == NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
Line 1490 instruction_cipher(struct_processus *s_e
|
Line 1381 instruction_cipher(struct_processus *s_e
|
|
|
longueur_clef = EVP_BytesToKey(EVP_chiffrement, EVP_sum, |
longueur_clef = EVP_BytesToKey(EVP_chiffrement, EVP_sum, |
(unsigned char *) &sel, (unsigned char *) |
(unsigned char *) &sel, (unsigned char *) |
(*s_objet_argument_2).objet, longueur_chaine(s_etat_processus, |
(*s_objet_argument_2).objet, |
|
(int) longueur_chaine(s_etat_processus, |
(unsigned char *) (*s_objet_argument_2).objet), |
(unsigned char *) (*s_objet_argument_2).objet), |
nombre_cycles, clef, iv); |
(int) nombre_cycles, clef, iv); |
|
|
if (longueur_clef != EVP_CIPHER_key_length(EVP_chiffrement)) |
if (longueur_clef != EVP_CIPHER_key_length(EVP_chiffrement)) |
{ |
{ |
Line 1671 instruction_cipher(struct_processus *s_e
|
Line 1563 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
if ((message_chiffre = chiffrement(EVP_chiffrement, encodage, message, |
if ((message_chiffre = chiffrement(s_etat_processus, |
|
EVP_chiffrement, encodage, message, |
longueur_message, clef_binaire, longueur_clef_binaire, |
longueur_message, clef_binaire, longueur_clef_binaire, |
iv_binaire, &longueur_message_chiffre)) == NULL) |
iv_binaire, &longueur_message_chiffre, padding)) == NULL) |
{ |
{ |
free(clef_binaire); |
free(clef_binaire); |
free(iv_binaire); |
free(iv_binaire); |
Line 1755 instruction_cipher(struct_processus *s_e
|
Line 1648 instruction_cipher(struct_processus *s_e
|
return; |
return; |
} |
} |
|
|
if (((*(*l_element_courant).donnee).objet = malloc( |
if (((*(*l_element_courant).donnee).objet = |
(strlen(algorithme_chiffrement) + 1) * sizeof(unsigned char))) |
conversion_majuscule(s_etat_processus, algorithme_chiffrement)) |
== NULL) |
== NULL) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
return; |
return; |
} |
} |
|
|
strcpy((*(*l_element_courant).donnee).objet, algorithme_chiffrement); |
|
|
|
// Clef |
// Clef |
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
if (((*l_element_courant).suivant = allocation_maillon( |
Line 1802 instruction_cipher(struct_processus *s_e
|
Line 1693 instruction_cipher(struct_processus *s_e
|
} |
} |
|
|
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
(*l_element_courant).suivant = NULL; |
|
|
|
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
if (((*l_element_courant).donnee = allocation(s_etat_processus, CHN)) |
== NULL) |
== NULL) |
Line 1819 instruction_cipher(struct_processus *s_e
|
Line 1709 instruction_cipher(struct_processus *s_e
|
|
|
free(iv_binaire); |
free(iv_binaire); |
|
|
|
// Padding |
|
|
|
if (((*l_element_courant).suivant = allocation_maillon( |
|
s_etat_processus)) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
l_element_courant = (*l_element_courant).suivant; |
|
(*l_element_courant).donnee = s_objet_padding; |
|
(*l_element_courant).suivant = NULL; |
|
|
liberation(s_etat_processus, s_objet_argument_1); |
liberation(s_etat_processus, s_objet_argument_1); |
liberation(s_etat_processus, s_objet_argument_2); |
liberation(s_etat_processus, s_objet_argument_2); |
|
|