Wed, 16 Feb 2011 20:29:33 +0000
There are no secrets better kept than the secrets that everybody guesses.
0
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | local aes = require("aeslua.aes"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | local util = require("aeslua.util"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local buffer = require("aeslua.buffer"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | local public = {}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | local aeslua = require("aeslua"); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | aeslua.ciphermode = public; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | -- Encrypt strings |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | -- key - byte array with key |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | -- string - string to encrypt |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | -- modefunction - function for cipher mode to use |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | function public.encryptString(key, data, modeFunction) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | local iv = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | local keySched = aes.expandEncryptionKey(key); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | local encryptedData = buffer.new(); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | for i = 1, #data/16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | local offset = (i-1)*16 + 1; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | local byteData = {string.byte(data,offset,offset +15)}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | modeFunction(keySched, byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | buffer.addString(encryptedData, string.char(unpack(byteData))); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | return buffer.toString(encryptedData); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | -- the following 4 functions can be used as |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | -- modefunction for encryptString |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | -- Electronic code book mode encrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | function public.encryptECB(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | aes.encrypt(keySched, byteData, 1, byteData, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | -- Cipher block chaining mode encrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | function public.encryptCBC(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | util.xorIV(byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | aes.encrypt(keySched, byteData, 1, byteData, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | for j = 1,16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | iv[j] = byteData[j]; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | -- Output feedback mode encrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | function public.encryptOFB(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | aes.encrypt(keySched, iv, 1, iv, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 | util.xorIV(byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 | -- Cipher feedback mode encrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | function public.encryptCFB(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | aes.encrypt(keySched, iv, 1, iv, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | util.xorIV(byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 | for j = 1,16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 | iv[j] = byteData[j]; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 | -- Decrypt strings |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 | -- key - byte array with key |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 | -- string - string to decrypt |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 | -- modefunction - function for cipher mode to use |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 | function public.decryptString(key, data, modeFunction) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 | local iv = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 | local keySched; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | if (modeFunction == public.decryptOFB or modeFunction == public.decryptCFB) then |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | keySched = aes.expandEncryptionKey(key); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | else |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | keySched = aes.expandDecryptionKey(key); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | local decryptedData = buffer.new(); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | for i = 1, #data/16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 | local offset = (i-1)*16 + 1; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 | local byteData = {string.byte(data,offset,offset +15)}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 | iv = modeFunction(keySched, byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 | buffer.addString(decryptedData, string.char(unpack(byteData))); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 | return buffer.toString(decryptedData); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 | -- the following 4 functions can be used as |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 | -- modefunction for decryptString |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 | -- |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 | -- Electronic code book mode decrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 | function public.decryptECB(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 | aes.decrypt(keySched, byteData, 1, byteData, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 | return iv; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 | -- Cipher block chaining mode decrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 | function public.decryptCBC(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 | local nextIV = {}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 | for j = 1,16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 | nextIV[j] = byteData[j]; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 | aes.decrypt(keySched, byteData, 1, byteData, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 | util.xorIV(byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 | return nextIV; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 | -- Output feedback mode decrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 | function public.decryptOFB(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 | aes.encrypt(keySched, iv, 1, iv, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 | util.xorIV(byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 | return iv; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 | -- Cipher feedback mode decrypt function |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 | function public.decryptCFB(keySched, byteData, iv) |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 | local nextIV = {}; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | for j = 1,16 do |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 | nextIV[j] = byteData[j]; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 | aes.encrypt(keySched, iv, 1, iv, 1); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 | util.xorIV(byteData, iv); |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 | return nextIV; |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 | end |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 | |
598d09faf89c
There are no secrets better kept than the secrets that everybody guesses.
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 | return public; |