_padding.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. #define _CFFI_
  2. /* We try to define Py_LIMITED_API before including Python.h.
  3. Mess: we can only define it if Py_DEBUG, Py_TRACE_REFS and
  4. Py_REF_DEBUG are not defined. This is a best-effort approximation:
  5. we can learn about Py_DEBUG from pyconfig.h, but it is unclear if
  6. the same works for the other two macros. Py_DEBUG implies them,
  7. but not the other way around.
  8. */
  9. #ifndef _CFFI_USE_EMBEDDING
  10. # include <pyconfig.h>
  11. # if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
  12. # define Py_LIMITED_API
  13. # endif
  14. #endif
  15. #include <Python.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <stddef.h>
  20. /* This part is from file 'cffi/parse_c_type.h'. It is copied at the
  21. beginning of C sources generated by CFFI's ffi.set_source(). */
  22. typedef void *_cffi_opcode_t;
  23. #define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
  24. #define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
  25. #define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
  26. #define _CFFI_OP_PRIMITIVE 1
  27. #define _CFFI_OP_POINTER 3
  28. #define _CFFI_OP_ARRAY 5
  29. #define _CFFI_OP_OPEN_ARRAY 7
  30. #define _CFFI_OP_STRUCT_UNION 9
  31. #define _CFFI_OP_ENUM 11
  32. #define _CFFI_OP_FUNCTION 13
  33. #define _CFFI_OP_FUNCTION_END 15
  34. #define _CFFI_OP_NOOP 17
  35. #define _CFFI_OP_BITFIELD 19
  36. #define _CFFI_OP_TYPENAME 21
  37. #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
  38. #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
  39. #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
  40. #define _CFFI_OP_CONSTANT 29
  41. #define _CFFI_OP_CONSTANT_INT 31
  42. #define _CFFI_OP_GLOBAL_VAR 33
  43. #define _CFFI_OP_DLOPEN_FUNC 35
  44. #define _CFFI_OP_DLOPEN_CONST 37
  45. #define _CFFI_OP_GLOBAL_VAR_F 39
  46. #define _CFFI_OP_EXTERN_PYTHON 41
  47. #define _CFFI_PRIM_VOID 0
  48. #define _CFFI_PRIM_BOOL 1
  49. #define _CFFI_PRIM_CHAR 2
  50. #define _CFFI_PRIM_SCHAR 3
  51. #define _CFFI_PRIM_UCHAR 4
  52. #define _CFFI_PRIM_SHORT 5
  53. #define _CFFI_PRIM_USHORT 6
  54. #define _CFFI_PRIM_INT 7
  55. #define _CFFI_PRIM_UINT 8
  56. #define _CFFI_PRIM_LONG 9
  57. #define _CFFI_PRIM_ULONG 10
  58. #define _CFFI_PRIM_LONGLONG 11
  59. #define _CFFI_PRIM_ULONGLONG 12
  60. #define _CFFI_PRIM_FLOAT 13
  61. #define _CFFI_PRIM_DOUBLE 14
  62. #define _CFFI_PRIM_LONGDOUBLE 15
  63. #define _CFFI_PRIM_WCHAR 16
  64. #define _CFFI_PRIM_INT8 17
  65. #define _CFFI_PRIM_UINT8 18
  66. #define _CFFI_PRIM_INT16 19
  67. #define _CFFI_PRIM_UINT16 20
  68. #define _CFFI_PRIM_INT32 21
  69. #define _CFFI_PRIM_UINT32 22
  70. #define _CFFI_PRIM_INT64 23
  71. #define _CFFI_PRIM_UINT64 24
  72. #define _CFFI_PRIM_INTPTR 25
  73. #define _CFFI_PRIM_UINTPTR 26
  74. #define _CFFI_PRIM_PTRDIFF 27
  75. #define _CFFI_PRIM_SIZE 28
  76. #define _CFFI_PRIM_SSIZE 29
  77. #define _CFFI_PRIM_INT_LEAST8 30
  78. #define _CFFI_PRIM_UINT_LEAST8 31
  79. #define _CFFI_PRIM_INT_LEAST16 32
  80. #define _CFFI_PRIM_UINT_LEAST16 33
  81. #define _CFFI_PRIM_INT_LEAST32 34
  82. #define _CFFI_PRIM_UINT_LEAST32 35
  83. #define _CFFI_PRIM_INT_LEAST64 36
  84. #define _CFFI_PRIM_UINT_LEAST64 37
  85. #define _CFFI_PRIM_INT_FAST8 38
  86. #define _CFFI_PRIM_UINT_FAST8 39
  87. #define _CFFI_PRIM_INT_FAST16 40
  88. #define _CFFI_PRIM_UINT_FAST16 41
  89. #define _CFFI_PRIM_INT_FAST32 42
  90. #define _CFFI_PRIM_UINT_FAST32 43
  91. #define _CFFI_PRIM_INT_FAST64 44
  92. #define _CFFI_PRIM_UINT_FAST64 45
  93. #define _CFFI_PRIM_INTMAX 46
  94. #define _CFFI_PRIM_UINTMAX 47
  95. #define _CFFI__NUM_PRIM 48
  96. #define _CFFI__UNKNOWN_PRIM (-1)
  97. #define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
  98. #define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
  99. #define _CFFI__IO_FILE_STRUCT (-1)
  100. struct _cffi_global_s {
  101. const char *name;
  102. void *address;
  103. _cffi_opcode_t type_op;
  104. void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
  105. // OP_CPYTHON_BLTN_*: addr of direct function
  106. };
  107. struct _cffi_getconst_s {
  108. unsigned long long value;
  109. const struct _cffi_type_context_s *ctx;
  110. int gindex;
  111. };
  112. struct _cffi_struct_union_s {
  113. const char *name;
  114. int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
  115. int flags; // _CFFI_F_* flags below
  116. size_t size;
  117. int alignment;
  118. int first_field_index; // -> _cffi_fields array
  119. int num_fields;
  120. };
  121. #define _CFFI_F_UNION 0x01 // is a union, not a struct
  122. #define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
  123. // "standard layout" or if some are missing
  124. #define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
  125. #define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
  126. #define _CFFI_F_OPAQUE 0x10 // opaque
  127. struct _cffi_field_s {
  128. const char *name;
  129. size_t field_offset;
  130. size_t field_size;
  131. _cffi_opcode_t field_type_op;
  132. };
  133. struct _cffi_enum_s {
  134. const char *name;
  135. int type_index; // -> _cffi_types, on a OP_ENUM
  136. int type_prim; // _CFFI_PRIM_xxx
  137. const char *enumerators; // comma-delimited string
  138. };
  139. struct _cffi_typename_s {
  140. const char *name;
  141. int type_index; /* if opaque, points to a possibly artificial
  142. OP_STRUCT which is itself opaque */
  143. };
  144. struct _cffi_type_context_s {
  145. _cffi_opcode_t *types;
  146. const struct _cffi_global_s *globals;
  147. const struct _cffi_field_s *fields;
  148. const struct _cffi_struct_union_s *struct_unions;
  149. const struct _cffi_enum_s *enums;
  150. const struct _cffi_typename_s *typenames;
  151. int num_globals;
  152. int num_struct_unions;
  153. int num_enums;
  154. int num_typenames;
  155. const char *const *includes;
  156. int num_types;
  157. int flags; /* future extension */
  158. };
  159. struct _cffi_parse_info_s {
  160. const struct _cffi_type_context_s *ctx;
  161. _cffi_opcode_t *output;
  162. unsigned int output_size;
  163. size_t error_location;
  164. const char *error_message;
  165. };
  166. struct _cffi_externpy_s {
  167. const char *name;
  168. size_t size_of_result;
  169. void *reserved1, *reserved2;
  170. };
  171. #ifdef _CFFI_INTERNAL
  172. static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
  173. static int search_in_globals(const struct _cffi_type_context_s *ctx,
  174. const char *search, size_t search_len);
  175. static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
  176. const char *search, size_t search_len);
  177. #endif
  178. /* this block of #ifs should be kept exactly identical between
  179. c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
  180. and cffi/_cffi_include.h */
  181. #if defined(_MSC_VER)
  182. # include <malloc.h> /* for alloca() */
  183. # if _MSC_VER < 1600 /* MSVC < 2010 */
  184. typedef __int8 int8_t;
  185. typedef __int16 int16_t;
  186. typedef __int32 int32_t;
  187. typedef __int64 int64_t;
  188. typedef unsigned __int8 uint8_t;
  189. typedef unsigned __int16 uint16_t;
  190. typedef unsigned __int32 uint32_t;
  191. typedef unsigned __int64 uint64_t;
  192. typedef __int8 int_least8_t;
  193. typedef __int16 int_least16_t;
  194. typedef __int32 int_least32_t;
  195. typedef __int64 int_least64_t;
  196. typedef unsigned __int8 uint_least8_t;
  197. typedef unsigned __int16 uint_least16_t;
  198. typedef unsigned __int32 uint_least32_t;
  199. typedef unsigned __int64 uint_least64_t;
  200. typedef __int8 int_fast8_t;
  201. typedef __int16 int_fast16_t;
  202. typedef __int32 int_fast32_t;
  203. typedef __int64 int_fast64_t;
  204. typedef unsigned __int8 uint_fast8_t;
  205. typedef unsigned __int16 uint_fast16_t;
  206. typedef unsigned __int32 uint_fast32_t;
  207. typedef unsigned __int64 uint_fast64_t;
  208. typedef __int64 intmax_t;
  209. typedef unsigned __int64 uintmax_t;
  210. # else
  211. # include <stdint.h>
  212. # endif
  213. # if _MSC_VER < 1800 /* MSVC < 2013 */
  214. # ifndef __cplusplus
  215. typedef unsigned char _Bool;
  216. # endif
  217. # endif
  218. #else
  219. # include <stdint.h>
  220. # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
  221. # include <alloca.h>
  222. # endif
  223. #endif
  224. #ifdef __GNUC__
  225. # define _CFFI_UNUSED_FN __attribute__((unused))
  226. #else
  227. # define _CFFI_UNUSED_FN /* nothing */
  228. #endif
  229. #ifdef __cplusplus
  230. # ifndef _Bool
  231. typedef bool _Bool; /* semi-hackish: C++ has no _Bool; bool is builtin */
  232. # endif
  233. #endif
  234. /********** CPython-specific section **********/
  235. #ifndef PYPY_VERSION
  236. #if PY_MAJOR_VERSION >= 3
  237. # define PyInt_FromLong PyLong_FromLong
  238. #endif
  239. #define _cffi_from_c_double PyFloat_FromDouble
  240. #define _cffi_from_c_float PyFloat_FromDouble
  241. #define _cffi_from_c_long PyInt_FromLong
  242. #define _cffi_from_c_ulong PyLong_FromUnsignedLong
  243. #define _cffi_from_c_longlong PyLong_FromLongLong
  244. #define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
  245. #define _cffi_to_c_double PyFloat_AsDouble
  246. #define _cffi_to_c_float PyFloat_AsDouble
  247. #define _cffi_from_c_int(x, type) \
  248. (((type)-1) > 0 ? /* unsigned */ \
  249. (sizeof(type) < sizeof(long) ? \
  250. PyInt_FromLong((long)x) : \
  251. sizeof(type) == sizeof(long) ? \
  252. PyLong_FromUnsignedLong((unsigned long)x) : \
  253. PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
  254. (sizeof(type) <= sizeof(long) ? \
  255. PyInt_FromLong((long)x) : \
  256. PyLong_FromLongLong((long long)x)))
  257. #define _cffi_to_c_int(o, type) \
  258. ((type)( \
  259. sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
  260. : (type)_cffi_to_c_i8(o)) : \
  261. sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
  262. : (type)_cffi_to_c_i16(o)) : \
  263. sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
  264. : (type)_cffi_to_c_i32(o)) : \
  265. sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
  266. : (type)_cffi_to_c_i64(o)) : \
  267. (Py_FatalError("unsupported size for type " #type), (type)0)))
  268. #define _cffi_to_c_i8 \
  269. ((int(*)(PyObject *))_cffi_exports[1])
  270. #define _cffi_to_c_u8 \
  271. ((int(*)(PyObject *))_cffi_exports[2])
  272. #define _cffi_to_c_i16 \
  273. ((int(*)(PyObject *))_cffi_exports[3])
  274. #define _cffi_to_c_u16 \
  275. ((int(*)(PyObject *))_cffi_exports[4])
  276. #define _cffi_to_c_i32 \
  277. ((int(*)(PyObject *))_cffi_exports[5])
  278. #define _cffi_to_c_u32 \
  279. ((unsigned int(*)(PyObject *))_cffi_exports[6])
  280. #define _cffi_to_c_i64 \
  281. ((long long(*)(PyObject *))_cffi_exports[7])
  282. #define _cffi_to_c_u64 \
  283. ((unsigned long long(*)(PyObject *))_cffi_exports[8])
  284. #define _cffi_to_c_char \
  285. ((int(*)(PyObject *))_cffi_exports[9])
  286. #define _cffi_from_c_pointer \
  287. ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[10])
  288. #define _cffi_to_c_pointer \
  289. ((char *(*)(PyObject *, struct _cffi_ctypedescr *))_cffi_exports[11])
  290. #define _cffi_get_struct_layout \
  291. not used any more
  292. #define _cffi_restore_errno \
  293. ((void(*)(void))_cffi_exports[13])
  294. #define _cffi_save_errno \
  295. ((void(*)(void))_cffi_exports[14])
  296. #define _cffi_from_c_char \
  297. ((PyObject *(*)(char))_cffi_exports[15])
  298. #define _cffi_from_c_deref \
  299. ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[16])
  300. #define _cffi_to_c \
  301. ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[17])
  302. #define _cffi_from_c_struct \
  303. ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18])
  304. #define _cffi_to_c_wchar_t \
  305. ((wchar_t(*)(PyObject *))_cffi_exports[19])
  306. #define _cffi_from_c_wchar_t \
  307. ((PyObject *(*)(wchar_t))_cffi_exports[20])
  308. #define _cffi_to_c_long_double \
  309. ((long double(*)(PyObject *))_cffi_exports[21])
  310. #define _cffi_to_c__Bool \
  311. ((_Bool(*)(PyObject *))_cffi_exports[22])
  312. #define _cffi_prepare_pointer_call_argument \
  313. ((Py_ssize_t(*)(struct _cffi_ctypedescr *, \
  314. PyObject *, char **))_cffi_exports[23])
  315. #define _cffi_convert_array_from_object \
  316. ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[24])
  317. #define _CFFI_CPIDX 25
  318. #define _cffi_call_python \
  319. ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX])
  320. #define _CFFI_NUM_EXPORTS 26
  321. struct _cffi_ctypedescr;
  322. static void *_cffi_exports[_CFFI_NUM_EXPORTS];
  323. #define _cffi_type(index) ( \
  324. assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
  325. (struct _cffi_ctypedescr *)_cffi_types[index])
  326. static PyObject *_cffi_init(const char *module_name, Py_ssize_t version,
  327. const struct _cffi_type_context_s *ctx)
  328. {
  329. PyObject *module, *o_arg, *new_module;
  330. void *raw[] = {
  331. (void *)module_name,
  332. (void *)version,
  333. (void *)_cffi_exports,
  334. (void *)ctx,
  335. };
  336. module = PyImport_ImportModule("_cffi_backend");
  337. if (module == NULL)
  338. goto failure;
  339. o_arg = PyLong_FromVoidPtr((void *)raw);
  340. if (o_arg == NULL)
  341. goto failure;
  342. new_module = PyObject_CallMethod(
  343. module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg);
  344. Py_DECREF(o_arg);
  345. Py_DECREF(module);
  346. return new_module;
  347. failure:
  348. Py_XDECREF(module);
  349. return NULL;
  350. }
  351. /********** end CPython-specific section **********/
  352. #else
  353. _CFFI_UNUSED_FN
  354. static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *);
  355. # define _cffi_call_python _cffi_call_python_org
  356. #endif
  357. #define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
  358. #define _cffi_prim_int(size, sign) \
  359. ((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \
  360. (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \
  361. (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \
  362. (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \
  363. _CFFI__UNKNOWN_PRIM)
  364. #define _cffi_prim_float(size) \
  365. ((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \
  366. (size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \
  367. (size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \
  368. _CFFI__UNKNOWN_FLOAT_PRIM)
  369. #define _cffi_check_int(got, got_nonpos, expected) \
  370. ((got_nonpos) == (expected <= 0) && \
  371. (got) == (unsigned long long)expected)
  372. #ifdef MS_WIN32
  373. # define _cffi_stdcall __stdcall
  374. #else
  375. # define _cffi_stdcall /* nothing */
  376. #endif
  377. #ifdef __cplusplus
  378. }
  379. #endif
  380. /************************************************************/
  381. // This file is dual licensed under the terms of the Apache License, Version
  382. // 2.0, and the BSD License. See the LICENSE file in the root of this
  383. // repository for complete details.
  384. /* Returns the value of the input with the most-significant-bit copied to all
  385. of the bits. */
  386. static uint16_t Cryptography_DUPLICATE_MSB_TO_ALL(uint16_t a) {
  387. return (1 - (a >> (sizeof(uint16_t) * 8 - 1))) - 1;
  388. }
  389. /* This returns 0xFFFF if a < b else 0x0000, but does so in a constant time
  390. fashion */
  391. static uint16_t Cryptography_constant_time_lt(uint16_t a, uint16_t b) {
  392. a -= b;
  393. return Cryptography_DUPLICATE_MSB_TO_ALL(a);
  394. }
  395. uint8_t Cryptography_check_pkcs7_padding(const uint8_t *data,
  396. uint16_t block_len) {
  397. uint16_t i;
  398. uint16_t pad_size = data[block_len - 1];
  399. uint16_t mismatch = 0;
  400. for (i = 0; i < block_len; i++) {
  401. unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
  402. uint16_t b = data[block_len - 1 - i];
  403. mismatch |= (mask & (pad_size ^ b));
  404. }
  405. /* Check to make sure the pad_size was within the valid range. */
  406. mismatch |= ~Cryptography_constant_time_lt(0, pad_size);
  407. mismatch |= Cryptography_constant_time_lt(block_len, pad_size);
  408. /* Make sure any bits set are copied to the lowest bit */
  409. mismatch |= mismatch >> 8;
  410. mismatch |= mismatch >> 4;
  411. mismatch |= mismatch >> 2;
  412. mismatch |= mismatch >> 1;
  413. /* Now check the low bit to see if it's set */
  414. return (mismatch & 1) == 0;
  415. }
  416. uint8_t Cryptography_check_ansix923_padding(const uint8_t *data,
  417. uint16_t block_len) {
  418. uint16_t i;
  419. uint16_t pad_size = data[block_len - 1];
  420. uint16_t mismatch = 0;
  421. /* Skip the first one with the pad size */
  422. for (i = 1; i < block_len; i++) {
  423. unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
  424. uint16_t b = data[block_len - 1 - i];
  425. mismatch |= (mask & b);
  426. }
  427. /* Check to make sure the pad_size was within the valid range. */
  428. mismatch |= ~Cryptography_constant_time_lt(0, pad_size);
  429. mismatch |= Cryptography_constant_time_lt(block_len, pad_size);
  430. /* Make sure any bits set are copied to the lowest bit */
  431. mismatch |= mismatch >> 8;
  432. mismatch |= mismatch >> 4;
  433. mismatch |= mismatch >> 2;
  434. mismatch |= mismatch >> 1;
  435. /* Now check the low bit to see if it's set */
  436. return (mismatch & 1) == 0;
  437. }
  438. #define CRYPTOGRAPHY_PACKAGE_VERSION "3.3.2"
  439. /************************************************************/
  440. static void *_cffi_types[] = {
  441. /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 2), // uint8_t()(uint8_t const *, uint8_t)
  442. /* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 2), // uint8_t const *
  443. /* 2 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 18), // uint8_t
  444. /* 3 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
  445. /* 4 */ _CFFI_OP(_CFFI_OP_POINTER, 5), // char const *
  446. /* 5 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char
  447. };
  448. static void _cffi_const_CRYPTOGRAPHY_PACKAGE_VERSION(char *o)
  449. {
  450. *(char const * *)o = CRYPTOGRAPHY_PACKAGE_VERSION;
  451. }
  452. static uint8_t _cffi_d_Cryptography_check_ansix923_padding(uint8_t const * x0, uint8_t x1)
  453. {
  454. return Cryptography_check_ansix923_padding(x0, x1);
  455. }
  456. #ifndef PYPY_VERSION
  457. static PyObject *
  458. _cffi_f_Cryptography_check_ansix923_padding(PyObject *self, PyObject *args)
  459. {
  460. uint8_t const * x0;
  461. uint8_t x1;
  462. Py_ssize_t datasize;
  463. uint8_t result;
  464. PyObject *arg0;
  465. PyObject *arg1;
  466. if (!PyArg_UnpackTuple(args, "Cryptography_check_ansix923_padding", 2, 2, &arg0, &arg1))
  467. return NULL;
  468. datasize = _cffi_prepare_pointer_call_argument(
  469. _cffi_type(1), arg0, (char **)&x0);
  470. if (datasize != 0) {
  471. if (datasize < 0)
  472. return NULL;
  473. x0 = (uint8_t const *)alloca((size_t)datasize);
  474. memset((void *)x0, 0, (size_t)datasize);
  475. if (_cffi_convert_array_from_object((char *)x0, _cffi_type(1), arg0) < 0)
  476. return NULL;
  477. }
  478. x1 = _cffi_to_c_int(arg1, uint8_t);
  479. if (x1 == (uint8_t)-1 && PyErr_Occurred())
  480. return NULL;
  481. Py_BEGIN_ALLOW_THREADS
  482. _cffi_restore_errno();
  483. { result = Cryptography_check_ansix923_padding(x0, x1); }
  484. _cffi_save_errno();
  485. Py_END_ALLOW_THREADS
  486. (void)self; /* unused */
  487. return _cffi_from_c_int(result, uint8_t);
  488. }
  489. #else
  490. # define _cffi_f_Cryptography_check_ansix923_padding _cffi_d_Cryptography_check_ansix923_padding
  491. #endif
  492. static uint8_t _cffi_d_Cryptography_check_pkcs7_padding(uint8_t const * x0, uint8_t x1)
  493. {
  494. return Cryptography_check_pkcs7_padding(x0, x1);
  495. }
  496. #ifndef PYPY_VERSION
  497. static PyObject *
  498. _cffi_f_Cryptography_check_pkcs7_padding(PyObject *self, PyObject *args)
  499. {
  500. uint8_t const * x0;
  501. uint8_t x1;
  502. Py_ssize_t datasize;
  503. uint8_t result;
  504. PyObject *arg0;
  505. PyObject *arg1;
  506. if (!PyArg_UnpackTuple(args, "Cryptography_check_pkcs7_padding", 2, 2, &arg0, &arg1))
  507. return NULL;
  508. datasize = _cffi_prepare_pointer_call_argument(
  509. _cffi_type(1), arg0, (char **)&x0);
  510. if (datasize != 0) {
  511. if (datasize < 0)
  512. return NULL;
  513. x0 = (uint8_t const *)alloca((size_t)datasize);
  514. memset((void *)x0, 0, (size_t)datasize);
  515. if (_cffi_convert_array_from_object((char *)x0, _cffi_type(1), arg0) < 0)
  516. return NULL;
  517. }
  518. x1 = _cffi_to_c_int(arg1, uint8_t);
  519. if (x1 == (uint8_t)-1 && PyErr_Occurred())
  520. return NULL;
  521. Py_BEGIN_ALLOW_THREADS
  522. _cffi_restore_errno();
  523. { result = Cryptography_check_pkcs7_padding(x0, x1); }
  524. _cffi_save_errno();
  525. Py_END_ALLOW_THREADS
  526. (void)self; /* unused */
  527. return _cffi_from_c_int(result, uint8_t);
  528. }
  529. #else
  530. # define _cffi_f_Cryptography_check_pkcs7_padding _cffi_d_Cryptography_check_pkcs7_padding
  531. #endif
  532. static const struct _cffi_global_s _cffi_globals[] = {
  533. { "CRYPTOGRAPHY_PACKAGE_VERSION", (void *)_cffi_const_CRYPTOGRAPHY_PACKAGE_VERSION, _CFFI_OP(_CFFI_OP_CONSTANT, 4), (void *)0 },
  534. { "Cryptography_check_ansix923_padding", (void *)_cffi_f_Cryptography_check_ansix923_padding, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 0), (void *)_cffi_d_Cryptography_check_ansix923_padding },
  535. { "Cryptography_check_pkcs7_padding", (void *)_cffi_f_Cryptography_check_pkcs7_padding, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 0), (void *)_cffi_d_Cryptography_check_pkcs7_padding },
  536. };
  537. static const struct _cffi_type_context_s _cffi_type_context = {
  538. _cffi_types,
  539. _cffi_globals,
  540. NULL, /* no fields */
  541. NULL, /* no struct_unions */
  542. NULL, /* no enums */
  543. NULL, /* no typenames */
  544. 3, /* num_globals */
  545. 0, /* num_struct_unions */
  546. 0, /* num_enums */
  547. 0, /* num_typenames */
  548. NULL, /* no includes */
  549. 6, /* num_types */
  550. 0, /* flags */
  551. };
  552. #ifdef PYPY_VERSION
  553. PyMODINIT_FUNC
  554. _cffi_pypyinit__padding(const void *p[])
  555. {
  556. p[0] = (const void *)0x2601;
  557. p[1] = &_cffi_type_context;
  558. }
  559. # ifdef _MSC_VER
  560. PyMODINIT_FUNC
  561. # if PY_MAJOR_VERSION >= 3
  562. PyInit__padding(void) { return NULL; }
  563. # else
  564. init_padding(void) { }
  565. # endif
  566. # endif
  567. #elif PY_MAJOR_VERSION >= 3
  568. PyMODINIT_FUNC
  569. PyInit__padding(void)
  570. {
  571. return _cffi_init("_padding", 0x2601, &_cffi_type_context);
  572. }
  573. #else
  574. PyMODINIT_FUNC
  575. init_padding(void)
  576. {
  577. _cffi_init("_padding", 0x2601, &_cffi_type_context);
  578. }
  579. #endif