1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.12
4: Copyright (C) 1989-2013 Dr. BERTRAND Joël
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 de chiffrement d'un séquence d'octets
29: ================================================================================
30: Entrées : pointeur sur une structure
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: unsigned char *
39: chiffrement(const EVP_CIPHER *type_chiffrement, logical1 encodage,
40: unsigned char *message, unsigned int longueur_message,
41: unsigned char *clef, unsigned int longueur_clef,
42: unsigned char *vecteur_initialisation,
43: unsigned int longueur_vecteur_initialisation,
44: unsigned int longueur_bloc_de_chiffrement,
45: unsigned int *longueur_message_chiffre)
46: {
47: int longueur_message_1;
48: int longueur_message_2;
49:
50: unsigned char *message_chiffre;
51:
52: EVP_CIPHER_CTX contexte;
53:
54: EVP_CIPHER_CTX_init(&contexte);
55:
56: if (EVP_CipherInit_ex(&contexte, type_chiffrement, NULL, clef,
57: vecteur_initialisation, (encodage == d_vrai) ? 1 : 0) != 1)
58: {
59: EVP_CIPHER_CTX_cleanup(&contexte);
60: return(NULL);
61: }
62:
63: (*longueur_message_chiffre) = ((longueur_message /
64: longueur_bloc_de_chiffrement) + 1) * longueur_bloc_de_chiffrement;
65:
66: if ((message_chiffre = malloc((*longueur_message_chiffre) *
67: sizeof(unsigned char))) == NULL)
68: {
69: return(NULL);
70: }
71:
72: if (EVP_CipherUpdate(&contexte, message_chiffre, &longueur_message_1,
73: message, longueur_message) != 1)
74: {
75: free(message_chiffre);
76: EVP_CIPHER_CTX_cleanup(&contexte);
77: return(NULL);
78: }
79:
80: if (EVP_CipherFinal_ex(&contexte, message_chiffre + longueur_message_1,
81: &longueur_message_2) != 1)
82: {
83: free(message_chiffre);
84: EVP_CIPHER_CTX_cleanup(&contexte);
85: return(NULL);
86: }
87:
88: (*longueur_message_chiffre) = longueur_message_1 + longueur_message_2;
89: EVP_CIPHER_CTX_cleanup(&contexte);
90:
91: return(message_chiffre);
92: }
93:
94: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>