Repository navigation
Expand file tree
/
Copy pathbuild_pyAES.py
More file actions
60 lines (48 loc) · 1.55 KB
/
Copy pathbuild_pyAES.py
File metadata and controls
60 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from os.path import join
import sys
from cffi import FFI
root = os.path.dirname(os.path.abspath(__file__))
ffibuilder = FFI()
libraries = [
"aes_cfb",
"cryptopp",
"stdc++",
]
if sys.platform == "win32":
libraries.append("advapi32")
# set_source() gives the name of the python extension module to
# produce, and some C source code as a string. This C code needs
# to make the declarated functions, types and globals available,
# so it is often just the "#include".
ffibuilder.set_source(
"py_aes_cfb",
"""
#include "aes_cfb.h"
""",
include_dirs=[
join(root, "cryptopp"),
join(root, "aes_cfb"),
],
library_dirs=[
join(root, "cryptopp"),
join(root, "aes_cfb"),
],
libraries=libraries,
extra_compile_args=[])
ffibuilder.cdef("""
int test_add_int(int a, int b);
typedef ... encryptor_t;
encryptor_t *encryptor_create(char *key, int key_len, char* iv, int iv_len);
void encryptor_update(encryptor_t *e, const char *plain_ptr, int plain_len, char *cipher_ptr);
void encryptor_destroy(encryptor_t *e);
typedef ... decryptor_t;
decryptor_t *decryptor_create(char *key, int key_len, char* iv, int iv_len);
void decryptor_update(decryptor_t *e, const char *in, int len, char *out);
void decryptor_destroy(decryptor_t *e);
""")
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == "generate_only":
ffibuilder.emit_c_code("cffi_aes_cfb/cffi_aes_cfb.c")
else:
ffibuilder.compile(verbose=True)