File: | builds/wireshark/wireshark/epan/wslua/wslua_gcrypt.c |
Warning: | line 54, column 9 Potential leak of memory pointed to by 'gcry_cipher' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * wslua_gcrypt.c | |||
3 | * | |||
4 | * Wireshark's interface to the Lua Programming Language | |||
5 | * | |||
6 | * (c) 2025, Bartis Csaba <bracsek@bracsek.eu> | |||
7 | * | |||
8 | * Wireshark - Network traffic analyzer | |||
9 | * By Gerald Combs <gerald@wireshark.org> | |||
10 | * Copyright 1998 Gerald Combs | |||
11 | * | |||
12 | * SPDX-License-Identifier: GPL-2.0-or-later | |||
13 | */ | |||
14 | ||||
15 | #include "config.h" | |||
16 | #include "wslua.h" | |||
17 | ||||
18 | /* WSLUA_MODULE Gcrypt Gcrypt symmetric cipher functions | |||
19 | ||||
20 | A <<lua_class_GcryptCipher,`GcryptCipher`>> object represents gcypt symmetric cipher in Lua. | |||
21 | ||||
22 | The cipher functions are used for symmetrical cryptography, i.e. cryptography using a shared key. | |||
23 | The programming model follows an open/process/close paradigm and is in that similar to | |||
24 | other building blocks provided by Libgcrypt. | |||
25 | ||||
26 | There is an example after the <<lua_fn_gcryptcipher_authenticate_abuf_,`GcryptCipher.authenticate`>> function. | |||
27 | ||||
28 | */ | |||
29 | ||||
30 | WSLUA_CLASS_DEFINE(GcryptCipher,FAIL_ON_NULL("GcryptCipher"))GcryptCipher toGcryptCipher(lua_State* L, int idx) { GcryptCipher * v = (GcryptCipher*)lua_touserdata (L, idx); if (!v) luaL_error (L, "bad argument %d (%s expected, got %s)", idx, "GcryptCipher" , lua_typename(L, lua_type(L, idx))); return v ? *v : ((void* )0); } GcryptCipher checkGcryptCipher(lua_State* L, int idx) { GcryptCipher* p; luaL_checktype(L,idx,7); p = (GcryptCipher* )luaL_checkudata(L, idx, "GcryptCipher"); if (! *p) luaL_argerror (L,idx,"null " "GcryptCipher"); return p ? *p : ((void*)0); } GcryptCipher* pushGcryptCipher(lua_State* L, GcryptCipher v) { GcryptCipher* p; luaL_checkstack(L,2,"Unable to grow stack\n" ); p = (GcryptCipher*)lua_newuserdatauv(L,sizeof(GcryptCipher ),1); *p = v; (lua_getfield(L, (-1000000 - 1000), ("GcryptCipher" ))); lua_setmetatable(L, -2); return p; }_Bool isGcryptCipher (lua_State* L,int i) { void *p; if(!lua_isuserdata(L,i)) return 0; p = lua_touserdata(L, i); lua_getfield(L, (-1000000 - 1000 ), "GcryptCipher"); if (p == ((void*)0) || !lua_getmetatable( L, i) || !lua_rawequal(L, -1, -2)) p=((void*)0); lua_settop(L , -(2)-1); return p ? 1 : 0; } GcryptCipher shiftGcryptCipher (lua_State* L,int i) { GcryptCipher* p; if(!lua_isuserdata(L, i)) return ((void*)0); p = (GcryptCipher*)lua_touserdata(L, i ); lua_getfield(L, (-1000000 - 1000), "GcryptCipher"); if (p == ((void*)0) || !lua_getmetatable(L, i) || !lua_rawequal(L, -1 , -2)) p=((void*)0); lua_settop(L, -(2)-1); if (p) { (lua_rotate (L, (i), -1), lua_settop(L, -(1)-1)); return *p; } else return ((void*)0);} typedef int dummyGcryptCipher; | |||
31 | ||||
32 | WSLUA_CONSTRUCTORstatic int GcryptCipher_open(lua_State* L) { | |||
33 | /* | |||
34 | Creates a new <<lua_class_GcryptCipher,`GcryptCipher`>> object. | |||
35 | ||||
36 | This object uses the symmetric cipher functions to encrypt or decrypt data. | |||
37 | ||||
38 | ===== Example | |||
39 | ||||
40 | [source,lua] | |||
41 | ---- | |||
42 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
43 | ---- | |||
44 | */ | |||
45 | #define WSLUA_ARG_GcryptCipher_open_ALGORITHM1 1 /* Select the algorithm for this cipher. */ | |||
46 | #define WSLUA_ARG_GcryptCipher_open_MODE2 2 /* Select mode for this algorithm */ | |||
47 | #define WSLUA_ARG_GcryptCipher_open_FLAGS3 3 /* Set the flags for this cipher */ | |||
48 | GcryptCipher gcry_cipher = (GcryptCipher)g_malloc(sizeof(gcry_cipher_hd_t)); | |||
| ||||
49 | int algo = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_open_ALGORITHM1); | |||
50 | int mode = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_open_MODE2); | |||
51 | int flags = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_open_FLAGS3); | |||
52 | gcry_error_t err = gcry_cipher_open(gcry_cipher, algo, mode, flags); | |||
53 | if (err) { | |||
54 | lua_pushstring(L, gcry_strerror(err)); | |||
| ||||
55 | return lua_error(L); | |||
56 | } | |||
57 | pushGcryptCipher(L, gcry_cipher); | |||
58 | WSLUA_RETURN(1)return (1); /* The new GcryptCipher object. */ | |||
59 | } | |||
60 | ||||
61 | /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */ | |||
62 | static int GcryptCipher__gc(lua_State* L) { | |||
63 | GcryptCipher gcry_cipher = toGcryptCipher(L,1); | |||
64 | if (!gcry_cipher) return 0; | |||
65 | gcry_cipher_close(*gcry_cipher); | |||
66 | g_free(gcry_cipher); | |||
67 | return 0; | |||
68 | } | |||
69 | ||||
70 | WSLUA_METHODstatic int GcryptCipher_ctl(lua_State* L) { | |||
71 | /* | |||
72 | Perform various operations on the cipher object H. | |||
73 | ||||
74 | ===== Example | |||
75 | ||||
76 | [source,lua] | |||
77 | ---- | |||
78 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
79 | -- CFB mode syncronization | |||
80 | cipher:ctl(GCRYCTL_CFB_SYNC, ByteArray.new()) | |||
81 | -- enabling CBC-MAC mode | |||
82 | cipher:ctl(GCRYCTL_SET_CBC_MAC, ByteArray.new()) | |||
83 | ---- | |||
84 | */ | |||
85 | #define WSLUA_ARG_GcryptCipher_ctl_CMD2 2 /* Command identifier. */ | |||
86 | #define WSLUA_ARG_GcryptCipher_ctl_BUFFER3 3 /* <<lua_class_ByteArray,`ByteArray`>> as buffer and buffer length. */ | |||
87 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
88 | int cmd = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_ctl_CMD2); | |||
89 | ByteArray buffer = checkByteArray(L, WSLUA_ARG_GcryptCipher_ctl_BUFFER3); | |||
90 | gcry_error_t err = gcry_cipher_ctl(*gcry_cipher, cmd, buffer->data, (size_t) buffer->len); | |||
91 | if (err) { | |||
92 | lua_pushstring(L, gcry_strerror(err)); | |||
93 | return lua_error(L); | |||
94 | } | |||
95 | WSLUA_RETURN(0)return (0); | |||
96 | } | |||
97 | ||||
98 | WSLUA_METHODstatic int GcryptCipher_info(lua_State* L) { | |||
99 | /* | |||
100 | Retrieve various information about the cipher object H. | |||
101 | ||||
102 | ===== Example | |||
103 | ||||
104 | [source,lua] | |||
105 | ---- | |||
106 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_GCM, 0) | |||
107 | -- Get the tag length of GCM. | |||
108 | local userdata, nbytes = cipher:info(GCRYCTL_GET_TAGLEN, NULL, 1) | |||
109 | print("Tag length: " .. tostring(nbytes)) | |||
110 | ---- | |||
111 | */ | |||
112 | #define WSLUA_ARG_GcryptCipher_info_WHAT2 2 /* Select what info will be returned. */ | |||
113 | #define WSLUA_ARG_GcryptCipher_info_BUFFER_SIZE3 3 /* Buffer size or NULL */ | |||
114 | #define WSLUA_ARG_GcryptCipher_info_NBYTES4 4 /* Nbytes integer or NULL */ | |||
115 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
116 | int what = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_info_WHAT2); | |||
117 | size_t *pnbytes = NULL((void*)0); | |||
118 | char* pbuffer = NULL((void*)0); | |||
119 | ByteArray ba = g_byte_array_new(); | |||
120 | size_t nbytes = 0; | |||
121 | if (lua_isinteger(L, WSLUA_ARG_GcryptCipher_info_BUFFER_SIZE3)) { | |||
122 | g_byte_array_set_size(ba, (int) luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_info_BUFFER_SIZE3)); | |||
123 | pbuffer = ba->data; | |||
124 | } | |||
125 | if (lua_isinteger(L, WSLUA_ARG_GcryptCipher_info_NBYTES4)) { | |||
126 | nbytes = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_info_NBYTES4); | |||
127 | pnbytes = (size_t *) &nbytes; | |||
128 | } | |||
129 | gcry_error_t err = gcry_cipher_info(*gcry_cipher, what, pbuffer, pnbytes); | |||
130 | if (err) { | |||
131 | lua_pushstring(L, gcry_strerror(err)); | |||
132 | return lua_error(L); | |||
133 | } | |||
134 | pushByteArray(L, ba); | |||
135 | if (pnbytes != NULL((void*)0)) { | |||
136 | lua_pushinteger(L, (int) nbytes); | |||
137 | } | |||
138 | else { | |||
139 | lua_pushinteger(L, 0); | |||
140 | } | |||
141 | WSLUA_RETURN(2)return (2); | |||
142 | } | |||
143 | ||||
144 | WSLUA_METHODstatic int GcryptCipher_encrypt(lua_State* L) { | |||
145 | /* | |||
146 | Encrypt the plaintext of size INLEN in IN using the cipher handle H | |||
147 | into the buffer OUT which has an allocated length of OUTSIZE. For | |||
148 | most algorithms it is possible to pass NULL for in and do a in-place | |||
149 | encryption of the data returned in a <<lua_class_ByteArray,`ByteArray`>>. | |||
150 | ||||
151 | ===== Example | |||
152 | ||||
153 | [source,lua] | |||
154 | ---- | |||
155 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
156 | cipher:setkey(ByteArray.new("abcdefabcdef1234abcdefabcdef1234")) | |||
157 | local encrypted = cipher:encrypt(NULL, ByteArray.new("000102030405060708090a0b0c0d0e0f")) | |||
158 | print("Encrypted: " .. encrypted:tohex()) | |||
159 | -- in place encryption | |||
160 | cipher:ctl(GCRYCTL_RESET, ByteArray.new()) | |||
161 | local data = ByteArray.new("000102030405060708090a0b0c0d0e0f") | |||
162 | cipher:encrypt(data) | |||
163 | print("In-place encrypted: " .. data:tohex()) | |||
164 | ---- | |||
165 | */ | |||
166 | #define WSLUA_ARG_GcryptCipher_encrypt_OUT2 2 /* <<lua_class_ByteArray,`ByteArray`>> with data for in-place encryption or NULL */ | |||
167 | #define WSLUA_OPTARG_GcryptCipher_encrypt_IN3 3 /* <<lua_class_ByteArray,`ByteArray`>> with data or NULL */ | |||
168 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
169 | char* pin = NULL((void*)0); | |||
170 | char* pout = NULL((void*)0); | |||
171 | size_t in_length = 0; | |||
172 | size_t out_length = 0; | |||
173 | ByteArray bain = NULL((void*)0); | |||
174 | ByteArray baout = NULL((void*)0); | |||
175 | if (!isByteArray(L, WSLUA_OPTARG_GcryptCipher_encrypt_IN3) && | |||
176 | !isByteArray(L, WSLUA_ARG_GcryptCipher_encrypt_OUT2)) { | |||
177 | return lua_error(L); | |||
178 | } | |||
179 | if (isByteArray(L, WSLUA_OPTARG_GcryptCipher_encrypt_IN3)) { | |||
180 | bain = checkByteArray(L, WSLUA_OPTARG_GcryptCipher_encrypt_IN3); | |||
181 | pin = bain->data; | |||
182 | in_length = (size_t) bain->len; | |||
183 | } | |||
184 | if (isByteArray(L, WSLUA_ARG_GcryptCipher_encrypt_OUT2)) { | |||
185 | baout = checkByteArray(L, WSLUA_ARG_GcryptCipher_encrypt_OUT2); | |||
186 | pout = baout->data; | |||
187 | out_length = (size_t) baout->len; | |||
188 | bain = NULL((void*)0); | |||
189 | pin = NULL((void*)0); | |||
190 | in_length = (size_t) 0; | |||
191 | } else { | |||
192 | baout = g_byte_array_new(); | |||
193 | if (bain != NULL((void*)0)) { | |||
194 | g_byte_array_set_size(baout, (int) bain->len); | |||
195 | } | |||
196 | pout = baout->data; | |||
197 | out_length = (size_t) baout->len; | |||
198 | } | |||
199 | gcry_error_t err = gcry_cipher_encrypt(*gcry_cipher, pout, out_length, pin, in_length); | |||
200 | if (err) { | |||
201 | lua_pushstring(L, gcry_strerror(err)); | |||
202 | return lua_error(L); | |||
203 | } | |||
204 | if (bain != NULL((void*)0)) { | |||
205 | pushByteArray(L, baout); | |||
206 | WSLUA_RETURN(1)return (1); | |||
207 | } else { | |||
208 | WSLUA_RETURN(0)return (0); | |||
209 | } | |||
210 | } | |||
211 | ||||
212 | WSLUA_METHODstatic int GcryptCipher_decrypt(lua_State* L) { | |||
213 | /* | |||
214 | The counterpart to gcry_cipher_encrypt. | |||
215 | ||||
216 | ===== Example | |||
217 | ||||
218 | [source,lua] | |||
219 | ---- | |||
220 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
221 | cipher:setkey(ByteArray.new("abcdefabcdef1234abcdefabcdef1234")) | |||
222 | local decrypted = cipher:decrypt(NULL, ByteArray.new("E27FC30A38E17B6BB7E67AFF2800792F")) | |||
223 | print("Decrypted: " .. decrypted:tohex()) | |||
224 | -- in place decryption | |||
225 | cipher:ctl(GCRYCTL_RESET, ByteArray.new()) | |||
226 | local data = ByteArray.new("E27FC30A38E17B6BB7E67AFF2800792F") | |||
227 | cipher:decrypt(data) | |||
228 | print("In-place decrypted: " .. data:tohex()) | |||
229 | ---- | |||
230 | */ | |||
231 | #define WSLUA_ARG_GcryptCipher_decrypt_OUT2 2 /* <<lua_class_ByteArray,`ByteArray`>> with data for in-place decryption or NULL */ | |||
232 | #define WSLUA_OPTARG_GcryptCipher_decrypt_IN3 3 /* <<lua_class_ByteArray,`ByteArray`>> with data or NULL */ | |||
233 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
234 | if (!isByteArray(L, WSLUA_OPTARG_GcryptCipher_decrypt_IN3) && | |||
235 | !isByteArray(L, WSLUA_ARG_GcryptCipher_decrypt_OUT2)) { | |||
236 | return lua_error(L); | |||
237 | } | |||
238 | char* pin = NULL((void*)0); | |||
239 | char* pout = NULL((void*)0); | |||
240 | size_t in_length = 0; | |||
241 | size_t out_length = 0; | |||
242 | ByteArray bain = NULL((void*)0); | |||
243 | ByteArray baout = NULL((void*)0); | |||
244 | if (isByteArray(L, WSLUA_OPTARG_GcryptCipher_decrypt_IN3)) { | |||
245 | bain = checkByteArray(L, WSLUA_OPTARG_GcryptCipher_decrypt_IN3); | |||
246 | pin = bain->data; | |||
247 | in_length = (size_t) bain->len; | |||
248 | } | |||
249 | if (isByteArray(L, WSLUA_ARG_GcryptCipher_decrypt_OUT2)) { | |||
250 | baout = checkByteArray(L, WSLUA_ARG_GcryptCipher_decrypt_OUT2); | |||
251 | pout = baout->data; | |||
252 | out_length = (size_t) baout->len; | |||
253 | bain = NULL((void*)0); | |||
254 | pin = NULL((void*)0); | |||
255 | in_length = (size_t) 0; | |||
256 | } else { | |||
257 | baout = g_byte_array_new(); | |||
258 | if (bain != NULL((void*)0)) { | |||
259 | g_byte_array_set_size(baout, (int) bain->len); | |||
260 | } | |||
261 | pout = baout->data; | |||
262 | out_length = (size_t) baout->len; | |||
263 | } | |||
264 | gcry_error_t err = gcry_cipher_decrypt(*gcry_cipher, pout, out_length, pin, in_length); | |||
265 | if (err) { | |||
266 | lua_pushstring(L, gcry_strerror(err)); | |||
267 | return lua_error(L); | |||
268 | } | |||
269 | if (bain != NULL((void*)0)) { | |||
270 | pushByteArray(L, baout); | |||
271 | WSLUA_RETURN(1)return (1); | |||
272 | } else { | |||
273 | WSLUA_RETURN(0)return (0); | |||
274 | } | |||
275 | } | |||
276 | ||||
277 | WSLUA_METHODstatic int GcryptCipher_setkey(lua_State* L) { | |||
278 | /* | |||
279 | Set KEY of length KEYLEN bytes for the cipher handle HD. | |||
280 | ||||
281 | ===== Example | |||
282 | ||||
283 | [source,lua] | |||
284 | ---- | |||
285 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
286 | cipher:setkey(ByteArray.new("abcdefabcdef1234abcdefabcdef1234")) | |||
287 | ---- | |||
288 | */ | |||
289 | #define WSLUA_ARG_GcryptCipher_setkey_KEY2 2 /* <<lua_class_ByteArray,`ByteArray`>> as buffer and buffer length. */ | |||
290 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
291 | ByteArray buffer = checkByteArray(L, WSLUA_ARG_GcryptCipher_setkey_KEY2); | |||
292 | gcry_error_t err = gcry_cipher_setkey(*gcry_cipher, buffer->data, (size_t) buffer->len); | |||
293 | if (err) { | |||
294 | lua_pushstring(L, gcry_strerror(err)); | |||
295 | return lua_error(L); | |||
296 | } | |||
297 | WSLUA_RETURN(0)return (0); | |||
298 | } | |||
299 | ||||
300 | WSLUA_METHODstatic int GcryptCipher_setiv(lua_State* L) { | |||
301 | /* | |||
302 | Set initialization vector IV of length IVLEN for the cipher handle HD. | |||
303 | ||||
304 | ===== Example | |||
305 | ||||
306 | [source,lua] | |||
307 | ---- | |||
308 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
309 | cipher:setiv(ByteArray.new("abcdefabcdef1234abcdefabcdef1234")) | |||
310 | ---- | |||
311 | */ | |||
312 | #define WSLUA_ARG_GcryptCipher_setiv_IV2 2 /* <<lua_class_ByteArray,`ByteArray`>> as buffer and buffer length. */ | |||
313 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
314 | ByteArray buffer = checkByteArray(L, WSLUA_ARG_GcryptCipher_setiv_IV2); | |||
315 | gcry_error_t err = gcry_cipher_setiv(*gcry_cipher, buffer->data, (size_t) buffer->len); | |||
316 | if (err) { | |||
317 | lua_pushstring(L, gcry_strerror(err)); | |||
318 | return lua_error(L); | |||
319 | } | |||
320 | WSLUA_RETURN(0)return (0); | |||
321 | } | |||
322 | ||||
323 | WSLUA_METHODstatic int GcryptCipher_authenticate(lua_State* L) { | |||
324 | /* | |||
325 | Provide additional authentication data for AEAD modes/ciphers. | |||
326 | ||||
327 | ===== Example | |||
328 | ||||
329 | [source,lua] | |||
330 | ---- | |||
331 | local cipher_encrypt = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_GCM, 0) | |||
332 | cipher_encrypt:setkey(ByteArray.new("abcdefabcdef1234abcdefabcdef1234")) | |||
333 | cipher_encrypt:setiv(ByteArray.new("01020304050607080102030405060708")) | |||
334 | ||||
335 | local cipher_decrypt = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_GCM, 0) | |||
336 | cipher_decrypt:setkey(ByteArray.new("abcdefabcdef1234abcdefabcdef1234")) | |||
337 | cipher_decrypt:setiv(ByteArray.new("01020304050607080102030405060708")) | |||
338 | ||||
339 | print("Plain data: " .. ByteArray.new("000102030405060708090a0b0c0d0e0f"):tohex()) | |||
340 | cipher_encrypt:authenticate(ByteArray.new("55667788")) | |||
341 | local encrypted = cipher_encrypt:encrypt(NULL, | |||
342 | ByteArray.new("000102030405060708090a0b0c0d0e0f")) | |||
343 | local tag = cipher_encrypt:gettag() | |||
344 | print("Encrypted data: " .. encrypted:tohex()) | |||
345 | print("Tag: " .. tag:tohex()) | |||
346 | ||||
347 | cipher_decrypt:authenticate(ByteArray.new("55667788")) | |||
348 | local decrypted = cipher_decrypt:decrypt(NULL, encrypted) | |||
349 | local result, errstring = cipher_decrypt:checktag(tag) | |||
350 | if (result == 0) then | |||
351 | print("Message ok!") | |||
352 | print("Decrypted data: " .. decrypted:tohex()) | |||
353 | else | |||
354 | print("Manipulated message: " .. errstring) | |||
355 | end | |||
356 | ---- | |||
357 | */ | |||
358 | #define WSLUA_ARG_GcryptCipher_authenticate_ABUF2 2 /* <<lua_class_ByteArray,`ByteArray`>> as authentication data. */ | |||
359 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
360 | ByteArray buffer = checkByteArray(L, WSLUA_ARG_GcryptCipher_authenticate_ABUF2); | |||
361 | gcry_error_t err = gcry_cipher_authenticate(*gcry_cipher, buffer->data, (size_t) buffer->len); | |||
362 | if (err) { | |||
363 | lua_pushstring(L, gcry_strerror(err)); | |||
364 | return lua_error(L); | |||
365 | } | |||
366 | WSLUA_RETURN(0)return (0); | |||
367 | } | |||
368 | ||||
369 | WSLUA_METHODstatic int GcryptCipher_gettag(lua_State* L) { | |||
370 | /* | |||
371 | Get authentication tag for AEAD modes/ciphers. | |||
372 | */ | |||
373 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
374 | ByteArray ba = g_byte_array_new(); | |||
375 | size_t tag_size = 0; | |||
376 | gcry_error_t err = gcry_cipher_info(*gcry_cipher, GCRYCTL_GET_TAGLEN, NULL((void*)0), &tag_size); | |||
377 | if (!err) { | |||
378 | g_byte_array_set_size(ba, (int)tag_size); | |||
379 | err = gcry_cipher_gettag(*gcry_cipher, ba->data, (size_t) ba->len); | |||
380 | } | |||
381 | if (err) { | |||
382 | lua_pushstring(L, gcry_strerror(err)); | |||
383 | return lua_error(L); | |||
384 | } | |||
385 | pushByteArray(L, ba); | |||
386 | WSLUA_RETURN(1)return (1); | |||
387 | } | |||
388 | ||||
389 | WSLUA_METHODstatic int GcryptCipher_checktag(lua_State* L) { | |||
390 | /* | |||
391 | Check authentication tag for AEAD modes/ciphers. | |||
392 | */ | |||
393 | #define WSLUA_ARG_GcryptCipher_checktag_TAG2 2 /* <<lua_class_ByteArray,`ByteArray`>> as authentication tag to check. */ | |||
394 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
395 | ByteArray buffer = checkByteArray(L, WSLUA_ARG_GcryptCipher_checktag_TAG2); | |||
396 | gcry_error_t err = gcry_cipher_checktag(*gcry_cipher, buffer->data, (size_t) buffer->len); | |||
397 | lua_pushinteger(L, err); | |||
398 | if (err) { | |||
399 | lua_pushstring(L, gcry_strerror(err)); | |||
400 | WSLUA_RETURN(2)return (2); | |||
401 | } | |||
402 | WSLUA_RETURN(1)return (1); | |||
403 | } | |||
404 | ||||
405 | WSLUA_METHODstatic int GcryptCipher_setctr(lua_State* L) { | |||
406 | /* | |||
407 | Set counter for CTR mode. (CTR,CTRLEN) must denote a buffer of | |||
408 | block size length, or (NULL,0) to set the CTR to the all-zero block. | |||
409 | ||||
410 | ===== Example | |||
411 | ||||
412 | [source,lua] | |||
413 | ---- | |||
414 | local cipher = GcryptCipher.open(GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0) | |||
415 | cipher:setctr(ByteArray.new("000102030405060708090A0B0C0D0E0F"), 16) | |||
416 | ---- | |||
417 | */ | |||
418 | #define WSLUA_ARG_GcryptCipher_setctr_CTR2 2 /* <<lua_class_ByteArray,`ByteArray`>> with ctr or NULL */ | |||
419 | #define WSLUA_ARG_GcryptCipher_setctr_CTRLEN3 3 /* CTR Length */ | |||
420 | GcryptCipher gcry_cipher = checkGcryptCipher(L, 1); | |||
421 | char* pctr = NULL((void*)0); | |||
422 | ByteArray ba = NULL((void*)0); | |||
423 | int ctrlen = 0; | |||
424 | if (isByteArray(L, WSLUA_ARG_GcryptCipher_setctr_CTR2)) { | |||
425 | ba = checkByteArray(L, WSLUA_ARG_GcryptCipher_setctr_CTR2); | |||
426 | pctr = ba->data; | |||
427 | } | |||
428 | if (lua_isinteger(L, WSLUA_ARG_GcryptCipher_setctr_CTRLEN3)) { | |||
429 | ctrlen = (int)luaL_checkinteger(L, WSLUA_ARG_GcryptCipher_setctr_CTRLEN3); | |||
430 | } | |||
431 | gcry_error_t err = gcry_cipher_setctr(*gcry_cipher, pctr, ctrlen); | |||
432 | if (err) { | |||
433 | lua_pushstring(L, gcry_strerror(err)); | |||
434 | return lua_error(L); | |||
435 | } | |||
436 | WSLUA_RETURN(0)return (0); | |||
437 | } | |||
438 | ||||
439 | WSLUA_FUNCTIONextern int wslua_gcry_cipher_algo_info(lua_State* L) { | |||
440 | /* | |||
441 | Retrieve various information about the cipher algorithm ALGO. | |||
442 | ||||
443 | ===== Example | |||
444 | ||||
445 | [source,lua] | |||
446 | ---- | |||
447 | local userdata, nbytes = gcry_cipher_algo_info(GCRY_CIPHER_AES, GCRYCTL_GET_KEYLEN, NULL, 0) | |||
448 | print("Key length: " .. nbytes) | |||
449 | local userdata, nbytes = gcry_cipher_algo_info(GCRY_CIPHER_AES, GCRYCTL_GET_BLKLEN, NULL, 0) | |||
450 | print("Block length: " .. nbytes) | |||
451 | local status = gcry_cipher_algo_info(GCRY_CIPHER_AES, GCRYCTL_TEST_ALGO) | |||
452 | if (status == 0) then | |||
453 | print("GCRY_CIPHER_AES - Supported.") | |||
454 | else | |||
455 | print("GCRY_CIPHER_AES - Not supported.") | |||
456 | end | |||
457 | ---- | |||
458 | */ | |||
459 | #define WSLUA_ARG_gcry_cipher_algo_info_ALGORITHM1 1 /* Select the algorithm for this function. */ | |||
460 | #define WSLUA_ARG_gcry_cipher_algo_info_WHAT2 2 /* Select the algorithm for this function. */ | |||
461 | #define WSLUA_OPTARG_gcry_cipher_algo_info_BUFFER_SIZE3 3 /* Buffer size or NULL, optional only if nbytes not present. */ | |||
462 | #define WSLUA_OPTARG_gcry_cipher_algo_info_NBYTES4 4 /* Nbytes integer or NULL, optional. */ | |||
463 | int algo = (int)luaL_checkinteger(L, WSLUA_ARG_gcry_cipher_algo_info_ALGORITHM1); | |||
464 | int what = (int)luaL_checkinteger(L, WSLUA_ARG_gcry_cipher_algo_info_WHAT2); | |||
465 | size_t *pnbytes = NULL((void*)0); | |||
466 | char* pbuffer = NULL((void*)0); | |||
467 | ByteArray ba = g_byte_array_new(); | |||
468 | size_t nbytes = 0; | |||
469 | if (lua_isinteger(L, WSLUA_OPTARG_gcry_cipher_algo_info_BUFFER_SIZE3)) { | |||
470 | g_byte_array_set_size(ba, (int) luaL_checkinteger(L, WSLUA_OPTARG_gcry_cipher_algo_info_BUFFER_SIZE3)); | |||
471 | pbuffer = ba->data; | |||
472 | } | |||
473 | if (lua_isinteger(L, WSLUA_OPTARG_gcry_cipher_algo_info_NBYTES4)) { | |||
474 | nbytes = (int)luaL_checkinteger(L, WSLUA_OPTARG_gcry_cipher_algo_info_NBYTES4); | |||
475 | pnbytes = (size_t *) &nbytes; | |||
476 | } | |||
477 | gcry_error_t err = gcry_cipher_algo_info(algo, what, pbuffer, pnbytes); | |||
478 | if (what == GCRYCTL_TEST_ALGO) { | |||
479 | lua_pushinteger(L, err); | |||
480 | WSLUA_RETURN(1)return (1); | |||
481 | } | |||
482 | if (err) { | |||
483 | lua_pushstring(L, gcry_strerror(err)); | |||
484 | return lua_error(L); | |||
485 | } | |||
486 | pushByteArray(L, ba); | |||
487 | if (!err || (pnbytes != NULL((void*)0))) { | |||
488 | lua_pushinteger(L, (int) nbytes); | |||
489 | } | |||
490 | else { | |||
491 | lua_pushinteger(L, -1); | |||
492 | } | |||
493 | WSLUA_RETURN(2)return (2); | |||
494 | } | |||
495 | ||||
496 | WSLUA_FUNCTIONextern int wslua_gcry_cipher_algo_name(lua_State* L) { | |||
497 | /* | |||
498 | Map the cipher algorithm whose ID is contained in ALGORITHM to a | |||
499 | string representation of the algorithm name. For unknown algorithm | |||
500 | IDs this function returns "?". | |||
501 | ||||
502 | ===== Example | |||
503 | ||||
504 | [source,lua] | |||
505 | ---- | |||
506 | local name = gcry_cipher_algo_name(GCRY_CIPHER_AES) | |||
507 | print(name) | |||
508 | ---- | |||
509 | */ | |||
510 | #define WSLUA_ARG_gcry_cipher_algo_name_ALGORITHM1 1 /* Algorithm id for this function. */ | |||
511 | int algo = (int)luaL_checkinteger(L, WSLUA_ARG_gcry_cipher_algo_name_ALGORITHM1); | |||
512 | lua_pushstring(L, gcry_cipher_algo_name (algo)); | |||
513 | WSLUA_RETURN(1)return (1); | |||
514 | } | |||
515 | ||||
516 | WSLUA_FUNCTIONextern int wslua_gcry_cipher_map_name(lua_State* L) { | |||
517 | /* | |||
518 | Map the algorithm name NAME to an cipher algorithm ID. Return 0 if | |||
519 | the algorithm name is not known. | |||
520 | ||||
521 | ===== Example | |||
522 | ||||
523 | [source,lua] | |||
524 | ---- | |||
525 | local id = gcry_cipher_map_name("AES") | |||
526 | print(id) | |||
527 | ---- | |||
528 | */ | |||
529 | #define WSLUA_ARG_gcry_cipher_map_name_ALGORITHM1 1 /* Algorithm name for this function. */ | |||
530 | const char* algo = luaL_checkstring(L, WSLUA_ARG_gcry_cipher_map_name_ALGORITHM)(luaL_checklstring(L, (1), ((void*)0))); | |||
531 | lua_pushinteger(L, gcry_cipher_map_name(algo)); | |||
532 | WSLUA_RETURN(1)return (1); | |||
533 | } | |||
534 | ||||
535 | WSLUA_FUNCTIONextern int wslua_gcry_cipher_mode_from_oid(lua_State* L) { | |||
536 | /* | |||
537 | Given an ASN.1 object identifier in standard IETF dotted decimal | |||
538 | format in STRING, return the encryption mode associated with that | |||
539 | OID or 0 if not known or applicable. | |||
540 | ||||
541 | ===== Example | |||
542 | ||||
543 | [source,lua] | |||
544 | ---- | |||
545 | local mode = gcry_cipher_mode_from_oid("2.16.840.1.101.3.4.1.2") | |||
546 | -- reurned value 3 means GCRY_CIPHER_MODE_CBC | |||
547 | print(mode) | |||
548 | ---- | |||
549 | */ | |||
550 | #define WSLUA_ARG_gcry_cipher_mode_from_oid_STRING1 1 /* ASN.1 object identifier as STRING. */ | |||
551 | const char* asn1 = luaL_checkstring(L, WSLUA_ARG_gcry_cipher_mode_from_oid_STRING)(luaL_checklstring(L, (1), ((void*)0))); | |||
552 | lua_pushinteger(L, gcry_cipher_mode_from_oid(asn1)); | |||
553 | WSLUA_RETURN(1)return (1); | |||
554 | } | |||
555 | ||||
556 | WSLUA_FUNCTIONextern int wslua_gcry_cipher_get_algo_keylen(lua_State* L) { | |||
557 | /* | |||
558 | Retrieve the key length in bytes used with algorithm A. | |||
559 | ||||
560 | ===== Example | |||
561 | ||||
562 | [source,lua] | |||
563 | ---- | |||
564 | local length = gcry_cipher_get_algo_keylen(GCRY_CIPHER_AES) | |||
565 | print(length) | |||
566 | ---- | |||
567 | */ | |||
568 | #define WSLUA_ARG_gcry_cipher_get_algo_keylen_ALGORITHM1 1 /* Algorithm id for this function. */ | |||
569 | int algo = (int)luaL_checkinteger(L, WSLUA_ARG_gcry_cipher_get_algo_keylen_ALGORITHM1); | |||
570 | lua_pushinteger(L, gcry_cipher_get_algo_keylen(algo)); | |||
571 | WSLUA_RETURN(1)return (1); | |||
572 | } | |||
573 | ||||
574 | WSLUA_FUNCTIONextern int wslua_gcry_cipher_get_algo_blklen(lua_State* L) { | |||
575 | /* | |||
576 | Retrieve the block length in bytes used with algorithm A. | |||
577 | ||||
578 | ===== Example | |||
579 | ||||
580 | [source,lua] | |||
581 | ---- | |||
582 | local length = gcry_cipher_get_algo_blklen(GCRY_CIPHER_AES) | |||
583 | print(length) | |||
584 | ---- | |||
585 | */ | |||
586 | #define WSLUA_ARG_gcry_cipher_get_algo_blklen_ALGORITHM1 1 /* Algorithm id for this function. */ | |||
587 | int algo = (int)luaL_checkinteger(L, WSLUA_ARG_gcry_cipher_get_algo_blklen_ALGORITHM1); | |||
588 | lua_pushinteger(L, gcry_cipher_get_algo_blklen(algo)); | |||
589 | WSLUA_RETURN(1)return (1); | |||
590 | } | |||
591 | ||||
592 | WSLUA_METHODSstatic const luaL_Reg GcryptCipher_methods[] = { | |||
593 | WSLUA_CLASS_FNREG(GcryptCipher, open){ "open", GcryptCipher_open }, | |||
594 | WSLUA_CLASS_FNREG(GcryptCipher, ctl){ "ctl", GcryptCipher_ctl }, | |||
595 | WSLUA_CLASS_FNREG(GcryptCipher, info){ "info", GcryptCipher_info }, | |||
596 | WSLUA_CLASS_FNREG(GcryptCipher, encrypt){ "encrypt", GcryptCipher_encrypt }, | |||
597 | WSLUA_CLASS_FNREG(GcryptCipher, decrypt){ "decrypt", GcryptCipher_decrypt }, | |||
598 | WSLUA_CLASS_FNREG(GcryptCipher, setkey){ "setkey", GcryptCipher_setkey }, | |||
599 | WSLUA_CLASS_FNREG(GcryptCipher, setiv){ "setiv", GcryptCipher_setiv }, | |||
600 | WSLUA_CLASS_FNREG(GcryptCipher, authenticate){ "authenticate", GcryptCipher_authenticate }, | |||
601 | WSLUA_CLASS_FNREG(GcryptCipher, gettag){ "gettag", GcryptCipher_gettag }, | |||
602 | WSLUA_CLASS_FNREG(GcryptCipher, checktag){ "checktag", GcryptCipher_checktag }, | |||
603 | WSLUA_CLASS_FNREG(GcryptCipher, setctr){ "setctr", GcryptCipher_setctr }, | |||
604 | { NULL((void*)0), NULL((void*)0) } | |||
605 | }; | |||
606 | ||||
607 | WSLUA_METAstatic const luaL_Reg GcryptCipher_meta[] = { | |||
608 | { NULL((void*)0), NULL((void*)0) } | |||
609 | }; | |||
610 | ||||
611 | int GcryptCipher_register(lua_State* L) { | |||
612 | // cipher identifiers | |||
613 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_NONE", 0){ lua_pushinteger(L,0); lua_setglobal(L,"GCRY_CIPHER_NONE"); }; | |||
614 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_IDEA", 1){ lua_pushinteger(L,1); lua_setglobal(L,"GCRY_CIPHER_IDEA"); }; | |||
615 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_3DES", 2){ lua_pushinteger(L,2); lua_setglobal(L,"GCRY_CIPHER_3DES"); }; | |||
616 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CAST5", 3){ lua_pushinteger(L,3); lua_setglobal(L,"GCRY_CIPHER_CAST5"); }; | |||
617 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_BLOWFISH", 4){ lua_pushinteger(L,4); lua_setglobal(L,"GCRY_CIPHER_BLOWFISH" ); }; | |||
618 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SAFER_SK128", 5){ lua_pushinteger(L,5); lua_setglobal(L,"GCRY_CIPHER_SAFER_SK128" ); }; | |||
619 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_DES_SK", 6){ lua_pushinteger(L,6); lua_setglobal(L,"GCRY_CIPHER_DES_SK") ; }; | |||
620 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_AES", 7){ lua_pushinteger(L,7); lua_setglobal(L,"GCRY_CIPHER_AES"); }; | |||
621 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_AES192", 8){ lua_pushinteger(L,8); lua_setglobal(L,"GCRY_CIPHER_AES192") ; }; | |||
622 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_AES256", 9){ lua_pushinteger(L,9); lua_setglobal(L,"GCRY_CIPHER_AES256") ; }; | |||
623 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_TWOFISH", 10){ lua_pushinteger(L,10); lua_setglobal(L,"GCRY_CIPHER_TWOFISH" ); }; | |||
624 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_ARCFOUR", 301){ lua_pushinteger(L,301); lua_setglobal(L,"GCRY_CIPHER_ARCFOUR" ); }; | |||
625 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_DES", 302){ lua_pushinteger(L,302); lua_setglobal(L,"GCRY_CIPHER_DES"); }; | |||
626 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_TWOFISH128", 303){ lua_pushinteger(L,303); lua_setglobal(L,"GCRY_CIPHER_TWOFISH128" ); }; | |||
627 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SERPENT128", 304){ lua_pushinteger(L,304); lua_setglobal(L,"GCRY_CIPHER_SERPENT128" ); }; | |||
628 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SERPENT192", 305){ lua_pushinteger(L,305); lua_setglobal(L,"GCRY_CIPHER_SERPENT192" ); }; | |||
629 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SERPENT256", 306){ lua_pushinteger(L,306); lua_setglobal(L,"GCRY_CIPHER_SERPENT256" ); }; | |||
630 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_RFC2268_40", 307){ lua_pushinteger(L,307); lua_setglobal(L,"GCRY_CIPHER_RFC2268_40" ); }; | |||
631 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_RFC2268_128", 308){ lua_pushinteger(L,308); lua_setglobal(L,"GCRY_CIPHER_RFC2268_128" ); }; | |||
632 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SEED", 309){ lua_pushinteger(L,309); lua_setglobal(L,"GCRY_CIPHER_SEED") ; }; | |||
633 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CAMELLIA128", 310){ lua_pushinteger(L,310); lua_setglobal(L,"GCRY_CIPHER_CAMELLIA128" ); }; | |||
634 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CAMELLIA192", 311){ lua_pushinteger(L,311); lua_setglobal(L,"GCRY_CIPHER_CAMELLIA192" ); }; | |||
635 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CAMELLIA256", 312){ lua_pushinteger(L,312); lua_setglobal(L,"GCRY_CIPHER_CAMELLIA256" ); }; | |||
636 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SALSA20", 313){ lua_pushinteger(L,313); lua_setglobal(L,"GCRY_CIPHER_SALSA20" ); }; | |||
637 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SALSA20R12", 314){ lua_pushinteger(L,314); lua_setglobal(L,"GCRY_CIPHER_SALSA20R12" ); }; | |||
638 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_GOST28147", 315){ lua_pushinteger(L,315); lua_setglobal(L,"GCRY_CIPHER_GOST28147" ); }; | |||
639 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CHACHA20", 316){ lua_pushinteger(L,316); lua_setglobal(L,"GCRY_CIPHER_CHACHA20" ); }; | |||
640 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_GOST28147_MESH", 317){ lua_pushinteger(L,317); lua_setglobal(L,"GCRY_CIPHER_GOST28147_MESH" ); }; | |||
641 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SM4", 318){ lua_pushinteger(L,318); lua_setglobal(L,"GCRY_CIPHER_SM4"); }; | |||
642 | // mode identifiers | |||
643 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_NONE", 0){ lua_pushinteger(L,0); lua_setglobal(L,"GCRY_CIPHER_MODE_NONE" ); }; | |||
644 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_ECB", 1){ lua_pushinteger(L,1); lua_setglobal(L,"GCRY_CIPHER_MODE_ECB" ); }; | |||
645 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_CFB", 2){ lua_pushinteger(L,2); lua_setglobal(L,"GCRY_CIPHER_MODE_CFB" ); }; | |||
646 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_CBC", 3){ lua_pushinteger(L,3); lua_setglobal(L,"GCRY_CIPHER_MODE_CBC" ); }; | |||
647 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_STREAM", 4){ lua_pushinteger(L,4); lua_setglobal(L,"GCRY_CIPHER_MODE_STREAM" ); }; | |||
648 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_OFB", 5){ lua_pushinteger(L,5); lua_setglobal(L,"GCRY_CIPHER_MODE_OFB" ); }; | |||
649 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_CTR", 6){ lua_pushinteger(L,6); lua_setglobal(L,"GCRY_CIPHER_MODE_CTR" ); }; | |||
650 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_AESWRAP", 7){ lua_pushinteger(L,7); lua_setglobal(L,"GCRY_CIPHER_MODE_AESWRAP" ); }; | |||
651 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_CCM", 8){ lua_pushinteger(L,8); lua_setglobal(L,"GCRY_CIPHER_MODE_CCM" ); }; | |||
652 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_GCM", 9){ lua_pushinteger(L,9); lua_setglobal(L,"GCRY_CIPHER_MODE_GCM" ); }; | |||
653 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_POLY1305", 10){ lua_pushinteger(L,10); lua_setglobal(L,"GCRY_CIPHER_MODE_POLY1305" ); }; | |||
654 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_OCB", 11){ lua_pushinteger(L,11); lua_setglobal(L,"GCRY_CIPHER_MODE_OCB" ); }; | |||
655 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_CFB8", 12){ lua_pushinteger(L,12); lua_setglobal(L,"GCRY_CIPHER_MODE_CFB8" ); }; | |||
656 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_XTS", 13){ lua_pushinteger(L,13); lua_setglobal(L,"GCRY_CIPHER_MODE_XTS" ); }; | |||
657 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_MODE_EAX", 14){ lua_pushinteger(L,14); lua_setglobal(L,"GCRY_CIPHER_MODE_EAX" ); }; | |||
658 | // cipher flags | |||
659 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_SECURE", 1){ lua_pushinteger(L,1); lua_setglobal(L,"GCRY_CIPHER_SECURE") ; }; | |||
660 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_ENABLE_SYNC", 2){ lua_pushinteger(L,2); lua_setglobal(L,"GCRY_CIPHER_ENABLE_SYNC" ); }; | |||
661 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CBC_CTS", 4){ lua_pushinteger(L,4); lua_setglobal(L,"GCRY_CIPHER_CBC_CTS" ); }; | |||
662 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRY_CIPHER_CBC_MAC", 8){ lua_pushinteger(L,8); lua_setglobal(L,"GCRY_CIPHER_CBC_MAC" ); }; | |||
663 | // cipher ctl identifiers | |||
664 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_CFB_SYNC", 3){ lua_pushinteger(L,3); lua_setglobal(L,"GCRYCTL_CFB_SYNC"); }; | |||
665 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_RESET", 4){ lua_pushinteger(L,4); lua_setglobal(L,"GCRYCTL_RESET"); }; | |||
666 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_FINALIZE", 5){ lua_pushinteger(L,5); lua_setglobal(L,"GCRYCTL_FINALIZE"); }; | |||
667 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_KEYLEN", 6){ lua_pushinteger(L,6); lua_setglobal(L,"GCRYCTL_GET_KEYLEN") ; }; | |||
668 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_BLKLEN", 7){ lua_pushinteger(L,7); lua_setglobal(L,"GCRYCTL_GET_BLKLEN") ; }; | |||
669 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_TEST_ALGO", 8){ lua_pushinteger(L,8); lua_setglobal(L,"GCRYCTL_TEST_ALGO"); }; | |||
670 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_IS_SECURE", 9){ lua_pushinteger(L,9); lua_setglobal(L,"GCRYCTL_IS_SECURE"); }; | |||
671 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_ASNOID", 10){ lua_pushinteger(L,10); lua_setglobal(L,"GCRYCTL_GET_ASNOID" ); }; | |||
672 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_ENABLE_ALGO", 11){ lua_pushinteger(L,11); lua_setglobal(L,"GCRYCTL_ENABLE_ALGO" ); }; | |||
673 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_ALGO", 12){ lua_pushinteger(L,12); lua_setglobal(L,"GCRYCTL_DISABLE_ALGO" ); }; | |||
674 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DUMP_RANDOM_STATS", 13){ lua_pushinteger(L,13); lua_setglobal(L,"GCRYCTL_DUMP_RANDOM_STATS" ); }; | |||
675 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DUMP_SECMEM_STATS", 14){ lua_pushinteger(L,14); lua_setglobal(L,"GCRYCTL_DUMP_SECMEM_STATS" ); }; | |||
676 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_ALGO_NPKEY", 15){ lua_pushinteger(L,15); lua_setglobal(L,"GCRYCTL_GET_ALGO_NPKEY" ); }; | |||
677 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_ALGO_NSKEY", 16){ lua_pushinteger(L,16); lua_setglobal(L,"GCRYCTL_GET_ALGO_NSKEY" ); }; | |||
678 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_ALGO_NSIGN", 17){ lua_pushinteger(L,17); lua_setglobal(L,"GCRYCTL_GET_ALGO_NSIGN" ); }; | |||
679 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_ALGO_NENCR", 18){ lua_pushinteger(L,18); lua_setglobal(L,"GCRYCTL_GET_ALGO_NENCR" ); }; | |||
680 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_VERBOSITY", 19){ lua_pushinteger(L,19); lua_setglobal(L,"GCRYCTL_SET_VERBOSITY" ); }; | |||
681 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_DEBUG_FLAGS", 20){ lua_pushinteger(L,20); lua_setglobal(L,"GCRYCTL_SET_DEBUG_FLAGS" ); }; | |||
682 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_CLEAR_DEBUG_FLAGS", 21){ lua_pushinteger(L,21); lua_setglobal(L,"GCRYCTL_CLEAR_DEBUG_FLAGS" ); }; | |||
683 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_USE_SECURE_RNDPOOL", 22){ lua_pushinteger(L,22); lua_setglobal(L,"GCRYCTL_USE_SECURE_RNDPOOL" ); }; | |||
684 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DUMP_MEMORY_STATS", 23){ lua_pushinteger(L,23); lua_setglobal(L,"GCRYCTL_DUMP_MEMORY_STATS" ); }; | |||
685 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_INIT_SECMEM", 24){ lua_pushinteger(L,24); lua_setglobal(L,"GCRYCTL_INIT_SECMEM" ); }; | |||
686 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_TERM_SECMEM", 25){ lua_pushinteger(L,25); lua_setglobal(L,"GCRYCTL_TERM_SECMEM" ); }; | |||
687 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_SECMEM_WARN", 27){ lua_pushinteger(L,27); lua_setglobal(L,"GCRYCTL_DISABLE_SECMEM_WARN" ); }; | |||
688 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SUSPEND_SECMEM_WARN", 28){ lua_pushinteger(L,28); lua_setglobal(L,"GCRYCTL_SUSPEND_SECMEM_WARN" ); }; | |||
689 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_RESUME_SECMEM_WARN", 29){ lua_pushinteger(L,29); lua_setglobal(L,"GCRYCTL_RESUME_SECMEM_WARN" ); }; | |||
690 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DROP_PRIVS", 30){ lua_pushinteger(L,30); lua_setglobal(L,"GCRYCTL_DROP_PRIVS" ); }; | |||
691 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_ENABLE_M_GUARD", 31){ lua_pushinteger(L,31); lua_setglobal(L,"GCRYCTL_ENABLE_M_GUARD" ); }; | |||
692 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_START_DUMP", 32){ lua_pushinteger(L,32); lua_setglobal(L,"GCRYCTL_START_DUMP" ); }; | |||
693 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_STOP_DUMP", 33){ lua_pushinteger(L,33); lua_setglobal(L,"GCRYCTL_STOP_DUMP") ; }; | |||
694 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_ALGO_USAGE", 34){ lua_pushinteger(L,34); lua_setglobal(L,"GCRYCTL_GET_ALGO_USAGE" ); }; | |||
695 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_IS_ALGO_ENABLED", 35){ lua_pushinteger(L,35); lua_setglobal(L,"GCRYCTL_IS_ALGO_ENABLED" ); }; | |||
696 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_INTERNAL_LOCKING", 36){ lua_pushinteger(L,36); lua_setglobal(L,"GCRYCTL_DISABLE_INTERNAL_LOCKING" ); }; | |||
697 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_SECMEM", 37){ lua_pushinteger(L,37); lua_setglobal(L,"GCRYCTL_DISABLE_SECMEM" ); }; | |||
698 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_INITIALIZATION_FINISHED", 38){ lua_pushinteger(L,38); lua_setglobal(L,"GCRYCTL_INITIALIZATION_FINISHED" ); }; | |||
699 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_INITIALIZATION_FINISHED_P", 39){ lua_pushinteger(L,39); lua_setglobal(L,"GCRYCTL_INITIALIZATION_FINISHED_P" ); }; | |||
700 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_ANY_INITIALIZATION_P", 40){ lua_pushinteger(L,40); lua_setglobal(L,"GCRYCTL_ANY_INITIALIZATION_P" ); }; | |||
701 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_CBC_CTS", 41){ lua_pushinteger(L,41); lua_setglobal(L,"GCRYCTL_SET_CBC_CTS" ); }; | |||
702 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_CBC_MAC", 42){ lua_pushinteger(L,42); lua_setglobal(L,"GCRYCTL_SET_CBC_MAC" ); }; | |||
703 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_ENABLE_QUICK_RANDOM", 44){ lua_pushinteger(L,44); lua_setglobal(L,"GCRYCTL_ENABLE_QUICK_RANDOM" ); }; | |||
704 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_RANDOM_SEED_FILE", 45){ lua_pushinteger(L,45); lua_setglobal(L,"GCRYCTL_SET_RANDOM_SEED_FILE" ); }; | |||
705 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_UPDATE_RANDOM_SEED_FILE", 46){ lua_pushinteger(L,46); lua_setglobal(L,"GCRYCTL_UPDATE_RANDOM_SEED_FILE" ); }; | |||
706 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_THREAD_CBS", 47){ lua_pushinteger(L,47); lua_setglobal(L,"GCRYCTL_SET_THREAD_CBS" ); }; | |||
707 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_FAST_POLL", 48){ lua_pushinteger(L,48); lua_setglobal(L,"GCRYCTL_FAST_POLL") ; }; | |||
708 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_RANDOM_DAEMON_SOCKET", 49){ lua_pushinteger(L,49); lua_setglobal(L,"GCRYCTL_SET_RANDOM_DAEMON_SOCKET" ); }; | |||
709 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_USE_RANDOM_DAEMON", 50){ lua_pushinteger(L,50); lua_setglobal(L,"GCRYCTL_USE_RANDOM_DAEMON" ); }; | |||
710 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_FAKED_RANDOM_P", 51){ lua_pushinteger(L,51); lua_setglobal(L,"GCRYCTL_FAKED_RANDOM_P" ); }; | |||
711 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_RNDEGD_SOCKET", 52){ lua_pushinteger(L,52); lua_setglobal(L,"GCRYCTL_SET_RNDEGD_SOCKET" ); }; | |||
712 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_PRINT_CONFIG", 53){ lua_pushinteger(L,53); lua_setglobal(L,"GCRYCTL_PRINT_CONFIG" ); }; | |||
713 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_OPERATIONAL_P", 54){ lua_pushinteger(L,54); lua_setglobal(L,"GCRYCTL_OPERATIONAL_P" ); }; | |||
714 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_FIPS_MODE_P", 55){ lua_pushinteger(L,55); lua_setglobal(L,"GCRYCTL_FIPS_MODE_P" ); }; | |||
715 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_FORCE_FIPS_MODE", 56){ lua_pushinteger(L,56); lua_setglobal(L,"GCRYCTL_FORCE_FIPS_MODE" ); }; | |||
716 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SELFTEST", 57){ lua_pushinteger(L,57); lua_setglobal(L,"GCRYCTL_SELFTEST"); }; | |||
717 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_HWF", 63){ lua_pushinteger(L,63); lua_setglobal(L,"GCRYCTL_DISABLE_HWF" ); }; | |||
718 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_ENFORCED_FIPS_FLAG", 64){ lua_pushinteger(L,64); lua_setglobal(L,"GCRYCTL_SET_ENFORCED_FIPS_FLAG" ); }; | |||
719 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_PREFERRED_RNG_TYPE", 65){ lua_pushinteger(L,65); lua_setglobal(L,"GCRYCTL_SET_PREFERRED_RNG_TYPE" ); }; | |||
720 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_CURRENT_RNG_TYPE", 66){ lua_pushinteger(L,66); lua_setglobal(L,"GCRYCTL_GET_CURRENT_RNG_TYPE" ); }; | |||
721 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_LOCKED_SECMEM", 67){ lua_pushinteger(L,67); lua_setglobal(L,"GCRYCTL_DISABLE_LOCKED_SECMEM" ); }; | |||
722 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DISABLE_PRIV_DROP", 68){ lua_pushinteger(L,68); lua_setglobal(L,"GCRYCTL_DISABLE_PRIV_DROP" ); }; | |||
723 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_CCM_LENGTHS", 69){ lua_pushinteger(L,69); lua_setglobal(L,"GCRYCTL_SET_CCM_LENGTHS" ); }; | |||
724 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_CLOSE_RANDOM_DEVICE", 70){ lua_pushinteger(L,70); lua_setglobal(L,"GCRYCTL_CLOSE_RANDOM_DEVICE" ); }; | |||
725 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_INACTIVATE_FIPS_FLAG", 71){ lua_pushinteger(L,71); lua_setglobal(L,"GCRYCTL_INACTIVATE_FIPS_FLAG" ); }; | |||
726 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_REACTIVATE_FIPS_FLAG", 72){ lua_pushinteger(L,72); lua_setglobal(L,"GCRYCTL_REACTIVATE_FIPS_FLAG" ); }; | |||
727 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_SBOX", 73){ lua_pushinteger(L,73); lua_setglobal(L,"GCRYCTL_SET_SBOX"); }; | |||
728 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_DRBG_REINIT", 74){ lua_pushinteger(L,74); lua_setglobal(L,"GCRYCTL_DRBG_REINIT" ); }; | |||
729 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_TAGLEN", 75){ lua_pushinteger(L,75); lua_setglobal(L,"GCRYCTL_SET_TAGLEN" ); }; | |||
730 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_GET_TAGLEN", 76){ lua_pushinteger(L,76); lua_setglobal(L,"GCRYCTL_GET_TAGLEN" ); }; | |||
731 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_REINIT_SYSCALL_CLAMP", 77){ lua_pushinteger(L,77); lua_setglobal(L,"GCRYCTL_REINIT_SYSCALL_CLAMP" ); }; | |||
732 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_AUTO_EXPAND_SECMEM", 78){ lua_pushinteger(L,78); lua_setglobal(L,"GCRYCTL_AUTO_EXPAND_SECMEM" ); }; | |||
733 | WSLUA_REG_GLOBAL_INTEGER(L, "GCRYCTL_SET_ALLOW_WEAK_KEY", 79){ lua_pushinteger(L,79); lua_setglobal(L,"GCRYCTL_SET_ALLOW_WEAK_KEY" ); }; | |||
734 | WSLUA_REGISTER_CLASS(GcryptCipher){ const wslua_class GcryptCipher_class = { .name = "GcryptCipher" , .class_methods = GcryptCipher_methods, .class_meta = GcryptCipher_meta , .instance_methods = GcryptCipher_methods, .instance_meta = GcryptCipher_meta , .attrs = ((void*)0) }; wslua_register_class(L, &GcryptCipher_class ); (lua_getfield(L, (-1000000 - 1000), ("GcryptCipher"))); lua_pushcclosure (L, (GcryptCipher__gc), 0); lua_setfield(L, -2, "__gc"); lua_settop (L, -(1)-1); }; | |||
735 | return 0; | |||
736 | } | |||
737 | ||||
738 | /* | |||
739 | * Editor modelines - https://www.wireshark.org/tools/modelines.html | |||
740 | * | |||
741 | * Local variables: | |||
742 | * c-basic-offset: 4 | |||
743 | * tab-width: 8 | |||
744 | * indent-tabs-mode: nil | |||
745 | * End: | |||
746 | * | |||
747 | * vi: set shiftwidth=4 tabstop=8 expandtab: | |||
748 | * :indentSize=4:tabSize=8:noTabs=true: | |||
749 | */ |