version 1.4, 2013/02/25 19:14:01
|
version 1.18, 2015/01/05 15:32:12
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.12 |
RPL/2 (R) version 4.1.20 |
Copyright (C) 1989-2012 Dr. BERTRAND Joël |
Copyright (C) 1989-2015 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 37
|
Line 37
|
|
|
unsigned char * |
unsigned char * |
chiffrement(const EVP_CIPHER *type_chiffrement, logical1 encodage, |
chiffrement(const EVP_CIPHER *type_chiffrement, logical1 encodage, |
unsigned char *message, unsigned int longueur_message, |
unsigned char *message, integer8 longueur_message, |
unsigned char *clef, unsigned int longueur_clef, |
unsigned char *clef, integer8 longueur_clef, |
unsigned char *vecteur_initialisation, |
unsigned char *vecteur_initialisation, |
unsigned int longueur_vecteur_initialisation, |
integer8 *longueur_message_chiffre) |
unsigned int longueur_bloc_de_chiffrement, |
|
unsigned int *longueur_message_chiffre) |
|
{ |
{ |
|
int i; |
|
int longueur_bloc_de_chiffrement; |
int longueur_message_1; |
int longueur_message_1; |
int longueur_message_2; |
int longueur_message_2; |
|
|
Line 53 chiffrement(const EVP_CIPHER *type_chiff
|
Line 53 chiffrement(const EVP_CIPHER *type_chiff
|
|
|
EVP_CIPHER_CTX_init(&contexte); |
EVP_CIPHER_CTX_init(&contexte); |
|
|
|
longueur_bloc_de_chiffrement = EVP_CIPHER_block_size(type_chiffrement); |
|
|
if (EVP_CipherInit_ex(&contexte, type_chiffrement, NULL, clef, |
if (EVP_CipherInit_ex(&contexte, type_chiffrement, NULL, clef, |
vecteur_initialisation, (encodage == d_vrai) ? 1 : 0) != 1) |
vecteur_initialisation, (encodage == d_vrai) ? 1 : 0) != 1) |
{ |
{ |
Line 63 chiffrement(const EVP_CIPHER *type_chiff
|
Line 65 chiffrement(const EVP_CIPHER *type_chiff
|
(*longueur_message_chiffre) = ((longueur_message / |
(*longueur_message_chiffre) = ((longueur_message / |
longueur_bloc_de_chiffrement) + 1) * longueur_bloc_de_chiffrement; |
longueur_bloc_de_chiffrement) + 1) * longueur_bloc_de_chiffrement; |
|
|
if ((message_chiffre = malloc((*longueur_message_chiffre) * |
if ((message_chiffre = malloc(((size_t) (*longueur_message_chiffre)) * |
sizeof(unsigned char))) == NULL) |
sizeof(unsigned char))) == NULL) |
{ |
{ |
return(NULL); |
return(NULL); |
} |
} |
|
|
if (EVP_CipherUpdate(&contexte, message_chiffre, &longueur_message_1, |
if (EVP_CipherUpdate(&contexte, message_chiffre, &longueur_message_1, |
message, longueur_message) != 1) |
message, (int) longueur_message) != 1) |
{ |
{ |
free(message_chiffre); |
free(message_chiffre); |
EVP_CIPHER_CTX_cleanup(&contexte); |
EVP_CIPHER_CTX_cleanup(&contexte); |
Line 86 chiffrement(const EVP_CIPHER *type_chiff
|
Line 88 chiffrement(const EVP_CIPHER *type_chiff
|
} |
} |
|
|
(*longueur_message_chiffre) = longueur_message_1 + longueur_message_2; |
(*longueur_message_chiffre) = longueur_message_1 + longueur_message_2; |
|
|
|
// Mise à jour du vecteur d'initialisation |
|
|
|
for(i = 0; i < EVP_CIPHER_iv_length(type_chiffrement); i++) |
|
{ |
|
vecteur_initialisation[i] = contexte.iv[i]; |
|
} |
|
|
EVP_CIPHER_CTX_cleanup(&contexte); |
EVP_CIPHER_CTX_cleanup(&contexte); |
|
|
return(message_chiffre); |
return(message_chiffre); |