summaryrefslogtreecommitdiff
path: root/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/blockmode.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/blockmode.c')
-rwxr-xr-xutils/zenutils/libraries/beecrypt-4.1.2/beecrypt/blockmode.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/blockmode.c b/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/blockmode.c
new file mode 100755
index 0000000000..cfccd43337
--- /dev/null
+++ b/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/blockmode.c
@@ -0,0 +1,137 @@
1/*
2 * Copyright (c) 2000, 2002 Virtual Unlimited B.V.
3 *
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 */
19
20/*!\file blockmode.c
21 * \brief Blockcipher operation modes.
22 * \author Bob Deblier <bob.deblier@pandora.be>
23 * \ingroup BC_m
24 */
25
26#define BEECRYPT_DLL_EXPORT
27
28#if HAVE_CONFIG_H
29# include "config.h"
30#endif
31
32#include "beecrypt/blockmode.h"
33
34int blockEncryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks)
35{
36 register const unsigned int blockwords = bc->blocksize >> 2;
37
38 while (nblocks > 0)
39 {
40 bc->raw.encrypt(bp, dst, src);
41
42 dst += blockwords;
43 src += blockwords;
44
45 nblocks--;
46 }
47
48 return 0;
49}
50
51int blockDecryptECB(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks)
52{
53 register const unsigned int blockwords = bc->blocksize >> 2;
54
55 while (nblocks > 0)
56 {
57 bc->raw.decrypt(bp, dst, src);
58
59 dst += blockwords;
60 src += blockwords;
61
62 nblocks--;
63 }
64
65 return 0;
66}
67
68int blockEncryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks)
69{
70 register const unsigned int blockwords = bc->blocksize >> 2;
71 register uint32_t* fdback = bc->getfb(bp);
72
73 if (nblocks > 0)
74 {
75 register unsigned int i;
76
77 for (i = 0; i < blockwords; i++)
78 dst[i] = src[i] ^ fdback[i];
79
80 bc->raw.encrypt(bp, dst, dst);
81
82 nblocks--;
83
84 while (nblocks > 0)
85 {
86 for (i = 0; i < blockwords; i++)
87 dst[i+blockwords] = src[i+blockwords] ^ dst[i];
88
89 dst += blockwords;
90
91 bc->raw.encrypt(bp, dst, dst);
92
93 src += blockwords;
94
95 nblocks--;
96 }
97
98 for (i = 0; i < blockwords; i++)
99 fdback[i] = dst[i];
100 }
101
102 return 0;
103}
104
105int blockDecryptCBC(const blockCipher* bc, blockCipherParam* bp, uint32_t* dst, const uint32_t* src, unsigned int nblocks)
106{
107 register const unsigned int blockwords = bc->blocksize >> 2;
108 register uint32_t* fdback = bc->getfb(bp);
109 register uint32_t* buf = (uint32_t*) malloc(blockwords * sizeof(uint32_t));
110
111 if (buf)
112 {
113 while (nblocks > 0)
114 {
115 register uint32_t tmp;
116 register unsigned int i;
117
118 bc->raw.decrypt(bp, buf, src);
119
120 for (i = 0; i < blockwords; i++)
121 {
122 tmp = src[i];
123 dst[i] = buf[i] ^ fdback[i];
124 fdback[i] = tmp;
125 }
126
127 dst += blockwords;
128 src += blockwords;
129
130 nblocks--;
131 }
132 free(buf);
133 return 0;
134 }
135
136 return -1;
137}