/* ================================================================================ RPL/2 (R) version 4.1.12 Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. RPL/2 is free software; you can redistribute it and/or modify it under the terms of the CeCILL V2 License as published by the french CEA, CNRS and INRIA. RPL/2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License for more details. You should have received a copy of the CeCILL License along with RPL/2. If not, write to info@cecill.info. ================================================================================ */ #include "rpl-conv.h" /* ================================================================================ Fonction de chiffrement d'un séquence d'octets ================================================================================ Entrées : pointeur sur une structure -------------------------------------------------------------------------------- Sorties : -------------------------------------------------------------------------------- Effets de bord : néant ================================================================================ */ unsigned char * chiffrement(const EVP_CIPHER *type_chiffrement, logical1 encodage, unsigned char *message, unsigned int longueur_message, unsigned char *clef, unsigned int longueur_clef, unsigned char *vecteur_initialisation, unsigned int longueur_vecteur_initialisation, unsigned int longueur_bloc_de_chiffrement, unsigned int *longueur_message_chiffre) { int longueur_message_1; int longueur_message_2; unsigned char *message_chiffre; EVP_CIPHER_CTX contexte; EVP_CIPHER_CTX_init(&contexte); if (EVP_CipherInit_ex(&contexte, type_chiffrement, NULL, clef, vecteur_initialisation, (encodage == d_vrai) ? 1 : 0) != 1) { EVP_CIPHER_CTX_cleanup(&contexte); return(NULL); } (*longueur_message_chiffre) = ((longueur_message / longueur_bloc_de_chiffrement) + 1) * longueur_bloc_de_chiffrement; if ((message_chiffre = malloc((*longueur_message_chiffre) * sizeof(unsigned char))) == NULL) { return(NULL); } if (EVP_CipherUpdate(&contexte, message_chiffre, &longueur_message_1, message, longueur_message) != 1) { free(message_chiffre); EVP_CIPHER_CTX_cleanup(&contexte); return(NULL); } if (EVP_CipherFinal_ex(&contexte, message_chiffre + longueur_message_1, &longueur_message_2) != 1) { free(message_chiffre); EVP_CIPHER_CTX_cleanup(&contexte); return(NULL); } (*longueur_message_chiffre) = longueur_message_1 + longueur_message_2; EVP_CIPHER_CTX_cleanup(&contexte); return(message_chiffre); } // vim: ts=4