summaryrefslogtreecommitdiff
path: root/networking/tls_aes.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-02-04 16:23:49 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-02-04 16:23:49 +0100
commitc31b54fd81690b3df3898437f5865674d06e6577 (patch)
tree22029dfd1c4892cf300051b486cc11ca8593e5d4 /networking/tls_aes.c
parent5b05d9db29843144b2ed620ca437d6a3bacc3816 (diff)
downloadbusybox-w32-c31b54fd81690b3df3898437f5865674d06e6577.tar.gz
busybox-w32-c31b54fd81690b3df3898437f5865674d06e6577.tar.bz2
busybox-w32-c31b54fd81690b3df3898437f5865674d06e6577.zip
tls: fold AES CBC en/decryption into single functions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/tls_aes.c')
-rw-r--r--networking/tls_aes.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/networking/tls_aes.c b/networking/tls_aes.c
index 6c3c39373..ebaab15b1 100644
--- a/networking/tls_aes.c
+++ b/networking/tls_aes.c
@@ -5,6 +5,46 @@
5 */ 5 */
6#include "tls.h" 6#include "tls.h"
7 7
8static
9int32 psAesInitKey(const unsigned char *key, uint32 keylen, psAesKey_t *skey);
10static
11void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
12 psAesKey_t *skey);
13static
14void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt,
15 psAesKey_t *skey);
16static
17int32 psAesInit(psCipherContext_t *ctx, unsigned char *IV,
18 const unsigned char *key, uint32 keylen);
19static
20int32 psAesEncrypt(psCipherContext_t *ctx, const unsigned char *pt,
21 unsigned char *ct, uint32 len);
22static
23int32 psAesDecrypt(psCipherContext_t *ctx, const unsigned char *ct,
24 unsigned char *pt, uint32 len);
25
26void aes_cbc_encrypt(const void *key, int klen, void *iv, const void *data, size_t len, void *dst)
27{
28 psCipherContext_t ctx;
29 psAesInit(&ctx, iv, key, klen);
30 psAesEncrypt(&ctx,
31 data, /* plaintext */
32 dst, /* ciphertext */
33 len
34 );
35}
36
37void aes_cbc_decrypt(const void *key, int klen, void *iv, const void *data, size_t len, void *dst)
38{
39 psCipherContext_t ctx;
40 psAesInit(&ctx, iv, key, klen);
41 psAesDecrypt(&ctx,
42 data, /* ciphertext */
43 dst, /* plaintext */
44 len
45 );
46}
47
8/* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/symmetric/. 48/* The file is taken almost verbatim from matrixssl-3-7-2b-open/crypto/symmetric/.
9 * Changes are flagged with //bbox 49 * Changes are flagged with //bbox
10 */ 50 */
@@ -1079,8 +1119,9 @@ static uint32 setup_mix2(uint32 temp)
1079 Software implementation of AES CBC APIs 1119 Software implementation of AES CBC APIs
1080 */ 1120 */
1081#ifndef USE_AES_CBC_EXTERNAL 1121#ifndef USE_AES_CBC_EXTERNAL
1122static //bbox
1082int32 psAesInit(psCipherContext_t *ctx, unsigned char *IV, 1123int32 psAesInit(psCipherContext_t *ctx, unsigned char *IV,
1083 unsigned char *key, uint32 keylen) 1124 const unsigned char *key, uint32 keylen)
1084{ 1125{
1085 int32 x, err; 1126 int32 x, err;
1086 1127
@@ -1106,7 +1147,8 @@ int32 psAesInit(psCipherContext_t *ctx, unsigned char *IV,
1106 return PS_SUCCESS; 1147 return PS_SUCCESS;
1107} 1148}
1108 1149
1109int32 psAesEncrypt(psCipherContext_t *ctx, unsigned char *pt, 1150static //bbox
1151int32 psAesEncrypt(psCipherContext_t *ctx, const unsigned char *pt,
1110 unsigned char *ct, uint32 len) 1152 unsigned char *ct, uint32 len)
1111{ 1153{
1112 int32 x; 1154 int32 x;
@@ -1156,7 +1198,8 @@ int32 psAesEncrypt(psCipherContext_t *ctx, unsigned char *pt,
1156 return len; 1198 return len;
1157} 1199}
1158 1200
1159int32 psAesDecrypt(psCipherContext_t *ctx, unsigned char *ct, 1201static //bbox
1202int32 psAesDecrypt(psCipherContext_t *ctx, const unsigned char *ct,
1160 unsigned char *pt, uint32 len) 1203 unsigned char *pt, uint32 len)
1161{ 1204{
1162 int32 x; 1205 int32 x;
@@ -1223,6 +1266,7 @@ int32 psAesDecrypt(psCipherContext_t *ctx, unsigned char *ct,
1223 skey: The key in as scheduled by this function. 1266 skey: The key in as scheduled by this function.
1224*/ 1267*/
1225 1268
1269static //bbox
1226int32 psAesInitKey(const unsigned char *key, uint32 keylen, psAesKey_t *skey) 1270int32 psAesInitKey(const unsigned char *key, uint32 keylen, psAesKey_t *skey)
1227{ 1271{
1228 int32 i, j; 1272 int32 i, j;
@@ -1390,6 +1434,7 @@ int32 psAesInitKey(const unsigned char *key, uint32 keylen, psAesKey_t *skey)
1390 1434
1391 1435
1392#ifdef USE_BURN_STACK 1436#ifdef USE_BURN_STACK
1437static //bbox
1393void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct, 1438void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
1394 psAesKey_t *skey) 1439 psAesKey_t *skey)
1395{ 1440{
@@ -1399,6 +1444,7 @@ void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
1399static void _aes_ecb_encrypt(const unsigned char *pt, unsigned char *ct, 1444static void _aes_ecb_encrypt(const unsigned char *pt, unsigned char *ct,
1400 psAesKey_t *skey) 1445 psAesKey_t *skey)
1401#else 1446#else
1447static //bbox
1402void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct, 1448void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
1403 psAesKey_t *skey) 1449 psAesKey_t *skey)
1404#endif /* USE_BURN_STACK */ 1450#endif /* USE_BURN_STACK */
@@ -1555,6 +1601,7 @@ void psAesEncryptBlock(const unsigned char *pt, unsigned char *ct,
1555} 1601}
1556 1602
1557#ifdef USE_BURN_STACK 1603#ifdef USE_BURN_STACK
1604static //bbox
1558void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt, 1605void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt,
1559 psAesKey_t *skey) 1606 psAesKey_t *skey)
1560{ 1607{
@@ -1564,6 +1611,7 @@ void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt,
1564static void _aes_ecb_decrypt(const unsigned char *ct, unsigned char *pt, 1611static void _aes_ecb_decrypt(const unsigned char *ct, unsigned char *pt,
1565 psAesKey_t *skey) 1612 psAesKey_t *skey)
1566#else 1613#else
1614static //bbox
1567void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt, 1615void psAesDecryptBlock(const unsigned char *ct, unsigned char *pt,
1568 psAesKey_t *skey) 1616 psAesKey_t *skey)
1569#endif /* USE_BURN_STACK */ 1617#endif /* USE_BURN_STACK */