blob: 43a3306a5a5b521c650a4e1c80bdd987219147a6 [file] [log] [blame]
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05001/*
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002 Copyright (C) 2012 by Werner Dittmann
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05003
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 * In addition, as a special exception, the copyright holders give
19 * permission to link the code of portions of this program with the
20 * OpenSSL library under certain conditions as described in each
21 * individual source file, and distribute linked combinations
22 * including the two.
23 * You must obey the GNU General Public License in all respects
24 * for all of the code used other than OpenSSL. If you modify
25 * file(s) with this exception, you may extend this exception to your
26 * version of the file(s), but you are not obligated to do so. If you
27 * do not wish to do so, delete this exception statement from your
28 * version. If you delete this exception statement from all source
29 * files in the program, then also delete it here.
30 */
31
Alexandre Lisionddd731e2014-01-31 11:50:08 -050032/** Copyright (C) 2012
33 *
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050034 * @author Werner Dittmann <Werner.Dittmann@t-online.de>
35 */
36
37#include <string.h>
38
39#include <zrtp/crypto/aesCFB.h>
40#include <cryptcommon/aescpp.h>
41
42void aesCfbEncrypt(uint8_t *key, int32_t keyLength, uint8_t* IV, uint8_t *data, int32_t dataLength)
43{
44 AESencrypt *saAes = new AESencrypt();
45
46 if (keyLength == 16)
47 saAes->key128(key);
48 else if (keyLength == 32)
49 saAes->key256(key);
50 else
51 return;
52
53 // Note: maybe copy IV to an internal array if we encounter strange things.
54 // the cfb encrypt modify the IV on return. Same for output data (inplace encryption)
55 saAes->cfb_encrypt(data, data, dataLength, IV);
56 delete saAes;
57}
58
59
60void aesCfbDecrypt(uint8_t *key, int32_t keyLength, uint8_t* IV, uint8_t *data, int32_t dataLength)
61{
62 AESencrypt *saAes = new AESencrypt();
63 if (keyLength == 16)
64 saAes->key128(key);
65 else if (keyLength == 32)
66 saAes->key256(key);
67 else
68 return;
69
70 // Note: maybe copy IV to an internal array if we encounter strange things.
71 // the cfb encrypt modify the IV on return. Same for output data (inplace encryption)
72 saAes->cfb_decrypt(data, data, dataLength, IV);
73 delete saAes;
74}